summaryrefslogtreecommitdiff
path: root/src/pardes.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-10-22 09:50:43 -0300
committerGabriel Schneider <[email protected]>2026-10-22 10:03:24 -0300
commita8b457a306a4442975210bcac3f04b56513c61c3 (patch)
tree6e2026ecb15da2fb919a0202f5d8b38e3b36a595 /src/pardes.zig
parenta8a1499bdffffc5b6919e24ec957e92fabaf003b (diff)
parent7e9d2c4169245072265b483ffaa6aa05f23f08d3 (diff)
downloadpardes-a8b457a306a4442975210bcac3f04b56513c61c3.tar.gz
pardes-a8b457a306a4442975210bcac3f04b56513c61c3.zip
Merge: Def/Refs, the diff viewer, Helix n/N, Callstack, Zig 0.17, Window mode and the terminal cwd fix onto 0.24
The docs keep both sides: 0.24's Ctrl-i fallbacks and typed ls with this line's Window mode, raw Esc and Helix n/N wording. The CHANGELOG's unreleased entries go above 0.24, Def/Refs and the context rows among them. cheatsheet-a4.pdf rendered again; .scratch/ ignored. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'src/pardes.zig')
-rw-r--r--src/pardes.zig384
1 files changed, 328 insertions, 56 deletions
diff --git a/src/pardes.zig b/src/pardes.zig
index 2a74e441..aaa9d177 100644
--- a/src/pardes.zig
+++ b/src/pardes.zig
@@ -220,7 +220,6 @@ pub const Turn = struct {
while (t.lsp_answers == answers) t.settled.wait(t.io.?, &t.mutex) catch return;
}
-
pub fn awaitRestored(t: *Turn, restores: u64) void {
while (t.restores == restores) t.settled.wait(t.io.?, &t.mutex) catch return;
}
@@ -294,7 +293,7 @@ pub const MAX_JUMPS = 64;
pub const TOPBAR_H: u16 = 1;
pub const COLBAR_H: u16 = 1;
pub const BOX_H: u16 = 1;
-pub const TAG_GAP: u16 = 1;
+pub const TAG_GAP: u16 = 0;
pub const TAG_TEXT_INSET: u16 = config.GUTTER + TAG_GAP;
pub fn taglineBandOffset(row: u16, canvas_h: f32, cell_h: u32, tagline_h: u32) u32 {
@@ -480,6 +479,7 @@ pub const Loc = struct {
test {
_ = @import("tagline.zig");
+ _ = @import("hunks.zig");
_ = @import("builtins_json.zig");
_ = @import("exec.zig");
_ = @import("look.zig");
@@ -654,25 +654,25 @@ test "topbar hover highlights exactly the executable word" {
defer frame.deinit();
_ = try p.render(frame.allocator());
- p.update(.{ .mouse = .{ .button = .none, .kind = .motion, .col = 1, .row = 0 } });
+ p.update(.{ .mouse = .{ .button = .none, .kind = .motion, .col = TAG_TEXT_INSET + 1, .row = 0 } });
_ = frame.reset(.retain_capacity);
const hovered = try p.render(frame.allocator());
for (0.."Newcol".len) |col| {
- const cell = hovered.at(@intCast(col), 0);
+ const cell = hovered.at(TAG_TEXT_INSET + @as(u16, @intCast(col)), 0);
try std.testing.expectEqual(Color{ .rgb = p.theme().sel_bg }, cell.style.bg);
try std.testing.expectEqual(Color{ .rgb = p.theme().sel_fg }, cell.style.fg);
}
- try std.testing.expectEqual(Color{ .rgb = p.chromeTheme().tag_bg }, hovered.at(6, 0).style.bg);
+ try std.testing.expectEqual(Color{ .rgb = p.chromeTheme().tag_bg }, hovered.at(TAG_TEXT_INSET + 6, 0).style.bg);
- p.update(.{ .mouse = .{ .button = .none, .kind = .motion, .col = 6, .row = 0 } });
+ p.update(.{ .mouse = .{ .button = .none, .kind = .motion, .col = TAG_TEXT_INSET + 6, .row = 0 } });
_ = frame.reset(.retain_capacity);
const whitespace = try p.render(frame.allocator());
- try std.testing.expectEqual(Color{ .rgb = p.chromeTheme().tag_bg }, whitespace.at(1, 0).style.bg);
+ try std.testing.expectEqual(Color{ .rgb = p.chromeTheme().tag_bg }, whitespace.at(TAG_TEXT_INSET + 1, 0).style.bg);
p.update(.pointer_leave);
_ = frame.reset(.retain_capacity);
const left = try p.render(frame.allocator());
- try std.testing.expectEqual(Color{ .rgb = p.chromeTheme().tag_bg }, left.at(1, 0).style.bg);
+ try std.testing.expectEqual(Color{ .rgb = p.chromeTheme().tag_bg }, left.at(TAG_TEXT_INSET + 1, 0).style.bg);
}
test "pane-tag Exec prefers Tty and argument builtins before shell fallback" {
@@ -807,7 +807,7 @@ test "TreeContext tag style preserves message rows and its opt-out survives rest
if (comptime !syntax.enabled) return error.SkipZigTest;
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 60, .rows = 16 });
defer p.deinit();
- const pane = try p.setTestFile("pub const Box = struct {\n pub fn run() void {\n" ++ (" // body\n" ** 30) ++ " }\n};\n");
+ const pane = try p.setTestFile("pub const Box = struct {\n pub fn run() void {\n" ++ (std.mem.asBytes(&@as([30][16]u8, @splat(" // body\n".*)))) ++ " }\n};\n");
p.gpa.free(pane.file.?.path);
pane.file.?.path = try p.gpa.dupe(u8, "/test.zig");
if (!panes.File.supportsContext(pane)) return error.SkipZigTest;
@@ -864,7 +864,7 @@ test "TreeContext command and custom tag survive a workspace round trip" {
p.gpa.free(pane.file.?.path);
pane.file.?.path = path;
if (!panes.File.supportsContext(pane)) return error.SkipZigTest;
- try std.testing.expectEqualStrings(tagline.context_pane_tail, tagline.curTail(pane));
+ try std.testing.expectEqualStrings(if (lsp.speaks("/test.zig")) tagline.lsp_context_pane_tail else tagline.context_pane_tail, tagline.curTail(pane));
try std.testing.expect(!pane.file.?.tree_context);
try std.testing.expect(p.executeBuiltinLine(0, "TreeContext on"));
try std.testing.expect(pane.file.?.tree_context);
@@ -920,11 +920,11 @@ test "Togglettymode builtin and keyboard chord share mode transitions including
try std.testing.expectEqualStrings("unchanged\n", file.file.?.content);
}
-test "Filter is ordered after Del and toggles only its terminal pane" {
+test "Filter is ordered after Del and toggles only its terminal or +Pager pane" {
const testing = std.testing;
const del = std.meta.stringToEnum(Builtin, "Del") orelse return error.MissingDelBuiltin;
const filter = std.meta.stringToEnum(Builtin, "Filter") orelse return error.MissingFilterBuiltin;
- try testing.expectEqual(@intFromEnum(del) + 1, @intFromEnum(filter));
+ try testing.expectEqual(@backingInt(del) + 1, @backingInt(filter));
const p = try Pardes.init(testing.allocator, .{ .tty_only = true });
defer p.deinit();
@@ -954,6 +954,17 @@ test "Filter is ordered after Del and toggles only its terminal pane" {
try testing.expect(p.executeBuiltinLine(0, "Filter"));
try testing.expect(first.tty_filter);
try testing.expect(!second.tty_filter);
+
+ // A +Pager opens filtered, with Filter on its tag and no line numbers;
+ // a second is a pane of its own.
+ const pager_id = try panes.Output.openPager(p, 0, "/tmp");
+ const pager_pane = p.panes[pager_id].?;
+ try testing.expect(pager_pane.tty_filter);
+ try testing.expectEqualStrings(tagline.pager_pane_tail, tagline.curTail(pager_pane));
+ try testing.expectEqual(@as(u16, 0), panes.File.gutterWidth(pager_pane));
+ try testing.expect(p.executeBuiltinLine(pager_id, "Filter"));
+ try testing.expect(!pager_pane.tty_filter);
+ try testing.expect(try panes.Output.openPager(p, 0, "/tmp") != pager_id);
}
test "compact tag commands stay beside their own prefix across layout changes" {
@@ -1194,6 +1205,78 @@ test "Lspwhy after a Hover asks to explain that hover, in its file at its place,
try std.testing.expect(seen);
}
+test "Def and Refs are a speaking file's tag words; gd, gr and a 2-1 chord all run them" {
+ if (!lsp.supports.contains(.definition)) return error.SkipZigTest;
+ const p = try Pardes.init(std.testing.allocator, .{ .cols = 100, .rows = 24, .tty_only = true });
+ defer p.deinit();
+ const pane = try p.setTestFile("const alpha = 1;\nconst beta = alpha;\n");
+ // A .txt has no server: no Def, no Refs.
+ try std.testing.expect(std.mem.indexOf(u8, tagline.curTail(pane), "Def") == null);
+ const f = &pane.file.?;
+ p.gpa.free(f.path);
+ f.path = try p.gpa.dupe(u8, "/tmp/x.zig");
+ try std.testing.expect(std.mem.endsWith(u8, tagline.curTail(pane), " Def Refs Del"));
+ p.sync();
+ while (p.nextEffect()) |_| {}
+ const Asked = struct {
+ fn one(q: *Pardes, kind: lsp.Kind) !u32 {
+ var at: ?u32 = null;
+ while (q.nextEffect()) |e| if (e == .lsp) {
+ try std.testing.expectEqual(kind, e.lsp.kind);
+ try std.testing.expectEqualStrings("", e.lsp.arg.slice());
+ try std.testing.expect(at == null);
+ at = e.lsp.offset;
+ };
+ q.lsp_wait = null;
+ return at orelse error.NothingAsked;
+ }
+ };
+ // gd and gr: at the cursor, on `alpha`'s declaration.
+ pane.body.cur_row = 0;
+ pane.body.cur_col = 8;
+ p.update(.{ .key = .{ .cp = 'g' } });
+ p.update(.{ .key = .{ .cp = 'd' } });
+ try std.testing.expectEqual(@as(u32, 8), try Asked.one(p, .definition));
+ p.update(.{ .key = .{ .cp = 'g' } });
+ p.update(.{ .key = .{ .cp = 'r' } });
+ try std.testing.expectEqual(@as(u32, 8), try Asked.one(p, .references));
+ p.update(.{ .key = .{ .cp = 'g' } });
+ p.update(.{ .key = .{ .cp = 'c' } });
+ try std.testing.expectEqual(@as(u32, 8), try Asked.one(p, .callstack));
+
+ const r = p.rects[0];
+ const x0 = r.x + config.GUTTER + panes.File.gutterWidth(pane);
+ const use_y = p.bodyTop(pane, r) + 1;
+ // Copied out of the scratch arena, which each p.update resets.
+ const tag = try std.testing.allocator.dupe(u8, try tagline.tagText(p, p.scratch.allocator(), pane));
+ defer std.testing.allocator.free(tag);
+ for ([_]struct { word: []const u8, kind: lsp.Kind }{ .{ .word = " Def ", .kind = .definition }, .{ .word = " Refs", .kind = .references } }) |w| {
+ // B1 sweeps the use of `alpha` on the second line (bytes 30..35),
+ // leaving the cursor at its far end.
+ p.update(.{ .mouse = .{ .button = config.select_button, .kind = .press, .col = x0 + 13, .row = use_y } });
+ p.update(.{ .mouse = .{ .button = config.select_button, .kind = .drag, .col = x0 + 17, .row = use_y } });
+ p.update(.{ .mouse = .{ .button = config.select_button, .kind = .release, .col = x0 + 17, .row = use_y } });
+ // B2 on the tag word, B1 clicked while it is held: the sweep is its
+ // argument, and it asks at the start of `alpha`, not at the cursor.
+ const wx = r.x + TAG_TEXT_INSET + @as(u16, @intCast(std.mem.indexOf(u8, tag, w.word).? + 1));
+ p.update(.{ .mouse = .{ .button = config.exec_button, .kind = .press, .col = wx, .row = r.y } });
+ p.update(.{ .mouse = .{ .button = config.select_button, .kind = .press, .col = wx, .row = r.y } });
+ p.update(.{ .mouse = .{ .button = config.select_button, .kind = .release, .col = wx, .row = r.y } });
+ p.update(.{ .mouse = .{ .button = config.exec_button, .kind = .release, .col = wx, .row = r.y } });
+ try std.testing.expectEqual(@as(u32, 30), try Asked.one(p, w.kind));
+ // Clicked bare, it asks at the cursor, where the sweep left it.
+ pane.body.cur_row = 0;
+ pane.body.cur_col = 2;
+ p.update(.{ .mouse = .{ .button = config.exec_button, .kind = .press, .col = wx, .row = r.y } });
+ p.update(.{ .mouse = .{ .button = config.exec_button, .kind = .release, .col = wx, .row = r.y } });
+ try std.testing.expectEqual(@as(u32, 2), try Asked.one(p, w.kind));
+ }
+ // A symbol the file does not hold is said, and nothing is asked.
+ exec.runBuiltin(p, .Def, 0, "", "gamma");
+ try std.testing.expectError(error.NothingAsked, Asked.one(p, .definition));
+ try std.testing.expectEqualStrings("Def: no gamma in this file", pane.msg[0..pane.msg_len]);
+}
+
test "the Tutor pane is named +Tutor in the session's directory, never a bare path at the root" {
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true });
defer p.deinit();
@@ -1267,7 +1350,7 @@ test "acme placement: under a pane's text when it has many blank rows, else halv
try std.testing.expectEqual(text_end, p.rects[second].y);
// Fill both with text: no blank space is big, so the biggest pane is
// halved.
- const full = "x\n" ** 80;
+ const full = std.mem.asBytes(&@as([80][2]u8, @splat("x\n".*)));
for ([_]usize{ top, second }) |id| panes.File.setContent(p, &p.panes[id].?.file.?, try p.gpa.dupe(u8, full));
p.sync();
const big = if (p.rects[second].h >= p.rects[top].h) second else top;
@@ -1446,7 +1529,6 @@ test "unknown Exec from a document runs as a command pane in its directory, type
try std.testing.expect(spawned);
}
-
const FakeTtyQuery = struct {
taken: [MAX_PANES]bool = @splat(false),
asked: usize = 0,
@@ -1926,11 +2008,10 @@ test "a command pane shows how its command ended, and the next command there run
try std.testing.expectEqual(@as(usize, 0), Count.signals);
p.host = host_before;
// A command line longer than a command pane takes is refused.
- const long = "x" ** (exec.command_max + 1);
+ const long = &@as([exec.command_max + 1]u8, @splat('x'));
try std.testing.expectEqual(@as(?usize, null), exec.execute(p, 1, long));
}
-
test "image dump restores source bytes renderer choices and exact custom tail" {
const gpa = std.testing.allocator;
const p = try Pardes.init(gpa, .{ .tty_only = true });
@@ -1983,7 +2064,6 @@ test "image dump restores source bytes renderer choices and exact custom tail" {
try std.testing.expectEqualStrings(" Keep Del", redump.panes[0].tag_tail.?);
}
-
test "a Look on a directory does not type ls into an occupied terminal" {
const gpa = std.testing.allocator;
const p = try Pardes.init(gpa, .{ .cols = 100, .rows = 30 });
@@ -2892,9 +2972,9 @@ test "restored terminals keep monotonic nonzero pane identities" {
fn chordName(comptime c: config.Chord) []const u8 {
comptime {
const mods = (if (c.ctrl) "C-" else "") ++ (if (c.alt) "A-" else "") ++ (if (c.shift) "S-" else "");
- for (@typeInfo(Key).@"struct".decls) |d| {
- if (@TypeOf(@field(Key, d.name)) != u21) continue;
- if (@field(Key, d.name) == c.cp) return mods ++ d.name;
+ for (@typeInfo(Key).@"struct".decl_names) |d| {
+ if (@TypeOf(@field(Key, d)) != u21) continue;
+ if (@field(Key, d) == c.cp) return mods ++ d;
}
if (c.cp < 0x20 or c.cp > 0x7e) @compileError("chord has no name for the index");
return mods ++ &[_]u8{@as(u8, @intCast(c.cp))};
@@ -2903,9 +2983,7 @@ fn chordName(comptime c: config.Chord) []const u8 {
fn shortcutCount(comptime b: Builtin) comptime_int {
var count = 0;
- for (config.window_keys) |wk| if (wk.cmd == b) {
- count += 2;
- };
+ if (b == .Window) count += 1;
for (config.jump_keys) |jk| if (jk.cmd == b) {
count += 1;
};
@@ -2923,13 +3001,9 @@ fn shortcuts(comptime b: Builtin) []const u8 {
@setEvalBranchQuota(20000);
var parts: [shortcutCount(b)][]const u8 = undefined;
var part: usize = 0;
- for (config.window_keys) |wk| {
- if (wk.cmd != b) continue;
- // the prefix has one spelling and this is it
- const pfx = chordName(config.window_prefix[0]) ++ " ";
- parts[part] = pfx ++ chordName(wk.letter);
- parts[part + 1] = pfx ++ chordName(wk.arrow);
- part += 2;
+ if (b == .Window) {
+ parts[part] = chordName(config.window_prefix[0]);
+ part += 1;
}
for (config.jump_keys) |jk| {
if (jk.cmd == b) {
@@ -3010,11 +3084,11 @@ pub const builtin_rows: [std.enums.values(Builtin).len]Row = blk: {
for (std.enums.values(Builtin), 0..) |b, i| {
const keys = if (config.leader_path.get(b)) |path| leaderKeys(path) else "";
const rest = shortcuts(b);
- const named = @tagName(b) ++ (if (rest.len == 0) "" else (" " ** (namew - @tagName(b).len)) ++ " " ++ rest);
+ const named = @tagName(b) ++ (if (rest.len == 0) "" else (&@as([namew - @tagName(b).len]u8, @splat(' '))) ++ " " ++ rest);
rows[i] = .{
.path = config.leader_path.get(b),
.cmd = b,
- .line = keys ++ (" " ** (4 + keyw - keys.len)) ++ " " ++ named,
+ .line = keys ++ (&@as([4 + keyw - keys.len]u8, @splat(' '))) ++ " " ++ named,
};
}
const last = "\x7f";
@@ -3033,8 +3107,8 @@ comptime {
@setEvalBranchQuota(20000); // one branch per string byte, behind the decl walk that folds Builtin
var it = std.mem.tokenizeScalar(u8, config.topbar_str, ' ');
words: while (it.next()) |w| {
- for (@typeInfo(Builtin).@"enum".fields) |f|
- if (std.mem.eql(u8, f.name, w)) continue :words;
+ for (@typeInfo(Builtin).@"enum".field_names) |name|
+ if (std.mem.eql(u8, name, w)) continue :words;
@compileError("topbar word is not a builtin: " ++ w);
}
}
@@ -3228,8 +3302,8 @@ test "tabbed file aligns syntax cursor and mouse at the nearest insertion gap" {
const pane = try p.setTestFile("\treturn x\n");
const f = &pane.file.?;
f.highlights = try p.tree_sitter_gpa.alloc(u8, f.content.len);
- @memset(f.highlights, @intFromEnum(syntax.Syn.none));
- @memset(f.highlights[1..7], @intFromEnum(syntax.Syn.keyword));
+ @memset(f.highlights, @backingInt(syntax.Syn.none));
+ @memset(f.highlights[1..7], @backingInt(syntax.Syn.keyword));
f.syntax_dirty = false;
pane.body.cur_row = 0;
pane.body.cur_col = 1;
@@ -3295,9 +3369,9 @@ test "editable workspace and column tags are typed into and persist" {
p.acknowledgePanelPresentation(&.{});
try std.testing.expectEqual(TOPBAR_H + COLBAR_H, p.rects[0].y);
// a sweep over a header is its selection, the caret where it ended
- p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = 0, .row = 0 } });
- p.update(.{ .mouse = .{ .button = .left, .kind = .drag, .col = 6, .row = 0 } });
- p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = 6, .row = 0 } });
+ p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = TAG_TEXT_INSET, .row = 0 } });
+ p.update(.{ .mouse = .{ .button = .left, .kind = .drag, .col = TAG_TEXT_INSET + 6, .row = 0 } });
+ p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = TAG_TEXT_INSET + 6, .row = 0 } });
try std.testing.expect(p.global_tag.vsel.active and p.global_tag.vsel.col == 0 and p.global_tag.cur_col == 6);
p.update(.{ .key = .{ .cp = 'H', .text = " Help" } });
try std.testing.expect(std.mem.startsWith(u8, p.global_tag.own.?, "Newcol Help Joincol"));
@@ -3641,7 +3715,7 @@ pub fn hit(key: Key, binding: []const config.Chord) bool {
return false;
}
-pub const sel_slot = @intFromEnum(config.select_button);
+pub const sel_slot = @backingInt(config.select_button);
/// Pixel dimensions are meaningful only to the native PDF placement path.
/// Keep resize events layout-only when that path is not part of the build.
@@ -4421,7 +4495,7 @@ pub const Pardes = struct {
/// Panes made this step that found no room in their column
/// (exec.placeNew): closed at the step's end, once whatever made them
/// is done with them.
- unplaced: std.StaticBitSet(MAX_PANES) = .initEmpty(),
+ unplaced: std.StaticBitSet(MAX_PANES) = .empty,
/// A look's word search is running (look.lookUnresolved): from a
/// terminal its rows refill the directory's one +Search (Output).
word_look: bool = false,
@@ -4470,6 +4544,9 @@ pub const Pardes = struct {
cursor_view: struct { serial: u32 = 0, line: i64 = 0, origin: [2]f32 = .{ 0, 0 }, inside: bool = true } = .{},
/// The cursor glides from one pane to another: it may cross the grid.
cursor_crossing: bool = false,
+ /// A click took focus to another pane and its button is still down: the
+ /// cursor waits where it was drawn for the release that places it.
+ cursor_held: bool = false,
input_ns: u64 = 0,
animate_theme_changes: bool = false,
native_images: bool = false,
@@ -4508,6 +4585,9 @@ pub const Pardes = struct {
chord_hold: bool = false,
/// The look just run found nothing (look.zig missed).
look_missed: bool = false,
+ /// The look being run opens a .diff or .patch as text whatever DiffLook
+ /// says: Diff going back from a +Diff, Edit's B (it edits the file).
+ look_text: bool = false,
look_hover_wait: ?look.LookHoverWait = null,
/// The place a look-hover last found nothing to open: the pointer
/// resting there does not ask again every frame (look.noteLookHover).
@@ -4528,6 +4608,8 @@ pub const Pardes = struct {
/// default one.
register: u21 = 0,
leader_on: bool = false,
+ /// Window mode's outlined pane (layout.windowKey); null outside it.
+ window_pick: ?usize = null,
leader_keys: [4]u8 = undefined,
leader_n: u8 = 0,
/// The keyboard is on a header: the column tag `header_column` names, or
@@ -4748,6 +4830,8 @@ pub const Pardes = struct {
const named = try std.fs.path.join(gpa, &.{ dir, "+Pager" });
gpa.free(shown.file.?.path);
shown.file.?.path = named;
+ shown.file.?.pager = true;
+ shown.tty_filter = true;
shown.file.?.pager_diff = panes.File.looksLikeDiff(content[0..@min(content.len, 64 * 1024)]);
shown.file.?.pager_spans = page.spans;
p.oneColumn();
@@ -4935,7 +5019,7 @@ pub const Pardes = struct {
if (p.dump_out) |d| gpa.free(d);
p.fallback.deinit();
if (p.last_dump) |d| gpa.free(d);
- if (p.custom_theme) |theme_value| std.zon.parse.free(gpa, theme_value);
+ if (p.custom_theme) |theme_value| gpa.free(theme_value.name);
if (p.chord_arg) |a| gpa.free(a);
for (p.spawn_dirs) |d| if (d) |dir| gpa.free(dir);
p.pipe.deinit(gpa);
@@ -5955,7 +6039,7 @@ pub const Pardes = struct {
// The one-failure rule is a write's: a refused open (its OTRUNC's
// truncation, a setattr, too), create or remove is its Rerror alone,
// no err, as is a write to pane/new, which is only ever read.
- const ruled = req.op == .write and req.node != @intFromEnum(ctlfs.TopFile.new);
+ const ruled = req.op == .write and req.node != @backingInt(ctlfs.TopFile.new);
if (reply.status == .err and ruled) ctlfs.events.noteError(p, req, reply);
// The request was a whole step of its own, so it settles the way a
// step does: the cursor and scroll reconciled, the scripted panes
@@ -6284,12 +6368,26 @@ pub const Pardes = struct {
}
return;
}
+ if (p.window_pick != null) return layout.windowKey(p, key);
const pane = p.panes[p.active] orelse return;
p.noteTyped();
+ // In a raw terminal the two Escs swap unless ProgramEsc is on: Esc
+ // backs out, and Shift-Esc is the program's, sent as a plain Esc.
+ const raw_esc = key.cp == Key.escape and !key.ctrl and !key.alt and !p.settings.program_esc and
+ pane.isTerminal() and pane.body.mode == .tty and pane.focus == .body and pane.prompt == .none and
+ tagline.focusedHeader(p) == null;
+ if (raw_esc and key.shift) {
+ p.leader_on = false;
+ p.ctrl_w_pending = false;
+ panes.terminal.followOutput(pane);
+ var plain = key;
+ plain.shift = false;
+ return panes.terminal.forwardKey(p, p.active, plain);
+ }
// Shift-Esc backs out of whatever the pane is in -- a prompt, insert
// mode, a pending count, a raw program -- to the previous pane, as
// Esc does from normal mode. Nothing under it sees the key.
- if (hit(key, config.back_out)) {
+ if (raw_esc or hit(key, config.back_out)) {
p.leader_on = false;
p.ctrl_w_pending = false;
if (pane.prompt != .none) {
@@ -6317,8 +6415,8 @@ pub const Pardes = struct {
p.ctrl_w_pending = false;
if (key.ctrl and !key.alt and key.cp == p.opts.tty_toggle)
return p.toggleTty(p.active);
- // Bare Escape leaves only at a shell prompt (Shift-Esc, above,
- // always).
+ // With ProgramEsc on, bare Escape leaves only at a shell prompt
+ // (Shift-Esc, above, always).
if (key.cp == Key.escape and !key.ctrl and !key.alt and !key.shift and exec.takesCommandLine(p, p.active))
return exec.runBuiltin(p, .Last, p.active, "", null);
panes.terminal.followOutput(pane); // typing snaps back to live output
@@ -6346,12 +6444,16 @@ pub const Pardes = struct {
}
return;
}
- // insert mode owns Ctrl-w (delete word backward, helix); the focus
- // prefix applies outside raw tty mode
+ // insert mode owns Ctrl-w (delete word backward, helix); outside raw
+ // tty mode it enters window mode, or on a header prefixes a move
+ // between the headers
const t = header orelse if (pane.focus == .tag) &pane.tag else &pane.body;
if (hit(key, config.window_prefix) and t.mode != .insert and (header != null or pane.prompt == .none)) {
- p.ctrl_w_pending = true;
- return;
+ if (header != null) {
+ p.ctrl_w_pending = true;
+ return;
+ }
+ return exec.runBuiltin(p, .Window, p.active, "", null);
}
// global window ops (any mode): Alt-n new terminal below, Alt-c move
// the active terminal into a fresh column
@@ -6674,7 +6776,8 @@ pub const Pardes = struct {
pub const SavePath = Effect.Buf(effect_path_cap);
- pub fn lspRequest(p: *Pardes, asked: usize, kind: lsp.Kind, arg: []const u8) void {
+ pub fn lspRequest(p: *Pardes, asked: usize, kind: lsp.Kind, arg_in: []const u8) void {
+ var arg = arg_in;
if (!normal.multiOnce(p)) return; // one question per keystroke, from the primary
// Lspwhy narrates the last query where it was asked -- that pane's
// file, place and argument -- from wherever it is run.
@@ -6697,10 +6800,30 @@ pub const Pardes = struct {
(!zig_buf and std.mem.indexOfAny(u8, arg, " \t\r\n\"\\") != null))
return p.reportFailure(id, std.fmt.bufPrint(&said, "Rename: {s} is no name", .{arg}) catch "Rename: no name");
}
- const off = if (pane.file) |f| modal.offsetAt(f.content, .{
+ var off = if (pane.file) |f| modal.offsetAt(f.content, .{
.row = @intCast(@max(0, pane.body.cur_row)),
.col = @intCast(@max(0, pane.body.cur_col)),
}) else 0;
+ // Def or Refs given a symbol (a 2-1 chord's selection) asks at its
+ // occurrence nearest the cursor, which a sweep leaves at one end of
+ // what it selected; the server is asked at a place, never a name.
+ if ((kind == .definition or kind == .references) and arg.len > 0) {
+ const content = pane.file.?.content;
+ var nearest: ?usize = null;
+ var best: usize = 0;
+ var from: usize = 0;
+ while (std.mem.indexOfPos(u8, content, from, arg)) |at_hit| : (from = at_hit + 1) {
+ const d = if (at_hit > off) at_hit - off else off -| (at_hit + arg.len);
+ if (nearest != null and at_hit > off and d >= best) break;
+ if (nearest == null or d < best) {
+ nearest = at_hit;
+ best = d;
+ }
+ }
+ off = nearest orelse
+ return p.reportFailure(id, std.fmt.bufPrint(&said, "{s}: no {s} in this file", .{ lspWord(kind), arg }) catch "no such symbol in this file");
+ arg = "";
+ }
// Lspwhy asks the last query again, narrated: its kind and argument,
// at its place when asked from its pane. None yet: a definition.
var explained: [160]u8 = undefined;
@@ -6858,7 +6981,10 @@ pub const Pardes = struct {
fn lspWord(kind: lsp.Kind) []const u8 {
return switch (kind) {
.hover => "Hover",
+ .definition => "Def",
+ .references => "Refs",
.explain => "Lspwhy",
+ .callstack => "Callstack",
.incoming_calls => "Callers",
.outgoing_calls => "Callees",
.document_symbols => "Symbols",
@@ -6974,6 +7100,18 @@ pub const Pardes = struct {
// (a multi-file Rename's preview, Lspinfo's +Lsp), made or filled
// again, not the pane it was asked from.
p.fs.lsp_result = if (p.next_serial != serial_before) p.next_serial else p.fs.refilled;
+ if (w.kind == .callstack) {
+ for (p.panes, 0..) |slot, result_id| if (slot) |result_pane| {
+ if (result_pane.serial != p.fs.lsp_result) continue;
+ if (p.next_serial != serial_before) {
+ const report_rows = std.mem.count(u8, result_pane.file.?.content, "\n");
+ const wanted: u16 = @intCast(@min(p.screen_h, report_rows + result_pane.tag_rows));
+ layout.givePaneRows(p, result_id, wanted, w.pane);
+ }
+ look.focusPaneLine(p, result_id, .{ .line = 1, .col = 1 }, .keep);
+ break;
+ };
+ }
if (w.kind == .rename) {
var said_buf: [128]u8 = undefined;
// Rows that only name a file the server left alone (lsp_client
@@ -7517,7 +7655,6 @@ pub const Pardes = struct {
return if (frames) |n| p.stepped_ns + n * animation.frame_ns else null;
}
-
/// A render-time animation is moving (a pane's lift): it is sampled at
/// each frame's own `now`, so while it moves the shell draws every loop
/// and its present (vsync) paces it, at the display's rate. `nextWake`
@@ -8319,7 +8456,7 @@ test "Esc back into a file leaves its view where it was" {
try std.testing.expectEqual(@as(usize, @intCast(row)) -| @as(usize, dp.rows) / 2, dp.file.?.scroll);
}
-test "raw tty Escape only leaves at a shell prompt" {
+test "raw tty Esc backs out and Shift-Esc is the program's Esc" {
if (platform == .web) return;
const p = try Pardes.init(std.testing.allocator, .{ .cols = 80, .rows = 24, .file = "mise.toml" });
defer p.deinit();
@@ -8329,6 +8466,32 @@ test "raw tty Escape only leaves at a shell prompt" {
var buf: [256]u8 = undefined;
_ = drainWrites(p, &buf);
+ p.update(.{ .key = .{ .cp = 'x', .text = "x" } });
+ _ = drainWrites(p, &buf);
+ p.update(.{ .key = .{ .cp = Key.escape } }); // past typed text too
+ try std.testing.expectEqual(@as(usize, 0), p.active);
+ try std.testing.expectEqualStrings("", drainWrites(p, &buf));
+ try std.testing.expectEqual(Text.Mode.tty, pane.body.mode);
+
+ p.update(.{ .key = .{ .cp = Key.escape } }); // back into the shell
+ try std.testing.expectEqual(shell, p.active);
+ _ = drainWrites(p, &buf);
+ p.update(.{ .key = .{ .cp = Key.escape, .shift = true } });
+ try std.testing.expectEqual(shell, p.active);
+ try std.testing.expectEqualStrings("\x1b", drainWrites(p, &buf));
+}
+
+test "with ProgramEsc raw tty Escape only leaves at a shell prompt" {
+ if (platform == .web) return;
+ const p = try Pardes.init(std.testing.allocator, .{ .cols = 80, .rows = 24, .file = "mise.toml" });
+ defer p.deinit();
+ p.settings.program_esc = true;
+ _ = exec.spawnTty(p, 0);
+ const shell = p.active;
+ const pane = p.panes[shell].?;
+ var buf: [256]u8 = undefined;
+ _ = drainWrites(p, &buf);
+
// Ordinary keys reach the child; Shift-Escape is the one unconditional way
// out and sends it nothing.
p.update(.{ .key = .{ .cp = 'x', .text = "x" } });
@@ -8372,6 +8535,63 @@ test "Shift-Esc backs out to the previous pane in every mode, never into raw" {
try std.testing.expect(p.active != 0);
}
+test "window mode moves an outline and focuses it on Enter, Esc or a label" {
+ const p = try Pardes.init(std.testing.allocator, .{ .cols = 120, .rows = 30 });
+ defer p.deinit();
+ _ = try p.setTestFile("left\n");
+ _ = try p.newShell(1, "");
+ try std.testing.expect(layout.splitColumn(p, 0, 1, false));
+ p.newScratchBelow(1);
+ p.sync();
+ const lower = for (p.panes, 0..) |slot, id| {
+ if (slot != null and id > 1) break id;
+ } else return error.TestExpectedScratch;
+ p.active = 0;
+ // Ctrl-w enters it; h/j/k/l move only the outline.
+ p.update(.{ .key = .{ .cp = 'w', .ctrl = true } });
+ try std.testing.expectEqual(@as(?usize, 0), p.window_pick);
+ p.update(.{ .key = .{ .cp = 'l', .text = "l" } });
+ try std.testing.expect(p.window_pick != null and p.window_pick.? != 0);
+ p.update(.{ .key = .{ .cp = 'j', .text = "j" } });
+ try std.testing.expectEqual(@as(?usize, lower), p.window_pick);
+ try std.testing.expectEqual(@as(usize, 0), p.active);
+ p.update(.{ .key = .{ .cp = Key.enter } });
+ try std.testing.expectEqual(lower, p.active);
+ try std.testing.expect(p.window_pick == null);
+ // SPC w enters it too, and Esc also leaves it on the outlined pane.
+ p.update(.{ .key = .{ .cp = ' ', .text = " " } });
+ p.update(.{ .key = .{ .cp = 'w', .text = "w" } });
+ p.update(.{ .key = .{ .cp = 'h', .text = "h" } });
+ p.update(.{ .key = .{ .cp = Key.escape } });
+ try std.testing.expectEqual(@as(usize, 0), p.active);
+ try std.testing.expect(p.window_pick == null);
+ // Other keys change nothing.
+ p.update(.{ .key = .{ .cp = 'w', .ctrl = true } });
+ p.update(.{ .key = .{ .cp = '!', .text = "!" } });
+ try std.testing.expectEqual(@as(?usize, 0), p.window_pick);
+ p.update(.{ .key = .{ .cp = Key.escape } });
+ // `:` focuses the outlined pane's tag.
+ p.update(.{ .key = .{ .cp = 'w', .ctrl = true } });
+ p.update(.{ .key = .{ .cp = 'l', .text = "l" } });
+ p.update(.{ .key = .{ .cp = ':', .text = ":" } });
+ try std.testing.expect(p.active != 0 and p.panes[p.active].?.focus == .tag);
+ p.update(.{ .key = .{ .cp = Key.escape } });
+ // A label goes straight there: the left column's pane is "a".
+ try std.testing.expectEqual(@as(?u8, 'a'), layout.windowLabel(p, 0));
+ try std.testing.expect(p.executeBuiltinLine(p.active, "Window"));
+ p.update(.{ .key = .{ .cp = 'a', .text = "a" } });
+ try std.testing.expectEqual(@as(usize, 0), p.active);
+ // Painted: the outlined tag's band in the selection colour, each pane's
+ // letter in its tag's box.
+ try std.testing.expect(p.executeBuiltinLine(p.active, "Window"));
+ var arena: std.heap.ArenaAllocator = .init(std.testing.allocator);
+ defer arena.deinit();
+ const shown = try p.render(arena.allocator());
+ try std.testing.expectEqual(p.theme().sel_bg, shown.tag_layers[0].bg);
+ const box = shown.at(p.rects[0].x, p.tagTop(p.panes[0].?, p.rects[0]));
+ try std.testing.expectEqualStrings("a", box.text[0..box.len]);
+}
+
test "raw tty Ctrl-B switches to editor mode without sending child input" {
if (platform == .web) return;
const p = try Pardes.init(std.testing.allocator, .{ .file = "mise.toml" });
@@ -8390,7 +8610,7 @@ test "raw tty Ctrl-B switches to editor mode without sending child input" {
test "the jump list never holds two entries in a row the same, when the one between them goes" {
const p = try Pardes.init(std.testing.allocator, .{ .cols = 60, .rows = 40 });
defer p.deinit();
- const pane = try p.setTestFile("a\n" ** 200);
+ const pane = try p.setTestFile(std.mem.asBytes(&@as([200][2]u8, @splat("a\n".*))));
const at: Loc = .{ .pane = 0, .serial = pane.serial, .line = 1, .col = 1 };
// A, a pane long closed with no file to keep it, A again, then far on.
p.jumps[0] = at;
@@ -8407,6 +8627,44 @@ test "the jump list never holds two entries in a row the same, when the one betw
try std.testing.expectEqual(@as(u32, 150), p.jumps[1].line);
}
+test "Callstack always opens and focuses its own pane, reusing it for another symbol" {
+ if (!lsp.supports.contains(.callstack)) return;
+ const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true });
+ defer p.deinit();
+ _ = try p.setTestFile("fn work() {}\n");
+ const source = p.panes[0].?;
+ p.lspRequest(0, .callstack, "");
+ const first = p.lsp_wait orelse return error.NoRequest;
+ p.lspResponse(first.id, "└──┬ /test.txt:1:4-7 work\n@callstack-match └─ /test.txt:1:4-7 fn work() {}\n");
+ const report = p.panes[p.active].?;
+ try std.testing.expect(report != source);
+ try std.testing.expect(std.mem.endsWith(u8, report.file.?.path, "/+Callstack"));
+ try std.testing.expectEqual(@as(i32, 0), source.body.cur_row);
+ const stale_selection = std.mem.indexOfScalar(u8, report.file.?.content, '\n').? + 1;
+ report.body.setRange(report.file.?.content, 0, .{ .anchor = stale_selection, .head = stale_selection + 6 }, true);
+ layout.toggleCollapse(p, 0);
+ var frame = std.heap.ArenaAllocator.init(std.testing.allocator);
+ defer frame.deinit();
+ const surface = try p.render(frame.allocator());
+ p.acknowledgePanelPresentation(&.{});
+ const r = p.rects[p.active];
+ const row = r.y + report.tag_rows;
+ const col = r.x + config.GUTTER + panes.File.gutterWidth(report) + 7;
+ try std.testing.expectEqual(.off, surface.at(col, row).style.ul);
+ p.update(.{ .mouse = .{ .button = .right, .kind = .press, .row = row, .col = col } });
+ p.update(.{ .mouse = .{ .button = .right, .kind = .release, .row = row, .col = col } });
+ try std.testing.expect(!source.collapsed);
+ try std.testing.expectEqual(@as(usize, 0), p.active);
+ try std.testing.expect(!report.body.vsel.active);
+ try std.testing.expectEqual(@as(usize, 0), report.body.nsel);
+ const serial = report.serial;
+ p.lspRequest(0, .callstack, "");
+ const second = p.lsp_wait orelse return error.NoRequest;
+ p.lspResponse(second.id, "No callers reported\n");
+ try std.testing.expectEqual(serial, p.panes[p.active].?.serial);
+ try std.testing.expectEqualStrings("No callers reported\n", p.panes[p.active].?.file.?.content);
+}
+
test "Callers with one answer jumps to it and says where, in a msg" {
if (!lsp.supports.contains(.incoming_calls)) return;
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true });
@@ -8460,6 +8718,7 @@ test "hopping between two panes does not grow the jump stack" {
p.update(.{ .key = .{ .cp = ' ' } });
p.update(.{ .key = .{ .cp = 'w' } });
p.update(.{ .key = .{ .cp = dir } });
+ p.update(.{ .key = .{ .cp = Key.enter } });
try std.testing.expectEqual(want, p.active);
}
try std.testing.expectEqual(depth, p.njumps);
@@ -8843,6 +9102,19 @@ test "board heap: every allocation failure during boot is a clean OutOfMemory" {
);
}
+test "a sweep pressed on the line numbers copies only the text" {
+ const p = try Pardes.init(std.testing.allocator, .{ .cols = 60, .rows = 12 });
+ defer p.deinit();
+ const pane = try p.setTestFile("alpha beta\ngamma delta\n");
+ const numbers: i32 = panes.File.gutterWidth(pane);
+ const top: i32 = pane.tag_rows;
+ pane.sel[0] = .{ .state = .done, .c0 = 1, .c1 = numbers + 4, .r0 = top, .r1 = top + 1 };
+ // Live, while the drag is held, and captured, once it is released.
+ try std.testing.expectEqualStrings("alpha beta\ngamma", try edit.selectionText(p, pane, pane.sel[0]));
+ try edit.capturePointerSelection(p, pane, 0);
+ try std.testing.expectEqualStrings("alpha beta\ngamma", try edit.selectionText(p, pane, pane.sel[0]));
+}
+
test "jump history clears selections and lands at the recorded cursor" {
const p = try Pardes.init(std.testing.allocator, .{ .cols = 60, .rows = 12 });
defer p.deinit();
@@ -8898,7 +9170,7 @@ const JumpsTest = struct {
fn init(order: []const u8) !JumpsTest {
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 80 });
errdefer p.deinit();
- const text = "row\n" ** 100;
+ const text = std.mem.asBytes(&@as([100][4]u8, @splat("row\n".*)));
_ = try p.setTestFile(text);
var t: JumpsTest = .{ .p = p };
for ([_][]const u8{ "/b.txt", "/test.txt", "" }, 1..) |path, n| {