diff options
| author | Gabriel Schneider <[email protected]> | 2026-10-31 06:28:48 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-10-31 06:28:48 -0300 |
| commit | a479792a1ab2b593642d7f648194bfa23ce01dba (patch) | |
| tree | 96ddee7d879a9084daa07db43b0b7910b072a785 /src/panes.zig | |
| parent | e179cc44fe5060c76a5b00c41e53f11209f5acd9 (diff) | |
| parent | 4c761893e5b3fdae422622cfa02104ab36633045 (diff) | |
| download | pardes-a479792a1ab2b593642d7f648194bfa23ce01dba.tar.gz pardes-a479792a1ab2b593642d7f648194bfa23ce01dba.zip | |
Merge the upstream daemon and replicated client/server refactor
Diffstat (limited to 'src/panes.zig')
| -rw-r--r-- | src/panes.zig | 57 |
1 files changed, 52 insertions, 5 deletions
diff --git a/src/panes.zig b/src/panes.zig index 51710d08..095e215f 100644 --- a/src/panes.zig +++ b/src/panes.zig @@ -1,6 +1,7 @@ const std = @import("std"); const vaxis = @import("vaxis"); const pardes = @import("pardes.zig"); +const views = @import("views.zig"); const layout = @import("layout.zig"); const config = @import("config.zig"); const Pardes = pardes.Pardes; @@ -8,7 +9,6 @@ const modal = @import("modal.zig"); const filesystem = @import("fs.zig"); const syntax = @import("syntax.zig"); const tracy = @import("tracy.zig"); -const dump = @import("dump.zig"); const limits = @import("memory.zig").limits; const builtins = @import("builtins.zig"); const effect_sources = @import("effect_sources.zig"); @@ -24,6 +24,18 @@ const Key = pardes.Key; pub const EditText = struct { text: []u8, row0: i32 }; pub const Pane = struct { + /// What the replay digest leaves out (src/walk.zig): the view's geometry, + /// made again from the rest (File.geometry); the 9P server's record of + /// 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", "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" } }, + // A picture's and a PDF's memory is their own allocators' (a dump + // loaded makes it there). + .alloc = .{ .{ "image", "image" }, .{ "pdf", "pdf" }, .{ "terminal", "terminal" } }, + }; /// The words that throw unsaved text away (builtins.zig warnModified). pub const Discarding = enum { Exit, Restore, get, Del, Delcol }; @@ -87,6 +99,7 @@ pub const Pane = struct { pub const Cwd = union(enum) { none, inherited: *Pane, owned: []u8 }; pub const Focus = enum { body, tag }; + pub const SessionView = struct { wrap: bool = true, layered: bool = true, body_h: u32 = 0, tagline_h: u32 = 0, rect_h: u16 = 0 }; terminal: ?*terminal.State = null, gpa: std.mem.Allocator, serial: u32 = 0, @@ -128,7 +141,12 @@ pub const Pane = struct { /// The last command line pardes typed into this terminal (an exec, a /// middle click, a pty/run): its first word, which Kill matches, and /// the shell's command count its start (C mark) reaches. - sent_command: ?struct { word: [64]u8 = undefined, len: u8 = 0, seq: u32 = 0 } = null, + sent_command: ?struct { + pub const replica = .{ .len = .{.{ "word", "len" }} }; + word: [64]u8 = undefined, + len: u8 = 0, + seq: u32 = 0, + } = null, /// A command pane (exec.zig runCommand): the line its child runs as /// `$SHELL -c`, owned, where an interactive terminal has null. command: ?[]u8 = null, @@ -245,6 +263,15 @@ pub const Pane = struct { body_rows: u16 = 0, body_visible_rows: u16 = 0, context_row_limit: ?u16 = null, + /// What the geometry above was made for (File.geometry), and the bytes + /// its text takes; 0 has it made again by whoever reads it next. + geometry_key: u64 = 0, + geometry_len: usize = 0, + /// The session's part of the geometry, as of the last step (`sync`). + /// Digested and dumped, not made again: a key's move reads it before its + /// step's `sync` (Text.halfPageMove's scroll), and a core loaded from a + /// dump has had none (Replica.initDump). + view: SessionView = .{}, sel: [3]Sel = @splat(.{}), pointer_selections: [3]?PointerSelection = @splat(null), next_pointer_selection: u64 = 0, @@ -278,6 +305,22 @@ pub const Pane = struct { /// body layer reserves exactly `len` rows for them, the way it already /// reserves rows for sticky context headers. notices: Notices = .{}, + /// Each other view's share of this pane, while it is not live + /// (views.zig): its cursor, scroll and place in that view's layout. + pv: [views.max]views.PaneView = undefined, + /// The views `pv` holds a share for (a pane retired before a view came + /// has none of it). + pv_known: u8 = 0, + /// 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 @@ -292,6 +335,7 @@ pub const Pane = struct { /// Older message lines kept on screen under a new one. pub const message_stack = 3; pub const OlderMessage = struct { + pub const replica = .{ .len = .{.{ "text", "len" }} }; text: [256]u8 = undefined, len: u16 = 0, life: MessageLife = .{}, @@ -511,10 +555,11 @@ 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 } { + File.geometry(pane); if (pane.wrap_n > 0 and vr >= 0 and vr < @as(i32, pane.wrap_n)) return .{ .line = pane.wrap_line[@intCast(vr)], .at = pane.wrap_col[@intCast(vr)], .pad = pane.wrap_pad[@intCast(vr)] }; // unwrapped: rows ARE lines, and the byte column a row starts at is the @@ -523,6 +568,7 @@ pub const Pane = struct { } pub fn wrapRow(pane: *Pane, line: i32, col: i32) struct { row: i32, at: i32, pad: i32 = 0 } { + File.geometry(pane); if (pane.wrap_n == 0) return .{ .row = line - pane.scroll(), .at = pane.hscroll }; var i: u16 = 0; while (i < pane.wrap_n) : (i += 1) { @@ -572,10 +618,11 @@ pub const Pane = struct { } pub fn ensureCursorVisible(pane: *Pane) void { + File.geometry(pane); const off = pane.scroll(); var in_context = false; - // Maps survive until the next render. A jump may have changed scroll - // already, so only treat an ancestor as pinned in the matching view. + // The map is the view's as it is now (File.geometry): an ancestor is + // pinned only in the view it was found for. if (pane.context_rows < pane.wrap_n and pane.wrap_line[pane.context_rows] == off) { for (pane.wrap_line[0..pane.context_rows]) |row| { if (row == pane.body.cur_row) { |
