Phase 3: $(...), aliases, a start-up file, PROMPT, Done lines, >&2
- $(...) runs in a subshell. A word that is only an unquoted $(...) is one word per line. X=$(cmd) sets $? to its status. - alias, unalias, and command NAME. An alias is one pipe. - ~/.config/bjosh/rc runs before the first prompt. - PROMPT, expanded as in double quotes, with \w \W \u \h \$ \e \n. - "Done" lines are written above the input while the prompt waits. - >&2, for programs and value commands. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
f54ceb35af
commit
f8c4ad64bc
13 changed files with 680 additions and 128 deletions
|
|
@ -7,7 +7,8 @@
|
|||
;; bjo build && bjo test tests/interactive.bjo
|
||||
;;
|
||||
;; The test runs bjosh under `script`, and writes keys to it with pauses
|
||||
;; between them. The history goes to a directory of the test.
|
||||
;; between them. The history and the start-up file are in a directory of
|
||||
;; the test.
|
||||
|
||||
(import (std prelude))
|
||||
(import (std simpletest))
|
||||
|
|
@ -38,6 +39,8 @@
|
|||
((not (file-exists? "src/main.exe")) (println "FAILURE: src/main.exe is missing: run bjo build first"))
|
||||
(else
|
||||
(def state (path-combine (temp-dir) (str "bjosh-interactive-" (int->string process-id))))
|
||||
(ignore (directory-create (path-combine state "bjosh")))
|
||||
(ignore (file-write-text (path-combine state "bjosh/rc") "alias fromrc='echo set in rc'\n"))
|
||||
(def keys (string-join ["sleep 2.5"
|
||||
"printf 'sleep 30\\r'" "sleep 1" "printf '\\032'" "sleep 0.5"
|
||||
"printf 'jobs\\r'" "sleep 0.5"
|
||||
|
|
@ -56,9 +59,13 @@
|
|||
"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 'fromrc\\r'" "sleep 0.5"
|
||||
"printf 'sleep 0.5 &\\r'" "sleep 0.3" "printf 'ec'" "sleep 1.5" "printf 'ho typed\\r'" "sleep 0.5"
|
||||
"printf 'cd /tmp\\r'" "sleep 0.3"
|
||||
"printf \"PROMPT='<\\\\W \\$(echo s)>\\\\$ '\\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"))
|
||||
(def command (str "(" keys ") | XDG_STATE_HOME=" state " XDG_CONFIG_HOME=" state " script -qec 'dotnet src/main.exe' /dev/null"))
|
||||
(def out (match (run/output '(sh "-c" ,command))
|
||||
((Ok (Tuple _ text)) (plain text))
|
||||
((Err e) (run-error-message e))))
|
||||
|
|
@ -76,6 +83,12 @@
|
|||
(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 start-up file runs" (string-contains? out "fromrc\nset in rc\n"))
|
||||
(expect-true "a job that ends is reported while the prompt waits"
|
||||
(match (string-split-once out "Done sleep 0.5")
|
||||
((Some (Tuple _ after)) (string-contains? after "echo typed\ntyped\n"))
|
||||
(None #f)))
|
||||
(expect-true "PROMPT" (string-contains? out "<tmp s>$ "))
|
||||
(expect-true "the history is saved"
|
||||
(match (file-read-text (path-combine state "bjosh/history"))
|
||||
((Ok text) (string-contains? text "kill %1"))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue