From 590ac3b853e967abc39bec3785a43ec89bd8207a55ce3da8c221ff6350f02301 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Linus=20Bj=C3=B6rnstam?= Date: Tue, 1 Dec 2026 06:19:36 +0100 Subject: [PATCH] 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 --- manifest.bjodat | 2 +- plan.org | 2 ++ src/line.bjo | 15 ++++++++++----- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/manifest.bjodat b/manifest.bjodat index c570a37..f053daa 100644 --- a/manifest.bjodat +++ b/manifest.bjodat @@ -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. diff --git a/plan.org b/plan.org index 98429da..af63992 100644 --- a/plan.org +++ b/plan.org @@ -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 diff --git a/src/line.bjo b/src/line.bjo index 1a78b48..3906838 100644 --- a/src/line.bjo +++ b/src/line.bjo @@ -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))))))