summaryrefslogtreecommitdiff
path: root/src/pardes.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/pardes.zig')
-rw-r--r--src/pardes.zig75
1 files changed, 58 insertions, 17 deletions
diff --git a/src/pardes.zig b/src/pardes.zig
index f0d2cd0c..36ce6bdb 100644
--- a/src/pardes.zig
+++ b/src/pardes.zig
@@ -857,7 +857,7 @@ test "Togglettymode builtin and keyboard chord share mode transitions including
try std.testing.expectEqual(Text.Mode.tty, pane.body.mode);
try std.testing.expect(p.executeBuiltinLine(0, "Togglettymode"));
try std.testing.expectEqual(Text.Mode.normal, pane.body.mode);
- p.update(.{ .key = .{ .cp = p.opts.tty_toggle, .ctrl = true } });
+ p.update(.{ .key = .{ .cp = p.tty_toggle, .ctrl = true } });
try std.testing.expectEqual(Text.Mode.tty, pane.body.mode);
// The tag has its own mode: the body keeps tty while the tag is typed into.
tagline.enterTag(p, pane);
@@ -867,7 +867,7 @@ test "Togglettymode builtin and keyboard chord share mode transitions including
try std.testing.expectEqual(Text.Mode.normal, pane.body.mode);
try std.testing.expect(pane.focus == .body);
tagline.enterTag(p, pane);
- p.update(.{ .key = .{ .cp = p.opts.tty_toggle, .ctrl = true } });
+ p.update(.{ .key = .{ .cp = p.tty_toggle, .ctrl = true } });
try std.testing.expectEqual(Text.Mode.tty, pane.body.mode);
try std.testing.expect(pane.focus == .body);
@@ -4732,6 +4732,10 @@ pub const Pardes = struct {
/// The views no frontend here draws: a replica client's, which its own
/// process draws (src/replica.zig). A pump skips them.
undrawn: u8 = 0,
+ /// The Ctrl key into a terminal's tty mode and out (`--tty-toggle`): the
+ /// session's, taken from its options when it is made, so a dump carries
+ /// it to a replica, whose own options are its process's.
+ tty_toggle: u21 = config.tty_toggle_default,
/// 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
@@ -4797,6 +4801,7 @@ pub const Pardes = struct {
.tree_sitter_gpa = opts.tree_sitter_allocator orelse gpa,
.opts = opts,
.windowed = opts.windowed,
+ .tty_toggle = opts.tty_toggle,
.col_tags = @splat(.{ .what = .column, .gpa = gpa }),
.global_tag = .{ .what = .workspace, .gpa = gpa },
.fs = .{},
@@ -4989,7 +4994,10 @@ pub const Pardes = struct {
/// Recent keeps it.
fn noteClosed(p: *Pardes, pane: *const Pane) void {
const d = recentPlace(pane) orelse return;
- if (p.recent.get(d.path) == null and !recentKeeps(d.path)) return;
+ // The host asked first, always: what Recent holds is the
+ // authority's, and a step that asked only when it did not know the
+ // file would ask on one side and not the other.
+ if (!recentKeeps(d.path) and p.recent.get(d.path) == null) return;
p.recent.closedSel(p.recentGpa(), d.path, d.line, d.col, d.aline, d.acol);
}
@@ -5024,9 +5032,38 @@ pub const Pardes = struct {
};
}
- /// The recent entry a closed jump names, by its path's hash.
- pub fn recentByHash(p: *const Pardes, hash: u64) ?recent_files.Entry {
- for (p.recent.entries.items) |e| if (std.hash.Wyhash.hash(0, e.path) == hash) return e;
+ /// The session's configuration directory and startup file, as a step
+ /// reads them: its process's options, so the authority's
+ /// (`tape.authority`); a replica's are its own process's.
+ pub fn configDir(p: *Pardes) ?[]const u8 {
+ return tape.authority(optsConfigDir, .{p});
+ }
+
+ pub fn startupPath(p: *Pardes) ?[]const u8 {
+ return tape.authority(optsStartupPath, .{p});
+ }
+
+ fn optsConfigDir(p: *Pardes) ?[]const u8 {
+ return p.opts.config_dir;
+ }
+
+ fn optsStartupPath(p: *Pardes) ?[]const u8 {
+ return p.opts.startup_config_path;
+ }
+
+ /// The recent entry a closed jump names, by its path's hash, its path
+ /// in scratch. Recent is the authority's (every window of its user
+ /// writes it): a replica has its answer (`tape.authority`).
+ pub fn recentByHash(p: *Pardes, hash: u64) ?recent_files.Entry {
+ return tape.authority(recentFound, .{ p, hash });
+ }
+
+ fn recentFound(p: *Pardes, hash: u64) ?recent_files.Entry {
+ for (p.recent.entries.items) |e| if (std.hash.Wyhash.hash(0, e.path) == hash) {
+ var found = e;
+ found.path = p.scratch.allocator().dupe(u8, e.path) catch return null;
+ return found;
+ };
return null;
}
@@ -6607,7 +6644,7 @@ pub const Pardes = struct {
if (header == null and pane.isTerminal() and pane.body.mode == .tty and pane.focus == .body and pane.prompt == .none) {
p.leader_on = false;
p.ctrl_w_pending = false;
- if (key.ctrl and !key.alt and key.cp == p.opts.tty_toggle)
+ if (key.ctrl and !key.alt and key.cp == p.tty_toggle)
return p.toggleTty(p.active);
// With ProgramEsc on, bare Escape leaves only at a shell prompt
// (Shift-Esc, above, always).
@@ -6672,7 +6709,7 @@ pub const Pardes = struct {
}
return;
}
- const tty_toggle = key.ctrl and key.cp == p.opts.tty_toggle;
+ const tty_toggle = key.ctrl and key.cp == p.tty_toggle;
if (pane.isTerminal() and tty_toggle) {
return p.toggleTty(p.active);
}
@@ -7624,10 +7661,12 @@ pub const Pardes = struct {
if (i == p.jcur) cur = w; // survives -> lands at w; dies -> the next one does
var kept = j;
const live = if (j.serial == 0) false else if (p.panes[j.pane]) |pane| pane.serial == j.serial else false;
- // A file's pane closed: its entry stays, closed, while the recent
- // list knows the file, and a jump to it opens it again.
+ // A file's pane closed: its entry stays, closed, and a jump to it
+ // opens it again from Recent, or drops it when Recent has
+ // forgotten it (`jumpBy`: Recent is the authority's, read when
+ // it is wanted, not at every step).
if (!live) {
- if (j.path_hash == 0 or p.recentByHash(j.path_hash) == null) continue;
+ if (j.path_hash == 0) continue;
kept.serial = 0;
// Open again in some pane (a look, Recent): the entry is that
// pane's, and closed only while no pane has the file.
@@ -7727,12 +7766,13 @@ pub const Pardes = struct {
// A closed file's entry: opened again at its dot, placed as a look
// places it, and the entry is that pane from here on.
if (j.serial == 0) {
- const e = p.recentByHash(j.path_hash) orelse return;
- // Deleted since: its entries go, it is said, and the step goes
- // on to the next place, never stuck on one that cannot open.
- if (!recentKeeps(e.path)) {
+ const found = p.recentByHash(j.path_hash);
+ // Deleted since, or Recent has forgotten it: its entries go (the
+ // first said), and the step goes on to the next place, never
+ // stuck on one that cannot open.
+ if (found == null or !recentKeeps(found.?.path)) {
var said: [recent_path_cap + 32]u8 = undefined;
- p.setMessage(p.active, std.fmt.bufPrint(&said, "{s}: deleted, skipped", .{e.path}) catch "deleted, skipped");
+ if (found) |e| p.setMessage(p.active, std.fmt.bufPrint(&said, "{s}: deleted, skipped", .{e.path}) catch "deleted, skipped");
const hash = j.path_hash;
var w: usize = 0;
var cur = p.jcur;
@@ -7750,6 +7790,7 @@ pub const Pardes = struct {
// round takes one file's entries away, so it ends.
return p.jumpBy(delta);
}
+ const e = found.?;
const from = p.active;
look.reopenAt(p, from, e.path, .{ .line = @max(1, j.line), .col = if (j.pdf) 0 else @max(1, j.col) });
const opened = p.panes[p.active] orelse return;
@@ -9284,7 +9325,7 @@ test "raw tty forwards Ctrl letters and former global shortcuts to the child" {
_ = drainWrites(p, &buf);
edit.setYank(p, "register text");
for ('a'..'z' + 1) |letter| {
- if (letter == p.opts.tty_toggle) continue; // editor/TTY mode shortcut
+ if (letter == p.tty_toggle) continue; // editor/TTY mode shortcut
if (letter == 'v') continue; // the window's paste, asserted just below
p.update(.{ .key = .{ .cp = @intCast(letter), .ctrl = true } });
const expected = [_]u8{@intCast(letter - 'a' + 1)};