From 2cce341e2c94fb3150dc1f3e7911c26502a70487 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Thu, 29 Oct 2026 17:01:35 -0300 Subject: views: several clients on one session, each its own layout, focus, cursors and scroll over the panes they share; a second `pardes --attach` draws on its own terminal beside the first, and `pardes-gui --attach` opens another window The core still sees one view, the live one, in the fields it always had (src/views.zig): a view's share of the session (`views.fields`: its screen, columns, rects, focus, pointer and gestures, jumps, key prefixes, column tags, presentation and animations, windowed and native_images) and of each pane (`PaneView`: its place in the layout, which text has the keyboard, the body's cursor, selections and mode, its scroll, a document's size, what the step measured of it) is copied out when another view goes live and back when it is live again. One view never parks: the single client pays a test of one byte a step. `toView`, `openView` and `closeView` are taped inputs; the pump draws each other view by going into it and back, which leaves every digested field as it was, so the replica that draws nothing skips it. A parked view is in no digest (its slot is written whenever it goes out); what drawing it made of its own (animations, presentation) is kept, whatever its unpark brought inside a changed text is done again when it is next live. Shared: the panes' text, terminals, tags, prompts, messages, registers (yanked in one view, put in another), the workspace tag and settings. A terminal shown at two sizes takes the size of the view that typed into it last (`Pane.sized_by`), and any view's once that one is gone; the others show it at that size. A text edited in one view moves the other views' cursors and scroll with the splice, as a Zerox twin's (File.ParkedPlaces). A pane closed in one view leaves the others' layouts (by its slot's serial); a pane focused in a view that does not show it is placed in its active column (views.show). tty: each terminal is a Screen of its own (its vaxis, input reader, frame answer, kitty images and shm probe, glide, trail and flash); its input reaches the loop as its view's (a `from` ahead of it when another terminal posted last, so one terminal posts none). A SIGWINCH asks every terminal its size; a SIGHUP asks each whether it hung up or lost its stub. Detach, or a terminal's end, with other views left closes only that view, its stub told `d`; the session's end tells every stub. daemon.zig: an attach names an attached session too (or the only one there is when none is detached). gui: the Gui holds the live window's share of itself (window_fields: the SDL window and its presenting, scroll, glide, scene and post chain, pointer, blink, captures); the others wait in Shell.windows, swapped in (`follow`) as the core's live view changes, and each SDL event first takes its window's view live (`route`). Closing a window while others stay closes its view. Harnesses: `start views=N` in a snapshot script gives the app N-1 more terminals (PARDES_TEST_VIEWS, opened as attached ones), `view ` types into and captures terminal k, every wait reads them all; `pardes-monkey --views=N` switches among N; `zig build replay` runs its seeds at three views too. views.snap pins two terminals: an edit seen in both, a scroll in one, a line yanked in one and put in the other, Newcol in one, Detach in one. Unit tests: own cursor, scroll, mode, layout and focus; edits shared; registers shared; terminal size by last typist; closing views; drawing the others leaves the digest; a view keeps its place in a text another edits. Co-Authored-By: Claude Opus 5.5 --- src/File.zig | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) (limited to 'src/File.zig') diff --git a/src/File.zig b/src/File.zig index d795eaa1..dd6b2d34 100644 --- a/src/File.zig +++ b/src/File.zig @@ -1208,7 +1208,12 @@ pub fn setContentSpan(p: *Pardes, f: *State, new: []u8, span_in: ?Span) void { // the caller did not say, is what the line index wants anyway. var twins: [pardes.MAX_PANES]usize = undefined; const ntwins = twinsOf(p, f, &twins); - const span: ?Span = span_in orelse if (ntwins > 0) spanOf(f.content, new) else null; + // The views not live keep their place in it as twins do (views.zig). + const viewed = pardes.views.several(p); + const span: ?Span = span_in orelse if (ntwins > 0 or viewed) spanOf(f.content, new) else null; + var parked: ParkedPlaces = .{}; + if (viewed) parked.before(p, f, span.?, new.len); + defer if (viewed) parked.after(p); var moved: [pardes.MAX_PANES]struct { cursor: usize, scroll: usize } = undefined; for (twins[0..ntwins], 0..) |id, i| { const t = p.panes[id].?; @@ -1301,6 +1306,50 @@ pub fn setContentSpan(p: *Pardes, f: *State, new: []u8, span_in: ?Span) void { } } +/// Each other view's cursor and scroll on a text being changed, as offsets +/// moved by the splice (`spliced`), put back as places in the new text once +/// it is in: a view not live keeps its place, as a twin does. Its +/// selections go, as a twin's do. +const ParkedPlaces = struct { + const max = pardes.MAX_PANES * pardes.views.max; + at: [max]struct { pane: *Pane, view: u8, cursor: usize, scroll: usize } = undefined, + n: usize = 0, + + fn before(pp: *ParkedPlaces, p: *Pardes, f: *State, span: Span, new_len: usize) void { + for (p.panes) |slot| { + const pane = slot orelse continue; + const tf = if (pane.file) |*file| file else continue; + if (tf != f and (f.twin == 0 or tf.twin != f.twin)) continue; + for (0..pardes.views.max) |k| { + if (k == p.view or !pardes.views.isOpen(p, @intCast(k)) or pp.n == max) continue; + const v = &pane.pv[k]; + const at = lineStart(p.gpa, tf, @intCast(@max(0, v.body.cur_row))) + @as(usize, @intCast(@max(0, v.body.cur_col))); + pp.at[pp.n] = .{ + .pane = pane, + .view = @intCast(k), + .cursor = spliced(@min(at, f.content.len), f.content.len, new_len, span), + .scroll = spliced(@min(lineStart(p.gpa, tf, v.scroll), f.content.len), f.content.len, new_len, span), + }; + pp.n += 1; + } + } + } + + fn after(pp: *ParkedPlaces, p: *Pardes) void { + for (pp.at[0..pp.n]) |a| { + const tf = &(a.pane.file orelse continue); + const v = &a.pane.pv[a.view]; + const cursor = positionIn(p.gpa, tf, @min(a.cursor, tf.content.len)); + v.body.cur_row = @intCast(cursor.row); + v.body.cur_col = @intCast(cursor.col); + v.body.vsel.active = false; + v.body.msel.active = false; + v.body.nsel = 0; + v.scroll = positionIn(p.gpa, tf, @min(a.scroll, tf.content.len)).row; + } + } +}; + /// Where an offset into the old text is in the new, after the splice that /// kept `span` at either end: past it, moved by what it added; inside it, /// at its start, as acme moves a clone's q0 (textinsert, textdelete). -- cgit v1.3