From cda0b279a24e8becc3c2836c42e7321830e2467a Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Thu, 1 Oct 2026 05:37:37 -0300 Subject: Recipes work through a pane of their own, its look and exec, and keep a command pane while their open lasts; the docs give cmd panes, the err grep, alt-screen prompts, /pager's refusals, Tty+ on a ctl, --, and theme failures in words Co-Authored-By: Claude Opus 5.5 --- docs/typ/scripting.typ | 43 +++++++++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 14 deletions(-) (limited to 'docs/typ/scripting.typ') diff --git a/docs/typ/scripting.typ b/docs/typ/scripting.typ index 555c6b43..7bf04efe 100644 --- a/docs/typ/scripting.typ +++ b/docs/typ/scripting.typ @@ -48,26 +48,34 @@ Both hold only where your environment names no pager. = Recipes -Each recipe starts after these lines, which find the session (with a mount) -and name a text pane by its serial (from #file("index"), or one you made): -#cmd("s=${PARDES_9P##*/pardes-9p-}; m=$NINE_MOUNT/pardes/${s%.sock}\nn=3; p=$m/pane/$n") +Each recipe starts after these lines, which find the session (with a +mount) and make a pane of your own. Work through that pane's #file("look") +and #file("exec"), not the root's (see the traps): +#cmd("s=${PARDES_9P##*/pardes-9p-}; m=$NINE_MOUNT/pardes/${s%.sock}\nn=$(cat $m/pane/new); p=$m/pane/$n # a scratch of your own") #pairs( [look around], [#cmd("cat $m/index\ncat $m/layout\ncat $m/focus\ncat $m/commands")], - [open a file at a place], [#cmd("exec 3<>$m/look; echo \"$PWD/main.zig:120\" >&3; cat <&3; exec 3<&- # where it went\necho 'main.zig:0/fn main/' > $m/look # the first match")], - [make, fill, name, save], [#cmd("n=$(cat $m/pane/new) # one pane per open\nprintf 'hello\\n' > $m/pane/$n/body # > replaces, >> appends\necho \"$PWD/notes.txt\" > $m/pane/$n/name\necho Save > $m/pane/$n/ctl\nrmdir $m/pane/$n # close it")], - [say something], [#cmd("echo 'Msg hello' > $m/exec")], + [open a file at a place], [#cmd("exec 3<>$p/look; echo \"$PWD/main.zig:120\" >&3; f=$(cat <&3); exec 3<&- # its pane\necho \"$PWD/main.zig:0/fn main/\" > $p/look # the first match")], + [fill, name, save, close], [#cmd("printf 'hello\\n' > $p/body # > replaces, >> appends\necho \"$PWD/notes.txt\" > $p/name\necho Save > $p/ctl\nrmdir $p")], + [say something], [#cmd("echo 'Msg hello' > $p/exec")], [replace everywhere], [#cmd("echo 'Edit ,x/foo/c/bar/' > $p/ctl\ngrep -c foo $p/body # 0: none left")], [replace one match], [#cmd("echo /old/ > $p/addr && printf new > $p/data")], [delete line 3], [#cmd("echo 3 > $p/addr; : > $p/data")], [select line 3, read it], [#cmd("echo 3 > $p/addr; cp $p/addr $p/dot; cat $p/sel")], - [run a command], [#cmd("exec 3<>$m/exec; echo 'make test' >&3; c=$(cat <&3); exec 3<&- # its pane\nuntil grep -q ') exit ' $m/pane/$c/tag; do sleep 0.2; done\ngrep -o 'exit [0-9?]*' $m/pane/$c/tag")], + [run a command], [#cmd("exec 3<>$p/exec; echo \"cd '$PWD' && make test\" >&3; c=$(cat <&3) # its pane\nuntil grep -q ') exit ' $m/pane/$c/tag; do sleep 0.2; done\ncat $m/pane/$c/body; exec 3<&- # read it before letting go")], [run at a prompt], [#cmd("t=$(awk '$2==\"term\"{print $1; exit}' $m/index)\nexec 3<>$m/pane/$t/pty/run; echo ls >&3; cat <&3; exec 3<&-")], [type, interrupt], [#cmd("t=$(awk '$2==\"term\"{print $1; exit}' $m/index)\nprintf 'q' > $m/pane/$t/pty/data # \\r Enter, \\x03 Ctrl-C\necho 'sig INT' > $m/pane/$t/pty/ctl")], - [ask the language server], [#cmd("echo /myFunc/ > $p/addr; echo dot=addr > $p/ctl\necho Hover > $p/exec # also Rename new, Symbols")], + [ask the language server], [#cmd("exec 3<>$p/look; echo \"$PWD/main.zig\" >&3; q=$m/pane/$(cat <&3); exec 3<&-\necho /myFunc/ > $q/addr; echo dot=addr > $q/ctl\necho Hover > $q/exec # also Rename new, Symbols")], [follow what happens], [#cmd("exec 3<>$m/log; echo 'follow new' >&3\ntimeout 30 cat <&3; exec 3<&-")], ) +A command pane your #file("exec") open was answered is yours while that +open stays open: another client's command in the same directory gets a +pane of its own. Read its #file("body") and poll its tag before you close +the open; once you have, the directory's next command may reuse the pane. +In #file("index") a `term` is a shell to type at, a `cmd` a +command's pane. + `follow` without `new` replays the ring first. == A script for a tag @@ -140,12 +148,19 @@ pardes the editor of every program run there. = Traps -- Check the write's own status first: a refused write says only `Invalid - argument` or `Input/output error`, and only then is the log's last `err` - record its reason: `echo Save > $p/ctl || tail -1 $m/log`. A write that - succeeds adds no record, so after a success the log's tail may still show - an older, unrelated `err`. Only writes log: a refused open, truncation or +- A refused write says only `Invalid argument` or `Input/output error`; + its reason is the log's last `err` record: `grep '^err' $m/log | tail -1`. + Not the log's last line: after a refused Del, Exit or Restore that may be + `new N .../+Unsaved`. A write that succeeds adds no record, so check the + write's own status first. Only writes log: a refused open, truncation or `rmdir` has its errno alone. +- The root #file("look") and #file("exec") act at the active pane, which + another client, an idle shell or an event helper may own: a line written + there may be typed into a terminal or taken by an event reader. Use a + pane's own #file("look") and #file("exec"). +- `head` through a 9ns mount says `Illegal seek` on the files that stat 0 + (#file("index"), #file("layout"), #file("log"), #file("recent")): they + are streams. Use `sed -n 1p` or `awk 'NR==1'`; `tail -n` works. - #file("addr") belongs to the pane, not to you, and moves on: each `/re/` searches from the last address, a #file("data") write leaves it just past what it wrote, and a read moves it too. Write #file("addr") @@ -167,7 +182,7 @@ pardes the editor of every program run there. - Read #file("look"), #file("exec") or #file("pager") on the open you wrote: a read answers the panes touched by this open's last write, and a fresh open reads the session's last answer, from whichever client wrote - it (`exec 3<>$m/exec; echo cmd >&3; cat <&3; exec 3<&-`). + it (`exec 3<>$p/exec; echo cmd >&3; cat <&3; exec 3<&-`). - `tail -f log` never sees anything new: write `follow` on the open you read. Through a FUSE mount bash's `read -t` cannot time out: wrap the loop in `timeout`. -- cgit v1.3