line-read: #:suspend? #f makes C-z ring the bell

A shell must not stop itself at its prompt. With #:suspend? #f, C-z
rings the bell instead of stopping the program. The default is #t, as
before. The manifest comment no longer names glue/Keys.cs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Linus Björnstam 2026-12-01 06:19:36 +01:00
parent 566008e264
commit 590ac3b853
3 changed files with 13 additions and 6 deletions

View file

@ -4,7 +4,7 @@
(description "The terminal for Bjolang programs: raw mode, key events and escape sequences. Linux.")
(license "MPL-2.0")
;; Termios, poll and the key decoder. See glue/Tty.cs and glue/Keys.cs.
;; Termios, signals, and poll and read of bytes. See glue/Tty.cs.
(csharp "glue")
;; A library: there is no src/main.bjo.

View file

@ -54,6 +54,8 @@ is in raw mode, and gives it back as it found it.
- A reflow that makes the drawn rows taller than the screen pushes the
first of them into the scrollback, where the cursor cannot go. They
stay there once, as a copy; the next drawing fits the screen.
- ~#:suspend? #f~ (2026-11-30): C-z rings the bell instead of stopping the
program. For a shell, which must not stop itself at its prompt.
- Tall input (2026-11-30): input taller than the screen is drawn in
part, so that the cursor can always go up to its first row.
~input-window~ chooses the rows: the window stays while the cursor is in

View file

@ -64,6 +64,7 @@
(: input-done? (Option (-> string bool)))
(: history-size int)
(: reflow? (Option bool))
(: suspend? bool)
(: history (Vec string) #:mutable))))
;; Reverse search through the history.
@ -105,6 +106,8 @@
;; - `#:input-done?`: called by Enter with the whole input. #f makes Enter
;; start a new line; a REPL returns #f while brackets are open.
;; - `#:history-size`: the most entries kept; the oldest go first.
;; - `#:suspend?`: whether C-z stops the program. A shell sets #f; C-z
;; then rings the bell.
;; - `#:reflow?`: whether the terminal wraps its lines again when it gets
;; narrower. None uses `terminal-reflows?`. A wrong #t can erase output
;; above the input when the terminal narrows; a wrong #f leaves a copy of
@ -113,10 +116,12 @@
(#:input-done? (Option (-> string bool)))
(#:history-size int)
(#:reflow? (Option bool))
(#:suspend? bool)
LineEditor))
(defun (make-line-editor #:completer None #:input-done? None #:history-size 1000 #:reflow? None)
(defun (make-line-editor #:completer None #:input-done? None #:history-size 1000 #:reflow? None
#:suspend? #t)
(LineEditor (completer completer) (input-done? input-done?)
(history-size history-size) (reflow? reflow?) (history [])))
(history-size history-size) (reflow? reflow?) (suspend? suspend?) (history [])))
;; The history, oldest first.
(: (-> LineEditor (Vec string)))
@ -199,8 +204,8 @@
;; - Tab completes with `#:completer`, and a second Tab lists the
;; candidates. Without a completer it inserts a tab.
;; - Enter accepts (see `#:input-done?`), M-Enter and C-j start a new line,
;; C-l clears the screen, C-z stops the program, C-c cancels, and C-d on
;; an empty buffer is end of input.
;; C-l clears the screen, C-z stops the program (see `#:suspend?`),
;; C-c cancels, and C-d on an empty buffer is end of input.
(: (-> LineEditor Terminal string (#:continuation (Option string)) LineResult))
(defun (line-read ed term prompt #:continuation None)
(def cont (match continuation
@ -791,5 +796,5 @@
((Tuple KeyTab (Tuple #f #f)) (complete ed st (record-ref prev tabbed?)))
((Tuple (KeyChar #\i) (Tuple #t #f)) (complete ed st (record-ref prev tabbed?)))
((Tuple (KeyChar #\l) (Tuple #t #f)) (ClearScreen st))
((Tuple (KeyChar #\z) (Tuple #t #f)) (SuspendNow st))
((Tuple (KeyChar #\z) (Tuple #t #f)) (if (record-ref ed suspend?) (SuspendNow st) (Bell st)))
(_ (Bell st))))))