Hi Erik,
I've just sent out a patch to foreigners that should fix the foreigners issue.
I patched the C5 version originally and missed a couple instances. The solution
indeed is to use error instead.
Attached here is a patch to your latest stty sources that, given a newly
patched foreigners, does a few things:
- Makes it compile in C6 by importing port? from scheme.base
- Adds some high-level functions I was missing from (chibi stty) - with-raw-io,
get-terminal-width, and get-terminal-dimensions
- Makes the high level functions all take an optional port argument defaulting
to (current-input-port)
Diego
On Wednesday, September 2nd, 2026 at 13:52, Erik Falor via Chicken-users
<[email protected]> wrote:
> Hi Mario,
>
> Thanks for adding color and x11-colors.
>
> I'll take a look at that stty build error and let you know what I find. I had
> been running into it intermittently while testing my eggs, and at one point
> it had just disappeared. I assumed that something in the upstream foreigners
> egg had been changed that fixed it. But I just received the same error
> message after clearing my chicken-install cache, re-installing foreigners,
> and re-building the stty egg.
>
> Digging deeper, I found that stty's issue has highlighted a mistake in the
> foreigners egg. Namely, that the `syntax-error` macro expects its first
> argument to be a string; the foreigners egg is passing a symbol instead. The
> attached patch to foreigners.scm adjusts this. I also noticed in CHICKEN
> 6.0's version of the foreigners egg that two uses of `syntax-error` were
> changed to `error`. So now I wonder if instead of my patch all instances of
> `syntax-error` should become `error` instead.
>
> Nevertheless, there is still something wrong with the stty egg, and I'll
> continue digging.
> -Erik
>
> On Wed, Sep 2, 2026 at 5:01 AM Mario Domenech Goulart <[email protected]>
> wrote:
>
>> On Sun, 30 Aug 2026 16:33:29 -0600 Erik Falor via Chicken-users
>> <[email protected]> wrote:
>>
>>> The eggs colors, x11-colors, and stty have been ported to CHICKEN 6. Until
>>> they arrive in the coop, you may clone them
>>> from their repositories:
>>>
>>> https://github.com/fadein/chicken-color version 1.2
>>> https://gitlab.com/erik.falor/x11-colors version 1.2.1
>>> https://github.com/fadein/chicken-stty version 0.9.1
>>
>> Thanks, Erik. color and x11-colors have been added to CHICKEN 6.
>> stty's installation fails with
>>
>> Syntax error: (stty.scm:106) in `syntax-error' - string expected
>>
>> (syntax-error40 (quote define-foreign-record) "array access out of range"
>> (quote term-attrs) (quote g55) NCCS)
>>
>> All the best.
>> Mario
>> --
>> https://parenteses.org/mario
>
> --
>
> Erik Falor
From 970dc0f568a007f2116f145bc8e4453c25a4c56d Mon Sep 17 00:00:00 2001
From: "Diego A. Mundo" <[email protected]>
Date: Sun, 13 Sep 2026 01:19:17 -0400
Subject: [PATCH] Add with-raw-io and terminal size procedures from Chibi
- Slightly modified to default to current-input-port
- Also make current-input-port default for with-stty
---
stty.scm | 49 ++++++++++++++++++++++++++++++++++++++++++++-----
1 file changed, 44 insertions(+), 5 deletions(-)
diff --git a/stty.scm b/stty.scm
index e3578d3..4a26c14 100644
--- a/stty.scm
+++ b/stty.scm
@@ -69,8 +69,9 @@
#f))
(module stty
- (stty with-stty
+ (stty with-stty with-raw-io
get-terminal-attributes set-terminal-attributes!
+ get-terminal-width get-terminal-dimensions
make-term-attrs free-term-attrs
term-attrs-iflag term-attrs-iflag-set!
term-attrs-oflag term-attrs-oflag-set!
@@ -97,8 +98,14 @@ (module stty
(chicken foreign)
foreigners)))
+(cond-expand
+ (chicken-6 (import (only (scheme base) port?)))
+ (else))
+
(declare (foreign-declare "#include <termios.h>\n"))
+(declare (foreign-declare "#include <sys/ioctl.h>\n"))
(declare (foreign-declare "typedef struct termios struct_termios;\n"))
+(declare (foreign-declare "typedef struct winsize struct_winsize;\n"))
;; Use the platform c_cc size for accessor bounds.
(define-foreign-variable NCCS int "NCCS")
@@ -113,6 +120,29 @@ (define-foreign-record-type (term-attrs struct_termios)
(unsigned-char (c_cc NCCS) term-attrs-cc term-attrs-cc-set!)
)
+(define-foreign-record-type (winsize struct_winsize)
+ (constructor: make-winsize)
+ (destructor: free-winsize)
+ (unsigned-short ws_row winsize-row)
+ (unsigned-short ws_col winsize-col))
+
+(define-foreign-type port-or-fileno
+ int
+ (lambda (x)
+ (if (integer? x)
+ x
+ (port->fileno x))))
+
+(define (ioctl port op)
+ (let ((winsize (make-winsize)))
+ (and (zero?
+ ((foreign-lambda* int ((port-or-fileno port) (unsigned-long op) (c-pointer t))
+ "C_return(ioctl(port, op, (struct winsize*) t));")
+ port
+ op
+ winsize))
+ winsize)))
+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; constants
@@ -240,6 +270,7 @@ (define-foreign-variable VSTATUS unsigned-long)
(define-foreign-variable VMIN unsigned-long)
(define-foreign-variable VTIME unsigned-long)
+(define TIOCGWINSZ (foreign-value "TIOCGWINSZ" int))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; basic interface
@@ -652,9 +683,8 @@ (define (port-or-fileno? arg)
(set-terminal-attributes! port TCSANOW attr)
(free-term-attrs attr)))
-(define (with-stty setting thunk)
- (let* ((port (current-input-port))
- (orig-attrs (get-terminal-attributes port)))
+(define (with-stty setting thunk #!optional (port (current-input-port)))
+ (let* ((orig-attrs (get-terminal-attributes port)))
(if orig-attrs
(dynamic-wind
(lambda ()
@@ -665,4 +695,13 @@ (define (with-stty setting thunk)
(free-term-attrs orig-attrs)))
(thunk))))
-)
+(define (with-raw-io thunk #!optional (port (current-input-port)))
+ (with-stty '(not icanon isig echo) thunk port))
+
+(define (get-terminal-width #!optional (port (current-input-port)))
+ (let ((ws (ioctl port TIOCGWINSZ)))
+ (and ws (winsize-col ws))))
+
+(define (get-terminal-dimensions #!optional (port (current-input-port)))
+ (let ((ws (ioctl port TIOCGWINSZ)))
+ (and ws (list (winsize-col ws) (winsize-row ws))))))
--
2.47.3