From 9be47b76e4edf4ddb56e4d572c14b54bf45fdd39 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Thu, 29 Oct 2026 10:48:56 -0300 Subject: docs: the daemon, Detach, --attach and Adopt; phase 3 notes in docs/next-daemon.md building.typ's detached sessions are the daemon and its sessions; the guide, cheatsheet and reference say what Detach, a closing terminal, --attach of each kind and Adopt do, and that attaching from another machine waits for phase 5. docs/next-daemon.md records the forks taken (sessions register and are not the daemon's children, and why; how it starts; masters; Adopt as a word; the stub's signals and job control; --detach; the Attach word; the harness switch), the known gaps, and the termios trap. Co-Authored-By: Claude Opus 5.5 --- docs/typ/reference.typ | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'docs/typ/reference.typ') diff --git a/docs/typ/reference.typ b/docs/typ/reference.typ index b83b4a83..c95a574a 100644 --- a/docs/typ/reference.typ +++ b/docs/typ/reference.typ @@ -386,9 +386,9 @@ Writes take settings and session builtins (`scope = .session` in record for why. A #word("ThemeFile") the dump names that fails to load changes nothing. - #word("Kill") `[word...]` (above), #word("Mount") `name dial`, #word("Unmount") `name`, #word("Theme") `x`. -- `size C R` sizes a `--detach` session no frontend is attached to (160x50 - until then): from 20x6 to 4096x4096, else `invalid size`; refused while a - frontend owns the size, and when a column would lose its panes' minimum +- `size C R` sizes a session no terminal or window is attached to (160x50 + for a `--detach` one until then): from 20x6 to 4096x4096, else `invalid + size`; refused while a terminal or window owns the size, and when a column would lose its panes' minimum rows (`size: too small for the panes, each its tag and 2 rows`). A bad `size` is refused quoting the value it got (`"5 2"`). @@ -454,8 +454,7 @@ turning it off: #word("PanelSlide"), #word("PanelZoom"), #word("PanelDissolve"), #word("PanelAscii"), #word("PanelVertical"), #word("PanelEdges"), #word("PanelFall"), #word("PanelWave"), #word("PanelCurtain"), #word("PanelScramble"), #word("PanelType"); all -start off, and the web shell has none. Scene passes (the SDL window, and -one attached to a detached session), each at a level 0-3 (`on` is 2), all +start off, and the web shell has none. Scene passes (the SDL window), each at a level 0-3 (`on` is 2), all off: #word("Crt"), #word("Bloom"), #word("Vignette"), #word("Grain"). #word("Shader") `` adds a Shadertoy file written for ghostty to the chain (#word("Shader") `off` removes it; it recompiles when saved); @@ -1011,11 +1010,14 @@ to its end before the write is answered, and one that finds nothing fails, git's `a/` `b/` (and `c/ i/ w/ o/`) prefixes are dropped; a `--no-prefix` diff's paths are kept. - *Sessions.* Bare `--detach` names the session after its pid; bare - `--attach` needs exactly one session; a second `--detach=NAME` while NAME - runs (a plain session is named by its pid) says so in words and exits 1. Frontends share the smallest common size. With - none attached, `size C R` sets the screen, messages clear by the clock, - and a pty reports its size in pixels at the last frontend's cell size - (8×16 before any), as CSI 14, 16 and 18 t do. + `--attach` needs exactly one detached session of its kind (a terminal's + for `pardes`, a window's for `pardes-gui`); a second `--detach=NAME` + while NAME runs (a plain session is named by its pid) says so in words + and exits 1. One terminal or window shows a session at a time. With none + attached, `size C R` sets the screen, messages clear by the clock, and a + pty reports its size in pixels at the last cell size (8×16 before any), + as CSI 14, 16 and 18 t do. Attaching from another machine is gone until + the replicated clients (docs/next-daemon.md, phase 5). - *Config.* The startup file is `$XDG_CONFIG_HOME/pardes/init` when that is absolute, else `~/.config/pardes/init` (macOS: `~/Library/Application Support/pardes/init`). A line that fails is a -- cgit v1.3 From 74286e81e88a6df7586ead9e8bcd503d44446a85 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Thu, 29 Oct 2026 17:58:06 -0300 Subject: docs: views in the guide and reference (a session attached already takes another view, up to four; Detach lets one go); phase 4 notes in docs/next-daemon.md; tty: Screen.hungUp reads a test terminal's fd as the test build has it Co-Authored-By: Claude Opus 5.5 --- docs/next-daemon.md | 124 +++++++++++++++++++++++++++++++++++++++++++++++++ docs/typ/guide.typ | 6 ++- docs/typ/reference.typ | 11 ++++- src/tty/tty.zig | 3 +- 4 files changed, 140 insertions(+), 4 deletions(-) (limited to 'docs/typ/reference.typ') diff --git a/docs/next-daemon.md b/docs/next-daemon.md index e3be6af8..b5939b9d 100644 --- a/docs/next-daemon.md +++ b/docs/next-daemon.md @@ -271,6 +271,130 @@ termios` into Zig's `std.c.termios`, which is 44 (the kernel's layout), and overran the stack, clobbering a neighbouring local in the forked child; `std.posix.tcgetattr` (an ioctl on that layout) is the right one. +## Phase 4 notes + +Built 2026-10-29 (`src/views.zig`, the tty and GUI hosts, `daemon.zig`, +the snapshot harness and the monkey). Decisions taken at the forks, with +the ponytail lens: + +- **A view is swapped in, not pointed at.** The ~1,900 references to the + core's layout, focus and pane state stay as they are: the core sees one + view, the live one, in the fields it always had. A view's share of the + session is a list of field names (`views.fields`, ~60) made into a struct + by one comptime `@Struct` (`Part`), and of each pane a struct beside it + (`PaneView`, in `Pane.pv`); going into view `k` copies the live one's out + (`park`) and `k`'s in (`unpark`). Copies, not swaps: a slot is stale + while its view is live and written whenever it goes out, so no two places + own a selection's heap. One view never parks: the single client pays + `views.several` (an AND and a compare) in the pump, the step's sync and an + edit, and one store a key (`typedInto`). Rejected: a `*View` the core + reads through (every reference rewritten, an indirection on every + access); a twin pane per view (Zerox exists only for files, and a + terminal's pty is its pane's slot). +- **Where each piece of state went.** + - Each view's own (`views.fields`): the screen size and cell metrics; + the columns, their weights, panes, serials, tags and the finder; rects; + `active`, `active_column` and the header focus; the jump list (kakoune's + is per client); the pointer, hover, drag, mouse grab, clicks and chords; + key prefixes (`"x` register name, leader, Ctrl-w, window pick); a + pending clipboard read; the presentation and the animations (lifts, + cursor glide); `windowed`, `native_images` and `native_image_patches`, + which the census had as watched host writes: a tty view on kitty and + one on a plain terminal differ. The 223 comptime platform branches stay + comptime: a session is one build, which the semantics hash says. + - Each pane's, each view's own (`PaneView`): `vweight`, `collapsed` and + `attached_to` (a layout's); `focus`; the body's mode, cursor, + selections, sticky column, pending normal command and find; a document's + scroll, `hscroll` and size; and what the step measured for that view + (`tag_rows`, `tag_top`, `tag_scroll`, `view`, `notices`), so a view drawn + without a step of its own draws its own geometry. + - The session's, every view's: the panes' text, undo, terminals and + their scroll (tmux shares a pane's copy mode too), tags (acme's are + per window; one tag per buffer is one text, its caret included), the + workspace tag, prompts, messages, registers (decided), the macro being + recorded, look-hover (one pointer at a time), mouse sweeps, query + panes, search state, settings and theme, the effect and input queues, + `needs_frame` (any change draws every view). +- **A terminal shown at two sizes** takes the size of the view that typed + into it last (`Pane.sized_by`, set by a key or a paste; a new pane's is + its maker's; a closed view's goes to the next to sync it). The others show + it at that size: `sync` resizes no pty for them, and `pane.cols/rows` + stay the terminal's own, so the terminal code's invariant (pane size is + the emulator's) holds. ponytail: a smaller view sees its top rows, cut; + panning to the cursor as tmux does is the upgrade, if a small view must + follow a shell it never types into. +- **Panes come and go under parked views.** A view keeps the serial of + each slot when it goes out; unparked, the ids whose serial changed leave + its layout and its keyboard moves to its first pane left. A pane focused + in a view that does not show it (a Look at a file another view opened, a + jump, a 9P focus) is placed in the view's active column (`views.show`, + kakoune's buffer shown in the window that asked). A text edited in one + view moves every other view's cursor and scroll with the splice, as a + Zerox twin's (`File.ParkedPlaces`); their selections go, as a twin's do. +- **Drawing the other views stays out of the digest.** The pump draws each + other view by unparking it, rendering and presenting, and restores the + live one exactly (`drawOthers`): no digested field moves, so the headless + replica, which draws nothing and skips it, agrees. What drawing a view + makes of its own (its animations, its presentation) is kept; what its + unpark normalised (a cursor clamped inside a changed text, a pruned + layout) is not, and is done again when it next goes live by an input, + in every replica alike. `parked` and `pv` are `.local`: a parked view is + checked when it is live again. Found by `pardes-monkey --views=3 --tape`: + a drawn view's `post_present` (acknowledgePanelPresentation, which moves + the pointer's hover) was applied by the headless replica to the live view; + other views take no post_present, their panels acknowledged when they + are live and drawn. +- **Inputs.** `toView`, `openView` and `closeView` are taped. A host goes + into a view before the input its client sent: the tty's terminal readers + post through a `Poster` that puts a `from` ahead of a terminal's input + whenever another terminal posted last (so one terminal posts none, and + coalesced motions never cross views); the GUI asks SDL which window an + event is for (`route`), which also takes a window's resize to its view + (the GUI sizes the live view from its window each frame). +- **The tty.** Each terminal is a `Screen` of its own: its vaxis, input + reader, frame answer (`FrameAck`, was global), kitty images and shm probe + (were global), glide, trail and flash, its stub and its Killed slot. The + primary's stub stays `daemon.stub`. A SIGWINCH asks every terminal its + size (attach stubs forward theirs; another view's terminal is no one's + controlling terminal); a SIGHUP asks each whether its terminal or stub's + pipe hung up, where it used to mean the one terminal. Detach, or a + terminal's end, with views left closes only that view and tells its stub + `d`; the session's end tells every stub. ponytail: a bracketed paste in + progress is the shell's, not a terminal's: keys from another terminal + during it join it. +- **The GUI.** One `Gui` (device, atlas, fonts, pipelines) and its + window's share swapped like the core's (`window_fields`: the SDL window + and its presenting, scroll and glide, scene and post chain, pointer, + blink, captures); `Shell.follow` keeps the Gui on the core's live view. + Closing a window while others stay closes its view; Restore closes the + others. ponytail: a second window's compositor hit test reads whichever + window's state is in the Gui (the workspace tag is in the same place in + every view). +- **The daemon.** `attach` names an attached session too: it takes another + view (a terminal, or a window). With no name, the detached sessions are + asked first, then the only session of that kind. +- **Harnesses, extended not new.** A snapshot script's `start ... views=N` + gives the app N-1 more ptys (PARDES_TEST_VIEWS, opened as attached ones + from the start), `view ` types into and captures terminal k, and every + wait reads all of them (a pty nobody reads would block the session's + frame); a `resize` there SIGWINCHes the app, as a stub would. + `pardes-monkey --views=N` switches among N terminals a quarter of its + steps, each with its own size; `zig build replay` runs its seeds at one + view and at three. The GUI's test feed takes `ESC]777;view;BEL`, and + PARDES_TEST_VIEWS=N opens N more hidden windows, captured under view-k. +- **What proved wrong in the design.** "Views" in the design were a + struct the core reads through; the swap made them cheaper and kept every + reference. Its rollback copy (phase 5) is the same list of fields. The + design's view-local state assumed a step per view; the step's + measurements (`tag_rows`, `notices`, the pane's geometry key) had to + become per view too, or a view drawn after another's step drew the + other's tag heights. And the census's single "frontend kind" leak is not + per process but per client: kitty graphics are a terminal's. + +Measured: PERF_TABLE + +Gates: GATES_TABLE + ## FreeBSD notes Groundwork for phase 5's main test, a client here and the session on the diff --git a/docs/typ/guide.typ b/docs/typ/guide.typ index 5dea0522..40802ed9 100644 --- a/docs/typ/guide.typ +++ b/docs/typ/guide.typ @@ -350,7 +350,11 @@ pardes-gui --attach=work a window session's window again leaves the session running, its panes, shells and files kept; so does a terminal that closes. `pardes --attach` takes it back in any terminal, `pardes-gui --attach` a window session's window: a terminal session takes -a terminal, a window session a window. A session is named by `--9p=` or +a terminal, a window session a window. Attached already, it takes another +view: each terminal or window has its own columns, focus, cursors and +scroll over the same panes, texts and registers, and a terminal shown in +two takes the size of the one that last typed into it. #word("Detach") in +one lets only that one go. A session is named by `--9p=` or `--detach=`, else its pid. A session killed outright leaves its shells running; #word("Adopt") in another takes them in as terminal panes, what they showed gone. One `pardes --daemon` per user keeps all of it, and diff --git a/docs/typ/reference.typ b/docs/typ/reference.typ index c95a574a..190adba7 100644 --- a/docs/typ/reference.typ +++ b/docs/typ/reference.typ @@ -1011,9 +1011,16 @@ to its end before the write is answered, and one that finds nothing fails, `--no-prefix` diff's paths are kept. - *Sessions.* Bare `--detach` names the session after its pid; bare `--attach` needs exactly one detached session of its kind (a terminal's - for `pardes`, a window's for `pardes-gui`); a second `--detach=NAME` + for `pardes`, a window's for `pardes-gui`), or with none detached the + only session of that kind; a second `--detach=NAME` while NAME runs (a plain session is named by its pid) says so in words - and exits 1. One terminal or window shows a session at a time. With none + and exits 1. A session attached already takes another view, up to four: + each terminal or window its own layout, focus, cursors, selections, + modes, scroll and jumps, over the panes, texts, tags, terminals, + messages and registers they share. A terminal pane shown in two takes the + size of the view that typed into it last; a smaller view shows its top + rows. #word("Detach"), or a terminal closing, lets that view go and + leaves the others. With none attached, `size C R` sets the screen, messages clear by the clock, and a pty reports its size in pixels at the last cell size (8×16 before any), as CSI 14, 16 and 18 t do. Attaching from another machine is gone until diff --git a/src/tty/tty.zig b/src/tty/tty.zig index f949d571..b56e74b1 100644 --- a/src/tty/tty.zig +++ b/src/tty/tty.zig @@ -1329,8 +1329,9 @@ const Screen = struct { /// Its terminal hung up, or the stub that waits on it is gone. fn hungUp(sc: *const Screen) bool { const stub = if (sc.primary) daemon.stub else sc.stub; + const handle = if (@TypeOf(sc.tty.fd) == std.Io.File) sc.tty.fd.handle else sc.tty.fd; var fds = [_]posix.pollfd{ - .{ .fd = sc.tty.fd.handle, .events = 0, .revents = 0 }, + .{ .fd = handle, .events = 0, .revents = 0 }, .{ .fd = stub, .events = 0, .revents = 0 }, }; _ = posix.poll(fds[0..if (stub >= 0) 2 else 1], 0) catch return false; -- cgit v1.3 From 32b80ad0393321d44f929e501e5515bbf6e51c12 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Thu, 29 Oct 2026 19:52:55 -0300 Subject: views: a terminal shown in a view shorter than it is passed down to its cursor, a shell's prompt never out of sight, an arrow in the gutter where rows are above; a name drafted in a tag is the view's that opened it A terminal takes the size of the view that typed into it last; a shorter view used to show its top rows, the prompt below them cut. It now passes over as many as keep the cursor's row in sight, as tmux pans a bigger window in a smaller client: `Pane.pan` (per view, derived) is made in the step's sync and again when a view is drawn out of turn (views.unpark), by terminal.panFor (0 in the view that sizes it, in one tall enough, or folded), and read where the body's rows start: `Pane.scroll`, the body walk in tty mode, the visible cursor. One view never pans: the view that sizes a terminal returns 0 at its first test. A `.name` prompt (a file's name drafted in its tag) is the view's that opened it (`Pane.prompt_view`): another view's step, where that pane has not the keyboard, no longer drops it; its view closing does. views-pan.snap: a shell sized for a 24-row view, its last lines and prompt in a 12-row one under the arrow, then typed into from the short view and sized for it. A unit test: the short view's frame has the cursor's row, and the line on it, inside the pane. docs: the notes, the reference. Co-Authored-By: Claude Opus 5.5 --- docs/next-daemon.md | 41 +++++++++++++++++++------------- docs/typ/reference.typ | 4 ++-- src/draw.zig | 3 +++ src/panes.zig | 11 +++++++-- src/pardes.zig | 11 +++++---- src/tagline.zig | 1 + src/terminal.zig | 24 ++++++++++++++++--- src/views.zig | 49 +++++++++++++++++++++++++++++++++++++- test/snapshots/views-pan.golden | 52 +++++++++++++++++++++++++++++++++++++++++ test/snapshots/views-pan.snap | 27 +++++++++++++++++++++ 10 files changed, 194 insertions(+), 29 deletions(-) create mode 100644 test/snapshots/views-pan.golden create mode 100644 test/snapshots/views-pan.snap (limited to 'docs/typ/reference.typ') diff --git a/docs/next-daemon.md b/docs/next-daemon.md index 3d4c8a08..e7ddcf5f 100644 --- a/docs/next-daemon.md +++ b/docs/next-daemon.md @@ -314,15 +314,23 @@ the ponytail lens: workspace tag, prompts, messages, registers (decided), the macro being recorded, look-hover (one pointer at a time), mouse sweeps, query panes, search state, settings and theme, the effect and input queues, - `needs_frame` (any change draws every view). + `needs_frame` (any change draws every view). A `.name` prompt (a + file's name drafted in its tag) is the view's that opened it + (`Pane.prompt_view`): only that view's focus leaving the pane drops it, + and its closing. - **A terminal shown at two sizes** takes the size of the view that typed into it last (`Pane.sized_by`, set by a key or a paste; a new pane's is its maker's; a closed view's goes to the next to sync it). The others show it at that size: `sync` resizes no pty for them, and `pane.cols/rows` stay the terminal's own, so the terminal code's invariant (pane size is - the emulator's) holds. ponytail: a smaller view sees its top rows, cut; - panning to the cursor as tmux does is the upgrade, if a small view must - follow a shell it never types into. + the emulator's) holds. A view shorter than the terminal is passed down + its top rows as far as keeps its cursor's row in sight, as tmux shows a + bigger window in a smaller client (`Pane.pan`, terminal.panFor: per view, + made in the step and again when a view is drawn out of turn, read where + the body's rows start, `Pane.scroll` and the body walk), an arrow in its + gutter's first row saying rows are above; a shell's prompt, at the + bottom, is never out of sight. ponytail: a panned view's mouse reports to + the terminal's program and its kitty images are placed as unpanned. - **Panes come and go under parked views.** A view keeps the serial of each slot when it goes out; unparked, the ids whose serial changed leave its layout and its keyboard moves to its first pane left. A pane focused @@ -390,8 +398,6 @@ the ponytail lens: named in a path yet (a script's focus or layout is that view's). - Every change draws every view (`needs_frame` is the session's); a view's own dirtiness waits for a measurement that wants it. - - Prompts are the pane's: a `.name` prompt drafted in one view is - closed by another view's step, where that pane has not the keyboard. - Dump, Restore and Handover keep one view, the live one. - **What proved wrong in the design.** "Views" in the design were a struct the core reads through; the swap made them cheaper and kept every @@ -433,21 +439,24 @@ Two views (not gated): every frame draws both, so a change costs two renders; a view switch copies ~60 fields and each pane's share, a few microseconds. -Gates, on the line rebased onto main's tty throughput fix (qzsouslm): +Gates, on the line rebased onto main's screen-state terminals (mnlwlpvk): -- `zig build replay -Dplatform=tty`: 112 snapshot scripts pass (the 110, - views.snap and views-term.snap), their 130 tapes replay in all three - replicas (390 runs, 29,355 digests); 20 monkey seeds at one view (60 - runs, 14,010 digests) and 20 at three views (60 runs, 9,720 digests); - no divergence, no panic. views.snap: 75 digests a replica, - views-term.snap 35. -- Unit tests: tty 1478 of 1498 pass, 20 skipped; GUI 1549 of 1560, 9 +- `zig build replay -Dplatform=tty`: 113 snapshot scripts pass (the 110, + views.snap, views-term.snap and views-pan.snap), their 131 tapes replay + in all three replicas (393 runs, 29,436 digests); 20 monkey seeds at one + view (60 runs, 14,004 digests) and 20 at three views (60 runs, 9,666 + digests); no divergence, no panic. views.snap: 75 digests a replica, + views-term.snap 35. core-test: 1117 of 1135, 18 skipped. +- Unit tests (on qzsouslm): tty 1478 of 1498 pass, 20 skipped; GUI 1549 of 1560, 9 skipped and 2 failed, the same two that fail on phase 1's line (`tagline pointer mapping retains physical grips...` and `a tag caret past its - row's end glides...`). The views' own: 7 (own cursor, scroll, mode, + row's end glides...`). The views' own: 8 (own cursor, scroll, mode, layout and focus; an edit and a register shared; a terminal sized by its last typist; views closing; the other views drawn leave the digest; a - view keeps its place in a text another edits). + view keeps its place in a text another edits; a short view keeps a tall + terminal's cursor in sight). views-pan.snap: a shell sized for the tall + view, its prompt and last lines in the short one under an arrow, then + typed into from the short one and sized for it. - test/fs.py passes (with a TMPDIR short enough for the 9P sockets' paths). test/daemon.py: 20 detach and attach cycles, then a second terminal on the attached session, both drawn, detached from inside and diff --git a/docs/typ/reference.typ b/docs/typ/reference.typ index 190adba7..ce2a45f1 100644 --- a/docs/typ/reference.typ +++ b/docs/typ/reference.typ @@ -1018,8 +1018,8 @@ to its end before the write is answered, and one that finds nothing fails, each terminal or window its own layout, focus, cursors, selections, modes, scroll and jumps, over the panes, texts, tags, terminals, messages and registers they share. A terminal pane shown in two takes the - size of the view that typed into it last; a smaller view shows its top - rows. #word("Detach"), or a terminal closing, lets that view go and + size of the view that typed into it last; a shorter view shows the + rows down to its cursor, an arrow in the gutter when rows are above. #word("Detach"), or a terminal closing, lets that view go and leaves the others. With none attached, `size C R` sets the screen, messages clear by the clock, and a pty reports its size in pixels at the last cell size (8×16 before any), diff --git a/src/draw.zig b/src/draw.zig index 4f9c6c87..0cc5c80d 100644 --- a/src/draw.zig +++ b/src/draw.zig @@ -958,6 +958,9 @@ fn renderPane(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r: } try body_layer.joinBody(p, s, arena, pane, r, id, active, rail.*); + // A terminal panned to its cursor in a view shorter than it: an arrow + // in the gutter's first body row says rows are above (views.zig). + if (pane.pan > 0) s.set(r.x, p.bodyTop(pane, r), "↑", .{ .fg = .{ .rgb = chrome.box } }); // A query's places' ticks, each in the track's cell of its row: chrome, // painted with the rail (a pixel shell draws its own from the same list). for (s.rail_ticks[0..s.nrail_ticks]) |tick| { diff --git a/src/panes.zig b/src/panes.zig index 71a04464..89f24eb6 100644 --- a/src/panes.zig +++ b/src/panes.zig @@ -30,7 +30,7 @@ pub const Pane = struct { /// the pane's opens and readers; the other views' share of it (views.zig). pub const replica = .{ .local = .{ "pv", "pv_known" }, - .derived = .{ "wrap_line", "wrap_col", "wrap_pad", "wrap_n", "body_wrapped", "context_rows", "body_rows", "body_visible_rows", "context_row_limit", "geometry_key", "geometry_len", "view", "notices" }, + .derived = .{ "wrap_line", "wrap_col", "wrap_pad", "wrap_n", "body_wrapped", "context_rows", "body_rows", "body_visible_rows", "context_row_limit", "geometry_key", "geometry_len", "view", "notices", "pan" }, .authority = .{"fs"}, .len = .{ .{ "msg", "msg_len" }, .{ "msg_older", "msg_older_len" }, .{ "question", "question_len" }, .{ "shell_tail", "shell_tail_len" }, .{ "sel_snap", "nsel_snap" } }, }; @@ -309,6 +309,13 @@ pub const Pane = struct { /// The view that last typed into it: a terminal shown at two sizes takes /// that view's (Pardes.sync). sized_by: u8 = 0, + /// A terminal shown in a view shorter than it (one that does not size + /// it): the rows its top is passed over by, so its cursor stays in + /// sight (terminal.panFor); 0 everywhere else. + pan: u16 = 0, + /// The view whose step a `.name` prompt is (tagline.draftName): only + /// that view's focus leaving the pane drops it. + prompt_view: u8 = 0, pub const MessagePhase = enum { entering, shown, lingering, leaving }; /// One message line's animation: falling in, shown, lingering after the @@ -543,7 +550,7 @@ pub const Pane = struct { pub fn scroll(pane: *Pane) i32 { if (pane.file) |f| return @intCast(f.scroll); if (comptime Pdf.enabled) if (pane.pdf) |pv| return @intCast(pv.text_scroll); - return pane.surfRow(terminal.gridOffset(pane)); + return pane.surfRow(terminal.gridOffset(pane) + pane.pan); } pub fn wrapAt(pane: *Pane, vr: i32) struct { line: i32, at: i32, pad: i32 = 0 } { diff --git a/src/pardes.zig b/src/pardes.zig index 59233347..75e91ee9 100644 --- a/src/pardes.zig +++ b/src/pardes.zig @@ -7729,7 +7729,7 @@ pub const Pardes = struct { // hands it back to its body, and a name drafted there is dropped. if (id != p.active or p.header_focus) { pane.focus = .body; - if (pane.prompt == .name) pane.closePrompt(); + if (pane.prompt == .name and pane.prompt_view == p.view) pane.closePrompt(); } // A sweep over the tag is the tag's while it has the keyboard. const swept = pane.sel[sel_slot]; @@ -7822,6 +7822,7 @@ pub const Pardes = struct { pane.rows = rows; if (pane.file) |*file| file.syntax_dirty = true; } + pane.pan = panes.terminal.panFor(p, pane, r); // A directory pane's entries follow its width, as acme's // columns do (Dir.fit). if (pane.file) |file| if (file.listing != null and r.h > pane.tag_rows) panes.Dir.fit(p, pane, pane.cols); @@ -7856,10 +7857,10 @@ pub const Pardes = struct { /// Whether the live view sizes terminal `pane`: a terminal shown at two /// sizes takes the size of the view that typed into it last, and any - /// view's once that one is gone. The others show it at that size. - // ponytail: a view smaller than the terminal shows its top rows, the - // rest cut; panning to its cursor, as tmux does, when a small view must - // follow a busy shell it never types into. + /// view's once that one is gone. The others show it at that size, a + /// shorter one passed down to its cursor (`Pane.pan`, terminal.panFor). + // ponytail: a panned view's pointer reports to a terminal's program and + // its kitty images are placed as the unpanned rows are. fn sizes(p: *Pardes, pane: *Pane) bool { if (pane.sized_by == p.view) return true; if (views.isOpen(p, pane.sized_by)) return false; diff --git a/src/tagline.zig b/src/tagline.zig index 79c2c09b..f669e98b 100644 --- a/src/tagline.zig +++ b/src/tagline.zig @@ -361,6 +361,7 @@ pub fn draftName(p: *Pardes, pane: *Pane, col: usize) void { const name = p.gpa.dupe(u8, f.path) catch return; pane.closePrompt(); pane.prompt = .name; + pane.prompt_view = p.view; pane.input = .{ .what = .input, .own = name, .mode = .insert, .cur_pinned = true, .cur_col = @intCast(@min(name.len, panes.File.rawAtDisplay(name, col))) }; } diff --git a/src/terminal.zig b/src/terminal.zig index 0afbe43a..e737a831 100644 --- a/src/terminal.zig +++ b/src/terminal.zig @@ -395,8 +395,26 @@ pub fn visibleCursor(pane: *const Pane) ?GridCursor { const cur = state.vt.screens.active.cursor; const sb = scrollbar(pane); const row = sb.total - sb.len + cur.y; - if (row < sb.offset or row - sb.offset >= sb.len) return null; - return .{ .x = @intCast(cur.x), .y = @intCast(row - sb.offset) }; + if (row < sb.offset + pane.pan or row - sb.offset >= sb.len) return null; + return .{ .x = @intCast(cur.x), .y = @intCast(row - sb.offset - pane.pan) }; +} + +/// The rows terminal `pane`'s top is passed over by in a view whose rect +/// `r` is shorter than it, one that does not size it (Pardes.sizes): as +/// many as keep its cursor's row in sight, as tmux pans a bigger window in +/// a smaller client. 0 in the view that sizes it, and in one tall enough. +pub fn panFor(p: *const Pardes, pane: *const Pane, r: pardes.Rect) u16 { + if (comptime !enabled) return 0; + if (pane.sized_by == p.view or pane.collapsed or !pane.isTerminal()) return 0; + const shown = r.h -| pane.tag_rows; + if (shown == 0 or shown >= pane.rows) return 0; + const state = pane.terminal orelse return 0; + const sb = scrollbar(pane); + // The cursor's row in the viewport; past its end (scrolled back), its + // last row. + const row = sb.total - sb.len + state.vt.screens.active.cursor.y; + const at: usize = if (row < sb.offset) 0 else @min(row - sb.offset, pane.rows - 1); + return @intCast(@min(pane.rows - shown, (at + 1) -| shown)); } /// Move the emulator's viewport by `delta` shell rows (negative scrolls back). @@ -1886,7 +1904,7 @@ const BodyWalk = struct { return .{ .pane = pane, .goff = goff, - .g = if (pane.body.mode == .tty) goff else pane.gridRow(off), + .g = if (pane.body.mode == .tty) goff + pane.pan else pane.gridRow(off), .skip = if (pane.ovl) |o| @intCast(@max(0, off - pane.surfRow(o.row))) else 0, }; } diff --git a/src/views.zig b/src/views.zig index e3ba5b4e..c847b987 100644 --- a/src/views.zig +++ b/src/views.zig @@ -53,7 +53,7 @@ pub const fields = [_][:0]const u8{ /// A pane's fields that are each view's own: where it is in the view's /// layout, which of its texts has the keyboard, how far it is scrolled, and /// what the view's step measured of it (its tag's rows, its bands). -const pane_fields = [_][:0]const u8{ "focus", "vweight", "collapsed", "attached_to", "hscroll", "tag_scroll", "tag_top", "tag_rows", "view", "notices" }; +const pane_fields = [_][:0]const u8{ "focus", "vweight", "collapsed", "attached_to", "hscroll", "tag_scroll", "tag_top", "tag_rows", "view", "notices", "pan" }; /// The body's: its cursor, selections and mode. Its undo stays the pane's. const body_fields = [_][:0]const u8{ "mode", "cur_pinned", "cur_row", "cur_col", "msel", "vsel", "sels", "nsel", "select", "sticky_col", "restore_cursor", "last_edit", "reg_wait", "normal", "find_op", "find_ch" }; @@ -72,6 +72,7 @@ pub const PaneView = struct { tag_rows: u16 = 1, view: Pane.SessionView = .{}, notices: Pane.Notices = .{}, + pan: u16 = 0, body: Part(Text, &body_fields) = .{}, /// A document's scroll and size; a terminal's size is its pty's, which /// every view shows (sized by its last typist, `Pardes.sync`). @@ -216,6 +217,10 @@ fn unpark(p: *Pardes, k: u8) void { }; } layout.compute(p); + // Its terminals' cursors moved while it was out: each pan follows. + for (p.panes, 0..) |s, id| if (s) |pane| { + pane.pan = pardes.panes.terminal.panFor(p, pane, p.rects[id]); + }; } /// The pane with the keyboard is one the live view shows: focused where its @@ -285,6 +290,8 @@ pub fn close(p: *Pardes, k: u8) void { if (sels.len > 0) p.gpa.free(sels); pane.pv[k].body.sels = &.{}; pane.pv_known &= ~(@as(u8, 1) << @intCast(k)); + // A name it was drafting goes with it. + if (pane.prompt == .name and pane.prompt_view == k) pane.closePrompt(); }; p.views_open &= ~(@as(u8, 1) << @intCast(k)); } @@ -555,3 +562,43 @@ test "a view not live keeps its place in a text another view edits" { try testing.expectEqual(scrolled + 3, pane.file.?.scroll); try testing.expect(std.mem.startsWith(u8, pardes.panes.File.sourceLine(pane, 103), "line 101")); } + +test "a terminal shown in a view shorter than it keeps its cursor in sight" { + const gpa = testing.allocator; + const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 80, .rows = 20 }); + defer p.deinit(); + const id = p.active; + const term = p.panes[id].?; + const k = p.openView().?; + p.toView(k); + p.update(.{ .resize = .{ .cols = 100, .rows = 50 } }); + p.update(.{ .key = .{ .cp = Key.right } }); + const rows = term.rows; + try testing.expect(rows > 30); + var out: std.ArrayList(u8) = .empty; + defer out.deinit(gpa); + for (1..rows) |i| try out.print(gpa, "row-{d}\r\n", .{i}); + try out.appendSlice(gpa, "LAST$ "); + p.update(.{ .output = .{ .pane = @intCast(id), .bytes = out.items } }); + // Sized for the tall view, it fits there whole: nothing is passed over. + try testing.expectEqual(@as(u16, 0), term.pan); + p.toView(0); + p.sync(); + try testing.expectEqual(rows, term.rows); + try testing.expect(term.pan > 0); + var arena: std.heap.ArenaAllocator = .init(gpa); + defer arena.deinit(); + const s = try p.render(arena.allocator()); + const r = p.rects[id]; + // The cursor's row, the last, is on screen in the short view, inside + // the pane, and so is the line it is on. + const cursor = s.cursor.?; + try testing.expect(cursor.y >= r.y and cursor.y < r.y + r.h); + var row_text: std.ArrayList(u8) = .empty; + defer row_text.deinit(gpa); + for (0..s.cols) |x| try row_text.appendSlice(gpa, s.cells[@as(usize, cursor.y) * s.cols + x].grapheme()); + try testing.expect(std.mem.indexOf(u8, row_text.items, "LAST$") != null); + // Back in the tall view, its top is where it was. + p.toView(k); + try testing.expectEqual(@as(u16, 0), term.pan); +} diff --git a/test/snapshots/views-pan.golden b/test/snapshots/views-pan.golden new file mode 100644 index 00000000..db63d29c --- /dev/null +++ b/test/snapshots/views-pan.golden @@ -0,0 +1,52 @@ +== snap tall grid=80x24 cursor=4,16 +| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +| New Tty Find Grep Joincol Delcol +|$ /tmp/pardes-snap/views-pan/cwd Tty+bash Save Mode Filter Collapse Del +| 18 +| 19 +| 20 +| 21 +| 22 +| 23 +| 24 +| 25 +| 26 +| 27 +| 28 +| 29 +| 30 +| $ +| /tmp/pardes-snap/views-pan/cwd/+New Save Tty Collapse Del +| 1 +== snap short-pans grid=60x12 cursor=4,8 +| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes +| New Tty Find Grep Joincol Delcol +|$ /tmp/pardes-snap/views-pan/cwd Tty+bash Save Mode Filter C +| ollapse Del +|↑ 27 +| 28 +| 29 +| 30 +| $ +| /tmp/pardes-snap/views-pan/cwd/+New Save Tty Collapse Del +| 1 +== snap short-typed grid=60x12 cursor=4,8 +|4: 29 +|5: 30 +|6: $ echo typed-in-short +|7: typed-in-short +== snap tall-sees grid=80x24 cursor=4,7 +|3: 29 +|4: 30 +|5: $ echo typed-in-short +|6: typed-in-short +|7: $ +|8: +|9: +|10: +|11: +|12: +|13: +|14: +|15: +|16: diff --git a/test/snapshots/views-pan.snap b/test/snapshots/views-pan.snap new file mode 100644 index 00000000..3ba1ac5b --- /dev/null +++ b/test/snapshots/views-pan.snap @@ -0,0 +1,27 @@ +# A terminal shown in a view shorter than it (src/views.zig): sized for the +# tall view that typed into it, the short one passes over its top rows so +# its cursor and prompt stay in sight, an arrow in the gutter saying rows +# are above. +config Verbose off +start 24 80 views=2 +wait 8000 $ +stable 700 20000 +view 2 +resize 12 60 +stable 500 10000 +view 1 +text seq 1 30 +key enter +wait 8000 30 +stable 500 10000 +snap tall +view 2 +stable 500 10000 +snap short-pans +text echo typed-in-short +key enter +stable 500 10000 +snap short-typed +view 1 +stable 500 10000 +snap tall-sees -- cgit v1.3 From 70de5ec5ff3dad01afcc45244ad5e5a481486da6 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Thu, 29 Oct 2026 17:01:35 -0300 Subject: dump: one walker dump of the whole session, by name across builds, for Restore, -l, Handover and the store; dump.zig's hand-written schema gone A dump is walk.zig's walk of the core with a table of every type it reaches (fields, enum and union names, number widths), read back by name; terminals are ghostty's snapshot (screens, history, kitty images); a failed load frees what it made. Co-Authored-By: Claude Opus 5.5 --- build.zig | 3 + build/snap.zig | 10 +- docs/typ/building.typ | 4 +- docs/typ/reference.typ | 35 +- src/File.zig | 387 --------------- src/Handover.zig | 112 +++-- src/Output.zig | 34 +- src/Pipe.zig | 4 + src/Query.zig | 9 +- src/Store.zig | 57 +-- src/builtins.zig | 2 +- src/dump.zig | 1176 +++++++++++----------------------------------- src/file_watch.zig | 57 +-- src/image.zig | 63 --- src/ninep/ctl.zig | 64 +-- src/ninep/events.zig | 24 +- src/panes.zig | 4 +- src/pardes.zig | 55 +-- src/pdf.zig | 4 +- src/pdf_view.zig | 14 + src/tagline.zig | 8 - src/tape.zig | 40 +- src/terminal.zig | 316 ++++++------- src/walk.zig | 1120 ++++++++++++++++++++++++++++++++++++++++++- test/fs.py | 5 +- test/fs_namespace.zig | 44 +- test/kitty.zig | 6 +- test/monkey.zig | 9 +- test/output.zig | 17 - test/panes.zig | 61 +-- test/pdf.zig | 39 -- test/snapshot.zig | 9 +- test/snapshots/dump.snap | 9 +- 33 files changed, 1851 insertions(+), 1950 deletions(-) (limited to 'docs/typ/reference.typ') diff --git a/build.zig b/build.zig index 1a5dd200..962b6322 100644 --- a/build.zig +++ b/build.zig @@ -1950,6 +1950,9 @@ pub fn build(b: *std.Build) void { run_shell_test.has_side_effects = true; unit_step.dependOn(&run_shell_test.step); if (unit_match) |check| check.addArtifactArg(shell_test); + // The native shell's tests alone, without the perf gate's + // ReleaseFast build: what a -Dtest-filter iteration wants. + b.step("shell-test", "run the native shell's unit tests (src/main.zig's)").dependOn(&run_shell_test.step); const run_profile = b.addRunArtifact(unit_profile); run_profile.addArtifactArg(shell_test); run_profile.addPassthruArgs(); diff --git a/build/snap.zig b/build/snap.zig index d74767d3..c1a26e64 100644 --- a/build/snap.zig +++ b/build/snap.zig @@ -69,19 +69,21 @@ pub fn addTty(b: *std.Build, opts: struct { // The replay-divergence gate (src/tape.zig, docs/next-daemon.md): every // snapshot script and `replay-seeds` monkey seeds with each session's // tape recorded, each replayed into two replicas at different - // addresses and one that never draws, every digest checked. + // addresses and one that never draws, every digest checked; and at each + // session's end its dump loaded, which must be that session, digest for + // digest, and dump again to the same bytes (phase 2). const tapes = ".zig-cache/tapes"; const run_replay = b.addRunArtifact(snap); run_replay.addArtifactArg(opts.exe); run_replay.addPrefixedFileArg("--lspmock=", lspmock.getEmittedBin()); - run_replay.addArg("--tape=" ++ tapes); + run_replay.addArgs(&.{ "--tape=" ++ tapes, "--dump" }); run_replay.setCwd(b.path(".")); run_replay.has_side_effects = true; const seeds = b.option(u32, "replay-seeds", "monkey seeds `zig build replay` records and replays (default 20)") orelse 20; const run_monkey_replay = b.addRunArtifact(monkey); run_monkey_replay.addArtifactArg(snap); run_monkey_replay.addArtifactArg(opts.exe); - run_monkey_replay.addArgs(&.{ b.fmt("{d}", .{seeds}), "70", "--tape=" ++ tapes ++ "/monkey", "--out=" ++ tapes ++ "/monkey" }); + run_monkey_replay.addArgs(&.{ b.fmt("{d}", .{seeds}), "70", "--tape=" ++ tapes ++ "/monkey", "--dump", "--out=" ++ tapes ++ "/monkey" }); run_monkey_replay.setCwd(b.path(".")); run_monkey_replay.has_side_effects = true; // One pardes-snap run at a time (its lock): the scripts, then the seeds. @@ -95,7 +97,7 @@ pub fn addTty(b: *std.Build, opts: struct { run_views_replay.setCwd(b.path(".")); run_views_replay.has_side_effects = true; run_views_replay.step.dependOn(&run_monkey_replay.step); - b.step("replay", "record every snapshot script's and -Dreplay-seeds monkey seeds' tapes (one terminal and three) and require each to replay without diverging").dependOn(&run_views_replay.step); + b.step("replay", "record every snapshot script's and -Dreplay-seeds monkey seeds' tapes (one terminal and three) and require each to replay without diverging, and each session's dump to load to its digest").dependOn(&run_views_replay.step); const monkey_tests = b.addTest(.{ .root_module = monkey.root_module }); b.step("monkey-test", "test the monkey's generator and panic detector").dependOn(&b.addRunArtifact(monkey_tests).step); const run_driver_test = b.addRunArtifact(snap); diff --git a/docs/typ/building.typ b/docs/typ/building.typ index 00088d7b..e42702c6 100644 --- a/docs/typ/building.typ +++ b/docs/typ/building.typ @@ -19,7 +19,7 @@ builds MuPDF and is on by default (`-Dmupdf=false` drops it). 9P over QUIC [`zig build`], [the terminal shell and the SDL window together, *installed into `~/.local/bin`* (`pardes`, `pardes-gui`, and `pardes-v9fs`, the #word("Tty9p") helper)], [`zig build -Dplatform=tty`], [the terminal shell alone], [`zig build -Dplatform=gui`], [the SDL3 window alone], - [`zig build web -Dplatform=web -Dtarget=wasm32-freestanding -Ddump=`], [a freestanding wasm core plus vanilla JavaScript (`docs/web.md`)], + [`zig build web -Dplatform=web -Dtarget=wasm32-freestanding -Ddump=`], [a freestanding wasm core plus vanilla JavaScript (`docs/web.md`)], [`zig build -Dplatform=macos`], [an AppKit and CoreText app over a static `libpardes.a` (`docs/macos.md`)], [`zig build -Dplatform=esp32p4`], [a freestanding riscv32 editor object for the ESP32-P4, with a 384 KiB heap], ) @@ -59,7 +59,7 @@ there; its namespace is in `src/esp32p4_gpio.zig`. [`-Dprebuilt-shaders`], [bool: embed the committed SPIR-V; on for a bare `zig build`, off with `-Dplatform`; `zig build shaders` refreshes it with glslc], [`-Dtracy`], [path to a Tracy checkout; off], [`-Dmacos-identity`], [codesigning identity for `pardes.app`; `-` (ad hoc)], - [`-Ddump`], [a `dump.zon` to embed in the web shell], + [`-Ddump`], [a Dump to embed in the web shell], [`-Dtest-filter`], [run only tests whose name contains it; a filter that matches nothing fails], [`-Dtest-rebuild`], [bool: fresh Zig test compilation], [`-Dhelix-harness`], [reference executable for live differential tests; `HX_HARNESS`, else `hx-harness` on `PATH`], diff --git a/docs/typ/reference.typ b/docs/typ/reference.typ index ce2a45f1..2e395cc6 100644 --- a/docs/typ/reference.typ +++ b/docs/typ/reference.typ @@ -368,22 +368,20 @@ Writes take settings and session builtins (`scope = .session` in #word("Delcol") and a pane's `get` refuse the same way with their own word, except that #word("Delcol") opens no `+Unsaved` pane: it names the panes only in its `unsaved` records and its notice. -- #word("Dump") writes `pardes--