Write the package of user commands on the first interactive start
When $XDG_CONFIG_HOME/bjosh/commands is not there, an interactive bjosh writes it with the example, then builds and loads it. An empty directory turns this off. --new-commands stays, for a start that is not interactive. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
aa5bae96e0
commit
bf961b12f9
4 changed files with 38 additions and 10 deletions
|
|
@ -121,13 +121,14 @@
|
|||
(go (+ j 1) out))))
|
||||
(else (stringbuilder-add! out (vec-ref chars i)) (go (+ i 1) out)))))
|
||||
|
||||
;; Types lines into an interactive bjosh under `script`. Returns what it
|
||||
;; writes, without escape sequences.
|
||||
(: (-> (Vec string) string))
|
||||
(defun (interactive lines)
|
||||
(def keys (str "sleep 2.5; "
|
||||
;; Types lines into an interactive bjosh under `script`, with `dir` as
|
||||
;; XDG_CONFIG_HOME, after `wait` seconds. Returns what it writes, without
|
||||
;; escape sequences.
|
||||
(: (-> string string (Vec string) string))
|
||||
(defun (interactive dir wait lines)
|
||||
(def keys (str "sleep " wait "; "
|
||||
(string-join (vec-map (fun (l) (str "printf '" l "\\r'; sleep 0.7")) lines) "; ")))
|
||||
(def command (str "(" keys ") | XDG_STATE_HOME=" config " XDG_CONFIG_HOME=" config
|
||||
(def command (str "(" keys ") | XDG_STATE_HOME=" dir " XDG_CONFIG_HOME=" dir
|
||||
" script -qec 'dotnet src/main.exe' /dev/null"))
|
||||
(match (run/output '(sh "-c" ,command))
|
||||
((Ok (Tuple _ text)) (plain text))
|
||||
|
|
@ -175,13 +176,21 @@
|
|||
|
||||
(if (not (file-exists? "/usr/bin/script"))
|
||||
(println "skipped: the prompt (no script command)")
|
||||
(let ((out (interactive ["true" "false" "true" "exit"])))
|
||||
(let ((out (interactive config "2.5" ["true" "false" "true" "exit"])))
|
||||
(expect-true "the prompt of the commands" (string-contains? out "[ext 0]> true"))
|
||||
(expect-true "a prompt that raises writes its message"
|
||||
(string-contains? out "bjosh: the prompt of your commands raised: the prompt failed"))
|
||||
(expect "once" (vec-length (string-split out "the prompt failed")) 2)
|
||||
(expect-true "and the default prompt is used after it" (not (string-contains? out "[ext 0]> exit")))))
|
||||
|
||||
(if (file-exists? "/usr/bin/script")
|
||||
(let* ((fresh (path-combine config "fresh"))
|
||||
(out (interactive fresh "12" ["echo a | twice" "exit"])))
|
||||
(expect-true "the first interactive start writes the package"
|
||||
(string-contains? out "bjosh: wrote your commands to "))
|
||||
(expect-true "and builds and loads it" (string-contains? out "twice\na\na\n")))
|
||||
unit)
|
||||
|
||||
(ignore (directory-delete-tree config))
|
||||
(println "extension ok")
|
||||
0)
|
||||
|
|
|
|||
|
|
@ -39,7 +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")))
|
||||
;; An empty commands directory: no package of user commands is written.
|
||||
(ignore (directory-create (path-combine state "bjosh/commands")))
|
||||
(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"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue