summaryrefslogtreecommitdiff
path: root/src/pardes.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-10-29 17:01:35 -0300
committerGabriel Schneider <[email protected]>2026-10-29 19:38:53 -0300
commit2cce341e2c94fb3150dc1f3e7911c26502a70487 (patch)
treec637fcfa9a52aa66f6c34600f4cdea4020088e01 /src/pardes.zig
parentc2b4f235e78735102c691677f08bd1b2403168df (diff)
downloadpardes-2cce341e2c94fb3150dc1f3e7911c26502a70487.tar.gz
pardes-2cce341e2c94fb3150dc1f3e7911c26502a70487.zip
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 <rows> <cols> views=N` in a snapshot script gives the app N-1 more terminals (PARDES_TEST_VIEWS, opened as attached ones), `view <k>` 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 <[email protected]>
Diffstat (limited to 'src/pardes.zig')
-rw-r--r--src/pardes.zig70
1 files changed, 68 insertions, 2 deletions
diff --git a/src/pardes.zig b/src/pardes.zig
index 228d97fa..88d75fd1 100644
--- a/src/pardes.zig
+++ b/src/pardes.zig
@@ -64,6 +64,7 @@ pub const memory = @import("memory.zig");
pub const tape = @import("tape.zig");
pub const walk = @import("walk.zig");
pub const screen_state = if (terminal_panes) @import("screen_state.zig") else struct {};
+pub const views = @import("views.zig");
pub const image = @import("image.zig");
pub const dump = @import("dump.zig");
pub const lsp = @import("lsp/lsp.zig");
@@ -511,6 +512,7 @@ test {
_ = @import("Handover.zig");
_ = @import("walk.zig");
_ = screen_state;
+ _ = @import("views.zig");
}
pub const Builtin = builtins.registry.Builtin();
@@ -4699,6 +4701,12 @@ pub const Pardes = struct {
restore_buf: [1024]u8 = undefined,
surface: Surface = .{},
+ /// The view the fields above are of: whose layout, focus, pointer and
+ /// panes' cursors and scroll (views.zig). `views_open` says which views
+ /// there are, one a window or terminal; each not live is in `parked`.
+ view: u8 = 0,
+ views_open: u8 = 1,
+ parked: [views.max]?*views.Parked = @splat(null),
/// per-update scratch (paneCursorLines, selection text); reset each update
scratch: std.heap.ArenaAllocator,
/// The arena each frame's Surface text is built in, reset by `pump`. Hosts
@@ -4725,6 +4733,9 @@ pub const Pardes = struct {
// Drained by every pump before its digest; a replica's queues
// are its own.
"effects", "in_q",
+ // The views not live: written whenever one goes out, so the
+ // live one's slot is stale (views.zig).
+ "parked",
},
.derived = .{ "shell_rows", "diff_output", "locations_cache", "retired_panes", "tty_filter_palette", "body_chrome" },
// The host's handles, the 9P server's fids and log, the store file
@@ -5020,6 +5031,7 @@ pub const Pardes = struct {
slot.* = null;
};
const gpa = p.gpa;
+ views.deinit(p);
for (&p.col_tags) |*t| t.deinit(gpa);
p.global_tag.deinit(gpa);
p.registers.deinit(gpa);
@@ -5167,6 +5179,7 @@ pub const Pardes = struct {
if (comptime pdf_enabled) if (pane.pdf) |*pv| panes.Pdf.deinitPane(p, pane, pv);
if (pane.file) |*file| panes.File.deinit(p, pane, file);
if (pane.ovl) |o| p.gpa.free(o.text);
+ views.tornDown(p, pane);
pane.body.deinit(p.gpa);
pane.tag.deinit(p.gpa);
pane.input.deinit(p.gpa);
@@ -5201,6 +5214,7 @@ pub const Pardes = struct {
pane.serial = p.next_serial;
p.rects[id] = .{};
p.panes[id] = pane;
+ views.installed(p, pane);
panes.terminal.adoptSettings(p, pane);
// /log hears of it once the update that made it ends, when it has
// its file, name and place (`ctlfs.events.announce`).
@@ -5569,6 +5583,33 @@ pub const Pardes = struct {
/// Something changed the core without going through `update` -- a watched
/// file reloading under it, a theme file rewritten on disk. `pump` draws
/// only when it has a reason to, and this is the reason.
+ /// A view of its own for a new client (a second window, a terminal
+ /// `pardes --attach`ed), as the live one is laid out; null at
+ /// views.max. Not live until `toView`.
+ pub fn openView(p: *Pardes) ?u8 {
+ const taped = tape.enter(p, .open_view);
+ defer tape.leave(p, taped);
+ p.needs_frame = true;
+ return views.open(p);
+ }
+
+ /// The client of view `k` gone: its view goes, the others stay. The
+ /// last one stays the session's own.
+ pub fn closeView(p: *Pardes, k: u8) void {
+ const taped = tape.enter(p, .{ .close_view = k });
+ defer tape.leave(p, taped);
+ views.close(p, k);
+ p.sync();
+ }
+
+ /// Into view `k`, before the input its client sent.
+ pub fn toView(p: *Pardes, k: u8) void {
+ if (k == p.view) return;
+ const taped = tape.enter(p, .{ .to_view = k });
+ defer tape.leave(p, taped);
+ views.to(p, k);
+ }
+
pub fn invalidate(p: *Pardes) void {
const taped = tape.enter(p, .invalidate);
defer tape.leave(p, taped);
@@ -6053,6 +6094,8 @@ pub const Pardes = struct {
// A pty streaming into an unwatched session spent most of its time
// drawing what nobody looked at.
if (v.watched) |f| if (!f(h.ctx)) return;
+ // The other views first, each into its own window or terminal.
+ if (views.several(p)) try views.drawOthers(p, h);
_ = p.frame_arena.reset(.{ .retain_with_limit = memory.limits.frame_kept });
p.frames.mark_update = FrameStats.nowNs();
p.frames.view = if (p.panes[p.active]) |pane| pane.scroll() else 0;
@@ -6235,6 +6278,7 @@ pub const Pardes = struct {
.key => |key| {
p.can_ask = true;
defer p.can_ask = false;
+ p.typedInto();
p.handleKey(key);
},
.mouse => |m| {
@@ -6254,7 +6298,10 @@ pub const Pardes = struct {
}
}
},
- .paste => |bytes| edit.applyPaste(p, bytes),
+ .paste => |bytes| {
+ p.typedInto();
+ edit.applyPaste(p, bytes);
+ },
.command => |line| _ = p.executeBuiltinLine(p.active, line),
.pinch => |scale| p.ov_pinch_scale = scale,
.touch_scroll => |delta| p.ov_touch_scroll_delta = delta,
@@ -7672,6 +7719,7 @@ pub const Pardes = struct {
tagline.exitHeader(p);
}
p.reapPanes();
+ if (views.several(p)) views.show(p);
layout.compute(p);
p.presentation.sync(p);
p.trackJump();
@@ -7759,7 +7807,9 @@ pub const Pardes = struct {
// A terminal's pty follows its pane down to a row, whatever the
// resize; only a folded one keeps the size it had, and one not
// placed yet the grid it was made with.
- if ((cols != pane.cols or rows != pane.rows) and (r.h > pane.tag_rows or (pane.isTerminal() and !pane.collapsed and r.h > 0))) {
+ if ((cols != pane.cols or rows != pane.rows) and (r.h > pane.tag_rows or (pane.isTerminal() and !pane.collapsed and r.h > 0)) and
+ (!pane.isTerminal() or p.sizes(pane)))
+ {
// doc panes have no pty/emulator grid to reflow; just record
// the size so bodyText renders the right number of rows
if (pane.isTerminal()) {
@@ -7798,6 +7848,22 @@ pub const Pardes = struct {
tagline.revealHeader(p);
}
+ /// The view typing goes into is the one its terminal is sized for
+ /// (`sizes`).
+ fn typedInto(p: *Pardes) void {
+ if (p.panes[p.active]) |pane| pane.sized_by = p.view;
+ }
+
+ /// 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.
+ fn sizes(p: *Pardes, pane: *Pane) bool {
+ if (pane.sized_by == p.view) return true;
+ if (views.isOpen(p, pane.sized_by)) return false;
+ pane.sized_by = p.view;
+ return true;
+ }
+
pub fn theme(p: *const Pardes) *const Theme {
if (p.custom_theme) |*custom| return custom;
return &themes[p.settings.theme];