summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/Band.zig167
-rw-r--r--core/Core.zig119
-rw-r--r--core/Db.zig2
-rw-r--r--core/Effect.zig2
-rw-r--r--core/File.zig7
-rw-r--r--core/Jump.zig7
-rw-r--r--core/Kind.zig5
-rw-r--r--core/Layer.zig7
-rw-r--r--core/Messages.zig1480
-rw-r--r--core/Output.zig51
-rw-r--r--core/Pick.zig1896
-rw-r--r--core/Pipe.zig2
-rw-r--r--core/Places.zig2
-rw-r--r--core/Plumb.zig6
-rw-r--r--core/Prompt.zig15
-rw-r--r--core/Query.zig49
-rw-r--r--core/Store.zig2
-rw-r--r--core/Stream.zig2
-rw-r--r--core/TagState.zig466
-rw-r--r--core/Term.zig8
-rw-r--r--core/Trail.zig198
-rw-r--r--core/bindings.zig172
-rw-r--r--core/body_layer.zig548
-rw-r--r--core/builtins.zig68
-rw-r--r--core/colors.zig23
-rw-r--r--core/config.zig18
-rw-r--r--core/draw.zig187
-rw-r--r--core/dump.zig43
-rw-r--r--core/edit.zig18
-rw-r--r--core/edit_cmd.zig8
-rw-r--r--core/exec.zig23
-rw-r--r--core/fuzz.zig12
-rw-r--r--core/jj.zig27
-rw-r--r--core/keys.zig86
-rw-r--r--core/layout.zig32
-rw-r--r--core/look.zig32
-rw-r--r--core/lsp/Ask.zig163
-rw-r--r--core/mouse.zig63
-rw-r--r--core/ninep/ctl.zig12
-rw-r--r--core/ninep/events.zig14
-rw-r--r--core/ninep/tree.zig5
-rw-r--r--core/normal.zig22
-rw-r--r--core/panes.zig163
-rw-r--r--core/replica.zig7
-rw-r--r--core/rollback.zig2
-rw-r--r--core/root.zig21
-rw-r--r--core/surface.zig3
-rw-r--r--core/syntax.zig5
-rw-r--r--core/tagline.zig47
49 files changed, 5439 insertions, 878 deletions
diff --git a/core/Band.zig b/core/Band.zig
index 7f9cfc7b..835c249f 100644
--- a/core/Band.zig
+++ b/core/Band.zig
@@ -47,6 +47,12 @@ pub const Row = struct {
/// Its place in the list its step shows (a level's child, a hit): what
/// a click on it moves the cursor to.
index: u16 = 0,
+ /// Marked in a picker's list: `•` before it.
+ mark: bool = false,
+ /// Its first `pre` bytes are a place (`file:line`, `@p3`): the name's
+ /// tint; the `faint` bytes after them dimmed (a path's directory).
+ pre: u16 = 0,
+ faint: u16 = 0,
};
/// A column of rows. A level of more than 9 rows flows into two columns
@@ -89,13 +95,21 @@ pub fn takes(p: *Pardes, id: usize) u16 {
switch (s.kind) {
.rest => {},
.help => return @max(doc_rows, @max(1, @min(Cursor.shown, s.nhits))),
- .describe => return 0,
+ .describe => {
+ if (!s.found) return 0;
+ var children: [bindings.max_children]bindings.Child = undefined;
+ return @max(doc_rows, levelRows(@intCast(bindings.level(p, s.scope_root.?, s.scope[0 .. s.scope_n - 1], &children).len)));
+ },
+ .pick => return @import("Pick.zig").bandRows(p),
.prompt => return Prompt.takes(p),
+ .rename => return 0,
}
if (!s.unrolled) return 0;
const cur = TagState.current(p, v) orelse return 0;
var children: [bindings.max_children]bindings.Child = undefined;
const n: u16 = @intCast(bindings.level(p, cur.root, cur.path, &children).len);
+ // The registers, one column of eleven at most (registerSteps).
+ if (cur.root == .register and cur.path.len == 0) return @max(doc_rows, @min(Cursor.shown, n));
return @max(doc_rows, levelRows(n));
}
@@ -118,15 +132,42 @@ pub fn of(p: *Pardes, arena: std.mem.Allocator, pane: *Pane, id: usize) !?Band {
try band.place(p, arena, pane, id);
return band;
},
- .describe => return null,
+ // describe-key's leaf: its level replayed, the leaf on the cursor,
+ // and its doc.
+ .describe => {
+ const root = s.scope_root.?;
+ const path = s.scope[0 .. s.scope_n - 1];
+ var children: [bindings.max_children]bindings.Child = undefined;
+ const level = bindings.level(p, root, path, &children);
+ var at: usize = 0;
+ for (level, 0..) |c, i| if (c.key == s.scope[s.scope_n - 1]) {
+ at = i;
+ };
+ const node = bindings.nodeAt(root, path);
+ band.add(try levelStep(arena, pane, level, at, if (node) |n| s.used[n.group] else 0));
+ band.add(try docStep(p, arena, root, path, level[at]));
+ try band.place(p, arena, pane, id);
+ return band;
+ },
+ .pick => {
+ for (try @import("Pick.zig").steps(p, arena)) |step| band.add(step);
+ try band.place(p, arena, pane, id);
+ return band;
+ },
.prompt => {
var steps: [max_steps]Step = undefined;
for (try Prompt.steps(p, arena, &steps)) |step| band.add(step);
try band.place(p, arena, pane, id);
return band;
},
+ .rename => return null,
}
const cur = TagState.current(p, v).?;
+ if (cur.root == .register) {
+ try band.registerSteps(p, arena, pane, cur.path);
+ try band.place(p, arena, pane, id);
+ return band;
+ }
// The level, its cursor on the child it names, else the leaf its group
// ran last, else the first; and that child's doc beside it.
const node = bindings.nodeAt(cur.root, cur.path);
@@ -172,6 +213,63 @@ fn helpSteps(band: *Band, p: *Pardes, arena: std.mem.Allocator, s: *const TagSta
band.add(try docStep(p, arena, at.root, at.path[0 .. at.path.len - 1], at.child));
}
+/// `"` unrolled (SPEC §9): the registers, a row each (its key, what it
+/// is, its first line) around the cursor, or under `"a` its verbs; beside
+/// them the value of the one on the cursor (or named) in full, as many of
+/// its lines as the band has rows, only those read.
+fn registerSteps(band: *Band, p: *Pardes, arena: std.mem.Allocator, pane: *const Pane, path: []const u8) !void {
+ const s = &p.view().tag_state;
+ var children: [bindings.max_children]bindings.Child = undefined;
+ const level = bindings.level(p, .register, path, &children);
+ const node = bindings.nodeAt(.register, path);
+ const used = if (node) |n| s.used[n.group] else 0;
+ var at: usize = 0;
+ for (level, 0..) |c, i| if (c.key == (if (s.hi != 0) s.hi else used)) {
+ at = i;
+ };
+ if (path.len > 0) band.add(try levelStep(arena, pane, level, at, used)) else {
+ const w = (Cursor{ .at = @intCast(at) }).window(@intCast(level.len));
+ const rows = try arena.alloc(Row, w.hi - w.lo);
+ for (rows, w.lo..) |*row, i| {
+ const c = level[i];
+ const name = for (bindings.register_names) |r| {
+ if (r.key == c.key) break r.name;
+ } else "named";
+ row.* = .{
+ .text = try std.fmt.allocPrint(arena, "{s} {s: <17} {s}{s}", .{ bindings.keyName(c.key), name, c.label, if (c.more) "…" else "" }),
+ .on = i == at,
+ .key = 1,
+ .under = c.key == used,
+ .index = @intCast(i),
+ };
+ }
+ band.add(.{ .rows = rows });
+ }
+ const key = if (path.len > 0) path[0] else level[at].key;
+ const name = for (bindings.register_names) |r| {
+ if (r.key == key) break r.name;
+ } else "named";
+ var rows: std.ArrayList(Row) = .empty;
+ try rows.append(arena, .{ .text = try std.fmt.allocPrint(arena, "\"{s} · {s}", .{ bindings.keyName(key), name }), .key = 2 });
+ const value = bindings.registerValue(p, key);
+ if (value.len == 0) try rows.append(arena, .{ .text = "(empty)", .dim = true });
+ // A line is cut at what the band could show of it: a long one is
+ // never scanned past that.
+ const most = @as(usize, band.columns) * band.height;
+ var rest = value;
+ while (rest.len > 0 and rows.items.len + 1 < band.height) {
+ const look = rest[0..@min(rest.len, most)];
+ const end = std.mem.indexOfScalar(u8, look, '\n') orelse {
+ try rows.append(arena, .{ .text = rest[0..if (look.len < rest.len) modal.graphemeStart(rest, look.len) else look.len] });
+ break;
+ };
+ try rows.append(arena, .{ .text = look[0..end] });
+ rest = rest[end + 1 ..];
+ }
+ if (path.len == 0) try rows.append(arena, .{ .text = "next p after P before R replace y into", .dim = true });
+ band.add(.{ .rows = rows.items, .doc = true });
+}
+
/// A list's cursor and the rows of it a band shows: eleven at most, around
/// the cursor (SPEC §3.6, the prototype's `H.window`). Each view's (a
/// tag state's field): Help's rows, a picker's, a prompt's history.
@@ -221,7 +319,7 @@ pub fn levelStep(arena: std.mem.Allocator, pane: *const Pane, level: []const bin
for (level, rows, 0..) |c, *row, i| {
const key = bindings.keyName(c.key);
row.* = .{
- .text = try std.fmt.allocPrint(arena, "{s} {s}{s}", .{ key, c.label, if (c.group) "…" else "" }),
+ .text = try std.fmt.allocPrint(arena, "{s} {s}{s}", .{ key, c.label, if (c.group or c.more) "…" else "" }),
.on = i == at,
.key = @intCast(key.len),
.dim = bindings.dimmed(pane, c),
@@ -271,7 +369,7 @@ fn place(band: *Band, p: *Pardes, arena: std.mem.Allocator, pane: *Pane, id: usi
if (step.doc) continue;
var widest: usize = 0;
for (step.rows) |row| widest = @max(widest, File.displayWidth(tab, row.text));
- const column: u16 = @intCast(@min(widest + 2, std.math.maxInt(u16) / 4));
+ const column: u16 = @intCast(@min(widest + 2, std.math.maxInt(u16) / 4, @max(min_width, band.columns -| x)));
step.width = if (step.two) 2 * column + 1 else column;
need += step.width + 2;
}
@@ -316,24 +414,31 @@ fn findSpines(band: *Band, p: *Pardes, arena: std.mem.Allocator, pane: *Pane, id
}
/// `rows` wrapped at `width` display columns, word by word, `height` rows
-/// at most: a doc's paragraphs.
+/// at most: a doc's paragraphs, a line each in its text (builtins.Doc),
+/// each starting a row (a newline drawn in a row was a `�`).
fn wrap(arena: std.mem.Allocator, tab: u16, rows: []const Row, width: u16, max: u16) ![]const Row {
var out: std.ArrayList(Row) = .empty;
- for (rows) |row| {
- if (File.displayWidth(tab, row.text) <= width) {
- try out.append(arena, row);
- } else {
- var rest = row.text;
- while (rest.len > 0 and out.items.len < max) {
- var cut = File.byteAtDisplay(tab, rest, width);
- if (cut < rest.len) {
- if (std.mem.lastIndexOfScalar(u8, rest[0..cut], ' ')) |space| {
- if (space > 0) cut = space;
+ for (rows) |whole| {
+ var paragraphs = std.mem.splitScalar(u8, whole.text, '\n');
+ var row = whole;
+ while (paragraphs.next()) |text| : (row = .{ .text = "" }) {
+ if (out.items.len >= max) break;
+ row.text = text;
+ if (File.displayWidth(tab, row.text) <= width) {
+ try out.append(arena, row);
+ } else {
+ var rest = row.text;
+ while (rest.len > 0 and out.items.len < max) {
+ var cut = File.byteAtDisplay(tab, rest, width);
+ if (cut < rest.len) {
+ if (std.mem.lastIndexOfScalar(u8, rest[0..cut], ' ')) |space| {
+ if (space > 0) cut = space;
+ }
}
+ if (cut == 0) cut = modal.nextGrapheme(rest, 0);
+ try out.append(arena, .{ .text = std.mem.trimEnd(u8, rest[0..cut], " ") });
+ rest = std.mem.trimStart(u8, rest[cut..], " ");
}
- if (cut == 0) cut = modal.nextGrapheme(rest, 0);
- try out.append(arena, .{ .text = std.mem.trimEnd(u8, rest[0..cut], " ") });
- rest = std.mem.trimStart(u8, rest[cut..], " ");
}
}
if (out.items.len >= max) break;
@@ -376,7 +481,7 @@ pub fn line(band: *const Band, arena: std.mem.Allocator, tab: u16, y: u16) !Line
while (col < start) : (col += 1) try text.append(arena, ' ');
if (y >= shown or k >= step.rows.len) continue;
const row = step.rows[k];
- const lead: []const u8 = if (step.doc) "" else if (row.on) "▶ " else " ";
+ const lead: []const u8 = if (step.doc) "" else if (row.on) "▶ " else if (row.mark) "• " else " ";
try text.appendSlice(arena, lead);
col += @intCast(File.displayWidth(tab, lead));
try parts.append(arena, .{ .col = col, .width = per -| @as(u16, @intCast(File.displayWidth(tab, lead))), .row = row });
@@ -403,8 +508,8 @@ pub fn wordAt(p: *Pardes, arena: std.mem.Allocator, id: usize, y: u16, col: u16)
}
fn bandLayer(p: *Pardes, id: usize) ?*pardes.Layer {
- const layer = &p.surface.tag_layers[pardes.BAND_LAYER_BASE + id];
- return if (layer.rows > 0 and layer.kind == .band) layer else null;
+ const layer = &p.surface.tag_layers[pardes.BAND_LAYER];
+ return if (layer.rows > 0 and layer.kind == .band and layer.id == id) layer else null;
}
fn layerRow(arena: std.mem.Allocator, layer: *const pardes.Layer, row: usize) ![]const u8 {
@@ -528,3 +633,23 @@ test "the band's words are read-only text: B2 runs one, the tag back at rest" {
try std.testing.expect(p.settings.wrap != wrapped);
try std.testing.expect(p.view().prefix == .none and !p.view().tag_state.unrolled);
}
+
+test "a doc's paragraphs are rows of their own: no newline in a band's row" {
+ const Key = pardes.Key;
+ const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 120, .rows = 40 });
+ defer p.deinit();
+ _ = try p.setTestFile("one\n");
+ const id = p.view().active;
+ var frame = std.heap.ArenaAllocator.init(std.testing.allocator);
+ defer frame.deinit();
+ const a = frame.allocator();
+ // SPC b b is Panes, whose documentation has three paragraphs.
+ for ([_]u21{ ' ', 'b', Key.down }) |c| p.update(.{ .key = .{ .cp = c } });
+ const band = (try of(p, a, p.panes[id].?, id)).?;
+ var docs: usize = 0;
+ for (band.steps[0..band.nsteps]) |step| for (step.rows) |row| {
+ try std.testing.expect(std.mem.indexOfScalar(u8, row.text, '\n') == null);
+ if (step.doc) docs += 1;
+ };
+ try std.testing.expect(docs > 2);
+}
diff --git a/core/Core.zig b/core/Core.zig
index 61d8c7e9..2c04cc64 100644
--- a/core/Core.zig
+++ b/core/Core.zig
@@ -183,6 +183,10 @@ pub const View = struct {
/// A key that waits for the next: the leader (SPC) or the window prefix
/// (Ctrl-w), one at a time.
prefix: enum { none, leader, window } = .none,
+ /// A background question SPC e gave the keyboard: the serial of the
+ /// pane it waits on (0: none). Its next key answers it; Esc leaves it
+ /// waiting (keys.zig handleKey).
+ answering: u32 = 0,
/// The register the running normal command names (`"<reg>`); 0 for the
/// default one.
register: u21 = 0,
@@ -343,6 +347,11 @@ locations_cache: locations.Cache = .{},
tty_filter_palette: pardes.Term.FilterPalette = .{},
font_request_taken: bool = false,
custom_theme: ?Theme = null,
+/// The theme the window wears while a picker of them (or `:theme `)
+/// previews one, by index, and its chrome (colors.previewTheme); the
+/// session's own theme untouched under it.
+theme_preview: ?u16 = null,
+preview_chrome: ChromeTheme = colors.initial_chrome,
/// bodyChrome's: the theme it was worked out for, and it.
body_chrome: ?struct { theme: Theme, chrome: ChromeTheme } = null,
theme_file_path: config.Settings.Text(limits.host_path_cap) = .{},
@@ -359,8 +368,8 @@ chrome: colors.ChromeTheme = colors.initial_chrome,
frames: *FrameStats = undefined,
own_frames: FrameStats = .{},
quit: bool = false,
-/// A detached session with no frontend attached: nothing renders, so
-/// no input ever dismisses a message (Messages.expireUnattended).
+/// A detached session with no frontend attached: nothing renders, and a
+/// 9P write may size its view (ninep/ctl.zig `size`).
unattended: bool = false,
haptic: HapticSlot = if (platform == .macos) .none else {},
/// The look just run found nothing (look.zig missed).
@@ -402,6 +411,9 @@ lsp_ask: Ask = .{},
pipe: Pipe = .{},
/// A query pane's Grep, and its Find's listing, on a worker (Stream.zig).
stream: Stream = .{},
+/// The pickers: the one live in a view's tag, and the last ones rolled
+/// up, which their list words and Resume reopen (Pick.zig).
+picks: [pardes.Pick.max_lists]?*pardes.Pick = @splat(null),
/// The panes' `Changes` (jj.zig): what was asked of jj, and what it
/// answered for each pane, by its serial: the session's, not a field of
/// every pane (a digest and a rollback copy walk every pane's fields at
@@ -531,7 +543,7 @@ pub const replica = .{
"opts", "dump_out", "dump_export",
"tape",
},
- .derived = .{ "shell_rows", "diff_output", "locations_cache", "retired_panes", "tty_filter_palette", "body_chrome" },
+ .derived = .{ "shell_rows", "diff_output", "locations_cache", "retired_panes", "tty_filter_palette", "body_chrome", "theme_preview", "preview_chrome" },
// The host's handles, the state file every session of the user
// shares (and Recent read from it), this session's closed panes, and
// the files of a host with no file system of its own. (The 9P
@@ -935,6 +947,7 @@ pub fn deinit(p: *Pardes) void {
look.cancelLookHover(p);
if (p.repl_ask) |ask| p.gpa.free(ask.text);
for (0..MAX_PANES) |id| p.dropPendingWrite(id);
+ pardes.Pick.deinitAll(p);
// The panes, then those retired these last two frames.
inline for (.{ &p.panes, &p.retired_panes.previous, &p.retired_panes.current }) |slots| for (slots) |*slot| if (slot.*) |pane| {
pardes.panes.teardownPane(p, pane);
@@ -1038,7 +1051,8 @@ fn reportFocus(p: *Pardes) void {
// program hears of it a round trip later (a write there would stop the
// speculation: pty_write is `keeps_stopping`'s).
if (p.tape.speculating) return;
- if (v.focus_told) |old| if (p.panes[old.id]) |pane| {
+ // A damaged dump's pane past the slots names none.
+ if (v.focus_told) |old| if (old.id < MAX_PANES) if (p.panes[old.id]) |pane| {
if (pane.serial == old.serial and pardes.Term.modes(pane.terminal).focus) p.emitWrite(old.id, "\x1b[O");
};
if (want) |new| if (pardes.Term.modes(p.panes[new.id].?.terminal).focus) p.emitWrite(new.id, "\x1b[I");
@@ -1589,11 +1603,6 @@ pub fn pump(p: *Pardes, host: Host) !void {
} else 0;
_ = p.tape.host(p, .wait_input, .{timeout});
}
- // Detached, nobody's key dismisses a message: they go on the clock,
- // here in the step, where the clock read is taped (the host's wait
- // did it, untaped, and a replay kept a message its session had let
- // go).
- Messages.expireUnattended(p);
p.frames.mark_start = FrameStats.nowNs();
if (p.tape.host(p, .now, .{})) |now| p.advance(now);
p.settle();
@@ -1714,18 +1723,13 @@ fn updateInner(p: *Pardes, ev: Event) void {
// Its bands as its state stands: a step reads them (a press on a chip, a
// body's top under them), and what a frame drew, a view put back or a
// dump left in Pane.notices (derived) is not what every core has.
- for (p.panes, 0..) |slot, id| if (slot) |pane| Messages.collectNotices(p, pane, v.rects[id], id);
+ for (p.panes, 0..) |slot, id| if (slot) |pane| Messages.collectNotices(p, pane, v.rects[id]);
defer pardes.panes.File.syncTwins(p);
defer p.reportFocus();
// A tick with no deadline due is the one event that cannot change
// the screen.
p.needs_frame = p.needs_frame or ev != .tick;
p.shell_rows.sweep(p.gpa);
- Messages.expireUnattended(p);
- // An announcement stands in only until its own step says more.
- for (p.panes) |slot| if (slot) |pane| {
- pane.msg_announcement = false;
- };
// A Look's hover outlives a tick, a batch of rows coming in (no
// gesture), a move with no button, and a change to another pane.
const hover_stays = switch (ev) {
@@ -1740,15 +1744,9 @@ fn updateInner(p: *Pardes, ev: Event) void {
look.cancelLookHover(p);
}
switch (ev) {
- .key, .mouse => {
- for (p.panes) |slot| {
- if (slot) |pane| Messages.dismissMessage(p, pane);
- }
- v.clip_pending = null;
- },
+ .key, .mouse => v.clip_pending = null,
.tick => {
Stream.step(p);
- Messages.advanceMessages(p);
for (0..p.panes.len) |id| exec.flushReplEnter(p, id, false);
},
else => {},
@@ -1836,6 +1834,7 @@ fn updateInner(p: *Pardes, ev: Event) void {
pardes.Prompt.settle(p);
// Each live query pane's rows, made from what changed this step.
pardes.panes.Query.produceAll(p, ev == .tick, ev == .key);
+ pardes.Pick.produceAll(p, ev == .tick);
_ = p.scratch.reset(.{ .retain_with_limit = memory.limits.scratch_kept });
p.sync();
p.fsReport();
@@ -1917,10 +1916,10 @@ pub const SavePath = Effect.Buf(effect_path_cap);
pub const noteLateFailure = pardes.tape.taped(noteLateFailureInner);
fn noteLateFailureInner(p: *Pardes, id: Pane.Id) void {
// Said by reportFailure just now: its words fitted whole, the
- // reason kept; else what the message row has.
+ // reason kept; else what was said of the pane last.
const said = if (p.fs.said_at == p.fs.failures and p.fs.said_len > 0)
p.fs.said[0..p.fs.said_len]
- else if (p.panes[id.index()]) |pane| pane.msg[0..pane.msg_len] else return;
+ else if (p.panes[id.index()]) |pane| p.messages.saidBy(pane) else return;
const kept = @import("Messages.zig").clip(said, p.fs.late_failure.len);
@memcpy(p.fs.late_failure[0..kept.len], kept);
p.fs.late_failure_len = @intCast(kept.len);
@@ -1931,7 +1930,7 @@ fn noteLateFailureInner(p: *Pardes, id: Pane.Id) void {
pub const presented = pardes.tape.taped(presentedInner);
fn presentedInner(p: *Pardes) void {
const v = p.view();
- for (p.panes, 0..) |slot, id| if (slot) |pane| Messages.collectNotices(p, pane, v.rects[id], id);
+ for (p.panes, 0..) |slot, id| if (slot) |pane| Messages.collectNotices(p, pane, v.rects[id]);
if (v.pointer_inside and v.drag != .none) {
v.hover_col = v.pointer_raw_col;
v.hover_row = v.pointer_raw_row;
@@ -2040,6 +2039,15 @@ pub fn sync(p: *Pardes) void {
caret_row = std.mem.count(u8, shown.text[0..@min(shown.fromReal(cur), shown.text.len)], "\n");
}
if (!pane.tag_expanded) wanted = 1;
+ // Out of rest the head is the tag's text (TagState), and the tag
+ // keeps the rows its own text takes at least: a head shorter than
+ // it (a root's key cell, before its level shows) moved the body up
+ // and back down a moment later; a terminal's exactly those, its pty
+ // its body (a resize the program under it saw at every C-w and SPC).
+ if (pardes.TagState.hostOf(p) == id) {
+ const rest = layout.wantedTagRows(p, id);
+ wanted = if (pane.isTerminal()) rest else @max(wanted, rest);
+ }
pane.tag_rows = @intCast(@min(wanted, MAX_TAG_ROWS, @max(BOX_H, r.h -| 1)));
if (pane.collapsed) pane.tag_rows = BOX_H;
if (pane.focus == .tag and pane.prompt != .name) {
@@ -2047,7 +2055,7 @@ pub fn sync(p: *Pardes) void {
var top: usize = pane.tag_top;
if (cur < top) top = cur;
if (cur >= top + pane.tag_rows) top = cur + 1 - pane.tag_rows;
- pane.tag_top = @intCast(@min(top, lines - pane.tag_rows));
+ pane.tag_top = @intCast(@min(top, lines -| pane.tag_rows));
} else pane.tag_top = 0;
// The band unrolled under the tag's text pushes the body down:
// the tag's rows, as everything under them counts them.
@@ -2087,7 +2095,7 @@ pub fn sync(p: *Pardes) void {
}.ready, .{pane}));
// Which bands a pane shows is the step's, as its geometry is:
// what is drawn under them, and where a click lands, read it.
- Messages.collectNotices(p, pane, r, id);
+ Messages.collectNotices(p, pane, r);
// The greeting `ls` of a new terminal in a directory is typed at
// its shell's FIRST prompt, or never: typed later it would land
// in whatever runs then, or in the middle of a line someone
@@ -2137,12 +2145,14 @@ fn sizes(p: *const Pardes, pane: *const Pane) bool {
}
pub fn theme(p: *const Pardes) *const Theme {
+ if (p.theme_preview) |i| return &themes[i];
if (p.custom_theme) |*custom| return custom;
return &themes[p.settings.theme];
}
/// The colours of the chrome: the theme's, set as it changes.
pub fn chromeTheme(p: *const Pardes) *const ChromeTheme {
+ if (p.theme_preview != null) return &p.preview_chrome;
return &p.chrome;
}
@@ -2174,7 +2184,7 @@ pub fn nextWake(p: *const Pardes) ?u64 {
for (p.panes) |slot| if (slot) |pane| if (pane.places.busy(pane)) return next;
const kinds = pardes.Kind.wake(p);
if (kinds) |due| if (due <= next) return next;
- if (pardes.panes.Query.busy(p)) return next;
+ if (pardes.panes.Query.busy(p) or pardes.Pick.busy(p)) return next;
// A typed Grep waiting out its pause.
const streaming = p.stream.wake(next);
if (streaming) |due| if (due <= next) return next;
@@ -2184,10 +2194,11 @@ pub fn nextWake(p: *const Pardes) ?u64 {
const delay = config.look_preview_delay_frames;
frames = @max(1, delay -| waiting.frames);
}
- for (p.panes) |slot| if (slot) |pane| {
- const wait = Messages.messageWake(p, pane) orelse continue;
+ // A message dims at the end of its bright time.
+ if (Messages.dimDue(p)) |due| {
+ const wait = @max(1, (due - p.clock.stepped_ns + frame_ns - 1) / frame_ns);
frames = if (frames) |soonest| @min(soonest, wait) else wait;
- };
+ }
// Del's question goes up at the end of its delay: a frame then, and
// none after (stepped time has reached it).
for (p.panes) |slot| if (slot) |pane| if (pane.prompt == .del_side and pane.question_due_ns > p.clock.stepped_ns and pane.question_due_ns != Pane.question_asked) {
@@ -2252,7 +2263,6 @@ fn advanceInner(p: *Pardes, now_ns: u64) void {
// Only waiting until `due`: its counters move there at once.
const held = (due - p.clock.stepped_ns) / frame;
if (held > 1) {
- Messages.holdMessages(p, held - 1);
if (p.look_hover_wait) |*waiting| waiting.frames +|= @intCast(@min(held - 1, std.math.maxInt(u16)));
p.clock.stepped_ns += (held - 1) * frame;
}
@@ -2658,36 +2668,18 @@ test "TreeContext rows in the tag style keep the message rows" {
p.update(.{ .resize = .{ .cols = 60, .rows = 16, .row_metrics = .{ .body_w = 10, .body_h = 20, .tagline_w = 6, .tagline_h = 12 } } });
pane.file.?.tree_context = true;
pane.file.?.scroll = 8;
- pane.msg_len = 0;
+ p.messages.live_len = 0;
p.sync();
_ = try p.render(p.scratch.allocator());
const full_height = p.surface.body_layers[0].viewport.h;
try std.testing.expect(p.surface.body_layers[0].rows > full_height);
try std.testing.expectEqual(FontRole.tagline, p.surface.body_layers[0].cells[0].style.font_role);
- pane.msg[0] = '!';
- pane.msg_len = 1;
- p.sync();
- _ = try p.render(p.scratch.allocator());
- // An overlay takes nothing: the message is a chip OVER the body's first
- // row, so the viewport keeps every row it had.
- try std.testing.expectEqual(full_height, p.surface.body_layers[0].viewport.h);
- const r = p.view().rects[0];
- const band = for (p.surface.tagLayers()) |*layer| {
- if (layer.rows != 0 and layer.kind == .notice) break layer;
- } else return error.NoNoticeBand;
- try std.testing.expectEqual(p.bodyTop(pane, r), band.viewport.y);
- try std.testing.expectEqual(p.surface.body_layers[0].viewport.y, band.viewport.y);
- // Sized to its message, flush with the pane's right edge, and the text
- // right aligned a cell short of that edge.
- try std.testing.expectEqual(r.x + r.w, band.viewport.x + band.viewport.w);
- try std.testing.expect(band.viewport.w < r.w - config.GUTTER);
- try std.testing.expectEqualStrings("!", band.cells[layout.tagCapacity(p, band.viewport.w) - 2].grapheme());
- pane.msg_len = 0;
- p.view().prefix = .leader;
+ // A message is on the notice row, not over the body: the viewport
+ // keeps every row it had.
+ _ = Messages.keep(p, .notice, pane.serial, "", "!");
p.sync();
_ = try p.render(p.scratch.allocator());
try std.testing.expectEqual(full_height, p.surface.body_layers[0].viewport.h);
- p.view().prefix = .none;
}
test "TreeContext command and custom tag survive a workspace round trip" {
@@ -3069,7 +3061,7 @@ test "a REPL bound for a language takes the exec made on a body in it; tags, Exe
try std.testing.expect(file.repl == null);
try std.testing.expect(p.executeBuiltinLine(1, "Repl pithon"));
try std.testing.expect(p.panes[1].?.repl == null);
- try std.testing.expect(std.mem.indexOf(u8, p.panes[1].?.msg[0..p.panes[1].?.msg_len], "python") != null);
+ try std.testing.expect(std.mem.indexOf(u8, p.messages.saidBy(p.panes[1].?), "python") != null);
try std.testing.expect(p.executeBuiltinLine(1, "Repl python"));
// again, as a code fence may name it: no change
try std.testing.expect(p.executeBuiltinLine(1, "Repl PY"));
@@ -3083,8 +3075,7 @@ test "a REPL bound for a language takes the exec made on a body in it; tags, Exe
Sent.drain(p);
try std.testing.expectEqualStrings("ls\r", Sent.said(1));
try std.testing.expect(!Sent.spawned);
- try std.testing.expect(file.msg_sent);
- try std.testing.expectEqualStrings("\u{2192} python-a", file.msg[0..file.msg_len]);
+ try std.testing.expectEqualStrings("\u{2192} python-a", p.messages.saidBy(file));
// A body's click written back to event is done as the click: sent. A
// line written to exec came back as F and runs as the command it was.
{
@@ -3207,7 +3198,7 @@ test "a REPL bound for a language takes the exec made on a body in it; tags, Exe
p.update(.{ .key = .{ .cp = 'b' } });
Sent.drain(p);
try std.testing.expect(Sent.len[1] == 0 and Sent.len[2] == 0);
- try std.testing.expectEqualStrings("Repl: the REPL chosen is gone; nothing sent", file.msg[0..file.msg_len]);
+ try std.testing.expectEqualStrings("Repl: the REPL chosen is gone; nothing sent", p.messages.saidBy(file));
try std.testing.expect(p.executeBuiltinLine(2, "Repl python"));
try std.testing.expectEqualStrings("python-b", exec.replId(&idbuf, p.panes[2].?));
@@ -3224,7 +3215,7 @@ test "a REPL bound for a language takes the exec made on a body in it; tags, Exe
try std.testing.expectEqual(Pane.Prompt.none, file.prompt);
Sent.drain(p);
try std.testing.expect(Sent.len[1] == 0 and Sent.len[2] == 0 and !Sent.spawned);
- try std.testing.expect(std.mem.indexOf(u8, file.msg[0..file.msg_len], "no program running") != null);
+ try std.testing.expect(std.mem.indexOf(u8, p.messages.saidBy(file), "no program running") != null);
host.taken[1] = true;
host.taken[2] = true;
@@ -3234,7 +3225,7 @@ test "a REPL bound for a language takes the exec made on a body in it; tags, Exe
try std.testing.expect(p.executeBuiltinLine(1, "Repl python"));
try std.testing.expectEqualStrings("python-a", exec.replId(&idbuf, p.panes[1].?));
try std.testing.expect(p.executeBuiltinLine(2, "Repl"));
- try std.testing.expectEqualStrings("Repl: python-b", p.panes[2].?.msg[0..p.panes[2].?.msg_len]);
+ try std.testing.expectEqualStrings("Repl: python-b", p.messages.saidBy(p.panes[2].?));
// A command pane is a REPL while its command runs: done, it is none,
// and a done one cannot be bound. A document pane is no terminal.
@@ -3313,13 +3304,13 @@ test "Term+fish, one word a tag can hold, opens a terminal on that shell" {
const caller = p.panes[0].?;
try std.testing.expect(p.executeBuiltinLine(0, "Term /nonexistent"));
try std.testing.expect(p.view().active == before and caller.shell == null);
- try std.testing.expect(std.mem.indexOf(u8, caller.msg[0..caller.msg_len], "shell \"/nonexistent\" not found") != null);
+ try std.testing.expect(std.mem.indexOf(u8, p.messages.saidBy(caller), "shell \"/nonexistent\" not found") != null);
try std.testing.expect(p.executeBuiltinLine(0, "Term fsh-not-a-shell"));
try std.testing.expect(caller.shell == null);
// A directory passes access(X_OK); it is no shell either.
try std.testing.expect(p.executeBuiltinLine(0, "Term /etc"));
try std.testing.expect(p.view().active == before);
- try std.testing.expect(std.mem.indexOf(u8, caller.msg[0..caller.msg_len], "Term: not a shell: /etc is a directory") != null);
+ try std.testing.expect(std.mem.indexOf(u8, p.messages.saidBy(caller), "Term: not a shell: /etc is a directory") != null);
// Only a word that says so splits at `+`: `Dump+x.zon` is no Dump.
try std.testing.expect(!p.executeBuiltinLine(0, "Dump+x.zon"));
try std.testing.expect(!p.executeBuiltinLine(0, "Msg+hello"));
@@ -3679,7 +3670,7 @@ test "Tab N draws every pane's tab N cells wide and clicks count past it; bare T
try std.testing.expectEqual(@as(i32, 1), pane.body.cur_col);
// Bare, it says the width.
try std.testing.expect(p.executeBuiltinLine(0, "Tab"));
- try std.testing.expectEqualStrings("Tab 8", pane.msg[0..pane.msg_len]);
+ try std.testing.expectEqualStrings("Tab 8", p.messages.saidBy(pane));
// Out of range: refused, the width kept.
try std.testing.expect(p.executeBuiltinLine(0, "Tab 0"));
try std.testing.expectEqual(@as(u16, 8), p.settings.tab);
@@ -4109,7 +4100,7 @@ test "bytes for a terminal past what may wait for it are dropped and said, never
p.emitWrite(0, big);
try std.testing.expectEqual(@as(usize, 0), p.pending_write_bytes);
const pane = p.panes[0].?;
- try std.testing.expect(std.mem.indexOf(u8, pane.msg[0..pane.msg_len], "dropped") != null);
+ try std.testing.expect(std.mem.indexOf(u8, p.messages.saidBy(pane), "dropped") != null);
}
test "a bracketed paste larger than the ring still closes its bracket" {
diff --git a/core/Db.zig b/core/Db.zig
index eb8ee20c..4131ccbc 100644
--- a/core/Db.zig
+++ b/core/Db.zig
@@ -1424,7 +1424,7 @@ test "state file: Recent is read once from the file it replaced, else from the s
defer c.deinit();
try testing.expectEqual(@as(usize, 0), c.recent.entries.items.len);
const pane = c.panes[c.view().active].?;
- try testing.expect(std.mem.indexOf(u8, pane.msg[0..pane.msg_len], "Recent: the files before the state file were not read") != null);
+ try testing.expect(std.mem.indexOf(u8, c.messages.saidBy(pane), "Recent: the files before the state file were not read") != null);
}
// Both left where they were.
_ = try tmp.dir.statFile(testing.io, "old/recent", .{});
diff --git a/core/Effect.zig b/core/Effect.zig
index bf02c5b7..3bca04c9 100644
--- a/core/Effect.zig
+++ b/core/Effect.zig
@@ -346,7 +346,7 @@ test "Detach asks the host to let its terminal go, and says so when there is not
p.perform(.{ .detach = asked });
const pane = p.panes[0].?;
- try std.testing.expectEqualStrings("detach: not attached", pane.msg[0..pane.msg_len]);
+ try std.testing.expectEqualStrings("detach: not attached", p.messages.saidBy(pane));
try std.testing.expect(!p.quit);
}
diff --git a/core/File.zig b/core/File.zig
index 2affde32..18745930 100644
--- a/core/File.zig
+++ b/core/File.zig
@@ -2441,8 +2441,9 @@ pub fn changed(p: *Pardes, id: u8, bytes: []const u8) void {
if (f.disk_newer == disk) return;
f.disk_newer = disk;
f.disk_newer_warned = false;
- var said: pardes.Kind.Buf(limits.host_path_cap + 64) = .{};
- p.setMessage(.at(id), said.print("{s} changed on disk (get reloads it, Save overwrites it)", .{f.path[0..@min(f.path.len, limits.host_path_cap)]}));
+ // A question in its tag, never the keyboard's (pick-ui SPEC §10.2):
+ // one waiting already is the one about it.
+ if (p.messages.waiting(pane) == null) pardes.Messages.say(p, .question, id, "changed on disk").asks = .disk;
var rec: [16]u8 = undefined;
pardes.ctlfs.events.notePath(p, "changed", std.fmt.bufPrint(&rec, "{d}", .{pane.serial}) catch unreachable); // a u32 fits 16
return;
@@ -3526,7 +3527,7 @@ test "a text replaced whole keeps its old buffer for its undo, swapped back and
setContent(p, f, try gpa.dupe(u8, t));
}
try std.testing.expectEqual(@as(usize, 2), j.done);
- try std.testing.expect(std.mem.indexOf(u8, pane.msg[0..pane.msg_len], "undo keeps the last two texts replaced whole") != null);
+ try std.testing.expect(std.mem.indexOf(u8, p.messages.saidBy(pane), "undo keeps the last two texts replaced whole") != null);
try undoStep(p, pane, true);
try undoStep(p, pane, true);
try std.testing.expectEqualStrings(texts[1], f.content);
diff --git a/core/Jump.zig b/core/Jump.zig
index a4ecca04..b28698ee 100644
--- a/core/Jump.zig
+++ b/core/Jump.zig
@@ -158,7 +158,7 @@ const JumpsTest = struct {
try out.print("{s}{c}{d}", .{ if (out.end > 0) " " else "", letters[which], pane.body.cur_row + 1 });
} else return error.NoEnd;
const pane = t.p.panes[t.p.view().active].?;
- const said = pane.msg[0..pane.msg_len];
+ const said = t.p.messages.saidBy(pane);
try std.testing.expect(std.mem.indexOf(u8, said, if (delta < 0) "nothing further back" else "nothing further on") != null);
return out.buffered();
}
@@ -275,9 +275,10 @@ pub fn trackJump(p: *Pardes) void {
pub fn jumpBy(p: *Pardes, delta: i32) void {
const v = p.view();
// A reading pane's walk first (pick-ui SPEC §6.4). Past its newest
- // step, Ctrl-i is to step the Walk queue once the pickers make one;
- // until then, the jump list's.
+ // step, Ctrl-i steps the Walk queue a picker left (Pick.stepQueue);
+ // then the jump list's.
if (pardes.Trail.walkBy(p, v.active, delta)) return;
+ if (delta > 0 and pardes.Pick.stepQueue(p, v.active)) return;
const older = delta < 0;
// At an end of the list: said, not a step that silently does nothing.
if (v.jumps.n == 0 or (older and v.jumps.cur == 0) or (!older and v.jumps.cur + 1 >= v.jumps.n))
diff --git a/core/Kind.zig b/core/Kind.zig
index 764b6f06..4e1aa469 100644
--- a/core/Kind.zig
+++ b/core/Kind.zig
@@ -312,6 +312,9 @@ pub fn reopen(p: *Pardes, id: usize, s: *Slot, bytes: ?[]const u8) bool {
s.tail.len = @intCast(w.buffered().len);
}
s.opened = if (bytes) |b| std.hash.Wyhash.hash(0, b) else 0;
+ // A state made afresh is told every view afresh: the views told the
+ // one before (a file changed on disk, a Restore) are not its.
+ s.views = @splat(0);
// Its file not read (not here): it waits for it, a placeholder.
if (s.ops != null and bytes == null and s.path.len > 0) _ = cl.refused.print("{s} is not here", .{s.path}) else if (s.ops) |ops| {
const path_z = s.arena.allocator().dupeSentinel(u8, s.path, 0) catch "";
@@ -763,7 +766,7 @@ pub fn viewOf(p: *const Pardes, k: u8, id: usize) c.pa_view {
if (collapsed) return out;
// Its bands made again, never the copy a step or a park left: they are
// derived, so a client joined from a dump has none.
- const notices = pardes.Messages.bands(p, v, pane, tag_rows, r, id).span();
+ const notices = pardes.Messages.bands(p, pane, tag_rows, r).span();
const th = p.theme();
const rgb = struct {
fn f(x: [3]u8) u32 {
diff --git a/core/Layer.zig b/core/Layer.zig
index 4574aab7..43c8191c 100644
--- a/core/Layer.zig
+++ b/core/Layer.zig
@@ -16,12 +16,13 @@ const layout = @import("layout.zig");
const Layer = @This();
-/// `notice` is a pane's transient line -- a builtin's name, a pending leader
-/// chord -- carried as a tagline-shaped band so it gets the tagline's height,
+/// `notice` is a pane's transient line -- a prompt waiting for input --
+/// carried as a tagline-shaped band so it gets the tagline's height,
/// small-font metrics, band offset and border instead of being a body-grid row
/// wearing a tagline font.
/// `band` is the rows a pane's tag unrolls into below it (Band.zig).
-pub const Kind = enum(u8) { workspace, column, pane, notice, body, band };
+/// `notice_row` is the window's foot row, the live messages' index.
+pub const Kind = enum(u8) { workspace, column, pane, notice, body, band, notice_row };
pub const Metrics = struct {
body_w: u16 = 1,
diff --git a/core/Messages.zig b/core/Messages.zig
index 6b406e91..e2224337 100644
--- a/core/Messages.zig
+++ b/core/Messages.zig
@@ -1,6 +1,10 @@
-//! The message row: messages and statuses a pane shows between its body and
-//! its tagline, how each line lingers once dismissed, the notices
-//! built from them every frame, and the log of everything said.
+//! The session's messages (pick-ui SPEC §10): each a kind, its cause as a
+//! word a Look understands, its text, the places it names and the lines
+//! that explain it, kept in a fixed list while it lives; the log of
+//! everything said behind them (the history, `SPC h m`, and 9P `/log`);
+//! the notice row at the window's foot that indexes them; and the
+//! transient band a pane shows over its body's top rows (a prompt waiting
+//! for input).
const pardes = @import("root.zig");
const memory = @import("memory.zig");
const std = @import("std");
@@ -16,12 +20,14 @@ const BOX_H = pardes.BOX_H;
const Key = pardes.Key;
const Rect = layout.Rect;
const Pardes = pardes.Pardes;
+const Buf = pardes.Kind.Buf;
const Messages = @This();
/// Where its ring's next line goes and how many it holds, held to the ring
-/// where a dump is read back (walk.zig `.place`).
-pub const replica = .{ .place = .{ .{ "head", "lastSlot" }, .{ "len", "size" } } };
+/// where a dump is read back (walk.zig `.place`); the live messages as far
+/// as they go.
+pub const replica = .{ .place = .{ .{ "head", "lastSlot" }, .{ "len", "size" } }, .len = .{.{ "live", "live_len" }} };
/// The message-row log: a fixed ring, never allocated, never grown. See
/// `logMessage` and the `Messages` builtin.
@@ -29,6 +35,14 @@ log: [limits.message_log]LoggedMessage = @splat(.{}),
/// Next slot to write. `len` saturates at the ring's size.
head: usize = 0,
len: usize = 0,
+/// The messages that live, oldest first: what the notice row, the marks
+/// and the ghosts at a cause's line are drawn from each frame.
+live: [max_live]Said = undefined,
+live_len: u8 = 0,
+
+/// How many messages live at once: past it the oldest that is no
+/// question goes (a burst of distinct ones; a repeat only counts).
+pub const max_live = 16;
pub fn lastSlot(m: *const Messages) usize {
return m.log.len - 1;
@@ -38,6 +52,125 @@ pub fn size(m: *const Messages) usize {
return m.log.len;
}
+/// What a message is, which says how long it lives (SPEC §10.1): an echo
+/// and a notice until the next message, bright for `MessageLinger`; a
+/// warning bright twice that, until Esc; an error until Esc or the next
+/// error; a question until it is answered; progress while it runs, at the
+/// right end of its tag rather than on the notice row.
+pub const Kind = enum(u8) {
+ echo,
+ notice,
+ warn,
+ @"error",
+ question,
+ progress,
+
+ pub fn glyph(k: Kind) []const u8 {
+ return switch (k) {
+ .echo => "\u{2713}",
+ .notice => "\u{b7}",
+ .warn => "!",
+ .@"error" => "\u{2717}",
+ .question => "?",
+ .progress => "\u{22ef}",
+ };
+ }
+
+ /// Which wins the notice row and a mark: error, question, warning,
+ /// notice, echo; progress never.
+ pub fn rank(k: Kind) u8 {
+ return switch (k) {
+ .progress => 0,
+ .echo => 1,
+ .notice => 2,
+ .warn => 3,
+ .question => 4,
+ .@"error" => 5,
+ };
+ }
+};
+
+/// A place a message names: a file's line and column, and what it says
+/// there (a compiler's `error: ...`), which the body shows at that line.
+pub const Place = struct {
+ path: Buf(256) = .{},
+ line: u32 = 1,
+ col: u32 = 1,
+ text: Buf(128) = .{},
+};
+
+/// The questions the session asks in the background, and their answers.
+pub const Ask = enum(u8) {
+ none,
+ /// A file changed on disk under unsaved text.
+ disk,
+
+ /// Its answers, as its pane's tag offers them: the key that gives one,
+ /// and its word (an Exec of the word's first word gives it too).
+ pub fn answers(a: Ask) []const Answer {
+ return switch (a) {
+ .none => &.{},
+ .disk => &.{ .{ .key = 'r', .word = "Reload" }, .{ .key = 'k', .word = "Keep mine" }, .{ .key = 'd', .word = "Diff" } },
+ };
+ }
+};
+
+pub const Answer = struct { key: u8, word: []const u8 };
+
+/// One live message.
+pub const Said = struct {
+ pub const replica = .{ .len = .{ .{ "places", "places_len" }, .{ "detail", "detail_len" } } };
+ pub const max_places = 4;
+ pub const max_detail = 4;
+ kind: Kind = .notice,
+ /// Its cause, first, as a word a Look understands: a file's path, a
+ /// pane's `@pN` (and its command), a server's name.
+ src: Buf(96) = .{},
+ text: Buf(256) = .{},
+ places: [max_places]Place = undefined,
+ places_len: u8 = 0,
+ /// The lines that explain it, shown under its first place's line while
+ /// the caret is on it.
+ detail: [max_detail]Buf(128) = undefined,
+ detail_len: u8 = 0,
+ /// The serial of the pane it is about, 0 for none in particular.
+ pane: u32 = 0,
+ asks: Ask = .none,
+ /// Its detail shown under its first place's line whatever the caret
+ /// (a question's Diff).
+ open: bool = false,
+ /// How many times in a row it was said.
+ n: u16 = 1,
+ /// When it was last said, on the core's clock (`Pardes.clock.now_ns`).
+ t: u64 = 0,
+
+ /// Its words without the clock a host stamped on them (Message.stamp).
+ pub fn words(s: *const Said) []const u8 {
+ return Message.body(s.text.slice());
+ }
+
+ /// Whether it has dimmed: an echo or a notice past `linger_ms`, a
+ /// warning past twice that.
+ pub fn faded(s: *const Said, now_ns: u64, linger_ms: u16) bool {
+ const bright: u64 = switch (s.kind) {
+ .echo, .notice => linger_ms,
+ .warn => 2 * @as(u64, linger_ms),
+ else => return false,
+ };
+ return now_ns -| s.t >= bright * std.time.ns_per_ms;
+ }
+
+ /// Whether it is about `pane`: said of it, or naming its file (as its
+ /// cause or among its places).
+ pub fn about(s: *const Said, pane: *const Pane) bool {
+ if (s.pane != 0 and s.pane == pane.serial) return true;
+ const f = pane.file orelse return false;
+ if (std.mem.eql(u8, s.src.slice(), f.path)) return true;
+ for (s.places[0..s.places_len]) |*place| if (std.mem.eql(u8, place.path.slice(), f.path)) return true;
+ return false;
+ }
+};
+
pub const LoggedMessage = struct {
pub const cap = 256;
pub const replica = .{ .len = .{.{ "text", "len" }} };
@@ -50,22 +183,13 @@ pub const LoggedMessage = struct {
/// How many times in a row. Saturating: a key held down against the same
/// refusal is one event, not four hundred.
repeats: u16 = 0,
+ kind: Kind = .notice,
pub fn slice(m: *const LoggedMessage) []const u8 {
return m.text[0..m.len];
}
};
-/// The room the leader band's line takes (TagState.lastUsed): a leaf's
-/// key, word and summary (builtins.summary_max), and "(last used here)".
-pub const leader_room = 192;
-
-/// The leaf the current which-key level ran last, and what it does: the
-/// line under a rolled level (walk UI SPEC §3.7).
-fn leaderText(p: *const Pardes, buf: *[leader_room]u8) []const u8 {
- return pardes.TagState.lastUsed(p, p.view(), buf) orelse "";
-}
-
pub const Message = struct {
const libc = std.c;
const Tm = extern struct {
@@ -133,195 +257,504 @@ pub const Message = struct {
}
};
-/// A status updates the message line in place (a progress count does not
-/// pile up); a message is an event, and stacks.
+
+/// A status updates its line in place (a progress count does not pile up),
+/// and is not logged; a message is an event.
pub const setStatus = pardes.tape.taped(setStatusInner);
fn setStatusInner(p: *Pardes, id: Pane.Id, text: []const u8) void {
- showMessage(p, id.index(), text, false);
+ // No text: the pane's progress is over, and goes.
+ if (text.len == 0) {
+ const serial: u32 = if (id.index() < MAX_PANES) if (p.panes[id.index()]) |pane| pane.serial else 0 else 0;
+ const m = &p.messages;
+ for (m.live[0..m.live_len], 0..) |*s, i| if (s.kind == .progress and s.pane == serial) {
+ m.remove(i);
+ p.needs_frame = true;
+ break;
+ };
+ return;
+ }
+ _ = say(p, .progress, id.index(), text);
}
pub const setMessage = pardes.tape.taped(setMessageInner);
fn setMessageInner(p: *Pardes, id: Pane.Id, text: []const u8) void {
- logMessage(p, id.index(), text);
- showMessage(p, id.index(), text, true);
+ _ = say(p, .notice, id.index(), text);
}
-fn showMessage(p: *Pardes, id: usize, text: []const u8, stack: bool) void {
- if (id >= MAX_PANES) return;
- const pane = p.panes[id] orelse return;
+/// Say `text`, a message of `kind` about pane `id` (MAX_PANES and up:
+/// none in particular), its cause first: logged (progress is not), and
+/// live (`keep`); the message, for the places it names.
+pub fn say(p: *Pardes, kind: Kind, id: usize, text: []const u8) *Said {
+ if (kind != .progress) logMessage(p, id, kind, text);
+ const pane: ?*Pane = if (id < MAX_PANES and !p.fs.session_write) p.panes[id] else null;
+ var src: Buf(96) = .{};
+ if (pane) |cause| causeWord(cause, &src);
+ return keep(p, kind, if (pane) |cause| cause.serial else 0, src.slice(), text);
+}
+
+/// A pane as a message names its cause: a file's path (a kind's too), else
+/// `@pN` and the command it runs.
+fn causeWord(pane: *const Pane, out: *Buf(96)) void {
+ if (pane.file) |f| return out.set(f.path);
+ if (pane.addon) |k| if (k.path.len > 0) return out.set(k.path);
+ const line = pane.command orelse {
+ _ = out.print(config.pane_addr ++ "{d}", .{pane.serial});
+ return;
+ };
+ const first = line[0 .. std.mem.indexOfAny(u8, line, "\r\n") orelse line.len];
+ var cut = @min(first.len, 64);
+ while (cut < first.len and cut > 0 and first[cut] & 0xC0 == 0x80) cut -= 1;
+ _ = out.print(config.pane_addr ++ "{d} {s}", .{ pane.serial, first[0..cut] });
+}
+
+/// Make a message live, and return it (for its places and its detail):
+/// a new message retires every echo and notice, a new error the error
+/// before it; the same message again right after itself is counted. The
+/// list is in the order things were said.
+pub fn keep(p: *Pardes, kind: Kind, serial: u32, src: []const u8, text: []const u8) *Said {
+ const m = &p.messages;
+ p.needs_frame = true;
// One row of printable text: a language server's multi-line report
// reads as one line, and the cut never leaves half a glyph behind.
- var n: usize = @min(text.len, pane.msg.len);
+ var row: [256]u8 = undefined;
+ var n: usize = @min(text.len, row.len);
if (n < text.len) {
while (n > 0 and text[n] & 0xC0 == 0x80) n -= 1;
}
- const same = pane.msg_len == n and for (text[0..n], pane.msg[0..n]) |c, have| {
- if ((if (c < 0x20 or c == 0x7f) ' ' else c) != have) break false;
- } else true;
- // A new event moves the line on screen up the stack, where it keeps
- // its own timing, and falls in below it.
- // Only an event stacks on an event: an announcement or a status
- // stands in for whatever comes next.
- if (stack and pane.msg_len > 0 and !same and !pane.msg_announcement and !pane.msg_status)
- pane.pushOlderMessage();
- if (pane.msg_len == 0) pane.msg_slot = pane.freeMessageSlot();
- pane.msg_announcement = false;
- pane.msg_sent = false;
- pane.msg_status = !stack;
- for (text[0..n], pane.msg[0..n]) |c, *cell| cell.* = if (c < 0x20 or c == 0x7f) ' ' else c;
- pane.msg_len = @intCast(n);
- // The clock when it was said (the session clock is the last pump's,
- // and a 9P write after an idle hour would say it an hour ago).
- pane.msg_said_ms = p.tape.value(.clock, nowMs, .{});
- p.needs_frame = true;
- // New, the same line again or a status update: fresh, so it stays.
- pane.msg_life = .{};
+ for (text[0..n], row[0..n]) |c, *cell| cell.* = if (c < 0x20 or c == 0x7f) ' ' else c;
+ const line = row[0..n];
+ const now = p.clock.now_ns;
+ // Progress from the same cause is updated, and is the newest said.
+ if (kind == .progress) for (m.live[0..m.live_len], 0..) |*s, i| {
+ if (s.kind != .progress or s.pane != serial or !std.mem.eql(u8, s.src.slice(), src)) continue;
+ const kept = s.*;
+ m.remove(i);
+ const last = &m.live[m.live_len];
+ m.live_len += 1;
+ last.* = kept;
+ last.text.set(line);
+ last.t = now;
+ return last;
+ };
+ if (m.live_len > 0) {
+ // The NEWEST wording wins, so it carries the latest clock.
+ const last = &m.live[m.live_len - 1];
+ if (last.kind == kind and last.pane == serial and std.mem.eql(u8, last.src.slice(), src) and
+ std.mem.eql(u8, Message.body(last.text.slice()), Message.body(line)))
+ {
+ last.n +|= 1;
+ last.t = now;
+ last.text.set(line);
+ return last;
+ }
+ }
+ if (kind != .progress) {
+ var i: usize = 0;
+ while (i < m.live_len) {
+ const old = m.live[i].kind;
+ if (old == .echo or old == .notice or (kind == .@"error" and old == .@"error")) m.remove(i) else i += 1;
+ }
+ }
+ if (m.live_len == max_live) {
+ var oldest: usize = 0;
+ while (oldest + 1 < m.live_len and m.live[oldest].kind == .question) oldest += 1;
+ m.remove(oldest);
+ }
+ const s = &m.live[m.live_len];
+ m.live_len += 1;
+ s.* = .{ .kind = kind, .pane = serial, .t = now };
+ s.src.set(src);
+ s.text.set(line);
+ return s;
}
-/// With no frontend attached no input dismisses a message, and a detached
-/// session's /screen and messages kept what was said an hour ago: each
-/// pane's lines go once its newest has been up `message_linger_ms`, on the
-/// clock, checked as the core is stepped (each event, and each pump after
-/// its wait, which a message wakes) -- not as a 9P request is served, since
-/// a read is answered while a step is out and must change nothing, nor by
-/// the host, whose call is no input a replay makes.
-/// ponytail: a pane's older lines go with its newest, not each on its own
-/// clock; the render pipeline's clock will give every line its own.
-fn nowMs() i64 {
- var ts: std.c.timespec = undefined;
- if (std.c.clock_gettime(.MONOTONIC, &ts) != 0) return 0;
- return @as(i64, ts.sec) * 1000 + @divTrunc(@as(i64, ts.nsec), 1_000_000);
+pub fn remove(m: *Messages, i: usize) void {
+ std.mem.copyForwards(Said, m.live[i .. m.live_len - 1], m.live[i + 1 .. m.live_len]);
+ m.live_len -= 1;
}
-pub fn expireUnattended(p: *Pardes) void {
- if (!p.unattended) return;
- // The clock as the session that recorded read it (core/tape.zig).
- const now = p.tape.value(.clock, nowMs, .{});
- for (p.panes) |slot| {
- const pane = slot orelse continue;
- if (pane.msg_len == 0 and pane.msg_older_len == 0) continue;
- if (awaited(p, pane)) continue;
- if (now - pane.msg_said_ms < p.settings.message_linger_ms) continue;
- pane.msg_len = 0;
- pane.msg_life = .{};
- pane.msg_older_len = 0;
- p.needs_frame = true;
+/// Retire every live message of `kinds` (Esc: the warnings and errors);
+/// how many went.
+pub fn retire(m: *Messages, kinds: []const Kind) usize {
+ var gone: usize = 0;
+ var i: usize = 0;
+ while (i < m.live_len) {
+ if (std.mem.indexOfScalar(Kind, kinds, m.live[i].kind) != null) {
+ m.remove(i);
+ gone += 1;
+ } else i += 1;
}
+ return gone;
}
-/// A message waits for someone to see it, and a view kept for its client's
-/// return (views.away: an Upgrade's clients, a divergence's) is someone
-/// on the way: what its keyboard's pane says (an Upgrade's outcome,
-/// upgrade.zig `tellEveryView`) is that client's until it is back for its
-/// view (Pardes.rejoinView: its join's dump has it) or the view's kept
-/// time is up; no other view's input and no unattended clock take it. A
-/// pair's one client is such a client; the session's own frontend is
-/// none (its view is never away). A session no build could load starts
-/// afresh with no view kept: a pair's is held attended for its client
-/// instead (tui.zig `Own.start`).
-fn awaited(p: *const Pardes, pane: *const Pane) bool {
- if (p.views_away == 0) return false;
- for (p.views, 0..) |slot, k| if (slot) |v| {
- if (pardes.views.isAway(p, @intCast(k)) and p.panes[v.active] == pane and
- p.clock.now_ns -| v.away_ns < pardes.views.away_kept_ns) return true;
- };
- return false;
+/// The message the notice row leads with: the highest-ranked, the newest
+/// within a rank; progress never.
+pub fn headline(m: *const Messages) ?*const Said {
+ var best: ?*const Said = null;
+ for (m.live[0..m.live_len]) |*s| {
+ if (s.kind == .progress) continue;
+ if (best == null or s.kind.rank() >= best.?.kind.rank()) best = s;
+ }
+ return best;
}
-/// The key or click that used to clear the message row now starts each
-/// line's exit: it stays `message_linger_ms`, then goes. A line already
-/// on its way out keeps its own timing.
-pub fn dismissMessage(p: *Pardes, pane: *Pane) void {
- if (awaited(p, pane)) return;
- if (pane.msg_len > 0 and dismissLine(p, &pane.msg_life)) {
- pane.msg_len = 0;
- pane.msg_life = .{};
- }
- var i: usize = 0;
- while (i < pane.msg_older_len) {
- if (dismissLine(p, &pane.msg_older[i].life)) pane.removeOlderMessage(i) else i += 1;
+/// The kind a pane's mark shows, one cell after its box (SPEC §10.2): the
+/// most important live error, question, warning or progress about it (an
+/// echo or a notice marks nothing); null for none.
+pub fn markOf(m: *const Messages, pane: *const Pane) ?Kind {
+ var best: ?Kind = null;
+ for (m.live[0..m.live_len]) |*s| {
+ if (s.kind == .echo or s.kind == .notice or !s.about(pane)) continue;
+ if (best == null or s.kind.rank() > best.?.rank()) best = s.kind;
}
+ return best;
}
-/// Start one line's exit; true when it is gone at once (no linger).
-fn dismissLine(p: *const Pardes, life: *Pane.MessageLife) bool {
- if (life.phase == .lingering) return false;
- if (p.settings.message_linger_ms == 0) return true;
- life.* = .{ .phase = .lingering };
- return false;
+/// A kind's ink, for its glyph, its mark and its words at a line.
+pub fn ink(chrome: *const pardes.colors.ChromeTheme, kind: Kind) [3]u8 {
+ return switch (kind) {
+ .@"error" => chrome.diagnostic_error,
+ .warn => chrome.diagnostic_warning,
+ .question => chrome.diagnostic_info,
+ else => chrome.diagnostic_hint,
+ };
}
-/// One frame of every lingering message line. The one that goes owes a
-/// frame: a tick asks for none itself.
-pub fn advanceMessages(p: *Pardes) void {
- for (p.panes) |slot| {
- const pane = slot orelse continue;
- if (pane.msg_len > 0 and pane.msg_life.phase != .shown) {
- p.needs_frame = true;
- if (advanceLine(p, &pane.msg_life)) {
- pane.msg_len = 0;
- pane.msg_life = .{};
+/// The places a compiler's report names put on `s`: each
+/// `path:line:col: error|warning|note: words` row (a relative path is
+/// `dir`'s), its words there, and the rows after the first error, up to
+/// the next place, its detail. How many it found; none without an error.
+pub fn readPlaces(s: *Said, dir: []const u8, rows: []const []const u8) usize {
+ var errors: usize = 0;
+ var detailing = false;
+ for (rows) |raw| {
+ const row = std.mem.trimEnd(u8, raw, " \t\r\n");
+ const found = placeOf(row) orelse {
+ if (detailing and row.len > 0 and s.detail_len < Said.max_detail) {
+ s.detail[s.detail_len] = .{};
+ s.detail[s.detail_len].set(row);
+ s.detail_len += 1;
}
+ continue;
+ };
+ detailing = false;
+ const is_error = std.mem.startsWith(u8, found.text, "error");
+ if (is_error) {
+ detailing = errors == 0;
+ errors += 1;
}
- var i: usize = 0;
- while (i < pane.msg_older_len) {
- if (pane.msg_older[i].life.phase != .shown) p.needs_frame = true;
- if (advanceLine(p, &pane.msg_older[i].life)) pane.removeOlderMessage(i) else i += 1;
+ if (s.places_len == Said.max_places) continue;
+ const place = &s.places[s.places_len];
+ place.* = .{ .line = found.line, .col = found.col };
+ if (std.Io.Dir.path.isAbsolute(found.path)) place.path.set(found.path) else _ = place.path.print("{s}/{s}", .{ std.mem.trimEnd(u8, dir, "/"), found.path });
+ place.text.set(if (std.mem.startsWith(u8, found.text, "error: ")) found.text["error: ".len..] else found.text);
+ s.places_len += 1;
+ }
+ if (errors == 0) s.places_len = 0;
+ return s.places_len;
+}
+
+/// A compiler's place row: `path:line:col: error|warning|note...`.
+fn placeOf(row: []const u8) ?struct { path: []const u8, line: u32, col: u32, text: []const u8 } {
+ const a = std.mem.indexOfScalar(u8, row, ':') orelse return null;
+ const path = row[0..a];
+ if (path.len == 0 or std.mem.indexOfAny(u8, path, " \t") != null) return null;
+ var rest = row[a + 1 ..];
+ const b = std.mem.indexOfScalar(u8, rest, ':') orelse return null;
+ const line = std.fmt.parseInt(u32, rest[0..b], 10) catch return null;
+ rest = rest[b + 1 ..];
+ const c = std.mem.indexOfScalar(u8, rest, ':') orelse return null;
+ const col = std.fmt.parseInt(u32, rest[0..c], 10) catch return null;
+ const text = std.mem.trim(u8, rest[c + 1 ..], " ");
+ for ([_][]const u8{ "error", "warning", "note" }) |word| {
+ if (std.mem.startsWith(u8, text, word)) return .{ .path = path, .line = line, .col = col, .text = text };
+ }
+ return null;
+}
+
+/// The question waiting on `pane`, an index into `live`; null for none.
+pub fn waiting(m: *const Messages, pane: *const Pane) ?usize {
+ for (m.live[0..m.live_len], 0..) |*s, i| if (s.kind == .question and s.pane == pane.serial) return i;
+ return null;
+}
+
+/// The answers of the question waiting on `pane`: what a `:` lists first
+/// (pick-ui SPEC §10.4); none without one.
+pub fn waitingAnswers(m: *const Messages, pane: *const Pane) []const Answer {
+ const i = m.waiting(pane) orelse return &.{};
+ return m.live[i].asks.answers();
+}
+
+/// Answer live question `i` with `key`: `r` reads the file again over its
+/// unsaved text, `k` keeps the text and lets the disk's be, `d` shows (or
+/// hides again) the disk's lines where they differ, as ghosts in its
+/// body. False for a key that is none of its answers.
+pub fn answer(p: *Pardes, i: usize, key: u8) bool {
+ const m = &p.messages;
+ const s = &m.live[i];
+ const a = for (s.asks.answers()) |a| {
+ if (a.key == key) break a;
+ } else return false;
+ p.needs_frame = true;
+ const id = p.paneBySerial(s.pane) orelse {
+ m.remove(i);
+ return true;
+ };
+ var said: Buf(256) = .{};
+ if (key == 'd') {
+ if (s.open) {
+ s.open = false;
+ return true;
}
+ diskDiff(p, s, id);
+ return true;
+ }
+ logMessage(p, id, .echo, said.print("{s} {s} \u{b7} answered {s}", .{ s.src.slice(), s.words(), a.word }));
+ m.remove(i);
+ if (key == 'r') {
+ const pane = p.panes[id].?;
+ // The answer is the consent Get would ask for.
+ if (pane.file) |f| pane.discard_warned = .{ .revision = f.revision, .by = .get };
+ pardes.exec.runBuiltin(p, .Get, id, "", null);
+ } else _ = say(p, .echo, id, "kept yours; the disk's is not read");
+ return true;
+}
+
+/// SPC e (the Message word, SPEC §10.4), on the message the notice row
+/// leads with: an error that names places lands them as a list in pane
+/// `id`'s walk (Pick's `list`, its word `✗ <cause>` in the trail), the
+/// first landed on, n and N walking the rest, and the error goes (a
+/// +Search under the pane where jumps do not walk, or for a 9P script:
+/// Pick.asked); a question takes the keyboard in its pane's tag; anything
+/// else, or nothing, opens the history.
+pub fn act(p: *Pardes, id: usize) void {
+ const m = &p.messages;
+ const lead = m.headline() orelse return history(p, id);
+ if (lead.kind == .question) {
+ p.view().answering = lead.pane;
+ p.needs_frame = true;
+ return;
+ }
+ if (lead.kind != .@"error" or lead.places_len == 0 or id >= MAX_PANES) return history(p, id);
+ const pane = p.panes[id] orelse return;
+ var rows: std.Io.Writer.Allocating = .init(p.gpa);
+ errdefer rows.deinit();
+ for (lead.places[0..lead.places_len]) |*place| rows.writer.print("{s}:{d}:{d} {s}\n", .{ place.path.slice(), place.line, place.col, place.text.slice() }) catch |err| return reportError(p, .at(id), "Message", err);
+ const cause = lead.src;
+ const lead_at = for (m.live[0..m.live_len], 0..) |*s, k| {
+ if (s == lead) break k;
+ } else return;
+ m.remove(lead_at);
+ const content = rows.toOwnedSlice() catch |err| return reportError(p, .at(id), "Message", err);
+ if (pardes.Pick.asked(p)) {
+ defer p.gpa.free(content);
+ // The cause cut at a character's start to the word's room.
+ const src = cause.slice();
+ var cut = @min(src.len, 24 - "\u{2717} ".len);
+ while (cut > 0 and cut < src.len and src[cut] & 0xC0 == 0x80) cut -= 1;
+ var word: Buf(24) = .{};
+ pardes.Pick.open(p, id, .list, word.print("\u{2717} {s}", .{src[0..cut]}), "", content);
+ return pardes.Pick.landHere(p);
}
+ pardes.panes.Output.fillResults(p, id, pardes.panes.paneDir(pane), .search, cause.slice(), content, null) catch |err| return reportError(p, .at(id), "Message", err);
+ _ = @import("look.zig").searchStep(p, id, 1);
}
-/// One frame of one line's life; true once it has gone.
-fn advanceLine(p: *const Pardes, life: *Pane.MessageLife) bool {
- if (life.phase == .shown) return false;
- life.frame +|= 1;
- return life.frame >= messageFrames(p.settings.message_linger_ms);
+/// The history (SPC h m, the Messages word; SPC e with nothing to act on):
+/// where jumps walk a picker over it in pane `id`'s tag (Pick's
+/// `messages`), the newest first, Enter Looking a row, C-q keeping it as
+/// a +Messages; else (or for a 9P script, Pick.asked) the +Messages.
+pub fn history(p: *Pardes, id: usize) void {
+ if (pardes.Pick.asked(p) and id < MAX_PANES and p.panes[id] != null) return pardes.Pick.open(p, id, .messages, "", "", "");
+ pardes.panes.Output.openMessages(p, id) catch |err| reportError(p, .at(id), "messages", err);
+}
+
+/// An Exec of an answer's word in the tag of a pane a question waits on
+/// (B2 on `Reload`): that answer. False for any other word.
+pub fn answerWord(p: *Pardes, id: usize, word: []const u8) bool {
+ if (id >= MAX_PANES) return false;
+ const pane = p.panes[id] orelse return false;
+ const i = p.messages.waiting(pane) orelse return false;
+ const typed = std.mem.trim(u8, word, " \t\r\n");
+ for (p.messages.live[i].asks.answers()) |a| {
+ const first = a.word[0 .. std.mem.indexOfScalar(u8, a.word, ' ') orelse a.word.len];
+ if (std.mem.eql(u8, typed, first)) return answer(p, i, a.key);
+ }
+ return false;
}
-/// Move every lingering message line `frames` along its linger at once:
-/// how `advance` jumps a wait instead of stepping it frame by frame.
-pub fn holdMessages(p: *Pardes, frames: u64) void {
- const n: u16 = @intCast(@min(frames, std.math.maxInt(u16)));
- for (p.panes) |slot| {
- const pane = slot orelse continue;
- if (pane.msg_len > 0 and pane.msg_life.phase == .lingering) pane.msg_life.frame +|= n;
- for (pane.msg_older[0..pane.msg_older_len]) |*line| {
- if (line.life.phase == .lingering) line.life.frame +|= n;
+/// A question's Diff: the disk's text read (the host's read, taped) and
+/// set against the buffer's, the lines they share at either end left out;
+/// where they part, its place, and up to `Said.max_detail` of the lines
+/// there, the disk's `+` and then the buffer's `-`, its detail, shown.
+fn diskDiff(p: *Pardes, s: *Said, id: usize) void {
+ const pane = p.panes[id].?;
+ const f = if (pane.file) |*file| file else return;
+ const disk = @import("fs.zig").read(p, f.path) catch |err| return pardes.Messages.reportError(p, .at(id), "Diff", err);
+ defer p.gpa.free(disk);
+ const mine = pardes.panes.File.fileText(f, p.scratch.allocator()) catch return;
+ var a = std.mem.splitScalar(u8, mine, '\n');
+ var b = std.mem.splitScalar(u8, disk, '\n');
+ var line: u32 = 1;
+ var ours: []const u8 = "";
+ var theirs: []const u8 = "";
+ while (true) : (line += 1) {
+ const x = a.next();
+ const y = b.next();
+ if (x == null and y == null) return;
+ if (x != null and y != null and std.mem.eql(u8, x.?, y.?)) continue;
+ ours = if (x) |l| mine[@intFromPtr(l.ptr) - @intFromPtr(mine.ptr) ..] else "";
+ theirs = if (y) |l| disk[@intFromPtr(l.ptr) - @intFromPtr(disk.ptr) ..] else "";
+ break;
+ }
+ // The lines both end with, left out.
+ var ours_end = ours.len;
+ var theirs_end = theirs.len;
+ while (ours_end > 0 and theirs_end > 0) {
+ const ol = std.mem.lastIndexOfScalar(u8, ours[0 .. ours_end - 1], '\n');
+ const tl = std.mem.lastIndexOfScalar(u8, theirs[0 .. theirs_end - 1], '\n');
+ const o_line = ours[if (ol) |nl| nl + 1 else 0..ours_end];
+ const t_line = theirs[if (tl) |nl| nl + 1 else 0..theirs_end];
+ if (!std.mem.eql(u8, o_line, t_line)) break;
+ ours_end = if (ol) |nl| nl + 1 else 0;
+ theirs_end = if (tl) |nl| nl + 1 else 0;
+ }
+ s.places[0] = .{ .line = line, .col = 1 };
+ s.places[0].path.set(f.path);
+ s.places[0].text.set("the disk's differs here");
+ s.places_len = 1;
+ s.detail_len = 0;
+ // The disk's first: it is what the answer shows.
+ for ([_]struct { []const u8, []const u8 }{ .{ "+", theirs[0..theirs_end] }, .{ "-", ours[0..ours_end] } }) |side| {
+ var rows = std.mem.splitScalar(u8, std.mem.trimEnd(u8, side[1], "\n"), '\n');
+ while (rows.next()) |row| {
+ if (side[1].len == 0 or s.detail_len == Said.max_detail) break;
+ s.detail[s.detail_len] = .{};
+ _ = s.detail[s.detail_len].print("{s}{s}", .{ side[0], row });
+ s.detail_len += 1;
}
}
+ s.open = true;
}
-/// Frames until this pane's message lines next change: the rest of a
-/// linger, null when every line just shows.
-pub fn messageWake(p: *const Pardes, pane: *const Pane) ?u64 {
+/// The words the newest live message said of `pane` has, "" for none:
+/// what its band shows, and what a write that failed on it answers.
+pub fn saidBy(m: *const Messages, pane: *const Pane) []const u8 {
+ var i = m.live_len;
+ while (i > 0) {
+ i -= 1;
+ if (m.live[i].pane == pane.serial) return m.live[i].text.slice();
+ }
+ return "";
+}
+
+/// When the next live message dims, on the core's clock; null for none.
+pub fn dimDue(p: *const Pardes) ?u64 {
+ const m = &p.messages;
+ if (p.settings.message_linger_ms == 0) return null;
var soonest: ?u64 = null;
- const linger = messageFrames(p.settings.message_linger_ms);
- for (0..@as(usize, pane.msg_older_len) + 1) |i| {
- const life = if (i < pane.msg_older_len) pane.msg_older[i].life else if (pane.msg_len > 0) pane.msg_life else continue;
- if (life.phase == .shown) continue;
- const frames: u64 = @max(1, linger -| life.frame);
- soonest = if (soonest) |n| @min(n, frames) else frames;
+ for (m.live[0..m.live_len]) |*s| {
+ const bright: u64 = switch (s.kind) {
+ .echo, .notice => p.settings.message_linger_ms,
+ .warn => 2 * @as(u64, p.settings.message_linger_ms),
+ else => continue,
+ };
+ const due = s.t + bright * std.time.ns_per_ms;
+ if (due <= p.clock.stepped_ns) continue;
+ soonest = if (soonest) |first| @min(first, due) else due;
}
return soonest;
}
-/// Frames a message timing lasts; at least one.
-pub fn messageFrames(ms: u16) u16 {
- return @intCast(@max(1, (@as(u32, ms) + pardes.frame_ms - 1) / pardes.frame_ms));
+/// The notice row's line (SPEC §10.3), `width` columns: on the left the
+/// message the row leads with (`headline`), its glyph, its cause, its
+/// words, `×n` and the places it names; on the right how many more live,
+/// the questions waiting, or the way to the history. With nothing live the
+/// left says where the focused pane's caret is. Built each frame from the
+/// state, in `out`.
+pub const Row = struct {
+ /// The left part's end and the right part's start, in bytes of `text`.
+ left: usize = 0,
+ right: usize = 0,
+ text: []const u8 = "",
+ /// The message the left says, when it says one.
+ lead: ?*const Said = null,
+};
+
+/// Room for the notice row's line: the widest window's at the tagline's
+/// pitch (Layer.capacity) is cut to it.
+pub const notice_row_cap = 1024;
+
+pub fn noticeRow(p: *const Pardes, width: usize, out: *[notice_row_cap]u8) Row {
+ const m = &p.messages;
+ const tab = p.settings.tab;
+ // A rolled level's last leaf, while the level shows: what it does, the
+ // whole row (SPEC §3.7's first mockup).
+ if (pardes.TagState.lastUsed(p, p.view(), out)) |used| {
+ var end = @min(used.len, panes.File.rawAtDisplay(tab, used, width));
+ while (end > 0 and panes.File.displayWidth(tab, used[0..end]) > width) end -= 1;
+ while (end > 0 and end < used.len and used[end] & 0xC0 == 0x80) end -= 1;
+ return .{ .left = end, .right = end, .text = used[0..end] };
+ }
+ var w: std.Io.Writer = .fixed(out);
+ var live: usize = 0;
+ var questions: usize = 0;
+ for (m.live[0..m.live_len]) |*s| {
+ if (s.kind == .progress) continue;
+ live += 1;
+ if (s.kind == .question) questions += 1;
+ }
+ const lead = m.headline();
+ if (lead) |s| {
+ w.print("{s} ", .{s.kind.glyph()}) catch {};
+ // Its cause first, unless its words name it already.
+ const words = s.words();
+ if (s.src.len > 0 and std.mem.indexOf(u8, words, s.src.slice()) == null) w.print("{s} ", .{s.src.slice()}) catch {};
+ w.writeAll(words) catch {};
+ if (s.n > 1) w.print(" \u{d7}{d}", .{s.n}) catch {};
+ for (s.places[0..s.places_len], 0..) |*place, i| w.print("{s} {s}:{d}:{d}", .{ if (i > 0) " \u{b7}" else "", place.path.slice(), place.line, place.col }) catch {};
+ } else if (p.panes[p.view().active]) |pane| {
+ if (pane.file) |f| w.print("{s}:{d}", .{ f.path, pane.body.cur_row + 1 }) catch {} else w.writeAll(pane.cwdSlice()) catch {};
+ }
+ const left_end = w.end;
+ var right: [64]u8 = undefined;
+ var r: std.Io.Writer = .fixed(&right);
+ if (live > 1) r.print("+{d} \u{b7} ", .{live - 1}) catch {};
+ if (questions > 0)
+ r.print("{d} question{s} \u{b7} SPC e", .{ questions, if (questions == 1) "" else "s" }) catch {}
+ else if (lead != null and lead.?.kind == .@"error" and lead.?.places_len > 0)
+ r.writeAll("SPC e walk") catch {}
+ else if (m.len > 0)
+ r.print("{d} message{s} \u{b7} SPC h m", .{ m.len, if (m.len == 1) "" else "s" }) catch {};
+ const tail = r.buffered();
+ // The left cut to make room for the right, a blank between them.
+ const tail_w = panes.File.displayWidth(tab, tail);
+ const room = width -| (tail_w + 1);
+ var cut = left_end;
+ if (panes.File.displayWidth(tab, out[0..cut]) > room) {
+ cut = panes.File.rawAtDisplay(tab, out[0..left_end], room);
+ while (cut > 0 and panes.File.displayWidth(tab, out[0..cut]) > room) {
+ cut -= 1;
+ while (cut > 0 and out[cut] & 0xC0 == 0x80) cut -= 1;
+ }
+ }
+ w.end = cut;
+ const gap = width -| (panes.File.displayWidth(tab, out[0..cut]) + tail_w);
+ for (0..gap) |_| w.writeByte(' ') catch {};
+ const right_at = w.end;
+ w.writeAll(tail) catch {};
+ return .{ .left = cut, .right = right_at, .text = w.buffered(), .lead = lead };
}
/// What notice band `i` says. The grid pass and the band layers both
/// read it here, so a terminal and a pixel shell show the same line.
-pub fn noticeText(p: *const Pardes, pane: *const Pane, i: usize, leader_buf: *[leader_room]u8) []const u8 {
+pub fn noticeText(pane: *const Pane, i: usize) []const u8 {
return switch (pane.notices.kinds[i]) {
- .message => pane.msg[0..pane.msg_len],
- .older => pane.msg_older[pane.notices.index[i]].slice(),
- .leader => leaderText(p, leader_buf),
.prompt => pane.promptText() orelse "",
};
}
-fn logMessage(p: *Pardes, id: usize, text: []const u8) void {
+fn logMessage(p: *Pardes, id: usize, kind: Kind, text: []const u8) void {
if (text.len == 0) return;
const serial: u32 = if (p.fs.session_write) 0 else if (id < MAX_PANES) if (p.panes[id]) |pane| pane.serial else 0 else 0;
const kept = text[0..@min(text.len, LoggedMessage.cap)];
@@ -345,6 +778,7 @@ fn logMessage(p: *Pardes, id: usize, text: []const u8) void {
@memcpy(slot.text[0..slot.len], kept);
slot.serial = serial;
slot.repeats = 1;
+ slot.kind = kind;
p.messages.head = (p.messages.head + 1) % limits.message_log;
p.messages.len = @min(p.messages.len + 1, limits.message_log);
}
@@ -474,17 +908,23 @@ pub fn reportFailure(p: *Pardes, id: usize, text: []const u8) void {
if (failing_write) {
p.fs.unlogged = true;
defer p.fs.unlogged = false;
- return setMessage(p, .at(id), text);
+ _ = say(p, .@"error", id, text);
+ return;
}
- setMessage(p, .at(id), text);
+ _ = say(p, .@"error", id, text);
}
/// The one place that decides which transient lines a pane is showing and
/// in what order. Everything downstream reads the answer: the body layer
/// so it does not paint under them, and the paint pass so it can stack
/// them instead of letting the last one win the row.
-pub fn collectNotices(p: *Pardes, pane: *Pane, r: Rect, id: usize) void {
- pane.notices = bands(p, p.view(), pane, pane.tag_rows, r, id);
+pub fn collectNotices(p: *Pardes, pane: *Pane, r: Rect) void {
+ pane.notices = bands(p, pane, pane.tag_rows, r);
+ // A message's detail under the caret's line, where the body draws it
+ // and a click's row is read (Pane.textRow): the step's, as the bands.
+ const under = if (r.h > pane.tag_rows) detailUnder(p, pane, p.panes[p.view().active] == pane, r.h - pane.tag_rows) else null;
+ pane.ghost_at = if (under) |d| d.row else 0;
+ pane.ghost_rows = if (under) |d| d.rows else 0;
// Each band's chip at the right edge, as wide as its own text and a
// blank cell either side, the pane's width at most: a click finds it
// whether or not a frame has drawn it. An overlay over the body's top
@@ -493,25 +933,41 @@ pub fn collectNotices(p: *Pardes, pane: *Pane, r: Rect, id: usize) void {
// draws, and a chip narrower than its text there would clip it.
const tx = r.x + config.GUTTER;
const tw = r.w -| config.GUTTER;
- var leader_buf: [leader_room]u8 = undefined;
for (0..pane.notices.len) |i| {
- const chip = panes.File.displayWidth(p.settings.tab, noticeText(p, pane, i, &leader_buf)) + 2;
+ const chip = panes.File.displayWidth(p.settings.tab, noticeText(pane, i)) + 2;
pane.notices.left[i] = if (tw == 0) std.math.maxInt(u16) else tx + tw - @as(u16, @intCast(@min(chip, tw)));
}
}
-/// The bands pane `id` shows in view `v`, over `r` below its `tag_rows`:
-/// the live view's each step, and any view's for its kind's facts
-/// (Kind.viewOf), made from what a dump keeps (the bands are derived).
-pub fn bands(p: *const Pardes, v: *const Pardes.View, pane: *const Pane, tag_rows: u16, r: Rect, id: usize) Pane.Notices {
+/// A message's detail under the caret's line (SPEC §10.2), as a body of
+/// `body_h` rows shows it: the row of that line's last row, how many of the
+/// detail's lines fit under it, the message (the first naming the line, as
+/// the words after it are); only in the pane with the keyboard, in its body.
+/// Bounded by the live messages' places and the rows shown.
+pub fn detailUnder(p: *const Pardes, pane: *Pane, active: bool, body_h: u16) ?struct { row: u16, rows: u16, said: *const Said } {
+ if (!active or pane.focus != .body or p.messages.live_len == 0) return null;
+ const f = pane.file orelse return null;
+ const caret = @max(0, pane.body.cur_row);
+ const said = found: for (p.messages.live[0..p.messages.live_len]) |*s| {
+ for (s.places[0..s.places_len]) |*place| if (place.line == caret + 1 and std.mem.eql(u8, place.path.slice(), f.path)) break :found s;
+ } else return null;
+ if (said.detail_len == 0) return null;
+ var row: u16 = 0;
+ while (row < body_h) : (row += 1) {
+ if (pane.wrapAt(p.settings.tab, row).line != caret) continue;
+ if (row + 1 < body_h and pane.wrapAt(p.settings.tab, row + 1).line == caret) continue;
+ const k: u16 = @intCast(@min(said.detail_len, body_h - row - 1));
+ return if (k == 0) null else .{ .row = row, .rows = k, .said = said };
+ }
+ return null;
+}
+
+/// The bands a pane shows over `r` below its `tag_rows`: the live view's
+/// each step, and any view's for its kind's facts (Kind.viewOf), made from
+/// what a dump keeps (the bands are derived).
+pub fn bands(p: *const Pardes, pane: *const Pane, tag_rows: u16, r: Rect) Pane.Notices {
var n: Pane.Notices = .{};
if (r.w <= config.GUTTER or r.h <= tag_rows) return n;
- // Oldest message line on top, so lines already up do not move when a
- // new one lands under them; when rows run out the oldest go first.
- for (pane.msg_older[0..pane.msg_older_len], 0..) |line, i| n.pushAt(.older, @intCast(i), line.slot);
- if (pane.msg_len > 0) n.pushAt(.message, 0, pane.msg_slot);
- var used_buf: [leader_room]u8 = undefined;
- if (id == v.active and pardes.TagState.lastUsed(p, v, &used_buf) != null) n.push(.leader);
// Del's question shows once its delay is up: answered before that, it
// was never there.
const del_waiting = pane.prompt == .del_side and pane.question_due_ns > p.clock.now_ns;
@@ -522,28 +978,18 @@ pub fn bands(p: *const Pardes, v: *const Pardes.View, pane: *const Pane, tag_row
// into blind. A two-row pane spends its only body row on one notice,
// which is what the single shared row used to do anyway.
const room: u8 = @intCast(@min(@as(u16, Pane.Notices.max), r.h - tag_rows));
- if (n.span() <= room) return n;
- // Too short for the gaps: close them up in screen order, and if even
- // that does not fit, the top bands go.
- var i: usize = 1;
- while (i < n.len) : (i += 1) {
- var j = i;
- while (j > 0 and n.row[j - 1] > n.row[j]) : (j -= 1) {
- std.mem.swap(Pane.Notices.Kind, &n.kinds[j - 1], &n.kinds[j]);
- std.mem.swap(u8, &n.index[j - 1], &n.index[j]);
- std.mem.swap(u8, &n.row[j - 1], &n.row[j]);
- }
- }
- const drop = n.len -| room;
- for (0..n.len - drop) |k| {
+ if (n.len <= room) return n;
+ // Too short for them all: the top bands go.
+ const drop = n.len - room;
+ for (0..room) |k| {
n.kinds[k] = n.kinds[k + drop];
- n.index[k] = n.index[k + drop];
n.row[k] = @intCast(k);
}
- n.len -= @intCast(drop);
+ n.len = room;
return n;
}
+
test "errors are said in words, and a ZON failure names its line" {
var buf: [128]u8 = undefined;
try std.testing.expectEqualStrings("file not found", errorWords(error.FileNotFound, &buf));
@@ -605,180 +1051,87 @@ test "the message log keeps what the row forgets, and collapses repeats" {
try std.testing.expectEqualStrings(want_last, p.messages.at(limits.message_log - 1).?.slice());
}
-test "Msg writes the transient row by hand, bare or with text, and input ends it" {
+test "Msg says a notice by hand, bare or with text, and the next message retires it" {
if (pardes.Term.ops == null) return error.SkipZigTest; // the classic boot's three shells
const p = try Pardes.init(std.testing.allocator, .{ .shells = 3, .cols = 100, .rows = 30 });
defer p.deinit();
while (p.nextEffect()) |_| {}
- const row = struct {
- fn of(pp: *Pardes, i: usize) []const u8 {
- const pane = pp.panes[i].?;
- return pane.msg[0..pane.msg_len];
- }
- }.of;
-
// the whole tail, spaces and all: the row is a sentence, not a word
try std.testing.expect(p.executeBuiltinLine(2, "Msg saved /etc/hosts"));
- try std.testing.expectEqualStrings("saved /etc/hosts", row(p, 2));
- // ...on the pane that ran it, and nowhere else
- try std.testing.expectEqualStrings("", row(p, 0));
-
+ try std.testing.expectEqualStrings("saved /etc/hosts", p.messages.saidBy(p.panes[2].?));
+ // ...of the pane that ran it, its cause that pane's address
+ try std.testing.expectEqualStrings("", p.messages.saidBy(p.panes[0].?));
+ var want: [16]u8 = undefined;
+ try std.testing.expectEqualStrings(try std.fmt.bufPrint(&want, "@p{d}", .{p.panes[2].?.serial}), p.messages.headline().?.src.slice());
// Bare, it reports ITSELF through reportError — the `<operation>: <error in words>`
- // every failed save and refused Look arrives in.
+ // every failed save and refused Look arrives in: an error.
try std.testing.expect(p.executeBuiltinLine(2, "Msg"));
- try std.testing.expectEqualStrings("Msg: no message", row(p, 2));
-
- // Input starts its exit: it lingers, and is gone.
- p.update(.{ .key = .{ .cp = Key.escape } });
- try std.testing.expectEqualStrings("Msg: no message", row(p, 2));
- for (0..200) |_| p.update(.tick);
- try std.testing.expectEqualStrings("", row(p, 2));
- // ...and with no linger it is as old as your last input.
- try std.testing.expect(p.executeBuiltinLine(2, "MessageLinger 0"));
- try std.testing.expect(p.executeBuiltinLine(2, "Msg gone"));
+ try std.testing.expectEqualStrings("Msg: no message", p.messages.saidBy(p.panes[2].?));
+ try std.testing.expectEqual(Kind.@"error", p.messages.headline().?.kind);
+ // Input takes nothing away; the next message does what the notice
+ // was, and the error stays until Esc.
p.update(.{ .key = .{ .cp = 'h' } });
- try std.testing.expectEqualStrings("", row(p, 2));
+ for (0..200) |_| p.update(.tick);
+ try std.testing.expectEqualStrings("Msg: no message", p.messages.saidBy(p.panes[2].?));
+ try std.testing.expect(p.executeBuiltinLine(2, "Msg next"));
+ try std.testing.expectEqual(@as(u8, 2), p.messages.live_len);
+ try std.testing.expectEqual(Kind.@"error", p.messages.headline().?.kind);
- // Longer than the row's buffer is CUT, never refused and never overrun:
+ // Longer than a message's room is CUT, never refused and never overrun:
// this word is the only way to reach that boundary without a 300-byte path.
var long: [600]u8 = @splat('x');
var line: [608]u8 = undefined;
const cmd = try std.fmt.bufPrint(&line, "Msg {s}", .{&long});
try std.testing.expect(p.executeBuiltinLine(2, cmd));
- try std.testing.expectEqual(p.panes[2].?.msg.len, row(p, 2).len);
+ try std.testing.expectEqual(@as(usize, 256), p.messages.saidBy(p.panes[2].?).len);
}
-test "with no frontend attached a message goes once it has lingered, on the clock" {
- const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true });
+test "an echo or a notice retires those before it, an error the error before it, a repeat counts and progress runs in place" {
+ const p = try Pardes.init(std.testing.allocator, .{ .cols = 80, .rows = 24 });
defer p.deinit();
- const pane = p.panes[p.view().active].?;
- p.setMessage(.at(p.view().active), "said");
- p.setMessage(.at(p.view().active), "said again");
- // Attached: it waits for input, however long.
- pane.msg_said_ms -= 60_000;
- p.update(.tick);
- try std.testing.expect(pane.msg_len > 0);
- // Detached with nobody attached: past its linger it is gone, and the
- // line above it with it.
- p.unattended = true;
- // A read served meanwhile changes nothing; the session's step after its
- // wait expires, not the host (whose call no replay makes).
- _ = p.serveFs(.{ .tag = 1, .op = .read, .node = @backingInt(ctlfs.TopFile.index), .size = 64 });
- try std.testing.expect(pane.msg_len > 0);
- try p.pump(.{});
- try std.testing.expectEqual(@as(u16, 0), pane.msg_len);
- try std.testing.expectEqual(@as(u8, 0), pane.msg_older_len);
- // A fresh one stays until its linger is up.
- p.setMessage(.at(p.view().active), "fresh");
- p.update(.tick);
- try std.testing.expect(pane.msg_len > 0);
-}
-
-test "a message lingers past the input that dismisses it, and goes" {
- const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 80, .rows = 24 });
- defer p.deinit();
- while (p.nextEffect()) |_| {}
- const pane = p.panes[p.view().active].?;
- try std.testing.expect(p.executeBuiltinLine(p.view().active, "MessageLinger 160"));
- try std.testing.expect(p.executeBuiltinLine(p.view().active, "Msg hello"));
- // Shown at once, until input; the same line again stays shown.
- try std.testing.expectEqual(Pane.MessagePhase.shown, pane.msg_life.phase);
- try std.testing.expect(!p.animationActive());
- for (0..100) |_| p.update(.tick);
- try std.testing.expectEqual(Pane.MessagePhase.shown, pane.msg_life.phase);
- try std.testing.expect(p.executeBuiltinLine(p.view().active, "Msg hello"));
- try std.testing.expectEqual(Pane.MessagePhase.shown, pane.msg_life.phase);
- // Input (a key that announces nothing): 160 ms of lingering (ten frames), unaffected by more input...
- p.update(.{ .key = .{ .cp = 'h' } });
- try std.testing.expectEqual(Pane.MessagePhase.lingering, pane.msg_life.phase);
- for (0..9) |_| {
- p.update(.tick);
- p.update(.{ .key = .{ .cp = 'h' } });
+ _ = try p.setTestFile("text\n");
+ const id = p.view().active;
+ const m = &p.messages;
+ m.live_len = 0;
+ _ = say(p, .notice, id, "first");
+ _ = say(p, .echo, id, "second");
+ try std.testing.expectEqual(@as(u8, 1), m.live_len);
+ try std.testing.expectEqualStrings("second", m.headline().?.text.slice());
+ _ = say(p, .@"error", id, "broke");
+ _ = say(p, .warn, id, "careful");
+ // The echo went with the error; the warning stands beside it.
+ try std.testing.expectEqual(@as(u8, 2), m.live_len);
+ try std.testing.expectEqual(Kind.@"error", m.headline().?.kind);
+ _ = say(p, .@"error", id, "broke again");
+ try std.testing.expectEqual(@as(u8, 2), m.live_len);
+ try std.testing.expectEqualStrings("broke again", m.headline().?.text.slice());
+ // The same again right after itself: one message, counted, its newest
+ // wording (and clock) kept.
+ for (0..9) |_| _ = say(p, .@"error", id, "broke again");
+ try std.testing.expectEqual(@as(u8, 2), m.live_len);
+ try std.testing.expectEqual(@as(u16, 10), m.headline().?.n);
+ // Progress updates its line in place and retires nothing.
+ _ = say(p, .progress, id, "Changes: jj 1/4");
+ _ = say(p, .progress, id, "Changes: jj 3/4");
+ try std.testing.expectEqual(@as(u8, 3), m.live_len);
+ try std.testing.expectEqualStrings("Changes: jj 3/4", m.saidBy(p.panes[id].?));
+ try std.testing.expectEqual(Kind.@"error", m.headline().?.kind);
+ // Esc in normal mode takes the warnings and errors.
+ p.update(.{ .key = .{ .cp = Key.escape } });
+ try std.testing.expectEqual(@as(u8, 1), m.live_len);
+ try std.testing.expectEqual(Kind.progress, m.live[0].kind);
+ try std.testing.expect(m.headline() == null);
+ // Past the room, the oldest that is no question goes.
+ m.live_len = 0;
+ for (0..max_live + 3) |i| {
+ var buf: [16]u8 = undefined;
+ _ = say(p, .warn, id, std.fmt.bufPrint(&buf, "w{d}", .{i}) catch unreachable);
}
- try std.testing.expectEqual(Pane.MessagePhase.lingering, pane.msg_life.phase);
- // ...then it is gone, and the tick that clears it owes the frame that
- // shows it gone.
- p.needs_frame = false;
- p.update(.tick);
- try std.testing.expectEqual(@as(u16, 0), pane.msg_len);
- try std.testing.expect(p.needs_frame);
- try std.testing.expect(!p.animationActive());
- // Shown again while lingering: fresh, so it stays; a status update to a
- // line on screen swaps its text in place.
- try std.testing.expect(p.executeBuiltinLine(p.view().active, "Msg again"));
- p.update(.{ .key = .{ .cp = 'h' } });
- try std.testing.expectEqual(Pane.MessagePhase.lingering, pane.msg_life.phase);
- try std.testing.expect(p.executeBuiltinLine(p.view().active, "Msg again"));
- try std.testing.expectEqual(Pane.MessagePhase.shown, pane.msg_life.phase);
- setStatus(p, .at(p.view().active), "progress 50%");
- try std.testing.expectEqual(Pane.MessagePhase.shown, pane.msg_life.phase);
- try std.testing.expectEqualStrings("progress 50%", pane.msg[0..pane.msg_len]);
- try std.testing.expectEqual(@as(u8, 0), pane.msg_older_len);
-}
-
-test "messages stack, oldest on top, each on its own timing" {
- const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 80, .rows = 24 });
- defer p.deinit();
- while (p.nextEffect()) |_| {}
- const pane = p.panes[p.view().active].?;
- try std.testing.expect(p.executeBuiltinLine(p.view().active, "Verbose off"));
- try std.testing.expect(p.executeBuiltinLine(p.view().active, "MessageLinger 160"));
- // `Verbose off` announced itself before it took effect.
- pane.msg_len = 0;
- pane.msg_life = .{};
- setMessage(p, .at(p.view().active), "first");
- try std.testing.expectEqual(Pane.MessagePhase.shown, pane.msg_life.phase);
- // A second message stacks under the first instead of replacing it.
- setMessage(p, .at(p.view().active), "second");
- try std.testing.expectEqual(@as(u8, 1), pane.msg_older_len);
- try std.testing.expectEqualStrings("first", pane.msg_older[0].slice());
- try std.testing.expectEqualStrings("second", pane.msg[0..pane.msg_len]);
- collectNotices(p, pane, p.view().rects[p.view().active], p.view().active);
- try std.testing.expectEqual(Pane.Notices.Kind.older, pane.notices.kinds[0]);
- try std.testing.expectEqual(Pane.Notices.Kind.message, pane.notices.kinds[1]);
- // One key dismisses both, each on its own clock: a line already
- // lingering keeps its timing.
- p.update(.{ .key = .{ .cp = 'h' } });
- try std.testing.expectEqual(Pane.MessagePhase.lingering, pane.msg_older[0].life.phase);
- try std.testing.expectEqual(Pane.MessagePhase.lingering, pane.msg_life.phase);
- p.update(.tick);
- setMessage(p, .at(p.view().active), "third");
- try std.testing.expectEqual(@as(u8, 2), pane.msg_older_len);
- p.update(.{ .key = .{ .cp = 'h' } });
- const linger = messageFrames(p.settings.message_linger_ms);
- for (0..linger - 1) |_| p.update(.tick);
- // The first two are gone; the third, a frame later, still lingers.
- try std.testing.expectEqual(@as(u8, 0), pane.msg_older_len);
- try std.testing.expectEqualStrings("third", pane.msg[0..pane.msg_len]);
- try std.testing.expectEqual(Pane.MessagePhase.lingering, pane.msg_life.phase);
- p.update(.tick);
- try std.testing.expectEqual(@as(u16, 0), pane.msg_len);
- try std.testing.expect(!p.animationActive());
- // A status ticking in place does not pile up.
- setStatus(p, .at(p.view().active), "lsp 10%");
- setStatus(p, .at(p.view().active), "lsp 20%");
- try std.testing.expectEqual(@as(u8, 0), pane.msg_older_len);
- // Lines keep their rows: when the top one leaves, the one under it does
- // not move up, and the next message fills the gap instead.
- setMessage(p, .at(p.view().active), "top");
- setMessage(p, .at(p.view().active), "under");
- try std.testing.expectEqual(@as(u8, 0), pane.msg_older[0].slot);
- try std.testing.expectEqual(@as(u8, 1), pane.msg_slot);
- pane.removeOlderMessage(0);
- collectNotices(p, pane, p.view().rects[p.view().active], p.view().active);
- try std.testing.expectEqual(@as(u8, 1), pane.notices.row[0]);
- try std.testing.expectEqual(@as(u8, 2), pane.notices.span());
- setMessage(p, .at(p.view().active), "fills");
- try std.testing.expectEqual(@as(u8, 0), pane.msg_slot);
- try std.testing.expectEqual(@as(u8, 1), pane.msg_older[0].slot);
- // The stack keeps the newest few.
- for ([_][]const u8{ "a", "b", "c", "d", "e" }) |text| setMessage(p, .at(p.view().active), text);
- try std.testing.expectEqual(@as(u8, Pane.message_stack), pane.msg_older_len);
- try std.testing.expectEqualStrings("b", pane.msg_older[0].slice());
- try std.testing.expectEqualStrings("e", pane.msg[0..pane.msg_len]);
+ try std.testing.expectEqual(@as(u8, max_live), m.live_len);
+ try std.testing.expectEqualStrings("w3", m.live[0].text.slice());
}
-test "a builtin announces itself on the message row, and Verbose silences it" {
+test "a builtin announces itself on the notice row, an echo, and Verbose silences it" {
if (pardes.Term.ops == null) return error.SkipZigTest; // a terminal's tag row
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 80, .rows = 24 });
defer p.deinit();
@@ -786,136 +1139,385 @@ test "a builtin announces itself on the message row, and Verbose silences it" {
p.sync();
try std.testing.expect(p.settings.verbose);
- // Wrap, not Collapse: a builtin that folds its own pane away leaves no row
- // for its announcement, which is correct and not what this is testing.
+ // Wrap, not Collapse: a builtin that folds its own pane away is not
+ // what this is testing.
try std.testing.expect(p.executeBuiltinLine(p.view().active, "Wrap"));
- try std.testing.expectEqualStrings("Wrap", pane.msg[0..pane.msg_len]);
- // A value it does not take is said, in place of the announcement.
+ try std.testing.expectEqualStrings("Wrap", p.messages.saidBy(pane));
+ try std.testing.expectEqual(Kind.echo, p.messages.headline().?.kind);
+ // A value it does not take is said, an error, and leads the row.
const wrapped = p.settings.wrap;
try std.testing.expect(p.executeBuiltinLine(p.view().active, "Wrap maybe"));
- try std.testing.expectEqualStrings("Wrap: takes on, off", pane.msg[0..pane.msg_len]);
+ try std.testing.expectEqualStrings("Wrap: takes on, off", p.messages.saidBy(pane));
try std.testing.expectEqual(wrapped, p.settings.wrap);
- // The notice list is what the paint pass reads, so the announcement has to
- // reach it, not just the buffer.
- collectNotices(p, pane, p.view().rects[p.view().active], p.view().active);
- try std.testing.expect(pane.notices.len > 0);
- try std.testing.expectEqual(Pane.Notices.Kind.message, pane.notices.kinds[0]);
-
- // ...and it is carried as a tagline band, not a body row: that is what
- // gives it the tagline's height, its small font and its border.
+ // ...on the window's foot row, a tagline-shaped layer, not on a chip
+ // over the pane's body.
var frame = std.heap.ArenaAllocator.init(std.testing.allocator);
defer frame.deinit();
- _ = try p.render(frame.allocator());
- const r = p.view().rects[p.view().active];
- const band = for (p.surface.tagLayers()) |*layer| {
- if (layer.rows != 0 and layer.kind == .notice) break layer;
- } else return error.NoNoticeBand;
- try std.testing.expectEqual(@as(u16, 1), band.viewport.h);
- try std.testing.expectEqual(r.y + BOX_H, band.viewport.y);
- // Right aligned: the text ends at the band's right edge.
- const line = band.cells[0..band.cols];
- var last: usize = line.len;
- while (last > 0 and line[last - 1].grapheme()[0] == ' ') last -= 1;
- try std.testing.expect(last > 0);
- try std.testing.expect(line[0].grapheme()[0] == ' ');
+ const s = try p.render(frame.allocator());
+ try std.testing.expectEqual(@as(u8, 0), pane.notices.len);
+ const row = for (s.tagLayers()) |*layer| {
+ if (layer.rows != 0 and layer.kind == .notice_row) break layer;
+ } else return error.NoNoticeRow;
+ try std.testing.expectEqual(@as(u16, 1), row.viewport.h);
+ try std.testing.expectEqual(p.view().screen_h - 1, row.viewport.y);
+ var want: [64]u8 = undefined;
+ const said = try std.fmt.bufPrint(&want, "\u{2717} @p{d} Wrap: takes on, off", .{pane.serial});
+ const grid = s.cells[@as(usize, row.viewport.y) * s.cols ..][0..s.cols];
+ var text: std.ArrayList(u8) = .empty;
+ defer text.deinit(std.testing.allocator);
+ for (grid) |cell| try text.appendSlice(std.testing.allocator, cell.grapheme());
+ try std.testing.expect(std.mem.indexOf(u8, text.items, said) != null);
// Msg owns the row itself, so it does not announce over its own text.
try std.testing.expect(p.executeBuiltinLine(p.view().active, "Msg hello"));
- try std.testing.expectEqualStrings("hello", pane.msg[0..pane.msg_len]);
+ try std.testing.expectEqualStrings("hello", p.messages.saidBy(pane));
- pane.msg_len = 0;
+ p.messages.live_len = 0;
p.settings.verbose = false;
try std.testing.expect(p.executeBuiltinLine(p.view().active, "Wrap"));
- try std.testing.expectEqual(@as(u16, 0), pane.msg_len);
+ try std.testing.expectEqual(@as(usize, 0), p.messages.saidBy(pane).len);
}
-test "notices stack over the body's top rows without moving them" {
- const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 200, .rows = 24 });
+test "the notice row leads with the most important live message, its count and places, and says how many more; with none, where the caret is" {
+ const p = try Pardes.init(std.testing.allocator, .{ .cols = 80, .rows = 24 });
defer p.deinit();
+ const pane = try p.setTestFile("one\ntwo\nthree\n");
const id = p.view().active;
- const pane = p.panes[id].?;
- p.sync();
- var frame = std.heap.ArenaAllocator.init(std.testing.allocator);
- defer frame.deinit();
-
- const r = p.view().rects[id];
- const top = p.bodyTop(pane, r);
-
- // A message and the leader's line (a shown level's last leaf) at once:
- // two chips, in the order collectNotices chose, each one row tall and
- // each one row further down.
- try std.testing.expect(p.executeBuiltinLine(id, "Msg first message here"));
- p.view().prefix = .leader;
- p.view().leader_n = 0;
- p.view().tag_state.used[0] = 'q';
- p.view().tag_state.due_ns = 1;
- p.clock.now_ns = 1;
- _ = frame.reset(.retain_capacity);
- _ = try p.render(frame.allocator());
- try std.testing.expectEqual(@as(u8, 2), pane.notices.len);
- // An overlay, not a reservation: the body still starts where it did.
- try std.testing.expectEqual(top, p.bodyTop(pane, r));
-
- var seen: usize = 0;
- for (p.surface.tagLayers()) |*layer| {
- if (layer.rows == 0 or layer.kind != .notice) continue;
- try std.testing.expectEqual(@as(u16, 1), layer.viewport.h);
- // Sized to its own message, right up against the pane's right edge --
- // not the width of the pane.
- try std.testing.expectEqual(r.x + r.w, layer.viewport.x + layer.viewport.w);
- try std.testing.expect(layer.viewport.w < r.w - config.GUTTER);
- try std.testing.expect(layer.viewport.y == top or layer.viewport.y == top + 1);
- try std.testing.expectEqual(pane.notices.left[layer.viewport.y - top], layer.viewport.x);
- seen += 1;
- }
- try std.testing.expectEqual(@as(usize, 2), seen);
- // The leader's line is longer than the message, so its chip is wider.
- try std.testing.expect(pane.notices.left[0] > pane.notices.left[1]);
+ p.messages.live_len = 0;
+ p.messages.len = 0;
+ pane.body.cur_row = 1;
+ var buf: [notice_row_cap]u8 = undefined;
+ var row = noticeRow(p, 60, &buf);
+ try std.testing.expectEqualStrings("/test.txt:2", row.text[0..row.left]);
+ try std.testing.expectEqual(@as(usize, 60), panes.File.displayWidth(p.settings.tab, row.text));
+ // A notice, then an error and a warning: the error leads, newest first
+ // within a rank; the others are counted.
+ _ = say(p, .notice, id, "indexed");
+ _ = say(p, .warn, id, "careful");
+ _ = say(p, .@"error", id, "broke");
+ row = noticeRow(p, 60, &buf);
+ try std.testing.expectEqualStrings("\u{2717} /test.txt broke", row.text[0..row.left]);
+ try std.testing.expect(std.mem.endsWith(u8, row.text, "+1 \u{b7} 3 messages \u{b7} SPC h m"));
+ // A burst of the same: one message, counted; the row keeps its width.
+ for (0..9) |_| _ = say(p, .@"error", id, "broke");
+ row = noticeRow(p, 60, &buf);
+ try std.testing.expectEqualStrings("\u{2717} /test.txt broke \u{d7}10", row.text[0..row.left]);
+ try std.testing.expectEqual(@as(usize, 60), panes.File.displayWidth(p.settings.tab, row.text));
+ // An error that names places offers the walk, its places as words.
+ const err = keep(p, .@"error", 0, "@p9 zig build", "exit 1");
+ err.places[0] = .{ .line = 25, .col = 12 };
+ err.places[0].path.set("core/pick.zig");
+ err.places_len = 1;
+ row = noticeRow(p, 80, &buf);
+ try std.testing.expectEqualStrings("\u{2717} @p9 zig build exit 1 core/pick.zig:25:12", row.text[0..row.left]);
+ try std.testing.expect(std.mem.endsWith(u8, row.text, "+1 \u{b7} SPC e walk"));
+ // Too narrow: the left gives way, the right stays whole.
+ row = noticeRow(p, 30, &buf);
+ try std.testing.expect(std.mem.endsWith(u8, row.text, "+1 \u{b7} SPC e walk"));
+ try std.testing.expect(panes.File.displayWidth(p.settings.tab, row.text) <= 30);
+ // A question outranks a warning, not an error; it is counted on the right.
+ _ = keep(p, .question, pane.serial, "/test.txt", "changed on disk");
+ row = noticeRow(p, 80, &buf);
+ try std.testing.expect(std.mem.startsWith(u8, row.text, "\u{2717} @p9"));
+ try std.testing.expect(std.mem.endsWith(u8, row.text, "+2 \u{b7} 1 question \u{b7} SPC e"));
+}
- // Gone with the notices: no stale chip left behind.
- p.view().prefix = .none;
- pane.msg_len = 0;
- _ = frame.reset(.retain_capacity);
- _ = try p.render(frame.allocator());
- for (p.surface.tagLayers()) |*layer|
- try std.testing.expect(layer.rows == 0 or layer.kind != .notice);
+test "a rolled level's last leaf is said on the notice row, the whole row, never in a chip over the body; at rest the row is the messages' again" {
+ const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 120, .rows = 30 });
+ defer p.deinit();
+ const pane = try p.setTestFile("one\n");
+ p.messages.live_len = 0;
+ p.clock.now_ns = 5 * std.time.ns_per_s;
+ p.clock.stepped_ns = p.clock.now_ns;
+ // SPC t w: Wrap, run from SPC t; then SPC t again, shown.
+ for (" tw t") |c| p.update(.{ .key = .{ .cp = c } });
+ p.advance(p.clock.now_ns);
+ p.clock.now_ns = p.view().tag_state.due_ns;
+ p.sync();
+ _ = try p.render(p.scratch.allocator());
+ var buf: [notice_row_cap]u8 = undefined;
+ var row = noticeRow(p, 110, &buf);
+ try std.testing.expect(std.mem.startsWith(u8, row.text, "w Wrap: "));
+ try std.testing.expect(std.mem.endsWith(u8, row.text, " (last used here)"));
+ try std.testing.expectEqual(row.text.len, row.right);
+ try std.testing.expect(row.lead == null);
+ try std.testing.expectEqual(@as(u8, 0), pane.notices.len);
+ // Narrower than the line: cut to the width, never past it.
+ row = noticeRow(p, 12, &buf);
+ try std.testing.expectEqualStrings("w Wrap: Long", row.text);
+ // Esc: at rest, the messages' (Wrap's echo), and with none where the
+ // caret is.
+ p.update(.{ .key = .{ .cp = pardes.Key.escape } });
+ row = noticeRow(p, 110, &buf);
+ try std.testing.expect(row.lead != null);
+ p.messages.live_len = 0;
+ row = noticeRow(p, 110, &buf);
+ try std.testing.expect(std.mem.startsWith(u8, row.text, "/test.txt:1"));
}
-test "an idle core wants no wake and a lingering message sleeps to its linger's end" {
+test "an idle core wants no wake, and a message wakes it once, when it dims" {
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 80, .rows = 24 });
defer p.deinit();
while (p.nextEffect()) |_| {}
- const frame = pardes.frame_ns;
p.advance(1_000_000);
+ p.messages.live_len = 0;
try std.testing.expectEqual(@as(?u64, null), p.nextWake());
- const pane = p.panes[p.view().active].?;
- // Shown, a message asks for no wake.
+ try std.testing.expect(p.executeBuiltinLine(p.view().active, "MessageLinger 160"));
try std.testing.expect(p.executeBuiltinLine(p.view().active, "Msg hello"));
- try std.testing.expectEqual(Pane.MessagePhase.shown, pane.msg_life.phase);
+ const said = p.messages.headline().?;
+ try std.testing.expect(!said.faded(p.clock.now_ns, p.settings.message_linger_ms));
+ // The core sleeps to its dimming, not a frame at a time.
+ const frame = pardes.frame_ns;
+ const due = said.t + 160 * std.time.ns_per_ms;
+ const woken = p.nextWake().?;
+ try std.testing.expect(woken >= due and woken < due + frame);
+ p.advance(woken);
+ try std.testing.expect(said.faded(p.clock.now_ns, p.settings.message_linger_ms));
try std.testing.expectEqual(@as(?u64, null), p.nextWake());
- // A key starts the 800 ms linger: the core sleeps to its end, not a
- // frame at a time, and the frames it jumps draw nothing.
- p.update(.{ .key = .{ .cp = 'x' } });
- try std.testing.expectEqual(Pane.MessagePhase.lingering, pane.msg_life.phase);
- const linger = messageFrames(p.settings.message_linger_ms);
- const due = p.clock.stepped_ns + linger * frame;
- try std.testing.expectEqual(@as(?u64, due), p.nextWake());
- p.needs_frame = false;
- p.advance(due - frame);
- try std.testing.expectEqual(@as(?u64, due), p.nextWake());
- try std.testing.expectEqual(Pane.MessagePhase.lingering, pane.msg_life.phase);
- p.advance(due);
- try std.testing.expectEqual(@as(usize, 0), pane.msg_len);
+ // A warning is bright twice as long; with no linger nothing wakes.
+ try std.testing.expect(p.executeBuiltinLine(p.view().active, "MessageLinger 0"));
+ _ = say(p, .warn, p.view().active, "careful");
try std.testing.expectEqual(@as(?u64, null), p.nextWake());
+}
+
+test "a compiler's report names its places: each place's words, the first error's rows after it its detail, a relative path the run's directory's" {
+ var s: Said = .{};
+ const rows = [_][]const u8{
+ "install",
+ "+- compile exe pardes Debug native 1 errors",
+ "core/pick.zig:25:12: error: expected 2 argument(s), found 3",
+ " const best = rank(q, name, 3) orelse continue;",
+ " ^~~~",
+ "core/look.zig:14:5: note: function declared here",
+ "pub fn rank(q: []const u8, name: []const u8) ?u32 {",
+ "error: the following command failed with 1 compilation errors:",
+ };
+ try std.testing.expectEqual(@as(usize, 2), readPlaces(&s, "/src/pardes/", &rows));
+ try std.testing.expectEqualStrings("/src/pardes/core/pick.zig", s.places[0].path.slice());
+ try std.testing.expectEqual(@as(u32, 25), s.places[0].line);
+ try std.testing.expectEqual(@as(u32, 12), s.places[0].col);
+ try std.testing.expectEqualStrings("expected 2 argument(s), found 3", s.places[0].text.slice());
+ try std.testing.expectEqualStrings("note: function declared here", s.places[1].text.slice());
+ try std.testing.expectEqual(@as(u8, 2), s.detail_len);
+ try std.testing.expectEqualStrings(" const best = rank(q, name, 3) orelse continue;", s.detail[0].slice());
+ try std.testing.expectEqualStrings(" ^~~~", s.detail[1].slice());
+ // No error among them: no places.
+ var none: Said = .{};
+ try std.testing.expectEqual(@as(usize, 0), readPlaces(&none, "/", &.{ "x.zig:1:1: note: only a note", "grep: nothing" }));
+}
+
+test "a burst of the same message is one message, counted, and moves nothing on the screen" {
+ const p = try Pardes.init(std.testing.allocator, .{ .cols = 80, .rows = 20 });
+ defer p.deinit();
+ const pane = try p.setTestFile("text\n");
+ const id = p.view().active;
+ _ = say(p, .@"error", id, "workspace/didChangeWatchedFiles: 3 files");
+ p.sync();
+ const rects = p.view().rects;
+ const tag_rows = pane.tag_rows;
+ for (0..9) |_| _ = say(p, .@"error", id, "workspace/didChangeWatchedFiles: 3 files");
+ p.sync();
+ try std.testing.expectEqual(@as(u8, 1), p.messages.live_len);
+ try std.testing.expectEqual(@as(u16, 10), p.messages.headline().?.n);
+ try std.testing.expectEqual(rects, p.view().rects);
+ try std.testing.expectEqual(tag_rows, pane.tag_rows);
+ var buf: [notice_row_cap]u8 = undefined;
+ const row = noticeRow(p, 78, &buf);
+ try std.testing.expect(std.mem.endsWith(u8, row.text[0..row.left], "3 files \u{d7}10"));
+}
+
+test "a file changed on disk under unsaved text asks in its tag and never takes the keyboard: SPC e's keyboard answers, d shows the disk's lines as ghosts, Esc leaves it waiting, B2 on Reload reads it again" {
+ const p = try Pardes.init(std.testing.allocator, .{ .cols = 120, .rows = 20 });
+ defer p.deinit();
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "c.zig", .data = "one\ntwo\nthree\n" });
+ var dir: [4096]u8 = undefined;
+ const path = try std.fmt.allocPrint(std.testing.allocator, "{s}/c.zig", .{dir[0..try tmp.dir.realPath(std.testing.io, &dir)]});
+ defer std.testing.allocator.free(path);
+ const pane = try p.setTestFile("one\ntwo\nthree\n");
+ const id = p.view().active;
+ p.gpa.free(pane.file.?.path);
+ pane.file.?.path = try p.gpa.dupe(u8, path);
+ const f = &pane.file.?;
+ f.saved_hash = panes.File.fileHash(f);
+ // Unsaved: a line typed at the end.
+ for ([_]u21{ 'G', 'o', 'f', 'o', 'u', 'r', Key.escape }) |cp| p.update(.{ .key = .{ .cp = cp } });
+ try std.testing.expect(f.revision != f.saved_revision);
+ const disk = "zero\none\ntwo\nthree\n";
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "c.zig", .data = disk });
+ p.update(.{ .file_changed = .{ .pane = .at(id), .bytes = disk } });
+ const i = p.messages.waiting(pane) orelse return error.NotAsked;
+ try std.testing.expectEqual(Kind.question, p.messages.live[i].kind);
+ // In its tag at rest, its answers offered in place of the tag's own
+ // words (the head, walk UI R1), read-only; its mark `?`.
+ var frame = std.heap.ArenaAllocator.init(std.testing.allocator);
+ defer frame.deinit();
+ const shown = try pardes.tagline.tagText(p, frame.allocator(), pane);
+ try std.testing.expect(std.mem.endsWith(u8, shown, " changed on disk \u{25b8} r Reload k Keep mine d Diff \u{b7} SPC e to answer"));
+ try std.testing.expect(std.mem.startsWith(u8, shown, path));
+ try std.testing.expectEqual(Kind.question, p.messages.markOf(pane).?);
+ try std.testing.expect(std.mem.indexOf(u8, shown, "Save") == null);
+ const prefix = try pardes.tagline.tagPrefix(p, pane);
+ try std.testing.expect(std.mem.indexOf(u8, prefix, "changed on disk") == null);
+ // The tag's own text is no one's to edit meanwhile.
+ try std.testing.expect((try pardes.TagState.head(p, frame.allocator(), pane)) != null);
+ // Out of rest (SPC: its key cell at once) the level's head, not the
+ // question; at rest again, the question.
+ p.update(.{ .key = .{ .cp = ' ' } });
+ try std.testing.expect(std.mem.indexOf(u8, try pardes.tagline.tagText(p, frame.allocator(), pane), "changed on disk") == null);
+ p.update(.{ .key = .{ .cp = Key.escape } });
+ try std.testing.expect(std.mem.indexOf(u8, try pardes.tagline.tagText(p, frame.allocator(), pane), "changed on disk") != null);
+ try std.testing.expectEqualStrings("Reload", p.messages.waitingAnswers(pane)[0].word);
+ // The keyboard is not its: `r` is the body's (helix's replace).
+ p.update(.{ .key = .{ .cp = 'k' } });
+ try std.testing.expect(p.messages.waiting(pane) != null);
+ // Given the keyboard: `d` shows the disk's lines and keeps asking; Esc
+ // leaves it waiting.
+ p.view().answering = pane.serial;
+ p.update(.{ .key = .{ .cp = 'd' } });
+ const asked = &p.messages.live[p.messages.waiting(pane).?];
+ try std.testing.expect(asked.open);
+ try std.testing.expectEqual(@as(u32, 1), asked.places[0].line);
+ try std.testing.expectEqualStrings("+zero", asked.detail[0].slice());
+ try std.testing.expectEqual(pane.serial, p.view().answering);
+ p.update(.{ .key = .{ .cp = Key.escape } });
+ try std.testing.expectEqual(@as(u32, 0), p.view().answering);
+ try std.testing.expect(p.messages.waiting(pane) != null);
+ // B2 on `Reload` in its tag: read again, the question gone.
+ try std.testing.expectEqual(@as(?usize, null), pardes.exec.execute(p, id, "Reload"));
+ while (p.nextEffect()) |_| {}
+ try std.testing.expect(p.messages.waiting(pane) == null);
+ try std.testing.expectEqualStrings(disk, p.panes[id].?.file.?.content);
+}
- // A long linger ends when it says, jumped in one step, not stretched by
- // the cap on catching up with moving frames.
- try std.testing.expect(p.executeBuiltinLine(p.view().active, "MessageLinger 5000"));
- try std.testing.expect(p.executeBuiltinLine(p.view().active, "Msg again"));
- p.update(.{ .key = .{ .cp = 'x' } });
- const long_due = p.clock.stepped_ns + messageFrames(5000) * frame;
- try std.testing.expectEqual(@as(?u64, long_due), p.nextWake());
- p.advance(long_due);
- try std.testing.expectEqual(@as(usize, 0), pane.msg_len);
+test "SPC e on an error that names places lists them under the pane and lands on the first, on a question gives its tag the keyboard, and on anything else opens the history, the newest first" {
+ const p = try Pardes.init(std.testing.allocator, .{ .cols = 100, .rows = 30 });
+ defer p.deinit();
+ // About a jump opening a pane: `Jumps new-pane` (SPEC §6.6).
+ p.settings.jumps = .@"new-pane";
+ const pane = try p.setTestFile("one\ntwo\nthree\nfour\nfive\n");
+ const serial = pane.serial;
+ p.messages.live_len = 0;
+ const err = keep(p, .@"error", 0, "@p9 zig build", "exit 1");
+ for ([_]u32{ 2, 4 }, 0..) |line, k| {
+ err.places[k] = .{ .line = line, .col = 1 };
+ err.places[k].path.set("/test.txt");
+ err.places[k].text.set("bad");
+ }
+ err.places_len = 2;
+ p.update(.{ .key = .{ .cp = ' ' } });
+ p.update(.{ .key = .{ .cp = 'e' } });
+ while (p.nextEffect()) |_| {}
+ try std.testing.expect(p.messages.headline() == null);
+ const here = p.paneBySerial(serial).?;
+ const list = p.panes[p.panes[here].?.search_pane orelse return error.NoList].?;
+ try std.testing.expect(std.mem.indexOf(u8, list.file.?.content, "/test.txt:4:1") != null);
+ try std.testing.expectEqual(@as(i32, 1), p.panes[here].?.body.cur_row);
+ // A question: its tag gets the keyboard.
+ keep(p, .question, serial, "/test.txt", "changed on disk").asks = .disk;
+ try std.testing.expect(p.executeBuiltinLine(here, "Message"));
+ try std.testing.expectEqual(serial, p.view().answering);
+ p.update(.{ .key = .{ .cp = Key.escape } });
+ try std.testing.expectEqual(@as(u32, 0), p.view().answering);
+ // Anything else: the history, the newest first, each with its glyph.
+ p.messages.live_len = 0;
+ _ = say(p, .notice, here, "older words");
+ _ = say(p, .warn, here, "newer words");
+ try std.testing.expect(p.executeBuiltinLine(here, "Message"));
+ const said_so_far = for (p.panes) |slot| {
+ const shown = slot orelse continue;
+ const f = shown.file orelse continue;
+ if (std.mem.endsWith(u8, f.path, config.messages_buffer)) break f.content;
+ } else return error.NoHistory;
+ const newer = std.mem.indexOf(u8, said_so_far, "! ") orelse return error.NoGlyph;
+ try std.testing.expect(newer < std.mem.indexOf(u8, said_so_far, "older words").?);
+}
+
+test "where jumps walk, SPC e lands an error's places as a list in the pane's walk, n walking them; SPC h m is a picker over the history in the pane's tag, the newest first, Enter on a message going to its cause, C-q keeping it as a +Messages" {
+ const p = try Pardes.init(std.testing.allocator, .{ .cols = 100, .rows = 30 });
+ defer p.deinit();
+ p.settings.jumps = .walk;
+ const pane = try p.setTestFile("one\ntwo\nthree\nfour\nfive\n");
+ const id = p.view().active;
+ p.messages.live_len = 0;
+ const err = keep(p, .@"error", 0, "@p9 zig build", "exit 1");
+ for ([_]u32{ 2, 4 }, 0..) |line, k| {
+ err.places[k] = .{ .line = line, .col = 1 };
+ err.places[k].path.set("/test.txt");
+ err.places[k].text.set("bad");
+ }
+ err.places_len = 2;
+ var panes_before: usize = 0;
+ for (p.panes) |slot| panes_before += @intFromBool(slot != null);
+ for (" e") |c| p.update(.{ .key = .{ .cp = c } });
+ while (p.nextEffect()) |_| {}
+ try std.testing.expect(p.messages.headline() == null);
+ // Landed in this reading pane, no pane made: on the first place, the
+ // list's word in its trail.
+ var panes_now: usize = 0;
+ for (p.panes) |slot| panes_now += @intFromBool(slot != null);
+ try std.testing.expectEqual(panes_before, panes_now);
+ try std.testing.expectEqual(id, p.view().active);
+ try std.testing.expectEqual(@as(i32, 1), pane.body.cur_row);
+ var frame = std.heap.ArenaAllocator.init(std.testing.allocator);
+ defer frame.deinit();
+ try std.testing.expect(std.mem.indexOf(u8, try pardes.tagline.tagText(p, frame.allocator(), pane), "\u{2717} @p9 zig build 1/2") != null);
+ // n: the next place, the word saying so.
+ p.update(.{ .key = .{ .cp = 'n' } });
+ try std.testing.expectEqual(@as(i32, 3), pane.body.cur_row);
+ try std.testing.expect(std.mem.indexOf(u8, try pardes.tagline.tagText(p, frame.allocator(), pane), "\u{2717} @p9 zig build 2/2") != null);
+ // SPC h m: the history in this pane's tag, a row a message, the newest
+ // first; no pane made.
+ _ = say(p, .echo, id, "older");
+ _ = say(p, .warn, id, "newest");
+ for (" hm") |c| p.update(.{ .key = .{ .cp = c } });
+ while (p.nextEffect()) |_| {}
+ try std.testing.expectEqual(pardes.TagState.Kind.pick, p.view().tag_state.kind);
+ const pk = pardes.Pick.live(p).?;
+ try std.testing.expectEqual(pardes.Pick.Source.messages, pk.source);
+ var marks: [256]u16 = undefined;
+ var nmarks: usize = 0;
+ // (Row 0 is the word's own echo, `Messages`, said as it ran.)
+ try std.testing.expect(std.mem.indexOf(u8, pk.names.row(1, &marks, &nmarks), "newest") != null);
+ try std.testing.expect(std.mem.indexOf(u8, pk.names.row(2, &marks, &nmarks), "older") != null);
+ // Enter on a message: its cause's pane has the keyboard, the picker
+ // rolled up; then the history again.
+ p.update(.{ .key = .{ .cp = Key.down } });
+ p.update(.{ .key = .{ .cp = Key.enter } });
+ while (p.nextEffect()) |_| {}
+ try std.testing.expectEqual(pardes.TagState.Kind.rest, p.view().tag_state.kind);
+ try std.testing.expectEqual(id, p.view().active);
+ for (" hm") |c| p.update(.{ .key = .{ .cp = c } });
+ while (p.nextEffect()) |_| {}
+ try std.testing.expectEqual(pardes.TagState.Kind.pick, p.view().tag_state.kind);
+ // C-q: kept as the +Messages, the picker rolled up.
+ p.update(.{ .key = .{ .cp = 'q', .ctrl = true } });
+ while (p.nextEffect()) |_| {}
+ try std.testing.expectEqual(pardes.TagState.Kind.rest, p.view().tag_state.kind);
+ panes_now = 0;
+ for (p.panes) |slot| panes_now += @intFromBool(slot != null);
+ try std.testing.expectEqual(panes_before + 1, panes_now);
+ const kept = p.panes[p.view().active].?;
+ try std.testing.expect(std.mem.endsWith(u8, kept.file.?.path, config.messages_buffer));
+}
+
+test "Esc at rest takes a search's tints first, then the warnings and errors, and only then goes back" {
+ const p = try Pardes.init(std.testing.allocator, .{ .cols = 100, .rows = 30 });
+ defer p.deinit();
+ const pane = try p.setTestFile("alpha beta alpha\n");
+ const id = p.view().active;
+ p.messages.live_len = 0;
+ p.update(.{ .key = .{ .cp = '*' } });
+ p.update(.{ .key = .{ .cp = 'n' } });
+ while (p.nextEffect()) |_| {}
+ if (pane.places.pattern.len == 0 and pane.places.hits.items.len == 0) return error.NoTints;
+ _ = say(p, .@"error", id, "broke");
+ p.update(.{ .key = .{ .cp = Key.escape } });
+ try std.testing.expect(pane.places.pattern.len == 0 and pane.places.hits.items.len == 0);
+ try std.testing.expectEqual(@as(u8, 1), p.messages.live_len);
+ p.update(.{ .key = .{ .cp = Key.escape } });
+ try std.testing.expectEqual(@as(u8, 0), p.messages.live_len);
+ try std.testing.expectEqual(id, p.view().active);
}
diff --git a/core/Output.zig b/core/Output.zig
index 380fadb1..fe1543fe 100644
--- a/core/Output.zig
+++ b/core/Output.zig
@@ -491,16 +491,23 @@ pub fn fillRows(p: *Pardes, id: usize, dir: []const u8, from: Origin, name: ?[]c
pub fn openJumps(p: *Pardes, id: usize) !void {
var out: std.Io.Writer.Allocating = .init(p.gpa);
errdefer out.deinit();
+ try jumpsText(p, &out.writer);
+ try refillOrOpen(p, id, .{ .cmd = .Jumplist }, try out.toOwnedSlice());
+}
+
+/// The live view's jump list as a +Jumps lists it, a place a row, the
+/// oldest first (its picker's rows too, Pick.zig).
+pub fn jumpsText(p: *Pardes, w: *std.Io.Writer) !void {
for (p.view().jumps.list[0..p.view().jumps.n]) |j| {
// A closed file's entry: marked, and a look at it opens it again.
if (j.serial == 0) {
const e = p.recentByHash(j.path_hash) orelse continue;
// A kind's place has no Look's column.
if (j.place.len > 0) {
- try out.writer.print("{s}:{d} (closed)\n", .{ e.path, @max(1, j.line) });
+ try w.print("{s}:{d} (closed)\n", .{ e.path, @max(1, j.line) });
continue;
}
- try out.writer.print("{s}:{d}:{d} (closed)\n", .{ e.path, @max(1, j.line), @max(1, j.col) });
+ try w.print("{s}:{d}:{d} (closed)\n", .{ e.path, @max(1, j.line), @max(1, j.col) });
continue;
}
const jp = p.panes[j.pane] orelse continue;
@@ -520,13 +527,12 @@ pub fn openJumps(p: *Pardes, id: usize) !void {
var cut = @min(what.len, 120);
while (cut > 0 and cut < what.len and what[cut] & 0xc0 == 0x80) cut -= 1;
if (j.line == 0)
- try out.writer.print("{s} {s}\n", .{ loc, what[0..cut] })
+ try w.print("{s} {s}\n", .{ loc, what[0..cut] })
else if (j.place.len > 0)
- try out.writer.print("{s}:{d} {s}\n", .{ loc, j.line, what[0..cut] })
+ try w.print("{s}:{d} {s}\n", .{ loc, j.line, what[0..cut] })
else
- try out.writer.print("{s}:{d}:{d} {s}\n", .{ loc, j.line, j.col, what[0..cut] });
+ try w.print("{s}:{d}:{d} {s}\n", .{ loc, j.line, j.col, what[0..cut] });
}
- try refillOrOpen(p, id, .{ .cmd = .Jumplist }, try out.toOwnedSlice());
}
/// The state file's dumps (Db.listDumps: label, date, size, pane count,
@@ -979,19 +985,32 @@ pub fn openConfig(p: *Pardes, id: usize) !void {
return openRead(p, id, .{ .cmd = .DumpConfig }, "", content);
}
-/// The message-row log, oldest first — the lines that were said in passing and
-/// then cleared by the next keystroke.
+/// The messages' history (the log ring), the newest first, each with its
+/// kind's glyph, a live error's places under it: the +Messages' text and
+/// the Messages picker's rows (SPC h m).
+pub fn messagesText(p: *Pardes, w: *std.Io.Writer) !void {
+ var i: usize = p.messages.len;
+ while (i > 0) {
+ i -= 1;
+ const m = p.messages.at(i).?;
+ try w.print("{s} ", .{m.kind.glyph()});
+ if (m.serial != 0) try w.print("{d}: ", .{m.serial});
+ try w.writeAll(m.slice());
+ if (m.repeats > 1) try w.print(" (x{d})", .{m.repeats});
+ try w.writeByte('\n');
+ for (p.messages.live[0..p.messages.live_len]) |*s| {
+ if (s.kind != .@"error" or s.places_len == 0 or !std.mem.eql(u8, pardes.Messages.Message.body(s.text.slice()), pardes.Messages.Message.body(m.slice()))) continue;
+ for (s.places[0..s.places_len]) |*place| try w.print(" {s}:{d}:{d} {s}\n", .{ place.path.slice(), place.line, place.col, place.text.slice() });
+ break;
+ }
+ }
+ if (p.messages.len == 0) try w.writeAll("nothing has been said yet\n");
+}
+
pub fn openMessages(p: *Pardes, id: usize) !void {
var out: std.Io.Writer.Allocating = .init(p.gpa);
errdefer out.deinit();
- var i: usize = 0;
- while (p.messages.at(i)) |m| : (i += 1) {
- if (m.serial != 0) try out.writer.print("{d}: ", .{m.serial});
- try out.writer.writeAll(m.slice());
- if (m.repeats > 1) try out.writer.print(" (x{d})", .{m.repeats});
- try out.writer.writeByte('\n');
- }
- if (i == 0) try out.writer.writeAll("nothing has been said yet\n");
+ try messagesText(p, &out.writer);
const content = try out.toOwnedSlice();
return openRead(p, id, .{ .cmd = .Messages }, "", content);
}
diff --git a/core/Pick.zig b/core/Pick.zig
new file mode 100644
index 00000000..6c86cb98
--- /dev/null
+++ b/core/Pick.zig
@@ -0,0 +1,1896 @@
+//! A picker (pick-ui SPEC.md §5, direction E): a list of places, panes or
+//! names unrolled in the tag of the pane its Enter lands in (§3.5): the
+//! asking pane when it reads, else its reader, made for the picker when it
+//! has none and taken away again by Esc. Its query is typed in that tag's
+//! field (TagState.field), its rows hang in the band under it (Band.zig)
+//! eleven at a time around the cursor, and that pane's body is the preview:
+//! the current row's file at its line, its own text set aside meanwhile and
+//! put back when the picker rolls up.
+//!
+//! The rows are Query.zig's producers', re-presented: names scored by
+//! Names.zig a frame's count at a time (Find's listing from the disk
+//! engine's worker, Recent, Panes, the asking text's declarations, the
+//! rows a language server answered, the jump list), Grep's lines from the
+//! disk engine's worker (Stream.zig: its pause, its cap). A frame makes
+//! only the rows it shows, in its arena.
+//!
+//! A picker is the session's, named by a serial drawn from the panes'
+//! counter (`id`), so the disk engine's `target` names it as it names a
+//! pane; one is live in a view's tag (TagState.pick), and the last
+//! `max_lists` are kept after they roll up.
+const Pick = @This();
+
+const std = @import("std");
+const pardes = @import("root.zig");
+const config = @import("config.zig");
+const layout = @import("layout.zig");
+const look = @import("look.zig");
+const panes = @import("panes.zig");
+const filesystem = @import("fs.zig");
+const exec = @import("exec.zig");
+const bindings = @import("bindings.zig");
+const Kind = @import("Kind.zig");
+const Names = @import("Names.zig");
+const Stream = @import("Stream.zig");
+const Trail = @import("Trail.zig");
+const TagState = @import("TagState.zig");
+const Band = @import("Band.zig");
+const Query = panes.Query;
+const File = panes.File;
+const Output = panes.Output;
+const Pardes = pardes.Pardes;
+const Pane = panes.Pane;
+const Key = pardes.Key;
+
+/// What a picker lists (SPEC §5.1, the sources pardes has): the files
+/// under the asking pane's directory, the lines of them holding the
+/// query, the files opened lately, the panes, the asking text's
+/// declarations, the lines holding the query in every open pane (All, its
+/// places in each), the jump list, rows handed over (a language server's
+/// answer, SPC e's places), titled by their word, the messages' history
+/// (SPC h m), and the themes (SPC t t, the window wearing the one under
+/// the cursor).
+pub const Source = enum { find, grep, recent, panes, symbols, all, jumplist, list, messages, themes };
+
+/// Each source's word in the tag and the leader keys of the builtin that
+/// opens it, its key cells (`␣ f Find`).
+const words = std.EnumArray(Source, struct { word: []const u8, keys: []const u8 }).init(.{
+ .find = .{ .word = "Find", .keys = "f" },
+ .grep = .{ .word = "Grep", .keys = "f" },
+ .recent = .{ .word = "Recent", .keys = "f" },
+ .panes = .{ .word = "Panes", .keys = "b" },
+ .symbols = .{ .word = "Symbols", .keys = "s" },
+ .all = .{ .word = "All", .keys = "" },
+ .jumplist = .{ .word = "Jumplist", .keys = "j" },
+ .list = .{ .word = "List", .keys = "l" },
+ .messages = .{ .word = "Messages", .keys = "hm" },
+ .themes = .{ .word = "Themes", .keys = "t" },
+});
+
+/// The pickers kept after they roll up, for their list words and Resume.
+pub const max_lists = 8;
+/// Refinements a picker stacks (C-SPC).
+pub const max_refine = 3;
+
+pub const replica = .{ .len = .{.{ "refined", "nrefined" }} };
+
+/// Its serial: the disk engine's target, a list word's index.
+id: u32,
+source: Source,
+/// Its word, `Find`, or a list's own (`Refs`).
+word: Kind.Buf(24) = .{},
+/// The leader keys under which its builtin is, drawn as key cells.
+keys: Kind.Buf(4) = .{},
+/// Where Find and Grep look; what the rows' paths are relative to.
+dir: Kind.Buf(4096) = .{},
+/// The pane that asked, and the one its Enter lands in, by serial.
+owner: u32 = 0,
+landing: u32 = 0,
+/// The landing pane was made for it: Esc takes it away.
+made: bool = false,
+/// Unrolled in a view's tag now.
+unrolled: bool = false,
+names: Names = .{},
+/// A Grep's lines, as the disk engine sends them (Query.take).
+found: std.ArrayList(Query.Found) = .empty,
+found_bytes: std.ArrayList(u8) = .empty,
+/// A list's rows, as they were handed over (`path:line:col text`).
+rows: []u8 = &.{},
+/// The query and the cursor as it rolled up (live, they are its view's
+/// field and cursor).
+query: Kind.Buf(256) = .{},
+at: u32 = 0,
+/// The landing pane's own text while its body previews (a reading pane:
+/// put back when the picker rolls up), and its caret and top then (put
+/// back too when it previewed its own file, with nothing set aside).
+aside: ?File.State = null,
+aside_row: i32 = 0,
+aside_col: i32 = 0,
+aside_top: usize = 0,
+/// The row the preview shows (`no_row`: none yet); asked again on the
+/// frame after the cursor moves, never on the key that moved it.
+shown: u32 = no_row,
+/// The preview on (M-p).
+previews: bool = true,
+/// Marked rows (Tab), by what each is (`idOf`), in order.
+marks: std.ArrayList(u32) = .empty,
+/// The queries refined from (C-SPC), each with the names it listed then:
+/// Backspace on an empty field goes back to them.
+refined: [max_refine]Refined = undefined,
+nrefined: u8 = 0,
+/// The band's second step: the sources to switch to (M-h), the acts on
+/// the picked rows (M-l, M-Enter); `edit`: the field is the act Edit's
+/// command, the query kept in `query`.
+spine: enum(u8) { rows, sources, acts, edit } = .rows,
+/// The act step's cursor, among the acts offered.
+act_at: u8 = 0,
+/// The places Walk queued (C-i steps them in the landing pane): each a
+/// path in `queue_bytes`, its line and column.
+queue: std.ArrayList(Queued) = .empty,
+queue_bytes: std.ArrayList(u8) = .empty,
+queue_at: u32 = 0,
+
+pub const Queued = struct { path: u32, len: u16, line: u32, col: u32 };
+
+const Refined = struct { query: Kind.Buf(64) = .{}, names: Names = .{} };
+
+const no_row = std.math.maxInt(u32);
+
+pub fn deinit(pk: *Pick, gpa: std.mem.Allocator) void {
+ for (pk.refined[0..pk.nrefined]) |*r| r.names.deinit(gpa);
+ pk.marks.deinit(gpa);
+ pk.queue.deinit(gpa);
+ pk.queue_bytes.deinit(gpa);
+ pk.names.deinit(gpa);
+ pk.found.deinit(gpa);
+ pk.found_bytes.deinit(gpa);
+ gpa.free(pk.rows);
+}
+
+/// Whether a search a builtin asks for from pane `id` is a picker in the
+/// tag (SPEC §14.3 phase 4): in a session whose jumps walk, from the
+/// keyboard or a click, never a script's (a 9P write's: the query pane,
+/// whose rows it reads back, and whose `not found` it hears).
+pub fn asked(p: *const Pardes) bool {
+ return p.settings.jumps == .walk and !p.fs.serving;
+}
+
+/// Picker `id`, kept or live.
+pub fn byId(p: *const Pardes, id: u32) ?*Pick {
+ if (id == 0) return null;
+ for (p.picks) |slot| if (slot) |pk| if (pk.id == id) return pk;
+ return null;
+}
+
+/// The picker live in the live view's tag.
+pub fn live(p: *const Pardes) ?*Pick {
+ const s = &p.view().tag_state;
+ if (s.kind != .pick) return null;
+ const pk = byId(p, s.pick) orelse return null;
+ return if (pk.unrolled) pk else null;
+}
+
+/// A picker of `source` asked from pane `from`, unrolled in the tag of the
+/// pane its Enter will land in (SPEC §3.5), its field `query`. `rows` are
+/// a list's (`source` `list`, titled `word`).
+pub fn open(p: *Pardes, from: usize, source: Source, word: []const u8, query: []const u8, rows: []const u8) void {
+ const asker = p.panes[from] orelse return;
+ TagState.toRest(p);
+ const pk = make(p, source) catch |err| return p.reportError(.at(from), "pick", err);
+ pk.word.set(if (word.len > 0) word else words.get(source).word);
+ pk.keys.set(words.get(source).keys);
+ pk.dir.set(Pardes.paneDir(asker));
+ pk.rows = p.gpa.dupe(u8, rows) catch |err| return p.reportError(.at(from), "pick", err);
+ hostIn(p, pk, from) catch |err| return p.reportError(.at(from), "pick", err);
+ unroll(p, pk, query);
+ start(p, pk);
+ filter(p, pk);
+ // The themes: the cursor on the one worn (their order, the field empty).
+ if (source == .themes and query.len == 0 and p.custom_theme == null) p.view().tag_state.rows.at = @intCast(p.settings.theme);
+}
+
+/// A new picker in the ring, the oldest kept one dropped for it.
+fn make(p: *Pardes, source: Source) !*Pick {
+ var slot: ?usize = null;
+ for (p.picks, 0..) |s, i| if (s == null) {
+ slot = i;
+ break;
+ };
+ if (slot == null) {
+ // The oldest not live.
+ var oldest: ?usize = null;
+ for (p.picks, 0..) |s, i| if (s) |pk| if (!pk.unrolled and (oldest == null or pk.id < p.picks[oldest.?].?.id)) {
+ oldest = i;
+ };
+ const i = oldest orelse return error.NoPickerSlots;
+ p.picks[i].?.deinit(p.gpa);
+ p.gpa.destroy(p.picks[i].?);
+ p.picks[i] = null;
+ slot = i;
+ }
+ const pk = try p.gpa.create(Pick);
+ p.next_serial += 1;
+ pk.* = .{ .id = p.next_serial, .source = source };
+ p.picks[slot.?] = pk;
+ return pk;
+}
+
+/// Picker `pk` asked from pane `from`: the pane it lands in is `from` when
+/// it reads; its reader when it is held and has one; else a pane made under
+/// it as its reader would be, empty until the preview fills it. The
+/// keyboard stays where it was: the landing pane is the tag's host.
+fn hostIn(p: *Pardes, pk: *Pick, from: usize) !void {
+ const asker = p.panes[from].?;
+ pk.owner = asker.serial;
+ pk.made = false;
+ // A theme is no place: its list is the asking pane's own tag (§3.5),
+ // and its preview the whole window.
+ if (pk.source == .themes) {
+ pk.landing = asker.serial;
+ p.view().active = from;
+ return;
+ }
+ const reader = if (Trail.reading(p, asker)) from else Trail.readerOf(p, asker);
+ pk.landing = p.panes[reader orelse try landingFor(p, from)].?.serial;
+ pk.made = reader == null;
+ p.view().active = from;
+}
+
+/// A pane made under pane `from` for a picker, where its reader goes.
+fn landingFor(p: *Pardes, from: usize) !usize {
+ const asker = p.panes[from].?;
+ const free = p.freeSlot() orelse return error.NoPaneSlots;
+ const content = try p.gpa.dupe(u8, "");
+ errdefer p.gpa.free(content);
+ _ = try Output.open(p, free, Pardes.paneDir(asker), .preview, "", content);
+ layout.placeNew(p, from, from, free, .reader);
+ layout.compute(p);
+ return free;
+}
+
+/// Picker `pk` live in the live view's tag: its host its landing pane, its
+/// field `query`, the cursor where it was.
+fn unroll(p: *Pardes, pk: *Pick, query: []const u8) void {
+ const v = p.view();
+ const s = &v.tag_state;
+ s.kind = .pick;
+ s.pick = pk.id;
+ s.host = pk.landing;
+ s.field.set(query);
+ s.rows = .{ .at = @intCast(@min(pk.at, std.math.maxInt(u16))) };
+ pk.unrolled = true;
+ pk.shown = no_row;
+ // The whole window previews a theme: no pane dimmed (SPEC §3.6).
+ if (pk.source == .themes) s.previewing = .full;
+ if (p.paneBySerial(pk.landing)) |id| {
+ s.previewing.set(id);
+ const pane = p.panes[id].?;
+ pk.aside_row = pane.body.cur_row;
+ pk.aside_col = pane.body.cur_col;
+ pk.aside_top = if (pane.file) |f| f.scroll else 0;
+ }
+}
+
+/// Its source begun: the names gathered, a listing started.
+fn start(p: *Pardes, pk: *Pick) void {
+ pk.names.reset();
+ pk.found.clearRetainingCapacity();
+ pk.found_bytes.clearRetainingCapacity();
+ const dir = pk.dir.slice();
+ switch (pk.source) {
+ .find => {
+ Stream.query(p, pk.id, .files, "", dir, .now) catch |err| return p.reportError(.at(p.view().active), "pick", err);
+ if (p.fs.serving) Stream.step(p);
+ },
+ .grep, .all => {},
+ .recent => Query.gather(p, &pk.names, .recent, dir, null, null),
+ .panes => Query.gather(p, &pk.names, .panes, dir, null, null),
+ .symbols => Query.gather(p, &pk.names, .symbols, dir, null, p.paneBySerial(pk.owner)),
+ .jumplist => {
+ var out: std.Io.Writer.Allocating = .init(p.gpa);
+ defer out.deinit();
+ Output.jumpsText(p, &out.writer) catch return;
+ addRows(p, pk, out.written());
+ },
+ .list => addRows(p, pk, pk.rows),
+ .messages => {
+ var out: std.Io.Writer.Allocating = .init(p.gpa);
+ defer out.deinit();
+ Output.messagesText(p, &out.writer) catch return;
+ addRows(p, pk, out.written());
+ },
+ .themes => for (pardes.colors.themes, 0..) |t, i| {
+ pk.names.add(p.gpa, t.name, 0, t.name.len, 0, @intCast(i)) catch return;
+ },
+ }
+}
+
+/// Rows of text as names, a row each, matched whole.
+fn addRows(p: *Pardes, pk: *Pick, text: []const u8) void {
+ var lines = std.mem.splitScalar(u8, text, '\n');
+ var i: u32 = 0;
+ while (lines.next()) |ln| : (i += 1) {
+ if (ln.len == 0) continue;
+ pk.names.add(p.gpa, ln, 0, ln.len, 0, i) catch return;
+ }
+}
+
+/// Its rows are names scored by the query: any source's but a live Grep's
+/// or All's, and theirs once refined.
+fn fuzzy(pk: *const Pick) bool {
+ return pk.nrefined > 0 or (pk.source != .grep and pk.source != .all);
+}
+
+/// The field typed: the rows again for it. A Grep's lines are the disk
+/// engine's, once the typing pauses; the names are scored a frame's count
+/// at a time from here.
+pub fn filter(p: *Pardes, pk: *Pick) void {
+ const q = std.mem.trim(u8, p.view().tag_state.field.text(), " ");
+ p.view().tag_state.rows.at = 0;
+ pk.shown = no_row;
+ if (fuzzy(pk)) return pk.names.typed(p.gpa, q);
+ if (pk.source == .grep) {
+ pk.found.clearRetainingCapacity();
+ pk.found_bytes.clearRetainingCapacity();
+ if (q.len > 0) {
+ Stream.query(p, pk.id, .grep, q, pk.dir.slice(), if (p.fs.serving) .now else .typed) catch |err| return p.reportError(.at(p.view().active), "pick", err);
+ if (p.fs.serving) Stream.step(p);
+ } else if (p.stream.target == pk.id) _ = p.stream.stop();
+ return;
+ }
+ {
+ // All: each open text's places, found a frame's more at a time.
+ for (p.panes) |slot| {
+ const tp = slot orelse continue;
+ if (!searchable(tp)) continue;
+ if (q.len == 0) {
+ if (tp.places.from == pk.id) tp.places.clear(p.gpa);
+ } else tp.places.search(p, tp, .list, pk.id, q, false, null, false);
+ }
+ }
+}
+
+/// A pane whose text All searches: a file's or a list's, not a query
+/// pane's nor a preview's.
+fn searchable(tp: *const Pane) bool {
+ const f = tp.file orelse return false;
+ if (tp.query != null) return false;
+ if (f.output) |o| if (o.from == .preview) return false;
+ return true;
+}
+
+/// The panes All's places are in, in the order of their serials.
+fn allPanes(p: *const Pardes, pk: *const Pick, out: *[pardes.MAX_PANES]usize) []usize {
+ var n: usize = 0;
+ for (p.panes, 0..) |slot, i| if (slot) |tp| if (tp.places.from == pk.id and tp.places.shows(tp) and tp.places.hits.items.len > 0) {
+ out[n] = i;
+ n += 1;
+ };
+ std.mem.sort(usize, out[0..n], p, struct {
+ fn lt(pp: *const Pardes, a: usize, b: usize) bool {
+ return pp.panes[a].?.serial < pp.panes[b].?.serial;
+ }
+ }.lt);
+ return out[0..n];
+}
+
+/// The disk engine's rows for picker `target` (Stream.receive).
+pub fn take(p: *Pardes, target: u32, kind: Stream.Kind, rows: []const u8) bool {
+ const pk = byId(p, target) orelse return false;
+ Query.take(p, pk, kind, rows);
+ // A listing's names, scored as they come.
+ if (kind == .files) pk.names.rescore(p.gpa);
+ return true;
+}
+
+/// Pane `serial`'s declarations came (Stream.receiveParse): a Symbols
+/// picker asked from it gathers them.
+pub fn declsArrived(p: *Pardes, serial: u32) void {
+ for (p.picks) |slot| if (slot) |pk| if (pk.unrolled and pk.source == .symbols and pk.owner == serial and pk.names.cands.items.len == 0) {
+ Query.gather(p, &pk.names, .symbols, pk.dir.slice(), null, p.paneBySerial(serial));
+ pk.names.typed(p.gpa, pk.names.queryText());
+ pk.names.rescore(p.gpa);
+ };
+}
+
+/// After every step: each live picker's names scored on (a frame's count),
+/// and on a frame of its own after the cursor stood, the preview of the
+/// current row.
+pub fn produceAll(p: *Pardes, tick: bool) void {
+ for (p.picks) |slot| if (slot) |pk| if (pk.unrolled) {
+ if (pk.names.busy()) pk.names.rescore(p.gpa);
+ // A theme's preview in the step of the key that moved to it.
+ if (pk.source == .themes) pardes.colors.previewTheme(p, themeAt(p, pk));
+ if (tick) preview(p, pk);
+ };
+}
+
+/// The frames a live picker still owes: scoring, a preview (nextWake's).
+pub fn busy(p: *const Pardes) bool {
+ for (p.picks) |slot| if (slot) |pk| if (pk.unrolled) {
+ if (pk.names.busy() or (pk.previews and pk.shown != p.view().tag_state.rows.at)) return true;
+ };
+ return false;
+}
+
+// ---- the rows ----
+
+/// The theme the cursor of a themes picker is on.
+fn themeAt(p: *const Pardes, pk: *const Pick) ?usize {
+ const n = pk.names.hits.items.len;
+ if (n == 0) return null;
+ const at = @min(p.view().tag_state.rows.at, n - 1);
+ return pk.names.cands.items[pk.names.hits.items[at].cand].ref;
+}
+
+/// The rows the list has now.
+pub fn count(p: *const Pardes, pk: *const Pick) usize {
+ if (fuzzy(pk)) return pk.names.hits.items.len;
+ switch (pk.source) {
+ .grep => return pk.found.items.len,
+ .all => {
+ var order: [pardes.MAX_PANES]usize = undefined;
+ var n: usize = 0;
+ for (allPanes(p, pk, &order)) |i| n += p.panes[i].?.places.hits.items.len;
+ return n;
+ },
+ else => return pk.names.hits.items.len,
+ }
+}
+
+/// What row `i` is, kept by a mark across a new query: a name's candidate,
+/// a line's place in its source.
+fn idOf(pk: *const Pick, i: usize) u32 {
+ return if (fuzzy(pk)) pk.names.hits.items[i].cand else @intCast(i);
+}
+
+fn marked(pk: *const Pick, id: u32) ?usize {
+ const at = std.sort.lowerBound(u32, pk.marks.items, id, struct {
+ fn order(a: u32, b: u32) std.math.Order {
+ return std.math.order(a, b);
+ }
+ }.order);
+ return if (at < pk.marks.items.len and pk.marks.items[at] == id) at else null;
+}
+
+/// Where a row points: a place in a file, or a pane by its serial.
+const Target = union(enum) { none, place: struct { path: []const u8, at: look.Spot }, pane: u32 };
+
+/// Row `i` as the band shows it and what it points at, its text in
+/// `arena`.
+const Row = struct { text: []const u8, pre: u16 = 0, faint: u16 = 0, dim: bool = false, marks: []const u16 = &.{}, target: Target = .none };
+
+fn rowAt(p: *Pardes, pk: *const Pick, arena: std.mem.Allocator, i: usize) !Row {
+ const dir = pk.dir.slice();
+ if (!fuzzy(pk) and pk.source == .all) {
+ var order: [pardes.MAX_PANES]usize = undefined;
+ var k = i;
+ for (allPanes(p, pk, &order)) |id| {
+ const tp = p.panes[id].?;
+ const hits = tp.places.hits.items;
+ if (k >= hits.len) {
+ k -= hits.len;
+ continue;
+ }
+ const f = &tp.file.?;
+ const h = hits[k];
+ const line = @import("Places.zig").lineOf(try File.lineIndex(p.gpa, f), h.start);
+ const ls = File.lineStart(p.gpa, f, line);
+ const le = std.mem.indexOfScalarPos(u8, f.content, h.start, '\n') orelse f.content.len;
+ const whole = f.content[ls..le];
+ const lead = whole.len - std.mem.trimStart(u8, whole, " \t").len;
+ const name = if (f.output == null) std.Io.Dir.path.basename(f.path) else "";
+ const pre = try std.fmt.allocPrint(arena, config.pane_addr ++ "{d} {s}:{d}", .{ tp.serial, name, line + 1 });
+ const text = try std.fmt.allocPrint(arena, "{s} {s}", .{ pre, whole[lead..@min(whole.len, lead + 240)] });
+ var marks: std.ArrayList(u16) = .empty;
+ var c = h.start - ls;
+ while (c < h.end - ls and c >= lead and pre.len + 1 + c - lead < text.len) : (c += 1) try marks.append(arena, @intCast(pre.len + 1 + c - lead));
+ const target: Target = if (f.output == null) .{ .place = .{ .path = f.path, .at = .{ .line = line + 1, .col = h.start - ls + 1 } } } else .{ .pane = tp.serial };
+ return .{ .text = text, .pre = @intCast(pre.len), .marks = marks.items, .target = target };
+ }
+ return .{ .text = "" };
+ }
+ if (!fuzzy(pk)) {
+ const fd = pk.found.items[i];
+ const name = pk.found_bytes.items[fd.path..][0..fd.path_len];
+ const code = pk.found_bytes.items[fd.code..][0..fd.code_len];
+ const lead = code.len - std.mem.trimStart(u8, code, " \t").len;
+ const pre = try std.fmt.allocPrint(arena, "{f}:{d}", .{ look.quoted(name), fd.line });
+ const text = try std.fmt.allocPrint(arena, "{s} {s}", .{ pre, code[lead..] });
+ var marks: std.ArrayList(u16) = .empty;
+ var c = fd.col;
+ while (c < fd.end and c >= lead and pre.len + 1 + c - lead < text.len) : (c += 1) try marks.append(arena, @intCast(pre.len + 1 + c - lead));
+ const path = try std.Io.Dir.path.join(arena, &.{ dir, name });
+ return .{ .text = text, .pre = @intCast(pre.len), .marks = marks.items, .target = .{ .place = .{ .path = path, .at = .{ .line = fd.line, .col = fd.col + 1 } } } };
+ }
+ var marks: [Names.max_query * 4]u16 = undefined;
+ var nmarks: usize = 0;
+ const text = pk.names.row(i, &marks, &nmarks);
+ const cand = pk.names.cands.items[pk.names.hits.items[i].cand];
+ var row: Row = .{ .text = text, .marks = try arena.dupe(u16, marks[0..nmarks]) };
+ switch (pk.source) {
+ .find => {
+ var namebuf: [4096]u8 = undefined;
+ const name = if (text.len > 1 and text[0] == '"' and text[text.len - 1] == '"') look.unquoted(&namebuf, text[1 .. text.len - 1]) else text;
+ row.faint = @intCast(if (std.mem.lastIndexOfScalar(u8, text, '/')) |k| k + 1 else 0);
+ row.target = .{ .place = .{ .path = try std.Io.Dir.path.join(arena, &.{ dir, name }), .at = .{ .line = 1, .col = 1 } } };
+ },
+ .panes => {
+ row.pre = cand.key -| 1;
+ row.dim = p.paneBySerial(cand.ref) == null;
+ row.target = .{ .pane = cand.ref };
+ },
+ .symbols => {
+ row.pre = 6;
+ const owner = p.panes[p.paneBySerial(pk.owner) orelse return row] orelse return row;
+ const f = owner.file orelse return row;
+ row.target = .{ .place = .{ .path = f.path, .at = .{ .line = cand.ref } } };
+ },
+ .themes => {},
+ .recent, .jumplist, .list, .grep, .all => {
+ const t = look.parsePathLine(text);
+ row.pre = @intCast(t.end);
+ if (t.path.len == 0) return row;
+ const path = if (t.path[0] == '/' or t.path[0] == '@') t.path else try std.Io.Dir.path.join(arena, &.{ dir, t.path });
+ row.target = .{ .place = .{ .path = path, .at = t.at } };
+ },
+ // A message (`✗ 3: words`, Output.messagesText): its cause's pane
+ // while it is open; a place under it (indented): that place.
+ .messages => {
+ const lead = text.len - std.mem.trimStart(u8, text, " ").len;
+ if (lead == 0) {
+ const sp = std.mem.indexOfScalar(u8, text, ' ') orelse return row;
+ const digits = text[sp + 1 ..];
+ const n = std.mem.indexOfNone(u8, digits, "0123456789") orelse return row;
+ if (n == 0 or digits[n] != ':') return row;
+ const serial = std.fmt.parseInt(u32, digits[0..n], 10) catch return row;
+ if (p.paneBySerial(serial) != null) row.target = .{ .pane = serial };
+ return row;
+ }
+ const t = look.parsePathLine(text[lead..]);
+ row.pre = @intCast(lead + t.end);
+ if (t.path.len == 0) return row;
+ row.target = .{ .place = .{ .path = t.path, .at = t.at } };
+ },
+ }
+ return row;
+}
+
+// ---- the tag ----
+
+/// The head of the landing pane's tag (SPEC §5.3): the key cells, the
+/// source's word, the query, the count `cursor/total` and `•marked`; on a
+/// second row the other sources' words, under spines from the key cells.
+pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?TagState.Head {
+ const pk = live(p) orelse return null;
+ const s = &p.view().tag_state;
+ var text: std.ArrayList(u8) = .empty;
+ var spans: std.ArrayList(TagState.Span) = .empty;
+ try text.append(arena, ' ');
+ var cells: [4][2]u32 = undefined;
+ var ncells: usize = 0;
+ // SPC's cell, then its keys': `␣ f`.
+ if (pk.keys.len > 0) for (0..pk.keys.len + 1) |k| {
+ const name = if (k == 0) "␣" else bindings.keyName(pk.keys.slice()[k - 1]);
+ cells[ncells] = .{ @intCast(text.items.len), @intCast(text.items.len + name.len) };
+ ncells += 1;
+ try text.appendSlice(arena, name);
+ try text.append(arena, ' ');
+ };
+ try text.appendSlice(arena, pk.word.slice());
+ try text.append(arena, ' ');
+ for (pk.refined[0..pk.nrefined]) |r| try text.print(arena, "{s} | ", .{r.query.slice()});
+ if (pk.spine == .edit) try text.print(arena, "{s} | Edit ", .{pk.query.slice()});
+ const caret: u32 = @intCast(text.items.len + s.field.caret);
+ try text.appendSlice(arena, s.field.text());
+ const n = count(p, pk);
+ try text.print(arena, " {d}/{d}", .{ if (n == 0) 0 else s.rows.at + 1, n });
+ if (pk.marks.items.len > 0) try text.print(arena, " •{d}", .{pk.marks.items.len});
+ if (pk.names.busy() or p.stream.busyFor(pk.id)) try text.appendSlice(arena, " ⋯");
+ // Themes have no acts and no other sources: no second row.
+ if (pk.source == .themes) {
+ try text.appendSlice(arena, " ⏎ wear it · esc");
+ for (cells[0..ncells]) |c| try spans.append(arena, .{ .lo = c[0], .hi = c[1], .style = .key });
+ return .{ .text = text.items, .spans = spans.items, .cells = @intCast(ncells), .caret = caret };
+ }
+ // The second row: the spines go on through it from the key cells,
+ // then the other sources' words, each switching to it.
+ try text.append(arena, '\n');
+ const prefix = try pardes.tagline.prefixIn(p, arena, pane);
+ const width = pardes.tagline.tagWidth(p, panes.paneIdOf(p, pane) orelse 0);
+ const lead = File.displayWidth(p.settings.tab, prefix) % @max(1, width);
+ var col: usize = 0;
+ for (cells[0..ncells]) |c| {
+ const at = lead + File.displayWidth(p.settings.tab, text.items[0..c[0]]);
+ while (col < at) : (col += 1) try text.append(arena, ' ');
+ try spans.append(arena, .{ .lo = @intCast(text.items.len), .hi = @intCast(text.items.len + "│".len), .style = .key });
+ try text.appendSlice(arena, "│");
+ col += 1;
+ }
+ const nspines: u8 = @intCast(spans.items.len);
+ try text.appendSlice(arena, if (ncells == 0) "" else " ");
+ for (acts) |act| if (offered(pk, act)) try text.print(arena, "{s} ", .{act.word});
+ try text.appendSlice(arena, "|");
+ var first = false;
+ inline for (comptime std.enums.values(Source)) |src| if (src != .list and src != .messages and src != .themes) {
+ if (src != pk.source) {
+ if (!first) try text.append(arena, ' ');
+ first = false;
+ try text.appendSlice(arena, words.get(src).word);
+ }
+ };
+ for (cells[0..ncells]) |c| try spans.append(arena, .{ .lo = c[0], .hi = c[1], .style = .key });
+ return .{ .text = text.items, .spans = spans.items, .cells = nspines, .caret = caret };
+}
+
+/// The band's rows: as many as the list will show, eleven at most, from
+/// what the source has (not what the query keeps: typing never moves the
+/// body).
+pub fn bandRows(p: *const Pardes) u16 {
+ const pk = live(p) orelse return 0;
+ const have = if (!fuzzy(pk)) Band.Cursor.shown else pk.names.cands.items.len;
+ const rows: usize = @max(1, @min(Band.Cursor.shown, have));
+ // Its second step's rows too: the sources, the acts and what they act on.
+ return @intCast(switch (pk.spine) {
+ .sources => @max(rows, spine_rows.len),
+ .acts => acts: {
+ var n: usize = 1;
+ for (acts) |act| n += @intFromBool(offered(pk, act));
+ break :acts @max(rows, n);
+ },
+ .rows, .edit => rows,
+ });
+}
+
+/// The band's steps: the rows around the cursor.
+pub fn steps(p: *Pardes, arena: std.mem.Allocator) ![]Band.Step {
+ const pk = live(p) orelse return &.{};
+ const s = &p.view().tag_state;
+ const n = count(p, pk);
+ const out = try arena.alloc(Band.Step, if (pk.spine == .sources or pk.spine == .acts) 2 else 1);
+ if (pk.spine == .acts) out[1] = try actStep(p, pk, arena);
+ if (pk.spine == .sources) {
+ const rows = try arena.alloc(Band.Row, spine_rows.len);
+ for (spine_rows, rows, 0..) |src, *row, i| row.* = .{ .text = try std.fmt.allocPrint(arena, "{c} {s}", .{ src.key, src.word }), .key = 1, .index = @intCast(i), .dim = src.source == pk.source };
+ out[1] = .{ .rows = rows };
+ }
+ if (n == 0) {
+ const none = try arena.alloc(Band.Row, 1);
+ none[0] = .{ .text = if (pk.names.busy() or p.stream.busyFor(pk.id)) "⋯" else if (s.field.len == 0 and pk.source == .grep) "type to search" else "nothing matches", .dim = true };
+ out[0] = .{ .rows = none };
+ return out;
+ }
+ const w = s.rows.window(@intCast(@min(n, std.math.maxInt(u16))));
+ const rows = try arena.alloc(Band.Row, w.hi - w.lo);
+ for (rows, w.lo..) |*row, i| {
+ const r = try rowAt(p, pk, arena, i);
+ row.* = .{ .text = r.text, .on = i == s.rows.at, .mark = marked(pk, idOf(pk, i)) != null, .dim = r.dim, .pre = r.pre, .faint = r.faint, .marks = r.marks, .index = @intCast(i) };
+ }
+ out[0] = .{ .rows = rows };
+ return out;
+}
+
+// ---- the preview ----
+
+/// The landing pane's body showing the current row's place (SPEC §5.3):
+/// a file at its line, the query's matches lit for a Grep. Its own text is
+/// set aside the first time, put back when the picker rolls up. A file an
+/// open pane shows is taken from it; any other is read.
+fn preview(p: *Pardes, pk: *Pick) void {
+ const s = &p.view().tag_state;
+ if (pk.shown == s.rows.at or !pk.previews) return;
+ pk.shown = s.rows.at;
+ if (count(p, pk) == 0) return;
+ var frame = std.heap.ArenaAllocator.init(p.gpa);
+ defer frame.deinit();
+ const row = rowAt(p, pk, frame.allocator(), s.rows.at) catch return;
+ const place = switch (row.target) {
+ .place => |t| t,
+ else => return,
+ };
+ const id = p.paneBySerial(pk.landing) orelse return;
+ const pane = p.panes[id].?;
+ const f = if (pane.file) |*file| file else return;
+ if (f.twin != 0) return;
+ if (!std.mem.eql(u8, f.path, place.path)) {
+ if (exec.kindOf(p.tape, place.path)) |kind| if (kind != .file) return;
+ const bytes = openText(p, place.path) orelse (p.tape.site(.preview, p.gpa, filesystem.read, .{ p, place.path }) catch return);
+ if (std.mem.indexOfScalar(u8, bytes[0..@min(bytes.len, 8000)], 0) != null) {
+ p.gpa.free(bytes);
+ return;
+ }
+ const path = p.gpa.dupe(u8, place.path) catch {
+ p.gpa.free(bytes);
+ return;
+ };
+ if (pk.aside == null and !pk.made) {
+ const history = File.History.create(p.gpa) catch {
+ p.gpa.free(bytes);
+ p.gpa.free(path);
+ return;
+ };
+ pk.aside = pane.file;
+ pane.file = .{ .path = path, .content = bytes, .output = .{ .from = .preview }, .history = history };
+ } else {
+ const pf = &pane.file.?;
+ p.gpa.free(pf.path);
+ pf.path = path;
+ File.setContent(p, pf, bytes);
+ pf.saved_revision = pf.revision;
+ pf.scroll = 0;
+ pf.scroll_row = 0;
+ pf.syntax_dirty = true;
+ pane.places.clear(p.gpa);
+ }
+ pane.hscroll = 0;
+ p.sync();
+ }
+ const keyboard = p.view().active;
+ defer p.view().active = keyboard;
+ look.clearNavigationSelection(p, pane);
+ const pf = &pane.file.?;
+ const at = place.at;
+ if (at.line == 0 or at.line > File.nlines(p.gpa, pf)) {
+ pf.scroll = 0;
+ pf.scroll_row = 0;
+ pane.body.cur_row = 0;
+ pane.body.cur_col = 0;
+ return;
+ }
+ look.focusPaneLine(p, id, at, .center);
+ // A Grep's matches in the file lit, as its own pane would have them.
+ if (pk.source == .grep) pane.places.search(p, pane, .list, pk.id, std.mem.trim(u8, s.field.text(), " "), true, null, false);
+}
+
+/// The text of `path` as an open pane has it, copied: no read for it.
+fn openText(p: *Pardes, path: []const u8) ?[]u8 {
+ for (p.panes) |slot| {
+ const tp = slot orelse continue;
+ const tf = tp.file orelse continue;
+ if (tf.output != null or !std.mem.eql(u8, tf.path, path)) continue;
+ return p.gpa.dupe(u8, tf.content) catch null;
+ }
+ return null;
+}
+
+/// The landing pane as the picker found it: its own text back, or the
+/// pane made for the picker taken away; the places it lit put out.
+fn restore(p: *Pardes, pk: *Pick) void {
+ if (pk.source == .themes) return pardes.colors.previewTheme(p, null);
+ const id = p.paneBySerial(pk.landing) orelse return;
+ for (p.panes) |slot| if (slot) |tp| if (tp.places.from == pk.id) tp.places.clear(p.gpa);
+ if (pk.made) {
+ pk.made = false;
+ p.removePane(id, p.paneBySerial(pk.owner)) catch |err| p.reportError(.at(id), "pick", err);
+ return;
+ }
+ putBack(p, pk);
+}
+
+/// The landing pane's own text back in it, the preview's freed.
+fn putBack(p: *Pardes, pk: *Pick) void {
+ const id = p.paneBySerial(pk.landing) orelse return;
+ const pane = p.panes[id].?;
+ if (pk.made) return;
+ const own = pk.aside orelse {
+ // Its own file previewed: its caret and top as they were.
+ look.clearNavigationSelection(p, pane);
+ pane.body.cur_row = pk.aside_row;
+ pane.body.cur_col = pk.aside_col;
+ if (pane.file != null) File.setTop(pane, .{ .line = pk.aside_top });
+ return;
+ };
+ pk.aside = null;
+ File.deinit(p, pane, &pane.file.?);
+ pane.file = own;
+ pane.body.cur_row = pk.aside_row;
+ pane.body.cur_col = pk.aside_col;
+ pane.body.vsel.active = false;
+ p.sync();
+}
+
+/// The live picker rolled up (Esc, or the tag put to rest by anything):
+/// its query and cursor kept for its list word and Resume, every body as
+/// it was (TagState.toRest).
+pub fn rollUp(p: *Pardes) void {
+ const pk = live(p) orelse return;
+ const s = &p.view().tag_state;
+ if (pk.spine != .edit) pk.query.set(s.field.text());
+ pk.spine = .rows;
+ pk.at = s.rows.at;
+ pk.unrolled = false;
+ if (p.stream.target == pk.id) _ = p.stream.stop();
+ restore(p, pk);
+}
+
+/// Every picker freed, a live one's landing pane put back first (the
+/// session's end).
+pub fn deinitAll(p: *Pardes) void {
+ for (&p.picks) |*slot| if (slot.*) |pk| {
+ if (pk.unrolled) {
+ pk.unrolled = false;
+ if (pk.aside) |own| if (p.paneBySerial(pk.landing)) |id| {
+ const pane = p.panes[id].?;
+ File.deinit(p, pane, &pane.file.?);
+ pane.file = own;
+ pk.aside = null;
+ };
+ }
+ pk.deinit(p.gpa);
+ p.gpa.destroy(pk);
+ slot.* = null;
+ };
+}
+
+// ---- keys ----
+
+/// A key in the live picker (keys.zig tagStateKey, SPEC §5.4). Esc is
+/// the tag's: TagState.toRest rolls it up.
+pub fn key(p: *Pardes, k: Key) void {
+ const pk = live(p) orelse return TagState.toRest(p);
+ const s = &p.view().tag_state;
+ const n: u16 = @intCast(@min(count(p, pk), std.math.maxInt(u16)));
+ const plain = !k.ctrl and !k.alt;
+ const ctrl = k.ctrl and !k.alt;
+ const alt = k.alt and !k.ctrl;
+ if (pk.spine == .sources) {
+ pk.spine = .rows;
+ for (spine_rows) |src| if (plain and k.cp == src.key) return switchTo(p, pk, src.source);
+ return;
+ }
+ if (pk.spine == .acts) return actKey(p, pk, k);
+ // Themes: Enter wears the one under the cursor; the rows and the field.
+ if (pk.source == .themes) {
+ if (plain and k.cp == Key.enter) {
+ const at = themeAt(p, pk) orelse return;
+ TagState.toRest(p);
+ pardes.colors.setThemeIndex(p, at);
+ return;
+ }
+ if (s.rows.key(k, n)) return;
+ if (s.field.key(k)) filter(p, pk);
+ return;
+ }
+ if (pk.spine == .edit) {
+ if (plain and k.cp == Key.enter) return editRows(p, pk);
+ if (plain and k.cp == Key.backspace and s.field.len == 0 or alt and k.cp == 'h') {
+ s.field.set(pk.query.slice());
+ pk.spine = .rows;
+ return;
+ }
+ _ = s.field.key(k);
+ return;
+ }
+ if (alt and (k.cp == Key.enter or k.cp == 'l')) {
+ pk.spine = .acts;
+ pk.act_at = 0;
+ return;
+ }
+ if (plain and k.cp == Key.enter) return land(p, if (k.shift) .below else .walk);
+ if (ctrl and k.cp == 's') return land(p, .below);
+ if (ctrl and k.cp == 'v') return land(p, .column);
+ if (plain and k.cp == Key.tab) {
+ if (n == 0) return;
+ toggle(p, pk, idOf(pk, s.rows.at));
+ _ = s.rows.key(.{ .cp = if (k.shift) Key.up else Key.down }, n);
+ return;
+ }
+ if (alt and k.cp == 'a') return markAll(p, pk);
+ if (alt and k.cp == 'h') {
+ pk.spine = .sources;
+ return;
+ }
+ if (ctrl and (k.cp == ' ' or k.cp == '@')) return refine(p, pk, false);
+ if (ctrl and k.cp == 'q') return keep(p, pk);
+ if (alt and k.cp == 'p') {
+ pk.previews = !pk.previews;
+ pk.shown = no_row;
+ if (!pk.previews) putBack(p, pk);
+ return;
+ }
+ if (plain and k.cp == Key.backspace and s.field.len == 0) return back(p, pk);
+ if (s.rows.key(k, n)) return;
+ if (s.field.key(k)) filter(p, pk);
+}
+
+/// The source spine (M-h): a key a source, the query kept.
+const spine_rows = [_]struct { key: u8, word: []const u8, source: ?Source }{
+ .{ .key = 'f', .word = "Find", .source = .find },
+ .{ .key = 'g', .word = "Grep", .source = .grep },
+ .{ .key = 'r', .word = "Recent", .source = .recent },
+ .{ .key = 'b', .word = "Panes", .source = .panes },
+ .{ .key = 's', .word = "Symbols", .source = .symbols },
+ .{ .key = '/', .word = "All", .source = .all },
+ .{ .key = '?', .word = "Help", .source = null },
+};
+
+/// The live picker's source another (`null`: Help over the binding tree),
+/// its query kept, its landing pane the same.
+fn switchTo(p: *Pardes, pk: *Pick, source: ?Source) void {
+ const s = &p.view().tag_state;
+ const to = source orelse {
+ var query: Kind.Buf(256) = .{};
+ query.set(s.field.text());
+ TagState.toRest(p);
+ TagState.openHelp(p, null, "");
+ p.view().tag_state.field.set(query.slice());
+ return TagState.filter(p);
+ };
+ if (p.stream.target == pk.id) _ = p.stream.stop();
+ for (p.panes) |slot| if (slot) |tp| if (tp.places.from == pk.id) tp.places.clear(p.gpa);
+ for (pk.refined[0..pk.nrefined]) |*r| r.names.deinit(p.gpa);
+ pk.nrefined = 0;
+ pk.marks.clearRetainingCapacity();
+ pk.source = to;
+ pk.word.set(words.get(to).word);
+ pk.keys.set(words.get(to).keys);
+ start(p, pk);
+ filter(p, pk);
+}
+
+fn toggle(p: *Pardes, pk: *Pick, id: u32) void {
+ if (marked(pk, id)) |at| {
+ _ = pk.marks.orderedRemove(at);
+ return;
+ }
+ const at = std.sort.lowerBound(u32, pk.marks.items, id, struct {
+ fn order(a: u32, b: u32) std.math.Order {
+ return std.math.order(a, b);
+ }
+ }.order);
+ pk.marks.insert(p.gpa, at, id) catch |err| p.reportError(.at(p.view().active), "pick", err);
+}
+
+/// Every row marked, or none when every one is.
+fn markAll(p: *Pardes, pk: *Pick) void {
+ const n = count(p, pk);
+ const all = pk.marks.items.len == n;
+ pk.marks.clearRetainingCapacity();
+ if (all) return;
+ pk.marks.ensureTotalCapacity(p.gpa, n) catch |err| return p.reportError(.at(p.view().active), "pick", err);
+ for (0..n) |i| pk.marks.appendAssumeCapacity(idOf(pk, i));
+ std.mem.sort(u32, pk.marks.items, {}, std.sort.asc(u32));
+}
+
+/// C-SPC: the rows the query keeps become the list, the query starts
+/// empty; a Grep's lines and All's become names to score from here.
+fn refine(p: *Pardes, pk: *Pick, drop: bool) void {
+ const s = &p.view().tag_state;
+ const q = std.mem.trim(u8, s.field.text(), " ");
+ if (q.len == 0 and !drop or pk.nrefined == max_refine) return;
+ // Dropped: the marked rows, or the current one.
+ const current = if (count(p, pk) > 0) idOf(pk, s.rows.at) else std.math.maxInt(u32);
+ var next: Names = .{};
+ if (fuzzy(pk)) {
+ for (pk.names.hits.items) |h| {
+ if (drop and (if (pk.marks.items.len > 0) marked(pk, h.cand) != null else h.cand == current)) continue;
+ const c = pk.names.cands.items[h.cand];
+ next.add(p.gpa, pk.names.bytes.items[c.start..][0..c.len], c.key, c.key_len, c.base, c.ref) catch break;
+ }
+ } else {
+ var arena = std.heap.ArenaAllocator.init(p.gpa);
+ defer arena.deinit();
+ for (0..count(p, pk)) |i| {
+ if (drop and (if (pk.marks.items.len > 0) marked(pk, @intCast(i)) != null else i == current)) continue;
+ _ = arena.reset(.retain_capacity);
+ const row = rowAt(p, pk, arena.allocator(), i) catch break;
+ const at = switch (row.target) {
+ .place => |t| t,
+ else => continue,
+ };
+ const ln = std.fmt.allocPrint(arena.allocator(), "{s}:{d}:{d} {s}", .{ relative(at.path, pk.dir.slice()), at.at.line, at.at.col, row.text[@min(row.text.len, row.pre + 1)..] }) catch break;
+ next.add(p.gpa, ln, 0, ln.len, 0, @intCast(i)) catch break;
+ }
+ if (p.stream.target == pk.id) _ = p.stream.stop();
+ for (p.panes) |slot| if (slot) |tp| if (tp.places.from == pk.id) tp.places.clear(p.gpa);
+ }
+ pk.refined[pk.nrefined] = .{ .names = pk.names };
+ pk.refined[pk.nrefined].query.set(q);
+ pk.nrefined += 1;
+ pk.names = next;
+ pk.marks.clearRetainingCapacity();
+ s.field.clear();
+ filter(p, pk);
+}
+
+fn relative(path: []const u8, dir: []const u8) []const u8 {
+ const d = std.mem.trimEnd(u8, dir, "/");
+ if (d.len > 0 and path.len > d.len + 1 and std.mem.startsWith(u8, path, d) and path[d.len] == '/') return path[d.len + 1 ..];
+ return path;
+}
+
+/// Backspace on an empty field: the last refinement undone, its query
+/// back; else back a step, to the leader's level the picker was run from.
+fn back(p: *Pardes, pk: *Pick) void {
+ const v = p.view();
+ const s = &v.tag_state;
+ if (pk.nrefined > 0) {
+ pk.nrefined -= 1;
+ const r = &pk.refined[pk.nrefined];
+ pk.names.deinit(p.gpa);
+ pk.names = r.names;
+ pk.marks.clearRetainingCapacity();
+ s.field.set(r.query.slice());
+ s.rows.at = 0;
+ pk.shown = no_row;
+ // A live source's own rows again: All's places are found anew.
+ if (!fuzzy(pk) and pk.source == .all) filter(p, pk);
+ return;
+ }
+ const keys = pk.keys;
+ TagState.toRest(p);
+ if (keys.len == 0) return;
+ v.prefix = .leader;
+ @memcpy(v.leader_keys[0..keys.len], keys.slice());
+ v.leader_n = @intCast(keys.len);
+ s.root = .leader;
+ s.unrolled = true;
+}
+
+/// C-q: the rows (the marked, else all, `Query.max_rows` at most) kept as
+/// text in a +Search under the asking pane, the source's word and query
+/// its first line, each row an address a Look opens.
+fn keep(p: *Pardes, pk: *Pick) void {
+ const s = &p.view().tag_state;
+ const from = p.paneBySerial(pk.owner) orelse p.view().active;
+ // The history kept is the +Messages (SPEC §10.4).
+ if (pk.source == .messages) {
+ TagState.toRest(p);
+ return Output.openMessages(p, from) catch |err| p.reportError(.at(from), "messages", err);
+ }
+ var out: std.Io.Writer.Allocating = .init(p.gpa);
+ defer out.deinit();
+ var arena = std.heap.ArenaAllocator.init(p.gpa);
+ defer arena.deinit();
+ out.writer.print("{s} ", .{pk.word.slice()}) catch return;
+ for (pk.refined[0..pk.nrefined]) |r| out.writer.print("{s} | ", .{r.query.slice()}) catch return;
+ out.writer.print("{s}\n", .{s.field.text()}) catch return;
+ var kept: usize = 0;
+ for (0..count(p, pk)) |i| {
+ if (kept == Query.max_rows) break;
+ if (pk.marks.items.len > 0 and marked(pk, idOf(pk, i)) == null) continue;
+ _ = arena.reset(.retain_capacity);
+ const row = rowAt(p, pk, arena.allocator(), i) catch break;
+ switch (row.target) {
+ .place => |t| if (pk.source == .symbols)
+ out.writer.print("{s}:{d} {s}\n", .{ std.Io.Dir.path.basename(t.path), t.at.line, std.mem.trimStart(u8, row.text, " 0123456789") }) catch break
+ else
+ out.writer.print("{s}\n", .{row.text}) catch break,
+ else => out.writer.print("{s}\n", .{row.text}) catch break,
+ }
+ kept += 1;
+ }
+ TagState.toRest(p);
+ const free = p.freeSlot() orelse return p.reportError(.at(from), "pick", error.NoPaneSlots);
+ const content = out.toOwnedSlice() catch |err| return p.reportError(.at(from), "pick", err);
+ _ = Output.open(p, free, pk.dir.slice(), .search, "", content) catch |err| {
+ p.gpa.free(content);
+ return p.reportError(.at(from), "pick", err);
+ };
+ layout.placeNew(p, from, from, free, .doc);
+}
+
+/// How Enter lands: a walk step, a new pane below, a new column; `queue`:
+/// a walk step to the first, the others queued for C-i (the act Walk).
+const How = enum { walk, below, column, queue };
+
+/// Enter: the current row, or the marked ones, looked at from the asking
+/// pane (look.open, the walk's way: a reading pane steps, a held one's
+/// reader does), the first as `how` says, the others each in a pane below.
+/// The list rolls into the landing pane's trail as its word (item 4).
+fn land(p: *Pardes, how: How) void {
+ const pk = live(p) orelse return;
+ var arena = std.heap.ArenaAllocator.init(p.gpa);
+ defer arena.deinit();
+ const a = arena.allocator();
+ const picked = pickedRows(p, pk, a) catch return;
+ if (picked.len == 0) return;
+ // Walk: the first now, the others queued for C-i.
+ pk.queue.clearRetainingCapacity();
+ pk.queue_bytes.clearRetainingCapacity();
+ pk.queue_at = 0;
+ if (how == .queue) for (picked[1..]) |t| switch (t) {
+ .place => |at| {
+ const q: Queued = .{ .path = @intCast(pk.queue_bytes.items.len), .len = @intCast(@min(at.path.len, std.math.maxInt(u16))), .line = std.math.lossyCast(u32, at.at.line), .col = std.math.lossyCast(u32, at.at.col) };
+ pk.queue_bytes.appendSlice(p.gpa, at.path[0..q.len]) catch break;
+ pk.queue.append(p.gpa, q) catch break;
+ },
+ else => {},
+ };
+ // A step from the pane it lands in when that reads (its owner's reader
+ // or itself), else from its owner, whose reader the place opens as.
+ const landing = if (pk.made) null else p.paneBySerial(pk.landing);
+ TagState.toRest(p);
+ const v = p.view();
+ const owner = p.paneBySerial(pk.owner) orelse v.active;
+ const from = if (how == .walk or how == .queue) landing orelse owner else owner;
+ v.active = from;
+ v.jumps.force = true;
+ for (picked, 0..) |t, k| switch (t) {
+ .none => {},
+ .pane => |serial| if (p.paneBySerial(serial)) |tid| {
+ v.active = tid;
+ if (layout.findPane(p, tid)) |at| p.setActiveColumn(at.col);
+ } else {
+ _ = p.store.reopen(p, serial, from);
+ },
+ .place => |at| if (k == 0 and (how == .walk or how == .queue)) {
+ switch (look.open(p, from, at.path, at.at, .replace)) {
+ .none => {},
+ else => listed(p, pk),
+ }
+ } else if (k == 0 and how == .column) {
+ layout.newColumn(p, from);
+ const c = layout.activeColumn(p) orelse continue;
+ p.exec_column = c;
+ defer p.exec_column = null;
+ pardes.tagline.exitHeader(p);
+ _ = look.open(p, from, at.path, at.at, .below);
+ } else if (how != .queue) {
+ _ = look.open(p, from, at.path, at.at, .below);
+ },
+ };
+ if (how == .queue and pk.queue.items.len > 0) {
+ var said: Kind.Buf(64) = .{};
+ p.setMessage(.at(v.active), said.print("Walk: {d} more places here, C-i for the next", .{pk.queue.items.len}));
+ }
+}
+
+// ---- after Enter: the list word ----
+
+/// The list as its word in a trail says it (SPEC §5.6): its source, its
+/// query, where its cursor is among its rows, and its marks:
+/// `Find pick 3/6 •2`.
+fn wordOf(p: *const Pardes, pk: *const Pick, buf: *Kind.Buf(Trail.max_text)) []const u8 {
+ var w: std.Io.Writer = .fixed(&buf.bytes);
+ w.writeAll(pk.word.slice()) catch {};
+ for (pk.refined[0..pk.nrefined]) |r| w.print(" {s} |", .{r.query.slice()}) catch {};
+ if (pk.query.len > 0) w.print(" {s}", .{pk.query.slice()}) catch {};
+ const n = count(p, pk);
+ w.print(" {d}/{d}", .{ if (n == 0) 0 else pk.at + 1, n }) catch {};
+ if (pk.marks.items.len > 0) w.print(" •{d}", .{pk.marks.items.len}) catch {};
+ buf.len = @intCast(w.buffered().len);
+ return buf.slice();
+}
+
+/// The list rolled into the trail of the reading pane it landed in, its
+/// word before the place: the list `n` and `N` walk there.
+fn listed(p: *Pardes, pk: *const Pick) void {
+ const pane = p.panes[p.view().active] orelse return;
+ if (!Trail.reading(p, pane)) return;
+ var w: Trail.Word = .{ .index = pk.id };
+ _ = wordOf(p, pk, &w.text);
+ Trail.through(&pane.trail, .{ .list = w });
+}
+
+/// `n` and `N` in a reading pane whose trail's newest list or search word
+/// is a list's: its next or previous row in place of the current step
+/// (Trail.replaceStep), its word saying where it is now. False when there
+/// is no list for them to walk (normal.zig: the search's then).
+pub fn walkList(p: *Pardes, id: usize, forward: bool) bool {
+ const pane = p.panes[id] orelse return false;
+ if (!Trail.reading(p, pane)) return false;
+ const t = &pane.trail;
+ var i: usize = @min(t.cur, t.n);
+ while (i > 0) {
+ i -= 1;
+ switch (t.steps[i]) {
+ .list => break,
+ .search => return false,
+ else => {},
+ }
+ } else return false;
+ const pk = byId(p, t.steps[i].list.index) orelse return false;
+ const n = count(p, pk);
+ if (n == 0) return false;
+ if (if (forward) pk.at + 1 >= n else pk.at == 0) {
+ p.setMessage(.at(id), if (forward) "n: the list's last row" else "N: the list's first row");
+ return true;
+ }
+ pk.at = if (forward) pk.at + 1 else pk.at - 1;
+ var arena = std.heap.ArenaAllocator.init(p.gpa);
+ defer arena.deinit();
+ const row = rowAt(p, pk, arena.allocator(), pk.at) catch return true;
+ const at = switch (row.target) {
+ .place => |x| x,
+ else => return true,
+ };
+ _ = wordOf(p, pk, &t.steps[i].list.text);
+ _ = Trail.replaceStep(p, id, at.path, at.at) catch |err| p.reportError(.at(id), "walk", err);
+ return true;
+}
+
+/// Look on a list word in pane `id`'s trail (SPEC §6.3): the list unrolled
+/// again in that pane's tag, its rows, marks, cursor and query as they were.
+pub fn reopen(p: *Pardes, id: usize, index: u32) void {
+ const pk = byId(p, index) orelse return p.setMessage(.at(id), "walk: that list is gone: the last 8 are kept");
+ const pane = p.panes[id] orelse return;
+ TagState.toRest(p);
+ pk.landing = pane.serial;
+ pk.made = false;
+ unroll(p, pk, pk.query.slice());
+ unrollRows(p, pk);
+}
+
+/// A list unrolled again: All's places found again, the cursor where it was.
+fn unrollRows(p: *Pardes, pk: *Pick) void {
+ const at = pk.at;
+ if (!fuzzy(pk) and pk.source == .all) filter(p, pk);
+ p.view().tag_state.rows.at = @intCast(@min(at, std.math.maxInt(u16)));
+}
+
+/// Exec on a list word (SPEC §6.3): its source run again with its query,
+/// from pane `id`.
+pub fn rerun(p: *Pardes, id: usize, index: u32) void {
+ const pk = byId(p, index) orelse return p.setMessage(.at(id), "walk: that list is gone: the last 8 are kept");
+ var query: Kind.Buf(256) = .{};
+ query.set(pk.query.slice());
+ open(p, id, pk.source, pk.word.slice(), query.slice(), pk.rows);
+}
+
+/// Resume (`SPC '`): the last picker reopened as it was, from pane `from`,
+/// in the tag of the pane its Enter lands in.
+pub fn resumeFrom(p: *Pardes, from: usize) void {
+ var newest: ?*Pick = null;
+ for (p.picks) |slot| if (slot) |pk| if (newest == null or pk.id > newest.?.id) {
+ newest = pk;
+ };
+ const pk = newest orelse return p.setMessage(.at(from), "Resume: no picker yet");
+ TagState.toRest(p);
+ if (p.panes[from] == null) return;
+ hostIn(p, pk, from) catch |err| return p.reportError(.at(from), "Resume", err);
+ unroll(p, pk, pk.query.slice());
+ unrollRows(p, pk);
+}
+
+/// B3 on a picker's row (mouse.zig bandPress): Enter on it.
+pub fn landHere(p: *Pardes) void {
+ const pk = live(p) orelse return;
+ if (pk.spine == .rows) land(p, .walk);
+}
+
+/// The rows an act or Enter takes: the marked, else the current.
+fn pickedRows(p: *Pardes, pk: *const Pick, a: std.mem.Allocator) ![]Target {
+ const s = &p.view().tag_state;
+ const n = count(p, pk);
+ var picked: std.ArrayList(Target) = .empty;
+ if (n == 0) return picked.items;
+ if (pk.marks.items.len == 0) {
+ try picked.append(a, (try rowAt(p, pk, a, s.rows.at)).target);
+ } else for (0..n) |i| if (marked(pk, idOf(pk, i)) != null) {
+ try picked.append(a, (try rowAt(p, pk, a, i)).target);
+ };
+ return picked.items;
+}
+
+/// C-i past a reading pane's newest step (Jump.jumpBy, SPEC §6.4): the
+/// next place a Walk queued in it, through the list its trail holds last.
+pub fn stepQueue(p: *Pardes, id: usize) bool {
+ const pane = p.panes[id] orelse return false;
+ const t = &pane.trail;
+ var i: usize = @min(t.cur, t.n);
+ const pk = while (i > 0) {
+ i -= 1;
+ if (t.steps[i] == .list) break byId(p, t.steps[i].list.index) orelse return false;
+ } else return false;
+ if (pk.queue_at >= pk.queue.items.len) return false;
+ const q = pk.queue.items[pk.queue_at];
+ pk.queue_at += 1;
+ p.view().jumps.force = true;
+ _ = look.open(p, id, pk.queue_bytes.items[q.path..][0..q.len], .{ .line = q.line, .col = q.col }, .replace);
+ return true;
+}
+
+// ---- acts ----
+
+/// What the act step offers (SPEC §5.5): the same everywhere, but a list
+/// of panes, whose rows are no places, has Look, Copy, Keep, Drop and Del.
+const Act = struct { key: u8, word: []const u8, says: []const u8 };
+const acts = [_]Act{
+ .{ .key = 'w', .word = "Walk", .says = "here, one by one (C-i)" },
+ .{ .key = 'o', .word = "Look", .says = "open them (Enter)" },
+ .{ .key = 's', .word = "Split", .says = "each in a pane below" },
+ .{ .key = 'v', .word = "Newcol", .says = "in a new column" },
+ .{ .key = 'g', .word = "Grep", .says = "in their directory, the same pattern" },
+ .{ .key = 'e', .word = "Edit", .says = "a sam command on each line" },
+ .{ .key = 'y', .word = "Copy", .says = "the places, as text" },
+ .{ .key = 'k', .word = "Keep", .says = "the rows as a +Search" },
+ .{ .key = 'x', .word = "Drop", .says = "the picked from the list" },
+ .{ .key = 'd', .word = "Del", .says = "close those panes" },
+};
+
+fn offered(pk: *const Pick, act: Act) bool {
+ if (pk.source == .panes) return std.mem.indexOfScalar(u8, "oykxd", act.key) != null;
+ return act.key != 'd';
+}
+
+/// The act step: what it acts on (`on 2 marked`, `on core/pick.zig`),
+/// then the acts.
+fn actStep(p: *Pardes, pk: *const Pick, arena: std.mem.Allocator) !Band.Step {
+ var rows: std.ArrayList(Band.Row) = .empty;
+ const s = &p.view().tag_state;
+ const on = if (pk.marks.items.len > 0)
+ try std.fmt.allocPrint(arena, "on {d} marked", .{pk.marks.items.len})
+ else if (count(p, pk) > 0) on: {
+ const row = try rowAt(p, pk, arena, s.rows.at);
+ break :on try std.fmt.allocPrint(arena, "on {s}", .{switch (row.target) {
+ .place => |t| relative(t.path, pk.dir.slice()),
+ else => row.text,
+ }});
+ } else "on nothing";
+ try rows.append(arena, .{ .text = on, .dim = true });
+ var k: u8 = 0;
+ for (acts) |act| if (offered(pk, act)) {
+ try rows.append(arena, .{ .text = try std.fmt.allocPrint(arena, "{c} {s: <7} {s}", .{ act.key, act.word, act.says }), .key = 1, .on = k == pk.act_at, .index = k });
+ k += 1;
+ };
+ return .{ .rows = rows.items };
+}
+
+fn actKey(p: *Pardes, pk: *Pick, k: Key) void {
+ const plain = !k.ctrl and !k.alt;
+ var n: u8 = 0;
+ for (acts) |act| n += @intFromBool(offered(pk, act));
+ if (plain and (k.cp == Key.down or k.cp == Key.up)) {
+ pk.act_at = if (k.cp == Key.down) (pk.act_at + 1) % n else (pk.act_at + n - 1) % n;
+ return;
+ }
+ var at: u8 = 0;
+ for (acts) |act| if (offered(pk, act)) {
+ if (plain and (k.cp == act.key or k.cp == Key.enter and at == pk.act_at)) return doAct(p, pk, act.key);
+ at += 1;
+ };
+ // Anything else (M-h, Left): back to the rows.
+ pk.spine = .rows;
+}
+
+/// Act `key` on the picked rows.
+fn doAct(p: *Pardes, pk: *Pick, key_: u8) void {
+ const s = &p.view().tag_state;
+ pk.spine = .rows;
+ switch (key_) {
+ 'w' => land(p, .queue),
+ 'o' => land(p, .walk),
+ 's' => land(p, .below),
+ 'v' => land(p, .column),
+ 'k' => keep(p, pk),
+ 'x' => refine(p, pk, true),
+ 'e' => {
+ pk.query.set(s.field.text());
+ s.field.clear();
+ pk.spine = .edit;
+ },
+ 'g' => {
+ var arena = std.heap.ArenaAllocator.init(p.gpa);
+ defer arena.deinit();
+ const picked = pickedRows(p, pk, arena.allocator()) catch return;
+ const dir = for (picked) |t| switch (t) {
+ .place => |at| break std.Io.Dir.path.dirname(at.path) orelse pk.dir.slice(),
+ else => {},
+ } else pk.dir.slice();
+ const q = if (pk.source == .grep) arena.allocator().dupe(u8, s.field.text()) catch return else "";
+ const where = arena.allocator().dupe(u8, dir) catch return;
+ const from = p.paneBySerial(pk.owner) orelse p.view().active;
+ TagState.toRest(p);
+ open(p, from, .grep, "", "", "");
+ const grep = live(p) orelse return;
+ grep.dir.set(where);
+ p.view().tag_state.field.set(q);
+ filter(p, grep);
+ },
+ 'y' => {
+ var out: std.Io.Writer.Allocating = .init(p.gpa);
+ defer out.deinit();
+ var arena = std.heap.ArenaAllocator.init(p.gpa);
+ defer arena.deinit();
+ const picked = pickedRows(p, pk, arena.allocator()) catch return;
+ for (picked) |t| switch (t) {
+ .place => |at| out.writer.print("{s}:{d}\n", .{ at.path, @max(1, at.at.line) }) catch return,
+ .pane => |serial| out.writer.print(config.pane_addr ++ "{d}\n", .{serial}) catch return,
+ .none => {},
+ };
+ p.registers.put(p.gpa, '"', out.written(), 0, 1, true) catch |err| return p.reportError(.at(p.view().active), "pick", err);
+ var said: Kind.Buf(64) = .{};
+ p.setMessage(.at(p.view().active), said.print("Copy: {d} places into the \" register", .{picked.len}));
+ },
+ 'd' => {
+ var arena = std.heap.ArenaAllocator.init(p.gpa);
+ defer arena.deinit();
+ const picked = pickedRows(p, pk, arena.allocator()) catch return;
+ for (picked) |t| if (t == .pane) if (p.paneBySerial(t.pane)) |id| if (id != p.paneBySerial(pk.landing)) {
+ p.removePane(id, null) catch |err| p.reportError(.at(id), "pick", err);
+ };
+ pk.marks.clearRetainingCapacity();
+ start(p, pk);
+ filter(p, pk);
+ },
+ else => {},
+ }
+}
+
+/// Edit's Enter: its command run on each picked row's line, in the open
+/// text that shows its file (edit_cmd.zig, an undo step a line); a row
+/// whose file no pane shows is passed over, and said.
+fn editRows(p: *Pardes, pk: *Pick) void {
+ const s = &p.view().tag_state;
+ var arena = std.heap.ArenaAllocator.init(p.gpa);
+ defer arena.deinit();
+ const a = arena.allocator();
+ const command = a.dupe(u8, std.mem.trim(u8, s.field.text(), " ")) catch return;
+ const picked = pickedRows(p, pk, a) catch return;
+ TagState.toRest(p);
+ if (command.len == 0) return;
+ var ran: usize = 0;
+ // From the last line up, so an edit that adds lines moves none still to come.
+ var k = picked.len;
+ while (k > 0) {
+ k -= 1;
+ const at = switch (picked[k]) {
+ .place => |t| t,
+ else => continue,
+ };
+ const id = for (p.panes, 0..) |slot, i| {
+ const tp = slot orelse continue;
+ const f = tp.file orelse continue;
+ if (f.output == null and std.mem.eql(u8, f.path, at.path)) break i;
+ } else continue;
+ @import("edit_cmd.zig").run(p, id, std.fmt.allocPrint(a, "{d} {s}", .{ @max(1, at.at.line), command }) catch return);
+ ran += 1;
+ }
+ var said: Kind.Buf(96) = .{};
+ p.setMessage(.at(p.view().active), said.print("Edit {s}: {d} of {d} lines, in open texts", .{ command[0..@min(command.len, 40)], ran, picked.len }));
+}
+
+/// A word of the picker's tag or band run (B2, exec.zig
+/// executeBuiltinLine) while it is live: an act's word acts, a source's
+/// switches to it (Grep, both, is the source); anything else is no
+/// picker's.
+pub fn execWord(p: *Pardes, txt: []const u8) bool {
+ const pk = live(p) orelse return false;
+ const word = std.mem.trim(u8, txt, " \t\n");
+ for (spine_rows) |src| if (std.mem.eql(u8, word, src.word)) {
+ switchTo(p, pk, src.source);
+ return true;
+ };
+ if (std.mem.eql(u8, word, "Jumplist")) {
+ switchTo(p, pk, .jumplist);
+ return true;
+ }
+ for (acts) |act| if (offered(pk, act) and std.mem.eql(u8, word, act.word)) {
+ doAct(p, pk, act.key);
+ return true;
+ };
+ return false;
+}
+
+fn testFile(p: *Pardes, tmp: *std.testing.TmpDir, name: []const u8, text: []const u8) ![]u8 {
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = name, .data = text });
+ var base_buf: [std.Io.Dir.max_path_bytes]u8 = undefined;
+ const dir = base_buf[0..try tmp.dir.realPath(std.testing.io, &base_buf)];
+ return std.Io.Dir.path.join(p.gpa, &.{ dir, name });
+}
+
+fn tagOf(p: *Pardes, arena: std.mem.Allocator, id: usize) ![]const u8 {
+ return pardes.tagline.tagText(p, arena, p.panes[id].?);
+}
+
+fn paneCount(p: *const Pardes) usize {
+ var n: usize = 0;
+ for (p.panes) |slot| n += @intFromBool(slot != null);
+ return n;
+}
+
+fn settle(p: *Pardes) void {
+ var n: usize = 0;
+ while (n < 50 and (busy(p) or p.stream.busyFor(live(p).?.id))) : (n += 1) {
+ Stream.step(p);
+ p.update(.tick);
+ }
+}
+
+test "a picker from a held pane unrolls in a reader made for it: its rows in the band, the body the current row's file, Esc takes the reader away" {
+ const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 140, .rows = 50 });
+ defer p.deinit();
+ p.settings.jumps = .walk;
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ const a_path = try testFile(p, &tmp, "alpha.zig", "const alpha = 1;\n");
+ defer p.gpa.free(a_path);
+ const b_path = try testFile(p, &tmp, "pick_state.zig", "//! The state a picker keeps\nconst x = 2;\n");
+ defer p.gpa.free(b_path);
+ const held = try p.setTestFile("held\n");
+ _ = held;
+ const asker = p.view().active;
+ // Held: Keep.
+ Trail.keep(p.panes[asker].?);
+ const dir = std.Io.Dir.path.dirname(a_path).?;
+ p.gpa.free(p.panes[asker].?.file.?.path);
+ p.panes[asker].?.file.?.path = try std.Io.Dir.path.join(p.gpa, &.{ dir, "held.txt" });
+ p.stream.engine = .walk;
+ const npanes = paneCount(p);
+ open(p, asker, .find, "", "", "");
+ const pk = live(p).?;
+ // A reader made for it, under the asker; its tag is the picker's.
+ try std.testing.expectEqual(npanes + 1, paneCount(p));
+ try std.testing.expect(pk.made);
+ const reader = p.paneBySerial(pk.landing).?;
+ try std.testing.expectEqual(@as(?usize, reader), TagState.hostOf(p));
+ try std.testing.expectEqual(asker, p.view().active);
+ settle(p);
+ try std.testing.expectEqual(@as(usize, 2), count(p, pk));
+ for ("pick") |c| p.update(.{ .key = .{ .cp = c, .text = &[_]u8{c} } });
+ settle(p);
+ try std.testing.expectEqual(@as(usize, 1), count(p, pk));
+ var frame = std.heap.ArenaAllocator.init(std.testing.allocator);
+ defer frame.deinit();
+ const a = frame.allocator();
+ const tag = try tagOf(p, a, reader);
+ try std.testing.expect(std.mem.indexOf(u8, tag, " ␣ f Find pick 1/1\n") != null);
+ try std.testing.expect(std.mem.indexOf(u8, tag, "│ Walk Look Split Newcol Grep Edit Copy Keep Drop | Grep Recent Panes Symbols All Jumplist") != null);
+ // The body previews the row's file, after a frame of its own.
+ p.update(.tick);
+ try std.testing.expectEqualStrings(b_path, p.panes[reader].?.file.?.path);
+ _ = try p.render(a);
+ const r = p.view().rects[reader];
+ try std.testing.expectEqualStrings("^", p.surface.at(r.x, r.y).grapheme());
+ try std.testing.expect(p.panes[reader].?.band_rows >= 1);
+ // Esc: the reader made for it goes, the asker as it was.
+ p.update(.{ .key = .{ .cp = Key.escape } });
+ try std.testing.expectEqual(npanes, paneCount(p));
+ try std.testing.expect(live(p) == null);
+ try std.testing.expectEqual(TagState.Kind.rest, p.view().tag_state.kind);
+ try std.testing.expectEqualStrings("pick", pk.query.slice());
+}
+
+test "a picker's keys: Tab marks and moves, M-a all and none, C-SPC refines and Backspace undoes it, M-h switches source keeping the query" {
+ const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 140, .rows = 50 });
+ defer p.deinit();
+ p.settings.jumps = .walk;
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ const a_path = try testFile(p, &tmp, "alpha.zig", "const alpha = 1;\n");
+ defer p.gpa.free(a_path);
+ look.lookAt(p, p.view().active, a_path);
+ const id = p.view().active;
+ open(p, id, .list, "Refs", "", "alpha.zig:1:1 one\nalpha.zig:1:2 two\nbeta.zig:1:1 tree\nalpha.zig:1:4 four\n");
+ const pk = live(p).?;
+ settle(p);
+ const s = &p.view().tag_state;
+ try std.testing.expectEqual(@as(usize, 4), count(p, pk));
+ p.update(.{ .key = .{ .cp = Key.tab } });
+ try std.testing.expectEqual(@as(u16, 1), s.rows.at);
+ p.update(.{ .key = .{ .cp = Key.tab } });
+ try std.testing.expectEqual(@as(usize, 2), pk.marks.items.len);
+ p.update(.{ .key = .{ .cp = Key.up } });
+ p.update(.{ .key = .{ .cp = Key.tab } });
+ try std.testing.expectEqual(@as(usize, 1), pk.marks.items.len);
+ try std.testing.expectEqual(@as(u16, 2), s.rows.at);
+ var frame = std.heap.ArenaAllocator.init(std.testing.allocator);
+ defer frame.deinit();
+ try std.testing.expect(std.mem.indexOf(u8, try tagOf(p, frame.allocator(), id), " Refs 3/4 •1\n") != null);
+ p.update(.{ .key = .{ .cp = 'a', .alt = true } });
+ try std.testing.expectEqual(@as(usize, 4), pk.marks.items.len);
+ p.update(.{ .key = .{ .cp = 'a', .alt = true } });
+ try std.testing.expectEqual(@as(usize, 0), pk.marks.items.len);
+ // C-SPC: what `alpha` keeps becomes the list; `w` then narrows it.
+ for ("alpha") |c| p.update(.{ .key = .{ .cp = c, .text = &[_]u8{c} } });
+ settle(p);
+ try std.testing.expectEqual(@as(usize, 3), count(p, pk));
+ p.update(.{ .key = .{ .cp = ' ', .ctrl = true } });
+ try std.testing.expectEqual(@as(u8, 1), pk.nrefined);
+ try std.testing.expectEqual(@as(u16, 0), s.field.len);
+ settle(p);
+ try std.testing.expectEqual(@as(usize, 3), count(p, pk));
+ for ("w") |c| p.update(.{ .key = .{ .cp = c, .text = &[_]u8{c} } });
+ settle(p);
+ try std.testing.expectEqual(@as(usize, 1), count(p, pk));
+ _ = frame.reset(.retain_capacity);
+ try std.testing.expect(std.mem.indexOf(u8, try tagOf(p, frame.allocator(), id), " Refs alpha | w 1/1\n") != null);
+ // Backspace twice: the `w` goes, then the refinement, its query back.
+ p.update(.{ .key = .{ .cp = Key.backspace } });
+ p.update(.{ .key = .{ .cp = Key.backspace } });
+ try std.testing.expectEqual(@as(u8, 0), pk.nrefined);
+ try std.testing.expectEqualStrings("alpha", s.field.text());
+ settle(p);
+ try std.testing.expectEqual(@as(usize, 3), count(p, pk));
+ // M-p: the preview off, and no frame asked for it.
+ p.update(.{ .key = .{ .cp = 'p', .alt = true } });
+ try std.testing.expect(!pk.previews and !busy(p));
+ p.update(.{ .key = .{ .cp = 'p', .alt = true } });
+ // M-h r: Recent, the query kept.
+ p.update(.{ .key = .{ .cp = 'h', .alt = true } });
+ try std.testing.expect(pk.spine == .sources);
+ p.update(.{ .key = .{ .cp = 'r', .text = "r" } });
+ try std.testing.expectEqual(Source.recent, pk.source);
+ try std.testing.expectEqualStrings("alpha", s.field.text());
+ p.update(.{ .key = .{ .cp = Key.escape } });
+}
+
+test "Enter lands as a walk step in the reading pane; S-Enter opens below; from a held pane the reader made for the picker becomes its reader" {
+ const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 140, .rows = 50 });
+ defer p.deinit();
+ p.settings.jumps = .walk;
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ const a_path = try testFile(p, &tmp, "alpha.zig", "const alpha = 1;\n");
+ defer p.gpa.free(a_path);
+ const b_path = try testFile(p, &tmp, "beta.zig", "one\ntwo\nthree\n");
+ defer p.gpa.free(b_path);
+ look.lookAt(p, p.view().active, a_path);
+ const id = p.view().active;
+ const npanes = paneCount(p);
+ open(p, id, .list, "Refs", "", "beta.zig:3:1 three\n");
+ settle(p);
+ p.update(.{ .key = .{ .cp = Key.enter } });
+ try std.testing.expect(live(p) == null);
+ const here = p.panes[p.view().active].?;
+ try std.testing.expectEqualStrings(b_path, here.file.?.path);
+ try std.testing.expectEqual(@as(i32, 2), here.body.cur_row);
+ try std.testing.expect(here.file.?.output == null);
+ try std.testing.expectEqual(npanes, paneCount(p));
+ // Its trail: where it was, then the place.
+ try std.testing.expect(here.trail.n >= 2);
+ // S-Enter: a pane below, the reading pane as it was.
+ open(p, p.view().active, .list, "Refs", "", "alpha.zig:1:7 alpha\n");
+ settle(p);
+ p.update(.{ .key = .{ .cp = Key.enter, .shift = true } });
+ try std.testing.expectEqual(npanes + 1, paneCount(p));
+ try std.testing.expectEqualStrings(a_path, p.panes[p.view().active].?.file.?.path);
+
+ // From a held pane: the reader made for the picker is taken away and
+ // the place opens as the held pane's reader, its trail its owner's.
+ const held = p.view().active;
+ Trail.keep(p.panes[held].?);
+ open(p, held, .list, "Refs", "", "beta.zig:2:1 two\n");
+ const pk = live(p).?;
+ try std.testing.expect(pk.made);
+ settle(p);
+ p.update(.{ .key = .{ .cp = Key.enter } });
+ const reader = Trail.readerOf(p, p.panes[held].?).?;
+ try std.testing.expectEqualStrings(b_path, p.panes[reader].?.file.?.path);
+ try std.testing.expectEqual(npanes + 2, paneCount(p));
+}
+
+test "M-l unrolls the act step, which says what it acts on; Copy puts the places in the register, Drop takes the picked rows out, Walk queues the rest for C-i" {
+ const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 140, .rows = 50 });
+ defer p.deinit();
+ p.settings.jumps = .walk;
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ const a_path = try testFile(p, &tmp, "alpha.zig", "one\ntwo\nthree\nfour\n");
+ defer p.gpa.free(a_path);
+ look.lookAt(p, p.view().active, a_path);
+ const id = p.view().active;
+ const rows = "alpha.zig:1:1 one\nalpha.zig:2:1 two\nalpha.zig:3:1 three\nalpha.zig:4:1 four\n";
+ open(p, id, .list, "Refs", "", rows);
+ const pk = live(p).?;
+ settle(p);
+ p.update(.{ .key = .{ .cp = 'l', .alt = true } });
+ try std.testing.expect(pk.spine == .acts);
+ // The band as tall as the acts and what they act on, the list's rows fewer.
+ try std.testing.expectEqual(@as(u16, 10), bandRows(p));
+ var frame = std.heap.ArenaAllocator.init(std.testing.allocator);
+ defer frame.deinit();
+ const band = (try Band.of(p, frame.allocator(), p.panes[id].?, id)).?;
+ try std.testing.expectEqual(@as(u8, 2), band.nsteps);
+ try std.testing.expectEqualStrings("on alpha.zig", band.steps[1].rows[0].text);
+ // y: the place copied, the act step rolled back to the rows.
+ p.update(.{ .key = .{ .cp = 'y', .text = "y" } });
+ try std.testing.expect(pk.spine == .rows);
+ // x: the current row dropped, as a refinement.
+ p.update(.{ .key = .{ .cp = 'l', .alt = true } });
+ p.update(.{ .key = .{ .cp = 'x', .text = "x" } });
+ settle(p);
+ try std.testing.expectEqual(@as(usize, 3), count(p, pk));
+ try std.testing.expectEqual(@as(u8, 1), pk.nrefined);
+ // Tab Tab: two marked; Walk lands on the first and queues the second.
+ p.update(.{ .key = .{ .cp = Key.tab } });
+ p.update(.{ .key = .{ .cp = Key.tab } });
+ p.update(.{ .key = .{ .cp = 'l', .alt = true } });
+ _ = frame.reset(.retain_capacity);
+ const marked_band = (try Band.of(p, frame.allocator(), p.panes[id].?, id)).?;
+ try std.testing.expectEqualStrings("on 2 marked", marked_band.steps[1].rows[0].text);
+ p.update(.{ .key = .{ .cp = 'w', .text = "w" } });
+ try std.testing.expect(live(p) == null);
+ try std.testing.expectEqual(@as(i32, 1), p.panes[p.view().active].?.body.cur_row);
+ try std.testing.expectEqual(@as(usize, 1), pk.queue.items.len);
+}
+
+test "after Enter the list is a word in the reader's trail: n and N walk its rows in place, a Look on it reopens it with its cursor and marks, Exec runs it again, Resume reopens the last" {
+ const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 160, .rows = 50 });
+ defer p.deinit();
+ p.settings.jumps = .walk;
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ const a_path = try testFile(p, &tmp, "alpha.zig", "one\ntwo\nthree\nfour\n");
+ defer p.gpa.free(a_path);
+ const b_path = try testFile(p, &tmp, "beta.zig", "b1\nb2\n");
+ defer p.gpa.free(b_path);
+ _ = try p.setTestFile("held\n");
+ const held = p.view().active;
+ Trail.keep(p.panes[held].?);
+ p.gpa.free(p.panes[held].?.file.?.path);
+ p.panes[held].?.file.?.path = try std.Io.Dir.path.join(p.gpa, &.{ std.Io.Dir.path.dirname(a_path).?, "held.txt" });
+ open(p, held, .list, "Refs", "", "alpha.zig:2:1 two\nbeta.zig:2:1 b2\nalpha.zig:4:1 four\n");
+ const pk = live(p).?;
+ settle(p);
+ p.update(.{ .key = .{ .cp = Key.tab } });
+ p.update(.{ .key = .{ .cp = Key.up } });
+ p.update(.{ .key = .{ .cp = Key.enter } });
+ // The reader: its owner, the list's word, the place.
+ const reader = Trail.readerOf(p, p.panes[held].?).?;
+ var t = &p.panes[reader].?.trail;
+ try std.testing.expectEqual(@as(u8, 3), t.n);
+ try std.testing.expect(t.steps[1] == .list);
+ try std.testing.expectEqualStrings("Refs 1/3 •1", t.steps[1].list.text.slice());
+ var frame = std.heap.ArenaAllocator.init(std.testing.allocator);
+ defer frame.deinit();
+ try std.testing.expect(std.mem.indexOf(u8, try tagOf(p, frame.allocator(), reader), "‹@p") != null);
+ try std.testing.expect(std.mem.indexOf(u8, try tagOf(p, frame.allocator(), reader), " › Refs 1/3 •1 › ") != null);
+ // n: the next row, in place of the step (another file: a pane in its place).
+ p.view().active = reader;
+ p.update(.{ .key = .{ .cp = 'n', .text = "n" } });
+ const r2 = Trail.readerOf(p, p.panes[held].?).?;
+ try std.testing.expectEqualStrings(b_path, p.panes[r2].?.file.?.path);
+ t = &p.panes[r2].?.trail;
+ try std.testing.expectEqual(@as(u8, 3), t.n);
+ try std.testing.expectEqualStrings("Refs 2/3 •1", t.steps[1].list.text.slice());
+ p.update(.{ .key = .{ .cp = 'N', .text = "N", .shift = true } });
+ const r3 = Trail.readerOf(p, p.panes[held].?).?;
+ try std.testing.expectEqualStrings(a_path, p.panes[r3].?.file.?.path);
+ try std.testing.expectEqual(@as(i32, 1), p.panes[r3].?.body.cur_row);
+ // Look on the word: the list again, in the reader's tag, as it was.
+ Trail.lookStep(p, r3, 1);
+ try std.testing.expect(live(p) == pk);
+ try std.testing.expectEqual(@as(?usize, r3), TagState.hostOf(p));
+ try std.testing.expectEqual(@as(u16, 0), p.view().tag_state.rows.at);
+ try std.testing.expectEqual(@as(usize, 1), pk.marks.items.len);
+ p.update(.{ .key = .{ .cp = Key.escape } });
+ // Exec on it: a new picker of the same source.
+ Trail.execStep(p, r3, 1);
+ try std.testing.expect(live(p) != null and live(p) != pk);
+ p.update(.{ .key = .{ .cp = Key.escape } });
+ // Resume: the last one.
+ exec.runBuiltin(p, .Resume, held, "", null);
+ try std.testing.expect(live(p) != null);
+ p.update(.{ .key = .{ .cp = Key.escape } });
+}
+
+test "pick-ui §14.3 phase 4: SPC f f from a held pane opens in its reader and Esc removes it; from a reading pane it unrolls there; Enter lands as a step leaving the list word; n walks; a Look on the word reopens it with its cursor and marks" {
+ const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 160, .rows = 50 });
+ defer p.deinit();
+ p.settings.jumps = .walk;
+ p.stream.engine = .walk;
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ const a_path = try testFile(p, &tmp, "pick.zig", "const pick = 1;\n");
+ defer p.gpa.free(a_path);
+ const b_path = try testFile(p, &tmp, "pick_test.zig", "test {}\n");
+ defer p.gpa.free(b_path);
+ const c_path = try testFile(p, &tmp, "other.zig", "x\n");
+ defer p.gpa.free(c_path);
+ _ = try p.setTestFile("held\n");
+ const held = p.view().active;
+ Trail.keep(p.panes[held].?);
+ p.gpa.free(p.panes[held].?.file.?.path);
+ p.panes[held].?.file.?.path = try std.Io.Dir.path.join(p.gpa, &.{ std.Io.Dir.path.dirname(a_path).?, "held.txt" });
+ const npanes = paneCount(p);
+ const typeIn = struct {
+ fn f(pp: *Pardes, keys: []const u8) void {
+ for (keys) |c| pp.update(.{ .key = .{ .cp = c, .text = &[_]u8{c} } });
+ }
+ }.f;
+ // SPC f f from the held pane: a reader made for it, which Esc takes.
+ typeIn(p, " ff");
+ try std.testing.expect(live(p) != null and live(p).?.made);
+ try std.testing.expectEqual(npanes + 1, paneCount(p));
+ p.update(.{ .key = .{ .cp = Key.escape } });
+ try std.testing.expectEqual(npanes, paneCount(p));
+ try std.testing.expectEqual(held, p.view().active);
+ // Again, typed into: Enter lands in a reader of the held pane.
+ typeIn(p, " ffpick");
+ const pk = live(p).?;
+ settle(p);
+ try std.testing.expectEqual(@as(usize, 2), count(p, pk));
+ p.update(.{ .key = .{ .cp = Key.tab } });
+ p.update(.{ .key = .{ .cp = Key.up } });
+ p.update(.{ .key = .{ .cp = Key.enter } });
+ const reader = Trail.readerOf(p, p.panes[held].?).?;
+ const t = &p.panes[reader].?.trail;
+ try std.testing.expect(t.n == 3 and t.steps[1] == .list);
+ try std.testing.expect(std.mem.startsWith(u8, t.steps[1].list.text.slice(), "Find pick 1/2 •1"));
+ const first = p.panes[reader].?.file.?.path;
+ try std.testing.expect(std.mem.eql(u8, first, a_path) or std.mem.eql(u8, first, b_path));
+ // n: the other row, in place of the step.
+ p.view().active = reader;
+ p.update(.{ .key = .{ .cp = 'n', .text = "n" } });
+ const now = Trail.readerOf(p, p.panes[held].?).?;
+ try std.testing.expect(!std.mem.eql(u8, p.panes[now].?.file.?.path, first));
+ try std.testing.expectEqual(@as(u8, 3), p.panes[now].?.trail.n);
+ // SPC f f from the reader, which reads: it unrolls in the reader itself.
+ typeIn(p, " ff");
+ try std.testing.expectEqual(@as(?usize, now), TagState.hostOf(p));
+ try std.testing.expect(!live(p).?.made);
+ p.update(.{ .key = .{ .cp = Key.escape } });
+ // A Look on the list word: the list again, its cursor and its mark.
+ Trail.lookStep(p, now, 1);
+ try std.testing.expect(live(p) == pk);
+ try std.testing.expectEqual(@as(u16, 1), p.view().tag_state.rows.at);
+ try std.testing.expectEqual(@as(usize, 1), pk.marks.items.len);
+ try std.testing.expectEqualStrings("pick", p.view().tag_state.field.text());
+ p.update(.{ .key = .{ .cp = Key.escape } });
+}
+
+test "a picker from a reading pane unrolls in that pane, its own text set aside while it previews and back on Esc" {
+ const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 140, .rows = 50 });
+ defer p.deinit();
+ p.settings.jumps = .walk;
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ const a_path = try testFile(p, &tmp, "alpha.zig", "const alpha = 1;\n");
+ defer p.gpa.free(a_path);
+ const b_path = try testFile(p, &tmp, "beta.zig", "one\ntwo\nthree\n");
+ defer p.gpa.free(b_path);
+ look.lookAt(p, p.view().active, a_path);
+ const id = p.view().active;
+ try std.testing.expect(Trail.reading(p, p.panes[id].?));
+ const npanes = paneCount(p);
+ open(p, id, .list, "Refs", "", "beta.zig:2:1 two\nalpha.zig:1:7 alpha\n");
+ const pk = live(p).?;
+ try std.testing.expect(!pk.made);
+ try std.testing.expectEqual(npanes, paneCount(p));
+ try std.testing.expectEqual(@as(?usize, id), TagState.hostOf(p));
+ settle(p);
+ try std.testing.expectEqual(@as(usize, 2), count(p, pk));
+ try std.testing.expectEqualStrings(b_path, p.panes[id].?.file.?.path);
+ try std.testing.expectEqual(@as(i32, 1), p.panes[id].?.body.cur_row);
+ try std.testing.expect(pk.aside != null);
+ // Down: the next row's file, on the frame after.
+ p.update(.{ .key = .{ .cp = Key.down } });
+ try std.testing.expectEqualStrings(b_path, p.panes[id].?.file.?.path);
+ p.update(.tick);
+ try std.testing.expectEqualStrings(a_path, p.panes[id].?.file.?.path);
+ p.update(.{ .key = .{ .cp = Key.escape } });
+ try std.testing.expect(pk.aside == null);
+ try std.testing.expectEqualStrings(a_path, p.panes[id].?.file.?.path);
+ try std.testing.expect(p.panes[id].?.file.?.output == null);
+ try std.testing.expectEqual(npanes, paneCount(p));
+}
+
+test "SPC t t is a picker of the themes in the asking pane's tag, the whole window wearing the row under the cursor and nothing dimmed; Esc puts the theme back, Enter wears it" {
+ const Key_ = pardes.Key;
+ const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 120, .rows = 30 });
+ defer p.deinit();
+ _ = try p.setTestFile("one\n");
+ const asker = p.view().active;
+ p.newScratchBelow(asker);
+ p.view().active = asker;
+ p.settings.jumps = .walk;
+ const themes = pardes.colors.themes;
+ const was = p.settings.theme;
+ const worn = p.theme().name;
+ for (" tt") |c| p.update(.{ .key = .{ .cp = c } });
+ const s = &p.view().tag_state;
+ try std.testing.expectEqual(TagState.Kind.pick, s.kind);
+ try std.testing.expectEqual(Source.themes, live(p).?.source);
+ try std.testing.expectEqual(p.panes[asker].?.serial, s.host);
+ try std.testing.expectEqual(@as(u16, @intCast(was)), s.rows.at);
+ try std.testing.expectEqual(pardes.MAX_PANES, s.previewing.count());
+ // Down: the window wears the next theme, the session's unchanged.
+ p.update(.{ .key = .{ .cp = if (was + 1 < themes.len) Key_.down else Key_.up } });
+ const shown = s.rows.at;
+ try std.testing.expect(std.mem.eql(u8, p.theme().name, themes[shown].name) and shown != was);
+ try std.testing.expectEqual(was, p.settings.theme);
+ // Esc: its own again.
+ p.update(.{ .key = .{ .cp = Key_.escape } });
+ try std.testing.expectEqualStrings(worn, p.theme().name);
+ try std.testing.expect(p.theme_preview == null);
+ // Again, and Enter wears it.
+ for (" tt") |c| p.update(.{ .key = .{ .cp = c } });
+ p.update(.{ .key = .{ .cp = if (was + 1 < themes.len) Key_.down else Key_.up } });
+ p.update(.{ .key = .{ .cp = Key_.enter } });
+ try std.testing.expectEqual(@as(@TypeOf(p.settings.theme), @intCast(shown)), p.settings.theme);
+ try std.testing.expectEqual(TagState.Kind.rest, s.kind);
+ try std.testing.expect(p.theme_preview == null);
+ try std.testing.expectEqualStrings(themes[shown].name, p.theme().name);
+}
diff --git a/core/Pipe.zig b/core/Pipe.zig
index d0413c08..1dc69d49 100644
--- a/core/Pipe.zig
+++ b/core/Pipe.zig
@@ -591,7 +591,7 @@ test "a pipe's output past its cap leaves the text as it was, and says so" {
const outputs: []const []const u8 = &.{ "AA", big };
p.update(.{ .pipe_resp = .{ .id = id, .success = true, .outputs = outputs } });
try std.testing.expectEqualSlices(u8, "aa bb cc\n", pane.file.?.content);
- try std.testing.expect(std.mem.indexOf(u8, pane.msg[0..pane.msg_len], "past") != null);
+ try std.testing.expect(std.mem.indexOf(u8, p.messages.saidBy(pane), "past") != null);
}
test "the four shell behaviours put their output where helix puts it" {
diff --git a/core/Places.zig b/core/Places.zig
index 7ffcb6cb..7f847f6a 100644
--- a/core/Places.zig
+++ b/core/Places.zig
@@ -802,7 +802,7 @@ test "places: * finds them all, n and N step them round the end silently, an edi
try std.testing.expectEqual(@as(?usize, 0), set.current);
// round the end: the search word says so, and the message row echoes
// it (Prompt.zig, pick-ui SPEC §7.3)
- try std.testing.expect(std.mem.indexOf(u8, pane.msg[0..pane.msg_len], "1/3 ↻ · line 1") != null);
+ try std.testing.expect(std.mem.indexOf(u8, p.messages.saidBy(pane), "1/3 ↻ · line 1") != null);
typeKeys(p, "N");
try std.testing.expectEqual(@as(?usize, 2), set.current);
diff --git a/core/Plumb.zig b/core/Plumb.zig
index e1b09e69..402752a3 100644
--- a/core/Plumb.zig
+++ b/core/Plumb.zig
@@ -1345,7 +1345,7 @@ test "plumb: dispose: no rule and no dst, a start, the web port, a port no rule
// A start of a builtin runs it in place.
try testing.expect(send(p, null, .{ .type = "msg", .data = "hello" }, null) == .done);
const pane = p.panes[p.view().active].?;
- try testing.expectEqualStrings("hello", pane.msg[0..pane.msg_len]);
+ try testing.expectEqualStrings("hello", p.messages.saidBy(pane));
try testing.expectEqualStrings(e_client, send(p, null, .{ .type = "client" }, null).refused);
try testing.expectEqualStrings(e_no_start, send(p, null, .{ .type = "none" }, null).refused);
try testing.expectEqualStrings(e_no_start, send(p, null, .{ .dst = "nobody", .type = "x" }, null).refused);
@@ -1499,12 +1499,12 @@ test "plumb: the Plumb word opens the plumbing file, include basic until one is
// A rule after the word is refused, in words.
try testing.expect(p.executeBuiltinLine(0, "Plumb suffix .svg to image"));
const first = p.panes[0].?;
- try testing.expectEqualStrings(e_word, first.msg[0..first.msg_len]);
+ try testing.expectEqualStrings(e_word, p.messages.saidBy(first));
// Saved: its rules, or why not, the rules as they were.
saved(p, 0, path, "type is text\ndata matches 'x.*'\nplumb to web\n");
try testing.expectEqualStrings("type\tis\ttext\ndata\tmatches\t'x.*'\nplumb\tto\tweb\n\n", inForce(p));
saved(p, 0, path, "type is text\ndata isnt x\nplumb to web\n");
- try testing.expectEqualStrings("plumbing:2: unknown verb isnt", first.msg[0..first.msg_len]);
+ try testing.expectEqualStrings("plumbing:2: unknown verb isnt", p.messages.saidBy(first));
try testing.expectEqualStrings("type\tis\ttext\ndata\tmatches\t'x.*'\nplumb\tto\tweb\n\n", inForce(p));
// Another file saved is no plumbing.
saved(p, 0, "/elsewhere/plumbing", "type is text\nplumb to edit\n");
diff --git a/core/Prompt.zig b/core/Prompt.zig
index 2f42443b..8081f7f9 100644
--- a/core/Prompt.zig
+++ b/core/Prompt.zig
@@ -749,11 +749,12 @@ pub fn execWord(p: *Pardes, id: usize) void {
/// The span of pane `pane`'s tag its search word takes while its places no
/// longer light it (the first Esc cleared them): drawn dimmed (draw.zig).
-pub fn unlit(pane: *Pane) ?[2]usize {
+pub fn unlit(p: *const Pardes, pane: *Pane) ?[2]usize {
const t = &pane.trail;
+ const whole = Trail.folded(p, pane);
for (t.steps[0..t.cur], 0..) |*step, i| if (step.* == .search) {
- if (lights(pane, &step.search) or t.cur - i > Trail.shown_steps) return null;
- return t.spanOf(i);
+ if (lights(pane, &step.search) or t.cur - i > whole) return null;
+ return t.spanOf(i, whole);
};
return null;
}
@@ -1303,7 +1304,7 @@ test "/ searches the body as it is typed: the current place selected, the gutter
// n: the word in place, and the line said.
typeKeys(p, "n");
try std.testing.expect(std.mem.startsWith(u8, try tagOf(p), "/dirty/ 4/7 › "));
- try std.testing.expect(has(pane.msg[0..pane.msg_len], "/dirty/ 4/7 · line 5"));
+ try std.testing.expect(has(p.messages.saidBy(pane), "/dirty/ 4/7 · line 5"));
typeKeys(p, "nnnn");
try std.testing.expect(std.mem.startsWith(u8, try tagOf(p), "/dirty/ 1/7 ↻ › "));
// Esc: the tints go, the word stays, dimmed; Look on it lights them
@@ -1311,10 +1312,10 @@ test "/ searches the body as it is typed: the current place selected, the gutter
p.update(.{ .key = .{ .cp = Key.escape } });
try std.testing.expect(!pane.places.started);
try std.testing.expect(std.mem.startsWith(u8, try tagOf(p), "/dirty/ 1/7 ↻ › "));
- try std.testing.expect(unlit(pane) != null);
+ try std.testing.expect(unlit(p, pane) != null);
typeKeys(p, "j");
Trail.lookStep(p, 0, 0);
- try std.testing.expect(pane.places.started and unlit(pane) == null);
+ try std.testing.expect(pane.places.started and unlit(p, pane) == null);
try std.testing.expectEqual(@as(?usize, 0), pane.places.current);
const sel = pane.body.primaryRange(pane.file.?.content, 0);
try std.testing.expectEqual(@as(usize, 0), @min(sel.anchor, sel.head));
@@ -1473,7 +1474,7 @@ test "a pipe prompt runs a known filter live, a run a selection: the outputs gho
p.update(.{ .pipe_resp = .{ .id = third, .success = true, .outputs = &.{ "\x1e\x1e1", "\x1e\x1e1" } } });
p.update(.{ .key = .{ .cp = Key.enter } });
try std.testing.expectEqual(TagState.Kind.prompt, p.view().tag_state.kind);
- try std.testing.expect(has(pane.msg[0..pane.msg_len], "every run failed"));
+ try std.testing.expect(has(p.messages.saidBy(pane), "every run failed"));
p.update(.{ .key = .{ .cp = Key.escape } });
try std.testing.expectEqualStrings("B\nX\nc\n", pane.file.?.content);
try std.testing.expect(p.pipe.preview == null);
diff --git a/core/Query.zig b/core/Query.zig
index 3ac87dfb..a090929a 100644
--- a/core/Query.zig
+++ b/core/Query.zig
@@ -713,7 +713,6 @@ fn startSource(p: *Pardes, id: usize, q: *Query, source: Source, owner_id: ?usiz
q.found.clearRetainingCapacity();
q.found_bytes.clearRetainingCapacity();
const dir = std.Io.Dir.path.dirname(rp.file.?.path) orelse "/";
- const gpa = p.gpa;
switch (source) {
// The files under the directory, listed once on the disk engine's
// worker (rg --files, else the walk); each keystroke scores them.
@@ -721,6 +720,19 @@ fn startSource(p: *Pardes, id: usize, q: *Query, source: Source, owner_id: ?usiz
Stream.query(p, rp.serial, .files, "", dir, .now) catch |err| return p.reportError(.at(id), "search", err);
if (p.fs.serving) Stream.step(p);
},
+ .recent, .panes, .symbols => gather(p, &q.names, source, dir, rp, owner_id),
+ else => {},
+ }
+}
+
+/// The names a Recent, Panes or Symbols query scores, into `names`: the
+/// files opened lately, the panes but `self` (then the ones this session
+/// closed), the declarations of pane `owner_id`'s text (asked of the
+/// worker when it has none yet: declsArrived gathers them). Rows relative
+/// to `dir`. A query pane's, and a picker's (Pick.zig).
+pub fn gather(p: *Pardes, names: *Names, source: Source, dir: []const u8, self: ?*const Pane, owner_id: ?usize) void {
+ const gpa = p.gpa;
+ switch (source) {
.recent => {
var out: std.Io.Writer.Allocating = .init(gpa);
defer out.deinit();
@@ -729,19 +741,19 @@ fn startSource(p: *Pardes, id: usize, q: *Query, source: Source, owner_id: ?usiz
if (ln.len == 0) continue;
const rel = relative(ln, dir);
const path_end = std.mem.indexOfAny(u8, rel, ": ") orelse rel.len;
- q.names.add(gpa, rel, 0, path_end, Names.baseOf(rel[0..path_end]), 0) catch break;
+ names.add(gpa, rel, 0, path_end, Names.baseOf(rel[0..path_end]), 0) catch break;
}
},
.panes => {
for (p.panes) |slot| {
const other = slot orelse continue;
- if (other == rp or other.query != null) continue;
+ if (other == self or other.query != null) continue;
var buf: [4096 + 32]u8 = undefined;
const what: []const u8 = if (other.file) |f| f.path else if (other.command) |c| c else other.cwdSlice();
const row = std.fmt.bufPrint(&buf, config.pane_addr ++ "{d} {s}", .{ other.serial, relative(what, dir) }) catch continue;
const key_at = std.mem.indexOfScalar(u8, row, ' ').? + 1;
const ln = row[0 .. std.mem.indexOfAny(u8, row, "\r\n") orelse row.len];
- q.names.add(gpa, ln, key_at, ln.len -| key_at, Names.baseOf(ln[@min(key_at, ln.len)..]), other.serial) catch break;
+ names.add(gpa, ln, key_at, ln.len -| key_at, Names.baseOf(ln[@min(key_at, ln.len)..]), other.serial) catch break;
}
// Then the panes this session closed, the latest first, each
// `(closed)` and dimmer (makeNameRows): Enter brings one back
@@ -752,7 +764,7 @@ fn startSource(p: *Pardes, id: usize, q: *Query, source: Source, owner_id: ?usiz
const row = std.fmt.bufPrint(&buf, config.pane_addr ++ "{d} {s}" ++ closed_word, .{ c.serial, relative(c.name, dir) }) catch continue;
const key_at = std.mem.indexOfScalar(u8, row, ' ').? + 1;
const key_len = row.len - closed_word.len - key_at;
- q.names.add(gpa, row, key_at, key_len, Names.baseOf(row[key_at..][0..key_len]), c.serial) catch break;
+ names.add(gpa, row, key_at, key_len, Names.baseOf(row[key_at..][0..key_len]), c.serial) catch break;
}
},
.symbols => {
@@ -769,7 +781,7 @@ fn startSource(p: *Pardes, id: usize, q: *Query, source: Source, owner_id: ?usiz
const first = std.mem.trim(u8, header[0 .. std.mem.indexOfScalar(u8, header, '\n') orelse header.len], " \t\r");
var buf: [256 + 16]u8 = undefined;
const row = std.fmt.bufPrint(&buf, "{d: >6} {s}", .{ d.start_line + 1, first[0..@min(first.len, 240)] }) catch continue;
- q.names.add(gpa, row, 8, row.len - 8, 0, @intCast(d.start_line + 1)) catch break;
+ names.add(gpa, row, 8, row.len - 8, 0, @intCast(d.start_line + 1)) catch break;
}
},
else => {},
@@ -1253,10 +1265,11 @@ fn countGrepCurrent(q: *Query) void {
if (c < q.items.items.len and q.items.items[c].kind == .hit) q.k = q.items.items[c].hit + 1;
}
-/// The disk engine's rows for query pane `q` (Stream.receive): a Grep's
-/// lines (`path:line:col-end code`, relative to the pane's directory) kept
-/// as found, a listing's names added to what Find scores.
-pub fn take(p: *Pardes, q: *Query, kind: Stream.Kind, rows: []const u8) void {
+/// The disk engine's rows for query pane `q` (Stream.receive), or for a
+/// picker (Pick.zig: the same fields): a Grep's lines (`path:line:col-end
+/// code`, relative to the pane's directory) kept as found, a listing's
+/// names added to what Find scores.
+pub fn take(p: *Pardes, q: anytype, kind: Stream.Kind, rows: []const u8) void {
var lines = std.mem.splitScalar(u8, rows, '\n');
while (lines.next()) |ln| {
if (ln.len == 0) continue;
@@ -2330,6 +2343,8 @@ test "Find: names fuzzy per keystroke, the group born with its +Preview, nothing
try tmp.dir.writeFile(std.testing.io, .{ .sub_path = name, .data = "pub fn split() void {}\nconst x = 1;\n" });
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 120, .rows = 48 });
defer p.deinit();
+ // About a jump opening a pane: `Jumps new-pane` (SPEC §6.6).
+ p.settings.jumps = .@"new-pane";
_ = try testFileIn(p, &tmp, "x.txt", "x\n");
p.newScratchBelow(0);
const other = p.view().cols[0].panes[1];
@@ -2379,6 +2394,8 @@ test "Grep: lines of the files under the owner's directory, under their file; Al
try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "b.zig", .data = "const needle = 1;\nconst hay = 2;\nneedle needle\n" });
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 120, .rows = 48 });
defer p.deinit();
+ // About a jump opening a pane: `Jumps new-pane` (SPEC §6.6).
+ p.settings.jumps = .@"new-pane";
const a = try testFileIn(p, &tmp, "a.txt", "one needle\ntwo\n");
leader(p, "fg");
const qid = queryPane(p).?;
@@ -2422,6 +2439,8 @@ test "* seeds line 1 and keeps the keyboard; SPC b b picks a pane, SPC s s a dec
if (comptime !syntax.minimal_grammars) return error.SkipZigTest;
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 120, .rows = 48 });
defer p.deinit();
+ // About a jump opening a pane: `Jumps new-pane` (SPEC §6.6).
+ p.settings.jumps = .@"new-pane";
const pane = try p.setTestFile("const alpha = 1;\nfn beta() void {\n _ = alpha;\n}\nfn gamma() void {}\n");
p.gpa.free(pane.file.?.path);
pane.file.?.path = try p.gpa.dupe(u8, "/tmp/x.zig");
@@ -2487,7 +2506,7 @@ test "a language server's list: one answer lands with no pane, several open the
p.lspRequest(0, .diagnostics, "");
p.update(.{ .lsp_resp = .{ .id = p.lsp_ask.wait.?.id, .rows = "" } });
try std.testing.expectEqual(@as(usize, 1), npanes(p));
- try std.testing.expect(std.mem.indexOf(u8, pane.msg[0..pane.msg_len], "none") != null);
+ try std.testing.expect(std.mem.indexOf(u8, p.messages.saidBy(pane), "none") != null);
// Several: the list open, the keyboard in it in normal mode on the
// current row, which the text shows; line 1 as text.
pane.body.cur_row = 0;
@@ -2577,6 +2596,8 @@ test "B1 on a query pane's rows places the caret and selects, nothing else, the
test "Enter on a frozen query pane's rows after its text was edited: no row to land on, the keyboard to its owner" {
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 40 });
defer p.deinit();
+ // About a jump opening a pane: `Jumps new-pane` (SPEC §6.6).
+ p.settings.jumps = .@"new-pane";
_ = try p.setTestFile("alpha\n");
p.newScratchBelow(0);
p.view().active = 0;
@@ -2600,6 +2621,8 @@ test "a query row's place is its text: the match tinted after it, B3 on it opens
defer tmp.cleanup();
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 120, .rows = 48 });
defer p.deinit();
+ // About a jump opening a pane: `Jumps new-pane` (SPEC §6.6).
+ p.settings.jumps = .@"new-pane";
const a = try testFileIn(p, &tmp, "a.txt", "zero\none needle\ntwo\nthree needle here\n");
leader(p, "fg");
typeKeys(p, "needle");
@@ -2661,6 +2684,8 @@ test "the +Preview: the query's hits in its file are its places, the row's one c
try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "b.zig", .data = text });
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 120, .rows = 60 });
defer p.deinit();
+ // About a jump opening a pane: `Jumps new-pane` (SPEC §6.6).
+ p.settings.jumps = .@"new-pane";
_ = try testFileIn(p, &tmp, "a.txt", "x\n");
leader(p, "fg");
typeKeys(p, "needle");
@@ -2745,6 +2770,8 @@ test "a query row's address reaches every way a look arrives: an empty look writ
defer tmp.cleanup();
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 120, .rows = 48 });
defer p.deinit();
+ // About a jump opening a pane: `Jumps new-pane` (SPEC §6.6).
+ p.settings.jumps = .@"new-pane";
const a = try testFileIn(p, &tmp, "a.txt", "zero\none needle\ntwo\nthree needle here\n");
leader(p, "fg");
typeKeys(p, "needle");
diff --git a/core/Store.zig b/core/Store.zig
index ac9387cb..1328af38 100644
--- a/core/Store.zig
+++ b/core/Store.zig
@@ -290,6 +290,8 @@ test "store: a closed pane comes back where it was, its rows from the pane that
const dir = dir_buf[0..try tmp.dir.realPath(testing.io, &dir_buf)];
const p = try testWindow(dir);
defer p.deinit();
+ // About a jump opening a pane: `Jumps new-pane` (SPEC §6.6).
+ p.settings.jumps = .@"new-pane";
_ = try p.setTestFile("alpha\nbeta\n");
p.newScratchBelow(0);
const sid = p.view().active;
diff --git a/core/Stream.zig b/core/Stream.zig
index a933c014..bcd4f4f8 100644
--- a/core/Stream.zig
+++ b/core/Stream.zig
@@ -713,6 +713,7 @@ pub fn receive(p: *Pardes, b: *const Batch) void {
}
}
p.needs_frame = true;
+ if (panes.Pick.take(p, s.target, s.kind, b.rows)) return;
const id = p.paneBySerial(s.target) orelse return;
const q = p.panes[id].?.query orelse return;
q.capped = s.state == .capped;
@@ -735,6 +736,7 @@ fn receiveParse(p: *Pardes, b: *const Batch, serial: u32, revision: u32) void {
if (p.tree_sitter_gpa.dupe(syntax.ContextDeclaration, b.decls)) |copy| {
f.context.replace(p.tree_sitter_gpa, copy, revision);
panes.Query.declsArrived(p, serial);
+ panes.Pick.declsArrived(p, serial);
} else |_| {}
};
p.needs_frame = true;
diff --git a/core/TagState.zig b/core/TagState.zig
index 716704b7..ef5c1d53 100644
--- a/core/TagState.zig
+++ b/core/TagState.zig
@@ -25,12 +25,14 @@ const Field = @import("Field.zig");
const Band = @import("Band.zig");
const Names = @import("Names.zig");
const Prompt = @import("Prompt.zig");
+const Ask = @import("lsp/Ask.zig");
/// The tag's states besides a root's level (which `kind` rest with a root
/// current is): `help`, a field over every leaf (SPEC §4.5); `describe`,
-/// a sequence replayed in the tree (item 5); `prompt`, a text prompt
-/// (Prompt.zig, SPEC §7).
-pub const Kind = enum(u8) { rest, help, describe, prompt };
+/// a sequence replayed in the tree (item 5); `pick`, a picker (Pick.zig,
+/// SPEC §5); `rename`, a rename's new name typed (lsp/Ask.zig, SPEC §3.5);
+/// `prompt`, a text prompt (Prompt.zig, SPEC §7).
+pub const Kind = enum(u8) { rest, help, describe, pick, rename, prompt };
pub const replica = .{ .len = .{ .{ "scope", "scope_n" }, .{ "hits", "nhits" } } };
@@ -42,8 +44,12 @@ host: u32 = 0,
/// Help's scope: the root and keys its `?` was struck under (`SPC l ?`),
/// or every root's leaves (`SPC ?`: null).
scope_root: ?Root = null,
-scope: [4]u8 = undefined,
+scope: [8]u8 = undefined,
scope_n: u8 = 0,
+/// describe-key's sequence (its root in scope_root, its keys in scope):
+/// it reached a leaf, or nothing is bound to it.
+found: bool = false,
+missed: bool = false,
/// The field typed in the head (Field.zig): Help's query; a picker's, a
/// prompt's.
field: Field = .{},
@@ -54,6 +60,8 @@ nhits: u16 = 0,
ntotal: u16 = 0,
/// The rows' cursor (Band.Cursor).
rows: Band.Cursor = .{},
+/// The picker unrolled in the host's tag, by its serial (Pick.zig).
+pick: u32 = 0,
/// A text prompt's own (Prompt.zig): which, its history's place, what its
/// field found.
prompt: Prompt = .{},
@@ -76,6 +84,61 @@ used: [bindings.ngroups]u8 = @splat(0),
/// while the others are (SPEC §3.6). Set by the state that previews.
previewing: std.StaticBitSet(pardes.MAX_PANES) = .empty,
+/// describe-key (SPEC §4.5), in the tag of pane `id`: the next keys are
+/// replayed in the tree.
+pub fn openDescribe(p: *Pardes, id: usize) void {
+ const pane = p.panes[id] orelse return;
+ toRest(p);
+ const s = &p.view().tag_state;
+ s.kind = .describe;
+ s.host = pane.serial;
+ s.scope_root = null;
+ s.scope_n = 0;
+ s.found = false;
+ s.missed = false;
+}
+
+/// A key of describe-key's sequence: the first a root's, then down its
+/// tree to a group (more keys) or a leaf (found), or to nothing (missed). A
+/// key after a sequence ended starts the next.
+pub fn describeKey(p: *Pardes, key: pardes.Key) void {
+ const s = &p.view().tag_state;
+ if (s.found or s.missed) {
+ s.scope_root = null;
+ s.scope_n = 0;
+ s.found = false;
+ s.missed = false;
+ }
+ const root = s.scope_root orelse {
+ s.scope_root = bindings.rootOf(key);
+ if (s.scope_root == null or s.scope_root == .register) {
+ // Not a root: the key alone, struck.
+ s.scope_root = null;
+ s.scope[0] = if (key.cp >= 0x20 and key.cp < 0x7f and !key.ctrl and !key.alt) @intCast(key.cp) else '?';
+ s.scope_n = 1;
+ s.missed = true;
+ }
+ return;
+ };
+ const printable = key.cp >= 0x20 and key.cp < 0x7f and !key.ctrl and !key.alt;
+ if (!printable or s.scope_n == s.scope.len) {
+ s.missed = true;
+ return;
+ }
+ const k: u8 = @intCast(key.cp);
+ var children: [bindings.max_children]bindings.Child = undefined;
+ const child = for (bindings.level(p, root, s.scope[0..s.scope_n], &children)) |c| {
+ if (c.key == k) break c;
+ } else null;
+ s.scope[s.scope_n] = k;
+ s.scope_n += 1;
+ const c = child orelse {
+ s.missed = true;
+ return;
+ };
+ if (!c.group) s.found = true;
+}
+
/// Help's rows at most: every leaf of every root, and the registry's words.
pub const max_hits = bindings.flat.len + 64;
@@ -95,7 +158,11 @@ pub fn current(p: *const Pardes, v: *const View) ?Current {
if (v != p.view() or v.header != null) return null;
const pane = p.panes[v.active] orelse return null;
const t = if (pane.focus == .tag) &pane.tag else &pane.body;
- const prefix = t.normal.prefix orelse return null;
+ const prefix = t.normal.prefix orelse {
+ // `"a`: the register named, its verbs next (SPEC §9).
+ const r = t.normal.register;
+ return if (r > ' ' and r <= '~') .{ .root = .register, .path = bindings.keyName(@intCast(r)) } else null;
+ };
const root: Root = switch (prefix) {
.goto_prefix => .goto,
.view_prefix => if (t.normal.sticky) .view_sticky else .view,
@@ -131,7 +198,8 @@ pub fn hostOf(p: *const Pardes) ?usize {
fn textPrefix(p: *const Pardes, v: *const View) bool {
const pane = p.panes[v.active] orelse return false;
- return pane.body.normal.prefix != null or pane.tag.normal.prefix != null;
+ return pane.body.normal.prefix != null or pane.tag.normal.prefix != null or
+ pane.body.normal.register != 0 or pane.tag.normal.register != 0;
}
/// After a key (keys.handleKey): a root newly current starts its delay; one
@@ -152,6 +220,8 @@ pub fn follow(p: *Pardes) void {
/// Back to rest in the live view: no root waits, no typing state, nothing
/// unrolled (a word run from the band, Esc in a typing state).
pub fn toRest(p: *Pardes) void {
+ // A picker rolls up first: every body it previewed in as it was.
+ @import("Pick.zig").rollUp(p);
const v = p.view();
v.prefix = .none;
v.window_pick = null;
@@ -179,17 +249,61 @@ pub fn dated(p: *Pardes, now_ns: u64) void {
};
}
-/// When a level next shows, for the loop's wake (Pardes.nextWake).
+/// When a level next shows, for the loop's wake (Pardes.nextWake): a root
+/// struck and not dated yet wants the next frame, whose advance dates it
+/// (a pump settles its keys after its advance: a wake that waited for
+/// the date would sleep until the next key, the level never shown).
pub fn wake(p: *const Pardes) ?u64 {
var soonest: ?u64 = null;
for (p.views) |slot| if (slot) |v| {
- const due = v.tag_state.due_ns;
- if (due == asked or due == 0 or due <= p.clock.stepped_ns) continue;
+ var due = v.tag_state.due_ns;
+ if (due == asked) due = p.clock.stepped_ns + pardes.frame_ns;
+ if (due == 0 or due <= p.clock.stepped_ns) continue;
soonest = if (soonest) |n| @min(n, due) else due;
};
return soonest;
}
+/// Each view's tag state as a dump gave it, held to what it indexes: Help's
+/// hits in the tree and the registry, its rows' cursor in them, the field's
+/// caret in its text, describe-key's found leaf or struck key in its keys.
+/// One that is not (a damaged dump: the fuzz's cut and flipped bytes) is
+/// at rest, its memory of leaves kept (dump.zig afterLoad).
+pub fn loaded(p: *Pardes) void {
+ for (&p.views) |*slot| if (slot.*) |*v| {
+ const s = &v.tag_state;
+ var held = s.field.caret <= s.field.len and s.nhits <= max_hits and s.rows.at < @max(1, s.nhits) and !(s.found and s.scope_n == 0) and !(s.missed and s.scope_root == null and s.scope_n == 0);
+ for (s.hits[0..@min(s.nhits, max_hits)]) |at| held = held and at < bindings.flat.len + p.kinds.nwords;
+ if (!held) s.* = .{ .used = s.used };
+ };
+}
+
+/// Asking (SPEC §3.2, §10.2): a question waiting on the pane, its tag at
+/// rest, in place of the tag's own text: what it asks, `▸`, each answer's
+/// key and word, and how to give one (`Esc later` while SPC e has given it
+/// the keyboard). The pane's state, not the view's keyboard: every view
+/// shows it; not while the tag has the keyboard, whose own text is edited
+/// then.
+fn asking(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?Head {
+ if (pane.focus == .tag or pane.prompt == .name) return null;
+ const i = p.messages.waiting(pane) orelse return null;
+ const said = &p.messages.live[i];
+ var b: Builder = .{ .arena = arena };
+ try b.put(" ");
+ try b.put(said.words());
+ try b.put(" ");
+ try b.styled("▸", .key);
+ for (said.asks.answers()) |a| {
+ try b.put(" ");
+ try b.styled(&.{a.key}, .key);
+ try b.put(" ");
+ try b.put(a.word);
+ try b.put(" ");
+ }
+ try b.styled(if (p.view().answering == pane.serial) "· Esc later" else "· SPC e to answer", .dim);
+ return b.done();
+}
+
/// The last leaf run in the current level, as the line under it says it
/// (Messages' leader band): `k Hover: its summary (last used here)`, while
/// the level is shown rolled.
@@ -212,6 +326,10 @@ pub fn lastUsed(p: *const Pardes, v: *const View, buf: []u8) ?[]const u8 {
pub fn point(p: *Pardes, index: u16) void {
const v = p.view();
const s = &v.tag_state;
+ if (s.kind == .pick) {
+ s.rows.at = index;
+ return;
+ }
const cur = current(p, v) orelse return;
var children: [bindings.max_children]bindings.Child = undefined;
const level = bindings.level(p, cur.root, cur.path, &children);
@@ -361,10 +479,10 @@ const Builder = struct {
};
/// The head of pane `pane`'s tag while it is out of rest in the live view,
-/// null at rest.
+/// or while a question waits on it at rest (`asking`); null at rest.
pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?Head {
- const id = hostOf(p) orelse return null;
- if (p.panes[id] != pane) return null;
+ const id = hostOf(p) orelse return asking(p, arena, pane);
+ if (p.panes[id] != pane) return asking(p, arena, pane);
const v = p.view();
const s = &v.tag_state;
var b: Builder = .{ .arena = arena };
@@ -383,8 +501,50 @@ pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?Head {
h.spans = b.spans.items;
return h;
},
- .describe => return null,
+ // `Keys`, then the keys replayed: `Keys g ▸ d Def`; struck,
+ // `runs nothing`.
+ .describe => {
+ try b.put(" Keys ");
+ if (s.missed) {
+ var buf: [64]u8 = undefined;
+ const keys = if (s.scope_root) |r| bindings.chord(r, s.scope[0..s.scope_n], &buf) else bindings.keyName(s.scope[0]);
+ try b.styled(keys, .strike);
+ // A key no root is: normal mode's own, no sequence.
+ try b.put(if (s.scope_root == null) " starts no sequence" else " runs nothing");
+ } else if (s.scope_root) |r| {
+ const n = s.scope_n - @intFromBool(s.found);
+ try b.keyCells(r, s.scope[0..n]);
+ if (s.found) {
+ var children: [bindings.max_children]bindings.Child = undefined;
+ const k = s.scope[n];
+ try b.styled("▸", .key);
+ try b.put(" ");
+ try b.styled(bindings.keyName(k), .key);
+ for (bindings.level(p, r, s.scope[0..n], &children)) |c| if (c.key == k) {
+ try b.put(" ");
+ try b.put(c.label);
+ };
+ try b.put(" ⏎ run · esc");
+ } else try b.put("…");
+ } else try b.put("… press a key or a sequence · esc");
+ return b.done();
+ },
+ .pick => return @import("Pick.zig").head(p, arena, pane),
.prompt => return try Prompt.head(p, arena, pane),
+ // `Rename`, the name under the caret struck, the new one typed:
+ // ` Rename best → top▌ ⏎ rename · esc` (SPEC §3.5).
+ .rename => {
+ try b.put(" Rename ");
+ try b.styled(Ask.renamedWord(pane) orelse "", .strike);
+ try b.put(" → ");
+ var h = b.done();
+ h.caret = @intCast(b.text.items.len + s.field.caret);
+ try b.put(s.field.text());
+ try b.put(" ⏎ rename · esc");
+ h.text = b.text.items;
+ h.spans = b.spans.items;
+ return h;
+ },
}
const cur = current(p, v) orelse return null;
try b.put(" ");
@@ -401,25 +561,35 @@ pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?Head {
}
try b.styled("▸", .key);
// The rolled level wraps to three rows at most (SPEC §3.6): what does
- // not fit is `…`, and `↓` unrolls it whole.
+ // not fit is `…`, and `↓` unrolls it whole. A terminal's to the rows its
+ // own text takes: its pty is its body, and a which-key that took a row
+ // would resize the program under it at every SPC. Every cell is
+ // counted: the prefix, each child with its separator and a group's
+ // `…`, the ` …` after a child that is not the last, a struck key, the
+ // hint (left out, a terminal's tag took a row more at some widths).
const hint = " ↓ unroll · ? help";
+ const more = " …";
const prefix = try tagline.prefixIn(p, arena, pane);
const tab = p.settings.tab;
- const room = 3 * tagline.tagWidth(p, id) -| panes.File.displayWidth(tab, prefix) -| panes.File.displayWidth(tab, hint) -| 2;
+ const most: usize = if (pane.isTerminal()) @import("layout.zig").wantedTagRows(p, id) else 3;
+ const struck: usize = if (s.miss != 0) 1 + panes.File.displayWidth(tab, bindings.keyName(s.miss)) else 0;
+ const room = most * tagline.tagWidth(p, id) -| panes.File.displayWidth(tab, prefix) -| panes.File.displayWidth(tab, hint) -| struck;
var children: [bindings.max_children]bindings.Child = undefined;
+ const level = bindings.level(p, cur.root, cur.path, &children);
const used = s.used[node.group];
- for (bindings.level(p, cur.root, cur.path, &children)) |c| {
- const width = panes.File.displayWidth(tab, b.text.items) + 2 + bindings.keyName(c.key).len + 1 + panes.File.displayWidth(tab, c.label);
- if (width > room) {
- try b.put(" …");
+ var width = panes.File.displayWidth(tab, b.text.items);
+ for (level, 0..) |c, i| {
+ width += @as(usize, if (i == 0) 1 else 2) + panes.File.displayWidth(tab, bindings.keyName(c.key)) + 1 + panes.File.displayWidth(tab, c.label) + @intFromBool(c.group);
+ if (width + @as(usize, if (i + 1 < level.len) panes.File.displayWidth(tab, more) else 0) > room) {
+ try b.put(more);
break;
}
- try b.put(if (b.text.items.len > 0 and std.mem.endsWith(u8, b.text.items, "▸")) " " else " ");
+ try b.put(if (i == 0) " " else " ");
const lo: u32 = @intCast(b.text.items.len);
try b.styled(bindings.keyName(c.key), .key);
try b.put(" ");
try b.put(c.label);
- if (c.group) try b.put("…");
+ if (c.group or c.more) try b.put("…");
const hi: u32 = @intCast(b.text.items.len);
if (bindings.dimmed(pane, c)) try b.spans.append(arena, .{ .lo = lo, .hi = hi, .style = .dim });
if (c.key == used) try b.spans.append(arena, .{ .lo = lo, .hi = hi, .style = .under });
@@ -614,3 +784,257 @@ test "? down a level is Help for that level; Backspace on its empty field goes b
p.update(.{ .key = .{ .cp = Key.escape } });
try std.testing.expectEqual(Kind.rest, s.kind);
}
+
+test "SPC h k is describe-key: g d replays `g ▸ d Def` with its level and doc under the tag; every root answers; Enter runs it; an unbound one runs nothing" {
+ const Key = pardes.Key;
+ const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 140, .rows = 40 });
+ defer p.deinit();
+ const pane = try p.setTestFile("one\ntwo\nthree\n");
+ var frame = std.heap.ArenaAllocator.init(std.testing.allocator);
+ defer frame.deinit();
+ const a = frame.allocator();
+ for (" hk") |c| p.update(.{ .key = .{ .cp = c } });
+ const s = &p.view().tag_state;
+ try std.testing.expectEqual(Kind.describe, s.kind);
+ try std.testing.expect(std.mem.indexOf(u8, try testTag(p, a), " Keys …") != null);
+ for ("gd") |c| p.update(.{ .key = .{ .cp = c } });
+ try std.testing.expect(s.found);
+ try std.testing.expect(std.mem.indexOf(u8, try testTag(p, a), " Keys g ▸ d Def") != null);
+ // The level unrolled under the tag, the leaf on the cursor, its doc.
+ try std.testing.expect(pane.band_rows >= 4);
+ _ = try p.render(a);
+ const layer = &p.surface.tag_layers[pardes.BAND_LAYER];
+ var text: std.ArrayList(u8) = .empty;
+ for (0..layer.rows) |row| for (layer.cells[row * layer.cols ..][0..layer.cols]) |cell| try text.appendSlice(a, cell.grapheme());
+ try std.testing.expect(std.mem.indexOf(u8, text.items, "▶ d Def") != null);
+ try std.testing.expect(std.mem.indexOf(u8, text.items, "keys g d") != null);
+ // Another sequence from the next key: ] f, then SPC l r.
+ for ("]f") |c| p.update(.{ .key = .{ .cp = c } });
+ try std.testing.expect(std.mem.indexOf(u8, try testTag(p, a), " Keys ] ▸ f function") != null);
+ for (" lr") |c| p.update(.{ .key = .{ .cp = c } });
+ try std.testing.expect(std.mem.indexOf(u8, try testTag(p, a), " Keys ␣ l ▸ r Rename") != null);
+ // Unbound: struck, runs nothing.
+ for ("gq") |c| p.update(.{ .key = .{ .cp = c } });
+ try std.testing.expect(s.missed);
+ const struck = (try head(p, a, pane)).?;
+ try std.testing.expect(std.mem.endsWith(u8, struck.text, "g q runs nothing"));
+ try std.testing.expectEqual(Style.strike, struck.spans[0].style);
+ // Enter runs a found one, typed as its keys: g e, the last line.
+ for ("ge") |c| p.update(.{ .key = .{ .cp = c } });
+ try std.testing.expect(s.found);
+ p.update(.{ .key = .{ .cp = Key.enter } });
+ try std.testing.expectEqual(Kind.rest, s.kind);
+ try std.testing.expectEqual(@as(i32, 2), pane.body.cur_row);
+ try std.testing.expectEqual(@as(u16, 0), pane.band_rows);
+}
+
+test "C-w's level is window mode's, shown at once and kept while its keys move the outline, until Enter" {
+ const Key = pardes.Key;
+ const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 140, .rows = 40 });
+ defer p.deinit();
+ _ = try p.setTestFile("one\n");
+ const top = p.view().active;
+ p.newScratchBelow(top);
+ var frame = std.heap.ArenaAllocator.init(std.testing.allocator);
+ defer frame.deinit();
+ const a = frame.allocator();
+ p.update(.{ .key = .{ .cp = 'w', .ctrl = true } });
+ try std.testing.expect(p.view().window_pick != null);
+ try std.testing.expect(std.mem.endsWith(u8, try testTag(p, a), " C-w …"));
+ p.advance(p.clock.now_ns);
+ p.clock.now_ns = p.view().tag_state.due_ns;
+ try std.testing.expect(std.mem.indexOf(u8, try testTag(p, a), " C-w ▸ c Collapse d Del h Left j Down k Up l Right") != null);
+ // Sticky: a move keeps the level.
+ p.update(.{ .key = .{ .cp = 'k' } });
+ try std.testing.expect(p.view().window_pick != null);
+ try std.testing.expect(std.mem.indexOf(u8, try testTag(p, a), " C-w ▸ ") != null);
+ p.update(.{ .key = .{ .cp = Key.enter } });
+ try std.testing.expect(p.view().window_pick == null);
+ try std.testing.expect(p.view().tag_state.root == null);
+}
+
+test "a root struck in a pump, after its advance, wakes the loop for the next frame, which dates it, then for its level" {
+ const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 120, .rows = 30 });
+ defer p.deinit();
+ _ = try p.setTestFile("one\n");
+ while (p.nextEffect()) |_| {}
+ p.advance(5 * std.time.ns_per_s);
+ try std.testing.expect(p.nextWake() == null);
+ // The pump's order: its advance, then its keys (Pardes.pump, settle).
+ p.update(.{ .key = .{ .cp = ' ' } });
+ const first = p.nextWake().?;
+ try std.testing.expectEqual(p.clock.stepped_ns + pardes.frame_ns, first);
+ p.advance(first);
+ const due = p.view().tag_state.due_ns;
+ try std.testing.expectEqual(first + 250 * std.time.ns_per_ms, due);
+ const second = p.nextWake().?;
+ try std.testing.expect(second >= due and second < due + pardes.frame_ns);
+ p.advance(second);
+ try std.testing.expect(shown(p, p.view()));
+ try std.testing.expect(p.nextWake() == null);
+}
+
+test "a terminal's rolled level takes no more tag rows than its own text: its pty keeps its size" {
+ if (pardes.Term.ops == null) return error.SkipZigTest; // a shell
+ const p = try Pardes.init(std.testing.allocator, .{ .file = "mise.toml", .cols = 40, .rows = 30 });
+ defer p.deinit();
+ _ = pardes.exec.spawnTty(p, 0);
+ const shell = p.view().active;
+ const pane = p.panes[shell].?;
+ pane.body.mode = .normal;
+ p.sync();
+ const rows, const tag_rows = .{ pane.rows, pane.tag_rows };
+ p.update(.{ .key = .{ .cp = ' ' } });
+ p.advance(p.clock.now_ns);
+ p.clock.now_ns = p.view().tag_state.due_ns;
+ p.sync();
+ try std.testing.expect(hostOf(p) == shell);
+ try std.testing.expectEqual(tag_rows, pane.tag_rows);
+ try std.testing.expectEqual(rows, pane.rows);
+}
+
+test "a rolled level fits its rows at every width: its `…`, its groups' `…` and a struck key are counted" {
+ const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 120, .rows = 40 });
+ defer p.deinit();
+ _ = try p.setTestFile("one\n");
+ var frame = std.heap.ArenaAllocator.init(std.testing.allocator);
+ defer frame.deinit();
+ const a = frame.allocator();
+ const pane = p.panes[p.view().active].?;
+ for ([_]pardes.Key{ .{ .cp = ' ' }, .{ .cp = 'w', .ctrl = true } }) |root| for ([_]bool{ false, true }) |struck| {
+ p.update(.{ .key = root });
+ p.advance(p.clock.now_ns);
+ p.clock.now_ns = p.view().tag_state.due_ns;
+ // `x` is a child of neither level: struck, the level stays.
+ if (struck) p.update(.{ .key = .{ .cp = 'x' } });
+ for (30..161) |cols| {
+ p.update(.{ .resize = .{ .cols = @intCast(cols), .rows = 40 } });
+ try std.testing.expect(hostOf(p) != null);
+ try std.testing.expect((try tagline.shownTag(p, a, pane)).rows() <= 3);
+ }
+ toRest(p);
+ p.update(.{ .resize = .{ .cols = 120, .rows = 40 } });
+ };
+}
+
+test "a terminal's rolled level keeps its tag rows at every width, C-w's as SPC's: its pty is never resized" {
+ if (pardes.Term.ops == null) return error.SkipZigTest; // a shell
+ const p = try Pardes.init(std.testing.allocator, .{ .file = "mise.toml", .cols = 100, .rows = 30 });
+ defer p.deinit();
+ _ = pardes.exec.spawnTty(p, 0);
+ const shell = p.view().active;
+ const pane = p.panes[shell].?;
+ pane.body.mode = .normal;
+ for ([_]pardes.Key{ .{ .cp = ' ' }, .{ .cp = 'w', .ctrl = true } }) |root| for (30..131) |cols| {
+ p.update(.{ .resize = .{ .cols = @intCast(cols), .rows = 30 } });
+ p.sync();
+ const rows, const tag_rows = .{ pane.rows, pane.tag_rows };
+ p.update(.{ .key = root });
+ // Its key cell alone, before the level shows: shorter than the
+ // tag's own text, the rows it had.
+ p.sync();
+ try std.testing.expect(hostOf(p) == shell);
+ try std.testing.expectEqual(tag_rows, pane.tag_rows);
+ try std.testing.expectEqual(rows, pane.rows);
+ p.advance(p.clock.now_ns);
+ p.clock.now_ns = p.view().tag_state.due_ns;
+ p.sync();
+ try std.testing.expectEqual(tag_rows, pane.tag_rows);
+ try std.testing.expectEqual(rows, pane.rows);
+ toRest(p);
+ };
+}
+
+test "a tag out of rest keeps its rows at rest at least: a root's key cell alone moves no body up" {
+ const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 40, .rows = 30 });
+ defer p.deinit();
+ _ = try p.setTestFile("one\n");
+ const pane = p.panes[p.view().active].?;
+ p.sync();
+ const rows, const tag_rows = .{ pane.rows, pane.tag_rows };
+ try std.testing.expect(tag_rows > 1);
+ p.update(.{ .key = .{ .cp = ' ' } });
+ p.sync();
+ try std.testing.expect(hostOf(p) != null);
+ try std.testing.expectEqual(tag_rows, pane.tag_rows);
+ try std.testing.expectEqual(rows, pane.rows);
+ // With the keyboard in the tag (whose top row follows its caret) too:
+ // C-w's key cell, a line, in a tag of more rows.
+ toRest(p);
+ pane.focus = .tag;
+ p.update(.{ .key = .{ .cp = 'w', .ctrl = true } });
+ p.sync();
+ try std.testing.expect(hostOf(p) != null);
+ try std.testing.expectEqual(tag_rows, pane.tag_rows);
+ try std.testing.expectEqual(@as(u16, 0), pane.tag_top);
+}
+
+test "a dump's tag state that indexes past what it names is at rest when loaded, and its frame draws" {
+ const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 120, .rows = 40 });
+ defer p.deinit();
+ _ = try p.setTestFile("one\n");
+ var frame = std.heap.ArenaAllocator.init(std.testing.allocator);
+ defer frame.deinit();
+ for (" ?hel") |c| p.update(.{ .key = .{ .cp = c, .text = &[_]u8{c} } });
+ const s = &p.view().tag_state;
+ try std.testing.expect(s.kind == .help and s.nhits > 0);
+ loaded(p);
+ try std.testing.expect(s.kind == .help);
+ // A hit past the tree and the registry's words, as a cut dump made one.
+ s.hits[0] = 65163;
+ s.used[0] = 'q';
+ loaded(p);
+ try std.testing.expect(s.kind == .rest and s.nhits == 0 and s.used[0] == 'q');
+ _ = try p.render(frame.allocator());
+ // A caret past the field's text, a cursor past the rows.
+ for (" ?hel") |c| p.update(.{ .key = .{ .cp = c, .text = &[_]u8{c} } });
+ s.field.caret = s.field.len + 1;
+ loaded(p);
+ try std.testing.expect(s.kind == .rest);
+ for (" ?hel") |c| p.update(.{ .key = .{ .cp = c, .text = &[_]u8{c} } });
+ s.rows.at = s.nhits;
+ loaded(p);
+ try std.testing.expect(s.kind == .rest);
+}
+
+test "a click that gives the keyboard to another pane ends a level as Esc does; one in the level's own tag keeps it" {
+ const config = @import("config.zig");
+ const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 120, .rows = 40 });
+ defer p.deinit();
+ _ = try p.setTestFile("one\ntwo\n");
+ const top = p.view().active;
+ p.newScratchBelow(top);
+ const low = p.view().active;
+ try std.testing.expect(low != top);
+ const click = struct {
+ fn at(q: *Pardes, col: u16, row: u16) void {
+ q.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = col, .row = row } });
+ q.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = col, .row = row } });
+ }
+ }.at;
+ const rt = p.view().rects[top];
+ const rl = p.view().rects[low];
+ // SPC's level in the lower pane's tag; a click in its own tag keeps it.
+ p.update(.{ .key = .{ .cp = ' ' } });
+ try std.testing.expect(hostOf(p) == low);
+ click(p, rl.x + config.GUTTER + 2, rl.y);
+ try std.testing.expect(hostOf(p) == low and p.view().prefix == .leader);
+ // A click in the other pane's body: the keyboard goes there, the level
+ // ends, nothing out of rest.
+ click(p, rt.x + config.GUTTER + 1, rt.y + pardes.BOX_H);
+ try std.testing.expectEqual(top, p.view().active);
+ try std.testing.expect(hostOf(p) == null and p.view().prefix == .none and p.view().tag_state.root == null);
+ // A helix prefix's level (g, shown after its delay) the same, its text's
+ // prefix gone with it; Help, a typing state, the same.
+ p.update(.{ .key = .{ .cp = 'g' } });
+ p.advance(p.clock.now_ns);
+ p.clock.now_ns = p.view().tag_state.due_ns;
+ try std.testing.expect(hostOf(p) == top);
+ click(p, rl.x + config.GUTTER + 1, rl.y + pardes.BOX_H);
+ try std.testing.expectEqual(low, p.view().active);
+ try std.testing.expect(hostOf(p) == null and p.panes[top].?.body.normal.prefix == null);
+ for (" ?") |c| p.update(.{ .key = .{ .cp = c } });
+ try std.testing.expect(p.view().tag_state.kind == .help);
+ click(p, rt.x + config.GUTTER + 1, rt.y + pardes.BOX_H);
+ try std.testing.expect(p.view().tag_state.kind == .rest and hostOf(p) == null);
+}
diff --git a/core/Term.zig b/core/Term.zig
index f0329852..d4baf4e8 100644
--- a/core/Term.zig
+++ b/core/Term.zig
@@ -422,7 +422,7 @@ pub const calls = [_]struct { []const u8, []const u8, []const u8 }{
.{ "endOutputHere", "ninep/pty.zig:1", "WRITE: a 9P pty/run's step ends a command's output at the cursor: the session's step, replayed as such" },
.{ "replies", "Core.zig:1", "WRITE: a step drains the reply buffer (in the digest), counted when it held any (the feed's own unit, which filled it); only the session writes it to the pty (pty_write is off the tape)" },
// ---- reads by a step: in the digest ----
- .{ "grid", "Core.zig:2 ansi.zig:3 body_layer.zig:3 draw.zig:2 dump.zig:4 echo.zig:8 exec.zig:2 layout.zig:2 panes.zig:5 replica.zig:2", "READ: the size, the history's length, the cursor: in the digest (a view's place is its pane's; ansi.zig, body_layer.zig, draw.zig, echo.zig: a draw's)" },
+ .{ "grid", "Core.zig:2 ansi.zig:3 body_layer.zig:3 draw.zig:2 dump.zig:4 echo.zig:8 exec.zig:2 layout.zig:2 panes.zig:6 replica.zig:2", "READ: the size, the history's length, the cursor: in the digest (a view's place is its pane's; ansi.zig, body_layer.zig, draw.zig, echo.zig: a draw's)" },
.{ "modes", "Core.zig:5 draw.zig:1 dump.zig:2 echo.zig:3 exec.zig:3 mouse.zig:4 ninep/pty.zig:3 panes.zig:2 replica.zig:1", "READ: the program's modes (mouse, focus, bracketed paste, the alternate screen): in the digest (draw.zig, echo.zig: a draw's; panes.zig: a view scrolls no history on the alternate screen)" },
.{ "prompt", "Core.zig:1 builtins.zig:1 echo.zig:1 exec.zig:3 ninep/pty.zig:1 panes.zig:1", "READ: the OSC 133 cycle: in the digest (`marksOf`); Core.zig's and ninep/pty.zig's also taped (`.prompt`, each side's compared)" },
.{ "promptPrefix", "body_layer.zig:1 edit.zig:1 exec.zig:1", "READ: a row's prompt cells (`promptCut`): the active area's in the digest; a history row's text is not (below)" },
@@ -441,7 +441,7 @@ pub const calls = [_]struct { []const u8, []const u8, []const u8 }{
.{ "commandOutput", "ninep/pty.zig:1", "READ, NOT COVERED: a command's output rows (a 9P pty/run): taped as the session's answer" },
.{ "textRows", "edit.zig:2", "READ, NOT COVERED: every row's text, the history's among them (a selection, a Look over a shell)" },
.{ "viewport", "body_layer.zig:1 replica.zig:1", "READ: the rows' text a view's place (in the digest, with its pane) shows (body_layer.zig: a draw's; replica.zig: a test's)" },
- .{ "editRows", "ansi.zig:1", "READ: rows' text for a draw" },
+ .{ "editRows", "ansi.zig:1 panes.zig:1", "READ: rows' text for a draw; a command's last rows read for the places its report names when it fails (panes.zig commandDone): in the digest as the emulator's rows are" },
// ---- local ----
.{ "due", "Core.zig:1", "LOCAL: its next wake (a blink, an animation): the loop's, never a step's state" },
.{ "cellPixels", "ansi.zig:1 panes.zig:2", "LOCAL: a frontend's draw sets its view's cell size (ansi.zig); a step sets the view's (in the digest) before each feed (panes.zig), so a reply to CSI 16 t is the step's" },
@@ -559,10 +559,10 @@ test "a core without a terminal: Term refuses in words, and no line is typed at
try std.testing.expectError(error.NoTerminal, p.newShell(p.freeSlot().?, ""));
try std.testing.expect(p.executeBuiltinLine(0, "Term"));
const pane = p.panes[0].?;
- try std.testing.expectEqualStrings("Term: " ++ none, pane.msg[0..pane.msg_len]);
+ try std.testing.expectEqualStrings("Term: " ++ none, p.messages.saidBy(pane));
// A line no shell can take runs in a command pane, a terminal: refused.
try std.testing.expectEqual(null, pardes.exec.execute(p, 0, "make"));
- try std.testing.expectEqualStrings("exec: " ++ none, pane.msg[0..pane.msg_len]);
+ try std.testing.expectEqualStrings("exec: " ++ none, p.messages.saidBy(pane));
for (p.panes, 0..) |slot, id| if (slot) |_| try std.testing.expect(!pardes.exec.takesCommandLine(p, id));
}
diff --git a/core/Trail.zig b/core/Trail.zig
index cb5dedf8..9223d1d3 100644
--- a/core/Trail.zig
+++ b/core/Trail.zig
@@ -18,6 +18,7 @@ const look = @import("look.zig");
const Pardes = pardes.Pardes;
const Pane = panes.Pane;
const Spot = look.Spot;
+const TagState = @import("TagState.zig");
const Trail = @This();
@@ -164,6 +165,32 @@ pub fn go(p: *Pardes, id: usize, i: u8) !usize {
return show(p, id, s.place.path.slice(), .{ .line = s.place.line, .col = s.place.col });
}
+/// A list the pane's newest step came through (§6.2: a picker's Enter,
+/// Pick.zig): its word before the step's place.
+pub fn through(t: *Trail, s: Step) void {
+ if (t.cur >= t.n or t.steps[t.cur] != .place) return;
+ if (t.n == max_steps) {
+ const first: usize = @intFromBool(t.steps[0] == .owner);
+ if (t.cur <= first) return;
+ std.mem.copyForwards(Step, t.steps[first .. max_steps - 1], t.steps[first + 1 ..]);
+ t.n -= 1;
+ t.cur -= 1;
+ }
+ std.mem.copyBackwards(Step, t.steps[t.cur + 1 .. t.n + 1], t.steps[t.cur..t.n]);
+ t.steps[t.cur] = s;
+ t.n += 1;
+ t.cur += 1;
+}
+
+/// Reading pane `id`'s current step replaced by `path` at `at`, no step
+/// pushed (a list's `n`, §5.6); its slot after it, as `step`'s.
+pub fn replaceStep(p: *Pardes, id: usize, path: []const u8, at: Spot) !usize {
+ const to = placeOf(path, at.line, at.col) orelse return error.NameTooLong;
+ const t = &p.panes[id].?.trail;
+ if (t.cur < t.n) t.steps[t.cur] = to;
+ return show(p, id, path, at);
+}
+
/// Pane `id` showing `path` at `at`, the keyboard on it: its caret moved
/// in the file it shows, or a new pane on `path` in its place, its walk
/// with it. A line past the new file's end is a miss that changes nothing.
@@ -172,6 +199,7 @@ fn show(p: *Pardes, id: usize, path: []const u8, at: Spot) !usize {
if (pane.file) |f| if (std.mem.eql(u8, f.path, path)) {
look.clearNavigationSelection(p, pane);
look.focusPaneLine(p, id, at, .center);
+ lift(p, id);
return id;
};
const free = p.freeSlot() orelse return error.NoPaneSlots;
@@ -188,7 +216,7 @@ fn show(p: *Pardes, id: usize, path: []const u8, at: Spot) !usize {
try panes.deinitPane(p, pane);
layout.replacePane(p, id, free);
p.panes[id] = null;
- layout.compute(p);
+ lift(p, free);
look.focusPaneLine(p, free, at, .keep);
// Its line half the body's rows down, as a look's new pane has it.
const rows = @max(1, p.view().rects[free].h -| pardes.BOX_H);
@@ -196,6 +224,17 @@ fn show(p: *Pardes, id: usize, path: []const u8, at: Spot) !usize {
return free;
}
+/// Pane `id`'s tag after a step may take more rows than it had (its walk's
+/// words, a longer name): it is given them from its column, as a step that
+/// wraps tags gives them (layout.restoreMinimaFrom), the others keeping
+/// their own minimum.
+fn lift(p: *Pardes, id: usize) void {
+ const now = p.view().rects;
+ var floor = layout.minima(p);
+ floor[id] = 0;
+ layout.restoreMinimaFrom(p, &now, &floor);
+}
+
/// `s`, a search's or a recipe's word, the pane's one of its kind (§7.3,
/// §7.5): the one it had goes, and it is the newest back step.
pub fn setWord(t: *Trail, s: Step) void {
@@ -239,7 +278,11 @@ pub fn keep(pane: *Pane) void {
}
/// An edit of file `f`: the panes showing it are held from now on (§6.5).
+/// Only where a pane could read: a session whose jumps walk, a file
+/// (isFile), so that an edit anywhere else (an output's, a 9P append's
+/// under `Jumps new-pane`) costs nothing past these checks.
pub fn edited(p: *Pardes, f: *const panes.File.State) void {
+ if (p.settings.jumps != .walk or f.output != null or f.listing != null or f.pager or f.mini != null) return;
for (p.panes) |slot| {
const pane = slot orelse continue;
if (pane.trail.held) continue;
@@ -272,9 +315,9 @@ pub const Part = enum { back, forward };
/// Step `i`'s word: `‹@p3`, `rank.zig:14`, a list's, search's or recipe's
/// own text; `·` when it is folded.
-fn wordOf(t: *const Trail, i: usize, buf: *[max_text + 16]u8) []const u8 {
+fn wordOf(t: *const Trail, i: usize, whole: usize, buf: *[max_text + 16]u8) []const u8 {
const s = &t.steps[i];
- if (s.* != .owner and i < t.cur and t.cur - i > shown_steps) return "·";
+ if (s.* != .owner and i < t.cur and t.cur - i > whole) return "·";
// The step itself, not a copy: a word's text is the step's own bytes.
return switch (s.*) {
.owner => |serial| std.fmt.bufPrint(buf, "‹" ++ config.pane_addr ++ "{d}", .{serial}) catch unreachable, // a u32 fits
@@ -294,42 +337,52 @@ fn range(t: *const Trail, part: Part) [2]usize {
}
/// The back steps' words, each with the separator after it (before the
-/// path), or the forward steps', each with one before it (after the path).
-pub fn write(t: *const Trail, part: Part, w: *std.Io.Writer) std.Io.Writer.Error!void {
+/// path), or the forward steps', each with one before it (after the path):
+/// the newest `whole` back steps whole, older ones `·` (`folded`).
+pub fn write(t: *const Trail, part: Part, whole: usize, w: *std.Io.Writer) std.Io.Writer.Error!void {
var buf: [max_text + 16]u8 = undefined;
const r = range(t, part);
for (r[0]..r[1]) |i| switch (part) {
- .back => try w.print("{s}" ++ sep, .{wordOf(t, i, &buf)}),
- .forward => try w.print(sep ++ "{s}", .{wordOf(t, i, &buf)}),
+ .back => try w.print("{s}" ++ sep, .{wordOf(t, i, whole, &buf)}),
+ .forward => try w.print(sep ++ "{s}", .{wordOf(t, i, whole, &buf)}),
};
}
/// The bytes `write` writes for `part`.
-pub fn bytes(t: *const Trail, part: Part) usize {
+pub fn bytes(t: *const Trail, part: Part, whole: usize) usize {
var buf: [max_text + 16]u8 = undefined;
var n: usize = 0;
const r = range(t, part);
- for (r[0]..r[1]) |i| n += wordOf(t, i, &buf).len + sep.len;
+ for (r[0]..r[1]) |i| n += wordOf(t, i, whole, &buf).len + sep.len;
return n;
}
-/// Where back step `i`'s word is in what `write` writes for the back steps.
-pub fn spanOf(t: *const Trail, i: usize) [2]usize {
+/// The back steps pane `pane`'s tag writes whole: `shown_steps` at rest,
+/// the newest alone while its tag is out of rest (SPEC §3.4.3), so a
+/// state's head and the band's spines keep their room.
+pub fn folded(p: *const Pardes, pane: *const Pane) usize {
+ const host = TagState.hostOf(p) orelse return shown_steps;
+ return if (p.panes[host] == pane) 1 else shown_steps;
+}
+
+/// Where back step `i`'s word is in what `write` writes for the back
+/// steps, the newest `whole` whole.
+pub fn spanOf(t: *const Trail, i: usize, whole: usize) [2]usize {
var buf: [max_text + 16]u8 = undefined;
var x: usize = 0;
- for (0..i) |j| x += wordOf(t, j, &buf).len + sep.len;
- return .{ x, x + wordOf(t, i, &buf).len };
+ for (0..i) |j| x += wordOf(t, j, whole, &buf).len + sep.len;
+ return .{ x, x + wordOf(t, i, whole, &buf).len };
}
/// The step whose word in `part` is at byte `off` of what `write` wrote
/// for it, null on a separator or past them.
-pub fn stepAt(t: *const Trail, part: Part, off: usize) ?u8 {
+pub fn stepAt(t: *const Trail, part: Part, whole: usize, off: usize) ?u8 {
var buf: [max_text + 16]u8 = undefined;
var x: usize = 0;
const r = range(t, part);
for (r[0]..r[1]) |i| {
if (part == .forward) x += sep.len;
- const n = wordOf(t, i, &buf).len;
+ const n = wordOf(t, i, whole, &buf).len;
if (off >= x and off < x + n) return @intCast(i);
x += n;
if (part == .back) x += sep.len;
@@ -338,8 +391,9 @@ pub fn stepAt(t: *const Trail, part: Part, off: usize) ?u8 {
}
/// Look on step `i` of pane `id`'s trail (§6.3): a place is gone back or
-/// forward to, the owner focused, a search lit again, a recipe's
-/// selections put back (Prompt.zig); a list is the pickers' (not yet: said).
+/// forward to, the owner focused, a list unrolled again as it was
+/// (Pick.reopen), a search lit again, a recipe's selections put back
+/// (Prompt.zig).
pub fn lookStep(p: *Pardes, id: usize, i: u8) void {
const pane = p.panes[id] orelse return;
switch (pane.trail.steps[i]) {
@@ -347,21 +401,21 @@ pub fn lookStep(p: *Pardes, id: usize, i: u8) void {
.owner => |serial| if (p.paneBySerial(serial)) |owner| {
p.view().active = owner;
} else p.reportFailure(id, "walk: its owner is closed"),
+ .list => |w| pardes.Pick.reopen(p, id, w.index),
.search => pardes.Prompt.lookWord(p, id),
.recipe => pardes.Prompt.lookRecipe(p, id),
- .list => p.setMessage(.at(id), "walk: a list is not walked yet"),
}
}
/// Exec on step `i` (§6.3): a place and the owner as Look; a list runs its
-/// source again, a search searches again, a recipe replays (not yet).
+/// source again, a search searches again, a recipe replays.
pub fn execStep(p: *Pardes, id: usize, i: u8) void {
const pane = p.panes[id] orelse return;
switch (pane.trail.steps[i]) {
.place, .owner => lookStep(p, id, i),
+ .list => |w| pardes.Pick.rerun(p, id, w.index),
.search => pardes.Prompt.execWord(p, id),
.recipe => pardes.Prompt.execRecipe(p, id),
- .list => p.setMessage(.at(id), "walk: a list is not run again yet"),
}
}
@@ -629,6 +683,51 @@ test "the session of pick-ui §6.7: four jumps across three files, back by a cli
try std.testing.expectEqual(owner, p.panes[fresh].?.trail.steps[0].owner);
}
+test "the walk drawn with a picker's list and the notice row (walk UI G 2e, SPEC §3.7, §6.7): a list handed to a held pane lands in its reader, its word in the reader's trail before the place, the reader's tag in the reading tint with Keep, the held pane's not, n walking the list, the notice row at the foot saying where the caret is" {
+ var f: Fixture = .{ .p = undefined, .tmp = undefined };
+ try f.init(40);
+ defer f.deinit();
+ const p = f.p;
+ p.messages.live_len = 0;
+ const owner = p.panes[f.held].?.serial;
+ var buf: [4096 + 128]u8 = undefined;
+ var want: [4096 + 128]u8 = undefined;
+ // g d from the held pane: its reader, made below it.
+ f.look(f.held, "rank.zig", 12);
+ const r = p.view().active;
+ // A list asked from the held pane (SPC e's places, a server's answer):
+ // its Enter lands in the reader, nothing made.
+ const rows = try std.fmt.bufPrint(&buf, "{s}/place.zig:8:1 of\n{s}/place.zig:40:1 Span\n", .{ f.dir, f.dir });
+ pardes.Pick.open(p, f.held, .list, "Refs", "", rows);
+ try std.testing.expectEqual(p.panes[r].?.serial, p.view().tag_state.host);
+ pardes.Pick.landHere(p);
+ p.sync();
+ // The reader stepped (to another file: a pane of its own, its owner's
+ // word kept), no pane more.
+ var n: usize = 0;
+ for (p.panes) |slot| n += @intFromBool(slot != null);
+ try std.testing.expectEqual(@as(usize, 3), n);
+ const rd = p.view().active;
+ try std.testing.expect(rd != f.held and p.panes[r] == null);
+ try std.testing.expect(std.mem.startsWith(u8, try tagOf(p, p.panes[rd].?), try std.fmt.bufPrint(&want, "‹@p{d} › rank.zig:12 › Refs 1/2 › {s}/place.zig Keep ", .{ owner, f.dir })));
+ var arena: std.heap.ArenaAllocator = .init(std.testing.allocator);
+ defer arena.deinit();
+ // The reader's tag in the reading tint, the held one's not; the notice
+ // row, nothing said, where the reader's caret is.
+ try std.testing.expectEqual(pardes.Color{ .rgb = p.chromeTheme().tag_reading_bg }, try tagGroundOf(p, &arena, rd));
+ try std.testing.expect(!std.meta.eql(pardes.Color{ .rgb = p.chromeTheme().tag_reading_bg }, try tagGroundOf(p, &arena, f.held)));
+ const s = try p.render(arena.allocator());
+ const foot = s.region(.notice_row, pardes.Region.none).?.rect;
+ var row: std.ArrayList(u8) = .empty;
+ for (0..s.cols) |x| try row.appendSlice(arena.allocator(), s.at(@intCast(x), foot.y).grapheme());
+ try std.testing.expect(std.mem.indexOf(u8, row.items, try std.fmt.bufPrint(&want, "{s}/place.zig:8", .{f.dir})) != null);
+ // n: the list's next place, in place of the current step.
+ typeKeys(p, "n");
+ p.sync();
+ try std.testing.expectEqual(@as(i32, 39), p.panes[rd].?.body.cur_row);
+ try std.testing.expect(std.mem.indexOf(u8, try tagOf(p, p.panes[rd].?), "› Refs 2/2 ›") != null);
+}
+
test "a trail keeps its newest three back steps whole, older ones fold to ·, and a click on a · goes back to its step" {
var f: Fixture = .{ .p = undefined, .tmp = undefined };
try f.init(60);
@@ -700,3 +799,62 @@ test "closing a held pane closes its reader; a kept reader stays; typed into, a
try std.testing.expect(p.paneBySerial(fresh_serial) == null);
try std.testing.expect(p.panes[r] != null);
}
+
+test "Jumps new-pane jumps as before the walk: a new pane for a file no pane shows, under the asking one, the one showing it focused, nothing stepped" {
+ var f: Fixture = .{ .p = undefined, .tmp = undefined };
+ try f.init(60);
+ defer f.deinit();
+ const p = f.p;
+ p.settings.jumps = .@"new-pane";
+ var at: [64]u8 = undefined;
+ var open: usize = 0;
+ for (p.panes) |slot| open += @intFromBool(slot != null);
+ // From the held pane and from the reading one: a new pane each time.
+ f.look(f.held, "rank.zig", 12);
+ const rank = p.view().active;
+ try std.testing.expectEqualStrings("rank.zig:12", f.at(&at));
+ f.look(rank, "place.zig", 8);
+ try std.testing.expect(p.view().active != rank and p.panes[rank] != null);
+ try std.testing.expectEqualStrings("place.zig:8", f.at(&at));
+ // A file a pane shows: that pane, focused; nothing new, no walk.
+ f.look(p.view().active, "rank.zig", 30);
+ try std.testing.expectEqual(rank, p.view().active);
+ try std.testing.expectEqualStrings("rank.zig:30", f.at(&at));
+ var now: usize = 0;
+ for (p.panes) |slot| if (slot) |pane| {
+ now += 1;
+ try std.testing.expectEqual(@as(u8, 0), pane.trail.n);
+ };
+ try std.testing.expectEqual(open + 2, now);
+}
+
+test "Enter on a word of the walk, the keyboard in the tag, goes back to its step as a click does; out of rest the walk folds to its newest word" {
+ var f: Fixture = .{ .p = undefined, .tmp = undefined };
+ try f.init(60);
+ defer f.deinit();
+ const p = f.p;
+ const owner = p.panes[f.held].?.serial;
+ for ([_]usize{ 10, 20, 30 }) |line| f.look(f.held, "rank.zig", line);
+ const r = p.view().active;
+ const pane = p.panes[r].?;
+ var buf: [4096 + 128]u8 = undefined;
+ var at: [64]u8 = undefined;
+ const rest = try std.fmt.bufPrint(&buf, "‹@p{d} › rank.zig:10 › rank.zig:20 › {s}/rank.zig Keep", .{ owner, f.dir });
+ try std.testing.expect(std.mem.startsWith(u8, try tagOf(p, pane), rest));
+ // SPC: out of rest, the older steps are `·`, the owner and the newest
+ // whole; back at rest, as they were.
+ p.update(.{ .key = .{ .cp = ' ' } });
+ var folded_buf: [4096 + 128]u8 = undefined;
+ try std.testing.expect(std.mem.startsWith(u8, try tagOf(p, pane), try std.fmt.bufPrint(&folded_buf, "‹@p{d} › · › rank.zig:20 › {s}/rank.zig", .{ owner, f.dir })));
+ p.update(.{ .key = .{ .cp = pardes.Key.escape } });
+ try std.testing.expect(std.mem.startsWith(u8, try tagOf(p, pane), rest));
+ // The keyboard in the tag, its cursor on `rank.zig:10`: Enter goes back
+ // to that step, the keyboard in the body again.
+ pane.focus = .tag;
+ pane.tag.cur_row = 0;
+ pane.tag.cur_col = @intCast(std.mem.indexOf(u8, rest, "rank.zig:10").? + 2);
+ p.update(.{ .key = .{ .cp = pardes.Key.enter } });
+ p.sync();
+ try std.testing.expectEqualStrings("rank.zig:10", f.at(&at));
+ try std.testing.expect(pane.focus == .body);
+}
diff --git a/core/bindings.zig b/core/bindings.zig
index b2d84a7c..2df51945 100644
--- a/core/bindings.zig
+++ b/core/bindings.zig
@@ -15,6 +15,8 @@ const Pardes = pardes.Pardes;
const Pane = pardes.Pane;
const Key = pardes.Key;
const Role = modal.Normal.Role;
+const edit = @import("edit.zig");
+const File = @import("File.zig");
/// The keys a sequence starts with. `register` (`"`) is drawn the same way
/// but its rows are the registers' contents, not a tree.
@@ -87,8 +89,9 @@ pub const groups = groups: {
};
break :groups paths;
};
-/// SPC's groups, then one for each other root.
-pub const ngroups = groups.len + std.enums.values(Root).len - 1;
+/// SPC's groups, then one for each other root, then the verbs a register
+/// takes (`"a ▸`).
+pub const ngroups = groups.len + std.enums.values(Root).len;
fn rootGroup(comptime r: Root) u8 {
return @intCast(groups.len + @intFromEnum(r) - 1);
@@ -233,6 +236,15 @@ const view_sticky_tree: Node = .{ .key = config.view_prefix_sticky, .label = "vi
const prev_tree: Node = .{ .key = config.prev_prefix, .label = "previous", .children = roleLevel(.goto_paragraph, .goto_xml_element, &.{}), .group = rootGroup(.prev) };
const next_tree: Node = .{ .key = config.next_prefix, .label = "next", .children = roleLevel(.goto_paragraph, .goto_xml_element, &.{}), .group = rootGroup(.next) };
const register_tree: Node = .{ .key = config.register_prefix, .label = "registers", .group = rootGroup(.register) };
+/// What the register `"` named does next (SPEC §9: `"a ▸ p after P before
+/// y into R replace`): normal mode's paste, yank and replace, which read
+/// the register the parser holds.
+const register_verbs: Node = .{ .key = 0, .label = "register", .group = ngroups - 1, .children = sorted(&.{
+ .{ .key = roleKey(.paste_after).?, .label = "after", .leaf = .{ .role = .paste_after } },
+ .{ .key = roleKey(.paste_before).?, .label = "before", .leaf = .{ .role = .paste_before } },
+ .{ .key = roleKey(.yank).?, .label = "into", .leaf = .{ .role = .yank } },
+ .{ .key = roleKey(.replace_with_yank).?, .label = "replace", .leaf = .{ .role = .replace_with_yank } },
+}) };
/// pardes's window mode (layout.windowKey): its moves, Collapse and Del;
/// a letter picks the pane its box shows.
const window_tree: Node = .{ .key = 'w', .label = "window", .group = rootGroup(.window), .children = window: {
@@ -248,7 +260,13 @@ const window_tree: Node = .{ .key = 'w', .label = "window", .group = rootGroup(.
/// The node `path` reaches under `root`, or null.
pub fn nodeAt(root: Root, path: []const u8) ?*const Node {
var n = info.get(root).node;
- for (path) |k| n = for (n.children) |*c| {
+ var keys = path;
+ // A register's name is any key: under each, its verbs.
+ if (root == .register and path.len > 0) {
+ n = &register_verbs;
+ keys = path[1..];
+ }
+ for (keys) |k| n = for (n.children) |*c| {
if (c.key == k) break c;
} else return null;
return n;
@@ -263,6 +281,8 @@ pub const Child = struct {
word: ?*const pardes.Kind.Word = null,
group: bool = false,
lsp: bool = false,
+ /// Its label is cut (a register's first line): `…` after it.
+ more: bool = false,
};
/// The most children a level shows: SPC's top has 17, and an addon's
/// words (Kind.Registry's 64) may each start a key of their own.
@@ -273,6 +293,7 @@ pub const max_children = 96;
/// addons' leader words joined in (SPC alone). Bounded by the level and the
/// registry's 64 words.
pub fn level(p: *const Pardes, root: Root, path: []const u8, out: *[max_children]Child) []Child {
+ if (root == .register and path.len == 0) return registerLevel(p, out);
var n: usize = 0;
if (nodeAt(root, path)) |node| for (node.children) |*c| {
if (c.leaf) |leaf| if (leaf == .builtin and !builtins.registry.here(p, leaf.builtin)) continue;
@@ -300,6 +321,87 @@ pub fn level(p: *const Pardes, root: Root, path: []const u8, out: *[max_children
return shown;
}
+/// The registers `"` shows (SPEC §9), in its order, and what each is: the
+/// default first, the ones a name was given (`"ay`) after it, by name,
+/// then these, the last four computed from the pane with the keyboard.
+pub const register_names = [_]struct { key: u8, name: []const u8 }{
+ .{ .key = '"', .name = "yank" },
+ .{ .key = '/', .name = "last search" },
+ .{ .key = ':', .name = "last command" },
+ .{ .key = '|', .name = "last pipe" },
+ .{ .key = '+', .name = "system clipboard" },
+ .{ .key = '@', .name = "last macro" },
+ .{ .key = '%', .name = "this file's name" },
+ .{ .key = '.', .name = "the selections" },
+ .{ .key = '#', .name = "selection numbers" },
+ .{ .key = '_', .name = "black hole" },
+};
+
+/// The display columns of a register's first line which-key shows; the
+/// rest is `…`.
+pub const register_cut = 24;
+
+/// `"`'s level: a child a register, its label the first line of its value
+/// (`—` when empty), cut. Read when the level is (a key, a frame), never
+/// kept: the first `register_cut` columns of each, the named ones bounded
+/// by the level's room.
+fn registerLevel(p: *const Pardes, out: *[max_children]Child) []Child {
+ var n: usize = 1;
+ for (p.registers.list.items) |*reg| {
+ if (reg.name <= ' ' or reg.name > '~' or n == out.len - (register_names.len - 1)) continue;
+ const k: u8 = @intCast(reg.name);
+ for (register_names) |r| {
+ if (r.key == k) break;
+ } else {
+ var j = n;
+ while (j > 1 and out[j - 1].key > k) : (j -= 1) out[j] = out[j - 1];
+ out[j] = .{ .key = k, .label = "" };
+ n += 1;
+ }
+ }
+ out[0] = .{ .key = '"', .label = "" };
+ for (register_names[1..]) |r| {
+ out[n] = .{ .key = r.key, .label = "" };
+ n += 1;
+ }
+ for (out[0..n]) |*c| {
+ const value = registerValue(p, c.key);
+ const bound = if (value.len > 4 * register_cut) modal.graphemeStart(value, 4 * register_cut) else value.len;
+ const line = value[0 .. std.mem.indexOfScalar(u8, value[0..bound], '\n') orelse bound];
+ const cut = File.byteAtDisplay(p.settings.tab, line, register_cut);
+ c.label = if (value.len == 0) "—" else line[0..cut];
+ c.more = cut < value.len;
+ }
+ return out[0..n];
+}
+
+/// Register `key`'s value as a paste of the pane with the keyboard reads
+/// its first range's (edit.registerValue): a stored one's first value; `%`
+/// the file's name, `.` the primary selection's text, `#` its number, `_`
+/// nothing. Borrowed from the register or the pane, for the frame.
+pub fn registerValue(p: *const Pardes, key: u8) []const u8 {
+ const pane = p.panes[p.view().active] orelse return "";
+ switch (key) {
+ '_' => return "",
+ '#' => return "1",
+ '%' => return if (pane.file) |*f| f.path else "",
+ '.' => {
+ const f = if (pane.file) |*f| f else return "";
+ const t = &pane.body;
+ const b = edit.cellBounds(.{ .row = t.cur_row, .col = t.cur_col, .arow = if (t.vsel.active) t.vsel.row else t.cur_row, .acol = if (t.vsel.active) t.vsel.col else t.cur_col });
+ const first = File.sourceLine(pane, b.lo_row);
+ const last = File.sourceLine(pane, b.hi_row);
+ if (f.content.len == 0) return "";
+ const lo = @min(f.content.len, first.ptr - f.content.ptr + @as(usize, @intCast(@max(0, b.lo_col))));
+ const hi = @min(f.content.len, last.ptr - f.content.ptr + @as(usize, @intCast(@max(0, b.hi_col))));
+ return f.content[lo..modal.nextGrapheme(f.content, @max(lo, hi))];
+ },
+ else => for (p.registers.list.items) |*reg| {
+ if (reg.name == key) return if (reg.values.len == 0) "" else reg.values[0];
+ } else return "",
+ }
+}
+
/// A key as a cell shows it: `SPC` for the space.
pub fn keyName(key: u8) []const u8 {
return if (key == ' ') "SPC" else @as(*const [1]u8, &printable[key - 0x20]);
@@ -450,3 +552,67 @@ test "Help's rows: every leaf of every root, spelled as its chord, its word and
try std.testing.expectEqual(@as(usize, 4), found);
for (flat) |f| try std.testing.expectEqual(f.row.len, f.lower.len);
}
+
+test "\" shows the registers rolled, each its first line; Down unrolls them beside the cursor's value; a register's key goes down to its verbs, Backspace back up, p pastes it" {
+ const tagline = @import("tagline.zig");
+ const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 160, .rows = 40 });
+ defer p.deinit();
+ const pane = try p.setTestFile("one\ntwo\n");
+ try p.registers.put(p.gpa, 'a', "const best = rank(q, name) orelse continue;\nreturn best;", 0, 1, true);
+ try p.registers.put(p.gpa, '"', "self.dirty = true;", 0, 1, true);
+ var frame = std.heap.ArenaAllocator.init(std.testing.allocator);
+ defer frame.deinit();
+ const a = frame.allocator();
+ p.clock.now_ns = 5 * std.time.ns_per_s;
+ p.clock.stepped_ns = p.clock.now_ns;
+ p.sync();
+ // Its key cell at once, the level 300 ms on.
+ p.update(.{ .key = .{ .cp = '"' } });
+ try std.testing.expect(std.mem.endsWith(u8, try tagline.tagText(p, a, pane), " \" …"));
+ p.advance(p.clock.now_ns);
+ try std.testing.expectEqual(p.clock.now_ns + 300 * std.time.ns_per_ms, p.view().tag_state.due_ns);
+ p.clock.now_ns = p.view().tag_state.due_ns;
+ const rolled = try tagline.tagText(p, a, pane);
+ try std.testing.expect(std.mem.indexOf(u8, rolled, " \" ▸ \" self.dirty = true; a const best = rank(q, nam… / —") != null);
+ try std.testing.expect(std.mem.indexOf(u8, rolled, "% /test.txt . o # 1 _ —") != null);
+ // Down unrolls: a row each, the cursor on the default, its value
+ // beside them.
+ p.update(.{ .key = .{ .cp = Key.down } });
+ try std.testing.expect(p.view().tag_state.unrolled);
+ try std.testing.expect(pane.band_rows >= 4);
+ _ = try p.render(a);
+ const layer = &p.surface.tag_layers[pardes.BAND_LAYER];
+ var band: std.ArrayList(u8) = .empty;
+ for (0..layer.rows) |row| for (layer.cells[row * layer.cols ..][0..layer.cols]) |cell| try band.appendSlice(a, cell.grapheme());
+ try std.testing.expect(std.mem.indexOf(u8, band.items, "▶ \" yank self.dirty = true;") != null);
+ try std.testing.expect(std.mem.indexOf(u8, band.items, "\"\" · yank") != null);
+ // The next row's value in full, every line of it.
+ p.update(.{ .key = .{ .cp = Key.down } });
+ _ = frame.reset(.retain_capacity);
+ _ = try p.render(a);
+ band = .empty;
+ for (0..layer.rows) |row| for (layer.cells[row * layer.cols ..][0..layer.cols]) |cell| try band.appendSlice(a, cell.grapheme());
+ try std.testing.expect(std.mem.indexOf(u8, band.items, "const best = rank(q, name) orelse continue;") != null);
+ try std.testing.expect(std.mem.indexOf(u8, band.items, "return best;") != null);
+ // Enter chooses it: its verbs, rolled.
+ p.update(.{ .key = .{ .cp = Key.enter } });
+ try std.testing.expect(std.mem.indexOf(u8, try tagline.tagText(p, a, pane), " \" a ▸ p after P before R replace y into") != null);
+ try std.testing.expect(!p.view().tag_state.unrolled);
+ // Backspace: the registers again; a register's own key goes down too.
+ p.update(.{ .key = .{ .cp = Key.backspace } });
+ try std.testing.expect(std.mem.indexOf(u8, try tagline.tagText(p, a, pane), " \" ▸ \" self.dirty") != null);
+ p.update(.{ .key = .{ .cp = 'a' } });
+ try std.testing.expect(std.mem.indexOf(u8, try tagline.tagText(p, a, pane), " \" a ▸ p after") != null);
+ // p pastes it after the selection, and the tag is at rest.
+ p.update(.{ .key = .{ .cp = 'p' } });
+ try std.testing.expect(std.mem.indexOf(u8, pane.file.?.content, "const best = rank(q, name) orelse continue;") != null);
+ try std.testing.expect(p.view().tag_state.root == null);
+ try std.testing.expect(@import("TagState.zig").hostOf(p) == null);
+ // Esc from the registers: rest, the keyboard where it was.
+ const id = p.view().active;
+ p.update(.{ .key = .{ .cp = '"' } });
+ p.update(.{ .key = .{ .cp = Key.escape } });
+ try std.testing.expect(p.view().tag_state.root == null);
+ try std.testing.expectEqual(id, p.view().active);
+ try std.testing.expectEqual(@as(u21, 0), pane.body.normal.register);
+}
diff --git a/core/body_layer.zig b/core/body_layer.zig
index eded5439..a182f218 100644
--- a/core/body_layer.zig
+++ b/core/body_layer.zig
@@ -25,6 +25,9 @@ const tagline = @import("tagline.zig");
const Text = panes.Text;
const Layer = @import("Layer.zig");
+const TagState = @import("TagState.zig");
+const bindings = @import("bindings.zig");
+const File = panes.File;
// ---- drawing a pane body into the surface ----
@@ -472,6 +475,15 @@ pub fn renderBody(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane
}
}
+ // What the body would do, drawn and never written (ruling R3): a motion
+ // root's targets in the gutter first, so the ghost rows below push them
+ // with their lines; then a message's words and detail (Messages), a
+ // hover's lines (SPEC §3.5), a rename's preview.
+ if (pane.file != null) paintTargets(p, s, arena, pane, r, tx, tw, body_y, body_h);
+ if (pane.file != null and p.messages.live_len > 0) messageGhosts(p, s, pane, tx, tw, body_y, body_h);
+ if (p.lsp_ask.hover != null) hoverGhosts(p, s, pane, tx, tw, body_y, body_h);
+ if (p.view().tag_state.kind == .rename) renameGhosts(p, s, pane, tx, tw, body_y, body_h);
+
// `gw`'s labels, two letters over the start of each word
if (pane.jump.items.len > 0) labels: {
const flat = edit.flatSurface(p.editor(), &pane.body) catch break :labels;
@@ -555,6 +567,378 @@ pub fn renderBody(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane
};
}
+/// A message at the lines it names, drawn and never written (SPEC §10.2,
+/// ruling R3): after the end of each such line shown, the message's glyph
+/// and its words there; under the caret's line, when the keyboard is in
+/// this body, the lines that explain it where the step put them
+/// (Pane.ghost_at, ghost_rows: Messages.detailUnder), pushing the rows
+/// below down (the rows past the body's foot are not shown meanwhile).
+/// Bounded by the rows shown and the live messages' places
+/// (Messages.max_live, Said.max_places).
+fn messageGhosts(p: *Pardes, s: *Surface, pane: *Pane, tx: u16, tw: u16, body_y: u16, body_h: u16) void {
+ const Messages = pardes.Messages;
+ const f = pane.file.?;
+ const chrome = p.chromeTheme();
+ const th = p.theme();
+ const pane_bg: Color = if (th.bg) |c| .{ .rgb = c } else .default;
+ const Hit = struct { line: usize, said: *const Messages.Said, place: *const Messages.Place };
+ var hits: [Messages.max_live * Messages.Said.max_places]Hit = undefined;
+ var n: usize = 0;
+ for (p.messages.live[0..p.messages.live_len]) |*said| for (said.places[0..said.places_len]) |*place| {
+ if (place.line == 0 or !std.mem.eql(u8, place.path.slice(), f.path)) continue;
+ hits[n] = .{ .line = place.line - 1, .said = said, .place = place };
+ n += 1;
+ };
+ if (n == 0) return;
+ var detail: ?*const Messages.Said = null;
+ var row: u16 = 0;
+ while (row < body_h) : (row += 1) {
+ const w = pane.wrapAt(p.settings.tab, row);
+ if (w.line < 0) continue;
+ const line: usize = @intCast(w.line);
+ // A line's words go after its last row.
+ if (row + 1 < body_h and pane.wrapAt(p.settings.tab, row + 1).line == w.line) continue;
+ const hit = for (hits[0..n]) |h| {
+ if (h.line == line) break h;
+ } else continue;
+ const cells = s.cells[@as(usize, body_y + row) * s.cols + tx ..][0..tw];
+ var end: usize = tw;
+ while (end > 0 and std.mem.eql(u8, cells[end - 1].grapheme(), " ")) end -= 1;
+ const at = end + 2;
+ if (at < tw) {
+ var buf: [160]u8 = undefined;
+ const words = std.fmt.bufPrint(&buf, "{s} {s}", .{ hit.said.kind.glyph(), hit.place.text.slice() }) catch &buf;
+ _ = s.print(tx + @as(u16, @intCast(at)), body_y + row, @intCast(tw - at), words, .{ .fg = .{ .rgb = Messages.ink(chrome, hit.said.kind) }, .bg = pane_bg });
+ }
+ if (pane.ghost_rows > 0 and row == pane.ghost_at) detail = hit.said;
+ }
+ const said = detail orelse return;
+ const under_row = pane.ghost_at;
+ // The rows below the caret's line move down by the detail's rows.
+ const k: u16 = @min(pane.ghost_rows, body_h -| (under_row + 1));
+ if (k == 0) return;
+ var dst: u16 = body_h - 1;
+ while (dst >= under_row + 1 + k) : (dst -= 1) {
+ const to = @as(usize, body_y + dst) * s.cols + tx;
+ const from = @as(usize, body_y + dst - k) * s.cols + tx;
+ @memcpy(s.cells[to..][0..tw], s.cells[from..][0..tw]);
+ }
+ const gutter: u16 = panes.File.gutterWidth(pane);
+ for (said.detail[0..k], 0..) |*text, i| {
+ const y = body_y + under_row + 1 + @as(u16, @intCast(i));
+ s.fill(tx, y, tw, 1, .{ .bg = pane_bg });
+ if (gutter + 2 < tw) _ = s.print(tx + gutter + 2, y, tw - gutter - 2, text.slice(), .{ .fg = .{ .rgb = Messages.ink(chrome, said.kind) }, .bg = pane_bg });
+ }
+}
+
+/// The word drawn at body row `row`, text column `col` of pane `id` in the
+/// frame drawn last (its body layer when it has one, else the grid): a
+/// message's detail is text no buffer holds, read as it is shown.
+pub fn wordAt(p: *Pardes, arena: std.mem.Allocator, id: usize, row: usize, col: usize) !?[]const u8 {
+ const layer = &p.surface.body_layers[id];
+ const body = (p.surface.region(.body, id) orelse return null).rect;
+ var text: std.ArrayList(u8) = .empty;
+ if (layer.rows > 0) {
+ if (row >= layer.rows) return null;
+ for (layer.cells[row * layer.cols ..][0..layer.cols]) |cell| try text.appendSlice(arena, cell.grapheme());
+ } else {
+ if (row >= body.h) return null;
+ for (0..body.w) |x| try text.appendSlice(arena, p.surface.at(body.x + @as(u16, @intCast(x)), body.y + @as(u16, @intCast(row))).grapheme());
+ }
+ const b = pardes.tagline.wordBoundsAtCol(text.items, panes.File.rawAtDisplay(p.settings.tab, text.items, col)) orelse return null;
+ if (b.lo == b.hi) return null;
+ return text.items[b.lo..b.hi];
+}
+
+/// Painted targets (SPEC §4.4), while a motion root's level shows in this
+/// body's tag: each of its keys at the line it would go to, in the gutter
+/// (`g e t b .` for `g`; for `]` the next and for `[` the previous
+/// function, paragraph, test, comment, change and diagnostic: `f p T c g
+/// d`, the spec's, each tree object a query of the rows shown); browsing `m a` or `m i` unrolled, the brackets'
+/// region around the caret tinted. Only the rows shown are looked at: a
+/// target off them is not painted (the tag's arrows, SPEC §15, are not
+/// built). At rest it costs one test of the view's tag state.
+fn paintTargets(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r: Rect, tx: u16, tw: u16, body_y: u16, body_h: u16) void {
+ const host = TagState.hostOf(p) orelse return;
+ if (p.panes[host] != pane) return;
+ const v = p.view();
+ const cur = TagState.current(p, v) orelse return;
+ if (!TagState.shown(p, v)) return;
+ const f = &pane.file.?;
+ if (f.line_starts.len == 0) return;
+ const tab = p.settings.tab;
+ const held = pane.context_rows;
+ if (body_h <= held) return;
+ // The lines the rows show, past the context rows held at the top.
+ const lo: usize = @intCast(@max(0, pane.wrapAt(tab, held).line));
+ var hi = lo;
+ for (held..body_h) |row| {
+ const line = pane.wrapAt(tab, @intCast(row)).line;
+ if (line >= 0 and line < f.line_starts.len) hi = @max(hi, @as(usize, @intCast(line)));
+ }
+ var children: [bindings.max_children]bindings.Child = undefined;
+ const level = bindings.level(p, cur.root, cur.path, &children);
+ if (cur.root == .match) {
+ const st = &v.tag_state;
+ if (!st.unrolled) return;
+ const on = for (level) |c| {
+ if (c.key == st.hi) break c;
+ } else return;
+ const leaf = (on.node orelse return).leaf orelse return;
+ if (leaf != .role or (leaf.role != .match_inside and leaf.role != .match_around)) return;
+ const role = leaf.role;
+ const caret = lineStart(f, @intCast(@max(0, pane.body.cur_row))) + @as(usize, @intCast(@max(0, pane.body.cur_col)));
+ const span = enclosing(f.content, @min(caret, f.content.len), lineStart(f, lo), lineStart(f, hi + 1)) orelse return;
+ const from = if (role == .match_inside) span[0] + 1 else span[0];
+ const to = if (role == .match_inside) span[1] else span[1] + 1;
+ const first = lineOf(f, from);
+ const last = lineOf(f, to -| 1);
+ const rows = arena.alloc(Pane.PointerRow, last - first + 1) catch return;
+ for (rows, first..) |*row, line| row.* = .{
+ .row = @intCast(line),
+ .lo = if (line == first) from - lineStart(f, line) else 0,
+ .hi = if (line == last) to - lineStart(f, line) else File.sourceLine(pane, @intCast(line)).len,
+ .to_edge = line != last,
+ };
+ const th = p.theme();
+ const page = th.bg orelse th.tag_bg;
+ paintSourceSelection(p, s, pane, r, rows, colors.mix(page, colors.mix(page, th.sel_bg)), null);
+ return;
+ }
+ if (cur.root != .goto and cur.root != .next and cur.root != .prev) return;
+ const th = p.theme();
+ const style: CellStyle = .{ .fg = .{ .rgb = p.chromeTheme().box }, .bg = if (th.bg) |c| .{ .rgb = c } else .default, .bold = true };
+ // The rows painted so far: a second key on a row goes after the first.
+ var painted: [bindings.max_children]u16 = undefined;
+ var n: usize = 0;
+ for (level) |c| {
+ const leaf = (c.node orelse continue).leaf orelse continue;
+ if (leaf != .role) continue;
+ const line = targetLine(p, pane, f, leaf.role, cur.root != .prev, lo, hi) orelse continue;
+ if (line < lo or line > hi) continue;
+ var row: u16 = held;
+ while (row < body_h) : (row += 1) {
+ const w = pane.wrapAt(tab, row);
+ if (w.line == line and w.at == 0) break;
+ } else continue;
+ const x: u16 = @intCast(std.mem.count(u16, painted[0..n], &.{row}));
+ if (x >= tw) continue;
+ s.set(tx + x, body_y + row, bindings.keyName(c.key), style);
+ painted[n] = row;
+ n += 1;
+ }
+}
+
+/// A hover's answer as ghost lines under the line it was asked at (SPEC
+/// §3.5, R3): the rows below move down by its lines (those past the body's
+/// foot not shown meanwhile), the buffer untouched. Bounded by the rows
+/// shown and the hover's `Ask.hover_max` bytes.
+fn hoverGhosts(p: *Pardes, s: *Surface, pane: *Pane, tx: u16, tw: u16, body_y: u16, body_h: u16) void {
+ const h = &p.lsp_ask.hover.?;
+ if (h.serial != pane.serial) return;
+ const f = if (pane.file) |*file| file else return;
+ if (f.revision != h.revision) return;
+ const tab = p.settings.tab;
+ // The last row the line is shown on.
+ var under: ?u16 = null;
+ var row: u16 = pane.context_rows;
+ while (row < body_h) : (row += 1) {
+ if (pane.wrapAt(tab, row).line == h.row) under = row else if (under != null) break;
+ }
+ const at = under orelse return;
+ const text = std.mem.trimEnd(u8, h.text.slice(), "\n");
+ const k: u16 = @intCast(@min(std.mem.count(u8, text, "\n") + 1, body_h - at - 1));
+ if (k == 0) return;
+ var dst: u16 = body_h - 1;
+ while (dst >= at + 1 + k) : (dst -= 1) {
+ const to = @as(usize, body_y + dst) * s.cols + tx;
+ const from = @as(usize, body_y + dst - k) * s.cols + tx;
+ @memcpy(s.cells[to..][0..tw], s.cells[from..][0..tw]);
+ }
+ const th = p.theme();
+ const style: CellStyle = .{ .fg = .{ .rgb = th.tag_fg }, .bg = .{ .rgb = th.tag_bg } };
+ const gutter: u16 = File.gutterWidth(pane);
+ var lines = std.mem.splitScalar(u8, text, '\n');
+ for (0..k) |i| {
+ const y = body_y + at + 1 + @as(u16, @intCast(i));
+ s.fill(tx, y, tw, 1, .{ .bg = .{ .rgb = th.tag_bg } });
+ if (gutter + 2 < tw) _ = s.print(tx + gutter + 2, y, tw - gutter - 2, lines.next() orelse "", style);
+ }
+}
+
+/// A Rename typed in this body's tag, shown in its rows (SPEC §3.5, R3):
+/// each whole-word place of the name under the caret in the rows shown
+/// struck, the name typed after it, the rest of its row pushed right.
+/// Never written; bounded by the rows shown.
+fn renameGhosts(p: *Pardes, s: *Surface, pane: *Pane, tx: u16, tw: u16, body_y: u16, body_h: u16) void {
+ const host = TagState.hostOf(p) orelse return;
+ if (p.panes[host] != pane or pane.file == null) return;
+ const old = @import("lsp/Ask.zig").renamedWord(pane) orelse return;
+ const new = p.view().tag_state.field.text();
+ const tab = p.settings.tab;
+ const chrome = p.chromeTheme();
+ const th = p.theme();
+ const added: CellStyle = .{ .fg = .{ .rgb = chrome.diagnostic_hint }, .bg = if (th.bg) |c| .{ .rgb = c } else .default, .bold = true };
+ const wide: u16 = @intCast(@min(File.displayWidth(tab, new), tw));
+ const gutter: i32 = File.gutterWidth(pane);
+ var row: u16 = pane.context_rows;
+ while (row < body_h) : (row += 1) {
+ const w = pane.wrapAt(tab, row);
+ if (w.line < 0) continue;
+ const line = File.sourceLine(pane, w.line);
+ const from: usize = @min(line.len, @as(usize, @intCast(@max(0, w.at))));
+ const next = pane.wrapAt(tab, row + 1);
+ const to: usize = if (next.line == w.line) @min(line.len, @as(usize, @intCast(@max(0, next.at)))) else line.len;
+ // Right to left, so a push leaves the places before it where they are.
+ var end = to;
+ while (std.mem.lastIndexOf(u8, line[from..end], old)) |k| {
+ const at = from + k;
+ end = at;
+ const before = at > 0 and (std.ascii.isAlphanumeric(line[at - 1]) or line[at - 1] == '_');
+ const after = at + old.len < line.len and (std.ascii.isAlphanumeric(line[at + old.len]) or line[at + old.len] == '_');
+ if (before or after) continue;
+ const c0 = gutter + w.pad + File.displayOffset(tab, pane, w.line, w.at, @intCast(at));
+ const c1 = gutter + w.pad + File.displayOffset(tab, pane, w.line, w.at, @intCast(at + old.len));
+ if (c0 < gutter or c1 > tw) continue;
+ const y = body_y + row;
+ var c: u16 = @intCast(c0);
+ while (c < c1) : (c += 1) {
+ const cell = s.at(tx + c, y);
+ cell.style.strikethrough = true;
+ cell.style.fg = .{ .rgb = chrome.diagnostic_error };
+ }
+ const x: u16 = @intCast(c1);
+ if (x + wide < tw) {
+ const cells = s.cells[@as(usize, y) * s.cols + tx ..][0..tw];
+ std.mem.copyBackwards(Cell, cells[x + wide ..], cells[x .. tw - wide]);
+ }
+ _ = s.print(tx + x, y, tw - x, new, added);
+ }
+ }
+}
+
+/// The line a motion role would go to from the caret of `pane`, looked for
+/// in lines `lo` to `hi` (the rows shown) alone; null for none there, or a
+/// role that is no line's.
+fn targetLine(p: *Pardes, pane: *Pane, f: *panes.File.State, role: modal.Normal.Role, forward: bool, lo: usize, hi: usize) ?usize {
+ const tab = p.settings.tab;
+ const caret: usize = @intCast(@max(0, pane.body.cur_row));
+ const nlines = f.line_starts.len;
+ switch (role) {
+ .goto_file_start => return 0,
+ .goto_last_line => return if (nlines > 1 and f.line_starts[nlines - 1] == f.content.len) nlines - 2 else nlines - 1,
+ .goto_last_modification => return if (pane.body.last_edit) |at| @intCast(@max(0, at.row)) else null,
+ // helix's goto_window, as normal.gotoWindow counts its rows.
+ .goto_view_top, .goto_view_bottom => {
+ const shown: i32 = File.shownRows(tab, pane);
+ const held: i32 = pane.context_rows;
+ var last: i32 = shown - 1;
+ while (last > 0 and pane.wrapAt(tab, held + last).line >= @as(i32, @intCast(nlines))) last -= 1;
+ const margin: i32 = @min(config.scroll_off, @divTrunc(shown - 1, 2));
+ const vr = std.math.clamp(@min(@max(if (role == .goto_view_top) margin else last - margin, margin), last - margin), 0, last);
+ const line = pane.wrapAt(tab, held + vr).line;
+ return if (line < 0) null else @intCast(line);
+ },
+ // helix's paragraph: past the lines with text, then past the blank
+ // ones (modal.moveParagraph).
+ .goto_paragraph => {
+ var l = caret;
+ if (forward) {
+ while (l <= hi and !blank(pane, l)) l += 1;
+ while (l <= hi and blank(pane, l)) l += 1;
+ return if (l <= hi and l != caret) l else null;
+ }
+ while (l > lo and blank(pane, l - 1)) l -= 1;
+ while (l > lo and !blank(pane, l - 1)) l -= 1;
+ return if (l == caret or (l == lo and lo > 0)) null else l;
+ },
+ .goto_change => return @import("jj.zig").nextChange(p, pane, caret, forward, hi - lo + 1),
+ // Once a Diagnostics list fed them, the pane's places (normal.zig's
+ // `]d`): the first after the caret's line, or the last before it.
+ .goto_diagnostic => {
+ const set = &pane.places;
+ const fed = set.started and set.provenance == .list and if (p.paneBySerial(set.from)) |qid|
+ (if (p.panes[qid].?.query) |q| q.source == .diagnostics else false)
+ else
+ false;
+ if (!fed) return null;
+ const hits = set.hits.items;
+ const edge = if (forward) lineStart(f, caret + 1) else lineStart(f, caret);
+ var a: usize = 0;
+ var b: usize = hits.len;
+ while (a < b) {
+ const m = (a + b) / 2;
+ if (hits[m].start < edge) a = m + 1 else b = m;
+ }
+ if (forward) return if (a < hits.len) lineOf(f, hits[a].start) else null;
+ return if (a > 0) lineOf(f, hits[a - 1].start) else null;
+ },
+ inline .goto_function, .goto_comment, .goto_test => |r| {
+ // The tree as the motion reads it, made once a revision; with
+ // the Changes layer's lines in the buffer its offsets are not the
+ // buffer's: not painted then.
+ if (f.layer.lines.len > 0) return null;
+ const tree = normal.fileTree(p, f) orelse return null;
+ const object = @field(modal.Normal.Object, @tagName(r)["goto_".len..]);
+ const at = lineStart(f, caret) + @as(usize, @intCast(@max(0, pane.body.cur_col)));
+ const span = @import("syntax.zig").objectNext(f.path, tree, f.content, object, forward, @min(at, f.content.len), .{ lineStart(f, lo), lineStart(f, hi + 1) }) orelse return null;
+ return lineOf(f, span.from);
+ },
+ else => return null,
+ }
+}
+
+fn blank(pane: *const Pane, line: usize) bool {
+ return std.mem.trim(u8, File.sourceLine(pane, @intCast(line)), " \t\r").len == 0;
+}
+
+/// Where line `line` starts in a file's buffer; past its last, its end.
+fn lineStart(f: *const panes.File.State, line: usize) usize {
+ return if (line < f.line_starts.len) f.line_starts[line] else f.content.len;
+}
+
+/// The line holding byte `off` of a file's buffer.
+fn lineOf(f: *const panes.File.State, off: usize) usize {
+ var a: usize = 0;
+ var b = f.line_starts.len;
+ while (a + 1 < b) {
+ const m = (a + b) / 2;
+ if (f.line_starts[m] <= off) a = m else b = m;
+ }
+ return a;
+}
+
+/// The innermost bracket pair around byte `at` of `text`, both in bytes
+/// `lo` to `hi` (the rows shown): its opening and its closing byte.
+fn enclosing(text: []const u8, at: usize, lo: usize, hi: usize) ?[2]usize {
+ var depth: usize = 0;
+ var i = at;
+ const open = while (i > lo) {
+ i -= 1;
+ switch (text[i]) {
+ ')', ']', '}' => depth += 1,
+ '(', '[', '{' => if (depth == 0) break i else {
+ depth -= 1;
+ },
+ else => {},
+ }
+ } else return null;
+ const close: u8 = switch (text[open]) {
+ '(' => ')',
+ '[' => ']',
+ else => '}',
+ };
+ depth = 0;
+ i = at;
+ while (i < @min(hi, text.len)) : (i += 1) {
+ if (text[i] == text[open]) depth += 1 else if (text[i] == close) {
+ if (depth == 0) return .{ open, i };
+ depth -= 1;
+ }
+ }
+ return null;
+}
+
pub fn bodyText(tab: u16, arena: std.mem.Allocator, pane: *Pane) ![]const u8 {
if (pane.addon != null) {
const buf = try arena.alloc(u8, pane.rows -| 1);
@@ -663,3 +1047,167 @@ fn fillBody(dst: ?[]u8, pane: *Pane, viewport: []const []const u8) usize {
}
return written;
}
+
+/// Grid row `y` of `s` from column `x`, as text.
+fn rowText(s: *const Surface, x: u16, y: u16, buf: []u8) []const u8 {
+ var n: usize = 0;
+ for (x..s.cols) |col| {
+ const g = s.cells[@as(usize, y) * s.cols + col].grapheme();
+ if (n + g.len > buf.len) break;
+ @memcpy(buf[n..][0..g.len], g);
+ n += g.len;
+ }
+ return buf[0..n];
+}
+
+test "a build error is said where its cause is: the mark on its file's tag, its words after its line, its detail under the caret's line pushing the rows below down, the walk on the notice row" {
+ const p = try Pardes.init(std.testing.allocator, .{ .cols = 80, .rows = 20 });
+ defer p.deinit();
+ const pane = try p.setTestFile("one\ntwo\nthree\nfour\nfive\nsix\n");
+ const id = p.view().active;
+ const err = pardes.Messages.keep(p, .@"error", 0, "@p9 zig build", "exit 1");
+ err.places[0] = .{ .line = 3, .col = 1 };
+ err.places[0].path.set("/test.txt");
+ err.places[0].text.set("expected 2 argument(s), found 3");
+ err.places_len = 1;
+ err.detail[0] = .{};
+ err.detail[0].set("const x = f(1, 2, 3);");
+ err.detail[1] = .{};
+ err.detail[1].set(" ^");
+ err.detail_len = 2;
+ var frame = std.heap.ArenaAllocator.init(std.testing.allocator);
+ defer frame.deinit();
+ pane.focus = .body;
+ pane.body.cur_row = 0;
+ p.sync();
+ var s = try p.render(frame.allocator());
+ const body = s.region(.body, id).?.rect;
+ // The mark, in the box's second cell; the tag's text as it was.
+ const r = p.view().rects[id];
+ try std.testing.expectEqualStrings("\u{2717}", s.at(r.x + config.GUTTER - 1, p.tagTop(pane, r)).grapheme());
+ try std.testing.expect(std.mem.startsWith(u8, try tagline.tagPrefix(p, pane), "/test.txt"));
+ var buf: [512]u8 = undefined;
+ // Its words after line 3's end; nothing inserted while the caret is
+ // elsewhere.
+ try std.testing.expect(std.mem.indexOf(u8, rowText(s, body.x, body.y + 2, &buf), "three \u{2717} expected 2 argument(s), found 3") != null);
+ try std.testing.expect(std.mem.indexOf(u8, rowText(s, body.x, body.y + 3, &buf), "four") != null);
+ // The caret on line 3: its detail under it, the rows below two rows down.
+ pane.body.cur_row = 2;
+ _ = frame.reset(.retain_capacity);
+ s = try p.render(frame.allocator());
+ try std.testing.expect(std.mem.indexOf(u8, rowText(s, body.x, body.y + 3, &buf), "const x = f(1, 2, 3);") != null);
+ try std.testing.expect(std.mem.indexOf(u8, rowText(s, body.x, body.y + 5, &buf), "four") != null);
+ // ...never written: the file is as it was.
+ try std.testing.expectEqualStrings("one\ntwo\nthree\nfour\nfive\nsix\n", pane.file.?.content);
+ // The notice row offers the walk.
+ const foot = s.region(.notice_row, pardes.Region.none).?;
+ try std.testing.expect(std.mem.endsWith(u8, std.mem.trimEnd(u8, rowText(s, 0, foot.rect.y, &buf), " "), "SPC e walk"));
+}
+
+test "a click under a message's detail lands on the row drawn there, a click on the detail on the line it explains, and B2 on a word of the detail runs it" {
+ const p = try Pardes.init(std.testing.allocator, .{ .cols = 80, .rows = 20 });
+ defer p.deinit();
+ const pane = try p.setTestFile("one\ntwo\nthree\nfour\nfive\nsix\n");
+ const id = p.view().active;
+ const err = pardes.Messages.keep(p, .@"error", 0, "@p9 zig build", "exit 1");
+ err.places[0] = .{ .line = 3, .col = 1 };
+ err.places[0].path.set("/test.txt");
+ err.places[0].text.set("bad");
+ err.places_len = 1;
+ err.detail[0] = .{};
+ err.detail[0].set("try Wrap here");
+ err.detail[1] = .{};
+ err.detail[1].set(" ^");
+ err.detail_len = 2;
+ pane.focus = .body;
+ pane.body.cur_row = 2;
+ p.sync();
+ var frame = std.heap.ArenaAllocator.init(std.testing.allocator);
+ defer frame.deinit();
+ var s = try p.render(frame.allocator());
+ const body = s.region(.body, id).?.rect;
+ var buf: [512]u8 = undefined;
+ // Line 5 drawn two rows lower than its place in the row map, under the
+ // detail: a click on it lands on it.
+ const five = std.mem.indexOf(u8, rowText(s, body.x, body.y + 6, &buf), "five").?;
+ const x = body.x + @as(u16, @intCast(five)) + 1;
+ p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = x, .row = body.y + 6 } });
+ p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = x, .row = body.y + 6 } });
+ try std.testing.expectEqual(@as(i32, 4), pane.body.cur_row);
+ // On line 3 again, its detail drawn: a click on the detail is on the
+ // line it explains, and the detail stays.
+ pane.body.cur_row = 2;
+ _ = frame.reset(.retain_capacity);
+ s = try p.render(frame.allocator());
+ const wrap_at = std.mem.indexOf(u8, rowText(s, body.x, body.y + 3, &buf), "Wrap").?;
+ const wx = body.x + @as(u16, @intCast(wrap_at)) + 1;
+ p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = wx, .row = body.y + 4 } });
+ p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = wx, .row = body.y + 4 } });
+ try std.testing.expectEqual(@as(i32, 2), pane.body.cur_row);
+ // B2 on a word of it: the word runs, as a typed one would.
+ _ = frame.reset(.retain_capacity);
+ s = try p.render(frame.allocator());
+ const wrapped = p.settings.wrap;
+ p.update(.{ .mouse = .{ .button = .middle, .kind = .press, .col = wx, .row = body.y + 3 } });
+ p.update(.{ .mouse = .{ .button = .middle, .kind = .release, .col = wx, .row = body.y + 3 } });
+ while (p.nextEffect()) |_| {}
+ try std.testing.expect(p.settings.wrap != wrapped);
+ try std.testing.expectEqualStrings("one\ntwo\nthree\nfour\nfive\nsix\n", pane.file.?.content);
+}
+
+test "a motion root's level paints its targets in the gutter: `]` the next paragraph's p, `g` g and e; `m` browsed on `i` tints the braces' inside; nothing at rest" {
+ const Key = pardes.Key;
+ const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 80, .rows = 20 });
+ defer p.deinit();
+ const pane = try p.setTestFile("fn a() {\n one;\n}\n\nfn b() {\n two;\n}\n");
+ const id = p.view().active;
+ var frame = std.heap.ArenaAllocator.init(std.testing.allocator);
+ defer frame.deinit();
+ const a = frame.allocator();
+ p.clock.now_ns = 5 * std.time.ns_per_s;
+ p.clock.stepped_ns = p.clock.now_ns;
+ pane.focus = .body;
+ pane.body.cur_row = 1;
+ pane.body.cur_col = 4;
+ p.sync();
+ var s = try p.render(a);
+ const body = s.region(.body, id).?.rect;
+ const gutter = body.x;
+ const at_rest = [_][]const u8{ s.at(gutter, body.y).grapheme(), s.at(gutter, body.y + 4).grapheme(), s.at(gutter, body.y + 6).grapheme() };
+ for (at_rest) |g| try std.testing.expect(!std.mem.eql(u8, g, "p") and !std.mem.eql(u8, g, "g") and !std.mem.eql(u8, g, "e"));
+ const plain_bg = s.at(gutter + panes.File.gutterWidth(pane) + 4, body.y + 1).style.bg;
+ // `]`: nothing until its level shows; then `p` on the next paragraph.
+ p.update(.{ .key = .{ .cp = ']' } });
+ p.advance(p.clock.now_ns);
+ _ = frame.reset(.retain_capacity);
+ s = try p.render(a);
+ try std.testing.expect(!std.mem.eql(u8, s.at(gutter, body.y + 4).grapheme(), "p"));
+ p.clock.now_ns = p.view().tag_state.due_ns;
+ _ = frame.reset(.retain_capacity);
+ s = try p.render(a);
+ try std.testing.expectEqualStrings("p", s.at(gutter, body.y + 4).grapheme());
+ p.update(.{ .key = .{ .cp = Key.escape } });
+ // `g`: its first and last lines.
+ p.update(.{ .key = .{ .cp = 'g' } });
+ p.advance(p.clock.now_ns);
+ p.clock.now_ns = p.view().tag_state.due_ns;
+ _ = frame.reset(.retain_capacity);
+ s = try p.render(a);
+ try std.testing.expectEqualStrings("g", s.at(gutter, body.y).grapheme());
+ try std.testing.expectEqualStrings("e", s.at(gutter, body.y + 6).grapheme());
+ p.update(.{ .key = .{ .cp = Key.escape } });
+ // `m` unrolled, its cursor on `i`: the inside of the braces around the
+ // caret tinted.
+ p.update(.{ .key = .{ .cp = 'm' } });
+ p.update(.{ .key = .{ .cp = Key.down } });
+ p.view().tag_state.hi = bindings.nodeAt(.match, "i").?.key;
+ _ = frame.reset(.retain_capacity);
+ s = try p.render(a);
+ const lit = s.at(gutter + panes.File.gutterWidth(pane) + 4, body.y + 1).style.bg;
+ try std.testing.expect(!std.meta.eql(plain_bg, lit));
+ // At rest again: the gutter as it was.
+ p.update(.{ .key = .{ .cp = Key.escape } });
+ _ = frame.reset(.retain_capacity);
+ s = try p.render(a);
+ try std.testing.expectEqualStrings(at_rest[1], s.at(gutter, body.y + 4).grapheme());
+}
diff --git a/core/builtins.zig b/core/builtins.zig
index 12ab9da5..32af63f7 100644
--- a/core/builtins.zig
+++ b/core/builtins.zig
@@ -797,6 +797,9 @@ pub const Themes = struct {
pub const scope: Scope = .session;
pub const output: OutputTraits = .{ .name = config.themes_buffer, .steps = true, .commands = true };
pub fn run(c: Ctx) void {
+ // From the keyboard, where the walk is on: a picker in the tag, the
+ // window wearing its row (Pick.zig, SPEC §5.1).
+ if (pardes.Pick.asked(c.p)) return pardes.Pick.open(c.p, c.id, .themes, "", "", "");
panes.Output.openThemes(c.p, c.id) catch |err| c.p.reportError(.at(c.id), "themes", err);
}
};
@@ -1248,7 +1251,7 @@ pub const Del = struct {
var rec: [32]u8 = undefined;
pardes.ctlfs.events.notePath(c.p, "ask", std.fmt.bufPrint(&rec, "{d} del k j", .{c.pane.serial}) catch unreachable); // a u32 fits 32
// The question says Del already.
- if (c.pane.msg_announcement) c.pane.msg_len = 0;
+ _ = c.p.messages.retire(&.{.echo});
return;
}
c.p.removePane(c.id, to) catch |err| return c.p.reportError(.at(c.id), "close", err);
@@ -1622,6 +1625,19 @@ pub const Help = struct {
}
};
+/// Show what a key sequence runs: the next keys typed are replayed in the tag.
+///
+/// The tag shows `Keys` and the keys as they are typed; a sequence that
+/// reaches a leaf unrolls its level under the tag with the leaf on the
+/// cursor and its documentation beside it, and Enter runs it. Every root
+/// answers: SPC, g, m, z, Z, [, ], window mode's C-w. A sequence nothing
+/// is bound to is shown struck, `runs nothing`. Esc leaves it.
+pub const Keys = struct {
+ pub fn run(c: Ctx) void {
+ pardes.TagState.openDescribe(c.p, c.id);
+ }
+};
+
/// Open the startup file, `init` in the configuration directory, in a pane.
///
/// Its pane when it is open, else the file; not there yet, a pane of that
@@ -1709,12 +1725,32 @@ pub const LocationsConfig = struct {
}
};
-/// Show the messages said so far in a +Messages.
+/// Act on the message the notice row leads with.
+///
+/// An error that names places lands them as a list in the pane's walk, n
+/// and N walking them (where jumps do not walk, a +Search the Look walk
+/// steps through); a question takes the keyboard in its pane's tag (its
+/// answer's key answers it, Esc leaves it waiting); anything else opens the
+/// history.
+pub const Message = struct {
+ pub const quiet = true;
+ pub const scope: Scope = .session;
+ pub fn run(c: Ctx) void {
+ pardes.Messages.act(c.p, c.id);
+ }
+};
+
+/// Show the messages said so far, the newest first, an error's places
+/// under it.
+///
+/// Where jumps walk, a list in the pane's tag: Enter Looks a row (a
+/// message's cause, a place), C-q keeps it as a +Messages; else the
+/// +Messages.
pub const Messages = struct {
pub const scope: Scope = .session;
pub const output: OutputTraits = .{ .name = config.messages_buffer };
pub fn run(c: Ctx) void {
- panes.Output.openMessages(c.p, c.id) catch |err| c.p.reportError(.at(c.id), "messages", err);
+ pardes.Messages.history(c.p, c.id);
}
};
@@ -1801,6 +1837,7 @@ pub const Grep = struct {
/// stays, its count 0; the write hears `not found`.
fn search(c: Ctx, source: panes.Query.Source, miss: []const u8) void {
const pat = std.mem.trim(u8, c.arg orelse "", " \t\r\n");
+ if (pardes.Pick.asked(c.p)) return pardes.Pick.open(c.p, c.id, if (source == .find) .find else .grep, "", pat, "");
const reused = panes.Query.ofOwner(c.p, c.pane.serial) != null;
panes.Query.open(c.p, c.id, source, pat, pat.len == 0);
if (pat.len == 0 or !c.p.fs.serving) return;
@@ -1823,6 +1860,11 @@ pub const Search = struct {
pub fn run(c: Ctx) void {
const line = std.mem.trim(u8, c.arg orelse "", " \t\r\n");
const asked = panes.Query.parse(line) orelse panes.Query.parse(std.mem.concat(c.p.scratch.allocator(), u8, &.{ "/", line }) catch return).?;
+ // `SPC b b`, `SPC s s`, `SPC /` and the like: a picker in the tag.
+ if (pardes.Pick.asked(c.p)) switch (asked.source) {
+ inline .find, .grep, .recent, .panes, .symbols, .all => |s| return pardes.Pick.open(c.p, c.id, @field(pardes.Pick.Source, @tagName(s)), "", asked.pat, ""),
+ else => {},
+ };
panes.Query.open(c.p, c.id, asked.source, asked.pat, true);
}
};
@@ -1844,6 +1886,7 @@ pub const Panes = struct {
pub const takes_arg = true;
pub const quiet = true;
pub fn run(c: Ctx) void {
+ if (pardes.Pick.asked(c.p)) return pardes.Pick.open(c.p, c.id, .panes, "", std.mem.trim(u8, c.arg orelse "", " \t\r\n"), "");
panes.Query.open(c.p, c.id, .panes, std.mem.trim(u8, c.arg orelse "", " \t\r\n"), true);
}
};
@@ -1998,6 +2041,16 @@ pub const Forward = struct {
}
};
+/// Reopen the last picker as it was: its rows, marks, cursor and query.
+///
+/// In the tag of the pane its Enter lands in from this one: this pane if it
+/// reads, else its reader. `SPC '`.
+pub const Resume = struct {
+ pub fn run(c: Ctx) void {
+ pardes.Pick.resumeFrom(c.p, c.id);
+ }
+};
+
/// Keep this pane: a reading pane, which a jump steps, is held from now on.
///
/// Its walk leaves its tag (its places, its owner): the next jump from its
@@ -2062,6 +2115,7 @@ pub const Recent = struct {
// The query pane under the pane the keyboard is in, line 1
// `Recent `, typed into; what follows the word narrows the files.
if (c.p.panes[c.id] == null) return c.p.reportFailure(c.id, "Recent: open a pane to search from");
+ if (pardes.Pick.asked(c.p)) return pardes.Pick.open(c.p, c.id, .recent, "", std.mem.trim(u8, c.arg orelse "", " \t\r\n"), "");
panes.Query.open(c.p, c.id, .recent, std.mem.trim(u8, c.arg orelse "", " \t\r\n"), true);
}
};
@@ -2091,6 +2145,7 @@ pub const Jumplist = struct {
pub const scope: Scope = .session;
pub const output: OutputTraits = .{ .name = config.jumps_buffer, .steps = true, .locations = true };
pub fn run(c: Ctx) void {
+ if (pardes.Pick.asked(c.p)) return pardes.Pick.open(c.p, c.id, .jumplist, "", "", "");
panes.Output.openJumps(c.p, c.id) catch |err| c.p.reportError(.at(c.id), "jumplist", err);
}
};
@@ -2240,6 +2295,9 @@ pub const Rename = struct {
pub fn run(c: Ctx) void {
const a = std.mem.trim(u8, c.arg orelse "", " \t\r\n");
if (a.len > 0) return c.p.lspRequest(c.id, .rename, a);
+ // From the keyboard, where the walk is on: typed in the pane's own
+ // tag, its edits drawn in its body as they are typed (SPEC §3.5).
+ if (pardes.Pick.asked(c.p) and c.pane.file != null) return @import("lsp/Ask.zig").openRename(c.p, c.id);
panes.startPrompt(c.p, c.pane, &c.pane.body, .{ .search = config.rename_marker });
}
};
@@ -2374,7 +2432,7 @@ test "Exit over a ctl write or a click names every pane it asks about, a second
try std.testing.expect(std.mem.endsWith(u8, unsavedList(p), "\nExit again to discard\n"));
var noticed = false;
for (p.panes) |slot| if (slot) |pane| {
- noticed = noticed or std.mem.eql(u8, pane.msg[0..pane.msg_len], "2 unsaved panes \u{2014} Exit again to discard");
+ noticed = noticed or std.mem.eql(u8, p.messages.saidBy(pane), "2 unsaved panes \u{2014} Exit again to discard");
};
try std.testing.expect(noticed);
// Edited since: only that one is named again (acme's rule).
@@ -2474,7 +2532,7 @@ test "Kill stops the commands pardes typed, bare all and by name those that matc
p.host = .{ .vtable = &killed.vtable };
// Nothing running: nothing to stop, and never the shell; said.
try std.testing.expectEqual(@as(usize, 0), killed.count(p, "Kill"));
- try std.testing.expectEqualStrings("Kill: nothing running", p.panes[term].?.msg[0..p.panes[term].?.msg_len]);
+ try std.testing.expectEqualStrings("Kill: nothing running", p.messages.saidBy(p.panes[term].?));
_ = exec.execute(p, term, "make -j8");
while (p.nextEffect()) |_| {}
// Typed but not started yet (no C mark): not running.
diff --git a/core/colors.zig b/core/colors.zig
index 84595a30..2a97ac69 100644
--- a/core/colors.zig
+++ b/core/colors.zig
@@ -832,6 +832,21 @@ pub fn themeIndex(name: []const u8) ?usize {
return null;
}
+/// The window wearing theme `index` (SPEC §5.1, a theme's preview), or
+/// its own again (null): nothing loaded, the session's theme and a theme
+/// file as they were; its chrome worked out once a theme, never a frame.
+/// The themes picker's (Pick.zig), and `:theme `'s argument rows'.
+pub fn previewTheme(p: *Pardes, index: ?usize) void {
+ const i = index orelse {
+ p.theme_preview = null;
+ return;
+ };
+ if (i >= themes.len) return;
+ if (p.theme_preview) |had| if (had == i) return;
+ p.theme_preview = @intCast(i);
+ p.preview_chrome = ChromeTheme.fromTheme(&themes[i]);
+}
+
pub fn setThemeIndex(p: *Pardes, index: usize) void {
if (index >= themes.len or
(p.custom_theme == null and p.theme_file_path.get().len == 0 and
@@ -960,7 +975,7 @@ test "a theme file that cannot be read is named in the failure" {
requestThemeFile(p, 0, "/nowhere/mine.zon");
failThemeFile(p, p.theme_file_generation, error.FileNotFound);
const pane = p.panes[0].?;
- try std.testing.expect(std.mem.indexOf(u8, pane.msg[0..pane.msg_len], "theme file /nowhere/mine.zon: ") != null);
+ try std.testing.expect(std.mem.indexOf(u8, p.messages.saidBy(pane), "theme file /nowhere/mine.zon: ") != null);
}
test "a theme file nested 10, 1 000 and 100 000 deep is refused in words, never a stack overflow" {
@@ -976,11 +991,11 @@ test "a theme file nested 10, 1 000 and 100 000 deep is refused in words, never
try source.appendSlice(gpa, "1");
for (0..depth) |_| try source.append(gpa, '}');
try source.appendSlice(gpa, " }\n");
- p.panes[0].?.msg_len = 0;
+ p.messages.live_len = 0;
// Up to 2026-11-23 std's parser took it: 5 000 deep overflowed the
// stack (a Debug build's 16 MiB).
try std.testing.expect(!loadThemeFile(p, p.theme_file_generation, source.items));
- const said = p.panes[0].?.msg[0..p.panes[0].?.msg_len];
+ const said = p.messages.saidBy(p.panes[0].?);
std.testing.expect(std.mem.indexOf(u8, said, "theme file /tmp/pardes-config/themes/deep.zon: ") != null) catch |err| {
std.debug.print("{d} deep: said {s}\n", .{ depth, said });
return err;
@@ -1021,7 +1036,7 @@ test "ThemeFile parses ZON atomically and Theme returns to the compiled ring" {
// A half-written save is rejected without disturbing the last good value.
try std.testing.expect(!loadThemeFile(p, request_effect.generation, ".{ .name = "));
// Said with its line, in words: never a bare `parse zon`.
- const said = p.panes[0].?.msg[0..p.panes[0].?.msg_len];
+ const said = p.messages.saidBy(p.panes[0].?);
try std.testing.expect(std.mem.indexOf(u8, said, ": line 1: ") != null and std.mem.indexOf(u8, said, "parse zon") == null);
try std.testing.expectEqualStrings("mine", p.theme().name);
try std.testing.expectEqual(@as(?[3]u8, .{ 1, 2, 3 }), p.theme().bg);
diff --git a/core/config.zig b/core/config.zig
index a3d0fb84..d916b677 100644
--- a/core/config.zig
+++ b/core/config.zig
@@ -115,6 +115,8 @@ pub const leader_path = paths: {
.Changelog = "hc",
.Build = "hb",
.Messages = "hm",
+ .Keys = "hk",
+ .Message = "e",
.Newcol = "cn",
.Delcol = "cd",
.Joincol = "cj",
@@ -145,6 +147,7 @@ pub const leader_path = paths: {
.Back = "jo",
.Forward = "ji",
.Keep = "jk",
+ .Resume = "'",
.Last = "jj",
.Jumplist = "jl",
.History = "fh",
@@ -636,8 +639,9 @@ pub const Settings = struct {
/// A jump of the cursor leaves a short trail that fades: a setting
/// alone, each frontend draws it (jump_trail.zig).
jump_trail: bool = false,
- /// How long a message stays after the key or click that dismisses it.
- message_linger_ms: u16 = 800,
+ /// How long an echo or a notice stays bright before it dims (a warning
+ /// twice as long): Messages.Said.faded.
+ message_linger_ms: u16 = 4000,
/// Where Dump writes and a relative Restore looks; empty is the default
/// ($XDG_DATA_HOME/pardes, else ~/.local/share/pardes).
dump_dir: Text(limits.host_path_cap) = .{},
@@ -672,10 +676,10 @@ pub const Settings = struct {
callstack_depth: u8 = @import("lsp/lsp.zig").callstack_default_depth,
/// A jump (a Look at a place, a definition, an error's place) steps
- /// the pane it is made from, or its reader, as a walk (Trail.zig); or
- /// opens a pane for each file, as before the walk, until the walk's
- /// pickers and prompts are in (pick-ui SPEC §14.3).
- jumps: Jumps = .@"new-pane",
+ /// the pane it is made from, or its reader, as a walk (Trail.zig, the
+ /// spec's default); `new-pane` opens a pane for each file, as before
+ /// the walk (pick-ui SPEC §6.6's opt-out).
+ jumps: Jumps = .walk,
/// A setting that is one of a few words, each an enum field of Settings.
pub const Choice = enum { pet, jumps };
@@ -809,7 +813,7 @@ pub const Settings = struct {
.{ .word = "InactiveDim", .action = .inactive_dim, .doc = "Fade the unfocused panes' text by a percentage, 0 through 100, 0 off." },
.{ .word = "Pet", .action = .{ .choice = .pet }, .doc = "The window's companion in the workspace tag's blank space: off, cat or frog." },
.{ .word = "Jumps", .action = .{ .choice = .jumps }, .doc = "A jump steps its pane or that pane's reader (walk), or opens a pane for each file (new-pane)." },
- .{ .word = "MessageLinger", .action = .message_linger, .doc = "How long, in milliseconds, a message stays after what dismisses it." },
+ .{ .word = "MessageLinger", .action = .message_linger, .doc = "How long, in milliseconds, an echo or a notice stays bright before it dims; a warning twice as long." },
.{ .word = "DumpDir", .action = .dump_dir, .doc = "The directory of the state file, where Dump writes and Recent is kept. A relative Restore name is looked for there too; bare, the default." },
.{ .word = "Theme", .action = .theme, .doc = "Switch to the theme named: `Theme atelier`. Themes lists them, NextColor steps through them." },
.{ .word = "Shell", .action = .shell, .doc = "The shell new terminals run: `Shell /bin/zsh`; bare, $SHELL if it is executable, else /bin/sh." },
diff --git a/core/draw.zig b/core/draw.zig
index 0b6cebcf..dbbb6148 100644
--- a/core/draw.zig
+++ b/core/draw.zig
@@ -95,7 +95,7 @@ pub fn place(p: *Pardes, s: *Surface) void {
for (&p.panes, 0..) |*slot, id| {
const pane = slot.* orelse continue;
paneFacts(p, &p.facts, id, pane);
- Messages.collectNotices(p, pane, v.rects[id], id);
+ Messages.collectNotices(p, pane, v.rects[id]);
const r = v.rects[id];
if (r.w <= config.GUTTER or r.h == 0) continue;
const owner: u8 = @intCast(id);
@@ -161,10 +161,12 @@ pub fn place(p: *Pardes, s: *Surface) void {
const active_col = if (layout.findPane(p, v.active)) |found| found.col else null;
for (0..p.view().ncol) |c| {
if (v.col_w[c] == 0) continue;
- s.addRegion(.{ .kind = .column, .owner = @intCast(c), .serial = v.cols[c].serial, .active = active_col == c, .rect = .{ .x = v.col_x[c], .y = p.topBarHeight(), .w = v.col_w[c], .h = s.rows -| p.topBarHeight() } });
+ s.addRegion(.{ .kind = .column, .owner = @intCast(c), .serial = v.cols[c].serial, .active = active_col == c, .rect = .{ .x = v.col_x[c], .y = p.topBarHeight(), .w = v.col_w[c], .h = s.rows -| (p.topBarHeight() + layout.noticeRowHeight(p)) } });
}
if (p.settings.workspace_tag)
s.addRegion(.{ .kind = .workspace_tag, .rect = .{ .x = 0, .y = 0, .w = s.cols, .h = p.topBarHeight() } });
+ const foot = layout.noticeRowHeight(p);
+ if (foot > 0) s.addRegion(.{ .kind = .notice_row, .rect = .{ .x = 0, .y = s.rows - foot, .w = s.cols, .h = foot } });
}
/// A pane's grip in the grid: `box` focused, else halfway between its ring
@@ -228,12 +230,9 @@ fn joinNotice(p: *Pardes, s: *Surface, arena: std.mem.Allocator, region: Region)
const kind = pane.notices.kinds[i];
const r = v.rects[id];
const chip = region.rect.w;
- var leader_buf: [Messages.leader_room]u8 = undefined;
- const text = Messages.noticeText(p, pane, i, &leader_buf);
+ const text = Messages.noticeText(pane, i);
const bg = chrome.tag_bg;
- // Where an exec was sent to a REPL reads in the tag's name tint, set
- // apart from what the editor says.
- const fg = if (kind == .message and pane.msg_sent) chrome.tag_name_fg else chrome.tag_fg;
+ const fg = chrome.tag_fg;
// Nothing to say, or too narrow for a layer: a blank chip on the grid.
if (text.len == 0 or r.w <= TAG_TEXT_INSET) {
s.fill(region.rect.x, region.rect.y, chip, 1, .{ .bg = .{ .rgb = bg }, .font_role = .tagline });
@@ -349,7 +348,7 @@ pub fn render(p: *Pardes, arena: std.mem.Allocator) !*Surface {
// Separators have their own role; a scrollbar need not frame the page.
const whole = s.regions[0].rect;
s.fill(whole.x, whole.y, whole.w, whole.h, .{ .bg = .{ .rgb = chrome.border } });
- for (0..p.view().ncol) |c| if (v.cols[c].n == 0) s.fill(v.col_x[c], p.topBarHeight() + layout.columnBarHeight(p), v.col_w[c], s.rows -| (p.topBarHeight() + layout.columnBarHeight(p)), .{ .bg = .{ .rgb = chrome.empty_col } });
+ for (0..p.view().ncol) |c| if (v.cols[c].n == 0) s.fill(v.col_x[c], p.topBarHeight() + layout.columnBarHeight(p), v.col_w[c], s.rows -| (p.topBarHeight() + layout.columnBarHeight(p) + layout.noticeRowHeight(p)), .{ .bg = .{ .rgb = chrome.empty_col } });
for (&p.panes, 0..) |*slot, id| {
const pane = slot.* orelse continue;
@@ -374,6 +373,7 @@ pub fn render(p: *Pardes, arena: std.mem.Allocator) !*Surface {
};
try paintHeaders(p, s);
+ try paintNoticeRow(p, s);
// debug overlay: a small stats box drawn last, top-right ("Debug")
if (p.settings.debug) if (p.panes[v.active]) |at| {
@@ -482,6 +482,12 @@ fn renderPane(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r:
s.fill(r.x, tag_y, config.GUTTER, @min(1, pane.tag_rows), box_style);
if (dirty and pane.tag_rows > 0 and config.GUTTER > 1)
s.set(r.x + config.GUTTER - 1, tag_y, "*", .{ .fg = .{ .rgb = inkOn(boxDirty(p)) }, .bg = .{ .rgb = boxDirty(p) }, .bold = true, .font_role = .tagline });
+ // The mark (pick-ui SPEC §2): the status of the most important live
+ // message about the pane, in the box's second cell, on the dirty ground
+ // when there is unsaved text: a cell of the box's, never the tag's
+ // text, so it moves nothing.
+ if (pane.tag_rows > 0 and config.GUTTER > 1) if (p.messages.markOf(pane)) |kind|
+ s.set(r.x + config.GUTTER - 1, tag_y, kind.glyph(), .{ .fg = .{ .rgb = Messages.ink(chrome, kind) }, .bg = .{ .rgb = if (dirty) boxDirty(p) else box_bg }, .bold = true, .font_role = .tagline });
s.fill(r.x, tag_y + 1, config.GUTTER, pane.tag_rows -| 1, .{
.bg = .{ .rgb = band },
.font_role = .tagline,
@@ -569,6 +575,19 @@ fn paintHeaders(p: *Pardes, s: *Surface) !void {
viewport.x += inset;
viewport.w -= inset;
try renderHeaderLayer(p, layer, .workspace, 0, viewport, tagline.topbar(p), top, chrome.tagline_bg, chrome.tagline_fg);
+ // A server's progress (a message of no pane) at its first row's
+ // right end, where the row has room for it.
+ if (layer.rows > 0 and top == 0) for (p.messages.live[0..p.messages.live_len]) |*said| {
+ if (said.kind != .progress or said.pane != 0) continue;
+ var buf: [Messages.LoggedMessage.cap + 8]u8 = undefined;
+ const text = std.fmt.bufPrint(&buf, "{s} {s}", .{ Messages.Kind.progress.glyph(), said.words() }) catch break;
+ const width = panes.File.displayWidth(p.settings.tab, text);
+ const used = panes.File.displayWidth(p.settings.tab, modal.lineSlice(tagline.topbar(p), 0));
+ const room = layout.tagCapacity(p, viewport.w);
+ var row: Surface = .{ .cols = layer.cols, .rows = 1, .cells = layer.cells[0..layer.cols], .tab = p.settings.tab };
+ if (used + 2 + width < room) _ = row.print(@intCast(room - 1 - width), 0, @intCast(width), text, .{ .fg = .{ .rgb = Messages.ink(chrome, .progress) }, .bg = .{ .rgb = chrome.tagline_bg }, .font_role = .tagline });
+ break;
+ };
joinHeaderRows(s, layer, chrome.tagline_fg);
}
const column_rows = layout.columnBarHeight(p);
@@ -597,6 +616,43 @@ fn paintHeaders(p: *Pardes, s: *Surface) !void {
};
}
+/// The notice row (Messages.noticeRow), the live messages' index at the
+/// window's foot: a header layer at the tagline's pitch in the workspace
+/// tag's colours, the glyph in its kind's, a message gone dim and the
+/// counts at the right end dimmed.
+fn paintNoticeRow(p: *Pardes, s: *Surface) !void {
+ const region = s.region(.notice_row, Region.none) orelse return;
+ const chrome = p.chromeTheme();
+ var viewport = region.rect;
+ const inset = @min(TAG_TEXT_INSET, viewport.w);
+ s.fill(viewport.x, viewport.y, inset, viewport.h, .{ .bg = .{ .rgb = chrome.tagline_bg }, .font_role = .tagline });
+ viewport.x += inset;
+ viewport.w -= inset;
+ var buf: [Messages.notice_row_cap]u8 = undefined;
+ const row = Messages.noticeRow(p, layout.tagCapacity(p, viewport.w) -| 1, &buf);
+ const layer = &s.tag_layers[pardes.NOTICE_ROW_LAYER];
+ try renderHeaderLayer(p, layer, .notice_row, 0, viewport, row.text, 0, chrome.tagline_bg, chrome.tagline_fg);
+ if (layer.rows == 0) return;
+ const dim: Color = .{ .rgb = colors.mix(chrome.tagline_fg, chrome.tagline_bg) };
+ const ink: Color = .{ .rgb = chrome.tagline_fg };
+ const cells = layer.cells[0..layer.cols];
+ const tab = p.settings.tab;
+ const left = @min(cells.len, panes.File.displayWidth(tab, row.text[0..row.left]));
+ const right = @min(cells.len, panes.File.displayWidth(tab, row.text[0..row.right]));
+ if (row.lead) |lead| {
+ if (lead.kind == .@"error" or lead.kind == .warn) if (cells.len > 0 and std.meta.eql(cells[0].style.fg, ink)) {
+ cells[0].style.fg = .{ .rgb = if (lead.kind == .@"error") chrome.diagnostic_error else chrome.diagnostic_warning };
+ };
+ if (lead.faded(p.clock.now_ns, p.settings.message_linger_ms)) for (cells[0..left]) |*cell| {
+ if (std.meta.eql(cell.style.fg, ink)) cell.style.fg = dim;
+ };
+ }
+ for (cells[right..]) |*cell| if (std.meta.eql(cell.style.fg, ink)) {
+ cell.style.fg = dim;
+ };
+ joinHeaderRows(s, layer, chrome.tagline_fg);
+}
+
/// Copy a header's layer into the grid under it, row by row, and its caret.
fn joinHeaderRows(s: *Surface, layer: *const pardes.Layer, fg: [3]u8) void {
const v = layer.viewport;
@@ -631,7 +687,7 @@ fn joinCells(s: *Surface, x: u16, y: u16, cells: []const Cell, from: usize, w: u
if (!cells[from].default and cells[from].len == 0) blank(&row[x], ink);
}
-fn tagTintRange(pane: *const Pane, tag: []const u8, prefix_len: usize) ?struct { lo: usize, hi: usize } {
+fn tagTintRange(p: *const Pardes, pane: *const Pane, tag: []const u8, prefix_len: usize) ?struct { lo: usize, hi: usize } {
if (pane.isTerminal()) {
// `tag` is the first row; a prefix longer than it ran to a second.
var words = std.mem.tokenizeAny(u8, tag[@min(prefix_len, tag.len)..], " \t\r\n");
@@ -642,7 +698,7 @@ fn tagTintRange(pane: *const Pane, tag: []const u8, prefix_len: usize) ?struct {
}
return null;
}
- var start: usize = tagline.nameAt(pane);
+ var start: usize = tagline.nameAt(p, pane);
const name = if (pane.file) |file|
if (pane.prompt == .name) pane.input.own orelse file.path else file.path
else if (pane.addon) |k| blk: {
@@ -689,7 +745,7 @@ fn renderHeaderLayer(p: *Pardes, layer: *pardes.Layer, kind: TagKind, id: u16, v
const editing: ?*Text = if (v.header != null and switch (kind) {
.workspace => p.headerColumn() == null,
.column => p.headerColumn() == id,
- .pane, .notice, .body, .band => false,
+ .pane, .notice, .body, .band, .notice_row => false,
}) tagline.focusedHeader(p) else null;
const scroll = if (editing != null) v.header_scroll else 0;
for (0..viewport.h) |index| {
@@ -741,7 +797,7 @@ fn renderHeaderLayer(p: *Pardes, layer: *pardes.Layer, kind: TagKind, id: u16, v
const mine = switch (kind) {
.workspace => column == null,
.column => column == id,
- .pane, .notice, .body, .band => false,
+ .pane, .notice, .body, .band, .notice_row => false,
};
const swept = sweep.span(text.len);
const start = modal.lineStartOffset(text, index + top);
@@ -822,7 +878,7 @@ fn joinPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r
/// grid: the spines and steps in the tag's tint, the keys in the key ink,
/// the cursor's row tinted as a selection.
fn joinBand(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r: Rect, id: usize, active: bool) !void {
- const layer = &s.tag_layers[pardes.BAND_LAYER_BASE + id];
+ const layer = &s.tag_layers[pardes.BAND_LAYER];
if (r.w <= TAG_TEXT_INSET) return;
const band = (try pardes.Band.of(p, arena, pane, id)) orelse return;
const th = p.theme();
@@ -861,7 +917,8 @@ fn joinBand(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r: R
style.fg = .{ .rgb = chrome.box };
style.bold = true;
}
- if (part.row.dim) style.dim = true;
+ if (b < part.row.pre) style.fg = .{ .rgb = if (active) chrome.tag_active_name_fg else chrome.tag_name_fg };
+ if (part.row.dim or (b >= part.row.pre and b < part.row.pre + part.row.faint)) style.dim = true;
if (part.row.under) style.ul = .single;
for (part.row.marks) |m| if (m == b) {
style.bg = .{ .rgb = chrome.search_bg };
@@ -954,7 +1011,7 @@ fn paintPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane,
else if (pane.prompt == .name) caret: {
// A drafted name is the prefix: its caret is on row 0 of the tag,
// the rows it wrapped onto included.
- const at = modal.positionAt(shown.text, shown.fromReal(tagline.nameAt(pane) + @as(usize, @intCast(@max(0, pane.input.cur_col)))));
+ const at = modal.positionAt(shown.text, shown.fromReal(tagline.nameAt(p, pane) + @as(usize, @intCast(@max(0, pane.input.cur_col)))));
if (at.row < top or at.row >= top + rows) break :caret null;
break :caret .{ .row = at.row - top, .at = @min(lines[at.row - top].len, at.col) };
} else if (pane.focus == .tag and pane.prompt == .none and head == null) caret: {
@@ -971,16 +1028,27 @@ fn paintPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane,
const start = @min(line.len, panes.File.rawAtDisplay(p.settings.tab, line, pane.tag_scroll));
_ = s.print(tx, tag_y + @as(u16, @intCast(row)), tw, line[start..], tag_style);
}
+ // The pane's progress at its first row's right end, where the row has
+ // room for it (SPEC §10.2).
+ if (top == 0 and rows > 0) for (p.messages.live[0..p.messages.live_len]) |*said| {
+ if (said.kind != .progress or said.pane != pane.serial) continue;
+ var buf: [Messages.LoggedMessage.cap + 8]u8 = undefined;
+ const text = std.fmt.bufPrint(&buf, "{s} {s}", .{ Messages.Kind.progress.glyph(), said.words() }) catch break;
+ const width = panes.File.displayWidth(p.settings.tab, text);
+ const used = panes.File.displayWidth(p.settings.tab, lines[0]);
+ if (used + 2 + width <= tw) _ = s.print(tx + @as(u16, @intCast(tw - width)), tag_y, @intCast(width), text, .{ .fg = .{ .rgb = Messages.ink(chrome, .progress) }, .bg = .{ .rgb = tag_bg }, .font_role = .tagline });
+ break;
+ };
// The name's tint, in the tag's first line, over whichever rows it
// wrapped onto.
const first_line = whole[0 .. std.mem.indexOfScalar(u8, whole, '\n') orelse whole.len];
- if (tagTintRange(pane, first_line, prefix_len)) |name| if (name.lo < name.hi)
+ if (tagTintRange(p, pane, first_line, prefix_len)) |name| if (name.lo < name.hi)
inkTag(p, s, shown, lines[0..rows], top, tx, tag_y, tw, name.lo, @min(name.hi, first_line.len), if (active) chrome.tag_active_name_fg else chrome.tag_name_fg);
// A walk's forward steps, after the name, dimmed (Trail.zig).
- const ahead = tagline.forwardSpan(pane);
+ const ahead = tagline.forwardSpan(p, pane);
if (ahead[0] < ahead[1]) inkTag(p, s, shown, lines[0..rows], top, tx, tag_y, tw, ahead[0], @min(ahead[1], first_line.len), chrome.lineno);
// A search word its places no longer light, dimmed (Prompt.zig).
- if (pardes.Prompt.unlit(pane)) |span| inkTag(p, s, shown, lines[0..rows], top, tx, tag_y, tw, span[0], @min(span[1], first_line.len), chrome.lineno);
+ if (pardes.Prompt.unlit(p, pane)) |span| inkTag(p, s, shown, lines[0..rows], top, tx, tag_y, tw, span[0], @min(span[1], first_line.len), chrome.lineno);
// The head's keys in the key ink, its dimmed, underlined and struck
// words (TagState.Span), over whichever rows they wrapped onto.
if (head) |h| for (h.spans) |span| {
@@ -1283,8 +1351,8 @@ test "place puts every part where the painters and layers put it, in every layou
}
}
-test "the word under the pointer on a notice is lit in its layer and in the grid's copy" {
- const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 41, .rows = 12 });
+test "the word under the pointer on the notice row is lit in its layer and in the grid's copy" {
+ const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 61, .rows = 12 });
defer p.deinit();
_ = try p.setTestFile("text\n");
var arena: std.heap.ArenaAllocator = .init(std.testing.allocator);
@@ -1292,36 +1360,35 @@ test "the word under the pointer on a notice is lit in its layer and in the grid
try std.testing.expect(p.executeBuiltinLine(p.view().active, "Msg Look here"));
p.sync();
var s = try p.render(arena.allocator());
- const notice = for (s.regionList()) |region| {
- if (region.kind == .notice) break region;
- } else return error.TestExpectedNotice;
- const row = s.cells[@as(usize, notice.rect.y) * s.cols ..][0..s.cols];
- // "here", the chip's last word, before its blank edge.
- const here = notice.rect.x + notice.rect.w - 5;
+ const foot = s.region(.notice_row, Region.none) orelse return error.TestExpectedNoticeRow;
+ try std.testing.expectEqual(s.rows - 1, foot.rect.y);
+ const row = s.cells[@as(usize, foot.rect.y) * s.cols ..][0..s.cols];
+ // "here": the message's last word, `· /test.txt Look here`, 17
+ // columns in.
+ const here: u16 = TAG_TEXT_INSET + 17;
try std.testing.expectEqualStrings("h", row[here].grapheme());
p.view().pointer_inside = true;
p.view().hover_col = here + 1;
- p.view().hover_row = notice.rect.y;
+ p.view().hover_row = foot.rect.y;
_ = arena.reset(.retain_capacity);
s = try p.render(arena.allocator());
- const lit = s.cells[@as(usize, notice.rect.y) * s.cols ..][0..s.cols];
- const sel: Color = .{ .rgb = p.theme().sel_bg };
+ const lit = s.cells[@as(usize, foot.rect.y) * s.cols ..][0..s.cols];
+ const sel: Color = .{ .rgb = p.theme().tag_sel_bg orelse p.theme().sel_bg };
for (lit[here..][0..4]) |cell| try std.testing.expectEqual(sel, cell.style.bg);
try std.testing.expect(!std.meta.eql(sel, lit[here - 2].style.bg));
- const layer = for (s.tagLayers()) |*layer| {
- if (layer.rows != 0 and layer.kind == .notice) break layer;
- } else return error.TestExpectedNotice;
+ const layer = &s.tag_layers[pardes.NOTICE_ROW_LAYER];
+ try std.testing.expectEqual(TagKind.notice_row, layer.kind);
const lit_in_layer = for (layer.cells) |cell| {
if (std.meta.eql(sel, cell.style.bg)) break true;
} else false;
try std.testing.expect(lit_in_layer);
}
-test "a notice wider than its band, as a shader's compile error is, draws its end and nothing past it" {
+test "a message wider than the notice row, as a shader's compile error is, gives way to the row's right end and draws nothing past the row" {
const p = try Pardes.init(std.testing.allocator, .{ .cols = 80, .rows = 20 });
defer p.deinit();
- // A gui-shaped core: its tagline is narrower than the body, so a notice's
- // band holds more columns than its chip has cells.
+ // A gui-shaped core: its tagline is narrower than the body, so the
+ // row's layer holds more columns than the grid has cells.
p.update(.{ .resize = .{ .cols = 80, .rows = 20, .row_metrics = .{ .body_w = 10, .body_h = 20, .tagline_w = 6, .tagline_h = 12 } } });
_ = try p.setTestFile("text\n");
var arena: std.heap.ArenaAllocator = .init(std.testing.allocator);
@@ -1334,13 +1401,12 @@ test "a notice wider than its band, as a shader's compile error is, draws its en
for (0..30) |_| p.update(.tick);
_ = arena.reset(.retain_capacity);
const s = try p.render(arena.allocator());
- const notice = for (s.regionList()) |region| {
- if (region.kind == .notice) break region;
- } else return error.TestExpectedNotice;
- // Text up to the chip's blank last cell, and no padding ink.
- const row = s.cells[@as(usize, notice.rect.y) * s.cols ..][notice.rect.x..][0..notice.rect.w];
- try std.testing.expectEqualStrings(" ", row[row.len - 1].grapheme());
- try std.testing.expect(!std.mem.eql(u8, " ", row[row.len - 2].grapheme()));
+ const layer = &s.tag_layers[pardes.NOTICE_ROW_LAYER];
+ try std.testing.expectEqual(layout.tagCapacity(p, s.cols - TAG_TEXT_INSET), layer.cols);
+ // The counts at the row's end, whole, a blank cell short of it.
+ const cells = layer.cells[0..layer.cols];
+ try std.testing.expectEqualStrings(" ", cells[cells.len - 1].grapheme());
+ try std.testing.expectEqualStrings("m", cells[cells.len - 2].grapheme());
}
}
@@ -1623,7 +1689,7 @@ fn apart(a: *const Pardes, b: *const Pardes) bool {
var pdb: [pane_names.len]u64 = undefined;
_ = pardes.walk.fieldDigests(Pane, x, &pda);
_ = pardes.walk.fieldDigests(Pane, y, &pdb);
- for (pane_names, pda, pdb) |name, u, v| if (u != v and !std.mem.eql(u8, name, "msg_said_ms") and !std.mem.eql(u8, name, "cwd")) {
+ for (pane_names, pda, pdb) |name, u, v| if (u != v and !std.mem.eql(u8, name, "cwd")) {
if (std.mem.eql(u8, name, "file")) if (x.file) |*fx| if (y.file) |*fy| {
const file_names = comptime pardes.walk.fieldNames(panes.File.State);
var fda: [file_names.len]u64 = undefined;
@@ -1642,3 +1708,38 @@ fn apart(a: *const Pardes, b: *const Pardes) bool {
}
return any;
}
+
+test "progress is said at the right end of its tag: a pane's at its tag's, a server's at the workspace tag's, and it goes when it ends" {
+ const p = try Pardes.init(std.testing.allocator, .{ .cols = 160, .rows = 20 });
+ defer p.deinit();
+ const pane = try p.setTestFile("text\n");
+ const id = p.view().active;
+ var frame = std.heap.ArenaAllocator.init(std.testing.allocator);
+ defer frame.deinit();
+ var buf: [512]u8 = undefined;
+ const Row = struct {
+ fn of(s: *const Surface, y: u16, out: []u8) []const u8 {
+ var n: usize = 0;
+ for (0..s.cols) |x| {
+ const g = s.cells[@as(usize, y) * s.cols + x].grapheme();
+ @memcpy(out[n..][0..g.len], g);
+ n += g.len;
+ }
+ return std.mem.trimEnd(u8, out[0..n], " ");
+ }
+ };
+ p.setStatus(.at(id), "Changes: jj\u{2026}");
+ p.setStatus(.at(pardes.MAX_PANES), "--:--:-- lsp zls: indexing 3/10");
+ p.sync();
+ var s = try p.render(frame.allocator());
+ const tag_y = p.tagTop(pane, p.view().rects[id]);
+ try std.testing.expect(std.mem.endsWith(u8, Row.of(s, tag_y, &buf), "\u{22ef} Changes: jj\u{2026}"));
+ try std.testing.expect(std.mem.endsWith(u8, Row.of(s, 0, &buf), "\u{22ef} lsp zls: indexing 3/10"));
+ // Its mark meanwhile, and neither is the notice row's.
+ try std.testing.expectEqualStrings("\u{22ef}", s.at(p.view().rects[id].x + config.GUTTER - 1, tag_y).grapheme());
+ try std.testing.expect(p.messages.headline() == null);
+ p.setStatus(.at(id), "");
+ _ = frame.reset(.retain_capacity);
+ s = try p.render(frame.allocator());
+ try std.testing.expect(std.mem.indexOf(u8, Row.of(s, tag_y, &buf), "\u{22ef}") == null);
+}
diff --git a/core/dump.zig b/core/dump.zig
index b4561ae2..8e44d82d 100644
--- a/core/dump.zig
+++ b/core/dump.zig
@@ -148,6 +148,7 @@ fn afterLoad(p: *Pardes) void {
f.context.reload(p.tree_sitter_gpa, f.path, text, f.revision);
};
@import("jj.zig").loaded(p);
+ pardes.TagState.loaded(p);
}
/// A file kept slim in a dump (`dumpExit`, a closed pane's past its bound,
@@ -399,26 +400,28 @@ fn loadKnowing(gpa: std.mem.Allocator, opts: Options, bytes: []const u8, notes:
errdefer {
if (notes) |n| n.appendSlice(gpa, l.notes.items) catch {};
l.rollback();
+ // Its opens are what the load read: the rollback's, freed (and
+ // their count may be a damaged one, refused).
+ p.fs.opens_len = 0;
p.fs.deinit(gpa);
gpa.destroy(p);
}
l.allocs = .{ .image = p.image_gpa, .terminal = terminal_gpa };
try l.into(Pardes, p);
const read = l.shared.items.len;
- const mounts = try l.get([]const filesystem.Mount);
+ // What is read after the core (its mounts, its theme) is freed here,
+ // what the load made for it once each, and no rollback of it: a
+ // damaged dump's reference to a slice the core holds is the core's,
+ // never freed here (a theme that was one was freed by hand and again
+ // by the rollback).
defer {
- for (mounts) |m| {
- gpa.free(m.name);
- gpa.free(m.dial);
- }
- gpa.free(mounts);
- // Freed here: no rollback of them.
+ for (l.shared.items[read..]) |m| if (m.bytes.len > 0) m.gpa.rawFree(m.bytes, m.alignment, @returnAddress());
l.shared.shrinkRetainingCapacity(read);
}
+ const mounts = try l.get([]const filesystem.Mount);
const was = try l.get(OnDisk);
if (on_disk) |out| out.* = was;
const theme = try l.get([]const u8);
- defer gpa.free(theme);
// This build's place for that theme; one it has not, its first.
p.settings.theme = for (colors.themes, 0..) |t, i| {
if (std.mem.eql(u8, t.name, theme)) break i;
@@ -452,8 +455,8 @@ fn loadKnowing(gpa: std.mem.Allocator, opts: Options, bytes: []const u8, notes:
else => return err,
};
views.undumped(p, others);
- for (others) |o| gpa.free(o.panes);
- gpa.free(others);
+ // What it made, as the mounts' (above).
+ for (l.shared.items[at..]) |m| if (m.bytes.len > 0) m.gpa.rawFree(m.bytes, m.alignment, @returnAddress());
l.shared.shrinkRetainingCapacity(at);
afterLoad(p);
p.readSessionFacts();
@@ -476,6 +479,9 @@ fn loadImage(gpa: std.mem.Allocator, opts: Options, bytes: []const u8, notes: ?*
errdefer {
if (notes) |n| n.appendSlice(gpa, l.notes.items) catch {};
l.rollback();
+ // Its opens are what the load read: the rollback's, freed (and
+ // their count may be a damaged one, refused).
+ p.fs.opens_len = 0;
p.fs.deinit(gpa);
gpa.destroy(p);
}
@@ -1418,3 +1424,20 @@ test "optional GPU addon reload generation survives a replica dump" {
try std.testing.expectEqual(original.gen, restored.gen);
try std.testing.expectEqual(walk.digest(Kind.Slot, &original), walk.digest(Kind.Slot, &restored));
}
+
+test "a load refused after the core frees what a script's open held once: the rollback's, not the namespace's" {
+ const gpa = std.testing.allocator;
+ const p = try Pardes.init(gpa, .{ .tty_only = true, .mounts = &.{.{ .name = "peer", .dial = "/tmp/peer.sock" }} });
+ defer p.deinit();
+ _ = try p.setTestFile("x\n");
+ // A script's open of a file of command lines, its last line half
+ // written: bytes the load makes.
+ p.fs.opens[0] = .{ .node = 1, .what = .lines };
+ try p.fs.opens[0].pending.appendSlice(gpa, "Look half");
+ p.fs.opens_len = 1;
+ const bytes = try byteDump(p);
+ defer gpa.free(bytes);
+ // The mounts are read after the core: the same name dialled elsewhere
+ // refuses the load there.
+ try std.testing.expectError(error.MountConflict, load(gpa, .{ .mounts = &.{.{ .name = "peer", .dial = "/tmp/other.sock" }} }, bytes, null));
+}
diff --git a/core/edit.zig b/core/edit.zig
index 6c0ba02b..e68f8d38 100644
--- a/core/edit.zig
+++ b/core/edit.zig
@@ -2140,6 +2140,9 @@ fn stepOwn(e: Editor, t: *Text, back: bool) error{OutOfMemory}!void {
const PointerTextSelection = struct {
sel: Pane.Sel,
on_tag: bool,
+ /// On a row of a message's detail (Pane.textRow): that body row as
+ /// drawn; the selection is on the line it explains.
+ ghost: ?u16 = null,
};
pub fn pointerTextSelection(p: *const Pardes, id: usize, col: u16, row: u16, body_hit: ?Mouse.BodyHit, tag_hit: ?TagHit) ?PointerTextSelection {
@@ -2158,16 +2161,21 @@ pub fn pointerTextSelection(p: *const Pardes, id: usize, col: u16, row: u16, bod
if (!on_tag) if (body_hit) |supplied| {
const mapped_hit = mouse.bodyHitForPane(p, id, supplied, false) orelse return null;
const c = @as(i32, mapped_hit.col) - config.GUTTER;
- const v = @as(i32, mapped_hit.row) + pane.tag_rows;
- return .{ .sel = .{ .state = .dragging, .c0 = c, .c1 = c, .r0 = v, .r1 = v }, .on_tag = false };
+ const drawn: i32 = mapped_hit.row;
+ const v = pane.textRow(drawn) + pane.tag_rows;
+ const ghost = pane.ghost_rows > 0 and drawn > pane.ghost_at and drawn <= pane.ghost_at + pane.ghost_rows;
+ return .{ .sel = .{ .state = .dragging, .c0 = c, .c1 = c, .r0 = v, .r1 = v }, .on_tag = false, .ghost = if (ghost) mapped_hit.row else null };
};
const tag_col = if (on_tag) Layer.columnAt(p, .pane, id, tag_hit, false, row - tag_y) else null;
const c: i32 = (if (tag_col) |value| @as(i32, value) else @as(i32, col) - @as(i32, r.x + (if (on_tag) TAG_TEXT_INSET else config.GUTTER))) +
(if (on_tag) @as(i32, pane.tag_scroll) else 0);
- const v: i32 = if (on_tag) @as(i32, row) - @as(i32, tag_y) else @as(i32, row) - @as(i32, body_y) + @as(i32, pane.tag_rows);
+ const drawn: i32 = @as(i32, row) - @as(i32, body_y);
+ const v: i32 = if (on_tag) @as(i32, row) - @as(i32, tag_y) else pane.textRow(drawn) + @as(i32, pane.tag_rows);
+ const ghost = !on_tag and pane.ghost_rows > 0 and drawn > pane.ghost_at and drawn <= pane.ghost_at + pane.ghost_rows;
return .{
.sel = .{ .state = .dragging, .c0 = c, .c1 = c, .r0 = v, .r1 = v },
.on_tag = on_tag,
+ .ghost = if (ghost) @intCast(drawn) else null,
};
}
@@ -2320,7 +2328,7 @@ test "insert on a terminal's text says it edits a copy the program's next drawin
pane.body.mode = .normal;
p.update(.{ .key = .{ .cp = 'i' } });
p.update(.{ .key = .{ .cp = 'x', .text = "x" } });
- try std.testing.expect(std.mem.indexOf(u8, pane.msg[0..pane.msg_len], "a copy of the terminal's text") != null);
+ try std.testing.expect(std.mem.indexOf(u8, p.messages.saidBy(pane), "a copy of the terminal's text") != null);
}
test "insert and normal modes edit complete Unicode graphemes" {
@@ -2533,7 +2541,7 @@ test "a paste past the limit is cut at it, and says so" {
try applyPaste(p, big);
try std.testing.expect(pane.file.?.content.len <= limit);
try std.testing.expect(pane.file.?.content.len > 0);
- try std.testing.expect(std.mem.indexOf(u8, pane.msg[0..pane.msg_len], "paste cut") != null);
+ try std.testing.expect(std.mem.indexOf(u8, p.messages.saidBy(pane), "paste cut") != null);
}
test "typing and backspace through the line index keep the text and the index as a rebuild has them" {
diff --git a/core/edit_cmd.zig b/core/edit_cmd.zig
index aec97c63..8fbde726 100644
--- a/core/edit_cmd.zig
+++ b/core/edit_cmd.zig
@@ -300,7 +300,7 @@ fn answerHold(p: *Pardes, at: usize, failed: bool) void {
if (!failed) return;
const words = if (p.fs.said_at == p.fs.failures and p.fs.said_len > 0)
p.fs.said[0..p.fs.said_len]
- else if (p.panes[at]) |pane| pane.msg[0..pane.msg_len] else "Edit: failed";
+ else if (p.panes[at]) |pane| p.messages.saidBy(pane) else "Edit: failed";
const kept = @import("Messages.zig").clip(words, h.said.len);
@memcpy(h.said[0..kept.len], kept);
h.said_len = @intCast(kept.len);
@@ -625,6 +625,8 @@ test "X over open files, w, e, r, f, B and D on panes and the disk" {
const dir = dir_buf[0..try tmp.dir.realPath(testing.io, &dir_buf)];
const p = try th.withFile(gpa, "scratch\n");
defer p.deinit();
+ // About a jump opening a pane: `Jumps new-pane` (SPEC §6.6).
+ p.settings.jumps = .@"new-pane";
var path: [4200]u8 = undefined;
look.lookAt(p, 0, try std.fmt.bufPrint(&path, "{s}/a.c", .{dir}));
const a = p.view().active;
@@ -697,6 +699,8 @@ test "an Edit's w to a file changed on disk is refused once, as Save is, and the
const dir = dir_buf[0..try tmp.dir.realPath(testing.io, &dir_buf)];
const p = try th.withFile(testing.allocator, "scratch\n");
defer p.deinit();
+ // About a jump opening a pane: `Jumps new-pane` (SPEC §6.6).
+ p.settings.jumps = .@"new-pane";
var path: [4200]u8 = undefined;
look.lookAt(p, 0, try std.fmt.bufPrint(&path, "{s}/a.txt", .{dir}));
const a = p.view().active;
@@ -731,6 +735,8 @@ test "an Edit with no command runs beside one whose commands run, unless it touc
const dir = dir_buf[0..try tmp.dir.realPath(testing.io, &dir_buf)];
const p = try th.withFile(testing.allocator, "b\na\n");
defer p.deinit();
+ // About a jump opening a pane: `Jumps new-pane` (SPEC §6.6).
+ p.settings.jumps = .@"new-pane";
var path: [4200]u8 = undefined;
look.lookAt(p, 0, try std.fmt.bufPrint(&path, "{s}/other.txt", .{dir}));
const other = p.view().active;
diff --git a/core/exec.zig b/core/exec.zig
index 2528805f..5a5ff725 100644
--- a/core/exec.zig
+++ b/core/exec.zig
@@ -617,8 +617,7 @@ pub fn sendToRepl(p: *Pardes, from: usize, to: usize, text: []const u8) void {
p.setMessage(.at(from), warn.print("Repl: {s} takes no bracketed paste; a blank line in a block ends it", .{id}));
}
var said: pardes.Kind.Buf(64) = .{};
- p.setMessage(.at(from), said.print("\u{2192} {s}", .{id}));
- src.msg_sent = true;
+ _ = pardes.Messages.say(p, .echo, from, said.print("\u{2192} {s}", .{id}));
var rec: [96]u8 = undefined;
pardes.ctlfs.events.notePath(p, "send", std.fmt.bufPrint(&rec, "{d} {d} {s}", .{ src.serial, dst.serial, id }) catch return);
}
@@ -634,6 +633,8 @@ const max_exec_depth = 8;
/// child is `$SHELL -c` the line, which shows its output and `exit N` when
/// done, and which Kill signals. Answers the pane it went to.
pub fn execute(p: *Pardes, id: usize, txt: []const u8) ?usize {
+ // A question's answer word, on the pane it waits on (B2 on `Reload`).
+ if (pardes.Messages.answerWord(p, id, txt)) return null;
return executeFrom(p, id, txt, false);
}
@@ -761,6 +762,11 @@ pub fn runCommand(p: *Pardes, from: usize, line: []const u8) ?usize {
pane.command_done = false;
pane.command_status = null;
pane.command_pty = true;
+ // Its last run's errors go with it (SPEC §11).
+ var i: usize = 0;
+ while (i < p.messages.live_len) {
+ if (p.messages.live[i].pane == pane.serial and p.messages.live[i].kind == .@"error") p.messages.remove(i) else i += 1;
+ }
pane.body.mode = .tty;
// What the last program left the emulator in goes first: the
// alternate screen left (only if it is there: leaving restores a
@@ -874,6 +880,8 @@ pub fn executeBuiltinLine(p: *Pardes, id: usize, txt: []const u8) bool {
const raw = commandText(txt);
if (raw.len == 0 or p.exec_depth >= max_exec_depth) return false;
if (isComment(raw)) return true;
+ // A live picker's act and source words are its own (Pick.zig).
+ if (pardes.Pick.execWord(p, raw)) return true;
// `+` too, so an old `Tty+fish` is renamed as `Tty fish` is.
const word_end = std.mem.indexOfAny(u8, raw, " \t+") orelse raw.len;
var renamed: [1024 + 16]u8 = undefined;
@@ -974,15 +982,14 @@ pub fn runBuiltinFrom(p: *Pardes, b: Builtin, id: usize, txt: []const u8, arg: ?
// No pane at all (the window Delcol emptied): a word runs all the same,
// with a stand-in that is no pane (New, Newcol, Exit are what make sense).
const pane = p.panes[id] orelse (if (builtins.registry.scope(b) == .session or panes.anyPane(p) == null) panes.standIn(p) orelse return else return);
- // A builtin says its own name before it runs, so a tagline click is
- // legible even when what it did is invisible. Whatever the builtin
- // then says for itself replaces the announcement. It is the message
- // row's only, never /log's: a msg record is something said.
+ // A builtin says its own name before it runs, an echo, so a tagline
+ // click is legible even when what it did is invisible. Whatever the
+ // builtin then says for itself retires it. It is the message row's
+ // only, never /log's: a msg record is something said.
if (p.announce and p.settings.verbose and builtins.registry.announces(b)) {
p.fs.unlogged = true;
- p.setMessage(.at(id), @tagName(b));
+ _ = pardes.Messages.say(p, .echo, id, @tagName(b));
p.fs.unlogged = false;
- pane.msg_announcement = true;
}
// A word for one kind of pane, on another: refused with why, not a
// silent nothing (Palette on a file, Filter on a PDF).
diff --git a/core/fuzz.zig b/core/fuzz.zig
index 616636ab..7f4526a7 100644
--- a/core/fuzz.zig
+++ b/core/fuzz.zig
@@ -777,6 +777,12 @@ test "a dump and an image cut, flipped and grown: refused or loaded, never a pan
const gpa = testing.allocator;
const p = try th.withFile(gpa, "alpha beta\ngamma\n\tdelta \xe6\x97\xa5\n");
defer p.deinit();
+ // A reader's walk in it: a union, a fixed array held to its length.
+ p.panes[0].?.trail = pardes.Trail.reader(7, "/x/rank.zig", .{ .line = 3, .col = 2 });
+ // A view's tag out of rest in it (View.tag_state): SPC t w remembered
+ // (a group's last leaf), then Help typed into (a scope, a field, hits).
+ for (" tw ?hel") |c| p.update(.{ .key = .{ .cp = c, .text = &[_]u8{c} } });
+ try testing.expect(p.view().tag_state.kind == .help and p.view().tag_state.nhits > 0);
// The byte dump a join streams, and the image a Dump keeps.
const bytes = try pardes.dump.byteDump(p);
defer gpa.free(bytes);
@@ -785,6 +791,12 @@ test "a dump and an image cut, flipped and grown: refused or loaded, never a pan
// Seconds a road, each core used (`use`). The image's past 1779 seeds
// reach xitdb's own reader (a slot's tag past its kinds: a `switch` on
// it), a dependency's.
+ // Join seed 19224: the theme read after the core a reference to a
+ // slice the core holds, freed by hand and again by the rollback.
+ try loadSeed(bytes, .join, 19224);
+ // Join seed 31554: the namespace's opens_len past its 64 slots, refused,
+ // and the rollback's teardown of the namespace read that far.
+ try loadSeed(bytes, .join, 31554);
for ([_][]const u8{ bytes, image }, [_]Road{ .join, .restore }, [_]u64{ 2048, 1024 }) |whole, road, n| {
try loadSeed(whole, road, 0);
for (1..n + 1) |seed| try loadSeed(whole, road, seed);
diff --git a/core/jj.zig b/core/jj.zig
index c1d07662..dea0236f 100644
--- a/core/jj.zig
+++ b/core/jj.zig
@@ -2030,14 +2030,15 @@ fn ownerOf(ch: *const Changes, f: *const File.State, row: usize) PinIndex {
/// The line `]g` (`forward`) or `[g` goes to from buffer line `from` of
/// the pane: the next or the previous change's first line (the first of a
/// run of lines one pin wrote or took away: a ghost line is a line); null
-/// with none shown, or none that way.
-pub fn nextChange(p: *Pardes, pane: *const Pane, from: usize, forward: bool) ?usize {
+/// with none shown, or none that way, or none in the `most` lines looked
+/// at (a body's painted targets look at the rows shown alone).
+pub fn nextChange(p: *Pardes, pane: *const Pane, from: usize, forward: bool, most: usize) ?usize {
if (pane.layers.lanes == 0) return null;
const f = if (pane.file) |*file| file else return null;
const ch = answered(p, f.layer.owner) orelse return null;
const n = File.lineCount(f.content);
var row = from;
- while (true) {
+ for (0..most) |_| {
if (forward) {
row += 1;
if (row >= n) return null;
@@ -2048,6 +2049,7 @@ pub fn nextChange(p: *Pardes, pane: *const Pane, from: usize, forward: bool) ?us
const owner = ownerOf(ch, f, row);
if (owner != .none and (row == 0 or ownerOf(ch, f, row - 1) != owner)) return row;
}
+ return null;
}
/// A Look (B3) at column `col` of body row `vr` of pane `id` on the id of
@@ -2534,7 +2536,7 @@ const Repo = struct {
fn told(p: *Pardes, id: usize) []const u8 {
const pane = p.panes[id].?;
- return pane.msg[0..pane.msg_len];
+ return p.messages.saidBy(pane);
}
test "At shows a file at a revision beside it, read-only, coloured as its file; a Look at path@rev:line goes to it; At in it turns it in place; jj's refusals are said" {
@@ -2543,6 +2545,8 @@ test "At shows a file at a revision beside it, read-only, coloured as its file;
defer repo.deinit(gpa);
const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 100, .rows = 40 });
defer p.deinit();
+ // About a jump opening a pane: `Jumps new-pane` (SPEC §6.6).
+ p.settings.jumps = .@"new-pane";
var line: [4200]u8 = undefined;
p.update(.{ .command = try std.fmt.bufPrint(&line, "Look {s}", .{repo.file}) });
const file = p.view().active;
@@ -2964,6 +2968,8 @@ test "Changes draws what the text has not where it stood, as ghost rows: a line
for ([_]bool{ false, true }) |windowed| {
const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 60, .rows = 24, .windowed = windowed });
defer p.deinit();
+ // About a jump opening a pane: `Jumps new-pane` (SPEC §6.6).
+ p.settings.jumps = .@"new-pane";
var line: [4200]u8 = undefined;
p.update(.{ .command = try std.fmt.bufPrint(&line, "Look {s}", .{repo.file}) });
const id = p.view().active;
@@ -3250,6 +3256,8 @@ test "a description is whole, its title and its author never cut: in a pane narr
for ([_]bool{ false, true }) |windowed| {
const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 50, .rows = 20, .windowed = windowed });
defer p.deinit();
+ // About a jump opening a pane: `Jumps new-pane` (SPEC §6.6).
+ p.settings.jumps = .@"new-pane";
var line: [4200]u8 = undefined;
p.update(.{ .command = try std.fmt.bufPrint(&line, "Look {s}", .{repo.file}) });
const id = p.view().active;
@@ -3487,6 +3495,8 @@ test "at one place a change's ghost rows come before its description: a line it
defer repo.deinit(gpa);
const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 60, .rows = 24, .windowed = false });
defer p.deinit();
+ // About a jump opening a pane: `Jumps new-pane` (SPEC §6.6).
+ p.settings.jumps = .@"new-pane";
var line: [4200]u8 = undefined;
p.update(.{ .command = try std.fmt.bufPrint(&line, "Look {s}", .{repo.file}) });
const pane = p.panes[p.view().active].?;
@@ -3513,6 +3523,8 @@ test "a change the revset does not pin, between two it does, moves the older one
defer repo.deinit(gpa);
const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 60, .rows = 24, .windowed = false });
defer p.deinit();
+ // About a jump opening a pane: `Jumps new-pane` (SPEC §6.6).
+ p.settings.jumps = .@"new-pane";
var line: [4200]u8 = undefined;
p.update(.{ .command = try std.fmt.bufPrint(&line, "Look {s}", .{repo.file}) });
const pane = p.panes[p.view().active].?;
@@ -3605,6 +3617,8 @@ test "the layer's lines are the pane's text, read-only: j and k go onto them, a
// query however long the test's directory makes the tags.
const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 60, .rows = 44, .windowed = windowed });
defer p.deinit();
+ // About a jump opening a pane: `Jumps new-pane` (SPEC §6.6).
+ p.settings.jumps = .@"new-pane";
var arena: std.heap.ArenaAllocator = .init(gpa);
defer arena.deinit();
const pane = try Lines.open(p, repo.file);
@@ -3656,8 +3670,7 @@ test "the layer's lines are the pane's text, read-only: j and k go onto them, a
// the path there opens it (no selection held: B2 in one runs it).
// (The refusals' words, stacked in the notice band over the body's
// first rows, gone.)
- pane.msg_len = 0;
- pane.msg_older_len = 0;
+ p.messages.live_len = 0;
p.view().active = id;
Lines.at(pane, 0, 0);
p.sync();
@@ -4405,6 +4418,8 @@ test "Compare pins the whole difference between each two points as one change: t
for ([_]bool{ false, true }) |windowed| {
const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 70, .rows = 24, .windowed = windowed });
defer p.deinit();
+ // About a jump opening a pane: `Jumps new-pane` (SPEC §6.6).
+ p.settings.jumps = .@"new-pane";
var line: [4200]u8 = undefined;
p.update(.{ .command = try std.fmt.bufPrint(&line, "Look {s}", .{repo.file}) });
const id = p.view().active;
diff --git a/core/keys.zig b/core/keys.zig
index a0aa9692..e9be2461 100644
--- a/core/keys.zig
+++ b/core/keys.zig
@@ -212,9 +212,32 @@ pub fn handleKey(p: *Pardes, key: Key) void {
}
return;
}
+ // A background question SPC e gave the keyboard: one of its answers'
+ // keys answers it (Diff leaves it asking), Esc leaves it waiting, and
+ // nothing else gets past it (pick-ui SPEC §10.4).
+ if (p.view().answering != 0) answering: {
+ const v = p.view();
+ const at = p.paneBySerial(v.answering) orelse break :answering;
+ const i = p.messages.waiting(p.panes[at].?) orelse break :answering;
+ if (key.cp == Key.escape and !key.ctrl and !key.alt) {
+ v.answering = 0;
+ p.needs_frame = true;
+ return;
+ }
+ if (key.ctrl or key.alt or key.cp > 0x7f) return;
+ if (pardes.Messages.answer(p, i, @intCast(key.cp)) and key.cp != 'd') v.answering = 0;
+ return;
+ }
+ p.view().answering = 0;
// A tag in a typing state takes every key (TagState: Help, describe-key).
if (p.view().tag_state.kind != .rest) return tagStateKey(p, key);
Prompt.keyAtRest(p, key);
+ // Esc takes a hover's ghost lines away (SPEC §3.5) before anything else
+ // it does.
+ if (p.lsp_ask.hover != null and hit(key, config.escape)) {
+ p.lsp_ask.hover = null;
+ return;
+ }
if (p.view().window_pick != null) return layout.windowKey(p, key);
const pane = p.panes[p.view().active] orelse return;
layout.noteTyped(p);
@@ -381,7 +404,7 @@ pub fn handleKey(p: *Pardes, key: Key) void {
return;
}
if (header == null) if (TagState.current(p, p.view())) |cur| if (cur.root != .leader and cur.root != .window) {
- if (prefixKey(p, t, cur.root, key)) return;
+ if (prefixKey(p, t, cur, key)) return;
};
if (t == &pane.body and pane.jump.items.len > 0) return normal.jumpKey(p, pane, t, key);
// A query pane's line 1 answers Enter, Esc and the stepping keys
@@ -406,6 +429,13 @@ pub fn handleKey(p: *Pardes, key: Key) void {
break :word .{ b.lo, b.hi };
};
const txt = shown[span[0]..span[1]];
+ // On a word of the pane's walk, the step's Look or Exec, as a
+ // click there (SPEC §6.3).
+ if (header == null and t.what == .tag) if (tagline.trailAt(p, pane, modal.selectionCursor(shown, range))) |step| {
+ pane.focus = .body;
+ if (cmd == config.look_cmd) pardes.Trail.lookStep(p, p.view().active, step) else pardes.Trail.execStep(p, p.view().active, step);
+ return;
+ };
// A column tag's command acts on that column, empty or not.
p.exec_column = if (header != null) p.headerColumn() else null;
defer p.exec_column = null;
@@ -558,7 +588,31 @@ fn tagStateKey(p: *Pardes, key: Key) void {
if (TagState.hostOf(p) == null or hit(key, config.escape)) return TagState.toRest(p);
switch (s.kind) {
.rest, .prompt => unreachable,
- .describe => return TagState.toRest(p),
+ .describe => {
+ const plain = !key.ctrl and !key.alt;
+ if (plain and key.cp == Key.enter and s.found) {
+ var out: [16]Key = undefined;
+ var path: [8]u8 = undefined;
+ const n = s.scope_n;
+ @memcpy(path[0..n], s.scope[0..n]);
+ const typed = bindings.keysOf(s.scope_root.?, path[0..n], &out);
+ TagState.toRest(p);
+ for (typed) |k| handleKey(p, k);
+ return;
+ }
+ if (plain and key.cp == Key.backspace) {
+ if (s.scope_n > 0 and s.scope_root != null) {
+ s.scope_n -= 1;
+ } else s.scope_root = null;
+ if (s.scope_root == null) s.scope_n = 0;
+ s.found = false;
+ s.missed = false;
+ return;
+ }
+ TagState.describeKey(p, key);
+ },
+ .pick => return @import("Pick.zig").key(p, key),
+ .rename => return @import("lsp/Ask.zig").renameKey(p, key),
.help => {
const plain = !key.ctrl and !key.alt;
if (plain and key.cp == Key.enter) {
@@ -662,15 +716,27 @@ fn levelKey(p: *Pardes, root: bindings.Root, path: []const u8, key: Key) LevelSt
/// A key while a helix prefix waits in text `t` (g m z Z [ ]): which-key's
/// own, else the prefix's, the leaf it runs remembered. True when taken here.
-fn prefixKey(p: *Pardes, t: *Text, root: bindings.Root, key: Key) bool {
+fn prefixKey(p: *Pardes, t: *Text, cur: TagState.Current, key: Key) bool {
+ const root = cur.root;
if (root != .register and key.cp == config.leader_help and !key.ctrl and !key.alt) {
TagState.openHelp(p, root, "");
return true;
}
- switch (levelKey(p, root, "", key)) {
+ // `"` and a register's verbs: Esc goes to rest (normal mode's would
+ // name the register, or leave the pane).
+ if (root == .register and hit(key, config.escape)) {
+ t.normal.clear();
+ return true;
+ }
+ switch (levelKey(p, root, cur.path, key)) {
.taken => return true,
.up => {
t.normal = .{};
+ // A register's verbs go back up to the registers (SPEC §9).
+ if (root == .register and cur.path.len > 0) {
+ t.normal.prefix = .register_prefix;
+ p.view().tag_state.hi = 0;
+ }
return true;
},
.take => |c| {
@@ -680,7 +746,15 @@ fn prefixKey(p: *Pardes, t: *Text, root: bindings.Root, key: Key) bool {
.pass => {
if (!key.ctrl and !key.alt and key.cp >= 0x20 and key.cp < 0x7f) {
const k: u8 = @intCast(key.cp);
- if (bindings.nodeAt(root, &.{k}) != null) TagState.ran(p.view(), root, "", k);
+ var buf: [2]u8 = .{ 0, k };
+ if (cur.path.len > 0) buf[0] = cur.path[0];
+ const here = if (cur.path.len > 0) buf[0..2] else buf[1..2];
+ if (bindings.nodeAt(root, here) != null) TagState.ran(p.view(), root, cur.path, k);
+ // A register named: its verbs, rolled, the cursor afresh.
+ if (root == .register) {
+ p.view().tag_state.hi = 0;
+ p.view().tag_state.unrolled = false;
+ }
}
return false;
},
@@ -786,7 +860,7 @@ test "Del from a key asks which neighbour takes the rows; nothing else asks" {
// A word that is not a side closes nothing.
try std.testing.expect(p.executeBuiltinLine(again, "Del x"));
- try std.testing.expectEqualStrings("Del: takes k, j or nothing", p.panes[again].?.msg[0..p.panes[again].?.msg_len]);
+ try std.testing.expectEqualStrings("Del: takes k, j or nothing", p.messages.saidBy(p.panes[again].?));
try std.testing.expect(p.panes[again] != null);
// DelAbove is Del k, and a line that is not a key never asks.
try std.testing.expect(p.executeBuiltinLine(again, "DelAbove"));
diff --git a/core/layout.zig b/core/layout.zig
index c2f0f96c..c0d21d6d 100644
--- a/core/layout.zig
+++ b/core/layout.zig
@@ -613,7 +613,7 @@ pub fn minRows(p: *Pardes, id: usize) u16 {
pub fn minimaFit(p: *Pardes) bool {
const v = p.view();
compute(p);
- const avail = v.screen_h -| (p.topBarHeight() + columnBarHeight(p));
+ const avail = v.screen_h -| (p.topBarHeight() + columnBarHeight(p) + noticeRowHeight(p));
for (0..p.view().ncol) |c| {
if (v.cols[c].n < 2) continue;
var need: u32 = 0;
@@ -647,7 +647,7 @@ pub fn shareColumn(p: *Pardes, c: usize) bool {
compute(p);
const n = v.cols[c].n;
if (n == 0) return false;
- const avail = v.screen_h -| (p.topBarHeight() + columnBarHeight(p));
+ const avail = v.screen_h -| (p.topBarHeight() + columnBarHeight(p) + noticeRowHeight(p));
var mins: [MAX_PANES]u16 = undefined;
var need: u32 = 0;
for (v.cols[c].panes[0..n], 0..) |k, i| {
@@ -1372,7 +1372,8 @@ pub fn expandedNeighbor(p: *const Pardes, col: usize, index: usize, side: enum {
fn computeCollapsedColumn(p: *Pardes, c: usize, x: u16, width: u16, folded: usize) void {
const v = p.view();
var y: u16 = p.topBarHeight() + columnBarHeight(p);
- const available = v.screen_h -| y;
+ const bottom = v.screen_h -| noticeRowHeight(p);
+ const available = bottom -| y;
var expanded_left: usize = 0;
var weight: f32 = 0;
for (v.cols[c].panes[0..p.view().cols[c].n]) |id| if (p.panes[id]) |pane| {
@@ -1386,7 +1387,7 @@ fn computeCollapsedColumn(p: *Pardes, c: usize, x: u16, width: u16, folded: usiz
var folded_left = folded;
for (v.cols[c].panes[0..p.view().cols[c].n]) |id| {
const pane = p.panes[id] orelse continue;
- const room = v.screen_h -| y;
+ const room = bottom -| y;
const height: u16 = if (pane.collapsed) blk: {
folded_left -= 1;
break :blk @min(room, BOX_H);
@@ -1440,7 +1441,8 @@ pub fn compute(p: *Pardes) void {
var y: u16 = p.topBarHeight() + columnBarHeight(p);
const top = y;
- const avail_h = v.screen_h -| y;
+ const bottom = v.screen_h -| noticeRowHeight(p);
+ const avail_h = bottom -| y;
var hs: [MAX_PANES]u16 = undefined;
const n = v.cols[c].n;
for (0..n) |k| {
@@ -1451,7 +1453,7 @@ pub fn compute(p: *Pardes) void {
};
const lastk = k + 1 == n;
const fh = @as(f32, @floatFromInt(avail_h)) * pane.vweight / vsum;
- const room = v.screen_h -| y;
+ const room = bottom -| y;
hs[k] = if (lastk) room else @min(room, @max(1, @as(u16, @intFromFloat(@round(fh)))));
y +|= hs[k];
}
@@ -1515,6 +1517,14 @@ pub fn topBarHeight(p: *const Pardes) u16 {
return TOPBAR_H;
}
+/// The notice row's height: one row at the window's foot (pick-ui SPEC
+/// §10.3), the index of the live messages, under every column; none on a
+/// screen too short for it, as the column tags have none.
+pub fn noticeRowHeight(p: *const Pardes) u16 {
+ if (p.view().screen_h < 3) return 0;
+ return 1;
+}
+
/// The column tags' height: one row, as acme's (cols.c:244, colresize,
/// gives a column tag one font height); a newline in one is a space
/// (tagline.flattenHeaders).
@@ -1712,14 +1722,14 @@ test "collapse transfers height upward and restores the original layout" {
toggleCollapse(p, 1);
try std.testing.expectEqual(@as(u16, 1), p.view().rects[1].h);
try std.testing.expectEqual(@as(f32, @floatFromInt(original[1].h)), p.panes[1].?.vweight);
- try std.testing.expectEqual(p.view().screen_h, p.view().rects[2].y + p.view().rects[2].h);
+ try std.testing.expectEqual(p.view().screen_h - noticeRowHeight(p), p.view().rects[2].y + p.view().rects[2].h);
try std.testing.expect(p.view().rects[0].h > original[0].h);
try std.testing.expectEqualDeep(original[2], p.view().rects[2]);
toggleCollapse(p, 1);
try std.testing.expectEqualDeep(original, p.view().rects);
toggleCollapse(p, 2);
try std.testing.expectEqual(@as(u16, 1), p.view().rects[2].h);
- try std.testing.expectEqual(p.view().screen_h, p.view().rects[2].y + p.view().rects[2].h);
+ try std.testing.expectEqual(p.view().screen_h - noticeRowHeight(p), p.view().rects[2].y + p.view().rects[2].h);
}
test "collapse changes only one neighbor at the top middle and bottom" {
@@ -1837,7 +1847,7 @@ test "collapse single and all panes leave unused column space" {
try std.testing.expectEqual(p.view().rects[0].y + 1, p.view().rects[1].y);
try std.testing.expect(p.view().rects[1].y + 1 < p.view().screen_h);
toggleCollapse(p, 0);
- try std.testing.expectEqual(p.view().screen_h - 1, p.view().rects[1].y);
+ try std.testing.expectEqual(p.view().screen_h - noticeRowHeight(p) - 1, p.view().rects[1].y);
}
test "collapse survives tiny resizes" {
@@ -1898,7 +1908,7 @@ test "collapse dump restores folded state and retained expansion weight" {
try std.testing.expectEqual(@as(f32, @floatFromInt(original_height)), restored.panes[0].?.vweight);
try std.testing.expectEqual(@as(u16, 1), restored.view().rects[0].h);
toggleCollapse(restored, 0);
- try std.testing.expectEqual(restored.view().screen_h - restored.view().rects[0].y, restored.view().rects[0].h);
+ try std.testing.expectEqual(restored.view().screen_h - noticeRowHeight(restored) - restored.view().rects[0].y, restored.view().rects[0].h);
}
test "column reorder moves only crossed state and preserves weights" {
@@ -2217,6 +2227,8 @@ test "a new pane goes below the rows a pane's text takes, a wrapped line's each
const dir = buf[0..try tmp.dir.realPath(io, &buf)];
const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 60, .rows = 40 });
defer p.deinit();
+ // About a jump opening a pane: `Jumps new-pane` (SPEC §6.6).
+ p.settings.jumps = .@"new-pane";
p.settings.wrap = true;
// Two lines of 400 bytes: seven rows each at this width.
const long = &@as([400]u8, @splat('a'));
diff --git a/core/look.zig b/core/look.zig
index d7dd7690..21043250 100644
--- a/core/look.zig
+++ b/core/look.zig
@@ -1538,7 +1538,6 @@ fn walk(p: *Pardes, from: usize, path: []const u8, at: Spot) Landed {
}
const into = if (reads) from else Trail.readerOf(p, src) orelse {
const free = openNew(p, from, path, at, .reader) orelse return .none;
- p.panes[free].?.trail = Trail.reader(src.serial, path, at);
return .{ .opened = free };
};
_ = Trail.step(p, into, path, at) catch |err| {
@@ -1566,6 +1565,9 @@ fn openNew(p: *Pardes, from: usize, path: []const u8, at: Spot, kind: layout.New
return null;
};
nt.body.cur_col = columnOn(nt, nt.body.cur_row, at.col);
+ // A reader's walk (its owner's word, its place) is in its tag before
+ // it is placed: the rows it is given are for the tag it shows.
+ if (kind == .reader) nt.trail = Trail.reader(p.panes[from].?.serial, path, at);
const failures = p.fs.failures;
layout.placeNew(p, from, from, free, kind);
// Refused a place: that is the look's one failure, not a miss of its
@@ -2021,6 +2023,8 @@ test "a Look that opens a file in a pane of its own puts its line half the body'
const dir = buf[0..try tmp.dir.realPath(io, &buf)];
const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 60, .rows = 40 });
defer p.deinit();
+ // About a jump opening a pane: `Jumps new-pane` (SPEC §6.6).
+ p.settings.jumps = .@"new-pane";
p.settings.wrap = true;
_ = try p.setTestFile("x\n");
var line: [4200]u8 = undefined;
@@ -2214,6 +2218,8 @@ test "Look copies its operand before releasing pointer selection storage" {
test "a Look whose column is past its line's end lands at the end, however big; a line past the file's is a miss" {
const p = try Pardes.init(std.testing.allocator, .{ .cols = 60, .rows = 12 });
defer p.deinit();
+ // About a jump opening a pane: `Jumps new-pane` (SPEC §6.6).
+ p.settings.jumps = .@"new-pane";
const pane = try p.setTestFile("alpha\n\tbeta\n");
// Up to 2026-11-23 a column past i32 panicked the session (`@intCast`
// in focusPaneLine): any text a B3 or Look takes, a server's row.
@@ -2306,6 +2312,8 @@ test "Look on each kind of diff line opens the new file at the line it names" {
defer fx.tmp.cleanup();
const p = try Pardes.init(std.testing.allocator, .{ .cols = 100, .rows = 30 });
defer p.deinit();
+ // About a jump opening a pane: `Jumps new-pane` (SPEC §6.6).
+ p.settings.jumps = .@"new-pane";
const pane = try fx.open(p, diff_text);
DiffFixture.click(p, pane, 4); // @@: the hunk's first new line
@@ -2358,6 +2366,8 @@ test "Look on plain diff -u output: names as written, timestamps cut, next to th
defer fx.tmp.cleanup();
const p = try Pardes.init(std.testing.allocator, .{ .cols = 100, .rows = 30 });
defer p.deinit();
+ // About a jump opening a pane: `Jumps new-pane` (SPEC §6.6).
+ p.settings.jumps = .@"new-pane";
const pane = try fx.open(p, diff_text);
DiffFixture.click(p, pane, 4);
try expectAt(p, "/new/x.zig", 2);
@@ -2385,6 +2395,8 @@ test "Look on a diff: headers and a hunk line's prefix are the whole line, hover
defer fx.tmp.cleanup();
const p = try Pardes.init(std.testing.allocator, .{ .cols = 100, .rows = 30 });
defer p.deinit();
+ // About a jump opening a pane: `Jumps new-pane` (SPEC §6.6).
+ p.settings.jumps = .@"new-pane";
const pane = try fx.open(p, diff_text);
pane.tag_expanded = false;
// `word`: what the pointer there expands to when it is not the whole
@@ -2543,6 +2555,8 @@ test "every entry point to Look takes one expansion: a diff line and a file:12:5
for (cases) |case| {
const p = try Pardes.init(std.testing.allocator, .{ .cols = 100, .rows = 30 });
defer p.deinit();
+ // About a jump opening a pane: `Jumps new-pane` (SPEC §6.6).
+ p.settings.jumps = .@"new-pane";
const pane = try fx.open(p, case.text);
p.gpa.free(pane.file.?.path);
pane.file.?.path = try std.Io.Dir.path.join(p.gpa, &.{ fx.dir, case.name });
@@ -2687,6 +2701,8 @@ test "Incl's directories find a name found nowhere else, <name> too; bare Incl l
const root = dir_buf[0..try tmp.dir.realPath(std.testing.io, &dir_buf)];
const p = try Pardes.init(std.testing.allocator, .{ .cols = 100, .rows = 30 });
defer p.deinit();
+ // About a jump opening a pane: `Jumps new-pane` (SPEC §6.6).
+ p.settings.jumps = .@"new-pane";
// C's two by default.
try std.testing.expectEqualStrings("/usr/include", p.incl.items[0]);
const pane = try p.setTestFile("#include <pardes_incl_probe.h>\n");
@@ -2703,7 +2719,7 @@ test "Incl's directories find a name found nowhere else, <name> too; bare Incl l
}
// Bare, it lists them.
try std.testing.expect(p.executeBuiltinLine(0, "Incl"));
- try std.testing.expect(std.mem.indexOf(u8, pane.msg[0..pane.msg_len], "/inc") != null);
+ try std.testing.expect(std.mem.indexOf(u8, p.messages.saidBy(pane), "/inc") != null);
// A dump keeps them.
try pardes.dump.dumpState(p);
const restored = try pardes.dump.restore(p, p.dump_out.?, "/tmp/pardes.dump.zon");
@@ -2788,6 +2804,8 @@ test "Look on a diff under each git prefix opens the repository's file, and a re
defer fx.tmp.cleanup();
const p = try Pardes.init(std.testing.allocator, .{ .cols = 100, .rows = 30 });
defer p.deinit();
+ // About a jump opening a pane: `Jumps new-pane` (SPEC §6.6).
+ p.settings.jumps = .@"new-pane";
const pane = try fx.open(p, c.text);
DiffFixture.click(p, pane, 6); // `two`, a context line: new line 2
try std.testing.expect(!p.look_missed);
@@ -2821,6 +2839,8 @@ test "Look on a diff line is the look of the address it names, selected by hand:
for (0..2) |way| {
const p = try Pardes.init(std.testing.allocator, .{ .cols = 100, .rows = 30 });
defer p.deinit();
+ // About a jump opening a pane: `Jumps new-pane` (SPEC §6.6).
+ p.settings.jumps = .@"new-pane";
const pane = try cache.open(p, patch);
// The checkout's file, opened by a look from the diff pane.
lookAt(p, 0, cargo);
@@ -2841,7 +2861,7 @@ test "Look on a diff line is the look of the address it names, selected by hand:
.active_path = try std.testing.allocator.dupe(u8, if (shown.file) |f| f.path else ""),
.row = shown.body.cur_row,
.missed = p.look_missed,
- .msg = try std.testing.allocator.dupe(u8, pane.msg[0..pane.msg_len]),
+ .msg = try std.testing.allocator.dupe(u8, p.messages.saidBy(pane)),
.panes = n,
};
}
@@ -2869,6 +2889,8 @@ test "Plumb: a look sends what it looks at, the rules written first: a rule's wo
const pic = try std.fmt.bufPrint(&pic_buf, "{s}/pic.svg", .{root});
const p = try Pardes.init(std.testing.allocator, .{ .cols = 100, .rows = 30 });
defer p.deinit();
+ // About a jump opening a pane: `Jumps new-pane` (SPEC §6.6).
+ p.settings.jumps = .@"new-pane";
const pane = try p.setTestFile("see https://ziglang.org here\n");
// The defaults: a URL to the web port, the host's opener; the hover
// asks resolve, as before.
@@ -2887,7 +2909,7 @@ test "Plumb: a look sends what it looks at, the rules written first: a rule's wo
lookAt(p, 0, pic);
try std.testing.expectEqual(@as(usize, 0), p.view().active);
var said_buf: [4300]u8 = undefined;
- try std.testing.expectEqualStrings(try std.fmt.bufPrint(&said_buf, "svg {s}", .{pic}), pane.msg[0..pane.msg_len]);
+ try std.testing.expectEqualStrings(try std.fmt.bufPrint(&said_buf, "svg {s}", .{pic}), p.messages.saidBy(pane));
// A name open in a pane is focused, never sent.
p.look_text = true;
lookAt(p, 0, pic);
@@ -2898,7 +2920,7 @@ test "Plumb: a look sends what it looks at, the rules written first: a rule's wo
p.setMessage(.at(0), "before");
lookAt(p, 0, pic);
try std.testing.expectEqual(opened, p.view().active);
- try std.testing.expectEqualStrings("before", pane.msg[0..pane.msg_len]);
+ try std.testing.expectEqualStrings("before", p.messages.saidBy(pane));
// With no web rule, a URL is a word Look searches for.
p.view().active = 0;
try std.testing.expect(Plumb.apply(p, false, "plumb/rules", "type is text\narg isfile $data\nplumb to edit\n") == null);
diff --git a/core/lsp/Ask.zig b/core/lsp/Ask.zig
index 29d36f0a..312743d0 100644
--- a/core/lsp/Ask.zig
+++ b/core/lsp/Ask.zig
@@ -18,6 +18,7 @@ const memory = @import("../memory.zig");
const Pardes = pardes.Pardes;
const Pane = panes.Pane;
const Effect = pardes.Effect;
+const TagState = @import("../TagState.zig");
const Ask = @This();
@@ -38,6 +39,12 @@ wait: ?struct {
row: i32 = 0,
col: i32 = 0,
} = null,
+/// A hover asked from the keyboard (where the walk is on), drawn as ghost
+/// lines under the line it was asked at in its own body (pick-ui SPEC §3.5,
+/// the coordinator's R3: never written): until Esc, an edit of that text,
+/// or the next hover. Its first `hover_max` bytes.
+hover: ?struct { serial: u32, row: i32, revision: u32, text: Effect.Buf(hover_max) } = null,
+pub const hover_max = 1024;
const TAG_TEXT_INSET = pardes.TAG_TEXT_INSET;
pub fn lspRequest(p: *Pardes, asked: usize, kind: lsp.Kind, arg_in: []const u8) void {
@@ -247,6 +254,48 @@ fn applyLspEdits(p: *Pardes, pane: *Pane, revision: u32, edits: []const LspEdit)
return true;
}
+/// Rename typed in pane `id`'s own tag (SPEC §3.5): the field the name
+/// under its caret, which the body shows renamed as it is typed
+/// (body_layer.renameGhosts) until Enter asks the server, or Esc.
+pub fn openRename(p: *Pardes, id: usize) void {
+ const pane = p.panes[id] orelse return;
+ const old = renamedWord(pane) orelse return p.reportFailure(id, "Rename: nothing here to rename");
+ TagState.toRest(p);
+ const s = &p.view().tag_state;
+ s.kind = .rename;
+ s.host = pane.serial;
+ s.field.set(old);
+ s.previewing.set(id);
+}
+
+/// A key in Rename's field: Enter asks the server to rename to it (a name
+/// the same as the old is no question), Esc (the tag's) puts it away.
+pub fn renameKey(p: *Pardes, key: pardes.Key) void {
+ const s = &p.view().tag_state;
+ if (!key.ctrl and !key.alt and key.cp == pardes.Key.enter) {
+ const id = TagState.hostOf(p) orelse return TagState.toRest(p);
+ var name: Effect.Buf(128) = .{};
+ const typed = std.mem.trim(u8, s.field.text(), " ");
+ const same = std.mem.eql(u8, typed, renamedWord(p.panes[id].?) orelse "");
+ if (typed.len <= 128) name = .from(typed);
+ TagState.toRest(p);
+ if (same) return;
+ if (typed.len > 128) return p.reportFailure(id, "Rename: a name is at most 128 bytes");
+ return lspRequest(p, id, .rename, name.slice());
+ }
+ _ = s.field.key(key);
+}
+
+/// The name under pane `pane`'s caret, which a Rename renames.
+pub fn renamedWord(pane: *const Pane) ?[]const u8 {
+ const line = panes.File.sourceLine(pane, pane.body.cur_row);
+ var lo: usize = @min(@as(usize, @intCast(@max(0, pane.body.cur_col))), line.len);
+ var hi = lo;
+ while (lo > 0 and (std.ascii.isAlphanumeric(line[lo - 1]) or line[lo - 1] == '_')) lo -= 1;
+ while (hi < line.len and (std.ascii.isAlphanumeric(line[hi]) or line[hi] == '_')) hi += 1;
+ return if (hi > lo) line[lo..hi] else null;
+}
+
/// The builtin word that asks `kind`, for what it says.
fn lspWord(kind: lsp.Kind) []const u8 {
return switch (kind) {
@@ -333,6 +382,14 @@ pub fn lspResponse(p: *Pardes, id: u32, response: ?[]const u8) void {
return;
}
+ // A hover asked from the keyboard: ghost lines in its own body, no
+ // +Hover pane (SPEC §3.5).
+ if (w.kind == .hover and pardes.Pick.asked(p)) {
+ var cut = @min(rows.len, hover_max);
+ while (cut < rows.len and cut > 0 and rows[cut] & 0xC0 == 0x80) cut -= 1;
+ p.lsp_ask.hover = .{ .serial = pane.serial, .row = w.row, .revision = w.revision, .text = .from(rows[0..cut]) };
+ return;
+ }
const from: panes.Output.Origin = .{ .query = w.kind };
const nrows = std.mem.count(u8, rows, "\n");
if ((panes.Output.traits(from).jumps or w.kind == .diagnostics) and nrows == 1) {
@@ -366,6 +423,12 @@ pub fn lspResponse(p: *Pardes, id: u32, response: ?[]const u8) void {
return;
}
+ // Symbols and diagnostics asked from the keyboard, where jumps walk: a
+ // picker in the tag of the pane its Enter lands in (Pick.zig).
+ if (pardes.Pick.asked(p)) switch (w.kind) {
+ .document_symbols, .workspace_symbols, .diagnostics, .workspace_diagnostics => return pardes.Pick.open(p, asked, .list, lspWord(w.kind), "", rows),
+ else => {},
+ };
// The lists of places: into the asking text's query pane (made or
// reused), line 1 their word, the places in that text its places.
const listed: ?panes.Query.Source = switch (w.kind) {
@@ -530,13 +593,15 @@ test "Def and Refs are a speaking file's tag words; gd, gr and a 2-1 chord all r
// 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]);
+ try std.testing.expectEqualStrings("Def: no gamma in this file", p.messages.saidBy(pane));
}
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();
+ // About a jump opening a pane: `Jumps new-pane` (SPEC §6.6).
+ p.settings.jumps = .@"new-pane";
_ = try p.setTestFile("fn work() {}\n");
const source = p.panes[0].?;
p.lspRequest(0, .callstack, "");
@@ -580,7 +645,7 @@ test "Callers with one answer jumps to it and says where, in a msg" {
const wait = p.lsp_ask.wait.?;
p.update(.{ .lsp_resp = .{ .id = wait.id, .rows = "/test.txt:2:10 b\n" } });
try std.testing.expectEqual(@as(i32, 1), pane.body.cur_row);
- try std.testing.expectEqualStrings("Callers: the one, /test.txt:2:10", pane.msg[0..pane.msg_len]);
+ try std.testing.expectEqualStrings("Callers: the one, /test.txt:2:10", p.messages.saidBy(pane));
}
test "a Rename the language server finds nothing for says so, and changes nothing" {
@@ -591,7 +656,7 @@ test "a Rename the language server finds nothing for says so, and changes nothin
p.lspRequest(p.view().active, .rename, "renamed");
const wait = p.lsp_ask.wait.?;
p.update(.{ .lsp_resp = .{ .id = wait.id, .rows = "" } });
- try std.testing.expectEqualStrings("Rename: nothing here to rename", pane.msg[0..pane.msg_len]);
+ try std.testing.expectEqualStrings("Rename: nothing here to rename", p.messages.saidBy(pane));
try std.testing.expectEqualStrings("const value=1;\n", pane.file.?.content);
}
@@ -620,3 +685,95 @@ test "LSP failure clears only its matching wait without completion indentation"
try std.testing.expectEqualStrings("x ", pane.file.?.content);
try std.testing.expectEqual(@as(i32, 4), pane.body.cur_col);
}
+
+test "a hover asked from the keyboard is ghost lines under the line it was asked at, drawn and never written, no +Hover pane; Esc takes them away" {
+ if (!lsp.supports.contains(.hover)) return error.SkipZigTest;
+ const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 80, .rows = 20 });
+ defer p.deinit();
+ const pane = try p.setTestFile("one\ntwo\nthree\nfour\n");
+ const id = p.view().active;
+ p.settings.jumps = .walk;
+ while (p.nextEffect()) |_| {}
+ pane.focus = .body;
+ pane.body.cur_row = 1;
+ var npanes: usize = 0;
+ for (p.panes) |slot| npanes += @intFromBool(slot != null);
+ p.lspRequest(id, .hover, "");
+ while (p.nextEffect()) |_| {}
+ lspResponse(p, p.lsp_ask.seq, "pub fn add(a: i32) i32\nadds them\n");
+ var now: usize = 0;
+ for (p.panes) |slot| now += @intFromBool(slot != null);
+ try std.testing.expectEqual(npanes, now);
+ var frame = std.heap.ArenaAllocator.init(std.testing.allocator);
+ defer frame.deinit();
+ p.sync();
+ var s = try p.render(frame.allocator());
+ const body = s.region(.body, id).?.rect;
+ var buf: [256]u8 = undefined;
+ try std.testing.expect(std.mem.indexOf(u8, rowText(s, body.x, body.y + 1, &buf), "two") != null);
+ try std.testing.expect(std.mem.indexOf(u8, rowText(s, body.x, body.y + 2, &buf), "pub fn add(a: i32) i32") != null);
+ try std.testing.expect(std.mem.indexOf(u8, rowText(s, body.x, body.y + 3, &buf), "adds them") != null);
+ try std.testing.expect(std.mem.indexOf(u8, rowText(s, body.x, body.y + 4, &buf), "three") != null);
+ try std.testing.expectEqualStrings("one\ntwo\nthree\nfour\n", pane.file.?.content);
+ p.update(.{ .key = .{ .cp = pardes.Key.escape } });
+ try std.testing.expect(p.lsp_ask.hover == null);
+ try std.testing.expectEqual(id, p.view().active);
+ _ = frame.reset(.retain_capacity);
+ s = try p.render(frame.allocator());
+ try std.testing.expect(std.mem.indexOf(u8, rowText(s, body.x, body.y + 2, &buf), "three") != null);
+}
+
+/// Grid row `y` of `s` from column `x`, as text.
+fn rowText(s: *const pardes.Surface, x: u16, y: u16, buf: []u8) []const u8 {
+ var n: usize = 0;
+ for (x..s.cols) |col| {
+ const g = s.cells[@as(usize, y) * s.cols + col].grapheme();
+ if (n + g.len > buf.len) break;
+ @memcpy(buf[n..][0..g.len], g);
+ n += g.len;
+ }
+ return buf[0..n];
+}
+
+test "SPC l r types the new name in the pane's own tag, the body showing each place in view renamed as it is typed, never written; Enter asks the server for it, Esc puts it away" {
+ if (!lsp.supports.contains(.rename)) return error.SkipZigTest;
+ const Key = pardes.Key;
+ const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 80, .rows = 20 });
+ defer p.deinit();
+ const pane = try p.setTestFile("const best = 1;\nconst b = best + best;\nconst bestow = 2;\n");
+ const id = p.view().active;
+ p.settings.jumps = .walk;
+ pane.focus = .body;
+ pane.body.cur_row = 0;
+ pane.body.cur_col = 7;
+ for (" lr") |c| p.update(.{ .key = .{ .cp = c } });
+ const s = &p.view().tag_state;
+ try std.testing.expectEqual(TagState.Kind.rename, s.kind);
+ try std.testing.expectEqualStrings("best", s.field.text());
+ for ("er") |c| p.update(.{ .key = .{ .cp = c } });
+ var frame = std.heap.ArenaAllocator.init(std.testing.allocator);
+ defer frame.deinit();
+ const a = frame.allocator();
+ try std.testing.expect(std.mem.indexOf(u8, try pardes.tagline.tagText(p, a, pane), " Rename best → bester") != null);
+ p.sync();
+ const sf = try p.render(a);
+ const body = sf.region(.body, id).?.rect;
+ var buf: [256]u8 = undefined;
+ // Each `best` in view struck and followed by the new name; `bestow` is
+ // another word.
+ try std.testing.expect(std.mem.indexOf(u8, rowText(sf, body.x, body.y, &buf), "const bestbester = 1;") != null);
+ try std.testing.expect(std.mem.indexOf(u8, rowText(sf, body.x, body.y + 1, &buf), "const b = bestbester + bestbester;") != null);
+ try std.testing.expect(std.mem.indexOf(u8, rowText(sf, body.x, body.y + 2, &buf), "const bestow = 2;") != null);
+ try std.testing.expectEqualStrings("const best = 1;\nconst b = best + best;\nconst bestow = 2;\n", pane.file.?.content);
+ // Enter: the server asked to rename it, the tag at rest.
+ while (p.nextEffect()) |_| {}
+ p.update(.{ .key = .{ .cp = Key.enter } });
+ try std.testing.expectEqual(TagState.Kind.rest, s.kind);
+ try std.testing.expectEqualStrings("bester", p.lsp_ask.wait.?.arg.slice());
+ // Esc from the field asks nothing.
+ p.lsp_ask.wait = null;
+ for (" lr") |c| p.update(.{ .key = .{ .cp = c } });
+ p.update(.{ .key = .{ .cp = Key.escape } });
+ try std.testing.expectEqual(TagState.Kind.rest, s.kind);
+ try std.testing.expect(p.lsp_ask.wait == null);
+}
diff --git a/core/mouse.zig b/core/mouse.zig
index f97bc39b..89a8c5c6 100644
--- a/core/mouse.zig
+++ b/core/mouse.zig
@@ -499,6 +499,17 @@ fn chordCutPaste(p: *Pardes, cut: bool) edit.Error!void {
pub fn handleMouse(p: *Pardes, event: Mouse) void {
const v = p.view();
+ // A click that gives the keyboard to another pane ends the level or
+ // typing state of the tag out of rest as Esc does, its text's prefix
+ // with it (SPEC §3.4.6: only the pane with the keyboard leaves rest);
+ // one in its band or its own tag keeps it.
+ const host = pardes.TagState.hostOf(p);
+ defer if (host) |was| if (v.active != was) {
+ const to = v.active;
+ v.active = was;
+ pardes.TagState.toRest(p);
+ v.active = to;
+ };
var m = event;
// A click goes somewhere else: the question it leaves unanswered is
// taken back, and the pane stays. A wheel only looks around.
@@ -581,6 +592,21 @@ pub fn handleMouse(p: *Pardes, event: Mouse) void {
v.hover_col = mcol;
v.hover_row = mrow;
+ // The notice row: the execute or the look button on a word there runs
+ // it or Looks at it, as on a header (a place a message names, its
+ // cause); nothing else happens on it.
+ const foot = layout.noticeRowHeight(p);
+ if (foot > 0 and mrow >= v.screen_h - foot and v.drag == .none and v.header_sweep == null and !v.header_drag) {
+ if (m.kind != .press or (m.button != config.exec_button and m.button != config.look_button)) return;
+ var buf: [pardes.Messages.notice_row_cap]u8 = undefined;
+ const row = pardes.Messages.noticeRow(p, layout.tagCapacity(p, v.screen_w -| TAG_TEXT_INSET) -| 1, &buf);
+ const col = Layer.columnAt(p, .notice_row, 0, v.pointer_tag_hit, false, 0) orelse (mcol -| TAG_TEXT_INSET);
+ const bounds = tagline.wordBoundsAtCol(row.text, panes.File.rawAtDisplay(p.settings.tab, row.text, col)) orelse return;
+ const word = p.scratch.allocator().dupe(u8, row.text[bounds.lo..bounds.hi]) catch |err| return p.reportError(.at(v.active), "notice row", err);
+ if (m.button == config.exec_button) _ = exec.execute(p, v.active, word) else exec.runBuiltin(p, config.look_cmd, v.active, "", word);
+ return;
+ }
+
const hovered = paneAt(p, mcol, mrow);
// any press that is NOT the execute+select chord abandons a pending
@@ -851,6 +877,13 @@ pub fn handleMouse(p: *Pardes, event: Mouse) void {
pane.scrollBy(p.settings.tab, if (m.button == config.look_button) local else -local);
} else if (edit.pointerTextSelection(p, id, mcol, mrow, m.body_hit, v.pointer_tag_hit)) |pointed| {
if (m.button == config.look_button) v.active = id;
+ // A word of a message's detail, read as it is drawn:
+ // run or looked at as a typed one would be.
+ if (pointed.ghost) |row| {
+ const arena = p.scratch.allocator();
+ const word = (body_layer.wordAt(p, arena, id, row, @intCast(@max(0, pointed.sel.c0))) catch return) orelse return;
+ return exec.runBuiltin(p, if (m.button == config.exec_button) config.exec_cmd else config.look_cmd, id, "", arena.dupe(u8, word) catch return);
+ }
pane.clearPointerSelection(@backingInt(m.button));
pane.sel[@backingInt(m.button)] = pointed.sel;
v.drag = .{
@@ -905,6 +938,18 @@ fn bandPress(p: *Pardes, button: Mouse.Button, point: BandPoint) void {
if (button != config.exec_button and button != config.look_button) return;
const word = (pardes.Band.wordAt(p, arena, point.id, point.line, point.col) catch return) orelse return;
const kept = arena.dupe(u8, word) catch return;
+ // A picker's band: B2 runs the word with the picker live (an act's word
+ // acts, Pick.execWord); B3 on a row lands on it.
+ if (v.tag_state.kind == .pick) {
+ if (button == config.exec_button) return exec.runBuiltin(p, config.exec_cmd, v.active, "", kept);
+ const band = (pardes.Band.of(p, arena, p.panes[point.id].?, point.id) catch return) orelse return;
+ const ln = band.line(arena, p.settings.tab, point.line) catch return;
+ for (ln.parts) |part| if (point.col >= part.col and point.col < part.col + part.width) {
+ pardes.TagState.point(p, part.row.index);
+ return pardes.Pick.landHere(p);
+ };
+ return;
+ }
pardes.TagState.toRest(p);
exec.runBuiltin(p, if (button == config.exec_button) config.exec_cmd else config.look_cmd, v.active, "", kept);
}
@@ -951,7 +996,7 @@ pub fn dragUpdate(p: *Pardes, mcol: u16, mrow: u16, body_hit: ?Mouse.BodyHit) vo
if (supplied.serial == pane.serial) s.body = supplied.place;
const mapped_hit = bodyHitForPane(p, s.id, supplied, true) orelse return;
pane.sel[b].c1 = @as(i32, mapped_hit.col) - config.GUTTER;
- pane.sel[b].r1 = @as(i32, mapped_hit.row) + tag_rows;
+ pane.sel[b].r1 = pane.textRow(mapped_hit.row) + tag_rows;
return;
};
// A sweep that began on the tag stays on it, on the tag line
@@ -976,9 +1021,9 @@ pub fn dragUpdate(p: *Pardes, mcol: u16, mrow: u16, body_hit: ?Mouse.BodyHit) vo
else if (mrow < body_y)
-1
else if (mrow >= body_y + body_h or
- // The pointer cannot leave the screen: at a bottom pane,
- // its last row is the edge.
- (body_y + body_h >= v.screen_h and mrow + 1 >= body_y + body_h))
+ // The pointer cannot leave the screen: at a bottom pane
+ // (over the notice row), its last row is the edge.
+ (body_y + body_h + layout.noticeRowHeight(p) >= v.screen_h and mrow + 1 >= body_y + body_h))
1
else
0;
@@ -987,7 +1032,7 @@ pub fn dragUpdate(p: *Pardes, mcol: u16, mrow: u16, body_hit: ?Mouse.BodyHit) vo
else if (body_h == 0)
0
else
- @as(i32, @min(@max(mrow, body_y), body_y + body_h - 1)) - @as(i32, body_y) + tag_rows;
+ pane.textRow(@as(i32, @min(@max(mrow, body_y), body_y + body_h - 1)) - @as(i32, body_y)) + tag_rows;
if (pane.sel[b].r1 < tag_rows) pane.sel[b].c1 += @as(i32, pane.tag_scroll);
}
},
@@ -1253,7 +1298,7 @@ fn dragRelease(p: *Pardes, button: Mouse.Button) void {
// (pick-ui SPEC §6.3): the one place B1 does more than
// select.
if (!dragged and tagline.trailClick(p, s.id, row, col, false)) return;
- if (if (dragged) null else tagline.onName(p.settings.tab, pane, row, col)) |at| {
+ if (if (dragged) null else tagline.onName(p, pane, row, col)) |at| {
tagline.draftName(p, pane, at);
} else if (tagline.tagOffsetAt(p, pane, row, col)) |cursor| {
pane.tag.cur_row = @intCast(cursor.row);
@@ -1588,12 +1633,12 @@ test "a chorded exec an event reader holds is told with its argument, and writte
const line = try std.fmt.bufPrint(&back, "M{s}", .{records[0][1..]});
try std.testing.expectEqual(ctlfs.Status.ok, th.call(p, .{ .tag = 3, .op = .write, .node = event, .handle = h, .data = line }).reply.status);
const pane = p.panes[0].?;
- try std.testing.expectEqualStrings("arg-text", pane.msg[0..pane.msg_len]);
+ try std.testing.expectEqualStrings("arg-text", p.messages.saidBy(pane));
// All three records written back as read, in one write or in three:
// the two after the first are its argument and where it came from,
// never commands of their own.
for ([_]bool{ true, false }) |together| {
- pane.msg_len = 0;
+ p.messages.live_len = 0;
var all: [256]u8 = undefined;
var w = std.Io.Writer.fixed(&all);
for (records) |r| try w.print("M{s}", .{r[1..]});
@@ -1603,7 +1648,7 @@ test "a chorded exec an event reader holds is told with its argument, and writte
var one: [80]u8 = undefined;
_ = th.call(p, .{ .tag = 6, .op = .write, .node = event, .handle = h, .data = try std.fmt.bufPrint(&one, "M{s}", .{r[1..]}) });
}
- try std.testing.expectEqualStrings("arg-text", pane.msg[0..pane.msg_len]);
+ try std.testing.expectEqualStrings("arg-text", p.messages.saidBy(pane));
try std.testing.expect(!th.logHas(p, "run "));
}
_ = th.call(p, .{ .tag = 4, .op = .release, .node = event, .handle = h });
diff --git a/core/ninep/ctl.zig b/core/ninep/ctl.zig
index 84f3ba6b..637999c2 100644
--- a/core/ninep/ctl.zig
+++ b/core/ninep/ctl.zig
@@ -1747,6 +1747,8 @@ test "a look whose pane is refused a place fails with that alone, not a missing
// A screen with rows for one pane only.
const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 80, .rows = 5 });
defer p.deinit();
+ // About a jump opening a pane: `Jumps new-pane` (SPEC §6.6).
+ p.settings.jumps = .@"new-pane";
while (p.nextEffect()) |_| {}
_ = try p.setTestFile("x\n");
while (p.nextEffect()) |_| {}
@@ -2055,7 +2057,7 @@ test "a language server question that finds nothing, cannot be answered, or is a
_ = wr(p, root_exec, "Recent\n");
const listed = p.paneBySerial(try std.fmt.parseInt(u32, std.mem.trimEnd(u8, rd(p, root_exec, 0, 64).bytes, "\n"), 10)).?;
p.lspRequest(listed, .incoming_calls, "");
- try testing.expect(std.mem.indexOf(u8, p.panes[listed].?.msg[0..p.panes[listed].?.msg_len], "Callers: only a file's pane asks") != null);
+ try testing.expect(std.mem.indexOf(u8, p.messages.saidBy(p.panes[listed].?), "Callers: only a file's pane asks") != null);
// Nothing found: Callers says so, and the waiting write hears it.
p.fs.late_failure_len = 0;
p.lspRequest(id, .incoming_calls, "");
@@ -2126,6 +2128,8 @@ test "with no pane at all, the root look opens its file and the root exec runs i
if (pardes.Term.ops == null) return error.SkipZigTest; // a command pane
const p = try withFile(testing.allocator, "x\n");
defer p.deinit();
+ // About a jump opening a pane: `Jumps new-pane` (SPEC §6.6).
+ p.settings.jumps = .@"new-pane";
var tmp = testing.tmpDir(.{});
defer tmp.cleanup();
try tmp.dir.writeFile(testing.io, .{ .sub_path = "f.txt", .data = "file\n" });
@@ -2264,7 +2268,7 @@ test "a column takes panes until their documented minimums fill it, not until no
const new = @backingInt(tree.TopFile.new);
while (call(p, .{ .tag = 1, .op = .open, .node = new }).reply.status == .ok) p.sync();
p.sync();
- const avail = p.view().screen_h - (p.topBarHeight() + layout.columnBarHeight(p));
+ const avail = p.view().screen_h - (p.topBarHeight() + layout.columnBarHeight(p) + layout.noticeRowHeight(p));
for (0..p.view().ncol) |c| {
var need: u32 = 0;
for (p.view().cols[c].panes[0..p.view().cols[c].n]) |k| need += layout.minRows(p, k);
@@ -2388,7 +2392,9 @@ test "a file changed on disk under unsaved edits is not reloaded: it says so, ge
pardes.panes.File.changed(p, 0, "three\n");
try testing.expectEqualStrings("two\nmine\n", f.content);
try testing.expect(f.revision != f.saved_revision);
- try testing.expect(th.logHas(p, "changed on disk (get reloads it, Save overwrites it)"));
+ // ...and asks, in its tag (Messages.waiting), which /log hears.
+ try testing.expect(p.messages.waiting(p.panes[0].?) != null);
+ try testing.expect(th.logHas(p, "changed on disk\n"));
var want: [32]u8 = undefined;
try testing.expect(th.logHas(p, try std.fmt.bufPrint(&want, "changed {d}\n", .{serial})));
// Exit and get still ask about the edits.
diff --git a/core/ninep/events.zig b/core/ninep/events.zig
index e18b5d96..fe9ec79a 100644
--- a/core/ninep/events.zig
+++ b/core/ninep/events.zig
@@ -1089,20 +1089,20 @@ test "writing an event record back performs the action it names" {
const w = wr(p, event, "FX0 10\n");
try testing.expectEqual(Status.ok, w.reply.status);
- try testing.expectEqualStrings("fs-ran", pane.msg[0..pane.msg_len]);
+ try testing.expectEqualStrings("fs-ran", p.messages.saidBy(pane));
- pane.msg_len = 0;
+ p.messages.live_len = 0;
try testing.expectEqual(Status.ok, wr(p, event, "FX0 10\nFX0 10\n").reply.status);
- try testing.expectEqualStrings("fs-ran", pane.msg[0..pane.msg_len]);
+ try testing.expectEqualStrings("fs-ran", p.messages.saidBy(pane));
// The last record needs no newline, as any line file's last line.
- pane.msg_len = 0;
+ p.messages.live_len = 0;
const bare = wr(p, event, "FX0 10");
try testing.expectEqual(Status.ok, bare.reply.status);
try testing.expectEqual(@as(u32, 6), bare.reply.written);
- try testing.expectEqualStrings("fs-ran", pane.msg[0..pane.msg_len]);
+ try testing.expectEqualStrings("fs-ran", p.messages.saidBy(pane));
- pane.msg_len = 0;
+ p.messages.live_len = 0;
for ([_][]const u8{
"FX0 10\nFQ0 1\n", // unknown type character
"FX0 999\n", // out of range
@@ -1111,7 +1111,7 @@ test "writing an event record back performs the action it names" {
"F\n",
}) |bad| {
try testing.expectEqual(E.INVAL, wr(p, event, bad).errno());
- try testing.expectEqual(@as(usize, 0), pane.msg_len);
+ try testing.expectEqual(@as(usize, 0), p.messages.saidBy(pane).len);
}
// A look written back sets what look reads back.
_ = wr(p, event, "FL0 3\n");
diff --git a/core/ninep/tree.zig b/core/ninep/tree.zig
index 01cfe297..4feb0153 100644
--- a/core/ninep/tree.zig
+++ b/core/ninep/tree.zig
@@ -2013,6 +2013,11 @@ test "random placements, refused or not, leave no pane under its tag and two row
const rows = r.intRangeAtMost(u16, 6, 40);
const p = try pardes.Pardes.init(testing.allocator, .{ .tty_only = true, .cols = r.intRangeAtMost(u16, 60, 240), .rows = rows });
defer p.deinit();
+ // Placements as a Look made them before the walk: `Jumps new-pane`
+ // (SPEC §6.6). Under the walk a step in place can wrap its tag in a
+ // column with no rows to give (seed 109): the trail's give-way,
+ // not a placement's refusal (Trail.lift lifts it when there are).
+ p.settings.jumps = .@"new-pane";
while (p.nextEffect()) |_| {}
_ = try p.setTestFile("x\n");
while (p.nextEffect()) |_| {}
diff --git a/core/normal.zig b/core/normal.zig
index 307f1296..e1af647d 100644
--- a/core/normal.zig
+++ b/core/normal.zig
@@ -259,7 +259,7 @@ fn objectJump(e: Editor, t: *Text, text: []const u8, range: modal.Selection, obj
const tree = nodeTree(e, t, text) orelse return;
var last = range;
for (0..count) |_| {
- const s = syntax.objectNext(tree.path, tree.root, tree.text, object, forward, tree.in(modal.selectionCursor(text, last))) orelse break;
+ const s = syntax.objectNext(tree.path, tree.root, tree.text, object, forward, tree.in(modal.selectionCursor(text, last)), null) orelse break;
const next: modal.Selection = .{ .anchor = tree.out(s.from, false), .head = tree.out(s.to, s.to > s.from) };
if (std.meta.eql(next, last)) break;
last = next;
@@ -1107,12 +1107,20 @@ pub fn textAction(e: Editor, t: *Text, a: modal.Normal.Action) edit.Error!void {
if (comptime Editor.lib) return;
// typed again by a macro, Esc is only helix's
if (e.p.macro.replaying > 0) return;
- // The first Esc clears a search's tints (pick-ui SPEC §7.3,
- // §10.4's first step); its word stays in the trail, dimmed.
- if (t.what == .body) if (t.pane()) |pane| if (pane.places.started and pane.places.provenance == .search) {
+ // At rest a thing at a time (pick-ui SPEC §10.4): a search's
+ // tints (its word stays in the trail, dimmed: §7.3), then the
+ // warnings and errors, then the selections (the primary kept);
+ // with none of them left, the previous pane.
+ if (e.p.panes[e.p.view().active]) |pane| if (t == &pane.body and (pane.places.pattern.len > 0 or pane.places.hits.items.len > 0)) {
pane.places.clear(e.p.gpa);
+ e.p.needs_frame = true;
return;
};
+ if (e.p.messages.retire(&.{ .warn, .@"error" }) > 0) return;
+ if (t.nsel > 0) {
+ t.nsel = 0;
+ return;
+ }
tagline.exitHeader(e.p); // out of a header too, as Shift-Esc
return exec.runBuiltin(e.p, .Last, e.p.view().active, "", null);
},
@@ -1335,7 +1343,7 @@ fn executeNormalAction(p: *Pardes, t: *Text, a: modal.Normal.Action) edit.Error!
.view_scroll_down => if (t.what == .body) return t.scrollViewMove(p.settings.tab, text, range, 1),
.view_scroll_up => if (t.what == .body) return t.scrollViewMove(p.settings.tab, text, range, -1),
// The next and the previous of the changes this view shows (jj.zig).
- .goto_change => if (@import("jj.zig").nextChange(p, pane, @intCast(@max(0, t.cur_row)), a.forward)) |line|
+ .goto_change => if (@import("jj.zig").nextChange(p, pane, @intCast(@max(0, t.cur_row)), a.forward, std.math.maxInt(usize))) |line|
return pointMove(p.settings.tab, t, text, range, modal.lineStartOffset(text, line)),
.goto_diagnostic, .goto_diagnostic_end => {
// Once a Diagnostics query fed them, the diagnostics are this
@@ -1408,7 +1416,9 @@ fn executeNormalAction(p: *Pardes, t: *Text, a: modal.Normal.Action) edit.Error!
const was = pane.places.current;
pane.places.step(p, pane, a.role == .search_next, a.count, t.select);
return Prompt.stepped(p, v.active, a.role == .search_next, was);
- } else
+ } else if (t.what == .body and panes.Pick.walkList(p, v.active, a.role == .search_next))
+ return
+ else
return searchStep(p.editor(), t, text, a.role == .search_next, a.count),
.goto_word => return startJump(p, pane, t),
.macro_record => {
diff --git a/core/panes.zig b/core/panes.zig
index e15ad180..e4ed3e9d 100644
--- a/core/panes.zig
+++ b/core/panes.zig
@@ -32,8 +32,8 @@ pub const Pane = struct {
/// it (views.zig). (The 9P server's part of `fs` says so in its type.)
pub const replica = .{
.local = .{ "pv", "pv_known" },
- .derived = .{ "band_rows", "wrap_line", "wrap_col", "wrap_pad", "wrap_n", "body_wrapped", "context_rows", "body_rows", "body_visible_rows", "context_row_limit", "geometry_key", "geometry_len", "top_skip", "notices", "pan" },
- .len = .{ .{ "msg", "msg_len" }, .{ "msg_older", "msg_older_len" }, .{ "question", "question_len" }, .{ "shell_tail", "shell_tail_len" }, .{ "sel_snap", "nsel_snap" } },
+ .derived = .{ "band_rows", "ghost_at", "ghost_rows", "wrap_line", "wrap_col", "wrap_pad", "wrap_n", "body_wrapped", "context_rows", "body_rows", "body_visible_rows", "context_row_limit", "geometry_key", "geometry_len", "top_skip", "notices", "pan" },
+ .len = .{ .{ "question", "question_len" }, .{ "shell_tail", "shell_tail_len" }, .{ "sel_snap", "nsel_snap" } },
// A picture's memory is its own allocator's (a dump loaded makes
// it there).
.alloc = .{ .{ "addon", "image" }, .{ "pdf", "image" }, .{ "terminal", "terminal" } },
@@ -243,8 +243,6 @@ pub const Pane = struct {
/// A question with its answers in it (`repl_choice`).
question: [96]u8 = undefined,
question_len: u8 = 0,
- /// The newest message says where an exec was sent: it is tinted.
- msg_sent: bool = false,
/// The revision an Exit or a Restore last warned this pane was modified
/// at, and which of them: only that word goes ahead on the warning
/// (builtins.zig warnModified).
@@ -357,32 +355,19 @@ pub const Pane = struct {
/// terminals only: the typed-text buffer standing in for shell rows
ovl: ?Text.EditBuffer = null,
tty_filter: bool = false,
- msg: [256]u8 = undefined,
- msg_len: u16 = 0,
- /// Where the newest message line is in its life.
- msg_life: MessageLife = .{},
- /// When it was said, in monotonic ms (Messages.expireUnattended).
- msg_said_ms: i64 = 0,
- /// The row (among the notice rows) the newest line holds for its life.
- msg_slot: u8 = 0,
- /// Earlier message lines still on screen, oldest first, each running its
- /// own life: a new message stacks under them instead of replacing them.
- msg_older: [message_stack]OlderMessage = undefined,
- msg_older_len: u8 = 0,
- /// The newest line is a builtin announcing itself in this step: what
- /// the step says next replaces it rather than stacking under it.
- msg_announcement: bool = false,
- /// The newest line is a status (progress, a server's state): the next
- /// line replaces it rather than stacking under it.
- msg_status: bool = false,
/// The transient lines this pane shows between its body and its tagline:
- /// a builtin's message, the pending leader chord, a prompt waiting for
- /// input. Rebuilt every frame from the state that owns each one, so a
+ /// a prompt waiting for input. Rebuilt every frame from the state that owns each one, so a
/// line that goes away is simply not added again and the rest close the
/// gap -- there is no second copy of the truth to fall out of step. The
/// body layer reserves exactly `len` rows for them, the way it already
/// reserves rows for sticky context headers.
notices: Notices = .{},
+ /// A message's detail as the body drawn last has it (body_layer.zig
+ /// messageGhosts): `ghost_rows` read-only rows after body row
+ /// `ghost_at` (its line's last), the rows below drawn that many lower.
+ /// The mouse reads it, so that a click lands on what is drawn under it.
+ ghost_at: u16 = 0,
+ ghost_rows: u16 = 0,
/// 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,
@@ -408,67 +393,14 @@ pub const Pane = struct {
/// that view's focus leaving the pane drops it.
prompt_view: u8 = 0,
- pub const MessagePhase = enum { shown, lingering };
- /// One message line's life: shown, or lingering after the key or click
- /// that dismissed it, `frame` frames of its linger gone.
- pub const MessageLife = struct {
- phase: MessagePhase = .shown,
- frame: u16 = 0,
- };
- /// 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 = .{},
- slot: u8 = 0,
-
- pub fn slice(line: *const OlderMessage) []const u8 {
- return line.text[0..line.len];
- }
- };
-
- /// Move the newest line onto the stack of older ones, dropping the oldest
- /// when it is full; the newest slot is left empty for what arrives.
- pub fn pushOlderMessage(pane: *Pane) void {
- if (pane.msg_older_len == message_stack) {
- std.mem.copyForwards(OlderMessage, pane.msg_older[0 .. message_stack - 1], pane.msg_older[1..]);
- pane.msg_older_len -= 1;
- }
- pane.msg_older[pane.msg_older_len] = .{ .text = pane.msg, .len = pane.msg_len, .life = pane.msg_life, .slot = pane.msg_slot };
- pane.msg_older_len += 1;
- pane.msg_len = 0;
- pane.msg_life = .{};
- }
-
- /// The first row no older line holds. A line keeps its row until it
- /// leaves, and a new one fills the first gap: nothing on screen moves.
- pub fn freeMessageSlot(pane: *const Pane) u8 {
- var used: u8 = 0;
- for (pane.msg_older[0..pane.msg_older_len]) |line| used |= @as(u8, 1) << @intCast(line.slot);
- var slot: u8 = 0;
- while (used & (@as(u8, 1) << @intCast(slot)) != 0) slot += 1;
- return slot;
- }
-
- pub fn removeOlderMessage(pane: *Pane, i: usize) void {
- std.mem.copyForwards(OlderMessage, pane.msg_older[i .. pane.msg_older_len - 1], pane.msg_older[i + 1 .. pane.msg_older_len]);
- pane.msg_older_len -= 1;
- }
-
pub const Notices = struct {
/// Painted bottom-up in this order, so a prompt keeps the row nearest
/// the tagline that it has always had, and its cursor with it.
- /// `older` is an earlier message line still on screen; `index` says
- /// which (`Pane.msg_older`).
- pub const Kind = enum { older, message, leader, prompt };
- pub const max = @typeInfo(Kind).@"enum".field_names.len - 1 + message_stack;
+ pub const Kind = enum { prompt };
+ pub const max = @typeInfo(Kind).@"enum".field_names.len;
kinds: [max]Kind = undefined,
- index: [max]u8 = @splat(0),
- /// Each band's row below the body's top: message lines keep theirs,
- /// so a band that leaves leaves a gap rather than moving the rest.
+ /// Each band's row below the body's top.
row: [max]u8 = @splat(0),
/// Where each band's chip starts, as an absolute grid column. A chip
/// is only as wide as its own text, so the rest of the row underneath
@@ -478,14 +410,9 @@ pub const Pane = struct {
/// A band on the next row after every band so far.
pub fn push(n: *Notices, kind: Kind) void {
- n.pushAt(kind, 0, n.span());
- }
-
- pub fn pushAt(n: *Notices, kind: Kind, index: u8, row: u8) void {
if (n.len >= max) return;
n.kinds[n.len] = kind;
- n.index[n.len] = index;
- n.row[n.len] = row;
+ n.row[n.len] = n.span();
n.left[n.len] = std.math.maxInt(u16);
n.len += 1;
}
@@ -637,6 +564,14 @@ pub const Pane = struct {
return @min(pane.scrolled_to orelse output, output);
}
+ /// Body row `vr` as drawn, as the row map counts it (`wrapAt`): a row
+ /// under a message's detail is `ghost_rows` higher there; a row of the
+ /// detail is the line's it explains.
+ pub fn textRow(pane: *const Pane, vr: i32) i32 {
+ if (pane.ghost_rows == 0 or vr <= pane.ghost_at) return vr;
+ return @max(pane.ghost_at, vr - pane.ghost_rows);
+ }
+
/// The line and byte a body row shows from.
pub fn wrapAt(pane: *Pane, tab: u16, vr: i32) struct { line: i32, at: i32, pad: i32 = 0 } {
File.geometry(tab, pane);
@@ -1131,6 +1066,23 @@ pub const Pane = struct {
pane.feedOutput(p, said.print("{s}exit {s}\r\n", .{ lead, code }));
pane.noteRun(p, "exit", code);
p.needs_frame = true;
+ // A failed run whose report names places (a compiler's
+ // `path:line:col: error: ...`): an error of this pane, the places
+ // its words, the rows after its first its detail (SPEC §10.2). Its
+ // last rows only: a report's places are at its end.
+ if (status != 0) if (pane.terminal) |state| report: {
+ const grid = Term.grid(state);
+ const first = grid.total -| 400;
+ const rows = Term.editRows(state, p.scratch.allocator(), first, grid.total - first) catch break :report;
+ var found: pardes.Messages.Said = .{};
+ if (pardes.Messages.readPlaces(&found, pane.cwdSlice(), rows) == 0) break :report;
+ var words: pardes.Kind.Buf(32) = .{};
+ const kept = pardes.Messages.say(p, .@"error", id, words.print("exit {s}", .{code}));
+ kept.places = found.places;
+ kept.places_len = found.places_len;
+ kept.detail = found.detail;
+ kept.detail_len = found.detail_len;
+ };
}
};
@@ -1144,6 +1096,7 @@ pub const Places = @import("Places.zig");
pub const Tables = @import("Tables.zig");
pub const Query = @import("Query.zig");
+pub const Pick = @import("Pick.zig");
pub const Dir = @import("Dir.zig");
@@ -1683,14 +1636,14 @@ test "owned cwd preserves long paths aliases and failed updates" {
const effects = p.effects_len;
exec.saveTo(p, 0, "file.txt");
try std.testing.expectEqual(effects, p.effects_len);
- try std.testing.expect(std.mem.indexOf(u8, pane.msg[0..pane.msg_len], "path too long") != null);
+ try std.testing.expect(std.mem.indexOf(u8, p.messages.saidBy(pane), "path too long") != null);
const current = pane.cwdSlice();
allocator.fail_index = allocator.alloc_index;
p.setCwd(.at(0), "/replacement");
try std.testing.expectEqual(current.ptr, pane.cwdSlice().ptr);
try std.testing.expectEqualStrings(&path, pane.cwdSlice());
- try std.testing.expect(std.mem.indexOf(u8, pane.msg[0..pane.msg_len], "out of memory") != null);
+ try std.testing.expect(std.mem.indexOf(u8, p.messages.saidBy(pane), "out of memory") != null);
allocator.fail_index = std.math.maxInt(usize);
p.setCwd(.at(0), "/replacement");
try std.testing.expectEqualStrings("/replacement", pane.cwdSlice());
@@ -1795,7 +1748,7 @@ test "owned cwd EOF failure retains the pane and Del retries its close" {
try std.testing.expectEqual(parent, p.panes[0].?);
try std.testing.expectEqual(parent, child.cwd.inherited);
try std.testing.expectEqual(Text.Mode.normal, parent.body.mode);
- try std.testing.expect(std.mem.indexOf(u8, parent.msg[0..parent.msg_len], "Del retries close") != null);
+ try std.testing.expect(std.mem.indexOf(u8, p.messages.saidBy(parent), "Del retries close") != null);
try std.testing.expectEqual(@as(usize, 0), p.effects_len);
allocator.fail_index = std.math.maxInt(usize);
try std.testing.expect(p.executeBuiltinLine(0, "Del"));
@@ -1995,3 +1948,35 @@ test "a Save prompt is typed on its own line in the notice band and leaves the t
p.update(.{ .key = .{ .cp = Key.escape } });
try std.testing.expect(pane.prompt == .none and pane.input.own == null);
}
+
+test "a command whose run fails naming places is an error of its pane, those places its words, and the pane's next run takes it away" {
+ if (pardes.Term.ops == null) return error.SkipZigTest; // a command pane's terminal
+ const gpa = std.testing.allocator;
+ const p = try Pardes.init(gpa, .{});
+ defer p.deinit();
+ while (p.nextEffect()) |_| {}
+ p.setCwd(.at(0), "/tmp/pardes-cmd");
+ _ = try pardes.Kind.open(p, 1, pardes.Kind.test_kind.of(p), "/tmp/pardes-cmd/pic.ppm", null);
+ const dst = exec.execute(p, 1, "zig build") orelse return error.NoCommandPane;
+ while (p.nextEffect()) |_| {}
+ const pane = p.panes[dst].?;
+ p.update(.{ .output = .{ .pane = .at(dst), .bytes = "core/pick.zig:25:12: error: expected 2 argument(s), found 3\r\n const best = rank(q, name, 3);\r\n" } });
+ p.update(.{ .exited = .{ .pane = .at(dst), .status = 1 } });
+ const said = p.messages.headline() orelse return error.NothingSaid;
+ try std.testing.expectEqual(pardes.Messages.Kind.@"error", said.kind);
+ try std.testing.expectEqualStrings("exit 1", said.text.slice());
+ try std.testing.expect(std.mem.endsWith(u8, said.src.slice(), " zig build"));
+ try std.testing.expectEqual(@as(u8, 1), said.places_len);
+ try std.testing.expectEqualStrings("/tmp/pardes-cmd/core/pick.zig", said.places[0].path.slice());
+ try std.testing.expectEqualStrings(" const best = rank(q, name, 3);", said.detail[0].slice());
+ var frame = std.heap.ArenaAllocator.init(gpa);
+ defer frame.deinit();
+ const s = try p.render(frame.allocator());
+ const r = p.view().rects[dst];
+ try std.testing.expectEqualStrings("\u{2717}", s.at(r.x + config.GUTTER - 1, p.tagTop(pane, r)).grapheme());
+ // Its next run: the last run's error goes.
+ p.update(.{ .eof = .{ .pane = .at(dst) } });
+ try std.testing.expectEqual(@as(?usize, dst), exec.execute(p, 1, "zig build"));
+ while (p.nextEffect()) |_| {}
+ try std.testing.expect(p.messages.headline() == null or p.messages.headline().?.kind != .@"error");
+}
diff --git a/core/replica.zig b/core/replica.zig
index 2a66cc3d..97cbaeee 100644
--- a/core/replica.zig
+++ b/core/replica.zig
@@ -5687,6 +5687,8 @@ test "a replica joined after a pane closed: the session's jump to it, its Panes
const gpa = std.testing.allocator;
const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, TestHost.host());
defer a.deinit();
+ // About a jump opening a pane: `Jumps new-pane` (SPEC §6.6).
+ a.core.settings.jumps = .@"new-pane";
// A file looked at and closed: a jump to it, Recent's, a closed pane.
var cwd: [std.Io.Dir.max_path_bytes]u8 = undefined;
var line: [std.Io.Dir.max_path_bytes + 32]u8 = undefined;
@@ -7335,6 +7337,7 @@ const may_wait = [_]Wait{
.{ .what = "*", .on = .shell, .stop = "pty_write", .why = "a key into a shell's program" },
// A file from the session's disk (P14).
.{ .what = "Look *", .on = .any, .stop = "resolve", .why = "a name looked for on the session's disk" },
+ .{ .what = "Look *", .on = .any, .stop = "read_file", .why = "a jump from a held pane (a kind's, a listing's) opens its reader on the file, read from the session's disk: a reading pane showing it is not focused (pick-ui SPEC §6.1)" },
.{ .what = "LookNext", .on = .any, .stop = "resolve", .why = "a Look's walk: each word asked of the disk" },
.{ .what = "LookPrev", .on = .any, .stop = "resolve", .why = "a Look's walk: each word asked of the disk" },
.{ .what = "Mini *", .on = .any, .stop = "resolve", .why = "a file opened by name, from the session's disk" },
@@ -7998,7 +8001,7 @@ test "a far client's drag in a kind's pane it grabbed, the pane since too short
}
for ([_]pardes.Event{
.{ .mouse = .{ .button = .left, .kind = .press, .col = col, .row = row } },
- .{ .resize = .{ .cols = 80, .rows = 4 } },
+ .{ .resize = .{ .cols = 80, .rows = 5 } },
.{ .mouse = .{ .button = .left, .kind = .drag, .col = col, .row = 30 } },
.{ .mouse = .{ .button = .left, .kind = .release, .col = col, .row = 30 } },
}) |ev| {
@@ -8395,7 +8398,7 @@ test "a far client's replay of a message its session's host stamped takes the se
r.confirm(u);
r.settle();
try agrees(a, r);
- try std.testing.expect(try shows(r.core(), "--:--:-- yanked x"));
+ try std.testing.expectEqualStrings("--:--:-- yanked x", r.core().messages.headline().?.text.slice());
}
// A script's `pty/run` in a shell (ninep/pty.zig): the open, the line, the
diff --git a/core/rollback.zig b/core/rollback.zig
index 2702594c..258a18d8 100644
--- a/core/rollback.zig
+++ b/core/rollback.zig
@@ -802,6 +802,8 @@ test "a rollback leaves the store and Recent as a speculation left them: they li
const gpa = e.allocator();
const p = try Pardes.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml", .image_allocator = gpa, .tree_sitter_allocator = gpa, .frame_allocator = gpa });
p.pump(.{}) catch {};
+ // About a jump opening a pane: `Jumps new-pane` (SPEC §6.6).
+ p.settings.jumps = .@"new-pane";
var line: [std.Io.Dir.max_path_bytes + 16]u8 = undefined;
p.update(.{ .command = try lookAt(&line, "build.zig.zon") });
p.update(.{ .command = "Del" });
diff --git a/core/root.zig b/core/root.zig
index 09486906..c086e987 100644
--- a/core/root.zig
+++ b/core/root.zig
@@ -92,6 +92,7 @@ pub const keys = @import("keys.zig");
pub const bindings = @import("bindings.zig");
pub const TagState = @import("TagState.zig");
pub const Band = @import("Band.zig");
+pub const Pick = @import("Pick.zig");
pub const Prompt = @import("Prompt.zig");
pub const Addon = @import("Addon.zig");
pub const dump = @import("dump.zig");
@@ -143,11 +144,15 @@ pub const TagKind = Layer.Kind;
/// too long for its width.
pub const MAX_TAG_ROWS = 8;
/// Panes, then columns, then the workspace bar, then each pane's notice
-/// bands: a band to a tag, however many lines it has; then each pane's
-/// rows unrolled under its tag (Band.zig).
-pub const MAX_TAG_LAYERS = BAND_LAYER_BASE + MAX_PANES;
-pub const NOTICE_LAYER_BASE = MAX_PANES + MAX_COLS + 1;
-pub const BAND_LAYER_BASE = NOTICE_LAYER_BASE + MAX_PANES * Pane.Notices.max;
+/// bands: a band to a tag, however many lines it has; then the rows
+/// unrolled under the one tag out of rest (Band.zig: a view has one, the
+/// keyboard's, SPEC §3.4). A frame makes many a temporary Surface, each
+/// with every layer: a layer to a pane here cost every frame 0.9%.
+pub const MAX_TAG_LAYERS = BAND_LAYER + 1;
+/// The notice row's layer, after the workspace tag's.
+pub const NOTICE_ROW_LAYER = MAX_PANES + MAX_COLS + 1;
+pub const NOTICE_LAYER_BASE = MAX_PANES + MAX_COLS + 2;
+pub const BAND_LAYER = NOTICE_LAYER_BASE + MAX_PANES * Pane.Notices.max;
/// Columns a session holds (each costs about 8 KB of state, a column tag
/// being most of it).
pub const MAX_COLS = 16;
@@ -415,6 +420,7 @@ test {
_ = @import("bindings.zig");
_ = @import("TagState.zig");
_ = @import("Band.zig");
+ _ = @import("Pick.zig");
_ = @import("Field.zig");
_ = @import("Prompt.zig");
_ = @import("Effect.zig");
@@ -636,7 +642,7 @@ const machine_lines = [_]struct { []const u8, usize, []const u8 }{
.{ "FrameStats.zig", 7, "a frame's clock and log: frames are local, never digested" },
.{ "Handover.zig", 29, "a window carried to another process over a socket: the session's host" },
.{ "Kind.zig", 1, "host_io's KindJob: a kind's job is the host's" },
- .{ "Messages.zig", 6, "the message clock, read through tape.value(.clock); PARDES_NOTIME, the tests', read by a host's `stamp` alone (between steps, or in a host's call), whose text the tape carries in the setMessage it makes: never a step's" },
+ .{ "Messages.zig", 4, "PARDES_NOTIME, the tests', and the time of day, read by a host's `stamp` alone (between steps, or in a host's call), whose text the tape carries in the setMessage it makes: never a step's" },
.{ "Output.zig", 2, "the fonts module (Fonts lists them under tape.site(.fonts)) and the build's version line" },
.{ "Stream.zig", 14, "the disk search's worker: it runs off the step and its batches are inputs" },
.{ "builtins.zig", 2, "Mount's probe (tape.site(.probe)) and Term's shell check (tape.site(.shell))" },
@@ -761,6 +767,7 @@ const kept_out = [_]struct { []const u8, []const u8, []const u8 }{
.{ "Core.zig", "shell_rows", "a terminal's rows as read here, swept at every update; the terminal's own digest covers its active area, not its history (Term.zig `calls`)" },
.{ "Core.zig", "diff_output locations_cache tty_filter_palette body_chrome", "caches of pure functions of their key (a text, a theme): a step finds what it would make; a query row's colours from them are out of its digest (locations.Row.digest), and what a step asks a worker to paint is never decided by them (Stream.paintRows)" },
.{ "Core.zig", "retired_panes", "panes torn down this step, freed at its end" },
+ .{ "Core.zig", "theme_preview preview_chrome", "a themes picker's preview (colors.previewTheme): made from the live picker's cursor, in the digest with it, after every step (Pick.produceAll) and gone at its roll-up; a step reading a theme meanwhile reads the one its own state previews" },
.{ "Core.zig", "multi_first multi_stop multi_index multi_count exec_depth exec_column", "a step's own: set by a key's replay across the ranges (normal.replaySels) and a word's run (exec.zig), each put back before the step ends; between steps what `init` makes, so a load takes them as it makes them (a dump's said 2^30 ranges once: a yank sized its register by it)" },
.{ "Core.zig", "rects col_x col_w", "a view's geometry: the layout pass's (layout.compute) over its columns and screen, at every sync and resize, and at a load (dump.afterLoad); never read before it" },
.{ "Core.zig", "distrusted frames tape", "Options: the client's own list, its runner's statistics, its tape" },
@@ -768,6 +775,8 @@ const kept_out = [_]struct { []const u8, []const u8, []const u8 }{
.{ "panes.zig", "pv pv_known", "the views' shares as this process parks them (views.zig)" },
.{ "panes.zig", "wrap_line wrap_col wrap_pad wrap_n body_wrapped context_rows body_rows body_visible_rows context_row_limit geometry_key geometry_len top_skip", "File.geometry's, made by whoever asks first (a frame or a step) from everything its key hashes of the step's state (the tab's width too); top_skip, keyed by the geometry it is of, read only through File.topSkip, which walks one of another key again" },
.{ "panes.zig views.zig", "notices", "made again from the step's state at the top of update and presented, and at sync (Messages.collectNotices); a frame's are its own" },
+ .{ "panes.zig", "ghost_at", "where a message's detail is drawn under the caret's line (Messages.detailUnder), made again from the step's state with the notices (Messages.collectNotices: at the top of update, presented, sync, place); a frame's are its own" },
+ .{ "panes.zig", "ghost_rows", "the detail's rows there, made again with ghost_at" },
.{ "panes.zig views.zig", "band_rows", "the band's rows under a tag (Band.takes), made again from the view's tag state at every sync before anything reads them (layout.floorRows reads the last sync's, as it reads tag_rows)" },
.{ "panes.zig views.zig", "pan", "written by steps only (sync, a view unparked) from the pane and its terminal" },
.{ "File.zig", "cap line_starts line_cap widest", "the text's line index, of its bytes, and the widest line it found (an upper bound: which walk answers, never what)" },
diff --git a/core/surface.zig b/core/surface.zig
index 98696721..7c04a387 100644
--- a/core/surface.zig
+++ b/core/surface.zig
@@ -98,6 +98,9 @@ pub const Region = struct {
column_grip,
column_tag,
workspace_tag,
+ /// The row at the window's foot that indexes the live messages
+ /// (Messages.noticeRow).
+ notice_row,
/// A column below the workspace tag, its bar and panes: its left
/// edge is the spine a pixel shell rules down it.
column,
diff --git a/core/syntax.zig b/core/syntax.zig
index 08ea1fb4..a388573b 100644
--- a/core/syntax.zig
+++ b/core/syntax.zig
@@ -566,7 +566,7 @@ pub fn objectAt(path: []const u8, tree_ptr: *anyopaque, text: []const u8, object
/// `]f`/`[f` and kin: the next object starting after byte `at`, or the
/// previous one ending before it (helix goto_treesitter_object), from the
/// first of `.movement`, `.around`, `.inside` the query names.
-pub fn objectNext(path: []const u8, tree_ptr: *anyopaque, text: []const u8, object: Object, forward: bool, at: usize) ?Span {
+pub fn objectNext(path: []const u8, tree_ptr: *anyopaque, text: []const u8, object: Object, forward: bool, at: usize, within: ?[2]usize) ?Span {
const q = objectQuery(path) orelse return null;
var buf: [32]u8 = undefined;
const capture = for ([_][]const u8{ "movement", "around", "inside" }) |kind| {
@@ -576,6 +576,9 @@ pub fn objectNext(path: []const u8, tree_ptr: *anyopaque, text: []const u8, obje
const tree: *const ts.Tree = @ptrCast(@alignCast(tree_ptr));
const cursor = ts.QueryCursor.create();
defer cursor.destroy();
+ // Only the objects these bytes hold (a body's rows shown): its painted
+ // targets (body_layer.paintTargets).
+ if (within) |w| cursor.setByteRange(@intCast(w[0]), @intCast(w[1])) catch return null;
cursor.exec(q, tree.rootNode());
var best: ?Span = null;
while (cursor.nextMatch()) |match| {
diff --git a/core/tagline.zig b/core/tagline.zig
index 25eb8387..e95d68de 100644
--- a/core/tagline.zig
+++ b/core/tagline.zig
@@ -163,11 +163,12 @@ pub fn pathPrefix(p: *const Pardes, arena: std.mem.Allocator, pane: *Pane) ![]co
// Its walk's back steps before the name, its forward steps after
// it (Trail.zig), in the room `bytes` measures them.
const keep_word = if (keep) " Keep" else "";
- const room = try arena.alloc(u8, pane.trail.bytes(.back) + name.len + pane.trail.bytes(.forward) + keep_word.len);
+ const whole = pardes.Trail.folded(p, pane);
+ const room = try arena.alloc(u8, pane.trail.bytes(.back, whole) + name.len + pane.trail.bytes(.forward, whole) + keep_word.len);
var w: std.Io.Writer = .fixed(room);
- pane.trail.write(.back, &w) catch return error.OutOfMemory;
+ pane.trail.write(.back, whole, &w) catch return error.OutOfMemory;
w.writeAll(name) catch return error.OutOfMemory;
- pane.trail.write(.forward, &w) catch return error.OutOfMemory;
+ pane.trail.write(.forward, whole, &w) catch return error.OutOfMemory;
w.writeAll(keep_word) catch return error.OutOfMemory;
return w.buffered();
}
@@ -183,16 +184,29 @@ pub fn pathPrefix(p: *const Pardes, arena: std.mem.Allocator, pane: *Pane) ![]co
}
/// Where a file's name starts in its tag: after its walk's back steps.
-pub fn nameAt(pane: *const Pane) usize {
- return if (pane.file != null) pane.trail.bytes(.back) else 0;
+pub fn nameAt(p: *const Pardes, pane: *const Pane) usize {
+ return if (pane.file != null and pane.trail.n > 0) pane.trail.bytes(.back, pardes.Trail.folded(p, pane)) else 0;
}
/// The bytes of a file's tag its walk's forward steps take, after its name.
-pub fn forwardSpan(pane: *const Pane) [2]usize {
+pub fn forwardSpan(p: *const Pardes, pane: *const Pane) [2]usize {
const f = pane.file orelse return .{ 0, 0 };
+ if (pane.trail.n == 0) return .{ 0, 0 };
+ const whole = pardes.Trail.folded(p, pane);
const name = if (pane.prompt == .name) pane.input.own orelse f.path else f.path;
- const lo = pane.trail.bytes(.back) + name.len;
- return .{ lo, lo + pane.trail.bytes(.forward) };
+ const lo = pane.trail.bytes(.back, whole) + name.len;
+ return .{ lo, lo + pane.trail.bytes(.forward, whole) };
+}
+
+/// The step of pane `pane`'s walk whose word is at byte `at` of its tag's
+/// text, if one is there.
+pub fn trailAt(p: *const Pardes, pane: *const Pane, at: usize) ?u8 {
+ if (pane.trail.n == 0 or pane.file == null) return null;
+ const whole = pardes.Trail.folded(p, pane);
+ const ahead = forwardSpan(p, pane);
+ if (at < nameAt(p, pane)) return pane.trail.stepAt(.back, whole, at);
+ if (at >= ahead[0] and at < ahead[1]) return pane.trail.stepAt(.forward, whole, at - ahead[0]);
+ return null;
}
/// A click at shown row `row`, display column `col` of pane `id`'s tag on
@@ -200,15 +214,9 @@ pub fn forwardSpan(pane: *const Pane) [2]usize {
/// (Trail.zig, pick-ui SPEC §6.3). True when it was on one.
pub fn trailClick(p: *Pardes, id: usize, row: usize, col: usize, run: bool) bool {
const pane = p.panes[id] orelse return false;
- if (pane.trail.n == 0 or pane.file == null) return false;
const at = tagOffsetAt(p, pane, row, col) orelse return false;
if (at.row != 0) return false;
- const lead = nameAt(pane);
- const ahead = forwardSpan(pane);
- const step = if (at.col < lead)
- pane.trail.stepAt(.back, at.col)
- else if (at.col >= ahead[0] and at.col < ahead[1]) pane.trail.stepAt(.forward, at.col - ahead[0]) else null;
- const i = step orelse return false;
+ const i = trailAt(p, pane, at.col) orelse return false;
if (run) pardes.Trail.execStep(p, id, i) else pardes.Trail.lookStep(p, id, i);
return true;
}
@@ -401,14 +409,15 @@ pub fn tagOffsetAt(p: *Pardes, pane: *Pane, row: usize, col: usize) ?modal.Curso
/// The display column in the name a click drafts at display column `col`
/// of the tag's shown row `row`: on a saving file's path, after its walk's
/// words; null off it.
-pub fn onName(tab: u16, pane: *Pane, row: usize, col: usize) ?usize {
+pub fn onName(p: *const Pardes, pane: *Pane, row: usize, col: usize) ?usize {
+ const tab = p.settings.tab;
if (row + pane.tag_top != 0) return null;
const f = pane.file orelse return null;
if (!panes.Output.fileTraits(f.output).saves) return null;
const name = if (pane.prompt == .name) pane.input.own orelse f.path else f.path;
var room: [pardes.Trail.max_steps * (pardes.Trail.max_text + 32)]u8 = undefined;
var w: std.Io.Writer = .fixed(&room);
- pane.trail.write(.back, &w) catch return null;
+ pane.trail.write(.back, pardes.Trail.folded(p, pane), &w) catch return null;
const lead = panes.File.displayWidth(tab, w.buffered());
if (col < lead or col >= lead + panes.File.displayWidth(tab, name)) return null;
return col - lead;
@@ -423,8 +432,8 @@ pub fn typedIntoName(p: *Pardes, pane: *Pane, key: pardes.Key) bool {
if (!panes.Output.fileTraits(f.output).saves or pane.tag.cur_row != 0) return false;
// The name starts after its walk's words.
const col: usize = @intCast(@max(0, pane.tag.cur_col));
- if (col < nameAt(pane)) return false;
- const at = col - nameAt(pane);
+ if (col < nameAt(p, pane)) return false;
+ const at = col - nameAt(p, pane);
const back = key.cp == pardes.Key.backspace or pardes.hit(key, config.insert_backspace_alias);
const forward = key.cp == pardes.Key.delete or pardes.hit(key, config.insert_delete_alias);
const typed = key.text.len > 0 and !key.ctrl and !key.alt;