Ctrl-C of a value command that reads a terminal or a FIFO

The file of < is opened with #:cancellable? #t, so Ctrl-C of
li < /dev/tty takes nothing from the terminal, and the next line goes to
the editor. tests/interactive.bjo checks it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Linus Björnstam 2026-12-01 08:13:20 +01:00
parent 8ded734477
commit f54ceb35af
3 changed files with 11 additions and 5 deletions

View file

@ -280,10 +280,10 @@ the text above:*
after one with ~>~ is an error. ~2>~, ~2>&1~, assignments and ~&~ of
value commands are errors.
- A pipe of only value commands runs in the shell, with an empty input
or the file of ~<~. Ctrl-C cancels it with status 130, but only at a
point where a command waits for a value: a read of a terminal or a FIFO
(~li < /dev/tty~) is not cancelled, and goes on until it has a line.
There is no test of Ctrl-C: no value command waits long otherwise.
or the file of ~<~. Ctrl-C cancels it with status 130. The file of ~<~
is opened with ~#:cancellable? #t~, so a cancelled read of a terminal or
a FIFO (~li < /dev/tty~) takes nothing from it, and the next line goes to
the editor (Linux only). tests/interactive.bjo checks this.
- ~jobs~ and ~history~ are values in a pipe: records of number, current,
state, command and id; and of number and line. Alone they write text.
- ~2>&1~ is done (phase 3): ~>FILE 2>&1~ works, ~2>&1 >FILE~ is an error.

View file

@ -312,7 +312,9 @@
(else
(match (record-ref seg from)
((Some path)
(match (open-input-file path)
;; Cancellable, so Ctrl-C of a read of a terminal or a FIFO takes
;; nothing from it.
(match (open-input-file path #:cancellable? #t)
((Ok in) (run-values-from sh seg in))
((Err e) (shell-error (fs-error-message e)) 1)))
(None (run-values-from sh seg (open-input-string "")))))))

View file

@ -54,6 +54,8 @@
"printf 'kill %%1\\r'" "sleep 0.5"
"printf 'printf x | u\\r'" "sleep 1"
"printf 'stty tostop; printf y | u; stty -tostop\\r'" "sleep 1"
"printf 'li < /dev/tty\\r'" "sleep 1" "printf '\\003'" "sleep 0.5"
"printf 'echo after $?\\r'" "sleep 0.5"
"printf 'exit\\r'" "sleep 1"]
"; "))
(def command (str "(" keys ") | XDG_STATE_HOME=" state " script -qec 'dotnet src/main.exe' /dev/null"))
@ -72,6 +74,8 @@
(string-contains? out "history | tl 1 | g line\nhistory | tl 1 | g line\n"))
(expect-true "a value command at the end of a job" (string-contains? out "printf x | u\nx\n"))
(expect-true "and with tostop set" (string-contains? out "stty -tostop\ny\n"))
(expect-true "Ctrl-C of a read of the terminal, and the next line runs"
(string-contains? out "\nafter 130\n"))
(expect-true "the history is saved"
(match (file-read-text (path-combine state "bjosh/history"))
((Ok text) (string-contains? text "kill %1"))