From 2f3f8776613ebb357ff6458267c3d79c79944968 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Sun, 27 Sep 2026 21:19:08 -0300 Subject: Move the Output namespace out of panes.zig into Output.zig Pure move: the body of `pub const Output = struct { ... }` is now the file Output.zig, dedented, with the imports it uses; panes.zig keeps `pub const Output = @import("Output.zig");`, so `panes.Output.x` callers are unchanged. decorateRow and RowDecoration.styleAt become pub because File calls them from another file now. Output.zig joins the embedded source list. Co-Authored-By: Claude Opus 5.5 --- src/Output.zig | 782 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 782 insertions(+) create mode 100644 src/Output.zig (limited to 'src/Output.zig') diff --git a/src/Output.zig b/src/Output.zig new file mode 100644 index 00000000..00122b16 --- /dev/null +++ b/src/Output.zig @@ -0,0 +1,782 @@ +//! Output buffers (+Errors, search and jump results, help, messages, the +//! changelog): their rows, traits and look targets. +const panes = @import("panes.zig"); +const std = @import("std"); +const pardes = @import("pardes.zig"); +const config = @import("config.zig"); +const Pardes = pardes.Pardes; +const modal = @import("modal.zig"); +const dump = @import("dump.zig"); +const limits = @import("memory.zig").limits; +const builtins = @import("builtins.zig"); +const effect_sources = @import("effect_sources.zig"); +const build_options = @import("pardes_config"); +const lsp = @import("lsp/lsp.zig"); +const look = @import("look.zig"); +const locations = @import("locations.zig"); +const Pane = panes.Pane; +const File = panes.File; + +const Builtin = builtins.registry.Builtin(); +const gui_shader_source_mode = effect_sources.guiShaderSourceMode(); + +const fonts = if (builtins.capabilities.font_picker) @import("fonts.zig") else struct {}; + +pub const Origin = union(enum) { + cmd: Builtin, + query: lsp.Kind, + search, + errors, + pdf_links, +}; + +pub const max_arg = dump.max_origin_arg; + +pub const State = struct { + from: Origin, + arg_buf: [max_arg]u8 = undefined, + arg_len: u16 = 0, + + pub fn arg(o: *const State) []const u8 { + return o.arg_buf[0..o.arg_len]; + } +}; + +const RowDecoration = struct { + location_end: usize = 0, + prefix_end: usize = 0, + declaration: bool = false, + mark_start: usize = 0, + mark_end: usize = 0, + severity: enum { none, err, warning, info, hint } = .none, + + pub fn styleAt(row: RowDecoration, p: *const Pardes, byte: usize) ?pardes.CellStyle { + // Body paper changes immediately, so its ink must change with it + // even while the surrounding tags are still fading. + const chrome = pardes.ChromeTheme.fromTheme(p.theme()); + if (row.declaration or byte < @max(row.location_end, row.prefix_end)) + return .{ .fg = .{ .rgb = chrome.lineno } }; + if (byte < row.mark_start or byte >= row.mark_end) return null; + if (row.severity == .none) return .{ + .fg = .{ .rgb = chrome.search_fg }, + .bg = .{ .rgb = chrome.search_bg }, + }; + return .{ .fg = .{ .rgb = switch (row.severity) { + .err => chrome.diagnostic_error, + .warning => chrome.diagnostic_warning, + .info => chrome.diagnostic_info, + .hint => chrome.diagnostic_hint, + .none => unreachable, + } }, .bold = true }; + } +}; + +fn rowDecoration(output: ?State, line: []const u8) RowDecoration { + return decorateRow(output, line, null); +} + +pub fn decorateRow(output: ?State, line: []const u8, metadata: ?locations.Row) RowDecoration { + const origin = (output orelse return .{}).from; + if (!traits(origin).locations) return .{}; + const target = locations.parse(line); + const spot = if (metadata) |m| m.at else target.at; + if (spot.line == 0) return .{}; + var row: RowDecoration = .{ + .location_end = if (metadata) |m| m.location_end else target.end, + .prefix_end = if (metadata) |m| m.code_start else target.end, + .declaration = if (metadata) |m| m.declaration else false, + }; + const source_start = if (metadata) |m| m.code_start else target.code_start; + if (source_start >= line.len) return row; + if (metadata) |m| if (m.kind == .context) return row; + const mark_occurrence = switch (origin) { + .search => true, + .cmd => |cmd| cmd == .Grep, + .query => |kind| switch (kind) { + .definition, .declaration, .type_definition, .implementation, .references => true, + else => false, + }, + else => false, + }; + if (mark_occurrence and spot.col > 0 and spot.end_line == spot.line and + spot.end_col >= spot.col) + { + row.mark_start = source_start +| (spot.col - 1); + row.mark_end = @min(line.len, source_start +| spot.end_col); + } + const is_diagnostic = switch (origin) { + .query => |kind| kind == .diagnostics or kind == .workspace_diagnostics, + else => false, + }; + if (is_diagnostic) { + const text = line[source_start..]; + inline for (.{ .{ "error:", .err }, .{ "warning:", .warning }, .{ "info:", .info }, .{ "hint:", .hint } }) |label| { + if (std.mem.startsWith(u8, text, label[0])) { + row.mark_start = source_start; + row.mark_end = source_start + label[0].len; + row.severity = label[1]; + } + } + } + return row; +} + +test "result decoration follows source byte ranges and diagnostic provenance" { + const row = rowDecoration(.{ .from = .search }, "src/a.rs:3:5-7 let abc = 1;"); + try std.testing.expectEqualStrings("abc", "src/a.rs:3:5-7 let abc = 1;"[row.mark_start..row.mark_end]); + const prose = rowDecoration(.{ .from = .{ .query = .hover } }, "src/a.rs:3:5-7 error: prose"); + try std.testing.expectEqual(@as(usize, 0), prose.mark_end); + const diagnostic = rowDecoration(.{ .from = .{ .query = .diagnostics } }, "src/a.rs:3:5-7 warning: unused"); + try std.testing.expectEqual(.warning, diagnostic.severity); + try std.testing.expectEqualStrings("warning:", "src/a.rs:3:5-7 warning: unused"[diagnostic.mark_start..diagnostic.mark_end]); + const malformed = rowDecoration(.{ .from = .search }, "src/a.rs:3:99999999999999999999-99999999999999999999 text"); + try std.testing.expect(malformed.mark_end <= "src/a.rs:3:99999999999999999999-99999999999999999999 text".len); + const snippet = "src/a.rs:3:14-16 \t\tfoo + 界 + foo"; + for ([_]lsp.Kind{ .definition, .declaration, .type_definition, .implementation, .references }) |kind| { + const occurrence = rowDecoration(.{ .from = .{ .query = kind } }, snippet); + try std.testing.expectEqualStrings("foo", snippet[occurrence.mark_start..occurrence.mark_end]); + } + for ([_]lsp.Kind{ .document_symbols, .workspace_symbols, .completion, .incoming_calls, .outgoing_calls, .supertypes, .subtypes, .rename }) |kind| { + const label = rowDecoration(.{ .from = .{ .query = kind } }, snippet); + try std.testing.expectEqual(@as(usize, 0), label.mark_end); + } +} + +test "stacked empty previews distinguish separators from trailing newlines" { + var path = [_]u8{ 'x', '.', 'c' }; + const rows = [_]locations.Row{ + .{ .kind = .match, .path = &path, .at = .{ .line = 1, .col = 1 }, .location_end = 7, .code_start = 7 }, + .{ .kind = .preview, .path = &path, .at = .{ .line = 1, .col = 1 }, .location_end = 0, .code_start = 0 }, + }; + try std.testing.expect(locations.sameInput("x.c:1:1 ", "x.c:1:1\n", &rows, .stacked)); + try std.testing.expect(locations.sameInput("x.c:1:1 \n", "x.c:1:1\n\n", &rows, .stacked)); + try std.testing.expect(!locations.sameInput("x.c:1:1 ", "x.c:1:1\n\n", &rows, .stacked)); + try std.testing.expect(!locations.sameInput("x.c:1:1 \n", "x.c:1:1\n", &rows, .stacked)); +} + +test "plain output does not opt into location decoration" { + const report = rowDecoration(.{ .from = .{ .cmd = .LocationsConfig } }, "LocationsConfig context:5 tscontext:on"); + try std.testing.expectEqualDeep(RowDecoration{}, report); + const prose = rowDecoration(.{ .from = .{ .query = .hover } }, "src/a.rs:3:5-7 error: prose"); + try std.testing.expectEqualDeep(RowDecoration{}, prose); + const errors = rowDecoration(.{ .from = .errors }, "src/a.rs:3:5-7 error: prose"); + try std.testing.expectEqualDeep(RowDecoration{}, errors); + try std.testing.expect(!traits(.{ .cmd = .Find }).locations); + try std.testing.expect(traits(.{ .cmd = .Grep }).locations); + try std.testing.expect(traits(.{ .query = .completion }).locations); +} + +pub fn setArg(o: *State, text: []const u8) error{ArgumentTooLong}!void { + if (text.len > max_arg) return error.ArgumentTooLong; + o.arg_len = @intCast(text.len); + @memcpy(o.arg_buf[0..o.arg_len], text); +} + +pub const Traits = builtins.OutputTraits; + +const file_row: Traits = .{ .name = "", .doc = true, .saves = true }; + +pub fn traits(o: Origin) Traits { + return switch (o) { + // rows are `location text`, so n/N walk them + .search => .{ .name = config.search_buffer, .steps = true, .locations = true }, + .errors => .{ .name = config.errors_buffer, .doc = true }, + .pdf_links => .{ .name = config.pdf_links_buffer, .steps = true, .locations = true }, + .cmd => |b| builtins.registry.outputTraits(b) orelse unreachable, + .query => |k| switch (k) { + .hover => .{ .name = config.hover_buffer }, + // prose: an action list, a diff, a report about the backend + .code_action, .format, .status, .explain => .{ .name = config.lsp_buffer }, + .rename => .{ .name = config.search_buffer, .steps = true, .locations = true }, + .definition, .declaration, .type_definition, .implementation, .references => .{ + .name = config.search_buffer, + .steps = true, + .locations = true, + .jumps = true, + }, + // The hierarchy kinds behave like references: a list of places, + // and a lone answer (one caller, one subtype) is a jump. + .incoming_calls, .outgoing_calls, .supertypes, .subtypes => .{ + .name = config.search_buffer, + .steps = true, + .locations = true, + .jumps = true, + }, + .document_symbols, .workspace_symbols, .diagnostics, .workspace_diagnostics, .select_refs, .completion => .{ + .name = config.search_buffer, + .steps = true, + .locations = true, + }, + }, + }; +} + +pub fn usesLocationsConfig(from: Origin) bool { + const tr = traits(from); + return tr.steps and !tr.commands and from != .pdf_links and + !std.meta.eql(from, Origin{ .cmd = .Find }) and + !std.meta.eql(from, Origin{ .query = .completion }); +} + +pub fn fileTraits(out: ?State) Traits { + return traits((out orelse return file_row).from); +} + +pub const Grain = enum { + word, + line, + whole, +}; + +pub fn grain(out: ?State) Grain { + const tr = fileTraits(out); + if (tr.commands) return .whole; + return if (tr.steps) .line else .word; +} + +pub fn word(o: Origin) []const u8 { + return switch (o) { + .cmd => |b| @tagName(b), + .query => |k| @tagName(k), + .search => "/", + .errors => config.errors_buffer, + .pdf_links => config.pdf_links_buffer, + }; +} + +pub fn fromWord(w: []const u8) ?Origin { + if (w.len == 0) return null; + if (std.mem.eql(u8, w, "/")) return .search; + if (std.mem.eql(u8, w, config.errors_buffer)) return .errors; + if (std.mem.eql(u8, w, config.pdf_links_buffer)) return .pdf_links; + if (std.meta.stringToEnum(Builtin, w)) |b| + if (builtins.registry.outputTraits(b) != null) return .{ .cmd = b }; + if (std.meta.stringToEnum(lsp.Kind, w)) |k| return .{ .query = k }; + return null; +} + +pub fn resultsFrom(p: *Pardes, pane: *Pane, from: Origin) bool { + const rp = p.panes[pane.search_pane orelse return false] orelse return false; + const f = rp.file orelse return false; + const o = f.output orelse return false; + return std.meta.eql(o.from, from); +} + +pub const Location = struct { + path: []const u8, + at: look.Spot, + end: usize, + + fn order(a: Location, b: Location) std.math.Order { + const path = std.mem.order(u8, a.path, b.path); + if (path != .eq) return path; + if (a.at.line != b.at.line) return std.math.order(a.at.line, b.at.line); + return std.math.order(a.at.col, b.at.col); + } +}; + +pub fn location(line: []const u8) Location { + const target = locations.parse(std.mem.trimEnd(u8, line, " \t\r\n")); + return .{ .path = target.path, .at = target.at, .end = target.end }; +} + +pub fn isResultRow(file: *const File.State, row: usize) bool { + if (row < file.location_rows.len) return file.location_rows[row].kind == .match; + return !locations.isContextLine(modal.lineSlice(file.content, row)); +} + +fn sortResults(arena: std.mem.Allocator, from: Origin, content: []u8, anchor: ?usize) !?usize { + switch (from) { + .search => {}, + .cmd => |cmd| switch (cmd) { + .Find, .Grep => {}, + else => return anchor, + }, + .query => |kind| switch (kind) { + .definition, + .declaration, + .type_definition, + .implementation, + .references, + .incoming_calls, + .outgoing_calls, + .supertypes, + .subtypes, + .document_symbols, + .workspace_symbols, + .diagnostics, + .workspace_diagnostics, + .select_refs, + .rename, + => {}, + else => return anchor, + }, + .errors, .pdf_links => return anchor, + } + if (content.len == 0) return anchor; + const path_only = std.meta.eql(from, Origin{ .cmd = .Find }); + const trailing_newline = content[content.len - 1] == '\n'; + const body = content[0 .. content.len - @intFromBool(trailing_newline)]; + var lines = std.mem.splitScalar(u8, body, '\n'); + var previous: ?Location = null; + var sorted = true; + var count: usize = 0; + while (lines.next()) |line| { + const current: Location = if (path_only) .{ .path = line, .at = .{}, .end = line.len } else location(line); + if (!path_only and current.at.line == 0) return anchor; + if (previous) |last| if (last.order(current) == .gt) { + sorted = false; + }; + previous = current; + count += 1; + } + if (sorted) return anchor; + + const Row = struct { + text: []const u8, + target: Location, + original: usize, + + fn lessThan(_: void, a: @This(), b: @This()) bool { + return switch (a.target.order(b.target)) { + .lt => true, + .eq => a.original < b.original, + .gt => false, + }; + } + }; + const rows = try arena.alloc(Row, count); + const copy = try arena.dupe(u8, body); + lines = std.mem.splitScalar(u8, copy, '\n'); + for (rows, 0..) |*row, original| { + const text = lines.next().?; + const target: Location = if (path_only) .{ .path = text, .at = .{}, .end = text.len } else location(text); + row.* = .{ + .text = text, + .target = target, + .original = original, + }; + } + std.mem.sort(Row, rows, {}, Row.lessThan); + var mapped = anchor; + var offset: usize = 0; + for (rows, 0..) |row, i| { + if (anchor == row.original) mapped = i; + @memcpy(content[offset..][0..row.text.len], row.text); + offset += row.text.len; + if (i + 1 < rows.len or trailing_newline) { + content[offset] = '\n'; + offset += 1; + } + } + std.debug.assert(offset == content.len); + return mapped; +} + +pub fn nextResult(content: []const u8, rows: []const locations.Row, path: []const u8, at: look.Spot) usize { + const current: Location = .{ .path = path, .at = at, .end = 0 }; + var lines = std.mem.splitScalar(u8, content, '\n'); + var first: ?usize = null; + var row: usize = 0; + while (lines.next()) |line| : (row += 1) { + if (row < rows.len) { + if (rows[row].kind != .match) continue; + } else if (locations.isContextLine(line)) continue; + const target = location(line); + if (target.at.line == 0) continue; + if (first == null) first = row; + if (target.order(current) == .gt) return row; + } + return first orelse 0; +} + +pub fn open(p: *Pardes, id: usize, dir: []const u8, from: Origin, arg: []const u8, content: []u8) !*Pane { + const path = try std.fmt.allocPrint(p.gpa, "{s}/{s}", .{ + std.mem.trimEnd(u8, dir, "/"), traits(from).name, + }); + errdefer p.gpa.free(path); + var out: State = .{ .from = from }; + try setArg(&out, arg); + const history = try File.History.create(p.gpa); + errdefer p.gpa.destroy(history); + const pane = try p.newDocPane(id); + pane.file = .{ .path = path, .content = content, .output = out, .history = history }; + pane.cur_pinned = true; + return pane; +} + +pub fn fillResults(p: *Pardes, id: usize, dir: []const u8, from: Origin, arg: []const u8, content: []u8, initial_anchor: ?usize) !void { + var result_content = content; + errdefer p.gpa.free(result_content); + var result_rows: []locations.Row = &.{}; + errdefer locations.freeRows(p.gpa, result_rows); + const pane = p.panes[id] orelse return error.MissingPane; + if (arg.len > max_arg) return error.ArgumentTooLong; + var anchor = try sortResults(p.scratch.allocator(), from, content, initial_anchor); + const by_arg = std.meta.activeTag(from) != .query; + if (p.locations_config.context == 0 and !p.locations_config.tscontext) { + for (p.panes, 0..) |slot, i| { + if (i == id) continue; + const rp = slot orelse continue; + const rf = if (rp.file) |*f| f else continue; + const output = if (rf.output) |*o| o else continue; + if (!std.meta.eql(output.from, from)) continue; + if (by_arg and !std.mem.eql(u8, output.arg(), arg)) continue; + if (!std.mem.eql(u8, std.fs.path.dirname(rf.path) orelse "", dir)) continue; + if (!locations.sameInput(content, rf.content, rf.location_rows, p.locations_config.layout)) continue; + try setArg(output, arg); + p.gpa.free(content); + p.active = id; + if (traits(from).steps) { + pane.search_pane = i; + pane.search_row = anchor; + p.armLookWalk(i); + } + return; + } + } + if (usesLocationsConfig(from)) { + const formatted = try locations.format(p, dir, content, anchor, true); + p.gpa.free(result_content); + result_content = formatted.content; + result_rows = formatted.rows; + anchor = formatted.anchor; + } + for (p.panes, 0..) |slot, i| { + if (i == id) continue; + const rp = slot orelse continue; + const rf = if (rp.file) |*f| f else continue; + const o = if (rf.output) |*x| x else continue; + if (!std.meta.eql(o.from, from)) continue; + if (by_arg and !std.mem.eql(u8, o.arg(), arg)) continue; + if (!std.mem.eql(u8, std.fs.path.dirname(rf.path) orelse "", dir)) continue; + try setArg(o, arg); + if (std.mem.eql(u8, rf.content, result_content)) { + p.gpa.free(result_content); + } else { + File.setContent(p, rf, result_content); + resetBody(p, rp); + } + if (locations.equalRows(rf.location_rows, result_rows)) { + locations.freeRows(p.gpa, result_rows); + } else { + locations.freeRows(p.gpa, rf.location_rows); + rf.location_rows = result_rows; + if (rf.highlights.len > 0) p.tree_sitter_gpa.free(rf.highlights); + rf.highlights = &.{}; + rf.highlight_start = 0; + rf.syntax_dirty = true; + } + p.active = id; + if (traits(from).steps) { + pane.search_pane = i; + pane.search_row = anchor; + p.armLookWalk(i); + } + return; + } + const free = p.freeSlot() orelse return error.NoPaneSlots; + const np = try open(p, free, dir, from, arg, result_content); + np.file.?.location_rows = result_rows; + p.placeDoc(id, free, np); + p.active = id; + if (traits(from).steps) { + pane.search_pane = free; + pane.search_row = anchor; + p.armLookWalk(free); + } +} + +pub fn openJumps(p: *Pardes, id: usize) !void { + var out: std.Io.Writer.Allocating = .init(p.gpa); + errdefer out.deinit(); + for (p.jumps[0..p.njumps]) |j| { + const jp = p.panes[j.pane] orelse continue; + var idbuf: [16]u8 = undefined; + const pdf_path: ?[]const u8 = if (comptime pardes.pdf_enabled) jp.pdfPath() else null; + const has_path = if (jp.file) |f| f.output == null else pdf_path != null; + const loc: []const u8 = if (has_path) + (if (jp.file) |f| f.path else pdf_path.?) + else + std.fmt.bufPrint(&idbuf, config.pane_addr ++ "{d}", .{j.pane}) catch unreachable; + const what: []const u8 = if (jp.file) |f| + std.mem.trim(u8, modal.lineSlice(f.content, j.line -| 1), " \t\r") + else if (jp.image) |iv| + iv.path + else if (pdf_path) |path| + path + else + jp.cwdSlice(); + 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] }) + else + try out.writer.print("{s}:{d}:{d} {s}\n", .{ loc, j.line, j.col, what[0..cut] }); + } + const content = try out.toOwnedSlice(); + try openStepped(p, id, .{ .cmd = .Jumplist }, content); +} + +pub fn openThemes(p: *Pardes, id: usize) !void { + var out: std.Io.Writer.Allocating = .init(p.gpa); + errdefer out.deinit(); + try out.writer.writeAll("# Pardes themes\n"); + for (pardes.themes, 0..) |t, i| { + if (i == pardes.native_theme_count) + try out.writer.writeAll("\n# Legacy and imported themes\n"); + try out.writer.print(comptime config.Runtime.findAction(.theme).?.word ++ " {s}\n", .{t.name}); + } + const content = try out.toOwnedSlice(); + try openStepped(p, id, .{ .cmd = .ThemeSel }, content); +} + +pub fn isWalkRow(file: *const File.State, row: usize, line: []const u8) bool { + const state = file.output orelse return true; + if (usesLocationsConfig(state.from)) return isResultRow(file, row); + if (!std.meta.eql(state.from, Origin{ .cmd = .ThemeSel })) return true; + // Section labels are for reading, not stops in the command walk. + return std.mem.startsWith(u8, std.mem.trimStart(u8, line, " \t"), comptime config.Runtime.findAction(.theme).?.word ++ " "); +} + +pub fn openFonts(p: *Pardes, id: usize) !void { + if (builtins.capabilities.font_picker) { + const arena = p.scratch.allocator(); + const font_list = fonts.list(arena, null); + var out: std.Io.Writer.Allocating = .init(p.gpa); + errdefer out.deinit(); + for (font_list) |f| + try out.writer.print(comptime config.Runtime.findAction(.font).?.word ++ " {s}\n", .{f.name}); + const content = try out.toOwnedSlice(); + try openStepped(p, id, .{ .cmd = .FontSel }, content); + } +} + +fn openStepped(p: *Pardes, id: usize, from: Origin, content: []u8) !void { + errdefer p.gpa.free(content); + const pane = p.panes[id] orelse return error.MissingPane; + const dir = if (pane.file) |f| (std.fs.path.dirname(f.path) orelse "/") else pane.cwdSlice(); + const free = p.freeSlot() orelse return error.NoPaneSlots; + const np = try open(p, free, dir, from, "", content); + p.placeDoc(id, free, np); + p.active = id; + pane.search_pane = free; + pane.search_row = null; + p.armLookWalk(free); +} + +fn helpContent(gpa: std.mem.Allocator, prefix: []const u8) ![]u8 { + const full_header = "pardes builtins, and how to run each:\nSPC and its keys, a chord, a button, the\ntopbar - or the name, executed anywhere.\n\n"; + const group_header = "pardes builtins under SPC"; + const language_footer = + "\nlanguage keys (motions, not words):\n" ++ + "gd gD gy gi gr goto: definition,\n" ++ + " declaration, type-def,\n" ++ + " implementation, refs\n" ++ + "]d [d ]D [D diagnostics: next,\n" ++ + " prev, last, first\n" ++ + "= format (applies, one\n" ++ + " undo step)\n" ++ + "Tab after a . completion, in insert\n" ++ + "C-left-click definition, by mouse\n" ++ + "SPC l ... hover, rename, symbols,\n" ++ + " calls, types: above\n"; + var len: usize = if (prefix.len == 0) + full_header.len + language_footer.len + else + group_header.len + prefix.len * 2 + 2; + for (pardes.builtin_rows) |row| { + // a path-less builtin filters as the empty path: in the full listing + // (which starts with nothing) and out of every group + if (!std.mem.startsWith(u8, row.path orelse "", prefix)) continue; + len += row.line.len + 1; + } + const content = try gpa.alloc(u8, len); + var at: usize = 0; + if (prefix.len == 0) { + @memcpy(content[0..full_header.len], full_header); + at = full_header.len; + } else { + @memcpy(content[0..group_header.len], group_header); + at = group_header.len; + for (prefix) |c| { + content[at] = ' '; + content[at + 1] = c; + at += 2; + } + content[at] = '\n'; + content[at + 1] = '\n'; + at += 2; + } + for (pardes.builtin_rows) |row| { + if (!std.mem.startsWith(u8, row.path orelse "", prefix)) continue; + @memcpy(content[at..][0..row.line.len], row.line); + at += row.line.len; + content[at] = '\n'; + at += 1; + } + if (prefix.len == 0) { + @memcpy(content[at..][0..language_footer.len], language_footer); + at += language_footer.len; + } + std.debug.assert(at == content.len); + return content; +} + +pub fn openHelp(p: *Pardes, id: usize, prefix: []const u8) !void { + const content = try helpContent(p.gpa, prefix); + // content is handed off unfreed on purpose: openRead adopts it or frees + // it, and nothing between the alloc above and this line can fail. + return openRead(p, id, .{ .cmd = .Help }, prefix, content); +} + +test "full Help renders every builtin row, then the language keys" { + const content = try helpContent(std.testing.allocator, ""); + defer std.testing.allocator.free(content); + + // FIRST blank line: the end of the header (the footer opens with one too) + const body = content[(std.mem.indexOf(u8, content, "\n\n") orelse + return error.MissingHelpHeader) + 2 ..]; + var lines = std.mem.splitScalar(u8, body, '\n'); + for (pardes.builtin_rows) |row| + try std.testing.expectEqualStrings(row.line, lines.next() orelse + return error.MissingBuiltinHelpRow); + // ...and after the last row, the language-keys section: the one part of + // the keymap no builtin row can carry, closing the page. + try std.testing.expectEqualStrings("", lines.next() orelse + return error.MissingLanguageKeys); + try std.testing.expectEqualStrings("language keys (motions, not words):", lines.next() orelse + return error.MissingLanguageKeys); + try std.testing.expect(std.mem.indexOf(u8, body, "\ngd gD gy gi gr goto: definition,\n") != null); + // the group view stays a pure filter: no footer under a prefix + const group = try helpContent(std.testing.allocator, "l"); + defer std.testing.allocator.free(group); + try std.testing.expect(std.mem.indexOf(u8, group, "language keys") == null); +} + +pub fn openConfig(p: *Pardes, id: usize) !void { + var out: std.Io.Writer.Allocating = .init(p.gpa); + errdefer out.deinit(); + var dir_buf: [1024]u8 = undefined; + const host_fs = comptime (pardes.platform != .web and pardes.platform != .esp32p4); + try config.Runtime.writeReport(&out.writer, .{ + .default_dump_dir = if (host_fs) (pardes.dump.defaultDirectory(&dir_buf) orelse "") else "", + .startup_config_path = p.opts.startup_config_path, + .platform = @tagName(pardes.platform), + .theme_name = p.theme().name, + .compiled_default_shell = config.default_shell, + .gui_shader_source_mode = if (gui_shader_source_mode) |mode| + mode.label() + else + null, + .hover_delay_frames = config.look_preview_delay_frames, + .native_images = p.native_images, + .capabilities = builtins.capabilities, + .state = &p.settings, + }); + const content = try out.toOwnedSlice(); + return openRead(p, id, .{ .cmd = .Config }, "", content); +} + +/// The message-row log, oldest first — the lines that were said in passing and +/// then cleared by the next keystroke. +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.messageLog(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"); + const content = try out.toOwnedSlice(); + return openRead(p, id, .{ .cmd = .Messages }, "", content); +} + +/// The version banner plus the embedded CHANGELOG, so an installed binary can +/// say what it is and what changed without a repository beside it. +pub fn openChangelog(p: *Pardes, id: usize) !void { + var out: std.Io.Writer.Allocating = .init(p.gpa); + errdefer out.deinit(); + try out.writer.print("pardes {s}\n\n", .{build_options.version}); + try out.writer.writeAll(@embedFile("CHANGELOG.md")); + const content = try out.toOwnedSlice(); + return openRead(p, id, .{ .cmd = .Changelog }, "", content); +} + +pub fn openEffectCode(p: *Pardes, id: usize, argument: []const u8) !void { + const name = std.mem.trim(u8, argument, " \t\r\n"); + const setting = config.Runtime.find(name) orelse return error.UnknownEffect; + switch (setting.action) { + .transition, .scene => {}, + else => return error.NotAnEffect, + } + if (!setting.enabled(builtins.capabilities)) return error.EffectUnavailable; + // Without -Dembed-sources the paths would name nothing this build can open. + if (!limits.embedded_sources) return error.EffectUnavailable; + const paths = effect_sources.forSetting(setting) orelse + return error.EffectUnavailable; + + var out: std.Io.Writer.Allocating = .init(p.gpa); + errdefer out.deinit(); + try out.writer.print("EffectCode {s} ({s})\n", .{ setting.word, @tagName(effect_sources.backend) }); + if (gui_shader_source_mode) |mode| + try out.writer.print("GUI shader source: {s}\n", .{mode.label()}); + try out.writer.writeByte('\n'); + for (paths) |path| try out.writer.print("/virtual/{s}\n", .{path}); + const content = try out.toOwnedSlice(); + return openRead(p, id, .{ .cmd = .EffectCode }, setting.word, content); +} + +pub fn openErrors(p: *Pardes, id: usize, content: []u8) !void { + return openRead(p, id, .errors, "", content); +} + +pub fn resetBody(p: *Pardes, pane: *Pane) void { + pane.file.?.scroll = 0; + pane.cur_row = 0; + pane.cur_col = 0; + pane.cur_pinned = true; + pane.hscroll = 0; + pane.wrap_n = 0; + pane.msel = .{}; + pane.vsel = .{}; + pane.nsel = 0; + pane.nsel_snap = 0; + pane.select = false; + pane.sel = @splat(.{}); + pane.sticky_col = -1; + pane.append_at = null; + pane.normal.clear(); + pane.look_at = null; + if (p.look_hover_wait) |wait| if (wait.serial == pane.serial) { + p.look_hover_wait = null; + }; + if (p.look_hover_preview) |preview| if (preview.serial == pane.serial) { + p.look_hover_preview = null; + }; + if (p.drag == .select and p.panes[p.drag.select.id] == pane) p.drag = .none; +} + +fn openRead(p: *Pardes, id: usize, from: Origin, arg: []const u8, content: []u8) !void { + errdefer p.gpa.free(content); + const pane = p.panes[id] orelse return error.MissingPane; + for (p.panes, 0..) |slot, i| { + const hp = slot orelse continue; + const hf = if (hp.file) |*f| f else continue; + const ho = if (hf.output) |*o| o else continue; + if (!std.meta.eql(ho.from, from)) continue; + try setArg(ho, arg); + File.setContent(p, hf, content); + resetBody(p, hp); + p.active = i; + return; + } + const dir = if (pane.file) |f| (std.fs.path.dirname(f.path) orelse "/") else pane.cwdSlice(); + const free = p.freeSlot() orelse return error.NoPaneSlots; + const np = try open(p, free, dir, from, arg, content); + p.placeDoc(id, free, np); + p.active = free; +} -- cgit v1.3 From fc2bc13e9f45099d4e2fe086e2a52aab7de8ad5c Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Sun, 27 Sep 2026 21:59:17 -0300 Subject: Move the message row out of pardes.zig into Messages.zig Pure move, no behaviour change: the Message stamp helpers, LoggedMessage, setStatus, setMessage, showMessage, dismissMessage, dismissLine, advanceMessages, advanceLine, messagesAnimating, MessageMotion, messageFrames, messageMotion, noticeText, noticeLife, blendRgb, logMessage, messageLog, reportError, the notice painters (leaderText, noticeCols, Printed, printRight), collectNotices, and the six message tests go verbatim to Messages.zig. The methods become free functions taking `p: *Pardes`. setStatus, setMessage and reportError are called from ~170 places as `p.setMessage(..)`, so Pardes keeps three declaration aliases (`pub const setMessage = Messages.setMessage;`) and those call sites stay as they are; every other call changes from `p.x(..)` to `Messages.x(p, ..)` (46 of them). The five shells' `pardes.Pardes.Message` become `pardes.Messages.Message`. The message ring's fields stay on Pardes for now; moving them into Messages is a separate change. Co-Authored-By: Claude Opus 5.5 --- src/Messages.zig | 773 ++++++++++++++++++++++++++++++++++++++++++++++ src/Output.zig | 3 +- src/detached/server.zig | 2 +- src/file_watch.zig | 2 +- src/fs.zig | 1 + src/gui/gui.zig | 2 +- src/macos.zig | 2 +- src/ninep/events.zig | 2 +- src/pardes.zig | 790 ++---------------------------------------------- src/tty/tty.zig | 2 +- 10 files changed, 805 insertions(+), 774 deletions(-) create mode 100644 src/Messages.zig (limited to 'src/Output.zig') diff --git a/src/Messages.zig b/src/Messages.zig new file mode 100644 index 00000000..6b041369 --- /dev/null +++ b/src/Messages.zig @@ -0,0 +1,773 @@ +//! The message row: messages and statuses a pane shows between its body and +//! its tagline, how each line falls in, lingers and dissolves, the notices +//! built from them every frame, and the log of everything said. +const pardes = @import("pardes.zig"); +const memory = @import("memory.zig"); +const std = @import("std"); +const layout = @import("layout.zig"); +const ctlfs = @import("ninep/tree.zig"); +const panes = @import("panes.zig"); +const CellStyle = @import("surface.zig").CellStyle; +const Surface = @import("surface.zig").Surface; +const limits = memory.limits; +const config = @import("config.zig"); +const platform = pardes.platform; +const Pane = panes.Pane; +const MAX_PANES = pardes.MAX_PANES; +const BOX_H = pardes.BOX_H; +const Key = pardes.Key; +const Rect = layout.Rect; +const Pardes = pardes.Pardes; + +pub const LoggedMessage = struct { + pub const cap = 256; + text: [cap]u8 = undefined, + len: u16 = 0, + /// The serial of the pane that said it, or 0 for none in particular. A + /// serial, not a slot: slots are reused, so an old line would name + /// whichever pane took the slot since. + serial: u32 = 0, + /// How many times in a row. Saturating: a key held down against the same + /// refusal is one event, not four hundred. + repeats: u16 = 0, + + pub fn slice(m: *const LoggedMessage) []const u8 { + return m.text[0..m.len]; + } +}; + +/// `SPC` plus the chord keys typed so far, spaced out the way the help +/// index spells a leader path. +fn leaderText(p: *const Pardes, buf: *[16]u8) []const u8 { + buf.* = @splat(' '); + @memcpy(buf[0..3], "SPC"); + var at: usize = 3; + for (p.leader_keys[0..p.leader_n]) |ch| { + if (at + 2 > buf.len) break; + buf[at + 1] = ch; + at += 2; + } + return buf[0..at]; +} + +/// How wide a notice chip is, in grid columns: its own text plus a blank +/// cell either side. A notice is an OVERLAY over the body's top rows, not +/// a row taken from them, so it is sized to its message and never to the +/// pane. Counted in GRID columns rather than scaled into the tagline face +/// it is drawn in, because the canonical grid is what a terminal client +/// draws and a chip narrower than its own text there would clip it; the +/// tagline face simply leaves a little more room inside the chip. +pub fn noticeCols(p: *const Pardes, text: []const u8, limit: u16) u16 { + _ = p; + if (limit == 0) return 0; + return @intCast(std.math.clamp(panes.File.displayWidth(text) + 2, 1, @as(usize, limit))); +} + +const Printed = struct { left: u16, dropped: usize }; + +/// Prints `text` flush with the right edge of the band, and answers the +/// column it started at so a cursor can follow it. Text wider than the +/// band loses its HEAD: the end is the part that says something -- a +/// path's file name, an error's reason -- and `dropped` is how many +/// columns of it went. +pub fn printRight(s: *Surface, x: u16, row: u16, w: u16, text: []const u8, style: CellStyle) Printed { + const width = panes.File.displayWidth(text); + if (width <= w) { + const left: u16 = @intCast(x + w - width); + _ = s.print(left, row, @intCast(width), text, style); + return .{ .left = left, .dropped = 0 }; + } + // Whole glyphs only: a cut inside a wide one would leave the rest a + // column too wide and clip its LAST glyph instead of the first. + var dropped = width - w; + var start = panes.File.rawAtDisplay(text, dropped); + if (panes.File.rawDisplayCol(text, start) < dropped) { + dropped += 1; + start = panes.File.rawAtDisplay(text, dropped); + } + const left: u16 = @intCast(x + w - (width - dropped)); + _ = s.print(left, row, @intCast(width - dropped), text[start..], style); + return .{ .left = left, .dropped = dropped }; +} + +pub const Message = struct { + const libc = std.c; + const Tm = extern struct { + sec: c_int, + min: c_int, + hour: c_int, + mday: c_int, + mon: c_int, + year: c_int, + wday: c_int, + yday: c_int, + isdst: c_int, + gmtoff: c_long, + zone: ?[*:0]const u8, + }; + extern "c" fn localtime_r(timep: *const libc.time_t, result: *Tm) ?*Tm; + + pub fn body(text: []const u8) []const u8 { + if (text.len < 10) return text; + if (text[2] != ':' or text[5] != ':' or text[8] != ' ' or text[9] != ' ') return text; + for ([_]usize{ 0, 1, 3, 4, 6, 7 }) |i| { + if (!std.ascii.isDigit(text[i]) and text[i] != '-') return text; + } + return text[10..]; + } + + pub fn stamp(buf: []u8, verb: []const u8, subject: []const u8) []const u8 { + var clock: [8]u8 = "--:--:--".*; + const notime = if (libc.getenv("PARDES_NOTIME")) |v| std.mem.span(v).len != 0 else false; + if (!notime) { + var ts: libc.timespec = undefined; + _ = libc.clock_gettime(.REALTIME, &ts); + const secs: libc.time_t = ts.sec; + var tm: Tm = undefined; + if (localtime_r(&secs, &tm) != null) { + _ = std.fmt.bufPrint(&clock, "{d:0>2}:{d:0>2}:{d:0>2}", .{ + @as(u32, @intCast(tm.hour)), + @as(u32, @intCast(tm.min)), + @as(u32, @intCast(tm.sec)), + }) catch {}; + } + } + const head = std.fmt.bufPrint(buf, "{s} {s} ", .{ &clock, verb }) catch return buf[0..0]; + const room = buf.len - head.len; + const tail = if (subject.len <= room) subject else subject[subject.len - room ..]; + @memcpy(buf[head.len..][0..tail.len], tail); + return buf[0 .. head.len + tail.len]; + } +}; + +/// A status updates the message line in place (a progress count does not +/// pile up); a message is an event, and stacks. +pub fn setStatus(p: *Pardes, id: usize, text: []const u8) void { + showMessage(p, id, text, false); +} + +pub fn setMessage(p: *Pardes, id: usize, text: []const u8) void { + logMessage(p, id, text); + showMessage(p, id, text, true); +} + +fn showMessage(p: *Pardes, id: usize, text: []const u8, stack: bool) void { + if (id >= MAX_PANES) return; + const pane = p.panes[id] orelse return; + // 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); + 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_status = !stack; + const arrives = pane.msg_len == 0 or pane.msg_life.phase == .leaving; + for (text[0..n], pane.msg[0..n]) |c, *cell| cell.* = if (c < 0x20 or c == 0x7f) ' ' else c; + pane.msg_len = @intCast(n); + p.needs_frame = true; + if (arrives) { + pane.msg_life = .{ .phase = if (p.settings.message_animation and n > 0) .entering else .shown }; + } else if (pane.msg_life.phase == .lingering or + (pane.msg_life.phase == .entering and !p.settings.message_animation)) + { + // The same line again, or a status update: fresh, so it stays. + pane.msg_life = .{}; + } else { + pane.msg_life.dismissed = false; + } +} + +/// The key or click that used to clear the message row now starts each +/// line's exit: it stays `message_linger_ms`, then dissolves. A line +/// already on its way out keeps its own timing. +pub fn dismissMessage(p: *Pardes, pane: *Pane) void { + 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; + } +} + +/// Start one line's exit; true when it is gone at once (no linger, no +/// animation). +fn dismissLine(p: *const Pardes, life: *Pane.MessageLife) bool { + switch (life.phase) { + .lingering, .leaving => return false, + // A falling line lands first, then lingers -- unless falling was + // just turned off, and nothing will land it. + .entering => if (p.settings.message_animation) { + life.dismissed = true; + return false; + }, + .shown => {}, + } + life.frame = 0; + if (p.settings.message_linger_ms > 0) { + life.phase = .lingering; + } else if (p.settings.message_animation) { + life.phase = .leaving; + } else return true; + return false; +} + +/// One animation frame of every message line. Each one that moves owes +/// a frame, the one that finishes included: 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 = .{}; + } + } + 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; + } + } +} + +/// One frame of one line's life; true once it has left. +fn advanceLine(p: *const Pardes, life: *Pane.MessageLife) bool { + if (life.phase == .shown) return false; + life.frame +|= 1; + switch (life.phase) { + .shown => {}, + .entering => if (life.frame >= messageFrames(p.settings.message_fall_ms)) { + life.* = .{ .phase = if (life.dismissed) .lingering else .shown }; + }, + .lingering => if (life.frame >= messageFrames(p.settings.message_linger_ms)) { + if (!p.settings.message_animation) return true; + life.* = .{ .phase = .leaving }; + }, + .leaving => if (life.frame >= messageFrames(p.settings.message_dissolve_ms)) return true, + } + return false; +} + +/// Is any message line moving (and so owed ticks)? +pub fn messagesAnimating(pane: *const Pane) bool { + if (pane.msg_len > 0 and pane.msg_life.phase != .shown) return true; + for (pane.msg_older[0..pane.msg_older_len]) |line| if (line.life.phase != .shown) return true; + return false; +} + +/// How present a message is (1 = fully) and how far above its row it +/// still is (rows): a fall that decelerates into place with its colour +/// arriving ahead of it, and a dissolve. +pub const MessageMotion = struct { alpha: f32 = 1, slide: f32 = 0 }; + +/// Animation frames a message timing lasts; at least one. +pub fn messageFrames(ms: u16) u16 { + return @intCast(@max(1, (@as(u32, ms) + layout.Animation.frame_ms - 1) / layout.Animation.frame_ms)); +} + +pub fn messageMotion(p: *const Pardes, life: Pane.MessageLife) MessageMotion { + const fall_frames = messageFrames(p.settings.message_fall_ms); + const dissolve_frames = messageFrames(p.settings.message_dissolve_ms); + return switch (life.phase) { + .shown, .lingering => .{ .alpha = 1, .slide = 0 }, + .entering => blk: { + const t = @as(f32, @floatFromInt(@min(life.frame, fall_frames))) / @as(f32, @floatFromInt(fall_frames)); + // Out of the gate fast and easing into its row (a cubic + // ease-out), so it is there the moment it is said and the + // last frames only settle it. No overshoot: at a row's height + // and a dozen frames, a follow-through is a pixel or two that + // reads as a jitter, not a bounce. + const left = 1 - t; + // The colour leads the motion: solid by half way, so what + // lands is already legible rather than still fading up. + const faded = 1 - @min(1, 2 * t); + break :blk .{ .alpha = 1 - faded * faded, .slide = -(left * left * left) }; + }, + .leaving => blk: { + // Counted to its last frame rather than past it, so that frame + // shows it gone and it never blinks out from part way. + const last = @max(1, dissolve_frames - 1); + const t = @as(f32, @floatFromInt(@min(life.frame, last))) / @as(f32, @floatFromInt(last)); + // An exit eases in: still readable for a beat, then away + // faster and faster. It stays where it is -- the lines + // stacked around it do not move either. + break :blk .{ .alpha = 1 - t * t, .slide = 0 }; + }, + }; +} + +/// 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: *[16]u8) []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 "", + }; +} + +/// The life of the message line notice `i` shows, if it shows one. +pub fn noticeLife(pane: *const Pane, i: usize) ?Pane.MessageLife { + return switch (pane.notices.kinds[i]) { + .message => pane.msg_life, + .older => pane.msg_older[pane.notices.index[i]].life, + .leader, .prompt => null, + }; +} + +pub fn blendRgb(from: [3]u8, to: [3]u8, amount: f32) [3]u8 { + var out: [3]u8 = undefined; + for (&out, from, to) |*o, a, b| { + const af: f32 = @floatFromInt(a); + const bf: f32 = @floatFromInt(b); + o.* = @intFromFloat(@round(bf + (af - bf) * std.math.clamp(amount, 0, 1))); + } + return out; +} + +fn logMessage(p: *Pardes, id: usize, text: []const u8) void { + if (text.len == 0) return; + const serial: u32 = if (id < MAX_PANES) if (p.panes[id]) |pane| pane.serial else 0 else 0; + const kept = text[0..@min(text.len, LoggedMessage.cap)]; + // /log hears every one: a client that retried and failed the same way + // is waiting on that second line. Only the +Messages view collapses. + ctlfs.events.noteMessage(p, serial, kept); + if (p.messages_len > 0) { + const last = &p.messages[(p.messages_head + limits.message_log - 1) % limits.message_log]; + if (last.serial == serial and + std.mem.eql(u8, Message.body(last.slice()), Message.body(kept))) + { + // The NEWEST wording wins, so the row carries the latest clock + // rather than the moment the run started. + last.len = @intCast(kept.len); + @memcpy(last.text[0..last.len], kept); + last.repeats +|= 1; + return; + } + } + const slot = &p.messages[p.messages_head]; + slot.len = @intCast(kept.len); + @memcpy(slot.text[0..slot.len], kept); + slot.serial = serial; + slot.repeats = 1; + p.messages_head = (p.messages_head + 1) % limits.message_log; + p.messages_len = @min(p.messages_len + 1, limits.message_log); +} + +/// The log oldest-first, which is reading order. +pub fn messageLog(p: *const Pardes, i: usize) ?*const LoggedMessage { + if (i >= p.messages_len) return null; + const first = (p.messages_head + limits.message_log - p.messages_len) % limits.message_log; + return &p.messages[(first + i) % limits.message_log]; +} + +pub fn reportError(p: *Pardes, id: usize, operation: []const u8, err: anyerror) void { + var buf: [256]u8 = undefined; + const text = std.fmt.bufPrint(&buf, "{s}: {s}", .{ operation, @errorName(err) }) catch operation; + setMessage(p, 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.len = 0; + if (r.w <= config.GUTTER or r.h <= BOX_H) return; + // 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| pane.notices.pushAt(.older, @intCast(i), line.slot); + if (pane.msg_len > 0) pane.notices.pushAt(.message, 0, pane.msg_slot); + if (id == p.active and p.leader_on) pane.notices.push(.leader); + if (pane.promptText()) |text| if (text.len > 0) pane.notices.push(.prompt); + // A pane only has so many rows to give. When they do not all fit the + // LAST ones survive, because the prompt is last and it is the one + // carrying the cursor: a prompt you cannot see is a prompt you type + // 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 - BOX_H)); + const n = &pane.notices; + if (n.span() <= room) return; + // 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| { + n.kinds[k] = n.kinds[k + drop]; + n.index[k] = n.index[k + drop]; + n.row[k] = @intCast(k); + } + n.len -= @intCast(drop); +} + +test "the message log keeps what the row forgets, and collapses repeats" { + const gpa = std.testing.allocator; + const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 100, .rows = 30 }); + defer p.deinit(); + + setMessage(p, 0, "14:32:07 saved /x.zig"); + setMessage(p, 0, "14:32:09 saved /x.zig"); // same event, later clock + setMessage(p, 0, "save: AccessDenied"); + + try std.testing.expectEqual(@as(usize, 2), p.messages_len); + const first = messageLog(p, 0).?; + try std.testing.expectEqual(@as(u16, 2), first.repeats); + // ...and the NEWEST wording is what survives, so the row carries the last + // time it happened rather than the first. + try std.testing.expectEqualStrings("14:32:09 saved /x.zig", first.slice()); + try std.testing.expectEqualStrings("save: AccessDenied", messageLog(p, 1).?.slice()); + try std.testing.expect(messageLog(p, 2) == null); + + // The same text from a DIFFERENT pane is a different event: one pane's + // failure must not be recorded as another's. + p.newScratchBelow(0); + const other = p.active; + setMessage(p, other, "save: AccessDenied"); + try std.testing.expectEqual(@as(usize, 3), p.messages_len); + try std.testing.expectEqual(p.panes[other].?.serial, messageLog(p, 2).?.serial); + + // Progress is NOT logged: it arrives several times a second for a whole + // index and would push everything else out (`setStatus`). + setStatus(p, 0, "14:32:10 lsp rust-analyzer: Indexing 47%"); + try std.testing.expectEqual(@as(usize, 3), p.messages_len); + + // The ring wraps rather than grows, and still reads oldest-first. + for (0..limits.message_log + 5) |i| { + var buf: [32]u8 = undefined; + setMessage(p, 0, std.fmt.bufPrint(&buf, "line {d}", .{i}) catch unreachable); + } + try std.testing.expectEqual(@as(usize, limits.message_log), p.messages_len); + try std.testing.expectEqualStrings("line 5", messageLog(p, 0).?.slice()); + var last_buf: [32]u8 = undefined; + const want_last = std.fmt.bufPrint(&last_buf, "line {d}", .{limits.message_log + 4}) catch unreachable; + try std.testing.expectEqualStrings(want_last, messageLog(p, limits.message_log - 1).?.slice()); +} + +test "Msg writes the transient row by hand, bare or with text, and input ends it" { + 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)); + + // Bare, it reports ITSELF through reportError — the `: ` + // every failed save and refused Look arrives in. + try std.testing.expect(p.executeBuiltinLine(2, "Msg")); + try std.testing.expectEqualStrings("Msg: NoMessage", row(p, 2)); + + // Input starts its exit: it lingers, dissolves, and is gone. + p.update(.{ .key = .{ .cp = Key.escape } }); + try std.testing.expectEqualStrings("Msg: NoMessage", row(p, 2)); + for (0..200) |_| p.update(.tick); + try std.testing.expectEqualStrings("", row(p, 2)); + // ...and with neither linger nor animation it is as old as your last input. + try std.testing.expect(p.executeBuiltinLine(2, "MessageAnimation off")); + try std.testing.expect(p.executeBuiltinLine(2, "MessageLinger 0")); + try std.testing.expect(p.executeBuiltinLine(2, "Msg gone")); + p.update(.{ .key = .{ .cp = 'h' } }); + try std.testing.expectEqualStrings("", row(p, 2)); + + // Longer than the row's buffer 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); +} + +test "a message falls in, lingers past the input that dismisses it, and dissolves" { + 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.active].?; + try std.testing.expect(p.settings.message_animation); + try std.testing.expect(p.executeBuiltinLine(p.active, "MessageLinger 160")); + try std.testing.expect(p.executeBuiltinLine(p.active, "Msg hello")); + try std.testing.expectEqual(Pane.MessagePhase.entering, pane.msg_life.phase); + try std.testing.expect(p.animationActive()); + // An ease-out fall: starts a whole row up and unseen, covers most of the + // way at once and settles into its row, landing exactly on it without + // passing it. Its colour is whole by half way. + const start = messageMotion(p, pane.msg_life); + try std.testing.expectEqual(@as(f32, -1), start.slide); + try std.testing.expectEqual(@as(f32, 0), start.alpha); + const fall = messageFrames(p.settings.message_fall_ms); + var last = start; + var first_step: f32 = 0; + var last_step: f32 = 0; + for (0..fall) |frame| { + p.needs_frame = false; + p.update(.tick); + // Every tick that moves it owes a frame, the landing one included. + try std.testing.expect(p.needs_frame); + const now = messageMotion(p, pane.msg_life); + try std.testing.expect(now.slide >= last.slide and now.slide <= 0); + try std.testing.expect(now.alpha >= last.alpha); + if (frame == 0) first_step = now.slide - last.slide; + // Never slower to colour up than to arrive, and solid by half way. + try std.testing.expect(now.alpha >= 1 + now.slide); + if (2 * (frame + 1) >= fall) try std.testing.expectEqual(@as(f32, 1), now.alpha); + last_step = now.slide - last.slide; + last = now; + } + try std.testing.expect(first_step > 4 * last_step); + try std.testing.expectEqual(Pane.MessagePhase.shown, pane.msg_life.phase); + try std.testing.expectEqual(@as(f32, 0), messageMotion(p, pane.msg_life).slide); + try std.testing.expect(!p.animationActive()); + // Shown until input, like always; the same line again does not re-enter. + for (0..100) |_| p.update(.tick); + try std.testing.expectEqual(Pane.MessagePhase.shown, pane.msg_life.phase); + try std.testing.expect(p.executeBuiltinLine(p.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 std.testing.expectEqual(Pane.MessagePhase.lingering, pane.msg_life.phase); + p.update(.tick); + // ...then an ease-in dissolve: it lets go slowly and goes faster and + // faster, in place, its last frame showing it gone. + try std.testing.expectEqual(Pane.MessagePhase.leaving, pane.msg_life.phase); + const dissolve = messageFrames(p.settings.message_dissolve_ms); + var alpha: f32 = 1; + var first_drop: f32 = 0; + var last_drop: f32 = 0; + for (0..dissolve) |frame| { + const now = messageMotion(p, pane.msg_life); + try std.testing.expect(now.alpha <= alpha); + try std.testing.expectEqual(@as(f32, 0), now.slide); + if (frame == 1) first_drop = alpha - now.alpha; + last_drop = alpha - now.alpha; + alpha = now.alpha; + p.needs_frame = false; + p.update(.tick); + } + try std.testing.expectEqual(@as(f32, 0), alpha); + try std.testing.expect(first_drop > 0 and first_drop < last_drop); + try std.testing.expectEqual(@as(u16, 0), pane.msg_len); + try std.testing.expect(!p.animationActive()); + // The tick that clears it still owes the frame that shows it gone. + try std.testing.expect(p.needs_frame); + + // Dismissed mid-fall: it lands, then lingers. + try std.testing.expect(p.executeBuiltinLine(p.active, "Msg again")); + try std.testing.expectEqual(Pane.MessagePhase.entering, pane.msg_life.phase); + p.update(.tick); + p.update(.{ .key = .{ .cp = 'h' } }); + try std.testing.expectEqual(Pane.MessagePhase.entering, pane.msg_life.phase); + for (0..messageFrames(p.settings.message_fall_ms)) |_| p.update(.tick); + try std.testing.expectEqual(Pane.MessagePhase.lingering, pane.msg_life.phase); + // Shown again while lingering: fresh, so it stays; a status update to a + // line on screen swaps its text in place instead of falling again. + try std.testing.expect(p.executeBuiltinLine(p.active, "Msg again")); + try std.testing.expectEqual(Pane.MessagePhase.shown, pane.msg_life.phase); + setStatus(p, p.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); + // The fall and the dissolve are timings of their own, in milliseconds. + try std.testing.expect(p.executeBuiltinLine(p.active, "MessageFall 48")); + try std.testing.expect(p.executeBuiltinLine(p.active, "MessageDissolve 0")); + try std.testing.expectEqual(@as(u16, 3), messageFrames(p.settings.message_fall_ms)); + try std.testing.expectEqual(@as(u16, 1), messageFrames(p.settings.message_dissolve_ms)); + // The Config report reads back as configuration. + try std.testing.expect(p.executeBuiltinLine(p.active, "MessageAnimation")); + try std.testing.expect(!p.settings.message_animation); + try std.testing.expect(p.executeBuiltinLine(p.active, "Msg plain")); + try std.testing.expectEqual(Pane.MessagePhase.shown, pane.msg_life.phase); +} + +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.active].?; + try std.testing.expect(p.executeBuiltinLine(p.active, "Verbose off")); + try std.testing.expect(p.executeBuiltinLine(p.active, "MessageLinger 160")); + // `Verbose off` announced itself before it took effect. + pane.msg_len = 0; + pane.msg_life = .{}; + const fall = messageFrames(p.settings.message_fall_ms); + setMessage(p, p.active, "first"); + for (0..fall) |_| p.update(.tick); + try std.testing.expectEqual(Pane.MessagePhase.shown, pane.msg_life.phase); + // A second message stacks under the first instead of replacing it. + setMessage(p, p.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]); + try std.testing.expectEqual(Pane.MessagePhase.entering, pane.msg_life.phase); + collectNotices(p, pane, p.rects[p.active], p.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, but each runs its own clock: the first starts + // lingering now, the second only once it has landed. + p.update(.{ .key = .{ .cp = 'h' } }); + try std.testing.expectEqual(Pane.MessagePhase.lingering, pane.msg_older[0].life.phase); + try std.testing.expectEqual(Pane.MessagePhase.entering, pane.msg_life.phase); + const linger = messageFrames(p.settings.message_linger_ms); + const dissolve = messageFrames(p.settings.message_dissolve_ms); + for (0..linger + dissolve) |_| p.update(.tick); + // The first is gone; the second, a fall later, is still dissolving. + try std.testing.expectEqual(@as(u8, 0), pane.msg_older_len); + try std.testing.expectEqualStrings("second", pane.msg[0..pane.msg_len]); + try std.testing.expectEqual(Pane.MessagePhase.leaving, pane.msg_life.phase); + for (0..fall) |_| 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, p.active, "lsp 10%"); + setStatus(p, p.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, p.active, "top"); + setMessage(p, p.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.rects[p.active], p.active); + try std.testing.expectEqual(@as(u8, 1), pane.notices.row[0]); + try std.testing.expectEqual(@as(u8, 2), pane.notices.span()); + setMessage(p, p.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, p.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]); +} + +test "a builtin announces itself on the message row, and Verbose silences it" { + if (platform == .web) return; + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 80, .rows = 24 }); + defer p.deinit(); + const pane = p.panes[p.active].?; + + 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. + try std.testing.expect(p.executeBuiltinLine(p.active, "Wrap")); + try std.testing.expectEqualStrings("Wrap", pane.msg[0..pane.msg_len]); + + // The notice list is what the paint pass reads, so the announcement has to + // reach it, not just the buffer. + collectNotices(p, pane, p.rects[p.active], p.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. + var frame = std.heap.ArenaAllocator.init(std.testing.allocator); + defer frame.deinit(); + _ = try p.render(frame.allocator()); + const r = p.rects[p.active]; + const band = for (p.surface.tagLayers()) |*layer| { + if (layer.cols != 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(if (p.settings.tag_bottom) r.y else 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] == ' '); + + // Msg owns the row itself, so it does not announce over its own text. + try std.testing.expect(p.executeBuiltinLine(p.active, "Msg hello")); + try std.testing.expectEqualStrings("hello", pane.msg[0..pane.msg_len]); + + pane.msg_len = 0; + p.settings.verbose = false; + try std.testing.expect(p.executeBuiltinLine(p.active, "Wrap")); + try std.testing.expectEqual(@as(u16, 0), pane.msg_len); +} + +test "notices stack over the body's top rows without moving them" { + if (platform == .web) return; + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 80, .rows = 24 }); + defer p.deinit(); + const id = p.active; + const pane = p.panes[id].?; + p.sync(); + var frame = std.heap.ArenaAllocator.init(std.testing.allocator); + defer frame.deinit(); + + const r = p.rects[id]; + const top = p.bodyTop(r); + + // A message and a leader prefix 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")); + p.leader_on = true; + p.leader_n = 0; + _ = 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(r)); + + var seen: usize = 0; + for (p.surface.tagLayers()) |*layer| { + if (layer.cols == 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); + // "first" is longer than "SPC", so its chip is wider. + try std.testing.expect(pane.notices.left[0] < pane.notices.left[1]); + + // Gone with the notices: no stale chip left behind. + p.leader_on = false; + pane.msg_len = 0; + _ = frame.reset(.retain_capacity); + _ = try p.render(frame.allocator()); + for (p.surface.tagLayers()) |*layer| + try std.testing.expect(layer.cols == 0 or layer.kind != .notice); +} diff --git a/src/Output.zig b/src/Output.zig index 00122b16..3b8100ac 100644 --- a/src/Output.zig +++ b/src/Output.zig @@ -3,6 +3,7 @@ const panes = @import("panes.zig"); const std = @import("std"); const pardes = @import("pardes.zig"); +const Messages = @import("Messages.zig"); const config = @import("config.zig"); const Pardes = pardes.Pardes; const modal = @import("modal.zig"); @@ -684,7 +685,7 @@ 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.messageLog(i)) |m| : (i += 1) { + while (Messages.messageLog(p, 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}); diff --git a/src/detached/server.zig b/src/detached/server.zig index c8d4b45e..e33354cf 100644 --- a/src/detached/server.zig +++ b/src/detached/server.zig @@ -15,7 +15,7 @@ const ninep_io = @import("../9p_io.zig"); const look = @import("../look.zig"); -const message = pardes.Pardes.Message; +const message = pardes.Messages.Message; const TIOCSWINSZ: c_int = @bitCast(@as(u32, if (@hasDecl(posix.T, "IOCSWINSZ")) posix.T.IOCSWINSZ else 0x80087467)); diff --git a/src/file_watch.zig b/src/file_watch.zig index 2d1c0d25..5d998470 100644 --- a/src/file_watch.zig +++ b/src/file_watch.zig @@ -15,7 +15,7 @@ const linux = std.os.linux; const pardes = @import("pardes.zig"); const colors = @import("colors.zig"); const filesystem = @import("fs.zig"); -const message = pardes.Pardes.Message; +const message = pardes.Messages.Message; pub const Identity = struct { inode: std.Io.File.INode, diff --git a/src/fs.zig b/src/fs.zig index 86154fc1..5817b3a4 100644 --- a/src/fs.zig +++ b/src/fs.zig @@ -38,6 +38,7 @@ const source_files = [_]Source{ .{ .path = "src/panes.zig", .contents = @embedFile("panes.zig") }, .{ .path = "src/surface.zig", .contents = @embedFile("surface.zig") }, .{ .path = "src/colors.zig", .contents = @embedFile("colors.zig") }, + .{ .path = "src/Messages.zig", .contents = @embedFile("Messages.zig") }, .{ .path = "src/File.zig", .contents = @embedFile("File.zig") }, .{ .path = "src/Output.zig", .contents = @embedFile("Output.zig") }, .{ .path = "src/Mini.zig", .contents = @embedFile("Mini.zig") }, diff --git a/src/gui/gui.zig b/src/gui/gui.zig index 6174c0d8..86c69ff6 100644 --- a/src/gui/gui.zig +++ b/src/gui/gui.zig @@ -8,7 +8,7 @@ const ghostty_vt = @import("ghostty-vt"); // 256-color palette for .index cells const pardes = @import("../pardes.zig"); const config = @import("../config.zig"); const look = @import("../look.zig"); -const message = pardes.Pardes.Message; +const message = pardes.Messages.Message; const file_watch = @import("../file_watch.zig"); const deck = @import("deck.zig"); const crt = @import("crt.zig"); diff --git a/src/macos.zig b/src/macos.zig index b4e03c13..cab8212a 100644 --- a/src/macos.zig +++ b/src/macos.zig @@ -8,7 +8,7 @@ const libc = std.c; const pardes = @import("pardes.zig"); const colors = @import("colors.zig"); const look = @import("look.zig"); -const message = pardes.Pardes.Message; +const message = pardes.Messages.Message; const layout = @import("layout.zig"); const file_watch = @import("file_watch.zig"); const image = if (pardes.pdf_enabled) @import("image.zig") else struct {}; diff --git a/src/ninep/events.zig b/src/ninep/events.zig index 8d5ba16c..0e8d7bb7 100644 --- a/src/ninep/events.zig +++ b/src/ninep/events.zig @@ -149,7 +149,7 @@ pub fn noteLog(p: *Pardes, kind: LogKind, pane: *Pane) void { /// Records `msg ` for what the editor said, `-` for no pane. pub fn noteMessage(p: *Pardes, serial: u32, text: []const u8) void { - var buf: [pardes.LoggedMessage.cap + 32]u8 = undefined; + var buf: [pardes.Messages.LoggedMessage.cap + 32]u8 = undefined; pushLog(p, (if (serial == 0) std.fmt.bufPrint(&buf, "msg - {s}\n", .{text}) else diff --git a/src/pardes.zig b/src/pardes.zig index 6fefe081..c171c669 100644 --- a/src/pardes.zig +++ b/src/pardes.zig @@ -11,6 +11,7 @@ pub const syntax = @import("syntax.zig"); pub const locations_config = @import("locations_config.zig"); const tracy = @import("tracy.zig"); pub const panes = @import("panes.zig"); +pub const Messages = @import("Messages.zig"); pub const colors = @import("colors.zig"); pub const Theme = colors.Theme; pub const themes = colors.themes; @@ -430,6 +431,7 @@ pub const Loc = struct { }; test { + _ = @import("Messages.zig"); _ = @import("selection_pipe.zig"); _ = @import("colors.zig"); _ = @import("surface.zig"); @@ -637,49 +639,6 @@ test "gj/gk step the wrapped rows a body draws while j/k keep the file's lines" try std.testing.expectEqual(@as(i32, 1), pane.cur_row); } -test "the message log keeps what the row forgets, and collapses repeats" { - const gpa = std.testing.allocator; - const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 100, .rows = 30 }); - defer p.deinit(); - - p.setMessage(0, "14:32:07 saved /x.zig"); - p.setMessage(0, "14:32:09 saved /x.zig"); // same event, later clock - p.setMessage(0, "save: AccessDenied"); - - try std.testing.expectEqual(@as(usize, 2), p.messages_len); - const first = p.messageLog(0).?; - try std.testing.expectEqual(@as(u16, 2), first.repeats); - // ...and the NEWEST wording is what survives, so the row carries the last - // time it happened rather than the first. - try std.testing.expectEqualStrings("14:32:09 saved /x.zig", first.slice()); - try std.testing.expectEqualStrings("save: AccessDenied", p.messageLog(1).?.slice()); - try std.testing.expect(p.messageLog(2) == null); - - // The same text from a DIFFERENT pane is a different event: one pane's - // failure must not be recorded as another's. - p.newScratchBelow(0); - const other = p.active; - p.setMessage(other, "save: AccessDenied"); - try std.testing.expectEqual(@as(usize, 3), p.messages_len); - try std.testing.expectEqual(p.panes[other].?.serial, p.messageLog(2).?.serial); - - // Progress is NOT logged: it arrives several times a second for a whole - // index and would push everything else out (`setStatus`). - p.setStatus(0, "14:32:10 lsp rust-analyzer: Indexing 47%"); - try std.testing.expectEqual(@as(usize, 3), p.messages_len); - - // The ring wraps rather than grows, and still reads oldest-first. - for (0..limits.message_log + 5) |i| { - var buf: [32]u8 = undefined; - p.setMessage(0, std.fmt.bufPrint(&buf, "line {d}", .{i}) catch unreachable); - } - try std.testing.expectEqual(@as(usize, limits.message_log), p.messages_len); - try std.testing.expectEqualStrings("line 5", p.messageLog(0).?.slice()); - var last_buf: [32]u8 = undefined; - const want_last = std.fmt.bufPrint(&last_buf, "line {d}", .{limits.message_log + 4}) catch unreachable; - try std.testing.expectEqualStrings(want_last, p.messageLog(limits.message_log - 1).?.slice()); -} - test "the acme chords act once per selection, not once on the primary" { const gpa = std.testing.allocator; const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 100, .rows = 30 }); @@ -2332,216 +2291,6 @@ test "a builtin that needs a pane reports capacity failure when every slot is fu try std.testing.expect(std.mem.indexOf(u8, p.panes[0].?.msg[0..p.panes[0].?.msg_len], "help: NoPaneSlots") != null); } -test "Msg writes the transient row by hand, bare or with text, and input ends it" { - 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)); - - // Bare, it reports ITSELF through reportError — the `: ` - // every failed save and refused Look arrives in. - try std.testing.expect(p.executeBuiltinLine(2, "Msg")); - try std.testing.expectEqualStrings("Msg: NoMessage", row(p, 2)); - - // Input starts its exit: it lingers, dissolves, and is gone. - p.update(.{ .key = .{ .cp = Key.escape } }); - try std.testing.expectEqualStrings("Msg: NoMessage", row(p, 2)); - for (0..200) |_| p.update(.tick); - try std.testing.expectEqualStrings("", row(p, 2)); - // ...and with neither linger nor animation it is as old as your last input. - try std.testing.expect(p.executeBuiltinLine(2, "MessageAnimation off")); - try std.testing.expect(p.executeBuiltinLine(2, "MessageLinger 0")); - try std.testing.expect(p.executeBuiltinLine(2, "Msg gone")); - p.update(.{ .key = .{ .cp = 'h' } }); - try std.testing.expectEqualStrings("", row(p, 2)); - - // Longer than the row's buffer 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); -} - -test "a message falls in, lingers past the input that dismisses it, and dissolves" { - 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.active].?; - try std.testing.expect(p.settings.message_animation); - try std.testing.expect(p.executeBuiltinLine(p.active, "MessageLinger 160")); - try std.testing.expect(p.executeBuiltinLine(p.active, "Msg hello")); - try std.testing.expectEqual(Pane.MessagePhase.entering, pane.msg_life.phase); - try std.testing.expect(p.animationActive()); - // An ease-out fall: starts a whole row up and unseen, covers most of the - // way at once and settles into its row, landing exactly on it without - // passing it. Its colour is whole by half way. - const start = p.messageMotion(pane.msg_life); - try std.testing.expectEqual(@as(f32, -1), start.slide); - try std.testing.expectEqual(@as(f32, 0), start.alpha); - const fall = Pardes.messageFrames(p.settings.message_fall_ms); - var last = start; - var first_step: f32 = 0; - var last_step: f32 = 0; - for (0..fall) |frame| { - p.needs_frame = false; - p.update(.tick); - // Every tick that moves it owes a frame, the landing one included. - try std.testing.expect(p.needs_frame); - const now = p.messageMotion(pane.msg_life); - try std.testing.expect(now.slide >= last.slide and now.slide <= 0); - try std.testing.expect(now.alpha >= last.alpha); - if (frame == 0) first_step = now.slide - last.slide; - // Never slower to colour up than to arrive, and solid by half way. - try std.testing.expect(now.alpha >= 1 + now.slide); - if (2 * (frame + 1) >= fall) try std.testing.expectEqual(@as(f32, 1), now.alpha); - last_step = now.slide - last.slide; - last = now; - } - try std.testing.expect(first_step > 4 * last_step); - try std.testing.expectEqual(Pane.MessagePhase.shown, pane.msg_life.phase); - try std.testing.expectEqual(@as(f32, 0), p.messageMotion(pane.msg_life).slide); - try std.testing.expect(!p.animationActive()); - // Shown until input, like always; the same line again does not re-enter. - for (0..100) |_| p.update(.tick); - try std.testing.expectEqual(Pane.MessagePhase.shown, pane.msg_life.phase); - try std.testing.expect(p.executeBuiltinLine(p.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 std.testing.expectEqual(Pane.MessagePhase.lingering, pane.msg_life.phase); - p.update(.tick); - // ...then an ease-in dissolve: it lets go slowly and goes faster and - // faster, in place, its last frame showing it gone. - try std.testing.expectEqual(Pane.MessagePhase.leaving, pane.msg_life.phase); - const dissolve = Pardes.messageFrames(p.settings.message_dissolve_ms); - var alpha: f32 = 1; - var first_drop: f32 = 0; - var last_drop: f32 = 0; - for (0..dissolve) |frame| { - const now = p.messageMotion(pane.msg_life); - try std.testing.expect(now.alpha <= alpha); - try std.testing.expectEqual(@as(f32, 0), now.slide); - if (frame == 1) first_drop = alpha - now.alpha; - last_drop = alpha - now.alpha; - alpha = now.alpha; - p.needs_frame = false; - p.update(.tick); - } - try std.testing.expectEqual(@as(f32, 0), alpha); - try std.testing.expect(first_drop > 0 and first_drop < last_drop); - try std.testing.expectEqual(@as(u16, 0), pane.msg_len); - try std.testing.expect(!p.animationActive()); - // The tick that clears it still owes the frame that shows it gone. - try std.testing.expect(p.needs_frame); - - // Dismissed mid-fall: it lands, then lingers. - try std.testing.expect(p.executeBuiltinLine(p.active, "Msg again")); - try std.testing.expectEqual(Pane.MessagePhase.entering, pane.msg_life.phase); - p.update(.tick); - p.update(.{ .key = .{ .cp = 'h' } }); - try std.testing.expectEqual(Pane.MessagePhase.entering, pane.msg_life.phase); - for (0..Pardes.messageFrames(p.settings.message_fall_ms)) |_| p.update(.tick); - try std.testing.expectEqual(Pane.MessagePhase.lingering, pane.msg_life.phase); - // Shown again while lingering: fresh, so it stays; a status update to a - // line on screen swaps its text in place instead of falling again. - try std.testing.expect(p.executeBuiltinLine(p.active, "Msg again")); - try std.testing.expectEqual(Pane.MessagePhase.shown, pane.msg_life.phase); - p.setStatus(p.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); - // The fall and the dissolve are timings of their own, in milliseconds. - try std.testing.expect(p.executeBuiltinLine(p.active, "MessageFall 48")); - try std.testing.expect(p.executeBuiltinLine(p.active, "MessageDissolve 0")); - try std.testing.expectEqual(@as(u16, 3), Pardes.messageFrames(p.settings.message_fall_ms)); - try std.testing.expectEqual(@as(u16, 1), Pardes.messageFrames(p.settings.message_dissolve_ms)); - // The Config report reads back as configuration. - try std.testing.expect(p.executeBuiltinLine(p.active, "MessageAnimation")); - try std.testing.expect(!p.settings.message_animation); - try std.testing.expect(p.executeBuiltinLine(p.active, "Msg plain")); - try std.testing.expectEqual(Pane.MessagePhase.shown, pane.msg_life.phase); -} - -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.active].?; - try std.testing.expect(p.executeBuiltinLine(p.active, "Verbose off")); - try std.testing.expect(p.executeBuiltinLine(p.active, "MessageLinger 160")); - // `Verbose off` announced itself before it took effect. - pane.msg_len = 0; - pane.msg_life = .{}; - const fall = Pardes.messageFrames(p.settings.message_fall_ms); - p.setMessage(p.active, "first"); - for (0..fall) |_| p.update(.tick); - try std.testing.expectEqual(Pane.MessagePhase.shown, pane.msg_life.phase); - // A second message stacks under the first instead of replacing it. - p.setMessage(p.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]); - try std.testing.expectEqual(Pane.MessagePhase.entering, pane.msg_life.phase); - p.collectNotices(pane, p.rects[p.active], p.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, but each runs its own clock: the first starts - // lingering now, the second only once it has landed. - p.update(.{ .key = .{ .cp = 'h' } }); - try std.testing.expectEqual(Pane.MessagePhase.lingering, pane.msg_older[0].life.phase); - try std.testing.expectEqual(Pane.MessagePhase.entering, pane.msg_life.phase); - const linger = Pardes.messageFrames(p.settings.message_linger_ms); - const dissolve = Pardes.messageFrames(p.settings.message_dissolve_ms); - for (0..linger + dissolve) |_| p.update(.tick); - // The first is gone; the second, a fall later, is still dissolving. - try std.testing.expectEqual(@as(u8, 0), pane.msg_older_len); - try std.testing.expectEqualStrings("second", pane.msg[0..pane.msg_len]); - try std.testing.expectEqual(Pane.MessagePhase.leaving, pane.msg_life.phase); - for (0..fall) |_| 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. - p.setStatus(p.active, "lsp 10%"); - p.setStatus(p.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. - p.setMessage(p.active, "top"); - p.setMessage(p.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); - p.collectNotices(pane, p.rects[p.active], p.active); - try std.testing.expectEqual(@as(u8, 1), pane.notices.row[0]); - try std.testing.expectEqual(@as(u8, 2), pane.notices.span()); - p.setMessage(p.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| p.setMessage(p.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]); -} - test "Font keeps requested and acknowledged faces as separate plain state" { if (comptime !font_picker) return; // there is no Font builtin on tty or web const p = try Pardes.init(std.testing.allocator, .{ .cols = 80, .rows = 24 }); @@ -4851,23 +4600,6 @@ pub const Options = struct { rows: u16 = 24, }; -pub const LoggedMessage = struct { - pub const cap = 256; - text: [cap]u8 = undefined, - len: u16 = 0, - /// The serial of the pane that said it, or 0 for none in particular. A - /// serial, not a slot: slots are reused, so an old line would name - /// whichever pane took the slot since. - serial: u32 = 0, - /// How many times in a row. Saturating: a key held down against the same - /// refusal is one event, not four hundred. - repeats: u16 = 0, - - pub fn slice(m: *const LoggedMessage) []const u8 { - return m.text[0..m.len]; - } -}; - pub const Haptic = enum { none, exec, look }; /// Zero-sized off macOS, the way PdfSlot is off -Dmupdf: no other shell reads @@ -5035,7 +4767,7 @@ pub const Pardes = struct { fallback: host_io.Fallback, /// The message-row log: a fixed ring, never allocated, never grown. See /// `logMessage` and the `Messages` builtin. - messages: [limits.message_log]LoggedMessage = @splat(.{}), + messages: [limits.message_log]Messages.LoggedMessage = @splat(.{}), /// Next slot to write. `messages_len` saturates at the ring's size. messages_head: usize = 0, messages_len: usize = 0, @@ -5067,6 +4799,12 @@ pub const Pardes = struct { /// for — see panes.Terminal.RowsCache for the lifetime rule shell_rows: panes.Terminal.RowsCache = .{}, + /// The message row's entry points, called from everywhere as + /// `p.setMessage(...)`; they live with the rest of it in Messages.zig. + pub const setStatus = Messages.setStatus; + pub const setMessage = Messages.setMessage; + pub const reportError = Messages.reportError; + pub fn init(gpa: std.mem.Allocator, opts: Options) !*Pardes { const image_gpa = opts.image_allocator orelse gpa; const pdf_gpa = opts.pdf_allocator orelse gpa; @@ -5177,60 +4915,6 @@ pub const Pardes = struct { return p; } - /// `SPC` plus the chord keys typed so far, spaced out the way the help - /// index spells a leader path. - fn leaderText(p: *const Pardes, buf: *[16]u8) []const u8 { - buf.* = @splat(' '); - @memcpy(buf[0..3], "SPC"); - var at: usize = 3; - for (p.leader_keys[0..p.leader_n]) |ch| { - if (at + 2 > buf.len) break; - buf[at + 1] = ch; - at += 2; - } - return buf[0..at]; - } - - /// How wide a notice chip is, in grid columns: its own text plus a blank - /// cell either side. A notice is an OVERLAY over the body's top rows, not - /// a row taken from them, so it is sized to its message and never to the - /// pane. Counted in GRID columns rather than scaled into the tagline face - /// it is drawn in, because the canonical grid is what a terminal client - /// draws and a chip narrower than its own text there would clip it; the - /// tagline face simply leaves a little more room inside the chip. - fn noticeCols(p: *const Pardes, text: []const u8, limit: u16) u16 { - _ = p; - if (limit == 0) return 0; - return @intCast(std.math.clamp(panes.File.displayWidth(text) + 2, 1, @as(usize, limit))); - } - - const Printed = struct { left: u16, dropped: usize }; - - /// Prints `text` flush with the right edge of the band, and answers the - /// column it started at so a cursor can follow it. Text wider than the - /// band loses its HEAD: the end is the part that says something -- a - /// path's file name, an error's reason -- and `dropped` is how many - /// columns of it went. - fn printRight(s: *Surface, x: u16, row: u16, w: u16, text: []const u8, style: CellStyle) Printed { - const width = panes.File.displayWidth(text); - if (width <= w) { - const left: u16 = @intCast(x + w - width); - _ = s.print(left, row, @intCast(width), text, style); - return .{ .left = left, .dropped = 0 }; - } - // Whole glyphs only: a cut inside a wide one would leave the rest a - // column too wide and clip its LAST glyph instead of the first. - var dropped = width - w; - var start = panes.File.rawAtDisplay(text, dropped); - if (panes.File.rawDisplayCol(text, start) < dropped) { - dropped += 1; - start = panes.File.rawAtDisplay(text, dropped); - } - const left: u16 = @intCast(x + w - (width - dropped)); - _ = s.print(left, row, @intCast(width - dropped), text[start..], style); - return .{ .left = left, .dropped = dropped }; - } - /// The layout every single-pane boot starts from. fn oneColumn(p: *Pardes) void { p.ncol = 1; @@ -5654,297 +5338,6 @@ pub const Pardes = struct { p.font_request_taken = false; } - pub const Message = struct { - const libc = std.c; - const Tm = extern struct { - sec: c_int, - min: c_int, - hour: c_int, - mday: c_int, - mon: c_int, - year: c_int, - wday: c_int, - yday: c_int, - isdst: c_int, - gmtoff: c_long, - zone: ?[*:0]const u8, - }; - extern "c" fn localtime_r(timep: *const libc.time_t, result: *Tm) ?*Tm; - - pub fn body(text: []const u8) []const u8 { - if (text.len < 10) return text; - if (text[2] != ':' or text[5] != ':' or text[8] != ' ' or text[9] != ' ') return text; - for ([_]usize{ 0, 1, 3, 4, 6, 7 }) |i| { - if (!std.ascii.isDigit(text[i]) and text[i] != '-') return text; - } - return text[10..]; - } - - pub fn stamp(buf: []u8, verb: []const u8, subject: []const u8) []const u8 { - var clock: [8]u8 = "--:--:--".*; - const notime = if (libc.getenv("PARDES_NOTIME")) |v| std.mem.span(v).len != 0 else false; - if (!notime) { - var ts: libc.timespec = undefined; - _ = libc.clock_gettime(.REALTIME, &ts); - const secs: libc.time_t = ts.sec; - var tm: Tm = undefined; - if (localtime_r(&secs, &tm) != null) { - _ = std.fmt.bufPrint(&clock, "{d:0>2}:{d:0>2}:{d:0>2}", .{ - @as(u32, @intCast(tm.hour)), - @as(u32, @intCast(tm.min)), - @as(u32, @intCast(tm.sec)), - }) catch {}; - } - } - const head = std.fmt.bufPrint(buf, "{s} {s} ", .{ &clock, verb }) catch return buf[0..0]; - const room = buf.len - head.len; - const tail = if (subject.len <= room) subject else subject[subject.len - room ..]; - @memcpy(buf[head.len..][0..tail.len], tail); - return buf[0 .. head.len + tail.len]; - } - }; - - /// A status updates the message line in place (a progress count does not - /// pile up); a message is an event, and stacks. - pub fn setStatus(p: *Pardes, id: usize, text: []const u8) void { - p.showMessage(id, text, false); - } - - pub fn setMessage(p: *Pardes, id: usize, text: []const u8) void { - p.logMessage(id, text); - p.showMessage(id, text, true); - } - - fn showMessage(p: *Pardes, id: usize, text: []const u8, stack: bool) void { - if (id >= MAX_PANES) return; - const pane = p.panes[id] orelse return; - // 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); - 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_status = !stack; - const arrives = pane.msg_len == 0 or pane.msg_life.phase == .leaving; - for (text[0..n], pane.msg[0..n]) |c, *cell| cell.* = if (c < 0x20 or c == 0x7f) ' ' else c; - pane.msg_len = @intCast(n); - p.needs_frame = true; - if (arrives) { - pane.msg_life = .{ .phase = if (p.settings.message_animation and n > 0) .entering else .shown }; - } else if (pane.msg_life.phase == .lingering or - (pane.msg_life.phase == .entering and !p.settings.message_animation)) - { - // The same line again, or a status update: fresh, so it stays. - pane.msg_life = .{}; - } else { - pane.msg_life.dismissed = false; - } - } - - /// The key or click that used to clear the message row now starts each - /// line's exit: it stays `message_linger_ms`, then dissolves. A line - /// already on its way out keeps its own timing. - fn dismissMessage(p: *Pardes, pane: *Pane) void { - if (pane.msg_len > 0 and p.dismissLine(&pane.msg_life)) { - pane.msg_len = 0; - pane.msg_life = .{}; - } - var i: usize = 0; - while (i < pane.msg_older_len) { - if (p.dismissLine(&pane.msg_older[i].life)) pane.removeOlderMessage(i) else i += 1; - } - } - - /// Start one line's exit; true when it is gone at once (no linger, no - /// animation). - fn dismissLine(p: *const Pardes, life: *Pane.MessageLife) bool { - switch (life.phase) { - .lingering, .leaving => return false, - // A falling line lands first, then lingers -- unless falling was - // just turned off, and nothing will land it. - .entering => if (p.settings.message_animation) { - life.dismissed = true; - return false; - }, - .shown => {}, - } - life.frame = 0; - if (p.settings.message_linger_ms > 0) { - life.phase = .lingering; - } else if (p.settings.message_animation) { - life.phase = .leaving; - } else return true; - return false; - } - - /// One animation frame of every message line. Each one that moves owes - /// a frame, the one that finishes included: a tick asks for none itself. - 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 (p.advanceLine(&pane.msg_life)) { - pane.msg_len = 0; - pane.msg_life = .{}; - } - } - var i: usize = 0; - while (i < pane.msg_older_len) { - if (pane.msg_older[i].life.phase != .shown) p.needs_frame = true; - if (p.advanceLine(&pane.msg_older[i].life)) pane.removeOlderMessage(i) else i += 1; - } - } - } - - /// One frame of one line's life; true once it has left. - fn advanceLine(p: *const Pardes, life: *Pane.MessageLife) bool { - if (life.phase == .shown) return false; - life.frame +|= 1; - switch (life.phase) { - .shown => {}, - .entering => if (life.frame >= messageFrames(p.settings.message_fall_ms)) { - life.* = .{ .phase = if (life.dismissed) .lingering else .shown }; - }, - .lingering => if (life.frame >= messageFrames(p.settings.message_linger_ms)) { - if (!p.settings.message_animation) return true; - life.* = .{ .phase = .leaving }; - }, - .leaving => if (life.frame >= messageFrames(p.settings.message_dissolve_ms)) return true, - } - return false; - } - - /// Is any message line moving (and so owed ticks)? - fn messagesAnimating(pane: *const Pane) bool { - if (pane.msg_len > 0 and pane.msg_life.phase != .shown) return true; - for (pane.msg_older[0..pane.msg_older_len]) |line| if (line.life.phase != .shown) return true; - return false; - } - - /// How present a message is (1 = fully) and how far above its row it - /// still is (rows): a fall that decelerates into place with its colour - /// arriving ahead of it, and a dissolve. - const MessageMotion = struct { alpha: f32 = 1, slide: f32 = 0 }; - - /// Animation frames a message timing lasts; at least one. - pub fn messageFrames(ms: u16) u16 { - return @intCast(@max(1, (@as(u32, ms) + layout.Animation.frame_ms - 1) / layout.Animation.frame_ms)); - } - - fn messageMotion(p: *const Pardes, life: Pane.MessageLife) MessageMotion { - const fall_frames = messageFrames(p.settings.message_fall_ms); - const dissolve_frames = messageFrames(p.settings.message_dissolve_ms); - return switch (life.phase) { - .shown, .lingering => .{ .alpha = 1, .slide = 0 }, - .entering => blk: { - const t = @as(f32, @floatFromInt(@min(life.frame, fall_frames))) / @as(f32, @floatFromInt(fall_frames)); - // Out of the gate fast and easing into its row (a cubic - // ease-out), so it is there the moment it is said and the - // last frames only settle it. No overshoot: at a row's height - // and a dozen frames, a follow-through is a pixel or two that - // reads as a jitter, not a bounce. - const left = 1 - t; - // The colour leads the motion: solid by half way, so what - // lands is already legible rather than still fading up. - const faded = 1 - @min(1, 2 * t); - break :blk .{ .alpha = 1 - faded * faded, .slide = -(left * left * left) }; - }, - .leaving => blk: { - // Counted to its last frame rather than past it, so that frame - // shows it gone and it never blinks out from part way. - const last = @max(1, dissolve_frames - 1); - const t = @as(f32, @floatFromInt(@min(life.frame, last))) / @as(f32, @floatFromInt(last)); - // An exit eases in: still readable for a beat, then away - // faster and faster. It stays where it is -- the lines - // stacked around it do not move either. - break :blk .{ .alpha = 1 - t * t, .slide = 0 }; - }, - }; - } - - /// 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. - fn noticeText(p: *const Pardes, pane: *const Pane, i: usize, leader_buf: *[16]u8) []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 => p.leaderText(leader_buf), - .prompt => pane.promptText() orelse "", - }; - } - - /// The life of the message line notice `i` shows, if it shows one. - fn noticeLife(pane: *const Pane, i: usize) ?Pane.MessageLife { - return switch (pane.notices.kinds[i]) { - .message => pane.msg_life, - .older => pane.msg_older[pane.notices.index[i]].life, - .leader, .prompt => null, - }; - } - - fn blendRgb(from: [3]u8, to: [3]u8, amount: f32) [3]u8 { - var out: [3]u8 = undefined; - for (&out, from, to) |*o, a, b| { - const af: f32 = @floatFromInt(a); - const bf: f32 = @floatFromInt(b); - o.* = @intFromFloat(@round(bf + (af - bf) * std.math.clamp(amount, 0, 1))); - } - return out; - } - - fn logMessage(p: *Pardes, id: usize, text: []const u8) void { - if (text.len == 0) return; - const serial: u32 = if (id < MAX_PANES) if (p.panes[id]) |pane| pane.serial else 0 else 0; - const kept = text[0..@min(text.len, LoggedMessage.cap)]; - // /log hears every one: a client that retried and failed the same way - // is waiting on that second line. Only the +Messages view collapses. - ctlfs.events.noteMessage(p, serial, kept); - if (p.messages_len > 0) { - const last = &p.messages[(p.messages_head + limits.message_log - 1) % limits.message_log]; - if (last.serial == serial and - std.mem.eql(u8, Message.body(last.slice()), Message.body(kept))) - { - // The NEWEST wording wins, so the row carries the latest clock - // rather than the moment the run started. - last.len = @intCast(kept.len); - @memcpy(last.text[0..last.len], kept); - last.repeats +|= 1; - return; - } - } - const slot = &p.messages[p.messages_head]; - slot.len = @intCast(kept.len); - @memcpy(slot.text[0..slot.len], kept); - slot.serial = serial; - slot.repeats = 1; - p.messages_head = (p.messages_head + 1) % limits.message_log; - p.messages_len = @min(p.messages_len + 1, limits.message_log); - } - - /// The log oldest-first, which is reading order. - pub fn messageLog(p: *const Pardes, i: usize) ?*const LoggedMessage { - if (i >= p.messages_len) return null; - const first = (p.messages_head + limits.message_log - p.messages_len) % limits.message_log; - return &p.messages[(first + i) % limits.message_log]; - } - pub fn reportError(p: *Pardes, id: usize, operation: []const u8, err: anyerror) void { - var buf: [256]u8 = undefined; - const text = std.fmt.bufPrint(&buf, "{s}: {s}", .{ operation, @errorName(err) }) catch operation; - p.setMessage(id, text); - } - fn applyWatchedFileChanged(p: *Pardes, id: u8, bytes: []const u8) bool { if (id >= MAX_PANES) return false; const pane = p.panes[id] orelse return false; @@ -6268,11 +5661,11 @@ pub const Pardes = struct { switch (ev) { .key, .mouse => { for (p.panes) |slot| { - if (slot) |pane| p.dismissMessage(pane); + if (slot) |pane| Messages.dismissMessage(p, pane); } p.clip_pending = null; }, - .tick => p.advanceMessages(), + .tick => Messages.advanceMessages(p), else => {}, } if (p.fs.listeners != 0) p.fs.origin = switch (ev) { @@ -12199,7 +11592,7 @@ pub const Pardes = struct { pub fn animationActive(p: *const Pardes) bool { if (p.chrome_animation.isActive() or p.look_hover_wait != null) return true; for (p.panes) |slot| if (slot) |pane| { - if (messagesAnimating(pane)) return true; + if (Messages.messagesAnimating(pane)) return true; }; const scene = p.settings.scene_effects; if (scene.crt or scene.ripple or scene.glitch) return true; @@ -12305,7 +11698,7 @@ pub const Pardes = struct { pane.body_visible_rows = 0; pane.context_row_limit = null; s.body_layers[id].rows = 0; - p.collectNotices(pane, p.rects[id], id); + Messages.collectNotices(p, pane, p.rects[id], id); try p.renderPane(arena, pane, p.rects[id], id, id == p.active); try p.renderBodyLayer(arena, pane, p.rects[id], id); } @@ -12338,21 +11731,21 @@ pub const Pardes = struct { // draws, and a band it cannot see is a message it never gets. // The GUI skips grid cells a tag layer covers, so nothing is // drawn twice there. - const text = p.noticeText(pane, i, &leader_buf); - const chip = p.noticeCols(text, tw); + const text = Messages.noticeText(p, pane, i, &leader_buf); + const chip = Messages.noticeCols(p, text, tw); if (chip == 0) continue; const cx = tx + tw - chip; pane.notices.left[i] = cx; // A message coming or going blends toward the page it sits // on; a grid cannot move it by less than a row. var style = msg_style; - if (noticeLife(pane, i)) |life| { + if (Messages.noticeLife(pane, i)) |life| { // No page colour to fade to (a terminal's own default): // the text dissolves into its chip instead. - const alpha = p.messageMotion(life).alpha; + const alpha = Messages.messageMotion(p, life).alpha; const page = th.bg orelse chrome.tag_bg; - style.fg = .{ .rgb = blendRgb(chrome.tag_fg, page, alpha) }; - style.bg = .{ .rgb = blendRgb(chrome.tag_bg, page, alpha) }; + style.fg = .{ .rgb = Messages.blendRgb(chrome.tag_fg, page, alpha) }; + style.bg = .{ .rgb = Messages.blendRgb(chrome.tag_bg, page, alpha) }; } s.fill(cx, row, chip, 1, .{ .bg = style.bg, .font_role = .tagline }); // One column short of the chip's right edge: a prompt's caret @@ -12360,7 +11753,7 @@ pub const Pardes = struct { // right would put it past the pane, off the grid, and past what // the detached wire will encode -- which drops every frame for // as long as the prompt is up. - const printed = printRight(s, cx, row, chip -| 1, text, style); + const printed = Messages.printRight(s, cx, row, chip -| 1, text, style); if (kind != .prompt or id != p.active) continue; const at = pane.promptAt() orelse continue; const prompt0 = (p.tagPrefix(pane) catch continue).len + at; @@ -12867,7 +12260,7 @@ pub const Pardes = struct { const first = p.bodyTop(r); var leader_buf: [16]u8 = undefined; for (pane.notices.slice(), 0..) |kind, i| { - const text = p.noticeText(pane, i, &leader_buf); + const text = Messages.noticeText(p, pane, i, &leader_buf); if (text.len == 0) continue; const cx = pane.notices.left[i]; if (cx == std.math.maxInt(u16) or cx >= r.x + r.w) continue; @@ -12889,7 +12282,7 @@ pub const Pardes = struct { @memcpy(line[pad..], kept); // A pixel shell slides the message in as it fades up, and // fades it on the way out. - const motion: MessageMotion = if (noticeLife(pane, i)) |life| p.messageMotion(life) else .{}; + const motion: Messages.MessageMotion = if (Messages.noticeLife(pane, i)) |life| Messages.messageMotion(p, life) else .{}; const fade = motion.alpha; const page = p.theme().bg orelse chrome.tag_bg; const layer_index = NOTICE_LAYER_BASE + id * Pane.Notices.max + i; @@ -12898,7 +12291,7 @@ pub const Pardes = struct { .y = first + @as(u16, pane.notices.row[i]), .w = chip, .h = BOX_H, - }, line, blendRgb(chrome.tag_bg, page, fade), blendRgb(chrome.tag_fg, page, fade)); + }, line, Messages.blendRgb(chrome.tag_bg, page, fade), Messages.blendRgb(chrome.tag_fg, page, fade)); p.surface.tag_layers[layer_index].slide = motion.slide; p.surface.tag_layers[layer_index].fade = fade; // The caret rides the band, where the prompt's glyphs are, @@ -12980,47 +12373,6 @@ pub const Pardes = struct { } } - /// 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. - fn collectNotices(p: *Pardes, pane: *Pane, r: Rect, id: usize) void { - pane.notices.len = 0; - if (r.w <= config.GUTTER or r.h <= BOX_H) return; - // 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| pane.notices.pushAt(.older, @intCast(i), line.slot); - if (pane.msg_len > 0) pane.notices.pushAt(.message, 0, pane.msg_slot); - if (id == p.active and p.leader_on) pane.notices.push(.leader); - if (pane.promptText()) |text| if (text.len > 0) pane.notices.push(.prompt); - // A pane only has so many rows to give. When they do not all fit the - // LAST ones survive, because the prompt is last and it is the one - // carrying the cursor: a prompt you cannot see is a prompt you type - // 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 - BOX_H)); - const n = &pane.notices; - if (n.span() <= room) return; - // 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| { - n.kinds[k] = n.kinds[k + drop]; - n.index[k] = n.index[k + drop]; - n.row[k] = @intCast(k); - } - n.len -= @intCast(drop); - } - fn renderBodyLayer(p: *Pardes, arena: std.mem.Allocator, pane: *Pane, r: Rect, id: usize) !void { if (!p.settings.tree_context_tag_style or pane.context_rows == 0 or pane.file == null or pane.collapsed) return; if (r.w <= config.GUTTER or r.h <= BOX_H) return; @@ -13683,102 +13035,6 @@ test "Esc back into a tty leaves its view at the prompt" { try std.testing.expectEqual(live, sp.terminal.?.vt.screens.active.pages.scrollbar().offset); } -test "a builtin announces itself on the message row, and Verbose silences it" { - if (platform == .web) return; - const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 80, .rows = 24 }); - defer p.deinit(); - const pane = p.panes[p.active].?; - - 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. - try std.testing.expect(p.executeBuiltinLine(p.active, "Wrap")); - try std.testing.expectEqualStrings("Wrap", pane.msg[0..pane.msg_len]); - - // The notice list is what the paint pass reads, so the announcement has to - // reach it, not just the buffer. - p.collectNotices(pane, p.rects[p.active], p.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. - var frame = std.heap.ArenaAllocator.init(std.testing.allocator); - defer frame.deinit(); - _ = try p.render(frame.allocator()); - const r = p.rects[p.active]; - const band = for (p.surface.tagLayers()) |*layer| { - if (layer.cols != 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(if (p.settings.tag_bottom) r.y else 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] == ' '); - - // Msg owns the row itself, so it does not announce over its own text. - try std.testing.expect(p.executeBuiltinLine(p.active, "Msg hello")); - try std.testing.expectEqualStrings("hello", pane.msg[0..pane.msg_len]); - - pane.msg_len = 0; - p.settings.verbose = false; - try std.testing.expect(p.executeBuiltinLine(p.active, "Wrap")); - try std.testing.expectEqual(@as(u16, 0), pane.msg_len); -} - -test "notices stack over the body's top rows without moving them" { - if (platform == .web) return; - const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 80, .rows = 24 }); - defer p.deinit(); - const id = p.active; - const pane = p.panes[id].?; - p.sync(); - var frame = std.heap.ArenaAllocator.init(std.testing.allocator); - defer frame.deinit(); - - const r = p.rects[id]; - const top = p.bodyTop(r); - - // A message and a leader prefix 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")); - p.leader_on = true; - p.leader_n = 0; - _ = 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(r)); - - var seen: usize = 0; - for (p.surface.tagLayers()) |*layer| { - if (layer.cols == 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); - // "first" is longer than "SPC", so its chip is wider. - try std.testing.expect(pane.notices.left[0] < pane.notices.left[1]); - - // Gone with the notices: no stale chip left behind. - p.leader_on = false; - pane.msg_len = 0; - _ = frame.reset(.retain_capacity); - _ = try p.render(frame.allocator()); - for (p.surface.tagLayers()) |*layer| - try std.testing.expect(layer.cols == 0 or layer.kind != .notice); -} - test "a prompt chip is a band with its caret, still on the grid, and only the chip swallows a click" { if (platform == .web) return; const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 80, .rows = 24 }); diff --git a/src/tty/tty.zig b/src/tty/tty.zig index 751bc42e..89a476f2 100644 --- a/src/tty/tty.zig +++ b/src/tty/tty.zig @@ -7,7 +7,7 @@ const vaxis = @import("vaxis"); const pardes = @import("../pardes.zig"); const tracy = @import("../tracy.zig"); const look = @import("../look.zig"); -const message = pardes.Pardes.Message; +const message = pardes.Messages.Message; const file_watch = @import("../file_watch.zig"); const selection_pipe = @import("../selection_pipe.zig"); const ninep_io = @import("../9p_io.zig"); -- cgit v1.3 From 82551f77833a09b313bd3e58371582abd1aedcc4 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Sun, 27 Sep 2026 22:27:42 -0300 Subject: Move looking out of pardes.zig into look.zig Pure move, no behaviour change (acme keeps this in look.c): expanding the word under a click (ExpandedWord, expandedWord, expandedSel, cursorWordSel), the n/N walk (LookFrom, lookEdge, lookStand, lookWalkPanes, lookPast, wholeRowSpan, lookSpanIn, lookWalk, landLookSpot, noteLookSource, armLookWalk), search results (Search, SearchStart, submitSearch, lookFirstHit, runSearch, searchStep, jumpResult), the look-hover preview (LookHoverWait, LookHoverPreview, FileWordSpan, PdfWordPreview, invalidateLookHover, cancelLookHover, lookHoverPane, noteLookHover, refreshLookHoverFromRaw, advanceLookHover) and lookAt with its targets (focusPaneLine, selectSpan, openPaneTarget, focusPaneByPath, clearNavigationSelection, resolveLookTarget, locationText, canonicalLookLocation, pdfLinkLocation, followPdfLink), with five tests, go verbatim to the end of look.zig after its word and target resolution. The methods become free functions taking `p: *Pardes`; their 143 call sites change from `p.lookAt(..)` to `look.lookAt(p, ..)` (tests reach them as `pardes.look.x`). Inside look.zig the moved code's `look.` prefix drops. Co-Authored-By: Claude Opus 5.5 --- src/Output.zig | 8 +- src/builtins.zig | 11 +- src/look.zig | 1101 ++++++++++++++++++++++++++++++++++++++++++++++ src/mouse.zig | 7 +- src/ninep/ctl.zig | 3 +- src/ninep/events.zig | 3 +- src/ninep/pane.zig | 3 +- src/normal.zig | 14 +- src/pardes.zig | 1163 ++----------------------------------------------- src/pdf_view.zig | 10 +- test/fs_namespace.zig | 2 +- test/output.zig | 10 +- test/panes.zig | 10 +- test/pdf.zig | 14 +- test/perf.zig | 4 +- 15 files changed, 1198 insertions(+), 1165 deletions(-) (limited to 'src/Output.zig') diff --git a/src/Output.zig b/src/Output.zig index 3b8100ac..674fcbc8 100644 --- a/src/Output.zig +++ b/src/Output.zig @@ -431,7 +431,7 @@ pub fn fillResults(p: *Pardes, id: usize, dir: []const u8, from: Origin, arg: [] if (traits(from).steps) { pane.search_pane = i; pane.search_row = anchor; - p.armLookWalk(i); + look.armLookWalk(p, i); } return; } @@ -472,7 +472,7 @@ pub fn fillResults(p: *Pardes, id: usize, dir: []const u8, from: Origin, arg: [] if (traits(from).steps) { pane.search_pane = i; pane.search_row = anchor; - p.armLookWalk(i); + look.armLookWalk(p, i); } return; } @@ -484,7 +484,7 @@ pub fn fillResults(p: *Pardes, id: usize, dir: []const u8, from: Origin, arg: [] if (traits(from).steps) { pane.search_pane = free; pane.search_row = anchor; - p.armLookWalk(free); + look.armLookWalk(p, free); } } @@ -563,7 +563,7 @@ fn openStepped(p: *Pardes, id: usize, from: Origin, content: []u8) !void { p.active = id; pane.search_pane = free; pane.search_row = null; - p.armLookWalk(free); + look.armLookWalk(p, free); } fn helpContent(gpa: std.mem.Allocator, prefix: []const u8) ![]u8 { diff --git a/src/builtins.zig b/src/builtins.zig index 074d1328..21dd4fa9 100644 --- a/src/builtins.zig +++ b/src/builtins.zig @@ -1,6 +1,7 @@ //! Command structs and runtime settings form the builtin registry; bindings live in config.zig. const std = @import("std"); const pardes = @import("pardes.zig"); +const look = @import("look.zig"); const edit = @import("edit.zig"); const colors = @import("colors.zig"); const Pardes = pardes.Pardes; @@ -213,7 +214,7 @@ pub const Look = struct { // name on the message row would only be noise over that pub const quiet = true; pub fn run(c: Ctx) void { - c.p.lookAt(c.id, c.arg orelse return); + look.lookAt(c.p, c.id, c.arg orelse return); } }; @@ -711,7 +712,7 @@ pub const Find = struct { pub const output: OutputTraits = .{ .name = config.search_buffer, .steps = true }; pub fn run(c: Ctx) void { const pat = std.mem.trim(u8, c.arg orelse "", " \t\r\n"); - if (pat.len > 0) return c.p.runSearch(c.id, pat, .find, .top) catch |err| + if (pat.len > 0) return look.runSearch(c.p, c.id, pat, .find, .top) catch |err| c.p.reportError(c.id, "find", err); c.p.startPrompt(c.pane, .{ .search = config.find_marker }); } @@ -724,7 +725,7 @@ pub const Grep = struct { pub const output: OutputTraits = .{ .name = config.search_buffer, .steps = true, .locations = true }; pub fn run(c: Ctx) void { const pat = std.mem.trim(u8, c.arg orelse "", " \t\r\n"); - if (pat.len > 0) return c.p.runSearch(c.id, pat, .grep, .top) catch |err| + if (pat.len > 0) return look.runSearch(c.p, c.id, pat, .grep, .top) catch |err| c.p.reportError(c.id, "grep", err); c.p.startPrompt(c.pane, .{ .search = config.grep_marker }); } @@ -779,11 +780,11 @@ pub const Last = struct { i -= 1; const j = c.p.jumps[i]; // Restore the cursor without recentering the pane's retained view. - if (j.pane != c.id) return c.p.focusPaneLine(j.pane, .{ .line = j.line, .col = j.col }, .keep); + if (j.pane != c.id) return look.focusPaneLine(c.p, j.pane, .{ .line = j.line, .col = j.col }, .keep); } // Nothing on the jumplist to go back to, which is the ordinary case // for a pane that opened beside this one and was never focused. - if (c.p.neighbourPane(c.id)) |next| c.p.focusPaneLine(next, .{ .line = 0, .col = 0 }, .keep); + if (c.p.neighbourPane(c.id)) |next| look.focusPaneLine(c.p, next, .{ .line = 0, .col = 0 }, .keep); } }; diff --git a/src/look.zig b/src/look.zig index 5ebb199a..af0905a4 100644 --- a/src/look.zig +++ b/src/look.zig @@ -6,6 +6,26 @@ const config = @import("config.zig"); const pdf_enabled = @import("pardes_config").mupdf; const fs = @import("fs.zig"); const platform_has_fs = fs.platform_has_fs; +const layout = @import("layout.zig"); +const modal = @import("modal.zig"); +const filesystem = @import("fs.zig"); +const panes = @import("panes.zig"); +const mouse = @import("mouse.zig"); +const normal = @import("normal.zig"); +const edit = @import("edit.zig"); +const colors = @import("colors.zig"); +const Color = @import("surface.zig").Color; +const pdf = panes.Pdf.pdf; +const Pane = panes.Pane; +const MAX_PANES = pardes.MAX_PANES; +const TagHit = @import("tag_layer.zig").Hit; +const BOX_H = pardes.BOX_H; +const TAG_TEXT_INSET = pardes.TAG_TEXT_INSET; +const pathUnder = pardes.pathUnder; +const Mouse = pardes.Mouse; +const Key = pardes.Key; +const Event = pardes.Event; +const Pardes = pardes.Pardes; extern "c" fn fork() c_int; extern "c" fn execv(path: [*:0]const u8, argv: [*:null]const ?[*:0]const u8) c_int; @@ -353,3 +373,1084 @@ pub fn resolve(p: ?*pardes.Pardes, word_raw: []const u8, cwd: []const u8, realbu if (isImagePath(found.path)) return .{ .image = .{ .path = found.path } }; return .{ .file = .{ .path = found.path, .at = pl.at } }; } + +// ---- looking inside the editor: expanding the word under a click, the n/N +// walk over look-able text, search results, the hover preview, and lookAt, +// which opens or focuses what a word names ---- + +pub const LookHoverWait = struct { + col: u16, + row: u16, + pane: usize, + serial: u32, + frames: u16 = 0, + body_hit: ?Mouse.BodyHit = null, + tag_hit: ?TagHit = null, +}; + +pub const LookHoverPreview = struct { + col: u16, + row: u16, + pane: usize, + serial: u32, + sel: ?Pane.Sel, + file_word: ?FileWordSpan = null, + body_hit: ?Mouse.BodyHit = null, + tag_hit: ?TagHit = null, +}; + +pub const FileWordSpan = struct { + row: i32, + lo: i32, + hi: i32, // exclusive +}; + +pub const PdfWordPreview = if (pdf_enabled) struct { + col: u16, + row: u16, + pane: usize, + serial: u32, + probe: panes.Pdf.WordProbe, + + fn deinit(preview: *@This(), gpa: std.mem.Allocator) void { + preview.probe.deinit(gpa); + preview.* = undefined; + } +} else void; + +fn noteLookSource(p: *Pardes, id: usize) void { + const pane = p.panes[id] orelse return; + var w: usize = 0; + for (p.look_src[0..p.n_look_src]) |s| { + if (s == pane.serial) continue; + p.look_src[w] = s; + w += 1; + } + if (w == p.look_src.len) { + std.mem.copyForwards(u32, p.look_src[0 .. w - 1], p.look_src[1..w]); + w -= 1; + } + p.look_src[w] = pane.serial; + p.n_look_src = w + 1; + p.look_walk_owner = pane.serial; +} + +pub fn armLookWalk(p: *Pardes, id: usize) void { + const pane = p.panes[id] orelse return; + if (pane.file) |file| if (file.content.len == 0) return; + p.look_walk_owner = pane.serial; +} + +pub fn invalidateLookHover(p: *Pardes, id: usize) void { + if (lookHoverPane(p) != id) return; + p.raw_hover_intent = false; + cancelLookHover(p); +} + +const ExpandedWord = struct { lo: usize, hi: usize }; + +pub fn expandedWord(line: []const u8, col: usize) ?ExpandedWord { + if (col >= line.len) return null; + const b = config.wordBounds(line, col); + const command_run = b.hi > b.lo and config.commandWord(line[b.lo..b.hi]) != null; + if (!config.isFileChar(line[col]) and !command_run) return null; + if (b.hi <= b.lo) return null; + return .{ .lo = b.lo, .hi = b.hi }; +} + +/// acme: a no-drag middle/right click expands to the word under it — +/// file-ish, or a whole `` @`...` `` run (config.wordBounds is the spelling) +pub fn expandedSel(p: *Pardes, pane: *Pane, at: Pane.Sel) ?Pane.Sel { + var sl = at; + if (sl.c0 != sl.c1 or sl.r0 != sl.r1) return sl; + const text = edit.paneText(p, pane) catch return null; + var it = std.mem.splitAny(u8, text, "\n"); + var v: i32 = 0; + while (it.next()) |line| : (v += 1) { + if (v != sl.r0) continue; + const display_col: usize = @intCast(@max(0, sl.c0)); + const col = panes.File.renderedLineByteCol(pane, v, line, display_col); + const b = expandedWord(line, col) orelse return null; + sl.c0 = @intCast(panes.File.renderedLineDisplayCol(pane, v, line, b.lo)); + sl.c1 = @intCast(panes.File.renderedLineDisplayCol(pane, v, line, b.hi) - 1); + return sl; + } + return null; +} + +/// the word under the modal cursor as a pane-local selection (paneText +/// coords: row 0 is the tag; file panes carry the line-number prefix) +pub fn cursorWordSel(p: *Pardes, pane: *Pane) Pane.Sel { + const w = pane.wrapRow(pane.cur_row, pane.cur_col); + const vrow = w.row + @as(i32, BOX_H); + const vcol = if (pane.file != null) + panes.File.displayOffset(pane, pane.cur_row, w.at, pane.cur_col) + @as(i32, panes.File.gutterWidth(pane)) + else blk: { + const lines = edit.paneCursorLines(p, pane) catch break :blk pane.cur_col; + const local = pane.cur_row; + if (local < 0 or @as(usize, @intCast(local)) >= lines.len) break :blk pane.cur_col; + break :blk panes.File.lineDisplayOffset(lines[@intCast(local)], @intCast(@max(0, w.at)), @intCast(@max(0, pane.cur_col))); + }; + return .{ .state = .done, .c0 = vcol, .c1 = vcol, .r0 = vrow, .r1 = vrow }; +} + +const Search = enum { text, find, grep }; + +const SearchStart = enum { top, cursor }; + +pub fn submitSearch(p: *Pardes, id: usize) void { + const pane = p.panes[id] orelse return; + if (normal.selRegexArmed(pane)) |a| return normal.applySelRegex(p, pane, a.pat, a.split); + const armed = pane.promptText() orelse return; + const slash = std.mem.indexOfScalar(u8, armed, '/') orelse return; + if (std.mem.startsWith(u8, armed, config.rename_marker)) return p.lspRequest(id, .rename, armed[slash + 1 ..]); + if (std.mem.startsWith(u8, armed, config.symbol_marker)) return p.lspRequest(id, .workspace_symbols, armed[slash + 1 ..]); + const kind: Search = if (std.mem.startsWith(u8, armed, config.find_marker)) + .find + else if (std.mem.startsWith(u8, armed, config.grep_marker)) + .grep + else + .text; + runSearch(p, id, armed[slash + 1 ..], kind, .top) catch |err| return p.reportError(id, "search", err); + if (kind == .text) lookFirstHit(p, id); +} + +fn lookFirstHit(p: *Pardes, id: usize) void { + const pane = p.panes[id] orelse return; + const rid = pane.search_pane orelse return; + const rp = p.panes[rid] orelse return; + if ((rp.file orelse return).content.len == 0) return; + p.active = rid; + lookWalk(p, 1); + if (p.active != rid) return; // walked out of the list; leave it there + const txt = edit.currentSelText(p, rp) orelse return; + // spent, exactly as the look chord spends it (handleKey) + rp.vsel.active = false; + rp.msel.active = false; + rp.select = false; + p.runBuiltin(config.look_cmd, rid, "", txt); +} + +pub fn runSearch(p: *Pardes, id: usize, pat_raw: []const u8, kind: Search, start: SearchStart) !void { + const pane = p.panes[id] orelse return; + const pat = std.mem.trim(u8, pat_raw, " \t\r\n"); + if (pat.len == 0) return; + const arena = p.scratch.allocator(); + // where the pane lives: a file's directory, a shell's cwd — the walk + // root, and the directory the results buffer is named in. + const dir = Pardes.paneDir(pane); + const out = try arena.alloc(u8, filesystem.search_max_output_bytes); + var out_len: usize = 0; + var nrows: usize = 0; + var anchor: ?usize = null; + if (kind == .grep) { + var roots: [MAX_PANES][]const u8 = undefined; + var nroots: usize = 0; + for (p.panes) |slot| { + const pp = slot orelse continue; + const d = Pardes.paneDir(pp); + var covered = false; + var k: usize = 0; + while (k < nroots) { + if (pathUnder(d, roots[k])) { + covered = true; + break; + } + if (pathUnder(roots[k], d)) { // this one swallows a root already kept + nroots -= 1; + roots[k] = roots[nroots]; + continue; + } + k += 1; + } + if (covered) continue; + roots[nroots] = d; + nroots += 1; + } + for (roots[0..nroots]) |r| + out_len += try filesystem.grep(arena, p.gpa, r, dir, pat, out[out_len..]); + } else if (kind == .find) { + out_len = try filesystem.find(arena, dir, pat, out); + } else if (pane.hasPdf()) { + if (comptime pdf_enabled) { + const found = try panes.Pdf.searchRows( + &pane.pdf.?, + p.pdf_gpa, + arena, + pat, + start == .cursor, + out, + ); + out_len = found.bytes; + nrows = found.rows; + anchor = found.anchor; + } + } else { + const lines = try edit.paneCursorLines(p, pane); + // a real file names itself; a terminal or an output buffer has no path + const has_path = if (pane.file) |f| f.output == null else false; + var idbuf: [16]u8 = undefined; + // relative to `dir`, like Find's rows — and `dir` IS this file's + // own directory, so that is exactly its basename + const loc: []const u8 = if (has_path) + std.fs.path.basename(pane.file.?.path) + else + std.fmt.bufPrint(&idbuf, config.pane_addr ++ "{d}", .{id}) catch return error.PathTooLong; + const cl: usize = @intCast(@max(0, pane.cur_row)); + const cc: usize = @intCast(@max(0, pane.cur_col)); + for (lines, 0..) |ln, i| { + const at = std.ascii.indexOfIgnoreCase(ln, pat) orelse continue; + const row = try std.fmt.allocPrint(arena, "{s}:{d}:{d}{c}{d} {s}\n", .{ + loc, i + 1, at + 1, config.range_sep, at + pat.len, std.mem.trimEnd(u8, ln, " \t"), + }); + if (row.len > out.len - out_len) break; + if (start == .cursor and (i < cl or (i == cl and at <= cc))) anchor = nrows; + @memcpy(out[out_len..][0..row.len], row); + out_len += row.len; + nrows += 1; + } + } + const content = try p.gpa.dupe(u8, out[0..out_len]); + // the buffer records WHICH search filled it, pattern and all: Find and + // Grep are builtins (words you can execute), the bare `/` is a key + const from: panes.Output.Origin = switch (kind) { + .text => .search, + .find => .{ .cmd = .Find }, + .grep => .{ .cmd = .Grep }, + }; + try panes.Output.fillResults(p, id, dir, from, pat, content, anchor); +} + +pub fn searchStep(p: *Pardes, id: usize, delta: i32) bool { + const pane = p.panes[id] orelse return false; + const rid = pane.search_pane orelse return false; + const rp = p.panes[rid] orelse return false; + const rf = if (rp.file) |*f| f else return false; + // one question covers both hazards: a freed slot can be reused by an + // unrelated pane, and a buffer of PROSE has nowhere to step to + const tr = panes.Output.fileTraits(rf.output); + if (!tr.steps) return false; + // fresh results: n starts at the first row, N has nothing behind it + const nrows: i64 = @intCast(std.mem.count(u8, rf.content, "\n") + + @intFromBool(rf.content.len > 0 and rf.content[rf.content.len - 1] != '\n')); + var step: i64 = if (pane.search_row) |c| @as(i64, @intCast(c)) + delta else if (delta > 0) 0 else -1; + if (delta == 0) return true; + const direction: i64 = if (delta > 0) 1 else -1; + while (step >= 0 and step < nrows) : (step += direction) { + if (!panes.Output.isResultRow(rf, @intCast(step))) continue; + _ = jumpResult(p, id, @intCast(step)); + p.active = id; + break; + } + return true; +} + +pub fn jumpResult(p: *Pardes, id: usize, row: usize) bool { + const pane = p.panes[id] orelse return false; + const rid = pane.search_pane orelse return false; + const rp = p.panes[rid] orelse return false; + const rf = if (rp.file) |*f| f else return false; + const tr = panes.Output.fileTraits(rf.output); + const ln = modal.lineSlice(rf.content, row); + if (ln.len == 0) return false; + const r: i32 = @intCast(row); + pane.search_row = row; + rp.msel = .{ .active = true, .r0 = r, .r1 = r }; + rp.vsel.active = false; + rp.nsel = 0; + rp.cur_row = r; + rp.cur_pinned = true; + const off = rp.scroll(); + const last = off + @as(i32, rp.rows) - 1; + if (r < off) rp.scrollBy(r - off) else if (r > last) rp.scrollBy(r - last); + var realbuf: [4096]u8 = undefined; + const span = if (tr.commands) + wholeRowSpan(ln) + else + lineSpan(p, ln, Pardes.paneDir(rp), &realbuf) orelse blk: { + const target = panes.Output.location(ln); + break :blk if (target.at.line > 0) + Span{ .start = 0, .end = target.end } + else + null; + }; + if (span) |selected| { + rp.cur_col = @intCast(selected.start); + rp.look_at = .{ + .row = r, + .col0 = @intCast(selected.start), + .col1 = @intCast(selected.end - 1), + }; + } else { + rp.cur_col = 0; + rp.look_at = null; + } + if (tr.commands) { + p.runBuiltin(config.exec_cmd, rid, "", std.mem.trim(u8, ln, " \t\r")); + } else if (span) |selected| { + lookAt(p, rid, ln[selected.start..selected.end]); + // This is the newly visited result, not a selection carried into + // the destination. Look cleared the previous source selection. + rp.msel = .{ .active = true, .r0 = r, .r1 = r }; + } + armLookWalk(p, rid); + return true; +} + +const LookFrom = struct { row: i32, col: ?i32, strict: bool = false }; + +fn lookEdge(delta: i32) LookFrom { + return .{ .row = if (delta > 0) 0 else std.math.maxInt(i32), .col = null }; +} + +fn lookStand(pane: *Pane) LookFrom { + if (pane.look_at) |s| if (s.row == pane.cur_row and s.col0 == pane.cur_col) + return .{ .row = s.row, .col = s.col0, .strict = true }; + return .{ .row = pane.cur_row, .col = pane.cur_col }; +} + +fn lookWalkPanes(p: *Pardes, out: *[MAX_PANES]usize) []const usize { + var n: usize = 0; + var i = p.n_look_src; + while (i > 0) { + i -= 1; + const id = p.paneBySerial(p.look_src[i]) orelse continue; + out[n] = id; + n += 1; + } + const looked = n; + for (p.panes, 0..) |slot, id| { + const pane = slot orelse continue; + const f = pane.file orelse continue; + if (f.output == null) continue; + for (out[0..looked]) |k| { + if (k == id) break; + } else { + // insertion by serial descending — at most MAX_PANES + // comparisons, which is not a sort worth naming + var at = n; + while (at > looked and p.panes[out[at - 1]].?.serial < pane.serial) : (at -= 1) + out[at] = out[at - 1]; + out[at] = id; + n += 1; + } + } + if (n == 0) { + if (p.panes[p.active] == null) return out[0..0]; + out[0] = p.active; + n = 1; + } + return out[0..n]; +} + +fn lookPast(col0: i32, from: LookFrom, on_start_row: bool, delta: i32) bool { + if (!on_start_row) return true; + const c = from.col orelse return true; + if (delta > 0) return if (from.strict) col0 > c else col0 >= c; + return if (from.strict) col0 < c else col0 <= c; +} + +fn wholeRowSpan(ln: []const u8) ?Span { + var lo: usize = 0; + while (lo < ln.len and (ln[lo] == ' ' or ln[lo] == '\t')) lo += 1; + const hi = std.mem.trimEnd(u8, ln, " \t\r").len; + return if (hi > lo) .{ .start = lo, .end = hi } else null; +} + +fn lookSpanIn(p: *Pardes, pane: *Pane, from: LookFrom, delta: i32, budget: *usize) ?Pane.LookSpot { + const lines = edit.paneCursorLines(p, pane) catch return null; + const nrows: i32 = @intCast(lines.len); + if (nrows == 0) return null; + const grain: panes.Output.Grain = if (pane.file) |*f| panes.Output.grain(f.output) else .word; + const dir = Pardes.paneDir(pane); + var realbuf: [4096]u8 = undefined; + const start = std.math.clamp(from.row, 0, nrows - 1); + var r = start; + while (r >= 0 and r < nrows) : (r += delta) { + if (budget.* == 0) return null; + budget.* -= 1; + const ln = lines[@intCast(r)]; + if (pane.file) |*f| if (!panes.Output.isWalkRow(f, @intCast(r), ln)) continue; + const on_start = r == start; + switch (grain) { + .word => { + var best: ?Pane.LookSpot = null; + var i: usize = 0; + while (i < ln.len) { + while (i < ln.len and (ln[i] == ' ' or ln[i] == '\t')) i += 1; + const t0 = i; + while (i < ln.len and ln[i] != ' ' and ln[i] != '\t') i += 1; + if (i == t0) break; + const sp = wordSpan(p, ln[t0..i], dir, &realbuf) orelse continue; + const col0: i32 = @intCast(t0 + sp.start); + if (!lookPast(col0, from, on_start, delta)) continue; + best = .{ .row = r, .col0 = col0, .col1 = @intCast(t0 + sp.end - 1) }; + if (delta > 0) break; // first one forward; keep the last one back + } + if (best) |b| return b; + }, + // one span per row, so there is nothing to keep and nothing to + // scan past: the row either offers it or it does not + .line, .whole => { + const sp = span: { + if (grain == .whole) break :span wholeRowSpan(ln); + if (pane.file) |f| if (@as(usize, @intCast(r)) < f.location_rows.len) { + const end = f.location_rows[@intCast(r)].location_end; + if (end > 0) break :span @as(?Span, .{ .start = 0, .end = end }); + }; + break :span lineSpan(p, ln, dir, &realbuf); + } orelse continue; + const col0: i32 = @intCast(sp.start); + if (lookPast(col0, from, on_start, delta)) + return .{ .row = r, .col0 = col0, .col1 = @intCast(sp.end - 1) }; + }, + } + } + return null; +} + +pub fn lookWalk(p: *Pardes, delta: i32) void { + var buf: [MAX_PANES]usize = undefined; + const order = lookWalkPanes(p, &buf); + if (order.len == 0) return; + const owner = if (p.look_walk_owner) |serial| p.paneBySerial(serial) else null; + const active_at = std.mem.indexOfScalar(usize, order, p.active) orelse 0; + const at = if (owner) |wanted| + std.mem.indexOfScalar(usize, order, wanted) orelse active_at + else + active_at; + var from = lookStand(p.panes[order[at]] orelse return); + var budget: usize = Pardes.max_look_rows; + var k: usize = 0; + while (k <= order.len) : (k += 1) { + // `+ 2 * len` only so the backward subtraction stays unsigned + const idx = (if (delta > 0) at + k else at + 2 * order.len - k) % order.len; + const pane = p.panes[order[idx]] orelse continue; + if (lookSpanIn(p, pane, from, delta, &budget)) |spot| + return landLookSpot(p, order[idx], pane, spot); + if (budget == 0) return; // gave up mid-pane: stay put, stay reversible + from = lookEdge(delta); + } +} + +fn landLookSpot(p: *Pardes, id: usize, pane: *Pane, spot: Pane.LookSpot) void { + edit.pinPaneCursor(p, pane); // fresh out of tty mode the cursor still tracks the shell + pane.vsel = .{ .active = true, .row = spot.row, .col = spot.col1, .explicit = true }; + pane.msel.active = false; + pane.nsel = 0; + pane.cur_row = spot.row; + pane.cur_col = spot.col0; + pane.cur_pinned = true; + pane.look_at = spot; + p.look_walk_owner = pane.serial; + p.active = id; + pane.ensureCursorVisible(); +} + +pub fn cancelLookHover(p: *Pardes) void { + if (comptime pdf_enabled) if (p.pdf_hover_preview) |*preview| { + if (preview.pane < p.panes.len) if (p.panes[preview.pane]) |pane| { + if (pane.serial == preview.serial) if (pane.pdf) |*pv| + pv.invalidateRaster(preview.probe.page); + }; + preview.deinit(p.pdf_gpa); + p.pdf_hover_preview = null; + }; + p.look_hover_wait = null; + p.look_hover_preview = null; +} + +pub fn lookHoverPane(p: *const Pardes) ?usize { + if (comptime pdf_enabled) if (p.pdf_hover_preview) |preview| return preview.pane; + if (p.look_hover_preview) |preview| return preview.pane; + if (p.look_hover_wait) |waiting| return waiting.pane; + return null; +} + +fn noteLookHover(p: *Pardes, col: u16, row: u16, body_hit: ?Mouse.BodyHit, tag_hit: ?TagHit) void { + const delay = config.look_preview_delay_frames orelse return; + _ = delay; + const id = mouse.paneAt(p, col, row) orelse return cancelLookHover(p); + const pane = p.panes[id] orelse return cancelLookHover(p); + _ = edit.pointerTextSelection(p, id, col, row, body_hit, tag_hit) orelse return cancelLookHover(p); + + if (comptime pdf_enabled) if (p.pdf_hover_preview) |shown| + if (shown.col == col and shown.row == row and shown.pane == id and shown.serial == pane.serial) return; + if (p.look_hover_preview) |shown| + if (shown.col == col and shown.row == row and shown.pane == id and shown.serial == pane.serial and mouse.sameBodyCell(shown.body_hit, body_hit) and mouse.sameTagCell(shown.tag_hit, tag_hit)) return; + if (p.look_hover_wait) |waiting| + if (waiting.col == col and waiting.row == row and waiting.pane == id and waiting.serial == pane.serial and mouse.sameBodyCell(waiting.body_hit, body_hit) and mouse.sameTagCell(waiting.tag_hit, tag_hit)) return; + + cancelLookHover(p); + p.look_hover_wait = .{ .col = col, .row = row, .pane = id, .serial = pane.serial, .body_hit = body_hit, .tag_hit = tag_hit }; +} + +pub fn refreshLookHoverFromRaw(p: *Pardes) void { + if (!p.pointer_inside or !p.raw_hover_intent) return; + const mapped = p.presentation.pointer(p.screen_w, p.screen_h, p.pointer_raw_col, p.pointer_raw_row) orelse + return cancelLookHover(p); + p.hover_col = mapped.col; + p.hover_row = mapped.row; + const body_hit: ?Mouse.BodyHit = if (p.pointer_body_hit) |mapped_hit| + mouse.bodyHitForPane(p, mouse.paneAt(p, mapped.col, mapped.row) orelse return cancelLookHover(p), mapped_hit, false) orelse return cancelLookHover(p) + else + null; + noteLookHover(p, mapped.col, mapped.row, body_hit, p.pointer_tag_hit); +} + +pub fn advanceLookHover(p: *Pardes) void { + const delay = config.look_preview_delay_frames orelse return; + const waiting = if (p.look_hover_wait) |*w| w else return; + waiting.frames +|= 1; + if (waiting.frames < delay) return; + const pane = p.panes[waiting.pane] orelse return cancelLookHover(p); + if (pane.serial != waiting.serial) return cancelLookHover(p); + const pointed = edit.pointerTextSelection(p, waiting.pane, waiting.col, waiting.row, waiting.body_hit, waiting.tag_hit) orelse + return cancelLookHover(p); + if (comptime pdf_enabled) if (!pointed.on_tag and panes.Pdf.paneNativeReady(p, pane)) { + const probe = panes.Pdf.probeAt(p, pane, waiting.col, waiting.row) orelse + return cancelLookHover(p); + const ready = waiting.*; + p.look_hover_wait = null; + p.pdf_hover_preview = .{ + .col = ready.col, + .row = ready.row, + .pane = ready.pane, + .serial = ready.serial, + .probe = probe, + }; + pane.pdf.?.invalidateRaster(probe.page); + return; + }; + const operand = p.pointerOperand(pane, pointed.sel); + if (operand.text == null or operand.text.?.len == 0) return cancelLookHover(p); + var preview = operand.preview; + if (preview) |*sel| sel.state = .done; + p.look_hover_preview = .{ + .col = waiting.col, + .row = waiting.row, + .pane = waiting.pane, + .serial = waiting.serial, + .sel = preview, + .file_word = operand.file_word, + .body_hit = waiting.body_hit, + .tag_hit = waiting.tag_hit, + }; + p.look_hover_wait = null; +} + +pub fn focusPaneLine(p: *Pardes, id: usize, at: Spot, landing: enum { center, keep }) void { + if (id >= MAX_PANES) return; + const pane = p.panes[id] orelse return; + p.active = id; + pane.normal.clear(); + if (pane.hasPdf()) { + if (landing == .keep) return; + if (comptime pdf_enabled) { + const pv = &pane.pdf.?; + if (pv.focusLocation(p.pdf_gpa, at.line, at.col)) panes.Pdf.resetPageChrome(pane); + } + return; + } + if (at.line == 0) return; + if (pane.file) |*f| { + if (at.line > panes.File.nlines(p.gpa, f)) return; + if (landing == .center) { + const next = (at.line - 1) -| pane.rows / 2; // center, clamp at top + if (next != f.scroll) { + f.scroll = next; + f.syntax_dirty = true; + } + } + } + pane.cur_row = @intCast(at.line - 1); + pane.cur_col = if (at.col > 0) @intCast(at.col - 1) else 0; + pane.cur_pinned = true; + if (at.end_line != 0) return selectSpan(p, pane, at); + pane.ensureCursorVisible(); +} + +fn selectSpan(p: *Pardes, pane: *Pane, at: Spot) void { + const text = edit.flatSurface(p, pane) catch return; + // saturating, not `- 1`: `f.zig:0-5` is a legal thing to type and a + // 1-based zero is the same nothing an absent number is + const acol: i32 = @intCast(at.col -| 1); + const ecol: i32 = if (at.end_col > 0) @intCast(at.end_col - 1) else std.math.maxInt(i32); + const r = Pane.cellRange(text, @intCast(at.line -| 1), acol, @intCast(at.end_line -| 1), ecol); + pane.setRange(text, 0, r, true); +} + +fn openPaneTarget(p: *const Pardes, path: []const u8, at: Spot) ?Target { + for (p.panes, 0..) |slot, i| { + const tt = slot orelse continue; + if (tt.image) |iv| if (std.mem.eql(u8, iv.path, path)) { + return .{ .pane = .{ .id = i, .at = .{} } }; + }; + if (comptime pdf_enabled) if (tt.pdf) |pv| if (std.mem.eql(u8, pv.path, path)) { + return .{ .pane = .{ .id = i, .at = at } }; + }; + const ff = if (tt.file) |*f| f else continue; + if (!std.mem.eql(u8, ff.path, path)) continue; + return .{ .pane = .{ .id = i, .at = at } }; + } + return null; +} + +fn focusPaneByPath(p: *Pardes, path: []const u8, at: Spot) bool { + const target = openPaneTarget(p, path, at) orelse return false; + clearNavigationSelection(p, p.panes[target.pane.id].?); + focusPaneLine(p, target.pane.id, target.pane.at, .center); + return true; +} + +/// Navigation starts a new selection at the destination. +pub fn clearNavigationSelection(p: *Pardes, pane: *Pane) void { + pane.vsel = .{}; + pane.msel = .{}; + pane.nsel = 0; + pane.select = false; + pane.normal.clear(); + pane.append_at = null; + pane.sticky_col = -1; + for (0..pane.sel.len) |slot| pane.clearPointerSelection(slot); + pane.sel = @splat(.{}); + if (comptime pdf_enabled) if (pane.pdf) |*state| { + state.clearDrag(); + state.clearSelection(p.pdf_gpa); + }; + if (p.drag == .select and p.panes[p.drag.select.id] == pane) p.drag = .none; +} + +/// Resolve without changing focus or falling back to search. PDF links use +/// the same location rules as an ordinary Look before offering a choice. +fn resolveLookTarget(p: *Pardes, id: usize, txt: []const u8, realbuf: *[4096]u8) Target { + const trimmed = std.mem.trim(u8, txt, " \t\r\n"); + const pl = parsePathLine(trimmed); + if (pl.path.len > 0) if (openPaneTarget(p, pl.path, pl.at)) |target| return target; + var found: Target = .none; + var seen: [MAX_PANES][]const u8 = undefined; + var nseen: usize = 0; + var n: usize = 0; + cand: while (n <= p.njumps) : (n += 1) { + const k: usize = if (n == 0) id else p.jumps[p.njumps - n].pane; + if (n > 0 and k == id) continue; // tried first, skip the rerun + const op = p.panes[k] orelse continue; + const dir = Pardes.paneDir(op); + for (seen[0..nseen]) |s| if (std.mem.eql(u8, s, dir)) continue :cand; + seen[nseen] = dir; + nseen += 1; + if (pl.path.len > 0 and pl.path[0] != '/') { + var joinbuf: [2048]u8 = undefined; + if (std.fmt.bufPrint(&joinbuf, "{s}/{s}", .{ dir, pl.path }) catch null) |j| + if (openPaneTarget(p, j, pl.at)) |target| return target; + } + found = resolve(p, txt, dir, realbuf); + if (found != .none or pl.path.len == 0 or pl.path[0] == '/') break; + } + return found; +} + +fn locationText(p: *Pardes, path: []const u8, at: Spot) ?[]const u8 { + if (std.mem.indexOfAny(u8, path, "\r\n") != null) return null; + const arena = p.scratch.allocator(); + if (at.line == 0) return arena.dupe(u8, path) catch null; + if (at.end_line != 0) { + if (at.col == 0 and at.end_col == 0) + return std.fmt.allocPrint(arena, "{s}:{d}-{d}", .{ path, at.line, at.end_line }) catch null; + return std.fmt.allocPrint(arena, "{s}:{d}:{d}-{d}:{d}", .{ path, at.line, at.col, at.end_line, at.end_col }) catch null; + } + if (at.col != 0) return std.fmt.allocPrint(arena, "{s}:{d}:{d}", .{ path, at.line, at.col }) catch null; + return std.fmt.allocPrint(arena, "{s}:{d}", .{ path, at.line }) catch null; +} + +fn canonicalLookLocation(p: *Pardes, id: usize, text: []const u8) ?[]const u8 { + const trimmed = std.mem.trim(u8, text, " \t\r\n"); + if (trimmed.len == 0) return null; + var realbuf: [4096]u8 = undefined; + switch (resolveLookTarget(p, id, trimmed, &realbuf)) { + .none => return null, + .url => |url| { + if (url.len > 256) return null; + for (url) |c| if (c <= 0x20 or c == 0x7f) return null; + return p.scratch.allocator().dupe(u8, url) catch null; + }, + .file => |file| return locationText(p, file.path, file.at), + .image => |iv| return locationText(p, iv.path, .{}), + .dir => |dir| return locationText(p, dir, .{}), + .pane => |target| { + if (target.id >= p.panes.len) return null; + const pane = p.panes[target.id] orelse return null; + if (pane.file) |file| return locationText(p, file.path, target.at); + if (comptime pdf_enabled) if (pane.pdf) |doc| return locationText(p, doc.path, target.at); + if (pane.image) |iv| return locationText(p, iv.path, target.at); + var path: [32]u8 = undefined; + return locationText(p, std.fmt.bufPrint(&path, config.pane_addr ++ "{d}", .{target.id}) catch return null, target.at); + }, + } +} + +pub fn pdfLinkLocation(p: *Pardes, pane: *const Pane, link: if (pdf_enabled) pdf.Link else void) ?[]const u8 { + if (comptime !pdf_enabled) return null; + const state = pane.pdf orelse return null; + const id = p.paneIdOf(pane) orelse return null; + return switch (link.destination) { + .none => null, + .internal => |dest| if (dest.page < state.document.pages) + locationText(p, state.path, .{ .line = dest.page + 1 }) + else + null, + .external => |uri| canonicalLookLocation(p, id, uri), + }; +} + +pub fn followPdfLink(p: *Pardes, id: usize, probe: *const panes.Pdf.WordProbe) void { + if (comptime !pdf_enabled) return; + const pane = p.panes[id] orelse return; + const link = probe.link orelse return; + const target = pdfLinkLocation(p, pane, link) orelse return; + clearNavigationSelection(p, pane); + if (canonicalLookLocation(p, id, probe.text)) |visible| { + if (!std.mem.eql(u8, visible, target)) { + const content = std.fmt.allocPrint(p.gpa, "{s}\n{s}\n", .{ visible, target }) catch |err| + return p.reportError(id, "PDF link choices", err); + panes.Output.fillResults(p, id, std.fs.path.dirname(pane.pdf.?.path) orelse ".", .pdf_links, "", content, null) catch |err| + return p.reportError(id, "PDF link choices", err); + return; + } + } + switch (link.destination) { + .internal => |dest| { + p.noteHaptic(.look); + noteLookSource(p, id); + p.active = id; + panes.Pdf.revealOutlineDestination(p, pane, dest); + }, + .external => lookAt(p, id, target), + .none => {}, + } +} + +pub fn lookAt(p: *Pardes, id: usize, operand: []const u8) void { + const pane = p.panes[id] orelse return; + p.noteHaptic(.look); + noteLookSource(p, id); + const command = std.mem.trim(u8, operand, " \t\r\n"); + if (config.commandWord(command)) |cmd| { + if (p.execute(id, cmd)) |dst| p.active = dst; + return; + } + // The operand may borrow selected terminal/PDF text released below. + const txt = p.scratch.allocator().dupe(u8, operand) catch return; + const trimmed = std.mem.trim(u8, txt, " \t\r\n"); + clearNavigationSelection(p, pane); + const pl = parsePathLine(trimmed); + if (comptime pdf_enabled) if (panes.Pdf.lookSection(p, id, pl.path, pl.at)) return; + var realbuf: [4096]u8 = undefined; + const found = resolveLookTarget(p, id, txt, &realbuf); + switch (found) { + .none => { + const bmode = if (pane.tag_edit) pane.tag_mode else pane.mode; + if (pane.image != null or bmode == .tty) return; + runSearch(p, id, trimmed, .text, .cursor) catch |err| { + p.reportError(id, "search", err); + return; + }; + const at = pane.search_row; + _ = searchStep(p, id, 1); + if (at != null and pane.search_row == at) { + pane.search_row = null; + _ = searchStep(p, id, 1); + } + }, + .pane => |t| { + if (t.id >= MAX_PANES) return; + const target = p.panes[t.id] orelse return; + clearNavigationSelection(p, target); + focusPaneLine(p, t.id, t.at, .center); + }, + .url => |u| if (u.len <= 256) p.emit(.{ .open_link = .from(u) }), + .dir => |dir| { + for (p.panes, 0..) |slot, i| { + if (slot) |tt| if (std.mem.eql(u8, tt.cwdSlice(), dir) and p.takesCommandLine(i)) { + clearNavigationSelection(p, tt); + p.active = i; + p.emitWrite(i, "ls\r"); + return; + }; + } + const free = p.freeSlot() orelse return p.reportError(id, "look", error.NoPaneSlots); + const nt = p.newShell(free, dir) catch |err| return p.reportError(id, "look", err); + nt.greet = true; + const src = layout.splitParent(p, id); + const f = layout.findPane(p, src).?; + layout.insert(p, f.col, f.idx + 1, free); + layout.splitBelow(p, src, nt); + p.active = free; + p.stillborn_joiner = nt.serial; + }, + .file => |target| { + if (comptime pdf_enabled) if (target.kind == .pdf) { + if (focusPaneByPath(p, target.path, target.at)) return; + const free = p.freeSlot() orelse return p.reportError(id, "look", error.NoPaneSlots); + const nt = panes.Pdf.openPane(p, free, target.path, target.at.line) catch |err| + return p.reportError(id, "look", err); + p.placeDoc(id, free, nt); + return; + }; + // focus an existing pane on this path (rescrolled), else open + if (focusPaneByPath(p, target.path, target.at)) return; + const free = p.freeSlot() orelse return p.reportError(id, "look", error.NoPaneSlots); + const nt = panes.File.open(p, free, target.path, target.at.line) catch |err| + return p.reportError(id, "look", err); + if (target.at.col > 0) nt.cur_col = @intCast(target.at.col - 1); + p.placeDoc(id, free, nt); + layout.compute(p); + nt.file.?.scroll -|= @max(1, p.rects[free].h -| BOX_H) / 2; + if (target.at.end_line != 0) { + const centered = nt.file.?.scroll; + selectSpan(p, nt, target.at); + nt.file.?.scroll = centered; + } + }, + .image => |target| { + if (focusPaneByPath(p, target.path, .{})) return; + const free = p.freeSlot() orelse return p.reportError(id, "look", error.NoPaneSlots); + const nt = panes.Image.create(p, free, target.path, &.{}) catch |err| + return p.reportError(id, "look", err); + p.placeDoc(id, free, nt); + }, + } +} + +test "Look hover waits without mutating the pane and input cancels it" { + const delay = config.look_preview_delay_frames orelse return; + try std.testing.expect(delay > 0); + + const gpa = std.testing.allocator; + const p = try Pardes.init(gpa, .{ .cols = 60, .rows = 12, .tty_only = true }); + defer p.deinit(); + while (p.nextEffect()) |_| {} + const pane = try p.setTestFile("alpha beta gamma\n"); + while (p.nextEffect()) |_| {} + const other_id = p.freeSlot() orelse return error.NoSparePaneForHoverTest; + _ = try p.newShell(other_id, ""); + try std.testing.expect(layout.splitColumn(p, 0, other_id, false)); + p.sync(); + while (p.nextEffect()) |_| {} + + var frame = std.heap.ArenaAllocator.init(gpa); + defer frame.deinit(); + _ = try p.render(frame.allocator()); + const rect = p.rects[p.active]; + const word_x = rect.x + config.GUTTER + config.PREFIX_W + 7; + const body_y = if (p.settings.tag_bottom) rect.y else rect.y + BOX_H; + const motion = Event{ .mouse = .{ .button = .none, .kind = .motion, .col = word_x, .row = body_y } }; + + const selections_before = pane.sel; + const active_before = p.active; + const cursor_before = .{ pane.cur_row, pane.cur_col }; + const jumps_before = .{ p.njumps, p.jcur, p.n_look_src }; + const effects_before = p.effects_len; + + p.update(motion); + try std.testing.expect(p.look_hover_wait != null); + try std.testing.expect(p.look_hover_preview == null); + try std.testing.expect(p.animationActive()); + + var ticks: u16 = 0; + while (ticks + 1 < delay) : (ticks += 1) { + p.update(.tick); + // Repeated motion reports for one cell are noise, not a fresh delay. + if (ticks == delay / 2) p.update(motion); + try std.testing.expect(p.look_hover_preview == null); + } + p.update(.tick); + const preview = p.look_hover_preview orelse return error.MissingLookHoverPreview; + const preview_sel = preview.sel orelse return error.MissingLookHoverSelection; + try std.testing.expectEqual(.done, preview_sel.state); + try std.testing.expectEqual(@as(i32, config.PREFIX_W + 6), preview_sel.c0); + try std.testing.expectEqual(@as(i32, config.PREFIX_W + 9), preview_sel.c1); + try std.testing.expect(!p.animationActive()); + + // Resolving and displaying the operand is observational only. + try std.testing.expect(std.meta.eql(selections_before, pane.sel)); + try std.testing.expectEqual(active_before, p.active); + try std.testing.expectEqual(cursor_before, .{ pane.cur_row, pane.cur_col }); + try std.testing.expectEqual(jumps_before, .{ p.njumps, p.jcur, p.n_look_src }); + try std.testing.expectEqual(effects_before, p.effects_len); + + _ = frame.reset(.retain_capacity); + const surface = try p.render(frame.allocator()); + const expected_bg = colors.mix(p.theme().bg orelse p.theme().tag_bg, colors.mix(p.theme().bg orelse p.theme().tag_bg, p.theme().sel_bg)); + try std.testing.expectEqual(Color{ .rgb = expected_bg }, surface.at(word_x, body_y).style.bg); + + // Background traffic in another pane does not change the text or geometry + // under this pointer and must not strand a stationary hover unarmed. + p.update(.{ .output = .{ .pane = @intCast(other_id), .bytes = "busy\r\n" } }); + try std.testing.expect(p.look_hover_preview != null); + + const seam_x = p.col_x[0] + p.col_w[0] - 1; + p.update(.{ .mouse = .{ .button = .none, .kind = .motion, .col = seam_x, .row = body_y } }); + _ = frame.reset(.retain_capacity); + const hovered_seam = try p.render(frame.allocator()); + try std.testing.expectEqualStrings("╎", hovered_seam.at(seam_x, body_y).grapheme()); + p.update(.pointer_leave); + try std.testing.expect(p.look_hover_wait == null); + try std.testing.expect(p.look_hover_preview == null); + _ = frame.reset(.retain_capacity); + const left_seam = try p.render(frame.allocator()); + try std.testing.expect(!std.mem.eql(u8, "╎", left_seam.at(seam_x, body_y).grapheme())); + + const blank_x = rect.x + config.GUTTER + config.PREFIX_W + 30; + p.update(.{ .mouse = .{ .button = .none, .kind = .motion, .col = blank_x, .row = body_y } }); + for (0..delay) |_| p.update(.tick); + try std.testing.expect(p.look_hover_wait == null); + try std.testing.expect(p.look_hover_preview == null); + try std.testing.expect(!p.animationActive()); + + // File PREFIX_W belongs only to body line numbers. A preview on the tag's + // first character must be paintable all the way at tag column zero — which + // is TAG_TEXT_INSET, not GUTTER: the grip keeps the gutter and the gap + // beside it separates the grip's hit area from the text. + const tag_y = if (p.settings.tag_bottom) rect.y + rect.h - BOX_H else rect.y; + p.look_hover_preview = .{ + .col = rect.x + TAG_TEXT_INSET, + .row = tag_y, + .pane = p.active, + .serial = pane.serial, + .sel = .{ .state = .done, .c0 = 0, .c1 = 0, .r0 = 0, .r1 = 0 }, + }; + _ = frame.reset(.retain_capacity); + const tag_surface = try p.render(frame.allocator()); + try std.testing.expectEqual(Color{ .rgb = expected_bg }, tag_surface.at(rect.x + TAG_TEXT_INSET, tag_y).style.bg); + + p.look_hover_preview = null; + p.update(motion); + try std.testing.expect(p.look_hover_wait != null); + p.update(.{ .key = .{ .cp = Key.escape } }); + try std.testing.expect(p.look_hover_wait == null); + try std.testing.expect(p.look_hover_preview == null); + // The following host repaint must not resurrect a hover after keyboard + // input cancelled its raw-pointer intent. + p.acknowledgePanelPresentation(&.{}); + try std.testing.expect(p.look_hover_wait == null); +} + +test "cwd changes cancel only the affected pane's Look hover" { + const gpa = std.testing.allocator; + const p = try Pardes.init(gpa, .{ .shells = 3 }); + defer p.deinit(); + + const first = p.panes[0] orelse return error.MissingFirstPane; + const other = p.panes[1] orelse return error.MissingOtherPane; + p.setCwd(0, "/work/first"); + p.setCwd(1, "/work/other"); + p.look_hover_wait = .{ .col = 1, .row = 1, .pane = 0, .serial = first.serial }; + + // Hosts poll cwd every frame. An unchanged answer is observational and a + // change reported for another pane cannot invalidate this pane's operand. + p.setCwd(0, "/work/first"); + try std.testing.expect(p.look_hover_wait != null); + p.setCwd(1, "/work/elsewhere"); + try std.testing.expect(p.look_hover_wait != null); + try std.testing.expectEqual(other.serial, p.panes[1].?.serial); + + p.setCwd(0, "/work/changed"); + try std.testing.expect(p.look_hover_wait == null); + try std.testing.expect(p.look_hover_preview == null); +} + +test "stationary Look hover follows only acknowledged panel samples" { + _ = config.look_preview_delay_frames orelse return; + const p = try Pardes.init(std.testing.allocator, .{ .cols = 120, .rows = 20, .tty_only = true }); + defer p.deinit(); + const pane = p.panes[0].?; + const rect = p.rects[0]; + const target: layout.Box = .{ + .x = @floatFromInt(rect.x), + .y = @floatFromInt(rect.y), + .w = @floatFromInt(rect.w), + .h = @floatFromInt(rect.h), + }; + var track: layout.Track = .{ + .serial = pane.serial, + .pane = 0, + .phase = .moving, + .effect = .slide, + .from = .{ .x = 20, .y = 5, .w = 40, .h = 10 }, + .to = target, + }; + p.acknowledgePanelPresentation(&.{track}); + p.update(.{ .mouse = .{ .button = .none, .kind = .motion, .col = 30, .row = 8 } }); + const first = p.look_hover_wait orelse return error.MissingInitialHoverWait; + + // Advancing the producer-side track alone cannot move the semantic cell + // under a stationary pointer. + track.frame = track.effect.frames() - 1; + p.presentation.tracks[0] = track; + refreshLookHoverFromRaw(p); + try std.testing.expectEqual(first, p.look_hover_wait.?); + + // Once that exact sample is acknowledged, the same raw cell maps through + // the new panel rectangle and the debounce starts over for the new target. + p.acknowledgePanelPresentation(&.{track}); + const moved = p.look_hover_wait orelse return error.MissingRemappedHoverWait; + try std.testing.expect(first.col != moved.col or first.row != moved.row); + try std.testing.expectEqual(@as(u16, 0), moved.frames); + + // Re-acknowledging the same semantic target is host repaint noise, not a + // new hover, so it preserves the accumulated delay. + p.look_hover_wait.?.frames = 3; + p.acknowledgePanelPresentation(&.{track}); + try std.testing.expectEqual(@as(u16, 3), p.look_hover_wait.?.frames); + + // A zero-sized opening sample covers its future target but exposes no + // clickable content. Successful presentation therefore cancels the hover. + track.phase = .opening; + track.effect = .zoom; + track.frame = 0; + track.from = .{ + .x = target.x + target.w * 0.5, + .y = target.y + target.h * 0.5, + }; + p.acknowledgePanelPresentation(&.{track}); + try std.testing.expect(p.look_hover_wait == null); + try std.testing.expect(p.look_hover_preview == null); + + track.frame = track.effect.frames() - 1; + p.acknowledgePanelPresentation(&.{track}); + try std.testing.expect(p.look_hover_wait != null); +} + +test "Look copies its operand before releasing pointer selection storage" { + const p = try Pardes.init(std.testing.allocator, .{ .cols = 60, .rows = 12 }); + defer p.deinit(); + const pane = try p.setTestFile("alpha beta\ngamma delta\nepsilon zeta\n"); + const operand = try p.gpa.dupe(u8, "/test.txt:3:2"); + pane.sel[0] = .{ .state = .done, .source_id = 1 }; + pane.pointer_selections[0] = .{ + .gesture = pane.sel[0], + .rows = try p.gpa.alloc(Pane.PointerRow, 0), + .raw_text = operand, + }; + p.drag = .{ .select = .{ .id = 0, .button = config.select_button } }; + lookAt(p, 0, operand); + try std.testing.expectEqual(@as(i32, 2), pane.cur_row); + try std.testing.expectEqual(@as(i32, 1), pane.cur_col); + try std.testing.expect(pane.pointer_selections[0] == null); + try std.testing.expectEqual(.none, pane.sel[0].state); + try std.testing.expectEqual(.none, p.drag); +} + +test "Look ignores missing and out of bounds pane addresses" { + const p = try Pardes.init(std.testing.allocator, .{ .cols = 60, .rows = 12 }); + defer p.deinit(); + const pane = try p.setTestFile("alpha\nbravo\n"); + for ([_][]const u8{ config.pane_addr ++ "15:2", config.pane_addr ++ "999999:2" }) |operand| { + pane.setRange(pane.file.?.content, 0, .{ .anchor = 0, .head = 3 }, true); + lookAt(p, 0, operand); + try std.testing.expectEqual(@as(usize, 0), p.active); + try std.testing.expectEqual(@as(i32, 0), pane.cur_row); + try std.testing.expect(!pane.vsel.active); + } +} diff --git a/src/mouse.zig b/src/mouse.zig index 7ce95302..27d5dd9c 100644 --- a/src/mouse.zig +++ b/src/mouse.zig @@ -2,6 +2,7 @@ //! releases (acme's chords, border and seam drags, gestures), and the //! chrome targets a shell asks about. const pardes = @import("pardes.zig"); +const look = @import("look.zig"); const std = @import("std"); const layout = @import("layout.zig"); const modal = @import("modal.zig"); @@ -254,12 +255,12 @@ pub fn handleMouse(p: *Pardes, m: Mouse) void { p.pointer_inside = true; if (m.button == .none and m.kind == .motion) { p.raw_hover_intent = true; - p.refreshLookHoverFromRaw(); + look.refreshLookHoverFromRaw(p); return; } p.raw_hover_intent = false; const mapped = p.presentation.pointer(p.screen_w, p.screen_h, raw_col, raw_row) orelse { - p.cancelLookHover(); + look.cancelLookHover(p); if (m.kind == .release) dragRelease(p, m.button); return; }; @@ -784,7 +785,7 @@ fn dragRelease(p: *Pardes, button: Mouse.Button) void { ); defer release.deinit(p.pdf_gpa); if (release.probe) |*probe| if (probe.link != null) { - p.followPdfLink(s.id, probe); + look.followPdfLink(p, s.id, probe); return; }; // A native PDF page has no byte offsets of its own to diff --git a/src/ninep/ctl.zig b/src/ninep/ctl.zig index a3c1ab9e..25fe4037 100644 --- a/src/ninep/ctl.zig +++ b/src/ninep/ctl.zig @@ -6,6 +6,7 @@ //! own would say any better: `get`, `lock` and `unlock`. const std = @import("std"); const pardes = @import("../pardes.zig"); +const look = @import("../look.zig"); const panes = @import("../panes.zig"); const config = @import("../config.zig"); const fs = @import("../fs.zig"); @@ -58,7 +59,7 @@ fn activeSerial(p: *Pardes) ?u32 { fn run(p: *Pardes, id: usize, exec: bool, text: []const u8) void { const context = p.panes[id].?.serial; const before = Serials.snapshot(p); - if (exec) _ = p.execute(id, text) else p.lookAt(id, text); + if (exec) _ = p.execute(id, text) else look.lookAt(p, id, text); const after = Serials.snapshot(p); var created = false; for (after.list[0..after.len]) |serial| if (!before.has(serial)) { diff --git a/src/ninep/events.zig b/src/ninep/events.zig index 0e8d7bb7..d4d7fcad 100644 --- a/src/ninep/events.zig +++ b/src/ninep/events.zig @@ -2,6 +2,7 @@ //! bounded queues that park a read until something happens. const std = @import("std"); const pardes = @import("../pardes.zig"); +const look = @import("../look.zig"); const tree = @import("tree.zig"); const pane_files = @import("pane.zig"); @@ -461,7 +462,7 @@ pub fn writeEvent(p: *Pardes, req: Req, id: usize) Reply { const text = p.scratch.allocator().dupe(u8, whole[lo..hi]) catch continue; switch (r.action) { .body_exec, .tag_exec => _ = p.execute(live, text), - .body_look, .tag_look => p.lookAt(live, text), + .body_look, .tag_look => look.lookAt(p, live, text), else => unreachable, } } diff --git a/src/ninep/pane.zig b/src/ninep/pane.zig index 24398445..4110380a 100644 --- a/src/ninep/pane.zig +++ b/src/ninep/pane.zig @@ -3,6 +3,7 @@ //! mark and scroll, errors, event, look and exec. Terminals add pty/ (pty.zig). const std = @import("std"); const pardes = @import("../pardes.zig"); +const look = @import("../look.zig"); const panes = @import("../panes.zig"); const modal = @import("../modal.zig"); const config = @import("../config.zig"); @@ -564,7 +565,7 @@ pub fn nameBuffer(p: *Pardes, id: usize, full: []const u8, preserve_tag: bool) ! f.context_revision = null; pane.context_rows = 0; pane.wrap_n = 0; - p.invalidateLookHover(id); + look.invalidateLookHover(p, id); p.emit(.{ .watch = .{ .pane = @intCast(id), .on = false } }); events.noteLog(p, .rename, pane); } diff --git a/src/normal.zig b/src/normal.zig index 7a18aae5..e273f7f1 100644 --- a/src/normal.zig +++ b/src/normal.zig @@ -2,6 +2,7 @@ //! modal actions, replayed across every selection, and each action is done //! to the pane; PDF panes get their own normal keys. const pardes = @import("pardes.zig"); +const look = @import("look.zig"); const std = @import("std"); const mvzr = @import("mvzr"); const modal = @import("modal.zig"); @@ -388,20 +389,20 @@ fn executeNormalAction(p: *Pardes, pane: *Pane, semantic: modal.Normal.Action) v const fwd = diagnostic.direction == .forward; if (!diagnostic.endpoint) { if (panes.Output.resultsFrom(p, pane, .{ .query = .diagnostics }) and - p.searchStep(p.active, if (fwd) 1 else -1)) return; + look.searchStep(p, p.active, if (fwd) 1 else -1)) return; return p.lspRequest(p.active, .diagnostics, ""); } if (!panes.Output.resultsFrom(p, pane, .{ .query = .diagnostics })) return p.lspRequest(p.active, .diagnostics, ""); if (!fwd) { pane.search_row = null; - _ = p.searchStep(p.active, 1); + _ = look.searchStep(p, p.active, 1); return; } const rp = p.panes[pane.search_pane orelse return] orelse return; const rf = rp.file orelse return; pane.search_row = std.mem.count(u8, rf.content, "\n"); - _ = p.searchStep(p.active, -1); + _ = look.searchStep(p, p.active, -1); }, .move => |move| switch (move.motion) { .left => { @@ -552,7 +553,8 @@ fn executeNormalAction(p: *Pardes, pane: *Pane, semantic: modal.Normal.Action) v }, .pipe_selection => |how| return p.startPrompt(pane, .{ .pipe = how }), .search => return p.startPrompt(pane, .{ .search = config.search_marker }), - .search_step => |direction| return p.lookWalk( + .search_step => |direction| return look.lookWalk( + p, if (direction == .forward) @as(i32, 1) else -1, ), } @@ -595,8 +597,8 @@ pub fn handlePdfNormal(p: *Pardes, pane: *Pane, key: Key) void { if (pane.tag_edit) pane.mode = .normal; }, .search => p.startPrompt(pane, .{ .search = config.search_marker }), - .search_forward => p.lookWalk(1), - .search_backward => p.lookWalk(-1), + .search_forward => look.lookWalk(p, 1), + .search_backward => look.lookWalk(p, -1), } }, } diff --git a/src/pardes.zig b/src/pardes.zig index 7a451b3a..bdde1455 100644 --- a/src/pardes.zig +++ b/src/pardes.zig @@ -435,6 +435,7 @@ pub const Loc = struct { }; test { + _ = @import("look.zig"); _ = @import("mouse.zig"); _ = @import("normal.zig"); _ = @import("edit.zig"); @@ -505,7 +506,7 @@ pub const test_api = if (@import("builtin").is_test) struct { } pub fn searchStep(p: *Pardes, id: usize, delta: i32) bool { - return p.searchStep(id, delta); + return look.searchStep(p, id, delta); } pub fn heldSelection(p: *Pardes, first: usize) ?[]const u8 { @@ -1509,7 +1510,7 @@ test "a Look on a directory does not type ls into an occupied terminal" { var host: FakeTtyQuery = .{}; host.install(p); host.taken[0] = true; - p.lookAt(0, tmp); + look.lookAt(p, 0, tmp); var spawned = false; while (p.nextEffect()) |effect| switch (effect) { @@ -1522,7 +1523,7 @@ test "a Look on a directory does not type ls into an occupied terminal" { // ...and the same look reuses that very pane once its program is gone: the // core keeps no state of its own about it, so recovery needs nothing reset host.taken[0] = false; - p.lookAt(0, tmp); + look.lookAt(p, 0, tmp); var sent: [64]u8 = undefined; var sent_len: usize = 0; while (p.nextEffect()) |effect| switch (effect) { @@ -2575,7 +2576,7 @@ pub fn wordAtCol(str: []const u8, col: usize) []const u8 { /// `a` IS `b` or lives under it — how Grep drops a pane's directory when /// another pane's directory already covers it -fn pathUnder(a: []const u8, b: []const u8) bool { +pub fn pathUnder(a: []const u8, b: []const u8) bool { const root = std.mem.trimEnd(u8, b, "/"); if (!std.mem.startsWith(u8, a, root)) return false; return a.len == root.len or a[root.len] == '/'; @@ -2711,152 +2712,14 @@ test "tabbed file aligns syntax cursor and mouse at the nearest insertion gap" { try std.testing.expectEqual(blank_x - virtual, virtual_surface.cursor.?.x); const local_blank: i32 = @intCast(blank_x - rect.x - config.GUTTER); - try std.testing.expect(p.expandedSel(pane, .{ .state = .dragging, .c0 = local_blank, .c1 = local_blank, .r0 = BOX_H, .r1 = BOX_H }) == null); + try std.testing.expect(look.expandedSel(p, pane, .{ .state = .dragging, .c0 = local_blank, .c1 = local_blank, .r0 = BOX_H, .r1 = BOX_H }) == null); // The immediately-adjacent EOL cell and an in-line separator are blank // too. Pointer expansion must not lean left into the preceding word. const adjacent: i32 = @intCast(config.PREFIX_W + panes.File.displayWidth(line)); - try std.testing.expect(p.expandedSel(pane, .{ .state = .dragging, .c0 = adjacent, .c1 = adjacent, .r0 = BOX_H, .r1 = BOX_H }) == null); + try std.testing.expect(look.expandedSel(p, pane, .{ .state = .dragging, .c0 = adjacent, .c1 = adjacent, .r0 = BOX_H, .r1 = BOX_H }) == null); const separator: i32 = @intCast(config.PREFIX_W + config.tab_width + "return".len); - try std.testing.expect(p.expandedSel(pane, .{ .state = .dragging, .c0 = separator, .c1 = separator, .r0 = BOX_H, .r1 = BOX_H }) == null); -} - -test "Look hover waits without mutating the pane and input cancels it" { - const delay = config.look_preview_delay_frames orelse return; - try std.testing.expect(delay > 0); - - const gpa = std.testing.allocator; - const p = try Pardes.init(gpa, .{ .cols = 60, .rows = 12, .tty_only = true }); - defer p.deinit(); - while (p.nextEffect()) |_| {} - const pane = try p.setTestFile("alpha beta gamma\n"); - while (p.nextEffect()) |_| {} - const other_id = p.freeSlot() orelse return error.NoSparePaneForHoverTest; - _ = try p.newShell(other_id, ""); - try std.testing.expect(layout.splitColumn(p, 0, other_id, false)); - p.sync(); - while (p.nextEffect()) |_| {} - - var frame = std.heap.ArenaAllocator.init(gpa); - defer frame.deinit(); - _ = try p.render(frame.allocator()); - const rect = p.rects[p.active]; - const word_x = rect.x + config.GUTTER + config.PREFIX_W + 7; - const body_y = if (p.settings.tag_bottom) rect.y else rect.y + BOX_H; - const motion = Event{ .mouse = .{ .button = .none, .kind = .motion, .col = word_x, .row = body_y } }; - - const selections_before = pane.sel; - const active_before = p.active; - const cursor_before = .{ pane.cur_row, pane.cur_col }; - const jumps_before = .{ p.njumps, p.jcur, p.n_look_src }; - const effects_before = p.effects_len; - - p.update(motion); - try std.testing.expect(p.look_hover_wait != null); - try std.testing.expect(p.look_hover_preview == null); - try std.testing.expect(p.animationActive()); - - var ticks: u16 = 0; - while (ticks + 1 < delay) : (ticks += 1) { - p.update(.tick); - // Repeated motion reports for one cell are noise, not a fresh delay. - if (ticks == delay / 2) p.update(motion); - try std.testing.expect(p.look_hover_preview == null); - } - p.update(.tick); - const preview = p.look_hover_preview orelse return error.MissingLookHoverPreview; - const preview_sel = preview.sel orelse return error.MissingLookHoverSelection; - try std.testing.expectEqual(.done, preview_sel.state); - try std.testing.expectEqual(@as(i32, config.PREFIX_W + 6), preview_sel.c0); - try std.testing.expectEqual(@as(i32, config.PREFIX_W + 9), preview_sel.c1); - try std.testing.expect(!p.animationActive()); - - // Resolving and displaying the operand is observational only. - try std.testing.expect(std.meta.eql(selections_before, pane.sel)); - try std.testing.expectEqual(active_before, p.active); - try std.testing.expectEqual(cursor_before, .{ pane.cur_row, pane.cur_col }); - try std.testing.expectEqual(jumps_before, .{ p.njumps, p.jcur, p.n_look_src }); - try std.testing.expectEqual(effects_before, p.effects_len); - - _ = frame.reset(.retain_capacity); - const surface = try p.render(frame.allocator()); - const expected_bg = colors.mix(p.theme().bg orelse p.theme().tag_bg, colors.mix(p.theme().bg orelse p.theme().tag_bg, p.theme().sel_bg)); - try std.testing.expectEqual(Color{ .rgb = expected_bg }, surface.at(word_x, body_y).style.bg); - - // Background traffic in another pane does not change the text or geometry - // under this pointer and must not strand a stationary hover unarmed. - p.update(.{ .output = .{ .pane = @intCast(other_id), .bytes = "busy\r\n" } }); - try std.testing.expect(p.look_hover_preview != null); - - const seam_x = p.col_x[0] + p.col_w[0] - 1; - p.update(.{ .mouse = .{ .button = .none, .kind = .motion, .col = seam_x, .row = body_y } }); - _ = frame.reset(.retain_capacity); - const hovered_seam = try p.render(frame.allocator()); - try std.testing.expectEqualStrings("╎", hovered_seam.at(seam_x, body_y).grapheme()); - p.update(.pointer_leave); - try std.testing.expect(p.look_hover_wait == null); - try std.testing.expect(p.look_hover_preview == null); - _ = frame.reset(.retain_capacity); - const left_seam = try p.render(frame.allocator()); - try std.testing.expect(!std.mem.eql(u8, "╎", left_seam.at(seam_x, body_y).grapheme())); - - const blank_x = rect.x + config.GUTTER + config.PREFIX_W + 30; - p.update(.{ .mouse = .{ .button = .none, .kind = .motion, .col = blank_x, .row = body_y } }); - for (0..delay) |_| p.update(.tick); - try std.testing.expect(p.look_hover_wait == null); - try std.testing.expect(p.look_hover_preview == null); - try std.testing.expect(!p.animationActive()); - - // File PREFIX_W belongs only to body line numbers. A preview on the tag's - // first character must be paintable all the way at tag column zero — which - // is TAG_TEXT_INSET, not GUTTER: the grip keeps the gutter and the gap - // beside it separates the grip's hit area from the text. - const tag_y = if (p.settings.tag_bottom) rect.y + rect.h - BOX_H else rect.y; - p.look_hover_preview = .{ - .col = rect.x + TAG_TEXT_INSET, - .row = tag_y, - .pane = p.active, - .serial = pane.serial, - .sel = .{ .state = .done, .c0 = 0, .c1 = 0, .r0 = 0, .r1 = 0 }, - }; - _ = frame.reset(.retain_capacity); - const tag_surface = try p.render(frame.allocator()); - try std.testing.expectEqual(Color{ .rgb = expected_bg }, tag_surface.at(rect.x + TAG_TEXT_INSET, tag_y).style.bg); - - p.look_hover_preview = null; - p.update(motion); - try std.testing.expect(p.look_hover_wait != null); - p.update(.{ .key = .{ .cp = Key.escape } }); - try std.testing.expect(p.look_hover_wait == null); - try std.testing.expect(p.look_hover_preview == null); - // The following host repaint must not resurrect a hover after keyboard - // input cancelled its raw-pointer intent. - p.acknowledgePanelPresentation(&.{}); - try std.testing.expect(p.look_hover_wait == null); -} - -test "cwd changes cancel only the affected pane's Look hover" { - const gpa = std.testing.allocator; - const p = try Pardes.init(gpa, .{ .shells = 3 }); - defer p.deinit(); - - const first = p.panes[0] orelse return error.MissingFirstPane; - const other = p.panes[1] orelse return error.MissingOtherPane; - p.setCwd(0, "/work/first"); - p.setCwd(1, "/work/other"); - p.look_hover_wait = .{ .col = 1, .row = 1, .pane = 0, .serial = first.serial }; - - // Hosts poll cwd every frame. An unchanged answer is observational and a - // change reported for another pane cannot invalidate this pane's operand. - p.setCwd(0, "/work/first"); - try std.testing.expect(p.look_hover_wait != null); - p.setCwd(1, "/work/elsewhere"); - try std.testing.expect(p.look_hover_wait != null); - try std.testing.expectEqual(other.serial, p.panes[1].?.serial); - - p.setCwd(0, "/work/changed"); - try std.testing.expect(p.look_hover_wait == null); - try std.testing.expect(p.look_hover_preview == null); + try std.testing.expect(look.expandedSel(p, pane, .{ .state = .dragging, .c0 = separator, .c1 = separator, .r0 = BOX_H, .r1 = BOX_H }) == null); } test "editable workspace and column tags replace selections and persist" { @@ -3214,46 +3077,6 @@ pub const Effect = union(enum) { } }; -const LookHoverWait = struct { - col: u16, - row: u16, - pane: usize, - serial: u32, - frames: u16 = 0, - body_hit: ?Mouse.BodyHit = null, - tag_hit: ?TagHit = null, -}; - -const LookHoverPreview = struct { - col: u16, - row: u16, - pane: usize, - serial: u32, - sel: ?Pane.Sel, - file_word: ?FileWordSpan = null, - body_hit: ?Mouse.BodyHit = null, - tag_hit: ?TagHit = null, -}; - -const FileWordSpan = struct { - row: i32, - lo: i32, - hi: i32, // exclusive -}; - -const PdfWordPreview = if (pdf_enabled) struct { - col: u16, - row: u16, - pane: usize, - serial: u32, - probe: panes.Pdf.WordProbe, - - fn deinit(preview: *@This(), gpa: std.mem.Allocator) void { - preview.probe.deinit(gpa); - preview.* = undefined; - } -} else void; - test "a new column takes width only from the column that created it" { if (platform == .web) return; const p = try Pardes.init(std.testing.allocator, .{ .cols = 124, .rows = 24 }); @@ -3712,68 +3535,6 @@ test "core composes character motion out of the new grid, not a fade" { try std.testing.expect(try p.composeAsciiTransitions(arena.allocator(), &surface) == &surface); } -test "stationary Look hover follows only acknowledged panel samples" { - _ = config.look_preview_delay_frames orelse return; - const p = try Pardes.init(std.testing.allocator, .{ .cols = 120, .rows = 20, .tty_only = true }); - defer p.deinit(); - const pane = p.panes[0].?; - const rect = p.rects[0]; - const target: layout.Box = .{ - .x = @floatFromInt(rect.x), - .y = @floatFromInt(rect.y), - .w = @floatFromInt(rect.w), - .h = @floatFromInt(rect.h), - }; - var track: layout.Track = .{ - .serial = pane.serial, - .pane = 0, - .phase = .moving, - .effect = .slide, - .from = .{ .x = 20, .y = 5, .w = 40, .h = 10 }, - .to = target, - }; - p.acknowledgePanelPresentation(&.{track}); - p.update(.{ .mouse = .{ .button = .none, .kind = .motion, .col = 30, .row = 8 } }); - const first = p.look_hover_wait orelse return error.MissingInitialHoverWait; - - // Advancing the producer-side track alone cannot move the semantic cell - // under a stationary pointer. - track.frame = track.effect.frames() - 1; - p.presentation.tracks[0] = track; - p.refreshLookHoverFromRaw(); - try std.testing.expectEqual(first, p.look_hover_wait.?); - - // Once that exact sample is acknowledged, the same raw cell maps through - // the new panel rectangle and the debounce starts over for the new target. - p.acknowledgePanelPresentation(&.{track}); - const moved = p.look_hover_wait orelse return error.MissingRemappedHoverWait; - try std.testing.expect(first.col != moved.col or first.row != moved.row); - try std.testing.expectEqual(@as(u16, 0), moved.frames); - - // Re-acknowledging the same semantic target is host repaint noise, not a - // new hover, so it preserves the accumulated delay. - p.look_hover_wait.?.frames = 3; - p.acknowledgePanelPresentation(&.{track}); - try std.testing.expectEqual(@as(u16, 3), p.look_hover_wait.?.frames); - - // A zero-sized opening sample covers its future target but exposes no - // clickable content. Successful presentation therefore cancels the hover. - track.phase = .opening; - track.effect = .zoom; - track.frame = 0; - track.from = .{ - .x = target.x + target.w * 0.5, - .y = target.y + target.h * 0.5, - }; - p.acknowledgePanelPresentation(&.{track}); - try std.testing.expect(p.look_hover_wait == null); - try std.testing.expect(p.look_hover_preview == null); - - track.frame = track.effect.frames() - 1; - p.acknowledgePanelPresentation(&.{track}); - try std.testing.expect(p.look_hover_wait != null); -} - test "repeated non-dyadic column splits preserve every unrelated boundary" { if (platform == .web) return; const p = try Pardes.init(std.testing.allocator, .{ .cols = 979, .rows = 20 }); @@ -3964,9 +3725,9 @@ pub const Pardes = struct { pointer_tag_hit: ?TagHit = null, raw_hover_intent: bool = false, pointer_inside: bool = false, - look_hover_wait: ?LookHoverWait = null, - look_hover_preview: ?LookHoverPreview = null, - pdf_hover_preview: if (pdf_enabled) ?PdfWordPreview else void = if (pdf_enabled) null else {}, + look_hover_wait: ?look.LookHoverWait = null, + look_hover_preview: ?look.LookHoverPreview = null, + pdf_hover_preview: if (pdf_enabled) ?look.PdfWordPreview else void = if (pdf_enabled) null else {}, wheel_guard: u8 = 0, ctrl_w_pending: bool = false, multi_on: bool = false, @@ -4196,7 +3957,7 @@ pub const Pardes = struct { } pub fn deinit(p: *Pardes) void { - p.cancelLookHover(); + look.cancelLookHover(p); for (0..MAX_PANES) |id| p.dropPendingWrite(id); for (&p.panes) |*slot| if (slot.*) |pane| { p.teardownPane(pane); @@ -4349,15 +4110,15 @@ pub const Pardes = struct { // ...and so do bytes still queued for the pty it no longer has. p.dropPendingWrite(id); }; - if (p.lookHoverPane()) |h| if (h < p.panes.len and p.panes[h] == pane) p.cancelLookHover(); + if (look.lookHoverPane(p)) |h| if (h < p.panes.len and p.panes[h] == pane) look.cancelLookHover(p); p.retired_panes.retire(pane); } // Retired panes keep their payloads until the following frame or core teardown. fn teardownPane(p: *Pardes, pane: *Pane) void { - if (p.lookHoverPane()) |hovered| { + if (look.lookHoverPane(p)) |hovered| { if (hovered < p.panes.len and p.panes[hovered] == pane) - p.cancelLookHover(); + look.cancelLookHover(p); } p.shell_rows.dropPane(pane); for (0..pane.pointer_selections.len) |slot| pane.clearPointerSelection(slot); @@ -4466,29 +4227,6 @@ pub const Pardes = struct { } else null; } - fn noteLookSource(p: *Pardes, id: usize) void { - const pane = p.panes[id] orelse return; - var w: usize = 0; - for (p.look_src[0..p.n_look_src]) |s| { - if (s == pane.serial) continue; - p.look_src[w] = s; - w += 1; - } - if (w == p.look_src.len) { - std.mem.copyForwards(u32, p.look_src[0 .. w - 1], p.look_src[1..w]); - w -= 1; - } - p.look_src[w] = pane.serial; - p.n_look_src = w + 1; - p.look_walk_owner = pane.serial; - } - - pub fn armLookWalk(p: *Pardes, id: usize) void { - const pane = p.panes[id] orelse return; - if (pane.file) |file| if (file.content.len == 0) return; - p.look_walk_owner = pane.serial; - } - pub fn emitWrite(p: *Pardes, id: usize, bytes: []const u8) void { var off: usize = 0; // Anything already parked for this pane owns the stream's position, so @@ -4531,10 +4269,10 @@ pub const Pardes = struct { }; if (std.mem.eql(u8, cur, cwd)) return; pane.setOwnedCwd(cwd) catch |err| return p.reportError(id, "directory", err); - if (p.lookHoverPane() == id) p.cancelLookHover(); + if (look.lookHoverPane(p) == id) look.cancelLookHover(p); } - fn takesCommandLine(p: *const Pardes, id: usize) bool { + pub fn takesCommandLine(p: *const Pardes, id: usize) bool { const pane = p.panes[id] orelse return false; if (!pane.isTerminal()) return false; // A mounted shell sits behind sudo's process supervisor. Its OSC 133 @@ -4638,19 +4376,13 @@ pub const Pardes = struct { pub fn reloadWatchedFile(p: *Pardes, id: u8, bytes: []const u8) bool { p.invalidate(); - p.invalidateLookHover(id); + look.invalidateLookHover(p, id); const applied = p.applyWatchedFileChanged(id, bytes); _ = p.scratch.reset(.retain_capacity); p.sync(); return applied; } - pub fn invalidateLookHover(p: *Pardes, id: usize) void { - if (p.lookHoverPane() != id) return; - p.raw_hover_intent = false; - p.cancelLookHover(); - } - pub fn emit(p: *Pardes, e: Effect) void { if (p.effects_len == p.effects.len) return; const tail = (p.effects_head + p.effects_len) % p.effects.len; @@ -4886,7 +4618,7 @@ pub const Pardes = struct { if (!ctlfs.changesPane(req)) return ctlfs.handle(p, req); p.needs_frame = true; p.raw_hover_intent = false; - p.cancelLookHover(); + look.cancelLookHover(p); const reply = ctlfs.handle(p, req); // The request was a whole step of its own, so it settles the way a // step does: the cursor and scroll reconciled, the scripted panes @@ -4912,23 +4644,23 @@ pub const Pardes = struct { .tick => {}, .mouse => |m| if (!(m.button == .none and m.kind == .motion)) { p.raw_hover_intent = false; - p.cancelLookHover(); + look.cancelLookHover(p); }, - .output => |o| if (p.lookHoverPane() == o.pane) { + .output => |o| if (look.lookHoverPane(p) == o.pane) { p.raw_hover_intent = false; - p.cancelLookHover(); + look.cancelLookHover(p); }, - .file_changed => |changed| if (p.lookHoverPane() == changed.pane) { + .file_changed => |changed| if (look.lookHoverPane(p) == changed.pane) { p.raw_hover_intent = false; - p.cancelLookHover(); + look.cancelLookHover(p); }, - .pdf_scroll => |scroll| if (p.lookHoverPane() == scroll.pane) { + .pdf_scroll => |scroll| if (look.lookHoverPane(p) == scroll.pane) { p.raw_hover_intent = false; - p.cancelLookHover(); + look.cancelLookHover(p); }, else => { p.raw_hover_intent = false; - p.cancelLookHover(); + look.cancelLookHover(p); }, } switch (ev) { @@ -5024,7 +4756,7 @@ pub const Pardes = struct { .tick => { p.chrome_animation.advance(); p.presentation.advance(); - p.advanceLookHover(); + look.advanceLookHover(p); }, } _ = p.scratch.reset(.retain_capacity); @@ -5083,7 +4815,7 @@ pub const Pardes = struct { return pane_tail; } - fn paneIdOf(p: *const Pardes, pane: *const Pane) ?usize { + pub fn paneIdOf(p: *const Pardes, pane: *const Pane) ?usize { for (p.panes, 0..) |slot, id| if (slot) |sp| { if (sp == pane) return id; }; @@ -5563,53 +5295,6 @@ pub const Pardes = struct { if (col) |c| p.topbar_col = @intCast(@min(c, modal.prevGrapheme(bar, bar.len))); } - const ExpandedWord = struct { lo: usize, hi: usize }; - - fn expandedWord(line: []const u8, col: usize) ?ExpandedWord { - if (col >= line.len) return null; - const b = config.wordBounds(line, col); - const command_run = b.hi > b.lo and config.commandWord(line[b.lo..b.hi]) != null; - if (!config.isFileChar(line[col]) and !command_run) return null; - if (b.hi <= b.lo) return null; - return .{ .lo = b.lo, .hi = b.hi }; - } - - /// acme: a no-drag middle/right click expands to the word under it — - /// file-ish, or a whole `` @`...` `` run (config.wordBounds is the spelling) - fn expandedSel(p: *Pardes, pane: *Pane, at: Pane.Sel) ?Pane.Sel { - var sl = at; - if (sl.c0 != sl.c1 or sl.r0 != sl.r1) return sl; - const text = edit.paneText(p, pane) catch return null; - var it = std.mem.splitAny(u8, text, "\n"); - var v: i32 = 0; - while (it.next()) |line| : (v += 1) { - if (v != sl.r0) continue; - const display_col: usize = @intCast(@max(0, sl.c0)); - const col = panes.File.renderedLineByteCol(pane, v, line, display_col); - const b = expandedWord(line, col) orelse return null; - sl.c0 = @intCast(panes.File.renderedLineDisplayCol(pane, v, line, b.lo)); - sl.c1 = @intCast(panes.File.renderedLineDisplayCol(pane, v, line, b.hi) - 1); - return sl; - } - return null; - } - - /// the word under the modal cursor as a pane-local selection (paneText - /// coords: row 0 is the tag; file panes carry the line-number prefix) - fn cursorWordSel(p: *Pardes, pane: *Pane) Pane.Sel { - const w = pane.wrapRow(pane.cur_row, pane.cur_col); - const vrow = w.row + @as(i32, BOX_H); - const vcol = if (pane.file != null) - panes.File.displayOffset(pane, pane.cur_row, w.at, pane.cur_col) + @as(i32, panes.File.gutterWidth(pane)) - else blk: { - const lines = edit.paneCursorLines(p, pane) catch break :blk pane.cur_col; - const local = pane.cur_row; - if (local < 0 or @as(usize, @intCast(local)) >= lines.len) break :blk pane.cur_col; - break :blk panes.File.lineDisplayOffset(lines[@intCast(local)], @intCast(@max(0, w.at)), @intCast(@max(0, pane.cur_col))); - }; - return .{ .state = .done, .c0 = vcol, .c1 = vcol, .r0 = vrow, .r1 = vrow }; - } - fn chordEachSel(p: *Pardes, pane: *Pane, cmd: Builtin) bool { if (pane.nsel == 0) return false; const text = edit.flatSurface(p, pane) catch return false; @@ -5660,7 +5345,7 @@ pub const Pardes = struct { preview: ?Pane.Sel = null, /// File words stay logical so a soft-wrapped operand is not cut into /// unrelated rendered fragments. Null for tags and non-file panes. - file_word: ?FileWordSpan = null, + file_word: ?look.FileWordSpan = null, /// A newly expanded word is installed in the gesture's button slot; /// an existing selection is only borrowed and must not replace it. expanded: ?Pane.Sel = null, @@ -5731,7 +5416,7 @@ pub const Pardes = struct { if (pane.file != null and clicked.r0 >= BOX_H and clicked.r0 == clicked.r1 and clicked.c0 == clicked.c1) { const line = panes.File.sourceLine(pane, row); const source_col: usize = @intCast(@max(0, col)); - const b = expandedWord(line, source_col) orelse return result; + const b = look.expandedWord(line, source_col) orelse return result; const lo = std.math.cast(i32, b.lo) orelse return result; const hi = std.math.cast(i32, b.hi) orelse return result; result.text = line[b.lo..b.hi]; @@ -5751,7 +5436,7 @@ pub const Pardes = struct { return result; } - const expanded = p.expandedSel(pane, clicked) orelse return result; + const expanded = look.expandedSel(p, pane, clicked) orelse return result; result.text = edit.selectionText(p, pane, expanded) catch null; if (result.text == null or result.text.?.len == 0) return result; result.preview = expanded; @@ -5920,7 +5605,7 @@ pub const Pardes = struct { }, .search => |at| { if (submit) - p.submitSearch(p.active) + look.submitSearch(p, p.active) else if (normal.selRegexArmed(pane)) |_| normal.applySelRegex(p, pane, "", false); pane.tag_tail_len = @min(at, pane.tag_tail_len); @@ -5953,7 +5638,7 @@ pub const Pardes = struct { return; } } - const sel = p.expandedSel(pane, p.cursorWordSel(pane)) orelse return; + const sel = look.expandedSel(p, pane, look.cursorWordSel(p, pane)) orelse return; const word = edit.selectionText(p, pane, sel) catch return; p.runBuiltin(cmd, p.active, "", word); return; @@ -6003,9 +5688,6 @@ pub const Pardes = struct { // ---- search (`/`, Find, n/N): results into an output buffer, look the rows ---- - const Search = enum { text, find, grep }; - const SearchStart = enum { top, cursor }; - pub fn paneDir(pane: *const Pane) []const u8 { switch (pane.cwd) { .inherited => |src| return paneDir(src), @@ -6130,205 +5812,6 @@ pub const Pardes = struct { } }); } - fn submitSearch(p: *Pardes, id: usize) void { - const pane = p.panes[id] orelse return; - if (normal.selRegexArmed(pane)) |a| return normal.applySelRegex(p, pane, a.pat, a.split); - const armed = pane.promptText() orelse return; - const slash = std.mem.indexOfScalar(u8, armed, '/') orelse return; - if (std.mem.startsWith(u8, armed, config.rename_marker)) return p.lspRequest(id, .rename, armed[slash + 1 ..]); - if (std.mem.startsWith(u8, armed, config.symbol_marker)) return p.lspRequest(id, .workspace_symbols, armed[slash + 1 ..]); - const kind: Search = if (std.mem.startsWith(u8, armed, config.find_marker)) - .find - else if (std.mem.startsWith(u8, armed, config.grep_marker)) - .grep - else - .text; - p.runSearch(id, armed[slash + 1 ..], kind, .top) catch |err| return p.reportError(id, "search", err); - if (kind == .text) p.lookFirstHit(id); - } - - fn lookFirstHit(p: *Pardes, id: usize) void { - const pane = p.panes[id] orelse return; - const rid = pane.search_pane orelse return; - const rp = p.panes[rid] orelse return; - if ((rp.file orelse return).content.len == 0) return; - p.active = rid; - p.lookWalk(1); - if (p.active != rid) return; // walked out of the list; leave it there - const txt = edit.currentSelText(p, rp) orelse return; - // spent, exactly as the look chord spends it (handleKey) - rp.vsel.active = false; - rp.msel.active = false; - rp.select = false; - p.runBuiltin(config.look_cmd, rid, "", txt); - } - - pub fn runSearch(p: *Pardes, id: usize, pat_raw: []const u8, kind: Search, start: SearchStart) !void { - const pane = p.panes[id] orelse return; - const pat = std.mem.trim(u8, pat_raw, " \t\r\n"); - if (pat.len == 0) return; - const arena = p.scratch.allocator(); - // where the pane lives: a file's directory, a shell's cwd — the walk - // root, and the directory the results buffer is named in. - const dir = paneDir(pane); - const out = try arena.alloc(u8, filesystem.search_max_output_bytes); - var out_len: usize = 0; - var nrows: usize = 0; - var anchor: ?usize = null; - if (kind == .grep) { - var roots: [MAX_PANES][]const u8 = undefined; - var nroots: usize = 0; - for (p.panes) |slot| { - const pp = slot orelse continue; - const d = paneDir(pp); - var covered = false; - var k: usize = 0; - while (k < nroots) { - if (pathUnder(d, roots[k])) { - covered = true; - break; - } - if (pathUnder(roots[k], d)) { // this one swallows a root already kept - nroots -= 1; - roots[k] = roots[nroots]; - continue; - } - k += 1; - } - if (covered) continue; - roots[nroots] = d; - nroots += 1; - } - for (roots[0..nroots]) |r| - out_len += try filesystem.grep(arena, p.gpa, r, dir, pat, out[out_len..]); - } else if (kind == .find) { - out_len = try filesystem.find(arena, dir, pat, out); - } else if (pane.hasPdf()) { - if (comptime pdf_enabled) { - const found = try panes.Pdf.searchRows( - &pane.pdf.?, - p.pdf_gpa, - arena, - pat, - start == .cursor, - out, - ); - out_len = found.bytes; - nrows = found.rows; - anchor = found.anchor; - } - } else { - const lines = try edit.paneCursorLines(p, pane); - // a real file names itself; a terminal or an output buffer has no path - const has_path = if (pane.file) |f| f.output == null else false; - var idbuf: [16]u8 = undefined; - // relative to `dir`, like Find's rows — and `dir` IS this file's - // own directory, so that is exactly its basename - const loc: []const u8 = if (has_path) - std.fs.path.basename(pane.file.?.path) - else - std.fmt.bufPrint(&idbuf, config.pane_addr ++ "{d}", .{id}) catch return error.PathTooLong; - const cl: usize = @intCast(@max(0, pane.cur_row)); - const cc: usize = @intCast(@max(0, pane.cur_col)); - for (lines, 0..) |ln, i| { - const at = std.ascii.indexOfIgnoreCase(ln, pat) orelse continue; - const row = try std.fmt.allocPrint(arena, "{s}:{d}:{d}{c}{d} {s}\n", .{ - loc, i + 1, at + 1, config.range_sep, at + pat.len, std.mem.trimEnd(u8, ln, " \t"), - }); - if (row.len > out.len - out_len) break; - if (start == .cursor and (i < cl or (i == cl and at <= cc))) anchor = nrows; - @memcpy(out[out_len..][0..row.len], row); - out_len += row.len; - nrows += 1; - } - } - const content = try p.gpa.dupe(u8, out[0..out_len]); - // the buffer records WHICH search filled it, pattern and all: Find and - // Grep are builtins (words you can execute), the bare `/` is a key - const from: panes.Output.Origin = switch (kind) { - .text => .search, - .find => .{ .cmd = .Find }, - .grep => .{ .cmd = .Grep }, - }; - try panes.Output.fillResults(p, id, dir, from, pat, content, anchor); - } - - pub fn searchStep(p: *Pardes, id: usize, delta: i32) bool { - const pane = p.panes[id] orelse return false; - const rid = pane.search_pane orelse return false; - const rp = p.panes[rid] orelse return false; - const rf = if (rp.file) |*f| f else return false; - // one question covers both hazards: a freed slot can be reused by an - // unrelated pane, and a buffer of PROSE has nowhere to step to - const tr = panes.Output.fileTraits(rf.output); - if (!tr.steps) return false; - // fresh results: n starts at the first row, N has nothing behind it - const nrows: i64 = @intCast(std.mem.count(u8, rf.content, "\n") + - @intFromBool(rf.content.len > 0 and rf.content[rf.content.len - 1] != '\n')); - var step: i64 = if (pane.search_row) |c| @as(i64, @intCast(c)) + delta else if (delta > 0) 0 else -1; - if (delta == 0) return true; - const direction: i64 = if (delta > 0) 1 else -1; - while (step >= 0 and step < nrows) : (step += direction) { - if (!panes.Output.isResultRow(rf, @intCast(step))) continue; - _ = p.jumpResult(id, @intCast(step)); - p.active = id; - break; - } - return true; - } - - fn jumpResult(p: *Pardes, id: usize, row: usize) bool { - const pane = p.panes[id] orelse return false; - const rid = pane.search_pane orelse return false; - const rp = p.panes[rid] orelse return false; - const rf = if (rp.file) |*f| f else return false; - const tr = panes.Output.fileTraits(rf.output); - const ln = modal.lineSlice(rf.content, row); - if (ln.len == 0) return false; - const r: i32 = @intCast(row); - pane.search_row = row; - rp.msel = .{ .active = true, .r0 = r, .r1 = r }; - rp.vsel.active = false; - rp.nsel = 0; - rp.cur_row = r; - rp.cur_pinned = true; - const off = rp.scroll(); - const last = off + @as(i32, rp.rows) - 1; - if (r < off) rp.scrollBy(r - off) else if (r > last) rp.scrollBy(r - last); - var realbuf: [4096]u8 = undefined; - const span = if (tr.commands) - wholeRowSpan(ln) - else - look.lineSpan(p, ln, paneDir(rp), &realbuf) orelse blk: { - const target = panes.Output.location(ln); - break :blk if (target.at.line > 0) - look.Span{ .start = 0, .end = target.end } - else - null; - }; - if (span) |selected| { - rp.cur_col = @intCast(selected.start); - rp.look_at = .{ - .row = r, - .col0 = @intCast(selected.start), - .col1 = @intCast(selected.end - 1), - }; - } else { - rp.cur_col = 0; - rp.look_at = null; - } - if (tr.commands) { - p.runBuiltin(config.exec_cmd, rid, "", std.mem.trim(u8, ln, " \t\r")); - } else if (span) |selected| { - p.lookAt(rid, ln[selected.start..selected.end]); - // This is the newly visited result, not a selection carried into - // the destination. Look cleared the previous source selection. - rp.msel = .{ .active = true, .r0 = r, .r1 = r }; - } - p.armLookWalk(rid); - return true; - } - pub fn lspRequest(p: *Pardes, id: usize, kind: lsp.Kind, arg: []const u8) void { if (!normal.multiOnce(p)) return; // one question per keystroke, from the primary if (!lsp.supports.contains(kind)) return; @@ -6520,7 +6003,7 @@ pub const Pardes = struct { const nrows = std.mem.count(u8, rows, "\n"); if (panes.Output.traits(from).jumps and nrows == 1) { const ln = std.mem.trimEnd(u8, rows, "\n"); - return p.lookAt(w.pane, ln[0..panes.Output.location(ln).end]); + return look.lookAt(p, w.pane, ln[0..panes.Output.location(ln).end]); } const dir = if (pane.file) |f| (std.fs.path.dirname(f.path) orelse "/") else pane.cwdSlice(); @@ -6536,260 +6019,18 @@ pub const Pardes = struct { .line = @as(usize, @intCast(@max(0, w.row))) + 1, .col = @as(usize, @intCast(@max(0, w.col))) + 1, }); - _ = p.jumpResult(w.pane, row); + _ = look.jumpResult(p, w.pane, row); } } // ---- n/N: the walk over look-able text ---- - const max_look_rows = 8192; - - const LookFrom = struct { row: i32, col: ?i32, strict: bool = false }; - - fn lookEdge(delta: i32) LookFrom { - return .{ .row = if (delta > 0) 0 else std.math.maxInt(i32), .col = null }; - } - - fn lookStand(pane: *Pane) LookFrom { - if (pane.look_at) |s| if (s.row == pane.cur_row and s.col0 == pane.cur_col) - return .{ .row = s.row, .col = s.col0, .strict = true }; - return .{ .row = pane.cur_row, .col = pane.cur_col }; - } - - fn lookWalkPanes(p: *Pardes, out: *[MAX_PANES]usize) []const usize { - var n: usize = 0; - var i = p.n_look_src; - while (i > 0) { - i -= 1; - const id = p.paneBySerial(p.look_src[i]) orelse continue; - out[n] = id; - n += 1; - } - const looked = n; - for (p.panes, 0..) |slot, id| { - const pane = slot orelse continue; - const f = pane.file orelse continue; - if (f.output == null) continue; - for (out[0..looked]) |k| { - if (k == id) break; - } else { - // insertion by serial descending — at most MAX_PANES - // comparisons, which is not a sort worth naming - var at = n; - while (at > looked and p.panes[out[at - 1]].?.serial < pane.serial) : (at -= 1) - out[at] = out[at - 1]; - out[at] = id; - n += 1; - } - } - if (n == 0) { - if (p.panes[p.active] == null) return out[0..0]; - out[0] = p.active; - n = 1; - } - return out[0..n]; - } - - fn lookPast(col0: i32, from: LookFrom, on_start_row: bool, delta: i32) bool { - if (!on_start_row) return true; - const c = from.col orelse return true; - if (delta > 0) return if (from.strict) col0 > c else col0 >= c; - return if (from.strict) col0 < c else col0 <= c; - } - - fn wholeRowSpan(ln: []const u8) ?look.Span { - var lo: usize = 0; - while (lo < ln.len and (ln[lo] == ' ' or ln[lo] == '\t')) lo += 1; - const hi = std.mem.trimEnd(u8, ln, " \t\r").len; - return if (hi > lo) .{ .start = lo, .end = hi } else null; - } - - fn lookSpanIn(p: *Pardes, pane: *Pane, from: LookFrom, delta: i32, budget: *usize) ?Pane.LookSpot { - const lines = edit.paneCursorLines(p, pane) catch return null; - const nrows: i32 = @intCast(lines.len); - if (nrows == 0) return null; - const grain: panes.Output.Grain = if (pane.file) |*f| panes.Output.grain(f.output) else .word; - const dir = paneDir(pane); - var realbuf: [4096]u8 = undefined; - const start = std.math.clamp(from.row, 0, nrows - 1); - var r = start; - while (r >= 0 and r < nrows) : (r += delta) { - if (budget.* == 0) return null; - budget.* -= 1; - const ln = lines[@intCast(r)]; - if (pane.file) |*f| if (!panes.Output.isWalkRow(f, @intCast(r), ln)) continue; - const on_start = r == start; - switch (grain) { - .word => { - var best: ?Pane.LookSpot = null; - var i: usize = 0; - while (i < ln.len) { - while (i < ln.len and (ln[i] == ' ' or ln[i] == '\t')) i += 1; - const t0 = i; - while (i < ln.len and ln[i] != ' ' and ln[i] != '\t') i += 1; - if (i == t0) break; - const sp = look.wordSpan(p, ln[t0..i], dir, &realbuf) orelse continue; - const col0: i32 = @intCast(t0 + sp.start); - if (!lookPast(col0, from, on_start, delta)) continue; - best = .{ .row = r, .col0 = col0, .col1 = @intCast(t0 + sp.end - 1) }; - if (delta > 0) break; // first one forward; keep the last one back - } - if (best) |b| return b; - }, - // one span per row, so there is nothing to keep and nothing to - // scan past: the row either offers it or it does not - .line, .whole => { - const sp = span: { - if (grain == .whole) break :span wholeRowSpan(ln); - if (pane.file) |f| if (@as(usize, @intCast(r)) < f.location_rows.len) { - const end = f.location_rows[@intCast(r)].location_end; - if (end > 0) break :span @as(?look.Span, .{ .start = 0, .end = end }); - }; - break :span look.lineSpan(p, ln, dir, &realbuf); - } orelse continue; - const col0: i32 = @intCast(sp.start); - if (lookPast(col0, from, on_start, delta)) - return .{ .row = r, .col0 = col0, .col1 = @intCast(sp.end - 1) }; - }, - } - } - return null; - } - - pub fn lookWalk(p: *Pardes, delta: i32) void { - var buf: [MAX_PANES]usize = undefined; - const order = p.lookWalkPanes(&buf); - if (order.len == 0) return; - const owner = if (p.look_walk_owner) |serial| p.paneBySerial(serial) else null; - const active_at = std.mem.indexOfScalar(usize, order, p.active) orelse 0; - const at = if (owner) |wanted| - std.mem.indexOfScalar(usize, order, wanted) orelse active_at - else - active_at; - var from = lookStand(p.panes[order[at]] orelse return); - var budget: usize = max_look_rows; - var k: usize = 0; - while (k <= order.len) : (k += 1) { - // `+ 2 * len` only so the backward subtraction stays unsigned - const idx = (if (delta > 0) at + k else at + 2 * order.len - k) % order.len; - const pane = p.panes[order[idx]] orelse continue; - if (p.lookSpanIn(pane, from, delta, &budget)) |spot| - return p.landLookSpot(order[idx], pane, spot); - if (budget == 0) return; // gave up mid-pane: stay put, stay reversible - from = lookEdge(delta); - } - } - - fn landLookSpot(p: *Pardes, id: usize, pane: *Pane, spot: Pane.LookSpot) void { - edit.pinPaneCursor(p, pane); // fresh out of tty mode the cursor still tracks the shell - pane.vsel = .{ .active = true, .row = spot.row, .col = spot.col1, .explicit = true }; - pane.msel.active = false; - pane.nsel = 0; - pane.cur_row = spot.row; - pane.cur_col = spot.col0; - pane.cur_pinned = true; - pane.look_at = spot; - p.look_walk_owner = pane.serial; - p.active = id; - pane.ensureCursorVisible(); - } + pub const max_look_rows = 8192; // ---- edit operations (d / c / y / p) ---- // ---- dumb undo/redo: whole-state snapshots, one per edit op ---- - pub fn cancelLookHover(p: *Pardes) void { - if (comptime pdf_enabled) if (p.pdf_hover_preview) |*preview| { - if (preview.pane < p.panes.len) if (p.panes[preview.pane]) |pane| { - if (pane.serial == preview.serial) if (pane.pdf) |*pv| - pv.invalidateRaster(preview.probe.page); - }; - preview.deinit(p.pdf_gpa); - p.pdf_hover_preview = null; - }; - p.look_hover_wait = null; - p.look_hover_preview = null; - } - - fn lookHoverPane(p: *const Pardes) ?usize { - if (comptime pdf_enabled) if (p.pdf_hover_preview) |preview| return preview.pane; - if (p.look_hover_preview) |preview| return preview.pane; - if (p.look_hover_wait) |waiting| return waiting.pane; - return null; - } - - fn noteLookHover(p: *Pardes, col: u16, row: u16, body_hit: ?Mouse.BodyHit, tag_hit: ?TagHit) void { - const delay = config.look_preview_delay_frames orelse return; - _ = delay; - const id = mouse.paneAt(p, col, row) orelse return p.cancelLookHover(); - const pane = p.panes[id] orelse return p.cancelLookHover(); - _ = edit.pointerTextSelection(p, id, col, row, body_hit, tag_hit) orelse return p.cancelLookHover(); - - if (comptime pdf_enabled) if (p.pdf_hover_preview) |shown| - if (shown.col == col and shown.row == row and shown.pane == id and shown.serial == pane.serial) return; - if (p.look_hover_preview) |shown| - if (shown.col == col and shown.row == row and shown.pane == id and shown.serial == pane.serial and mouse.sameBodyCell(shown.body_hit, body_hit) and mouse.sameTagCell(shown.tag_hit, tag_hit)) return; - if (p.look_hover_wait) |waiting| - if (waiting.col == col and waiting.row == row and waiting.pane == id and waiting.serial == pane.serial and mouse.sameBodyCell(waiting.body_hit, body_hit) and mouse.sameTagCell(waiting.tag_hit, tag_hit)) return; - - p.cancelLookHover(); - p.look_hover_wait = .{ .col = col, .row = row, .pane = id, .serial = pane.serial, .body_hit = body_hit, .tag_hit = tag_hit }; - } - - pub fn refreshLookHoverFromRaw(p: *Pardes) void { - if (!p.pointer_inside or !p.raw_hover_intent) return; - const mapped = p.presentation.pointer(p.screen_w, p.screen_h, p.pointer_raw_col, p.pointer_raw_row) orelse - return p.cancelLookHover(); - p.hover_col = mapped.col; - p.hover_row = mapped.row; - const body_hit: ?Mouse.BodyHit = if (p.pointer_body_hit) |mapped_hit| - mouse.bodyHitForPane(p, mouse.paneAt(p, mapped.col, mapped.row) orelse return p.cancelLookHover(), mapped_hit, false) orelse return p.cancelLookHover() - else - null; - p.noteLookHover(mapped.col, mapped.row, body_hit, p.pointer_tag_hit); - } - - fn advanceLookHover(p: *Pardes) void { - const delay = config.look_preview_delay_frames orelse return; - const waiting = if (p.look_hover_wait) |*w| w else return; - waiting.frames +|= 1; - if (waiting.frames < delay) return; - const pane = p.panes[waiting.pane] orelse return p.cancelLookHover(); - if (pane.serial != waiting.serial) return p.cancelLookHover(); - const pointed = edit.pointerTextSelection(p, waiting.pane, waiting.col, waiting.row, waiting.body_hit, waiting.tag_hit) orelse - return p.cancelLookHover(); - if (comptime pdf_enabled) if (!pointed.on_tag and panes.Pdf.paneNativeReady(p, pane)) { - const probe = panes.Pdf.probeAt(p, pane, waiting.col, waiting.row) orelse - return p.cancelLookHover(); - const ready = waiting.*; - p.look_hover_wait = null; - p.pdf_hover_preview = .{ - .col = ready.col, - .row = ready.row, - .pane = ready.pane, - .serial = ready.serial, - .probe = probe, - }; - pane.pdf.?.invalidateRaster(probe.page); - return; - }; - const operand = p.pointerOperand(pane, pointed.sel); - if (operand.text == null or operand.text.?.len == 0) return p.cancelLookHover(); - var preview = operand.preview; - if (preview) |*sel| sel.state = .done; - p.look_hover_preview = .{ - .col = waiting.col, - .row = waiting.row, - .pane = waiting.pane, - .serial = waiting.serial, - .sel = preview, - .file_word = operand.file_word, - .body_hit = waiting.body_hit, - .tag_hit = waiting.tag_hit, - }; - p.look_hover_wait = null; - } - pub fn acknowledgePanelPresentation(p: *Pardes, tracks: []const layout.Track) void { p.presentation.acknowledge(p, tracks); if (p.pointer_inside and p.drag != .none) { @@ -6799,12 +6040,12 @@ pub const Pardes = struct { mouse.dragUpdate(p, mapped.col, mapped.row, p.pointer_body_hit); } } - p.refreshLookHoverFromRaw(); + look.refreshLookHoverFromRaw(p); } pub fn abandonPanelAnimations(p: *Pardes) void { p.presentation.cancel(); - p.cancelLookHover(); + look.cancelLookHover(p); } /// A native scene pass proved unavailable. Config reads these exact bits, @@ -6947,289 +6188,6 @@ pub const Pardes = struct { // ---- the ONE dispatcher: look (right/Enter) and execute (middle/Tab) ---- - pub fn focusPaneLine(p: *Pardes, id: usize, at: look.Spot, landing: enum { center, keep }) void { - if (id >= MAX_PANES) return; - const pane = p.panes[id] orelse return; - p.active = id; - pane.normal.clear(); - if (pane.hasPdf()) { - if (landing == .keep) return; - if (comptime pdf_enabled) { - const pv = &pane.pdf.?; - if (pv.focusLocation(p.pdf_gpa, at.line, at.col)) panes.Pdf.resetPageChrome(pane); - } - return; - } - if (at.line == 0) return; - if (pane.file) |*f| { - if (at.line > panes.File.nlines(p.gpa, f)) return; - if (landing == .center) { - const next = (at.line - 1) -| pane.rows / 2; // center, clamp at top - if (next != f.scroll) { - f.scroll = next; - f.syntax_dirty = true; - } - } - } - pane.cur_row = @intCast(at.line - 1); - pane.cur_col = if (at.col > 0) @intCast(at.col - 1) else 0; - pane.cur_pinned = true; - if (at.end_line != 0) return p.selectSpan(pane, at); - pane.ensureCursorVisible(); - } - - fn selectSpan(p: *Pardes, pane: *Pane, at: look.Spot) void { - const text = edit.flatSurface(p, pane) catch return; - // saturating, not `- 1`: `f.zig:0-5` is a legal thing to type and a - // 1-based zero is the same nothing an absent number is - const acol: i32 = @intCast(at.col -| 1); - const ecol: i32 = if (at.end_col > 0) @intCast(at.end_col - 1) else std.math.maxInt(i32); - const r = Pane.cellRange(text, @intCast(at.line -| 1), acol, @intCast(at.end_line -| 1), ecol); - pane.setRange(text, 0, r, true); - } - - fn openPaneTarget(p: *const Pardes, path: []const u8, at: look.Spot) ?look.Target { - for (p.panes, 0..) |slot, i| { - const tt = slot orelse continue; - if (tt.image) |iv| if (std.mem.eql(u8, iv.path, path)) { - return .{ .pane = .{ .id = i, .at = .{} } }; - }; - if (comptime pdf_enabled) if (tt.pdf) |pv| if (std.mem.eql(u8, pv.path, path)) { - return .{ .pane = .{ .id = i, .at = at } }; - }; - const ff = if (tt.file) |*f| f else continue; - if (!std.mem.eql(u8, ff.path, path)) continue; - return .{ .pane = .{ .id = i, .at = at } }; - } - return null; - } - - fn focusPaneByPath(p: *Pardes, path: []const u8, at: look.Spot) bool { - const target = p.openPaneTarget(path, at) orelse return false; - p.clearNavigationSelection(p.panes[target.pane.id].?); - p.focusPaneLine(target.pane.id, target.pane.at, .center); - return true; - } - - /// Navigation starts a new selection at the destination. - pub fn clearNavigationSelection(p: *Pardes, pane: *Pane) void { - pane.vsel = .{}; - pane.msel = .{}; - pane.nsel = 0; - pane.select = false; - pane.normal.clear(); - pane.append_at = null; - pane.sticky_col = -1; - for (0..pane.sel.len) |slot| pane.clearPointerSelection(slot); - pane.sel = @splat(.{}); - if (comptime pdf_enabled) if (pane.pdf) |*state| { - state.clearDrag(); - state.clearSelection(p.pdf_gpa); - }; - if (p.drag == .select and p.panes[p.drag.select.id] == pane) p.drag = .none; - } - - /// Resolve without changing focus or falling back to search. PDF links use - /// the same location rules as an ordinary Look before offering a choice. - fn resolveLookTarget(p: *Pardes, id: usize, txt: []const u8, realbuf: *[4096]u8) look.Target { - const trimmed = std.mem.trim(u8, txt, " \t\r\n"); - const pl = look.parsePathLine(trimmed); - if (pl.path.len > 0) if (p.openPaneTarget(pl.path, pl.at)) |target| return target; - var found: look.Target = .none; - var seen: [MAX_PANES][]const u8 = undefined; - var nseen: usize = 0; - var n: usize = 0; - cand: while (n <= p.njumps) : (n += 1) { - const k: usize = if (n == 0) id else p.jumps[p.njumps - n].pane; - if (n > 0 and k == id) continue; // tried first, skip the rerun - const op = p.panes[k] orelse continue; - const dir = paneDir(op); - for (seen[0..nseen]) |s| if (std.mem.eql(u8, s, dir)) continue :cand; - seen[nseen] = dir; - nseen += 1; - if (pl.path.len > 0 and pl.path[0] != '/') { - var joinbuf: [2048]u8 = undefined; - if (std.fmt.bufPrint(&joinbuf, "{s}/{s}", .{ dir, pl.path }) catch null) |j| - if (p.openPaneTarget(j, pl.at)) |target| return target; - } - found = look.resolve(p, txt, dir, realbuf); - if (found != .none or pl.path.len == 0 or pl.path[0] == '/') break; - } - return found; - } - - fn locationText(p: *Pardes, path: []const u8, at: look.Spot) ?[]const u8 { - if (std.mem.indexOfAny(u8, path, "\r\n") != null) return null; - const arena = p.scratch.allocator(); - if (at.line == 0) return arena.dupe(u8, path) catch null; - if (at.end_line != 0) { - if (at.col == 0 and at.end_col == 0) - return std.fmt.allocPrint(arena, "{s}:{d}-{d}", .{ path, at.line, at.end_line }) catch null; - return std.fmt.allocPrint(arena, "{s}:{d}:{d}-{d}:{d}", .{ path, at.line, at.col, at.end_line, at.end_col }) catch null; - } - if (at.col != 0) return std.fmt.allocPrint(arena, "{s}:{d}:{d}", .{ path, at.line, at.col }) catch null; - return std.fmt.allocPrint(arena, "{s}:{d}", .{ path, at.line }) catch null; - } - - fn canonicalLookLocation(p: *Pardes, id: usize, text: []const u8) ?[]const u8 { - const trimmed = std.mem.trim(u8, text, " \t\r\n"); - if (trimmed.len == 0) return null; - var realbuf: [4096]u8 = undefined; - switch (p.resolveLookTarget(id, trimmed, &realbuf)) { - .none => return null, - .url => |url| { - if (url.len > 256) return null; - for (url) |c| if (c <= 0x20 or c == 0x7f) return null; - return p.scratch.allocator().dupe(u8, url) catch null; - }, - .file => |file| return p.locationText(file.path, file.at), - .image => |iv| return p.locationText(iv.path, .{}), - .dir => |dir| return p.locationText(dir, .{}), - .pane => |target| { - if (target.id >= p.panes.len) return null; - const pane = p.panes[target.id] orelse return null; - if (pane.file) |file| return p.locationText(file.path, target.at); - if (comptime pdf_enabled) if (pane.pdf) |doc| return p.locationText(doc.path, target.at); - if (pane.image) |iv| return p.locationText(iv.path, target.at); - var path: [32]u8 = undefined; - return p.locationText(std.fmt.bufPrint(&path, config.pane_addr ++ "{d}", .{target.id}) catch return null, target.at); - }, - } - } - - pub fn pdfLinkLocation(p: *Pardes, pane: *const Pane, link: if (pdf_enabled) pdf.Link else void) ?[]const u8 { - if (comptime !pdf_enabled) return null; - const state = pane.pdf orelse return null; - const id = p.paneIdOf(pane) orelse return null; - return switch (link.destination) { - .none => null, - .internal => |dest| if (dest.page < state.document.pages) - p.locationText(state.path, .{ .line = dest.page + 1 }) - else - null, - .external => |uri| p.canonicalLookLocation(id, uri), - }; - } - - pub fn followPdfLink(p: *Pardes, id: usize, probe: *const panes.Pdf.WordProbe) void { - if (comptime !pdf_enabled) return; - const pane = p.panes[id] orelse return; - const link = probe.link orelse return; - const target = p.pdfLinkLocation(pane, link) orelse return; - p.clearNavigationSelection(pane); - if (p.canonicalLookLocation(id, probe.text)) |visible| { - if (!std.mem.eql(u8, visible, target)) { - const content = std.fmt.allocPrint(p.gpa, "{s}\n{s}\n", .{ visible, target }) catch |err| - return p.reportError(id, "PDF link choices", err); - panes.Output.fillResults(p, id, std.fs.path.dirname(pane.pdf.?.path) orelse ".", .pdf_links, "", content, null) catch |err| - return p.reportError(id, "PDF link choices", err); - return; - } - } - switch (link.destination) { - .internal => |dest| { - p.noteHaptic(.look); - p.noteLookSource(id); - p.active = id; - panes.Pdf.revealOutlineDestination(p, pane, dest); - }, - .external => p.lookAt(id, target), - .none => {}, - } - } - - pub fn lookAt(p: *Pardes, id: usize, operand: []const u8) void { - const pane = p.panes[id] orelse return; - p.noteHaptic(.look); - p.noteLookSource(id); - const command = std.mem.trim(u8, operand, " \t\r\n"); - if (config.commandWord(command)) |cmd| { - if (p.execute(id, cmd)) |dst| p.active = dst; - return; - } - // The operand may borrow selected terminal/PDF text released below. - const txt = p.scratch.allocator().dupe(u8, operand) catch return; - const trimmed = std.mem.trim(u8, txt, " \t\r\n"); - p.clearNavigationSelection(pane); - const pl = look.parsePathLine(trimmed); - if (comptime pdf_enabled) if (panes.Pdf.lookSection(p, id, pl.path, pl.at)) return; - var realbuf: [4096]u8 = undefined; - const found = p.resolveLookTarget(id, txt, &realbuf); - switch (found) { - .none => { - const bmode = if (pane.tag_edit) pane.tag_mode else pane.mode; - if (pane.image != null or bmode == .tty) return; - p.runSearch(id, trimmed, .text, .cursor) catch |err| { - p.reportError(id, "search", err); - return; - }; - const at = pane.search_row; - _ = p.searchStep(id, 1); - if (at != null and pane.search_row == at) { - pane.search_row = null; - _ = p.searchStep(id, 1); - } - }, - .pane => |t| { - if (t.id >= MAX_PANES) return; - const target = p.panes[t.id] orelse return; - p.clearNavigationSelection(target); - p.focusPaneLine(t.id, t.at, .center); - }, - .url => |u| if (u.len <= 256) p.emit(.{ .open_link = .from(u) }), - .dir => |dir| { - for (p.panes, 0..) |slot, i| { - if (slot) |tt| if (std.mem.eql(u8, tt.cwdSlice(), dir) and p.takesCommandLine(i)) { - p.clearNavigationSelection(tt); - p.active = i; - p.emitWrite(i, "ls\r"); - return; - }; - } - const free = p.freeSlot() orelse return p.reportError(id, "look", error.NoPaneSlots); - const nt = p.newShell(free, dir) catch |err| return p.reportError(id, "look", err); - nt.greet = true; - const src = layout.splitParent(p, id); - const f = layout.findPane(p, src).?; - layout.insert(p, f.col, f.idx + 1, free); - layout.splitBelow(p, src, nt); - p.active = free; - p.stillborn_joiner = nt.serial; - }, - .file => |target| { - if (comptime pdf_enabled) if (target.kind == .pdf) { - if (p.focusPaneByPath(target.path, target.at)) return; - const free = p.freeSlot() orelse return p.reportError(id, "look", error.NoPaneSlots); - const nt = panes.Pdf.openPane(p, free, target.path, target.at.line) catch |err| - return p.reportError(id, "look", err); - p.placeDoc(id, free, nt); - return; - }; - // focus an existing pane on this path (rescrolled), else open - if (p.focusPaneByPath(target.path, target.at)) return; - const free = p.freeSlot() orelse return p.reportError(id, "look", error.NoPaneSlots); - const nt = panes.File.open(p, free, target.path, target.at.line) catch |err| - return p.reportError(id, "look", err); - if (target.at.col > 0) nt.cur_col = @intCast(target.at.col - 1); - p.placeDoc(id, free, nt); - layout.compute(p); - nt.file.?.scroll -|= @max(1, p.rects[free].h -| BOX_H) / 2; - if (target.at.end_line != 0) { - const centered = nt.file.?.scroll; - p.selectSpan(nt, target.at); - nt.file.?.scroll = centered; - } - }, - .image => |target| { - if (p.focusPaneByPath(target.path, .{})) return; - const free = p.freeSlot() orelse return p.reportError(id, "look", error.NoPaneSlots); - const nt = panes.Image.create(p, free, target.path, &.{}) catch |err| - return p.reportError(id, "look", err); - p.placeDoc(id, free, nt); - }, - } - } - const max_exec_depth = 8; pub fn execute(p: *Pardes, id: usize, txt: []const u8) ?usize { @@ -7845,10 +6803,10 @@ pub const Pardes = struct { if (j.pane >= MAX_PANES) return; const pane = p.panes[j.pane] orelse return; if (pane.serial != j.serial) return; - if (p.panes[p.active]) |source| p.clearNavigationSelection(source); - if (p.active != j.pane) p.clearNavigationSelection(pane); + if (p.panes[p.active]) |source| look.clearNavigationSelection(p, source); + if (p.active != j.pane) look.clearNavigationSelection(p, pane); p.jcur = @intCast(next); - p.focusPaneLine(j.pane, .{ .line = j.line, .col = j.col }, .center); + look.focusPaneLine(p, j.pane, .{ .line = j.line, .col = j.col }, .center); } /// Recompute geometry, push grid-size changes to each emulator + pty, fire @@ -7921,7 +6879,7 @@ pub const Pardes = struct { return p.presentation.animating(); } - fn noteHaptic(p: *Pardes, pulse: Haptic) void { + pub fn noteHaptic(p: *Pardes, pulse: Haptic) void { if (comptime platform != .macos) return; if (p.haptic == .look) return; p.haptic = pulse; @@ -9262,7 +8220,7 @@ test "Esc back into a file leaves its view where it was" { try std.testing.expect(dp.cur_row < @as(i32, @intCast(view)) + @as(i32, dp.rows)); // The other arm still centres: a look target, a `:NN`, a search hit. - p.focusPaneLine(doc, .{ .line = @intCast(row + 1), .col = 1 }, .center); + look.focusPaneLine(p, doc, .{ .line = @intCast(row + 1), .col = 1 }, .center); try std.testing.expect(dp.file.?.scroll != view); try std.testing.expectEqual(@as(usize, @intCast(row)) -| @as(usize, dp.rows) / 2, dp.file.?.scroll); } @@ -9724,39 +8682,6 @@ test "board heap: every allocation failure during boot is a clean OutOfMemory" { ); } -test "Look copies its operand before releasing pointer selection storage" { - const p = try Pardes.init(std.testing.allocator, .{ .cols = 60, .rows = 12 }); - defer p.deinit(); - const pane = try p.setTestFile("alpha beta\ngamma delta\nepsilon zeta\n"); - const operand = try p.gpa.dupe(u8, "/test.txt:3:2"); - pane.sel[0] = .{ .state = .done, .source_id = 1 }; - pane.pointer_selections[0] = .{ - .gesture = pane.sel[0], - .rows = try p.gpa.alloc(Pane.PointerRow, 0), - .raw_text = operand, - }; - p.drag = .{ .select = .{ .id = 0, .button = config.select_button } }; - p.lookAt(0, operand); - try std.testing.expectEqual(@as(i32, 2), pane.cur_row); - try std.testing.expectEqual(@as(i32, 1), pane.cur_col); - try std.testing.expect(pane.pointer_selections[0] == null); - try std.testing.expectEqual(.none, pane.sel[0].state); - try std.testing.expectEqual(.none, p.drag); -} - -test "Look ignores missing and out of bounds pane addresses" { - const p = try Pardes.init(std.testing.allocator, .{ .cols = 60, .rows = 12 }); - defer p.deinit(); - const pane = try p.setTestFile("alpha\nbravo\n"); - for ([_][]const u8{ config.pane_addr ++ "15:2", config.pane_addr ++ "999999:2" }) |operand| { - pane.setRange(pane.file.?.content, 0, .{ .anchor = 0, .head = 3 }, true); - p.lookAt(0, operand); - try std.testing.expectEqual(@as(usize, 0), p.active); - try std.testing.expectEqual(@as(i32, 0), pane.cur_row); - try std.testing.expect(!pane.vsel.active); - } -} - test "jump history clears selections and lands at the recorded cursor" { const p = try Pardes.init(std.testing.allocator, .{ .cols = 60, .rows = 12 }); defer p.deinit(); diff --git a/src/pdf_view.zig b/src/pdf_view.zig index 106252a0..9b623183 100644 --- a/src/pdf_view.zig +++ b/src/pdf_view.zig @@ -1962,7 +1962,7 @@ fn refreshCleanSections(core: *pardes.Pardes, state: *State) void { core.gpa.free(content); return; } - core.invalidateLookHover(remembered.pane); + look.invalidateLookHover(core, remembered.pane); File.setContent(core, file, content); const rows = File.lineCount(file.content); file.scroll = @min(file.scroll, rows - 1); @@ -2009,7 +2009,7 @@ fn rearmCleanSections( result.nsel = 0; pane.search_pane = remembered.pane; pane.search_row = null; - core.armLookWalk(remembered.pane); + look.armLookWalk(core, remembered.pane); core.active = id; return true; } @@ -2049,7 +2049,7 @@ pub fn openSections(core: *pardes.Pardes, id: usize) void { core.active = id; pane.search_pane = free; pane.search_row = null; - core.armLookWalk(free); + look.armLookWalk(core, free); } const SectionsOwner = struct { @@ -2098,7 +2098,7 @@ pub fn lookSection( const destination = owner.state.sectionDestination(core.pdf_gpa, at.col - 1) orelse return true; switch (destination) { .internal => |internal| { - core.clearNavigationSelection(owner.pane); + look.clearNavigationSelection(core, owner.pane); revealOutlineDestination(core, owner.pane, internal); }, .external => |uri| if (uri.len <= 256) core.emit(.{ .open_link = .from(uri) }), @@ -2282,7 +2282,7 @@ pub fn probeAt( const state = &(pane.pdf orelse return null); if (state.document.linkAt(core.pdf_gpa, page, point) catch null) |found| { var link = found; - if (core.pdfLinkLocation(pane, link) != null) { + if (look.pdfLinkLocation(core, pane, link) != null) { const quads = core.pdf_gpa.alloc(pdf.Quad, 1) catch { link.deinit(core.pdf_gpa); return null; diff --git a/test/fs_namespace.zig b/test/fs_namespace.zig index ec94b509..470615c9 100644 --- a/test/fs_namespace.zig +++ b/test/fs_namespace.zig @@ -224,7 +224,7 @@ test "virtual file opens do not request OS watches" { test "Look at a virtual file opens one pane and failed opens release their slot" { const p = try pardes.Pardes.init(std.testing.allocator, .{ .tty_only = true }); defer p.deinit(); - p.lookAt(0, "/virtual/index"); + pardes.look.lookAt(p, 0, "/virtual/index"); var opened: usize = 0; for (p.panes) |slot| { const pane = slot orelse continue; diff --git a/test/output.zig b/test/output.zig index ebea79d4..b4c018db 100644 --- a/test/output.zig +++ b/test/output.zig @@ -610,7 +610,7 @@ test "EffectCode lists readable virtual sources used by this backend" { } try std.testing.expect(count >= 3); const report = p.active; - p.lookAt(report, backend_source); + pardes.look.lookAt(p, report, backend_source); try std.testing.expect(p.active != report); const source = p.panes[p.active].?.file.?; try std.testing.expectEqualStrings(backend_source, source.path); @@ -722,7 +722,7 @@ test "n/N in ordinary text skips comment slashes and retains real paths" { defer p.deinit(); const pane = try p.setTestFile("// ordinary comment\n/// documentation comment\n(//) [///] punctuation\n/\n// /tmp\n//tmp\n"); try std.testing.expect(pane.file.?.output == null); - p.armLookWalk(0); + pardes.look.armLookWalk(p, 0); const available = p.freeSlot(); for ([_]struct { key: u21, row: i32, text: []const u8 }{ .{ .key = 'n', .row = 3, .text = "/" }, @@ -796,7 +796,7 @@ test "n/N skips formatted context and selects comment match locations" { try p.dumpState(); const restored = try Pardes.initFromDump(p.gpa, .{ .tty_only = true }, p.dump_out.?); defer restored.deinit(); - restored.armLookWalk(id); + pardes.look.armLookWalk(restored, id); const restored_result = restored.panes[id].?; restored.update(.{ .key = .{ .cp = 'n' } }); try std.testing.expectEqual(@as(i32, @intCast(matches[0])), restored_result.cur_row); @@ -1562,7 +1562,7 @@ test "stacked search and LSP results retain source tint navigation and dump owne try std.testing.expectEqual(@intFromEnum(pardes.syntax.Syn.number), file.highlights[number]); p.active = id; pane.mode = .normal; - p.armLookWalk(id); + pardes.look.armLookWalk(p, id); for ([_]struct { key: u21, match: usize }{ .{ .key = 'n', .match = 0 }, .{ .key = 'n', .match = 1 }, .{ .key = 'N', .match = 0 } }) |step| { p.update(.{ .key = .{ .cp = step.key } }); try std.testing.expectEqual(@as(i32, @intCast(matches[step.match])), pane.cur_row); @@ -1585,7 +1585,7 @@ test "stacked search and LSP results retain source tint navigation and dump owne try std.testing.expectEqualSlices(u8, before.colors, after.colors); } restored.active = id; - restored.armLookWalk(id); + pardes.look.armLookWalk(restored, id); restored.update(.{ .key = .{ .cp = 'N' } }); try std.testing.expectEqual(@as(i32, @intCast(matches[1])), restored.panes[id].?.cur_row); try std.testing.expectEqualStrings(source_text, source.file.?.content); diff --git a/test/panes.zig b/test/panes.zig index e865641f..f45d42b2 100644 --- a/test/panes.zig +++ b/test/panes.zig @@ -494,7 +494,7 @@ const TreeContextTests = struct { defer frame.deinit(); _ = try p.render(frame.allocator()); try std.testing.expectEqual(@as(i32, 0), pane.scroll()); - p.lookAt(0, "/tree-context.zig:60"); + pardes.look.lookAt(p, 0, "/tree-context.zig:60"); try std.testing.expectEqual(@as(usize, 0), p.active); try std.testing.expectEqual(@as(i32, 59), pane.cur_row); const surface = try p.render(frame.allocator()); @@ -4469,7 +4469,7 @@ const LookResetTests = struct { const pane = try p.setTestFile("alpha\nbravo\ncharlie\nneedle\n"); try seed(pane, "/test.txt:3:2"); // This operand is released by Look's selection cleanup. - p.lookAt(0, pane.pointer_selections[0].?.raw_text.?); + pardes.look.lookAt(p, 0, pane.pointer_selections[0].?.raw_text.?); try cleared(pane); try std.testing.expectEqual(@as(usize, 0), p.active); try std.testing.expectEqual(@as(i32, 2), pane.cur_row); @@ -4477,7 +4477,7 @@ const LookResetTests = struct { try std.testing.expect(!pane.vsel.active); try seed(pane, "/test.txt:2:2-4"); - p.lookAt(0, pane.pointer_selections[0].?.raw_text.?); + pardes.look.lookAt(p, 0, pane.pointer_selections[0].?.raw_text.?); try cleared(pane); try std.testing.expectEqual(@as(i32, 1), pane.cur_row); try std.testing.expectEqualStrings("rav", selected(pane)); @@ -4485,7 +4485,7 @@ const LookResetTests = struct { p.gpa.free(pane.file.?.path); pane.file.?.path = try p.gpa.dupe(u8, "/tmp/look-selection-source.txt"); try seed(pane, "needle"); - p.lookAt(0, pane.pointer_selections[0].?.raw_text.?); + pardes.look.lookAt(p, 0, pane.pointer_selections[0].?.raw_text.?); try cleared(pane); try std.testing.expectEqual(@as(i32, 3), pane.cur_row); try std.testing.expectEqualStrings("needle", selected(pane)); @@ -4508,7 +4508,7 @@ const LookResetTests = struct { p.active = 0; try seed(source, if (range) "/look-destination.txt:2:2-4" else "/look-destination.txt:3:2"); try seed(destination, "previous destination"); - p.lookAt(0, source.pointer_selections[0].?.raw_text.?); + pardes.look.lookAt(p, 0, source.pointer_selections[0].?.raw_text.?); try std.testing.expectEqual(id, p.active); try cleared(source); try cleared(destination); diff --git a/test/pdf.zig b/test/pdf.zig index 25d0de76..69a82123 100644 --- a/test/pdf.zig +++ b/test/pdf.zig @@ -135,9 +135,9 @@ const PdfLinkTests = struct { const choices_id = for (p.panes, 0..) |slot, id| { if (slot == choices) break id; } else return error.MissingPdfLinkChoices; - p.lookAt(choices_id, "https://example.com/embedded"); + pardes.look.lookAt(p, choices_id, "https://example.com/embedded"); try expectOpened(p, "https://example.com/embedded"); - p.lookAt(choices_id, "target.txt"); + pardes.look.lookAt(p, choices_id, "target.txt"); try std.testing.expectEqualStrings("chosen file\n", p.panes[p.active].?.file.?.content); p.active = 0; _ = try p.render(frame.allocator()); @@ -349,16 +349,16 @@ test "PdfSections Look follows the exact owning PDF, not an equal path" { const first_row = std.mem.sliceTo(first_output.file.?.content, '\n'); const target = first_row[0 .. std.mem.indexOfScalar(u8, first_row, ' ') orelse first_row.len]; - p.lookAt(first_output_id, target); + pardes.look.lookAt(p, first_output_id, target); try std.testing.expectEqual(@as(usize, 0), p.active); - p.lookAt(duplicate_output_id, target); + pardes.look.lookAt(p, duplicate_output_id, target); try std.testing.expectEqual(duplicate_id, p.active); // Once the original document is gone, its output cannot reinterpret an // old ordinal against the still-open equal-path duplicate. try std.testing.expect(pardes.test_api.runBuiltin(p, "Del", 0, "", null)); p.active = first_output_id; - p.lookAt(first_output_id, target); + pardes.look.lookAt(p, first_output_id, target); try std.testing.expectEqual(first_output_id, p.active); } @@ -881,7 +881,7 @@ test "MuPDF pane renders, navigates, searches, and round-trips its page" { try std.testing.expect(pane.pdf.?.document_scroll_y > before_height_scroll); const revision_before_search = active_raster.revision; - try p.runSearch(0, "Pardes", .text, .top); + try pardes.look.runSearch(p, 0, "Pardes", .text, .top); try std.testing.expectEqualStrings("Pardes", pane.pdf.?.search_query); try std.testing.expectEqual(revision_before_search, active_raster.revision); const results_id = pane.search_pane orelse return error.MissingPdfSearchResults; @@ -1578,7 +1578,7 @@ test "PDF n/N addresses and reveals distinct MuPDF hits on one page" { p.locations_config.context = 2; p.locations_config.tscontext = true; - try p.runSearch(0, "Pardes", .text, .top); + try pardes.look.runSearch(p, 0, "Pardes", .text, .top); const results_id = pane.search_pane orelse return error.MissingPdfSearchResults; const results = p.panes[results_id].?.file.?; var found: [3]bool = @splat(false); diff --git a/test/perf.zig b/test/perf.zig index 7d3b5e3d..6ce8f014 100644 --- a/test/perf.zig +++ b/test/perf.zig @@ -445,7 +445,7 @@ fn measure(op: Op, fx: Fixture, path: []const u8, expected_bytes: usize, reps: u const core = try boot(); defer core.deinit(); const t0 = nowNs(); - core.lookAt(0, path); + pardes.look.lookAt(core, 0, path); pump(core); _ = try frame(core); const dt = nowNs() -| t0; @@ -459,7 +459,7 @@ fn measure(op: Op, fx: Fixture, path: []const u8, expected_bytes: usize, reps: u const core = try boot(); defer core.deinit(); - core.lookAt(0, path); + pardes.look.lookAt(core, 0, path); pump(core); const id = filePane(core) orelse return error.OpenDidNotOpenFile; core.active = id; -- cgit v1.3 From 52049344c1992850ea712e029eb5c4a88a7dfe19 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Sun, 27 Sep 2026 22:30:58 -0300 Subject: Move exec out of pardes.zig into exec.zig Pure move, no behaviour change (acme keeps this in exec.c): execute, commandText, max_exec_depth, executeBuiltinLine, applyStartupConfig, runBuiltin and applySettingBuiltin; the getarg-style operand code (withArg, PointerOperand, pointerOperand, heldSelection, chordEachSel); takesCommandLine and the terminals commands run in (spawnTty, spawnV9fsTty, spawnTtyWithMount, evictLonePristineTty, replaceStillborn, ttyForDir); placeDoc; and the save path (submitSave, saveFile, saveTo, askWrite), with the acme-chords test, go verbatim to exec.zig. The methods become free functions taking `p: *Pardes`. executeBuiltinLine is called from ~170 places as `p.executeBuiltinLine(..)`, so Pardes keeps one declaration alias for it and those call sites stay; the other 104 calls change from `p.execute(..)` to `exec.execute(p, ..)`. ninep/ctl.zig has a local named exec, so it writes `pardes.exec.execute` instead of importing the file. Co-Authored-By: Claude Opus 5.5 --- src/Mini.zig | 3 +- src/Output.zig | 7 +- src/builtins.zig | 15 +- src/exec.zig | 571 ++++++++++++++++++++++++++++++++++++++++++++ src/fs.zig | 1 + src/look.zig | 17 +- src/mouse.zig | 25 +- src/ninep/ctl.zig | 2 +- src/ninep/events.zig | 3 +- src/ninep/pane.zig | 3 +- src/normal.zig | 7 +- src/pardes.zig | 653 +++++---------------------------------------------- src/pdf_view.zig | 3 +- test/panes.zig | 6 +- test/pdf.zig | 2 +- 15 files changed, 681 insertions(+), 637 deletions(-) create mode 100644 src/exec.zig (limited to 'src/Output.zig') diff --git a/src/Mini.zig b/src/Mini.zig index bc93f678..52e26a37 100644 --- a/src/Mini.zig +++ b/src/Mini.zig @@ -2,6 +2,7 @@ const panes = @import("panes.zig"); const std = @import("std"); const pardes = @import("pardes.zig"); +const exec = @import("exec.zig"); const config = @import("config.zig"); const Pardes = pardes.Pardes; const modal = @import("modal.zig"); @@ -187,7 +188,7 @@ pub fn open(p: *Pardes, id: usize, argument: []const u8) !void { .syntax_dirty = false, }; pane.cur_pinned = true; - p.placeDoc(id, free, pane); + exec.placeDoc(p, id, free, pane); p.active = free; } diff --git a/src/Output.zig b/src/Output.zig index 674fcbc8..b216c0cf 100644 --- a/src/Output.zig +++ b/src/Output.zig @@ -3,6 +3,7 @@ const panes = @import("panes.zig"); const std = @import("std"); const pardes = @import("pardes.zig"); +const exec = @import("exec.zig"); const Messages = @import("Messages.zig"); const config = @import("config.zig"); const Pardes = pardes.Pardes; @@ -479,7 +480,7 @@ pub fn fillResults(p: *Pardes, id: usize, dir: []const u8, from: Origin, arg: [] const free = p.freeSlot() orelse return error.NoPaneSlots; const np = try open(p, free, dir, from, arg, result_content); np.file.?.location_rows = result_rows; - p.placeDoc(id, free, np); + exec.placeDoc(p, id, free, np); p.active = id; if (traits(from).steps) { pane.search_pane = free; @@ -559,7 +560,7 @@ fn openStepped(p: *Pardes, id: usize, from: Origin, content: []u8) !void { const dir = if (pane.file) |f| (std.fs.path.dirname(f.path) orelse "/") else pane.cwdSlice(); const free = p.freeSlot() orelse return error.NoPaneSlots; const np = try open(p, free, dir, from, "", content); - p.placeDoc(id, free, np); + exec.placeDoc(p, id, free, np); p.active = id; pane.search_pane = free; pane.search_row = null; @@ -778,6 +779,6 @@ fn openRead(p: *Pardes, id: usize, from: Origin, arg: []const u8, content: []u8) const dir = if (pane.file) |f| (std.fs.path.dirname(f.path) orelse "/") else pane.cwdSlice(); const free = p.freeSlot() orelse return error.NoPaneSlots; const np = try open(p, free, dir, from, arg, content); - p.placeDoc(id, free, np); + exec.placeDoc(p, id, free, np); p.active = free; } diff --git a/src/builtins.zig b/src/builtins.zig index 21dd4fa9..19be62e2 100644 --- a/src/builtins.zig +++ b/src/builtins.zig @@ -1,6 +1,7 @@ //! Command structs and runtime settings form the builtin registry; bindings live in config.zig. const std = @import("std"); const pardes = @import("pardes.zig"); +const exec = @import("exec.zig"); const look = @import("look.zig"); const edit = @import("edit.zig"); const colors = @import("colors.zig"); @@ -155,7 +156,7 @@ pub const registry = struct { inline for (manualBuiltinList(), 0..) |T, i| if (@intFromEnum(b) == i) return T.run(c); inline for (comptime settingList(), manualBuiltinCount()..) |setting, i| - if (@intFromEnum(b) == i) return c.p.applySettingBuiltin(setting, c.arg); + if (@intFromEnum(b) == i) return exec.applySettingBuiltin(c.p, setting, c.arg); unreachable; } }; @@ -223,7 +224,7 @@ pub const Exec = struct { pub fn run(c: Ctx) void { // the destination pane is Look's business (it focuses what answered); // an execute deliberately leaves you where you were - _ = c.p.execute(c.id, c.arg orelse return); + _ = exec.execute(c.p, c.id, c.arg orelse return); } }; @@ -478,8 +479,8 @@ pub const Save = struct { pub const takes_arg = true; pub fn run(c: Ctx) void { const path = std.mem.trim(u8, c.arg orelse "", " \t\r\n"); - if (path.len > 0) return c.p.saveTo(c.id, path); - if (c.pane.file) |file| if (file.output == null) return c.p.saveFile(c.id); + if (path.len > 0) return exec.saveTo(c.p, c.id, path); + if (c.pane.file) |file| if (file.output == null) return exec.saveFile(c.p, c.id); if (c.pane.file != null or c.pane.isTerminal()) c.p.startPrompt(c.pane, .save); } }; @@ -585,7 +586,7 @@ pub const DelBelow = struct { /// pane's tagline: the fast path from wherever you are to a prompt there. pub const Tty = struct { pub fn run(c: Ctx) void { - c.p.spawnTty(c.id); + exec.spawnTty(c.p, c.id); } }; @@ -593,7 +594,7 @@ pub const Tty = struct { pub const Tty9p = struct { pub const enabled = pardes.hosted and @import("builtin").os.tag == .linux; pub fn run(c: Ctx) void { - c.p.spawnV9fsTty(c.id); + exec.spawnV9fsTty(c.p, c.id); } }; @@ -609,7 +610,7 @@ pub const Tutor = struct { pub fn run(c: Ctx) void { const free = c.p.freeSlot() orelse return; const nt = c.p.openTutorView(free) catch return; - c.p.placeDoc(c.id, free, nt); // a doc like any other + exec.placeDoc(c.p, c.id, free, nt); // a doc like any other } }; diff --git a/src/exec.zig b/src/exec.zig new file mode 100644 index 00000000..75d07441 --- /dev/null +++ b/src/exec.zig @@ -0,0 +1,571 @@ +//! Executing a word (acme's exec.c): a builtin line or a command typed into +//! a terminal, the builtin dispatch and settings, the operand a click or +//! chord hands over, the terminals commands run in, placing a document, and +//! saving a pane. +const pardes = @import("pardes.zig"); +const std = @import("std"); +const layout = @import("layout.zig"); +const modal = @import("modal.zig"); +const look = @import("look.zig"); +const panes = @import("panes.zig"); +const normal = @import("normal.zig"); +const edit = @import("edit.zig"); +const body_layer = @import("body_layer.zig"); +const colors = @import("colors.zig"); +const themes = colors.themes; +const builtins = @import("builtins.zig"); +const config = @import("config.zig"); +const pdf_enabled = panes.Pdf.enabled; +const font_picker = pardes.font_picker; +const hosted = pardes.hosted; +const fonts = pardes.fonts; +const Pane = panes.Pane; +const MAX_COLS = pardes.MAX_COLS; +const BOX_H = pardes.BOX_H; +const Builtin = pardes.Builtin; +const Key = pardes.Key; +const sel_slot = pardes.sel_slot; +const Pardes = pardes.Pardes; + +pub fn takesCommandLine(p: *const Pardes, id: usize) bool { + const pane = p.panes[id] orelse return false; + if (!pane.isTerminal()) return false; + // A mounted shell sits behind sudo's process supervisor. Its OSC 133 + // prompt marks identify input readiness; the launcher's executable is + // not the shell executable used by the ordinary process heuristic. + if (pane.v9fs_on_spawn) return panes.Terminal.promptInputReady(pane); + return !p.hostTtyTaken(id); +} + +pub fn chordEachSel(p: *Pardes, pane: *Pane, cmd: Builtin) bool { + if (pane.nsel == 0) return false; + const text = edit.flatSurface(p, pane) catch return false; + var ranges: [Pane.max_selections]modal.Selection = undefined; + const got = pane.ranges(text, 0, &ranges); + if (got.n < 2) return false; + + var texts: [Pane.max_selections][]u8 = undefined; + var made: usize = 0; + defer for (texts[0..made]) |t| p.gpa.free(t); + for (ranges[0..got.n]) |range| { + const lo = @min(range.anchor, range.head); + const hi = @max(range.anchor, range.head); + if (hi > text.len) break; + texts[made] = p.gpa.dupe(u8, text[lo..hi]) catch break; + made += 1; + } + // All or nothing, like the pipe: half a chord is not a chord. + if (made != got.n) return false; + + const id = p.active; + const serial = pane.serial; + pane.vsel.active = false; + pane.msel.active = false; + pane.select = false; + pane.nsel = 0; // the chord consumed them, exactly as it consumes one + + var primary_active: ?usize = null; + for (texts[0..made], 0..) |txt, i| { + runBuiltin(p, cmd, id, "", txt); + if (i == got.pri) primary_active = p.active; + const still = p.panes[id] orelse break; + if (still.serial != serial) break; + } + if (primary_active) |a| if (p.panes[a] != null) { + p.active = a; + }; + return true; +} + +pub const PointerOperand = struct { + /// Absolute body position corresponding to the pointed screen cell. + row: i32, + col: i32, + /// Exactly what a no-drag middle/right click will dispatch. + text: ?[]const u8 = null, + /// What hover paints. Null names the pane's live modal selection. + preview: ?Pane.Sel = null, + /// File words stay logical so a soft-wrapped operand is not cut into + /// unrelated rendered fragments. Null for tags and non-file panes. + file_word: ?look.FileWordSpan = null, + /// A newly expanded word is installed in the gesture's button slot; + /// an existing selection is only borrowed and must not replace it. + expanded: ?Pane.Sel = null, +}; + +pub fn pointerOperand(p: *Pardes, pane: *Pane, clicked: Pane.Sel) PointerOperand { + const visible = clicked.r0 - @as(i32, BOX_H); + const wrapped = pane.wrapAt(visible); + const raw = pane.isTerminal() and pane.mode == .tty and clicked.r0 >= BOX_H; + const row = if (raw) panes.Terminal.gridOffset(pane) + visible else wrapped.line; + const raw_line = if (raw) modal.lineSlice(body_layer.bodyText(p, p.scratch.allocator(), pane) catch "", @intCast(@max(0, visible))) else ""; + const col = if (raw) + @as(i32, @intCast(panes.File.rawAtDisplay(raw_line, @intCast(@max(0, clicked.c0))))) + else if (clicked.r0 >= BOX_H) + edit.paneByteAtDisplay( + p, + pane, + wrapped.line, + wrapped.at, + clicked.c0 - (if (pane.file != null) @as(i32, panes.File.gutterWidth(pane)) else 0), + ) + else + clicked.c0; + var result: PointerOperand = .{ .row = row, .col = col }; + + const kept = pane.sel[sel_slot]; + const inside_kept = if (pane.pointerSelection(kept)) |rows| inside: { + if (clicked.r0 < BOX_H) break :inside false; + if (pane.file != null and clicked.c0 < panes.File.gutterWidth(pane)) break :inside false; + const source_col: usize = @intCast(@max(0, col)); + for (rows) |span| { + const target = if (span.raw_terminal) + (if (raw) span.row else pane.surfRow(span.row)) + else + (if (raw) pane.gridRow(span.row) else span.row); + var lo = span.lo; + var hi = span.hi; + if (span.raw_terminal and !raw) { + lo -|= span.prompt_bytes; + hi -|= span.prompt_bytes; + } else if (!span.raw_terminal and raw) { + const prefix = panes.Terminal.promptPrefixBytes(pane, row, raw_line); + lo += prefix; + hi += prefix; + } + if (target == row and source_col >= lo and source_col < hi) + break :inside true; + } + break :inside false; + } else edit.spanHas(clicked.r0, clicked.c0, kept.r0, kept.c0, kept.r1, kept.c1); + if (kept.state == .done and inside_kept) { + result.text = edit.selectionText(p, pane, kept) catch null; + result.preview = kept; + return result; + } + if (pane.vsel.active and pane.vsel.explicit and + edit.spanHas(row, col, pane.vsel.row, pane.vsel.col, pane.cur_row, pane.cur_col)) + { + result.text = edit.currentSelText(p, pane); + return result; + } + if (pane.msel.active and row >= @min(pane.msel.r0, pane.msel.r1) and + row <= @max(pane.msel.r0, pane.msel.r1)) + { + result.text = edit.currentSelText(p, pane); + return result; + } + if (pane.file != null and clicked.r0 >= BOX_H and clicked.r0 == clicked.r1 and clicked.c0 == clicked.c1) { + const line = panes.File.sourceLine(pane, row); + const source_col: usize = @intCast(@max(0, col)); + const b = look.expandedWord(line, source_col) orelse return result; + const lo = std.math.cast(i32, b.lo) orelse return result; + const hi = std.math.cast(i32, b.hi) orelse return result; + result.text = line[b.lo..b.hi]; + result.file_word = .{ .row = row, .lo = lo, .hi = hi }; + + var expanded = clicked; + const first = pane.wrapRow(row, lo); + const last = pane.wrapRow(row, hi - 1); + if (first.row >= 0 and last.row >= 0) { + expanded.r0 = first.row + @as(i32, BOX_H); + expanded.c0 = @as(i32, panes.File.gutterWidth(pane)) + panes.File.displayOffset(pane, row, first.at, lo); + expanded.r1 = last.row + @as(i32, BOX_H); + expanded.c1 = @as(i32, panes.File.gutterWidth(pane)) + panes.File.displayEndOffset(pane, row, last.at, hi - 1); + } + result.preview = expanded; + result.expanded = expanded; + return result; + } + + const expanded = look.expandedSel(p, pane, clicked) orelse return result; + result.text = edit.selectionText(p, pane, expanded) catch null; + if (result.text == null or result.text.?.len == 0) return result; + result.preview = expanded; + result.expanded = expanded; + return result; +} + +pub fn heldSelection(p: *Pardes, first: usize) ?[]const u8 { + var k: usize = 0; + while (k < p.panes.len + 2) : (k += 1) { + const i = switch (k) { + 0 => first, + 1 => p.active, + else => k - 2, + }; + if (k > 0 and (i == first or (k > 1 and i == p.active))) continue; + const t = p.panes[i] orelse continue; + if (comptime pdf_enabled) if (p.native_images) if (t.pdf) |pv| { + if (pv.selection != null and pv.selection_text.len > 0) + return pv.selection_text; + }; + if (t.sel[sel_slot].state == .done) { + if (edit.selectionText(p, t, t.sel[sel_slot]) catch null) |tx| return tx; + } else if ((t.vsel.active and t.vsel.explicit) or t.msel.active) { + if (edit.currentSelText(p, t)) |tx| return tx; + } + } + return null; +} + +pub fn withArg(p: *Pardes, txt: []const u8, arg: ?[]const u8) []const u8 { + const a = std.mem.trim(u8, arg orelse return txt, " \t\r\n"); + if (a.len == 0) return txt; + const t = std.mem.trim(u8, txt, " \t\r\n"); + return std.fmt.allocPrint(p.scratch.allocator(), "{s} {s}", .{ t, a }) catch txt; +} + +/// Enter on a save input: the path is everything past the marker. +pub fn submitSave(p: *Pardes, id: usize) void { + const pane = p.panes[id] orelse return; + const at = switch (pane.prompt) { + .save => |a| a, + else => return, + }; + const armed = pane.tag_tail[at..pane.tag_tail_len]; + pane.tag_tail_len = at; // drop the prompt back to the seeded tail + if (!std.mem.startsWith(u8, armed, config.save_marker)) return; + const path = std.mem.trim(u8, armed[config.save_marker.len..], " \t\r\n"); + if (path.len == 0) return; + saveTo(p, id, path); +} + +/// Write the file this pane already has: acme's Put, and the one Save that +/// needs no argument because the path was never a question. +pub fn saveFile(p: *Pardes, id: usize) void { + const pane = p.panes[id] orelse return; + const f = if (pane.file) |*file| file else return; + if (f.output != null) return; // nothing behind it yet: saveTo, with a path + p.emit(.{ .save_file = .{ .pane = @intCast(id) } }); +} + +pub fn saveTo(p: *Pardes, id: usize, path: []const u8) void { + const pane = p.panes[id] orelse return; + if (path.len == 0 or path[path.len - 1] == '/' or + std.mem.indexOfScalar(u8, path, '\n') != null) + return p.reportError(id, "save", error.NoFilename); + const full = std.fs.path.resolvePosix( + p.scratch.allocator(), + &.{ Pardes.paneDir(pane), path }, + ) catch return; + if (!std.fs.path.isAbsolute(full)) return p.reportError(id, "save", error.NoDirectory); + if (full.len > Pardes.SavePath.cap) return p.reportError(id, "save", error.PathTooLong); + const f = if (pane.file) |*file| file else { + // a terminal writes its scrollback; an image and a PDF have nothing + // of their own that is unwritten, so they have nothing to write + if (pane.isTerminal()) askWrite(p, id, pane.serial, full); + return; + }; + if (f.output != null and panes.Output.fileTraits(f.output).saves) { + const owned = p.gpa.dupe(u8, full) catch return; + p.gpa.free(f.path); + f.path = owned; + f.output = null; // an ordinary file pane from here on + f.watch_after_save = true; + pane.clearCwd(); + pane.tag_init = false; // re-derive the tag as a plain file + pane.tag_tail_len = 0; + p.emit(.{ .save_file = .{ .pane = @intCast(id) } }); + return; + } + // its own path, spelled out: the in-place write, so the pane comes clean + if (f.output == null and std.mem.eql(u8, f.path, full)) return saveFile(p, id); + askWrite(p, id, pane.serial, full); +} + +fn askWrite(p: *Pardes, id: usize, serial: u32, path: []const u8) void { + p.emit(.{ .save_text = .{ + .pane = @intCast(id), + .serial = serial, + .path = Pardes.SavePath.from(path), + } }); +} + +/// Tty: a shell in the caller's directory, raw from the first frame, +/// stacked below the caller like Alt-n's new shell. +pub fn spawnTty(p: *Pardes, from: usize) void { + spawnTtyWithMount(p, from, false); +} + +pub fn spawnV9fsTty(p: *Pardes, from: usize) void { + if (comptime !hosted or @import("builtin").os.tag != .linux) + return p.reportError(from, "Tty9p", error.LinuxRequired); + if (p.fs.socket_path.len == 0) + return p.reportError(from, "Tty9p", error.SessionSocketRequired); + spawnTtyWithMount(p, from, true); +} + +fn spawnTtyWithMount(p: *Pardes, from: usize, v9fs: bool) void { + const src = p.panes[from] orelse return; + const free = p.freeSlot() orelse return; + const nt = p.newShell(free, Pardes.paneDir(src)) catch return; + nt.greet = !v9fs; + nt.v9fs_on_spawn = v9fs; + nt.mode = .tty; + const parent = layout.splitParent(p, from); + const f = layout.findPane(p, parent).?; + layout.insert(p, f.col, f.idx + 1, free); + layout.splitBelow(p, parent, nt); + p.active = free; + p.stillborn_joiner = nt.serial; +} + +/// when a doc lands in `col`, a lone pristine shell there is clutter — drop +/// it; absorbVWeight hands its space to the doc +pub fn evictLonePristineTty(p: *Pardes, col: usize, keep_id: usize) void { + var n_tty: usize = 0; + var tty_id: usize = 0; + for (0..p.col_n[col]) |k| { + const cid = p.col_panes[col][k]; + if (p.panes[cid]) |ct| if (ct.isTerminal()) { + n_tty += 1; + tty_id = cid; + }; + } + if (n_tty != 1) return; + const tt = p.panes[tty_id] orelse return; + // No typing, cursor on the first prompt line, no scrollback: this is + // the throwaway boot placeholder a document may replace. + if (tt.ovl != null or panes.Terminal.gridCursor(tt).y != 0 or + panes.Terminal.scrollbar(tt).total > tt.rows) return; + p.deinitPane(tt) catch |err| return p.reportError(tty_id, "close", err); + layout.compute(p); // a just-stacked doc has no rect yet; absorb snaps to rows + layout.absorbVWeight(p, tty_id, null); + layout.removePane(p, tty_id); + p.panes[tty_id] = null; + if (p.active == tty_id) p.active = keep_id; +} + +/// A pane that just joined a column whose only other pane is stillborn — +/// an empty scratch nobody typed into, body or tag (what Newcol makes and +/// what a closed column's last pane leaves behind) — takes the column +/// whole: the placeholder was only holding the space for it. Run at the +/// end of a step: the pane that asked for the joiner is often the +/// placeholder itself, and its caller is still holding it. +pub fn replaceStillborn(p: *Pardes) void { + const serial = p.stillborn_joiner orelse return; + p.stillborn_joiner = null; + const new_id = p.paneBySerial(serial) orelse return; + const f = layout.findPane(p, new_id) orelse return; + if (p.col_n[f.col] != 2) return; + const old_id = p.col_panes[f.col][1 - f.idx]; + const old = p.panes[old_id] orelse return; + const file = old.file orelse return; + const out = file.output orelse return; + if (out.from != .cmd or out.from.cmd != .New) return; + if (file.revision != 0 or file.content.len != 0) return; + if (old.tag_init and !std.mem.eql(u8, old.tagSlice(), Pardes.defaultTail(old))) return; + const was_active = p.active == old_id; + layout.compute(p); // the joiner may have no rect yet; absorb snaps to rows + p.removePane(old_id, new_id) catch |err| return p.reportError(old_id, "close", err); + if (was_active) p.active = new_id; +} + +fn ttyForDir(p: *Pardes, dir: []const u8) ?usize { + for (p.panes, 0..) |slot, i| if (slot) |tt| { + if (!std.mem.eql(u8, tt.cwdSlice(), dir)) continue; + if (takesCommandLine(p, i)) return i; + }; + const free = p.freeSlot() orelse return null; + const nt = p.newShell(free, dir) catch return null; + nt.greet = false; + const rc = if (p.ncol > 0) p.ncol - 1 else 0; + if (p.col_n[rc] > 0) { + const src = layout.splitParent(p, p.col_panes[rc][p.col_n[rc] - 1]); + const f = layout.findPane(p, src).?; + layout.splitBelow(p, src, nt); + layout.insert(p, f.col, f.idx + 1, free); + } else layout.insert(p, rc, p.col_n[rc], free); + return free; +} + +const max_exec_depth = 8; + +pub fn execute(p: *Pardes, id: usize, txt: []const u8) ?usize { + const pane = p.panes[id] orelse return null; + const cmd = commandText(txt); + if (cmd.len == 0) return null; + if (p.exec_depth == 0) p.noteHaptic(.exec); + if (executeBuiltinLine(p, id, cmd)) return null; + if (p.exec_depth >= max_exec_depth) return null; + p.exec_depth += 1; + defer p.exec_depth -= 1; + const dst = (if (takesCommandLine(p, id)) id else ttyForDir(p, Pardes.paneDir(pane))) orelse return null; + panes.Terminal.padOutputBelowEdits(p, dst); + if (panes.Terminal.queuePendingCommand(p.panes[dst].?, cmd) catch |err| { + p.reportError(id, "queue command", err); + return dst; + }) return dst; + p.emitWrite(dst, cmd); + p.emitWrite(dst, "\r"); + return dst; +} + +/// Trim and unwrap clickable command-word notation once for every command +/// consumer, so startup lines and interactive Exec speak the same syntax. +pub fn commandText(txt: []const u8) []const u8 { + var cmd = std.mem.trim(u8, txt, " \t\r\n"); + while (config.commandWord(cmd)) |inner| cmd = std.mem.trim(u8, inner, " \t\r\n"); + return cmd; +} + +pub fn executeBuiltinLine(p: *Pardes, id: usize, txt: []const u8) bool { + const cmd = commandText(txt); + if (cmd.len == 0 or p.exec_depth >= max_exec_depth) return false; + const sp = std.mem.indexOfAny(u8, cmd, " \t"); + const bi: ?Builtin = std.meta.stringToEnum(Builtin, cmd) orelse blk: { + const head = std.meta.stringToEnum(Builtin, cmd[0 .. sp orelse break :blk null]) orelse break :blk null; + break :blk if (builtins.registry.takesArg(head)) head else null; + }; + const b = bi orelse return false; + p.exec_depth += 1; + defer p.exec_depth -= 1; + const typed = if (sp) |s| std.mem.trim(u8, cmd[s + 1 ..], " \t") else ""; + runBuiltin(p, b, id, cmd, if (typed.len > 0) typed else null); + return true; +} + +pub fn applyStartupConfig(p: *Pardes) void { + p.announce = false; + defer p.announce = true; + var lines = std.mem.splitScalar(u8, p.opts.startup_config orelse return, '\n'); + while (lines.next()) |line| _ = executeBuiltinLine(p, p.active, line); +} + +pub fn runBuiltin(p: *Pardes, b: Builtin, id: usize, txt: []const u8, arg: ?[]const u8) void { + if (!normal.multiOnce(p)) return; // a builtin is per-keystroke, never per-cursor + const pane = p.panes[id] orelse 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. + if (p.announce and p.settings.verbose and builtins.registry.announces(b)) { + p.setMessage(id, @tagName(b)); + pane.msg_announcement = true; + } + const c: builtins.Ctx = .{ .p = p, .pane = pane, .id = id, .txt = txt, .arg = arg }; + builtins.registry.dispatch(b, c); +} + +pub fn applySettingBuiltin(p: *Pardes, setting: config.Runtime.Setting, arg: ?[]const u8) void { + const previous_colors = p.settings.colors; + const previous_context_style = p.settings.tree_context_tag_style; + const previous_transition = p.settings.panel_transition; + const previous_tagline_percent = p.settings.font.tagline_percent; + const previous_column_tags = p.settings.column_tags; + switch (setting.action) { + .theme => { + const want = std.mem.trim(u8, arg orelse return, " \t\r\n"); + for (themes, 0..) |t, i| if (std.mem.eql(u8, t.name, want)) { + colors.setThemeIndex(p, i); + return; + }; + }, + .font => { + if (comptime !font_picker) return; + const spec = config.Runtime.FontSpec.parse(arg orelse return) orelse return; + const matches = fonts.list(p.scratch.allocator(), spec.name); + if (matches.len == 0) return; + if (!p.settings.requestFont(matches[0].path, matches[0].name, spec.size_hundredths)) return; + p.font_request_taken = false; + }, + else => _ = p.settings.apply(setting, arg), + } + if (p.settings.colors != previous_colors) { + for (p.panes) |slot| { + const pane = slot orelse continue; + if (pane.file) |*file| file.syntax_dirty = true; + } + } + if (p.settings.tree_context_tag_style != previous_context_style) { + for (p.panes, 0..) |slot, id| { + p.surface.body_layers[id].rows = 0; + const pane = slot orelse continue; + pane.body_rows = 0; + pane.body_visible_rows = 0; + pane.context_row_limit = null; + pane.wrap_n = 0; + } + p.abandonPanelAnimations(); + } + const transition_changed = setting.action == .transition and + p.settings.panel_transition != previous_transition; + const tagline_metrics_changed = setting.action == .tagline_size and + p.settings.font.tagline_percent != previous_tagline_percent; + if (p.settings.column_tags != previous_column_tags) { + if (p.header_column != null) p.exitHeader(); + } + if (transition_changed or tagline_metrics_changed or p.settings.column_tags != previous_column_tags) { + p.abandonPanelAnimations(); + } +} + +pub fn placeDoc(p: *Pardes, from_id: usize, free: usize, nt: *Pane) void { + p.stillborn_joiner = nt.serial; + const doc = if (nt.file) |f| panes.Output.fileTraits(f.output).doc else true; // an image is a doc + var src_id: ?usize = null; + if (p.panes[from_id]) |src| if (if (src.file) |f| panes.Output.fileTraits(f.output).doc else src.image != null or src.hasPdf()) { + src_id = from_id; + }; + if (doc and src_id == null) { + var n = p.njumps; + while (n > 0) : (n -= 1) { + const j = p.jumps[n - 1]; + const pp = p.panes[j.pane] orelse continue; + if (pp.serial != j.serial) continue; + if (if (pp.file) |f| panes.Output.fileTraits(f.output).doc else pp.image != null or pp.hasPdf()) { + src_id = j.pane; + break; + } + } + } + if (doc and src_id == null) for (p.panes, 0..) |sl, i| { + if (sl) |pp| if (i != free and (if (pp.file) |f| panes.Output.fileTraits(f.output).doc else pp.image != null or pp.hasPdf())) { + src_id = i; + break; + }; + }; + if (!doc) if (layout.findPane(p, from_id)) |sf| { + layout.insert(p, sf.col, sf.idx + 1, free); + layout.splitBelow(p, from_id, nt); // NOT splitParent: no bystander pays + p.active = free; + return; + }; + if (src_id == null and doc and p.ncol < MAX_COLS and + layout.columnFitsHalves(p, from_id, 100) and layout.splitColumn(p, from_id, free, true)) + { + p.active = free; + return; + } + // Without room for a first-document column, split the Look origin + // just like Tty. Never displace (or evict) a top-left bystander. + const src = layout.splitParent(p, src_id orelse from_id); + const sf = layout.findPane(p, src).?; + layout.insert(p, sf.col, sf.idx + 1, free); + layout.splitBelow(p, src, nt); + p.active = free; +} + +test "the acme chords act once per selection, not once on the primary" { + const gpa = std.testing.allocator; + const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 100, .rows = 30 }); + defer p.deinit(); + while (p.nextEffect()) |_| {} + // Two selections, each naming a DIFFERENT builtin, so what ran is visible + // in the layout rather than in a shell nobody can read from a test. + const pane = try p.setTestFile("Newcol\nNewcol\n"); + const ranges = [_]modal.Selection{ + .{ .anchor = 0, .head = 6 }, + .{ .anchor = 7, .head = 13 }, + }; + pane.setRanges(pane.file.?.content, &ranges, &.{}, 0, true); + try std.testing.expectEqual(@as(u8, 1), pane.nsel); + + const before = p.ncol; + p.update(.{ .key = .{ .cp = Key.tab } }); // config.exec_key: Exec + // BOTH ran. Before this the chord read the primary range and dropped the + // other cursor, so one keystroke over two cursors made one column. + try std.testing.expectEqual(before + 2, p.ncol); + // ...and the chord consumed the selection exactly as it does with one. + try std.testing.expectEqual(@as(u8, 0), p.panes[0].?.nsel); +} diff --git a/src/fs.zig b/src/fs.zig index 13fce858..825e63bb 100644 --- a/src/fs.zig +++ b/src/fs.zig @@ -43,6 +43,7 @@ const source_files = [_]Source{ .{ .path = "src/edit.zig", .contents = @embedFile("edit.zig") }, .{ .path = "src/normal.zig", .contents = @embedFile("normal.zig") }, .{ .path = "src/mouse.zig", .contents = @embedFile("mouse.zig") }, + .{ .path = "src/exec.zig", .contents = @embedFile("exec.zig") }, .{ .path = "src/File.zig", .contents = @embedFile("File.zig") }, .{ .path = "src/Output.zig", .contents = @embedFile("Output.zig") }, .{ .path = "src/Mini.zig", .contents = @embedFile("Mini.zig") }, diff --git a/src/look.zig b/src/look.zig index af0905a4..1534d332 100644 --- a/src/look.zig +++ b/src/look.zig @@ -2,6 +2,7 @@ const std = @import("std"); const builtin = @import("builtin"); const libc = std.c; const pardes = @import("pardes.zig"); +const exec = @import("exec.zig"); const config = @import("config.zig"); const pdf_enabled = @import("pardes_config").mupdf; const fs = @import("fs.zig"); @@ -528,7 +529,7 @@ fn lookFirstHit(p: *Pardes, id: usize) void { rp.vsel.active = false; rp.msel.active = false; rp.select = false; - p.runBuiltin(config.look_cmd, rid, "", txt); + exec.runBuiltin(p, config.look_cmd, rid, "", txt); } pub fn runSearch(p: *Pardes, id: usize, pat_raw: []const u8, kind: Search, start: SearchStart) !void { @@ -686,7 +687,7 @@ pub fn jumpResult(p: *Pardes, id: usize, row: usize) bool { rp.look_at = null; } if (tr.commands) { - p.runBuiltin(config.exec_cmd, rid, "", std.mem.trim(u8, ln, " \t\r")); + exec.runBuiltin(p, config.exec_cmd, rid, "", std.mem.trim(u8, ln, " \t\r")); } else if (span) |selected| { lookAt(p, rid, ln[selected.start..selected.end]); // This is the newly visited result, not a selection carried into @@ -922,7 +923,7 @@ pub fn advanceLookHover(p: *Pardes) void { pane.pdf.?.invalidateRaster(probe.page); return; }; - const operand = p.pointerOperand(pane, pointed.sel); + const operand = exec.pointerOperand(p, pane, pointed.sel); if (operand.text == null or operand.text.?.len == 0) return cancelLookHover(p); var preview = operand.preview; if (preview) |*sel| sel.state = .done; @@ -1136,7 +1137,7 @@ pub fn lookAt(p: *Pardes, id: usize, operand: []const u8) void { noteLookSource(p, id); const command = std.mem.trim(u8, operand, " \t\r\n"); if (config.commandWord(command)) |cmd| { - if (p.execute(id, cmd)) |dst| p.active = dst; + if (exec.execute(p, id, cmd)) |dst| p.active = dst; return; } // The operand may borrow selected terminal/PDF text released below. @@ -1171,7 +1172,7 @@ pub fn lookAt(p: *Pardes, id: usize, operand: []const u8) void { .url => |u| if (u.len <= 256) p.emit(.{ .open_link = .from(u) }), .dir => |dir| { for (p.panes, 0..) |slot, i| { - if (slot) |tt| if (std.mem.eql(u8, tt.cwdSlice(), dir) and p.takesCommandLine(i)) { + if (slot) |tt| if (std.mem.eql(u8, tt.cwdSlice(), dir) and exec.takesCommandLine(p, i)) { clearNavigationSelection(p, tt); p.active = i; p.emitWrite(i, "ls\r"); @@ -1194,7 +1195,7 @@ pub fn lookAt(p: *Pardes, id: usize, operand: []const u8) void { const free = p.freeSlot() orelse return p.reportError(id, "look", error.NoPaneSlots); const nt = panes.Pdf.openPane(p, free, target.path, target.at.line) catch |err| return p.reportError(id, "look", err); - p.placeDoc(id, free, nt); + exec.placeDoc(p, id, free, nt); return; }; // focus an existing pane on this path (rescrolled), else open @@ -1203,7 +1204,7 @@ pub fn lookAt(p: *Pardes, id: usize, operand: []const u8) void { const nt = panes.File.open(p, free, target.path, target.at.line) catch |err| return p.reportError(id, "look", err); if (target.at.col > 0) nt.cur_col = @intCast(target.at.col - 1); - p.placeDoc(id, free, nt); + exec.placeDoc(p, id, free, nt); layout.compute(p); nt.file.?.scroll -|= @max(1, p.rects[free].h -| BOX_H) / 2; if (target.at.end_line != 0) { @@ -1217,7 +1218,7 @@ pub fn lookAt(p: *Pardes, id: usize, operand: []const u8) void { const free = p.freeSlot() orelse return p.reportError(id, "look", error.NoPaneSlots); const nt = panes.Image.create(p, free, target.path, &.{}) catch |err| return p.reportError(id, "look", err); - p.placeDoc(id, free, nt); + exec.placeDoc(p, id, free, nt); }, } } diff --git a/src/mouse.zig b/src/mouse.zig index 27d5dd9c..2a00bded 100644 --- a/src/mouse.zig +++ b/src/mouse.zig @@ -2,6 +2,7 @@ //! releases (acme's chords, border and seam drags, gestures), and the //! chrome targets a shell asks about. const pardes = @import("pardes.zig"); +const exec = @import("exec.zig"); const look = @import("look.zig"); const std = @import("std"); const layout = @import("layout.zig"); @@ -341,9 +342,9 @@ pub fn handleMouse(p: *Pardes, m: Mouse) void { if (word.len > 0) { if (m.button == config.exec_button) { const named = std.meta.stringToEnum(Builtin, word); - const held = if (named) |b| (if (builtins.registry.takesArg(b)) p.heldSelection(p.active) else null) else p.heldSelection(p.active); - _ = p.execute(p.active, p.withArg(word, held)); - } else p.runBuiltin(config.look_cmd, p.active, "", word); + const held = if (named) |b| (if (builtins.registry.takesArg(b)) exec.heldSelection(p, p.active) else null) else exec.heldSelection(p, p.active); + _ = exec.execute(p, p.active, exec.withArg(p, word, held)); + } else exec.runBuiltin(p, config.look_cmd, p.active, "", word); } } return; @@ -389,7 +390,7 @@ pub fn handleMouse(p: *Pardes, m: Mouse) void { config.select_button => switch (m.kind) { .press => { if (p.drag == .select and p.drag.select.button == config.exec_button) { - if (p.heldSelection(p.drag.select.id)) |tx| { + if (exec.heldSelection(p, p.drag.select.id)) |tx| { if (p.chord_arg) |old| p.gpa.free(old); p.chord_arg = p.gpa.dupe(u8, tx) catch null; } @@ -629,7 +630,7 @@ fn reportGesture( cmd: Builtin, text: []const u8, on_tag: bool, - operand: Pardes.PointerOperand, + operand: exec.PointerOperand, chorded: bool, ) bool { const scripted = p.panes[id] orelse return false; @@ -639,7 +640,7 @@ fn reportGesture( (if (on_tag) .tag_look else .body_look) else (if (on_tag) .tag_exec else .body_exec); - const named = std.meta.stringToEnum(Builtin, Pardes.commandText(text)) != null; + const named = std.meta.stringToEnum(Builtin, exec.commandText(text)) != null; const range = gestureRange(p, id, text, on_tag, operand); var flag: u32 = if (named) ctlfs.events.flag_builtin else 0; if (range.q0 == range.q1 and text.len > 0) flag |= ctlfs.events.flag_expansion; @@ -649,7 +650,7 @@ fn reportGesture( return ctlfs.events.noteAction(p, id, action, range.q0, range.q1, flag, text); } -fn gestureRange(p: *Pardes, id: usize, text: []const u8, on_tag: bool, operand: Pardes.PointerOperand) ctlfs.pane.State.Range { +fn gestureRange(p: *Pardes, id: usize, text: []const u8, on_tag: bool, operand: exec.PointerOperand) ctlfs.pane.State.Range { const pane = p.panes[id] orelse return .{}; if (on_tag) { const tag = p.tagText(p.scratch.allocator(), pane) catch return .{}; @@ -697,7 +698,7 @@ fn dispatchPointerBuiltin( id: usize, cmd: Builtin, text: ?[]const u8, - gesture: ?struct { on_tag: bool, operand: Pardes.PointerOperand }, + gesture: ?struct { on_tag: bool, operand: exec.PointerOperand }, ) void { const arg = p.chord_arg; p.chord_arg = null; @@ -707,7 +708,7 @@ fn dispatchPointerBuiltin( return; }; if (gesture) |g| if (reportGesture(p, id, cmd, operand, g.on_tag, g.operand, arg != null)) return; - p.runBuiltin(cmd, id, "", p.withArg(operand, arg)); + exec.runBuiltin(p, cmd, id, "", exec.withArg(p, operand, arg)); } fn mirrorTtySelection(p: *Pardes, pane: *Pane) void { @@ -769,7 +770,7 @@ fn dragRelease(p: *Pardes, button: Mouse.Button) void { // a file moved into the left column evicts a lone unused shell if (p.panes[d.id]) |mt| if (mt.file != null) { if (layout.findPane(p, d.id)) |f| if (f.col == 0) - p.evictLonePristineTty(0, d.id); + exec.evictLonePristineTty(p, 0, d.id); }; }, .select => |s| { @@ -848,11 +849,11 @@ fn dragRelease(p: *Pardes, button: Mouse.Button) void { pane.sel[b].state = .none; var buf: [48]u8 = undefined; const target = std.fmt.bufPrint(&buf, "@p{d}:{d}", .{ s.id, @as(usize, @intCast(line)) + 1 }) catch return; - p.runBuiltin(config.look_cmd, s.id, "", target); + exec.runBuiltin(p, config.look_cmd, s.id, "", target); return; } }; - var operand = p.pointerOperand(pane, clk); + var operand = exec.pointerOperand(p, pane, clk); if (operand.expanded) |expanded| pane.sel[b] = expanded else if (operand.text == null) diff --git a/src/ninep/ctl.zig b/src/ninep/ctl.zig index 25fe4037..645b1c33 100644 --- a/src/ninep/ctl.zig +++ b/src/ninep/ctl.zig @@ -59,7 +59,7 @@ fn activeSerial(p: *Pardes) ?u32 { fn run(p: *Pardes, id: usize, exec: bool, text: []const u8) void { const context = p.panes[id].?.serial; const before = Serials.snapshot(p); - if (exec) _ = p.execute(id, text) else look.lookAt(p, id, text); + if (exec) _ = pardes.exec.execute(p, id, text) else look.lookAt(p, id, text); const after = Serials.snapshot(p); var created = false; for (after.list[0..after.len]) |serial| if (!before.has(serial)) { diff --git a/src/ninep/events.zig b/src/ninep/events.zig index d4d7fcad..49e852b3 100644 --- a/src/ninep/events.zig +++ b/src/ninep/events.zig @@ -2,6 +2,7 @@ //! bounded queues that park a read until something happens. const std = @import("std"); const pardes = @import("../pardes.zig"); +const exec = @import("../exec.zig"); const look = @import("../look.zig"); const tree = @import("tree.zig"); const pane_files = @import("pane.zig"); @@ -461,7 +462,7 @@ pub fn writeEvent(p: *Pardes, req: Req, id: usize) Reply { const hi = @max(lo, @min(@as(usize, r.q1), whole.len)); const text = p.scratch.allocator().dupe(u8, whole[lo..hi]) catch continue; switch (r.action) { - .body_exec, .tag_exec => _ = p.execute(live, text), + .body_exec, .tag_exec => _ = exec.execute(p, live, text), .body_look, .tag_look => look.lookAt(p, live, text), else => unreachable, } diff --git a/src/ninep/pane.zig b/src/ninep/pane.zig index 4110380a..76854dbc 100644 --- a/src/ninep/pane.zig +++ b/src/ninep/pane.zig @@ -3,6 +3,7 @@ //! mark and scroll, errors, event, look and exec. Terminals add pty/ (pty.zig). const std = @import("std"); const pardes = @import("../pardes.zig"); +const exec = @import("../exec.zig"); const look = @import("../look.zig"); const panes = @import("../panes.zig"); const modal = @import("../modal.zig"); @@ -589,7 +590,7 @@ pub fn appendErrors(p: *Pardes, id: usize, text: []const u8) ?usize { p.gpa.free(content); return null; }; - p.placeDoc(id, free, np); + exec.placeDoc(p, id, free, np); return text.len; } diff --git a/src/normal.zig b/src/normal.zig index e273f7f1..6647dcca 100644 --- a/src/normal.zig +++ b/src/normal.zig @@ -2,6 +2,7 @@ //! modal actions, replayed across every selection, and each action is done //! to the pane; PDF panes get their own normal keys. const pardes = @import("pardes.zig"); +const exec = @import("exec.zig"); const look = @import("look.zig"); const std = @import("std"); const mvzr = @import("mvzr"); @@ -302,7 +303,7 @@ fn executeNormalAction(p: *Pardes, pane: *Pane, semantic: modal.Normal.Action) v switch (semantic) { .escape => { pane.select = false; - return p.runBuiltin(.Last, p.active, "", null); + return exec.runBuiltin(p, .Last, p.active, "", null); }, .goto => |go| switch (go.target) { .file_start => { @@ -566,11 +567,11 @@ pub fn handlePdfNormal(p: *Pardes, pane: *Pane, key: Key) void { if (hit(key, config.leave_pane)) { pane.normal.clear(); pane.select = false; - return p.runBuiltin(.Last, p.active, "", null); + return exec.runBuiltin(p, .Last, p.active, "", null); } if (pane.normal.prefix == .none and isPrefix(key, 'f')) { pane.normal.clear(); - return p.runBuiltin(.PdfSections, p.active, "", null); + return exec.runBuiltin(p, .PdfSections, p.active, "", null); } const parsed = modal.Normal.parse(&pane.normal, normalInput(key)); switch (parsed) { diff --git a/src/pardes.zig b/src/pardes.zig index bdde1455..75766827 100644 --- a/src/pardes.zig +++ b/src/pardes.zig @@ -11,6 +11,7 @@ pub const syntax = @import("syntax.zig"); pub const locations_config = @import("locations_config.zig"); const tracy = @import("tracy.zig"); pub const panes = @import("panes.zig"); +pub const exec = @import("exec.zig"); pub const mouse = @import("mouse.zig"); pub const normal = @import("normal.zig"); pub const edit = @import("edit.zig"); @@ -435,6 +436,7 @@ pub const Loc = struct { }; test { + _ = @import("exec.zig"); _ = @import("look.zig"); _ = @import("mouse.zig"); _ = @import("normal.zig"); @@ -497,7 +499,7 @@ pub const test_api = if (@import("builtin").is_test) struct { arg: ?[]const u8, ) bool { const command = std.meta.stringToEnum(Builtin, name) orelse return false; - p.runBuiltin(command, id, txt, arg); + exec.runBuiltin(p, command, id, txt, arg); return true; } @@ -510,7 +512,7 @@ pub const test_api = if (@import("builtin").is_test) struct { } pub fn heldSelection(p: *Pardes, first: usize) ?[]const u8 { - return p.heldSelection(first); + return exec.heldSelection(p, first); } } else struct {}; @@ -581,30 +583,6 @@ test "Detach asks the frontend to leave, and says so when there is nothing to le try std.testing.expect(!p.quit); } -test "the acme chords act once per selection, not once on the primary" { - const gpa = std.testing.allocator; - const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 100, .rows = 30 }); - defer p.deinit(); - while (p.nextEffect()) |_| {} - // Two selections, each naming a DIFFERENT builtin, so what ran is visible - // in the layout rather than in a shell nobody can read from a test. - const pane = try p.setTestFile("Newcol\nNewcol\n"); - const ranges = [_]modal.Selection{ - .{ .anchor = 0, .head = 6 }, - .{ .anchor = 7, .head = 13 }, - }; - pane.setRanges(pane.file.?.content, &ranges, &.{}, 0, true); - try std.testing.expectEqual(@as(u8, 1), pane.nsel); - - const before = p.ncol; - p.update(.{ .key = .{ .cp = Key.tab } }); // config.exec_key: Exec - // BOTH ran. Before this the chord read the primary range and dropped the - // other cursor, so one keystroke over two cursors made one column. - try std.testing.expectEqual(before + 2, p.ncol); - // ...and the chord consumed the selection exactly as it does with one. - try std.testing.expectEqual(@as(u8, 0), p.panes[0].?.nsel); -} - test "startup config runs builtin lines in order and isolates bad lines" { const p = try Pardes.init(std.testing.allocator, .{ .startup_config = @@ -1188,11 +1166,11 @@ test "Tty9p marks only the new Linux terminal for a mounted shell" { try std.testing.expect(pane.isTerminal() and pane.mode == .tty); try std.testing.expect(pane.v9fs_on_spawn); try std.testing.expect(!pane.greet); - try std.testing.expect(!p.takesCommandLine(p.active)); + try std.testing.expect(!exec.takesCommandLine(p, p.active)); panes.Terminal.feedOutput(p, pane, "\x1b]133;A\x07$ \x1b]133;B\x07"); - try std.testing.expect(p.takesCommandLine(p.active)); + try std.testing.expect(exec.takesCommandLine(p, p.active)); panes.Terminal.feedOutput(p, pane, "\x1b]133;C\x07"); - try std.testing.expect(!p.takesCommandLine(p.active)); + try std.testing.expect(!exec.takesCommandLine(p, p.active)); } test "first document fallback splits like Tty from the originating pane" { @@ -1215,8 +1193,8 @@ test "first document fallback splits like Tty from the originating pane" { p.active = (from + 1) % 3; const free = p.freeSlot().?; const doc = try p.openTutorView(free); - p.placeDoc(from, free, doc); - tty.spawnTty(from); + exec.placeDoc(p, from, free, doc); + exec.spawnTty(tty, from); p.sync(); tty.sync(); try std.testing.expectEqual(@as(usize, 2), p.ncol); @@ -1240,7 +1218,7 @@ test "first document keeps its originating shell and only opens a column when it defer p.deinit(); const shell = p.panes[0].?; const doc = try p.openTutorView(1); - p.placeDoc(0, 1, doc); + exec.placeDoc(p, 0, 1, doc); p.sync(); try std.testing.expectEqual(shell, p.panes[0].?); try std.testing.expectEqual(@as(usize, 1), p.active); @@ -1318,7 +1296,7 @@ test "unknown Exec from an image writes to a terminal in the image directory" { const image_doc = try p.newDocPane(1); image_doc.image = .{ .path = try gpa.dupe(u8, "/tmp/pardes-image-dir/pic.ppm") }; try std.testing.expectEqualStrings("/tmp/pardes-image-dir", Pardes.paneDir(image_doc)); - try std.testing.expectEqual(@as(?usize, 0), p.execute(1, "echo image-fallback")); + try std.testing.expectEqual(@as(?usize, 0), exec.execute(p, 1, "echo image-fallback")); var sent: [256]u8 = undefined; var sent_len: usize = 0; @@ -1364,7 +1342,7 @@ test "Exec in a terminal whose tty is taken spawns a shell instead of typing at var host: FakeTtyQuery = .{}; host.install(p); host.taken[0] = true; - const dst = p.execute(0, "echo taken-fallback") orelse return error.ExecFoundNowhereToRun; + const dst = exec.execute(p, 0, "echo taken-fallback") orelse return error.ExecFoundNowhereToRun; // somewhere ELSE — and still without moving focus, which is execute's // contract and the whole difference between it and a look try std.testing.expect(dst != 0); @@ -1466,7 +1444,7 @@ test "Exec from a document pane skips an occupied terminal in its directory and host.install(p); host.taken[0] = true; - const dst = p.execute(1, "echo image-fallback") orelse return error.ExecFoundNowhereToRun; + const dst = exec.execute(p, 1, "echo image-fallback") orelse return error.ExecFoundNowhereToRun; try std.testing.expect(dst != 0 and dst != 1); var spawned: ?Effect = null; @@ -1551,13 +1529,13 @@ test "a terminal its program gave back takes command lines again" { var host: FakeTtyQuery = .{}; host.install(p); host.taken[0] = true; - try std.testing.expect(p.execute(0, "echo while-taken") != 0); + try std.testing.expect(exec.execute(p, 0, "echo while-taken") != 0); while (p.nextEffect()) |_| {} // the program exited, so the host's answer changes — and the core asks // again, because it never cached the old one host.taken[0] = false; - try std.testing.expectEqual(@as(?usize, 0), p.execute(0, "echo after")); + try std.testing.expectEqual(@as(?usize, 0), exec.execute(p, 0, "echo after")); var sent: [64]u8 = undefined; var sent_len: usize = 0; while (p.nextEffect()) |effect| switch (effect) { @@ -1595,13 +1573,13 @@ test "the host is asked about a tty only where a command line is about to go" { try std.testing.expectEqual(@as(usize, 0), host.asked); // The pane an Exec is typed into is one question, asked once... - _ = p.execute(0, "echo lazy"); + _ = exec.execute(p, 0, "echo lazy"); while (p.nextEffect()) |_| {} try std.testing.expectEqual(@as(usize, 1), host.asked); host.taken[0] = true; host.asked = 0; - _ = p.execute(0, "echo lazy-again"); + _ = exec.execute(p, 0, "echo lazy-again"); while (p.nextEffect()) |_| {} try std.testing.expectEqual(@as(usize, 2), host.asked); } @@ -1654,7 +1632,7 @@ test "owned cwd preserves long paths aliases and failed updates" { const free = p.freeSlot().?; try std.testing.expectError(error.PathTooLong, p.newShell(free, path[0 .. effect_path_cap + 1])); try std.testing.expect(p.panes[free] == null); - p.saveTo(0, "file.txt"); + 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], "PathTooLong") != null); @@ -1820,7 +1798,7 @@ test "owned cwd Save promotion releases the former directory" { const id = p.active; const pane = p.panes[id].?; try pane.setOwnedCwd("/old/directory"); - p.saveTo(id, "saved.txt"); + exec.saveTo(p, id, "saved.txt"); try std.testing.expect(pane.cwd == .none); try std.testing.expect(pane.file.?.output == null); try std.testing.expectEqualStrings("/old/directory/saved.txt", pane.file.?.path); @@ -1847,7 +1825,7 @@ test "Save on a scratch asks for a path in its inherited dir and makes it a file // typing the filename and submitting converts it into an ordinary file try std.testing.expect(np.appendTag("note.txt")); - p.submitSave(id); + exec.submitSave(p, id); try std.testing.expect(np.file.?.output == null); try std.testing.expectEqualStrings("/tmp/pardes-save-dir/note.txt", np.file.?.path); var saved = false; @@ -1872,7 +1850,7 @@ test "Save on a terminal writes its plaintext scrollback and stays a terminal" { try std.testing.expect(p.executeBuiltinLine(0, "Save")); try std.testing.expect(pane.prompt == .save); try std.testing.expect(pane.appendTag("log.txt")); - p.submitSave(0); + exec.submitSave(p, 0); // the pane is untouched: still a terminal, no file behind it try std.testing.expect(pane.isTerminal()); @@ -1921,7 +1899,7 @@ test "Save on an output buffer writes its rows out and leaves the buffer alone" try std.testing.expect(p.executeBuiltinLine(id, "Save")); try std.testing.expect(out.prompt == .save); try std.testing.expect(out.appendTag("help.txt")); - p.submitSave(id); + exec.submitSave(p, id); // the buffer itself is untouched: same origin, same name, still refillable // and still walked by n/N, because a saved copy of a list is only a copy @@ -2156,7 +2134,7 @@ test "a save path that names no file is refused before anything is rewritten" { try std.testing.expect(p.executeBuiltinLine(id, "Save")); try std.testing.expect(scratch.prompt == .save); - p.submitSave(id); + exec.submitSave(p, id); var buf: [256]u8 = undefined; try std.testing.expect(drainForSavePath(p, &buf) == null); try std.testing.expect(scratch.file.?.output != null); @@ -2213,7 +2191,7 @@ test "a builtin that needs a pane reports capacity failure when every slot is fu _ = try p.newDocPane(id); }; const help = std.meta.stringToEnum(Builtin, "Help") orelse return error.MissingHelpBuiltin; - p.runBuiltin(help, 0, "", null); + exec.runBuiltin(p, help, 0, "", null); try std.testing.expect(std.mem.indexOf(u8, p.panes[0].?.msg[0..p.panes[0].?.msg_len], "help: NoPaneSlots") != null); } @@ -2760,7 +2738,7 @@ test "column tags follow their column through split and close" { defer p.deinit(); _ = try p.setTestFile("left\n"); try std.testing.expect(p.col_tags[0].set("Left Find")); - _ = p.execute(0, "Newcol"); + _ = exec.execute(p, 0, "Newcol"); try std.testing.expectEqual(@as(usize, 2), p.ncol); try std.testing.expectEqualStrings("Left Find", p.columnTag(0)); try std.testing.expect(p.col_tags[1].set("Right Grep")); @@ -3362,7 +3340,7 @@ test "canonical fallback and transition toggle retire unpresented tracks" { const moving = try p.render(frame.allocator()); p.acknowledgePanelPresentation(moving.panelTracks()); try std.testing.expect(moving.panelTracks().len > 0); - p.applySettingBuiltin(config.Runtime.find("PanelZoom").?, null); + exec.applySettingBuiltin(p, config.Runtime.find("PanelZoom").?, null); try std.testing.expectEqual(layout.Transition.zoom, p.settings.panel_transition); try std.testing.expect(p.presentation.pending); try std.testing.expect(p.presentation.pointer(p.screen_w, p.screen_h, 10, 4) == null); @@ -3379,11 +3357,11 @@ test "canonical fallback and transition toggle retire unpresented tracks" { const old_tagline_percent = p.settings.font.tagline_percent; var percent_buf: [3]u8 = undefined; const same_percent = try std.fmt.bufPrint(&percent_buf, "{d}", .{old_tagline_percent}); - p.applySettingBuiltin(config.Runtime.find("TaglineSize").?, same_percent); + exec.applySettingBuiltin(p, config.Runtime.find("TaglineSize").?, same_percent); try std.testing.expect(p.animationActive()); const changed_percent: u8 = if (old_tagline_percent == 73) 74 else 73; const changed_text = try std.fmt.bufPrint(&percent_buf, "{d}", .{changed_percent}); - p.applySettingBuiltin(config.Runtime.find("TaglineSize").?, changed_text); + exec.applySettingBuiltin(p, config.Runtime.find("TaglineSize").?, changed_text); try std.testing.expectEqual(changed_percent, p.settings.font.tagline_percent); try std.testing.expect(p.presentation.pending); for (p.presentation.tracks) |track| try std.testing.expect(track == null); @@ -3839,6 +3817,10 @@ pub const Pardes = struct { pub const setMessage = Messages.setMessage; pub const reportError = Messages.reportError; + /// Running a builtin line, called from everywhere as + /// `p.executeBuiltinLine(...)`; it lives with the rest of exec in exec.zig. + pub const executeBuiltinLine = exec.executeBuiltinLine; + pub fn init(gpa: std.mem.Allocator, opts: Options) !*Pardes { const image_gpa = opts.image_allocator orelse gpa; const pdf_gpa = opts.pdf_allocator orelse gpa; @@ -3936,7 +3918,7 @@ pub const Pardes = struct { }, } p.sync(); - p.applyStartupConfig(); + exec.applyStartupConfig(p); colors.finishThemeInitialization(p); p.sync(); p.presentation.enabled = true; @@ -4272,16 +4254,6 @@ pub const Pardes = struct { if (look.lookHoverPane(p) == id) look.cancelLookHover(p); } - pub fn takesCommandLine(p: *const Pardes, id: usize) bool { - const pane = p.panes[id] orelse return false; - if (!pane.isTerminal()) return false; - // A mounted shell sits behind sudo's process supervisor. Its OSC 133 - // prompt marks identify input readiness; the launcher's executable is - // not the shell executable used by the ordinary process heuristic. - if (pane.v9fs_on_spawn) return panes.Terminal.promptInputReady(pane); - return !p.hostTtyTaken(id); - } - pub fn shellBin(p: *const Pardes) []const u8 { const selected = p.settings.shell.requested.get(); return if (selected.len == 0) config.default_shell else selected; @@ -4631,7 +4603,7 @@ pub const Pardes = struct { } pub fn update(p: *Pardes, ev: Event) void { - defer p.replaceStillborn(); + defer exec.replaceStillborn(p); // A tick with nothing animating is the one event that cannot change // the screen. p.needs_frame = p.needs_frame or ev != .tick; @@ -4805,7 +4777,7 @@ pub const Pardes = struct { return defaultTail(pane); } - fn defaultTail(pane: *const Pane) []const u8 { + pub fn defaultTail(pane: *const Pane) []const u8 { if (comptime pdf_enabled) if (pane.pdf != null) return pdf_pane_tail; if (pane.file) |file| if (file.output) |out| if (panes.Output.usesLocationsConfig(out.from)) return locations_pane_tail; @@ -5029,7 +5001,7 @@ pub const Pardes = struct { } if (p.tagChordText(pane)) |txt| { pane.tag_sel = false; - p.runBuiltin(if (hit(key, config.look_key)) config.look_cmd else config.exec_cmd, p.active, "", txt); + exec.runBuiltin(p, if (hit(key, config.look_key)) config.look_cmd else config.exec_cmd, p.active, "", txt); } return; } @@ -5086,7 +5058,7 @@ pub const Pardes = struct { const body_mode = pane.tag_mode; exitTagEdit(pane); // leave the tag FIRST: Del frees the pane pane.mode = body_mode; - p.runBuiltin(cmd, id, "", txt); + exec.runBuiltin(p, cmd, id, "", txt); return; } if (hit(key, config.tag_yank)) { @@ -5116,7 +5088,7 @@ pub const Pardes = struct { } else null; if (dir) |d| { const from = p.active; - p.runBuiltin(d, from, "", null); + exec.runBuiltin(p, d, from, "", null); if (p.active == from) { if (d == .Up) { exitTagEdit(pane); @@ -5208,8 +5180,8 @@ pub const Pardes = struct { if (word.len > 0) { if (!p.header_insert) { // Preserve the workspace tag's keyboard command semantics. - _ = p.execute(p.active, word); - } else p.runBuiltin(if (hit(key, config.look_key)) config.look_cmd else config.exec_cmd, p.active, "", word); + _ = exec.execute(p, p.active, word); + } else exec.runBuiltin(p, if (hit(key, config.look_key)) config.look_cmd else config.exec_cmd, p.active, "", word); } return; } @@ -5295,185 +5267,6 @@ pub const Pardes = struct { if (col) |c| p.topbar_col = @intCast(@min(c, modal.prevGrapheme(bar, bar.len))); } - fn chordEachSel(p: *Pardes, pane: *Pane, cmd: Builtin) bool { - if (pane.nsel == 0) return false; - const text = edit.flatSurface(p, pane) catch return false; - var ranges: [Pane.max_selections]modal.Selection = undefined; - const got = pane.ranges(text, 0, &ranges); - if (got.n < 2) return false; - - var texts: [Pane.max_selections][]u8 = undefined; - var made: usize = 0; - defer for (texts[0..made]) |t| p.gpa.free(t); - for (ranges[0..got.n]) |range| { - const lo = @min(range.anchor, range.head); - const hi = @max(range.anchor, range.head); - if (hi > text.len) break; - texts[made] = p.gpa.dupe(u8, text[lo..hi]) catch break; - made += 1; - } - // All or nothing, like the pipe: half a chord is not a chord. - if (made != got.n) return false; - - const id = p.active; - const serial = pane.serial; - pane.vsel.active = false; - pane.msel.active = false; - pane.select = false; - pane.nsel = 0; // the chord consumed them, exactly as it consumes one - - var primary_active: ?usize = null; - for (texts[0..made], 0..) |txt, i| { - p.runBuiltin(cmd, id, "", txt); - if (i == got.pri) primary_active = p.active; - const still = p.panes[id] orelse break; - if (still.serial != serial) break; - } - if (primary_active) |a| if (p.panes[a] != null) { - p.active = a; - }; - return true; - } - - pub const PointerOperand = struct { - /// Absolute body position corresponding to the pointed screen cell. - row: i32, - col: i32, - /// Exactly what a no-drag middle/right click will dispatch. - text: ?[]const u8 = null, - /// What hover paints. Null names the pane's live modal selection. - preview: ?Pane.Sel = null, - /// File words stay logical so a soft-wrapped operand is not cut into - /// unrelated rendered fragments. Null for tags and non-file panes. - file_word: ?look.FileWordSpan = null, - /// A newly expanded word is installed in the gesture's button slot; - /// an existing selection is only borrowed and must not replace it. - expanded: ?Pane.Sel = null, - }; - - pub fn pointerOperand(p: *Pardes, pane: *Pane, clicked: Pane.Sel) PointerOperand { - const visible = clicked.r0 - @as(i32, BOX_H); - const wrapped = pane.wrapAt(visible); - const raw = pane.isTerminal() and pane.mode == .tty and clicked.r0 >= BOX_H; - const row = if (raw) panes.Terminal.gridOffset(pane) + visible else wrapped.line; - const raw_line = if (raw) modal.lineSlice(body_layer.bodyText(p, p.scratch.allocator(), pane) catch "", @intCast(@max(0, visible))) else ""; - const col = if (raw) - @as(i32, @intCast(panes.File.rawAtDisplay(raw_line, @intCast(@max(0, clicked.c0))))) - else if (clicked.r0 >= BOX_H) - edit.paneByteAtDisplay( - p, - pane, - wrapped.line, - wrapped.at, - clicked.c0 - (if (pane.file != null) @as(i32, panes.File.gutterWidth(pane)) else 0), - ) - else - clicked.c0; - var result: PointerOperand = .{ .row = row, .col = col }; - - const kept = pane.sel[sel_slot]; - const inside_kept = if (pane.pointerSelection(kept)) |rows| inside: { - if (clicked.r0 < BOX_H) break :inside false; - if (pane.file != null and clicked.c0 < panes.File.gutterWidth(pane)) break :inside false; - const source_col: usize = @intCast(@max(0, col)); - for (rows) |span| { - const target = if (span.raw_terminal) - (if (raw) span.row else pane.surfRow(span.row)) - else - (if (raw) pane.gridRow(span.row) else span.row); - var lo = span.lo; - var hi = span.hi; - if (span.raw_terminal and !raw) { - lo -|= span.prompt_bytes; - hi -|= span.prompt_bytes; - } else if (!span.raw_terminal and raw) { - const prefix = panes.Terminal.promptPrefixBytes(pane, row, raw_line); - lo += prefix; - hi += prefix; - } - if (target == row and source_col >= lo and source_col < hi) - break :inside true; - } - break :inside false; - } else edit.spanHas(clicked.r0, clicked.c0, kept.r0, kept.c0, kept.r1, kept.c1); - if (kept.state == .done and inside_kept) { - result.text = edit.selectionText(p, pane, kept) catch null; - result.preview = kept; - return result; - } - if (pane.vsel.active and pane.vsel.explicit and - edit.spanHas(row, col, pane.vsel.row, pane.vsel.col, pane.cur_row, pane.cur_col)) - { - result.text = edit.currentSelText(p, pane); - return result; - } - if (pane.msel.active and row >= @min(pane.msel.r0, pane.msel.r1) and - row <= @max(pane.msel.r0, pane.msel.r1)) - { - result.text = edit.currentSelText(p, pane); - return result; - } - if (pane.file != null and clicked.r0 >= BOX_H and clicked.r0 == clicked.r1 and clicked.c0 == clicked.c1) { - const line = panes.File.sourceLine(pane, row); - const source_col: usize = @intCast(@max(0, col)); - const b = look.expandedWord(line, source_col) orelse return result; - const lo = std.math.cast(i32, b.lo) orelse return result; - const hi = std.math.cast(i32, b.hi) orelse return result; - result.text = line[b.lo..b.hi]; - result.file_word = .{ .row = row, .lo = lo, .hi = hi }; - - var expanded = clicked; - const first = pane.wrapRow(row, lo); - const last = pane.wrapRow(row, hi - 1); - if (first.row >= 0 and last.row >= 0) { - expanded.r0 = first.row + @as(i32, BOX_H); - expanded.c0 = @as(i32, panes.File.gutterWidth(pane)) + panes.File.displayOffset(pane, row, first.at, lo); - expanded.r1 = last.row + @as(i32, BOX_H); - expanded.c1 = @as(i32, panes.File.gutterWidth(pane)) + panes.File.displayEndOffset(pane, row, last.at, hi - 1); - } - result.preview = expanded; - result.expanded = expanded; - return result; - } - - const expanded = look.expandedSel(p, pane, clicked) orelse return result; - result.text = edit.selectionText(p, pane, expanded) catch null; - if (result.text == null or result.text.?.len == 0) return result; - result.preview = expanded; - result.expanded = expanded; - return result; - } - - pub fn heldSelection(p: *Pardes, first: usize) ?[]const u8 { - var k: usize = 0; - while (k < p.panes.len + 2) : (k += 1) { - const i = switch (k) { - 0 => first, - 1 => p.active, - else => k - 2, - }; - if (k > 0 and (i == first or (k > 1 and i == p.active))) continue; - const t = p.panes[i] orelse continue; - if (comptime pdf_enabled) if (p.native_images) if (t.pdf) |pv| { - if (pv.selection != null and pv.selection_text.len > 0) - return pv.selection_text; - }; - if (t.sel[sel_slot].state == .done) { - if (edit.selectionText(p, t, t.sel[sel_slot]) catch null) |tx| return tx; - } else if ((t.vsel.active and t.vsel.explicit) or t.msel.active) { - if (edit.currentSelText(p, t)) |tx| return tx; - } - } - return null; - } - - pub fn withArg(p: *Pardes, txt: []const u8, arg: ?[]const u8) []const u8 { - const a = std.mem.trim(u8, arg orelse return txt, " \t\r\n"); - if (a.len == 0) return txt; - const t = std.mem.trim(u8, txt, " \t\r\n"); - return std.fmt.allocPrint(p.scratch.allocator(), "{s} {s}", .{ t, a }) catch txt; - } - /// Cycle only the body modes supported by this pane. pub fn cycleMode(p: *Pardes, id: usize) void { const pane = p.panes[id] orelse return; @@ -5516,8 +5309,8 @@ pub const Pardes = struct { const asked = slot orelse continue; if (asked.prompt != .del_side) continue; asked.prompt = .none; - if (hit(key, config.del_above)) p.runBuiltin(.Del, id, "", "k"); - if (hit(key, config.del_below)) p.runBuiltin(.Del, id, "", "j"); + if (hit(key, config.del_above)) exec.runBuiltin(p, .Del, id, "", "k"); + if (hit(key, config.del_below)) exec.runBuiltin(p, .Del, id, "", "j"); return; } if (p.topbar_col != null) return p.topbarKey(key); @@ -5530,9 +5323,9 @@ pub const Pardes = struct { // Shift-Escape is the unconditional way out, even mid-application; // bare Escape only leaves at a shell prompt. if (hit(key, config.tty_toggle_alt)) - return p.runBuiltin(.Last, p.active, "", null); - if (key.cp == Key.escape and !key.ctrl and !key.alt and !key.shift and p.takesCommandLine(p.active)) - return p.runBuiltin(.Last, p.active, "", null); + return exec.runBuiltin(p, .Last, p.active, "", null); + if (key.cp == Key.escape and !key.ctrl and !key.alt and !key.shift and exec.takesCommandLine(p, p.active)) + return exec.runBuiltin(p, .Last, p.active, "", null); panes.Terminal.followOutput(pane); // typing snaps back to live output // Paste stays the window's, the one exception to forwarding a raw // tty's keys: Ctrl-V types the register at the program and @@ -5554,7 +5347,7 @@ pub const Pardes = struct { if (p.ctrl_w_pending) { p.ctrl_w_pending = false; for (config.window_keys) |wk| { - if (hit(key, &.{ wk.letter, wk.arrow })) return p.runBuiltin(wk.cmd, p.active, "", null); + if (hit(key, &.{ wk.letter, wk.arrow })) return exec.runBuiltin(p, wk.cmd, p.active, "", null); } return; } @@ -5579,7 +5372,7 @@ pub const Pardes = struct { return; } for (config.jump_keys) |jk| { - if (hit(key, &.{jk.chord})) return p.runBuiltin(jk.cmd, p.active, "", null); + if (hit(key, &.{jk.chord})) return exec.runBuiltin(p, jk.cmd, p.active, "", null); } if (hit(key, config.pane_to_new_column)) { const f = layout.findPane(p, p.active).?; @@ -5601,7 +5394,7 @@ pub const Pardes = struct { pane.tag_tail_len = @min(pipe.at, pane.tag_tail_len); }, .save => |at| { - if (submit) p.submitSave(p.active) else pane.tag_tail_len = @min(at, pane.tag_tail_len); + if (submit) exec.submitSave(p, p.active) else pane.tag_tail_len = @min(at, pane.tag_tail_len); }, .search => |at| { if (submit) @@ -5629,18 +5422,18 @@ pub const Pardes = struct { const explicit = (p.native_images and pane.hasPdfSelection()) or (pane.vsel.active and pane.vsel.explicit) or pane.msel.active; if (explicit) { - if (p.chordEachSel(pane, cmd)) return; + if (exec.chordEachSel(p, pane, cmd)) return; if (edit.currentSelText(p, pane)) |txt| { pane.vsel.active = false; pane.msel.active = false; pane.select = false; - p.runBuiltin(cmd, p.active, "", txt); + exec.runBuiltin(p, cmd, p.active, "", txt); return; } } const sel = look.expandedSel(p, pane, look.cursorWordSel(p, pane)) orelse return; const word = edit.selectionText(p, pane, sel) catch return; - p.runBuiltin(cmd, p.active, "", word); + exec.runBuiltin(p, cmd, p.active, "", word); return; } if (pane.mode == .normal and pane.hasPdf()) return normal.handlePdfNormal(p, pane, key); @@ -5672,7 +5465,7 @@ pub const Pardes = struct { // a path-less builtin is a row here too (it is the same index Help // reads), and SPC cannot reach one — so both scans skip it for (builtin_rows) |row| { - if (std.mem.eql(u8, row.path orelse continue, pfx)) return p.runBuiltin(row.cmd, p.active, "", null); + if (std.mem.eql(u8, row.path orelse continue, pfx)) return exec.runBuiltin(p, row.cmd, p.active, "", null); } for (builtin_rows) |row| { if (std.mem.startsWith(u8, row.path orelse continue, pfx)) { @@ -5744,73 +5537,7 @@ pub const Pardes = struct { pane.tag_col = @intCast(prefix_len + pane.tag_tail_len); } - /// Enter on a save input: the path is everything past the marker. - fn submitSave(p: *Pardes, id: usize) void { - const pane = p.panes[id] orelse return; - const at = switch (pane.prompt) { - .save => |a| a, - else => return, - }; - const armed = pane.tag_tail[at..pane.tag_tail_len]; - pane.tag_tail_len = at; // drop the prompt back to the seeded tail - if (!std.mem.startsWith(u8, armed, config.save_marker)) return; - const path = std.mem.trim(u8, armed[config.save_marker.len..], " \t\r\n"); - if (path.len == 0) return; - p.saveTo(id, path); - } - - /// Write the file this pane already has: acme's Put, and the one Save that - /// needs no argument because the path was never a question. - pub fn saveFile(p: *Pardes, id: usize) void { - const pane = p.panes[id] orelse return; - const f = if (pane.file) |*file| file else return; - if (f.output != null) return; // nothing behind it yet: saveTo, with a path - p.emit(.{ .save_file = .{ .pane = @intCast(id) } }); - } - - pub fn saveTo(p: *Pardes, id: usize, path: []const u8) void { - const pane = p.panes[id] orelse return; - if (path.len == 0 or path[path.len - 1] == '/' or - std.mem.indexOfScalar(u8, path, '\n') != null) - return p.reportError(id, "save", error.NoFilename); - const full = std.fs.path.resolvePosix( - p.scratch.allocator(), - &.{ paneDir(pane), path }, - ) catch return; - if (!std.fs.path.isAbsolute(full)) return p.reportError(id, "save", error.NoDirectory); - if (full.len > SavePath.cap) return p.reportError(id, "save", error.PathTooLong); - const f = if (pane.file) |*file| file else { - // a terminal writes its scrollback; an image and a PDF have nothing - // of their own that is unwritten, so they have nothing to write - if (pane.isTerminal()) p.askWrite(id, pane.serial, full); - return; - }; - if (f.output != null and panes.Output.fileTraits(f.output).saves) { - const owned = p.gpa.dupe(u8, full) catch return; - p.gpa.free(f.path); - f.path = owned; - f.output = null; // an ordinary file pane from here on - f.watch_after_save = true; - pane.clearCwd(); - pane.tag_init = false; // re-derive the tag as a plain file - pane.tag_tail_len = 0; - p.emit(.{ .save_file = .{ .pane = @intCast(id) } }); - return; - } - // its own path, spelled out: the in-place write, so the pane comes clean - if (f.output == null and std.mem.eql(u8, f.path, full)) return p.saveFile(id); - p.askWrite(id, pane.serial, full); - } - - const SavePath = Effect.Buf(effect_path_cap); - - fn askWrite(p: *Pardes, id: usize, serial: u32, path: []const u8) void { - p.emit(.{ .save_text = .{ - .pane = @intCast(id), - .serial = serial, - .path = SavePath.from(path), - } }); - } + pub const SavePath = Effect.Buf(effect_path_cap); pub fn lspRequest(p: *Pardes, id: usize, kind: lsp.Kind, arg: []const u8) void { if (!normal.multiOnce(p)) return; // one question per keystroke, from the primary @@ -6054,104 +5781,6 @@ pub const Pardes = struct { p.settings.scene_effects = .{}; } - /// Tty: a shell in the caller's directory, raw from the first frame, - /// stacked below the caller like Alt-n's new shell. - pub fn spawnTty(p: *Pardes, from: usize) void { - p.spawnTtyWithMount(from, false); - } - - pub fn spawnV9fsTty(p: *Pardes, from: usize) void { - if (comptime !hosted or @import("builtin").os.tag != .linux) - return p.reportError(from, "Tty9p", error.LinuxRequired); - if (p.fs.socket_path.len == 0) - return p.reportError(from, "Tty9p", error.SessionSocketRequired); - p.spawnTtyWithMount(from, true); - } - - fn spawnTtyWithMount(p: *Pardes, from: usize, v9fs: bool) void { - const src = p.panes[from] orelse return; - const free = p.freeSlot() orelse return; - const nt = p.newShell(free, paneDir(src)) catch return; - nt.greet = !v9fs; - nt.v9fs_on_spawn = v9fs; - nt.mode = .tty; - const parent = layout.splitParent(p, from); - const f = layout.findPane(p, parent).?; - layout.insert(p, f.col, f.idx + 1, free); - layout.splitBelow(p, parent, nt); - p.active = free; - p.stillborn_joiner = nt.serial; - } - - /// when a doc lands in `col`, a lone pristine shell there is clutter — drop - /// it; absorbVWeight hands its space to the doc - pub fn evictLonePristineTty(p: *Pardes, col: usize, keep_id: usize) void { - var n_tty: usize = 0; - var tty_id: usize = 0; - for (0..p.col_n[col]) |k| { - const cid = p.col_panes[col][k]; - if (p.panes[cid]) |ct| if (ct.isTerminal()) { - n_tty += 1; - tty_id = cid; - }; - } - if (n_tty != 1) return; - const tt = p.panes[tty_id] orelse return; - // No typing, cursor on the first prompt line, no scrollback: this is - // the throwaway boot placeholder a document may replace. - if (tt.ovl != null or panes.Terminal.gridCursor(tt).y != 0 or - panes.Terminal.scrollbar(tt).total > tt.rows) return; - p.deinitPane(tt) catch |err| return p.reportError(tty_id, "close", err); - layout.compute(p); // a just-stacked doc has no rect yet; absorb snaps to rows - layout.absorbVWeight(p, tty_id, null); - layout.removePane(p, tty_id); - p.panes[tty_id] = null; - if (p.active == tty_id) p.active = keep_id; - } - - /// A pane that just joined a column whose only other pane is stillborn — - /// an empty scratch nobody typed into, body or tag (what Newcol makes and - /// what a closed column's last pane leaves behind) — takes the column - /// whole: the placeholder was only holding the space for it. Run at the - /// end of a step: the pane that asked for the joiner is often the - /// placeholder itself, and its caller is still holding it. - fn replaceStillborn(p: *Pardes) void { - const serial = p.stillborn_joiner orelse return; - p.stillborn_joiner = null; - const new_id = p.paneBySerial(serial) orelse return; - const f = layout.findPane(p, new_id) orelse return; - if (p.col_n[f.col] != 2) return; - const old_id = p.col_panes[f.col][1 - f.idx]; - const old = p.panes[old_id] orelse return; - const file = old.file orelse return; - const out = file.output orelse return; - if (out.from != .cmd or out.from.cmd != .New) return; - if (file.revision != 0 or file.content.len != 0) return; - if (old.tag_init and !std.mem.eql(u8, old.tagSlice(), defaultTail(old))) return; - const was_active = p.active == old_id; - layout.compute(p); // the joiner may have no rect yet; absorb snaps to rows - p.removePane(old_id, new_id) catch |err| return p.reportError(old_id, "close", err); - if (was_active) p.active = new_id; - } - - fn ttyForDir(p: *Pardes, dir: []const u8) ?usize { - for (p.panes, 0..) |slot, i| if (slot) |tt| { - if (!std.mem.eql(u8, tt.cwdSlice(), dir)) continue; - if (p.takesCommandLine(i)) return i; - }; - const free = p.freeSlot() orelse return null; - const nt = p.newShell(free, dir) catch return null; - nt.greet = false; - const rc = if (p.ncol > 0) p.ncol - 1 else 0; - if (p.col_n[rc] > 0) { - const src = layout.splitParent(p, p.col_panes[rc][p.col_n[rc] - 1]); - const f = layout.findPane(p, src).?; - layout.splitBelow(p, src, nt); - layout.insert(p, f.col, f.idx + 1, free); - } else layout.insert(p, rc, p.col_n[rc], free); - return free; - } - // ---- doc panes ---- pub fn openTutorView(p: *Pardes, id: usize) !*Pane { @@ -6188,172 +5817,6 @@ pub const Pardes = struct { // ---- the ONE dispatcher: look (right/Enter) and execute (middle/Tab) ---- - const max_exec_depth = 8; - - pub fn execute(p: *Pardes, id: usize, txt: []const u8) ?usize { - const pane = p.panes[id] orelse return null; - const cmd = commandText(txt); - if (cmd.len == 0) return null; - if (p.exec_depth == 0) p.noteHaptic(.exec); - if (p.executeBuiltinLine(id, cmd)) return null; - if (p.exec_depth >= max_exec_depth) return null; - p.exec_depth += 1; - defer p.exec_depth -= 1; - const dst = (if (p.takesCommandLine(id)) id else p.ttyForDir(paneDir(pane))) orelse return null; - panes.Terminal.padOutputBelowEdits(p, dst); - if (panes.Terminal.queuePendingCommand(p.panes[dst].?, cmd) catch |err| { - p.reportError(id, "queue command", err); - return dst; - }) return dst; - p.emitWrite(dst, cmd); - p.emitWrite(dst, "\r"); - return dst; - } - - /// Trim and unwrap clickable command-word notation once for every command - /// consumer, so startup lines and interactive Exec speak the same syntax. - pub fn commandText(txt: []const u8) []const u8 { - var cmd = std.mem.trim(u8, txt, " \t\r\n"); - while (config.commandWord(cmd)) |inner| cmd = std.mem.trim(u8, inner, " \t\r\n"); - return cmd; - } - - pub fn executeBuiltinLine(p: *Pardes, id: usize, txt: []const u8) bool { - const cmd = commandText(txt); - if (cmd.len == 0 or p.exec_depth >= max_exec_depth) return false; - const sp = std.mem.indexOfAny(u8, cmd, " \t"); - const bi: ?Builtin = std.meta.stringToEnum(Builtin, cmd) orelse blk: { - const head = std.meta.stringToEnum(Builtin, cmd[0 .. sp orelse break :blk null]) orelse break :blk null; - break :blk if (builtins.registry.takesArg(head)) head else null; - }; - const b = bi orelse return false; - p.exec_depth += 1; - defer p.exec_depth -= 1; - const typed = if (sp) |s| std.mem.trim(u8, cmd[s + 1 ..], " \t") else ""; - p.runBuiltin(b, id, cmd, if (typed.len > 0) typed else null); - return true; - } - - fn applyStartupConfig(p: *Pardes) void { - p.announce = false; - defer p.announce = true; - var lines = std.mem.splitScalar(u8, p.opts.startup_config orelse return, '\n'); - while (lines.next()) |line| _ = p.executeBuiltinLine(p.active, line); - } - - pub fn runBuiltin(p: *Pardes, b: Builtin, id: usize, txt: []const u8, arg: ?[]const u8) void { - if (!normal.multiOnce(p)) return; // a builtin is per-keystroke, never per-cursor - const pane = p.panes[id] orelse 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. - if (p.announce and p.settings.verbose and builtins.registry.announces(b)) { - p.setMessage(id, @tagName(b)); - pane.msg_announcement = true; - } - const c: builtins.Ctx = .{ .p = p, .pane = pane, .id = id, .txt = txt, .arg = arg }; - builtins.registry.dispatch(b, c); - } - - pub fn applySettingBuiltin(p: *Pardes, setting: config.Runtime.Setting, arg: ?[]const u8) void { - const previous_colors = p.settings.colors; - const previous_context_style = p.settings.tree_context_tag_style; - const previous_transition = p.settings.panel_transition; - const previous_tagline_percent = p.settings.font.tagline_percent; - const previous_column_tags = p.settings.column_tags; - switch (setting.action) { - .theme => { - const want = std.mem.trim(u8, arg orelse return, " \t\r\n"); - for (themes, 0..) |t, i| if (std.mem.eql(u8, t.name, want)) { - colors.setThemeIndex(p, i); - return; - }; - }, - .font => { - if (comptime !font_picker) return; - const spec = config.Runtime.FontSpec.parse(arg orelse return) orelse return; - const matches = fonts.list(p.scratch.allocator(), spec.name); - if (matches.len == 0) return; - if (!p.settings.requestFont(matches[0].path, matches[0].name, spec.size_hundredths)) return; - p.font_request_taken = false; - }, - else => _ = p.settings.apply(setting, arg), - } - if (p.settings.colors != previous_colors) { - for (p.panes) |slot| { - const pane = slot orelse continue; - if (pane.file) |*file| file.syntax_dirty = true; - } - } - if (p.settings.tree_context_tag_style != previous_context_style) { - for (p.panes, 0..) |slot, id| { - p.surface.body_layers[id].rows = 0; - const pane = slot orelse continue; - pane.body_rows = 0; - pane.body_visible_rows = 0; - pane.context_row_limit = null; - pane.wrap_n = 0; - } - p.abandonPanelAnimations(); - } - const transition_changed = setting.action == .transition and - p.settings.panel_transition != previous_transition; - const tagline_metrics_changed = setting.action == .tagline_size and - p.settings.font.tagline_percent != previous_tagline_percent; - if (p.settings.column_tags != previous_column_tags) { - if (p.header_column != null) p.exitHeader(); - } - if (transition_changed or tagline_metrics_changed or p.settings.column_tags != previous_column_tags) { - p.abandonPanelAnimations(); - } - } - - pub fn placeDoc(p: *Pardes, from_id: usize, free: usize, nt: *Pane) void { - p.stillborn_joiner = nt.serial; - const doc = if (nt.file) |f| panes.Output.fileTraits(f.output).doc else true; // an image is a doc - var src_id: ?usize = null; - if (p.panes[from_id]) |src| if (if (src.file) |f| panes.Output.fileTraits(f.output).doc else src.image != null or src.hasPdf()) { - src_id = from_id; - }; - if (doc and src_id == null) { - var n = p.njumps; - while (n > 0) : (n -= 1) { - const j = p.jumps[n - 1]; - const pp = p.panes[j.pane] orelse continue; - if (pp.serial != j.serial) continue; - if (if (pp.file) |f| panes.Output.fileTraits(f.output).doc else pp.image != null or pp.hasPdf()) { - src_id = j.pane; - break; - } - } - } - if (doc and src_id == null) for (p.panes, 0..) |sl, i| { - if (sl) |pp| if (i != free and (if (pp.file) |f| panes.Output.fileTraits(f.output).doc else pp.image != null or pp.hasPdf())) { - src_id = i; - break; - }; - }; - if (!doc) if (layout.findPane(p, from_id)) |sf| { - layout.insert(p, sf.col, sf.idx + 1, free); - layout.splitBelow(p, from_id, nt); // NOT splitParent: no bystander pays - p.active = free; - return; - }; - if (src_id == null and doc and p.ncol < MAX_COLS and - layout.columnFitsHalves(p, from_id, 100) and layout.splitColumn(p, from_id, free, true)) - { - p.active = free; - return; - } - // Without room for a first-document column, split the Look origin - // just like Tty. Never displace (or evict) a top-left bystander. - const src = layout.splitParent(p, src_id orelse from_id); - const sf = layout.findPane(p, src).?; - layout.insert(p, sf.col, sf.idx + 1, free); - layout.splitBelow(p, src, nt); - p.active = free; - } - // ---- dump / load (acme-style: `pardes -l state.zon` restores a session) ---- pub fn dumpState(p: *Pardes) !void { @@ -6562,7 +6025,7 @@ pub const Pardes = struct { } p.active = @min(st.active, MAX_PANES - 1); p.sync(); - p.applyStartupConfig(); + exec.applyStartupConfig(p); colors.finishThemeInitialization(p); p.sync(); p.presentation.enabled = true; @@ -7725,7 +7188,7 @@ test "Esc alternates between two panes of the SAME kind" { defer p.deinit(); p.update(.{ .resize = .{ .cols = 80, .rows = 40 } }); const a = p.active; - p.runBuiltin(.Look, a, "", "build.zig"); + exec.runBuiltin(p, .Look, a, "", "build.zig"); p.sync(); const b = p.active; try std.testing.expect(b != a); @@ -8229,7 +7692,7 @@ test "raw tty Escape only leaves at a shell prompt" { if (platform == .web) return; const p = try Pardes.init(std.testing.allocator, .{ .cols = 80, .rows = 24, .file = "mise.toml" }); defer p.deinit(); - p.spawnTty(0); + exec.spawnTty(p, 0); const shell = p.active; const pane = p.panes[shell].?; var buf: [256]u8 = undefined; @@ -8260,7 +7723,7 @@ test "raw tty Ctrl-B switches to editor mode without sending child input" { if (platform == .web) return; const p = try Pardes.init(std.testing.allocator, .{ .file = "mise.toml" }); defer p.deinit(); - p.spawnTty(0); + exec.spawnTty(p, 0); const shell = p.active; p.sync(); var buf: [256]u8 = undefined; @@ -8313,7 +7776,7 @@ test "hopping between two panes does not grow the jump stack" { try std.testing.expectEqual(depth, p.njumps); const before = p.active; - p.runBuiltin(.Back, p.active, "", null); + exec.runBuiltin(p, .Back, p.active, "", null); p.sync(); try std.testing.expect(p.active != before); try std.testing.expectEqual(depth, p.njumps); diff --git a/src/pdf_view.zig b/src/pdf_view.zig index 9b623183..721dac5a 100644 --- a/src/pdf_view.zig +++ b/src/pdf_view.zig @@ -3,6 +3,7 @@ const panes = @import("panes.zig"); const std = @import("std"); const pardes = @import("pardes.zig"); +const exec = @import("exec.zig"); const layout = @import("layout.zig"); const config = @import("config.zig"); const modal = @import("modal.zig"); @@ -2044,7 +2045,7 @@ pub fn openSections(core: *pardes.Pardes, id: usize) void { .serial = result.serial, .revision = result.file.?.revision, }; - core.placeDoc(id, free, result); + exec.placeDoc(core, id, free, result); layout.compute(core); core.active = id; pane.search_pane = free; diff --git a/test/panes.zig b/test/panes.zig index f45d42b2..f99f9d56 100644 --- a/test/panes.zig +++ b/test/panes.zig @@ -721,7 +721,7 @@ const TtySelectionTests = struct { const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 40, .rows = 24 }); defer p.deinit(); p.presentation.enabled = false; - p.spawnTty(0); + pardes.exec.spawnTty(p, 0); for (p.panes[0..2]) |slot| { slot.?.mode = .tty; slot.?.tty_filter = false; @@ -3111,8 +3111,8 @@ const TerminalTests = struct { defer p.deinit(); while (p.nextEffect()) |_| {} // the host has not acknowledged spawn yet - try std.testing.expectEqual(@as(?usize, 0), p.execute(0, "echo first")); - try std.testing.expectEqual(@as(?usize, 0), p.execute(0, "echo second")); + try std.testing.expectEqual(@as(?usize, 0), pardes.exec.execute(p, 0, "echo first")); + try std.testing.expectEqual(@as(?usize, 0), pardes.exec.execute(p, 0, "echo second")); while (p.nextEffect()) |effect| switch (effect) { .write => return error.CommandEscapedBeforeFork, else => {}, diff --git a/test/pdf.zig b/test/pdf.zig index 69a82123..dde58df8 100644 --- a/test/pdf.zig +++ b/test/pdf.zig @@ -342,7 +342,7 @@ test "PdfSections Look follows the exact owning PDF, not an equal path" { const duplicate_id = p.freeSlot() orelse return error.NoDuplicatePdfSlot; const duplicate = try panes.Pdf.openPane(p, duplicate_id, path, 0); - p.placeDoc(0, duplicate_id, duplicate); + pardes.exec.placeDoc(p, 0, duplicate_id, duplicate); layout.compute(p); panes.Pdf.openSections(p, duplicate_id); const duplicate_output_id = duplicate.search_pane orelse return error.MissingDuplicatePdfSections; -- cgit v1.3 From 898c61ee7cddaade523885bb9b02a89678b00fcc Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Sun, 27 Sep 2026 22:41:19 -0300 Subject: Give the message log to Messages as its own fields Not a pure move: state moves. Pardes's three message-log fields (`messages: [message_log]LoggedMessage`, `messages_head`, `messages_len`) become the fields of Messages.zig itself (`log`, `head`, `len`), and Pardes embeds one as `messages: Messages = .{}`. messageLog reads only the ring, so it now takes `m: *const Messages` and is called `p.messages.messageLog(i)` (Output's +Messages view and the log test); logMessage still needs the panes and the 9P event log, so it keeps `p: *Pardes` and writes `p.messages.log/head/len`. No behaviour change. Co-Authored-By: Claude Opus 5.5 --- src/Messages.zig | 47 ++++++++++++++++++++++++++++------------------- src/Output.zig | 3 +-- src/pardes.zig | 8 ++------ 3 files changed, 31 insertions(+), 27 deletions(-) (limited to 'src/Output.zig') diff --git a/src/Messages.zig b/src/Messages.zig index 6b041369..053950da 100644 --- a/src/Messages.zig +++ b/src/Messages.zig @@ -19,6 +19,15 @@ const Key = pardes.Key; const Rect = layout.Rect; const Pardes = pardes.Pardes; +const Messages = @This(); + +/// The message-row log: a fixed ring, never allocated, never grown. See +/// `logMessage` and the `Messages` builtin. +log: [limits.message_log]LoggedMessage = @splat(.{}), +/// Next slot to write. `len` saturates at the ring's size. +head: usize = 0, +len: usize = 0, + pub const LoggedMessage = struct { pub const cap = 256; text: [cap]u8 = undefined, @@ -347,8 +356,8 @@ fn logMessage(p: *Pardes, id: usize, text: []const u8) void { // /log hears every one: a client that retried and failed the same way // is waiting on that second line. Only the +Messages view collapses. ctlfs.events.noteMessage(p, serial, kept); - if (p.messages_len > 0) { - const last = &p.messages[(p.messages_head + limits.message_log - 1) % limits.message_log]; + if (p.messages.len > 0) { + const last = &p.messages.log[(p.messages.head + limits.message_log - 1) % limits.message_log]; if (last.serial == serial and std.mem.eql(u8, Message.body(last.slice()), Message.body(kept))) { @@ -360,20 +369,20 @@ fn logMessage(p: *Pardes, id: usize, text: []const u8) void { return; } } - const slot = &p.messages[p.messages_head]; + const slot = &p.messages.log[p.messages.head]; slot.len = @intCast(kept.len); @memcpy(slot.text[0..slot.len], kept); slot.serial = serial; slot.repeats = 1; - p.messages_head = (p.messages_head + 1) % limits.message_log; - p.messages_len = @min(p.messages_len + 1, limits.message_log); + p.messages.head = (p.messages.head + 1) % limits.message_log; + p.messages.len = @min(p.messages.len + 1, limits.message_log); } /// The log oldest-first, which is reading order. -pub fn messageLog(p: *const Pardes, i: usize) ?*const LoggedMessage { - if (i >= p.messages_len) return null; - const first = (p.messages_head + limits.message_log - p.messages_len) % limits.message_log; - return &p.messages[(first + i) % limits.message_log]; +pub fn messageLog(m: *const Messages, i: usize) ?*const LoggedMessage { + if (i >= m.len) return null; + const first = (m.head + limits.message_log - m.len) % limits.message_log; + return &m.log[(first + i) % limits.message_log]; } pub fn reportError(p: *Pardes, id: usize, operation: []const u8, err: anyerror) void { @@ -432,38 +441,38 @@ test "the message log keeps what the row forgets, and collapses repeats" { setMessage(p, 0, "14:32:09 saved /x.zig"); // same event, later clock setMessage(p, 0, "save: AccessDenied"); - try std.testing.expectEqual(@as(usize, 2), p.messages_len); - const first = messageLog(p, 0).?; + try std.testing.expectEqual(@as(usize, 2), p.messages.len); + const first = p.messages.messageLog(0).?; try std.testing.expectEqual(@as(u16, 2), first.repeats); // ...and the NEWEST wording is what survives, so the row carries the last // time it happened rather than the first. try std.testing.expectEqualStrings("14:32:09 saved /x.zig", first.slice()); - try std.testing.expectEqualStrings("save: AccessDenied", messageLog(p, 1).?.slice()); - try std.testing.expect(messageLog(p, 2) == null); + try std.testing.expectEqualStrings("save: AccessDenied", p.messages.messageLog(1).?.slice()); + try std.testing.expect(p.messages.messageLog(2) == null); // The same text from a DIFFERENT pane is a different event: one pane's // failure must not be recorded as another's. p.newScratchBelow(0); const other = p.active; setMessage(p, other, "save: AccessDenied"); - try std.testing.expectEqual(@as(usize, 3), p.messages_len); - try std.testing.expectEqual(p.panes[other].?.serial, messageLog(p, 2).?.serial); + try std.testing.expectEqual(@as(usize, 3), p.messages.len); + try std.testing.expectEqual(p.panes[other].?.serial, p.messages.messageLog(2).?.serial); // Progress is NOT logged: it arrives several times a second for a whole // index and would push everything else out (`setStatus`). setStatus(p, 0, "14:32:10 lsp rust-analyzer: Indexing 47%"); - try std.testing.expectEqual(@as(usize, 3), p.messages_len); + try std.testing.expectEqual(@as(usize, 3), p.messages.len); // The ring wraps rather than grows, and still reads oldest-first. for (0..limits.message_log + 5) |i| { var buf: [32]u8 = undefined; setMessage(p, 0, std.fmt.bufPrint(&buf, "line {d}", .{i}) catch unreachable); } - try std.testing.expectEqual(@as(usize, limits.message_log), p.messages_len); - try std.testing.expectEqualStrings("line 5", messageLog(p, 0).?.slice()); + try std.testing.expectEqual(@as(usize, limits.message_log), p.messages.len); + try std.testing.expectEqualStrings("line 5", p.messages.messageLog(0).?.slice()); var last_buf: [32]u8 = undefined; const want_last = std.fmt.bufPrint(&last_buf, "line {d}", .{limits.message_log + 4}) catch unreachable; - try std.testing.expectEqualStrings(want_last, messageLog(p, limits.message_log - 1).?.slice()); + try std.testing.expectEqualStrings(want_last, p.messages.messageLog(limits.message_log - 1).?.slice()); } test "Msg writes the transient row by hand, bare or with text, and input ends it" { diff --git a/src/Output.zig b/src/Output.zig index b216c0cf..6df2fd34 100644 --- a/src/Output.zig +++ b/src/Output.zig @@ -4,7 +4,6 @@ const panes = @import("panes.zig"); const std = @import("std"); const pardes = @import("pardes.zig"); const exec = @import("exec.zig"); -const Messages = @import("Messages.zig"); const config = @import("config.zig"); const Pardes = pardes.Pardes; const modal = @import("modal.zig"); @@ -686,7 +685,7 @@ 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 (Messages.messageLog(p, i)) |m| : (i += 1) { + while (p.messages.messageLog(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}); diff --git a/src/pardes.zig b/src/pardes.zig index 44f0d2ea..d2ac5868 100644 --- a/src/pardes.zig +++ b/src/pardes.zig @@ -3777,12 +3777,8 @@ pub const Pardes = struct { /// The in-program answers behind every unimplemented host method. Per /// instance, so several cores behind one fan-out host stay independent. fallback: host_io.Fallback, - /// The message-row log: a fixed ring, never allocated, never grown. See - /// `logMessage` and the `Messages` builtin. - messages: [limits.message_log]Messages.LoggedMessage = @splat(.{}), - /// Next slot to write. `messages_len` saturates at the ring's size. - messages_head: usize = 0, - messages_len: usize = 0, + /// The message-row log (see Messages.zig). + messages: Messages = .{}, in_q: [64]Event = undefined, in_head: usize = 0, in_len: usize = 0, -- cgit v1.3 From 95a3a1bb822e583988bfe0f312d0ef219b27a454 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Sun, 27 Sep 2026 23:06:11 -0300 Subject: Give a pane's body its own Text holding the cursor, selections, mode and undo acme keeps what edits a text in its Text (dat.h:171-190) and the window holds a body and a tag of that type. The cursor, the selections, the modal state and the edit-buffer undo move off Pane into Text.zig, Pane holds them as its body, and the edit and normal-mode operations take the Text they edit. Nothing changes in behaviour; this is the step that lets the tag become a second Text. Co-Authored-By: Claude Opus 5.5 --- src/File.zig | 78 ++-- src/Mini.zig | 2 +- src/Output.zig | 22 +- src/Pipe.zig | 52 +-- src/Terminal.zig | 114 +++--- src/Text.zig | 606 ++++++++++++++++++++++++++++ src/body_layer.zig | 44 +- src/colors.zig | 6 +- src/config.zig | 6 +- src/detached/client.zig | 6 +- src/detached/server.zig | 4 +- src/dump.zig | 4 +- src/edit.zig | 1020 ++++++++++++++++++++++++----------------------- src/exec.zig | 40 +- src/gui/gui.zig | 14 +- src/host_io.zig | 2 +- src/layout.zig | 2 +- src/look.zig | 106 ++--- src/macos.zig | 8 +- src/mouse.zig | 130 +++--- src/ninep/ctl.zig | 18 +- src/ninep/pane.zig | 26 +- src/normal.zig | 464 ++++++++++----------- src/panes.zig | 623 +---------------------------- src/pardes.zig | 239 +++++------ src/pdf_view.zig | 48 +-- src/tty/tty.zig | 6 +- test/fs_bench.zig | 4 +- test/hxdiff.zig | 34 +- test/mode.zig | 28 +- test/output.zig | 128 +++--- test/panes.zig | 398 +++++++++--------- test/pdf.zig | 42 +- test/perf.zig | 78 ++-- 34 files changed, 2224 insertions(+), 2178 deletions(-) create mode 100644 src/Text.zig (limited to 'src/Output.zig') diff --git a/src/File.zig b/src/File.zig index eb1c6a7c..239aa4ba 100644 --- a/src/File.zig +++ b/src/File.zig @@ -17,16 +17,17 @@ const Pane = panes.Pane; const Output = panes.Output; const Mini = panes.Mini; const Terminal = panes.Terminal; +const Text = panes.Text; const SYNTAX_CONTEXT_AFTER_ROWS: usize = 2; /// Content and primary selection at one file edit boundary. Keeping only the -/// primary avoids putting Pane.max_selections ranges in every history entry. +/// primary avoids putting Text.max_selections ranges in every history entry. pub const Snapshot = struct { content: []u8, cur_row: i32, cur_col: i32, - vsel: Pane.CharSel, + vsel: Text.CharSel, }; pub const History = struct { @@ -652,27 +653,28 @@ pub fn cursorLines(arena: std.mem.Allocator, pane: *Pane, f: *State) ![]const [] /// Use the file's line index only when `text` is its complete live content. /// Edit-buffer fragments and other temporary text retain modal's scan path. -fn contentIndex(pane: *Pane, text: []const u8) ?[]const usize { +fn contentIndex(t: *Text, text: []const u8) ?[]const usize { + const pane = t.pane(); const f = if (pane.file) |*file| file else return null; if (text.ptr != f.content.ptr or text.len != f.content.len) return null; return lineIndex(pane.gpa, f) catch null; } -pub fn textOffset(pane: *Pane, text: []const u8, cursor: modal.Cursor) usize { - const index = contentIndex(pane, text) orelse return modal.offsetAt(text, cursor); +pub fn textOffset(t: *Text, text: []const u8, cursor: modal.Cursor) usize { + const index = contentIndex(t, text) orelse return modal.offsetAt(text, cursor); const row = @min(cursor.row, index.len - 1); const start = index[row]; const end = if (row + 1 < index.len) index[row + 1] - 1 else text.len; return start + modal.graphemeStart(text[start..end], @min(cursor.col, end - start)); } -pub fn textLineStart(pane: *Pane, text: []const u8, row: usize) usize { - const index = contentIndex(pane, text) orelse return modal.lineStartOffset(text, row); +pub fn textLineStart(t: *Text, text: []const u8, row: usize) usize { + const index = contentIndex(t, text) orelse return modal.lineStartOffset(text, row); return if (row >= index.len) text.len else index[row]; } -pub fn textLine(pane: *Pane, text: []const u8, row: usize) []const u8 { - const index = contentIndex(pane, text) orelse return modal.lineSlice(text, row); +pub fn textLine(t: *Text, text: []const u8, row: usize) []const u8 { + const index = contentIndex(t, text) orelse return modal.lineSlice(text, row); if (row >= index.len) return ""; const start = index[row]; const end = if (row + 1 < index.len) index[row + 1] - 1 else text.len; @@ -686,7 +688,7 @@ test "indexed text rows preserve fragment and allocation failure semantics" { const pane = try p.setTestFile("first\n\tλ界\n\nlast\n"); const text = pane.file.?.content; allocator.fail_index = allocator.alloc_index; - for (0..lineCount(text) + 2) |row| try std.testing.expectEqualStrings(modal.lineSlice(text, row), textLine(pane, text, row)); + for (0..lineCount(text) + 2) |row| try std.testing.expectEqualStrings(modal.lineSlice(text, row), textLine(&pane.body, text, row)); try std.testing.expectEqual(@as(usize, 0), pane.file.?.line_starts.len); allocator.fail_index = std.math.maxInt(usize); _ = try lineIndex(p.gpa, &pane.file.?); @@ -695,19 +697,19 @@ test "indexed text rows preserve fragment and allocation failure semantics" { for ([_][]const u8{ text, text[2..], text[0..8], "other\nrows\n\n", "" }) |fragment| { for (0..lineCount(fragment) + 2) |row| try std.testing.expectEqualStrings( modal.lineSlice(fragment, row), - textLine(pane, fragment, row), + textLine(&pane.body, fragment, row), ); } try std.testing.expectEqual(allocations, allocator.allocations); } -pub fn textLineCount(pane: *Pane, text: []const u8) usize { - const index = contentIndex(pane, text) orelse return modal.cursorLineCount(text); +pub fn textLineCount(t: *Text, text: []const u8) usize { + const index = contentIndex(t, text) orelse return modal.cursorLineCount(text); return index.len; } -pub fn textPosition(pane: *Pane, text: []const u8, offset: usize) modal.Cursor { - const index = contentIndex(pane, text) orelse return modal.positionAt(text, offset); +pub fn textPosition(t: *Text, text: []const u8, offset: usize) modal.Cursor { + const index = contentIndex(t, text) orelse return modal.positionAt(text, offset); const bounded = @min(offset, text.len); const row = std.sort.upperBound(usize, index, bounded, struct { fn cmp(key: usize, item: usize) std.math.Order { @@ -734,8 +736,8 @@ pub fn open(p: *Pardes, id: usize, path: []const u8, line: usize) !*Pane { const total = lineCount(content); const scroll: usize = if (line > 0 and line <= total) line - 1 else 0; pane.file = .{ .path = path_copy, .content = content, .scroll = scroll, .history = history }; - pane.cur_pinned = true; - pane.cur_row = @intCast(scroll); + pane.body.cur_pinned = true; + pane.body.cur_row = @intCast(scroll); p.installPane(id, pane); if (filesystem.localPath(path) != null) p.emit(.{ .watch = .{ .pane = @intCast(id), .on = true } }); return pane; @@ -794,8 +796,8 @@ pub fn restore(p: *Pardes, id: usize, src: dump.Pane) !*Pane { .history = history, }; pane.file.?.tree_context = saved.tree_context and supportsContext(pane); - pane.cur_pinned = true; - pane.cur_row = @intCast(src.scroll); + pane.body.cur_pinned = true; + pane.body.cur_row = @intCast(src.scroll); pane.cols = @max(1, src.cols); pane.rows = @max(1, src.rows); if (output == null and filesystem.localPath(path) != null) p.emit(.{ .watch = .{ .pane = @intCast(id), .on = true, .mode = .baseline_disk } }); @@ -858,12 +860,12 @@ pub fn restoreSnap(pane: *Pane, f: *State, snap: Snapshot) void { const n = nlines(pane.gpa, f); const row: usize = @min(@as(usize, @intCast(@max(0, snap.cur_row))), n - 1); const llen = modal.lineSlice(f.content, row).len; - pane.cur_row = @intCast(row); - pane.cur_col = @intCast(@min(@as(usize, @intCast(@max(0, snap.cur_col))), llen)); - pane.vsel = snap.vsel; - pane.msel.active = false; - pane.cur_pinned = true; - pane.sticky_col = -1; + pane.body.cur_row = @intCast(row); + pane.body.cur_col = @intCast(@min(@as(usize, @intCast(@max(0, snap.cur_col))), llen)); + pane.body.vsel = snap.vsel; + pane.body.msel.active = false; + pane.body.cur_pinned = true; + pane.body.sticky_col = -1; pane.ensureCursorVisible(); } @@ -883,9 +885,9 @@ pub fn pushUndo(p: *Pardes, pane: *Pane) void { if (history.undo_len > 0 and std.mem.eql(u8, history.undo[history.undo_len - 1].content, f.content)) return; const snap: Snapshot = .{ .content = p.gpa.dupe(u8, f.content) catch return, - .cur_row = pane.cur_row, - .cur_col = pane.cur_col, - .vsel = pane.vsel, + .cur_row = pane.body.cur_row, + .cur_col = pane.body.cur_col, + .vsel = pane.body.vsel, }; pushHistory(p.gpa, &history.undo, &history.undo_len, snap); for (history.redo[0..history.redo_len]) |item| p.gpa.free(item.content); @@ -898,9 +900,9 @@ pub fn undo(p: *Pardes, pane: *Pane) void { if (history.undo_len == 0) return; const current: Snapshot = .{ .content = p.gpa.dupe(u8, f.content) catch return, - .cur_row = pane.cur_row, - .cur_col = pane.cur_col, - .vsel = pane.vsel, + .cur_row = pane.body.cur_row, + .cur_col = pane.body.cur_col, + .vsel = pane.body.vsel, }; pushHistory(p.gpa, &history.redo, &history.redo_len, current); history.undo_len -= 1; @@ -915,9 +917,9 @@ pub fn redo(p: *Pardes, pane: *Pane) void { if (history.redo_len == 0) return; const current: Snapshot = .{ .content = p.gpa.dupe(u8, f.content) catch return, - .cur_row = pane.cur_row, - .cur_col = pane.cur_col, - .vsel = pane.vsel, + .cur_row = pane.body.cur_row, + .cur_col = pane.body.cur_col, + .vsel = pane.body.vsel, }; pushHistory(p.gpa, &history.undo, &history.undo_len, current); history.redo_len -= 1; @@ -939,9 +941,9 @@ pub fn changed(p: *Pardes, id: u8, bytes: []const u8) void { // restoreSnap only consumes cursor/selection from this synthetic snapshot. restoreSnap(pane, f, .{ .content = undefined, - .cur_row = pane.cur_row, - .cur_col = pane.cur_col, - .vsel = pane.vsel, + .cur_row = pane.body.cur_row, + .cur_col = pane.body.cur_col, + .vsel = pane.body.vsel, }); } @@ -1126,7 +1128,7 @@ pub fn drawGutter(p: *Pardes, pane: *Pane, r: pardes.Rect, tx: u16, tw: u16, bod const prefix_width = gutterWidth(pane); const goff = pane.scroll(); const gcur = Terminal.gridCursor(pane); - const gcrow = if (pane.cur_pinned) pane.cur_row else @as(i32, gcur.y) + goff; + const gcrow = if (pane.body.cur_pinned) pane.body.cur_row else @as(i32, gcur.y) + goff; const cur_line: i32 = if (active and !pane.tag_edit) gcrow else std.math.minInt(i32); // the body's first row, the way renderPane derives it (Tagbottom) const body_y = p.bodyTop(r); diff --git a/src/Mini.zig b/src/Mini.zig index 52e26a37..e118e738 100644 --- a/src/Mini.zig +++ b/src/Mini.zig @@ -187,7 +187,7 @@ pub fn open(p: *Pardes, id: usize, argument: []const u8) !void { .history = history, .syntax_dirty = false, }; - pane.cur_pinned = true; + pane.body.cur_pinned = true; exec.placeDoc(p, id, free, pane); p.active = free; } diff --git a/src/Output.zig b/src/Output.zig index 6df2fd34..6e1765a7 100644 --- a/src/Output.zig +++ b/src/Output.zig @@ -402,7 +402,7 @@ pub fn open(p: *Pardes, id: usize, dir: []const u8, from: Origin, arg: []const u errdefer p.gpa.destroy(history); const pane = try p.newDocPane(id); pane.file = .{ .path = path, .content = content, .output = out, .history = history }; - pane.cur_pinned = true; + pane.body.cur_pinned = true; return pane; } @@ -737,20 +737,20 @@ pub fn openErrors(p: *Pardes, id: usize, content: []u8) !void { pub fn resetBody(p: *Pardes, pane: *Pane) void { pane.file.?.scroll = 0; - pane.cur_row = 0; - pane.cur_col = 0; - pane.cur_pinned = true; + pane.body.cur_row = 0; + pane.body.cur_col = 0; + pane.body.cur_pinned = true; pane.hscroll = 0; pane.wrap_n = 0; - pane.msel = .{}; - pane.vsel = .{}; - pane.nsel = 0; + pane.body.msel = .{}; + pane.body.vsel = .{}; + pane.body.nsel = 0; pane.nsel_snap = 0; - pane.select = false; + pane.body.select = false; pane.sel = @splat(.{}); - pane.sticky_col = -1; - pane.append_at = null; - pane.normal.clear(); + pane.body.sticky_col = -1; + pane.body.append_at = null; + pane.body.normal.clear(); pane.look_at = null; if (p.look_hover_wait) |wait| if (wait.serial == pane.serial) { p.look_hover_wait = null; diff --git a/src/Pipe.zig b/src/Pipe.zig index c01098ff..c2b49f31 100644 --- a/src/Pipe.zig +++ b/src/Pipe.zig @@ -45,7 +45,7 @@ pub const PendingPipe = struct { command: []u8, cwd: []u8, inputs: []selection_pipe.Input, - ranges: [Pane.max_selections]modal.Selection, + ranges: [panes.Text.max_selections]modal.Selection, primary: u8, explicit: bool, how: modal.Normal.PipeBehavior, @@ -84,8 +84,8 @@ pub fn submitPipe(p: *Pardes, id: usize) void { const command = armed[marker.len..]; if (command.len == 0) return; - var ranges: [Pane.max_selections]modal.Selection = undefined; - const got = pane.ranges(f.content, 0, &ranges); + var ranges: [panes.Text.max_selections]modal.Selection = undefined; + const got = pane.body.ranges(f.content, 0, &ranges); // `!`/`A-!` take no stdin and run ONCE — see `PendingPipe.nranges`. const ninputs = if (prompt.how.pipes()) got.n else 1; const inputs = p.gpa.alloc(selection_pipe.Input, ninputs) catch return; @@ -130,7 +130,7 @@ pub fn submitPipe(p: *Pardes, id: usize) void { .inputs = inputs, .ranges = ranges, .primary = @intCast(got.pri), - .explicit = (pane.vsel.active and pane.vsel.explicit) or pane.msel.active, + .explicit = (pane.body.vsel.active and pane.body.vsel.explicit) or pane.body.msel.active, .how = prompt.how, .nranges = @intCast(got.n), }; @@ -255,7 +255,7 @@ pub fn pipeResponse( const final_len = std.math.add(usize, kept, total_output) catch return; const replacement = p.gpa.alloc(u8, final_len) catch return; - var new_ranges: [Pane.max_selections]modal.Selection = undefined; + var new_ranges: [panes.Text.max_selections]modal.Selection = undefined; var read_at: usize = 0; var write_at: usize = 0; for (0..n) |i| { @@ -277,10 +277,10 @@ pub fn pipeResponse( @memcpy(replacement[write_at..], f.content[read_at..]); // One async request is one history transaction, even at 64 cursors. - edit.pushUndo(p, pane); + edit.pushUndo(p, &pane.body); panes.File.setContent(p, f, replacement); - pane.setRanges(f.content, new_ranges[0..n], &.{}, wait.primary, wait.explicit); - pane.select = false; + pane.body.setRanges(f.content, new_ranges[0..n], &.{}, wait.primary, wait.explicit); + pane.body.select = false; pane.ensureCursorVisible(); } @@ -290,9 +290,9 @@ test "selection pipe prompt submits exact request and Escape cancels" { defer p.deinit(); while (p.nextEffect()) |_| {} const pane = try p.setTestFile("one\ntwo\n"); - pane.cur_row = 0; - pane.cur_col = 2; - pane.vsel = .{ .active = true, .row = 0, .col = 0, .explicit = true }; + pane.body.cur_row = 0; + pane.body.cur_col = 2; + pane.body.vsel = .{ .active = true, .row = 0, .col = 0, .explicit = true }; p.update(.{ .key = .{ .cp = '|' } }); try std.testing.expect(pane.tag_edit and pane.prompt == .pipe); @@ -327,7 +327,7 @@ test "selection pipe replaces all ranges atomically and undo restores them" { .{ .anchor = 0, .head = 2 }, .{ .anchor = 6, .head = 8 }, }; - pane.setRanges(pane.file.?.content, &ranges, &.{}, 0, true); + pane.body.setRanges(pane.file.?.content, &ranges, &.{}, 0, true); p.update(.{ .key = .{ .cp = '|' } }); p.update(.{ .key = .{ .cp = 'c', .text = "cat" } }); @@ -345,9 +345,9 @@ test "selection pipe replaces all ranges atomically and undo restores them" { p.update(.{ .pipe_resp = .{ .id = id, .success = true, .outputs = outputs } }); try std.testing.expectEqualSlices(u8, "AA bb \n", pane.file.?.content); try std.testing.expectEqual(@as(usize, 1), pane.file.?.history.undo_len); - try std.testing.expectEqual(@as(u8, 1), pane.nsel); - try std.testing.expectEqual(@as(i32, 1), pane.cur_col); - try std.testing.expectEqual(@as(i32, 6), pane.sels[0].col); + try std.testing.expectEqual(@as(u8, 1), pane.body.nsel); + try std.testing.expectEqual(@as(i32, 1), pane.body.cur_col); + try std.testing.expectEqual(@as(i32, 6), pane.body.sels[0].col); try std.testing.expect(!denied.has_induced_failure); p.update(.{ .key = .{ .cp = 'u' } }); @@ -378,7 +378,7 @@ test "the four shell behaviours put their output where helix puts it" { defer p.deinit(); while (p.nextEffect()) |_| {} const pane = try p.setTestFile("aa bb cc\n"); - pane.setRanges(pane.file.?.content, &.{.{ .anchor = 3, .head = 5 }}, &.{}, 0, true); + pane.body.setRanges(pane.file.?.content, &.{.{ .anchor = 3, .head = 5 }}, &.{}, 0, true); p.update(.{ .key = case.key }); for ("cmd") |c| p.update(.{ .key = .{ .cp = c, .text = &.{c} } }); @@ -399,7 +399,7 @@ test "a command with no stdin runs once and every cursor gets that one answer" { .{ .anchor = 0, .head = 2 }, .{ .anchor = 6, .head = 8 }, }; - pane.setRanges(pane.file.?.content, &ranges, &.{}, 0, true); + pane.body.setRanges(pane.file.?.content, &ranges, &.{}, 0, true); p.update(.{ .key = .{ .cp = '!' } }); // insert-output: no stdin for ("date") |c| p.update(.{ .key = .{ .cp = c, .text = &.{c} } }); @@ -421,8 +421,8 @@ test "selection pipe failure and stale completion never mutate the file" { defer p.deinit(); while (p.nextEffect()) |_| {} const pane = try p.setTestFile("abc\n"); - pane.cur_col = 2; - pane.vsel = .{ .active = true, .row = 0, .col = 0, .explicit = true }; + pane.body.cur_col = 2; + pane.body.vsel = .{ .active = true, .row = 0, .col = 0, .explicit = true }; p.update(.{ .key = .{ .cp = '|' } }); p.update(.{ .key = .{ .cp = 'c', .text = "cat" } }); @@ -448,8 +448,8 @@ test "a failed filter opens an errors buffer carrying the command's own words" { defer p.deinit(); while (p.nextEffect()) |_| {} const pane = try p.setTestFile("abc\n"); - pane.cur_col = 2; - pane.vsel = .{ .active = true, .row = 0, .col = 0, .explicit = true }; + pane.body.cur_col = 2; + pane.body.vsel = .{ .active = true, .row = 0, .col = 0, .explicit = true }; p.update(.{ .key = .{ .cp = '|' } }); for ("trr") |c| p.update(.{ .key = .{ .cp = c, .text = &.{c} } }); @@ -491,8 +491,8 @@ test "selection pipe rejects a reused pane slot and a superseded request" { defer p.deinit(); while (p.nextEffect()) |_| {} var pane = try p.setTestFile("old\n"); - pane.cur_col = 2; - pane.vsel = .{ .active = true, .row = 0, .col = 0, .explicit = true }; + pane.body.cur_col = 2; + pane.body.vsel = .{ .active = true, .row = 0, .col = 0, .explicit = true }; p.update(.{ .key = .{ .cp = '|' } }); p.update(.{ .key = .{ .cp = 'c', .text = "cat" } }); @@ -503,8 +503,8 @@ test "selection pipe rejects a reused pane slot and a superseded request" { try std.testing.expectEqualSlices(u8, "new\n", pane.file.?.content); try std.testing.expectEqual(@as(usize, 0), pane.file.?.history.undo_len); - pane.cur_col = 2; - pane.vsel = .{ .active = true, .row = 0, .col = 0, .explicit = true }; + pane.body.cur_col = 2; + pane.body.vsel = .{ .active = true, .row = 0, .col = 0, .explicit = true }; p.update(.{ .key = .{ .cp = '|' } }); p.update(.{ .key = .{ .cp = 'c', .text = "cat" } }); p.update(.{ .key = .{ .cp = Key.enter } }); @@ -533,7 +533,7 @@ test "selection pipe binding is file-normal-only" { p.update(.{ .key = .{ .cp = '|' } }); try std.testing.expect(pane.prompt != .pipe); pane.file.?.output = null; - pane.mode = .insert; + pane.body.mode = .insert; p.update(.{ .key = .{ .cp = '|', .text = "|" } }); try std.testing.expect(pane.prompt != .pipe); try std.testing.expectEqualSlices(u8, "|x", pane.file.?.content); diff --git a/src/Terminal.zig b/src/Terminal.zig index cb752613..fbe7bfc0 100644 --- a/src/Terminal.zig +++ b/src/Terminal.zig @@ -200,7 +200,7 @@ pub const Snapshot = struct { ovl: ?EditBuffer, cur_row: i32, cur_col: i32, - vsel: Pane.CharSel, + vsel: panes.Text.CharSel, }; pub const PendingCommand = struct { @@ -677,16 +677,16 @@ pub fn feedOutput(p: *Pardes, pane: *Pane, bytes: []const u8) void { // There are no pty reads at all without an emulator to parse them into. if (comptime !enabled) return; if (pane.terminal == null) return; - const has_positions = pane.ovl != null or pane.cur_pinned or pane.vsel.active or - pane.msel.active or pane.nsel > 0 or pane.append_at != null or pane.look_at != null or - pane.ed_undo_len > 0 or pane.ed_redo_len > 0 or pointerRowCount(pane) > 0; + const has_positions = pane.ovl != null or pane.body.cur_pinned or pane.body.vsel.active or + pane.body.msel.active or pane.body.nsel > 0 or pane.body.append_at != null or pane.look_at != null or + pane.body.ed_undo_len > 0 or pane.body.ed_redo_len > 0 or pointerRowCount(pane) > 0; // Sticky bottom, as every other terminal does it: output drags the // viewport down only when the viewport was already on the last row, so // a reader scrolled back into the scrollback stays where they scrolled. const at_bottom = atBottom(pane); if (has_positions) ingestWithPositions(pane, bytes) else ingest(pane, bytes); p.shell_rows.markStale(pane); - const body_mode = if (pane.tag_edit) pane.tag_mode else pane.mode; + const body_mode = if (pane.tag_edit) pane.tag_mode else pane.body.mode; if (body_mode == .tty and at_bottom) followOutput(pane); } @@ -752,15 +752,15 @@ fn ingestWithPositions(pane: *Pane, bytes: []const u8) void { const key = screens.active_key; const generation = screens.generation(key); const pages = &screens.active.pages; - const Group = struct { overlay: ?*EditBuffer, cursor: *i32, selection: *Pane.CharSel }; + const Group = struct { overlay: ?*EditBuffer, cursor: *i32, selection: *panes.Text.CharSel }; var groups: [history_max * 2 + 1]Group = undefined; groups[0] = .{ .overlay = if (pane.ovl) |*overlay| overlay else null, - .cursor = &pane.cur_row, - .selection = &pane.vsel, + .cursor = &pane.body.cur_row, + .selection = &pane.body.vsel, }; var ngroups: usize = 1; - for ([_][]Snapshot{ pane.ed_undo[0..pane.ed_undo_len], pane.ed_redo[0..pane.ed_redo_len] }) |history| { + for ([_][]Snapshot{ pane.body.ed_undo[0..pane.body.ed_undo_len], pane.body.ed_redo[0..pane.body.ed_redo_len] }) |history| { for (history) |*snapshot| { groups[ngroups] = .{ .overlay = if (snapshot.ovl) |*overlay| overlay else null, @@ -773,7 +773,7 @@ fn ingestWithPositions(pane: *Pane, bytes: []const u8) void { const Span = struct { overlay: *EditBuffer, start: RowPin, end: RowPin }; var spans: [groups.len]Span = undefined; var nspans: usize = 0; - var positions: [groups.len * 2 + Pane.max_selections * 2 + 4]PositionPin = undefined; + var positions: [groups.len * 2 + panes.Text.max_selections * 2 + 4]PositionPin = undefined; var npositions: usize = 0; var failed = false; for (groups[0..ngroups]) |group| { @@ -793,19 +793,19 @@ fn ingestWithPositions(pane: *Pane, bytes: []const u8) void { } } const overlay = groups[0].overlay; - var extra: [Pane.max_selections * 2 + 4]*i32 = undefined; + var extra: [panes.Text.max_selections * 2 + 4]*i32 = undefined; var nextra: usize = 0; - if (pane.msel.active) { - extra[nextra] = &pane.msel.r0; - extra[nextra + 1] = &pane.msel.r1; + if (pane.body.msel.active) { + extra[nextra] = &pane.body.msel.r0; + extra[nextra + 1] = &pane.body.msel.r1; nextra += 2; } - for (pane.sels[0..pane.nsel]) |*selection| { + for (pane.body.sels[0..pane.body.nsel]) |*selection| { extra[nextra] = &selection.row; extra[nextra + 1] = &selection.arow; nextra += 2; } - if (pane.append_at) |*at| { + if (pane.body.append_at) |*at| { extra[nextra] = &at.row; nextra += 1; } @@ -883,7 +883,7 @@ test "raw terminal output needs no position tracking allocations" { const p = try Pardes.init(failing.allocator(), .{ .tty_only = true, .cols = 80, .rows = 24 }); defer p.deinit(); const pane = p.panes[0].?; - pane.mode = .tty; + pane.body.mode = .tty; feedOutput(p, pane, "warm"); const allocations = failing.alloc_index; failing.fail_index = allocations; @@ -1045,13 +1045,13 @@ pub fn forwardKey(p: *Pardes, id: usize, key: Key) void { pub fn enterTty(p: *Pardes, id: usize) void { const pane = p.panes[id] orelse return; const selected = pane.rawPointerText(pane.sel[@intFromEnum(config.select_button)]) != null; - if (comptime enabled) if (!selected and pane.terminal != null and pane.cur_pinned and pane.terminal.?.vt.cursorIsAtPrompt()) handoff: { + if (comptime enabled) if (!selected and pane.terminal != null and pane.body.cur_pinned and pane.terminal.?.vt.cursorIsAtPrompt()) handoff: { const screen = pane.terminal.?.vt.screens.active; const goff: i32 = @intCast(screen.pages.scrollbar().offset); - const vp_row = pane.gridRow(pane.cur_row) - goff; + const vp_row = pane.gridRow(pane.body.cur_row) - goff; if (vp_row < 0) break :handoff; - var grid_col: i32 = @max(0, pane.cur_col); + var grid_col: i32 = @max(0, pane.body.cur_col); if (screen.pages.pin(.{ .viewport = .{ .x = 0, .y = @intCast(vp_row) } })) |row_pin| { if (row_pin.rowAndCell().row.semantic_prompt != .none) switch (promptCut(row_pin)) { .cut => |cols| grid_col += @intCast(cols), @@ -1070,18 +1070,18 @@ pub fn enterTty(p: *Pardes, id: usize) void { for (0..moves.right) |_| p.emitWrite(id, "\x1b[C"); }; - pane.mode = .tty; + pane.body.mode = .tty; followOutput(pane); // entering raw mode is a request for the live shell - pane.msel.active = false; - pane.vsel.active = false; - pane.nsel = 0; + pane.body.msel.active = false; + pane.body.vsel.active = false; + pane.body.nsel = 0; // The raw renderer follows the live cursor. A captured mouse selection // keeps its modal endpoint for the next return to editor mode. - pane.cur_pinned = selected; - pane.select = false; - pane.append_at = null; - pane.sticky_col = -1; - pane.normal.clear(); + pane.body.cur_pinned = selected; + pane.body.select = false; + pane.body.append_at = null; + pane.body.sticky_col = -1; + pane.body.normal.clear(); } // Returned slices remain valid until the next cache rebuild or reset. @@ -1397,7 +1397,7 @@ pub fn dumpPane( var skip: i32 = 0; while (lines.next()) |raw| : (row += 1) { // Hidden overlay rows still consume prompt pins to keep them aligned. - const prompt = if (pane.mode != .tty) prompts.next() else null; + const prompt = if (pane.body.mode != .tty) prompts.next() else null; if (skip > 0) { skip -= 1; continue; @@ -1406,7 +1406,7 @@ pub fn dumpPane( stream[len] = '\n'; len += 1; } - if (pane.mode != .tty) if (pane.ovl) |overlay| if (row == overlay.row) { + if (pane.body.mode != .tty) if (pane.ovl) |overlay| if (row == overlay.row) { @memcpy(stream[len..][0..overlay.text.len], overlay.text); len += overlay.text.len; skip = overlay.rows - 1; @@ -1493,7 +1493,7 @@ pub fn bodyText(arena: std.mem.Allocator, pane: *Pane) ![]const u8 { var lines = std.mem.splitScalar(u8, raw, '\n'); var n: usize = 0; while (lines.next()) |ln| { - vp[n] = if (pane.mode != .tty) + vp[n] = if (pane.body.mode != .tty) if (prompts.next()) |pin| if (pin.rowAndCell().row.semantic_prompt != .none) promptRow(pin, ln) else ln else @@ -1535,7 +1535,7 @@ const BodyWalk = struct { return .{ .pane = pane, .goff = goff, - .g = if (pane.mode == .tty) goff else pane.gridRow(off), + .g = if (pane.body.mode == .tty) goff else pane.gridRow(off), .skip = if (pane.ovl) |o| @intCast(@max(0, off - pane.surfRow(o.row))) else 0, }; } @@ -1562,7 +1562,7 @@ const BodyWalk = struct { w.lines = null; continue; } - if (w.pane.mode != .tty) if (w.pane.ovl) |o| if (w.g == o.row) { + if (w.pane.body.mode != .tty) if (w.pane.ovl) |o| if (w.g == o.row) { w.lines = std.mem.splitScalar(u8, o.text, '\n'); w.covered = o.rows; w.line_idx = 0; @@ -1759,7 +1759,7 @@ pub fn recolorAnsi(p: *Pardes, pane: *Pane, r: pardes.Rect, tx: u16, tw: u16, bo const vi = anchor.row; if (vi < 0 or vi >= vp_rows) continue; const row_pin = pages.pin(.{ .viewport = .{ .y = @intCast(vi) } }) orelse continue; - const cut: u16 = if (pane.mode == .tty) 0 else cut: { + const cut: u16 = if (pane.body.mode == .tty) 0 else cut: { if (row_pin.rowAndCell().row.semantic_prompt == .none) break :cut 0; break :cut switch (promptCut(row_pin)) { .keep => 0, @@ -2388,13 +2388,13 @@ test "tty ansi colors follow the prompt hug into normal mode" { const blue: pardes.Color = .{ .rgb = p.theme().palette.?[4] }; // tty mode projects the emulator's ansi colours cell for cell. - pane.mode = .tty; + pane.body.mode = .tty; p.shell_rows.stale = true; const tty = try p.render(frame.allocator()); try testing.expectEqual(red, tty.at(tx + 2, body_y).style.fg); try testing.expectEqual(blue, tty.at(tx + 3, body_y).style.fg); - pane.mode = .normal; + pane.body.mode = .normal; p.shell_rows.stale = true; _ = frame.reset(.retain_capacity); const norm = try p.render(frame.allocator()); @@ -2411,7 +2411,7 @@ test "a prompt row hidden end to end paints nothing at all" { while (p.nextEffect()) |_| {} const pane = p.panes[0].?; pane.tty_filter = false; - pane.mode = .normal; + pane.body.mode = .normal; p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b]133;A\x1b\\\x1b[32maaaaaaaaa\x1b]133;B\x1b\\\x1b[41;36m\u{754C}\x1b[0m\r\n" } }); var frame = std.heap.ArenaAllocator.init(testing.allocator); @@ -2467,7 +2467,7 @@ pub fn padOutputBelowEdits(p: *Pardes, id: usize) void { pub fn snap(p: *Pardes, pane: *Pane) ?Snapshot { var ovl: ?EditBuffer = null; if (pane.ovl) |o| ovl = .{ .row = o.row, .rows = o.rows, .text = p.gpa.dupe(u8, o.text) catch return null }; - return .{ .ovl = ovl, .cur_row = pane.cur_row, .cur_col = pane.cur_col, .vsel = pane.vsel }; + return .{ .ovl = ovl, .cur_row = pane.body.cur_row, .cur_col = pane.body.cur_col, .vsel = pane.body.vsel }; } /// undo/redo restores the selection recorded with the snapshot (helix @@ -2475,11 +2475,11 @@ pub fn snap(p: *Pardes, pane: *Pane) ?Snapshot { pub fn restoreSnap(p: *Pardes, pane: *Pane, s: Snapshot) void { if (pane.ovl) |o| p.gpa.free(o.text); pane.ovl = s.ovl; - pane.cur_row = s.cur_row; - pane.cur_col = s.cur_col; - pane.cur_pinned = true; - pane.vsel = s.vsel; - pane.msel.active = false; + pane.body.cur_row = s.cur_row; + pane.body.cur_col = s.cur_col; + pane.body.cur_pinned = true; + pane.body.vsel = s.vsel; + pane.body.msel.active = false; pane.ensureCursorVisible(); } @@ -2495,32 +2495,32 @@ fn pushHistory(gpa: std.mem.Allocator, slots: []Snapshot, len: *usize, value: Sn pub fn pushUndo(p: *Pardes, pane: *Pane) void { const current = pane.ovl orelse EditBuffer{ .rows = 0 }; - if (pane.ed_undo_len > 0) { - const top = pane.ed_undo[pane.ed_undo_len - 1]; + if (pane.body.ed_undo_len > 0) { + const top = pane.body.ed_undo[pane.body.ed_undo_len - 1]; const same = if (top.ovl) |overlay| pane.ovl != null and overlay.row == current.row and overlay.rows == current.rows and std.mem.eql(u8, overlay.text, current.text) else pane.ovl == null; if (same) return; } const value = snap(p, pane) orelse return; - pushHistory(p.gpa, &pane.ed_undo, &pane.ed_undo_len, value); - for (pane.ed_redo[0..pane.ed_redo_len]) |item| if (item.ovl) |overlay| p.gpa.free(overlay.text); - pane.ed_redo_len = 0; + pushHistory(p.gpa, &pane.body.ed_undo, &pane.body.ed_undo_len, value); + for (pane.body.ed_redo[0..pane.body.ed_redo_len]) |item| if (item.ovl) |overlay| p.gpa.free(overlay.text); + pane.body.ed_redo_len = 0; } pub fn undo(p: *Pardes, pane: *Pane) void { - if (pane.ed_undo_len == 0) return; + if (pane.body.ed_undo_len == 0) return; const current = snap(p, pane) orelse return; - pushHistory(p.gpa, &pane.ed_redo, &pane.ed_redo_len, current); - pane.ed_undo_len -= 1; - restoreSnap(p, pane, pane.ed_undo[pane.ed_undo_len]); + pushHistory(p.gpa, &pane.body.ed_redo, &pane.body.ed_redo_len, current); + pane.body.ed_undo_len -= 1; + restoreSnap(p, pane, pane.body.ed_undo[pane.body.ed_undo_len]); } pub fn redo(p: *Pardes, pane: *Pane) void { - if (pane.ed_redo_len == 0) return; + if (pane.body.ed_redo_len == 0) return; const current = snap(p, pane) orelse return; - pushHistory(p.gpa, &pane.ed_undo, &pane.ed_undo_len, current); - pane.ed_redo_len -= 1; - restoreSnap(p, pane, pane.ed_redo[pane.ed_redo_len]); + pushHistory(p.gpa, &pane.body.ed_undo, &pane.body.ed_undo_len, current); + pane.body.ed_redo_len -= 1; + restoreSnap(p, pane, pane.body.ed_redo[pane.body.ed_redo_len]); } pub fn ptyReport(handler: *ghostty_vt.TerminalStream.Handler, data: [:0]const u8) void { diff --git a/src/Text.zig b/src/Text.zig new file mode 100644 index 00000000..ad5aa186 --- /dev/null +++ b/src/Text.zig @@ -0,0 +1,606 @@ +//! One editable text, acme's Text (editors/acme/dat.h:171-190, text.c): the +//! cursor, the selections and the modal state that edit it, and the undo of +//! an edit buffer. A pane's body is one. Where its characters come from -- a +//! file's content, a terminal's edit overlay, a PDF's text -- is the window's +//! business (edit.zig's editText and flatSurface), the way acme's Text reads +//! its File; everything here works on the flat text it is handed. +const std = @import("std"); +const panes = @import("panes.zig"); +const modal = @import("modal.zig"); +const config = @import("config.zig"); +const Pane = panes.Pane; +const File = panes.File; +const Terminal = panes.Terminal; +const Text = @This(); + +pub const Mode = enum { normal, insert, tty }; + +/// A modal line selection (helix `x`): whole rows [r0, r1], absolute. +pub const LineSel = struct { + active: bool = false, + r0: i32 = 0, + r1: i32 = 0, +}; + +pub const CharSel = struct { + active: bool = false, + row: i32 = 0, + col: i32 = 0, + explicit: bool = false, +}; + +pub const max_selections = 64; + +pub const SelRange = struct { + row: i32, + col: i32, + arow: i32, + acol: i32, + /// this range's own j/k goal column (helix Range::old_visual_position); + /// the PRIMARY's copy is Text.sticky_col + sticky: i32 = -1, +}; + +mode: Mode = .normal, +cur_pinned: bool = false, +cur_row: i32 = 0, +cur_col: i32 = 0, +msel: LineSel = .{}, +vsel: CharSel = .{}, +sels: [max_selections - 1]SelRange = undefined, +nsel: u8 = 0, +select: bool = false, +/// sticky goal column for j/k runs (helix old_visual_position): any +/// non-vertical range write resets it to -1. +sticky_col: i32 = -1, +append_at: ?struct { row: i32, col: i32 } = null, +normal: modal.Normal.State = .{}, +/// last f/F/t/T motion, for Alt-. repeat +find_op: u8 = 0, +find_ch: u21 = 0, +ed_undo: [Terminal.history_max]Terminal.Snapshot = undefined, +ed_undo_len: usize = 0, +ed_redo: [Terminal.history_max]Terminal.Snapshot = undefined, +ed_redo_len: usize = 0, + +/// The window this text belongs to (acme's t->w). +pub fn pane(t: *Text) *Pane { + return @alignCast(@fieldParentPtr("body", t)); +} + +pub fn toModalCursor(t: *Text) modal.Cursor { + return .{ .row = @intCast(@max(0, t.cur_row)), .col = @intCast(@max(0, t.cur_col)) }; +} + +pub fn fromModalCursor(t: *Text, c: modal.Cursor) void { + t.cur_row = @as(i32, @intCast(c.row)); + t.cur_col = @intCast(c.col); + t.cur_pinned = true; +} + +pub fn insertVerticalCursor(lines: []const []const u8, c: modal.Cursor, down: bool) modal.Cursor { + if (lines.len == 0) return c; + const row = if (down) @min(c.row + 1, lines.len - 1) else c.row -| 1; + const target = lines[row]; + if (target.len == 0) return .{ .row = row, .col = 0 }; + const source = if (c.row < lines.len) lines[c.row] else ""; + const goal = File.rawDisplayCol(source, c.col); + const mapped = File.rawAtDisplay(target, goal); + const last = modal.prevGrapheme(target, target.len); + return .{ .row = row, .col = modal.graphemeStart(target, @min(mapped, last)) }; +} + +pub fn primaryRange(t: *Text, text: []const u8, row0: i32) modal.Selection { + const c = File.textOffset(t, text, .{ .row = @intCast(@max(0, t.cur_row - row0)), .col = @intCast(@max(0, t.cur_col)) }); + if (t.msel.active) { + // legacy line selection (file-search results highlight): linewise + const r0: usize = @intCast(@max(0, @min(t.msel.r0, t.msel.r1) - row0)); + const r1: usize = @intCast(@max(0, @max(t.msel.r0, t.msel.r1) - row0)); + const s = modal.lineStartOffset(text, r0); + const e = if (r1 + 1 >= modal.cursorLineCount(text)) text.len else modal.lineStartOffset(text, r1 + 1); + return .{ .anchor = s, .head = @max(e, modal.nextGrapheme(text, c)) }; + } + if (t.vsel.active) return cellRange(text, t.vsel.row - row0, t.vsel.col, t.cur_row - row0, t.cur_col); + return .{ .anchor = c, .head = modal.nextGrapheme(text, c) }; +} + +pub fn cellRange(text: []const u8, arow: i32, acol: i32, hrow: i32, hcol: i32) modal.Selection { + const a = modal.offsetAt(text, .{ .row = @intCast(@max(0, arow)), .col = @intCast(@max(0, acol)) }); + const c = modal.offsetAt(text, .{ .row = @intCast(@max(0, hrow)), .col = @intCast(@max(0, hcol)) }); + return cellOffRange(text, a, c); +} + +/// the same, from the two cells' gap offsets +pub fn cellOffRange(text: []const u8, a: usize, c: usize) modal.Selection { + if (a <= c) return .{ .anchor = a, .head = modal.nextGrapheme(text, c) }; + return .{ .anchor = modal.nextGrapheme(text, a), .head = c }; +} + +pub fn rangeCells(text: []const u8, r: modal.Selection) struct { cur: usize, anc: usize } { + if (r.head > r.anchor) return .{ .cur = modal.prevGrapheme(text, r.head), .anc = r.anchor }; + if (r.head < r.anchor) return .{ .cur = r.head, .anc = modal.prevGrapheme(text, r.anchor) }; + return .{ .cur = r.head, .anc = r.head }; +} + +pub fn setRange(t: *Text, text: []const u8, row0: i32, r0: modal.Selection, explicit: bool) void { + var r = r0; + if (r.anchor == r.head) r.head = modal.nextGrapheme(text, r.head); // min_width_1 + const off = rangeCells(text, r); + const cc = File.textPosition(t, text, off.cur); + // a bare block cursor has both cells on the same offset — the common + // case by far — and this conversion is not free even indexed + const ac = if (off.anc == off.cur) cc else File.textPosition(t, text, off.anc); + t.cur_row = @as(i32, @intCast(cc.row)) + row0; + t.cur_col = @intCast(cc.col); + t.vsel = .{ + .active = off.anc != off.cur or t.select, + .row = @as(i32, @intCast(ac.row)) + row0, + .col = @intCast(ac.col), + .explicit = explicit or t.select, + }; + t.msel.active = false; + t.nsel = 0; // writing ONE range means the selection IS that range + t.cur_pinned = true; + t.sticky_col = -1; + t.normal.clear(); + t.pane().ensureCursorVisible(); +} + +pub fn ranges(t: *Text, text: []const u8, row0: i32, out: *[max_selections]modal.Selection) struct { n: usize, pri: usize } { + const pr = primaryRange(t, text, row0); + var n: usize = 0; + var pri: usize = 0; + var placed = false; + for (t.sels[0..t.nsel]) |s| { + const r = cellRange(text, s.arow - row0, s.acol, s.row - row0, s.col); + if (!placed and @min(pr.anchor, pr.head) <= @min(r.anchor, r.head)) { + pri = n; + out[n] = pr; + n += 1; + placed = true; + } + out[n] = r; + n += 1; + } + if (!placed) { + pri = n; + out[n] = pr; + n += 1; + } + return .{ .n = n, .pri = pri }; +} + +pub fn setRanges(t: *Text, text: []const u8, in: []const modal.Selection, sticky: []const i32, pri0: usize, explicit: bool) void { + if (in.len == 0) return; // helix asserts non-empty; here it just means "no change" + var r: [max_selections]modal.Selection = undefined; + var st: [max_selections]i32 = undefined; + var n: usize = @min(in.len, max_selections); + var pri: usize = @min(pri0, n - 1); + for (in[0..n], 0..) |x, i| { + r[i] = x; + if (r[i].anchor == r[i].head) r[i].head = modal.nextGrapheme(text, r[i].head); + st[i] = if (i < sticky.len) sticky[i] else -1; + } + // insertion sort by start — n is tiny and usually already ordered + var i: usize = 1; + while (i < n) : (i += 1) { + var j = i; + while (j > 0 and @min(r[j].anchor, r[j].head) < @min(r[j - 1].anchor, r[j - 1].head)) : (j -= 1) { + std.mem.swap(modal.Selection, &r[j], &r[j - 1]); + std.mem.swap(i32, &st[j], &st[j - 1]); + if (pri == j) pri = j - 1 else if (pri == j - 1) pri = j; + } + } + var k: usize = 0; + i = 1; + while (i < n) : (i += 1) { + const a = r[k]; + const b = r[i]; + const af = @min(a.anchor, a.head); + const at = @max(a.anchor, a.head); + const bf = @min(b.anchor, b.head); + const bt = @max(b.anchor, b.head); + if (af == bf or (at > bf and bt > af)) { + r[k] = if (a.anchor > a.head and b.anchor > b.head) + .{ .anchor = @max(a.anchor, b.anchor), .head = @min(a.head, b.head) } + else + .{ .anchor = @min(af, bf), .head = @max(at, bt) }; + if (pri == i) pri = k; + if (st[k] < 0) st[k] = st[i]; + continue; + } + k += 1; + r[k] = b; + st[k] = st[i]; + if (pri == i) pri = k; + } + n = k + 1; + setRange(t, text, 0, r[pri], explicit); + t.sticky_col = st[pri]; + var w: usize = 0; + for (r[0..n], 0..) |x, idx| { + if (idx == pri) continue; + const c = rangeCells(text, x); + const cc = modal.positionAt(text, c.cur); + const ac = modal.positionAt(text, c.anc); + t.sels[w] = .{ + .row = @as(i32, @intCast(cc.row)), + .col = @intCast(cc.col), + .arow = @as(i32, @intCast(ac.row)), + .acol = @intCast(ac.col), + .sticky = st[idx], + }; + w += 1; + } + t.nsel = @intCast(w); +} + +pub fn multiSelAction(t: *Text, text: []const u8, kind: modal.Normal.Multi, cnt: usize) void { + var rs: [max_selections]modal.Selection = undefined; + const got = ranges(t, text, 0, &rs); + const n = got.n; + const expl = (t.vsel.active and t.vsel.explicit) or t.msel.active; + if (kind == .remove_primary) { + if (n < 2) return; // helix: "no selections remaining" + var out: [max_selections]modal.Selection = undefined; + var m: usize = 0; + for (rs[0..n], 0..) |r, i| { + if (i == got.pri) continue; + out[m] = r; + m += 1; + } + // helix Selection::remove: the NEXT range takes over, or the + // previous one when the primary was last + return setRanges(t, text, out[0..m], &.{}, @min(got.pri, m - 1), expl); + } + if (kind == .rotate_forward or kind == .rotate_backward) { + const step = cnt % n; + const pri = if (kind == .rotate_forward) (got.pri + step) % n else (got.pri + (n - step)) % n; + return setRanges(t, text, rs[0..n], &.{}, pri, expl); + } + if (kind == .merge) { + // helix merge_selections: first.merge(last) — the ranges are + // sorted, so that is simply the whole span + const lo = @min(rs[0].anchor, rs[0].head); + const hi = @max(rs[n - 1].anchor, rs[n - 1].head); + const rev = rs[0].anchor > rs[0].head and rs[n - 1].anchor > rs[n - 1].head; + const one: modal.Selection = if (rev) .{ .anchor = hi, .head = lo } else .{ .anchor = lo, .head = hi }; + return setRanges(t, text, &.{one}, &.{}, 0, expl); + } + if (kind == .merge_consecutive) { + var out: [max_selections]modal.Selection = undefined; + var m: usize = 0; + var pri: usize = 0; + for (rs[0..n], 0..) |r, i| { + if (m > 0 and @min(r.anchor, r.head) == @max(out[m - 1].anchor, out[m - 1].head)) { + const lo = @min(@min(out[m - 1].anchor, out[m - 1].head), @min(r.anchor, r.head)); + const hi = @max(@max(out[m - 1].anchor, out[m - 1].head), @max(r.anchor, r.head)); + out[m - 1] = .{ .anchor = lo, .head = hi }; + if (i == got.pri) pri = m - 1; + continue; + } + if (i == got.pri) pri = m; + out[m] = r; + m += 1; + } + return setRanges(t, text, out[0..m], &.{}, pri, expl); + } + if (kind == .split_newline) { + // helix selection::split_on_newline — one range per line the + // selection covers, the newlines themselves left out + var out: [max_selections]modal.Selection = undefined; + var m: usize = 0; + for (rs[0..n]) |r| { + const from = @min(r.anchor, r.head); + const to = @max(r.anchor, r.head); + if (from == to) { + if (m < max_selections) { + out[m] = r; + m += 1; + } + continue; + } + var start = from; + while (start < to and m < max_selections) { + const eol = modal.lineEndOffset(text, modal.lineAtOffset(text, start)); + if (eol >= to) { + out[m] = .{ .anchor = start, .head = to }; + m += 1; + break; + } + out[m] = .{ .anchor = start, .head = eol }; + m += 1; + start = eol + 1; + } + } + if (m == 0) return; + return setRanges(t, text, out[0..m], &.{}, 0, true); // helix keeps primary 0 + } + if (kind == .trim) { + // helix trim_selections: whitespace off both ends; ranges that are + // empty or all whitespace are dropped entirely + var out: [max_selections]modal.Selection = undefined; + var m: usize = 0; + for (rs[0..n]) |r| { + var from = @min(r.anchor, r.head); + var to = @max(r.anchor, r.head); + while (from < to and std.ascii.isWhitespace(text[from])) from += 1; + while (to > from and std.ascii.isWhitespace(text[to - 1])) to -= 1; + if (from >= to) continue; + out[m] = if (r.anchor > r.head) .{ .anchor = to, .head = from } else .{ .anchor = from, .head = to }; + m += 1; + } + if (m == 0) { // helix: collapse_selection + keep_primary_selection + const c = modal.selectionCursor(text, rs[got.pri]); + return setRange(t, text, 0, .{ .anchor = c, .head = c }, false); + } + // helix: the first survivor that OVERLAPS the old primary, else the last + const pf = @min(rs[got.pri].anchor, rs[got.pri].head); + const pt = @max(rs[got.pri].anchor, rs[got.pri].head); + var pri = m - 1; + for (out[0..m], 0..) |r, i| { + const f = @min(r.anchor, r.head); + const to = @max(r.anchor, r.head); + if (f == pf or (to > pf and pt > f)) { + pri = i; + break; + } + } + return setRanges(t, text, out[0..m], &.{}, pri, expl); + } + const below = kind == .copy_below; + var out: [max_selections]modal.Selection = undefined; + var m: usize = 0; + var pri: usize = 0; + const nlines = modal.cursorLineCount(text); + for (rs[0..n], 0..) |r, ri| { + const is_pri = ri == got.pri; + // head-exclusive: back the leading end off onto its own cell + const hp = modal.positionAt(text, if (r.anchor < r.head) modal.prevGrapheme(text, r.head) else r.head); + const ap = modal.positionAt(text, if (r.anchor < r.head) r.anchor else modal.prevGrapheme(text, r.anchor)); + const height = @max(hp.row, ap.row) - @min(hp.row, ap.row) + 1; + if (m >= max_selections) break; + if (is_pri) pri = m; + out[m] = r; + m += 1; + var made: usize = 0; + var k: usize = 0; + while (made < cnt and m < max_selections) : (k += 1) { + const d = (k + 1) * height; + const arow = if (below) ap.row + d else ap.row -| d; + const hrow = if (below) hp.row + d else hp.row -| d; + if (arow >= nlines or hrow >= nlines) break; + const a2 = modal.offsetAt(text, .{ .row = arow, .col = ap.col }); + const h2 = modal.offsetAt(text, .{ .row = hrow, .col = hp.col }); + // a line too short to reach the column is skipped, not clamped + if (modal.positionAt(text, a2).col == ap.col and modal.positionAt(text, h2).col == hp.col) { + if (is_pri) pri = m; + out[m] = modal.moveSelectionCursor(text, .{ .anchor = a2, .head = a2 }, h2, true); + m += 1; + made += 1; + } + if (arow == 0 and hrow == 0) break; + } + } + setRanges(t, text, out[0..m], &.{}, pri, expl); +} + +/// a range's start CELL (document order key) — the smaller of its two ends +pub fn selStart(s: SelRange) struct { row: i32, col: i32 } { + if (s.arow < s.row or (s.arow == s.row and s.acol < s.col)) return .{ .row = s.arow, .col = s.acol }; + return .{ .row = s.row, .col = s.col }; +} + +pub fn maxLine(text: []const u8) usize { + const nl = modal.cursorLineCount(text); + return if (text.len == 0 or text[text.len - 1] == '\n') nl -| 2 else nl - 1; +} + +/// point-target motion: collapse there (extend in select mode) +pub fn pointMove(t: *Text, text: []const u8, range: modal.Selection, target: usize) void { + setRange(t, text, 0, modal.moveSelectionCursor(text, range, target, t.select), false); +} + +/// word motions select their traversed span (extend mode: head only) +pub fn wordMove(t: *Text, text: []const u8, range: modal.Selection, cnt: usize, target: modal.WordTarget) void { + const wr = modal.moveWord(text, range, cnt, target); + const res = if (t.select) modal.moveSelectionCursor(text, range, modal.selectionCursor(text, wr), true) else wr; + setRange(t, text, 0, res, false); +} + +/// f/t/F/T: anchor at the old cursor cell, head on the hit (not found: no move) +pub fn findMove(t: *Text, text: []const u8, range: modal.Selection, ch: u21, fwd: bool, till: bool, cnt: usize) void { + const cur = modal.selectionCursor(text, range); + const target = modal.findTarget(text, cur, ch, fwd, till, cnt) orelse return; + const res = if (t.select) + modal.moveSelectionCursor(text, range, target, true) + else + modal.moveSelectionCursor(text, .{ .anchor = cur, .head = cur }, target, true); + setRange(t, text, 0, res, false); +} + +/// j/k and friends: sticky goal column, clamped onto short lines' newline +pub fn verticalMove(t: *Text, text: []const u8, range: modal.Selection, down: bool, cnt: usize) void { + const cur = modal.selectionCursor(text, range); + const pos = File.textPosition(t, text, cur); + const goal: usize = if (t.sticky_col >= 0) + @intCast(t.sticky_col) + else + File.rawDisplayCol(File.textLine(t, text, pos.row), pos.col); + const last_row = File.textLineCount(t, text) - 1; + const nline = if (down) @min(pos.row + @max(1, cnt), last_row) else pos.row -| @max(1, cnt); + const target_col = File.rawAtDisplay(File.textLine(t, text, nline), goal); + const target = File.textOffset(t, text, .{ .row = nline, .col = target_col }); + // extend mode never walks onto the empty trailing line (helix) + if (t.select and target == text.len and text.len > 0 and text[text.len - 1] == '\n') return; + setRange(t, text, 0, modal.moveSelectionCursor(text, range, target, t.select), false); + t.sticky_col = @intCast(goal); +} + +pub fn visualMove( + t: *Text, + text: []const u8, + range: modal.Selection, + down: bool, + cnt: usize, + width: usize, +) void { + const cur = modal.selectionCursor(text, range); + const pos = File.textPosition(t, text, cur); + const last_row = File.textLineCount(t, text) - 1; + var row = pos.row; + var line = modal.lineSlice(text, row); + var vrow = File.visualRow(line, pos.col, width); + const goal: usize = if (t.sticky_col >= 0) + @intCast(t.sticky_col) + else + File.rawDisplayCol(line[vrow.start..vrow.end], pos.col -| vrow.start); + var steps = @max(1, cnt); + while (steps > 0) : (steps -= 1) { + if (down) { + if (vrow.end < line.len) { + vrow = File.visualRow(line, vrow.end, width); + continue; + } + if (row == last_row) break; + row += 1; + line = modal.lineSlice(text, row); + vrow = File.visualRow(line, 0, width); + } else { + if (vrow.start > 0) { + vrow = File.visualRow(line, vrow.start - 1, width); + continue; + } + if (row == 0) break; + row -= 1; + line = modal.lineSlice(text, row); + vrow = File.visualRow(line, line.len, width); + } + } + // The newline slot is a real cursor position, but the first byte of the + // NEXT visual row is not: landing there would read as two rows moved. + var target_col = vrow.start + File.rawAtDisplay(line[vrow.start..vrow.end], goal); + if (vrow.end < line.len and target_col >= vrow.end) + target_col = modal.graphemeStart(line, vrow.end - 1); + const target = File.textOffset(t, text, .{ .row = row, .col = target_col }); + // extend mode never walks onto the empty trailing line (helix) + if (t.select and target == text.len and text.len > 0 and text[text.len - 1] == '\n') return; + setRange(t, text, 0, modal.moveSelectionCursor(text, range, target, t.select), false); + t.sticky_col = @intCast(goal); +} + +/// Ctrl-d/u: scroll half a page AND move the cursor by the same rows +pub fn halfPageMove(t: *Text, text: []const u8, range: modal.Selection, down: bool) void { + const half: i32 = @max(1, @divTrunc(@as(i32, t.pane().rows), 2)); + t.pane().scrollBy(if (down) half else -half); + verticalMove(t, text, range, down, @intCast(half)); +} + +/// helix `scroll` without cursor sync (Ctrl-f/b, PgUp/PgDn, zj/zk): shift +/// the view, then snap a fallen-out cursor to the near scrolloff edge, col 0 +pub fn scrollViewMove(t: *Text, text: []const u8, range: modal.Selection, delta: i32) void { + const margin: i32 = @min(config.scroll_off, @divTrunc(@as(i32, t.pane().rows) - 1, 2)); + t.pane().scrollBy(delta); + const top = t.pane().scroll(); + const last_row: i32 = @intCast(File.textLineCount(t, text) - 1); + const cur = modal.selectionCursor(text, range); + if (delta > 0) { + const snap: i32 = @max(0, @min(top + margin, last_row)); + const head = File.textLineStart(t, text, @intCast(snap)); + if (head <= cur) return; + const anchor = if (t.select) range.anchor else head; + setRange(t, text, 0, .{ .anchor = anchor, .head = head }, false); + } else { + const snap: i32 = @max(0, @min(top + @as(i32, t.pane().rows) - margin - 1, last_row)); + const head = File.textLineStart(t, text, @intCast(snap)); + if (head >= cur) return; + const anchor = if (t.select) range.anchor else head; + setRange(t, text, 0, .{ .anchor = anchor, .head = head }, false); + } +} + +/// gt/gc/gb: view-relative rows, col 0, scrolloff clamped (helix goto_window) +pub fn gotoWindow(t: *Text, text: []const u8, range: modal.Selection, which: enum { top, center, bottom }, cnt: usize) void { + const margin: i32 = @min(config.scroll_off, @divTrunc(@as(i32, t.pane().rows) - 1, 2)); + const top = t.pane().scroll(); + const last_row: i32 = @intCast(File.textLineCount(t, text) - 1); + const last_vis: i32 = @min(@as(i32, t.pane().rows) - 1, last_row - top); + const n: i32 = @intCast(cnt - 1); + var vline: i32 = switch (which) { + .top => top + margin + n, + .center => top + @divTrunc(last_vis, 2), + .bottom => top + last_vis - (margin + n), + }; + vline = @max(vline, top + margin); + vline = @min(vline, top + last_vis - margin); + const row: i32 = std.math.clamp(vline, 0, last_row); + pointMove(t, text, range, File.textLineStart(t, text, @intCast(row))); +} + +/// helix Range::line_range — the inclusive line span a range covers +pub fn rangeLineSpan(text: []const u8, r: modal.Selection) struct { start: usize, end: usize } { + const from = @min(r.anchor, r.head); + const to = @max(r.anchor, r.head); + const to_adj = if (from == to) to else @max(modal.prevGrapheme(text, to), from); + return .{ .start = modal.lineAtOffset(text, from), .end = modal.lineAtOffset(text, to_adj) }; +} + +fn lineStartOrEof(text: []const u8, line: usize) usize { + if (line >= modal.cursorLineCount(text)) return text.len; + return modal.lineStartOffset(text, line); +} + +/// helix `x` extend_line_below: full lines incl. the newline, cursor ON +/// the last one's '\n'; an already-line-bounded selection grows downward +pub fn lineSelect(t: *Text, text: []const u8, range: modal.Selection, cnt: usize) void { + const span = rangeLineSpan(text, range); + const start = modal.lineStartOffset(text, span.start); + const end = lineStartOrEof(text, span.end + 1); + const full = @min(range.anchor, range.head) == start and @max(range.anchor, range.head) == end; + const head = lineStartOrEof(text, span.end + cnt + @intFromBool(full)); + setRange(t, text, 0, .{ .anchor = start, .head = head }, true); +} + +/// helix `X` extend_to_line_bounds (direction kept) +pub fn lineBoundsSelect(t: *Text, text: []const u8, range: modal.Selection) void { + const span = rangeLineSpan(text, range); + const start = modal.lineStartOffset(text, span.start); + const end = lineStartOrEof(text, span.end + 1); + const r: modal.Selection = if (range.head < range.anchor) + .{ .anchor = end, .head = start } + else + .{ .anchor = start, .head = end }; + setRange(t, text, 0, r, true); +} + +/// helix `Alt-x` shrink_to_line_bounds (single-line selections untouched) +pub fn shrinkSelToLineBounds(t: *Text, text: []const u8, range: modal.Selection) void { + const span = rangeLineSpan(text, range); + if (span.start == span.end) return; + const from = @min(range.anchor, range.head); + const to = @max(range.anchor, range.head); + var start = modal.lineStartOffset(text, span.start); + var end = lineStartOrEof(text, span.end + 1); + if (start != from) start = lineStartOrEof(text, span.start + 1); + if (end != to) end = modal.lineStartOffset(text, span.end); + const expl = (t.vsel.active and t.vsel.explicit) or t.msel.active; + const r: modal.Selection = if (range.head < range.anchor) + .{ .anchor = end, .head = start } + else + .{ .anchor = start, .head = end }; + setRange(t, text, 0, r, expl); +} + +/// pull the cursor back inside `text` after a rewrite; `row0` is the +/// absolute surface row of its first line (0 for a file) +pub fn clampCursor(t: *Text, text: []const u8, row0: i32) void { + const n = modal.lineCount(text); + const row: usize = @min(@as(usize, @intCast(@max(0, t.cur_row - row0))), if (n == 0) 0 else n - 1); + const llen = modal.lineSlice(text, row).len; + t.cur_row = @as(i32, @intCast(row)) + row0; + t.cur_col = @intCast(@min(@as(usize, @intCast(@max(0, t.cur_col))), llen)); + t.cur_pinned = true; + t.vsel.active = false; + t.msel.active = false; + t.pane().ensureCursorVisible(); +} diff --git a/src/body_layer.zig b/src/body_layer.zig index 6bac7018..71529326 100644 --- a/src/body_layer.zig +++ b/src/body_layer.zig @@ -132,7 +132,7 @@ test "compact context borders separate source gaps and preserve multiline header fn paintTerminalSelection(p: *Pardes, pane: *Pane, r: Rect, rows: []const Pane.PointerRow, bg: [3]u8, fg: ?[3]u8) void { const body = bodyText(p, p.scratch.allocator(), pane) catch return; - const raw = pane.mode == .tty; + const raw = pane.body.mode == .tty; const tx = r.x + config.GUTTER; const width = r.w -| config.GUTTER; const body_y = p.bodyTop(r); @@ -366,14 +366,14 @@ pub fn renderBody(p: *Pardes, arena: std.mem.Allocator, pane: *Pane, r: Rect, id paintPointerSelection(p, pane, r, tx, tw, tag_y, body_y, sl, sel_btn[b], th.sel_fg); } // modal line selection (helix `x`): whole body rows, normal mode only - if ((pane.mode == .normal or modal_hover) and pane.msel.active) { - const hover_only = modal_hover and pane.mode != .normal; + if ((pane.body.mode == .normal or modal_hover) and pane.body.msel.active) { + const hover_only = modal_hover and pane.body.mode != .normal; const modal_bg = if (hover_only) colors.mix(page_rgb, colors.mix(page_rgb, th.sel_bg)) else th.sel_bg; - const lo = @min(pane.msel.r0, pane.msel.r1); - const hi = @max(pane.msel.r0, pane.msel.r1); + const lo = @min(pane.body.msel.r0, pane.body.msel.r1); + const hi = @max(pane.body.msel.r0, pane.body.msel.r1); var row: u16 = BOX_H; // never paint the tag row while (row < body_bottom) : (row += 1) { const ar = pane.wrapAt(@as(i32, row) - @as(i32, BOX_H)).line; @@ -388,23 +388,23 @@ pub fn renderBody(p: *Pardes, arena: std.mem.Allocator, pane: *Pane, r: Rect, id } } const preview = normal.selRegexArmed(pane) != null; - const show_prim = (pane.mode == .normal and pane.vsel.active) or preview or - (modal_hover and pane.vsel.active); - const show_extra = pane.mode != .tty and pane.nsel > 0; + const show_prim = (pane.body.mode == .normal and pane.body.vsel.active) or preview or + (modal_hover and pane.body.vsel.active); + const show_extra = pane.body.mode != .tty and pane.body.nsel > 0; if (show_prim or show_extra) { const vpfx: i32 = if (pane.file != null) panes.File.gutterWidth(pane) else 0; var si: usize = 0; - while (si <= pane.nsel) : (si += 1) { - const primary = si == pane.nsel; + while (si <= pane.body.nsel) : (si += 1) { + const primary = si == pane.body.nsel; if (if (primary) !show_prim else !show_extra) continue; - const sr = if (primary) Pane.SelRange{ - .row = pane.cur_row, - .col = pane.cur_col, - .arow = if (pane.vsel.active) pane.vsel.row else pane.cur_row, - .acol = if (pane.vsel.active) pane.vsel.col else pane.cur_col, - } else pane.sels[si]; + const sr = if (primary) panes.Text.SelRange{ + .row = pane.body.cur_row, + .col = pane.body.cur_col, + .arow = if (pane.body.vsel.active) pane.body.vsel.row else pane.body.cur_row, + .acol = if (pane.body.vsel.active) pane.body.vsel.col else pane.body.cur_col, + } else pane.body.sels[si]; const bnd = edit.cellBounds(sr); - const hover_only = primary and modal_hover and pane.mode != .normal and !preview; + const hover_only = primary and modal_hover and pane.body.mode != .normal and !preview; const bg = if (hover_only) colors.mix(page_rgb, colors.mix(page_rgb, th.sel_bg)) else if (primary) @@ -462,18 +462,18 @@ pub fn renderBody(p: *Pardes, arena: std.mem.Allocator, pane: *Pane, r: Rect, id // cursor: tracks the shell cursor until pinned by a click or a key // (the tag cursor above wins while the tag is focused) if (active and !pane.tag_edit) { - if (pane.mode != .tty) { + if (pane.body.mode != .tty) { const cur = panes.Terminal.gridCursor(pane); const goff = panes.Terminal.gridOffset(pane); - const crow = if (pane.cur_pinned) pane.cur_row else pane.surfRow(@as(i32, @intCast(cur.y)) + goff); - const ccol = if (pane.cur_pinned) pane.cur_col else @as(i32, @intCast(cur.x)); + const crow = if (pane.body.cur_pinned) pane.body.cur_row else pane.surfRow(@as(i32, @intCast(cur.y)) + goff); + const ccol = if (pane.body.cur_pinned) pane.body.cur_col else @as(i32, @intCast(cur.x)); const cwp = pane.wrapRow(crow, ccol); const prow = cwp.row + @as(i32, BOX_H); // Files store source-byte columns; the Surface stores display // cells, so account for every expanded tab before the cursor. const cx = if (pane.file != null) @as(i32, panes.File.gutterWidth(pane)) + panes.File.displayOffset(pane, crow, cwp.at, ccol) - else if (pane.cur_pinned) + else if (pane.body.cur_pinned) panes.File.lineDisplayOffset( modal.lineSlice(body, @intCast(@max(0, cwp.row))), @intCast(@max(0, cwp.at)), @@ -482,7 +482,7 @@ pub fn renderBody(p: *Pardes, arena: std.mem.Allocator, pane: *Pane, r: Rect, id else ccol; if (prow >= BOX_H and cx >= 0 and prow < body_bottom and cx < tw) - s.cursor = .{ .x = tx + @as(u16, @intCast(cx)), .y = body_y + @as(u16, @intCast(prow - BOX_H)), .bar = pane.mode == .insert }; + s.cursor = .{ .x = tx + @as(u16, @intCast(cx)), .y = body_y + @as(u16, @intCast(prow - BOX_H)), .bar = pane.body.mode == .insert }; } else if (panes.Terminal.visibleCursor(pane)) |cur| { if (cur.y + BOX_H < body_bottom and cur.x < tw) s.cursor = .{ .x = tx + cur.x, .y = body_y + cur.y }; diff --git a/src/colors.zig b/src/colors.zig index d6e1d535..741187c6 100644 --- a/src/colors.zig +++ b/src/colors.zig @@ -572,8 +572,8 @@ test "line numbers stay quiet without a current-line tag background" { const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 80, .rows = 24 }); defer p.deinit(); const pane = try p.setTestFile("first\nsecond\n"); - pane.cur_pinned = true; - pane.cur_row = 0; + pane.body.cur_pinned = true; + pane.body.cur_row = 0; var custom = themes[0]; custom.name = try gpa.dupe(u8, "quiet-gutter"); custom.lineno = .{ 70, 70, 70 }; @@ -598,7 +598,7 @@ test "line numbers stay quiet without a current-line tag background" { try std.testing.expectEqual(Color{ .rgb = custom.bg.? }, fallback.at(x, y).style.bg); try std.testing.expect(fallback.at(x, y).style.bold); // Moving the caret clears the previous cue; editing the tag parks it. - pane.cur_row = 1; + pane.body.cur_row = 1; const moved = try p.render(p.scratch.allocator()); try std.testing.expect(!moved.at(x, y).style.bold); try std.testing.expect(moved.at(x, y + 1).style.bold); diff --git a/src/config.zig b/src/config.zig index 4b47b188..38b87011 100644 --- a/src/config.zig +++ b/src/config.zig @@ -173,16 +173,16 @@ test "Space-k is unbound while Kill and other k chords remain available" { const p = try pardes.Pardes.init(std.testing.allocator, .{ .tty_only = true }); defer p.deinit(); const pane = try p.setTestFile("first\nsecond\n"); - pane.cur_row = 1; + pane.body.cur_row = 1; while (p.nextEffect()) |_| {} p.update(.{ .key = .{ .cp = ' ' } }); try std.testing.expect(p.leader_on); p.update(.{ .key = .{ .cp = 'k' } }); try std.testing.expect(!p.leader_on and !p.quit); - try std.testing.expectEqual(@as(i32, 1), pane.cur_row); + try std.testing.expectEqual(@as(i32, 1), pane.body.cur_row); while (p.nextEffect()) |effect| try std.testing.expect(effect != .quit); p.update(.{ .key = .{ .cp = 'k' } }); - try std.testing.expectEqual(@as(i32, 0), pane.cur_row); + try std.testing.expectEqual(@as(i32, 0), pane.body.cur_row); try std.testing.expect(p.executeBuiltinLine(p.active, "Kill")); try std.testing.expect(p.quit); } diff --git a/src/detached/client.zig b/src/detached/client.zig index 6476d521..4468c961 100644 --- a/src/detached/client.zig +++ b/src/detached/client.zig @@ -868,9 +868,9 @@ test "detached selection pipe runs off the loop and returns through the attached try h.init(60, 16); defer h.deinit(); const pane = try h.core.setTestFile("one\ntwo\n"); - pane.cur_row = 0; - pane.cur_col = 2; - pane.vsel = .{ .active = true, .row = 0, .col = 0, .explicit = true }; + pane.body.cur_row = 0; + pane.body.cur_col = 2; + pane.body.vsel = .{ .active = true, .row = 0, .col = 0, .explicit = true }; var client = try h.attach(60, 16); defer client.deinit(); _ = try h.pumpUntil(&client, .frame); diff --git a/src/detached/server.zig b/src/detached/server.zig index 2b9c9247..a3694c57 100644 --- a/src/detached/server.zig +++ b/src/detached/server.zig @@ -1251,8 +1251,8 @@ test "detached worker setup failure completes requests without changing document try std.testing.expect(s.core.lsp_wait == null); try std.testing.expect(s.lsp_task == null); - pane.cur_col = 2; - pane.vsel = .{ .active = true, .row = 0, .col = 0, .explicit = true }; + pane.body.cur_col = 2; + pane.body.vsel = .{ .active = true, .row = 0, .col = 0, .explicit = true }; s.core.update(.{ .key = .{ .cp = '|' } }); s.core.update(.{ .key = .{ .cp = 't', .text = "tr a-z A-Z" } }); s.core.update(.{ .key = .{ .cp = pardes.Key.enter } }); diff --git a/src/dump.zig b/src/dump.zig index 46cf6001..2fb9ce80 100644 --- a/src/dump.zig +++ b/src/dump.zig @@ -740,7 +740,7 @@ fn initDump(gpa: std.mem.Allocator, opts: Options, zon_bytes: []const u8, previo const restored = try pardes.panes.Terminal.restore(p, src, revive); p.installPane(i, restored); try restored.setOwnedCwd(t.cwd); - if (std.mem.startsWith(u8, src.tag, "TTY ")) restored.mode = .tty; + if (std.mem.startsWith(u8, src.tag, "TTY ")) restored.body.mode = .tty; if (revive) p.emit(.{ .spawn = .{ .pane = @intCast(i), .cwd = .from(t.cwd) } }); break :terminal restored; }, @@ -773,7 +773,7 @@ fn initDump(gpa: std.mem.Allocator, opts: Options, zon_bytes: []const u8, previo errdefer gpa.destroy(history); const restored = try p.newDocPane(i); restored.file = .{ .path = path, .content = content, .history = history }; - restored.cur_pinned = true; + restored.body.cur_pinned = true; restored.cols = @max(1, src.cols); restored.rows = @max(1, src.rows); p.emit(.{ .watch = .{ .pane = @intCast(i), .on = true, .mode = .baseline_disk } }); diff --git a/src/edit.zig b/src/edit.zig index 04416b67..f1b381d6 100644 --- a/src/edit.zig +++ b/src/edit.zig @@ -14,6 +14,7 @@ const pdf_enabled = panes.Pdf.enabled; const lsp = @import("lsp/lsp.zig"); const platform = pardes.platform; const Pane = panes.Pane; +const Text = panes.Text; const TagHit = @import("tag_layer.zig").Hit; const BOX_H = pardes.BOX_H; const TAG_TEXT_INSET = pardes.TAG_TEXT_INSET; @@ -91,11 +92,11 @@ pub fn applyPaste(p: *Pardes, bytes: []const u8) void { if (normal.selRegexArmed(pane)) |a| normal.applySelRegex(p, pane, a.pat, a.split); return; } - if (pane.isTerminal() and pane.mode == .tty) return typeToTty(p, id, pane, bytes); + if (pane.isTerminal() and pane.body.mode == .tty) return typeToTty(p, id, pane, bytes); switch (if (req) |r| r.mode else .after) { - .after => pasteText(p, pane, bytes, false, 1), - .before => pasteText(p, pane, bytes, true, 1), - .replace => replaceWithText(p, pane, bytes), + .after => pasteText(p, &pane.body, bytes, false, 1), + .before => pasteText(p, &pane.body, bytes, true, 1), + .replace => replaceWithText(p, &pane.body, bytes), } } @@ -104,13 +105,13 @@ pub fn clipYank(p: *Pardes, pane: *Pane, main_only: bool) void { if (pv.selection_text.len > 0) setClipboard(p, pv.selection_text); return; }; - if (pane.nsel > 0 and !main_only) { - normal.replaySels(p, pane, .{ .normal = .{ .edit = .{ .kind = .yank, .count = 1 } } }); + if (pane.body.nsel > 0 and !main_only) { + normal.replaySels(p, &pane.body, .{ .normal = .{ .edit = .{ .kind = .yank, .count = 1 } } }); } else { - const others = pane.nsel; - pane.nsel = 0; - normalYank(p, pane); - pane.nsel = others; + const others = pane.body.nsel; + pane.body.nsel = 0; + normalYank(p, &pane.body); + pane.body.nsel = others; } p.emit(.{ .set_clipboard = {} }); } @@ -135,7 +136,7 @@ pub fn capturePointerSelection(p: *Pardes, pane: *Pane, slot: usize) !void { if (pane.pointerSelection(gesture) != null) return; pane.clearPointerSelection(slot); // Refresh the source map before translating the rendered rectangle. - const raw = pane.isTerminal() and pane.mode == .tty; + const raw = pane.isTerminal() and pane.body.mode == .tty; const body = try body_layer.bodyText(p, p.scratch.allocator(), pane); const terminal_lines = if (pane.file == null and !raw) try panes.Terminal.cursorLines(p, pane) else &.{}; const first = @max(0, @min(gesture.r0, gesture.r1) - BOX_H); @@ -253,28 +254,28 @@ pub fn spanHas(r: i32, c: i32, ar: i32, ac: i32, br: i32, bc: i32) bool { pub fn currentSelText(p: *Pardes, pane: *Pane) ?[]const u8 { if (comptime pdf_enabled) if (p.native_images) if (pane.pdf) |pv| if (pv.selection != null and pv.selection_text.len > 0) return pv.selection_text; - if (pane.vsel.active) return vselText(p, pane); - if (!pane.msel.active) return null; - return yankRows(p, pane, @min(pane.msel.r0, pane.msel.r1), @max(pane.msel.r0, pane.msel.r1)); + if (pane.body.vsel.active) return vselText(p, &pane.body); + if (!pane.body.msel.active) return null; + return yankRows(p, &pane.body, @min(pane.body.msel.r0, pane.body.msel.r1), @max(pane.body.msel.r0, pane.body.msel.r1)); } -pub fn exitInsert(p: *Pardes, pane: *Pane) void { - pane.mode = .normal; - pane.msel.active = false; - pane.normal.clear(); - if (pane.append_at) |aa| { - pane.append_at = null; - const text = flatSurface(p, pane) catch return; - const gap = modal.offsetAt(text, .{ .row = @intCast(@max(0, pane.cur_row)), .col = @intCast(@max(0, pane.cur_col)) }); +pub fn exitInsert(p: *Pardes, t: *Text) void { + t.mode = .normal; + t.msel.active = false; + t.normal.clear(); + if (t.append_at) |aa| { + t.append_at = null; + const text = flatSurface(p, t) catch return; + const gap = modal.offsetAt(text, .{ .row = @intCast(@max(0, t.cur_row)), .col = @intCast(@max(0, t.cur_col)) }); const a_off = modal.offsetAt(text, .{ .row = @intCast(@max(0, aa.row)), .col = @intCast(@max(0, aa.col)) }); const back = @max(a_off, modal.prevGrapheme(text, gap)); const bc = modal.positionAt(text, back); - pane.cur_row = @intCast(bc.row); - pane.cur_col = @intCast(bc.col); - pane.vsel = .{ .active = a_off != back, .row = aa.row, .col = aa.col, .explicit = false }; - pane.cur_pinned = true; - pane.ensureCursorVisible(); - for (pane.sels[0..pane.nsel]) |*s| { + t.cur_row = @intCast(bc.row); + t.cur_col = @intCast(bc.col); + t.vsel = .{ .active = a_off != back, .row = aa.row, .col = aa.col, .explicit = false }; + t.cur_pinned = true; + t.pane().ensureCursorVisible(); + for (t.sels[0..t.nsel]) |*s| { const sgap = modal.offsetAt(text, .{ .row = @intCast(@max(0, s.row)), .col = @intCast(@max(0, s.col)) }); const b2 = if (back == gap) sgap else modal.prevGrapheme(text, sgap); const bp = modal.positionAt(text, b2); @@ -286,7 +287,8 @@ pub fn exitInsert(p: *Pardes, pane: *Pane) void { } } -pub fn paneCursorLines(p: *Pardes, pane: *Pane) ![]const []const u8 { +pub fn paneCursorLines(p: *Pardes, t: *Text) ![]const []const u8 { + const pane = t.pane(); const arena = p.scratch.allocator(); if (pane.file) |*f| return panes.File.cursorLines(arena, pane, f); if (pane.hasPdf()) { @@ -296,10 +298,11 @@ pub fn paneCursorLines(p: *Pardes, pane: *Pane) ![]const []const u8 { return panes.Terminal.cursorLines(p, pane); } -pub fn paneByteAtDisplay(p: *Pardes, pane: *Pane, row: i32, from_raw: i32, display_col: i32) i32 { +pub fn paneByteAtDisplay(p: *Pardes, t: *Text, row: i32, from_raw: i32, display_col: i32) i32 { + const pane = t.pane(); if (pane.file != null) return panes.File.byteAtRowDisplay(pane, row, from_raw, display_col); - const lines = paneCursorLines(p, pane) catch return @max(0, from_raw + display_col); + const lines = paneCursorLines(p, t) catch return @max(0, from_raw + display_col); const local = row; if (local < 0 or @as(usize, @intCast(local)) >= lines.len) return @max(0, from_raw + display_col); @@ -312,14 +315,16 @@ pub fn paneByteAtDisplay(p: *Pardes, pane: *Pane, row: i32, from_raw: i32, displ /// Freeze the live terminal cursor into the modal coordinate space. The /// emulator reports screen cells; editing state stores UTF-8 byte offsets. -pub fn pinPaneCursor(p: *Pardes, pane: *Pane) void { - if (pane.cur_pinned) return; +pub fn pinPaneCursor(p: *Pardes, t: *Text) void { + const pane = t.pane(); + if (t.cur_pinned) return; pane.pinCursor(); if (pane.file == null and !pane.hasPdf()) - pane.cur_col = paneByteAtDisplay(p, pane, pane.cur_row, 0, pane.cur_col); + t.cur_col = paneByteAtDisplay(p, t, t.cur_row, 0, t.cur_col); } -pub fn flatSurface(p: *Pardes, pane: *Pane) ![]const u8 { +pub fn flatSurface(p: *Pardes, t: *Text) ![]const u8 { + const pane = t.pane(); if (pane.file) |f| return f.content; if (pane.hasPdf()) { if (comptime pdf_enabled) return pane.pdf.?.ensureText(p.pdf_gpa); @@ -329,28 +334,31 @@ pub fn flatSurface(p: *Pardes, pane: *Pane) ![]const u8 { return panes.Terminal.flatSurface(p, pane, lines); } -pub fn paneWrapWidth(p: *const Pardes, pane: *const Pane) usize { +pub fn paneWrapWidth(p: *const Pardes, t: *Text) usize { + const pane = t.pane(); if (pane.file == null) return 0; return panes.File.wrapWidth(pane, p.settings.wrap); } /// Route shared edit operations to a file's content or a terminal overlay. -fn editText(p: *Pardes, pane: *Pane, lo: i32, hi: i32, col: i32) ?panes.EditText { +fn editText(p: *Pardes, t: *Text, lo: i32, hi: i32, col: i32) ?panes.EditText { + const pane = t.pane(); if (pane.file) |f| return .{ .text = f.content, .row0 = 0 }; if (pane.image != null or pane.hasPdf()) return null; return panes.Terminal.editText(p, pane, lo, hi, col); } -fn editTextEol(p: *Pardes, pane: *Pane, b: Bounds) ?panes.EditText { - const eb = editText(p, pane, b.lo_row, b.hi_row, -1) orelse return null; +fn editTextEol(p: *Pardes, t: *Text, b: Bounds) ?panes.EditText { + const eb = editText(p, t, b.lo_row, b.hi_row, -1) orelse return null; const r: usize = @intCast(@max(0, b.hi_row - eb.row0)); if (r + 1 < modal.lineCount(eb.text)) return eb; if (b.hi_col < @as(i32, @intCast(modal.lineSlice(eb.text, r).len))) return eb; - return editText(p, pane, b.lo_row, b.hi_row + 1, -1); + return editText(p, t, b.lo_row, b.hi_row + 1, -1); } /// install a rewritten editable text (frees the old one) -fn setEditText(p: *Pardes, pane: *Pane, new: []u8) void { +fn setEditText(p: *Pardes, t: *Text, new: []u8) void { + const pane = t.pane(); if (pane.file) |*f| return panes.File.setContent(p, f, new); panes.Terminal.setEditText(p, pane, new); } @@ -359,73 +367,75 @@ pub const InsertAt = enum { at, append, line_start, line_end, open_below, open_a /// Files insert only inside existing rows and at grapheme boundaries. /// Terminal overlays can materialize virtual rows/columns, so keep those. -pub fn clampFileCursor(pane: *Pane) bool { +pub fn clampFileCursor(t: *Text) bool { + const pane = t.pane(); const file = if (pane.file) |*file| file else return false; - const old_row = pane.cur_row; - const old_col = pane.cur_col; + const old_row = t.cur_row; + const old_col = t.cur_col; const last = panes.File.nlines(pane.gpa, file) -| 1; - pane.cur_row = @intCast(@min(last, @as(usize, @intCast(@max(0, pane.cur_row))))); - const line = panes.File.sourceLine(pane, pane.cur_row); - pane.cur_col = @intCast(modal.graphemeStart(line, @min(line.len, @as(usize, @intCast(@max(0, pane.cur_col)))))); - return old_row != pane.cur_row or old_col != pane.cur_col; + t.cur_row = @intCast(@min(last, @as(usize, @intCast(@max(0, t.cur_row))))); + const line = panes.File.sourceLine(pane, t.cur_row); + t.cur_col = @intCast(modal.graphemeStart(line, @min(line.len, @as(usize, @intCast(@max(0, t.cur_col)))))); + return old_row != t.cur_row or old_col != t.cur_col; } -pub fn enterInsert(p: *Pardes, pane: *Pane, where: InsertAt, cnt: usize) void { +pub fn enterInsert(p: *Pardes, t: *Text, where: InsertAt, cnt: usize) void { + const pane = t.pane(); if (pane.hasPdf()) return; - pinPaneCursor(p, pane); - _ = clampFileCursor(pane); + pinPaneCursor(p, t); + _ = clampFileCursor(t); // snapshot once per insert session (WITH the pre-insert selection) so // `u` undoes the whole session and restores what was selected - pushUndo(p, pane); - pane.select = false; - pane.append_at = null; - pane.sticky_col = -1; - const text = flatSurface(p, pane) catch { - pane.mode = .insert; - pane.msel.active = false; - pane.vsel.active = false; - pane.normal.clear(); + pushUndo(p, t); + t.select = false; + t.append_at = null; + t.sticky_col = -1; + const text = flatSurface(p, t) catch { + t.mode = .insert; + t.msel.active = false; + t.vsel.active = false; + t.normal.clear(); return; }; - const cur = pane.toModalCursor(); - const line = panes.File.textLine(pane, text, cur.row); - const b: ?Bounds = if (pane.vsel.active) vselBounds(pane) else null; + const cur = t.toModalCursor(); + const line = panes.File.textLine(t, text, cur.row); + const b: ?Bounds = if (t.vsel.active) vselBounds(t) else null; switch (where) { .at => { if (b) |bb| { - pane.cur_row = bb.lo_row; - pane.cur_col = bb.lo_col; - pane.vsel = .{ .active = true, .row = bb.hi_row, .col = bb.hi_col, .explicit = false }; - pane.cur_pinned = true; + t.cur_row = bb.lo_row; + t.cur_col = bb.lo_col; + t.vsel = .{ .active = true, .row = bb.hi_row, .col = bb.hi_col, .explicit = false }; + t.cur_pinned = true; } }, .append => { - const lo_row = if (b) |bb| bb.lo_row else pane.cur_row; - const lo_col = if (b) |bb| bb.lo_col else pane.cur_col; - const hi_row = if (b) |bb| bb.hi_row else pane.cur_row; - const hi_col = if (b) |bb| bb.hi_col else pane.cur_col; - pane.append_at = .{ .row = lo_row, .col = lo_col }; + const lo_row = if (b) |bb| bb.lo_row else t.cur_row; + const lo_col = if (b) |bb| bb.lo_col else t.cur_col; + const hi_row = if (b) |bb| bb.hi_row else t.cur_row; + const hi_col = if (b) |bb| bb.hi_col else t.cur_col; + t.append_at = .{ .row = lo_row, .col = lo_col }; const gap = modal.nextGrapheme(text, modal.offsetAt(text, .{ .row = @intCast(@max(0, hi_row)), .col = @intCast(@max(0, hi_col)) })); const gc = modal.positionAt(text, gap); - pane.cur_row = @intCast(gc.row); - pane.cur_col = @intCast(gc.col); - pane.vsel = .{ .active = b != null, .row = lo_row, .col = lo_col, .explicit = false }; - pane.cur_pinned = true; + t.cur_row = @intCast(gc.row); + t.cur_col = @intCast(gc.col); + t.vsel = .{ .active = b != null, .row = lo_row, .col = lo_col, .explicit = false }; + t.cur_pinned = true; }, .line_start => { - pane.fromModalCursor(.{ .row = cur.row, .col = modal.firstNonWs(line) }); - pane.vsel.active = false; + t.fromModalCursor(.{ .row = cur.row, .col = modal.firstNonWs(line) }); + t.vsel.active = false; }, .line_end => { - pane.cur_col = @intCast(line.len); - pane.cur_pinned = true; - pane.vsel.active = false; + t.cur_col = @intCast(line.len); + t.cur_pinned = true; + t.vsel.active = false; }, .open_below, .open_above => { - pane.vsel.active = false; + t.vsel.active = false; const below = where == .open_below; - const abs: i32 = if (b) |bb| (if (below) bb.hi_row else bb.lo_row) else pane.cur_row; - const eb = editText(p, pane, abs, abs, -1) orelse return; + const abs: i32 = if (b) |bb| (if (below) bb.hi_row else bb.lo_row) else t.cur_row; + const eb = editText(p, t, abs, abs, -1) orelse return; const row: usize = @intCast(@max(0, abs - eb.row0)); const ind = modal.indentText(modal.lineSlice(eb.text, row)); const arena = p.scratch.allocator(); @@ -449,146 +459,147 @@ pub fn enterInsert(p: *Pardes, pane: *Pane, where: InsertAt, cnt: usize) void { else .{ .row = row, .col = 0 }; const new = modal.insertAt(p.gpa, eb.text, at, block) catch return; - setEditText(p, pane, new); - pane.cur_row = @as(i32, @intCast(if (below) row + 1 else row)) + eb.row0; - pane.cur_col = @intCast(ind.len); - pane.cur_pinned = true; + setEditText(p, t, new); + t.cur_row = @as(i32, @intCast(if (below) row + 1 else row)) + eb.row0; + t.cur_col = @intCast(ind.len); + t.cur_pinned = true; if (cnt > 1 and !p.multi_on) opened: { - const t2 = flatSurface(p, pane) catch break :opened; - var rs: [Pane.max_selections]modal.Selection = undefined; - const m = @min(cnt, Pane.max_selections); + const t2 = flatSurface(p, t) catch break :opened; + var rs: [Text.max_selections]modal.Selection = undefined; + const m = @min(cnt, Text.max_selections); for (0..m) |k| { - const o = modal.offsetAt(t2, .{ .row = @intCast(@max(0, pane.cur_row) + @as(i32, @intCast(k))), .col = ind.len }); + const o = modal.offsetAt(t2, .{ .row = @intCast(@max(0, t.cur_row) + @as(i32, @intCast(k))), .col = ind.len }); rs[k] = .{ .anchor = o, .head = o }; } - pane.setRanges(t2, rs[0..m], &.{}, 0, false); + t.setRanges(t2, rs[0..m], &.{}, 0, false); } }, } - pane.mode = .insert; - pane.msel.active = false; - pane.normal.clear(); + t.mode = .insert; + t.msel.active = false; + t.normal.clear(); pane.ensureCursorVisible(); } -pub fn handleInsert(p: *Pardes, pane: *Pane, key: Key) void { - if (pane.nsel == 0) return insertKey(p, pane, key); - normal.replaySels(p, pane, .{ .insert = key }); +pub fn handleInsert(p: *Pardes, t: *Text, key: Key) void { + if (t.nsel == 0) return insertKey(p, t, key); + normal.replaySels(p, t, .{ .insert = key }); } -pub fn insertKey(p: *Pardes, pane: *Pane, key: Key) void { +pub fn insertKey(p: *Pardes, t: *Text, key: Key) void { + const pane = t.pane(); // helix aliases: normalize to the base key and re-dispatch - if (hit(key, config.insert_backspace_alias)) return insertKey(p, pane, .{ .cp = Key.backspace }); - if (hit(key, config.insert_enter_alias)) return insertKey(p, pane, .{ .cp = Key.enter }); - if (hit(key, config.insert_delete_alias)) return insertKey(p, pane, .{ .cp = Key.delete }); - pane.vsel.active = false; - if (!pane.cur_pinned) pinPaneCursor(p, pane); - _ = clampFileCursor(pane); + if (hit(key, config.insert_backspace_alias)) return insertKey(p, t, .{ .cp = Key.backspace }); + if (hit(key, config.insert_enter_alias)) return insertKey(p, t, .{ .cp = Key.enter }); + if (hit(key, config.insert_delete_alias)) return insertKey(p, t, .{ .cp = Key.delete }); + t.vsel.active = false; + if (!t.cur_pinned) pinPaneCursor(p, t); + _ = clampFileCursor(t); switch (key.cp) { Key.left, Key.right, Key.up, Key.down => { - const lines = paneCursorLines(p, pane) catch return; - const cur0 = pane.toModalCursor(); + const lines = paneCursorLines(p, t) catch return; + const cur0 = t.toModalCursor(); const nc = switch (key.cp) { Key.left => modal.charLeft(lines, cur0), Key.right => modal.charRight(lines, cur0), - Key.up => Pane.insertVerticalCursor(lines, cur0, false), - Key.down => Pane.insertVerticalCursor(lines, cur0, true), + Key.up => Text.insertVerticalCursor(lines, cur0, false), + Key.down => Text.insertVerticalCursor(lines, cur0, true), else => cur0, }; - pane.fromModalCursor(nc); + t.fromModalCursor(nc); pane.ensureCursorVisible(); return; }, Key.page_up, Key.page_down => { // helix binds insert pageup/pagedown to the same view // scroll + cursor snap as normal mode - const flat = flatSurface(p, pane) catch return; - const range = pane.primaryRange(flat, 0); + const flat = flatSurface(p, t) catch return; + const range = t.primaryRange(flat, 0); const step: i32 = @intCast(@max(1, pane.rows)); - pane.scrollViewMove(flat, range, if (key.cp == Key.page_down) step else -step); + t.scrollViewMove(flat, range, if (key.cp == Key.page_down) step else -step); return; }, Key.home => { - pane.cur_col = 0; - pane.cur_pinned = true; + t.cur_col = 0; + t.cur_pinned = true; pane.ensureCursorVisible(); return; }, Key.end => { // helix insert End: past the last char (goto_line_end_newline) - const text = flatSurface(p, pane) catch return; - const cur0 = pane.toModalCursor(); - pane.cur_col = @intCast(panes.File.textLine(pane, text, cur0.row).len); - pane.cur_pinned = true; + const text = flatSurface(p, t) catch return; + const cur0 = t.toModalCursor(); + t.cur_col = @intCast(panes.File.textLine(t, text, cur0.row).len); + t.cur_pinned = true; pane.ensureCursorVisible(); return; }, else => {}, } - const eb = editText(p, pane, pane.cur_row, pane.cur_row, pane.cur_col) orelse return; + const eb = editText(p, t, t.cur_row, t.cur_row, t.cur_col) orelse return; const text = eb.text; - const c = modal.Cursor{ .row = @intCast(@max(0, pane.cur_row - eb.row0)), .col = @intCast(@max(0, pane.cur_col)) }; + const c = modal.Cursor{ .row = @intCast(@max(0, t.cur_row - eb.row0)), .col = @intCast(@max(0, t.cur_col)) }; if (key.text.len > 0 and !key.ctrl and !key.alt) { const new = modal.insertAt(p.gpa, text, c, key.text) catch return; - setEditText(p, pane, new); + setEditText(p, t, new); for (key.text) |ch| { if (ch == '\n') { - pane.cur_row += 1; - pane.cur_col = 0; - } else pane.cur_col += 1; + t.cur_row += 1; + t.cur_col = 0; + } else t.cur_col += 1; } - pane.cur_pinned = true; + t.cur_pinned = true; pane.ensureCursorVisible(); return; } // helix insert-mode kills (word/line; deleteSpan is exclusive) if (hit(key, config.delete_word_backward)) { const e2 = if (c.row == 0 and c.col == 0) - (editText(p, pane, pane.cur_row - 1, pane.cur_row, 0) orelse return) + (editText(p, t, t.cur_row - 1, t.cur_row, 0) orelse return) else eb; - const c2 = modal.Cursor{ .row = @intCast(@max(0, pane.cur_row - e2.row0)), .col = c.col }; + const c2 = modal.Cursor{ .row = @intCast(@max(0, t.cur_row - e2.row0)), .col = c.col }; const g = modal.offsetAt(e2.text, c2); if (g == 0) return; const wr = modal.moveWord(e2.text, .{ .anchor = g, .head = g }, 1, .prev_word_start); const from = @min(wr.anchor, wr.head); const fc = modal.positionAt(e2.text, from); const new = modal.deleteSpan(p.gpa, e2.text, fc, c2) catch return; - setEditText(p, pane, new); - pane.cur_row = @as(i32, @intCast(fc.row)) + e2.row0; - pane.cur_col = @intCast(fc.col); - pane.cur_pinned = true; + setEditText(p, t, new); + t.cur_row = @as(i32, @intCast(fc.row)) + e2.row0; + t.cur_col = @intCast(fc.col); + t.cur_pinned = true; pane.ensureCursorVisible(); return; } if (hit(key, config.delete_word_forward)) { const e2 = if (c.col >= modal.lineSlice(text, c.row).len and c.row + 1 >= modal.lineCount(text)) - (editText(p, pane, pane.cur_row, pane.cur_row + 1, pane.cur_col) orelse return) + (editText(p, t, t.cur_row, t.cur_row + 1, t.cur_col) orelse return) else eb; - const c2 = modal.Cursor{ .row = @intCast(@max(0, pane.cur_row - e2.row0)), .col = c.col }; + const c2 = modal.Cursor{ .row = @intCast(@max(0, t.cur_row - e2.row0)), .col = c.col }; const g = modal.offsetAt(e2.text, c2); const wr = modal.moveWord(e2.text, .{ .anchor = g, .head = g }, 1, .next_word_end); const to = @max(wr.anchor, wr.head); if (to <= g) return; const new = modal.deleteSpan(p.gpa, e2.text, c2, modal.positionAt(e2.text, to)) catch return; - setEditText(p, pane, new); - pane.cur_pinned = true; + setEditText(p, t, new); + t.cur_pinned = true; return; } if (hit(key, config.kill_to_line_start)) { const new = modal.deleteSpan(p.gpa, text, .{ .row = c.row, .col = 0 }, c) catch return; - setEditText(p, pane, new); - pane.cur_col = 0; - pane.cur_pinned = true; + setEditText(p, t, new); + t.cur_col = 0; + t.cur_pinned = true; pane.ensureCursorVisible(); return; } if (hit(key, config.kill_to_line_end)) { const llen = modal.lineSlice(text, c.row).len; const new = modal.deleteSpan(p.gpa, text, c, .{ .row = c.row, .col = llen }) catch return; - setEditText(p, pane, new); - pane.cur_pinned = true; + setEditText(p, t, new); + t.cur_pinned = true; return; } switch (key.cp) { @@ -600,35 +611,35 @@ pub fn insertKey(p: *Pardes, pane: *Pane, key: Key) void { block[0] = '\n'; @memset(block[1..], ' '); const new = modal.insertAt(p.gpa, text, c, block) catch return; - setEditText(p, pane, new); - pane.cur_row += 1; - pane.cur_col = @intCast(indent); - pane.cur_pinned = true; + setEditText(p, t, new); + t.cur_row += 1; + t.cur_col = @intCast(indent); + t.cur_pinned = true; pane.ensureCursorVisible(); }, Key.backspace => { - if (pane.cur_col > 0) { + if (t.cur_col > 0) { const line = modal.lineSlice(text, c.row); const prev = modal.prevGrapheme(line, c.col); const new = modal.deleteChar(p.gpa, text, .{ .row = c.row, .col = prev }) catch return; - setEditText(p, pane, new); - pane.cur_col = @intCast(prev); - pane.cur_pinned = true; + setEditText(p, t, new); + t.cur_col = @intCast(prev); + t.cur_pinned = true; pane.ensureCursorVisible(); return; } // at col 0: eat the newline above (join up) — a terminal grows // its buffer over the row it is joining with - if (pane.cur_row <= 0) return; - const e2 = editText(p, pane, pane.cur_row - 1, pane.cur_row, 0) orelse return; - const row: usize = @intCast(@max(0, pane.cur_row - e2.row0)); + if (t.cur_row <= 0) return; + const e2 = editText(p, t, t.cur_row - 1, t.cur_row, 0) orelse return; + const row: usize = @intCast(@max(0, t.cur_row - e2.row0)); if (row == 0) return; const prevlen = modal.lineSlice(e2.text, row - 1).len; const new = modal.deleteSpan(p.gpa, e2.text, .{ .row = row - 1, .col = prevlen }, .{ .row = row, .col = 0 }) catch return; - setEditText(p, pane, new); - pane.cur_row -= 1; - pane.cur_col = @intCast(prevlen); - pane.cur_pinned = true; + setEditText(p, t, new); + t.cur_row -= 1; + t.cur_col = @intCast(prevlen); + t.cur_pinned = true; pane.ensureCursorVisible(); }, Key.delete => { @@ -637,15 +648,15 @@ pub fn insertKey(p: *Pardes, pane: *Pane, key: Key) void { const line = modal.lineSlice(text, c.row); if (c.col < line.len) { const new = modal.deleteChar(p.gpa, text, c) catch return; - setEditText(p, pane, new); + setEditText(p, t, new); } else { - const e2 = editText(p, pane, pane.cur_row, pane.cur_row + 1, pane.cur_col) orelse return; - const row: usize = @intCast(@max(0, pane.cur_row - e2.row0)); + const e2 = editText(p, t, t.cur_row, t.cur_row + 1, t.cur_col) orelse return; + const row: usize = @intCast(@max(0, t.cur_row - e2.row0)); if (row + 1 >= modal.lineCount(e2.text)) return; const new = modal.deleteSpan(p.gpa, e2.text, .{ .row = row, .col = c.col }, .{ .row = row + 1, .col = 0 }) catch return; - setEditText(p, pane, new); + setEditText(p, t, new); } - pane.cur_pinned = true; + t.cur_pinned = true; }, Key.tab => { const ln = modal.lineSlice(text, c.row); @@ -656,51 +667,51 @@ pub fn insertKey(p: *Pardes, pane: *Pane, key: Key) void { p.lspRequest(p.active, .completion, ""); if (p.lsp_seq != seq) return; } - insertTab(p, pane); + insertTab(p, t); }, else => {}, } } -pub fn insertTab(p: *Pardes, pane: *Pane) void { - const eb = editText(p, pane, pane.cur_row, pane.cur_row, pane.cur_col) orelse return; +pub fn insertTab(p: *Pardes, t: *Text) void { + const eb = editText(p, t, t.cur_row, t.cur_row, t.cur_col) orelse return; const c: modal.Cursor = .{ - .row = @intCast(@max(0, pane.cur_row - eb.row0)), - .col = @intCast(@max(0, pane.cur_col)), + .row = @intCast(@max(0, t.cur_row - eb.row0)), + .col = @intCast(@max(0, t.cur_col)), }; const pad = modal.INDENT_W - (c.col % modal.INDENT_W); const new = modal.insertAt(p.gpa, eb.text, c, " "[0..pad]) catch return; - setEditText(p, pane, new); - pane.cur_col += @intCast(pad); - pane.cur_pinned = true; - pane.ensureCursorVisible(); + setEditText(p, t, new); + t.cur_col += @intCast(pad); + t.cur_pinned = true; + t.pane().ensureCursorVisible(); } const Bounds = struct { lo_row: i32, lo_col: i32, hi_row: i32, hi_col: i32 }; /// a range's two cells, normalized to document order -pub fn cellBounds(s: Pane.SelRange) Bounds { +pub fn cellBounds(s: Text.SelRange) Bounds { if (s.row < s.arow or (s.row == s.arow and s.col < s.acol)) return .{ .lo_row = s.row, .lo_col = s.col, .hi_row = s.arow, .hi_col = s.acol }; return .{ .lo_row = s.arow, .lo_col = s.acol, .hi_row = s.row, .hi_col = s.col }; } /// the char selection [anchor, cursor] normalized to document order -fn vselBounds(pane: *Pane) Bounds { - return cellBounds(.{ .row = pane.cur_row, .col = pane.cur_col, .arow = pane.vsel.row, .acol = pane.vsel.col }); +fn vselBounds(t: *Text) Bounds { + return cellBounds(.{ .row = t.cur_row, .col = t.cur_col, .arow = t.vsel.row, .acol = t.vsel.col }); } -fn vselText(p: *Pardes, pane: *Pane) []const u8 { +fn vselText(p: *Pardes, t: *Text) []const u8 { const arena = p.scratch.allocator(); - const b = vselBounds(pane); - const text = flatSurface(p, pane) catch return ""; + const b = vselBounds(t); + const text = flatSurface(p, t) catch return ""; return modal.rangeText(arena, text, .{ .row = @intCast(@max(0, b.lo_row)), .col = @intCast(@max(0, b.lo_col)) }, .{ .row = @intCast(@max(0, b.hi_row)), .col = @intCast(@max(0, b.hi_col)) }) catch ""; } /// join surface rows [r0, r1] (absolute) with '\n'; scratch-owned -fn yankRows(p: *Pardes, pane: *Pane, r0: i32, r1: i32) []const u8 { +fn yankRows(p: *Pardes, t: *Text, r0: i32, r1: i32) []const u8 { const arena = p.scratch.allocator(); - const lines = paneCursorLines(p, pane) catch return ""; + const lines = paneCursorLines(p, t) catch return ""; const rows_count: usize = @intCast(@max(0, r1 - r0 + 1)); var total: usize = rows_count -| 1; var i = r0; @@ -725,54 +736,54 @@ fn yankRows(p: *Pardes, pane: *Pane, r0: i32, r1: i32) []const u8 { return out; } -pub fn normalDelete(p: *Pardes, pane: *Pane, yank: bool) void { - pane.select = false; // helix delete exits select mode - pane.sticky_col = -1; - if (pane.vsel.active) { - const b = vselBounds(pane); - if (yank) setYank(p, vselText(p, pane)); // read the range before the move - pushUndo(p, pane); - const eb = editTextEol(p, pane, b) orelse { - pane.vsel.active = false; +pub fn normalDelete(p: *Pardes, t: *Text, yank: bool) void { + t.select = false; // helix delete exits select mode + t.sticky_col = -1; + if (t.vsel.active) { + const b = vselBounds(t); + if (yank) setYank(p, vselText(p, t)); // read the range before the move + pushUndo(p, t); + const eb = editTextEol(p, t, b) orelse { + t.vsel.active = false; return; }; const d = modal.deleteRange(p.gpa, eb.text, .{ .row = @intCast(@max(0, b.lo_row - eb.row0)), .col = @intCast(@max(0, b.lo_col)) }, .{ .row = @intCast(@max(0, b.hi_row - eb.row0)), .col = @intCast(@max(0, b.hi_col)) }) catch { - pane.vsel.active = false; + t.vsel.active = false; return; }; - setEditText(p, pane, d.content); + setEditText(p, t, d.content); p.gpa.free(d.deleted); - pane.cur_row = b.lo_row; - pane.cur_col = b.lo_col; - pane.clampCursor(d.content, eb.row0); + t.cur_row = b.lo_row; + t.cur_col = b.lo_col; + t.clampCursor(d.content, eb.row0); return; } - if (pane.msel.active) { - const r0 = @min(pane.msel.r0, pane.msel.r1); - const r1 = @max(pane.msel.r0, pane.msel.r1); - pushUndo(p, pane); + if (t.msel.active) { + const r0 = @min(t.msel.r0, t.msel.r1); + const r1 = @max(t.msel.r0, t.msel.r1); + pushUndo(p, t); // linewise: a line's newline lives on the row below it - const eb = editText(p, pane, r0, r1 + 1, -1) orelse { - pane.msel.active = false; + const eb = editText(p, t, r0, r1 + 1, -1) orelse { + t.msel.active = false; return; }; const d = modal.deleteLines(p.gpa, eb.text, @intCast(@max(0, r0 - eb.row0)), @intCast(@max(0, r1 - eb.row0))) catch { - pane.msel.active = false; + t.msel.active = false; return; }; - setEditText(p, pane, d.content); + setEditText(p, t, d.content); if (yank) setYank(p, d.deleted); p.gpa.free(d.deleted); const n = modal.lineCount(d.content); - pane.cur_row = @as(i32, @intCast(@min(@as(usize, @intCast(@max(0, r0 - eb.row0))), if (n == 0) 0 else n - 1))) + eb.row0; - pane.cur_col = 0; - pane.msel.active = false; - pane.cur_pinned = true; - pane.ensureCursorVisible(); + t.cur_row = @as(i32, @intCast(@min(@as(usize, @intCast(@max(0, r0 - eb.row0))), if (n == 0) 0 else n - 1))) + eb.row0; + t.cur_col = 0; + t.msel.active = false; + t.cur_pinned = true; + t.pane().ensureCursorVisible(); } else { - pushUndo(p, pane); - const eb = editTextEol(p, pane, .{ .lo_row = pane.cur_row, .lo_col = pane.cur_col, .hi_row = pane.cur_row, .hi_col = pane.cur_col }) orelse return; - const c = modal.Cursor{ .row = @intCast(@max(0, pane.cur_row - eb.row0)), .col = @intCast(@max(0, pane.cur_col)) }; + pushUndo(p, t); + const eb = editTextEol(p, t, .{ .lo_row = t.cur_row, .lo_col = t.cur_col, .hi_row = t.cur_row, .hi_col = t.cur_col }) orelse return; + const c = modal.Cursor{ .row = @intCast(@max(0, t.cur_row - eb.row0)), .col = @intCast(@max(0, t.cur_col)) }; if (yank) { const arena = p.scratch.allocator(); setYank(p, modal.rangeText(arena, eb.text, c, c) catch return); @@ -780,38 +791,39 @@ pub fn normalDelete(p: *Pardes, pane: *Pane, yank: bool) void { // deleteRange (not deleteChar): the cursor may sit ON a '\n' // cell, where a delete joins the lines (helix 1-wide selection) const d = modal.deleteRange(p.gpa, eb.text, c, c) catch return; - setEditText(p, pane, d.content); + setEditText(p, t, d.content); p.gpa.free(d.deleted); const llen = modal.lineSlice(d.content, c.row).len; - pane.cur_col = @min(pane.cur_col, @as(i32, @intCast(llen))); + t.cur_col = @min(t.cur_col, @as(i32, @intCast(llen))); } } -pub fn normalYank(p: *Pardes, pane: *Pane) void { - pane.select = false; +pub fn normalYank(p: *Pardes, t: *Text) void { + const pane = t.pane(); + t.select = false; if (pane.rawPointerText(pane.sel[sel_slot])) |text| { setYank(p, text); return; } - if (pane.vsel.active) { - setYank(p, vselText(p, pane)); + if (t.vsel.active) { + setYank(p, vselText(p, t)); return; } - if (pane.msel.active) { - setYank(p, yankRows(p, pane, @min(pane.msel.r0, pane.msel.r1), @max(pane.msel.r0, pane.msel.r1))); + if (t.msel.active) { + setYank(p, yankRows(p, t, @min(t.msel.r0, t.msel.r1), @max(t.msel.r0, t.msel.r1))); } else { - const save = pane.vsel; - pane.vsel = .{ .active = true, .row = pane.cur_row, .col = pane.cur_col, .explicit = false }; - setYank(p, vselText(p, pane)); - pane.vsel = save; + const save = t.vsel; + t.vsel = .{ .active = true, .row = t.cur_row, .col = t.cur_col, .explicit = false }; + setYank(p, vselText(p, t)); + t.vsel = save; } } -pub fn pasteText(p: *Pardes, pane: *Pane, y0: []const u8, before: bool, count: usize) void { +pub fn pasteText(p: *Pardes, t: *Text, y0: []const u8, before: bool, count: usize) void { if (y0.len == 0) return; - pushUndo(p, pane); - pane.select = false; - pane.sticky_col = -1; + pushUndo(p, t); + t.select = false; + t.sticky_col = -1; const arena = p.scratch.allocator(); var y: []const u8 = y0; if (count > 1) { @@ -820,11 +832,11 @@ pub fn pasteText(p: *Pardes, pane: *Pane, y0: []const u8, before: bool, count: u for (0..count) |i| @memcpy(buf[i * y0.len ..][0..y0.len], y0); y = buf; } - const b: Bounds = if (pane.vsel.active) - vselBounds(pane) + const b: Bounds = if (t.vsel.active) + vselBounds(t) else - .{ .lo_row = pane.cur_row, .lo_col = pane.cur_col, .hi_row = pane.cur_row, .hi_col = pane.cur_col }; - const eb = editText(p, pane, b.lo_row, b.hi_row, -1) orelse return; + .{ .lo_row = t.cur_row, .lo_col = t.cur_col, .hi_row = t.cur_row, .hi_col = t.cur_col }; + const eb = editText(p, t, b.lo_row, b.hi_row, -1) orelse return; const row0 = eb.row0; if (y[y.len - 1] == '\n') { const block_text = y[0 .. y.len - 1]; @@ -834,17 +846,17 @@ pub fn pasteText(p: *Pardes, pane: *Pane, y0: []const u8, before: bool, count: u const row: usize = @intCast(@max(0, b.lo_row - row0)); const block = std.fmt.allocPrint(arena, "{s}\n", .{block_text}) catch return; out = modal.insertAt(p.gpa, eb.text, .{ .row = row, .col = 0 }, block) catch return; - pane.cur_row = @as(i32, @intCast(row + n - 1)) + row0; + t.cur_row = @as(i32, @intCast(row + n - 1)) + row0; } else { const row: usize = @intCast(@max(0, b.hi_row - row0)); out = modal.pasteLineBelow(p.gpa, eb.text, row, block_text) catch return; - pane.cur_row = @as(i32, @intCast(row + n)) + row0; + t.cur_row = @as(i32, @intCast(row + n)) + row0; } - setEditText(p, pane, out); - pane.vsel = .{ .active = true, .row = pane.cur_row - @as(i32, @intCast(n - 1)), .col = 0, .explicit = false }; + setEditText(p, t, out); + t.vsel = .{ .active = true, .row = t.cur_row - @as(i32, @intCast(n - 1)), .col = 0, .explicit = false }; // cursor ON the last pasted line's '\n' (helix) - const llen = modal.lineSlice(out, @intCast(@max(0, pane.cur_row - row0))).len; - pane.cur_col = @intCast(llen); + const llen = modal.lineSlice(out, @intCast(@max(0, t.cur_row - row0))).len; + t.cur_col = @intCast(llen); } else { const at: modal.Cursor = if (before) .{ .row = @intCast(@max(0, b.lo_row - row0)), .col = @intCast(@max(0, b.lo_col)) } @@ -857,34 +869,35 @@ pub fn pasteText(p: *Pardes, pane: *Pane, y0: []const u8, before: bool, count: u break :blk .{ .row = hrow, .col = gcol }; }; const out = modal.insertAt(p.gpa, eb.text, at, y) catch return; - setEditText(p, pane, out); - pane.vsel = .{ .active = modal.nextGrapheme(y, 0) < y.len, .row = @as(i32, @intCast(at.row)) + row0, .col = @intCast(at.col), .explicit = false }; + setEditText(p, t, out); + t.vsel = .{ .active = modal.nextGrapheme(y, 0) < y.len, .row = @as(i32, @intCast(at.row)) + row0, .col = @intCast(at.col), .explicit = false }; const end = modal.advanceBy(at, y); if (end.col > 0) { - pane.cur_row = @as(i32, @intCast(end.row)) + row0; - pane.cur_col = @intCast(modal.prevGrapheme(modal.lineSlice(out, end.row), end.col)); + t.cur_row = @as(i32, @intCast(end.row)) + row0; + t.cur_col = @intCast(modal.prevGrapheme(modal.lineSlice(out, end.row), end.col)); } else { - pane.cur_row = @as(i32, @intCast(end.row -| 1)) + row0; - pane.cur_col = @intCast(modal.lineSlice(out, end.row -| 1).len); + t.cur_row = @as(i32, @intCast(end.row -| 1)) + row0; + t.cur_col = @intCast(modal.lineSlice(out, end.row -| 1).len); } } - pane.msel.active = false; - pane.cur_pinned = true; - pane.ensureCursorVisible(); + t.msel.active = false; + t.cur_pinned = true; + t.pane().ensureCursorVisible(); } -pub fn normalChange(p: *Pardes, pane: *Pane) void { - pane.select = false; - pane.sticky_col = -1; - if (pane.vsel.active) { - const b = vselBounds(pane); - const eb = editTextEol(p, pane, b) orelse return; +pub fn normalChange(p: *Pardes, t: *Text) void { + const pane = t.pane(); + t.select = false; + t.sticky_col = -1; + if (t.vsel.active) { + const b = vselBounds(t); + const eb = editTextEol(p, t, b) orelse return; const hi_len = modal.lineSlice(eb.text, @intCast(@max(0, b.hi_row - eb.row0))).len; if (b.lo_col == 0 and @as(usize, @intCast(@max(0, b.hi_col))) >= hi_len) { - setYank(p, vselText(p, pane)); - pushUndo(p, pane); + setYank(p, vselText(p, t)); + pushUndo(p, t); const d = modal.deleteLines(p.gpa, eb.text, @intCast(@max(0, b.lo_row - eb.row0)), @intCast(@max(0, b.hi_row - eb.row0))) catch return; - setEditText(p, pane, d.content); + setEditText(p, t, d.content); p.gpa.free(d.deleted); const n = modal.lineCount(d.content); const row: usize = @min(@as(usize, @intCast(@max(0, b.lo_row - eb.row0))), if (n == 0) 0 else n - 1); @@ -892,37 +905,37 @@ pub fn normalChange(p: *Pardes, pane: *Pane) void { const arena = p.scratch.allocator(); const block = std.fmt.allocPrint(arena, "{s}\n", .{ind}) catch return; const new = modal.insertAt(p.gpa, d.content, .{ .row = row, .col = 0 }, block) catch return; - setEditText(p, pane, new); - pane.cur_row = @as(i32, @intCast(row)) + eb.row0; - pane.cur_col = @intCast(ind.len); - pane.vsel.active = false; - pane.msel.active = false; - pane.cur_pinned = true; - pane.mode = .insert; - pane.normal.clear(); + setEditText(p, t, new); + t.cur_row = @as(i32, @intCast(row)) + eb.row0; + t.cur_col = @intCast(ind.len); + t.vsel.active = false; + t.msel.active = false; + t.cur_pinned = true; + t.mode = .insert; + t.normal.clear(); pane.ensureCursorVisible(); return; } - setYank(p, vselText(p, pane)); - pushUndo(p, pane); + setYank(p, vselText(p, t)); + pushUndo(p, t); const d = modal.deleteRange(p.gpa, eb.text, .{ .row = @intCast(@max(0, b.lo_row - eb.row0)), .col = @intCast(@max(0, b.lo_col)) }, .{ .row = @intCast(@max(0, b.hi_row - eb.row0)), .col = @intCast(@max(0, b.hi_col)) }) catch { - pane.vsel.active = false; + t.vsel.active = false; return; }; - setEditText(p, pane, d.content); + setEditText(p, t, d.content); p.gpa.free(d.deleted); - pane.cur_row = b.lo_row; - pane.cur_col = b.lo_col; - pane.clampCursor(d.content, eb.row0); - pane.mode = .insert; - pane.normal.clear(); + t.cur_row = b.lo_row; + t.cur_col = b.lo_col; + t.clampCursor(d.content, eb.row0); + t.mode = .insert; + t.normal.clear(); return; } - if (pane.msel.active) { - const r0 = @min(pane.msel.r0, pane.msel.r1); - const r1 = @max(pane.msel.r0, pane.msel.r1); - pushUndo(p, pane); - const eb = editText(p, pane, r0, r1 + 1, -1) orelse return; + if (t.msel.active) { + const r0 = @min(t.msel.r0, t.msel.r1); + const r1 = @max(t.msel.r0, t.msel.r1); + pushUndo(p, t); + const eb = editText(p, t, r0, r1 + 1, -1) orelse return; const arena = p.scratch.allocator(); const lo: usize = @intCast(@max(0, r0 - eb.row0)); const hi: usize = @intCast(@max(0, r1 - eb.row0)); @@ -943,77 +956,77 @@ pub fn normalChange(p: *Pardes, pane: *Pane) void { var body: []u8 = eb.text; if (hi > lo) { const d = modal.deleteLines(p.gpa, body, lo + 1, hi) catch { - pane.msel.active = false; + t.msel.active = false; return; }; - setEditText(p, pane, d.content); + setEditText(p, t, d.content); p.gpa.free(d.deleted); body = d.content; } const cl = modal.clearLine(p.gpa, body, lo) catch { - pane.msel.active = false; + t.msel.active = false; return; }; - setEditText(p, pane, cl); - pane.cur_row = r0; - pane.cur_col = 0; - pane.msel.active = false; - pane.cur_pinned = true; - pane.mode = .insert; - pane.normal.clear(); + setEditText(p, t, cl); + t.cur_row = r0; + t.cur_col = 0; + t.msel.active = false; + t.cur_pinned = true; + t.mode = .insert; + t.normal.clear(); pane.ensureCursorVisible(); } else { - pushUndo(p, pane); - const eb = editTextEol(p, pane, .{ .lo_row = pane.cur_row, .lo_col = pane.cur_col, .hi_row = pane.cur_row, .hi_col = pane.cur_col }) orelse return; - const c = modal.Cursor{ .row = @intCast(@max(0, pane.cur_row - eb.row0)), .col = @intCast(@max(0, pane.cur_col)) }; + pushUndo(p, t); + const eb = editTextEol(p, t, .{ .lo_row = t.cur_row, .lo_col = t.cur_col, .hi_row = t.cur_row, .hi_col = t.cur_col }) orelse return; + const c = modal.Cursor{ .row = @intCast(@max(0, t.cur_row - eb.row0)), .col = @intCast(@max(0, t.cur_col)) }; const arena = p.scratch.allocator(); setYank(p, modal.rangeText(arena, eb.text, c, c) catch return); const d = modal.deleteRange(p.gpa, eb.text, c, c) catch return; - setEditText(p, pane, d.content); + setEditText(p, t, d.content); p.gpa.free(d.deleted); const llen = modal.lineSlice(d.content, c.row).len; - pane.cur_col = @min(pane.cur_col, @as(i32, @intCast(llen))); - pane.mode = .insert; - pane.normal.clear(); + t.cur_col = @min(t.cur_col, @as(i32, @intCast(llen))); + t.mode = .insert; + t.normal.clear(); } } -fn selRange(pane: *Pane, content: []const u8, row0: i32) modal.Range { - if (pane.vsel.active) { - const b = vselBounds(pane); +fn selRange(t: *Text, content: []const u8, row0: i32) modal.Range { + if (t.vsel.active) { + const b = vselBounds(t); return .{ .a = .{ .row = @intCast(@max(0, b.lo_row - row0)), .col = @intCast(@max(0, b.lo_col)) }, .b = .{ .row = @intCast(@max(0, b.hi_row - row0)), .col = @intCast(@max(0, b.hi_col)) }, }; } - if (pane.msel.active) { - const r0: usize = @intCast(@max(0, @min(pane.msel.r0, pane.msel.r1) - row0)); - const r1: usize = @intCast(@max(0, @max(pane.msel.r0, pane.msel.r1) - row0)); + if (t.msel.active) { + const r0: usize = @intCast(@max(0, @min(t.msel.r0, t.msel.r1) - row0)); + const r1: usize = @intCast(@max(0, @max(t.msel.r0, t.msel.r1) - row0)); const llen = modal.lineSlice(content, r1).len; return .{ .a = .{ .row = r0, .col = 0 }, .b = .{ .row = r1, .col = if (llen == 0) 0 else modal.prevGrapheme(modal.lineSlice(content, r1), llen) } }; } - const c = modal.Cursor{ .row = @intCast(@max(0, pane.cur_row - row0)), .col = @intCast(@max(0, pane.cur_col)) }; + const c = modal.Cursor{ .row = @intCast(@max(0, t.cur_row - row0)), .col = @intCast(@max(0, t.cur_col)) }; return .{ .a = c, .b = c }; } /// the rows an op's selection spans, absolute (what editText must cover) -fn selRows(pane: *Pane) Bounds { - if (pane.vsel.active) return vselBounds(pane); - if (pane.msel.active) return .{ - .lo_row = @min(pane.msel.r0, pane.msel.r1), +fn selRows(t: *Text) Bounds { + if (t.vsel.active) return vselBounds(t); + if (t.msel.active) return .{ + .lo_row = @min(t.msel.r0, t.msel.r1), .lo_col = 0, - .hi_row = @max(pane.msel.r0, pane.msel.r1), + .hi_row = @max(t.msel.r0, t.msel.r1), .hi_col = 0, }; - return .{ .lo_row = pane.cur_row, .lo_col = pane.cur_col, .hi_row = pane.cur_row, .hi_col = pane.cur_col }; + return .{ .lo_row = t.cur_row, .lo_col = t.cur_col, .hi_row = t.cur_row, .hi_col = t.cur_col }; } /// `r`: overwrite the selection (or the cursor char) with ch — /// newlines included (helix), so `xrz` joins the selected lines -pub fn normalReplaceChar(p: *Pardes, pane: *Pane, ch: u21) void { - pane.select = false; - const eb = editTextEol(p, pane, selRows(pane)) orelse return; - const before = pane.primaryRange(eb.text, eb.row0); +pub fn normalReplaceChar(p: *Pardes, t: *Text, ch: u21) void { + t.select = false; + const eb = editTextEol(p, t, selRows(t)) orelse return; + const before = t.primaryRange(eb.text, eb.row0); const lo = @min(before.anchor, before.head); const hi = @max(before.anchor, before.head); var graphemes: usize = 0; @@ -1021,59 +1034,59 @@ pub fn normalReplaceChar(p: *Pardes, pane: *Pane, ch: u21) void { while (at < hi) : (graphemes += 1) at = modal.nextGrapheme(eb.text, at); var encoded: [4]u8 = undefined; const encoded_len = std.unicode.utf8Encode(ch, &encoded) catch return; - const r = selRange(pane, eb.text, eb.row0); - pushUndo(p, pane); + const r = selRange(t, eb.text, eb.row0); + pushUndo(p, t); const new = modal.replaceChars(p.gpa, eb.text, r.a, r.b, ch) catch return; - setEditText(p, pane, new); + setEditText(p, t, new); const end = lo + graphemes * encoded_len; const mapped: modal.Selection = if (before.head < before.anchor) .{ .anchor = end, .head = lo } else .{ .anchor = lo, .head = end }; - pane.setRange(new, eb.row0, mapped, pane.vsel.explicit); + t.setRange(new, eb.row0, mapped, t.vsel.explicit); } /// `R`: replace the selection (or the cursor char) with the DEFAULT /// register. `SPC R` is the same verb over the system clipboard. -pub fn normalReplaceYank(p: *Pardes, pane: *Pane) void { - replaceWithText(p, pane, p.yank orelse return); +pub fn normalReplaceYank(p: *Pardes, t: *Text) void { + replaceWithText(p, t, p.yank orelse return); } /// The pasted text becomes the selection, head on its last char (which for /// a trailing-newline `y` is the '\n' cell of the last full line). -fn replaceWithText(p: *Pardes, pane: *Pane, y: []const u8) void { +fn replaceWithText(p: *Pardes, t: *Text, y: []const u8) void { if (y.len == 0) return; - pane.select = false; - const eb = editTextEol(p, pane, selRows(pane)) orelse return; - const r = selRange(pane, eb.text, eb.row0); - pushUndo(p, pane); + t.select = false; + const eb = editTextEol(p, t, selRows(t)) orelse return; + const r = selRange(t, eb.text, eb.row0); + pushUndo(p, t); const new = modal.replaceRange(p.gpa, eb.text, r.a, r.b, y) catch return; - setEditText(p, pane, new); - pane.msel.active = false; - pane.vsel = .{ .active = modal.nextGrapheme(y, 0) < y.len, .row = @as(i32, @intCast(r.a.row)) + eb.row0, .col = @intCast(r.a.col), .explicit = false }; + setEditText(p, t, new); + t.msel.active = false; + t.vsel = .{ .active = modal.nextGrapheme(y, 0) < y.len, .row = @as(i32, @intCast(r.a.row)) + eb.row0, .col = @intCast(r.a.col), .explicit = false }; const end = modal.advanceBy(r.a, y); if (end.col > 0) { - pane.cur_row = @as(i32, @intCast(end.row)) + eb.row0; - pane.cur_col = @intCast(modal.prevGrapheme(modal.lineSlice(new, end.row), end.col)); + t.cur_row = @as(i32, @intCast(end.row)) + eb.row0; + t.cur_col = @intCast(modal.prevGrapheme(modal.lineSlice(new, end.row), end.col)); } else { // the yank ended in '\n': the cursor lands ON that newline - pane.cur_row = @as(i32, @intCast(end.row -| 1)) + eb.row0; - pane.cur_col = @intCast(modal.lineSlice(new, end.row -| 1).len); + t.cur_row = @as(i32, @intCast(end.row -| 1)) + eb.row0; + t.cur_col = @intCast(modal.lineSlice(new, end.row -| 1).len); } - pane.cur_pinned = true; - pane.sticky_col = -1; - pane.ensureCursorVisible(); + t.cur_pinned = true; + t.sticky_col = -1; + t.pane().ensureCursorVisible(); } /// `~` / `` ` `` / ``Alt-` ``: case-map the selection (or the cursor char), /// keeping the selection (helix) -pub fn normalCase(p: *Pardes, pane: *Pane, op: modal.CaseOp) void { - pane.select = false; - const eb = editTextEol(p, pane, selRows(pane)) orelse return; - const r = selRange(pane, eb.text, eb.row0); - pushUndo(p, pane); +pub fn normalCase(p: *Pardes, t: *Text, op: modal.CaseOp) void { + t.select = false; + const eb = editTextEol(p, t, selRows(t)) orelse return; + const r = selRange(t, eb.text, eb.row0); + pushUndo(p, t); const new = modal.changeCase(p.gpa, eb.text, r.a, r.b, op) catch return; - setEditText(p, pane, new); + setEditText(p, t, new); } /// a change to apply to file content: delete [from, to), insert `ins` at @@ -1115,14 +1128,14 @@ fn applyChanges(p: *Pardes, text: []const u8, chs: []const TextChange) ![]u8 { return out; } -pub fn normalJoin(p: *Pardes, pane: *Pane) void { +pub fn normalJoin(p: *Pardes, t: *Text) void { // a join always eats the newline of its last line, so the buffer has // to reach one row PAST the selection - const sr = selRows(pane); - const eb = editText(p, pane, sr.lo_row, sr.hi_row + 1, -1) orelse return; + const sr = selRows(t); + const eb = editText(p, t, sr.lo_row, sr.hi_row + 1, -1) orelse return; const text = eb.text; - const range = pane.primaryRange(text, eb.row0); - const span = Pane.rangeLineSpan(text, range); + const range = t.primaryRange(text, eb.row0); + const span = Text.rangeLineSpan(text, range); const nlines = modal.cursorLineCount(text); var end = span.end; if (span.start == end) end = @min(end + 1, nlines - 1); @@ -1140,37 +1153,37 @@ pub fn normalJoin(p: *Pardes, pane: *Pane) void { chs_len += 1; } if (chs_len == 0) return; - pushUndo(p, pane); - const cur_off = modal.offsetAt(text, .{ .row = @intCast(@max(0, pane.cur_row - eb.row0)), .col = @intCast(@max(0, pane.cur_col)) }); - const anc_off = if (pane.vsel.active) - modal.offsetAt(text, .{ .row = @intCast(@max(0, pane.vsel.row - eb.row0)), .col = @intCast(@max(0, pane.vsel.col)) }) + pushUndo(p, t); + const cur_off = modal.offsetAt(text, .{ .row = @intCast(@max(0, t.cur_row - eb.row0)), .col = @intCast(@max(0, t.cur_col)) }); + const anc_off = if (t.vsel.active) + modal.offsetAt(text, .{ .row = @intCast(@max(0, t.vsel.row - eb.row0)), .col = @intCast(@max(0, t.vsel.col)) }) else cur_off; const new = applyChanges(p, text, chs[0..chs_len]) catch return; const nc = mapThroughChanges(chs[0..chs_len], cur_off); const na = mapThroughChanges(chs[0..chs_len], anc_off); - setEditText(p, pane, new); + setEditText(p, t, new); const cc = modal.positionAt(new, nc); const ac = modal.positionAt(new, na); - pane.cur_row = @as(i32, @intCast(cc.row)) + eb.row0; - pane.cur_col = @intCast(cc.col); - if (pane.vsel.active) { - pane.vsel.row = @as(i32, @intCast(ac.row)) + eb.row0; - pane.vsel.col = @intCast(ac.col); + t.cur_row = @as(i32, @intCast(cc.row)) + eb.row0; + t.cur_col = @intCast(cc.col); + if (t.vsel.active) { + t.vsel.row = @as(i32, @intCast(ac.row)) + eb.row0; + t.vsel.col = @intCast(ac.col); } - pane.msel.active = false; - pane.cur_pinned = true; - pane.sticky_col = -1; - pane.ensureCursorVisible(); + t.msel.active = false; + t.cur_pinned = true; + t.sticky_col = -1; + t.pane().ensureCursorVisible(); } -pub fn normalIndent(p: *Pardes, pane: *Pane, cnt: usize, add: bool) void { - pane.select = false; - const sr = selRows(pane); - const eb = editText(p, pane, sr.lo_row, sr.hi_row, -1) orelse return; +pub fn normalIndent(p: *Pardes, t: *Text, cnt: usize, add: bool) void { + t.select = false; + const sr = selRows(t); + const eb = editText(p, t, sr.lo_row, sr.hi_row, -1) orelse return; const text = eb.text; - const range = pane.primaryRange(text, eb.row0); - const span = Pane.rangeLineSpan(text, range); + const range = t.primaryRange(text, eb.row0); + const span = Text.rangeLineSpan(text, range); const arena = p.scratch.allocator(); // one run of spaces, sliced per line: `>` never inserts more than this const pad = arena.alloc(u8, modal.INDENT_W * cnt) catch return; @@ -1208,45 +1221,45 @@ pub fn normalIndent(p: *Pardes, pane: *Pane, cnt: usize, add: bool) void { } } if (chs_len == 0) return; - pushUndo(p, pane); - const cur_off = modal.offsetAt(text, .{ .row = @intCast(@max(0, pane.cur_row - eb.row0)), .col = @intCast(@max(0, pane.cur_col)) }); - const anc_off = if (pane.vsel.active) - modal.offsetAt(text, .{ .row = @intCast(@max(0, pane.vsel.row - eb.row0)), .col = @intCast(@max(0, pane.vsel.col)) }) + pushUndo(p, t); + const cur_off = modal.offsetAt(text, .{ .row = @intCast(@max(0, t.cur_row - eb.row0)), .col = @intCast(@max(0, t.cur_col)) }); + const anc_off = if (t.vsel.active) + modal.offsetAt(text, .{ .row = @intCast(@max(0, t.vsel.row - eb.row0)), .col = @intCast(@max(0, t.vsel.col)) }) else cur_off; const new = applyChanges(p, text, chs[0..chs_len]) catch return; const nc = mapThroughChanges(chs[0..chs_len], cur_off); const na = mapThroughChanges(chs[0..chs_len], anc_off); - setEditText(p, pane, new); + setEditText(p, t, new); const cc = modal.positionAt(new, nc); const ac = modal.positionAt(new, na); - pane.cur_row = @as(i32, @intCast(cc.row)) + eb.row0; - pane.cur_col = @intCast(cc.col); - if (pane.vsel.active) { - pane.vsel.row = @as(i32, @intCast(ac.row)) + eb.row0; - pane.vsel.col = @intCast(ac.col); + t.cur_row = @as(i32, @intCast(cc.row)) + eb.row0; + t.cur_col = @intCast(cc.col); + if (t.vsel.active) { + t.vsel.row = @as(i32, @intCast(ac.row)) + eb.row0; + t.vsel.col = @intCast(ac.col); } - pane.msel.active = false; - pane.cur_pinned = true; - pane.sticky_col = -1; - pane.ensureCursorVisible(); + t.msel.active = false; + t.cur_pinned = true; + t.sticky_col = -1; + t.pane().ensureCursorVisible(); } -pub fn normalToggleComment(p: *Pardes, pane: *Pane) void { - const expl = (pane.vsel.active and pane.vsel.explicit) or pane.msel.active; - pane.select = false; // helix exit_select_mode +pub fn normalToggleComment(p: *Pardes, t: *Text) void { + const expl = (t.vsel.active and t.vsel.explicit) or t.msel.active; + t.select = false; // helix exit_select_mode // the buffer must cover every cursor's rows, not just the primary's - var b = selRows(pane); - for (pane.sels[0..pane.nsel]) |s| { + var b = selRows(t); + for (t.sels[0..t.nsel]) |s| { b.lo_row = @min(b.lo_row, @min(s.row, s.arow)); b.hi_row = @max(b.hi_row, @max(s.row, s.arow)); } - const surface = flatSurface(p, pane) catch return; - const last_row = @as(i32, @intCast(panes.File.textLineCount(pane, surface))) - 1; - const eb = editText(p, pane, b.lo_row, @min(b.hi_row + 1, last_row), -1) orelse return; + const surface = flatSurface(p, t) catch return; + const last_row = @as(i32, @intCast(panes.File.textLineCount(t, surface))) - 1; + const eb = editText(p, t, b.lo_row, @min(b.hi_row + 1, last_row), -1) orelse return; const text = eb.text; - var rs: [Pane.max_selections]modal.Selection = undefined; - const got = pane.ranges(text, eb.row0, &rs); + var rs: [Text.max_selections]modal.Selection = undefined; + const got = t.ranges(text, eb.row0, &rs); const nlines = modal.cursorLineCount(text); const arena = p.scratch.allocator(); // the lines the ranges cover, each ONE ONCE and in order (helix's @@ -1255,7 +1268,7 @@ pub fn normalToggleComment(p: *Pardes, pane: *Pane) void { var lines_len: usize = 0; var next: usize = 0; for (rs[0..got.n]) |r| { - const span = Pane.rangeLineSpan(text, r); + const span = Text.rangeLineSpan(text, r); var l = @max(span.start, next); const end = @min(span.end + 1, nlines); while (l < end) : (l += 1) { @@ -1264,7 +1277,7 @@ pub fn normalToggleComment(p: *Pardes, pane: *Pane) void { } next = @max(next, end); } - const ext = if (pane.file) |f| std.fs.path.extension(f.path) else ""; + const ext = if (t.pane().file) |f| std.fs.path.extension(f.path) else ""; var token: []const u8 = config.comment_token_default; lang: for (config.comment_tokens) |row| { for (row.exts) |e| if (std.ascii.eqlIgnoreCase(ext, e)) { @@ -1303,13 +1316,13 @@ pub fn normalToggleComment(p: *Pardes, pane: *Pane) void { .{ .from = at, .to = at, .ins = ins }; chs_len += 1; } - pushUndo(p, pane); + pushUndo(p, t); // one edit, and the WHOLE selection rides through it (helix maps the // selection with the transaction) - var cells: [Pane.max_selections]Pane.SelRange = undefined; + var cells: [Text.max_selections]Text.SelRange = undefined; const new = applyChanges(p, text, chs[0..chs_len]) catch return; for (rs[0..got.n], 0..) |r, i| { - const c = Pane.rangeCells(new, .{ + const c = Text.rangeCells(new, .{ .anchor = mapThroughChanges(chs[0..chs_len], r.anchor), .head = mapThroughChanges(chs[0..chs_len], r.head), }); @@ -1322,53 +1335,53 @@ pub fn normalToggleComment(p: *Pardes, pane: *Pane) void { .acol = @intCast(ac.col), }; } - setEditText(p, pane, new); - const t2 = flatSurface(p, pane) catch return; - for (cells[0..got.n], 0..) |s, i| rs[i] = Pane.cellRange(t2, s.arow, s.acol, s.row, s.col); - pane.setRanges(t2, rs[0..got.n], &.{}, got.pri, expl); + setEditText(p, t, new); + const t2 = flatSurface(p, t) catch return; + for (cells[0..got.n], 0..) |s, i| rs[i] = Text.cellRange(t2, s.arow, s.acol, s.row, s.col); + t.setRanges(t2, rs[0..got.n], &.{}, got.pri, expl); } -pub fn normalAdjustNumber(p: *Pardes, pane: *Pane, delta: i64) void { - const eb = editTextEol(p, pane, selRows(pane)) orelse return; - const r = selRange(pane, eb.text, eb.row0); +pub fn normalAdjustNumber(p: *Pardes, t: *Text, delta: i64) void { + const eb = editTextEol(p, t, selRows(t)) orelse return; + const r = selRange(t, eb.text, eb.row0); const arena = p.scratch.allocator(); const frag = modal.rangeText(arena, eb.text, r.a, r.b) catch return; const rep = (modal.incrementDecimal(arena, frag, delta) catch null) orelse return; - pushUndo(p, pane); - pane.select = false; + pushUndo(p, t); + t.select = false; const new = modal.replaceRange(p.gpa, eb.text, r.a, r.b, rep) catch return; - setEditText(p, pane, new); + setEditText(p, t, new); const start = modal.lineStartOffset(new, r.a.row) + r.a.col; const cc = modal.positionAt(new, modal.prevGrapheme(new, start + rep.len)); - pane.vsel = .{ .active = modal.nextGrapheme(rep, 0) < rep.len, .row = @as(i32, @intCast(r.a.row)) + eb.row0, .col = @intCast(r.a.col), .explicit = false }; - pane.msel.active = false; - pane.cur_row = @as(i32, @intCast(cc.row)) + eb.row0; - pane.cur_col = @intCast(cc.col); - pane.cur_pinned = true; - pane.sticky_col = -1; - pane.ensureCursorVisible(); + t.vsel = .{ .active = modal.nextGrapheme(rep, 0) < rep.len, .row = @as(i32, @intCast(r.a.row)) + eb.row0, .col = @intCast(r.a.col), .explicit = false }; + t.msel.active = false; + t.cur_row = @as(i32, @intCast(cc.row)) + eb.row0; + t.cur_col = @intCast(cc.col); + t.cur_pinned = true; + t.sticky_col = -1; + t.pane().ensureCursorVisible(); } /// `]Space` / `[Space`: add blank lines below/above, the cursor staying /// on its text line (the selection rides along) -pub fn addNewline(p: *Pardes, pane: *Pane, below: bool, cnt: usize) void { - const eb = editText(p, pane, pane.cur_row, pane.cur_row, -1) orelse return; - pushUndo(p, pane); - const row: usize = @intCast(@max(0, pane.cur_row - eb.row0)); +pub fn addNewline(p: *Pardes, t: *Text, below: bool, cnt: usize) void { + const eb = editText(p, t, t.cur_row, t.cur_row, -1) orelse return; + pushUndo(p, t); + const row: usize = @intCast(@max(0, t.cur_row - eb.row0)); const arena = p.scratch.allocator(); const nl = arena.alloc(u8, cnt) catch return; @memset(nl, '\n'); const llen = modal.lineSlice(eb.text, row).len; const new = modal.insertAt(p.gpa, eb.text, .{ .row = row, .col = if (below) llen else 0 }, nl) catch return; - setEditText(p, pane, new); + setEditText(p, t, new); if (!below) { - pane.cur_row += @intCast(cnt); // the line moved down; stay on it - if (pane.vsel.active and pane.vsel.row >= @as(i32, @intCast(row))) pane.vsel.row += @intCast(cnt); - } else if (pane.vsel.active and pane.vsel.row > @as(i32, @intCast(row))) { - pane.vsel.row += @intCast(cnt); + t.cur_row += @intCast(cnt); // the line moved down; stay on it + if (t.vsel.active and t.vsel.row >= @as(i32, @intCast(row))) t.vsel.row += @intCast(cnt); + } else if (t.vsel.active and t.vsel.row > @as(i32, @intCast(row))) { + t.vsel.row += @intCast(cnt); } - pane.cur_pinned = true; - pane.ensureCursorVisible(); + t.cur_pinned = true; + t.pane().ensureCursorVisible(); } /// pair mapping for m-mode: either bracket names the pair; anything else @@ -1383,20 +1396,20 @@ fn pairFor(ch: u21) ?struct { o: u8, c: u8 } { }; } -pub fn textobjectSelect(p: *Pardes, pane: *Pane, text: []const u8, obj: u21, around: bool) void { - const range = pane.primaryRange(text, 0); +pub fn textobjectSelect(p: *Pardes, t: *Text, text: []const u8, obj: u21, around: bool) void { + const range = t.primaryRange(text, 0); switch (obj) { 'w', 'W' => { const r = modal.selectWord(text, range, around, obj == 'W'); - return pane.setRange(text, 0, r, false); + return t.setRange(text, 0, r, false); }, 'p' => { const r = modal.selectParagraph(text, range, around, 1); - return pane.setRange(text, 0, r, false); + return t.setRange(text, 0, r, false); }, else => {}, } - const lines = paneCursorLines(p, pane) catch return; + const lines = paneCursorLines(p, t) catch return; const cur = modal.positionAt(text, modal.selectionCursor(text, range)); const pair: ?modal.Range = switch (obj) { '\'', '"', '`' => modal.enclosingQuote(lines, cur, @intCast(obj)), @@ -1415,102 +1428,105 @@ pub fn textobjectSelect(p: *Pardes, pane: *Pane, text: []const u8, obj: u21, aro a = modal.nextGrapheme(text, a); head = modal.prevGrapheme(text, head); } - pane.setRange(text, 0, .{ .anchor = a, .head = head }, false); + t.setRange(text, 0, .{ .anchor = a, .head = head }, false); } /// `ms`: wrap the selection (or the cursor char) in a pair; the wrap /// including the pair becomes the selection -pub fn surroundAdd(p: *Pardes, pane: *Pane, ch: u21) void { +pub fn surroundAdd(p: *Pardes, t: *Text, ch: u21) void { const pr = pairFor(ch) orelse return; - pane.select = false; - const eb = editTextEol(p, pane, selRows(pane)) orelse return; - const r = selRange(pane, eb.text, eb.row0); - pushUndo(p, pane); + t.select = false; + const eb = editTextEol(p, t, selRows(t)) orelse return; + const r = selRange(t, eb.text, eb.row0); + pushUndo(p, t); const close_col = modal.nextGrapheme(modal.lineSlice(eb.text, r.b.row), r.b.col); var new = modal.insertAt(p.gpa, eb.text, .{ .row = r.b.row, .col = close_col }, &[1]u8{pr.c}) catch return; - setEditText(p, pane, new); + setEditText(p, t, new); new = modal.insertAt(p.gpa, new, .{ .row = r.a.row, .col = r.a.col }, &[1]u8{pr.o}) catch return; - setEditText(p, pane, new); - pane.msel.active = false; - pane.vsel = .{ .active = true, .row = @as(i32, @intCast(r.a.row)) + eb.row0, .col = @intCast(r.a.col), .explicit = false }; - pane.cur_row = @as(i32, @intCast(r.b.row)) + eb.row0; - pane.cur_col = @intCast(close_col + @as(usize, if (r.a.row == r.b.row) 1 else 0)); - pane.cur_pinned = true; - pane.sticky_col = -1; - pane.ensureCursorVisible(); + setEditText(p, t, new); + t.msel.active = false; + t.vsel = .{ .active = true, .row = @as(i32, @intCast(r.a.row)) + eb.row0, .col = @intCast(r.a.col), .explicit = false }; + t.cur_row = @as(i32, @intCast(r.b.row)) + eb.row0; + t.cur_col = @intCast(close_col + @as(usize, if (r.a.row == r.b.row) 1 else 0)); + t.cur_pinned = true; + t.sticky_col = -1; + t.pane().ensureCursorVisible(); } /// `md`: delete the enclosing pair's chars; the cursor maps through -pub fn surroundDelete(p: *Pardes, pane: *Pane, ch: u21) void { +pub fn surroundDelete(p: *Pardes, t: *Text, ch: u21) void { const pr = pairFor(ch) orelse return; - const lines = paneCursorLines(p, pane) catch return; - const cur = pane.toModalCursor(); + const lines = paneCursorLines(p, t) catch return; + const cur = t.toModalCursor(); const r = (if (pr.o == pr.c) modal.enclosingQuote(lines, cur, pr.o) else modal.enclosingPair(lines, cur, pr.o, pr.c)) orelse return; const lo: i32 = @intCast(@min(r.a.row, cur.row)); const hi: i32 = @intCast(@max(r.b.row, cur.row)); - const eb = editText(p, pane, lo, hi, -1) orelse return; + const eb = editText(p, t, lo, hi, -1) orelse return; const text = eb.text; const drow = -eb.row0; // surface row -> buffer row const ra: modal.Cursor = .{ .row = @intCast(@as(i32, @intCast(r.a.row)) + drow), .col = r.a.col }; const rb: modal.Cursor = .{ .row = @intCast(@as(i32, @intCast(r.b.row)) + drow), .col = r.b.col }; - pushUndo(p, pane); + pushUndo(p, t); const a_off = modal.offsetAt(text, ra); const b_off = modal.offsetAt(text, rb); const cur_off = modal.offsetAt(text, .{ .row = @intCast(@as(i32, @intCast(cur.row)) + drow), .col = cur.col }); // the close first, so the open's position stays valid var new = modal.deleteChar(p.gpa, text, rb) catch return; - setEditText(p, pane, new); + setEditText(p, t, new); new = modal.deleteChar(p.gpa, new, ra) catch return; - setEditText(p, pane, new); + setEditText(p, t, new); var nc = cur_off; if (nc > b_off) nc -= 1; if (nc > a_off) nc -= 1; const cc = modal.positionAt(new, nc); - pane.cur_row = @as(i32, @intCast(cc.row)) + eb.row0; - pane.cur_col = @intCast(cc.col); - pane.vsel.active = false; - pane.msel.active = false; - pane.cur_pinned = true; - pane.ensureCursorVisible(); + t.cur_row = @as(i32, @intCast(cc.row)) + eb.row0; + t.cur_col = @intCast(cc.col); + t.vsel.active = false; + t.msel.active = false; + t.cur_pinned = true; + t.pane().ensureCursorVisible(); } /// `mr`: swap the enclosing pair's chars for 's -pub fn surroundReplace(p: *Pardes, pane: *Pane, from: u21, to: u21) void { +pub fn surroundReplace(p: *Pardes, t: *Text, from: u21, to: u21) void { const fp = pairFor(from) orelse return; const tp = pairFor(to) orelse return; - const lines = paneCursorLines(p, pane) catch return; - const cur = pane.toModalCursor(); + const lines = paneCursorLines(p, t) catch return; + const cur = t.toModalCursor(); const r = (if (fp.o == fp.c) modal.enclosingQuote(lines, cur, fp.o) else modal.enclosingPair(lines, cur, fp.o, fp.c)) orelse return; - const eb = editText(p, pane, @as(i32, @intCast(r.a.row)), @as(i32, @intCast(r.b.row)), -1) orelse return; + const eb = editText(p, t, @as(i32, @intCast(r.a.row)), @as(i32, @intCast(r.b.row)), -1) orelse return; const drow = -eb.row0; // surface row -> buffer row const ar: usize = @intCast(@as(i32, @intCast(r.a.row)) + drow); const br: usize = @intCast(@as(i32, @intCast(r.b.row)) + drow); - pushUndo(p, pane); + pushUndo(p, t); const out = p.gpa.dupe(u8, eb.text) catch return; out[modal.lineStartOffset(out, ar) + r.a.col] = tp.o; out[modal.lineStartOffset(out, br) + r.b.col] = tp.c; - setEditText(p, pane, out); + setEditText(p, t, out); } -pub fn pushUndo(p: *Pardes, pane: *Pane) void { +pub fn pushUndo(p: *Pardes, t: *Text) void { + const pane = t.pane(); // one keystroke, one undo step — even when it edited at ten cursors. if (p.multi_on and !p.multi_first) return; if (pane.file != null) return panes.File.pushUndo(p, pane); panes.Terminal.pushUndo(p, pane); } -pub fn doUndo(p: *Pardes, pane: *Pane) void { +pub fn doUndo(p: *Pardes, t: *Text) void { + const pane = t.pane(); if (pane.file != null) return panes.File.undo(p, pane); panes.Terminal.undo(p, pane); } -pub fn doRedo(p: *Pardes, pane: *Pane) void { +pub fn doRedo(p: *Pardes, t: *Text) void { + const pane = t.pane(); if (pane.file != null) return panes.File.redo(p, pane); panes.Terminal.redo(p, pane); } @@ -1564,14 +1580,14 @@ test "insert newline adds one indent level after a closing call" { defer p.deinit(); while (p.nextEffect()) |_| {} const pane = try p.setTestFile(" callback({})\n"); - pane.mode = .insert; - pane.cur_col = 16; + pane.body.mode = .insert; + pane.body.cur_col = 16; p.update(.{ .key = .{ .cp = Key.enter } }); try std.testing.expectEqualSlices(u8, " callback({})\n \n", pane.file.?.content); - try std.testing.expectEqual(@as(i32, 1), pane.cur_row); - try std.testing.expectEqual(@as(i32, 8), pane.cur_col); + try std.testing.expectEqual(@as(i32, 1), pane.body.cur_row); + try std.testing.expectEqual(@as(i32, 8), pane.body.cur_col); } test "insert and normal modes edit complete Unicode graphemes" { @@ -1580,41 +1596,41 @@ test "insert and normal modes edit complete Unicode graphemes" { defer p.deinit(); const pane = try p.setTestFile("a" ++ "e\u{301}" ++ "👩🏽\u{200d}🚀" ++ "界" ++ "z"); - pane.mode = .insert; - pane.cur_col = 22; // on z, after the CJK grapheme - insertKey(p, pane, .{ .cp = Key.left }); - try std.testing.expectEqual(@as(i32, 19), pane.cur_col); - insertKey(p, pane, .{ .cp = Key.left }); - try std.testing.expectEqual(@as(i32, 4), pane.cur_col); - insertKey(p, pane, .{ .cp = Key.right }); - try std.testing.expectEqual(@as(i32, 19), pane.cur_col); - insertKey(p, pane, .{ .cp = Key.backspace }); + pane.body.mode = .insert; + pane.body.cur_col = 22; // on z, after the CJK grapheme + insertKey(p, &pane.body, .{ .cp = Key.left }); + try std.testing.expectEqual(@as(i32, 19), pane.body.cur_col); + insertKey(p, &pane.body, .{ .cp = Key.left }); + try std.testing.expectEqual(@as(i32, 4), pane.body.cur_col); + insertKey(p, &pane.body, .{ .cp = Key.right }); + try std.testing.expectEqual(@as(i32, 19), pane.body.cur_col); + insertKey(p, &pane.body, .{ .cp = Key.backspace }); try std.testing.expectEqualStrings("ae\u{301}界z", pane.file.?.content); - try std.testing.expectEqual(@as(i32, 4), pane.cur_col); + try std.testing.expectEqual(@as(i32, 4), pane.body.cur_col); - pane.mode = .normal; - pane.cur_col = 1; - normalDelete(p, pane, false); + pane.body.mode = .normal; + pane.body.cur_col = 1; + normalDelete(p, &pane.body, false); try std.testing.expectEqualStrings("a界z", pane.file.?.content); - try std.testing.expectEqual(@as(i32, 1), pane.cur_col); - normalReplaceChar(p, pane, 'λ'); + try std.testing.expectEqual(@as(i32, 1), pane.body.cur_col); + normalReplaceChar(p, &pane.body, 'λ'); try std.testing.expectEqualStrings("aλz", pane.file.?.content); panes.File.setContent(p, &pane.file.?, try gpa.dupe(u8, "界a")); - pane.cur_col = 3; - pane.vsel = .{ .active = true, .row = 0, .col = 0, .explicit = true }; - normalReplaceChar(p, pane, 'λ'); + pane.body.cur_col = 3; + pane.body.vsel = .{ .active = true, .row = 0, .col = 0, .explicit = true }; + normalReplaceChar(p, &pane.body, 'λ'); try std.testing.expectEqualStrings("λλ", pane.file.?.content); - try std.testing.expectEqual(@as(i32, 2), pane.cur_col); - try std.testing.expectEqual(@as(i32, 0), pane.vsel.col); + try std.testing.expectEqual(@as(i32, 2), pane.body.cur_col); + try std.testing.expectEqual(@as(i32, 0), pane.body.vsel.col); panes.File.setContent(p, &pane.file.?, try gpa.dupe(u8, "界a")); - pane.cur_col = 0; - pane.vsel = .{ .active = true, .row = 0, .col = 3, .explicit = true }; - normalReplaceChar(p, pane, 'λ'); + pane.body.cur_col = 0; + pane.body.vsel = .{ .active = true, .row = 0, .col = 3, .explicit = true }; + normalReplaceChar(p, &pane.body, 'λ'); try std.testing.expectEqualStrings("λλ", pane.file.?.content); - try std.testing.expectEqual(@as(i32, 0), pane.cur_col); - try std.testing.expectEqual(@as(i32, 2), pane.vsel.col); + try std.testing.expectEqual(@as(i32, 0), pane.body.cur_col); + try std.testing.expectEqual(@as(i32, 2), pane.body.vsel.col); } test "flat text replacement preserves a terminal fragment origin and direction" { @@ -1622,23 +1638,23 @@ test "flat text replacement preserves a terminal fragment origin and direction" defer p.deinit(); p.update(.{ .output = .{ .pane = 0, .bytes = "first\r\nsecond\r\nthird\r\n界a\r\n" } }); const pane = p.panes[0].?; - pane.mode = .normal; - pane.cur_pinned = true; - pane.cur_row = 3; - pane.cur_col = 0; - pane.vsel = .{ .active = true, .row = 3, .col = 3, .explicit = true }; - normalReplaceChar(p, pane, 'λ'); + pane.body.mode = .normal; + pane.body.cur_pinned = true; + pane.body.cur_row = 3; + pane.body.cur_col = 0; + pane.body.vsel = .{ .active = true, .row = 3, .col = 3, .explicit = true }; + normalReplaceChar(p, &pane.body, 'λ'); try std.testing.expectEqual(@as(i32, 3), pane.ovl.?.row); try std.testing.expectEqualStrings("λλ", pane.ovl.?.text); - try std.testing.expectEqual(@as(i32, 3), pane.cur_row); - try std.testing.expectEqual(@as(i32, 0), pane.cur_col); - try std.testing.expectEqual(@as(i32, 3), pane.vsel.row); - try std.testing.expectEqual(@as(i32, 2), pane.vsel.col); - try std.testing.expect(pane.vsel.active and pane.vsel.explicit); - const lines = try paneCursorLines(p, pane); + try std.testing.expectEqual(@as(i32, 3), pane.body.cur_row); + try std.testing.expectEqual(@as(i32, 0), pane.body.cur_col); + try std.testing.expectEqual(@as(i32, 3), pane.body.vsel.row); + try std.testing.expectEqual(@as(i32, 2), pane.body.vsel.col); + try std.testing.expect(pane.body.vsel.active and pane.body.vsel.explicit); + const lines = try paneCursorLines(p, &pane.body); try std.testing.expectEqualStrings("first", lines[0]); try std.testing.expectEqualStrings("λλ", lines[3]); - const flat = try flatSurface(p, pane); + const flat = try flatSurface(p, &pane.body); try std.testing.expect(std.mem.startsWith(u8, flat, "first\nsecond\nthird\nλλ\n")); } diff --git a/src/exec.zig b/src/exec.zig index 75d07441..0a9d6f31 100644 --- a/src/exec.zig +++ b/src/exec.zig @@ -38,13 +38,13 @@ pub fn takesCommandLine(p: *const Pardes, id: usize) bool { } pub fn chordEachSel(p: *Pardes, pane: *Pane, cmd: Builtin) bool { - if (pane.nsel == 0) return false; - const text = edit.flatSurface(p, pane) catch return false; - var ranges: [Pane.max_selections]modal.Selection = undefined; - const got = pane.ranges(text, 0, &ranges); + if (pane.body.nsel == 0) return false; + const text = edit.flatSurface(p, &pane.body) catch return false; + var ranges: [panes.Text.max_selections]modal.Selection = undefined; + const got = pane.body.ranges(text, 0, &ranges); if (got.n < 2) return false; - var texts: [Pane.max_selections][]u8 = undefined; + var texts: [panes.Text.max_selections][]u8 = undefined; var made: usize = 0; defer for (texts[0..made]) |t| p.gpa.free(t); for (ranges[0..got.n]) |range| { @@ -59,10 +59,10 @@ pub fn chordEachSel(p: *Pardes, pane: *Pane, cmd: Builtin) bool { const id = p.active; const serial = pane.serial; - pane.vsel.active = false; - pane.msel.active = false; - pane.select = false; - pane.nsel = 0; // the chord consumed them, exactly as it consumes one + pane.body.vsel.active = false; + pane.body.msel.active = false; + pane.body.select = false; + pane.body.nsel = 0; // the chord consumed them, exactly as it consumes one var primary_active: ?usize = null; for (texts[0..made], 0..) |txt, i| { @@ -96,7 +96,7 @@ pub const PointerOperand = struct { pub fn pointerOperand(p: *Pardes, pane: *Pane, clicked: Pane.Sel) PointerOperand { const visible = clicked.r0 - @as(i32, BOX_H); const wrapped = pane.wrapAt(visible); - const raw = pane.isTerminal() and pane.mode == .tty and clicked.r0 >= BOX_H; + const raw = pane.isTerminal() and pane.body.mode == .tty and clicked.r0 >= BOX_H; const row = if (raw) panes.Terminal.gridOffset(pane) + visible else wrapped.line; const raw_line = if (raw) modal.lineSlice(body_layer.bodyText(p, p.scratch.allocator(), pane) catch "", @intCast(@max(0, visible))) else ""; const col = if (raw) @@ -104,7 +104,7 @@ pub fn pointerOperand(p: *Pardes, pane: *Pane, clicked: Pane.Sel) PointerOperand else if (clicked.r0 >= BOX_H) edit.paneByteAtDisplay( p, - pane, + &pane.body, wrapped.line, wrapped.at, clicked.c0 - (if (pane.file != null) @as(i32, panes.File.gutterWidth(pane)) else 0), @@ -143,14 +143,14 @@ pub fn pointerOperand(p: *Pardes, pane: *Pane, clicked: Pane.Sel) PointerOperand result.preview = kept; return result; } - if (pane.vsel.active and pane.vsel.explicit and - edit.spanHas(row, col, pane.vsel.row, pane.vsel.col, pane.cur_row, pane.cur_col)) + if (pane.body.vsel.active and pane.body.vsel.explicit and + edit.spanHas(row, col, pane.body.vsel.row, pane.body.vsel.col, pane.body.cur_row, pane.body.cur_col)) { result.text = edit.currentSelText(p, pane); return result; } - if (pane.msel.active and row >= @min(pane.msel.r0, pane.msel.r1) and - row <= @max(pane.msel.r0, pane.msel.r1)) + if (pane.body.msel.active and row >= @min(pane.body.msel.r0, pane.body.msel.r1) and + row <= @max(pane.body.msel.r0, pane.body.msel.r1)) { result.text = edit.currentSelText(p, pane); return result; @@ -202,7 +202,7 @@ pub fn heldSelection(p: *Pardes, first: usize) ?[]const u8 { }; if (t.sel[sel_slot].state == .done) { if (edit.selectionText(p, t, t.sel[sel_slot]) catch null) |tx| return tx; - } else if ((t.vsel.active and t.vsel.explicit) or t.msel.active) { + } else if ((t.body.vsel.active and t.body.vsel.explicit) or t.body.msel.active) { if (edit.currentSelText(p, t)) |tx| return tx; } } @@ -302,7 +302,7 @@ fn spawnTtyWithMount(p: *Pardes, from: usize, v9fs: bool) void { const nt = p.newShell(free, Pardes.paneDir(src)) catch return; nt.greet = !v9fs; nt.v9fs_on_spawn = v9fs; - nt.mode = .tty; + nt.body.mode = .tty; const parent = layout.splitParent(p, from); const f = layout.findPane(p, parent).?; layout.insert(p, f.col, f.idx + 1, free); @@ -558,8 +558,8 @@ test "the acme chords act once per selection, not once on the primary" { .{ .anchor = 0, .head = 6 }, .{ .anchor = 7, .head = 13 }, }; - pane.setRanges(pane.file.?.content, &ranges, &.{}, 0, true); - try std.testing.expectEqual(@as(u8, 1), pane.nsel); + pane.body.setRanges(pane.file.?.content, &ranges, &.{}, 0, true); + try std.testing.expectEqual(@as(u8, 1), pane.body.nsel); const before = p.ncol; p.update(.{ .key = .{ .cp = Key.tab } }); // config.exec_key: Exec @@ -567,5 +567,5 @@ test "the acme chords act once per selection, not once on the primary" { // other cursor, so one keystroke over two cursors made one column. try std.testing.expectEqual(before + 2, p.ncol); // ...and the chord consumed the selection exactly as it does with one. - try std.testing.expectEqual(@as(u8, 0), p.panes[0].?.nsel); + try std.testing.expectEqual(@as(u8, 0), p.panes[0].?.body.nsel); } diff --git a/src/gui/gui.zig b/src/gui/gui.zig index a11b22c7..97bbc816 100644 --- a/src/gui/gui.zig +++ b/src/gui/gui.zig @@ -1399,7 +1399,7 @@ test "GUI completion failure survives backlog and leaves the document unchanged" const core = try pardes.Pardes.init(gpa, .{ .tty_only = true }); defer core.deinit(); const pane = try core.setTestFile("abc"); - pane.cur_col = 1; + pane.body.cur_col = 1; core.lspRequest(core.active, .completion, ""); const id = core.lsp_wait.?.id; var workers: LspWorkers = .{}; @@ -1426,7 +1426,7 @@ test "GUI completion failure survives backlog and leaves the document unchanged" shell.drainQueue(); try std.testing.expect(core.lsp_wait == null); try std.testing.expectEqualStrings("abc", pane.file.?.content); - try std.testing.expectEqual(@as(i32, 1), pane.cur_col); + try std.testing.expectEqual(@as(i32, 1), pane.body.cur_col); try std.testing.expect(shell.saw_event); } @@ -1611,7 +1611,7 @@ test "GUI LSP worker limit rejects before allocation and recovers after owned wo const core = try pardes.Pardes.init(gpa, .{ .tty_only = true }); defer core.deinit(); const pane = try core.setTestFile("abc"); - pane.cur_col = 1; + pane.body.cur_col = 1; var workers: LspWorkers = .{}; var gate: std.Io.Event = .unset; var threads: [LspWorkers.capacity]?std.Thread = @splat(null); @@ -1650,7 +1650,7 @@ test "GUI LSP worker limit rejects before allocation and recovers after owned wo }); try std.testing.expect(core.lsp_wait == null); try std.testing.expectEqualStrings("abc", pane.file.?.content); - try std.testing.expectEqual(@as(i32, 1), pane.cur_col); + try std.testing.expectEqual(@as(i32, 1), pane.body.cur_col); try std.testing.expect(std.mem.indexOf(u8, pane.msg[0..pane.msg_len], "WorkersBusy") != null); try std.testing.expectEqual(@as(usize, 0), failing.alloc_index); try std.testing.expect(!failing.has_induced_failure); @@ -1762,8 +1762,8 @@ test "GUI worker setup failures finish matching LSP and pipe requests" { try std.testing.expect(core.lsp_wait == null); try std.testing.expectEqualStrings("abc", pane.file.?.content); - pane.cur_col = 2; - pane.vsel = .{ .active = true, .row = 0, .col = 0, .explicit = true }; + pane.body.cur_col = 2; + pane.body.vsel = .{ .active = true, .row = 0, .col = 0, .explicit = true }; core.update(.{ .key = .{ .cp = '|' } }); core.update(.{ .key = .{ .cp = 't', .text = "tr a-z A-Z" } }); core.update(.{ .key = .{ .cp = pardes.Key.enter } }); @@ -3870,7 +3870,7 @@ const Shell = struct { s.closePty(e.pane); if (e.failure) |err| { if (s.core.panes[e.pane]) |pane| { - pane.mode = .normal; + pane.body.mode = .normal; s.core.reportError(e.pane, "terminal reader", err); } } else s.core.update(.{ .eof = .{ .pane = e.pane } }); diff --git a/src/host_io.zig b/src/host_io.zig index d0b9de71..959ce3bd 100644 --- a/src/host_io.zig +++ b/src/host_io.zig @@ -322,7 +322,7 @@ pub const Lsp = struct { const path = try gpa.dupe(u8, "/file.zig"); gpa.free(pane.file.?.path); pane.file.?.path = path; - pane.cur_col = 6; + pane.body.cur_col = 6; const revision = pane.file.?.revision; const undo_len = pane.file.?.history.undo_len; var failing = std.testing.FailingAllocator.init(gpa, .{}); diff --git a/src/layout.zig b/src/layout.zig index 3d8932a8..49da0207 100644 --- a/src/layout.zig +++ b/src/layout.zig @@ -704,7 +704,7 @@ pub fn focusDir(p: *Pardes, from: usize, dir: enum { left, right, up, down }) vo if (best) |b| { p.active = b; // a count typed before the hop was meant for the pane you left - p.panes[b].?.normal.clear(); + p.panes[b].?.body.normal.clear(); } } diff --git a/src/look.zig b/src/look.zig index 1534d332..efc3f312 100644 --- a/src/look.zig +++ b/src/look.zig @@ -482,15 +482,15 @@ pub fn expandedSel(p: *Pardes, pane: *Pane, at: Pane.Sel) ?Pane.Sel { /// the word under the modal cursor as a pane-local selection (paneText /// coords: row 0 is the tag; file panes carry the line-number prefix) pub fn cursorWordSel(p: *Pardes, pane: *Pane) Pane.Sel { - const w = pane.wrapRow(pane.cur_row, pane.cur_col); + const w = pane.wrapRow(pane.body.cur_row, pane.body.cur_col); const vrow = w.row + @as(i32, BOX_H); const vcol = if (pane.file != null) - panes.File.displayOffset(pane, pane.cur_row, w.at, pane.cur_col) + @as(i32, panes.File.gutterWidth(pane)) + panes.File.displayOffset(pane, pane.body.cur_row, w.at, pane.body.cur_col) + @as(i32, panes.File.gutterWidth(pane)) else blk: { - const lines = edit.paneCursorLines(p, pane) catch break :blk pane.cur_col; - const local = pane.cur_row; - if (local < 0 or @as(usize, @intCast(local)) >= lines.len) break :blk pane.cur_col; - break :blk panes.File.lineDisplayOffset(lines[@intCast(local)], @intCast(@max(0, w.at)), @intCast(@max(0, pane.cur_col))); + const lines = edit.paneCursorLines(p, &pane.body) catch break :blk pane.body.cur_col; + const local = pane.body.cur_row; + if (local < 0 or @as(usize, @intCast(local)) >= lines.len) break :blk pane.body.cur_col; + break :blk panes.File.lineDisplayOffset(lines[@intCast(local)], @intCast(@max(0, w.at)), @intCast(@max(0, pane.body.cur_col))); }; return .{ .state = .done, .c0 = vcol, .c1 = vcol, .r0 = vrow, .r1 = vrow }; } @@ -526,9 +526,9 @@ fn lookFirstHit(p: *Pardes, id: usize) void { if (p.active != rid) return; // walked out of the list; leave it there const txt = edit.currentSelText(p, rp) orelse return; // spent, exactly as the look chord spends it (handleKey) - rp.vsel.active = false; - rp.msel.active = false; - rp.select = false; + rp.body.vsel.active = false; + rp.body.msel.active = false; + rp.body.select = false; exec.runBuiltin(p, config.look_cmd, rid, "", txt); } @@ -587,7 +587,7 @@ pub fn runSearch(p: *Pardes, id: usize, pat_raw: []const u8, kind: Search, start anchor = found.anchor; } } else { - const lines = try edit.paneCursorLines(p, pane); + const lines = try edit.paneCursorLines(p, &pane.body); // a real file names itself; a terminal or an output buffer has no path const has_path = if (pane.file) |f| f.output == null else false; var idbuf: [16]u8 = undefined; @@ -597,8 +597,8 @@ pub fn runSearch(p: *Pardes, id: usize, pat_raw: []const u8, kind: Search, start std.fs.path.basename(pane.file.?.path) else std.fmt.bufPrint(&idbuf, config.pane_addr ++ "{d}", .{id}) catch return error.PathTooLong; - const cl: usize = @intCast(@max(0, pane.cur_row)); - const cc: usize = @intCast(@max(0, pane.cur_col)); + const cl: usize = @intCast(@max(0, pane.body.cur_row)); + const cc: usize = @intCast(@max(0, pane.body.cur_col)); for (lines, 0..) |ln, i| { const at = std.ascii.indexOfIgnoreCase(ln, pat) orelse continue; const row = try std.fmt.allocPrint(arena, "{s}:{d}:{d}{c}{d} {s}\n", .{ @@ -656,11 +656,11 @@ pub fn jumpResult(p: *Pardes, id: usize, row: usize) bool { if (ln.len == 0) return false; const r: i32 = @intCast(row); pane.search_row = row; - rp.msel = .{ .active = true, .r0 = r, .r1 = r }; - rp.vsel.active = false; - rp.nsel = 0; - rp.cur_row = r; - rp.cur_pinned = true; + rp.body.msel = .{ .active = true, .r0 = r, .r1 = r }; + rp.body.vsel.active = false; + rp.body.nsel = 0; + rp.body.cur_row = r; + rp.body.cur_pinned = true; const off = rp.scroll(); const last = off + @as(i32, rp.rows) - 1; if (r < off) rp.scrollBy(r - off) else if (r > last) rp.scrollBy(r - last); @@ -676,14 +676,14 @@ pub fn jumpResult(p: *Pardes, id: usize, row: usize) bool { null; }; if (span) |selected| { - rp.cur_col = @intCast(selected.start); + rp.body.cur_col = @intCast(selected.start); rp.look_at = .{ .row = r, .col0 = @intCast(selected.start), .col1 = @intCast(selected.end - 1), }; } else { - rp.cur_col = 0; + rp.body.cur_col = 0; rp.look_at = null; } if (tr.commands) { @@ -692,7 +692,7 @@ pub fn jumpResult(p: *Pardes, id: usize, row: usize) bool { lookAt(p, rid, ln[selected.start..selected.end]); // This is the newly visited result, not a selection carried into // the destination. Look cleared the previous source selection. - rp.msel = .{ .active = true, .r0 = r, .r1 = r }; + rp.body.msel = .{ .active = true, .r0 = r, .r1 = r }; } armLookWalk(p, rid); return true; @@ -705,9 +705,9 @@ fn lookEdge(delta: i32) LookFrom { } fn lookStand(pane: *Pane) LookFrom { - if (pane.look_at) |s| if (s.row == pane.cur_row and s.col0 == pane.cur_col) + if (pane.look_at) |s| if (s.row == pane.body.cur_row and s.col0 == pane.body.cur_col) return .{ .row = s.row, .col = s.col0, .strict = true }; - return .{ .row = pane.cur_row, .col = pane.cur_col }; + return .{ .row = pane.body.cur_row, .col = pane.body.cur_col }; } fn lookWalkPanes(p: *Pardes, out: *[MAX_PANES]usize) []const usize { @@ -759,7 +759,7 @@ fn wholeRowSpan(ln: []const u8) ?Span { } fn lookSpanIn(p: *Pardes, pane: *Pane, from: LookFrom, delta: i32, budget: *usize) ?Pane.LookSpot { - const lines = edit.paneCursorLines(p, pane) catch return null; + const lines = edit.paneCursorLines(p, &pane.body) catch return null; const nrows: i32 = @intCast(lines.len); if (nrows == 0) return null; const grain: panes.Output.Grain = if (pane.file) |*f| panes.Output.grain(f.output) else .word; @@ -835,13 +835,13 @@ pub fn lookWalk(p: *Pardes, delta: i32) void { } fn landLookSpot(p: *Pardes, id: usize, pane: *Pane, spot: Pane.LookSpot) void { - edit.pinPaneCursor(p, pane); // fresh out of tty mode the cursor still tracks the shell - pane.vsel = .{ .active = true, .row = spot.row, .col = spot.col1, .explicit = true }; - pane.msel.active = false; - pane.nsel = 0; - pane.cur_row = spot.row; - pane.cur_col = spot.col0; - pane.cur_pinned = true; + edit.pinPaneCursor(p, &pane.body); // fresh out of tty mode the cursor still tracks the shell + pane.body.vsel = .{ .active = true, .row = spot.row, .col = spot.col1, .explicit = true }; + pane.body.msel.active = false; + pane.body.nsel = 0; + pane.body.cur_row = spot.row; + pane.body.cur_col = spot.col0; + pane.body.cur_pinned = true; pane.look_at = spot; p.look_walk_owner = pane.serial; p.active = id; @@ -944,7 +944,7 @@ pub fn focusPaneLine(p: *Pardes, id: usize, at: Spot, landing: enum { center, ke if (id >= MAX_PANES) return; const pane = p.panes[id] orelse return; p.active = id; - pane.normal.clear(); + pane.body.normal.clear(); if (pane.hasPdf()) { if (landing == .keep) return; if (comptime pdf_enabled) { @@ -964,21 +964,21 @@ pub fn focusPaneLine(p: *Pardes, id: usize, at: Spot, landing: enum { center, ke } } } - pane.cur_row = @intCast(at.line - 1); - pane.cur_col = if (at.col > 0) @intCast(at.col - 1) else 0; - pane.cur_pinned = true; + pane.body.cur_row = @intCast(at.line - 1); + pane.body.cur_col = if (at.col > 0) @intCast(at.col - 1) else 0; + pane.body.cur_pinned = true; if (at.end_line != 0) return selectSpan(p, pane, at); pane.ensureCursorVisible(); } fn selectSpan(p: *Pardes, pane: *Pane, at: Spot) void { - const text = edit.flatSurface(p, pane) catch return; + const text = edit.flatSurface(p, &pane.body) catch return; // saturating, not `- 1`: `f.zig:0-5` is a legal thing to type and a // 1-based zero is the same nothing an absent number is const acol: i32 = @intCast(at.col -| 1); const ecol: i32 = if (at.end_col > 0) @intCast(at.end_col - 1) else std.math.maxInt(i32); - const r = Pane.cellRange(text, @intCast(at.line -| 1), acol, @intCast(at.end_line -| 1), ecol); - pane.setRange(text, 0, r, true); + const r = panes.Text.cellRange(text, @intCast(at.line -| 1), acol, @intCast(at.end_line -| 1), ecol); + pane.body.setRange(text, 0, r, true); } fn openPaneTarget(p: *const Pardes, path: []const u8, at: Spot) ?Target { @@ -1006,13 +1006,13 @@ fn focusPaneByPath(p: *Pardes, path: []const u8, at: Spot) bool { /// Navigation starts a new selection at the destination. pub fn clearNavigationSelection(p: *Pardes, pane: *Pane) void { - pane.vsel = .{}; - pane.msel = .{}; - pane.nsel = 0; - pane.select = false; - pane.normal.clear(); - pane.append_at = null; - pane.sticky_col = -1; + pane.body.vsel = .{}; + pane.body.msel = .{}; + pane.body.nsel = 0; + pane.body.select = false; + pane.body.normal.clear(); + pane.body.append_at = null; + pane.body.sticky_col = -1; for (0..pane.sel.len) |slot| pane.clearPointerSelection(slot); pane.sel = @splat(.{}); if (comptime pdf_enabled) if (pane.pdf) |*state| { @@ -1150,7 +1150,7 @@ pub fn lookAt(p: *Pardes, id: usize, operand: []const u8) void { const found = resolveLookTarget(p, id, txt, &realbuf); switch (found) { .none => { - const bmode = if (pane.tag_edit) pane.tag_mode else pane.mode; + const bmode = if (pane.tag_edit) pane.tag_mode else pane.body.mode; if (pane.image != null or bmode == .tty) return; runSearch(p, id, trimmed, .text, .cursor) catch |err| { p.reportError(id, "search", err); @@ -1203,7 +1203,7 @@ pub fn lookAt(p: *Pardes, id: usize, operand: []const u8) void { const free = p.freeSlot() orelse return p.reportError(id, "look", error.NoPaneSlots); const nt = panes.File.open(p, free, target.path, target.at.line) catch |err| return p.reportError(id, "look", err); - if (target.at.col > 0) nt.cur_col = @intCast(target.at.col - 1); + if (target.at.col > 0) nt.body.cur_col = @intCast(target.at.col - 1); exec.placeDoc(p, id, free, nt); layout.compute(p); nt.file.?.scroll -|= @max(1, p.rects[free].h -| BOX_H) / 2; @@ -1249,7 +1249,7 @@ test "Look hover waits without mutating the pane and input cancels it" { const selections_before = pane.sel; const active_before = p.active; - const cursor_before = .{ pane.cur_row, pane.cur_col }; + const cursor_before = .{ pane.body.cur_row, pane.body.cur_col }; const jumps_before = .{ p.njumps, p.jcur, p.n_look_src }; const effects_before = p.effects_len; @@ -1276,7 +1276,7 @@ test "Look hover waits without mutating the pane and input cancels it" { // Resolving and displaying the operand is observational only. try std.testing.expect(std.meta.eql(selections_before, pane.sel)); try std.testing.expectEqual(active_before, p.active); - try std.testing.expectEqual(cursor_before, .{ pane.cur_row, pane.cur_col }); + try std.testing.expectEqual(cursor_before, .{ pane.body.cur_row, pane.body.cur_col }); try std.testing.expectEqual(jumps_before, .{ p.njumps, p.jcur, p.n_look_src }); try std.testing.expectEqual(effects_before, p.effects_len); @@ -1436,8 +1436,8 @@ test "Look copies its operand before releasing pointer selection storage" { }; p.drag = .{ .select = .{ .id = 0, .button = config.select_button } }; lookAt(p, 0, operand); - try std.testing.expectEqual(@as(i32, 2), pane.cur_row); - try std.testing.expectEqual(@as(i32, 1), pane.cur_col); + try std.testing.expectEqual(@as(i32, 2), pane.body.cur_row); + try std.testing.expectEqual(@as(i32, 1), pane.body.cur_col); try std.testing.expect(pane.pointer_selections[0] == null); try std.testing.expectEqual(.none, pane.sel[0].state); try std.testing.expectEqual(.none, p.drag); @@ -1448,10 +1448,10 @@ test "Look ignores missing and out of bounds pane addresses" { defer p.deinit(); const pane = try p.setTestFile("alpha\nbravo\n"); for ([_][]const u8{ config.pane_addr ++ "15:2", config.pane_addr ++ "999999:2" }) |operand| { - pane.setRange(pane.file.?.content, 0, .{ .anchor = 0, .head = 3 }, true); + pane.body.setRange(pane.file.?.content, 0, .{ .anchor = 0, .head = 3 }, true); lookAt(p, 0, operand); try std.testing.expectEqual(@as(usize, 0), p.active); - try std.testing.expectEqual(@as(i32, 0), pane.cur_row); - try std.testing.expect(!pane.vsel.active); + try std.testing.expectEqual(@as(i32, 0), pane.body.cur_row); + try std.testing.expect(!pane.body.vsel.active); } } diff --git a/src/macos.zig b/src/macos.zig index ccbb5dd5..c9c83a2d 100644 --- a/src/macos.zig +++ b/src/macos.zig @@ -338,8 +338,8 @@ test "mac worker setup failures finish matching LSP and pipe requests" { try std.testing.expect(core.lsp_wait == null); try std.testing.expectEqualStrings("abc", pane.file.?.content); - pane.cur_col = 2; - pane.vsel = .{ .active = true, .row = 0, .col = 0, .explicit = true }; + pane.body.cur_col = 2; + pane.body.vsel = .{ .active = true, .row = 0, .col = 0, .explicit = true }; core.update(.{ .key = .{ .cp = '|' } }); core.update(.{ .key = .{ .cp = 't', .text = "tr a-z A-Z" } }); core.update(.{ .key = .{ .cp = pardes.Key.enter } }); @@ -1465,8 +1465,8 @@ test "mac Restore keeps host state and rejects callbacks from the old core" { try std.testing.expect(st.core.lsp_wait == null); const pane = st.core.panes[0].?; - pane.cur_col = 4; - pane.vsel = .{ .active = true, .row = 0, .col = 0, .explicit = true }; + pane.body.cur_col = 4; + pane.body.vsel = .{ .active = true, .row = 0, .col = 0, .explicit = true }; st.core.update(.{ .key = .{ .cp = '|' } }); st.core.update(.{ .key = .{ .cp = 't', .text = "tr a-z A-Z" } }); st.core.update(.{ .key = .{ .cp = pardes.Key.enter } }); diff --git a/src/mouse.zig b/src/mouse.zig index 2a00bded..a840c8fc 100644 --- a/src/mouse.zig +++ b/src/mouse.zig @@ -378,7 +378,7 @@ pub fn handleMouse(p: *Pardes, m: Mouse) void { // next cursor move or left wheel pulls it back } else if (pane.file != null and !p.settings.wrap) { // wrapped there is nothing off to the right to reach - const line = panes.File.sourceLine(pane, pane.cur_row); + const line = panes.File.sourceLine(pane, pane.body.cur_row); const visual = panes.File.rawDisplayCol(line, @intCast(@max(0, pane.hscroll))); const next: usize = if (m.button == .wheel_right) visual +| @as(usize, @intCast(config.wheel_cols)) @@ -682,7 +682,7 @@ fn gestureRange(p: *Pardes, id: usize, text: []const u8, on_tag: bool, operand: const top = @min(sel.r0, sel.r1) - @as(i32, BOX_H); if (top < 0) break :lead null; const w = pane.wrapAt(top); - const col = edit.paneByteAtDisplay(p, pane, w.line, w.at, @min(sel.c0, sel.c1) - panes.File.gutterWidth(pane)); + const col = edit.paneByteAtDisplay(p, &pane.body, w.line, w.at, @min(sel.c0, sel.c1) - panes.File.gutterWidth(pane)); break :lead .{ .row = @intCast(@max(0, w.line)), .col = @intCast(@max(0, col)), @@ -720,22 +720,22 @@ fn mirrorTtySelection(p: *Pardes, pane: *Pane) void { const body = body_layer.bodyText(p, p.scratch.allocator(), pane) catch return; const line = modal.lineSlice(body, @intCast(@max(0, endpoint.row - panes.Terminal.gridOffset(pane)))); const byte = if (gesture.c1 >= gesture.c0) modal.prevGrapheme(line, @min(endpoint.hi, line.len)) else endpoint.lo; - pane.cur_row = pane.surfRow(endpoint.row); + pane.body.cur_row = pane.surfRow(endpoint.row); var shown = std.mem.trimEnd(u8, line[@min(endpoint.prompt_bytes, line.len)..], " \t"); if (pane.ovl) |overlay| { - const relative = pane.cur_row - overlay.row; + const relative = pane.body.cur_row - overlay.row; if (relative >= 0 and relative < modal.lineCount(overlay.text)) shown = modal.lineSlice(overlay.text, @intCast(relative)); } - pane.cur_col = @intCast(modal.graphemeStart(shown, @min(shown.len, byte -| endpoint.prompt_bytes))); - pane.cur_pinned = true; - pane.msel.active = false; - pane.vsel.active = false; - pane.nsel = 0; - pane.select = false; - pane.append_at = null; - pane.sticky_col = -1; - pane.normal.clear(); + pane.body.cur_col = @intCast(modal.graphemeStart(shown, @min(shown.len, byte -| endpoint.prompt_bytes))); + pane.body.cur_pinned = true; + pane.body.msel.active = false; + pane.body.vsel.active = false; + pane.body.nsel = 0; + pane.body.select = false; + pane.body.append_at = null; + pane.body.sticky_col = -1; + pane.body.normal.clear(); edit.setYank(p, text); } @@ -813,27 +813,27 @@ fn dragRelease(p: *Pardes, button: Mouse.Button) void { const dragged = sl.c0 != sl.c1 or sl.r0 != sl.r1; if (!dragged) pane.sel[sel_slot].state = .none; if (dragged) edit.capturePointerSelection(p, pane, sel_slot) catch {}; - if (dragged and pane.mode == .tty) mirrorTtySelection(p, pane); + if (dragged and pane.body.mode == .tty) mirrorTtySelection(p, pane); const body_vis = sl.r1 - @as(i32, BOX_H); - if (body_vis >= 0 and pane.mode != .tty) { + if (body_vis >= 0 and pane.body.mode != .tty) { const w = pane.wrapAt(body_vis); - pane.cur_row = w.line; - pane.cur_col = edit.paneByteAtDisplay( + pane.body.cur_row = w.line; + pane.body.cur_col = edit.paneByteAtDisplay( p, - pane, + &pane.body, w.line, w.at, sl.c1 - (if (pane.file != null) @as(i32, panes.File.gutterWidth(pane)) else 0), ); - pane.cur_pinned = true; - if (edit.clampFileCursor(pane)) pane.ensureCursorVisible(); - pane.msel.active = false; - pane.normal.clear(); - pane.vsel.active = false; - pane.nsel = 0; // a click says WHERE the one cursor is - pane.select = false; - pane.append_at = null; - pane.sticky_col = -1; + pane.body.cur_pinned = true; + if (edit.clampFileCursor(&pane.body)) pane.ensureCursorVisible(); + pane.body.msel.active = false; + pane.body.normal.clear(); + pane.body.vsel.active = false; + pane.body.nsel = 0; // a click says WHERE the one cursor is + pane.body.select = false; + pane.body.append_at = null; + pane.body.sticky_col = -1; if (s.ctrl) p.lspRequest(s.id, .definition, ""); } } else { @@ -842,7 +842,7 @@ fn dragRelease(p: *Pardes, button: Mouse.Button) void { // this file -- a sticky context header's number included, // since the row map holds each header's own source line. if (s.button == config.look_button and clk.r0 >= BOX_H and clk.r0 == clk.r1 and - clk.c0 == clk.c1 and clk.c0 >= 0 and pane.mode != .tty) + clk.c0 == clk.c1 and clk.c0 >= 0 and pane.body.mode != .tty) if (pane.file) |f| if (f.output == null and clk.c0 < panes.File.gutterWidth(pane)) { const line = pane.wrapAt(clk.r0 - BOX_H).line; if (line >= 0) { @@ -858,10 +858,10 @@ fn dragRelease(p: *Pardes, button: Mouse.Button) void { pane.sel[b] = expanded else if (operand.text == null) pane.sel[b].state = .none; - if (s.button == config.look_button and clk.r0 >= BOX_H and pane.mode != .tty) { - pane.cur_row = operand.row; - pane.cur_col = operand.col; - if (edit.clampFileCursor(pane)) pane.ensureCursorVisible(); + if (s.button == config.look_button and clk.r0 >= BOX_H and pane.body.mode != .tty) { + pane.body.cur_row = operand.row; + pane.body.cur_col = operand.col; + if (edit.clampFileCursor(&pane.body)) pane.ensureCursorVisible(); } const txt = operand.text; const cmd = if (s.button == config.look_button) config.look_cmd else config.exec_cmd; @@ -909,7 +909,7 @@ fn chordCutPaste(p: *Pardes, cut: bool) void { if (cut and pv.selection_text.len > 0) edit.setYank(p, pv.selection_text); return; }; - if (pane.mode == .tty) { + if (pane.body.mode == .tty) { if (!s.chorded) { s.chorded = true; pane.sel[sel_slot].state = .none; // drop the sweep highlight @@ -944,44 +944,44 @@ fn chordCutPaste(p: *Pardes, cut: bool) void { const w1 = pane.wrapAt(@max(0, sl.r1 - @as(i32, BOX_H))); const row0 = w0.line; const row1 = w1.line; - const col0 = edit.paneByteAtDisplay(p, pane, w0.line, w0.at, sl.c0 - pfx); - const col1 = edit.paneByteAtDisplay(p, pane, w1.line, w1.at, sl.c1 - pfx); - pane.cur_row = row1; - pane.cur_col = col1; - pane.cur_pinned = true; - pane.msel.active = false; - pane.normal.clear(); - if (!pane.isTerminal()) pane.mode = .normal; - pane.vsel = .{ .active = row0 != row1 or col0 != col1, .row = row0, .col = col0, .explicit = false }; - pane.nsel = 0; + const col0 = edit.paneByteAtDisplay(p, &pane.body, w0.line, w0.at, sl.c0 - pfx); + const col1 = edit.paneByteAtDisplay(p, &pane.body, w1.line, w1.at, sl.c1 - pfx); + pane.body.cur_row = row1; + pane.body.cur_col = col1; + pane.body.cur_pinned = true; + pane.body.msel.active = false; + pane.body.normal.clear(); + if (!pane.isTerminal()) pane.body.mode = .normal; + pane.body.vsel = .{ .active = row0 != row1 or col0 != col1, .row = row0, .col = col0, .explicit = false }; + pane.body.nsel = 0; } if (cut) { - if (pane.vsel.active) edit.normalDelete(p, pane, true); - } else if (pane.vsel.active) { - edit.normalReplaceYank(p, pane); + if (pane.body.vsel.active) edit.normalDelete(p, &pane.body, true); + } else if (pane.body.vsel.active) { + edit.normalReplaceYank(p, &pane.body); } else if (pane.file) |*f| { // bare cursor: splice the register in literally (no linewise // magic) so a paste right after a cut restores the text exactly const y = p.yank orelse return; if (y.len == 0) return; - const at = modal.Cursor{ .row = @intCast(@max(0, pane.cur_row)), .col = @intCast(@max(0, pane.cur_col)) }; - edit.pushUndo(p, pane); + const at = modal.Cursor{ .row = @intCast(@max(0, pane.body.cur_row)), .col = @intCast(@max(0, pane.body.cur_col)) }; + edit.pushUndo(p, &pane.body); const new = modal.insertAt(p.gpa, f.content, at, y) catch return; panes.File.setContent(p, f, new); - pane.vsel = .{ .active = modal.nextGrapheme(y, 0) < y.len, .row = @intCast(at.row), .col = @intCast(at.col), .explicit = false }; + pane.body.vsel = .{ .active = modal.nextGrapheme(y, 0) < y.len, .row = @intCast(at.row), .col = @intCast(at.col), .explicit = false }; const end = modal.advanceBy(at, y); if (end.col > 0) { - pane.cur_row = @intCast(end.row); - pane.cur_col = @intCast(modal.prevGrapheme(modal.lineSlice(f.content, end.row), end.col)); + pane.body.cur_row = @intCast(end.row); + pane.body.cur_col = @intCast(modal.prevGrapheme(modal.lineSlice(f.content, end.row), end.col)); } else { // the register ended in '\n': the cursor lands ON that newline - pane.cur_row = @intCast(end.row -| 1); - pane.cur_col = @intCast(modal.lineSlice(f.content, end.row -| 1).len); + pane.body.cur_row = @intCast(end.row -| 1); + pane.body.cur_col = @intCast(modal.lineSlice(f.content, end.row -| 1).len); } - pane.cur_pinned = true; - pane.sticky_col = -1; + pane.body.cur_pinned = true; + pane.body.sticky_col = -1; pane.ensureCursorVisible(); - } else edit.pasteText(p, pane, p.yank orelse return, true, 1); + } else edit.pasteText(p, &pane.body, p.yank orelse return, true, 1); } test "plain left click clears explicit modal selection" { @@ -989,10 +989,10 @@ test "plain left click clears explicit modal selection" { const p = try Pardes.init(gpa, .{ .cols = 40, .rows = 10 }); defer p.deinit(); const pane = try p.setTestFile("abcdef\n"); - pane.cur_row = 0; - pane.cur_col = 5; - pane.vsel = .{ .active = true, .row = 0, .col = 1, .explicit = true }; - pane.msel = .{ .active = true, .r0 = 0, .r1 = 0 }; + pane.body.cur_row = 0; + pane.body.cur_col = 5; + pane.body.vsel = .{ .active = true, .row = 0, .col = 1, .explicit = true }; + pane.body.msel = .{ .active = true, .r0 = 0, .r1 = 0 }; var frame = std.heap.ArenaAllocator.init(gpa); defer frame.deinit(); @@ -1003,9 +1003,9 @@ test "plain left click clears explicit modal selection" { p.update(.{ .mouse = .{ .button = config.select_button, .kind = .press, .col = click_x, .row = body_y } }); p.update(.{ .mouse = .{ .button = config.select_button, .kind = .release, .col = click_x, .row = body_y } }); - try std.testing.expectEqual(@as(i32, 3), pane.cur_col); - try std.testing.expect(!pane.vsel.active); - try std.testing.expect(!pane.msel.active); + try std.testing.expectEqual(@as(i32, 3), pane.body.cur_col); + try std.testing.expect(!pane.body.vsel.active); + try std.testing.expect(!pane.body.msel.active); try std.testing.expectEqual(.none, pane.sel[@intFromEnum(config.select_button)].state); } @@ -1412,7 +1412,7 @@ test "mouse thumb buttons navigate once and clear selection gestures" { const p = try Pardes.init(std.testing.allocator, .{ .cols = 60, .rows = 12 }); defer p.deinit(); const pane = try p.setTestFile("alpha beta\ngamma delta\nepsilon zeta\n"); - pane.setRange(pane.file.?.content, 0, .{ .anchor = 1, .head = 5 }, true); + pane.body.setRange(pane.file.?.content, 0, .{ .anchor = 1, .head = 5 }, true); p.njumps = 3; p.jcur = 2; for (0..3) |i| p.jumps[i] = .{ .pane = 0, .serial = pane.serial, .line = @intCast(i + 1), .col = 1 }; @@ -1425,6 +1425,6 @@ test "mouse thumb buttons navigate once and clear selection gestures" { p.update(.{ .mouse = .{ .button = .forward, .kind = .press, .col = 0, .row = 0 } }); p.update(.{ .mouse = .{ .button = .forward, .kind = .release, .col = 0, .row = 0 } }); try std.testing.expectEqual(@as(usize, 2), p.jcur); - try std.testing.expect(!pane.vsel.active); + try std.testing.expect(!pane.body.vsel.active); try std.testing.expectEqual(.none, p.drag); } diff --git a/src/ninep/ctl.zig b/src/ninep/ctl.zig index 645b1c33..484b08c9 100644 --- a/src/ninep/ctl.zig +++ b/src/ninep/ctl.zig @@ -297,9 +297,9 @@ test "the pane ctl takes get, lock and unlock, and nothing that a file of its ow defer p.deinit(); const ctl_node = Node.of(serialOf(p), .ctl); for ([_][]const u8{ - "menu", "nomenu", "dump echo hi", "font Go Mono", "lock x", "bogus", "DEL", - "name x.txt", "put", "del", "delete", "Look x", "Exec Save", "clean", - "dirty", "cleartag", "dot=addr", "addr=dot", "show", "mark", "nomark", + "menu", "nomenu", "dump echo hi", "font Go Mono", "lock x", "bogus", "DEL", + "name x.txt", "put", "del", "delete", "Look x", "Exec Save", "clean", + "dirty", "cleartag", "dot=addr", "addr=dot", "show", "mark", "nomark", "scroll", "limit=addr", "get x", "look /tmp", "exec Del", }) |bad| try testing.expectEqual(E.INVAL, wr(p, ctl_node, bad).errno()); try testing.expect(p.paneBySerial(serialOf(p)) != null); @@ -447,27 +447,27 @@ test "look opens spaced paths and locations without editing the source pane" { const look_node = Node.of(source.serial, .look); const revision = source.file.?.revision; const undo_len = source.file.?.history.undo_len; - source.cur_col = 3; + source.body.cur_col = 3; var clicked: [4200]u8 = undefined; try testing.expectEqual(Status.ok, wr(p, look_node, try std.fmt.bufPrint(&clicked, "{s}:2:3\n", .{path})).reply.status); const opened = p.panes[p.active].?; try testing.expect(opened != source); try testing.expectEqualStrings(path, opened.file.?.path); try testing.expectEqualStrings("first\nsecond\nthird\n", opened.file.?.content); - try testing.expectEqual(@as(i32, 1), opened.cur_row); - try testing.expectEqual(@as(i32, 2), opened.cur_col); + try testing.expectEqual(@as(i32, 1), opened.body.cur_row); + try testing.expectEqual(@as(i32, 2), opened.body.cur_col); try testing.expectEqualStrings("source stays intact\n", source.file.?.content); try testing.expectEqual(revision, source.file.?.revision); try testing.expectEqual(undo_len, source.file.?.history.undo_len); - try testing.expectEqual(@as(i32, 3), source.cur_col); + try testing.expectEqual(@as(i32, 3), source.body.cur_col); var expected: [16]u8 = undefined; try testing.expectEqualStrings(try std.fmt.bufPrint(&expected, "{d}\n", .{opened.serial}), rd(p, root_look, 0, 4096).bytes); p.active = 0; try testing.expectEqual(Status.ok, wr(p, root_look, try std.fmt.bufPrint(&clicked, "{s}:3:2\n", .{path})).reply.status); try testing.expect(p.panes[p.active].? == opened); - try testing.expectEqual(@as(i32, 2), opened.cur_row); - try testing.expectEqual(@as(i32, 1), opened.cur_col); + try testing.expectEqual(@as(i32, 2), opened.body.cur_row); + try testing.expectEqual(@as(i32, 1), opened.body.cur_col); try testing.expectEqualStrings(try std.fmt.bufPrint(&expected, "{d}\n", .{opened.serial}), rd(p, root_look, 0, 4096).bytes); } diff --git a/src/ninep/pane.zig b/src/ninep/pane.zig index 76854dbc..7e9cf7e7 100644 --- a/src/ninep/pane.zig +++ b/src/ninep/pane.zig @@ -124,9 +124,9 @@ fn cellOf(row: i32, col: i32) modal.Cursor { pub fn dotOf(pane: *Pane) State.Range { const text = bodyOf(pane); - const head = modal.offsetAt(text, cellOf(pane.cur_row, pane.cur_col)); - if (!pane.vsel.active) return .{ .q0 = clip(head), .q1 = clip(head) }; - const anchor = modal.offsetAt(text, cellOf(pane.vsel.row, pane.vsel.col)); + const head = modal.offsetAt(text, cellOf(pane.body.cur_row, pane.body.cur_col)); + if (!pane.body.vsel.active) return .{ .q0 = clip(head), .q1 = clip(head) }; + const anchor = modal.offsetAt(text, cellOf(pane.body.vsel.row, pane.body.vsel.col)); var hi = @max(head, anchor); if (hi < text.len) hi = modal.nextGrapheme(text, hi); return .{ .q0 = clip(@min(head, anchor)), .q1 = clip(hi) }; @@ -137,23 +137,23 @@ pub fn setDot(pane: *Pane, r: State.Range) void { const q0 = @min(@as(usize, r.q0), text.len); const q1 = @max(q0, @min(@as(usize, r.q1), text.len)); const a = modal.positionAt(text, q0); - pane.vsel = .{ .active = q1 > q0, .row = @intCast(a.row), .col = @intCast(a.col), .explicit = true }; + pane.body.vsel = .{ .active = q1 > q0, .row = @intCast(a.row), .col = @intCast(a.col), .explicit = true }; const h = modal.positionAt(text, if (q1 > q0) modal.prevGrapheme(text, q1) else q0); - pane.cur_row = @intCast(h.row); - pane.cur_col = @intCast(h.col); - pane.cur_pinned = true; - pane.sticky_col = -1; - pane.msel.active = false; + pane.body.cur_row = @intCast(h.row); + pane.body.cur_col = @intCast(h.col); + pane.body.cur_pinned = true; + pane.body.sticky_col = -1; + pane.body.msel.active = false; pane.ensureCursorVisible(); } pub fn showOffset(pane: *Pane, off: usize) void { const text = bodyOf(pane); const c = modal.positionAt(text, @min(off, text.len)); - pane.cur_row = @intCast(c.row); - pane.cur_col = @intCast(c.col); - pane.cur_pinned = true; - pane.sticky_col = -1; + pane.body.cur_row = @intCast(c.row); + pane.body.cur_col = @intCast(c.col); + pane.body.cur_pinned = true; + pane.body.sticky_col = -1; pane.ensureCursorVisible(); } diff --git a/src/normal.zig b/src/normal.zig index 6647dcca..192fd933 100644 --- a/src/normal.zig +++ b/src/normal.zig @@ -12,6 +12,7 @@ const edit = @import("edit.zig"); const config = @import("config.zig"); const pdf_enabled = panes.Pdf.enabled; const Pane = panes.Pane; +const Text = panes.Text; const Key = pardes.Key; const hit = pardes.hit; const sel_slot = pardes.sel_slot; @@ -66,11 +67,11 @@ pub fn multiOnce(p: *Pardes) bool { } fn startSelRegex(p: *Pardes, pane: *Pane, split: bool) void { - const text = edit.flatSurface(p, pane) catch return; - const got = pane.ranges(text, 0, &pane.sel_snap); + const text = edit.flatSurface(p, &pane.body) catch return; + const got = pane.body.ranges(text, 0, &pane.sel_snap); pane.nsel_snap = @intCast(got.n); pane.sel_snap_pri = @intCast(got.pri); - pane.sel_snap_expl = (pane.vsel.active and pane.vsel.explicit) or pane.msel.active; + pane.sel_snap_expl = (pane.body.vsel.active and pane.body.vsel.explicit) or pane.body.msel.active; p.startPrompt(pane, .{ .search = if (split) config.split_marker else config.select_marker }); } @@ -89,9 +90,9 @@ pub fn selRegexArmed(pane: *Pane) ?struct { pat: []const u8, split: bool } { } pub fn applySelRegex(p: *Pardes, pane: *Pane, pat: []const u8, split: bool) void { - const text = edit.flatSurface(p, pane) catch return; + const text = edit.flatSurface(p, &pane.body) catch return; const snap = pane.sel_snap[0..pane.nsel_snap]; - var out: [Pane.max_selections]modal.Selection = undefined; + var out: [Text.max_selections]modal.Selection = undefined; var m: usize = 0; if (pat.len > 0) if (mvzr.compile(pat)) |re| { var hay_all = text; @@ -109,7 +110,7 @@ pub fn applySelRegex(p: *Pardes, pane: *Pane, pat: []const u8, split: bool) void const hay = hay_all[from..to]; var at: usize = 0; var piece = from; // split: where the next piece begins - while (at < hay.len and m < Pane.max_selections) { + while (at < hay.len and m < Text.max_selections) { const hit_at = re.matchPos(at, hay) orelse break; if (split) { out[m] = .{ .anchor = piece, .head = from + hit_at.start }; @@ -122,7 +123,7 @@ pub fn applySelRegex(p: *Pardes, pane: *Pane, pat: []const u8, split: bool) void // an empty match would otherwise never advance at = if (hit_at.end > hit_at.start) hit_at.end else hit_at.end + 1; } - if (split and piece < to and m < Pane.max_selections) { + if (split and piece < to and m < Text.max_selections) { out[m] = .{ .anchor = piece, .head = to }; m += 1; } @@ -135,37 +136,37 @@ pub fn applySelRegex(p: *Pardes, pane: *Pane, pat: []const u8, split: bool) void r.anchor = @min(r.anchor, text.len); r.head = @min(r.head, text.len); } - return pane.setRanges(text, snap, &.{}, pane.sel_snap_pri, pane.sel_snap_expl); + return pane.body.setRanges(text, snap, &.{}, pane.sel_snap_pri, pane.sel_snap_expl); } - pane.setRanges(text, out[0..m], &.{}, 0, true); // helix keeps primary 0 (its own TODO) + pane.body.setRanges(text, out[0..m], &.{}, 0, true); // helix keeps primary 0 (its own TODO) } const KeyState = struct { - mode: Pane.Mode, + mode: Text.Mode, select: bool, normal: modal.Normal.State, find_op: u8, find_ch: u21, - append_at: @FieldType(Pane, "append_at"), + append_at: @FieldType(Text, "append_at"), - fn of(pane: *Pane) KeyState { + fn of(t: *Text) KeyState { return .{ - .mode = pane.mode, - .select = pane.select, - .normal = pane.normal, - .find_op = pane.find_op, - .find_ch = pane.find_ch, - .append_at = pane.append_at, + .mode = t.mode, + .select = t.select, + .normal = t.normal, + .find_op = t.find_op, + .find_ch = t.find_ch, + .append_at = t.append_at, }; } - fn into(s: KeyState, pane: *Pane) void { - pane.mode = s.mode; - pane.select = s.select; - pane.normal = s.normal; - pane.find_op = s.find_op; - pane.find_ch = s.find_ch; - pane.append_at = s.append_at; + fn into(s: KeyState, t: *Text) void { + t.mode = s.mode; + t.select = s.select; + t.normal = s.normal; + t.find_op = s.find_op; + t.find_ch = s.find_ch; + t.append_at = s.append_at; } }; @@ -175,25 +176,25 @@ const Replay = union(enum) { insert: Key, }; -pub fn replaySels(p: *Pardes, pane: *Pane, what: Replay) void { +pub fn replaySels(p: *Pardes, t: *Text, what: Replay) void { const id = p.active; - const serial = pane.serial; - // the whole selection in pane coordinates, document order. pane.sels + const serial = t.pane().serial; + // the whole selection in text coordinates, document order. t.sels // is already ordered, so this only slots the primary into place. - var list: [Pane.max_selections]Pane.SelRange = undefined; + var list: [Text.max_selections]Text.SelRange = undefined; var n: usize = 0; var pri: usize = 0; - const prim: Pane.SelRange = .{ - .row = pane.cur_row, - .col = pane.cur_col, - .arow = if (pane.vsel.active) pane.vsel.row else pane.cur_row, - .acol = if (pane.vsel.active) pane.vsel.col else pane.cur_col, - .sticky = pane.sticky_col, + const prim: Text.SelRange = .{ + .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, + .sticky = t.sticky_col, }; - const pr = Pane.selStart(prim); + const pr = Text.selStart(prim); var placed = false; - for (pane.sels[0..pane.nsel]) |s| { - const sr = Pane.selStart(s); + for (t.sels[0..t.nsel]) |s| { + const sr = Text.selStart(s); if (!placed and (pr.row < sr.row or (pr.row == sr.row and pr.col <= sr.col))) { pri = n; list[n] = prim; @@ -209,13 +210,13 @@ pub fn replaySels(p: *Pardes, pane: *Pane, what: Replay) void { n += 1; } - const saved = KeyState.of(pane); - const explicit = pane.vsel.explicit; + const saved = KeyState.of(t); + const explicit = t.vsel.explicit; var after = saved; var after_expl = explicit; // each pass's result: cursor and anchor cells as distances from the // end of the surface text, plus the range's own j/k goal column - var res: [Pane.max_selections]struct { cur: usize, anc: usize, sticky: i32 } = undefined; + var res: [Text.max_selections]struct { cur: usize, anc: usize, sticky: i32 } = undefined; p.multi_on = true; p.multi_stop = false; var passes: usize = 0; @@ -224,98 +225,99 @@ pub fn replaySels(p: *Pardes, pane: *Pane, what: Replay) void { i -= 1; p.multi_first = passes == 0; passes += 1; - saved.into(pane); - pane.nsel = 0; // the handler underneath sees ONE selection - pane.cur_row = list[i].row; - pane.cur_col = list[i].col; - pane.vsel = .{ - .active = list[i].arow != list[i].row or list[i].acol != list[i].col or pane.select, + saved.into(t); + t.nsel = 0; // the handler underneath sees ONE selection + t.cur_row = list[i].row; + t.cur_col = list[i].col; + t.vsel = .{ + .active = list[i].arow != list[i].row or list[i].acol != list[i].col or t.select, .row = list[i].arow, .col = list[i].acol, .explicit = explicit, }; - pane.msel.active = false; - pane.sticky_col = list[i].sticky; + t.msel.active = false; + t.sticky_col = list[i].sticky; switch (what) { - .normal => |normal_action| executeNormalAction(p, pane, normal_action), - .insert => |insert_key| edit.insertKey(p, pane, insert_key), + .normal => |normal_action| executeNormalAction(p, t, normal_action), + .insert => |insert_key| edit.insertKey(p, t, insert_key), } if (p.multi_stop) break; if (i == pri) { - after = KeyState.of(pane); - after_expl = pane.vsel.explicit; + after = KeyState.of(t); + after_expl = t.vsel.explicit; } - const text = edit.flatSurface(p, pane) catch { + const text = edit.flatSurface(p, t) catch { p.multi_stop = true; break; }; - const co = modal.offsetAt(text, .{ .row = @intCast(@max(0, pane.cur_row)), .col = @intCast(@max(0, pane.cur_col)) }); - const ao = if (pane.vsel.active) - modal.offsetAt(text, .{ .row = @intCast(@max(0, pane.vsel.row)), .col = @intCast(@max(0, pane.vsel.col)) }) + const co = modal.offsetAt(text, .{ .row = @intCast(@max(0, t.cur_row)), .col = @intCast(@max(0, t.cur_col)) }); + const ao = if (t.vsel.active) + modal.offsetAt(text, .{ .row = @intCast(@max(0, t.vsel.row)), .col = @intCast(@max(0, t.vsel.col)) }) else co; - res[i] = .{ .cur = text.len - @min(co, text.len), .anc = text.len - @min(ao, text.len), .sticky = pane.sticky_col }; + res[i] = .{ .cur = text.len - @min(co, text.len), .anc = text.len - @min(ao, text.len), .sticky = t.sticky_col }; } p.multi_on = false; p.multi_first = false; if (p.multi_stop) { p.multi_stop = false; const pn = p.panes[id] orelse return; - if (pn.serial == serial) pn.nsel = 0; + if (pn.serial == serial) pn.body.nsel = 0; return; } - const text = edit.flatSurface(p, pane) catch return; - var rs: [Pane.max_selections]modal.Selection = undefined; - var st: [Pane.max_selections]i32 = undefined; + const text = edit.flatSurface(p, t) catch return; + var rs: [Text.max_selections]modal.Selection = undefined; + var st: [Text.max_selections]i32 = undefined; for (res[0..n], 0..) |r, k| { - rs[k] = Pane.cellOffRange(text, text.len - @min(r.anc, text.len), text.len - @min(r.cur, text.len)); + rs[k] = Text.cellOffRange(text, text.len - @min(r.anc, text.len), text.len - @min(r.cur, text.len)); st[k] = r.sticky; } - pane.setRanges(text, rs[0..n], st[0..n], pri, after_expl); - after.into(pane); - pane.ensureCursorVisible(); // the view follows the PRIMARY, not the last pass + t.setRanges(text, rs[0..n], st[0..n], pri, after_expl); + after.into(t); + t.pane().ensureCursorVisible(); // the view follows the PRIMARY, not the last pass } -pub fn handleNormal(p: *Pardes, pane: *Pane, key: Key) void { - const parsed = modal.Normal.parse(&pane.normal, normalInput(key)); +pub fn handleNormal(p: *Pardes, t: *Text, key: Key) void { + const parsed = modal.Normal.parse(&t.normal, normalInput(key)); const semantic = switch (parsed) { .pending, .ignored, .unbound => return, .action => |value| value, }; - if (pane.nsel == 0 or semantic.scope() == .once) - return executeNormalAction(p, pane, semantic); - replaySels(p, pane, .{ .normal = semantic }); + if (t.nsel == 0 or semantic.scope() == .once) + return executeNormalAction(p, t, semantic); + replaySels(p, t, .{ .normal = semantic }); } -fn executeNormalAction(p: *Pardes, pane: *Pane, semantic: modal.Normal.Action) void { +fn executeNormalAction(p: *Pardes, t: *Text, semantic: modal.Normal.Action) void { + const pane = t.pane(); const raw_selection = pane.rawPointerText(pane.sel[sel_slot]) != null; - const before = .{ pane.cur_row, pane.cur_col, pane.vsel, pane.msel, pane.select, pane.nsel, pane.mode }; - defer if (raw_selection and !std.meta.eql(before, .{ pane.cur_row, pane.cur_col, pane.vsel, pane.msel, pane.select, pane.nsel, pane.mode })) { + const before = .{ t.cur_row, t.cur_col, t.vsel, t.msel, t.select, t.nsel, t.mode }; + defer if (raw_selection and !std.meta.eql(before, .{ t.cur_row, t.cur_col, t.vsel, t.msel, t.select, t.nsel, t.mode })) { pane.clearPointerSelection(sel_slot); pane.sel[sel_slot].state = .none; }; - if (raw_selection and semantic == .edit and semantic.edit.kind == .yank) return edit.normalYank(p, pane); - edit.pinPaneCursor(p, pane); - const text = edit.flatSurface(p, pane) catch return; - const range = pane.primaryRange(text, 0); + if (raw_selection and semantic == .edit and semantic.edit.kind == .yank) return edit.normalYank(p, t); + edit.pinPaneCursor(p, t); + const text = edit.flatSurface(p, t) catch return; + const range = t.primaryRange(text, 0); const cur = modal.selectionCursor(text, range); switch (semantic) { .escape => { - pane.select = false; + t.select = false; return exec.runBuiltin(p, .Last, p.active, "", null); }, .goto => |go| switch (go.target) { .file_start => { - const line = if (go.explicit_count) @min(@as(usize, go.count) - 1, Pane.maxLine(text)) else 0; - return pane.pointMove(text, range, modal.lineStartOffset(text, line)); + const line = if (go.explicit_count) @min(@as(usize, go.count) - 1, Text.maxLine(text)) else 0; + return t.pointMove(text, range, modal.lineStartOffset(text, line)); }, - .last_line => return pane.pointMove(text, range, modal.lineStartOffset(text, Pane.maxLine(text))), - .line_start => return pane.pointMove(text, range, modal.lineStartOffset(text, modal.lineAtOffset(text, cur))), + .last_line => return t.pointMove(text, range, modal.lineStartOffset(text, Text.maxLine(text))), + .line_start => return t.pointMove(text, range, modal.lineStartOffset(text, modal.lineAtOffset(text, cur))), .line_end => { const line = modal.lineAtOffset(text, cur); const ls = modal.lineStartOffset(text, line); - return pane.pointMove(text, range, @max(ls, modal.prevGrapheme(text, modal.lineEndOffset(text, line)))); + return t.pointMove(text, range, @max(ls, modal.prevGrapheme(text, modal.lineEndOffset(text, line)))); }, .first_nonws => { const line = modal.lineAtOffset(text, cur); @@ -323,35 +325,35 @@ fn executeNormalAction(p: *Pardes, pane: *Pane, semantic: modal.Normal.Action) v const slice = text[ls..modal.lineEndOffset(text, line)]; const nw = modal.firstNonWs(slice); if (nw == slice.len) return; - return pane.pointMove(text, range, ls + nw); + return t.pointMove(text, range, ls + nw); }, - .line_down => return pane.visualMove(text, range, true, go.count, edit.paneWrapWidth(p, pane)), - .line_up => return pane.visualMove(text, range, false, go.count, edit.paneWrapWidth(p, pane)), + .line_down => return t.visualMove(text, range, true, go.count, edit.paneWrapWidth(p, t)), + .line_up => return t.visualMove(text, range, false, go.count, edit.paneWrapWidth(p, t)), .column => { const line = modal.lineAtOffset(text, cur); const ls = modal.lineStartOffset(text, line); const slice = text[ls..modal.lineEndOffset(text, line)]; - return pane.pointMove(text, range, ls + modal.graphemeAtColumn(slice, @as(usize, go.count) - 1)); + return t.pointMove(text, range, ls + modal.graphemeAtColumn(slice, @as(usize, go.count) - 1)); }, - .view_top => return pane.gotoWindow(text, range, .top, go.count), - .view_center => return pane.gotoWindow(text, range, .center, go.count), - .view_bottom => return pane.gotoWindow(text, range, .bottom, go.count), + .view_top => return t.gotoWindow(text, range, .top, go.count), + .view_center => return t.gotoWindow(text, range, .center, go.count), + .view_bottom => return t.gotoWindow(text, range, .bottom, go.count), }, .view => |view| switch (view) { .top => { - pane.scrollBy(pane.cur_row - pane.scroll()); + pane.scrollBy(t.cur_row - pane.scroll()); pane.ensureCursorVisible(); }, .center => { - pane.scrollBy(pane.cur_row - (pane.scroll() + @divTrunc(@as(i32, pane.rows), 2) - 1)); + pane.scrollBy(t.cur_row - (pane.scroll() + @divTrunc(@as(i32, pane.rows), 2) - 1)); pane.ensureCursorVisible(); }, .bottom => { - pane.scrollBy(pane.cur_row - (pane.scroll() + @as(i32, pane.rows) - 1)); + pane.scrollBy(t.cur_row - (pane.scroll() + @as(i32, pane.rows) - 1)); pane.ensureCursorVisible(); }, - .scroll_down => return pane.scrollViewMove(text, range, 1), - .scroll_up => return pane.scrollViewMove(text, range, -1), + .scroll_down => return t.scrollViewMove(text, range, 1), + .scroll_up => return t.scrollViewMove(text, range, -1), }, .find => |find| { const op: u8 = switch (find.kind) { @@ -360,9 +362,9 @@ fn executeNormalAction(p: *Pardes, pane: *Pane, semantic: modal.Normal.Action) v .till_forward => @intCast(config.till_char_fwd), .till_backward => @intCast(config.till_char_back), }; - pane.find_op = op; - pane.find_ch = find.char; - return pane.findMove( + t.find_op = op; + t.find_ch = find.char; + return t.findMove( text, range, find.char, @@ -371,21 +373,21 @@ fn executeNormalAction(p: *Pardes, pane: *Pane, semantic: modal.Normal.Action) v find.count, ); }, - .replace_char => |char| return edit.normalReplaceChar(p, pane, char), + .replace_char => |char| return edit.normalReplaceChar(p, t, char), .match_bracket => { - const lines = edit.paneCursorLines(p, pane) catch return; + const lines = edit.paneCursorLines(p, t) catch return; const mc = modal.matchBracket(lines, modal.positionAt(text, cur)) orelse return; - return pane.pointMove(text, range, modal.offsetAt(text, mc)); + return t.pointMove(text, range, modal.offsetAt(text, mc)); }, - .textobject => |object| return edit.textobjectSelect(p, pane, text, object.char, object.around), - .surround_add => |char| return edit.surroundAdd(p, pane, char), - .surround_delete => |char| return edit.surroundDelete(p, pane, char), - .surround_replace => |replace| return edit.surroundReplace(p, pane, replace.from, replace.to), + .textobject => |object| return edit.textobjectSelect(p, t, text, object.char, object.around), + .surround_add => |char| return edit.surroundAdd(p, t, char), + .surround_delete => |char| return edit.surroundDelete(p, t, char), + .surround_replace => |replace| return edit.surroundReplace(p, t, replace.from, replace.to), .paragraph => |paragraph| { - const r2 = modal.moveParagraph(text, range, paragraph.count, paragraph.direction == .forward, pane.select); - return pane.setRange(text, 0, r2, false); + const r2 = modal.moveParagraph(text, range, paragraph.count, paragraph.direction == .forward, t.select); + return t.setRange(text, 0, r2, false); }, - .add_newline => |newline| return edit.addNewline(p, pane, newline.direction == .forward, newline.count), + .add_newline => |newline| return edit.addNewline(p, t, newline.direction == .forward, newline.count), .diagnostic => |diagnostic| { const fwd = diagnostic.direction == .forward; if (!diagnostic.endpoint) { @@ -409,46 +411,46 @@ fn executeNormalAction(p: *Pardes, pane: *Pane, semantic: modal.Normal.Action) v .left => { var target = cur; for (0..move.count) |_| target = modal.prevGrapheme(text, target); - return pane.pointMove(text, range, target); + return t.pointMove(text, range, target); }, .right => { var target = cur; for (0..move.count) |_| target = modal.nextGrapheme(text, target); - return pane.pointMove(text, range, target); + return t.pointMove(text, range, target); }, - .down => return pane.verticalMove(text, range, true, move.count), - .up => return pane.verticalMove(text, range, false, move.count), - .next_word_start => return pane.wordMove(text, range, move.count, .next_word_start), - .prev_word_start => return pane.wordMove(text, range, move.count, .prev_word_start), - .next_word_end => return pane.wordMove(text, range, move.count, .next_word_end), - .next_long_word_start => return pane.wordMove(text, range, move.count, .next_long_word_start), - .prev_long_word_start => return pane.wordMove(text, range, move.count, .prev_long_word_start), - .next_long_word_end => return pane.wordMove(text, range, move.count, .next_long_word_end), + .down => return t.verticalMove(text, range, true, move.count), + .up => return t.verticalMove(text, range, false, move.count), + .next_word_start => return t.wordMove(text, range, move.count, .next_word_start), + .prev_word_start => return t.wordMove(text, range, move.count, .prev_word_start), + .next_word_end => return t.wordMove(text, range, move.count, .next_word_end), + .next_long_word_start => return t.wordMove(text, range, move.count, .next_long_word_start), + .prev_long_word_start => return t.wordMove(text, range, move.count, .prev_long_word_start), + .next_long_word_end => return t.wordMove(text, range, move.count, .next_long_word_end), }, .repeat_find => |count| { - if (pane.find_op == 0) return; - const fwd = pane.find_op == config.find_char_fwd or pane.find_op == config.till_char_fwd; - const till = pane.find_op == config.till_char_fwd or pane.find_op == config.till_char_back; + if (t.find_op == 0) return; + const fwd = t.find_op == config.find_char_fwd or t.find_op == config.till_char_fwd; + const till = t.find_op == config.till_char_fwd or t.find_op == config.till_char_back; var repeated = range; var moved = false; for (0..count) |_| { const cc = modal.selectionCursor(text, repeated); - const target = modal.findTarget(text, cc, pane.find_ch, fwd, till, 1) orelse break; - repeated = if (pane.select) + const target = modal.findTarget(text, cc, t.find_ch, fwd, till, 1) orelse break; + repeated = if (t.select) modal.moveSelectionCursor(text, repeated, target, true) else modal.moveSelectionCursor(text, .{ .anchor = cc, .head = cc }, target, true); moved = true; } if (!moved) return; - return pane.setRange(text, 0, repeated, false); + return t.setRange(text, 0, repeated, false); }, .line => |line_kind| switch (line_kind) { - .start => return pane.pointMove(text, range, modal.lineStartOffset(text, modal.lineAtOffset(text, cur))), + .start => return t.pointMove(text, range, modal.lineStartOffset(text, modal.lineAtOffset(text, cur))), .end => { const line = modal.lineAtOffset(text, cur); const ls = modal.lineStartOffset(text, line); - return pane.pointMove(text, range, @max(ls, modal.prevGrapheme(text, modal.lineEndOffset(text, line)))); + return t.pointMove(text, range, @max(ls, modal.prevGrapheme(text, modal.lineEndOffset(text, line)))); }, .first_nonws => { const line = modal.lineAtOffset(text, cur); @@ -456,21 +458,21 @@ fn executeNormalAction(p: *Pardes, pane: *Pane, semantic: modal.Normal.Action) v const slice = text[ls..modal.lineEndOffset(text, line)]; const nw = modal.firstNonWs(slice); if (nw == slice.len) return; - return pane.pointMove(text, range, ls + nw); + return t.pointMove(text, range, ls + nw); }, }, .goto_line => |go| { if (!go.explicit) return; - const line = @min(@as(usize, go.count) - 1, Pane.maxLine(text)); - return pane.pointMove(text, range, modal.lineStartOffset(text, line)); + const line = @min(@as(usize, go.count) - 1, Text.maxLine(text)); + return t.pointMove(text, range, modal.lineStartOffset(text, line)); }, .page => |page| switch (page.kind) { // Counts were parsed historically but these four text view // actions intentionally move exactly one viewport unit. - .half_down => return pane.halfPageMove(text, range, true), - .half_up => return pane.halfPageMove(text, range, false), - .down => return pane.scrollViewMove(text, range, @as(i32, pane.rows)), - .up => return pane.scrollViewMove(text, range, -@as(i32, pane.rows)), + .half_down => return t.halfPageMove(text, range, true), + .half_up => return t.halfPageMove(text, range, false), + .down => return t.scrollViewMove(text, range, @as(i32, pane.rows)), + .up => return t.scrollViewMove(text, range, -@as(i32, pane.rows)), }, .insert => |insert| { const where: edit.InsertAt = switch (insert.kind) { @@ -481,59 +483,59 @@ fn executeNormalAction(p: *Pardes, pane: *Pane, semantic: modal.Normal.Action) v .open_below => .open_below, .open_above => .open_above, }; - return edit.enterInsert(p, pane, where, insert.count); + return edit.enterInsert(p, t, where, insert.count); }, .select => |select| switch (select.kind) { .mode => { - if (pane.select) { - pane.select = false; + if (t.select) { + t.select = false; } else { - pane.select = true; - if (pane.msel.active) { - pane.setRange(text, 0, range, true); - } else if (!pane.vsel.active) { - pane.vsel = .{ .active = true, .row = pane.cur_row, .col = pane.cur_col, .explicit = true }; + t.select = true; + if (t.msel.active) { + t.setRange(text, 0, range, true); + } else if (!t.vsel.active) { + t.vsel = .{ .active = true, .row = t.cur_row, .col = t.cur_col, .explicit = true }; } else { - pane.vsel.explicit = true; + t.vsel.explicit = true; } } - pane.cur_pinned = true; + t.cur_pinned = true; }, - .line => return pane.lineSelect(text, range, select.count), - .line_bounds => return pane.lineBoundsSelect(text, range), - .shrink_to_line_bounds => return pane.shrinkSelToLineBounds(text, range), - .collapse => return pane.setRange(text, 0, .{ .anchor = cur, .head = cur }, false), + .line => return t.lineSelect(text, range, select.count), + .line_bounds => return t.lineBoundsSelect(text, range), + .shrink_to_line_bounds => return t.shrinkSelToLineBounds(text, range), + .collapse => return t.setRange(text, 0, .{ .anchor = cur, .head = cur }, false), .flip => { - const explicit = (pane.vsel.active and pane.vsel.explicit) or pane.msel.active; - return pane.setRange(text, 0, .{ .anchor = range.head, .head = range.anchor }, explicit); + const explicit = (t.vsel.active and t.vsel.explicit) or t.msel.active; + return t.setRange(text, 0, .{ .anchor = range.head, .head = range.anchor }, explicit); }, - .all => return pane.setRange(text, 0, .{ .anchor = 0, .head = text.len }, false), + .all => return t.setRange(text, 0, .{ .anchor = 0, .head = text.len }, false), }, .multi => |multi| { if (multi.kind == .keep_primary) { - pane.nsel = 0; + t.nsel = 0; return; } - return pane.multiSelAction(text, multi.kind, multi.count); + return t.multiSelAction(text, multi.kind, multi.count); }, .select_regex => |split| return startSelRegex(p, pane, split), .edit => |op| switch (op.kind) { - .delete => return edit.normalDelete(p, pane, true), - .delete_noyank => return edit.normalDelete(p, pane, false), - .change => return edit.normalChange(p, pane), - .yank => return edit.normalYank(p, pane), - .replace_with_yank => return edit.normalReplaceYank(p, pane), - .paste_after => return edit.pasteText(p, pane, p.yank orelse return, false, op.count), - .paste_before => return edit.pasteText(p, pane, p.yank orelse return, true, op.count), - .switch_case => return edit.normalCase(p, pane, .toggle), - .lowercase => return edit.normalCase(p, pane, .lower), - .uppercase => return edit.normalCase(p, pane, .upper), - .join_lines => return edit.normalJoin(p, pane), - .indent => return edit.normalIndent(p, pane, op.count, true), - .unindent => return edit.normalIndent(p, pane, op.count, false), - .comment_toggle => return edit.normalToggleComment(p, pane), - .undo => return edit.doUndo(p, pane), - .redo => return edit.doRedo(p, pane), + .delete => return edit.normalDelete(p, t, true), + .delete_noyank => return edit.normalDelete(p, t, false), + .change => return edit.normalChange(p, t), + .yank => return edit.normalYank(p, t), + .replace_with_yank => return edit.normalReplaceYank(p, t), + .paste_after => return edit.pasteText(p, t, p.yank orelse return, false, op.count), + .paste_before => return edit.pasteText(p, t, p.yank orelse return, true, op.count), + .switch_case => return edit.normalCase(p, t, .toggle), + .lowercase => return edit.normalCase(p, t, .lower), + .uppercase => return edit.normalCase(p, t, .upper), + .join_lines => return edit.normalJoin(p, t), + .indent => return edit.normalIndent(p, t, op.count, true), + .unindent => return edit.normalIndent(p, t, op.count, false), + .comment_toggle => return edit.normalToggleComment(p, t), + .undo => return edit.doUndo(p, t), + .redo => return edit.doRedo(p, t), }, .lsp => |request| return p.lspRequest(p.active, switch (request) { .definition => .definition, @@ -543,14 +545,14 @@ fn executeNormalAction(p: *Pardes, pane: *Pane, semantic: modal.Normal.Action) v .references => .references, .format => .format, }, ""), - .adjust_number => |delta| return edit.normalAdjustNumber(p, pane, delta), + .adjust_number => |delta| return edit.normalAdjustNumber(p, t, delta), .leader => { p.leader_on = true; p.leader_n = 0; }, .command_line => { p.enterTagEdit(pane, -1); - if (pane.tag_edit) pane.mode = .normal; + if (pane.tag_edit) t.mode = .normal; }, .pipe_selection => |how| return p.startPrompt(pane, .{ .pipe = how }), .search => return p.startPrompt(pane, .{ .search = config.search_marker }), @@ -565,15 +567,15 @@ pub fn handlePdfNormal(p: *Pardes, pane: *Pane, key: Key) void { if (comptime !pdf_enabled) return; if (pane.pdf == null) return; if (hit(key, config.leave_pane)) { - pane.normal.clear(); - pane.select = false; + pane.body.normal.clear(); + pane.body.select = false; return exec.runBuiltin(p, .Last, p.active, "", null); } - if (pane.normal.prefix == .none and isPrefix(key, 'f')) { - pane.normal.clear(); + if (pane.body.normal.prefix == .none and isPrefix(key, 'f')) { + pane.body.normal.clear(); return exec.runBuiltin(p, .PdfSections, p.active, "", null); } - const parsed = modal.Normal.parse(&pane.normal, normalInput(key)); + const parsed = modal.Normal.parse(&pane.body.normal, normalInput(key)); switch (parsed) { .pending, .ignored, .unbound => {}, .action => |semantic| { @@ -595,7 +597,7 @@ pub fn handlePdfNormal(p: *Pardes, pane: *Pane, key: Key) void { }, .command_line => { p.enterTagEdit(pane, -1); - if (pane.tag_edit) pane.mode = .normal; + if (pane.tag_edit) pane.body.mode = .normal; }, .search => p.startPrompt(pane, .{ .search = config.search_marker }), .search_forward => look.lookWalk(p, 1), @@ -618,57 +620,57 @@ test "gj/gk step the wrapped rows a body draws while j/k keep the file's lines" // gj holds the column INSIDE the row and lands on the next break; the line // is one line the whole way down, which is the whole point. - pane.cur_row = 0; - pane.cur_col = 3; - pane.sticky_col = -1; + pane.body.cur_row = 0; + pane.body.cur_col = 3; + pane.body.sticky_col = -1; p.update(.{ .key = .{ .cp = 'g' } }); p.update(.{ .key = .{ .cp = 'j' } }); - try std.testing.expectEqual(@as(i32, 0), pane.cur_row); - try std.testing.expectEqual(@as(i32, @intCast(width + 3)), pane.cur_col); + try std.testing.expectEqual(@as(i32, 0), pane.body.cur_row); + try std.testing.expectEqual(@as(i32, @intCast(width + 3)), pane.body.cur_col); p.update(.{ .key = .{ .cp = 'g' } }); p.update(.{ .key = .{ .cp = 'j' } }); - try std.testing.expectEqual(@as(i32, @intCast(width * 2 + 3)), pane.cur_col); + try std.testing.expectEqual(@as(i32, @intCast(width * 2 + 3)), pane.body.cur_col); p.update(.{ .key = .{ .cp = 'g' } }); p.update(.{ .key = .{ .cp = 'k' } }); - try std.testing.expectEqual(@as(i32, @intCast(width + 3)), pane.cur_col); + try std.testing.expectEqual(@as(i32, @intCast(width + 3)), pane.body.cur_col); // A count is counted in rows, not lines. p.update(.{ .key = .{ .cp = '2' } }); p.update(.{ .key = .{ .cp = 'g' } }); p.update(.{ .key = .{ .cp = 'j' } }); - try std.testing.expectEqual(@as(i32, 0), pane.cur_row); - try std.testing.expectEqual(@as(i32, @intCast(width * 3 + 3)), pane.cur_col); + try std.testing.expectEqual(@as(i32, 0), pane.body.cur_row); + try std.testing.expectEqual(@as(i32, @intCast(width * 3 + 3)), pane.body.cur_col); // Plain j/k are untouched: one FILE line each, whatever the body drew. - pane.cur_col = 3; - pane.sticky_col = -1; + pane.body.cur_col = 3; + pane.body.sticky_col = -1; p.update(.{ .key = .{ .cp = 'j' } }); - try std.testing.expectEqual(@as(i32, 1), pane.cur_row); + try std.testing.expectEqual(@as(i32, 1), pane.body.cur_row); p.update(.{ .key = .{ .cp = 'k' } }); - try std.testing.expectEqual(@as(i32, 0), pane.cur_row); + try std.testing.expectEqual(@as(i32, 0), pane.body.cur_row); // The last row of a line steps into the next line's first row, and the // first row steps back onto the previous line's LAST row. - pane.cur_row = 0; - pane.cur_col = @intCast(long.len - 1); - pane.sticky_col = -1; + pane.body.cur_row = 0; + pane.body.cur_col = @intCast(long.len - 1); + pane.body.sticky_col = -1; p.update(.{ .key = .{ .cp = 'g' } }); p.update(.{ .key = .{ .cp = 'j' } }); - try std.testing.expectEqual(@as(i32, 1), pane.cur_row); - pane.cur_col = 0; - pane.sticky_col = -1; + try std.testing.expectEqual(@as(i32, 1), pane.body.cur_row); + pane.body.cur_col = 0; + pane.body.sticky_col = -1; p.update(.{ .key = .{ .cp = 'g' } }); p.update(.{ .key = .{ .cp = 'k' } }); - try std.testing.expectEqual(@as(i32, 0), pane.cur_row); - try std.testing.expect(pane.cur_col >= @as(i32, @intCast(long.len - long.len % width))); + try std.testing.expectEqual(@as(i32, 0), pane.body.cur_row); + try std.testing.expect(pane.body.cur_col >= @as(i32, @intCast(long.len - long.len % width))); // Wrap OFF: a line is one visual row, so gj/gk ARE j/k again. p.settings.wrap = false; - pane.cur_row = 0; - pane.cur_col = 3; - pane.sticky_col = -1; + pane.body.cur_row = 0; + pane.body.cur_col = 3; + pane.body.sticky_col = -1; p.update(.{ .key = .{ .cp = 'g' } }); p.update(.{ .key = .{ .cp = 'j' } }); - try std.testing.expectEqual(@as(i32, 1), pane.cur_row); + try std.testing.expectEqual(@as(i32, 1), pane.body.cur_row); } test "flat text movement and selection replay need no scratch rows" { @@ -685,39 +687,39 @@ test "flat text movement and selection replay need no scratch rows" { p.scratch.deinit(); p.scratch = .init(denied.allocator()); - pane.cur_row = 4094; - handleNormal(p, pane, .{ .cp = 'l' }); - try std.testing.expectEqual(@as(i32, 1), pane.cur_col); - handleNormal(p, pane, .{ .cp = 'j' }); - try std.testing.expectEqual(@as(i32, 4095), pane.cur_row); - try std.testing.expectEqual(@as(i32, 1), pane.cur_col); - handleNormal(p, pane, .{ .cp = 'h' }); - try std.testing.expectEqual(@as(i32, 0), pane.cur_col); - executeNormalAction(p, pane, .{ .textobject = .{ .char = 'w', .around = false } }); - try std.testing.expectEqual(@as(i32, 2), pane.cur_col); - try std.testing.expectEqual(@as(i32, 0), pane.vsel.col); + pane.body.cur_row = 4094; + handleNormal(p, &pane.body, .{ .cp = 'l' }); + try std.testing.expectEqual(@as(i32, 1), pane.body.cur_col); + handleNormal(p, &pane.body, .{ .cp = 'j' }); + try std.testing.expectEqual(@as(i32, 4095), pane.body.cur_row); + try std.testing.expectEqual(@as(i32, 1), pane.body.cur_col); + handleNormal(p, &pane.body, .{ .cp = 'h' }); + try std.testing.expectEqual(@as(i32, 0), pane.body.cur_col); + executeNormalAction(p, &pane.body, .{ .textobject = .{ .char = 'w', .around = false } }); + try std.testing.expectEqual(@as(i32, 2), pane.body.cur_col); + try std.testing.expectEqual(@as(i32, 0), pane.body.vsel.col); - pane.vsel.active = false; - pane.cur_row = 1024; - pane.cur_col = 0; - pane.nsel = 1; - pane.sels[0] = .{ .row = 3072, .col = 0, .arow = 3072, .acol = 0 }; - handleNormal(p, pane, .{ .cp = 'l' }); - handleNormal(p, pane, .{ .cp = 'j' }); - try std.testing.expectEqual(@as(u8, 1), pane.nsel); - try std.testing.expectEqual(@as(i32, 1025), pane.cur_row); - try std.testing.expectEqual(@as(i32, 1), pane.cur_col); - try std.testing.expectEqual(@as(i32, 3073), pane.sels[0].row); - try std.testing.expectEqual(@as(i32, 1), pane.sels[0].col); + pane.body.vsel.active = false; + pane.body.cur_row = 1024; + pane.body.cur_col = 0; + pane.body.nsel = 1; + pane.body.sels[0] = .{ .row = 3072, .col = 0, .arow = 3072, .acol = 0 }; + handleNormal(p, &pane.body, .{ .cp = 'l' }); + handleNormal(p, &pane.body, .{ .cp = 'j' }); + try std.testing.expectEqual(@as(u8, 1), pane.body.nsel); + try std.testing.expectEqual(@as(i32, 1025), pane.body.cur_row); + try std.testing.expectEqual(@as(i32, 1), pane.body.cur_col); + try std.testing.expectEqual(@as(i32, 3073), pane.body.sels[0].row); + try std.testing.expectEqual(@as(i32, 1), pane.body.sels[0].col); try std.testing.expect(!denied.has_induced_failure); try std.testing.expectEqual(@as(usize, 0), p.scratch.queryCapacity()); - pane.nsel = 0; - pane.cur_col = 4; - executeNormalAction(p, pane, .match_bracket); + pane.body.nsel = 0; + pane.body.cur_col = 4; + executeNormalAction(p, &pane.body, .match_bracket); try std.testing.expect(denied.has_induced_failure); - try std.testing.expectEqual(@as(i32, 4), pane.cur_col); + try std.testing.expectEqual(@as(i32, 4), pane.body.cur_col); denied.fail_index = std.math.maxInt(usize); - executeNormalAction(p, pane, .match_bracket); - try std.testing.expectEqual(@as(i32, 8), pane.cur_col); + executeNormalAction(p, &pane.body, .match_bracket); + try std.testing.expectEqual(@as(i32, 8), pane.body.cur_col); } diff --git a/src/panes.zig b/src/panes.zig index 9bf2d92f..e6634583 100644 --- a/src/panes.zig +++ b/src/panes.zig @@ -24,8 +24,6 @@ const Key = pardes.Key; pub const EditText = struct { text: []u8, row0: i32 }; pub const Pane = struct { - pub const Mode = enum { normal, insert, tty }; - /// One mouse selection (block-shaped), per button. c/r are text-area relative; /// r counts from the tag row (body starts at BOX_H). pub const Sel = struct { @@ -53,39 +51,12 @@ pub const Pane = struct { rows: []PointerRow, raw_text: ?[]u8 = null, }; - - /// A modal line selection (helix `x`): whole rows [r0, r1], absolute. - pub const LineSel = struct { - active: bool = false, - r0: i32 = 0, - r1: i32 = 0, - }; - - pub const CharSel = struct { - active: bool = false, - row: i32 = 0, - col: i32 = 0, - explicit: bool = false, - }; - pub const LookSpot = struct { row: i32, col0: i32, col1: i32, }; - pub const max_selections = 64; - - pub const SelRange = struct { - row: i32, - col: i32, - arow: i32, - acol: i32, - /// this range's own j/k goal column (helix Range::old_visual_position); - /// the PRIMARY's copy is Pane.sticky_col - sticky: i32 = -1, - }; - const PdfSlot = if (Pdf.enabled) ?Pdf.State else void; pub const Prompt = union(enum) { @@ -108,7 +79,9 @@ pub const Pane = struct { /// dies with it, as acme keeps the same on its Window /// (editors/acme/dat.h:226-266). fs: pardes.ctlfs.pane.State = .{}, - mode: Mode = .normal, + /// The body: what the pane shows and edits, its cursor, selections, + /// mode and edit-buffer undo. + body: Text = .{}, vweight: f32 = 1, /// A folded pane keeps its expansion weight, but occupies only its tag row. collapsed: bool = false, @@ -121,26 +94,13 @@ pub const Pane = struct { file: ?File.State = null, image: ?Image.State = null, pdf: PdfSlot = if (Pdf.enabled) null else {}, - msel: LineSel = .{}, - vsel: CharSel = .{}, - sels: [max_selections - 1]SelRange = undefined, - nsel: u8 = 0, - select: bool = false, - /// sticky goal column for j/k runs (helix old_visual_position): any - /// non-vertical range write resets it to -1. - sticky_col: i32 = -1, - append_at: ?struct { row: i32, col: i32 } = null, - normal: modal.Normal.State = .{}, - /// last f/F/t/T motion, for Alt-. repeat - find_op: u8 = 0, - find_ch: u21 = 0, /// Tag-tail input state. The tag text is presentation; this tag carries /// which operation owns it and the tail offset restored on submit/cancel. prompt: Prompt = .none, search_pane: ?usize = null, search_row: ?usize = null, look_at: ?LookSpot = null, - sel_snap: [max_selections]modal.Selection = undefined, + sel_snap: [Text.max_selections]modal.Selection = undefined, nsel_snap: u8 = 0, sel_snap_pri: u8 = 0, sel_snap_expl: bool = false, @@ -153,7 +113,7 @@ pub const Pane = struct { tag_sel: bool = false, /// the body mode a tag edit hijacked (tags are always insert); terminals /// restore it on exit so clicking the tag never changes the pane's mode - tag_mode: Mode = .normal, + tag_mode: Text.Mode = .normal, tag_col: u16 = 0, tag_saved_col: ?u16 = null, tag_anchor: u16 = 0, @@ -163,14 +123,7 @@ pub const Pane = struct { tag_name_len: ?u16 = null, /// Display columns hidden to reveal the tag caret; tag addresses stay whole. tag_scroll: u16 = 0, - ed_undo: [Terminal.history_max]Terminal.Snapshot = undefined, - ed_undo_len: usize = 0, - ed_redo: [Terminal.history_max]Terminal.Snapshot = undefined, - ed_redo_len: usize = 0, cwd: Cwd = .none, - cur_pinned: bool = false, - cur_row: i32 = 0, - cur_col: i32 = 0, hscroll: i32 = 0, // Visible rows map to source lines and raw/display column origins. wrap_line: [limits.wrap_rows]i32 = undefined, @@ -512,7 +465,7 @@ pub const Pane = struct { // already, so only treat an ancestor as pinned in the matching view. if (pane.context_rows < pane.wrap_n and pane.wrap_line[pane.context_rows] == off) { for (pane.wrap_line[0..pane.context_rows]) |row| { - if (row == pane.cur_row) { + if (row == pane.body.cur_row) { in_context = true; break; } @@ -528,10 +481,10 @@ pub const Pane = struct { margin = @min(margin, @divTrunc(@max(0, lines_shown), 2)); } if (!in_context) { - if (pane.cur_row < off + margin) { - pane.scrollBy(pane.cur_row - margin - off); - } else if (pane.cur_row > last - margin) { - var to = pane.cur_row + margin; + if (pane.body.cur_row < off + margin) { + pane.scrollBy(pane.body.cur_row - margin - off); + } else if (pane.body.cur_row > last - margin) { + var to = pane.body.cur_row + margin; if (pane.file) |*f| to = @min(to, @as(i32, @intCast(File.nlines(pane.gpa, f) -| 1))); if (comptime Pdf.enabled) { if (pane.pdf) |pv| @@ -544,8 +497,8 @@ pub const Pane = struct { if (pane.body_wrapped) return; const w: i32 = @max(1, @as(i32, pane.cols) - @as(i32, File.gutterWidth(pane))); const hmargin: i32 = @min(config.scroll_off, @divTrunc(w - 1, 2)); - const line = modal.lineSlice(f.content, @intCast(@max(0, pane.cur_row))); - const raw_cur: usize = @intCast(@max(0, pane.cur_col)); + const line = modal.lineSlice(f.content, @intCast(@max(0, pane.body.cur_row))); + const raw_cur: usize = @intCast(@max(0, pane.body.cur_col)); const raw_scroll: usize = @intCast(@max(0, pane.hscroll)); const cur = @as(i32, @intCast(File.rawDisplayCol(line, raw_cur))); const visual_scroll = @as(i32, @intCast(File.rawDisplayCol(line, raw_scroll))); @@ -559,16 +512,16 @@ pub const Pane = struct { } pub fn pinCursor(pane: *Pane) void { - if (pane.cur_pinned) return; + if (pane.body.cur_pinned) return; if (pane.file != null or hasPdf(pane)) { - pane.cur_row = pane.scroll(); - pane.cur_col = 0; + pane.body.cur_row = pane.scroll(); + pane.body.cur_col = 0; } else { const cur = Terminal.gridCursor(pane); - pane.cur_row = pane.surfRow(@as(i32, cur.y) + Terminal.gridOffset(pane)); - pane.cur_col = @intCast(cur.x); + pane.body.cur_row = pane.surfRow(@as(i32, cur.y) + Terminal.gridOffset(pane)); + pane.body.cur_col = @intCast(cur.x); } - pane.cur_pinned = true; + pane.body.cur_pinned = true; } pub fn hasPdf(pane: *const Pane) bool { @@ -581,545 +534,10 @@ pub const Pane = struct { else false; } - - pub fn toModalCursor(pane: *Pane) modal.Cursor { - return .{ .row = @intCast(@max(0, pane.cur_row)), .col = @intCast(@max(0, pane.cur_col)) }; - } - - pub fn fromModalCursor(pane: *Pane, c: modal.Cursor) void { - pane.cur_row = @as(i32, @intCast(c.row)); - pane.cur_col = @intCast(c.col); - pane.cur_pinned = true; - } - - pub fn insertVerticalCursor(lines: []const []const u8, c: modal.Cursor, down: bool) modal.Cursor { - if (lines.len == 0) return c; - const row = if (down) @min(c.row + 1, lines.len - 1) else c.row -| 1; - const target = lines[row]; - if (target.len == 0) return .{ .row = row, .col = 0 }; - const source = if (c.row < lines.len) lines[c.row] else ""; - const goal = File.rawDisplayCol(source, c.col); - const mapped = File.rawAtDisplay(target, goal); - const last = modal.prevGrapheme(target, target.len); - return .{ .row = row, .col = modal.graphemeStart(target, @min(mapped, last)) }; - } - - pub fn primaryRange(pane: *Pane, text: []const u8, row0: i32) modal.Selection { - const c = File.textOffset(pane, text, .{ .row = @intCast(@max(0, pane.cur_row - row0)), .col = @intCast(@max(0, pane.cur_col)) }); - if (pane.msel.active) { - // legacy line selection (file-search results highlight): linewise - const r0: usize = @intCast(@max(0, @min(pane.msel.r0, pane.msel.r1) - row0)); - const r1: usize = @intCast(@max(0, @max(pane.msel.r0, pane.msel.r1) - row0)); - const s = modal.lineStartOffset(text, r0); - const e = if (r1 + 1 >= modal.cursorLineCount(text)) text.len else modal.lineStartOffset(text, r1 + 1); - return .{ .anchor = s, .head = @max(e, modal.nextGrapheme(text, c)) }; - } - if (pane.vsel.active) return cellRange(text, pane.vsel.row - row0, pane.vsel.col, pane.cur_row - row0, pane.cur_col); - return .{ .anchor = c, .head = modal.nextGrapheme(text, c) }; - } - - pub fn cellRange(text: []const u8, arow: i32, acol: i32, hrow: i32, hcol: i32) modal.Selection { - const a = modal.offsetAt(text, .{ .row = @intCast(@max(0, arow)), .col = @intCast(@max(0, acol)) }); - const c = modal.offsetAt(text, .{ .row = @intCast(@max(0, hrow)), .col = @intCast(@max(0, hcol)) }); - return cellOffRange(text, a, c); - } - - /// the same, from the two cells' gap offsets - pub fn cellOffRange(text: []const u8, a: usize, c: usize) modal.Selection { - if (a <= c) return .{ .anchor = a, .head = modal.nextGrapheme(text, c) }; - return .{ .anchor = modal.nextGrapheme(text, a), .head = c }; - } - - pub fn rangeCells(text: []const u8, r: modal.Selection) struct { cur: usize, anc: usize } { - if (r.head > r.anchor) return .{ .cur = modal.prevGrapheme(text, r.head), .anc = r.anchor }; - if (r.head < r.anchor) return .{ .cur = r.head, .anc = modal.prevGrapheme(text, r.anchor) }; - return .{ .cur = r.head, .anc = r.head }; - } - - pub fn setRange(pane: *Pane, text: []const u8, row0: i32, r0: modal.Selection, explicit: bool) void { - var r = r0; - if (r.anchor == r.head) r.head = modal.nextGrapheme(text, r.head); // min_width_1 - const off = rangeCells(text, r); - const cc = File.textPosition(pane, text, off.cur); - // a bare block cursor has both cells on the same offset — the common - // case by far — and this conversion is not free even indexed - const ac = if (off.anc == off.cur) cc else File.textPosition(pane, text, off.anc); - pane.cur_row = @as(i32, @intCast(cc.row)) + row0; - pane.cur_col = @intCast(cc.col); - pane.vsel = .{ - .active = off.anc != off.cur or pane.select, - .row = @as(i32, @intCast(ac.row)) + row0, - .col = @intCast(ac.col), - .explicit = explicit or pane.select, - }; - pane.msel.active = false; - pane.nsel = 0; // writing ONE range means the selection IS that range - pane.cur_pinned = true; - pane.sticky_col = -1; - pane.normal.clear(); - pane.ensureCursorVisible(); - } - - pub fn ranges(pane: *Pane, text: []const u8, row0: i32, out: *[max_selections]modal.Selection) struct { n: usize, pri: usize } { - const pr = primaryRange(pane, text, row0); - var n: usize = 0; - var pri: usize = 0; - var placed = false; - for (pane.sels[0..pane.nsel]) |s| { - const r = cellRange(text, s.arow - row0, s.acol, s.row - row0, s.col); - if (!placed and @min(pr.anchor, pr.head) <= @min(r.anchor, r.head)) { - pri = n; - out[n] = pr; - n += 1; - placed = true; - } - out[n] = r; - n += 1; - } - if (!placed) { - pri = n; - out[n] = pr; - n += 1; - } - return .{ .n = n, .pri = pri }; - } - - pub fn setRanges(pane: *Pane, text: []const u8, in: []const modal.Selection, sticky: []const i32, pri0: usize, explicit: bool) void { - if (in.len == 0) return; // helix asserts non-empty; here it just means "no change" - var r: [max_selections]modal.Selection = undefined; - var st: [max_selections]i32 = undefined; - var n: usize = @min(in.len, max_selections); - var pri: usize = @min(pri0, n - 1); - for (in[0..n], 0..) |x, i| { - r[i] = x; - if (r[i].anchor == r[i].head) r[i].head = modal.nextGrapheme(text, r[i].head); - st[i] = if (i < sticky.len) sticky[i] else -1; - } - // insertion sort by start — n is tiny and usually already ordered - var i: usize = 1; - while (i < n) : (i += 1) { - var j = i; - while (j > 0 and @min(r[j].anchor, r[j].head) < @min(r[j - 1].anchor, r[j - 1].head)) : (j -= 1) { - std.mem.swap(modal.Selection, &r[j], &r[j - 1]); - std.mem.swap(i32, &st[j], &st[j - 1]); - if (pri == j) pri = j - 1 else if (pri == j - 1) pri = j; - } - } - var k: usize = 0; - i = 1; - while (i < n) : (i += 1) { - const a = r[k]; - const b = r[i]; - const af = @min(a.anchor, a.head); - const at = @max(a.anchor, a.head); - const bf = @min(b.anchor, b.head); - const bt = @max(b.anchor, b.head); - if (af == bf or (at > bf and bt > af)) { - r[k] = if (a.anchor > a.head and b.anchor > b.head) - .{ .anchor = @max(a.anchor, b.anchor), .head = @min(a.head, b.head) } - else - .{ .anchor = @min(af, bf), .head = @max(at, bt) }; - if (pri == i) pri = k; - if (st[k] < 0) st[k] = st[i]; - continue; - } - k += 1; - r[k] = b; - st[k] = st[i]; - if (pri == i) pri = k; - } - n = k + 1; - setRange(pane, text, 0, r[pri], explicit); - pane.sticky_col = st[pri]; - var w: usize = 0; - for (r[0..n], 0..) |x, idx| { - if (idx == pri) continue; - const c = rangeCells(text, x); - const cc = modal.positionAt(text, c.cur); - const ac = modal.positionAt(text, c.anc); - pane.sels[w] = .{ - .row = @as(i32, @intCast(cc.row)), - .col = @intCast(cc.col), - .arow = @as(i32, @intCast(ac.row)), - .acol = @intCast(ac.col), - .sticky = st[idx], - }; - w += 1; - } - pane.nsel = @intCast(w); - } - - pub fn multiSelAction(pane: *Pane, text: []const u8, kind: modal.Normal.Multi, cnt: usize) void { - var rs: [max_selections]modal.Selection = undefined; - const got = ranges(pane, text, 0, &rs); - const n = got.n; - const expl = (pane.vsel.active and pane.vsel.explicit) or pane.msel.active; - if (kind == .remove_primary) { - if (n < 2) return; // helix: "no selections remaining" - var out: [max_selections]modal.Selection = undefined; - var m: usize = 0; - for (rs[0..n], 0..) |r, i| { - if (i == got.pri) continue; - out[m] = r; - m += 1; - } - // helix Selection::remove: the NEXT range takes over, or the - // previous one when the primary was last - return setRanges(pane, text, out[0..m], &.{}, @min(got.pri, m - 1), expl); - } - if (kind == .rotate_forward or kind == .rotate_backward) { - const step = cnt % n; - const pri = if (kind == .rotate_forward) (got.pri + step) % n else (got.pri + (n - step)) % n; - return setRanges(pane, text, rs[0..n], &.{}, pri, expl); - } - if (kind == .merge) { - // helix merge_selections: first.merge(last) — the ranges are - // sorted, so that is simply the whole span - const lo = @min(rs[0].anchor, rs[0].head); - const hi = @max(rs[n - 1].anchor, rs[n - 1].head); - const rev = rs[0].anchor > rs[0].head and rs[n - 1].anchor > rs[n - 1].head; - const one: modal.Selection = if (rev) .{ .anchor = hi, .head = lo } else .{ .anchor = lo, .head = hi }; - return setRanges(pane, text, &.{one}, &.{}, 0, expl); - } - if (kind == .merge_consecutive) { - var out: [max_selections]modal.Selection = undefined; - var m: usize = 0; - var pri: usize = 0; - for (rs[0..n], 0..) |r, i| { - if (m > 0 and @min(r.anchor, r.head) == @max(out[m - 1].anchor, out[m - 1].head)) { - const lo = @min(@min(out[m - 1].anchor, out[m - 1].head), @min(r.anchor, r.head)); - const hi = @max(@max(out[m - 1].anchor, out[m - 1].head), @max(r.anchor, r.head)); - out[m - 1] = .{ .anchor = lo, .head = hi }; - if (i == got.pri) pri = m - 1; - continue; - } - if (i == got.pri) pri = m; - out[m] = r; - m += 1; - } - return setRanges(pane, text, out[0..m], &.{}, pri, expl); - } - if (kind == .split_newline) { - // helix selection::split_on_newline — one range per line the - // selection covers, the newlines themselves left out - var out: [max_selections]modal.Selection = undefined; - var m: usize = 0; - for (rs[0..n]) |r| { - const from = @min(r.anchor, r.head); - const to = @max(r.anchor, r.head); - if (from == to) { - if (m < max_selections) { - out[m] = r; - m += 1; - } - continue; - } - var start = from; - while (start < to and m < max_selections) { - const eol = modal.lineEndOffset(text, modal.lineAtOffset(text, start)); - if (eol >= to) { - out[m] = .{ .anchor = start, .head = to }; - m += 1; - break; - } - out[m] = .{ .anchor = start, .head = eol }; - m += 1; - start = eol + 1; - } - } - if (m == 0) return; - return setRanges(pane, text, out[0..m], &.{}, 0, true); // helix keeps primary 0 - } - if (kind == .trim) { - // helix trim_selections: whitespace off both ends; ranges that are - // empty or all whitespace are dropped entirely - var out: [max_selections]modal.Selection = undefined; - var m: usize = 0; - for (rs[0..n]) |r| { - var from = @min(r.anchor, r.head); - var to = @max(r.anchor, r.head); - while (from < to and std.ascii.isWhitespace(text[from])) from += 1; - while (to > from and std.ascii.isWhitespace(text[to - 1])) to -= 1; - if (from >= to) continue; - out[m] = if (r.anchor > r.head) .{ .anchor = to, .head = from } else .{ .anchor = from, .head = to }; - m += 1; - } - if (m == 0) { // helix: collapse_selection + keep_primary_selection - const c = modal.selectionCursor(text, rs[got.pri]); - return setRange(pane, text, 0, .{ .anchor = c, .head = c }, false); - } - // helix: the first survivor that OVERLAPS the old primary, else the last - const pf = @min(rs[got.pri].anchor, rs[got.pri].head); - const pt = @max(rs[got.pri].anchor, rs[got.pri].head); - var pri = m - 1; - for (out[0..m], 0..) |r, i| { - const f = @min(r.anchor, r.head); - const t = @max(r.anchor, r.head); - if (f == pf or (t > pf and pt > f)) { - pri = i; - break; - } - } - return setRanges(pane, text, out[0..m], &.{}, pri, expl); - } - const below = kind == .copy_below; - var out: [max_selections]modal.Selection = undefined; - var m: usize = 0; - var pri: usize = 0; - const nlines = modal.cursorLineCount(text); - for (rs[0..n], 0..) |r, ri| { - const is_pri = ri == got.pri; - // head-exclusive: back the leading end off onto its own cell - const hp = modal.positionAt(text, if (r.anchor < r.head) modal.prevGrapheme(text, r.head) else r.head); - const ap = modal.positionAt(text, if (r.anchor < r.head) r.anchor else modal.prevGrapheme(text, r.anchor)); - const height = @max(hp.row, ap.row) - @min(hp.row, ap.row) + 1; - if (m >= max_selections) break; - if (is_pri) pri = m; - out[m] = r; - m += 1; - var made: usize = 0; - var k: usize = 0; - while (made < cnt and m < max_selections) : (k += 1) { - const d = (k + 1) * height; - const arow = if (below) ap.row + d else ap.row -| d; - const hrow = if (below) hp.row + d else hp.row -| d; - if (arow >= nlines or hrow >= nlines) break; - const a2 = modal.offsetAt(text, .{ .row = arow, .col = ap.col }); - const h2 = modal.offsetAt(text, .{ .row = hrow, .col = hp.col }); - // a line too short to reach the column is skipped, not clamped - if (modal.positionAt(text, a2).col == ap.col and modal.positionAt(text, h2).col == hp.col) { - if (is_pri) pri = m; - out[m] = modal.moveSelectionCursor(text, .{ .anchor = a2, .head = a2 }, h2, true); - m += 1; - made += 1; - } - if (arow == 0 and hrow == 0) break; - } - } - setRanges(pane, text, out[0..m], &.{}, pri, expl); - } - - /// a range's start CELL (document order key) — the smaller of its two ends - pub fn selStart(s: SelRange) struct { row: i32, col: i32 } { - if (s.arow < s.row or (s.arow == s.row and s.acol < s.col)) return .{ .row = s.arow, .col = s.acol }; - return .{ .row = s.row, .col = s.col }; - } - - pub fn maxLine(text: []const u8) usize { - const nl = modal.cursorLineCount(text); - return if (text.len == 0 or text[text.len - 1] == '\n') nl -| 2 else nl - 1; - } - - /// point-target motion: collapse there (extend in select mode) - pub fn pointMove(pane: *Pane, text: []const u8, range: modal.Selection, target: usize) void { - setRange(pane, text, 0, modal.moveSelectionCursor(text, range, target, pane.select), false); - } - - /// word motions select their traversed span (extend mode: head only) - pub fn wordMove(pane: *Pane, text: []const u8, range: modal.Selection, cnt: usize, target: modal.WordTarget) void { - const wr = modal.moveWord(text, range, cnt, target); - const res = if (pane.select) modal.moveSelectionCursor(text, range, modal.selectionCursor(text, wr), true) else wr; - setRange(pane, text, 0, res, false); - } - - /// f/t/F/T: anchor at the old cursor cell, head on the hit (not found: no move) - pub fn findMove(pane: *Pane, text: []const u8, range: modal.Selection, ch: u21, fwd: bool, till: bool, cnt: usize) void { - const cur = modal.selectionCursor(text, range); - const t = modal.findTarget(text, cur, ch, fwd, till, cnt) orelse return; - const res = if (pane.select) - modal.moveSelectionCursor(text, range, t, true) - else - modal.moveSelectionCursor(text, .{ .anchor = cur, .head = cur }, t, true); - setRange(pane, text, 0, res, false); - } - - /// j/k and friends: sticky goal column, clamped onto short lines' newline - pub fn verticalMove(pane: *Pane, text: []const u8, range: modal.Selection, down: bool, cnt: usize) void { - const cur = modal.selectionCursor(text, range); - const pos = File.textPosition(pane, text, cur); - const goal: usize = if (pane.sticky_col >= 0) - @intCast(pane.sticky_col) - else - File.rawDisplayCol(File.textLine(pane, text, pos.row), pos.col); - const last_row = File.textLineCount(pane, text) - 1; - const nline = if (down) @min(pos.row + @max(1, cnt), last_row) else pos.row -| @max(1, cnt); - const target_col = File.rawAtDisplay(File.textLine(pane, text, nline), goal); - const t = File.textOffset(pane, text, .{ .row = nline, .col = target_col }); - // extend mode never walks onto the empty trailing line (helix) - if (pane.select and t == text.len and text.len > 0 and text[text.len - 1] == '\n') return; - setRange(pane, text, 0, modal.moveSelectionCursor(text, range, t, pane.select), false); - pane.sticky_col = @intCast(goal); - } - - pub fn visualMove( - pane: *Pane, - text: []const u8, - range: modal.Selection, - down: bool, - cnt: usize, - width: usize, - ) void { - const cur = modal.selectionCursor(text, range); - const pos = File.textPosition(pane, text, cur); - const last_row = File.textLineCount(pane, text) - 1; - var row = pos.row; - var line = modal.lineSlice(text, row); - var vrow = File.visualRow(line, pos.col, width); - const goal: usize = if (pane.sticky_col >= 0) - @intCast(pane.sticky_col) - else - File.rawDisplayCol(line[vrow.start..vrow.end], pos.col -| vrow.start); - var steps = @max(1, cnt); - while (steps > 0) : (steps -= 1) { - if (down) { - if (vrow.end < line.len) { - vrow = File.visualRow(line, vrow.end, width); - continue; - } - if (row == last_row) break; - row += 1; - line = modal.lineSlice(text, row); - vrow = File.visualRow(line, 0, width); - } else { - if (vrow.start > 0) { - vrow = File.visualRow(line, vrow.start - 1, width); - continue; - } - if (row == 0) break; - row -= 1; - line = modal.lineSlice(text, row); - vrow = File.visualRow(line, line.len, width); - } - } - // The newline slot is a real cursor position, but the first byte of the - // NEXT visual row is not: landing there would read as two rows moved. - var target_col = vrow.start + File.rawAtDisplay(line[vrow.start..vrow.end], goal); - if (vrow.end < line.len and target_col >= vrow.end) - target_col = modal.graphemeStart(line, vrow.end - 1); - const t = File.textOffset(pane, text, .{ .row = row, .col = target_col }); - // extend mode never walks onto the empty trailing line (helix) - if (pane.select and t == text.len and text.len > 0 and text[text.len - 1] == '\n') return; - setRange(pane, text, 0, modal.moveSelectionCursor(text, range, t, pane.select), false); - pane.sticky_col = @intCast(goal); - } - - /// Ctrl-d/u: scroll half a page AND move the cursor by the same rows - pub fn halfPageMove(pane: *Pane, text: []const u8, range: modal.Selection, down: bool) void { - const half: i32 = @max(1, @divTrunc(@as(i32, pane.rows), 2)); - pane.scrollBy(if (down) half else -half); - verticalMove(pane, text, range, down, @intCast(half)); - } - - /// helix `scroll` without cursor sync (Ctrl-f/b, PgUp/PgDn, zj/zk): shift - /// the view, then snap a fallen-out cursor to the near scrolloff edge, col 0 - pub fn scrollViewMove(pane: *Pane, text: []const u8, range: modal.Selection, delta: i32) void { - const margin: i32 = @min(config.scroll_off, @divTrunc(@as(i32, pane.rows) - 1, 2)); - pane.scrollBy(delta); - const top = pane.scroll(); - const last_row: i32 = @intCast(File.textLineCount(pane, text) - 1); - const cur = modal.selectionCursor(text, range); - if (delta > 0) { - const snap: i32 = @max(0, @min(top + margin, last_row)); - const head = File.textLineStart(pane, text, @intCast(snap)); - if (head <= cur) return; - const anchor = if (pane.select) range.anchor else head; - setRange(pane, text, 0, .{ .anchor = anchor, .head = head }, false); - } else { - const snap: i32 = @max(0, @min(top + @as(i32, pane.rows) - margin - 1, last_row)); - const head = File.textLineStart(pane, text, @intCast(snap)); - if (head >= cur) return; - const anchor = if (pane.select) range.anchor else head; - setRange(pane, text, 0, .{ .anchor = anchor, .head = head }, false); - } - } - - /// gt/gc/gb: view-relative rows, col 0, scrolloff clamped (helix goto_window) - pub fn gotoWindow(pane: *Pane, text: []const u8, range: modal.Selection, which: enum { top, center, bottom }, cnt: usize) void { - const margin: i32 = @min(config.scroll_off, @divTrunc(@as(i32, pane.rows) - 1, 2)); - const top = pane.scroll(); - const last_row: i32 = @intCast(File.textLineCount(pane, text) - 1); - const last_vis: i32 = @min(@as(i32, pane.rows) - 1, last_row - top); - const n: i32 = @intCast(cnt - 1); - var vline: i32 = switch (which) { - .top => top + margin + n, - .center => top + @divTrunc(last_vis, 2), - .bottom => top + last_vis - (margin + n), - }; - vline = @max(vline, top + margin); - vline = @min(vline, top + last_vis - margin); - const row: i32 = std.math.clamp(vline, 0, last_row); - pointMove(pane, text, range, File.textLineStart(pane, text, @intCast(row))); - } - - /// helix Range::line_range — the inclusive line span a range covers - pub fn rangeLineSpan(text: []const u8, r: modal.Selection) struct { start: usize, end: usize } { - const from = @min(r.anchor, r.head); - const to = @max(r.anchor, r.head); - const to_adj = if (from == to) to else @max(modal.prevGrapheme(text, to), from); - return .{ .start = modal.lineAtOffset(text, from), .end = modal.lineAtOffset(text, to_adj) }; - } - - fn lineStartOrEof(text: []const u8, line: usize) usize { - if (line >= modal.cursorLineCount(text)) return text.len; - return modal.lineStartOffset(text, line); - } - - /// helix `x` extend_line_below: full lines incl. the newline, cursor ON - /// the last one's '\n'; an already-line-bounded selection grows downward - pub fn lineSelect(pane: *Pane, text: []const u8, range: modal.Selection, cnt: usize) void { - const span = rangeLineSpan(text, range); - const start = modal.lineStartOffset(text, span.start); - const end = lineStartOrEof(text, span.end + 1); - const full = @min(range.anchor, range.head) == start and @max(range.anchor, range.head) == end; - const head = lineStartOrEof(text, span.end + cnt + @intFromBool(full)); - setRange(pane, text, 0, .{ .anchor = start, .head = head }, true); - } - - /// helix `X` extend_to_line_bounds (direction kept) - pub fn lineBoundsSelect(pane: *Pane, text: []const u8, range: modal.Selection) void { - const span = rangeLineSpan(text, range); - const start = modal.lineStartOffset(text, span.start); - const end = lineStartOrEof(text, span.end + 1); - const r: modal.Selection = if (range.head < range.anchor) - .{ .anchor = end, .head = start } - else - .{ .anchor = start, .head = end }; - setRange(pane, text, 0, r, true); - } - - /// helix `Alt-x` shrink_to_line_bounds (single-line selections untouched) - pub fn shrinkSelToLineBounds(pane: *Pane, text: []const u8, range: modal.Selection) void { - const span = rangeLineSpan(text, range); - if (span.start == span.end) return; - const from = @min(range.anchor, range.head); - const to = @max(range.anchor, range.head); - var start = modal.lineStartOffset(text, span.start); - var end = lineStartOrEof(text, span.end + 1); - if (start != from) start = lineStartOrEof(text, span.start + 1); - if (end != to) end = modal.lineStartOffset(text, span.end); - const expl = (pane.vsel.active and pane.vsel.explicit) or pane.msel.active; - const r: modal.Selection = if (range.head < range.anchor) - .{ .anchor = end, .head = start } - else - .{ .anchor = start, .head = end }; - setRange(pane, text, 0, r, expl); - } - - /// pull the cursor back inside `text` after a rewrite; `row0` is the - /// absolute surface row of its first line (0 for a file) - pub fn clampCursor(pane: *Pane, text: []const u8, row0: i32) void { - const n = modal.lineCount(text); - const row: usize = @min(@as(usize, @intCast(@max(0, pane.cur_row - row0))), if (n == 0) 0 else n - 1); - const llen = modal.lineSlice(text, row).len; - pane.cur_row = @as(i32, @intCast(row)) + row0; - pane.cur_col = @intCast(@min(@as(usize, @intCast(@max(0, pane.cur_col))), llen)); - pane.cur_pinned = true; - pane.vsel.active = false; - pane.msel.active = false; - pane.ensureCursorVisible(); - } }; +pub const Text = @import("Text.zig"); + pub const File = @import("File.zig"); pub const Output = @import("Output.zig"); @@ -1134,6 +552,7 @@ pub const Terminal = @import("Terminal.zig"); test { _ = Pane; + _ = Text; _ = File; _ = Output; _ = Mini; diff --git a/src/pardes.zig b/src/pardes.zig index 97860cfe..15b2c49b 100644 --- a/src/pardes.zig +++ b/src/pardes.zig @@ -240,6 +240,7 @@ pub const pdf_raster_policy: PdfRasterPolicy = switch (platform) { }; pub const Pane = panes.Pane; +const Text = panes.Text; pub const MAX_PANES = 16; pub const BodyLayer = @import("body_layer.zig").Layer; @@ -875,19 +876,19 @@ test "Togglettymode builtin and keyboard chord share mode transitions including try std.testing.expect(std.mem.indexOf(u8, Pardes.curTail(pane), " Mode ") != null); p.seedTail(pane); try std.testing.expect(pane.appendTag(" Togglettymode")); - try std.testing.expectEqual(Pane.Mode.tty, pane.mode); + try std.testing.expectEqual(Text.Mode.tty, pane.body.mode); try std.testing.expect(p.executeBuiltinLine(0, "Togglettymode")); - try std.testing.expectEqual(Pane.Mode.normal, pane.mode); + try std.testing.expectEqual(Text.Mode.normal, pane.body.mode); p.update(.{ .key = .{ .cp = p.opts.tty_toggle, .ctrl = true } }); - try std.testing.expectEqual(Pane.Mode.tty, pane.mode); + try std.testing.expectEqual(Text.Mode.tty, pane.body.mode); p.enterTagEdit(pane, -1); - try std.testing.expectEqual(Pane.Mode.insert, pane.mode); + try std.testing.expectEqual(Text.Mode.insert, pane.body.mode); try std.testing.expect(p.executeBuiltinLine(0, "Togglettymode")); - try std.testing.expectEqual(Pane.Mode.normal, pane.mode); + try std.testing.expectEqual(Text.Mode.normal, pane.body.mode); try std.testing.expect(!pane.tag_edit); p.enterTagEdit(pane, -1); p.update(.{ .key = .{ .cp = p.opts.tty_toggle, .ctrl = true } }); - try std.testing.expectEqual(Pane.Mode.tty, pane.mode); + try std.testing.expectEqual(Text.Mode.tty, pane.body.mode); try std.testing.expect(!pane.tag_edit); p.acknowledgePanelPresentation(&.{}); @@ -896,10 +897,10 @@ test "Togglettymode builtin and keyboard chord share mode transitions including const y = p.rects[0].y; p.update(.{ .mouse = .{ .button = .middle, .kind = .press, .col = x, .row = y } }); p.update(.{ .mouse = .{ .button = .middle, .kind = .release, .col = x, .row = y } }); - try std.testing.expectEqual(Pane.Mode.normal, pane.mode); + try std.testing.expectEqual(Text.Mode.normal, pane.body.mode); const file = try p.setTestFile("unchanged\n"); try std.testing.expect(p.executeBuiltinLine(0, "Togglettymode")); - try std.testing.expectEqual(Pane.Mode.normal, file.mode); + try std.testing.expectEqual(Text.Mode.normal, file.body.mode); try std.testing.expectEqualStrings("unchanged\n", file.file.?.content); } @@ -1143,7 +1144,7 @@ test "Tty spawns a raw shell in the caller's directory" { try std.testing.expect(free != 0); const nt = p.panes[free] orelse return error.NoNewPane; try std.testing.expect(nt.isTerminal()); - try std.testing.expect(nt.mode == .tty); + try std.testing.expect(nt.body.mode == .tty); var found = false; while (p.nextEffect()) |effect| switch (effect) { @@ -1165,7 +1166,7 @@ test "Tty9p marks only the new Linux terminal for a mounted shell" { try std.testing.expect(p.active != 0); try std.testing.expect(!p.panes[0].?.v9fs_on_spawn); const pane = p.panes[p.active].?; - try std.testing.expect(pane.isTerminal() and pane.mode == .tty); + try std.testing.expect(pane.isTerminal() and pane.body.mode == .tty); try std.testing.expect(pane.v9fs_on_spawn); try std.testing.expect(!pane.greet); try std.testing.expect(!exec.takesCommandLine(p, p.active)); @@ -1753,7 +1754,7 @@ test "owned cwd EOF failure retains the pane and Del retries its close" { p.update(.{ .eof = .{ .pane = 0 } }); try std.testing.expectEqual(parent, p.panes[0].?); try std.testing.expectEqual(parent, child.cwd.inherited); - try std.testing.expectEqual(Pane.Mode.normal, parent.mode); + 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.expectEqual(@as(usize, 0), p.effects_len); allocator.fail_index = std.math.maxInt(usize); @@ -2626,7 +2627,7 @@ test "Unicode display cells map back to body and tag byte cursors" { // Both halves map to its one byte boundary. p.update(.{ .mouse = .{ .button = config.select_button, .kind = .press, .col = text_x + 2, .row = body_y } }); p.update(.{ .mouse = .{ .button = config.select_button, .kind = .release, .col = text_x + 2, .row = body_y } }); - try std.testing.expectEqual(@as(i32, 1), pane.cur_col); + try std.testing.expectEqual(@as(i32, 1), pane.body.cur_col); // A click in the wide path glyph likewise becomes a byte cursor at the // grapheme start; arrow motion then advances by the full UTF-8 cluster. @@ -2660,8 +2661,8 @@ test "tabbed file aligns syntax cursor and mouse at the nearest insertion gap" { @memset(f.highlights, @intFromEnum(syntax.Syn.none)); @memset(f.highlights[1..7], @intFromEnum(syntax.Syn.keyword)); f.syntax_dirty = false; - pane.cur_row = 0; - pane.cur_col = 1; + pane.body.cur_row = 0; + pane.body.cur_col = 1; var frame = std.heap.ArenaAllocator.init(gpa); defer frame.deinit(); @@ -2678,14 +2679,14 @@ test "tabbed file aligns syntax cursor and mouse at the nearest insertion gap" { const click_x = text_x + config.tab_width + 2; p.update(.{ .mouse = .{ .button = config.select_button, .kind = .press, .col = click_x, .row = body_y } }); p.update(.{ .mouse = .{ .button = config.select_button, .kind = .release, .col = click_x, .row = body_y } }); - try std.testing.expectEqual(@as(i32, 3), pane.cur_col); + try std.testing.expectEqual(@as(i32, 3), pane.body.cur_col); const line = modal.lineSlice(f.content, 0); const virtual: u16 = 3; const blank_x = text_x + @as(u16, @intCast(panes.File.displayWidth(line))) + virtual; p.update(.{ .mouse = .{ .button = config.select_button, .kind = .press, .col = blank_x, .row = body_y } }); p.update(.{ .mouse = .{ .button = config.select_button, .kind = .release, .col = blank_x, .row = body_y } }); - try std.testing.expectEqual(@as(i32, @intCast(line.len)), pane.cur_col); + try std.testing.expectEqual(@as(i32, @intCast(line.len)), pane.body.cur_col); _ = frame.reset(.retain_capacity); const virtual_surface = try p.render(frame.allocator()); @@ -3887,7 +3888,7 @@ pub const Pardes = struct { }, .tty, .tty_shell => { _ = try p.newShell(0, ""); - p.panes[0].?.mode = .tty; + p.panes[0].?.body.mode = .tty; p.oneColumn(); // A bare tty is still an editor: it opens with somewhere to put // text under the shell. The shell keeps the keyboard. @@ -4108,8 +4109,8 @@ pub const Pardes = struct { if (comptime pdf_enabled) if (pane.pdf) |*pv| panes.Pdf.deinitPane(p, pane, pv); if (pane.file) |*file| panes.File.deinit(p, pane, file); if (pane.ovl) |o| p.gpa.free(o.text); - for (pane.ed_undo[0..pane.ed_undo_len]) |sn| if (sn.ovl) |o| p.gpa.free(o.text); - for (pane.ed_redo[0..pane.ed_redo_len]) |sn| if (sn.ovl) |o| p.gpa.free(o.text); + for (pane.body.ed_undo[0..pane.body.ed_undo_len]) |sn| if (sn.ovl) |o| p.gpa.free(o.text); + for (pane.body.ed_redo[0..pane.body.ed_redo_len]) |sn| if (sn.ovl) |o| p.gpa.free(o.text); panes.Terminal.deinitEmulator(pane, p.gpa); pane.clearCwd(); pane.fs.deinit(p.gpa); @@ -4159,7 +4160,7 @@ pub const Pardes = struct { errdefer p.gpa.free(content); const np = try panes.Output.open(p, free, paneDir(src), .{ .cmd = .New }, "", content); np.cwd = .{ .inherited = src }; - np.cur_pinned = true; + np.body.cur_pinned = true; return np; } @@ -4170,7 +4171,7 @@ pub const Pardes = struct { const content = try p.gpa.dupe(u8, ""); errdefer p.gpa.free(content); const np = try panes.Output.open(p, free, dir, .{ .cmd = .New }, "", content); - np.cur_pinned = true; + np.body.cur_pinned = true; return np; } @@ -4685,7 +4686,7 @@ pub const Pardes = struct { ctlfs.pty.noteMarks(p, o.pane, pane); }, .eof => |e| p.removePane(e.pane, null) catch |err| { - if (p.panes[e.pane]) |pane| pane.mode = .normal; + if (p.panes[e.pane]) |pane| pane.body.mode = .normal; p.reportError(e.pane, "terminal exited; Del retries close", err); }, .lsp_resp => |r| p.lspResponse(r.id, r.rows), @@ -4839,12 +4840,12 @@ pub const Pardes = struct { const edit0: i32 = @intCast((p.tagPrefix(pane) catch return).len); p.seedTail(pane); if (!pane.tag_init) return; - if (!pane.tag_edit) pane.tag_mode = pane.mode; + if (!pane.tag_edit) pane.tag_mode = pane.body.mode; pane.tag_edit = true; pane.tag_sel = false; // a one-line tag has no use for normal mode: always insert - pane.mode = .insert; - pane.normal.clear(); + pane.body.mode = .insert; + pane.body.normal.clear(); const end = edit0 + @as(i32, @intCast(pane.tag_tail_len)); const tail = pane.tagSlice(); const lead: i32 = @intCast(tail.len - std.mem.trimStart(u8, tail, " ").len); @@ -4870,8 +4871,8 @@ pub const Pardes = struct { pub fn exitTagEdit(pane: *Pane) void { if (pane.tag_edit and pane.prompt == .none) pane.tag_saved_col = pane.tag_col; if (pane.isTerminal()) { - if (pane.tag_edit) pane.mode = pane.tag_mode; - } else pane.mode = .normal; + if (pane.tag_edit) pane.body.mode = pane.tag_mode; + } else pane.body.mode = .normal; pane.tag_edit = false; pane.tag_sel = false; pane.tag_name_len = null; @@ -5054,7 +5055,7 @@ pub const Pardes = struct { const id = p.active; const body_mode = pane.tag_mode; exitTagEdit(pane); // leave the tag FIRST: Del frees the pane - pane.mode = body_mode; + pane.body.mode = body_mode; exec.runBuiltin(p, cmd, id, "", txt); return; } @@ -5075,7 +5076,7 @@ pub const Pardes = struct { else cur)); pane.tag_sel = false; - pane.mode = .insert; + pane.body.mode = .insert; return; } const dir: ?Builtin = for (config.window_keys) |wk| { @@ -5096,7 +5097,7 @@ pub const Pardes = struct { const dest = p.panes[p.active] orelse return; exitTagEdit(pane); // the pane we left is fully out of its tag... p.enterTagEdit(dest, -1); - if (dest.tag_edit) dest.mode = .normal; + if (dest.tag_edit) dest.body.mode = .normal; return; } if (lineMotion(text, cur, key)) |r| setTagRange(pane, text, r); @@ -5244,7 +5245,7 @@ pub const Pardes = struct { p.exitHeader(); p.active = d; p.enterTagEdit(pane, -1); - if (pane.tag_edit) pane.mode = .normal; + if (pane.tag_edit) pane.body.mode = .normal; return; } if (hit(key, config.topbar_up)) { @@ -5268,19 +5269,19 @@ pub const Pardes = struct { pub fn cycleMode(p: *Pardes, id: usize) void { const pane = p.panes[id] orelse return; if (pane.file == null and !pane.isTerminal()) return; - const previous = if (pane.tag_edit) pane.tag_mode else pane.mode; + const previous = if (pane.tag_edit) pane.tag_mode else pane.body.mode; p.active = id; p.exitHeader(); if (pane.tag_edit) exitTagEdit(pane); - pane.mode = previous; + pane.body.mode = previous; switch (previous) { .tty => { - pane.mode = .normal; - pane.normal.clear(); + pane.body.mode = .normal; + pane.body.normal.clear(); }, - .normal => edit.enterInsert(p, pane, .at, 1), + .normal => edit.enterInsert(p, &pane.body, .at, 1), .insert => { - edit.exitInsert(p, pane); + edit.exitInsert(p, &pane.body); if (pane.isTerminal()) panes.Terminal.enterTty(p, id); }, } @@ -5293,9 +5294,9 @@ pub const Pardes = struct { p.active = id; p.exitHeader(); if (pane.tag_edit) exitTagEdit(pane); - if (pane.mode == .tty) { - pane.mode = .normal; - pane.normal.clear(); + if (pane.body.mode == .tty) { + pane.body.mode = .normal; + pane.body.normal.clear(); } else panes.Terminal.enterTty(p, id); } @@ -5312,7 +5313,7 @@ pub const Pardes = struct { } if (p.topbar_col != null) return p.topbarKey(key); const pane = p.panes[p.active] orelse return; - if (pane.isTerminal() and pane.mode == .tty and !pane.tag_edit) { + if (pane.isTerminal() and pane.body.mode == .tty and !pane.tag_edit) { p.leader_on = false; p.ctrl_w_pending = false; if (key.ctrl and !key.alt and key.cp == p.opts.tty_toggle) @@ -5350,7 +5351,7 @@ pub const Pardes = struct { } // insert mode owns Ctrl-w (delete word backward, helix); the focus // prefix applies outside raw tty mode - if (hit(key, config.window_prefix) and pane.mode != .insert) { + if (hit(key, config.window_prefix) and pane.body.mode != .insert) { p.ctrl_w_pending = true; return; } @@ -5403,27 +5404,27 @@ pub const Pardes = struct { .none, .del_side => unreachable, } exitTagEdit(pane); - pane.mode = .normal; - pane.normal.clear(); + pane.body.mode = .normal; + pane.body.normal.clear(); return; } if (pane.tag_edit) { - if (pane.mode == .normal) p.tagNormalKey(pane, key) else p.tagInsertKey(pane, key); + if (pane.body.mode == .normal) p.tagNormalKey(pane, key) else p.tagInsertKey(pane, key); const pn = p.panes[p.active] orelse return; if (normal.selRegexArmed(pn)) |a| normal.applySelRegex(p, pn, a.pat, a.split); return; } - if (pane.mode == .normal and (hit(key, config.look_key) or hit(key, config.exec_key))) { + if (pane.body.mode == .normal and (hit(key, config.look_key) or hit(key, config.exec_key))) { const cmd = if (hit(key, config.look_key)) config.look_cmd else config.exec_cmd; - edit.pinPaneCursor(p, pane); + edit.pinPaneCursor(p, &pane.body); const explicit = (p.native_images and pane.hasPdfSelection()) or - (pane.vsel.active and pane.vsel.explicit) or pane.msel.active; + (pane.body.vsel.active and pane.body.vsel.explicit) or pane.body.msel.active; if (explicit) { if (exec.chordEachSel(p, pane, cmd)) return; if (edit.currentSelText(p, pane)) |txt| { - pane.vsel.active = false; - pane.msel.active = false; - pane.select = false; + pane.body.vsel.active = false; + pane.body.msel.active = false; + pane.body.select = false; exec.runBuiltin(p, cmd, p.active, "", txt); return; } @@ -5433,14 +5434,14 @@ pub const Pardes = struct { exec.runBuiltin(p, cmd, p.active, "", word); return; } - if (pane.mode == .normal and pane.hasPdf()) return normal.handlePdfNormal(p, pane, key); - switch (pane.mode) { + if (pane.body.mode == .normal and pane.hasPdf()) return normal.handlePdfNormal(p, pane, key); + switch (pane.body.mode) { .normal => { - normal.handleNormal(p, pane, key); + normal.handleNormal(p, &pane.body, key); }, .insert => { - if (hit(key, config.escape)) return edit.exitInsert(p, pane); - edit.handleInsert(p, pane, key); + if (hit(key, config.escape)) return edit.exitInsert(p, &pane.body); + edit.handleInsert(p, &pane.body, key); }, .tty => panes.Terminal.forwardKey(p, p.active, key), } @@ -5529,8 +5530,8 @@ pub const Pardes = struct { }; pane.tag_edit = true; pane.tag_sel = false; - pane.mode = .insert; - pane.normal.clear(); + pane.body.mode = .insert; + pane.body.normal.clear(); pane.tag_col = @intCast(prefix_len + pane.tag_tail_len); } @@ -5551,8 +5552,8 @@ pub const Pardes = struct { if (!zig_buf and std.mem.indexOfAny(u8, arg, " \t\r\n\"\\") != null) return; } const off = if (pane.file) |f| modal.offsetAt(f.content, .{ - .row = @intCast(@max(0, pane.cur_row)), - .col = @intCast(@max(0, pane.cur_col)), + .row = @intCast(@max(0, pane.body.cur_row)), + .col = @intCast(@max(0, pane.body.cur_col)), }) else 0; p.lsp_seq +%= 1; p.lsp_wait = .{ @@ -5562,8 +5563,8 @@ pub const Pardes = struct { .serial = pane.serial, .revision = if (pane.file) |f| f.revision else 0, .arg = .from(arg), - .row = pane.cur_row, - .col = pane.cur_col, + .row = pane.body.cur_row, + .col = pane.body.cur_col, }; p.emit(.{ .lsp = .{ .id = p.lsp_seq, @@ -5666,8 +5667,8 @@ pub const Pardes = struct { const replacement = p.gpa.alloc(u8, final_len) catch return false; const old_cursor = modal.offsetAt(f.content, .{ - .row = @intCast(@max(0, pane.cur_row)), - .col = @intCast(@max(0, pane.cur_col)), + .row = @intCast(@max(0, pane.body.cur_row)), + .col = @intCast(@max(0, pane.body.cur_col)), }); const mapped_cursor = mapLspEditOffset(edits, old_cursor); var read_at: usize = 0; @@ -5681,15 +5682,15 @@ pub const Pardes = struct { } @memcpy(replacement[write_at..], f.content[read_at..]); - edit.pushUndo(p, pane); + edit.pushUndo(p, &pane.body); panes.File.setContent(p, f, replacement); const cursor = modal.positionAt(f.content, mapped_cursor); - pane.cur_row = @intCast(cursor.row); - pane.cur_col = @intCast(cursor.col); - pane.vsel.active = false; - pane.msel.active = false; - pane.select = false; - pane.sticky_col = -1; + pane.body.cur_row = @intCast(cursor.row); + pane.body.cur_col = @intCast(cursor.col); + pane.body.vsel.active = false; + pane.body.msel.active = false; + pane.body.select = false; + pane.body.sticky_col = -1; pane.ensureCursorVisible(); return true; } @@ -5718,8 +5719,8 @@ pub const Pardes = struct { } else return; } if (rows.len == 0) { - if (w.kind == .completion and pane.mode == .insert and pane.nsel == 0 and - pane.cur_row == w.row and pane.cur_col == w.col) edit.insertTab(p, pane); + if (w.kind == .completion and pane.body.mode == .insert and pane.body.nsel == 0 and + pane.body.cur_row == w.row and pane.body.cur_col == w.col) edit.insertTab(p, &pane.body); return; } @@ -5789,7 +5790,7 @@ pub const Pardes = struct { errdefer p.gpa.destroy(history); const pane = try p.newDocPane(id); pane.file = .{ .path = path, .content = content, .history = history }; - pane.cur_pinned = true; + pane.body.cur_pinned = true; return pane; } @@ -5806,7 +5807,7 @@ pub const Pardes = struct { p.panes[0] = null; pane.file = .{ .path = path, .content = copy, .history = history }; p.installPane(0, pane); - pane.cur_pinned = true; + pane.body.cur_pinned = true; p.active = 0; p.sync(); return pane; @@ -6015,8 +6016,8 @@ pub const Pardes = struct { const now: Loc = .{ .pane = @intCast(p.active), .serial = pane.serial, - .line = if (pane.pdfPage()) |page| @intCast(page + 1) else if (pane.cur_pinned) @intCast(@max(0, pane.cur_row) + 1) else 0, - .col = if (pane.pdfPage() != null) 0 else if (pane.cur_pinned) @intCast(@max(0, pane.cur_col) + 1) else 0, + .line = if (pane.pdfPage()) |page| @intCast(page + 1) else if (pane.body.cur_pinned) @intCast(@max(0, pane.body.cur_row) + 1) else 0, + .col = if (pane.pdfPage() != null) 0 else if (pane.body.cur_pinned) @intCast(@max(0, pane.body.cur_col) + 1) else 0, }; if (p.njumps > 0 and p.samePlace(p.jumps[p.jcur], now)) { p.jumps[p.jcur] = now; // same visit; the entry IS where you are @@ -6289,7 +6290,7 @@ pub const Pardes = struct { if (prompt_col < printed.dropped) continue; const caret = printed.left + (prompt_col - printed.dropped); if (caret < tx + tw) - s.cursor = .{ .x = @intCast(caret), .y = row, .bar = pane.mode == .insert }; + s.cursor = .{ .x = @intCast(caret), .y = row, .bar = pane.body.mode == .insert }; } } @@ -6717,7 +6718,7 @@ pub const Pardes = struct { const typed = panes.File.displayWidth(text[0..@min(pane.tag_col - prompt0, text.len)]); const dropped = shown - panes.File.displayWidth(kept); if (typed < dropped) continue; - p.surface.tag_layers[layer_index].cursor = .{ .col = @intCast(pad + typed - dropped), .bar = pane.mode == .insert }; + p.surface.tag_layers[layer_index].cursor = .{ .col = @intCast(pad + typed - dropped), .bar = pane.body.mode == .insert }; } } if (p.columnBarHeight() > 0) for (0..p.ncol) |column| { @@ -6820,7 +6821,7 @@ pub const Pardes = struct { .font_role = .tagline, }; s.fill(r.x, tag_y, config.GUTTER, BOX_H, box_style); - const box_mode = if (pane.tag_edit) pane.tag_mode else pane.mode; + const box_mode = if (pane.tag_edit) pane.tag_mode else pane.body.mode; s.set(r.x, tag_y, switch (box_mode) { .normal => config.tag_normal, .insert => config.tag_insert, @@ -6929,7 +6930,7 @@ pub const Pardes = struct { if (active and pane.tag_edit) { // bar while typing, block for `:` normal mode (same rule as a body) const col = panes.File.rawDisplayCol(tag, pane.tag_col) -| pane.tag_scroll; - if (col < tw) s.cursor = .{ .x = tx + @as(u16, @intCast(col)), .y = tag_y, .bar = pane.mode == .insert }; + if (col < tw) s.cursor = .{ .x = tx + @as(u16, @intCast(col)), .y = tag_y, .bar = pane.body.mode == .insert }; } for (pane.sel, 0..) |selection, button| { @@ -7039,7 +7040,7 @@ test "raw terminal cursor obeys visibility without hiding modal and tag cursors" defer p.deinit(); while (p.nextEffect()) |_| {} const pane = p.panes[0].?; - pane.mode = .tty; + pane.body.mode = .tty; p.update(.{ .output = .{ .pane = 0, .bytes = "abc" } }); var frame = std.heap.ArenaAllocator.init(gpa); defer frame.deinit(); @@ -7051,10 +7052,10 @@ test "raw terminal cursor obeys visibility without hiding modal and tag cursors" p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[?25l" } }); try std.testing.expect((try p.render(frame.allocator())).cursor == null); - pane.mode = .normal; - pane.cur_pinned = true; - pane.cur_row = 0; - pane.cur_col = 1; + pane.body.mode = .normal; + pane.body.cur_pinned = true; + pane.body.cur_row = 0; + pane.body.cur_col = 1; const modal_cursor = (try p.render(frame.allocator())).cursor orelse return error.MissingCursor; try std.testing.expectEqual(rect.x + config.GUTTER + 1, modal_cursor.x); try std.testing.expectEqual(body_y, modal_cursor.y); @@ -7062,7 +7063,7 @@ test "raw terminal cursor obeys visibility without hiding modal and tag cursors" const tag_cursor = (try p.render(frame.allocator())).cursor orelse return error.MissingCursor; try std.testing.expectEqual(if (p.settings.tag_bottom) rect.y + rect.h - BOX_H else rect.y, tag_cursor.y); Pardes.exitTagEdit(pane); - pane.mode = .tty; + pane.body.mode = .tty; try std.testing.expect((try p.render(frame.allocator())).cursor == null); p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[?25h\x1b[?1049h\x1b[2;5H" } }); @@ -7086,7 +7087,7 @@ test "raw terminal cursor follows its active row only while that row is visible" while (p.nextEffect()) |_| {} p.settings.tag_bottom = tag_bottom; const pane = p.panes[0].?; - pane.mode = .tty; + pane.body.mode = .tty; for (0..60) |_| p.update(.{ .output = .{ .pane = 0, .bytes = "row\r\n" } }); p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[3;4H" } }); var frame = std.heap.ArenaAllocator.init(gpa); @@ -7129,7 +7130,7 @@ test "Esc back into a tty leaves its view at the prompt" { try std.testing.expectEqual(shell, p.active); p.update(.{ .key = .{ .cp = Key.escape, .shift = true } }); - try std.testing.expectEqual(Pane.Mode.tty, sp.mode); + try std.testing.expectEqual(Text.Mode.tty, sp.body.mode); // tty mode follows output to the bottom, so a screenful and a half of it // rides the view down and leaves that pin far up in the scrollback. @@ -7368,7 +7369,7 @@ test "the bare tty startup opens a text pane under the shell, unfocused" { const shell = p.panes[p.col_panes[0][0]].?; const scratch = p.panes[p.col_panes[0][1]].?; try std.testing.expect(shell.isTerminal()); - try std.testing.expectEqual(Pane.Mode.tty, shell.mode); + try std.testing.expectEqual(Text.Mode.tty, shell.body.mode); try std.testing.expect(!scratch.isTerminal()); try std.testing.expectEqualStrings("", scratch.file.?.content); @@ -7391,7 +7392,7 @@ test "tty output follows only from the bottom" { const shell = p.active; const sp = p.panes[shell].?; p.update(.{ .key = .{ .cp = Key.escape, .shift = true } }); - try std.testing.expectEqual(Pane.Mode.tty, sp.mode); + try std.testing.expectEqual(Text.Mode.tty, sp.body.mode); for (0..60) |i| { var buf: [32]u8 = undefined; @@ -7445,7 +7446,7 @@ test "Esc back into a file leaves its view where it was" { for (0..20) |_| p.update(.{ .key = .{ .cp = 'j' } }); p.sync(); const view = dp.file.?.scroll; - const row = dp.cur_row; + const row = dp.body.cur_row; try std.testing.expect(view > 0); p.update(.{ .key = .{ .cp = Key.escape } }); // out to the shell @@ -7458,10 +7459,10 @@ test "Esc back into a file leaves its view where it was" { // Nothing moved. The old landing recentred the line under the cursor, so // coming back repainted the whole screen to show what was already on it. try std.testing.expectEqual(view, dp.file.?.scroll); - try std.testing.expectEqual(row, dp.cur_row); + try std.testing.expectEqual(row, dp.body.cur_row); // ...and the cursor is still on screen, which is all `.nearest` promises. - try std.testing.expect(dp.cur_row >= @as(i32, @intCast(view))); - try std.testing.expect(dp.cur_row < @as(i32, @intCast(view)) + @as(i32, dp.rows)); + try std.testing.expect(dp.body.cur_row >= @as(i32, @intCast(view))); + try std.testing.expect(dp.body.cur_row < @as(i32, @intCast(view)) + @as(i32, dp.rows)); // The other arm still centres: a look target, a `:NN`, a search hit. look.focusPaneLine(p, doc, .{ .line = @intCast(row + 1), .col = 1 }, .center); @@ -7488,7 +7489,7 @@ test "raw tty Escape only leaves at a shell prompt" { p.update(.{ .key = .{ .cp = Key.escape, .shift = true } }); try std.testing.expectEqual(@as(usize, 0), p.active); try std.testing.expectEqualStrings("", drainWrites(p, &buf)); - try std.testing.expectEqual(Pane.Mode.tty, pane.mode); + try std.testing.expectEqual(Text.Mode.tty, pane.body.mode); p.update(.{ .key = .{ .cp = Key.escape } }); // back into the shell try std.testing.expectEqual(shell, p.active); @@ -7497,7 +7498,7 @@ test "raw tty Escape only leaves at a shell prompt" { p.update(.{ .key = .{ .cp = Key.escape } }); // bare Escape leaves at a prompt try std.testing.expectEqual(@as(usize, 0), p.active); try std.testing.expectEqualStrings("", drainWrites(p, &buf)); - try std.testing.expectEqual(Pane.Mode.tty, pane.mode); + try std.testing.expectEqual(Text.Mode.tty, pane.body.mode); } test "raw tty Ctrl-B switches to editor mode without sending child input" { @@ -7511,7 +7512,7 @@ test "raw tty Ctrl-B switches to editor mode without sending child input" { _ = drainWrites(p, &buf); p.update(.{ .key = .{ .cp = 'b', .ctrl = true } }); try std.testing.expectEqual(shell, p.active); - try std.testing.expectEqual(Pane.Mode.normal, p.panes[shell].?.mode); + try std.testing.expectEqual(Text.Mode.normal, p.panes[shell].?.body.mode); try std.testing.expectEqualStrings("", drainWrites(p, &buf)); } @@ -7599,7 +7600,7 @@ test "raw tty forwards Ctrl letters and former global shortcuts to the child" { }; try std.testing.expectEqualStrings(encoded, drainWrites(p, &buf)); try std.testing.expectEqual(@as(usize, 0), p.active); - try std.testing.expectEqual(Pane.Mode.tty, p.panes[0].?.mode); + try std.testing.expectEqual(Text.Mode.tty, p.panes[0].?.body.mode); try std.testing.expect(!p.ctrl_w_pending and p.clip_pending == null); } // ...and the two paste chords are the exception: Ctrl-V types the register @@ -7745,13 +7746,13 @@ test "leaving tty hides the prompt and keeps the command typed at it" { // The BODY is what you look at, and it follows the mode: in tty the pane // is the program's own screen, so the prompt is there. - sp.mode = .tty; + sp.body.mode = .tty; try std.testing.expectEqualStrings( "user@box ~/src $ grep -rn TODO src/", bodyRowOf(p, sp, "grep") orelse return error.MissingPromptRow, ); - sp.mode = .normal; + sp.body.mode = .normal; try std.testing.expectEqualStrings( "grep -rn TODO src/", bodyRowOf(p, sp, "grep") orelse return error.MissingPromptRow, @@ -7788,7 +7789,7 @@ test "entering tty walks the shell cursor to the column clicked past the prompt" .bytes = "\x1b]133;A;cl=line\x1b\\prompt> \x1b]133;B\x1b\\0123456789", } }); p.sync(); - sp.mode = .normal; + sp.body.mode = .normal; p.shell_rows.stale = true; // The command shows LEFT-HUGGED, so its column 3 is the '3'... @@ -7802,9 +7803,9 @@ test "entering tty walks the shell cursor to the column clicked past the prompt" // ...but the shell's own cursor lives on the real grid, eight cells // further right, behind the prompt this pane is not showing. - sp.cur_row = row; - sp.cur_col = 3; - sp.cur_pinned = true; + sp.body.cur_row = row; + sp.body.cur_col = 3; + sp.body.cur_pinned = true; while (p.nextEffect()) |_| {} panes.Terminal.enterTty(p, shell); @@ -7897,8 +7898,8 @@ test "LSP failure clears only its matching wait without completion indentation" const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true }); defer p.deinit(); const pane = try p.setTestFile("x"); - pane.mode = .insert; - pane.cur_col = 1; + pane.body.mode = .insert; + pane.body.cur_col = 1; p.lspRequest(p.active, .completion, ""); const old_id = p.lsp_wait.?.id; @@ -7909,13 +7910,13 @@ test "LSP failure clears only its matching wait without completion indentation" p.update(.{ .lsp_resp = .{ .id = current_id, .rows = null } }); try std.testing.expect(p.lsp_wait == null); try std.testing.expectEqualStrings("x", pane.file.?.content); - try std.testing.expectEqual(@as(i32, 1), pane.cur_col); + try std.testing.expectEqual(@as(i32, 1), pane.body.cur_col); p.lspRequest(p.active, .completion, ""); p.update(.{ .lsp_resp = .{ .id = p.lsp_wait.?.id, .rows = "" } }); try std.testing.expect(p.lsp_wait == null); try std.testing.expectEqualStrings("x ", pane.file.?.content); - try std.testing.expectEqual(@as(i32, 4), pane.cur_col); + try std.testing.expectEqual(@as(i32, 4), pane.body.cur_col); } test "board heap: every allocation failure during boot is a clean OutOfMemory" { @@ -7935,25 +7936,25 @@ test "jump history clears selections and lands at the recorded cursor" { p.jumps[0] = .{ .pane = 0, .serial = pane.serial, .line = 3, .col = 8 }; p.jumps[1] = .{ .pane = 0, .serial = pane.serial, .line = 1, .col = 1 }; for ([_]u21{ 'o', 'i' }, 0..) |key, index| { - pane.setRange(pane.file.?.content, 0, .{ .anchor = 1, .head = 5 }, true); + pane.body.setRange(pane.file.?.content, 0, .{ .anchor = 1, .head = 5 }, true); pane.sel[0] = .{ .state = .done, .c0 = 2, .c1 = 5, .r0 = 1, .r1 = 1 }; try edit.capturePointerSelection(p, pane, 0); - pane.select = true; + pane.body.select = true; p.update(.{ .key = .{ .cp = key, .ctrl = true } }); try std.testing.expectEqual(index, p.jcur); try std.testing.expectEqual(@as(usize, 2), p.njumps); try std.testing.expectEqual(@as(u32, 3), p.jumps[0].line); - try std.testing.expect(!pane.vsel.active and !pane.msel.active and !pane.select); - try std.testing.expectEqual(@as(u8, 0), pane.nsel); + try std.testing.expect(!pane.body.vsel.active and !pane.body.msel.active and !pane.body.select); + try std.testing.expectEqual(@as(u8, 0), pane.body.nsel); try std.testing.expectEqual(.none, pane.sel[0].state); try std.testing.expect(pane.pointer_selections[0] == null); - try std.testing.expectEqual(@as(i32, if (index == 0) 2 else 0), pane.cur_row); - try std.testing.expectEqual(@as(i32, if (index == 0) 7 else 0), pane.cur_col); + try std.testing.expectEqual(@as(i32, if (index == 0) 2 else 0), pane.body.cur_row); + try std.testing.expectEqual(@as(i32, if (index == 0) 7 else 0), pane.body.cur_col); } - pane.setRange(pane.file.?.content, 0, .{ .anchor = 1, .head = 5 }, true); - const selected = pane.primaryRange(pane.file.?.content, 0); + pane.body.setRange(pane.file.?.content, 0, .{ .anchor = 1, .head = 5 }, true); + const selected = pane.body.primaryRange(pane.file.?.content, 0); p.jumpBy(1); // No forward entry: selection stays untouched. - try std.testing.expectEqualDeep(selected, pane.primaryRange(pane.file.?.content, 0)); + try std.testing.expectEqualDeep(selected, pane.body.primaryRange(pane.file.?.content, 0)); for ([_]Loc{ .{ .pane = 15, .serial = pane.serial, .line = 1, .col = 1 }, .{ .pane = 0, .serial = pane.serial + 1, .line = 1, .col = 1 }, @@ -7961,7 +7962,7 @@ test "jump history clears selections and lands at the recorded cursor" { p.jumps[0] = missing; p.jumpBy(-1); try std.testing.expectEqual(@as(usize, 1), p.jcur); - try std.testing.expectEqualDeep(selected, pane.primaryRange(pane.file.?.content, 0)); + try std.testing.expectEqualDeep(selected, pane.body.primaryRange(pane.file.?.content, 0)); } } diff --git a/src/pdf_view.zig b/src/pdf_view.zig index 721dac5a..92a05618 100644 --- a/src/pdf_view.zig +++ b/src/pdf_view.zig @@ -1911,7 +1911,7 @@ pub fn openPane( errdefer state.deinit(core.pdf_gpa); const pane = try core.newDocPane(id); pane.pdf = state; - pane.cur_pinned = true; + pane.body.cur_pinned = true; if (filesystem.localPath(path) != null) core.emit(.{ .watch = .{ .pane = @intCast(id), .on = true } }); return pane; } @@ -1967,15 +1967,15 @@ fn refreshCleanSections(core: *pardes.Pardes, state: *State) void { File.setContent(core, file, content); const rows = File.lineCount(file.content); file.scroll = @min(file.scroll, rows - 1); - const row = @min(@as(usize, @intCast(@max(0, result.cur_row))), rows - 1); - result.cur_row = @intCast(row); - result.cur_col = @intCast(@min( - @as(usize, @intCast(@max(0, result.cur_col))), + const row = @min(@as(usize, @intCast(@max(0, result.body.cur_row))), rows - 1); + result.body.cur_row = @intCast(row); + result.body.cur_col = @intCast(@min( + @as(usize, @intCast(@max(0, result.body.cur_col))), modal.lineSlice(file.content, row).len, )); - result.msel.active = false; - result.vsel.active = false; - result.nsel = 0; + result.body.msel.active = false; + result.body.vsel.active = false; + result.body.nsel = 0; state.sections_output.?.revision = file.revision; } @@ -2003,11 +2003,11 @@ fn rearmCleanSections( if (file.revision != remembered.revision) return false; file.scroll = 0; - result.cur_row = 0; - result.cur_col = 0; - result.msel.active = false; - result.vsel.active = false; - result.nsel = 0; + result.body.cur_row = 0; + result.body.cur_col = 0; + result.body.msel.active = false; + result.body.vsel.active = false; + result.body.nsel = 0; pane.search_pane = remembered.pane; pane.search_row = null; look.armLookWalk(core, remembered.pane); @@ -2110,11 +2110,11 @@ pub fn lookSection( } pub fn resetPageChrome(pane: *pardes.Pane) void { - pane.cur_row = 0; - pane.cur_col = 0; - pane.vsel.active = false; - pane.msel.active = false; - pane.nsel = 0; + pane.body.cur_row = 0; + pane.body.cur_col = 0; + pane.body.vsel.active = false; + pane.body.msel.active = false; + pane.body.nsel = 0; } pub fn activatePage( @@ -2454,12 +2454,12 @@ pub fn pointerRelease( const dragged = grid_selection.c0 != grid_selection.c1 or grid_selection.r0 != grid_selection.r1; if (!dragged) state.clearSelection(core.pdf_gpa); - pane.cur_pinned = true; - pane.mode = .normal; - pane.msel.active = false; - pane.vsel.active = false; - pane.normal.clear(); - pane.nsel = 0; + pane.body.cur_pinned = true; + pane.body.mode = .normal; + pane.body.msel.active = false; + pane.body.vsel.active = false; + pane.body.normal.clear(); + pane.body.nsel = 0; state.clearDrag(); return .{}; } diff --git a/src/tty/tty.zig b/src/tty/tty.zig index e3378f5b..903c5c0c 100644 --- a/src/tty/tty.zig +++ b/src/tty/tty.zig @@ -1418,8 +1418,8 @@ test "TTY worker setup failures finish matching LSP and pipe requests" { try std.testing.expect(core.lsp_wait == null); try std.testing.expectEqualStrings("abc", pane.file.?.content); - pane.cur_col = 2; - pane.vsel = .{ .active = true, .row = 0, .col = 0, .explicit = true }; + pane.body.cur_col = 2; + pane.body.vsel = .{ .active = true, .row = 0, .col = 0, .explicit = true }; core.update(.{ .key = .{ .cp = '|' } }); core.update(.{ .key = .{ .cp = 't', .text = "tr a-z A-Z" } }); core.update(.{ .key = .{ .cp = pardes.Key.enter } }); @@ -1607,7 +1607,7 @@ test "keypad Enter matches Return for editor input terminal writes and paste" { { const core = try pardes.Pardes.init(std.testing.allocator, .{ .tty_only = true }); defer core.deinit(); - core.panes[0].?.mode = .tty; + core.panes[0].?.body.mode = .tty; while (core.nextEffect()) |_| {} core.update(event); var written: std.Io.Writer.Allocating = .init(std.testing.allocator); diff --git a/test/fs_bench.zig b/test/fs_bench.zig index 00601ca3..a816ebbd 100644 --- a/test/fs_bench.zig +++ b/test/fs_bench.zig @@ -281,7 +281,7 @@ pub fn main(init: std.process.Init) !void { var keys = try Session.init(&counting, 32 * 1024); defer keys.deinit(); const pane = keys.core.panes[keys.file_id].?; - pane.mode = .insert; + pane.body.mode = .insert; const initial_bytes = pane.file.?.content.len; key_body_bytes = initial_bytes; if (scripted) { @@ -295,7 +295,7 @@ pub fn main(init: std.process.Init) !void { while (keys.core.nextEffect()) |_| {} } const elapsed = nowNs() - start; - if (pane.file.?.content.len != initial_bytes + key_reps or pane.cur_col != key_reps or + if (pane.file.?.content.len != initial_bytes + key_reps or pane.body.cur_col != key_reps or !std.mem.allEqual(u8, pane.file.?.content[0..key_reps], 'x')) return error.MissingKeystroke; const events = &keys.core.panes[keys.file_id].?.fs.events; if (scripted) for (0..key_reps) |i| { diff --git a/test/hxdiff.zig b/test/hxdiff.zig index e79a6bb6..627bbac3 100644 --- a/test/hxdiff.zig +++ b/test/hxdiff.zig @@ -397,9 +397,9 @@ fn runCase(arena: std.mem.Allocator, case: Case, pane_kind: []const u8) !Result core.update(.{ .key = .{ .cp = core.opts.tty_toggle, .ctrl = true } }); pump(core); if (core.panes[core.active]) |pane| { - pane.cur_row = 0; - pane.cur_col = 0; - pane.cur_pinned = true; + pane.body.cur_row = 0; + pane.body.cur_col = 0; + pane.body.cur_pinned = true; } } else fatal("case {s}: unknown pane {s}", .{ case.name, pane_kind }); @@ -488,7 +488,7 @@ fn runCase(arena: std.mem.Allocator, case: Case, pane_kind: []const u8) !Result // the cursor's empty row below the output (see Pardes.shellRows), so // its line list is exactly a file content's — join it and you have the // same bytes, trailing newline included, with nothing to patch up. - const lines = try pardes.edit.paneCursorLines(core, pane); + const lines = try pardes.edit.paneCursorLines(core, &pane.body); var text_len: usize = if (lines.len == 0) 0 else lines.len - 1; for (lines) |ln| text_len = std.math.add(usize, text_len, ln.len) catch return error.OutOfMemory; const joined = try arena.alloc(u8, text_len); @@ -503,28 +503,28 @@ fn runCase(arena: std.mem.Allocator, case: Case, pane_kind: []const u8) !Result } text = joined; } - var anchor: Pos = .{ .row = pane.cur_row, .col = pane.cur_col }; - if (pane.vsel.active) { - anchor = .{ .row = pane.vsel.row, .col = pane.vsel.col }; - } else if (pane.msel.active) { + var anchor: Pos = .{ .row = pane.body.cur_row, .col = pane.body.cur_col }; + if (pane.body.vsel.active) { + anchor = .{ .row = pane.body.vsel.row, .col = pane.body.vsel.col }; + } else if (pane.body.msel.active) { // line selection: the far end (the r0/r1 not holding the cursor), col 0 - anchor = .{ .row = if (pane.cur_row == pane.msel.r1) pane.msel.r0 else pane.msel.r1, .col = 0 }; + anchor = .{ .row = if (pane.body.cur_row == pane.body.msel.r1) pane.body.msel.r0 else pane.body.msel.r1, .col = 0 }; } // mode "select" ONLY while v-extend is on (helix keeps x/%/mi selections - // in normal mode); pane.mode itself never holds a select state - const mode = if (pane.mode == .normal and pane.select) "select" else @tagName(pane.mode); + // in normal mode); pane.body.mode itself never holds a select state + const mode = if (pane.body.mode == .normal and pane.body.select) "select" else @tagName(pane.body.mode); // multiple cursors: the primary (cur_row/cur_col + the anchor above) and - // pane.sels, slotted together in document order. pane.sels is already + // pane.body.sels, slotted together in document order. pane.body.sels is already // ordered, so the primary is the only one that needs placing. var sels: ?[]const Sel = null; var primary: ?usize = null; - if (pane.nsel > 0) { - const out = try arena.alloc(Sel, @as(usize, pane.nsel) + 1); + if (pane.body.nsel > 0) { + const out = try arena.alloc(Sel, @as(usize, pane.body.nsel) + 1); var out_len: usize = 0; - const prim: Sel = .{ .cursor = .{ .row = pane.cur_row, .col = pane.cur_col }, .anchor = anchor }; + const prim: Sel = .{ .cursor = .{ .row = pane.body.cur_row, .col = pane.body.cur_col }, .anchor = anchor }; const pr_row = @min(prim.cursor.row, prim.anchor.row); const pr_col = if (prim.cursor.row == prim.anchor.row) @min(prim.cursor.col, prim.anchor.col) else if (prim.cursor.row < prim.anchor.row) prim.cursor.col else prim.anchor.col; - for (pane.sels[0..pane.nsel]) |s| { + for (pane.body.sels[0..pane.body.nsel]) |s| { const s_row = @min(s.row, s.arow); const s_col = if (s.row == s.arow) @min(s.col, s.acol) else if (s.row < s.arow) s.col else s.acol; if (primary == null and (pr_row < s_row or (pr_row == s_row and pr_col <= s_col))) { @@ -545,7 +545,7 @@ fn runCase(arena: std.mem.Allocator, case: Case, pane_kind: []const u8) !Result .name = case.name, .text = try arena.dupe(u8, text), .mode = mode, - .cursor = .{ .row = pane.cur_row, .col = pane.cur_col }, + .cursor = .{ .row = pane.body.cur_row, .col = pane.body.cur_col }, .anchor = anchor, .sels = sels, .primary = primary, diff --git a/test/mode.zig b/test/mode.zig index cc36ac04..19d59699 100644 --- a/test/mode.zig +++ b/test/mode.zig @@ -3,9 +3,9 @@ const pardes = @import("pardes"); const panes = pardes.panes; const Pardes = pardes.Pardes; -fn mode(p: *Pardes, id: usize, expected: pardes.Pane.Mode) !void { +fn mode(p: *Pardes, id: usize, expected: panes.Text.Mode) !void { try std.testing.expect(p.executeBuiltinLine(id, "Mode")); - try std.testing.expectEqual(expected, p.panes[id].?.mode); + try std.testing.expectEqual(expected, p.panes[id].?.body.mode); try std.testing.expect(!p.panes[id].?.tag_edit); } @@ -33,14 +33,14 @@ test "Mode cycles terminal modes and keeps legacy toggle and custom tags" { p.presentation.enabled = false; while (p.nextEffect()) |_| {} const pane = p.panes[0].?; - try std.testing.expectEqual(pardes.Pane.Mode.tty, pane.mode); + try std.testing.expectEqual(panes.Text.Mode.tty, pane.body.mode); try std.testing.expect(std.mem.indexOf(u8, try p.tagText(p.scratch.allocator(), pane), " Mode") != null); try mode(p, 0, .normal); try mode(p, 0, .insert); try clickModeTag(p); - try std.testing.expectEqual(pardes.Pane.Mode.insert, pane.tag_mode); + try std.testing.expectEqual(panes.Text.Mode.insert, pane.tag_mode); p.update(.{ .key = .{ .cp = pardes.Key.tab } }); - try std.testing.expectEqual(pardes.Pane.Mode.tty, pane.mode); + try std.testing.expectEqual(panes.Text.Mode.tty, pane.body.mode); try std.testing.expect(!pane.tag_edit); while (p.nextEffect()) |effect| try std.testing.expect(effect != .write); @@ -48,11 +48,11 @@ test "Mode cycles terminal modes and keeps legacy toggle and custom tags" { try mode(p, 0, .normal); try mode(p, 0, .insert); try std.testing.expect(p.executeBuiltinLine(0, "Togglettymode")); - try std.testing.expectEqual(pardes.Pane.Mode.tty, pane.mode); + try std.testing.expectEqual(panes.Text.Mode.tty, pane.body.mode); p.update(.{ .key = .{ .cp = 'b', .ctrl = true } }); - try std.testing.expectEqual(pardes.Pane.Mode.normal, pane.mode); + try std.testing.expectEqual(panes.Text.Mode.normal, pane.body.mode); p.update(.{ .key = .{ .cp = 'b', .ctrl = true } }); - try std.testing.expectEqual(pardes.Pane.Mode.tty, pane.mode); + try std.testing.expectEqual(panes.Text.Mode.tty, pane.body.mode); try std.testing.expectEqualStrings(" Togglettymode Keep", pane.tag_tail[0..pane.tag_tail_len]); } @@ -71,19 +71,19 @@ test "Mode from actual tag Exec preserves parked file and output insert transact p.update(.{ .key = .{ .cp = 'x', .text = "x" } }); try std.testing.expectEqualStrings("界xab\n", pane.file.?.content); try clickModeTag(p); - try std.testing.expectEqual(pardes.Pane.Mode.insert, pane.tag_mode); - if (normal_tag) pane.mode = .normal; + try std.testing.expectEqual(panes.Text.Mode.insert, pane.tag_mode); + if (normal_tag) pane.body.mode = .normal; p.update(.{ .key = .{ .cp = pardes.Key.tab } }); - try std.testing.expectEqual(pardes.Pane.Mode.normal, pane.mode); + try std.testing.expectEqual(panes.Text.Mode.normal, pane.body.mode); try std.testing.expect(!pane.tag_edit); - try std.testing.expect(pane.append_at == null); + try std.testing.expect(pane.body.append_at == null); p.update(.{ .key = .{ .cp = 'u' } }); try std.testing.expectEqualStrings("ab\n", pane.file.?.content); p.update(.{ .key = .{ .cp = 'a' } }); p.update(.{ .key = .{ .cp = 'z', .text = "z" } }); - try std.testing.expect(pane.append_at != null); + try std.testing.expect(pane.body.append_at != null); try mode(p, 0, .normal); - try std.testing.expect(pane.append_at == null); + try std.testing.expect(pane.body.append_at == null); p.update(.{ .key = .{ .cp = 'u' } }); try std.testing.expectEqualStrings("ab\n", pane.file.?.content); } diff --git a/test/output.zig b/test/output.zig index 7c5f7f9b..c245e5f5 100644 --- a/test/output.zig +++ b/test/output.zig @@ -61,10 +61,10 @@ test "search tint survives wrapping and theme changes while selections remain au light_matches += 1; } try std.testing.expectEqual(@as(usize, 3), light_matches); - pane.mode = .normal; - pane.cur_row = 0; - pane.cur_col = @intCast(std.mem.indexOf(u8, text, "abc").? + 2); - pane.vsel = .{ .active = true, .row = 0, .col = pane.cur_col - 2, .explicit = true }; + pane.body.mode = .normal; + pane.body.cur_row = 0; + pane.body.cur_col = @intCast(std.mem.indexOf(u8, text, "abc").? + 2); + pane.body.vsel = .{ .active = true, .row = 0, .col = pane.body.cur_col - 2, .explicit = true }; const selected = try p.render(frame.allocator()); for (selected.cells) |cell| try std.testing.expect(!std.meta.eql(cell.style.bg, pardes.Color{ .rgb = p.theme().search_bg.? })); @@ -200,46 +200,46 @@ test "reference Look selects the next sorted row from the captured request and k const source = p.panes[0].?; const response = "m.zig:5:5-8 later\nz.zig:1:1 last-file\nm.zig:1:7-10 earlier\nm.zig:3:5-8 current\na.zig:1:1 first-file\nm.zig:4:5-8 next\n"; const sorted = "a.zig:1:1 first-file\nm.zig:1:7-10 earlier\nm.zig:3:5-8 current\nm.zig:4:5-8 next\nm.zig:5:5-8 later\nz.zig:1:1 last-file\n"; - source.cur_row = 2; - source.cur_col = 4; + source.body.cur_row = 2; + source.body.cur_col = 4; p.lspRequest(0, .references, ""); const request = p.lsp_wait.?.id; - source.cur_row = 4; + source.body.cur_row = 4; p.lspResponse(request, response); const rid = source.search_pane orelse return error.MissingResults; const results = p.panes[rid].?; try expectResultRows(sorted, &results.file.?); try std.testing.expectEqual(@as(usize, 0), p.active); - try std.testing.expectEqual(@as(i32, 3), source.cur_row); - try std.testing.expect(source.vsel.active); - try std.testing.expectEqual(@as(i32, 4), @min(source.cur_col, source.vsel.col)); - try std.testing.expectEqual(@as(i32, 7), @max(source.cur_col, source.vsel.col)); - try std.testing.expectEqual(@as(i32, 3), results.cur_row); + try std.testing.expectEqual(@as(i32, 3), source.body.cur_row); + try std.testing.expect(source.body.vsel.active); + try std.testing.expectEqual(@as(i32, 4), @min(source.body.cur_col, source.body.vsel.col)); + try std.testing.expectEqual(@as(i32, 7), @max(source.body.cur_col, source.body.vsel.col)); + try std.testing.expectEqual(@as(i32, 3), results.body.cur_row); try std.testing.expectEqual(@as(usize, 3), source.search_row.?); try std.testing.expectEqual(results.serial, p.look_walk_owner.?); try std.testing.expectEqual(@as(i32, 3), results.look_at.?.row); const available = p.freeSlot(); p.update(.{ .key = .{ .cp = 'n' } }); try std.testing.expectEqual(rid, p.active); - try std.testing.expectEqual(@as(i32, 4), results.cur_row); + try std.testing.expectEqual(@as(i32, 4), results.body.cur_row); try std.testing.expectEqual(available, p.freeSlot()); p.update(.{ .key = .{ .cp = 'N' } }); - try std.testing.expectEqual(@as(i32, 3), results.cur_row); + try std.testing.expectEqual(@as(i32, 3), results.body.cur_row); p.active = 0; - source.cur_row = 4; - source.cur_col = 4; + source.body.cur_row = 4; + source.body.cur_col = 4; p.lspRequest(0, .references, ""); p.lspResponse(p.lsp_wait.?.id, response); try std.testing.expect(std.mem.endsWith(u8, p.panes[p.active].?.file.?.path, "/z.zig")); - try std.testing.expectEqual(@as(i32, 5), results.cur_row); + try std.testing.expectEqual(@as(i32, 5), results.body.cur_row); try std.testing.expectEqual(@as(usize, 5), source.search_row.?); const last = p.active; p.lspRequest(last, .references, ""); p.lspResponse(p.lsp_wait.?.id, response); try std.testing.expect(std.mem.endsWith(u8, p.panes[p.active].?.file.?.path, "/a.zig")); const wrapped = p.panes[p.panes[last].?.search_pane.?].?; - try std.testing.expectEqual(@as(i32, 0), wrapped.cur_row); + try std.testing.expectEqual(@as(i32, 0), wrapped.body.cur_row); try std.testing.expectEqual(wrapped.serial, p.look_walk_owner.?); } @@ -280,7 +280,7 @@ test "a single language location opens the full spaced filename" { p.lspRequest(0, .references, ""); p.lspResponse(p.lsp_wait.?.id, "with space.zig:2:1 second\n"); try std.testing.expect(std.mem.endsWith(u8, p.panes[p.active].?.file.?.path, "/with space.zig")); - try std.testing.expectEqual(@as(i32, 1), p.panes[p.active].?.cur_row); + try std.testing.expectEqual(@as(i32, 1), p.panes[p.active].?.body.cur_row); for (p.panes) |slot| { const pane = slot orelse continue; if (pane.file) |file| try std.testing.expect(file.output == null); @@ -316,19 +316,19 @@ test "reordered identical results preserve the selected row and warm line index" const index = try panes.File.lineIndex(p.gpa, file); const content = file.content.ptr; const revision = file.revision; - result.cur_row = 1; - result.cur_col = 0; - result.vsel = .{ .active = true, .explicit = true, .row = 1, .col = 9 }; - result.select = true; - const selected = result.vsel; + result.body.cur_row = 1; + result.body.cur_col = 0; + result.body.vsel = .{ .active = true, .explicit = true, .row = 1, .col = 9 }; + result.body.select = true; + const selected = result.body.vsel; try panes.Output.fillResults(p, 0, "/tmp", .{ .query = .references }, "new request", try p.gpa.dupe(u8, "a.zig:10:1 second\na.zig:2:1 first\n"), 0); try expectResultRows(sorted, file); try std.testing.expectEqual(content, file.content.ptr); try std.testing.expectEqual(index.ptr, file.line_starts.ptr); try std.testing.expectEqual(revision, file.revision); - try std.testing.expectEqual(selected, result.vsel); - try std.testing.expect(result.select); - try std.testing.expectEqual(@as(i32, 1), result.cur_row); + try std.testing.expectEqual(selected, result.body.vsel); + try std.testing.expect(result.body.select); + try std.testing.expectEqual(@as(i32, 1), result.body.cur_row); try std.testing.expectEqual(@as(usize, 1), source.search_row.?); } @@ -390,7 +390,7 @@ test "result stepping reaches an unterminated last row" { try std.testing.expect(pardes.test_api.searchStep(p, 0, 1)); try std.testing.expectEqual(@as(usize, 1), source.search_row.?); const result = p.panes[source.search_pane.?].?; - try std.testing.expectEqual(@as(i32, 1), result.cur_row); + try std.testing.expectEqual(@as(i32, 1), result.body.cur_row); } test "Mini uses OS source precedence and refreshes one independent snapshot" { @@ -708,10 +708,10 @@ fn projectPaths(cwd_buf: *[4096]u8, path_buf: *[4096]u8) !ProjectPaths { fn selectedOutputText(pane: *const pardes.Pane) ?[]const u8 { const file = pane.file orelse return null; - if (!pane.vsel.active or pane.vsel.row != pane.cur_row or pane.cur_row < 0) return null; - const line = modal.lineSlice(file.content, @intCast(pane.cur_row)); - const lo: usize = @intCast(@max(0, @min(pane.vsel.col, pane.cur_col))); - const hi: usize = @intCast(@max(0, @max(pane.vsel.col, pane.cur_col))); + if (!pane.body.vsel.active or pane.body.vsel.row != pane.body.cur_row or pane.body.cur_row < 0) return null; + const line = modal.lineSlice(file.content, @intCast(pane.body.cur_row)); + const lo: usize = @intCast(@max(0, @min(pane.body.vsel.col, pane.body.cur_col))); + const hi: usize = @intCast(@max(0, @max(pane.body.vsel.col, pane.body.cur_col))); if (lo >= line.len) return ""; return line[lo..@min(line.len, hi + 1)]; } @@ -735,7 +735,7 @@ test "n/N in ordinary text skips comment slashes and retains real paths" { }) |step| { p.update(.{ .key = .{ .cp = step.key } }); try std.testing.expectEqual(@as(usize, 0), p.active); - try std.testing.expectEqual(step.row, pane.cur_row); + try std.testing.expectEqual(step.row, pane.body.cur_row); try std.testing.expectEqualStrings(step.text, selectedOutputText(pane) orelse ""); try std.testing.expectEqual(available, p.freeSlot()); } @@ -788,7 +788,7 @@ test "n/N skips formatted context and selects comment match locations" { p.update(.{ .key = .{ .cp = step.key } }); try std.testing.expectEqual(id, p.active); const row = matches[step.match]; - try std.testing.expectEqual(@as(i32, @intCast(row)), result.cur_row); + try std.testing.expectEqual(@as(i32, @intCast(row)), result.body.cur_row); const line = modal.lineSlice(file.content, row); try std.testing.expectEqualStrings(line[0..file.location_rows[row].location_end], selectedOutputText(result) orelse ""); try std.testing.expectEqual(available, p.freeSlot()); @@ -799,9 +799,9 @@ test "n/N skips formatted context and selects comment match locations" { pardes.look.armLookWalk(restored, id); const restored_result = restored.panes[id].?; restored.update(.{ .key = .{ .cp = 'n' } }); - try std.testing.expectEqual(@as(i32, @intCast(matches[0])), restored_result.cur_row); + try std.testing.expectEqual(@as(i32, @intCast(matches[0])), restored_result.body.cur_row); restored.update(.{ .key = .{ .cp = 'N' } }); - try std.testing.expectEqual(@as(i32, @intCast(matches[1])), restored_result.cur_row); + try std.testing.expectEqual(@as(i32, @intCast(matches[1])), restored_result.body.cur_row); const restored_file = &restored_result.file.?; const last = modal.lineSlice(restored_file.content, matches[1]); try std.testing.expectEqualStrings(last[0..restored_file.location_rows[matches[1]].location_end], selectedOutputText(restored_result) orelse ""); @@ -825,18 +825,18 @@ test "n/N selects one output location per row and opens nothing" { p.update(.{ .key = .{ .cp = 'n' } }); try std.testing.expectEqual(rid, p.active); try std.testing.expectEqual(panes_before, p.freeSlot()); - try std.testing.expect(results.vsel.active and results.vsel.explicit); + try std.testing.expect(results.body.vsel.active and results.body.vsel.explicit); try std.testing.expectEqualStrings("build.zig:1:1", selectedOutputText(results) orelse ""); try std.testing.expectEqual(panes.Output.Grain.line, panes.Output.grain(results.file.?.output)); p.update(.{ .key = .{ .cp = 'n' } }); - try std.testing.expectEqual(@as(i32, 1), results.cur_row); + try std.testing.expectEqual(@as(i32, 1), results.body.cur_row); try std.testing.expectEqualStrings("mise.toml", selectedOutputText(results) orelse ""); p.update(.{ .key = .{ .cp = 'n' } }); - try std.testing.expectEqual(@as(i32, 3), results.cur_row); // row 2 is not look-able + try std.testing.expectEqual(@as(i32, 3), results.body.cur_row); // row 2 is not look-able try std.testing.expectEqualStrings("uucode_config.zig:7:1", selectedOutputText(results) orelse ""); p.update(.{ .key = .{ .cp = 'n' } }); - try std.testing.expectEqual(@as(i32, 0), results.cur_row); // ring seam + try std.testing.expectEqual(@as(i32, 0), results.body.cur_row); // ring seam p.update(.{ .key = .{ .cp = Key.enter } }); try std.testing.expect(p.freeSlot() != panes_before); @@ -861,16 +861,16 @@ test "n/N resumes the result output whose Look moved focus away" { try std.testing.expect(p.executeBuiltinLine(0, "Look target")); const rid = p.panes[0].?.search_pane orelse return error.MissingResults; const results = p.panes[rid].?; - const first = results.cur_row; + const first = results.body.cur_row; try std.testing.expectEqual(@as(usize, 0), p.active); try std.testing.expect(results.look_at != null); try std.testing.expectEqual(results.serial, p.look_walk_owner orelse return error.MissingLookOwner); p.update(.{ .key = .{ .cp = 'n' } }); try std.testing.expectEqual(rid, p.active); - try std.testing.expectEqual(first + 1, results.cur_row); + try std.testing.expectEqual(first + 1, results.body.cur_row); p.update(.{ .key = .{ .cp = 'N' } }); - try std.testing.expectEqual(first, results.cur_row); + try std.testing.expectEqual(first, results.body.cur_row); // A later no-match answer has no position to resume and therefore cannot // steal the provenance established by the Look above. @@ -888,7 +888,7 @@ test "n/N resumes the result output whose Look moved focus away" { try std.testing.expectEqual(owner, p.look_walk_owner.?); p.update(.{ .key = .{ .cp = 'n' } }); try std.testing.expectEqual(rid, p.active); - try std.testing.expectEqual(first + 1, results.cur_row); + try std.testing.expectEqual(first + 1, results.body.cur_row); // Emptying the owner itself keeps its identity as the ring's starting // point. Deleting it then leaves a stale serial, never an id that can bind @@ -920,7 +920,7 @@ test "N exactly reverses n across output panes and the ring seam" { const here = struct { fn at(pp: *Pardes) Mark { const pane = pp.panes[pp.active].?; - return .{ .pane = pp.active, .row = pane.cur_row, .col = pane.cur_col }; + return .{ .pane = pp.active, .row = pane.body.cur_row, .col = pane.body.cur_col }; } }.at; p.update(.{ .key = .{ .cp = 'n' } }); @@ -957,7 +957,7 @@ test "ThemeSel groups native themes first and skips headings in both directions" const list = p.panes[tid].?; const content = list.file.?.content; try std.testing.expectEqual(@as(usize, 0), p.active); - try std.testing.expectEqual(@as(i32, 0), list.cur_row); + try std.testing.expectEqual(@as(i32, 0), list.body.cur_row); try std.testing.expectEqual(@as(usize, 0), list.file.?.scroll); try std.testing.expectEqualStrings("# Pardes themes", modal.lineSlice(content, 0)); try std.testing.expectEqualStrings("# Legacy and imported themes", modal.lineSlice(content, pardes.native_theme_count + 2)); @@ -1024,10 +1024,10 @@ test "identical result refresh keeps warm content caches without allocation" { const id = source.search_pane orelse return error.MissingResults; const result = p.panes[id].?; const file = &result.file.?; - result.cur_row = 1; - result.cur_col = 12; - result.vsel = .{ .active = true, .explicit = true, .row = 0, .col = 2 }; - result.select = true; + result.body.cur_row = 1; + result.body.cur_col = 12; + result.body.vsel = .{ .active = true, .explicit = true, .row = 0, .col = 2 }; + result.body.select = true; file.scroll = 1; result.hscroll = 3; panes.File.refreshHighlights(p); @@ -1040,7 +1040,7 @@ test "identical result refresh keeps warm content caches without allocation" { const body_ptr = file.content.ptr; const style_ptr = file.highlights.ptr; const highlight_start = file.highlight_start; - const selected = result.vsel; + const selected = result.body.vsel; const event_node = pardes.ctlfs.Node.of(result.serial, .event); const opened = pardes.ctlfs.handle(p, .{ .tag = 0, .op = .open, .node = event_node }); try std.testing.expectEqual(.ok, opened.status); @@ -1071,10 +1071,10 @@ test "identical result refresh keeps warm content caches without allocation" { try std.testing.expectEqual(freed + text.len, allocator.freed_bytes); try std.testing.expectEqual(deallocations + 1, allocator.deallocations); try std.testing.expect(!allocator.has_induced_failure); - try std.testing.expectEqual(selected, result.vsel); - try std.testing.expect(result.select); - try std.testing.expectEqual(@as(i32, 1), result.cur_row); - try std.testing.expectEqual(@as(i32, 12), result.cur_col); + try std.testing.expectEqual(selected, result.body.vsel); + try std.testing.expect(result.body.select); + try std.testing.expectEqual(@as(i32, 1), result.body.cur_row); + try std.testing.expectEqual(@as(i32, 12), result.body.cur_col); try std.testing.expectEqual(@as(usize, 1), file.scroll); try std.testing.expectEqual(@as(i32, 3), result.hscroll); try std.testing.expectEqualStrings("after", file.output.?.arg()); @@ -1093,9 +1093,9 @@ test "identical result refresh keeps warm content caches without allocation" { try std.testing.expectEqualSlices(usize, &.{ 0, 6 }, file.line_starts); try std.testing.expectEqual(@as(usize, 0), file.highlights.len); try std.testing.expect(file.syntax_dirty); - try std.testing.expect(!result.vsel.active and !result.select); - try std.testing.expectEqual(@as(i32, 0), result.cur_row); - try std.testing.expectEqual(@as(i32, 0), result.cur_col); + try std.testing.expect(!result.body.vsel.active and !result.body.select); + try std.testing.expectEqual(@as(i32, 0), result.body.cur_row); + try std.testing.expectEqual(@as(i32, 0), result.body.cur_col); try std.testing.expectEqual(@as(usize, 0), file.scroll); try std.testing.expectEqual(@as(i32, 0), result.hscroll); try std.testing.expect(source.search_row == null); @@ -1211,15 +1211,15 @@ test "result alignment chunks keep seventeen matches independent and refresh sta const content = file.content.ptr; const revision = file.revision; const index = try panes.File.lineIndex(p.gpa, file); - result.cur_row = 8; - result.cur_col = @intCast(file.location_rows[8].code_start); + result.body.cur_row = 8; + result.body.cur_col = @intCast(file.location_rows[8].code_start); try panes.Output.fillResults(p, 0, "/", origin, "chunks", try p.gpa.dupe(u8, input.items), 8); try std.testing.expectEqual(result_id, source.search_pane.?); try std.testing.expectEqual(content, file.content.ptr); try std.testing.expectEqual(revision, file.revision); try std.testing.expectEqual(index.ptr, file.line_starts.ptr); try std.testing.expectEqual(@as(usize, 8), source.search_row.?); - try std.testing.expectEqual(@as(i32, 8), result.cur_row); + try std.testing.expectEqual(@as(i32, 8), result.body.cur_row); for (file.location_rows, starts) |row, start| try std.testing.expectEqual(start, row.code_start); // Simulate a restored view made by the previous global-padding @@ -1561,11 +1561,11 @@ test "stacked search and LSP results retain source tint navigation and dump owne const number = std.mem.indexOf(u8, file.content, "42").?; try std.testing.expectEqual(@intFromEnum(pardes.syntax.Syn.number), file.highlights[number]); p.active = id; - pane.mode = .normal; + pane.body.mode = .normal; pardes.look.armLookWalk(p, id); for ([_]struct { key: u21, match: usize }{ .{ .key = 'n', .match = 0 }, .{ .key = 'n', .match = 1 }, .{ .key = 'N', .match = 0 } }) |step| { p.update(.{ .key = .{ .cp = step.key } }); - try std.testing.expectEqual(@as(i32, @intCast(matches[step.match])), pane.cur_row); + try std.testing.expectEqual(@as(i32, @intCast(matches[step.match])), pane.body.cur_row); const row = file.location_rows[matches[step.match]]; const line = modal.lineSlice(file.content, matches[step.match]); try std.testing.expectEqualStrings(line[0..row.location_end], selectedOutputText(pane) orelse ""); @@ -1587,7 +1587,7 @@ test "stacked search and LSP results retain source tint navigation and dump owne restored.active = id; pardes.look.armLookWalk(restored, id); restored.update(.{ .key = .{ .cp = 'N' } }); - try std.testing.expectEqual(@as(i32, @intCast(matches[1])), restored.panes[id].?.cur_row); + try std.testing.expectEqual(@as(i32, @intCast(matches[1])), restored.panes[id].?.body.cur_row); try std.testing.expectEqualStrings(source_text, source.file.?.content); } } diff --git a/test/panes.zig b/test/panes.zig index 60dabb8a..4c969ab5 100644 --- a/test/panes.zig +++ b/test/panes.zig @@ -327,14 +327,14 @@ const TagNavigationTests = struct { key(p, 'i'); key(p, Key.end); const before = pane.tag_tail_len; - try std.testing.expect(pane.tag_edit and pane.mode == .insert); + try std.testing.expect(pane.tag_edit and pane.body.mode == .insert); for ("hjklHJKL") |letter| { const text = [_]u8{letter}; p.update(.{ .key = .{ .cp = letter, .text = &text } }); - try std.testing.expect(pane.tag_edit and pane.mode == .insert); + try std.testing.expect(pane.tag_edit and pane.body.mode == .insert); } try std.testing.expectEqualStrings("hjklHJKL", pane.tag_tail[before..pane.tag_tail_len]); - try std.testing.expect(pane.tag_edit and pane.mode == .insert and p.topbar_col == null); + try std.testing.expect(pane.tag_edit and pane.body.mode == .insert and p.topbar_col == null); try std.testing.expectEqual(@as(usize, 0), p.active); } } @@ -370,7 +370,7 @@ const BodyHitTests = struct { const expected = pane.wrapAt(row).line; p.update(.{ .mouse = mouse(layer, row, 2, .press) }); p.update(.{ .mouse = mouse(layer, row, 2, .release) }); - try std.testing.expectEqual(expected, pane.cur_row); + try std.testing.expectEqual(expected, pane.body.cur_row); try std.testing.expectEqual(top, pane.scroll()); } const last = pane.body_visible_rows - 1; @@ -383,11 +383,11 @@ const BodyHitTests = struct { try std.testing.expectEqualStrings("body\nbody", pardes.test_api.heldSelection(p, 0).?); p.update(.{ .mouse = mouse(layer, last, 10, .press) }); p.update(.{ .mouse = mouse(layer, last, 10, .release) }); - try std.testing.expectEqual(expected, pane.cur_row); + try std.testing.expectEqual(expected, pane.body.cur_row); var stale = mouse(layer, 0, 2, .press); stale.body_hit.?.serial +%= 1; p.update(.{ .mouse = stale }); - try std.testing.expectEqual(expected, pane.cur_row); + try std.testing.expectEqual(expected, pane.body.cur_row); p.update(.{ .key = .{ .cp = 'i' } }); p.update(.{ .key = .{ .cp = 'X', .text = "X" } }); try std.testing.expect(std.mem.indexOfScalar(u8, modal.lineSlice(pane.file.?.content, @intCast(expected)), 'X') != null); @@ -425,7 +425,7 @@ const LineNumberLookTests = struct { release.button = .right; p.update(.{ .mouse = press }); p.update(.{ .mouse = release }); - try std.testing.expectEqual(expected, pane.cur_row); + try std.testing.expectEqual(expected, pane.body.cur_row); } } }; @@ -496,9 +496,9 @@ const TreeContextTests = struct { try std.testing.expectEqual(@as(i32, 0), pane.scroll()); pardes.look.lookAt(p, 0, "/tree-context.zig:60"); try std.testing.expectEqual(@as(usize, 0), p.active); - try std.testing.expectEqual(@as(i32, 59), pane.cur_row); + try std.testing.expectEqual(@as(i32, 59), pane.body.cur_row); const surface = try p.render(frame.allocator()); - const visible = pane.wrapRow(pane.cur_row, pane.cur_col); + const visible = pane.wrapRow(pane.body.cur_row, pane.body.cur_col); try std.testing.expect(visible.row >= pane.context_rows); try std.testing.expect(visible.row < pane.rows); try std.testing.expectEqual(@as(i32, 59), pane.wrapAt(visible.row).line); @@ -528,8 +528,8 @@ const TreeContextTests = struct { const x = rect.x + config.GUTTER + panes.File.gutterWidth(pane); const y = p.bodyTop(rect); ClickCursorTests.click(p, .left, x + 6, y); - try std.testing.expectEqual(@as(i32, 0), pane.cur_row); - try std.testing.expectEqual(@as(i32, 6), pane.cur_col); + try std.testing.expectEqual(@as(i32, 0), pane.body.cur_row); + try std.testing.expectEqual(@as(i32, 6), pane.body.cur_col); try std.testing.expectEqual(@as(i32, 7), pane.scroll()); const cursor = (try p.render(frame.allocator())).cursor orelse return error.MissingContextCursor; try std.testing.expectEqual(x + 6, cursor.x); @@ -552,7 +552,7 @@ const TreeContextTests = struct { try std.testing.expectEqual(pane.scroll(), pane.wrapAt(pane.context_rows).line); } try std.testing.expectEqual(@as(u16, 0), pane.context_rows); - try std.testing.expectEqual(@as(i32, 0), pane.wrapRow(0, pane.cur_col).row); + try std.testing.expectEqual(@as(i32, 0), pane.wrapRow(0, pane.body.cur_col).row); try std.testing.expect(p.executeBuiltinLine(0, "TreeContext")); pane.scrollBy(7); _ = try p.render(frame.allocator()); @@ -581,8 +581,8 @@ const TreeContextTests = struct { } const x = glyph_x orelse return error.MissingContextUnicode; ClickCursorTests.click(p, .left, x + 1, y); - try std.testing.expectEqual(@as(i32, 0), pane.cur_row); - try std.testing.expectEqual(@as(i32, 9), pane.cur_col); + try std.testing.expectEqual(@as(i32, 0), pane.body.cur_row); + try std.testing.expectEqual(@as(i32, 9), pane.body.cur_col); try std.testing.expectEqual(@as(i32, 8), pane.scroll()); const cursor = (try p.render(frame.allocator())).cursor orelse return error.MissingContextCursor; try std.testing.expectEqual(x, cursor.x); @@ -617,8 +617,8 @@ const TreeContextTests = struct { }; const glyph = target orelse return error.MissingWrappedContextBody; ClickCursorTests.click(p, .left, glyph.x + 1, glyph.y); - try std.testing.expectEqual(@as(i32, 2), pane.cur_row); - try std.testing.expectEqual(@as(i32, @intCast(std.mem.indexOf(u8, body, "界").?)), pane.cur_col); + try std.testing.expectEqual(@as(i32, 2), pane.body.cur_row); + try std.testing.expectEqual(@as(i32, @intCast(std.mem.indexOf(u8, body, "界").?)), pane.body.cur_col); const cursor = (try p.render(frame.allocator())).cursor orelse return error.MissingContextBodyCursor; try std.testing.expectEqual(glyph.x, cursor.x); try std.testing.expectEqual(glyph.y, cursor.y); @@ -652,7 +652,7 @@ const TtySelectionTests = struct { try std.testing.expectEqualStrings("lph", p.yank orelse return error.MissingAutomaticTtyYank); p.update(.{ .key = .{ .cp = p.opts.tty_toggle, .ctrl = true } }); p.update(.{ .key = .{ .cp = 'l' } }); - try std.testing.expectEqual(@as(i32, 4), pane.cur_col); + try std.testing.expectEqual(@as(i32, 4), pane.body.cur_col); p.update(.{ .key = .{ .cp = 'y' } }); try std.testing.expectEqualStrings("a", p.yank.?); try noChildInput(p); @@ -664,7 +664,7 @@ const TtySelectionTests = struct { const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 40, .rows = 12 }); defer p.deinit(); const pane = p.panes[0].?; - pane.mode = .tty; + pane.body.mode = .tty; pane.tty_filter = false; p.presentation.enabled = false; while (p.nextEffect()) |_| {} @@ -680,7 +680,7 @@ const TtySelectionTests = struct { const y = p.bodyTop(rect); JumpSelectionTests.drag(p, x + @as(u16, if (prompt) 0 else 1), y, x + 3, y + @as(u16, if (prompt) 0 else 1)); const expected = if (prompt) "$ ab" else "lph\nrav"; - try std.testing.expectEqual(Pane.Mode.tty, pane.mode); + try std.testing.expectEqual(panes.Text.Mode.tty, pane.body.mode); try std.testing.expectEqualStrings(expected, pardes.test_api.heldSelection(p, 0).?); try std.testing.expectEqualStrings(expected, p.yank orelse return error.MissingAutomaticTtyYank); try noChildInput(p); @@ -689,7 +689,7 @@ const TtySelectionTests = struct { try noChildInput(p); try std.testing.expectEqualStrings(expected, p.fallback.clipboard.items); p.update(.{ .key = .{ .cp = p.opts.tty_toggle, .ctrl = true } }); - try std.testing.expectEqual(Pane.Mode.normal, pane.mode); + try std.testing.expectEqual(panes.Text.Mode.normal, pane.body.mode); const normal = try p.render(frame.allocator()); if (!prompt) { const selection_bg: pardes.Color = .{ .rgb = p.theme().sel_bg }; @@ -701,13 +701,13 @@ const TtySelectionTests = struct { try std.testing.expectEqualStrings(expected, p.yank.?); try noChildInput(p); p.update(.{ .key = .{ .cp = p.opts.tty_toggle, .ctrl = true } }); - try std.testing.expectEqual(Pane.Mode.tty, pane.mode); + try std.testing.expectEqual(panes.Text.Mode.tty, pane.body.mode); try noChildInput(p); _ = try p.render(frame.allocator()); try std.testing.expectEqualStrings(expected, pardes.test_api.heldSelection(p, 0).?); p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b]133;C\x07" ++ "\r\nnew output" ** 30 } }); _ = try p.render(frame.allocator()); - try std.testing.expectEqual(Pane.Mode.tty, pane.mode); + try std.testing.expectEqual(panes.Text.Mode.tty, pane.body.mode); try std.testing.expectEqualStrings(expected, pardes.test_api.heldSelection(p, 0).?); try std.testing.expectEqualStrings(expected, p.yank.?); try noChildInput(p); @@ -723,7 +723,7 @@ const TtySelectionTests = struct { p.presentation.enabled = false; pardes.exec.spawnTty(p, 0); for (p.panes[0..2]) |slot| { - slot.?.mode = .tty; + slot.?.body.mode = .tty; slot.?.tty_filter = false; slot.?.greet = false; slot.?.vweight = 1; @@ -765,8 +765,8 @@ const TtySelectionTests = struct { }); defer p.gpa.free(expected); try std.testing.expectEqualStrings(expected, written.written()); - try std.testing.expectEqual(Pane.Mode.tty, p.panes[0].?.mode); - try std.testing.expectEqual(Pane.Mode.tty, p.panes[1].?.mode); + try std.testing.expectEqual(panes.Text.Mode.tty, p.panes[0].?.body.mode); + try std.testing.expectEqual(panes.Text.Mode.tty, p.panes[1].?.body.mode); try std.testing.expectEqualStrings("lph\nrav", pardes.test_api.heldSelection(p, 0).?); } } @@ -799,7 +799,7 @@ const TtySelectionTests = struct { const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 40, .rows = 12 }); defer p.deinit(); const pane = p.panes[0].?; - try std.testing.expectEqual(Pane.Mode.tty, pane.mode); + try std.testing.expectEqual(panes.Text.Mode.tty, pane.body.mode); if (bracketed) p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[?2004h" } }); try std.testing.expectEqual(bracketed, panes.Terminal.bracketedPaste(pane)); p.yank = try p.gpa.dupe(u8, "one\ntwo"); // what a `y` anywhere left behind @@ -867,13 +867,13 @@ const ClickCursorTests = struct { const x = rect.x + config.GUTTER + panes.File.gutterWidth(pane); const y = if (bottom_tag) rect.y else rect.y + pardes.BOX_H; click(p, .left, x + 15, y + case.click_row); - try std.testing.expectEqual(case.row, pane.cur_row); - try std.testing.expectEqual(case.col, pane.cur_col); + try std.testing.expectEqual(case.row, pane.body.cur_row); + try std.testing.expectEqual(case.col, pane.body.cur_col); const clicked = (try p.render(frame.allocator())).cursor orelse return error.MissingClickCursor; try std.testing.expectEqual(x + @as(u16, @intCast(case.col)), clicked.x); try std.testing.expectEqual(y + @as(u16, @intCast(case.row)), clicked.y); if (!already_insert) p.update(.{ .key = .{ .cp = 'i' } }); - try std.testing.expectEqual(Pane.Mode.insert, pane.mode); + try std.testing.expectEqual(panes.Text.Mode.insert, pane.body.mode); const insert = (try p.render(frame.allocator())).cursor orelse return error.MissingInsertCursor; try std.testing.expectEqual(clicked.x, insert.x); try std.testing.expectEqual(clicked.y, insert.y); @@ -906,12 +906,12 @@ const ClickCursorTests = struct { if (wrap) try std.testing.expect(glyph.y > p.rects[0].y + pardes.BOX_H); click(p, .left, glyph.x + 1, glyph.y); const byte = std.mem.indexOf(u8, source, "界").?; - try std.testing.expectEqual(@as(i32, @intCast(byte)), pane.cur_col); + try std.testing.expectEqual(@as(i32, @intCast(byte)), pane.body.cur_col); const clicked = (try p.render(frame.allocator())).cursor orelse return error.MissingClickCursor; try std.testing.expectEqual(glyph.x, clicked.x); try std.testing.expectEqual(glyph.y, clicked.y); if (!already_insert) p.update(.{ .key = .{ .cp = 'i' } }); - try std.testing.expectEqual(Pane.Mode.insert, pane.mode); + try std.testing.expectEqual(panes.Text.Mode.insert, pane.body.mode); const insert = (try p.render(frame.allocator())).cursor orelse return error.MissingInsertCursor; try std.testing.expectEqual(clicked.x, insert.x); try std.testing.expectEqual(clicked.y, insert.y); @@ -1016,10 +1016,10 @@ const JumpSelectionTests = struct { try std.testing.expectEqual(@as(usize, 0), p.jcur); try std.testing.expect(pane.file.?.scroll > 20); try LookResetTests.cleared(pane); - try std.testing.expect(!pane.vsel.active); + try std.testing.expect(!pane.body.vsel.active); try std.testing.expect(pardes.test_api.heldSelection(p, 0) == null); - try std.testing.expectEqual(@as(i32, 59), pane.cur_row); - try std.testing.expectEqual(@as(i32, 0), pane.cur_col); + try std.testing.expectEqual(@as(i32, 59), pane.body.cur_row); + try std.testing.expectEqual(@as(i32, 0), pane.body.cur_col); // A selection created after Back must also disappear on Forward. // Back announces itself, so the body sits under a notice band now. @@ -1032,10 +1032,10 @@ const JumpSelectionTests = struct { try std.testing.expectEqual(@as(usize, 1), p.jcur); try std.testing.expectEqual(@as(usize, 0), pane.file.?.scroll); try LookResetTests.cleared(pane); - try std.testing.expect(!pane.vsel.active); + try std.testing.expect(!pane.body.vsel.active); try std.testing.expect(pardes.test_api.heldSelection(p, 0) == null); - try std.testing.expectEqual(@as(i32, 0), pane.cur_row); - try std.testing.expectEqual(@as(i32, 0), pane.cur_col); + try std.testing.expectEqual(@as(i32, 0), pane.body.cur_row); + try std.testing.expectEqual(@as(i32, 0), pane.body.cur_col); } test "jump selection clears copied rectangles in both history directions" { @@ -1073,9 +1073,9 @@ const JumpSelectionTests = struct { try std.testing.expectEqual(@as(usize, 0), p.jcur); try LookResetTests.cleared(source); try LookResetTests.cleared(destination); - try std.testing.expect(!source.vsel.active and !destination.vsel.active); - try std.testing.expectEqual(@as(i32, 2), destination.cur_row); - try std.testing.expectEqual(@as(i32, 1), destination.cur_col); + try std.testing.expect(!source.body.vsel.active and !destination.body.vsel.active); + try std.testing.expectEqual(@as(i32, 2), destination.body.cur_row); + try std.testing.expectEqual(@as(i32, 1), destination.body.cur_col); try LookResetTests.seed(source, "new source held text"); try LookResetTests.seed(destination, "new destination held text"); @@ -1084,9 +1084,9 @@ const JumpSelectionTests = struct { try std.testing.expectEqual(@as(usize, 1), p.jcur); try LookResetTests.cleared(source); try LookResetTests.cleared(destination); - try std.testing.expect(!source.vsel.active and !destination.vsel.active); - try std.testing.expectEqual(@as(i32, 1), source.cur_row); - try std.testing.expectEqual(@as(i32, 0), source.cur_col); + try std.testing.expect(!source.body.vsel.active and !destination.body.vsel.active); + try std.testing.expectEqual(@as(i32, 1), source.body.cur_row); + try std.testing.expectEqual(@as(i32, 0), source.body.cur_col); } }; @@ -1395,7 +1395,7 @@ test "terminal overlay recoloring never materializes unrelated history" { const pane = p.panes[0].?; pane.tty_filter = false; for (0..1000) |_| p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[32mcaf\xc3\xa9 \xe7\x95\x8c\x1b[0m\r\n" } }); - pane.mode = .normal; + pane.body.mode = .normal; pane.ovl = .{ .row = 0, .rows = 1, .text = try p.gpa.dupe(u8, "edited history") }; var frame = std.heap.ArenaAllocator.init(testing.allocator); defer frame.deinit(); @@ -1422,7 +1422,7 @@ test "terminal output keeps following new rows after scrollback eviction" { defer p.deinit(); while (p.nextEffect()) |_| {} const pane = p.panes[0].?; - pane.mode = .tty; + pane.body.mode = .tty; pane.tty_filter = false; const pages = &pane.terminal.?.vt.screens.active.pages; pages.explicit_max_size = 64 * 1024; @@ -1431,7 +1431,7 @@ test "terminal output keeps following new rows after scrollback eviction" { var evictions: usize = 0; for (0..3) |phase| { if (phase > 0) { - pane.mode = .normal; + pane.body.mode = .normal; panes.Terminal.scrollGrid(pane, -30); try std.testing.expect(pages.scrollbar().offset < pages.scrollbar().total - pane.rows); panes.Terminal.enterTty(p, 0); @@ -1483,7 +1483,7 @@ test "terminal edit stays on its surviving row when old scrollback is evicted" { defer p.deinit(); while (p.nextEffect()) |_| {} const pane = p.panes[0].?; - pane.mode = .tty; + pane.body.mode = .tty; const pages = &pane.terminal.?.vt.screens.active.pages; pages.explicit_max_size = 64 * 1024; var next: usize = 0; @@ -1497,12 +1497,12 @@ test "terminal edit stays on its surviving row when old scrollback is evicted" { try std.testing.expect(next < 3000); var last_buf: [16]u8 = undefined; const last = try std.fmt.bufPrint(&last_buf, "row-{d:0>5}", .{next - 1}); - pane.mode = .normal; + pane.body.mode = .normal; const original_row: i32 = @intCast(pages.scrollbar().total - 2); pane.ovl = .{ .row = original_row, .rows = 1, .text = try gpa.dupe(u8, "my unsent edit") }; - pane.cur_row = original_row; - pane.cur_col = 3; - pane.cur_pinned = true; + pane.body.cur_row = original_row; + pane.body.cur_col = 3; + pane.body.cur_pinned = true; var removed: usize = 0; for (next..next + 3000) |n| { var buf: [32]u8 = undefined; @@ -1520,7 +1520,7 @@ test "terminal edit stays on its surviving row when old scrollback is evicted" { const row = original_row - @as(i32, @intCast(removed)); try std.testing.expectEqualStrings(last, modal.lineSlice(full, @intCast(row))); try std.testing.expectEqual(row, pane.ovl.?.row); - try std.testing.expectEqual(row, pane.cur_row); + try std.testing.expectEqual(row, pane.body.cur_row); try std.testing.expectEqualStrings("my unsent edit", pane.ovl.?.text); } @@ -1533,7 +1533,7 @@ test "terminal edits and undo survive partial history clearing and whole-screen defer p.deinit(); while (p.nextEffect()) |_| {} const pane = p.panes[0].?; - pane.mode = .tty; + pane.body.mode = .tty; if (action == .reset_alternate) p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[?1049h" } }); p.update(.{ .output = .{ .pane = 0, .bytes = "old row\r\n" ** 40 } }); @@ -1541,15 +1541,15 @@ test "terminal edits and undo survive partial history clearing and whole-screen pages.explicit_max_size = 64 * 1024; const row: i32 = @as(i32, @intCast(pages.total_rows - pane.rows)) + @as(i32, if (action == .partial_clear_history) -1 else 2); - pane.mode = .normal; + pane.body.mode = .normal; pane.ovl = .{ .row = row, .rows = if (action == .partial_clear_history) 3 else 2, .text = try gpa.dupe(u8, "edit one\nedit two") }; - pane.cur_row = row + 1; - pane.cur_col = 4; - pane.cur_pinned = true; - pane.vsel = .{ .active = true, .row = row, .col = 1 }; + pane.body.cur_row = row + 1; + pane.body.cur_col = 4; + pane.body.cur_pinned = true; + pane.body.vsel = .{ .active = true, .row = row, .col = 1 }; panes.Terminal.pushUndo(p, pane); - pane.ed_redo[0] = panes.Terminal.snap(p, pane) orelse return error.SnapshotFailed; - pane.ed_redo_len = 1; + pane.body.ed_redo[0] = panes.Terminal.snap(p, pane) orelse return error.SnapshotFailed; + pane.body.ed_redo_len = 1; if (action == .hidden_undo) { gpa.free(pane.ovl.?.text); pane.ovl = null; @@ -1566,10 +1566,10 @@ test "terminal edits and undo survive partial history clearing and whole-screen try std.testing.expectEqual(expected, edit.row); try std.testing.expectEqual(@as(i32, if (action == .clear_history or action == .partial_clear_history) 2 else 1), edit.rows); try std.testing.expectEqualStrings("edit one\nedit two", edit.text); - try std.testing.expectEqual(expected + 1, pane.cur_row); - try std.testing.expectEqual(expected, pane.vsel.row); + try std.testing.expectEqual(expected + 1, pane.body.cur_row); + try std.testing.expectEqual(expected, pane.body.vsel.row); } - for ([_]panes.Terminal.Snapshot{ pane.ed_undo[0], pane.ed_redo[0] }) |snapshot| { + for ([_]panes.Terminal.Snapshot{ pane.body.ed_undo[0], pane.body.ed_redo[0] }) |snapshot| { try std.testing.expectEqual(expected, snapshot.ovl.?.row); try std.testing.expectEqual(expected + 1, snapshot.cur_row); try std.testing.expectEqualStrings("edit one\nedit two", snapshot.ovl.?.text); @@ -1588,11 +1588,11 @@ test "terminal lower scroll regions do not move edits above them" { defer p.deinit(); while (p.nextEffect()) |_| {} const pane = p.panes[0].?; - pane.mode = .normal; + pane.body.mode = .normal; p.update(.{ .output = .{ .pane = 0, .bytes = "top\r\nsecond\r\nthird" } }); pane.ovl = .{ .row = 1, .rows = 1, .text = try gpa.dupe(u8, "unsent") }; - pane.cur_row = 1; - pane.cur_pinned = true; + pane.body.cur_row = 1; + pane.body.cur_pinned = true; panes.Terminal.pushUndo(p, pane); const total = panes.Terminal.scrollbar(pane).total; var setup: [64]u8 = undefined; @@ -1601,8 +1601,8 @@ test "terminal lower scroll regions do not move edits above them" { p.update(.{ .output = .{ .pane = 0, .bytes = "tail\r\n" ** 50 } }); try std.testing.expectEqual(total, panes.Terminal.scrollbar(pane).total); try std.testing.expectEqual(@as(i32, 1), pane.ovl.?.row); - try std.testing.expectEqual(@as(i32, 1), pane.cur_row); - try std.testing.expectEqual(@as(i32, 1), pane.ed_undo[0].ovl.?.row); + try std.testing.expectEqual(@as(i32, 1), pane.body.cur_row); + try std.testing.expectEqual(@as(i32, 1), pane.body.ed_undo[0].ovl.?.row); const full = try panes.Terminal.screenTextAlloc(pane, gpa); defer gpa.free(full); try std.testing.expect(std.mem.startsWith(u8, full, "top\nsecond\nthird\n")); @@ -1615,7 +1615,7 @@ test "terminal eviction and lower-region scrolling in one read preserve a surviv defer p.deinit(); while (p.nextEffect()) |_| {} const pane = p.panes[0].?; - pane.mode = .tty; + pane.body.mode = .tty; const pages = &pane.terminal.?.vt.screens.active.pages; pages.explicit_max_size = 64 * 1024; var next: usize = 0; @@ -1630,10 +1630,10 @@ test "terminal eviction and lower-region scrolling in one read preserve a surviv try std.testing.expect(next < 3000); const removed = pages.pages.first.?.rows(); const old_row: i32 = @intCast(removed + 2); - pane.mode = .normal; + pane.body.mode = .normal; pane.ovl = .{ .row = old_row, .rows = 1, .text = try gpa.dupe(u8, "kept edit") }; - pane.cur_row = old_row; - pane.cur_pinned = true; + pane.body.cur_row = old_row; + pane.body.cur_pinned = true; panes.Terminal.pushUndo(p, pane); const old_total = pages.total_rows; var buf: [128]u8 = undefined; @@ -1641,8 +1641,8 @@ test "terminal eviction and lower-region scrolling in one read preserve a surviv p.update(.{ .output = .{ .pane = 0, .bytes = bytes } }); try std.testing.expectEqual(old_total + 1 - removed, pages.total_rows); try std.testing.expectEqual(@as(i32, 2), pane.ovl.?.row); - try std.testing.expectEqual(@as(i32, 2), pane.cur_row); - try std.testing.expectEqual(@as(i32, 2), pane.ed_undo[0].ovl.?.row); + try std.testing.expectEqual(@as(i32, 2), pane.body.cur_row); + try std.testing.expectEqual(@as(i32, 2), pane.body.ed_undo[0].ovl.?.row); try std.testing.expectEqualStrings("kept edit", pane.ovl.?.text); } @@ -1667,9 +1667,9 @@ test "tag prompt entry and cancellation preserve exact text and cursor state" { pane.tag_init = true; pane.tag_sel = true; pane.tag_col = 1; - pane.cur_row = 1; - pane.cur_col = 2; - pane.cur_pinned = true; + pane.body.cur_row = 1; + pane.body.cur_col = 2; + pane.body.cur_pinned = true; if (case.key) |key| { p.update(.{ .key = key }); } else if (case.save) { @@ -1679,18 +1679,18 @@ test "tag prompt entry and cancellation preserve exact text and cursor state" { } try std.testing.expect(pane.tag_edit); try std.testing.expect(!pane.tag_sel); - try std.testing.expectEqual(.insert, pane.mode); - try std.testing.expectEqualDeep(modal.Normal.State{}, pane.normal); + try std.testing.expectEqual(.insert, pane.body.mode); + try std.testing.expectEqualDeep(modal.Normal.State{}, pane.body.normal); try std.testing.expectEqualStrings(tail, pane.tag_tail[0..tail.len]); try std.testing.expectEqualStrings(case.marker, pane.tag_tail[tail.len..pane.tag_tail_len]); try std.testing.expectEqual(pane.file.?.path.len + pane.tag_tail_len, pane.tag_col); p.update(.{ .key = .{ .cp = Key.escape } }); try std.testing.expect(pane.prompt == .none); try std.testing.expect(!pane.tag_edit); - try std.testing.expectEqual(.normal, pane.mode); + try std.testing.expectEqual(.normal, pane.body.mode); try std.testing.expectEqualStrings(tail, pane.tag_tail[0..pane.tag_tail_len]); - try std.testing.expectEqual(@as(i32, 1), pane.cur_row); - try std.testing.expectEqual(@as(i32, 2), pane.cur_col); + try std.testing.expectEqual(@as(i32, 1), pane.body.cur_row); + try std.testing.expectEqual(@as(i32, 2), pane.body.cur_col); try std.testing.expectEqualStrings("one\ntwo\n", pane.file.?.content); } } @@ -1713,7 +1713,7 @@ test "tag prompt capacity refusal leaves the existing tail and input state untou try std.testing.expect(pane.prompt == .none); try std.testing.expect(!pane.tag_edit); try std.testing.expect(pane.tag_sel); - try std.testing.expectEqual(.normal, pane.mode); + try std.testing.expectEqual(.normal, pane.body.mode); try std.testing.expectEqual(@as(u16, 17), pane.tag_col); try std.testing.expectEqual(pane.tag_tail.len - 1, pane.tag_tail_len); for (pane.tag_tail) |byte| try std.testing.expectEqual(@as(u8, 'x'), byte); @@ -1739,9 +1739,9 @@ test "tag prompt owns the pipe behavior through cancellation and submission" { const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true }); defer p.deinit(); const pane = try p.setTestFile("one\ntwo\n"); - pane.cur_row = 0; - pane.cur_col = 2; - pane.vsel = .{ .active = true, .row = 0, .col = 0, .explicit = true }; + pane.body.cur_row = 0; + pane.body.cur_col = 2; + pane.body.vsel = .{ .active = true, .row = 0, .col = 0, .explicit = true }; for (std.enums.values(modal.Normal.PipeBehavior)) |how| { p.startPrompt(pane, .{ .pipe = .append }); p.update(.{ .key = .{ .cp = Key.escape } }); @@ -1767,21 +1767,21 @@ test "tag prompt cancellation restores the selection before regex previews" { .{ .key = 'S', .pattern = " ", .secondary = 2 }, }; for (cases) |case| { - pane.cur_row = 0; - pane.cur_col = 10; - pane.cur_pinned = true; - pane.vsel = .{ .active = true, .row = 0, .col = 0, .explicit = true }; - pane.nsel = 0; + pane.body.cur_row = 0; + pane.body.cur_col = 10; + pane.body.cur_pinned = true; + pane.body.vsel = .{ .active = true, .row = 0, .col = 0, .explicit = true }; + pane.body.nsel = 0; p.update(.{ .key = .{ .cp = case.key } }); try std.testing.expect(pane.prompt == .search); p.update(.{ .key = .{ .cp = case.pattern[0], .text = case.pattern } }); - try std.testing.expectEqual(case.secondary, pane.nsel); + try std.testing.expectEqual(case.secondary, pane.body.nsel); p.update(.{ .key = .{ .cp = Key.escape } }); - try std.testing.expectEqual(@as(u8, 0), pane.nsel); + try std.testing.expectEqual(@as(u8, 0), pane.body.nsel); try std.testing.expectEqual(@as(u8, 0), pane.nsel_snap); - try std.testing.expectEqual(@as(i32, 10), pane.cur_col); - try std.testing.expectEqual(@as(i32, 0), pane.vsel.col); - try std.testing.expect(pane.vsel.active and pane.vsel.explicit); + try std.testing.expectEqual(@as(i32, 10), pane.body.cur_col); + try std.testing.expectEqual(@as(i32, 0), pane.body.vsel.col); + try std.testing.expect(pane.body.vsel.active and pane.body.vsel.explicit); try std.testing.expectEqualStrings("one two one", pane.file.?.content); } } @@ -1802,18 +1802,18 @@ test "tag prompt prefix allocation failure preserves an already seeded prompt" { pane.tag_sel = true; pane.tag_col = 14; pane.tag_anchor = 7; - pane.normal = .{ .count = 9, .prefix = .goto }; + pane.body.normal = .{ .count = 9, .prefix = .goto }; const previous_prompt = pane.prompt; - const previous_normal = pane.normal; + const previous_normal = pane.body.normal; _ = p.scratch.reset(.free_all); failing.fail_index = failing.alloc_index; p.startPrompt(pane, request); try std.testing.expect(failing.has_induced_failure); try std.testing.expectEqualDeep(previous_prompt, pane.prompt); - try std.testing.expectEqualDeep(previous_normal, pane.normal); + try std.testing.expectEqualDeep(previous_normal, pane.body.normal); try std.testing.expectEqualStrings(tail, pane.tag_tail[0..pane.tag_tail_len]); try std.testing.expect(pane.tag_edit and pane.tag_sel); - try std.testing.expectEqual(.normal, pane.mode); + try std.testing.expectEqual(.normal, pane.body.mode); try std.testing.expectEqual(@as(u16, 14), pane.tag_col); try std.testing.expectEqual(@as(u16, 7), pane.tag_anchor); } @@ -1867,7 +1867,7 @@ test "tag prompt successful seeded entry needs one scratch allocation" { const before = failing.alloc_index; p.startPrompt(pane, request); try std.testing.expectEqual(before + 1, failing.alloc_index); - try std.testing.expect(pane.tag_edit and pane.mode == .insert); + try std.testing.expect(pane.tag_edit and pane.body.mode == .insert); } } @@ -1892,20 +1892,20 @@ test "tag prompt failure may initialize only the default tail" { pane.tag_tail_len = 0; pane.tag_col = 17; pane.tag_sel = true; - pane.normal = .{ .count = 9, .prefix = .goto }; - const previous_normal = pane.normal; + pane.body.normal = .{ .count = 9, .prefix = .goto }; + const previous_normal = pane.body.normal; _ = p.scratch.reset(.free_all); failing.fail_index = failing.alloc_index + failure; p.startPrompt(pane, request); if (!failing.has_induced_failure) { - try std.testing.expect(pane.tag_edit and pane.mode == .insert); + try std.testing.expect(pane.tag_edit and pane.body.mode == .insert); succeeded = true; break; } try std.testing.expect(pane.prompt == .none); try std.testing.expect(!pane.tag_edit and pane.tag_sel); - try std.testing.expectEqual(.normal, pane.mode); - try std.testing.expectEqualDeep(previous_normal, pane.normal); + try std.testing.expectEqual(.normal, pane.body.mode); + try std.testing.expectEqualDeep(previous_normal, pane.body.normal); try std.testing.expectEqual(@as(u16, 17), pane.tag_col); if (pane.tag_init) { saw_seeded_failure = true; @@ -2390,10 +2390,10 @@ const OutputTests = struct { try std.testing.expectEqual(matches[1], pane.search_row.?); try std.testing.expect(pardes.test_api.searchStep(p, 0, -1)); try std.testing.expectEqual(matches[0], pane.search_row.?); - try std.testing.expectEqual(@as(i32, 3), pane.cur_row); + try std.testing.expectEqual(@as(i32, 3), pane.body.cur_row); try std.testing.expect(pardes.test_api.searchStep(p, 0, 1)); try std.testing.expectEqual(matches[1], pane.search_row.?); - try std.testing.expectEqual(@as(i32, 5), pane.cur_row); + try std.testing.expectEqual(@as(i32, 5), pane.body.cur_row); try std.testing.expect(pardes.test_api.searchStep(p, 0, 1)); try std.testing.expectEqual(matches[1], pane.search_row.?); @@ -2571,9 +2571,9 @@ const OutputTests = struct { const id = p.active; const help = p.panes[id].?; for ("gevkk") |key| p.update(.{ .key = .{ .cp = key } }); - try std.testing.expect(help.vsel.active); - try std.testing.expect(help.vsel.row > 5); - try std.testing.expect(help.cur_row != help.vsel.row); + try std.testing.expect(help.body.vsel.active); + try std.testing.expect(help.body.vsel.row > 5); + try std.testing.expect(help.body.cur_row != help.body.vsel.row); for (" h?") |key| p.update(.{ .key = .{ .cp = key } }); try std.testing.expectEqual(id, p.active); const content = help.file.?.content; @@ -2607,35 +2607,35 @@ const OutputTests = struct { const result = p.panes[id].?; p.active = id; for ("Cv3") |key| p.update(.{ .key = .{ .cp = key } }); - try std.testing.expect(result.nsel > 0); - try std.testing.expect(result.select); - try std.testing.expect(result.vsel.active); - try std.testing.expect(result.normal.count > 0); + try std.testing.expect(result.body.nsel > 0); + try std.testing.expect(result.body.select); + try std.testing.expect(result.body.vsel.active); + try std.testing.expect(result.body.normal.count > 0); result.file.?.scroll = 1; result.hscroll = 2; - const selected = result.vsel; - const selections = result.nsel; - const cursor_row = result.cur_row; - const cursor_col = result.cur_col; + const selected = result.body.vsel; + const selections = result.body.nsel; + const cursor_row = result.body.cur_row; + const cursor_col = result.body.cur_col; try fillResults(p, 0, "/", .{ .query = .hover }, "", try p.gpa.dupe(u8, content), null); - try std.testing.expectEqual(selected, result.vsel); - try std.testing.expectEqual(selections, result.nsel); - try std.testing.expectEqual(cursor_row, result.cur_row); - try std.testing.expectEqual(cursor_col, result.cur_col); + try std.testing.expectEqual(selected, result.body.vsel); + try std.testing.expectEqual(selections, result.body.nsel); + try std.testing.expectEqual(cursor_row, result.body.cur_row); + try std.testing.expectEqual(cursor_col, result.body.cur_col); try std.testing.expectEqual(@as(usize, 1), result.file.?.scroll); try std.testing.expectEqual(@as(i32, 2), result.hscroll); - try std.testing.expect(result.normal.count > 0); + try std.testing.expect(result.body.normal.count > 0); try fillResults(p, 0, "/", .{ .query = .hover }, "", try p.gpa.dupe(u8, "short\n"), null); try std.testing.expectEqualStrings("short\n", result.file.?.content); - try std.testing.expect(!result.vsel.active and !result.msel.active and !result.select); - try std.testing.expectEqual(@as(u8, 0), result.nsel); - try std.testing.expectEqual(@as(i32, 0), result.cur_row); - try std.testing.expectEqual(@as(i32, 0), result.cur_col); + try std.testing.expect(!result.body.vsel.active and !result.body.msel.active and !result.body.select); + try std.testing.expectEqual(@as(u8, 0), result.body.nsel); + try std.testing.expectEqual(@as(i32, 0), result.body.cur_row); + try std.testing.expectEqual(@as(i32, 0), result.body.cur_col); try std.testing.expectEqual(@as(usize, 0), result.file.?.scroll); try std.testing.expectEqual(@as(i32, 0), result.hscroll); - try std.testing.expectEqual(modal.Normal.State{}, result.normal); + try std.testing.expectEqual(modal.Normal.State{}, result.body.normal); } test "generated result replacement cancels an in-progress body selection" { @@ -2665,7 +2665,7 @@ const OutputTests = struct { try std.testing.expect(p.drag == .none); p.update(.{ .mouse = .{ .button = config.select_button, .kind = .release, .col = x + 2, .row = y + 1 } }); for (result.sel) |selection| try std.testing.expectEqual(.none, selection.state); - try std.testing.expect(!result.vsel.active and !result.msel.active); + try std.testing.expect(!result.body.vsel.active and !result.body.msel.active); } test "dump origins accept only builtins that actually own output panes" { @@ -2993,8 +2993,8 @@ const TerminalTests = struct { gpa.free(sn.style); }; - for ([_]pardes.Pane.Mode{ .tty, .normal }, 0..) |mode, i| { - pane.mode = mode; + for ([_]panes.Text.Mode{ .tty, .normal }, 0..) |mode, i| { + pane.body.mode = mode; p.shell_rows.stale = true; _ = frame.reset(.retain_capacity); const s = try p.render(frame.allocator()); @@ -3204,7 +3204,7 @@ const TerminalTests = struct { while (p.nextEffect()) |_| {} const pane = p.panes[0].?; pane.tty_filter = false; - pane.mode = .normal; + pane.body.mode = .normal; p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[31mAAA\x1b[0m\r\n\x1b[32mBBB\x1b[0m\r\n\x1b[34mCCC\x1b[0m" } }); @@ -3254,7 +3254,7 @@ const TerminalTests = struct { while (p.nextEffect()) |_| {} const pane = p.panes[0].?; pane.tty_filter = false; - pane.mode = .normal; + pane.body.mode = .normal; // A ONE-cell prompt carrying a combining mark — an NFD `e` — then `ABC` // typed at it. The cell walk that finds the prompt's end must step ONE @@ -3290,7 +3290,7 @@ const TerminalTests = struct { // Raw palette, so a leaked background reads back as `.index` — the theme // filter would repaint every blank cell and hide the evidence. pane.tty_filter = false; - pane.mode = .normal; + pane.body.mode = .normal; // Sixty rows, each a distinct background, so a leaked colour names the row // it leaked from. @@ -3346,7 +3346,7 @@ const TerminalTests = struct { while (p.nextEffect()) |_| {} const pane = p.panes[0].?; pane.tty_filter = false; - pane.mode = .normal; + pane.body.mode = .normal; p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[31mAAA\x1b[0m\r\n\x1b[32mBBB\x1b[0m\r\n\x1b[34mCCC\x1b[0m" } }); @@ -3383,7 +3383,7 @@ const TerminalTests = struct { while (p.nextEffect()) |_| {} const pane = p.panes[0].?; pane.tty_filter = false; - pane.mode = .normal; + pane.body.mode = .normal; p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[31mAAA\x1b[0m\r\n\x1b[32mBBB\x1b[0m\r\n\x1b[34mCCC\x1b[0m" } }); @@ -3459,7 +3459,7 @@ const TerminalTests = struct { while (p.nextEffect()) |_| {} const pane = p.panes[0].?; pane.tty_filter = filter; - pane.mode = .normal; + pane.body.mode = .normal; var buf: [256]u8 = undefined; const bytes = try std.fmt.bufPrint( @@ -3539,7 +3539,7 @@ const TerminalTests = struct { while (p.nextEffect()) |_| {} const pane = p.panes[0].?; pane.tty_filter = false; - pane.mode = .tty; + pane.body.mode = .tty; for (0..60) |i| { var buf: [40]u8 = undefined; @@ -3598,13 +3598,13 @@ const TerminalTests = struct { // ABSOLUTE assertions: both modes were wrong identically here, so a // tty/normal differential says nothing. for ([_]bool{ false, true }) |filter| { - for ([_]pardes.Pane.Mode{ .tty, .normal }) |mode| { + for ([_]panes.Text.Mode{ .tty, .normal }) |mode| { const p = try Pardes.init(testing.allocator, .{ .tty_only = true, .cols = 12, .rows = 8 }); defer p.deinit(); while (p.nextEffect()) |_| {} const pane = p.panes[0].?; pane.tty_filter = filter; - pane.mode = mode; + pane.body.mode = mode; p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[32m\u{754C}\x1b[41m\x1b[K\x1b[7G\x1b[44m\x1b[K\r\n" } }); var frame = std.heap.ArenaAllocator.init(testing.allocator); @@ -3634,13 +3634,13 @@ const TerminalTests = struct { // ghostty leaves a `spacer_head` in that last column, carrying the row's // background, and wraps the glyph to the next row. A head OWNS its column, // so skipping it the way a tail is skipped left the row's final column bare. - for ([_]pardes.Pane.Mode{ .tty, .normal }) |mode| { + for ([_]panes.Text.Mode{ .tty, .normal }) |mode| { const p = try Pardes.init(testing.allocator, .{ .startup_config = "Theme helix\n", .tty_only = true, .cols = 16, .rows = 8 }); defer p.deinit(); while (p.nextEffect()) |_| {} const pane = p.panes[0].?; pane.tty_filter = false; - pane.mode = mode; + pane.body.mode = mode; p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[41mzzzzzzzzzzzzz\u{754C}\x1b[0m\r\n" } }); var frame = std.heap.ArenaAllocator.init(testing.allocator); @@ -3667,7 +3667,7 @@ const TerminalTests = struct { while (p.nextEffect()) |_| {} const pane = p.panes[0].?; pane.tty_filter = false; - pane.mode = .tty; + pane.body.mode = .tty; for (0..40) |i| { var buf: [64]u8 = undefined; const bytes = std.fmt.bufPrint(&buf, "\x1b[38;5;{d}mline-{d:0>2}\x1b[0m\r\n", .{ 20 + i, i }) catch unreachable; @@ -3717,7 +3717,7 @@ const TerminalTests = struct { while (p.nextEffect()) |_| {} const pane = p.panes[0].?; pane.tty_filter = filter; - pane.mode = .normal; + pane.body.mode = .normal; var frame = std.heap.ArenaAllocator.init(testing.allocator); defer frame.deinit(); @@ -3749,7 +3749,7 @@ const TerminalTests = struct { while (p.nextEffect()) |_| {} const pane = p.panes[0].?; pane.tty_filter = false; - pane.mode = .normal; + pane.body.mode = .normal; for (0..6) |i| { var buf: [40]u8 = undefined; @@ -3791,7 +3791,7 @@ const TerminalTests = struct { while (p.nextEffect()) |_| {} const pane = p.panes[0].?; pane.tty_filter = false; - pane.mode = .normal; + pane.body.mode = .normal; p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[31m000\x1b[0m\r\n\x1b[32m111\x1b[0m\r\n\r\n\x1b[34m333\x1b[0m\r\n\x1b[35m444\x1b[0m" } }); @@ -3825,7 +3825,7 @@ const TerminalTests = struct { while (p.nextEffect()) |_| {} const pane = p.panes[0].?; pane.tty_filter = false; - pane.mode = .tty; + pane.body.mode = .tty; p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[31mAAA\x1b[0m\r\n\x1b[32mBBB\x1b[0m\r\n\x1b[34mCCC\x1b[0m" } }); @@ -3862,7 +3862,7 @@ const TerminalTests = struct { while (p.nextEffect()) |_| {} const pane = p.panes[0].?; pane.tty_filter = false; - pane.mode = .normal; + pane.body.mode = .normal; for (0..6) |i| { var buf: [64]u8 = undefined; const bytes = std.fmt.bufPrint(&buf, "\x1b[38;5;{d}mrow-{d}-abcdefgh\x1b[0m\r\n", .{ 30 + i, i }) catch unreachable; @@ -3912,7 +3912,7 @@ const TerminalTests = struct { while (p.nextEffect()) |_| {} const pane = p.panes[0].?; pane.tty_filter = false; - pane.mode = .normal; + pane.body.mode = .normal; for (0..26) |i| { var buf: [64]u8 = undefined; const bytes = std.fmt.bufPrint(&buf, "\x1b[38;5;{d}mrow-{d:0>2}-xyzzy\x1b[0m\r\n", .{ 20 + i, i }) catch unreachable; @@ -3971,7 +3971,7 @@ const TerminalTests = struct { // The raw palette, so a row's text names its exact colour instead of one // this test would have to re-derive from the theme. pane.tty_filter = false; - pane.mode = .normal; + pane.body.mode = .normal; for (0..26) |i| { var buf: [64]u8 = undefined; const bytes = std.fmt.bufPrint(&buf, "\x1b[38;5;{d}mrow-{d:0>2}-xyzzy\x1b[0m\r\n", .{ 20 + i, i }) catch unreachable; @@ -4059,7 +4059,7 @@ const TerminalTests = struct { while (p.nextEffect()) |_| {} const pane = p.panes[0].?; pane.tty_filter = false; - pane.mode = .normal; + pane.body.mode = .normal; for (0..26) |i| { var buf: [64]u8 = undefined; const bytes = std.fmt.bufPrint(&buf, "\x1b[38;5;{d}mrow-{d:0>2}-xyzzy\x1b[0m\r\n", .{ 20 + i, i }) catch unreachable; @@ -4130,9 +4130,9 @@ test "an empty counted paste leaves no count for the next motion" { const pane = try p.setTestFile("abcdefgh\n"); if (empty_register) p.yank = try p.gpa.dupe(u8, ""); for ("3p") |cp| p.update(.{ .key = .{ .cp = cp } }); - try std.testing.expectEqual(modal.Normal.State{}, pane.normal); + try std.testing.expectEqual(modal.Normal.State{}, pane.body.normal); p.update(.{ .key = .{ .cp = 'l' } }); - try std.testing.expectEqual(@as(i32, 1), pane.cur_col); + try std.testing.expectEqual(@as(i32, 1), pane.body.cur_col); try std.testing.expectEqualStrings("abcdefgh\n", pane.file.?.content); } } @@ -4156,7 +4156,7 @@ test "cancelled normal gestures leave no count or subprefix after mouse and focu defer frame.deinit(); _ = try p.render(frame.allocator()); for (keys) |cp| p.update(.{ .key = .{ .cp = cp } }); - try std.testing.expect(!std.meta.eql(modal.Normal.State{}, pane.normal)); + try std.testing.expect(!std.meta.eql(modal.Normal.State{}, pane.body.normal)); switch (gesture) { .body, .tag => { const rect = p.rects[0]; @@ -4185,10 +4185,10 @@ test "cancelled normal gestures leave no count or subprefix after mouse and focu try std.testing.expectEqual(@as(usize, 0), p.active); }, } - try std.testing.expectEqual(modal.Normal.State{}, pane.normal); - const col = pane.cur_col; + try std.testing.expectEqual(modal.Normal.State{}, pane.body.normal); + const col = pane.body.cur_col; p.update(.{ .key = .{ .cp = 'l' } }); - try std.testing.expectEqual(col + 1, pane.cur_col); + try std.testing.expectEqual(col + 1, pane.body.cur_col); try std.testing.expectEqualStrings("abcdefghij\n", pane.file.?.content); } } @@ -4199,16 +4199,16 @@ test "cancelled normal gestures leave no count or subprefix through raw tty mode const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 80, .rows = 12 }); defer p.deinit(); const pane = p.panes[0].?; - pane.mode = .normal; + pane.body.mode = .normal; p.update(.{ .output = .{ .pane = 0, .bytes = "abcdefghij\r\n" } }); for (keys) |cp| p.update(.{ .key = .{ .cp = cp } }); - try std.testing.expect(!std.meta.eql(modal.Normal.State{}, pane.normal)); + try std.testing.expect(!std.meta.eql(modal.Normal.State{}, pane.body.normal)); p.update(.{ .key = .{ .cp = p.opts.tty_toggle, .ctrl = true } }); - try std.testing.expectEqual(pardes.Pane.Mode.tty, pane.mode); - try std.testing.expectEqual(modal.Normal.State{}, pane.normal); + try std.testing.expectEqual(panes.Text.Mode.tty, pane.body.mode); + try std.testing.expectEqual(modal.Normal.State{}, pane.body.normal); p.update(.{ .key = .{ .cp = p.opts.tty_toggle, .ctrl = true } }); - try std.testing.expectEqual(pardes.Pane.Mode.normal, pane.mode); - try std.testing.expectEqual(modal.Normal.State{}, pane.normal); + try std.testing.expectEqual(panes.Text.Mode.normal, pane.body.mode); + try std.testing.expectEqual(modal.Normal.State{}, pane.body.normal); } } @@ -4333,8 +4333,8 @@ test "Zig keywords keep every rendered byte colored across line-number widths" { gpa.free(file.path); file.path = try gpa.dupe(u8, "/highlight.zig"); file.scroll = line - 1; - pane.cur_row = @intCast(line - 1); - pane.cur_col = @intCast(std.mem.indexOf(u8, sample, "fn").?); + pane.body.cur_row = @intCast(line - 1); + pane.body.cur_col = @intCast(std.mem.indexOf(u8, sample, "fn").?); pane.hscroll = view.horizontal; p.settings.colors = true; p.settings.wrap = view.wrap; @@ -4373,8 +4373,8 @@ test "Zig keywords keep every rendered byte colored across line-number widths" { const clicked = if_position.?; p.update(.{ .mouse = .{ .button = config.select_button, .kind = .press, .col = clicked.x, .row = clicked.y } }); p.update(.{ .mouse = .{ .button = config.select_button, .kind = .release, .col = clicked.x, .row = clicked.y } }); - try std.testing.expectEqual(@as(i32, @intCast(line - 1)), pane.cur_row); - try std.testing.expectEqual(@as(i32, @intCast(std.mem.indexOf(u8, sample, "if").?)), pane.cur_col); + try std.testing.expectEqual(@as(i32, @intCast(line - 1)), pane.body.cur_row); + try std.testing.expectEqual(@as(i32, @intCast(std.mem.indexOf(u8, sample, "if").?)), pane.body.cur_col); } } } @@ -4389,7 +4389,7 @@ test "terminal overlays preserve trailing blank styles without coloring inserted const pane = p.panes[0].?; pane.tty_filter = false; p.update(.{ .output = .{ .pane = 0, .bytes = "A\r\n\x1b[41m\x1b[2K\r\n\x1b[42m\x1b[2K\r\n\x1b[44m\x1b[2K\x1b[0m" } }); - pane.mode = .normal; + pane.body.mode = .normal; pane.ovl = .{ .row = 0, .rows = 3, .text = try gpa.dupe(u8, "A\n\n") }; var frame = std.heap.ArenaAllocator.init(gpa); defer frame.deinit(); @@ -4421,16 +4421,16 @@ test "terminal overlays preserve trailing blank styles without coloring inserted const LookResetTests = struct { fn seed(pane: *Pane, operand: []const u8) !void { - pane.cur_row = 0; - pane.cur_col = 3; - pane.vsel = .{ .active = true, .explicit = true, .row = 0, .col = 0 }; - pane.msel = .{ .active = true, .r0 = 0, .r1 = 1 }; - pane.sels[0] = .{ .row = 1, .col = 2, .arow = 0, .acol = 1 }; - pane.nsel = 1; - pane.select = true; - pane.normal.count = 5; - pane.append_at = .{ .row = 0, .col = 3 }; - pane.sticky_col = 7; + pane.body.cur_row = 0; + pane.body.cur_col = 3; + pane.body.vsel = .{ .active = true, .explicit = true, .row = 0, .col = 0 }; + pane.body.msel = .{ .active = true, .r0 = 0, .r1 = 1 }; + pane.body.sels[0] = .{ .row = 1, .col = 2, .arow = 0, .acol = 1 }; + pane.body.nsel = 1; + pane.body.select = true; + pane.body.normal.count = 5; + pane.body.append_at = .{ .row = 0, .col = 3 }; + pane.body.sticky_col = 7; for (0..pane.sel.len) |slot| { pane.clearPointerSelection(slot); pane.sel[slot] = .{ .state = .done, .source_id = slot + 1, .r0 = 1, .r1 = 1, .c0 = 0, .c1 = 3 }; @@ -4445,21 +4445,21 @@ const LookResetTests = struct { } fn cleared(pane: *const Pane) !void { - try std.testing.expect(!pane.msel.active); - try std.testing.expectEqual(@as(u8, 0), pane.nsel); - try std.testing.expect(!pane.select); - try std.testing.expectEqual(modal.Normal.State{}, pane.normal); - try std.testing.expect(pane.append_at == null); - try std.testing.expectEqual(@as(i32, -1), pane.sticky_col); + try std.testing.expect(!pane.body.msel.active); + try std.testing.expectEqual(@as(u8, 0), pane.body.nsel); + try std.testing.expect(!pane.body.select); + try std.testing.expectEqual(modal.Normal.State{}, pane.body.normal); + try std.testing.expect(pane.body.append_at == null); + try std.testing.expectEqual(@as(i32, -1), pane.body.sticky_col); for (pane.sel) |selection| try std.testing.expectEqual(.none, selection.state); for (pane.pointer_selections) |selection| try std.testing.expect(selection == null); } fn selected(pane: *const Pane) []const u8 { - if (!pane.vsel.active or pane.cur_row != pane.vsel.row) return ""; - const line = modal.lineSlice(pane.file.?.content, @intCast(pane.cur_row)); - const lo: usize = @intCast(@min(pane.cur_col, pane.vsel.col)); - const hi: usize = @intCast(@max(pane.cur_col, pane.vsel.col)); + if (!pane.body.vsel.active or pane.body.cur_row != pane.body.vsel.row) return ""; + const line = modal.lineSlice(pane.file.?.content, @intCast(pane.body.cur_row)); + const lo: usize = @intCast(@min(pane.body.cur_col, pane.body.vsel.col)); + const hi: usize = @intCast(@max(pane.body.cur_col, pane.body.vsel.col)); return line[lo..modal.nextGrapheme(line, hi)]; } @@ -4472,14 +4472,14 @@ const LookResetTests = struct { pardes.look.lookAt(p, 0, pane.pointer_selections[0].?.raw_text.?); try cleared(pane); try std.testing.expectEqual(@as(usize, 0), p.active); - try std.testing.expectEqual(@as(i32, 2), pane.cur_row); - try std.testing.expectEqual(@as(i32, 1), pane.cur_col); - try std.testing.expect(!pane.vsel.active); + try std.testing.expectEqual(@as(i32, 2), pane.body.cur_row); + try std.testing.expectEqual(@as(i32, 1), pane.body.cur_col); + try std.testing.expect(!pane.body.vsel.active); try seed(pane, "/test.txt:2:2-4"); pardes.look.lookAt(p, 0, pane.pointer_selections[0].?.raw_text.?); try cleared(pane); - try std.testing.expectEqual(@as(i32, 1), pane.cur_row); + try std.testing.expectEqual(@as(i32, 1), pane.body.cur_row); try std.testing.expectEqualStrings("rav", selected(pane)); p.gpa.free(pane.file.?.path); @@ -4487,7 +4487,7 @@ const LookResetTests = struct { try seed(pane, "needle"); pardes.look.lookAt(p, 0, pane.pointer_selections[0].?.raw_text.?); try cleared(pane); - try std.testing.expectEqual(@as(i32, 3), pane.cur_row); + try std.testing.expectEqual(@as(i32, 3), pane.body.cur_row); try std.testing.expectEqualStrings("needle", selected(pane)); } @@ -4512,14 +4512,14 @@ const LookResetTests = struct { try std.testing.expectEqual(id, p.active); try cleared(source); try cleared(destination); - try std.testing.expect(!source.vsel.active); + try std.testing.expect(!source.body.vsel.active); if (range) { - try std.testing.expectEqual(@as(i32, 1), destination.cur_row); + try std.testing.expectEqual(@as(i32, 1), destination.body.cur_row); try std.testing.expectEqualStrings("rav", selected(destination)); } else { - try std.testing.expectEqual(@as(i32, 2), destination.cur_row); - try std.testing.expectEqual(@as(i32, 1), destination.cur_col); - try std.testing.expect(!destination.vsel.active); + try std.testing.expectEqual(@as(i32, 2), destination.body.cur_row); + try std.testing.expectEqual(@as(i32, 1), destination.body.cur_col); + try std.testing.expect(!destination.body.vsel.active); } } } diff --git a/test/pdf.zig b/test/pdf.zig index 8e87dfb1..52fb62aa 100644 --- a/test/pdf.zig +++ b/test/pdf.zig @@ -13,7 +13,7 @@ const Pardes = pardes.Pardes; const Builtin = builtins.registry.Builtin(); const Key = pardes.Key; const Event = pardes.Event; -const Mode = pardes.Pane.Mode; +const Mode = panes.Text.Mode; const Surface = pardes.Surface; const ImagePlace = pardes.ImagePlace; const PdfFitMode = panes.Pdf.FitMode; @@ -457,8 +457,8 @@ test "watched PDF reload replaces MuPDF state and preserves the reading view" { anchor_fraction * @as(f64, @floatFromInt(state.page_heights[2])); state.scroll_to_page_pending = false; state.layout_anchor_pending = false; - pane.cur_row = 9; - pane.cur_col = 8; + pane.body.cur_row = 9; + pane.body.cur_col = 8; try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "live.pdf", .data = replacement }); try std.testing.expect(p.reloadWatchedFile(0, &.{})); @@ -482,8 +482,8 @@ test "watched PDF reload replaces MuPDF state and preserves the reading view" { try std.testing.expect(state.layout_anchor_pending); try std.testing.expectEqual(@as(usize, 2), state.layout_anchor_page); try std.testing.expectApproxEqAbs(anchor_fraction, state.layout_anchor_fraction, 0.0001); - try std.testing.expectEqual(@as(i32, 0), pane.cur_row); - try std.testing.expectEqual(@as(i32, 0), pane.cur_col); + try std.testing.expectEqual(@as(i32, 0), pane.body.cur_row); + try std.testing.expectEqual(@as(i32, 0), pane.body.cur_col); _ = state.ensureText(p.pdf_gpa); const text_lines = std.mem.count(u8, state.text, "\n") + 1; try std.testing.expect(state.text_scroll < text_lines); @@ -690,8 +690,8 @@ test "MuPDF pane renders, navigates, searches, and round-trips its page" { p.update(.{ .key = .{ .cp = '4' } }); p.update(.{ .key = .{ .cp = 'g' } }); p.update(.{ .key = .{ .cp = '?' } }); - try std.testing.expectEqual(.none, pane.normal.prefix); - try std.testing.expectEqual(@as(u32, 0), pane.normal.count); + try std.testing.expectEqual(.none, pane.body.normal.prefix); + try std.testing.expectEqual(@as(u32, 0), pane.body.normal.count); p.update(.{ .key = .{ .cp = 'j' } }); try std.testing.expectEqual(row_scroll, pane.pdf.?.document_scroll_y); @@ -893,9 +893,9 @@ test "MuPDF pane renders, navigates, searches, and round-trips its page" { p.update(.{ .key = .{ .cp = 'n' } }); try std.testing.expectEqual(results_id, p.active); const results_pane = p.panes[results_id].?; - try std.testing.expect(results_pane.vsel.active and results_pane.vsel.explicit); - try std.testing.expectEqual(@as(i32, 0), results_pane.cur_row); - try std.testing.expectEqual(@as(i32, 0), results_pane.cur_col); + try std.testing.expect(results_pane.body.vsel.active and results_pane.body.vsel.explicit); + try std.testing.expectEqual(@as(i32, 0), results_pane.body.cur_row); + try std.testing.expectEqual(@as(i32, 0), results_pane.body.cur_col); p.update(.{ .key = .{ .cp = Key.enter } }); try std.testing.expectEqual(@as(usize, 0), p.active); try std.testing.expectEqualStrings("Pardes", pane.pdf.?.search_query); @@ -1097,15 +1097,15 @@ test "PDF normal adapter consumes unsupported actions and navigates page fallbac p.update(.{ .key = .{ .cp = '|' } }); try std.testing.expectEqual(page_before_noop, pv.page); try std.testing.expectEqual(revision_before_noop, pv.next_raster_revision); - try std.testing.expectEqual(@as(u32, 0), pane.normal.count); - try std.testing.expectEqual(.none, pane.normal.prefix); - try std.testing.expect(!pane.vsel.active and !pane.msel.active and pane.nsel == 0); + try std.testing.expectEqual(@as(u32, 0), pane.body.normal.count); + try std.testing.expectEqual(.none, pane.body.normal.prefix); + try std.testing.expect(!pane.body.vsel.active and !pane.body.msel.active and pane.body.nsel == 0); try std.testing.expect(!pane.tag_edit); // Cross-pane BODY-NORMAL actions keep their established shared paths. p.update(.{ .key = .{ .cp = ':' } }); try std.testing.expect(pane.tag_edit); - try std.testing.expectEqual(Mode.normal, pane.mode); + try std.testing.expectEqual(Mode.normal, pane.body.mode); p.update(.{ .key = .{ .cp = Key.escape } }); try std.testing.expect(!pane.tag_edit); p.update(.{ .key = .{ .cp = ' ' } }); @@ -1167,8 +1167,8 @@ test "Escape cancels PDF chrome in place and Shift-Escape leaves the pane" { try std.testing.expect(!pv.highlights_dirty and !pv.search_reveal_pending); try std.testing.expectEqual(page_before, pv.page); try std.testing.expectEqual(scroll_before, pv.document_scroll_y); - try std.testing.expectEqual(@as(u32, 0), pane.normal.count); - try std.testing.expectEqual(.none, pane.normal.prefix); + try std.testing.expectEqual(@as(u32, 0), pane.body.normal.count); + try std.testing.expectEqual(.none, pane.body.normal.prefix); // A second Escape on a bare document is inert rather than an exit. p.update(.{ .key = .{ .cp = Key.escape } }); try std.testing.expectEqual(@as(usize, 0), p.active); @@ -1781,8 +1781,8 @@ test "PDF native mouse selection, Look, and highlights share page geometry" { const page_before = pv.page; const scroll_before = pv.document_scroll_y; const sels_before = pane.sel; - const cursor_before = .{ pane.cur_row, pane.cur_col }; - const modal_before = .{ pane.msel, pane.vsel, pane.nsel }; + const cursor_before = .{ pane.body.cur_row, pane.body.cur_col }; + const modal_before = .{ pane.body.msel, pane.body.vsel, pane.body.nsel }; const selection_before = pv.selection orelse return error.MissingPdfSelection; const selection_quads_before = try gpa.dupe(pdf_impl.Quad, selection_before.quads); defer gpa.free(selection_quads_before); @@ -1836,8 +1836,8 @@ test "PDF native mouse selection, Look, and highlights share page geometry" { try std.testing.expectEqual(page_before, pv.page); try std.testing.expectEqual(scroll_before, pv.document_scroll_y); try std.testing.expect(std.meta.eql(sels_before, pane.sel)); - try std.testing.expectEqual(cursor_before, .{ pane.cur_row, pane.cur_col }); - try std.testing.expect(std.meta.eql(modal_before, .{ pane.msel, pane.vsel, pane.nsel })); + try std.testing.expectEqual(cursor_before, .{ pane.body.cur_row, pane.body.cur_col }); + try std.testing.expect(std.meta.eql(modal_before, .{ pane.body.msel, pane.body.vsel, pane.body.nsel })); const selection_after = pv.selection orelse return error.HoverDroppedPdfSelection; try std.testing.expectEqualSlices(pdf_impl.Quad, selection_quads_before, selection_after.quads); try std.testing.expectEqualStrings(selection_text_before, pv.selection_text); @@ -1938,7 +1938,7 @@ test "PDF native mouse selection, Look, and highlights share page geometry" { try std.testing.expect(panes.Pdf.beginSelection(p, pane, word_col, selected_row)); p.update(.{ .key = .{ .cp = 'v' } }); try std.testing.expect(pv.selection != null); - try std.testing.expect(!pane.vsel.active); + try std.testing.expect(!pane.body.vsel.active); p.update(.{ .mouse = .{ .button = config.select_button, .kind = .press, .col = word_col, .row = selected_row } }); p.update(.{ .mouse = .{ .button = config.select_button, .kind = .release, .col = word_col, .row = selected_row } }); try std.testing.expect(pv.selection == null); diff --git a/test/perf.zig b/test/perf.zig index 6ce8f014..8eec1ed0 100644 --- a/test/perf.zig +++ b/test/perf.zig @@ -229,7 +229,7 @@ fn measureStartup(io: std.Io, reps: usize, json: bool) !void { try std.json.Stringify.valueAlloc(gpa, result, .{}) else try std.fmt.allocPrint(gpa, "{s}: boot {d} ns (cold {d}), first frame {d} ns, {d} allocations / {d} B, peak {d} B", .{ - result.case, result.init_median_ns, result.cold_ns, result.frame_median_ns, + result.case, result.init_median_ns, result.cold_ns, result.frame_median_ns, result.allocations, result.allocated_bytes, result.peak_bytes, }); defer gpa.free(text); @@ -473,7 +473,7 @@ fn measure(op: Op, fx: Fixture, path: []const u8, expected_bytes: usize, reps: u for (0..warmup + reps) |n| { seek(pane, fx, n); _ = try frame(core); // settle the view at the new spot, untimed - const before = .{ .row = pane.cur_row, .col = pane.cur_col, .scroll = pane.scroll(), .len = pane.file.?.content.len }; + const before = .{ .row = pane.body.cur_row, .col = pane.body.cur_col, .scroll = pane.scroll(), .len = pane.file.?.content.len }; const rect = core.rects[id]; const wheel_col = rect.x + pardes.config.GUTTER; const wheel_row = if (core.settings.tag_bottom) rect.y else rect.y + pardes.BOX_H; @@ -492,16 +492,16 @@ fn measure(op: Op, fx: Fixture, path: []const u8, expected_bytes: usize, reps: u const dt = nowNs() -| t0; switch (op) { .open => unreachable, - .render => if (pane.cur_row != before.row or pane.cur_col != before.col or pane.file.?.content.len != before.len) + .render => if (pane.body.cur_row != before.row or pane.body.cur_col != before.col or pane.file.?.content.len != before.len) return error.RenderChangedDocument, - .key_down => if (pane.cur_row != before.row + 1) return error.DownDidNotMove, - .key_right => if (pane.cur_row != before.row or pane.cur_col != before.col + 1) return error.RightDidNotMove, + .key_down => if (pane.body.cur_row != before.row + 1) return error.DownDidNotMove, + .key_right => if (pane.body.cur_row != before.row or pane.body.cur_col != before.col + 1) return error.RightDidNotMove, .page_down => if (pane.scroll() <= before.scroll and before.scroll < @as(i32, @intCast(fx.lines)) - pane.rows) return error.PageDidNotScroll, .wheel => if (pane.scroll() <= before.scroll and before.scroll < @as(i32, @intCast(fx.lines)) - pane.rows) return error.WheelDidNotScroll, .edit_char => { - if (pane.file.?.content.len != before.len + 1 or pane.cur_row != before.row or pane.cur_col != before.col + 1) + if (pane.file.?.content.len != before.len + 1 or pane.body.cur_row != before.row or pane.body.cur_col != before.col + 1) return error.CharacterWasNotInserted; const line = pardes.panes.File.sourceLine(pane, before.row); if (line[@intCast(before.col)] != 'x') return error.CharacterWasNotInserted; @@ -521,13 +521,13 @@ fn measureTerm(op: TermOp, fx: TermFixture, reps: usize) !Cell { defer core.deinit(); const pane = core.panes[0] orelse return error.MissingTerminal; const state = pane.terminal orelse return error.MissingTerminal; - if (op == .key_down or op == .edit_char) pane.mode = .normal; + if (op == .key_down or op == .edit_char) pane.body.mode = .normal; if (op == .edit_char) { core.update(.{ .key = .{ .cp = 'i', .text = "i" } }); pump(core); } _ = try frame(core); - const motion_rows = if (op == .key_down) (try pardes.edit.paneCursorLines(core, pane)).len else 0; + const motion_rows = if (op == .key_down) (try pardes.edit.paneCursorLines(core, &pane.body)).len else 0; if (op == .key_down and motion_rows < 3) return error.EmptyTerminalFixture; var cols = screen_cols; @@ -535,16 +535,16 @@ fn measureTerm(op: TermOp, fx: TermFixture, reps: usize) !Cell { for (0..warmup + reps) |n| { if (op == .key_down) { const span = @max(1, motion_rows * 8 / 10); - pane.cur_row = @intCast(@min(motion_rows - 2, motion_rows / 10 + (n *% 7919) % span)); - pane.cur_col = 0; - pane.cur_pinned = true; - pane.sticky_col = -1; + pane.body.cur_row = @intCast(@min(motion_rows - 2, motion_rows / 10 + (n *% 7919) % span)); + pane.body.cur_col = 0; + pane.body.cur_pinned = true; + pane.body.sticky_col = -1; pane.ensureCursorVisible(); _ = try frame(core); } const before = .{ - .row = pane.cur_row, - .col = pane.cur_col, + .row = pane.body.cur_row, + .col = pane.body.cur_col, .edit_len = if (pane.ovl) |overlay| overlay.text.len else 0, .replay_head = state.replay.head, .replay_len = state.replay.len, @@ -570,7 +570,7 @@ fn measureTerm(op: TermOp, fx: TermFixture, reps: usize) !Cell { _ = try frame(core); const dt = nowNs() -| t0; switch (op) { - .render => if (pane.cur_row != before.row or pane.cur_col != before.col or + .render => if (pane.body.cur_row != before.row or pane.body.cur_col != before.col or state.replay.head != before.replay_head or state.replay.len != before.replay_len) return error.RenderChangedTerminal, .output => { @@ -590,12 +590,12 @@ fn measureTerm(op: TermOp, fx: TermFixture, reps: usize) !Cell { state.vt.screens.active.pages.rows != pane.rows) return error.TerminalDidNotResize, .resize_cols => if (pane.cols == before.cols or pane.rows != before.rows or state.vt.screens.active.pages.cols != pane.cols) return error.TerminalDidNotResize, - .key_down => if (pane.cur_row != before.row + 1) return error.DownDidNotMove, + .key_down => if (pane.body.cur_row != before.row + 1) return error.DownDidNotMove, .edit_char => { const overlay = pane.ovl orelse return error.CharacterWasNotInserted; - if (overlay.text.len != before.edit_len + 1 or pane.cur_row != before.row or pane.cur_col != before.col + 1) + if (overlay.text.len != before.edit_len + 1 or pane.body.cur_row != before.row or pane.body.cur_col != before.col + 1) return error.CharacterWasNotInserted; - const line = pardes.modal.lineSlice(overlay.text, @intCast(pane.cur_row - overlay.row)); + const line = pardes.modal.lineSlice(overlay.text, @intCast(pane.body.cur_row - overlay.row)); if (before.col < 0 or before.col >= line.len or line[@intCast(before.col)] != 'x') return error.CharacterWasNotInserted; }, @@ -711,7 +711,7 @@ const UndoOutput = struct { fn measureUndoOutput(core: *pardes.Pardes, counter: *Allocations, arena: *std.heap.ArenaAllocator, samples: []u64) ![3]UndoOutput { const pane = core.panes[0].?; const pages = &pane.terminal.?.vt.screens.active.pages; - if (pane.ed_undo_len != 0 or pane.ed_redo_len != 0) return error.UnexpectedTerminalHistory; + if (pane.body.ed_undo_len != 0 or pane.body.ed_redo_len != 0) return error.UnexpectedTerminalHistory; if (pane.ovl) |overlay| core.gpa.free(overlay.text); pane.ovl = null; var result: [3]UndoOutput = undefined; @@ -722,17 +722,17 @@ fn measureUndoOutput(core: *pardes.Pardes, counter: *Allocations, arena: *std.he const first: i32 = @intCast(@min(128, pages.total_rows - 2)); for (0..depth) |index| { pane.ovl = .{ .row = first, .rows = 2, .text = try std.fmt.allocPrint(core.gpa, "saved edit {d}\nsecond row", .{index}) }; - pane.cur_row = first + 1; - pane.cur_col = 1; - pane.vsel = .{ .active = true, .row = first, .col = 0 }; + pane.body.cur_row = first + 1; + pane.body.cur_col = 1; + pane.body.vsel = .{ .active = true, .row = first, .col = 0 }; pardes.panes.Terminal.pushUndo(core, pane); core.gpa.free(pane.ovl.?.text); pane.ovl = null; - if (pane.ed_undo_len != index + 1) return error.TerminalUndoSnapshotFailed; + if (pane.body.ed_undo_len != index + 1) return error.TerminalUndoSnapshotFailed; } defer { - for (pane.ed_undo[0..pane.ed_undo_len]) |snapshot| if (snapshot.ovl) |overlay| core.gpa.free(overlay.text); - pane.ed_undo_len = 0; + for (pane.body.ed_undo[0..pane.body.ed_undo_len]) |snapshot| if (snapshot.ovl) |overlay| core.gpa.free(overlay.text); + pane.body.ed_undo_len = 0; } pardes.panes.Terminal.enterTty(core, 0); pump(core); @@ -767,7 +767,7 @@ fn measureUndoOutput(core: *pardes.Pardes, counter: *Allocations, arena: *std.he if (pages.countTrackedPins() != tracked_before + 2) return error.TerminalPinsLeaked; const expected: i32 = if (start.garbage) 0 else @intCast((pages.pointFromPin(.screen, start.*) orelse return error.TerminalAnchorLost).screen.y); const last: i32 = if (end.garbage) 0 else @intCast((pages.pointFromPin(.screen, end.*) orelse return error.TerminalAnchorLost).screen.y); - for (pane.ed_undo[0..pane.ed_undo_len], 0..) |snapshot, index| { + for (pane.body.ed_undo[0..pane.body.ed_undo_len], 0..) |snapshot, index| { const overlay = snapshot.ovl orelse return error.TerminalUndoTextLost; var expected_buffer: [64]u8 = undefined; const text = try std.fmt.bufPrint(&expected_buffer, "saved edit {d}\nsecond row", .{index}); @@ -812,7 +812,7 @@ fn measureTerminalSession(io: std.Io, mib: usize, reps: usize, json: bool) !void pump(core); const pane = core.panes[0] orelse return error.MissingTerminal; const state = pane.terminal orelse return error.MissingTerminal; - pane.mode = .tty; + pane.body.mode = .tty; pane.tty_filter = false; var arena: std.heap.ArenaAllocator = .init(counter.allocator()); defer arena.deinit(); @@ -855,17 +855,17 @@ fn measureTerminalSession(io: std.Io, mib: usize, reps: usize, json: bool) !void pump(core); _ = try core.render(arena.allocator()); const first_modal_ns = nowNs() - modal_begin; - if (pane.mode != .normal or !pane.cur_pinned or pane.cur_row != first_row - 1) return error.FirstModalKeyDidNotMove; + if (pane.body.mode != .normal or !pane.body.cur_pinned or pane.body.cur_row != first_row - 1) return error.FirstModalKeyDidNotMove; for (modal_samples, 0..) |*sample, index| { const down = index % 2 == 0; - const before = pane.cur_row; + const before = pane.body.cur_row; _ = arena.reset(.retain_capacity); const begin = nowNs(); core.update(.{ .key = .{ .cp = if (down) 'j' else 'k' } }); pump(core); _ = try core.render(arena.allocator()); sample.* = nowNs() - begin; - if (pane.cur_row != before + @as(i32, if (down) 1 else -1)) return error.ModalKeyDidNotMove; + if (pane.body.cur_row != before + @as(i32, if (down) 1 else -1)) return error.ModalKeyDidNotMove; } core.update(.{ .key = .{ .cp = core.opts.tty_toggle, .ctrl = true } }); pump(core); @@ -883,8 +883,8 @@ fn measureTerminalSession(io: std.Io, mib: usize, reps: usize, json: bool) !void const live_after_modal = counter.live; var overlay_median_ns: [2]u64 = undefined; var overlay_p95_ns: [2]u64 = undefined; - pane.mode = .normal; - pane.cur_pinned = true; + pane.body.mode = .normal; + pane.body.cur_pinned = true; pane.ovl = .{ .row = 0, .rows = 1, .text = try core.gpa.dupe(u8, "edited output") }; for (0..2) |phase| { for (modal_samples, 0..) |*sample, index| { @@ -897,8 +897,8 @@ fn measureTerminalSession(io: std.Io, mib: usize, reps: usize, json: bool) !void pump(core); const cursor_row = pardes.panes.Terminal.gridOffset(pane) + @as(i32, pardes.panes.Terminal.gridCursor(pane).y); pane.ovl.?.row = if (phase == 0) 0 else cursor_row - 1; - pane.cur_row = pane.ovl.?.row; - pane.cur_col = 0; + pane.body.cur_row = pane.ovl.?.row; + pane.body.cur_col = 0; const surface = try core.render(arena.allocator()); sample.* = nowNs() - begin; try checkTerminalTail(core, surface, tail_id); @@ -1146,11 +1146,11 @@ fn seek(pane: *pardes.Pane, fx: Fixture, n: usize) void { const row = fx.lines / 10 + (n *% 7919) % span; f.scroll = @min(row, fx.lines -| 1); f.syntax_dirty = true; - pane.cur_row = @intCast(f.scroll); - pane.cur_col = if (fx.cols > 200) @intCast(fx.cols * 3 / 4) else 0; - pane.cur_pinned = true; - pane.hscroll = @max(0, pane.cur_col - 40); - pane.sticky_col = -1; + pane.body.cur_row = @intCast(f.scroll); + pane.body.cur_col = if (fx.cols > 200) @intCast(fx.cols * 3 / 4) else 0; + pane.body.cur_pinned = true; + pane.hscroll = @max(0, pane.body.cur_col - 40); + pane.body.sticky_col = -1; } fn boot() !*pardes.Pardes { -- cgit v1.3 From c811c34ed3bcd23954414125b45c7cac67307d5d Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Mon, 28 Sep 2026 16:04:12 -0300 Subject: Every range lives through insert mode, carried through each edit Insert mode dropped the selection on the first key and restored only the primary's appended-over span on Esc. Now each insert-mode edit is made at the bare cursor as before, and the range is then carried through it with helix's Range::map rules: typing slides an i range and stretches an a range, Enter (which now also drops the blanks before the cursor, as helix does) slides or stretches by what the cursor moved, and an arrow collapses. The replay gives every other range the same. Esc after a pulls each range's end back by one (helix restore_cursor), which replaces Text.append_at. The wiX-edit-drops-sel and msel-append waivers are gone. Co-Authored-By: Claude Opus 5.5 --- docs/helix-keys.md | 36 ++++++++----- docs/selections.md | 22 +++++--- src/Output.zig | 2 +- src/Terminal.zig | 8 +-- src/Text.zig | 4 +- src/edit.zig | 127 ++++++++++++++++++++++++++++++++++++--------- src/look.zig | 2 +- src/mouse.zig | 4 +- src/normal.zig | 6 +-- src/tagline.zig | 4 +- test/hxcases/cases.jsonl | 15 ++++++ test/hxcases/goldens.jsonl | 15 ++++++ test/hxcases/waivers.jsonl | 2 - test/mode.zig | 6 +-- test/panes.zig | 4 +- transactions.txt | 15 ++---- 16 files changed, 194 insertions(+), 78 deletions(-) (limited to 'src/Output.zig') diff --git a/docs/helix-keys.md b/docs/helix-keys.md index 90efc463..35f62765 100644 --- a/docs/helix-keys.md +++ b/docs/helix-keys.md @@ -7,10 +7,17 @@ checkout (`~/05-genizah/helix`); that checkout now sits on the local `pardes-harness` branch, whose three commits add only the harness, so `book/src/keymap.md` is byte-identical at its tip (694e7dfd). As of phase 5 every helix-equivalent row in A and B is differentially verified against real -helix (see "Differential testing" at the bottom). Five of the six waivers are -named in the row they belong to; the sixth, `wiX-edit-drops-sel`, belongs to no -single key — it is the anchor-only divergence every insert-mode edit shares — -and is described in the Files list at the bottom instead. +helix (see "Differential testing" at the bottom). Every waiver is named in the +row it belongs to. + +**The reference helix is fixed at one commit:** the `hx-harness` built from +`694e7dfdd` on the genizah checkout's `pardes-harness` branch, which is upstream +`278b24389` (2026-06-29, `25.07-905`) plus the three harness commits. "helix" +in this document means that build, not the 25.07.1 release, which differs on +counted `Alt-(`/`Alt-)` and on `&`. Upstream master was 82 commits further on +2026-09-28 (`079a789e`); of those only `416a0e09` (continuing a comment in an +injected `comment` layer) touches the editing code, and it needs tree-sitter, +which the harness runs without. Code map, by SYMBOL — line numbers rot, names do not. Body-normal key RECOGNITION is `modal.Normal` in `src/modal.zig`: a state machine over `Role` (one @@ -227,7 +234,7 @@ grew `sels` + `primary`, emitted only when there is more than one range. | `y` with several ranges | one value per range, pasted back value i at range i by `p`/`P`/`R` and insert `Ctrl-r`; the acme cut/paste chords and a paste into a terminal take the values joined by newlines | `Registers.zig` | helix-verified | | `"` | the next command's register: any character names one of its own. Computed ones: `_` swallows writes and reads nothing (`"_d`), `#` is each range's number from 1, `.` each range's text, `%` the file's name, `/` the last `s`/`S` pattern; `+`/`*` the system clipboard. A count typed before `"` stays the command's | helix `select_register` | helix-verified | | insert `Ctrl-r ` | type this range's value of the register (`Ctrl-r #` numbers the cursors). Esc after `Ctrl-r` only cancels it. `Ctrl-r +` reads what pardes last put on the clipboard, not the desktop's | helix `insert_register` | helix-verified | -| `a` … `Esc` with several ranges | the primary's appended-over span is restored; the others collapse to bare cursors | `Pane.append_at` is a single field. Waived (`msel-append`) | waived | +| insert mode with a selection | every range is carried through each edit as helix maps it (`Range::map`): typing at the head of an `i` range slides it, typing at the end of an `a` range stretches it, Enter slides or stretches it by what the cursor moved, and an arrow key collapses it. Esc after `a` pulls each range's end back one character (helix `restore_cursor`) | `edit.insertKey`, `Text.restore_cursor` | helix-verified | | `&` | align selections into columns: the k-th range of each line is column k, and spaces go in before each range until its head reaches the column's widest head, in display cells (`File.rawDisplayCol`) | helix `align_selections` as of the harness's helix (25.07.1 grouped columns differently). A range over several lines refuses. A TAB counts as `tab_width` cells, not up to the next stop | helix-verified | | `Alt-)` / `Alt-(` / `Alt-)` | rotate the CONTENTS of the selections forward / back by one range (n ranges), in one edit; each range comes back over the text it now holds and the primary moves with its text | helix `rotate_selection_contents_*` as of the harness's helix: 25.07.1 read the count as a GROUP size instead (rotate by one within each run of n ranges) and left the primary where it was, which is what helix-golf's `invert_dictionary_2` relies on | helix-verified | @@ -389,11 +396,11 @@ Files (all in `test/hxcases/`): (runs the `hx-harness` binary from the helix checkout; override with `$HX_HARNESS`). Only needed when cases change — the diff itself runs offline. -- `waivers.jsonl` — named exemptions, each with a reason. Three live ones: - `wiX-edit-drops-sel` and `msel-append` (helix maps selections through - insert-mode edits, pardes does not) and `alt-c-window-op` (the pardes - window op deliberately shadows helix change-noyank). `msel-yank-paste` - went with registers of one value per range; `sel-regex-caret` and +- `waivers.jsonl` — named exemptions, each with a reason. One live one: + `alt-c-window-op` (the pardes window op deliberately shadows helix + change-noyank). `wiX-edit-drops-sel` and `msel-append` went when insert + mode began carrying every range through its edits, `msel-yank-paste` with + registers of one value per range, `sel-regex-caret` and `sel-regex-dot-newline` when `s`/`S` began searching line by line. - `parity.jsonl` — 80 further cases, used only by the parity gate below. - `parity-waivers.jsonl` — 14 named exemptions for the parity gate, in three @@ -412,10 +419,11 @@ Files (all in `test/hxcases/`): tested when an earlier one misses. The goldens are `hx-harness test/hxcases/golf.jsonl`; `zig build hxgolf` runs them. All ten examples reproduce their published result in hx 25.07.1 under the site's own conditions (a file of the example's language, auto-pairs - on). Under the harness pins two do not: `csv_to_sql` needs auto-pairs to - close its `VALUES (`, and `invert_dictionary_2` needs 25.07's - `Alt-(` (rotate within groups of count) where the harness's newer - helix rotates by count. + on). Under the harness two do not, and their goldens are the harness's + anyway, which pardes follows: `csv_to_sql` needs auto-pairs (off in the + harness and absent in pardes) to close its `VALUES (`, and + `invert_dictionary_2` needs 25.07.1's `Alt-(` (rotate within groups + of count) where the reference helix rotates by count. - `smoke.jsonl` — 20 cases referenced by nothing in the tree: no build step, no script. Either wire it up or delete it. diff --git a/docs/selections.md b/docs/selections.md index 0f000e2c..c08ccb14 100644 --- a/docs/selections.md +++ b/docs/selections.md @@ -3,6 +3,8 @@ How normal mode holds and changes its selections, and where that differs from helix's `Selection` (a list of ranges over gap offsets, with a primary index). Key-by-key behaviour is in docs/helix-keys.md; this is the model underneath. +"helix" here is the reference build docs/helix-keys.md names: `hx-harness` +at `694e7dfdd`, upstream `278b24389`. ## What a selection is @@ -25,8 +27,9 @@ plus up to 63 others. `s`, `n`/`N`, ...) rather than left behind by a motion. Only pardes reads it: the look (Enter) and execute (Tab) chords act on explicit selections and on the word under the cursor otherwise. -- `select` is `v` extend mode. `append_at` remembers where an `a` began, so - Esc can give back the range it appended over. +- `select` is `v` extend mode. `restore_cursor` says the insert session + began with `a`, so Esc gives each range back the character it was + stretched by. `Text.setRanges` is the one writer of a whole selection: it sorts by start, merges ranges that overlap or share a start (helix `normalize`), follows the @@ -67,6 +70,17 @@ A parsed action has a scope (`modal.Normal.Action.scope`). look) runs once from the primary and drops back to one cursor (`normal.multiOnce`). +## Insert mode + +Each range lives on through insert mode. Every insert-mode edit happens at +the cursor, so `edit.insertKey` runs it on the bare cursor and then carries +the range through what it did to the text, with helix's `Range::map` rules: +at an insertion, a backward range's head and an empty range move past it +and a forward range's head stays before it, so typing slides an `i` range +and stretches an `a` range. Enter slides or stretches the range by what the +cursor moved; an arrow key collapses it. The other ranges get the same by +the replay. + ## Undo, registers, repeat - One keystroke is one undo step however many ranges it edited: only the @@ -86,10 +100,6 @@ A parsed action has a scope (`modal.Normal.Action.scope`). ## Where it differs from helix -- Insert mode: helix maps every range through each keystroke's edit, so a - range an `i`/`a` started from stretches over what is typed and keeps its - anchor. Here only the cursor cells move, and after Esc only the primary's - `append_at` span comes back (waivers `wiX-edit-drops-sel`, `msel-append`). - Direction of a one-character range: both of its cells are the same cell, so it has none. helix can flip one (`Alt-;`) and the commands that read the head (`&`, the next extend) see the difference. diff --git a/src/Output.zig b/src/Output.zig index 6e1765a7..201b5491 100644 --- a/src/Output.zig +++ b/src/Output.zig @@ -749,7 +749,7 @@ pub fn resetBody(p: *Pardes, pane: *Pane) void { pane.body.select = false; pane.sel = @splat(.{}); pane.body.sticky_col = -1; - pane.body.append_at = null; + pane.body.restore_cursor = false; pane.body.normal.clear(); pane.look_at = null; if (p.look_hover_wait) |wait| if (wait.serial == pane.serial) { diff --git a/src/Terminal.zig b/src/Terminal.zig index e204b44c..e3378007 100644 --- a/src/Terminal.zig +++ b/src/Terminal.zig @@ -717,7 +717,7 @@ pub fn feedOutput(p: *Pardes, pane: *Pane, bytes: []const u8) void { if (comptime !enabled) return; if (pane.terminal == null) return; const has_positions = pane.ovl != null or pane.body.cur_pinned or pane.body.vsel.active or - pane.body.msel.active or pane.body.nsel > 0 or pane.body.append_at != null or pane.look_at != null or + pane.body.msel.active or pane.body.nsel > 0 or pane.look_at != null or pane.body.ed_undo_len > 0 or pane.body.ed_redo_len > 0 or pointerRowCount(pane) > 0; // Sticky bottom, as every other terminal does it: output drags the // viewport down only when the viewport was already on the last row, so @@ -843,10 +843,6 @@ fn ingestWithPositions(pane: *Pane, bytes: []const u8) void { extra[nextra + 1] = &selection.arow; nextra += 2; } - if (pane.body.append_at) |*at| { - extra[nextra] = &at.row; - nextra += 1; - } if (pane.look_at) |*at| { extra[nextra] = &at.row; nextra += 1; @@ -1124,7 +1120,7 @@ pub fn enterTty(p: *Pardes, id: usize) void { // keeps its modal endpoint for the next return to editor mode. pane.body.cur_pinned = selected; pane.body.select = false; - pane.body.append_at = null; + pane.body.restore_cursor = false; pane.body.sticky_col = -1; pane.body.normal.clear(); } diff --git a/src/Text.zig b/src/Text.zig index 7ad243a1..764b8a6a 100644 --- a/src/Text.zig +++ b/src/Text.zig @@ -65,7 +65,9 @@ select: bool = false, /// sticky goal column for j/k runs (helix old_visual_position): any /// non-vertical range write resets it to -1. sticky_col: i32 = -1, -append_at: ?struct { row: i32, col: i32 } = null, +/// The insert session began with `a`: on Esc every range gives back the +/// one character it was stretched by (helix restore_cursor). +restore_cursor: bool = false, /// insert `Ctrl-r` was pressed: the next key names the register to insert reg_wait: bool = false, normal: modal.Normal.State = .{}, diff --git a/src/edit.zig b/src/edit.zig index 14d8b7ed..8f6f09c6 100644 --- a/src/edit.zig +++ b/src/edit.zig @@ -344,28 +344,20 @@ pub fn exitInsert(p: *Pardes, t: *Text) void { t.reg_wait = false; t.msel.active = false; t.normal.clear(); - if (t.append_at) |aa| { - t.append_at = null; - const text = flatSurface(p, t) catch return; - const gap = modal.offsetAt(text, .{ .row = @intCast(@max(0, t.cur_row)), .col = @intCast(@max(0, t.cur_col)) }); - const a_off = modal.offsetAt(text, .{ .row = @intCast(@max(0, aa.row)), .col = @intCast(@max(0, aa.col)) }); - const back = @max(a_off, modal.prevGrapheme(text, gap)); - const bc = modal.positionAt(text, back); - t.cur_row = @intCast(bc.row); - t.cur_col = @intCast(bc.col); - t.vsel = .{ .active = a_off != back, .row = aa.row, .col = aa.col, .explicit = false }; - t.cur_pinned = true; - t.show(); - for (t.sels[0..t.nsel]) |*s| { - const sgap = modal.offsetAt(text, .{ .row = @intCast(@max(0, s.row)), .col = @intCast(@max(0, s.col)) }); - const b2 = if (back == gap) sgap else modal.prevGrapheme(text, sgap); - const bp = modal.positionAt(text, b2); - s.row = @intCast(bp.row); - s.col = @intCast(bp.col); - s.arow = s.row; - s.acol = s.col; - } + if (!t.restore_cursor) return; + t.restore_cursor = false; + // helix enter_normal_mode: every range, from its start to the char + // before its end when it points forward, else to its end + const expl = (t.vsel.active and t.vsel.explicit) or t.msel.active; + const text = flatSurface(p, t) catch return; + var rs: [Text.max_selections]modal.Selection = undefined; + const got = t.ranges(text, 0, &rs); + for (rs[0..got.n]) |*r| { + const from = @min(r.anchor, r.head); + const to = @max(r.anchor, r.head); + r.* = .{ .anchor = from, .head = if (r.head > r.anchor) @max(from, modal.prevGrapheme(text, to)) else to }; } + t.setRanges(text, rs[0..got.n], &.{}, got.pri, expl); } pub fn paneCursorLines(p: *Pardes, t: *Text) ![]const []const u8 { @@ -518,7 +510,7 @@ pub fn enterInsert(p: *Pardes, t: *Text, where: InsertAt, cnt: usize) void { // `u` undoes the whole session and restores what was selected pushUndo(p, t); t.select = false; - t.append_at = null; + t.restore_cursor = false; t.sticky_col = -1; const text = flatSurface(p, t) catch { t.mode = .insert; @@ -544,12 +536,14 @@ pub fn enterInsert(p: *Pardes, t: *Text, where: InsertAt, cnt: usize) void { const lo_col = if (b) |bb| bb.lo_col else t.cur_col; const hi_row = if (b) |bb| bb.hi_row else t.cur_row; const hi_col = if (b) |bb| bb.hi_col else t.cur_col; - t.append_at = .{ .row = lo_row, .col = lo_col }; + t.restore_cursor = true; const gap = modal.nextGrapheme(text, modal.offsetAt(text, .{ .row = @intCast(@max(0, hi_row)), .col = @intCast(@max(0, hi_col)) })); const gc = modal.positionAt(text, gap); t.cur_row = @intCast(gc.row); t.cur_col = @intCast(gc.col); - t.vsel = .{ .active = b != null, .row = lo_row, .col = lo_col, .explicit = false }; + // helix append_mode: the range reaches one past its end, which + // is where typing goes; a bare cursor becomes a range too + t.vsel = .{ .active = true, .row = lo_row, .col = lo_col, .explicit = false }; t.cur_pinned = true; }, .line_start => { @@ -634,6 +628,72 @@ pub fn insertKey(p: *Pardes, t: *Text, key: Key) void { t.reg_wait = true; return; } + // helix maps every range through each insert-mode edit (Range::map): + // the edits below work on the bare cursor, and the range the cursor + // heads is carried through what they did to the text afterwards + if (!t.vsel.active) return insertEdit(p, t, key); + const old = flatSurface(p, t) catch return insertEdit(p, t, key); + const r = t.primaryRange(old, 0); + const c = modal.selectionCursor(old, r); + const old_len = old.len; + const explicit = t.vsel.explicit; + t.vsel.active = false; + insertEdit(p, t, key); + if (t.mode != .insert) return; + const new = flatSurface(p, t) catch return; + const c2 = modal.offsetAt(new, .{ .row = @intCast(@max(0, t.cur_row)), .col = @intCast(@max(0, t.cur_col)) }); + // every insert-mode edit happens at the cursor: an insertion there, or + // a deletion that ends there (backward) or starts there (forward) + if (key.cp == Key.enter) { + // helix insert_newline: an appending range stretches by what the + // cursor moved, any other slides by it + const d = @as(isize, @intCast(c2)) - @as(isize, @intCast(c)); + const head: usize = @intCast(@as(isize, @intCast(r.head)) + d); + const anchor: usize = if (c > r.anchor) r.anchor else @intCast(@as(isize, @intCast(r.anchor)) + d); + return setInsertRange(t, new, .{ .anchor = anchor, .head = head }, explicit); + } + var at: usize = c; + var del: usize = 0; + var ins: usize = 0; + if (new.len > old_len and c2 == c + (new.len - old_len)) { + ins = new.len - old_len; + } else if (new.len < old_len and c2 + (old_len - new.len) == c) { + at = c2; + del = old_len - new.len; + } else if (new.len < old_len and c2 == c) { + del = old_len - new.len; + } else if (new.len != old_len or c2 != c) { + return; // a motion: the range collapses onto the cursor (helix) + } + // helix Assoc: the head sticks after an insertion at it when the range + // points backward or is empty, the anchor when it points forward + const fwd = r.anchor < r.head; + setInsertRange(t, new, .{ + .anchor = mapThroughEdit(r.anchor, at, del, ins, !fwd and r.anchor != r.head), + .head = mapThroughEdit(r.head, at, del, ins, fwd), + }, explicit); +} + +fn setInsertRange(t: *Text, new: []const u8, mapped: modal.Selection, explicit: bool) void { + const cells = Text.rangeCells(new, mapped); + const cc = modal.positionAt(new, cells.cur); + const ac = modal.positionAt(new, cells.anc); + t.cur_row = @intCast(cc.row); + t.cur_col = @intCast(cc.col); + t.vsel = .{ .active = cells.anc != cells.cur, .row = @intCast(ac.row), .col = @intCast(ac.col), .explicit = explicit }; +} + +/// A position through one edit at `at` that deleted `del` bytes and put +/// `ins` in (one of the two is 0). A position exactly at an insertion stays +/// before it when `before` is set, else moves past it. +fn mapThroughEdit(pos: usize, at: usize, del: usize, ins: usize, before: bool) usize { + if (pos < at) return pos; + if (del > 0) return if (pos < at + del) at else pos - del; + if (pos == at and before) return pos; + return pos + ins; +} + +fn insertEdit(p: *Pardes, t: *Text, key: Key) void { t.vsel.active = false; if (!t.cur_pinned) pinPaneCursor(p, t); _ = clampFileCursor(t); @@ -748,12 +808,29 @@ pub fn insertKey(p: *Pardes, t: *Text, key: Key) void { switch (key.cp) { Key.enter => { const line = modal.lineSlice(text, c.row); + const before = line[0..@min(c.col, line.len)]; + // helix insert_newline: after nothing but blanks, the line + // itself moves down, blanks and all; else the blanks before the + // cursor go and the new line takes the indent + if (std.mem.indexOfNone(u8, before, " \t") == null) { + const new = modal.insertAt(p.gpa, text, .{ .row = c.row, .col = 0 }, "\n") catch return; + setEditText(p, t, new); + t.cur_row += 1; + t.cur_pinned = true; + t.show(); + return; + } const indent = modal.newlineIndentWidth(line, c.col); const arena = p.scratch.allocator(); const block = arena.alloc(u8, 1 + indent) catch return; block[0] = '\n'; @memset(block[1..], ' '); - const new = modal.insertAt(p.gpa, text, c, block) catch return; + // a tag keeps its blanks: they part its words, and the last + // may be its read-only prefix's + const kept = if (t.what == .body) std.mem.trimEnd(u8, before, " \t").len else c.col; + const cut = modal.deleteSpan(p.gpa, text, .{ .row = c.row, .col = kept }, c) catch return; + defer p.gpa.free(cut); + const new = modal.insertAt(p.gpa, cut, .{ .row = c.row, .col = kept }, block) catch return; setEditText(p, t, new); t.cur_row += 1; t.cur_col = @intCast(indent); diff --git a/src/look.zig b/src/look.zig index 5e2d6068..30fb0dab 100644 --- a/src/look.zig +++ b/src/look.zig @@ -1016,7 +1016,7 @@ pub fn clearNavigationSelection(p: *Pardes, pane: *Pane) void { pane.body.nsel = 0; pane.body.select = false; pane.body.normal.clear(); - pane.body.append_at = null; + pane.body.restore_cursor = false; pane.body.sticky_col = -1; for (0..pane.sel.len) |slot| pane.clearPointerSelection(slot); pane.sel = @splat(.{}); diff --git a/src/mouse.zig b/src/mouse.zig index 91ec41a6..d1c32b40 100644 --- a/src/mouse.zig +++ b/src/mouse.zig @@ -747,7 +747,7 @@ fn mirrorTtySelection(p: *Pardes, pane: *Pane) void { pane.body.vsel.active = false; pane.body.nsel = 0; pane.body.select = false; - pane.body.append_at = null; + pane.body.restore_cursor = false; pane.body.sticky_col = -1; pane.body.normal.clear(); edit.setYank(p, text); @@ -859,7 +859,7 @@ fn dragRelease(p: *Pardes, button: Mouse.Button) void { pane.body.vsel.active = false; pane.body.nsel = 0; // a click says WHERE the one cursor is pane.body.select = false; - pane.body.append_at = null; + pane.body.restore_cursor = false; pane.body.sticky_col = -1; if (s.ctrl) p.lspRequest(s.id, .definition, ""); } diff --git a/src/normal.zig b/src/normal.zig index f5e868a4..53e416fd 100644 --- a/src/normal.zig +++ b/src/normal.zig @@ -149,7 +149,7 @@ const KeyState = struct { normal: modal.Normal.State, find_op: u8, find_ch: u21, - append_at: @FieldType(Text, "append_at"), + restore_cursor: bool, reg_wait: bool, fn of(t: *Text) KeyState { @@ -159,7 +159,7 @@ const KeyState = struct { .normal = t.normal, .find_op = t.find_op, .find_ch = t.find_ch, - .append_at = t.append_at, + .restore_cursor = t.restore_cursor, .reg_wait = t.reg_wait, }; } @@ -170,7 +170,7 @@ const KeyState = struct { t.normal = s.normal; t.find_op = s.find_op; t.find_ch = s.find_ch; - t.append_at = s.append_at; + t.restore_cursor = s.restore_cursor; t.reg_wait = s.reg_wait; } }; diff --git a/src/tagline.zig b/src/tagline.zig index 14bf5677..1c060a66 100644 --- a/src/tagline.zig +++ b/src/tagline.zig @@ -219,7 +219,7 @@ pub fn enterTag(p: *Pardes, pane: *Pane) void { t.msel.active = false; t.nsel = 0; t.select = false; - t.append_at = null; + t.restore_cursor = false; t.sticky_col = -1; t.mode = .normal; t.normal.clear(); @@ -325,7 +325,7 @@ pub fn enterHeader(p: *Pardes, column: ?usize) void { t.msel.active = false; t.nsel = 0; t.select = false; - t.append_at = null; + t.restore_cursor = false; t.mode = .normal; t.normal.clear(); } diff --git a/test/hxcases/cases.jsonl b/test/hxcases/cases.jsonl index 7ba44f09..ba75c611 100644 --- a/test/hxcases/cases.jsonl +++ b/test/hxcases/cases.jsonl @@ -344,6 +344,21 @@ {"name": "i-keeps-sel-start", "pane": "file", "text": "alpha beta\n", "keys": "wi"} {"name": "wa-sel-end", "pane": "file", "text": "alpha beta\n", "keys": "wa"} {"name": "wiX-edit-drops-sel", "pane": "file", "text": "alpha beta\n", "keys": "wiX"} +{"name": "reg-selection-insert", "pane": "file", "text": "ab\n", "keys": "vli."} +{"name": "ins-sel-backspace", "pane": "file", "text": "alpha beta\n", "keys": "wi"} +{"name": "ins-append-enter", "pane": "file", "text": "ab cd\n", "keys": "wax"} +{"name": "ins-append-backspace", "pane": "file", "text": "ab cd\n", "keys": "ea"} +{"name": "ins-sel-delete", "pane": "file", "text": "ab cd\n", "keys": "wi"} +{"name": "ins-sel-arrow-collapses", "pane": "file", "text": "ab cd\n", "keys": "wi"} +{"name": "msel-insert-keeps-ranges", "pane": "file", "text": "ab cd\nab cd\n", "keys": "wCiX"} +{"name": "msel-append-lines", "pane": "file", "text": "aa\nbb\n", "keys": "%a!"} +{"name": "ins-append-bare", "pane": "file", "text": "ab\n", "keys": "axy"} +{"name": "ins-change-then-type", "pane": "file", "text": "ab cd\n", "keys": "wcX"} +{"name": "ins-open-below-sel", "pane": "file", "text": "ab\ncd\n", "keys": "xoX"} +{"name": "ins-enter-trims-blanks", "pane": "file", "text": "ab cd\n", "keys": "5li"} +{"name": "ins-enter-in-indent", "pane": "file", "text": " ab\n", "keys": "2li"} +{"name": "ins-enter-after-open", "pane": "file", "text": " ab\n", "keys": "ox"} +{"name": "msel-ins-enter", "pane": "file", "text": "ab cd\nab cd\n", "keys": "wCa"} {"name": "a-esc-restore", "pane": "file", "text": "abc\n", "keys": "a"} {"name": "ax-restore", "pane": "file", "text": "abc\n", "keys": "ax"} {"name": "lax-restore", "pane": "file", "text": "abc\n", "keys": "lax"} diff --git a/test/hxcases/goldens.jsonl b/test/hxcases/goldens.jsonl index f6a6aada..188b7ce4 100644 --- a/test/hxcases/goldens.jsonl +++ b/test/hxcases/goldens.jsonl @@ -344,6 +344,21 @@ {"name":"i-keeps-sel-start","text":"alpha beta\n","mode":"insert","cursor":{"row":0,"col":0},"anchor":{"row":0,"col":5}} {"name":"wa-sel-end","text":"alpha beta\n","mode":"insert","cursor":{"row":0,"col":6},"anchor":{"row":0,"col":0}} {"name":"wiX-edit-drops-sel","text":"Xalpha beta\n","mode":"normal","cursor":{"row":0,"col":1},"anchor":{"row":0,"col":6}} +{"name":"reg-selection-insert","text":"abab\n","mode":"normal","cursor":{"row":0,"col":2},"anchor":{"row":0,"col":3}} +{"name":"ins-sel-backspace","text":"alpha beta\n","mode":"normal","cursor":{"row":0,"col":0},"anchor":{"row":0,"col":5}} +{"name":"ins-append-enter","text":"ab\nxcd\n","mode":"normal","cursor":{"row":1,"col":0},"anchor":{"row":0,"col":0}} +{"name":"ins-append-backspace","text":" cd\n","mode":"normal","cursor":{"row":0,"col":0},"anchor":{"row":0,"col":0}} +{"name":"ins-sel-delete","text":"b cd\n","mode":"normal","cursor":{"row":0,"col":0},"anchor":{"row":0,"col":1}} +{"name":"ins-sel-arrow-collapses","text":"ab cd\n","mode":"normal","cursor":{"row":0,"col":1},"anchor":{"row":0,"col":1}} +{"name":"msel-insert-keeps-ranges","text":"Xab cd\nXab cd\n","mode":"normal","cursor":{"row":1,"col":1},"anchor":{"row":1,"col":3},"sels":[{"cursor":{"row":0,"col":1},"anchor":{"row":0,"col":3}},{"cursor":{"row":1,"col":1},"anchor":{"row":1,"col":3}}],"primary":1} +{"name":"msel-append-lines","text":"aa!\nbb!\n","mode":"normal","cursor":{"row":0,"col":2},"anchor":{"row":0,"col":0},"sels":[{"cursor":{"row":0,"col":2},"anchor":{"row":0,"col":0}},{"cursor":{"row":1,"col":2},"anchor":{"row":1,"col":0}}],"primary":0} +{"name":"ins-append-bare","text":"axyb\n","mode":"normal","cursor":{"row":0,"col":2},"anchor":{"row":0,"col":0}} +{"name":"ins-change-then-type","text":"Xcd\n","mode":"normal","cursor":{"row":0,"col":1},"anchor":{"row":0,"col":1}} +{"name":"ins-open-below-sel","text":"ab\nX\ncd\n","mode":"normal","cursor":{"row":1,"col":1},"anchor":{"row":1,"col":1}} +{"name":"ins-enter-trims-blanks","text":"ab\ncd\n","mode":"normal","cursor":{"row":1,"col":0},"anchor":{"row":1,"col":0}} +{"name":"ins-enter-in-indent","text":"\n ab\n","mode":"normal","cursor":{"row":1,"col":2},"anchor":{"row":1,"col":2}} +{"name":"ins-enter-after-open","text":" ab\n\n x\n","mode":"normal","cursor":{"row":2,"col":5},"anchor":{"row":2,"col":5}} +{"name":"msel-ins-enter","text":"ab\ncd\nab\ncd\n","mode":"normal","cursor":{"row":2,"col":2},"anchor":{"row":2,"col":0},"sels":[{"cursor":{"row":0,"col":2},"anchor":{"row":0,"col":0}},{"cursor":{"row":2,"col":2},"anchor":{"row":2,"col":0}}],"primary":1} {"name":"a-esc-restore","text":"abc\n","mode":"normal","cursor":{"row":0,"col":0},"anchor":{"row":0,"col":0}} {"name":"ax-restore","text":"axbc\n","mode":"normal","cursor":{"row":0,"col":1},"anchor":{"row":0,"col":0}} {"name":"lax-restore","text":"abxc\n","mode":"normal","cursor":{"row":0,"col":2},"anchor":{"row":0,"col":1}} diff --git a/test/hxcases/waivers.jsonl b/test/hxcases/waivers.jsonl index 8ac3bd9c..2d74e346 100644 --- a/test/hxcases/waivers.jsonl +++ b/test/hxcases/waivers.jsonl @@ -1,3 +1 @@ -{"name":"wiX-edit-drops-sel","reason":"Insert edits clear the selection instead of tracking its anchor.","reference":{"name":"wiX-edit-drops-sel","text":"Xalpha beta\n","mode":"normal","cursor":{"row":0,"col":1},"anchor":{"row":0,"col":6}},"expected":{"name":"wiX-edit-drops-sel","text":"Xalpha beta\n","mode":"normal","cursor":{"row":0,"col":1},"anchor":{"row":0,"col":1}}} {"name":"alt-c-window-op","reason":"Alt-c moves a pane to a new column instead of Helix's change-noyank.","reference":{"name":"alt-c-window-op","text":"bc def\n","mode":"insert","cursor":{"row":0,"col":0},"anchor":{"row":0,"col":0}},"expected":{"name":"alt-c-window-op","text":"abc def\n","mode":"normal","cursor":{"row":0,"col":0},"anchor":{"row":0,"col":0}}} -{"name":"msel-append","reason":"Append-mode selection origins are tracked only for the primary selection.","reference":{"name":"msel-append","text":"aza\nbzb\n","mode":"normal","cursor":{"row":1,"col":1},"anchor":{"row":1,"col":0},"sels":[{"cursor":{"row":0,"col":1},"anchor":{"row":0,"col":0}},{"cursor":{"row":1,"col":1},"anchor":{"row":1,"col":0}}],"primary":1},"expected":{"name":"msel-append","text":"aza\nbzb\n","mode":"normal","cursor":{"row":1,"col":1},"anchor":{"row":1,"col":0},"sels":[{"cursor":{"row":0,"col":1},"anchor":{"row":0,"col":1}},{"cursor":{"row":1,"col":1},"anchor":{"row":1,"col":0}}],"primary":1}} diff --git a/test/mode.zig b/test/mode.zig index c7d7d548..cba93c30 100644 --- a/test/mode.zig +++ b/test/mode.zig @@ -79,14 +79,14 @@ test "Mode from actual tag Exec preserves parked file and output insert transact p.update(.{ .key = .{ .cp = pardes.Key.tab } }); try std.testing.expectEqual(panes.Text.Mode.normal, pane.body.mode); try std.testing.expect(pane.focus == .body); - try std.testing.expect(pane.body.append_at == null); + try std.testing.expect(!pane.body.restore_cursor); p.update(.{ .key = .{ .cp = 'u' } }); try std.testing.expectEqualStrings("ab\n", pane.file.?.content); p.update(.{ .key = .{ .cp = 'a' } }); p.update(.{ .key = .{ .cp = 'z', .text = "z" } }); - try std.testing.expect(pane.body.append_at != null); + try std.testing.expect(pane.body.restore_cursor); try mode(p, 0, .normal); - try std.testing.expect(pane.body.append_at == null); + try std.testing.expect(!pane.body.restore_cursor); p.update(.{ .key = .{ .cp = 'u' } }); try std.testing.expectEqualStrings("ab\n", pane.file.?.content); } diff --git a/test/panes.zig b/test/panes.zig index cbf9d097..4e98f449 100644 --- a/test/panes.zig +++ b/test/panes.zig @@ -4547,7 +4547,7 @@ const LookResetTests = struct { pane.body.nsel = 1; pane.body.select = true; pane.body.normal.count = 5; - pane.body.append_at = .{ .row = 0, .col = 3 }; + pane.body.restore_cursor = true; pane.body.sticky_col = 7; for (0..pane.sel.len) |slot| { pane.clearPointerSelection(slot); @@ -4567,7 +4567,7 @@ const LookResetTests = struct { try std.testing.expectEqual(@as(u8, 0), pane.body.nsel); try std.testing.expect(!pane.body.select); try std.testing.expectEqual(modal.Normal.State{}, pane.body.normal); - try std.testing.expect(pane.body.append_at == null); + try std.testing.expect(!pane.body.restore_cursor); try std.testing.expectEqual(@as(i32, -1), pane.body.sticky_col); for (pane.sel) |selection| try std.testing.expectEqual(.none, selection.state); for (pane.pointer_selections) |selection| try std.testing.expect(selection == null); diff --git a/transactions.txt b/transactions.txt index 6c2e7646..8d2fda3f 100644 --- a/transactions.txt +++ b/transactions.txt @@ -1,13 +1,8 @@ -Selection anchors through insert-mode edits, and the transaction model -======================================================================= - -STATUS: still open. `wiX-edit-drops-sel` is line 1 of test/hxcases/waivers.jsonl, -so the gap below describes the code as it stands rather than something already -fixed. One correction to the sentence that follows: it is not quite "the one -place". Line 3 of the same file, `msel-append`, says in its own words "Same -family as wiX-edit-drops-sel: pardes does not map selections through insert-mode -edits" — so the gap has two waivers, and what is singular is the CAUSE below, -not the number of divergences it produces. +STATUS: closed for the waivers. Insert mode now carries every range through +each edit (edit.insertKey maps the range with helix's Range::map rules after +the edit is made), so `wiX-edit-drops-sel` and `msel-append` are gone. What +follows is the original analysis; the delta layer it proposes was not needed +for that and stays unbuilt. The one place the helix differential suite shows a real structural gap (waiver "wiX-edit-drops-sel" in test/hxcases/waivers.jsonl): helix keeps a -- cgit v1.3 From b8c5e8772e646fa21f6afdd2a875a1bd52848bd5 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Mon, 28 Sep 2026 18:53:37 -0300 Subject: A column can be empty, as acme's can; new panes go where acme's makenewwindow puts them Newcol makes an empty column; closing a column's last pane leaves it empty with the keyboard on its tag; Delcol and Joincol alone take a column away; the session's last pane closing quits. The +New stand-in and replaceStillborn / stillborn_joiner are gone. Every new pane goes through exec.placeNew, which follows acme's makenewwindow (active column, empty column whole, blank space, halving the biggest) or, with Placement pardes, the old rules. ColumnTags is gone: column tags are always shown. A grip drag shows acme's box cursor. Co-Authored-By: Claude Opus 5.5 --- .agents/skills/pardes-9p/SKILL.md | 9 +- docs/config.md | 8 +- docs/fs.md | 9 +- docs/helix-keys.md | 2 +- docs/tags.md | 68 +++++- docs/ui-review.md | 3 +- src/CHANGELOG.md | 16 ++ src/Mini.zig | 2 +- src/Output.zig | 10 +- src/builtins.zig | 25 +- src/config.zig | 24 +- src/draw.zig | 7 +- src/dump.zig | 17 +- src/exec.zig | 160 ++++++++----- src/fs-help.txt | 8 +- src/gui/gui.zig | 30 ++- src/layout.zig | 238 ++++++++++++++----- src/look.zig | 17 +- src/mouse.zig | 11 +- src/ninep/ctl.zig | 19 +- src/ninep/pane.zig | 4 +- src/ninep/tree.zig | 2 +- src/pardes.zig | 459 ++++++++++++++++++++++++------------- src/pdf_view.zig | 2 +- src/surface.zig | 4 +- src/tagline.zig | 1 + src/web/app.mjs | 3 +- test/appearance_gallery.py | 4 +- test/column_drag.zig | 5 - test/column_tags.py | 5 +- test/gui-goldens.txt | 13 +- test/gui_golden.py | 5 +- test/panes.zig | 1 - test/pdf.zig | 2 +- test/snapshots/argv.snap | 2 + test/snapshots/builtins.snap | 2 + test/snapshots/chordcut.snap | 2 + test/snapshots/cmdword.snap | 2 + test/snapshots/delask.snap | 2 + test/snapshots/doccol.snap | 2 + test/snapshots/emptycol.golden | 14 ++ test/snapshots/emptycol.snap | 22 ++ test/snapshots/filewatch.snap | 2 + test/snapshots/find.snap | 2 + test/snapshots/fsearch.snap | 2 + test/snapshots/grep.snap | 2 + test/snapshots/jumps.snap | 2 + test/snapshots/layout-close.golden | 5 +- test/snapshots/layout-close.snap | 8 +- test/snapshots/layout-open.snap | 2 + test/snapshots/leader.snap | 2 + test/snapshots/lookpanes.snap | 2 + test/snapshots/lookrange.snap | 2 + test/snapshots/lsp-client.snap | 2 + test/snapshots/lsp.snap | 2 + test/snapshots/lspcomplete.snap | 2 + test/snapshots/lsprelpath.snap | 2 + test/snapshots/mini.snap | 2 + test/snapshots/nested.snap | 2 + test/snapshots/psearch.snap | 2 + test/snapshots/reflow.snap | 2 + test/snapshots/rsearch.snap | 2 + test/snapshots/savepane.snap | 2 + test/snapshots/scrolloff.snap | 2 + test/snapshots/splitparent.snap | 2 + test/snapshots/stepgrain.snap | 2 + test/snapshots/tagalign.snap | 2 + test/snapshots/tagalign2col.snap | 2 + test/snapshots/tagbottom.snap | 2 + test/snapshots/tagnav.snap | 2 + test/snapshots/themesel.snap | 2 + test/snapshots/tinywin.snap | 2 + test/snapshots/topbarexec.snap | 2 + test/snapshots/ttyhelp.snap | 2 + test/snapshots/ttylook.snap | 2 + test/snapshots/ttyonly.snap | 2 + test/snapshots/ttytaken.snap | 2 + test/snapshots/windownav.snap | 2 + 78 files changed, 934 insertions(+), 388 deletions(-) create mode 100644 test/snapshots/emptycol.golden create mode 100644 test/snapshots/emptycol.snap (limited to 'src/Output.zig') diff --git a/.agents/skills/pardes-9p/SKILL.md b/.agents/skills/pardes-9p/SKILL.md index 757ce64a..9473974c 100644 --- a/.agents/skills/pardes-9p/SKILL.md +++ b/.agents/skills/pardes-9p/SKILL.md @@ -68,7 +68,7 @@ $m/listeners this session's dial addresses $m/focus the serial of the pane with the keyboard (empty while a column/workspace tag has it); echo a serial into it to move the keyboard (a folded pane stays folded) $m/ctl the settings, one a line as a write takes them; write a setting or a session builtin - (Newcol, Dump, Theme x; Exit QUITS the editor, Kill [word...] stops the + (Newcol makes an empty column, Dump, Theme x; Exit QUITS the editor, Kill [word...] stops the commands pardes started (command panes, lines it typed into shells), a word matching a command line's first word; Exit and Restore refuse once, naming every unsaved pane, `, : Modified (Exit again to discard them all)`, and the same @@ -78,8 +78,11 @@ $m/ctl the settings, one a line as a write takes them; write a setting or a pane's builtins (Del, Save f, Collapse, which folds that pane, and the column word Delcol, which closes that pane's column) go to $m/pane//ctl $m/commands every builtin: `Word`, `Word arg`, then `root` or `pane` (which ctl takes it) -$m/pane/new open it to make a pane (a scratch named /+New), read names it; - rmdir $m/pane/ closes it; closing a column's last pane leaves a +New there +$m/pane/new open it to make a pane (a scratch named /+New), read names it; it goes in + the ACTIVE column (the one last typed or clicked in, or Newcol's), filling it if + empty, else taking the bottom half of its last pane (ctl `Placement pardes`: the old rules); + rmdir $m/pane/ closes it; a column's last pane leaves the column EMPTY + (focus reads empty, the log says only del), and the session's LAST pane QUITS it $m/pane//errors write-only: text appended to the +Errors pane of the pane's directory $m/os/ the host filesystem ``` diff --git a/docs/config.md b/docs/config.md index 16fd59e5..77ed68e7 100644 --- a/docs/config.md +++ b/docs/config.md @@ -111,9 +111,11 @@ themes and all imported names remain available. `FocusTint` toggles the focused pane and column tag tints; it is on by default. Workspace, column and pane command text can be edited directly; see [editable tags](tags.md) for naming and saved-workspace behavior. -`ColumnTags` toggles the column command row in both GUI and TTY; it is on by -default. Add `ColumnTags` to startup configuration to reclaim that row on a -compact screen. Hiding it preserves your custom column commands. +The column command row is always shown; an old `ColumnTags` init line is +ignored with a message. +`Placement acme` (the default) puts new panes where acme would, in the active +column; `Placement pardes` brings back pardes's own rules, which open a first +document in a column of its own. See [where new panes go](tags.md#where-new-panes-go). `Verbose` toggles the message-row announcement every builtin makes of its own name before it runs; it is on by default, and the builtins that own the message row themselves (`Msg`) never announce. Turning it off leaves the row to the diff --git a/docs/fs.md b/docs/fs.md index 98a8638d..eaaedf02 100644 --- a/docs/fs.md +++ b/docs/fs.md @@ -69,8 +69,13 @@ for any process, and `$NINE_MOUNT/pardes/NAME/` a `--detach=NAME` session's. 9ns exports `$NINE_MOUNT` to everything it starts, so a script checks that variable to know the mount is there, and takes the name from `$PARDES_9P` (`pardes-9p-.sock`). A new pane made through `pane/new` is a scratch named -`/+New` until it is given a name, and closing a column's last pane -leaves such a `+New` in its place (`Delcol` closes the column). +`/+New` until it is given a name. A column may hold no pane, as in acme: +`Newcol` makes one empty, and closing a column's last pane leaves it empty +with its tag holding the keyboard (`focus` reads empty) and logs only the +`del`. `pane/new` places its pane as acme's makenewwindow(nil) does: in the +active column, filling it when it is empty, else taking the bottom half of its +last pane ([where new panes go](tags.md#where-new-panes-go)). `Delcol` closes the column. Closing the +session's last pane quits pardes; see [tags](tags.md#empty-columns). For [Linux v9fs](https://www.kernel.org/doc/html/latest/filesystems/9p.html), use `version=9p2000,cache=none,access=any` and `trans=unix`, or `trans=tcp` diff --git a/docs/helix-keys.md b/docs/helix-keys.md index c703a3da..8874bf08 100644 --- a/docs/helix-keys.md +++ b/docs/helix-keys.md @@ -127,7 +127,7 @@ language-backend queries, and the shell pipe. | `Enter` (normal) | acme **look** chord: EXPLICIT selection, else file-ish word under cursor | pardes-specific, keep (helix normal-mode Enter unbound). Covers helix `gf`. Implicit motion residue falls back to the cursor word | pardes-specific | | `Tab` (normal) | acme **execute** chord | pardes-specific, keep; explicit-selection rule as Enter | pardes-specific | | `:` (normal, body or tag) | in the body, focuses the pane's tag in normal mode at its remembered cursor (the first time, on `Save`); in the tag, goes back to the body; in a column or workspace tag, back to the active pane. The tag's normal and insert modes ARE the body's: every motion, selection, edit and undo works there, and `0` goes to the line's start, the path's. Tab runs the word under the cursor or the selection and Enter looks it up (in a column or workspace tag Enter runs it too), and either hands the keyboard back to the body first. Clicks choose a new cursor position and type into the tag. | Each tag keeps its own cursor during the session. The computed path/marker/page is reachable and yankable but read-only: an edit into it is refused, and typing into a file's path drafts a new name. File-name changes are staged as described in [editable tags](tags.md). | pardes-specific | -| `Ctrl-w k` / `SPC w k` (pane with nothing above) | focuses its column's tag, then the workspace tag; with `ColumnTags` disabled it goes directly to the workspace. `Ctrl-w j` walks back to the panes, `Ctrl-w h`/`l` walk the column tags. Headers edit exactly as a pane tag does. | Column commands target that column's active pane, or its first pane when coming from elsewhere. Workspace and column text are independently editable and persist in dumps. See [editable tags](tags.md). | pardes-specific | +| `Ctrl-w k` / `SPC w k` (pane with nothing above) | focuses its column's tag, then the workspace tag. `Ctrl-w j` walks back to the panes, `Ctrl-w h`/`l` walk the column tags. Headers edit exactly as a pane tag does. | Column commands target that column's active pane, or its first pane when coming from elsewhere. Workspace and column text are independently editable and persist in dumps. See [editable tags](tags.md). | pardes-specific | | `Ctrl-w` + `h/j/k/l`/arrows | directional pane focus prefix — editor normal mode only | pardes' own window handling (helix window mode skipped, section C). Runs the SAME `Left`/`Down`/`Up`/`Right` builtins `SPC w h/j/k/l` runs; Raw **tty** mode forwards Ctrl-w to the child. Insert mode owns `Ctrl-w` = delete-word-back, so a tag being TYPED into swallows it; from a tag in normal mode it moves focus to the neighbour's BODY, as from a body, and from the top pane `Up` reaches the column and workspace tags | pardes-specific | | `Alt-n` | new terminal below (outside raw tty) | shadows helix `Alt-n` (select next sibling), which pardes spells `Alt-right` alone | pardes-specific | | `Alt-c` | move active terminal to a fresh column (outside raw tty) | helix `Alt-c` is change-noyank; the pardes window op wins (do-not-touch contract). `Alt-d` + `i` covers the behavior | waived (`alt-c-window-op`) | diff --git a/docs/tags.md b/docs/tags.md index fdea1472..7787d7f1 100644 --- a/docs/tags.md +++ b/docs/tags.md @@ -1,8 +1,9 @@ # Editable tags Pardes has three levels of command text: the workspace tag, one tag per -column, and each pane's tag. Column commands run in that column's active -pane (or its first pane when focus comes from another column). This makes +column, and each pane's tag. Column commands act on that column and run in +its active pane (or its first pane when focus comes from another column); a +column with no pane is described under [empty columns](#empty-columns). This makes `New`, `Tty`, `Find`, and `Grep` available beside the work they act on. `New` appears only in the column tag by default; pane tags keep their own save, terminal, close, and collapse commands. `Tty` opens a new embedded terminal. @@ -152,7 +153,7 @@ upgrade to `Mode`; customized command text is preserved. ## Saved workspaces `Dump` and `Restore` preserve customized workspace and column tags, including -intentionally empty tags. New columns start with the standard column tag. +intentionally empty tags, and columns that hold no pane. New columns start with the standard column tag. Closing a column keeps surviving columns' tags; `Joincol` keeps the destination column's tag. Old dumps without these optional fields retain the defaults. The automatic `Restore` shortcut does not overwrite a customized workspace @@ -163,7 +164,66 @@ than three rows it is omitted so a pane still has room. SDL and TTY share the same tag text, editing and layout; SDL additionally uses compact font sizing and subtle pixel separators. -`ColumnTags` toggles the column row (on by default) without deleting its text. +The column row is always shown. An old `ColumnTags` line in an init file is +ignored, with a message saying so. `FocusTint` controls active-column and active-pane emphasis. SDL also honors the shared bold, underline, and strikethrough attributes, including diagnostic underlines and the optional `SyntaxBold` keyword weight. + +## Empty columns + +A column can hold no pane, as acme's can: its tag stands over blank space, the +frame's own fill, where acme paints white (cols.c:186-188). `Newcol` makes an +empty column right of the keyboard's and gives its tag the keyboard. Closing a +column's last pane (`Del`, `Del k`/`Del j`, a shell exiting, a drag to another +column) leaves the column empty where it was, and the keyboard goes to its tag +if it was on that pane. Only `Delcol` and `Joincol` take a column away. + +`Delcol` and `Joincol` from a column's tag act on that column; `Delcol` +written to a pane's ctl closes that pane's column. A pane dragged onto an +empty column fills it. + +## Where new panes go + +Every new pane goes through one placement, chosen by the `Placement` setting: +`acme` (the default) or `pardes`. `Placement pardes` or `Placement acme` sets +it, in an init file, a tag or the root ctl; bare `Placement` flips it; `SPC c +p` is its leader path, and `Config` reports it. + +`Placement acme` is acme's makenewwindow (util.c:449-495). The core keeps +acme's *active column* (activecol, dat.c:37): the column last typed in +(acme.c:487), clicked in with the select button (acme.c:659), dropped into by +a grip (acme.c:640), whose tag was given the keyboard (`Newcol`, an emptied +column, `Ctrl-w k`), or that was given the last new pane (util.c:467). A Look +click moves the keyboard but not the active column, as button 3 does not in +acme. A new pane goes into the column a command's tag belongs to when it came +from a column tag, else the active column, else the keyboard's pane's, and +never into a new column: + +- an empty column it takes whole (util.c:468-469); +- from a tag, or 9P's `pane/new` (acme's `t->w == nil`), it takes the bottom + half of the column's last pane (coladd, cols.c:62-65); +- from a pane's text (a Look, `Tty`, `Alt-n`, a Grep or Find listing), it goes + right under the text of the pane with the most blank rows when that is more + than 15 rows, or more than 3 and more than half the biggest pane + (util.c:482-486); otherwise it halves the biggest pane, or the asking pane + when that is in the column and not much smaller (util.c:487-491); +- `New` goes into its own column, the bottom half of its last pane + (look.c:921-923); +- a command pane or a `+Errors` pane goes to the last column, the bottom + half of its last pane (util.c:94-98). + +`Placement pardes` is what pardes did before: an empty column whose tag asked, +or has the keyboard, is filled; a scratch goes right under the pane that asked; +a shell under it or the nearest pane with room; a document beside the last one +read, or in a column of its own on the left when there is none and the column +is at least 200 cells wide; a command pane at the foot of the last column. + +Down from an empty column's tag stays there, and the pane-to-pane keys pass +over an empty column; Left and Right from a tag walk every column's tag. + +One divergence from acme: acme keeps running when its last window closes, +every column empty. Pardes quits when the session's last pane closes, as +`Delcol` of the last column always has. A key, a prompt or a command in +pardes runs in a pane, so a session without one would have nothing to run +them in. diff --git a/docs/ui-review.md b/docs/ui-review.md index 58a42e61..1180a20e 100644 --- a/docs/ui-review.md +++ b/docs/ui-review.md @@ -98,8 +98,7 @@ tests and 797 SDL tests; SDL image/PDF and Kitty PDF rendering harnesses pass. ## Column and editable-tag follow-up The follow-up adds editable workspace and column command rows, compact pane -tags, staged buffer-name edits, caret reveal for long tags, and `ColumnTags` -to reclaim the extra row when needed. See [editable tags](tags.md) for the +tags, staged buffer-name edits, and caret reveal for long tags. See [editable tags](tags.md) for the exact interaction and save-target rules. `test/column_tags.py` exercises isolated SDL and TTY sessions against the same diff --git a/src/CHANGELOG.md b/src/CHANGELOG.md index f8451baf..874082d8 100644 --- a/src/CHANGELOG.md +++ b/src/CHANGELOG.md @@ -2,6 +2,22 @@ ## 0.0.3 +- A column can be empty, as in acme. `Newcol` makes an empty column and + gives its tag the keyboard; closing a column's last pane, or dragging it + away, leaves the column where it was with nothing in it, drawn as its tag + over blank space. The `+New` placeholder that used to stand in an emptied + column, and the machinery that swapped it out when something else arrived, + are gone. Closing the session's last pane now quits. +- New panes go where acme's makenewwindow puts them: into the active column + (the one last typed or clicked in), filling it when it is empty, else under + the text of a pane with room to spare, else halving the biggest pane; never + into a new column. `Placement pardes` brings back the old rules, which open a + first document in a column of its own. +- Column tags are always shown: the `ColumnTags` setting is gone, and an + init file's `ColumnTags` line is ignored with a message. +- Carrying a pane or a column by its grip shows acme's box cursor in the SDL + shell and a move cursor on the web. + - `Del` takes a side. `Del k` and `DelAbove` give the closed pane's rows to the expanded pane above it, `Del j` and `DelBelow` to the one below. A bare `Del` from the keyboard on a pane with panes both above and below asks on diff --git a/src/Mini.zig b/src/Mini.zig index e118e738..ac9a8e85 100644 --- a/src/Mini.zig +++ b/src/Mini.zig @@ -188,7 +188,7 @@ pub fn open(p: *Pardes, id: usize, argument: []const u8) !void { .syntax_dirty = false, }; pane.body.cur_pinned = true; - exec.placeDoc(p, id, free, pane); + exec.placeNew(p, id, id, free, .doc); p.active = free; } diff --git a/src/Output.zig b/src/Output.zig index 201b5491..2f462fd1 100644 --- a/src/Output.zig +++ b/src/Output.zig @@ -479,7 +479,7 @@ pub fn fillResults(p: *Pardes, id: usize, dir: []const u8, from: Origin, arg: [] const free = p.freeSlot() orelse return error.NoPaneSlots; const np = try open(p, free, dir, from, arg, result_content); np.file.?.location_rows = result_rows; - exec.placeDoc(p, id, free, np); + exec.placeNew(p, id, id, free, .doc); p.active = id; if (traits(from).steps) { pane.search_pane = free; @@ -558,8 +558,8 @@ fn openStepped(p: *Pardes, id: usize, from: Origin, content: []u8) !void { const pane = p.panes[id] orelse return error.MissingPane; const dir = if (pane.file) |f| (std.fs.path.dirname(f.path) orelse "/") else pane.cwdSlice(); const free = p.freeSlot() orelse return error.NoPaneSlots; - const np = try open(p, free, dir, from, "", content); - exec.placeDoc(p, id, free, np); + _ = try open(p, free, dir, from, "", content); + exec.placeNew(p, id, id, free, .doc); p.active = id; pane.search_pane = free; pane.search_row = null; @@ -777,7 +777,7 @@ fn openRead(p: *Pardes, id: usize, from: Origin, arg: []const u8, content: []u8) } const dir = if (pane.file) |f| (std.fs.path.dirname(f.path) orelse "/") else pane.cwdSlice(); const free = p.freeSlot() orelse return error.NoPaneSlots; - const np = try open(p, free, dir, from, arg, content); - exec.placeDoc(p, id, free, np); + _ = try open(p, free, dir, from, arg, content); + exec.placeNew(p, id, id, free, if (from == .errors) .errors else .doc); p.active = free; } diff --git a/src/builtins.zig b/src/builtins.zig index 72df0271..c2b4d62f 100644 --- a/src/builtins.zig +++ b/src/builtins.zig @@ -169,7 +169,7 @@ pub const registry = struct { inline for (comptime settingList(), manualBuiltinCount()..) |setting, i| if (@intFromEnum(b) == i) return switch (setting.action) { // a switch flips bare, and DumpDir bare is the default - .toggle, .transition, .scene, .dump_dir => false, + .toggle, .transition, .scene, .dump_dir, .placement => false, .shell, .theme, .font, .tagline_size, .window_opacity, .window_blur, .message_ms, .shader, .shader_animation => true, }; unreachable; @@ -818,11 +818,11 @@ pub const New = struct { } }; -/// The same empty scratch, opened in a fresh column beside the calling pane. +/// An empty column right of the keyboard's, its tag taking the keyboard. pub const Newcol = struct { pub const scope: Scope = .session; pub fn run(c: Ctx) void { - c.p.newScratchColumn(c.id); + c.p.newColumn(c.id); } }; @@ -937,7 +937,10 @@ pub const Collapse = struct { pub const Delcol = struct { pub fn run(c: Ctx) void { - c.p.removeColumn(c.id) catch |err| c.p.reportError(c.id, "close column", err); + // The column of the tag it came from, else the pane's: a pane ctl's + // Delcol closes that pane's column wherever the keyboard is. + const col = c.p.exec_column orelse (layout.findPane(c.p, c.id) orelse return).col; + c.p.removeColumn(col) catch |err| c.p.reportError(c.id, "close column", err); } }; @@ -1049,9 +1052,9 @@ pub const Joincol = struct { pub const scope: Scope = .session; pub fn run(c: Ctx) void { // The keyboard's column joins the one to its right; the last has none. - const at = layout.findPane(c.p, c.p.active) orelse return; - if (at.col + 1 >= c.p.ncol) return c.p.reportFailure(c.id, "Joincol: no column to the right"); - layout.joinCol(c.p); + const col = c.p.keyboardColumn(c.p.active) orelse return; + if (col + 1 >= c.p.ncol) return c.p.reportFailure(c.id, "Joincol: no column to the right"); + layout.joinCol(c.p, col); } }; @@ -1059,8 +1062,8 @@ pub const Tutor = struct { pub const scope: Scope = .session; pub fn run(c: Ctx) void { const free = c.p.freeSlot() orelse return; - const nt = c.p.openTutorView(free) catch return; - exec.placeDoc(c.p, c.id, free, nt); // a doc like any other + _ = c.p.openTutorView(free) catch return; + exec.placeNew(c.p, c.id, c.id, free, .doc); // a doc like any other } }; @@ -1221,8 +1224,10 @@ pub const Down = struct { return tagline.enterHeader(c.p, if (column) |at| at.col else 0); // Onto the top pane of the column the header stands over. const col = c.p.header_column orelse if (column) |at| at.col else return; + // An empty column's tag has nothing below it. + if (col < c.p.ncol and c.p.col_n[col] == 0) return; tagline.exitHeader(c.p); - if (col < c.p.ncol and c.p.col_n[col] > 0) c.p.active = c.p.col_panes[col][0]; + if (col < c.p.ncol) c.p.active = c.p.col_panes[col][0]; return; } _ = layout.focusDir(c.p, c.id, .down); diff --git a/src/config.zig b/src/config.zig index 2eaaa505..48f49d50 100644 --- a/src/config.zig +++ b/src/config.zig @@ -73,11 +73,11 @@ pub const leader_path = paths: { .Newcol = "cn", .Delcol = "cd", .Joincol = "cj", + .Placement = "cp", .Debug = "td", .Msg = null, .Colors = "tc", .FocusTint = null, - .ColumnTags = null, .SyntaxBold = null, .Verbose = null, .TreeContextTagStyle = null, @@ -616,7 +616,6 @@ pub const Runtime = struct { /// menu bar) turn it off and carry its commands there instead; the core /// keeps the row as the acme tradition everywhere else. workspace_tag: bool = true, - column_tags: bool = true, syntax_bold: bool = false, /// A font's programming ligatures (`->`, `!=`) draw across their cells. /// Only a shell that shapes text has the setting (`Capabilities.ligatures`). @@ -664,8 +663,12 @@ pub const Runtime = struct { /// never, while the window has the focus, or always (ghostty's /// custom-shader-animation). shader_animation: ShaderAnimation = .on, + /// Where a new pane goes (exec.placeNew): `acme`, acme's makenewwindow, + /// or `pardes`, the rules pardes had before it. + placement: Placement = .acme, pub const ShaderAnimation = enum { off, on, always }; + pub const Placement = enum { acme, pardes }; /// Each pass the bundled Crt or a Shadertoy file. pub const Post = struct { @@ -818,7 +821,7 @@ pub const Runtime = struct { /// The message timings a setting word sets, each in milliseconds. pub const MessageTime = enum { linger, fall, dissolve }; - pub const Toggle = enum { colors, wrap, tree_context_tag_style, tag_bottom, debug, focus_tint, column_tags, syntax_bold, verbose, message_animation, ligatures }; + pub const Toggle = enum { colors, wrap, tree_context_tag_style, tag_bottom, debug, focus_tint, syntax_bold, verbose, message_animation, ligatures }; /// The bundled post pass, a Shadertoy file in shaders/post/. pub const Scene = enum { crt }; @@ -838,6 +841,7 @@ pub const Runtime = struct { /// it of files. shader, shader_animation, + placement, }; pub const Setting = struct { @@ -861,7 +865,6 @@ pub const Runtime = struct { .{ .word = "Tagbottom", .action = .{ .toggle = .tag_bottom } }, .{ .word = "Debug", .action = .{ .toggle = .debug } }, .{ .word = "FocusTint", .action = .{ .toggle = .focus_tint } }, - .{ .word = "ColumnTags", .action = .{ .toggle = .column_tags } }, .{ .word = "SyntaxBold", .action = .{ .toggle = .syntax_bold } }, .{ .word = "Verbose", .action = .{ .toggle = .verbose } }, .{ .word = "MessageAnimation", .action = .{ .toggle = .message_animation } }, @@ -890,6 +893,7 @@ pub const Runtime = struct { .{ .word = "Crt", .action = .{ .scene = .crt }, .availability = .scene_shaders }, .{ .word = "Shader", .action = .shader, .availability = .scene_shaders }, .{ .word = "ShaderAnimation", .action = .shader_animation, .availability = .scene_shaders }, + .{ .word = "Placement", .action = .placement }, }; pub fn find(name: []const u8) ?Setting { @@ -1048,6 +1052,14 @@ pub const Runtime = struct { const text = std.mem.trim(u8, argument orelse return false, " \t\r\n"); state.shader_animation = std.meta.stringToEnum(ShaderAnimation, text) orelse return false; }, + // Bare, it flips between the two, as a tag word should. + .placement => { + const text = std.mem.trim(u8, argument orelse "", " \t\r\n"); + state.placement = if (text.len == 0) + (if (state.placement == .acme) .pardes else .acme) + else + std.meta.stringToEnum(Placement, text) orelse return false; + }, .theme, .font => return false, } return true; @@ -1217,6 +1229,7 @@ pub const Runtime = struct { try out.print("{s} {s}\n", .{ setting.word, @tagName(state.shader_animation) }) else try out.print("{s} unsupported\n", .{setting.word}), + .placement => try out.print("{s} {s}\n", .{ setting.word, @tagName(state.placement) }), }; if (context.startup_config_path) |path| @@ -1468,6 +1481,7 @@ pub const Runtime = struct { .dump_dir => "~/dumps", .shader => "~/crt.glsl", .shader_animation => "always", + .placement => "pardes", else => null, }; try std.testing.expect(apply(&state, setting, argument)); @@ -1483,7 +1497,6 @@ pub const Runtime = struct { .tag_bottom => "Tagbottom on\n", .debug => "Debug on\n", .focus_tint => "FocusTint off\n", - .column_tags => "ColumnTags off\n", .syntax_bold => "SyntaxBold on\n", .verbose => "Verbose off\n", .message_animation => "MessageAnimation off\n", @@ -1518,6 +1531,7 @@ pub const Runtime = struct { }, .shader => "Shader ~/crt.glsl\n", .shader_animation => "ShaderAnimation always\n", + .placement => "Placement pardes\n", .theme, .font => unreachable, }; try std.testing.expect(std.mem.indexOf(u8, report, expected) != null); diff --git a/src/draw.zig b/src/draw.zig index 2d757635..b12ab52c 100644 --- a/src/draw.zig +++ b/src/draw.zig @@ -163,6 +163,7 @@ pub fn render(p: *Pardes, arena: std.mem.Allocator) !*Surface { // the pointer per-text (the macOS I-beam) read this as "target" and // afford it the arrow instead. if (p.look_hover_preview != null) s.pointer_shape = .target; + if (p.drag == .move or p.drag == .column_move) s.pointer_shape = .box; for (&s.body_layers) |*layer| layer.rows = 0; for (&s.tag_layers) |*layer| layer.rows = 0; s.nimages = 0; @@ -974,14 +975,14 @@ test "place puts every part where the painters and layers put it, in every layou const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 30 }); defer p.deinit(); _ = try p.setTestFile("placed\n" ** 80); - p.newScratchColumn(0); + p.newColumn(0); + p.newScratchIn(0, p.activeColumn().?); p.newScratchBelow(0); p.sync(); var arena: std.heap.ArenaAllocator = .init(std.testing.allocator); defer arena.deinit(); for (0..16) |step| { p.settings.tag_bottom = step & 1 != 0; - p.settings.column_tags = step & 2 != 0; if (step & 4 != 0) try std.testing.expect(p.executeBuiltinLine(p.active, "Msg a placed notice")); if (step == 8) try std.testing.expect(p.executeBuiltinLine(1, "Collapse")); if (step == 12) try std.testing.expect(p.executeBuiltinLine(1, "Collapse")); @@ -1121,7 +1122,7 @@ test "a monkey over notices, prompts, tags and tiny panes at a gui's metrics nev var arena: std.heap.ArenaAllocator = .init(std.testing.allocator); defer arena.deinit(); const words = [_][]const u8{ "error:", "\u{754c}", "x", "Shader /tmp/a.glsl:", "e\u{301}", "\t", "long-" ** 20, " " }; - const commands = [_][]const u8{ "New", "Newcol", "Collapse", "Tagbottom", "ColumnTags", "TreeContext", "Wrap", "Find", "Del", "FocusTint", "Debug" }; + const commands = [_][]const u8{ "New", "Newcol", "Collapse", "Tagbottom", "TreeContext", "Wrap", "Find", "Del", "FocusTint", "Debug" }; var text: std.ArrayListUnmanaged(u8) = .empty; defer text.deinit(std.testing.allocator); for (0..steps) |_| { diff --git a/src/dump.zig b/src/dump.zig index 954a3270..8e669b77 100644 --- a/src/dump.zig +++ b/src/dump.zig @@ -217,7 +217,8 @@ pub fn validate(state: State) !void { } for (state.columns) |col| { if (!std.math.isFinite(col.weight) or col.weight <= 0) return error.BadDumpColumns; - if (col.panes.len == 0 or col.panes.len > max_panes) return error.BadDumpColumns; + // An empty column is a column, as in acme's dump (rows.c:639). + if (col.panes.len > max_panes) return error.BadDumpColumns; for (col.panes) |pane| { if (pane >= state.panes.len) return error.BadDumpPaneRef; } @@ -638,14 +639,12 @@ pub fn dumpState(p: *Pardes) !void { column_ids[c][ids_len] = compact; ids_len += 1; }; - if (ids_len > 0) { - columns[columns_len] = .{ - .tag = p.col_tags[c].own, - .weight = @as(f32, @floatFromInt(p.col_weight[c])) / @as(f32, @floatFromInt(column_weight_unit)), - .panes = column_ids[c][0..ids_len], - }; - columns_len += 1; - } + columns[columns_len] = .{ + .tag = p.col_tags[c].own, + .weight = @as(f32, @floatFromInt(p.col_weight[c])) / @as(f32, @floatFromInt(column_weight_unit)), + .panes = column_ids[c][0..ids_len], + }; + columns_len += 1; } var mounts: [filesystem.max_mounts]Mount = undefined; diff --git a/src/exec.zig b/src/exec.zig index ee7c31e9..117970d9 100644 --- a/src/exec.zig +++ b/src/exec.zig @@ -322,12 +322,7 @@ fn spawnTtyWithMount(p: *Pardes, from: usize, v9fs: bool) ?*Pane { nt.greet = !v9fs; nt.v9fs_on_spawn = v9fs; nt.body.mode = .tty; - const parent = layout.splitParent(p, from); - const f = layout.findPane(p, parent).?; - layout.insert(p, f.col, f.idx + 1, free); - layout.splitBelow(p, parent, nt); - p.active = free; - p.stillborn_joiner = nt.serial; + placeNew(p, from, from, free, .shell); return nt; } @@ -357,29 +352,6 @@ pub fn evictLonePristineTty(p: *Pardes, col: usize, keep_id: usize) void { if (p.active == tty_id) p.active = keep_id; } -/// A pane that just joined a column whose only other pane is stillborn — -/// an empty scratch nobody typed into, body or tag (what Newcol makes and -/// what a closed column's last pane leaves behind) — takes the column -/// whole: the placeholder was only holding the space for it. Run at the -/// end of a step: the pane that asked for the joiner is often the -/// placeholder itself, and its caller is still holding it. -pub fn replaceStillborn(p: *Pardes) void { - const serial = p.stillborn_joiner orelse return; - p.stillborn_joiner = null; - const new_id = p.paneBySerial(serial) orelse return; - const f = layout.findPane(p, new_id) orelse return; - if (p.col_n[f.col] != 2) return; - const old_id = p.col_panes[f.col][1 - f.idx]; - const old = p.panes[old_id] orelse return; - const file = old.file orelse return; - const out = file.output orelse return; - if (out.from != .cmd or out.from.cmd != .New) return; - if (file.revision != 0 or file.content.len != 0) return; - if (old.tag.own) |own| if (!std.mem.eql(u8, own, tagline.defaultTail(old))) return; - layout.compute(p); // the joiner may have no rect yet; absorb snaps to rows - p.removePane(old_id, new_id) catch |err| return p.reportError(old_id, "close", err); -} - // ---- REPLs ---- // // A terminal is bound as a language's REPL by `Repl python` (builtins.zig). @@ -552,7 +524,7 @@ pub fn executeFrom(p: *Pardes, id: usize, txt: []const u8, from_body: bool) ?usi /// Runs `line` in a command pane for `from`'s directory: `from` itself if /// it is one whose command is done, else the directory's command pane that -/// is done, else a new one below the last pane of the rightmost column. +/// is done, else a new one, placed as placeNew places a command pane. /// A pane reused keeps what it showed: the new command runs below a line /// naming it, as acme appends to +Errors and never clears it (util.c:213). fn runCommand(p: *Pardes, from: usize, line: []const u8) ?usize { @@ -607,13 +579,7 @@ fn runCommand(p: *Pardes, from: usize, line: []const u8) ?usize { return null; }; echoCommand(p, pane, line); - const rc = if (p.ncol > 0) p.ncol - 1 else 0; - if (p.col_n[rc] > 0) { - const parent = layout.splitParent(p, p.col_panes[rc][p.col_n[rc] - 1]); - const f = layout.findPane(p, parent).?; - layout.splitBelow(p, parent, pane); - layout.insert(p, f.col, f.idx + 1, free); - } else layout.insert(p, rc, p.col_n[rc], free); + placeNew(p, from, from, free, .command); noteRun(p, pane, "run", line); return free; } @@ -691,7 +657,24 @@ pub fn applyStartupConfig(p: *Pardes) void { p.announce = false; defer p.announce = true; var lines = std.mem.splitScalar(u8, p.opts.startup_config orelse return, '\n'); - while (lines.next()) |line| _ = executeBuiltinLine(p, p.active, line); + while (lines.next()) |line| { + if (executeBuiltinLine(p, p.active, line)) continue; + // A setting pardes no longer has is said, once, and changes nothing. + const word = commandText(line); + if (std.mem.eql(u8, word[0 .. std.mem.indexOfAny(u8, word, " \t") orelse word.len], "ColumnTags")) + p.setMessage(p.active, "ColumnTags: column tags are always shown now; the init line is ignored"); + } +} + +test "an init file's retired ColumnTags line is said and ignored" { + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 80, .rows = 24 }); + defer p.deinit(); + p.opts.startup_config = "ColumnTags\nWrap off\n"; + applyStartupConfig(p); + try std.testing.expect(!p.settings.wrap); + try std.testing.expect(p.columnBarHeight() > 0); + const pane = p.panes[p.active].?; + try std.testing.expectEqualStrings("ColumnTags: column tags are always shown now; the init line is ignored", pane.msg[0..pane.msg_len]); } pub fn runBuiltin(p: *Pardes, b: Builtin, id: usize, txt: []const u8, arg: ?[]const u8) void { @@ -718,7 +701,6 @@ pub fn applySettingBuiltin(p: *Pardes, setting: config.Runtime.Setting, arg: ?[] const previous_context_style = p.settings.tree_context_tag_style; const previous_transition = p.settings.panel_transition; const previous_tagline_percent = p.settings.font.tagline_percent; - const previous_column_tags = p.settings.column_tags; switch (setting.action) { .theme => { const want = std.mem.trim(u8, arg orelse return, " \t\r\n"); @@ -768,20 +750,98 @@ pub fn applySettingBuiltin(p: *Pardes, setting: config.Runtime.Setting, arg: ?[] p.settings.panel_transition != previous_transition; const tagline_metrics_changed = setting.action == .tagline_size and p.settings.font.tagline_percent != previous_tagline_percent; - if (p.settings.column_tags != previous_column_tags) { - if (p.header_column != null) tagline.exitHeader(p); - } // Idle frames keep no frozen grid while transitions are off; the one // just drawn is the baseline the first transition starts from. if (transition_changed and previous_transition == .off) p.presentation.capturePrevious(p.gpa, &p.surface); - if (transition_changed or tagline_metrics_changed or p.settings.column_tags != previous_column_tags) { + if (transition_changed or tagline_metrics_changed) { p.abandonPanelAnimations(); } } -pub fn placeDoc(p: *Pardes, from_id: usize, free: usize, nt: *Pane) void { - p.stillborn_joiner = nt.serial; +/// What a new pane is, and who asked: each rule places them differently. +/// `scratch` is New's, `fs` 9P's pane/new, `errors` a +Errors pane. +pub const NewPane = enum { scratch, fs, shell, doc, command, errors }; + +/// Put new pane `id` in the layout: every new pane comes through here, by +/// the `Placement` setting, and every one but a command pane takes the +/// keyboard. `from` is the pane that asked, `origin` the text it asked +/// from: null when a column tag, the workspace tag or 9P asked (acme's +/// t->w == nil). +pub fn placeNew(p: *Pardes, from: usize, origin: ?usize, id: usize, kind: NewPane) void { + const asked = if (p.exec_column != null) null else origin; + switch (p.settings.placement) { + .acme => switch (kind) { + // New: the bottom half of the last pane in its own column + // (look.c:921-923, et->col). + .scratch => layout.acmePlace(p, p.exec_column orelse columnOf(p, from), null, id), + // +Errors, a command's output: the last column (util.c:94-98). + .command, .errors => layout.acmePlace(p, p.ncol - 1, null, id), + // makenewwindow(nil) for 9P's new (acme.c:877), else (t). + .fs => layout.acmePlace(p, acmeColumn(p, from), null, id), + .shell, .doc => layout.acmePlace(p, acmeColumn(p, from), asked, id), + }, + .pardes => pardesPlace(p, from, id, kind), + } + if (kind == .command) return; + tagline.exitHeader(p); + p.active = id; + if (layout.findPane(p, id)) |f| p.setActiveColumn(f.col); +} + +/// acme's makenewwindow column (util.c:456-467): the column a command came +/// from (its tag's), else the active column, else the keyboard's pane's, +/// else the asking pane's. +fn acmeColumn(p: *Pardes, from: usize) usize { + if (p.exec_column) |c| return c; + if (p.activeColumn()) |c| return c; + if (layout.findPane(p, p.active)) |f| return f.col; + return columnOf(p, from); +} + +fn columnOf(p: *Pardes, id: usize) usize { + return if (layout.findPane(p, id)) |f| f.col else p.ncol - 1; +} + +/// The placements pardes had before it took acme's: an empty column whose +/// tag asked, or has the keyboard, is filled; a scratch goes under the +/// asking pane, a shell under it or the nearest pane with room, a document +/// beside the last one read or in a column of its own, and a command pane +/// at the foot of the last column. +fn pardesPlace(p: *Pardes, from: usize, id: usize, kind: NewPane) void { + const empty = if (p.exec_column orelse if (p.header_focus) p.header_column else null) |c| + (if (c < p.ncol and p.col_n[c] == 0) c else null) + else + null; + if (empty) |c| { + layout.insert(p, c, 0, id); + p.panes[id].?.vweight = 1; + return; + } + const nt = p.panes[id].?; + switch (kind) { + .scratch, .fs => if (layout.findPane(p, from)) |sf| { + layout.insert(p, sf.col, sf.idx + 1, id); + layout.splitBelow(p, from, nt); + }, + .shell => belowParent(p, from, id), + .doc, .errors => pardesDoc(p, from, id), + .command => { + const rc = p.ncol - 1; + if (p.col_n[rc] > 0) belowParent(p, p.col_panes[rc][p.col_n[rc] - 1], id) else layout.insert(p, rc, 0, id); + }, + } +} + +fn belowParent(p: *Pardes, from: usize, id: usize) void { + const parent = layout.splitParent(p, from); + const f = layout.findPane(p, parent).?; + layout.insert(p, f.col, f.idx + 1, id); + layout.splitBelow(p, parent, p.panes[id].?); +} + +fn pardesDoc(p: *Pardes, from_id: usize, free: usize) void { + const nt = p.panes[free].?; const doc = if (nt.file) |f| panes.Output.fileTraits(f.output).doc else true; // an image is a doc var src_id: ?usize = null; if (p.panes[from_id]) |src| if (if (src.file) |f| panes.Output.fileTraits(f.output).doc else src.image != null or src.hasPdf()) { @@ -808,22 +868,14 @@ pub fn placeDoc(p: *Pardes, from_id: usize, free: usize, nt: *Pane) void { if (!doc) if (layout.findPane(p, from_id)) |sf| { layout.insert(p, sf.col, sf.idx + 1, free); layout.splitBelow(p, from_id, nt); // NOT splitParent: no bystander pays - p.active = free; return; }; if (src_id == null and doc and p.ncol < MAX_COLS and layout.columnFitsHalves(p, from_id, 100) and layout.splitColumn(p, from_id, free, true)) - { - p.active = free; return; - } // Without room for a first-document column, split the Look origin // just like Tty. Never displace (or evict) a top-left bystander. - const src = layout.splitParent(p, src_id orelse from_id); - const sf = layout.findPane(p, src).?; - layout.insert(p, sf.col, sf.idx + 1, free); - layout.splitBelow(p, src, nt); - p.active = free; + belowParent(p, src_id orelse from_id, free); } test "the acme chords act once per selection, not once on the primary" { diff --git a/src/fs-help.txt b/src/fs-help.txt index 2b42be1f..0121a831 100644 --- a/src/fs-help.txt +++ b/src/fs-help.txt @@ -8,10 +8,10 @@ exec write a line: a middle click, an editor command word or a shell line log events: new/del/rename/save , run/exit/send ..., dump/restore , msg, err screen rendered screen as JSON, frozen from open to close listeners the session's dial addresses -focus the serial of the pane with the keyboard; write a serial to give it the keyboard -ctl settings, one a line; or Newcol, Dump, Exit (quits, asks once), Kill [w] (stops what pardes ran, w: by first word) +focus the serial of the pane with the keyboard (empty on a column tag); write a serial to give it the keyboard +ctl settings, one a line; or Newcol (an empty column), Dump, Exit (quits, asks once), Kill [w] (stops what pardes ran, w: by first word) commands every builtin: its word, arg if it takes one, and root or pane: which ctl takes it -pane/new open it to make a pane (named +New); the read answers that pane's serial +pane/new open it to make a pane (named +New) in the active column, filling it if empty; the read answers its serial pane// name body tag ctl addr dot limit data xdata sel dirty mark scroll errors (write-only: appended to its directory's +Errors pane) event look exec, pty/ on terminals; rmdir closes os/, src/ the host filesystem; the editor's own sources (-Dembed-sources=true builds only) @@ -41,5 +41,5 @@ Pitfalls, one each: A terminal's body is a history snapshot frozen per open; pty/data is the live stream. exec: a non-builtin line runs as a command pane (ctl's Shell -c; exit N shown, logged), a shell's typed in. Through a mount a malformed write is EINVAL, a well-formed one that fails EIO: log's err says why. - lock/unlock need a held ctl fd (exec 3>ctl), a held lock fails: retry. A column's last pane -> +New. + lock/unlock need a held ctl fd (exec 3>ctl), a held lock fails: retry. A column's last pane leaves it empty; the last pane of all quits. Repl python on a terminal's ctl: a .py body's clicks go to it (Repl - unbinds, Repl says it); tags stay commands. diff --git a/src/gui/gui.zig b/src/gui/gui.zig index 84ec1c5c..26e9e24d 100644 --- a/src/gui/gui.zig +++ b/src/gui/gui.zig @@ -73,6 +73,24 @@ const p9_arrow_set = [32]u8{ 0x7F, 0xFC, 0x7F, 0xFE, 0x7F, 0xFC, 0x73, 0xF8, 0x61, 0xF0, 0x60, 0xE0, 0x40, 0x40, 0x00, 0x00, }; +/// acme's boxcursor (acme.c:956), while a grip carries a pane or column. +const p9_box_clr = [32]u8{ + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xF8, 0x1F, 0xF8, 0x1F, 0xF8, 0x1F, + 0xF8, 0x1F, 0xF8, 0x1F, 0xF8, 0x1F, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, +}; +const p9_box_set = [32]u8{ + 0x00, 0x00, 0x7F, 0xFE, 0x7F, 0xFE, 0x7F, 0xFE, + 0x70, 0x0E, 0x70, 0x0E, 0x70, 0x0E, 0x70, 0x0E, + 0x70, 0x0E, 0x70, 0x0E, 0x70, 0x0E, 0x70, 0x0E, + 0x7F, 0xFE, 0x7F, 0xFE, 0x7F, 0xFE, 0x00, 0x00, +}; +const p9_box_mask = blk: { + var m: [32]u8 = undefined; + for (&m, p9_box_set, p9_box_clr) |*b, s, cl| b.* = s | cl; + break :blk m; +}; const p9_arrow_mask = blk: { var m: [32]u8 = undefined; for (&m, p9_arrow_set, p9_arrow_clr) |*b, s, cl| b.* = s | cl; @@ -1847,6 +1865,7 @@ const Gui = struct { pointer_present: bool = false, arrow_cursor: ?*c.SDL_Cursor = null, link_cursor: ?*c.SDL_Cursor = null, + box_cursor: ?*c.SDL_Cursor = null, pointer_shape: pardes.Surface.PointerShape = .arrow, pointer_mapped: bool = false, pointer_cell: ?MouseCell = null, @@ -2292,6 +2311,9 @@ fn runNative(init: std.process.Init, opts_in: pardes.Options, attach: ?[]const u defer if (arrow_cursor) |cursor| c.SDL_DestroyCursor(cursor); const link_cursor = c.SDL_CreateSystemCursor(c.SDL_SYSTEM_CURSOR_POINTER); defer if (link_cursor) |cursor| c.SDL_DestroyCursor(cursor); + // Its hot spot the middle, as acme's {-7, -7} offset puts it. + const box_cursor = c.SDL_CreateCursor(&p9_box_set, &p9_box_mask, 16, 16, 7, 7); + defer if (box_cursor) |cursor| c.SDL_DestroyCursor(cursor); if (arrow_cursor) |cur| { _ = c.SDL_SetCursor(cur); } else log.err("SDL_CreateCursor: {s}", .{c.SDL_GetError()}); @@ -2427,6 +2449,7 @@ fn runNative(init: std.process.Init, opts_in: pardes.Options, attach: ?[]const u .window = window, .arrow_cursor = arrow_cursor, .link_cursor = link_cursor, + .box_cursor = box_cursor, .device = device, .swapchain_format = swapchain_format, .pipeline = pipeline, @@ -5270,7 +5293,11 @@ fn renderFrame( ) !bool { if (surface.pointer_shape != g.pointer_shape) { g.pointer_shape = surface.pointer_shape; - const cursor = if (g.pointer_shape == .link) g.link_cursor else g.arrow_cursor orelse c.SDL_GetDefaultCursor(); + const cursor = switch (g.pointer_shape) { + .link => g.link_cursor, + .box => g.box_cursor orelse g.arrow_cursor, + else => g.arrow_cursor orelse c.SDL_GetDefaultCursor(), + }; if (cursor) |value| _ = c.SDL_SetCursor(value); } g.scene_target_failed = false; @@ -5810,7 +5837,6 @@ test "the layer cover is the per-cell layer scan, over a core's layouts and rand var notices = false; for (0..32) |step| { core.settings.tag_bottom = step & 1 != 0; - core.settings.column_tags = step & 2 != 0; if (step & 3 == 0) try std.testing.expect(core.executeBuiltinLine(2, "Collapse")); core.leader_on = step & 4 != 0; if (step & 8 != 0) { diff --git a/src/layout.zig b/src/layout.zig index f0e6fd16..c58f3bcf 100644 --- a/src/layout.zig +++ b/src/layout.zig @@ -19,7 +19,9 @@ pub const max_column_weight: u64 = std.math.maxInt(u64) / MAX_COLS; pub const MovePlacement = struct { preview_col: usize, - above_id: usize, + /// The pane the moved one lands below; null when the column is empty + /// and the moved pane takes it whole. + above_id: ?usize, row: u16, above_y: u16, above_h: u16, @@ -60,6 +62,16 @@ pub fn focusDir(p: *Pardes, from: usize, dir: enum { left, right, up, down }) bo return true; } +/// Column `c`'s serial, handed out the first time it is asked for. +pub fn columnSerial(p: *Pardes, c: usize) u32 { + if (p.col_serial[c] == 0) { + p.col_serial[c] = p.next_column_serial; + p.next_column_serial +%= 1; + if (p.next_column_serial == 0) p.next_column_serial = 1; + } + return p.col_serial[c]; +} + pub fn columnBySerial(p: *const Pardes, serial: u32) ?usize { if (serial == 0) return null; for (0..p.ncol) |column| if (p.col_serial[column] == serial) return column; @@ -178,6 +190,7 @@ pub fn movePlacement(p: *Pardes, id: usize, cur_x: u16, cur_y: u16) ?MovePlaceme heights[sib] +|= p.rects[id].h; } var y: u16 = p.topBarHeight() + p.columnBarHeight(); + if (p.col_n[tc] == 0) return .{ .preview_col = tc, .above_id = null, .row = y, .above_y = y, .above_h = 0 }; var last: ?MovePlacement = null; for (0..p.col_n[tc]) |k| { const pid = p.col_panes[tc][k]; @@ -213,18 +226,23 @@ pub fn movePane(p: *Pardes, id: usize, cur_x: u16, cur_y: u16) void { } } removePane(p, id); - if (source_multi and src.col < p.ncol and p.col_n[src.col] > 0) { + if (source_multi) { const sib = if (src.idx > 0) p.col_panes[src.col][src.idx - 1] else p.col_panes[src.col][src.idx]; heights[sib] +|= p.rects[id].h; } - const af = findPane(p, placement.above_id) orelse return; + const above = placement.above_id orelse { + insert(p, placement.preview_col, 0, id); + if (source_multi) setColumnWeights(p, src.col, &heights); + return; + }; + const af = findPane(p, above) orelse return; const upper_h = @max(1, placement.row -| placement.above_y); const lower_h = @max(1, placement.above_h -| upper_h); - heights[placement.above_id] = upper_h; + heights[above] = upper_h; heights[id] = lower_h; insert(p, af.col, af.idx + 1, id); setColumnWeights(p, af.col, &heights); - if (source_multi and src.col < p.ncol and src.col != af.col) setColumnWeights(p, src.col, &heights); + if (source_multi and src.col != af.col) setColumnWeights(p, src.col, &heights); } pub fn setColumnWeights(p: *Pardes, col: usize, heights: *const [MAX_PANES]u16) void { @@ -278,39 +296,23 @@ pub fn insert(p: *Pardes, c: usize, idx: usize, id: usize) void { p.col_n[c] += 1; } +/// Take a pane out of its column. The column stays, empty if this was its +/// last pane, as acme's colclose leaves it (cols.c:186): only Delcol and +/// Joincol take a column away. pub fn removePane(p: *Pardes, id: usize) void { const f = findPane(p, id) orelse return; const c = f.col; var k = f.idx; while (k + 1 < p.col_n[c]) : (k += 1) p.col_panes[c][k] = p.col_panes[c][k + 1]; p.col_n[c] -= 1; - if (p.col_n[c] == 0) { - tagline.exitHeader(p); - if (p.ncol > 1) p.col_weight[if (c > 0) c - 1 else c + 1] +|= p.col_weight[c]; - p.col_tags[c].deinit(p.gpa); - var j = c; - while (j + 1 < p.ncol) : (j += 1) { - p.col_panes[j] = p.col_panes[j + 1]; - p.col_n[j] = p.col_n[j + 1]; - p.col_weight[j] = p.col_weight[j + 1]; - p.col_tags[j] = p.col_tags[j + 1]; - p.col_serial[j] = p.col_serial[j + 1]; - } - p.ncol -= 1; - p.col_tags[p.ncol] = .{ .what = .column, .gpa = p.gpa }; - p.col_serial[p.ncol] = 0; - } } -pub fn joinCol(p: *Pardes) void { - const f = findPane(p, p.active) orelse return; - const c = f.col; - if (c + 1 >= p.ncol) return; +/// Close column `c` once its panes are gone, its width to the one left of +/// it (the first column's to its right), as acme's rowclose gives it. +pub fn dropColumn(p: *Pardes, c: usize) void { + std.debug.assert(p.col_n[c] == 0); tagline.exitHeader(p); - const dst = c + 1; - p.col_weight[dst] +|= p.col_weight[c]; - for (0..p.col_n[c]) |k| p.col_panes[dst][p.col_n[dst] + k] = p.col_panes[c][k]; - p.col_n[dst] += p.col_n[c]; + if (p.ncol > 1) p.col_weight[if (c > 0) c - 1 else c + 1] +|= p.col_weight[c]; p.col_tags[c].deinit(p.gpa); var j = c; while (j + 1 < p.ncol) : (j += 1) { @@ -325,42 +327,145 @@ pub fn joinCol(p: *Pardes) void { p.col_serial[p.ncol] = 0; } +/// Fold column `c` into the one on its right, its panes below theirs. +pub fn joinCol(p: *Pardes, c: usize) void { + if (c + 1 >= p.ncol) return; + const dst = c + 1; + for (0..p.col_n[c]) |k| p.col_panes[dst][p.col_n[dst] + k] = p.col_panes[c][k]; + p.col_n[dst] += p.col_n[c]; + p.col_n[c] = 0; + // The width goes right, where the panes went. + p.col_weight[dst] +|= p.col_weight[c]; + p.col_weight[c] = 0; + dropColumn(p, c); +} + +/// Put new pane `id` in column `c` as acme's makenewwindow does +/// (util.c:449-495): an empty column it takes whole; asked from a tag or +/// from 9P (`origin` null, acme's t->w == nil) it takes the bottom half of +/// the column's last pane (coladd with y < 0, cols.c:62-65). Asked from a +/// pane's text, it goes under the text of the pane with the most blank rows +/// when there are many, else it halves the biggest pane, or `origin` when +/// that is in the column and not much smaller. +pub fn acmePlace(p: *Pardes, c: usize, origin: ?usize, id: usize) void { + compute(p); + const n = p.col_n[c]; + if (n == 0) { + insert(p, c, 0, id); + p.panes[id].?.vweight = 1; + return; + } + var big: ?usize = null; + var empty: ?usize = null; + for (p.col_panes[c][0..n]) |k| { + const pane = p.panes[k] orelse continue; + if (pane.collapsed) continue; + // `>=`: at a tie the one nearer the bottom, as acme picks. + if (big == null or bodyRows(p, k) >= bodyRows(p, big.?)) big = k; + if (empty == null or blankRows(p, k) >= blankRows(p, empty.?)) empty = k; + } + const v0 = big orelse { + // Every pane folded: the new one goes last. + insert(p, c, n, id); + return; + }; + const y: u16 = y: { + const o = origin orelse { + var last = v0; + for (p.col_panes[c][0..n]) |k| if (!p.panes[k].?.collapsed) { + last = k; + }; + break :y bodyTop(p, last) + bodyRows(p, last) / 2; + }; + const e = empty.?; + const el = blankRows(p, e); + if (el > 15 or (el > 3 and el > (bodyRows(p, v0) -| 1) / 2)) + break :y bodyTop(p, e) + bodyRows(p, e) - el; + const mine = if (findPane(p, o)) |f| f.col == c and !p.panes[o].?.collapsed else false; + const v = if (mine and @as(u32, p.rects[o].h) * 3 > @as(u32, p.rects[v0].h) * 2) o else v0; + break :y p.rects[v].y + p.rects[v].h / 2; + }; + splitAt(p, c, id, y); +} + +/// acme's coladd at row `y` (cols.c:66-126): the new pane goes under the +/// pane that `y` falls in, which keeps its rows above `y`. +fn splitAt(p: *Pardes, c: usize, id: usize, y: u16) void { + const n = p.col_n[c]; + var k: usize = 0; + while (k + 1 < n and y >= p.rects[p.col_panes[c][k]].y + p.rects[p.col_panes[c][k]].h) k += 1; + const v = p.col_panes[c][k]; + const r = p.rects[v]; + snapColWeights(p, c); + insert(p, c, k + 1, id); + const pane = p.panes[id].?; + // Each keeps a tag and a body row, as acme's minht does. + const lo = r.y +| BOX_H + 1; + const hi = (r.y + r.h) -| (BOX_H + 1); + const row = splitRowForExtent(r.y, r.h, if (lo <= hi) std.math.clamp(y, lo, hi) else r.y + r.h / 2) orelse { + pane.vweight = BOX_H + 1; + return; + }; + // `y` fell in an unfolded pane: acmePlace picks from those. + p.panes[v].?.vweight = @floatFromInt(@max(1, row - r.y)); + pane.vweight = @floatFromInt(@max(1, (r.y + r.h) - row)); +} + +fn bodyTop(p: *const Pardes, id: usize) u16 { + return p.rects[id].y + p.panes[id].?.tag_rows; +} + +fn bodyRows(p: *const Pardes, id: usize) u16 { + return p.rects[id].h -| p.panes[id].?.tag_rows; +} + +/// The rows at the bottom of a pane's body that show nothing: acme's +/// maxlines - nlines. A picture or a PDF page fills its body. +fn blankRows(p: *const Pardes, id: usize) u16 { + const pane = p.panes[id].?; + const rows = bodyRows(p, id); + const used: usize = if (pane.file) |*f| + // The empty line after a final newline shows nothing. + (panes.File.nlines(p.gpa, f) -| @intFromBool(std.mem.endsWith(u8, f.content, "\n"))) -| f.scroll + else if (pane.isTerminal()) + @as(usize, panes.Terminal.gridCursor(pane).y) + 1 + else + rows; + return rows -| @as(u16, @intCast(@min(used, rows))); +} + pub fn canSplitColumn(p: *Pardes, source_id: usize) bool { - if (p.ncol >= MAX_COLS or source_id >= MAX_PANES or p.panes[source_id] == null) return false; + if (source_id >= MAX_PANES or p.panes[source_id] == null) return false; const source = findPane(p, source_id) orelse return false; + return canSplitCol(p, source.col); +} + +fn canSplitCol(p: *Pardes, col: usize) bool { + if (p.ncol >= MAX_COLS or col >= p.ncol) return false; // Refresh derived widths: public layout surgery may be chained between // syncs, and a cached width must never admit a now-too-narrow split. compute(p); - if (p.col_w[source.col] < config.MINW * 2) return false; + if (p.col_w[col] < config.MINW * 2) return false; - const weight = p.col_weight[source.col]; + const weight = p.col_weight[col]; if (weight >= 2 and weight % 2 == 0) return true; for (0..p.ncol) |column| if (p.col_weight[column] > std.math.maxInt(u64) / 2) return false; return weight > 0; } -pub fn splitColumn(p: *Pardes, source_id: usize, id: usize, before: bool) bool { - if (id >= MAX_PANES or p.panes[id] == null) return false; - if (!canSplitColumn(p, source_id)) return false; - const source = findPane(p, source_id) orelse return false; - const source_col = source.col; - var old_weight = p.col_weight[source_col]; - const needs_rebase = old_weight < 2 or old_weight % 2 != 0; - if (needs_rebase) old_weight *= 2; - if (id == source_id) { - if (p.col_n[source_col] <= 1) return false; - _ = absorbVWeight(p, id, null); - removePane(p, id); - } else if (findPane(p, id) != null) return false; - - if (needs_rebase) { +/// An empty column beside column `col`, with half its width: acme's Newcol +/// (rowadd, rows.c:51). The new column's index, or null with no room. +pub fn insertColumn(p: *Pardes, col: usize, before: bool) ?usize { + if (!canSplitCol(p, col)) return null; + var old_weight = p.col_weight[col]; + if (old_weight < 2 or old_weight % 2 != 0) { + old_weight *= 2; for (0..p.ncol) |column| p.col_weight[column] *= 2; } const source_weight = old_weight / 2; - const new_weight = old_weight - source_weight; - p.col_weight[source_col] = source_weight; - const c = source_col + @intFromBool(!before); + p.col_weight[col] = source_weight; + const c = col + @intFromBool(!before); tagline.exitHeader(p); var j = p.ncol; while (j > c) : (j -= 1) { @@ -370,12 +475,27 @@ pub fn splitColumn(p: *Pardes, source_id: usize, id: usize, before: bool) bool { p.col_tags[j] = p.col_tags[j - 1]; p.col_serial[j] = p.col_serial[j - 1]; } - p.col_weight[c] = new_weight; + p.col_weight[c] = old_weight - source_weight; p.col_tags[c] = .{ .what = .column, .gpa = p.gpa }; p.col_serial[c] = 0; - p.col_panes[c][0] = id; - p.col_n[c] = 1; + p.col_n[c] = 0; p.ncol += 1; + return c; +} + +/// Pane `id` alone in a new column beside `source_id`'s; `id` may be the +/// source itself when its column keeps another pane. +pub fn splitColumn(p: *Pardes, source_id: usize, id: usize, before: bool) bool { + if (id >= MAX_PANES or p.panes[id] == null) return false; + if (!canSplitColumn(p, source_id)) return false; + const source = findPane(p, source_id) orelse return false; + if (id == source_id) { + if (p.col_n[source.col] <= 1) return false; + _ = absorbVWeight(p, id, null); + removePane(p, id); + } else if (findPane(p, id) != null) return false; + const c = insertColumn(p, source.col, before).?; + insert(p, c, 0, id); return true; } @@ -551,11 +671,7 @@ fn computeCollapsedColumn(p: *Pardes, c: usize, x: u16, width: u16, folded: usiz pub fn compute(p: *Pardes) void { p.rects = @splat(.{}); if (p.ncol == 0) return; - for (0..p.ncol) |column| if (p.col_serial[column] == 0) { - p.col_serial[column] = p.next_column_serial; - p.next_column_serial +%= 1; - if (p.next_column_serial == 0) p.next_column_serial = 1; - }; + for (0..p.ncol) |column| _ = columnSerial(p, column); var wsum: u128 = 0; for (0..p.ncol) |c| wsum += p.col_weight[c]; if (wsum == 0) wsum = 1; @@ -688,7 +804,6 @@ test "collapse local transfers remain bounded through repeated tiny window resiz } for (0..180) |step| { p.screen_h = @intCast((step * 17) % 81); - p.settings.column_tags = step % 2 == 0; p.settings.tag_bottom = step % 3 == 0; compute(p); toggleCollapse(p, step % 5); @@ -743,7 +858,7 @@ test "collapse single and all panes leave unused column space" { try std.testing.expectEqual(p.screen_h - 1, p.rects[1].y); } -test "collapse survives tiny resizes column tags and TagBottom" { +test "collapse survives tiny resizes and TagBottom" { const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 80, .rows = 32 }); defer p.deinit(); _ = try p.newShell(1, ""); @@ -753,8 +868,7 @@ test "collapse survives tiny resizes column tags and TagBottom" { p.panes[1].?.collapsed = true; for ([_]bool{ false, true }) |bottom| { p.settings.tag_bottom = bottom; - for ([_]bool{ false, true }) |column_tags| { - p.settings.column_tags = column_tags; + { for (0..50) |height| { p.screen_h = @intCast(height); compute(p); diff --git a/src/look.zig b/src/look.zig index 020aacb8..b6a89b64 100644 --- a/src/look.zig +++ b/src/look.zig @@ -1251,20 +1251,15 @@ pub fn lookAt(p: *Pardes, id: usize, operand: []const u8) void { const free = p.freeSlot() orelse return p.reportError(id, "look", error.NoPaneSlots); const nt = p.newShell(free, dir) catch |err| return p.reportError(id, "look", err); nt.greet = true; - const src = layout.splitParent(p, id); - const f = layout.findPane(p, src).?; - layout.insert(p, f.col, f.idx + 1, free); - layout.splitBelow(p, src, nt); - p.active = free; - p.stillborn_joiner = nt.serial; + exec.placeNew(p, id, id, free, .shell); }, .file => |target| { if (comptime pdf_enabled) if (target.kind == .pdf) { if (focusPaneByPath(p, target.path, target.at)) return; const free = p.freeSlot() orelse return p.reportError(id, "look", error.NoPaneSlots); - const nt = panes.Pdf.openPane(p, free, target.path, target.at.line) catch |err| + _ = panes.Pdf.openPane(p, free, target.path, target.at.line) catch |err| return p.reportError(id, "look", err); - exec.placeDoc(p, id, free, nt); + exec.placeNew(p, id, id, free, .doc); return; }; // focus an existing pane on this path (rescrolled), else open @@ -1273,7 +1268,7 @@ pub fn lookAt(p: *Pardes, id: usize, operand: []const u8) void { const nt = panes.File.open(p, free, target.path, target.at.line) catch |err| return p.reportError(id, "look", err); if (target.at.col > 0) nt.body.cur_col = @intCast(target.at.col - 1); - exec.placeDoc(p, id, free, nt); + exec.placeNew(p, id, id, free, .doc); layout.compute(p); nt.file.?.scroll -|= @max(1, p.rects[free].h -| BOX_H) / 2; if (target.at.end_line != 0) { @@ -1285,9 +1280,9 @@ pub fn lookAt(p: *Pardes, id: usize, operand: []const u8) void { .image => |target| { if (focusPaneByPath(p, target.path, .{})) return; const free = p.freeSlot() orelse return p.reportError(id, "look", error.NoPaneSlots); - const nt = panes.Image.create(p, free, target.path, &.{}) catch |err| + _ = panes.Image.create(p, free, target.path, &.{}) catch |err| return p.reportError(id, "look", err); - exec.placeDoc(p, id, free, nt); + exec.placeNew(p, id, id, free, .doc); }, } } diff --git a/src/mouse.zig b/src/mouse.zig index 22eb3270..5f0a6c4b 100644 --- a/src/mouse.zig +++ b/src/mouse.zig @@ -337,6 +337,9 @@ pub fn handleMouse(p: *Pardes, m: Mouse) void { wordAtCol(bar, at); const word = p.scratch.allocator().dupe(u8, selected) catch return; tagline.exitHeader(p); + // A column tag's command acts on that column, empty or not. + p.exec_column = column; + defer p.exec_column = null; if (word.len > 0) { if (m.button == config.exec_button) { const named = std.meta.stringToEnum(Builtin, word); @@ -450,6 +453,7 @@ pub fn handleMouse(p: *Pardes, m: Mouse) void { const on_tag = mrow >= tag_y and mrow < tag_y + pane.tag_rows; if (on_tag and mcol < r.x + TAG_TEXT_INSET) return; p.active = id; + p.noteTyped(); // acme's button 1 sets activecol (acme.c:659) pane.closePrompt(); const pointed = edit.pointerTextSelection(p, id, mcol, mrow, m.body_hit, p.pointer_tag_hit) orelse return; pane.clearPointerSelection(sel_slot); @@ -775,12 +779,15 @@ fn dragRelease(p: *Pardes, button: Mouse.Button) void { layout.applyRowSplit(p, d.col, d.top_idx, d.cur_y), .column_move => |d| if (layout.columnBySerial(p, d.serial)) |column| switch (layout.columnDrop(p, column, d.cur_x, d.grab)) { .stay => {}, - .reorder => |target| layout.reorderColumn(p, column, target), + .reorder => |target| { + layout.reorderColumn(p, column, target); + p.setActiveColumn(target); // a grip drag sets activecol (acme.c:640) + }, .edge => |x| layout.setColumnPairWidth(p, column - 1, x - p.col_x[column - 1]), }, .move => |d| { layout.movePane(p, d.id, d.cur_x, d.cur_y); - if (p.panes[d.id]) |mp| p.stillborn_joiner = mp.serial; + if (layout.findPane(p, d.id)) |f| p.setActiveColumn(f.col); // a file moved into the left column evicts a lone unused shell if (p.panes[d.id]) |mt| if (mt.file != null) { if (layout.findPane(p, d.id)) |f| if (f.col == 0) diff --git a/src/ninep/ctl.zig b/src/ninep/ctl.zig index 18068ab1..b4ae7231 100644 --- a/src/ninep/ctl.zig +++ b/src/ninep/ctl.zig @@ -308,6 +308,7 @@ fn writeSettings(p: *Pardes, w: *std.Io.Writer) !void { .tagline_size => try w.print("{s} {d}\n", .{ word, s.font.tagline_percent }), .window_opacity => try w.print("{s} {d}\n", .{ word, s.window_opacity }), .window_blur => try w.print("{s} {d}\n", .{ word, s.window_blur }), + .placement => try w.print("{s} {s}\n", .{ word, @tagName(s.placement) }), .message_ms => |which| try w.print("{s} {d}\n", .{ word, @field(s, "message_" ++ @tagName(which) ++ "_ms") }), // Bare, it names the default directory. .dump_dir => if (s.dump_dir.len > 0) try w.print("{s} {s}\n", .{ word, s.dump_dir.get() }) else try w.print("{s}\n", .{word}), @@ -1120,7 +1121,7 @@ test "Joincol with no column to the right and Theme with no such theme say so" { try testing.expect(std.mem.indexOf(u8, pane.msg[0..pane.msg_len], "no theme \"drak\"") != null); } -test "a look that fills a column's stillborn scratch is answered with the scratch already gone" { +test "a look after Newcol fills the empty column the keyboard is on" { const gpa = testing.allocator; const p = try withFile(gpa, "x\n"); defer p.deinit(); @@ -1130,14 +1131,12 @@ test "a look that fills a column's stillborn scratch is answered with the scratc var dir: [4096]u8 = undefined; const at = dir[0..try tmp.dir.realPath(testing.io, &dir)]; var line: [4200]u8 = undefined; - // Newcol makes a column of one empty +New; a file looked from it - // joins that column and takes the scratch's place. + // Newcol makes an empty column and gives its tag the keyboard; no pane + // has it, so focus reads empty. try testing.expectEqual(tree.Status.ok, wr(p, @intFromEnum(tree.TopFile.ctl), "Newcol\n").reply.status); - const scratch = p.panes[p.active].?.serial; - try testing.expectEqual(tree.Status.ok, wr(p, Node.of(scratch, .look), try std.fmt.bufPrint(&line, "{s}/f.txt\n", .{at})).reply.status); - try testing.expect(p.paneBySerial(scratch) == null); - var want: [32]u8 = undefined; - const gone = try std.fmt.bufPrint(&want, "{d} ", .{scratch}); - var rows = std.mem.splitScalar(u8, rd(p, @intFromEnum(tree.TopFile.index), 0, 4096).bytes, '\n'); - while (rows.next()) |row| try testing.expect(!std.mem.startsWith(u8, row, gone)); + try testing.expectEqual(@as(usize, 0), p.col_n[p.ncol - 1]); + try testing.expectEqualStrings("", rd(p, @intFromEnum(tree.TopFile.focus), 0, 64).bytes); + try testing.expectEqual(tree.Status.ok, wr(p, @intFromEnum(tree.TopFile.look), try std.fmt.bufPrint(&line, "{s}/f.txt\n", .{at})).reply.status); + try testing.expectEqual(@as(usize, 1), p.col_n[p.ncol - 1]); + try testing.expectEqual(p.active, p.col_panes[p.ncol - 1][0]); } diff --git a/src/ninep/pane.zig b/src/ninep/pane.zig index 714a2566..99acf24b 100644 --- a/src/ninep/pane.zig +++ b/src/ninep/pane.zig @@ -593,11 +593,11 @@ pub fn appendErrors(p: *Pardes, id: usize, text: []const u8) ?usize { } const free = p.freeSlot() orelse return null; const content = p.gpa.dupe(u8, text) catch return null; - const np = panes.Output.open(p, free, dir, .errors, "", content) catch { + _ = panes.Output.open(p, free, dir, .errors, "", content) catch { p.gpa.free(content); return null; }; - exec.placeDoc(p, id, free, np); + exec.placeNew(p, id, id, free, .errors); return text.len; } diff --git a/src/ninep/tree.zig b/src/ninep/tree.zig index b3f3dde6..5ef69bb4 100644 --- a/src/ninep/tree.zig +++ b/src/ninep/tree.zig @@ -577,7 +577,7 @@ fn open(p: *Pardes, req: Req, target: Target) Reply { // closing it leaves the pane alone. .new => { const slot = p.freeSlot() orelse return Reply.fail(req.tag, E.NFILE); - p.newScratchBelow(p.active); + p.newScratchFor(p.active, .fs); const made = p.panes[slot] orelse return Reply.fail(req.tag, E.NFILE); return .{ .tag = req.tag, .handle = made.serial }; }, diff --git a/src/pardes.zig b/src/pardes.zig index 00843b78..bad512a9 100644 --- a/src/pardes.zig +++ b/src/pardes.zig @@ -1092,13 +1092,13 @@ test "Joincol folds the active column into its right neighbor, keeping its panes try std.testing.expectEqual(@as(usize, 2), p.ncol); p.active = 0; // the left column is current - layout.joinCol(p); + layout.joinCol(p, 0); try std.testing.expectEqual(@as(usize, 1), p.ncol); const lf = layout.findPane(p, 0) orelse return error.LostLeftPane; const rf = layout.findPane(p, right) orelse return error.LostRightPane; try std.testing.expectEqual(lf.col, rf.col); - layout.joinCol(p); // no right neighbor left: inert + layout.joinCol(p, 0); // no right neighbor left: inert try std.testing.expectEqual(@as(usize, 1), p.ncol); } @@ -1179,6 +1179,8 @@ test "first document fallback splits like Tty from the originating pane" { defer p.deinit(); const tty = try Pardes.init(std.testing.allocator, .{ .cols = width, .rows = 62, .shells = 3 }); defer tty.deinit(); + p.settings.placement = .pardes; + tty.settings.placement = .pardes; if (collapsed) { layout.toggleCollapse(p, from); layout.toggleCollapse(tty, from); @@ -1191,8 +1193,8 @@ test "first document fallback splits like Tty from the originating pane" { // The Look origin need not be the currently active pane. p.active = (from + 1) % 3; const free = p.freeSlot().?; - const doc = try p.openTutorView(free); - exec.placeDoc(p, from, free, doc); + _ = try p.openTutorView(free); + exec.placeNew(p, from, from, free, .doc); _ = exec.spawnTty(tty, from); p.sync(); tty.sync(); @@ -1215,9 +1217,10 @@ test "first document keeps its originating shell and only opens a column when it for ([_]u16{ 199, 200 }) |width| { const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = width, .rows = 32 }); defer p.deinit(); + p.settings.placement = .pardes; const shell = p.panes[0].?; - const doc = try p.openTutorView(1); - exec.placeDoc(p, 0, 1, doc); + _ = try p.openTutorView(1); + exec.placeNew(p, 0, 0, 1, .doc); p.sync(); try std.testing.expectEqual(shell, p.panes[0].?); try std.testing.expectEqual(@as(usize, 1), p.active); @@ -1233,6 +1236,112 @@ test "first document keeps its originating shell and only opens a column when it } } +test "acme placement: an empty active column takes the new pane whole" { + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 160, .rows = 32 }); + defer p.deinit(); + try std.testing.expectEqual(config.Runtime.Placement.acme, p.settings.placement); + p.newColumn(0); // its tag has the keyboard: it is the active column + tagline.exitHeader(p); + p.sync(); + // A Look from the shell's text still lands in the active column, as + // acme's makenewwindow puts it in activecol first (util.c:456). + _ = try p.openTutorView(1); + exec.placeNew(p, 0, 0, 1, .doc); + try std.testing.expectEqualSlices(usize, &.{1}, p.col_panes[1][0..p.col_n[1]]); + try std.testing.expectEqual(@as(usize, 1), p.active); + try std.testing.expectEqual(@as(?usize, 1), p.activeColumn()); + // Never a new column. + try std.testing.expectEqual(@as(usize, 2), p.ncol); +} + +test "acme placement: under a pane's text when it has many blank rows, else halving the biggest" { + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 60 }); + defer p.deinit(); + const top = p.active; + _ = try p.setTestFile("one\ntwo\nthree\n"); + p.sync(); + p.setActiveColumn(0); + // Most of the pane is blank: a document looked from it starts under its + // three lines (makenewwindow, util.c:482-486). + const second = p.freeSlot().?; + _ = try p.openTutorView(second); + exec.placeNew(p, top, top, second, .doc); + p.sync(); + const text_end = p.bodyTop(p.panes[top].?, p.rects[top]) + 3; + try std.testing.expectEqual(text_end, p.rects[second].y); + // Fill both with text: no blank space is big, so the biggest pane is + // halved. + const full = "x\n" ** 80; + for ([_]usize{ top, second }) |id| panes.File.setContent(p, &p.panes[id].?.file.?, try p.gpa.dupe(u8, full)); + p.sync(); + const big = if (p.rects[second].h >= p.rects[top].h) second else top; + const was = p.rects[big]; + const third = p.freeSlot().?; + _ = try p.openTutorView(third); + exec.placeNew(p, second, second, third, .doc); + p.sync(); + try std.testing.expectEqual(big, p.col_panes[0][layout.findPane(p, third).?.idx - 1]); + try std.testing.expectEqual(was.y + was.h / 2, p.rects[third].y); + try std.testing.expectEqual(was.y + was.h, p.rects[third].y + p.rects[third].h); +} + +test "acme placement: New and 9P's new take the bottom half of the last pane" { + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 40 }); + defer p.deinit(); + p.newScratchBelow(p.active); + const last = p.active; + p.sync(); + const was = p.rects[last]; + p.newScratchFor(last, .fs); + const made = p.active; + p.sync(); + try std.testing.expectEqual(layout.findPane(p, last).?.idx + 1, layout.findPane(p, made).?.idx); + try std.testing.expectEqual(was.y + was.h, p.rects[made].y + p.rects[made].h); + try std.testing.expect(p.rects[made].y > was.y + BOX_H); +} + +test "Placement pardes brings back the old rules, and says so in Config" { + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 40 }); + defer p.deinit(); + try std.testing.expect(p.executeBuiltinLine(p.active, "Placement pardes")); + try std.testing.expectEqual(config.Runtime.Placement.pardes, p.settings.placement); + const top = p.active; + p.sync(); + const was = p.rects[top]; + p.newScratchBelow(top); + p.sync(); + // Directly under the asking pane, as New always put it. + try std.testing.expectEqual(@as(usize, 1), layout.findPane(p, p.active).?.idx); + try std.testing.expectEqual(was.y + was.h, p.rects[p.active].y + p.rects[p.active].h); + try std.testing.expect(p.executeBuiltinLine(p.active, "Placement")); + try std.testing.expectEqual(config.Runtime.Placement.acme, p.settings.placement); +} + +test "dragging a column's only pane to another leaves that column in place, empty" { + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 160, .rows = 32 }); + defer p.deinit(); + p.newColumn(0); + p.newScratchIn(0, p.activeColumn().?); + const moved = p.active; + p.sync(); + const weights = p.col_weight; + const tag_serial = p.col_serial[1]; + layout.movePane(p, moved, p.col_x[0] + 4, p.rects[0].y + p.rects[0].h / 2); + p.sync(); + // acme's coldragwin: colclose then coladd (cols.c:516-517); the column + // left behind keeps its place, width and tag. + try std.testing.expectEqual(@as(usize, 2), p.ncol); + try std.testing.expectEqual(@as(usize, 0), p.col_n[1]); + try std.testing.expectEqual(tag_serial, p.col_serial[1]); + try std.testing.expectEqualDeep(weights, p.col_weight); + try std.testing.expectEqual(@as(usize, 2), p.col_n[0]); + // ...and a pane dragged into the empty column takes it whole. + layout.movePane(p, moved, p.col_x[1] + 4, p.screen_h / 2); + p.sync(); + try std.testing.expectEqualSlices(usize, &.{moved}, p.col_panes[1][0..p.col_n[1]]); + try std.testing.expectEqual(@as(usize, 1), p.col_n[0]); +} + test "pane defaults keep creation of scratch panes in column tags" { const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true }); defer p.deinit(); @@ -3047,7 +3156,7 @@ test "column tags follow their column through split and close" { try std.testing.expectEqualStrings("Left Find", tagline.columnTag(p, 0)); p.col_tags[1].own = try p.gpa.dupe(u8, "Right Grep"); p.active = p.col_panes[0][0]; - layout.joinCol(p); + layout.joinCol(p, 0); try std.testing.expectEqual(@as(usize, 1), p.ncol); try std.testing.expectEqualStrings("Right Grep", tagline.columnTag(p, 0)); } @@ -3056,7 +3165,8 @@ test "column tags render edit hover and scroll from the column edge" { const p = try Pardes.init(std.testing.allocator, .{ .cols = 80, .rows = 20, .tty_only = true }); defer p.deinit(); _ = try p.setTestFile("untouched\n"); - p.newScratchColumn(0); + p.newColumn(0); + p.newScratchIn(0, p.activeColumn().?); p.sync(); p.acknowledgePanelPresentation(&.{}); var frame = std.heap.ArenaAllocator.init(std.testing.allocator); @@ -3112,7 +3222,8 @@ test "column tag first-cell execution keeps New local to the clicked column" { const p = try Pardes.init(std.testing.allocator, .{ .cols = 80, .rows = 20, .tty_only = true }); defer p.deinit(); _ = try p.setTestFile("untouched\n"); - p.newScratchColumn(0); + p.newColumn(0); + p.newScratchIn(0, p.activeColumn().?); p.sync(); for (0..2) |column| { p.active = p.col_panes[1 - column][0]; @@ -3189,7 +3300,7 @@ test "tiny screens keep pane space before adding a column tag" { _ = try p.render(p.scratch.allocator()); } -test "ColumnTags reclaims the row and releases hidden header focus without losing commands" { +test "a screen too short for the column row releases a column tag's focus without losing its commands" { const p = try Pardes.init(std.testing.allocator, .{ .cols = 60, .rows = 12, .tty_only = true }); defer p.deinit(); const pane = try p.setTestFile("unchanged body\n"); @@ -3201,24 +3312,7 @@ test "ColumnTags reclaims the row and releases hidden header focus without losin p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = TAG_TEXT_INSET, .row = TOPBAR_H } }); try std.testing.expect(p.header_focus and p.header_column != null); - p.update(.{ .command = "ColumnTags" }); - try std.testing.expect(!p.settings.column_tags); - try std.testing.expectEqual(@as(u16, 0), p.columnBarHeight()); - try std.testing.expectEqual(TOPBAR_H, p.rects[0].y); - try std.testing.expectEqual(shown.h + COLBAR_H, p.rects[0].h); - try std.testing.expect(!p.header_focus and p.header_column == null); - try std.testing.expect(!p.header_drag); - try std.testing.expectEqualStrings("New Help", tagline.columnTag(p, 0)); - - p.update(.{ .command = "ColumnTags" }); - try std.testing.expect(p.settings.column_tags); - try std.testing.expectEqual(shown, p.rects[0]); - p.acknowledgePanelPresentation(&.{}); - p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = TAG_TEXT_INSET, .row = TOPBAR_H } }); - p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = TAG_TEXT_INSET, .row = TOPBAR_H } }); - try std.testing.expect(p.header_column != null); p.update(.{ .resize = .{ .cols = 60, .rows = 2 } }); - try std.testing.expect(p.settings.column_tags); try std.testing.expectEqual(@as(u16, 0), p.columnBarHeight()); try std.testing.expectEqual(TOPBAR_H, p.rects[0].y); try std.testing.expect(!p.header_focus and p.header_column == null); @@ -3268,15 +3362,17 @@ test "Enter in a header runs the word under its cursor, as the execute key does" p.global_tag.cur_col = @intCast(std.mem.indexOf(u8, config.topbar_str, "Newcol").?); p.update(.{ .key = .{ .cp = Key.enter } }); try std.testing.expectEqual(@as(usize, 2), p.ncol); - // and the header lets go of the keyboard, as a pane tag does - try std.testing.expect(!p.header_focus); + // and the workspace tag lets go of the keyboard: the new, empty + // column's tag has it + try std.testing.expect(p.header_focus and p.header_column.? == 1); } test "window keys walk from a pane up through the column and workspace tags and back" { const p = try Pardes.init(std.testing.allocator, .{ .cols = 100, .rows = 20, .tty_only = true }); defer p.deinit(); _ = try p.setTestFile("body\n"); - p.newScratchColumn(0); + p.newColumn(0); + p.newScratchIn(0, p.activeColumn().?); p.sync(); p.active = p.col_panes[0][0]; const window = struct { @@ -3563,6 +3659,7 @@ test "Newcol refuses an unsplittable restored weight before spawning" { const pane = p.panes[id].?; try p.deinitPane(pane); layout.removePane(p, id); + layout.dropColumn(p, id); p.panes[id] = null; } while (p.nextEffect()) |_| {} @@ -4099,9 +4196,15 @@ pub const Pardes = struct { look_walk_owner: ?u32 = null, /// hands out Pane.serial; monotonic, never reused next_serial: u32 = 0, - /// The pane (by serial) that joined a column this step; `replaceStillborn` - /// checks it once the step is over and nothing holds the column's panes. - stillborn_joiner: ?u32 = null, + /// The column whose tag the running command came from, while it runs: + /// the column acme's commands take from their Text's col. + exec_column: ?usize = null, + /// acme's activecol (dat.c:37), by column serial, 0 for none: the + /// column last typed in (acme.c:487), clicked in with the select button + /// (acme.c:659), dropped into by a grip (acme.c:640), or given a new + /// pane (util.c:467). Where the acme placement puts new panes + /// (exec.placeNew). A Look click moves the keyboard but not this. + active_column: u32 = 0, settings: config.Runtime = .{ .font = .{ .tagline_percent = config.gui_tagline_font_percent } }, locations_config: locations_config.Config = .{}, locations_cache: @import("locations_cache.zig").Cache = .{}, @@ -4347,10 +4450,12 @@ pub const Pardes = struct { p.panes[0].?.body.mode = .tty; p.oneColumn(); // A bare tty is still an editor: it opens with somewhere to put - // text under the shell. The shell keeps the keyboard. + // text under the shell. The shell keeps the keyboard. A boot + // layout, like .classic's, not a placement. if (p.boot == .tty) { - p.newScratchBelow(0); - p.active = 0; + const np = try p.newScratch(0, 1); + layout.insert(p, 0, 1, 1); + layout.splitBelow(p, 0, np); } }, .classic => { @@ -4469,7 +4574,7 @@ pub const Pardes = struct { /// The column tags' height: a row per line of the tallest one. pub fn columnBarHeight(p: *const Pardes) u16 { - if (!p.settings.column_tags or p.screen_h < 3) return 0; + if (p.screen_h < 3) return 0; var lines: usize = COLBAR_H; for (p.col_tags[0..p.ncol]) |t| if (t.own) |own| { lines = @max(lines, std.mem.count(u8, own, "\n") + 1); @@ -4609,34 +4714,56 @@ pub const Pardes = struct { return np; } - /// The empty pane that stands in for one that closed, keeping its column - /// alive and its directory. Unlike `newScratch` it inherits nothing: the - /// pane it replaces is on its way out. - fn newScratchIn(p: *Pardes, free: usize, dir: []const u8) !*Pane { - const content = try p.gpa.dupe(u8, ""); - errdefer p.gpa.free(content); - const np = try panes.Output.open(p, free, dir, .{ .cmd = .New }, "", content); - np.body.cur_pinned = true; - return np; - } - - /// New: a scratch below the calling pane, in its column. + /// New: an empty scratch in `from_id`'s directory, placed as exec.placeNew + /// places it. pub fn newScratchBelow(p: *Pardes, from_id: usize) void { - const free = p.freeSlot() orelse return; - const sf = layout.findPane(p, from_id) orelse return; - const np = p.newScratch(from_id, free) catch return; - layout.insert(p, sf.col, sf.idx + 1, free); - layout.splitBelow(p, from_id, np); - p.active = free; + p.newScratchFor(from_id, .scratch); } - /// Newcol: a scratch in a fresh column beside the calling pane. - pub fn newScratchColumn(p: *Pardes, from_id: usize) void { + /// A scratch for New (`.scratch`) or 9P's pane/new (`.fs`). + pub fn newScratchFor(p: *Pardes, from_id: usize, kind: exec.NewPane) void { const free = p.freeSlot() orelse return; - if (!layout.canSplitColumn(p, from_id)) return; _ = p.newScratch(from_id, free) catch return; - std.debug.assert(layout.splitColumn(p, from_id, free, false)); - p.active = free; + exec.placeNew(p, from_id, from_id, free, kind); + } + + /// Newcol: an empty column right of the calling pane's, the keyboard + /// on its tag, for the next pane made to fill. + pub fn newColumn(p: *Pardes, from_id: usize) void { + const col = p.keyboardColumn(from_id) orelse return; + const c = layout.insertColumn(p, col, false) orelse return; + tagline.enterHeader(p, c); + } + + pub fn setActiveColumn(p: *Pardes, c: usize) void { + if (c < p.ncol) p.active_column = layout.columnSerial(p, c); + } + + /// The active column, while it is still there. + pub fn activeColumn(p: *const Pardes) ?usize { + return layout.columnBySerial(p, p.active_column); + } + + /// The column the keyboard is in: its tag's, or its pane's. + pub fn noteTyped(p: *Pardes) void { + if (p.header_focus) { + if (p.header_column) |c| p.setActiveColumn(c); + } else if (layout.findPane(p, p.active)) |f| p.setActiveColumn(f.col); + } + + /// New, run from column `c`'s tag. + pub fn newScratchIn(p: *Pardes, from_id: usize, c: usize) void { + p.exec_column = c; + defer p.exec_column = null; + p.newScratchBelow(from_id); + } + + /// The column a command acts on: the one whose tag it came from, else + /// the one whose tag has the keyboard, else `id`'s. + pub fn keyboardColumn(p: *Pardes, id: usize) ?usize { + if (p.exec_column) |c| return c; + if (p.header_focus) if (p.header_column) |c| return c; + return if (layout.findPane(p, id)) |f| f.col else null; } pub fn freeSlot(p: *Pardes) ?usize { @@ -5088,10 +5215,6 @@ pub const Pardes = struct { look.cancelLookHover(p); const reply = ctlfs.handle(p, req); if (reply.status == .err and (req.op == .write or req.op == .setattr)) ctlfs.events.noteError(p, req, reply); - // A pane that joined a column holding only a stillborn scratch takes - // it now, before the answer: one read of index after the look shows - // the replacement done, and the log has its del with the new. - exec.replaceStillborn(p); // The request was a whole step of its own, so it settles the way a // step does: the cursor and scroll reconciled, the scripted panes // told, and the panes it made announced to /log now rather than at @@ -5103,7 +5226,6 @@ pub const Pardes = struct { } pub fn update(p: *Pardes, ev: Event) void { - defer exec.replaceStillborn(p); // A tick with nothing animating is the one event that cannot change // the screen. p.needs_frame = p.needs_frame or ev != .tick; @@ -5347,6 +5469,7 @@ pub const Pardes = struct { return; } const pane = p.panes[p.active] orelse return; + p.noteTyped(); // An open prompt takes the keys even when it answers for a header. const header = if (pane.prompt != .none) null else tagline.focusedHeader(p); if (header == null and pane.isTerminal() and pane.body.mode == .tty and pane.focus == .body and pane.prompt == .none) { @@ -5395,16 +5518,11 @@ pub const Pardes = struct { // global window ops (any mode): Alt-n new terminal below, Alt-c move // the active terminal into a fresh column if (hit(key, config.new_shell_below)) { - tagline.exitHeader(p); const free = p.freeSlot() orelse return; const nt = p.newShell(free, "") catch return; nt.greet = true; - const src = layout.splitParent(p, p.active); - const f = layout.findPane(p, src).?; - layout.insert(p, f.col, f.idx + 1, free); - layout.splitBelow(p, src, nt); - p.active = free; - p.stillborn_joiner = nt.serial; + // From a tag, as a 9P new is: acme's t->w == nil. + exec.placeNew(p, p.active, if (p.header_focus) null else p.active, free, .shell); return; } for (config.jump_keys) |jk| { @@ -5483,6 +5601,9 @@ pub const Pardes = struct { const b = config.wordBounds(shown, modal.selectionCursor(shown, range)); break :word shown[b.lo..b.hi]; }; + // A column tag's command acts on that column, empty or not. + p.exec_column = if (header != null) p.header_column else null; + defer p.exec_column = null; // Out of the tag or header FIRST: Del frees the pane, Kill // and Restore the whole session. if (header != null) tagline.exitHeader(p) else pane.focus = .body; @@ -5947,59 +6068,38 @@ pub const Pardes = struct { // ---- dump / load (acme-style: `pardes -l state.zon` restores a session) ---- /// Close a pane; its rows go to `to`, or where layout.absorbVWeight - /// sends them when that is null. Focus on it follows its rows: to the - /// pane that grew into them, or to the scratch left standing in an - /// emptied column. Every route that closes a pane comes through here or - /// removeColumn, so none picks focus for itself, and none by recency. + /// sends them when that is null. Focus on it follows its rows to the + /// pane that grew into them. A column outlives its panes, as acme's + /// does (cols.c:186): closing its last one leaves it empty, the keyboard + /// on its tag; only Delcol takes a column away. The session's last pane + /// closing ends the session. Every route that closes a pane comes + /// through here or removeColumn, so none picks focus for itself, and + /// none by recency. pub fn removePane(p: *Pardes, id: usize, to: ?usize) !void { const pane = p.panes[id] orelse return; - // A column outlives its panes. Closing the last one leaves an empty - // pane standing in its place and in its directory; only Delcol ever - // takes a column away. const place = layout.findPane(p, id); - const last_in_column = if (place) |f| p.col_n[f.col] == 1 else false; - var dir_buf: [limits.host_path_cap]u8 = undefined; - var dir: []const u8 = ""; - if (last_in_column) { - const had = paneDir(pane); - const n = @min(had.len, dir_buf.len); - @memcpy(dir_buf[0..n], had[0..n]); - dir = dir_buf[0..n]; - } + const emptied = if (place) |f| (if (p.col_n[f.col] == 1) f.col else null) else null; // Before anything is torn down, so a failure here changes nothing. try p.deinitPane(pane); - // ...and after it, so the stand-in inherits none of the closing pane. - const heir: ?usize = heir: { - if (!last_in_column) break :heir null; - const f = place.?; - const free = p.freeSlot() orelse break :heir null; - _ = p.newScratchIn(free, dir) catch break :heir null; - layout.insert(p, f.col, f.idx + 1, free); - break :heir free; - }; const gainer = layout.absorbVWeight(p, id, to); - const beside = if (last_in_column) p.besideColumn(place.?.col, id) else null; + const beside = if (emptied) |c| p.besideColumn(c, p.rects[id]) else null; layout.removePane(p, id); p.panes[id] = null; - if (p.active == id) p.active = heir orelse gainer orelse beside orelse p.anyPane() orelse { - p.quit = true; - p.emit(.quit); - return; - }; + if (p.active != id) return; + p.active = gainer orelse beside orelse p.anyPane() orelse return p.quitEmpty(); + if (emptied) |c| if (!p.header_focus) tagline.enterHeader(p, c); } - pub fn removeColumn(p: *Pardes, id: usize) !void { - const place = layout.findPane(p, id) orelse return; - const had_focus = layout.findPane(p, p.active); - const beside = if (had_focus != null and had_focus.?.col == place.col) - p.besideColumn(place.col, p.active) - else - null; + /// Delcol: close column `col` and every pane in it. + pub fn removeColumn(p: *Pardes, col: usize) !void { + if (col >= p.ncol) return; + const had_focus = p.keyboardColumn(p.active) == col; + const beside = if (had_focus) p.besideColumn(col, if (p.header_focus) null else p.rects[p.active]) else null; var ids: [MAX_PANES]usize = undefined; var parents: [MAX_PANES]*Pane = undefined; - const count = p.col_n[place.col]; + const count = p.col_n[col]; for (0..count) |i| { - ids[i] = p.col_panes[place.col][i]; + ids[i] = p.col_panes[col][i]; parents[i] = p.panes[ids[i]].?; } try p.detachCwds(parents[0..count]); @@ -6008,11 +6108,14 @@ pub const Pardes = struct { layout.removePane(p, closed); p.panes[closed] = null; } - if (p.panes[p.active] == null) p.active = beside orelse p.anyPane() orelse { - p.quit = true; - p.emit(.quit); - return; - }; + layout.dropColumn(p, col); + if (p.panes[p.active] == null) p.active = beside orelse p.anyPane() orelse return p.quitEmpty(); + } + + /// No pane is left: the session is over. + fn quitEmpty(p: *Pardes) void { + p.quit = true; + p.emit(.quit); } /// The pane Last should fall back to when the jumplist has nothing: the @@ -6031,14 +6134,13 @@ pub const Pardes = struct { return null; } - /// The pane that takes over `id`'s place when column `col` goes: in the - /// column layout.removePane gives the width to, the one level with the - /// middle of `id`. Asked before the column goes, while rects still hold. - fn besideColumn(p: *const Pardes, col: usize, id: usize) ?usize { + /// The pane that takes over the keyboard from column `col`: in the + /// column layout.dropColumn gives the width to, the one level with the + /// middle of `r` (of the screen without one). Asked while rects hold. + fn besideColumn(p: *const Pardes, col: usize, r: ?Rect) ?usize { if (p.ncol < 2) return null; const next = if (col > 0) col - 1 else col + 1; - const r = p.rects[id]; - const mid = r.y + r.h / 2; + const mid = if (r) |at| at.y + at.h / 2 else p.screen_h / 2; var pick: ?usize = null; for (p.col_panes[next][0..p.col_n[next]]) |k| { if (p.panes[k] == null) continue; @@ -6648,43 +6750,67 @@ test "a prompt is typed on its own line in the notice band and leaves the tag ro try std.testing.expect(pane.prompt == .none and pane.input.own == null); } -test "a stillborn pane gives its column to the first pane that joins it" { +test "Newcol makes an empty column, and the next pane made from its tag fills it" { if (platform == .web) return; const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 160, .rows = 40 }); defer p.deinit(); - try std.testing.expect(p.executeBuiltinLine(0, "Newcol")); - const blank = p.active; - p.sync(); // Tty splits by the rects a frame has laid out - try std.testing.expect(p.executeBuiltinLine(blank, "Tty")); + const first = p.active; + const panes_before = p.col_n[0]; + try std.testing.expect(p.executeBuiltinLine(first, "Newcol")); + try std.testing.expectEqual(@as(usize, 2), p.ncol); + try std.testing.expectEqual(@as(usize, 0), p.col_n[1]); + try std.testing.expectEqual(panes_before, p.col_n[0]); + // The keyboard is on the new column's tag; no pane has it. + try std.testing.expect(p.header_focus and p.header_column.? == 1); + try std.testing.expectEqual(first, p.active); + p.sync(); + try std.testing.expect(p.executeBuiltinLine(first, "Tty")); const shell = p.active; - p.update(.tick); // the step ends: the placeholder goes - try std.testing.expect(p.panes[blank] == null); - try std.testing.expectEqual(@as(usize, 1), p.col_n[layout.findPane(p, shell).?.col]); - try std.testing.expectEqual(shell, p.active); + try std.testing.expect(shell != first); + try std.testing.expectEqual(@as(usize, 1), p.col_n[1]); + try std.testing.expectEqual(shell, p.col_panes[1][0]); + try std.testing.expect(!p.header_focus); - // Typed into, body or tag, it is a pane like any other. - try std.testing.expect(p.executeBuiltinLine(shell, "Newcol")); - const typed = p.active; + // The next Tty splits as it always has: nothing is empty any more. p.sync(); - for ("ix") |c| p.update(.{ .key = .{ .cp = c, .text = &.{c} } }); - try std.testing.expect(p.executeBuiltinLine(typed, "Tty")); - p.update(.tick); - try std.testing.expect(p.panes[typed] != null); - try std.testing.expectEqual(@as(usize, 2), p.col_n[layout.findPane(p, typed).?.col]); - - try std.testing.expect(p.executeBuiltinLine(shell, "Newcol")); - const tagged = p.active; + try std.testing.expect(p.executeBuiltinLine(shell, "Tty")); + try std.testing.expectEqual(@as(usize, 2), p.col_n[1]); +} + +test "a column tag's command acts on that column" { + if (platform == .web) return; + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 160, .rows = 40 }); + defer p.deinit(); + const first = p.active; + try std.testing.expect(p.executeBuiltinLine(first, "Newcol")); + try std.testing.expect(p.executeBuiltinLine(first, "Newcol")); + try std.testing.expectEqual(@as(usize, 3), p.ncol); p.sync(); - try p.panes[tagged].?.appendTag(" make"); - try std.testing.expect(p.executeBuiltinLine(tagged, "Tty")); - p.update(.tick); - try std.testing.expect(p.panes[tagged] != null); + // New from the middle column's tag lands in it, not below `first`. + p.exec_column = 1; + try std.testing.expect(p.executeBuiltinLine(first, "New")); + p.exec_column = null; + try std.testing.expectEqual(@as(usize, 1), p.col_n[1]); + try std.testing.expectEqual(p.active, p.col_panes[1][0]); + // Delcol from the empty right column's tag closes that one. + p.exec_column = 2; + try std.testing.expect(p.executeBuiltinLine(first, "Delcol")); + p.exec_column = null; + try std.testing.expectEqual(@as(usize, 2), p.ncol); + try std.testing.expectEqual(@as(usize, 1), p.col_n[1]); + // A pane's own Delcol closes its column whatever tag has the keyboard. + try std.testing.expect(p.executeBuiltinLine(first, "Newcol")); + try std.testing.expect(p.header_focus); + try std.testing.expect(p.executeBuiltinLine(p.col_panes[1][0], "Delcol")); + try std.testing.expectEqual(@as(usize, 2), p.ncol); + try std.testing.expectEqual(@as(usize, 0), p.col_n[1]); } test "Del from a key asks which neighbour takes the rows; nothing else asks" { if (platform == .web) return; const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 80, .rows = 40 }); defer p.deinit(); + p.settings.placement = .pardes; // the neighbours below are what is under test var frame = std.heap.ArenaAllocator.init(std.testing.allocator); defer frame.deinit(); const top = p.active; @@ -6781,7 +6907,8 @@ test "focus on a closed pane goes to the pane that takes its place, not the one const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 120, .rows = 40 }); defer p.deinit(); const shell = p.active; - p.newScratchColumn(shell); + p.newColumn(shell); + p.newScratchIn(shell, p.activeColumn().?); const right = p.active; p.sync(); p.newScratchBelow(shell); @@ -6813,45 +6940,50 @@ test "focus on a closed pane goes to the pane that takes its place, not the one p.sync(); p.active = left_low; p.sync(); - try p.removeColumn(left_low); + try p.removeColumn(layout.findPane(p, left_low).?.col); p.sync(); try std.testing.expectEqual(right_low, p.active); } -test "closing the last pane in a column leaves an empty one in its place" { +test "closing the last pane in a column leaves the column empty, its tag focused" { if (platform == .web) return; const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 120, .rows = 24 }); defer p.deinit(); const shell = p.active; - p.newScratchColumn(shell); + p.newColumn(shell); + p.newScratchIn(shell, p.activeColumn().?); const lone = p.active; try std.testing.expect(lone != shell); try std.testing.expectEqual(@as(usize, 2), p.ncol); const at = layout.findPane(p, lone).?; try std.testing.expectEqual(@as(usize, 1), p.col_n[at.col]); - const had = try std.testing.allocator.dupe(u8, p.panes[lone].?.cwdSlice()); - defer std.testing.allocator.free(had); + p.sync(); try p.removePane(lone, null); p.sync(); - // The column outlives the pane: still two columns, and the one that was - // emptied holds a fresh empty pane in the same directory. + // The column outlives the pane, as acme's does: still two columns, the + // emptied one with no pane and the keyboard on its tag. try std.testing.expectEqual(@as(usize, 2), p.ncol); - try std.testing.expectEqual(@as(usize, 1), p.col_n[at.col]); - const heir = p.col_panes[at.col][0]; - try std.testing.expect(heir != lone); + try std.testing.expectEqual(@as(usize, 0), p.col_n[at.col]); try std.testing.expect(p.panes[lone] == null); - const hp = p.panes[heir].?; - try std.testing.expectEqualStrings("", hp.file.?.content); - try std.testing.expectEqualStrings(had, hp.cwdSlice()); - try std.testing.expectEqual(heir, p.active); + try std.testing.expect(p.header_focus and p.header_column.? == at.col); + try std.testing.expectEqual(shell, p.active); try std.testing.expect(!p.quit); + // Down from it goes nowhere: nothing is below. + try std.testing.expect(p.executeBuiltinLine(shell, "Down")); + try std.testing.expect(p.header_focus and p.header_column.? == at.col); + // ...and Delcol is what actually takes the column away. - try p.removeColumn(heir); + try p.removeColumn(at.col); p.sync(); try std.testing.expectEqual(@as(usize, 1), p.ncol); + try std.testing.expectEqual(shell, p.active); + + // The session's last pane closing ends it. + try p.removePane(shell, null); + try std.testing.expect(p.quit); } test "the bare tty startup opens a text pane under the shell, unfocused" { @@ -7017,6 +7149,7 @@ test "hopping between two panes does not grow the jump stack" { if (platform == .web) return; const gpa = std.testing.allocator; const p = try Pardes.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }); + p.settings.placement = .pardes; // two panes of room, not acme's fit to the doc's two lines defer p.deinit(); p.update(.{ .resize = .{ .cols = 80, .rows = 24 } }); p.update(.{ .key = .{ .cp = 'n', .alt = true } }); // a shell under the doc diff --git a/src/pdf_view.zig b/src/pdf_view.zig index 13c02231..58dd2c3c 100644 --- a/src/pdf_view.zig +++ b/src/pdf_view.zig @@ -2045,7 +2045,7 @@ pub fn openSections(core: *pardes.Pardes, id: usize) void { .serial = result.serial, .revision = result.file.?.revision, }; - exec.placeDoc(core, id, free, result); + exec.placeNew(core, id, id, free, .doc); layout.compute(core); core.active = id; pane.search_pane = free; diff --git a/src/surface.zig b/src/surface.zig index b6f41853..a0471e51 100644 --- a/src/surface.zig +++ b/src/surface.zig @@ -397,7 +397,9 @@ pub const Chrome = struct { /// The canonical interface: what a frame of pardes IS. The tty shell writes /// these cells to vaxis one-to-one; the SDL shells rasterize them. pub const Surface = struct { - pub const PointerShape = enum(u8) { arrow, link, target }; + /// `box` is acme's boxcursor, shown while a pane or a column is carried + /// by its grip (cols.c:485, rows.c:151). + pub const PointerShape = enum(u8) { arrow, link, target, box }; pointer_shape: PointerShape = .arrow, body_layers: [MAX_PANES]Layer = @splat(.{}), tag_layers: [MAX_TAG_LAYERS]Layer = @splat(.{}), diff --git a/src/tagline.zig b/src/tagline.zig index 59c51b4d..c04cbc66 100644 --- a/src/tagline.zig +++ b/src/tagline.zig @@ -321,6 +321,7 @@ pub fn enterHeader(p: *Pardes, column: ?usize) void { if (p.panes[p.active]) |pane| pane.focus = .body; p.header_focus = true; p.header_column = column; + if (column) |c| p.setActiveColumn(c); const t = focusedHeader(p) orelse return exitHeader(p); const text = edit.flatSurface(p, t) catch ""; const rows = modal.cursorLineCount(text); diff --git a/src/web/app.mjs b/src/web/app.mjs index 03829178..c053d663 100644 --- a/src/web/app.mjs +++ b/src/web/app.mjs @@ -42,7 +42,8 @@ export class DomRenderer { render() { const count = this.wasm.pardes_frame(); - this.root.style.cursor = this.wasm.pardes_pointer_shape() === 1 ? "pointer" : "text"; + const shape = this.wasm.pardes_pointer_shape(); + this.root.style.cursor = shape === 1 ? "pointer" : shape === 3 ? "move" : "text"; const cols = this.wasm.pardes_frame_cols(); const rows = this.wasm.pardes_frame_rows(); if (count !== cols * rows) throw new Error(`bad frame: ${count} cells for ${cols}x${rows}`); diff --git a/test/appearance_gallery.py b/test/appearance_gallery.py index 48c0ea1b..bc9a7570 100644 --- a/test/appearance_gallery.py +++ b/test/appearance_gallery.py @@ -78,8 +78,8 @@ def run(args): launch=launch, inherited=inherited, terminal=handles) as (client, _): source = next(serial for serial, tag in panes(client).items() if str(source_path) in tag) before = set(panes(client)) - command(client, source, 'Newcol') - right = require(wait_for(lambda: next((s for s in panes(client) if s not in before), None)), 'right column missing') + command(client, source, 'Newcol') # empty, its tag with the keyboard + right = int(client.read('/pane/new')) client.write(f'/pane/{right}/name', f'{root / "Review"}\n'.encode()) client.write(f'/pane/{right}/body', PREFERENCE_NOTES if args.theme_selector else NOTES, truncate=True) client.write(f'/pane/{right}/dirty', b'0\n') diff --git a/test/column_drag.zig b/test/column_drag.zig index 3aea4286..89508800 100644 --- a/test/column_drag.zig +++ b/test/column_drag.zig @@ -46,7 +46,6 @@ test "column grip drag moves only its interval and keeps tag caret with the colu defer p.deinit(); _ = try p.setTestFile("body\n"); p.presentation.enabled = false; - p.settings.column_tags = true; p.row_metrics = .{ .body_w = 10, .body_h = 20, .tagline_w = 5, .tagline_h = 10 }; for (0..3) |_| { try std.testing.expect(p.executeBuiltinLine(p.active, "New")); @@ -127,7 +126,6 @@ test "column grip is separate from compact text and the resize seam" { defer p.deinit(); _ = try p.setTestFile("body\n"); p.presentation.enabled = false; - p.settings.column_tags = true; p.row_metrics = .{ .body_w = 10, .body_h = 20, .tagline_w = 5, .tagline_h = 10 }; try std.testing.expect(p.executeBuiltinLine(0, "New")); try std.testing.expect(layout.splitColumn(p, p.active, p.active, false)); @@ -181,7 +179,6 @@ test "column grips stay blank, and muted across focus and hover until grabbed" { defer p.deinit(); _ = try p.setTestFile("left\n"); p.presentation.enabled = false; - p.settings.column_tags = true; p.row_metrics = .{ .body_w = 10, .body_h = 20, .tagline_w = 5, .tagline_h = 10 }; try std.testing.expect(p.executeBuiltinLine(0, "New")); try std.testing.expect(layout.splitColumn(p, p.active, p.active, false)); @@ -219,7 +216,6 @@ test "column grip dropped in its own place moves the column's left edge" { defer p.deinit(); _ = try p.setTestFile("body\n"); p.presentation.enabled = false; - p.settings.column_tags = true; try std.testing.expect(p.executeBuiltinLine(0, "New")); try std.testing.expect(layout.splitColumn(p, p.active, p.active, false)); p.update(.tick); @@ -284,7 +280,6 @@ test "column grip drag previews where the column lands, in the seam beside its r defer p.deinit(); _ = try p.setTestFile("body\n"); p.presentation.enabled = false; - p.settings.column_tags = true; for (0..2) |_| { try std.testing.expect(p.executeBuiltinLine(p.active, "New")); try std.testing.expect(layout.splitColumn(p, p.active, p.active, false)); diff --git a/test/column_tags.py b/test/column_tags.py index fe3a8699..ba638b7d 100644 --- a/test/column_tags.py +++ b/test/column_tags.py @@ -138,7 +138,10 @@ def run(args): before = panes(client) keys.click(*require(locate(client, 'Newcol', row=0), 'Newcol missing'), button=1) - right = require(wait_for(lambda: new_serial(client, before)), 'Newcol did not create its pane') + # Newcol makes an empty column and gives its tag the keyboard; the + # pane made next fills it. + require(wait_for(lambda: client.read('/focus').strip() == b''), 'Newcol did not focus its empty column') + right = int(client.read('/pane/new')) right_name = root / 'right.rs' client.write(f'/pane/{right}/name', f'{right_name}\n'.encode()) right_body = b'// Column-local scratch\nfn main() {\n let ready = true;\n}\n' diff --git a/test/gui-goldens.txt b/test/gui-goldens.txt index 38ca89e5..8e859fdc 100644 --- a/test/gui-goldens.txt +++ b/test/gui-goldens.txt @@ -8,11 +8,10 @@ 08-wide-glyph-edges 123a182b82a2a8c455291a5c89ccfa28e1f8ce9566172ca404c0b9c71dd33b48 09-collapsed-focus-tint ae66076fdfb0cab9a906b052df257deee5ba91a6274712d52a76d8a7adc5b415 10-tagbottom dd8ba0d3ecabf3420d000b0c9591a57278179cbd2a9060f849d283f3881d1847 -11-column-tags 6b1731d1611404597c96ad77f34c2d5cd5a81c1085ec68c6779388e07ce28614 -12-multiline-tag 1b9ccd331814dc76111470f18448b1ca192e1edc3d79ea6eee19a6a78a4b1831 -13-image a52e2cf9f238447d885692cba01e68ef7fdc6ae3fc7c8fe1e95c8463c85f519c -14-theme-ink cc2ea256ddda24e1c97871f75b71ddf62fa825bd02f5d1432592d05e478c707a -15-theme-acme-light 2bde8a2bdfada7f061217f52cb2272913fc0657dbfa1d7448e1852f321f8e3bf +12-multiline-tag 0edffadbabef48e5a7422ef8433ccf2552b9c812a352e30b32bb000aacad607d +13-image 91f9363493c9c1b9618426ef7362da469f5b051890a3128ef8c94cee6ae2bb06 +14-theme-ink 84440553176db695a9a8a82714e858c815ea31cd82a29760c4894b4675c3a2ed +15-theme-acme-light cd216282f477512284372f330709d0cde93d1f2fb6d9c4616ebb642f3ef5c129 16-debug 129ad6f5f85b0e60e81bc6e8e78434629ee751f49731cf2eb28fd0553efd914a -17-terminal 45a3d9f823ccf28a336ef6687c9c210f9fb05cc426c0fdee98bb0ebb2a957d42 -18-mid-transition 79f90fb247f75ab284fca147028ee18ea78e77a02a57203699fb423f4bcc02fb +17-terminal d958ca0182ddf360abd266e29c3934c6e251ed25f258f687597372369899eaea +18-mid-transition a35f460c8637c2183f37b3a5ac2e7bd34bdde708a52fa0f8dcdbf937627b125f diff --git a/test/gui_golden.py b/test/gui_golden.py index d97009c9..407b19cd 100644 --- a/test/gui_golden.py +++ b/test/gui_golden.py @@ -91,7 +91,7 @@ def run(args): config.mkdir(parents=True) # No linger: a dismissed message is gone, not caught part way, when a # scene settles. - (config / 'init').write_text('Shell /bin/sh\nTheme forge\nMessageLinger 0\n') + (config / 'init').write_text('Shell /bin/sh\nTheme forge\nMessageLinger 0\nPlacement pardes\n') source = root / 'shapes.zig' source.write_bytes(ZIG) notes = root / 'notes.txt' @@ -177,9 +177,6 @@ def run(args): client.write('/ctl', b'Tagbottom\n') scene('10-tagbottom') client.write('/ctl', b'Tagbottom\n') - client.write('/ctl', b'ColumnTags\n') - scene('11-column-tags') - client.write('/ctl', b'ColumnTags\n') client.write(f'/pane/{first}/tag', b' Second\nthird line of the tag') scene('12-multiline-tag') client.write(f'/pane/{first}/look', f'{image}\n'.encode()) diff --git a/test/panes.zig b/test/panes.zig index 40b4b6ba..9802432e 100644 --- a/test/panes.zig +++ b/test/panes.zig @@ -103,7 +103,6 @@ const TagLayerTests = struct { defer p.deinit(); _ = try p.setTestFile("body\n"); p.presentation.enabled = false; - p.settings.column_tags = true; p.row_metrics = .{ .body_w = 10, .body_h = 20, .tagline_w = 5, .tagline_h = 10 }; try std.testing.expect(p.executeBuiltinLine(0, "New")); const second = p.active; diff --git a/test/pdf.zig b/test/pdf.zig index 2699fe01..4cb8f3dd 100644 --- a/test/pdf.zig +++ b/test/pdf.zig @@ -343,7 +343,7 @@ test "PdfSections Look follows the exact owning PDF, not an equal path" { const duplicate_id = p.freeSlot() orelse return error.NoDuplicatePdfSlot; const duplicate = try panes.Pdf.openPane(p, duplicate_id, path, 0); - pardes.exec.placeDoc(p, 0, duplicate_id, duplicate); + pardes.exec.placeNew(p, 0, 0, duplicate_id, .doc); layout.compute(p); panes.Pdf.openSections(p, duplicate_id); const duplicate_output_id = duplicate.search_pane orelse return error.MissingDuplicatePdfSections; diff --git a/test/snapshots/argv.snap b/test/snapshots/argv.snap index 892f6b24..0d4c8f64 100644 --- a/test/snapshots/argv.snap +++ b/test/snapshots/argv.snap @@ -4,6 +4,8 @@ # argument becomes the cwd the shell spawns in lines notes.txt 8 file zmarker.txt x +# its clicks and goldens were laid out by the pardes placement rule +config Placement pardes start 31 100 wait 8000 $ stable 700 20000 diff --git a/test/snapshots/builtins.snap b/test/snapshots/builtins.snap index 8bf70f36..7810ebda 100644 --- a/test/snapshots/builtins.snap +++ b/test/snapshots/builtins.snap @@ -1,4 +1,6 @@ lines notes.txt 6 +# its clicks and goldens were laid out by the pardes placement rule +config Placement pardes start 67 120 notes.txt wait 8000 notes.txt stable 700 20000 diff --git a/test/snapshots/chordcut.snap b/test/snapshots/chordcut.snap index 56170cce..01fee1f7 100644 --- a/test/snapshots/chordcut.snap +++ b/test/snapshots/chordcut.snap @@ -11,6 +11,8 @@ lines g.txt 2 # unrelated right column untouched. Give the caller enough cells that the selected # `echo B''OO g.txt` remains one displayed row; this test is about chords, not # soft-wrap traversal. +# its clicks and goldens were laid out by the pardes placement rule +config Placement pardes start 31 120 -n 3 wait 8000 f.txt stable 700 20000 diff --git a/test/snapshots/cmdword.snap b/test/snapshots/cmdword.snap index 631fab8b..438d3ed5 100644 --- a/test/snapshots/cmdword.snap +++ b/test/snapshots/cmdword.snap @@ -23,6 +23,8 @@ file zzmark.txt x # the top of the body -- which would move every row this script clicks. The # verbs are what is under test here, not the announcement. config Verbose off +# its clicks and goldens were laid out by the pardes placement rule +config Placement pardes start 31 120 cmds.txt wait 8000 Newcol Joincol wait 8000 cmds.txt diff --git a/test/snapshots/delask.snap b/test/snapshots/delask.snap index 04bc850c..05f4b204 100644 --- a/test/snapshots/delask.snap +++ b/test/snapshots/delask.snap @@ -2,6 +2,8 @@ # pane's notice band, which one takes its rows: k above, j below, anything else # keeps the pane. A click, and DelAbove/DelBelow (Del k / Del j), never ask. file top.txt top-marker +# its clicks and goldens were laid out by the pardes placement rule +config Placement pardes start 36 100 top.txt wait 8000 top-marker stable 700 20000 diff --git a/test/snapshots/doccol.snap b/test/snapshots/doccol.snap index 2135c533..7855453c 100644 --- a/test/snapshots/doccol.snap +++ b/test/snapshots/doccol.snap @@ -17,6 +17,8 @@ file c.txt CCC # the top of the body -- which moves every row this script clicks. What the # verbs do is what is under test, not the announcement. config Verbose off +# its clicks and goldens were laid out by the pardes placement rule +config Placement pardes start 31 100 a.txt wait 8000 AAA stable 700 20000 diff --git a/test/snapshots/emptycol.golden b/test/snapshots/emptycol.golden new file mode 100644 index 00000000..bb41c028 --- /dev/null +++ b/test/snapshots/emptycol.golden @@ -0,0 +1,14 @@ +== snap newcol grid=100x24 cursor=53,1 +|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +| New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol +| /tmp/pardes-snap/emptycol/cwd/notes.txt Save Tt +| 1 one +| 2 two +== snap filled grid=100x24 cursor=54,5 +|2: /tmp/pardes-snap/emptycol/cwd/notes.txt Save Tt /tmp/pardes-snap/emptycol/cwd Tty+bash Save Mod +|3: 1 one ls +|4: 2 two notes.txt +== snap emptied grid=100x24 cursor=53,1 +|2: /tmp/pardes-snap/emptycol/cwd/notes.txt Save Tt +|3: 1 one +|4: 2 two diff --git a/test/snapshots/emptycol.snap b/test/snapshots/emptycol.snap new file mode 100644 index 00000000..edf61eed --- /dev/null +++ b/test/snapshots/emptycol.snap @@ -0,0 +1,22 @@ +# A column can hold no pane, as acme's can (cols.c:186). Newcol makes one +# empty, its tag over blank space and holding the keyboard; the next pane +# made while it is the active column fills it whole (makenewwindow, +# util.c:468-469); and a shell that exits there leaves it empty again, the +# keyboard back on its tag. +file notes.txt one\ntwo +config Verbose off +start 24 100 notes.txt +wait 8000 notes.txt +stable 700 20000 +key space c n +stable 400 5000 +snap newcol +key a-n +stable 700 15000 +snap filled +key c-b +stable 400 5000 +text exit +key enter +stable 700 10000 +snap emptied diff --git a/test/snapshots/filewatch.snap b/test/snapshots/filewatch.snap index 38b6ac8e..1579ad40 100644 --- a/test/snapshots/filewatch.snap +++ b/test/snapshots/filewatch.snap @@ -22,6 +22,8 @@ lines sub/s.txt 8 # the top of the body -- which moves every row this script clicks. What the # verbs do is what is under test, not the announcement. config Verbose off +# its clicks and goldens were laid out by the pardes placement rule +config Placement pardes start 31 210 -n 1 wait 8000 w.txt stable 700 20000 diff --git a/test/snapshots/find.snap b/test/snapshots/find.snap index fe1ecad3..82c68343 100644 --- a/test/snapshots/find.snap +++ b/test/snapshots/find.snap @@ -17,6 +17,8 @@ file sub/ZQMARK-beta.txt beta body file sub/nest/zqmark-gamma.txt gamma body file other.txt nothing to match here file .git/zqmark-hidden.txt hidden body +# its clicks and goldens were laid out by the pardes placement rule +config Placement pardes start 41 120 here.txt wait 8000 here.txt stable 700 20000 diff --git a/test/snapshots/fsearch.snap b/test/snapshots/fsearch.snap index b050f1db..aff3e37f 100644 --- a/test/snapshots/fsearch.snap +++ b/test/snapshots/fsearch.snap @@ -13,6 +13,8 @@ file g.txt l1\nMARK a\nl3\nl4\nl5\nMARK b\nl7\nl8\nl9\nMARK c\nl11\nl12 # the top of the body -- which moves every row this script clicks. What the # verbs do is what is under test, not the announcement. config Verbose off +# its clicks and goldens were laid out by the pardes placement rule +config Placement pardes start 31 180 -n 3 wait 8000 g.txt stable 700 20000 diff --git a/test/snapshots/grep.snap b/test/snapshots/grep.snap index 07777e67..207aedc6 100644 --- a/test/snapshots/grep.snap +++ b/test/snapshots/grep.snap @@ -21,6 +21,8 @@ config Verbose off # The stacked layout spends two rows on each hit, which puts the third one # below the fold of this results pane; the claim here is which hits there are. config LocationsConfig layout:inline +# its clicks and goldens were laid out by the pardes placement rule +config Placement pardes start 31 180 -n 3 wait 8000 a.txt stable 700 20000 diff --git a/test/snapshots/jumps.snap b/test/snapshots/jumps.snap index e4816f88..74dc5fd7 100644 --- a/test/snapshots/jumps.snap +++ b/test/snapshots/jumps.snap @@ -10,6 +10,8 @@ # Focus and position both show in the golden's `cursor=` header: that is the # ACTIVE pane's cursor, so each snap is named by where it should land. lines big.txt 200 +# its clicks and goldens were laid out by the pardes placement rule +config Placement pardes start 31 150 big.txt wait 8000 big.txt stable 700 20000 diff --git a/test/snapshots/layout-close.golden b/test/snapshots/layout-close.golden index a7d159b5..38985b40 100644 --- a/test/snapshots/layout-close.golden +++ b/test/snapshots/layout-close.golden @@ -43,6 +43,7 @@ |10: |11: |12: -== snap colclose grid=140x41 cursor=42,3 -|3: ls 1 ls +== snap colclose grid=140x41 cursor=38,1 +|2: /tmp/pardes-snap/layout-close/cw /tmp/pardes-snap/layout-close/cwd Tty+bash Save Mode Filter Collaps +|3: ls ls |4: marker.txt marker.txt diff --git a/test/snapshots/layout-close.snap b/test/snapshots/layout-close.snap index 4ae3e31f..b168eb2b 100644 --- a/test/snapshots/layout-close.snap +++ b/test/snapshots/layout-close.snap @@ -1,7 +1,9 @@ # every pane close hands its space to ONE sibling, the rest of the column # keeps its sizes: Alt-c move-out, tag Del, and shell exit (pty EOF); an -# emptied column hands its width to one neighbor +# emptied column stays, as acme's does, its tag over blank space file marker.txt x +# its clicks and goldens were laid out by the pardes placement rule +config Placement pardes start 41 140 -n 3 wait 8000 marker.txt stable 700 20000 @@ -49,8 +51,8 @@ text exit key enter stable 700 10000 snap exit -# exit the moved-out pane's shell: its column empties and returns its width to -# the source column it was carved from; the untouched right column stays put +# exit the moved-out pane's shell: its column stays where it was, empty, the +# keyboard on its tag; the other columns keep their widths press left 40 9 release left 40 9 stable 400 5000 diff --git a/test/snapshots/layout-open.snap b/test/snapshots/layout-open.snap index 04770f27..c67dcfa5 100644 --- a/test/snapshots/layout-open.snap +++ b/test/snapshots/layout-open.snap @@ -5,6 +5,8 @@ # unrelated pane (including the ones above the source) at its exact rectangle. dirmk sub file sub/f.txt echo 'TTY'OK +# its clicks and goldens were laid out by the pardes placement rule +config Placement pardes start 31 100 -n 3 wait 8000 sub stable 700 20000 diff --git a/test/snapshots/leader.snap b/test/snapshots/leader.snap index 78594a47..e8f42331 100644 --- a/test/snapshots/leader.snap +++ b/test/snapshots/leader.snap @@ -1,4 +1,6 @@ file cmds.txt Help +# its clicks and goldens were laid out by the pardes placement rule +config Placement pardes start 41 100 cmds.txt wait 8000 Newcol Joincol wait 8000 cmds.txt diff --git a/test/snapshots/lookpanes.snap b/test/snapshots/lookpanes.snap index 8ada3f1b..296570f7 100644 --- a/test/snapshots/lookpanes.snap +++ b/test/snapshots/lookpanes.snap @@ -24,6 +24,8 @@ file beta/bmark.txt both.txt\nb-marker # the top of the body -- which moves every row this script clicks. What the # verbs do is what is under test, not the announcement. config Verbose off +# its clicks and goldens were laid out by the pardes placement rule +config Placement pardes start 51 130 beta/bmark.txt wait 8000 b-marker stable 700 20000 diff --git a/test/snapshots/lookrange.snap b/test/snapshots/lookrange.snap index 50ef9ad3..ef04409e 100644 --- a/test/snapshots/lookrange.snap +++ b/test/snapshots/lookrange.snap @@ -18,6 +18,8 @@ file look.txt r.txt:3-5\nr.txt:7:4-9\nr.txt:3:2-5:3\nr.txt:8:6-99:9 # the top of the body -- which moves every row this script clicks. What the # verbs do is what is under test, not the announcement. config Verbose off +# its clicks and goldens were laid out by the pardes placement rule +config Placement pardes start 31 150 look.txt wait 8000 r.txt:3-5 stable 700 20000 diff --git a/test/snapshots/lsp-client.snap b/test/snapshots/lsp-client.snap index 541e7c7f..7b255bd8 100644 --- a/test/snapshots/lsp-client.snap +++ b/test/snapshots/lsp-client.snap @@ -9,6 +9,8 @@ # gr -> sorted rows, selecting the next occurrence; n/N continue there. file main.rs mod lib;\n\nfn main() {\n let x = add(1, 2);\n let y = add(3, 4);\n let _ = x + y;\n}\n file lib.rs // mock fixture\npub fn add(a: i32, b: i32) -> i32 {\n a + b\n}\n +# its clicks and goldens were laid out by the pardes placement rule +config Placement pardes start 25 100 main.rs wait 8000 add(1, 2) stable 700 20000 diff --git a/test/snapshots/lsp.snap b/test/snapshots/lsp.snap index b40484ee..68365527 100644 --- a/test/snapshots/lsp.snap +++ b/test/snapshots/lsp.snap @@ -11,6 +11,8 @@ # symbol from std — so these goldens do not encode this machine's stdlib # version or its install path. file a.zig const std = @import("std");\n\nfn helper(x: u32) u32 {\n return x + 1;\n}\n\npub fn main() void {\n _ = helper(41);\n}\n +# its clicks and goldens were laid out by the pardes placement rule +config Placement pardes start 41 120 a.zig wait 8000 helper stable 700 20000 diff --git a/test/snapshots/lspcomplete.snap b/test/snapshots/lspcomplete.snap index 53ce7ef9..dcdec45c 100644 --- a/test/snapshots/lspcomplete.snap +++ b/test/snapshots/lspcomplete.snap @@ -18,6 +18,8 @@ # script the only end-to-end coverage the feature has. file a.zig const Shade = enum {\n verdigris,\n cinnabar,\n};\n\nfn pick(s: Shade) u8 {\n return switch (s) {\n \n };\n}\n\n// note. see below\n file notes.txt abc.def ghi\n +# its clicks and goldens were laid out by the pardes placement rule +config Placement pardes start 41 120 a.zig wait 8000 verdigris stable 700 20000 diff --git a/test/snapshots/lsprelpath.snap b/test/snapshots/lsprelpath.snap index 247390fe..89b0e124 100644 --- a/test/snapshots/lsprelpath.snap +++ b/test/snapshots/lsprelpath.snap @@ -30,6 +30,8 @@ file sub/inner/tint.zig pub const Tint = enum {\n ochre,\n indigo,\n};\n file sub/parent.zig const shade = @import("../shade.zig");\n\npub fn pick(s: shade.Shade) u8 {\n return switch (s) {\n \n };\n}\n file sub/subdir.zig const tint = @import("inner/tint.zig");\n\npub fn hue(t: tint.Tint) u8 {\n return switch (t) {\n \n };\n}\n # ---- PARENT: outside the asking file's tree, so the row stays absolute ---- +# its clicks and goldens were laid out by the pardes placement rule +config Placement pardes start 35 100 sub/parent.zig wait 8000 fn pick stable 700 20000 diff --git a/test/snapshots/mini.snap b/test/snapshots/mini.snap index 4905c68d..ffa9d94e 100644 --- a/test/snapshots/mini.snap +++ b/test/snapshots/mini.snap @@ -1,5 +1,7 @@ file commands.txt @`Mini demo.zig` file demo.zig const greeting = "café λ 界 é";\n\npub fn choose(ok: bool) u32 {\n if (ok) return 42;\n return 7;\n}\n\n// space and color survive compression\nconst answer = choose(true);\n +# its clicks and goldens were laid out by the pardes placement rule +config Placement pardes start 23 90 commands.txt wait 8000 Mini demo.zig stable 400 10000 diff --git a/test/snapshots/nested.snap b/test/snapshots/nested.snap index c26b7cea..9c31fb00 100644 --- a/test/snapshots/nested.snap +++ b/test/snapshots/nested.snap @@ -1,6 +1,8 @@ dirmk nestdir file nestdir/inside-nested.txt marker file nested.txt hello-from-nested\nsecond-nested-line\n +# its clicks and goldens were laid out by the pardes placement rule +config Placement pardes start 31 100 wait 8000 $ stable 700 20000 diff --git a/test/snapshots/psearch.snap b/test/snapshots/psearch.snap index a46e2b9d..f32fdf75 100644 --- a/test/snapshots/psearch.snap +++ b/test/snapshots/psearch.snap @@ -12,6 +12,8 @@ # It splits BELOW the shell it came from: every snap below stays ONE column, # the shell's tag and the +Search tag both starting at x=0, thirty rows split # between them, and nothing shifts sideways. +# its clicks and goldens were laid out by the pardes placement rule +config Placement pardes start 31 140 wait 8000 Newcol Joincol stable 700 20000 diff --git a/test/snapshots/reflow.snap b/test/snapshots/reflow.snap index 7aac1e8c..4a2a5368 100644 --- a/test/snapshots/reflow.snap +++ b/test/snapshots/reflow.snap @@ -4,6 +4,8 @@ # integrity check panicked the whole app ("ViewportPinInsufficientRows"). # build.zig now pins the ghostty dependency at ReleaseSafe so those # development-only checks are off — the app's own safety checks are unchanged. +# its clicks and goldens were laid out by the pardes placement rule +config Placement pardes start 25 40 wait 8000 $ text printf 'y%.0s' $(seq 1 3000); echo do''ne diff --git a/test/snapshots/rsearch.snap b/test/snapshots/rsearch.snap index 30459488..a83d27c4 100644 --- a/test/snapshots/rsearch.snap +++ b/test/snapshots/rsearch.snap @@ -11,6 +11,8 @@ file code.txt run count_x now\nopen sub/dep.txt:3 here\ncount_x again\npick two # the top of the body -- which moves every row this script clicks. What the # verbs do is what is under test, not the announcement. config Verbose off +# its clicks and goldens were laid out by the pardes placement rule +config Placement pardes start 31 210 -n 1 wait 8000 code.txt stable 700 20000 diff --git a/test/snapshots/savepane.snap b/test/snapshots/savepane.snap index 58df13ef..39129347 100644 --- a/test/snapshots/savepane.snap +++ b/test/snapshots/savepane.snap @@ -7,6 +7,8 @@ # scratch asks for a path in its inherited dir and makes it a file"); none of # them can see it drawn, land on the tag rather than the message row, or show # what the pane becomes afterwards. That is what this script is for. +# its clicks and goldens were laid out by the pardes placement rule +config Placement pardes start 31 100 -n 1 wait 8000 Newcol Joincol stable 700 20000 diff --git a/test/snapshots/scrolloff.snap b/test/snapshots/scrolloff.snap index caed9d47..f99c7341 100644 --- a/test/snapshots/scrolloff.snap +++ b/test/snapshots/scrolloff.snap @@ -1,6 +1,8 @@ # scrolloff: keyboard motion keeps 3 context rows above/below the cursor, # clamped at file boundaries (cursor may reach the top/bottom body row there) lines g.txt 40 +# its clicks and goldens were laid out by the pardes placement rule +config Placement pardes start 12 210 -n 1 wait 8000 g.txt stable 700 20000 diff --git a/test/snapshots/splitparent.snap b/test/snapshots/splitparent.snap index 1fd4e935..e5595144 100644 --- a/test/snapshots/splitparent.snap +++ b/test/snapshots/splitparent.snap @@ -1,6 +1,8 @@ # a new pane never opens under a too-short parent: Alt-n from a tag-only pane # splits the tall sibling in its column instead; when NO pane could leave the # newcomer 2 body rows, the tallest one anywhere is split +# its clicks and goldens were laid out by the pardes placement rule +config Placement pardes start 31 100 -n 3 stable 700 20000 # shrink pane 0 (top-left) to just its tagline diff --git a/test/snapshots/stepgrain.snap b/test/snapshots/stepgrain.snap index 3c4d3e4c..323fda5c 100644 --- a/test/snapshots/stepgrain.snap +++ b/test/snapshots/stepgrain.snap @@ -21,6 +21,8 @@ dirmk sub file a.txt hello ZQMARK one\nsee also sub/b.txt for ZQMARK two file sub/b.txt ZQMARK inside sub run touch 'two words.txt' +# its clicks and goldens were laid out by the pardes placement rule +config Placement pardes start 31 150 a.txt wait 8000 hello ZQMARK stable 700 20000 diff --git a/test/snapshots/tagalign.snap b/test/snapshots/tagalign.snap index a77415d9..7a0c93ce 100644 --- a/test/snapshots/tagalign.snap +++ b/test/snapshots/tagalign.snap @@ -2,6 +2,8 @@ dirmk deep dirmk deep/nested-project-directory file deep/nested-project-directory/document.txt alpha\nbeta\ngamma +# its clicks and goldens were laid out by the pardes placement rule +config Placement pardes start 31 100 deep/nested-project-directory/document.txt wait 8000 Newcol Joincol wait 8000 document.txt diff --git a/test/snapshots/tagalign2col.snap b/test/snapshots/tagalign2col.snap index 0849ffae..353289d4 100644 --- a/test/snapshots/tagalign2col.snap +++ b/test/snapshots/tagalign2col.snap @@ -2,6 +2,8 @@ dirmk deep dirmk deep/proj file deep/proj/document.txt alpha\nbeta\ngamma +# its clicks and goldens were laid out by the pardes placement rule +config Placement pardes start 31 160 deep/proj/document.txt wait 8000 Newcol Joincol wait 8000 document.txt diff --git a/test/snapshots/tagbottom.snap b/test/snapshots/tagbottom.snap index 67bb2ead..c294a7b6 100644 --- a/test/snapshots/tagbottom.snap +++ b/test/snapshots/tagbottom.snap @@ -21,6 +21,8 @@ file bottom.txt ZZONE\nZZTWO # the top of the body -- which moves every row this script clicks. What the # verbs do is what is under test, not the announcement. config Verbose off +# its clicks and goldens were laid out by the pardes placement rule +config Placement pardes start 31 100 top.txt wait 8000 Newcol Joincol wait 8000 top.txt diff --git a/test/snapshots/tagnav.snap b/test/snapshots/tagnav.snap index f145480e..a0e06cd0 100644 --- a/test/snapshots/tagnav.snap +++ b/test/snapshots/tagnav.snap @@ -10,6 +10,8 @@ # carries its BODY mode as one character: ` ` normal, `^` insert, `$` tty. The # tag has a mode of its own, so the box never changes while a tag is used. file w.txt alpha\nbeta\ngamma +# its clicks and goldens were laid out by the pardes placement rule +config Placement pardes start 31 100 w.txt wait 8000 Newcol Joincol wait 8000 w.txt diff --git a/test/snapshots/themesel.snap b/test/snapshots/themesel.snap index 04a95d23..734b9fdd 100644 --- a/test/snapshots/themesel.snap +++ b/test/snapshots/themesel.snap @@ -16,6 +16,8 @@ # read with snapstyle, so this proves the generated themes are real data and # not just names in a list. lines t.txt 40 +# its clicks and goldens were laid out by the pardes placement rule +config Placement pardes start 31 100 t.txt wait 8000 t.txt stable 700 20000 diff --git a/test/snapshots/tinywin.snap b/test/snapshots/tinywin.snap index 3d22d583..388609e4 100644 --- a/test/snapshots/tinywin.snap +++ b/test/snapshots/tinywin.snap @@ -2,6 +2,8 @@ # every pane in a column at least one row, so `y` walked off the bottom and # renderPane got a rect outside the surface (assert). Panes that no longer fit # now get h = 0 and simply do not render until the window grows back. +# its clicks and goldens were laid out by the pardes placement rule +config Placement pardes start 31 100 wait 8000 $ key a-n diff --git a/test/snapshots/topbarexec.snap b/test/snapshots/topbarexec.snap index 516a23b3..9f62af46 100644 --- a/test/snapshots/topbarexec.snap +++ b/test/snapshots/topbarexec.snap @@ -14,6 +14,8 @@ # So both halves are pinned here, against the same live selection: the no-arg # builtin runs, and the arg-taking one still gets the word. file zmarkfile.txt hay ZQNEEDLE stack +# its clicks and goldens were laid out by the pardes placement rule +config Placement pardes start 21 90 -n 3 wait 8000 zmarkfile.txt stable 700 20000 diff --git a/test/snapshots/ttyhelp.snap b/test/snapshots/ttyhelp.snap index 24399848..59e73af2 100644 --- a/test/snapshots/ttyhelp.snap +++ b/test/snapshots/ttyhelp.snap @@ -1,6 +1,8 @@ # bare boot = tty mode: SPC belongs to the shell, so the topbar Help word is # the only route to the command list. Row 0 is not a pane, so a middle-click # there is dispatched before any pane's mode is consulted. +# its clicks and goldens were laid out by the pardes placement rule +config Placement pardes start 31 100 wait 8000 Newcol Joincol stable 700 20000 diff --git a/test/snapshots/ttylook.snap b/test/snapshots/ttylook.snap index 5b82bd89..6eecc419 100644 --- a/test/snapshots/ttylook.snap +++ b/test/snapshots/ttylook.snap @@ -9,6 +9,8 @@ lines big.txt 40 file plain.txt just text dirmk sub +# its clicks and goldens were laid out by the pardes placement rule +config Placement pardes start 31 120 -n 3 wait 8000 big.txt stable 700 20000 diff --git a/test/snapshots/ttyonly.snap b/test/snapshots/ttyonly.snap index 1008e084..85180b40 100644 --- a/test/snapshots/ttyonly.snap +++ b/test/snapshots/ttyonly.snap @@ -1,5 +1,7 @@ # --tty: a single fullscreen shell already in raw tty mode, prompts visible file t.txt x +# its clicks and goldens were laid out by the pardes placement rule +config Placement pardes start 31 100 --tty wait 8000 $ stable 700 20000 diff --git a/test/snapshots/ttytaken.snap b/test/snapshots/ttytaken.snap index a6ccb632..be0bad29 100644 --- a/test/snapshots/ttytaken.snap +++ b/test/snapshots/ttytaken.snap @@ -6,6 +6,8 @@ # the pager's screen changes. (From any pane but a terminal, an Exec always # runs as a command pane: exec.snap and cmdword.snap.) lines big.txt 40 +# its clicks and goldens were laid out by the pardes placement rule +config Placement pardes start 31 210 -n 1 wait 8000 big.txt stable 700 20000 diff --git a/test/snapshots/windownav.snap b/test/snapshots/windownav.snap index 66509e11..fc26896f 100644 --- a/test/snapshots/windownav.snap +++ b/test/snapshots/windownav.snap @@ -8,6 +8,8 @@ # `cursor=` header: that is the # ACTIVE pane's cursor, so each snap is named by the pane it should land in. file w.txt alpha\nbeta\ngamma +# its clicks and goldens were laid out by the pardes placement rule +config Placement pardes start 31 100 w.txt wait 8000 Newcol Joincol wait 8000 w.txt -- cgit v1.3 From 45a66bd1c062a5cf4d63b1df68e050b059cdfa1d Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 29 Sep 2026 02:23:59 -0300 Subject: The default Shell is $SHELL, else /bin/sh With no Shell set, pardes ran fish, which a box may not have and a user may not use. The default is now the user's login shell ($SHELL), else /bin/sh; an explicit Shell still overrides it. The tests pin their own shell (snapshots bash, the python suites /bin/sh or bash) and pass with SHELL unset; the Config report and docs say where the default comes from. Co-Authored-By: Claude Opus 5.5 --- .agents/skills/pardes-9p/SKILL.md | 2 +- docs/config.md | 3 ++- docs/fs.md | 2 +- src/Output.zig | 2 +- src/builtins.zig | 2 +- src/config.zig | 14 +++++++++++--- src/ninep/ctl.zig | 2 +- src/pardes.zig | 2 +- test/macos_e2e.swift | 2 +- test/output.zig | 3 ++- test/snapshot.zig | 5 +++-- test/snapshots/shellset.snap | 4 ++-- 12 files changed, 27 insertions(+), 16 deletions(-) (limited to 'src/Output.zig') diff --git a/.agents/skills/pardes-9p/SKILL.md b/.agents/skills/pardes-9p/SKILL.md index 61b117a5..0cd52715 100644 --- a/.agents/skills/pardes-9p/SKILL.md +++ b/.agents/skills/pardes-9p/SKILL.md @@ -149,7 +149,7 @@ the editor, not as a write error, so inspect the resulting pane, index, message or screen; only a malformed line fails the write itself. A word no builtin knows (a typo included) is a command line: written at a terminal at its prompt it is typed into that shell; from anywhere else it runs as a command -pane, a terminal whose child is the root ctl's `Shell` (fish unless set) +pane, a terminal whose child is the root ctl's `Shell` ($SHELL, else /bin/sh, unless set) running `-c` the line in the pane's directory, which ends showing `exit N` (a typo: `exit 127`) and logs `run ` and `exit ` -- `exec` reads back its serial, so follow `log` for the exit. The directory's next command reuses a finished diff --git a/docs/config.md b/docs/config.md index 40d0fb24..93190556 100644 --- a/docs/config.md +++ b/docs/config.md @@ -46,7 +46,8 @@ the browser still applies the compiled percentage to its DOM glyphs. The startup path is printed whether or not a file exists — that is usually when it is most useful — and is ordinary selectable text, so a right click on it opens the file. Shell follows the same requested/effective/pending model as -Font. `Compiled default shell` is the command built into the binary; `Shell +Font. `Default shell` is the one used while no `Shell` is set: `$SHELL`, the +user's login shell, else `/bin/sh`; an explicit `Shell` overrides it. `Shell effective (last spawn)` is the executable the native host really chose after installation lookup and fallback. A changed request remains pending until a terminal is spawned, because the core does not resolve native executables. diff --git a/docs/fs.md b/docs/fs.md index a93137bb..95ab4de0 100644 --- a/docs/fs.md +++ b/docs/fs.md @@ -304,7 +304,7 @@ same tree without leaving the process. is typed into that shell (and a terminal whose shell exits, `exit` typed or run, closes its pane). From anywhere else -- a file, a scratch, a tag, a terminal whose tty a program holds -- it runs as a command pane: a - terminal whose child is the root ctl's `Shell` (fish unless set) run + terminal whose child is the root ctl's `Shell` ($SHELL, else /bin/sh, unless set) run with `-c` and the line, in the pane's directory, with job control on (bash, sh, dash, zsh, ksh `-m`; fish `status job-control full`), which shows its output and then `exit N` (its tag reads ` () diff --git a/src/Output.zig b/src/Output.zig index 2f462fd1..ee932768 100644 --- a/src/Output.zig +++ b/src/Output.zig @@ -665,7 +665,7 @@ pub fn openConfig(p: *Pardes, id: usize) !void { .startup_config_path = p.opts.startup_config_path, .platform = @tagName(pardes.platform), .theme_name = p.theme().name, - .compiled_default_shell = config.default_shell, + .compiled_default_shell = config.defaultShell(), .gui_shader_source_mode = if (gui_shader_source_mode) |mode| mode.label() else diff --git a/src/builtins.zig b/src/builtins.zig index 8c6228c0..f7104a8c 100644 --- a/src/builtins.zig +++ b/src/builtins.zig @@ -399,7 +399,7 @@ test "Ligatures is a setting only in the shell that shapes text" { .startup_config_path = null, .platform = @tagName(pardes.platform), .theme_name = p.theme().name, - .compiled_default_shell = config.default_shell, + .compiled_default_shell = config.defaultShell(), .hover_delay_frames = null, .native_images = false, .capabilities = capabilities, diff --git a/src/config.zig b/src/config.zig index fb38e4dd..a59fe18d 100644 --- a/src/config.zig +++ b/src/config.zig @@ -345,7 +345,15 @@ test "wheel drift guard" { try std.testing.expect(wheelTick(&g, false)); } -pub const default_shell = "fish"; +/// The shell when no `Shell` is set: the user's login shell ($SHELL), as a +/// terminal would start, else /bin/sh. An explicit `Shell` overrides it. +pub fn defaultShell() []const u8 { + if (comptime pardes.hosted) if (std.c.getenv("SHELL")) |s| { + const shell = std.mem.span(s); + if (shell.len > 0) return shell; + }; + return "/bin/sh"; +} // Minimum file gutter width, including the space after the line number. pub const PREFIX_W: u16 = 5; @@ -1364,7 +1372,7 @@ pub const Runtime = struct { try out.writeAll("Startup config: no per-user config path\n"); try out.print( "Platform: {s}\n" ++ - "Compiled default shell: {s}\n", + "Default shell ($SHELL, else /bin/sh): {s}\n", .{ context.platform, context.compiled_default_shell }, ); if (context.gui_shader_source_mode) |mode| @@ -1719,7 +1727,7 @@ pub const Runtime = struct { "TaglineSize 82\n", "Startup config: /tmp/pardes/init\n", "Platform: gui\n", - "Compiled default shell: /bin/sh\n", + "Default shell ($SHELL, else /bin/sh): /bin/sh\n", "GUI shader source: live GLSL compiled during this build\n", "Look hover delay: 18 frames\n", "Native images: on\n", diff --git a/src/ninep/ctl.zig b/src/ninep/ctl.zig index 8a35c381..0ab63fbb 100644 --- a/src/ninep/ctl.zig +++ b/src/ninep/ctl.zig @@ -399,7 +399,7 @@ pub fn writeSettingsOf(p: *Pardes, s: *const config.Runtime, w: *std.Io.Writer) .theme => try w.print("{s} {s}\n", .{ word, if (s == &p.settings) p.theme().name else pardes.themes[s.theme].name }), .shell => { const chosen = s.shell.requested.get(); - try w.print("{s} {s}\n", .{ word, if (chosen.len > 0) chosen else config.default_shell }); + try w.print("{s} {s}\n", .{ word, if (chosen.len > 0) chosen else config.defaultShell() }); }, .font => { const requested = s.font.requested_name.get(); diff --git a/src/pardes.zig b/src/pardes.zig index a0b11566..f2791e33 100644 --- a/src/pardes.zig +++ b/src/pardes.zig @@ -4925,7 +4925,7 @@ pub const Pardes = struct { pub fn shellBin(p: *const Pardes) []const u8 { const selected = p.settings.shell.requested.get(); - return if (selected.len == 0) config.default_shell else selected; + return if (selected.len == 0) config.defaultShell() else selected; } pub fn acknowledgeShell(p: *Pardes, id: usize, executable: []const u8, prompt_marks: bool) void { diff --git a/test/macos_e2e.swift b/test/macos_e2e.swift index 5f172f9d..2b0eedad 100644 --- a/test/macos_e2e.swift +++ b/test/macos_e2e.swift @@ -1251,7 +1251,7 @@ private func buildWorld(stem: String) throws -> String { // sources $HOME/.bashrc (host_io.Shell) — so this is what pins the // prompt to `$ ` and keeps the developer's history out of the capture. try "PS1='$ '\nHISTFILE=\n".write(toFile: "\(home)/.bashrc", atomically: true, encoding: .utf8) - // ...and the config is not empty, because the DEFAULT shell is fish, whose + // ...and the config is not empty, because the DEFAULT shell is $SHELL (fish, say), whose // prompt carries a hostname and whose greeting carries a version. A golden // taken against that is a golden for one machine. try "Shell bash\n".write(toFile: "\(pardesConfig)/init", atomically: true, encoding: .utf8) diff --git a/test/output.zig b/test/output.zig index 419bcca2..f3e61e93 100644 --- a/test/output.zig +++ b/test/output.zig @@ -544,10 +544,11 @@ test "Config prints the startup path and refreshes its one output" { for ([_][]const u8{ "Startup config: " ++ path ++ "\n", "Theme orchard\n", - "Shell requested (new panes) " ++ config.default_shell ++ " (default)\n", "Shell effective (last spawn) (none)\n", "Shell pending on\n", }) |line| try std.testing.expect(std.mem.indexOf(u8, out.content, line) != null); + var default_line: [256]u8 = undefined; + try std.testing.expect(std.mem.indexOf(u8, out.content, try std.fmt.bufPrint(&default_line, "Shell requested (new panes) {s} (default)\n", .{config.defaultShell()})) != null); try std.testing.expectEqualStrings(config.config_buffer, std.fs.path.basename(out.path)); try std.testing.expectEqual(panes.Output.Origin{ .cmd = .Config }, out.output.?.from); diff --git a/test/snapshot.zig b/test/snapshot.zig index 2fa8e89c..c49e7645 100644 --- a/test/snapshot.zig +++ b/test/snapshot.zig @@ -562,8 +562,9 @@ fn runScript(arena: std.mem.Allocator, exe_z: [:0]const u8, script_path: []const // XDG directory that points outside this per-snapshot fake home. const config_home = try std.fmt.allocPrintSentinel(arena, "{s}/.config", .{home}, 0); _ = setenv("XDG_CONFIG_HOME", config_home, 1); - // ...and it is not empty: the DEFAULT shell is fish, whose prompt carries - // a hostname and whose greeting carries a version, so a golden taken + // ...and it is not empty: the DEFAULT shell is $SHELL, whatever this + // machine's user logs in with (fish's prompt carries a hostname and its + // greeting a version), so a golden taken // against it would be a golden for this machine. Every script here runs // bash — the .bashrc above pins its prompt to `$ ` — and the fish path is // covered by host_io.Shell's unit tests instead. This is an ordinary diff --git a/test/snapshots/shellset.snap b/test/snapshots/shellset.snap index d2bacf38..ef8b02b9 100644 --- a/test/snapshots/shellset.snap +++ b/test/snapshots/shellset.snap @@ -2,8 +2,8 @@ # here is the case that has to hold on a machine you did not set up: the name # resolves to nothing, and the pane opens anyway. # -# That is not a corner — it is the DEFAULT's failure mode. pardes ships -# `Shell fish` as the default, and a box without fish must still get a working +# That is not a corner — it is the DEFAULT's failure mode. pardes defaults +# to $SHELL, which may name a shell the box lacks, and it must still get a working # shell rather than a pane whose child dies at exec and shows one EOF. So the # lookup falls back, and this is the proof: a name nothing resolves to, and the # new pane still greets and lists like any other. -- cgit v1.3 From 9b623d635b79f97122f512153b974dfa434f85ab Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 29 Sep 2026 05:33:00 -0300 Subject: @p names a pane by its serial, as /index and the log do A +Search row for a pane with no path (a terminal's), a jump list row and a line-number look said @p, the pane's place in the core's table, which no client can see. They now say @p, and @p resolves a serial. Re-recorded by name, their diffs checked: jumps, ttylook and psearch (whose waits now say @p1) for @p, and with them argv, nested, reflow, tinywin, ttyhelp and ttyonly for the boot scratch now named /+New (the change before). Co-Authored-By: Claude Opus 5.5 --- src/Output.zig | 2 +- src/look.zig | 21 ++++++++++++++++++--- src/mouse.zig | 2 +- test/snapshots/argv.golden | 2 +- test/snapshots/jumps.golden | 4 ++-- test/snapshots/nested.golden | 6 +++--- test/snapshots/psearch.golden | 10 +++++----- test/snapshots/psearch.snap | 8 ++++---- test/snapshots/reflow.golden | 2 +- test/snapshots/tinywin.golden | 18 +++++++++--------- test/snapshots/ttyhelp.golden | 2 +- test/snapshots/ttylook.golden | 2 +- test/snapshots/ttyonly.golden | 4 ++-- 13 files changed, 49 insertions(+), 34 deletions(-) (limited to 'src/Output.zig') diff --git a/src/Output.zig b/src/Output.zig index ee932768..b32a40a2 100644 --- a/src/Output.zig +++ b/src/Output.zig @@ -499,7 +499,7 @@ pub fn openJumps(p: *Pardes, id: usize) !void { const loc: []const u8 = if (has_path) (if (jp.file) |f| f.path else pdf_path.?) else - std.fmt.bufPrint(&idbuf, config.pane_addr ++ "{d}", .{j.pane}) catch unreachable; + std.fmt.bufPrint(&idbuf, config.pane_addr ++ "{d}", .{jp.serial}) catch unreachable; const what: []const u8 = if (jp.file) |f| std.mem.trim(u8, modal.lineSlice(f.content, j.line -| 1), " \t\r") else if (jp.image) |iv| diff --git a/src/look.zig b/src/look.zig index 86238413..d53ac76a 100644 --- a/src/look.zig +++ b/src/look.zig @@ -360,7 +360,12 @@ pub fn resolve(p: ?*pardes.Pardes, word_raw: []const u8, cwd: []const u8, realbu for (word[config.pane_addr.len..]) |c| { if (!std.ascii.isDigit(c)) break; id = id *| 10 +| (c - '0'); - } else return .{ .pane = .{ .id = id, .at = pl.at } }; + } else { + // `@p`: the pane's serial, as /index and the log name + // it, not its slot; one that is not open names none. + const slot = if (p) |pp| (pp.paneBySerial(@intCast(@min(id, std.math.maxInt(u32)))) orelse MAX_PANES) else id; + return .{ .pane = .{ .id = slot, .at = pl.at } }; + } } for (config.url_schemes) |scheme| { @@ -635,7 +640,7 @@ pub fn runSearch(p: *Pardes, id: usize, pat_raw: []const u8, kind: Search, start const loc: []const u8 = if (has_path) std.fs.path.basename(pane.file.?.path) else - std.fmt.bufPrint(&idbuf, config.pane_addr ++ "{d}", .{id}) catch return error.PathTooLong; + std.fmt.bufPrint(&idbuf, config.pane_addr ++ "{d}", .{pane.serial}) catch return error.PathTooLong; const cl: usize = @intCast(@max(0, pane.body.cur_row)); const cc: usize = @intCast(@max(0, pane.body.cur_col)); for (lines, 0..) |ln, i| { @@ -1133,7 +1138,7 @@ fn canonicalLookLocation(p: *Pardes, id: usize, text: []const u8) ?[]const u8 { if (comptime pdf_enabled) if (pane.pdf) |doc| return locationText(p, doc.path, target.at); if (pane.image) |iv| return locationText(p, iv.path, target.at); var path: [32]u8 = undefined; - return locationText(p, std.fmt.bufPrint(&path, config.pane_addr ++ "{d}", .{target.id}) catch return null, target.at); + return locationText(p, std.fmt.bufPrint(&path, config.pane_addr ++ "{d}", .{pane.serial}) catch return null, target.at); }, } } @@ -1641,6 +1646,16 @@ test "Look copies its operand before releasing pointer selection storage" { try std.testing.expectEqual(.none, p.drag); } +test "@p names a pane by its serial, as /index does" { + const p = try Pardes.init(std.testing.allocator, .{ .cols = 60, .rows = 12 }); + defer p.deinit(); + const pane = try p.setTestFile("alpha\nbravo\n"); + var realbuf: [4096]u8 = undefined; + var word: [32]u8 = undefined; + const target = resolve(p, try std.fmt.bufPrint(&word, config.pane_addr ++ "{d}:2", .{pane.serial}), "/", &realbuf); + try std.testing.expectEqual(p.paneBySerial(pane.serial).?, target.pane.id); +} + test "Look ignores missing and out of bounds pane addresses" { const p = try Pardes.init(std.testing.allocator, .{ .cols = 60, .rows = 12 }); defer p.deinit(); diff --git a/src/mouse.zig b/src/mouse.zig index 0d1bfadd..cb5512ad 100644 --- a/src/mouse.zig +++ b/src/mouse.zig @@ -1032,7 +1032,7 @@ fn dragRelease(p: *Pardes, button: Mouse.Button) void { if (line >= 0) { pane.sel[b].state = .none; var buf: [48]u8 = undefined; - const target = std.fmt.bufPrint(&buf, "@p{d}:{d}", .{ s.id, @as(usize, @intCast(line)) + 1 }) catch return; + const target = std.fmt.bufPrint(&buf, "@p{d}:{d}", .{ pane.serial, @as(usize, @intCast(line)) + 1 }) catch return; exec.runBuiltin(p, config.look_cmd, s.id, "", target); return; } diff --git a/test/snapshots/argv.golden b/test/snapshots/argv.golden index ab143a88..e4d41d6c 100644 --- a/test/snapshots/argv.golden +++ b/test/snapshots/argv.golden @@ -20,7 +20,7 @@ | | | -| /+New Save Tty Collapse Del +| /tmp/pardes-snap/argv/cwd/+New Save Tty Collapse Del | 1 == snap filearg grid=100x31 cursor=7,3 |Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit diff --git a/test/snapshots/jumps.golden b/test/snapshots/jumps.golden index 96ba2cc5..764269ce 100644 --- a/test/snapshots/jumps.golden +++ b/test/snapshots/jumps.golden @@ -134,9 +134,9 @@ == snap jumplist grid=150x31 cursor=7,17 |3: 86 line 86 Jumplist ls |16: /tmp/pardes-snap/jumps/cwd/+Jumps Save Tty Collapse Del LocationsConfig -|17: 1 @p1:3:3 /tmp/pardes-snap/jumps/cwd +|17: 1 @p2:3:3 /tmp/pardes-snap/jumps/cwd |18: 2 /tmp/pardes-snap/jumps/cwd/big.txt:1:1 line 1 -|19: 3 @p1:3:3 /tmp/pardes-snap/jumps/cwd +|19: 3 @p2:3:3 /tmp/pardes-snap/jumps/cwd |20: 4 /tmp/pardes-snap/jumps/cwd/big.txt:100:1 line 100 |21: 5 |22: diff --git a/test/snapshots/nested.golden b/test/snapshots/nested.golden index e5244e71..9758c491 100644 --- a/test/snapshots/nested.golden +++ b/test/snapshots/nested.golden @@ -20,7 +20,7 @@ | | | -| /+New Save Tty Collapse Del +| /tmp/pardes-snap/nested/cwd/+New Save Tty Collapse Del | 1 == snap no-arg grid=100x31 cursor=4,7 |Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit @@ -44,7 +44,7 @@ | | | -| /+New Save Tty Collapse Del +| /tmp/pardes-snap/nested/cwd/+New Save Tty Collapse Del | 1 == snap dir-arg grid=100x31 cursor=4,8 |Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit @@ -68,5 +68,5 @@ | | | -| /+New Save Tty Collapse Del +| /tmp/pardes-snap/nested/cwd/+New Save Tty Collapse Del | 1 diff --git a/test/snapshots/psearch.golden b/test/snapshots/psearch.golden index 228096ba..1ac01c0d 100644 --- a/test/snapshots/psearch.golden +++ b/test/snapshots/psearch.golden @@ -20,18 +20,18 @@ | | | -| /+New Save Tty Collapse Del +| /tmp/pardes-snap/psearch/cwd/+New Save Tty Collapse Del | 1 == snap typing grid=140x31 cursor=139,3 |3: printf 'x MA''RK a\nzz\nx MA''RK b\nzz\nx MA''RK c\n' /MARK == snap results grid=140x31 cursor=7,4 |3: printf 'x MA''RK a\nzz\nx MA''RK b\nzz\nx MA''RK c\n' |10: /tmp/pardes-snap/psearch/cwd/+Search Save Tty Collapse Del LocationsConfig -|11: 1 @p0:2:3-6 +|11: 1 @p1:2:3-6 |12: 2 x MARK a -|13: 3 @p0:4:3-6 +|13: 3 @p1:4:3-6 |14: 4 x MARK b -|15: 5 @p0:6:3-6 +|15: 5 @p1:6:3-6 |16: 6 x MARK c |17: 7 == style results grid=140x31 @@ -56,7 +56,7 @@ |18: 0-0 d,#608269, 1-1 d,#0d1410, 2-6 #59675c,#0d1410, 7-139 d,#0d1410, |19: 0-0 d,#608269, 1-1 d,#0d1410, 2-6 #59675c,#0d1410, 7-139 d,#0d1410, |20: 0-0 d,#608269, 1-1 d,#0d1410, 2-6 #59675c,#0d1410, 7-139 d,#0d1410, -|21: 0-1 #ffffff,#496656, 2-2 d,#1d2824, 3-3 #b2c3b8,#1d2824, 4-7 #d3b0d9,#1d2824, 8-29 #b2c3b8,#1d2824, 30-139 d,#1d2824, +|21: 0-1 #ffffff,#496656, 2-2 d,#1d2824, 3-31 #b2c3b8,#1d2824, 32-35 #d3b0d9,#1d2824, 36-57 #b2c3b8,#1d2824, 58-139 d,#1d2824, |22: 0-0 d,#608269, 1-1 d,#0d1410, 2-6 #59675c,#0d1410, 7-139 d,#0d1410, |23: 0-0 d,#608269, 1-1 d,#0d1410, 2-6 #59675c,#0d1410, 7-139 d,#0d1410, |24: 0-0 d,#608269, 1-1 d,#0d1410, 2-6 #59675c,#0d1410, 7-139 d,#0d1410, diff --git a/test/snapshots/psearch.snap b/test/snapshots/psearch.snap index a46e2b9d..6e463119 100644 --- a/test/snapshots/psearch.snap +++ b/test/snapshots/psearch.snap @@ -1,7 +1,7 @@ # `/` search on a TERMINAL pane: the same tag input as a file pane, searching # the shell's own scrollback (the plain text view Look reads, prompt rows # hidden). Results land in a +Search OUTPUT BUFFER — a file pane with no file -# behind it, so its tag has no Save — and point at `@p0:LINE:COL-ENDCOL`, the +# behind it, so its tag has no Save — and point at `@p1:LINE:COL-ENDCOL` (the terminal's serial), the # look target that names a live pane, since a terminal has no path. n/N SELECT # the next/prev row in the buffer and open nothing; Enter — the look chord — # is what scrolls the terminal to that line of its scrollback and selects the @@ -31,12 +31,12 @@ stable 400 5000 text MARK stable 400 5000 snap typing -# Enter opens the results buffer — three @p0:LINE:COL rows — and goes to the +# Enter opens the results buffer — three @p1:LINE:COL rows — and goes to the # first of them: the terminal's cursor lands on that scrollback line, on the # matched SPAN (cols 3..6, past the leading "x ") — not the start of the line, # and selected rather than merely parked on. No `n` was pressed to get here. key enter -wait 10000 @p0:2:3 +wait 10000 @p1:2:3 stable 700 15000 snap results snapstyle results @@ -83,6 +83,6 @@ key c-b stable 600 8000 press right 5 5 release right 5 5 -wait 10000 @p0:2:3 +wait 10000 @p1:2:3 stable 700 15000 snap rightsearch diff --git a/test/snapshots/reflow.golden b/test/snapshots/reflow.golden index ab8bfe9b..afd4b93f 100644 --- a/test/snapshots/reflow.golden +++ b/test/snapshots/reflow.golden @@ -16,5 +16,5 @@ | yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy | yyyyyyyyyyyyyyyyyyyyyyyyyyyyyydone | $ -| /+New Save Tty Collapse Del +| /tmp/pardes-snap/reflow/cwd/+New Save Tty Collapse Del | 1 diff --git a/test/snapshots/tinywin.golden b/test/snapshots/tinywin.golden index d24ab0c5..c847a2f1 100644 --- a/test/snapshots/tinywin.golden +++ b/test/snapshots/tinywin.golden @@ -20,13 +20,13 @@ | | | -| /+New Save Tty Collapse Del +| /tmp/pardes-snap/tinywin/cwd/+New Save Tty Collapse Del | 1 == snap shrunk grid=60x4 cursor=59,3 |Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor | New Tty Find Grep Joincol Delcol |$ /tmp/pardes-snap/tinywin/cwd Tty+bash Save Mode Filter Co -| /+New Save Tty Collapse Del +| /tmp/pardes-snap/tinywin/cwd/+New Save Tty Collapse Del == snap columns grid=100x31 cursor=23,3 |Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit | New Tty Find Grep Joincol Delcol @@ -49,7 +49,7 @@ | | | -| /+New Save Tty Collapse Del +| /tmp/pardes-snap/tinywin/cwd/+New Save Tty Collapse Del | 1 == snap narrow grid=4x31 cursor=2,20 |Newc @@ -74,10 +74,10 @@ | cn | | / -| + -| N -| e -| w -| -| S +| t +| m +| p +| / +| p | a +| r diff --git a/test/snapshots/ttyhelp.golden b/test/snapshots/ttyhelp.golden index cd7cb946..8b8d4195 100644 --- a/test/snapshots/ttyhelp.golden +++ b/test/snapshots/ttyhelp.golden @@ -20,7 +20,7 @@ | | | -| /+New Save Tty Collapse Del +| /tmp/pardes-snap/ttyhelp/cwd/+New Save Tty Collapse Del | 1 == snap helped grid=100x31 cursor=7,6 |5: /tmp/pardes-snap/ttyhelp/cwd/+Help Save Tty Collapse Del diff --git a/test/snapshots/ttylook.golden b/test/snapshots/ttylook.golden index ceb32b50..f7a5dc0f 100644 --- a/test/snapshots/ttylook.golden +++ b/test/snapshots/ttylook.golden @@ -66,6 +66,6 @@ == snap fileopen grid=120x31 cursor=3,4 |22: /tmp/pardes-snap/ttylook/cwd/+Search Save Tty Collapse De |23: l LocationsConfig -|24: 1 @p0:1:1-2 +|24: 1 @p1:1:1-2 |25: 2 ls |26: 3 diff --git a/test/snapshots/ttyonly.golden b/test/snapshots/ttyonly.golden index 8c201176..784de4cb 100644 --- a/test/snapshots/ttyonly.golden +++ b/test/snapshots/ttyonly.golden @@ -20,7 +20,7 @@ | | | -| /+New Save Tty Collapse Del +| /tmp/pardes-snap/ttyonly/cwd/+New Save Tty Collapse Del | 1 == style ttyonly grid=100x31 |0: 0-70 #b2c3b8,#1d2824, 71-99 d,#1d2824, @@ -44,7 +44,7 @@ |18: 0-0 d,#608269, 1-1 d,#0d1410, 2-99 #e5eee5,#0d1410, |19: 0-0 d,#608269, 1-1 d,#0d1410, 2-99 #e5eee5,#0d1410, |20: 0-0 d,#608269, 1-1 d,#0d1410, 2-99 #e5eee5,#0d1410, -|21: 0-1 #ffffff,#496656, 2-2 d,#1d2824, 3-3 #b2c3b8,#1d2824, 4-7 #d3b0d9,#1d2824, 8-29 #b2c3b8,#1d2824, 30-99 d,#1d2824, +|21: 0-1 #ffffff,#496656, 2-2 d,#1d2824, 3-31 #b2c3b8,#1d2824, 32-35 #d3b0d9,#1d2824, 36-57 #b2c3b8,#1d2824, 58-99 d,#1d2824, |22: 0-0 d,#608269, 1-1 d,#0d1410, 2-6 #59675c,#0d1410, 7-99 d,#0d1410, |23: 0-0 d,#608269, 1-1 d,#0d1410, 2-6 #59675c,#0d1410, 7-99 d,#0d1410, |24: 0-0 d,#608269, 1-1 d,#0d1410, 2-6 #59675c,#0d1410, 7-99 d,#0d1410, -- cgit v1.3 From c8bcda00ad54e4f81cc83ffe601d49703f4a7135 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 29 Sep 2026 10:18:23 -0300 Subject: ThemeSel in sections: acme and lapis with the current themes, helix and dark as legacy, a section per ported family The picker's headings come from colors.theme_groups instead of one split at native_theme_count, so acme (current, matched to plan9port acme's source) no longer sits under a legacy heading. Ring order follows the sections: the fifteen pardes palettes, acme, lapis, the faithful ports a family at a time, then helix and dark, then the imports. An imported theme whose name a port takes gets _helix, as zed's carry _zed. --- docs/config.md | 12 ++++++--- docs/themes.md | 32 +++++++++++++++++++--- src/Output.zig | 5 ++-- src/colors.zig | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--- test/output.zig | 32 +++++++++++++++++----- 5 files changed, 143 insertions(+), 21 deletions(-) (limited to 'src/Output.zig') diff --git a/docs/config.md b/docs/config.md index 59883b59..0c11b206 100644 --- a/docs/config.md +++ b/docs/config.md @@ -109,11 +109,15 @@ project gains or loses a file. A name that is not in the ring is ignored. The fifteen [native Pardes themes](themes.md) lead the ring: `orchard` (the default), `dusk`, `ink`, `paper`, `daybreak`, `atelier`, `forge`, `lagoon`, `solarium`, `spectrum`, `harvest`, `clay`, `forge_black`, `forge_soft`, and -`orchard_black`. `ThemeSel` lists them first under Pardes themes, followed by -a separate legacy/imported section. They add coordinated +`orchard_black`, then `acme` and `lapis`. `ThemeSel` lists them first under +Pardes themes. They add coordinated focus, search, diagnostic and terminal colors; `ink` and `daybreak` are high -contrast dark and light options. The original `helix`, `dark` and `acme` -themes and all imported names remain available. +contrast dark and light options. After them come the +[faithful ports](themes.md#faithful-ports) of well-known themes, a section per +family, then the legacy `helix` and `dark`, then everything imported. Where a +port takes an imported theme's name (`dracula`), the imported one gains +`_helix` (`dracula_helix`), as zed's carry `_zed`. `NextColor` walks the same +ring in the same order. `FocusTint` toggles the focused pane and column tag tints; it is on by default. Workspace, column and pane command text can be edited directly; see diff --git a/docs/themes.md b/docs/themes.md index 38596819..9c8e91a5 100644 --- a/docs/themes.md +++ b/docs/themes.md @@ -6,9 +6,10 @@ terminals together. `orchard` is the initial theme. Execute `Theme ` anywhere, or open `ThemeSel` with `SPC t t` and select a theme's command. Put the same command in your [startup configuration](config.md) to keep a preference. `NextColor` cycles through the native themes first, -then the retained `helix`, `dark` and `acme` themes and imported palettes. -`ThemeSel` groups the new palettes under `Pardes themes`, followed by -`Legacy and imported themes`; its navigation skips the section headings. +then `acme` and `lapis`, the [faithful ports](#faithful-ports), the legacy +`helix` and `dark`, and the imported palettes. `ThemeSel` shows the same +order in sections: `Pardes themes`, one per ported family, `Legacy themes` +and `Imported themes (helix, zed)`; its navigation skips the section headings. See the [Agave visual review](ui-review.md) for the original six-palette gallery. | Theme | Character | Page | Accent | @@ -58,7 +59,8 @@ Their local references are `vendor/themes/dark_plus.toml`, `material_oceanic.toml` (and its `material_deep_ocean.toml` parent), `solarized_dark.toml`, `monokai_pro.toml`, `autumn.toml`, and the Gruvbox Dark entry in `gruvbox.json`. The original imported themes remain selectable under -their existing names; the adaptations have distinct Pardes names and do not +their existing names (one a [faithful port](#faithful-ports) now holds gains +`_helix`, as in `dracula_helix`); the adaptations have distinct Pardes names and do not claim upstream affiliation. Existing vendor provenance and licenses remain with those sources. @@ -81,6 +83,28 @@ no more than 1.6:1, keeping focus changes quiet. ANSI black is exempt because ap also use it as a background. These are palette checks, not a guarantee about arbitrary terminal escape sequences, reversed colors or shader effects. +## Faithful ports + +These are well-known themes taken as close to their originals as pardes can +draw them: every colour the original has (page, text, selection, syntax, line +numbers, diagnostics, terminal ANSI) is its own, read out of the original's +files, and each theme file cites the file and line of every value. The loose +adaptations above (`forge`, `solarium`, `spectrum`, ...) stay as they are. + +pardes has one colour each for keywords, strings, numbers and comments, so a +theme that splits a kind (VS Code's control-flow keywords) keeps its main +one. A pane's tag is the original's window bar (vim's `StatusLine` and +`StatusLineNC`, emacs's `mode-line` and `mode-line-inactive`) or, in a tabbed +editor, its tab. What the original lacks (grips, a scroll column) comes from +its own palette. Where a chrome colour misses one of pardes's floors (rules +1.5:1 off the page, the focused tag 1.5:1 off the unfocused one on a dark +page and 1.25:1 on a light one, tag text 4.5:1), only that chrome colour +moves, just far enough, and the file's header says so. Text, syntax and ANSI +are never adjusted. + +| Family | Themes | Source | +| --- | --- | --- | + ## Make a theme your own Run `DumpThemes` to export complete `.zon` files below the configuration diff --git a/src/Output.zig b/src/Output.zig index b32a40a2..553dcc95 100644 --- a/src/Output.zig +++ b/src/Output.zig @@ -522,10 +522,9 @@ pub fn openJumps(p: *Pardes, id: usize) !void { pub fn openThemes(p: *Pardes, id: usize) !void { var out: std.Io.Writer.Allocating = .init(p.gpa); errdefer out.deinit(); - try out.writer.writeAll("# Pardes themes\n"); for (pardes.themes, 0..) |t, i| { - if (i == pardes.native_theme_count) - try out.writer.writeAll("\n# Legacy and imported themes\n"); + if (pardes.colors.groupAt(i)) |title| + try out.writer.print("{s}# {s}\n", .{ if (i == 0) "" else "\n", title }); try out.writer.print(comptime config.Runtime.findAction(.theme).?.word ++ " {s}\n", .{t.name}); } const content = try out.toOwnedSlice(); diff --git a/src/colors.zig b/src/colors.zig index 8319a112..743a74d7 100644 --- a/src/colors.zig +++ b/src/colors.zig @@ -105,6 +105,25 @@ test "every native theme's separators stand off its page, and its focus tint off } } +test "every faithful port meets pardes's chrome floors in its own colours, with nothing left to derive" { + const first = comptime indexOfTheme("lapis") + 1; + const last = comptime indexOfTheme("helix"); + for (themes[first..last]) |*th| { + const chrome = ChromeTheme.fromTheme(th); + const page = th.bg.?; + // Written out already adjusted: the run-time lift and push leave + // the file's own values, so what the file says is what is drawn. + try std.testing.expectEqual(th.border.?, chrome.border); + try std.testing.expectEqual(th.tag_active_bg.?, chrome.tag_active_bg); + try std.testing.expect(contrast(th.border.?, page) >= separator_floor); + try std.testing.expect(contrast(th.tag_active_bg.?, th.tag_bg) >= focusTintFloor(th)); + try std.testing.expect(contrast(th.tag_fg, th.tag_bg) >= 4.5); + try std.testing.expect(contrast(th.tag_active_fg.?, th.tag_active_bg.?) >= 4.5); + try std.testing.expect(contrast(th.box_dim, th.tag_bg) >= 1.5); + try std.testing.expect(th.palette != null); + } +} + test "a derived separator or tint keeps the theme's own when it already stands off" { const forge = &themes[for (themes[0..native_count], 0..) |t, i| { if (std.mem.eql(u8, t.name, "forge")) break i; @@ -303,10 +322,13 @@ const curated = struct { pub const forge_black = @import("themes/forge_black.zig"); pub const forge_soft = @import("themes/forge_soft.zig"); pub const orchard_black = @import("themes/orchard_black.zig"); - pub const helix = @import("themes/helix.zig"); - pub const dark = @import("themes/dark.zig"); pub const acme = @import("themes/acme.zig"); pub const lapis = @import("themes/lapis.zig"); + // Faithful ports of well-known themes, a family at a time (src/themes/ + // .zig says where each value came from): `theme_groups`. + // The legacy pair last. + pub const helix = @import("themes/helix.zig"); + pub const dark = @import("themes/dark.zig"); }; fn fold(comptime C: type) [@typeInfo(C).@"struct".decls.len]Theme { @@ -338,10 +360,65 @@ fn fold(comptime C: type) [@typeInfo(C).@"struct".decls.len]Theme { } } -pub const themes = fold(curated) ++ fold(@import("generated_themes")); +/// The imported themes (tools/gen_themes.zig), less any name one of ours +/// takes: a faithful port (`dracula`) keeps the plain name, and helix's +/// looser copy of it is still there as `dracula_helix` (the zed ones already +/// carry `_zed`). +fn foldImports(comptime ours: anytype, comptime C: type) [@typeInfo(C).@"struct".decls.len]Theme { + comptime { + @setEvalBranchQuota(400000); + var out = fold(C); + for (&out) |*g| for (ours) |c| if (std.mem.eql(u8, c.name, g.name)) { + g.name = g.name ++ "_helix"; + }; + return out; + } +} + +pub const themes = fold(curated) ++ foldImports(fold(curated), @import("generated_themes")); /// The first `native_count` of `themes` are pardes's own; the rest imported. pub const native_count = @typeInfo(curated).@"struct".decls.len; +/// The picker's sections (`ThemeSel`), in ring order, each running from +/// the theme it names to the next section's; `NextColor` and `Theme` still +/// see one flat ring. The current pardes themes, then the faithful ports a +/// family at a time, then the legacy pair (`helix`, captured from an old +/// helix setup and the boot default before orchard; `dark`, the host +/// terminal's own ground), then everything imported. +pub const ThemeGroup = struct { title: []const u8, first: []const u8 }; +const theme_groups = [_]ThemeGroup{ + .{ .title = "Pardes themes", .first = "orchard" }, + .{ .title = "Legacy themes", .first = "helix" }, +}; + +fn indexOfTheme(comptime name: []const u8) usize { + return comptime blk: { + @setEvalBranchQuota(100000); + for (themes[0..native_count], 0..) |t, i| if (std.mem.eql(u8, t.name, name)) break :blk i; + @compileError("theme_groups names " ++ name ++ ", which is not one of ours"); + }; +} + +/// The heading of the picker section that starts at ring index `index`. +pub fn groupAt(index: usize) ?[]const u8 { + inline for (theme_groups) |g| if (index == comptime indexOfTheme(g.first)) return g.title; + if (index == native_count) return "Imported themes (helix, zed)"; + return null; +} + +test "the picker's sections run in ring order and cover it" { + var last: usize = 0; + inline for (theme_groups, 0..) |g, n| { + const at = comptime indexOfTheme(g.first); + if (n == 0) try std.testing.expectEqual(@as(usize, 0), at) else try std.testing.expect(at > last); + last = at; + } + try std.testing.expectEqualStrings("Pardes themes", groupAt(0).?); + // acme is a current theme, not a legacy one. + try std.testing.expect(indexOfTheme("acme") < indexOfTheme("helix")); + try std.testing.expect(groupAt(native_count) != null); +} + /// Original and classic-inspired Pardes palettes precede retained imports. pub const native_theme_count = 15; diff --git a/test/output.zig b/test/output.zig index 478f1b4a..d9d41e28 100644 --- a/test/output.zig +++ b/test/output.zig @@ -952,7 +952,7 @@ test "N exactly reverses n across output panes and the ring seam" { try std.testing.expect(saw_first and saw_second); } -test "ThemeSel groups native themes first and skips headings in both directions" { +test "ThemeSel lists the ring in sections and skips headings in both directions" { const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 40 }); defer p.deinit(); const source = try p.setTestFile("notes\n"); @@ -966,17 +966,35 @@ test "ThemeSel groups native themes first and skips headings in both directions" try std.testing.expectEqual(@as(i32, 0), list.body.cur_row); try std.testing.expectEqual(@as(usize, 0), list.file.?.scroll); try std.testing.expectEqualStrings("# Pardes themes", modal.lineSlice(content, 0)); - try std.testing.expectEqualStrings("# Legacy and imported themes", modal.lineSlice(content, pardes.native_theme_count + 2)); - try std.testing.expectEqual(@as(usize, pardes.themes.len + 3), std.mem.count(u8, content, "\n")); + // Every theme in ring order, each section's heading after a blank line + // where colors.groupAt says one starts. + var row: usize = 1; + var sections: usize = 1; + var first_break: ?usize = null; for (pardes.themes, 0..) |theme, i| { - const row = i + 1 + @as(usize, if (i >= pardes.native_theme_count) 2 else 0); + if (i > 0) if (pardes.colors.groupAt(i)) |title| { + try std.testing.expectEqualStrings("", modal.lineSlice(content, row)); + try std.testing.expect(std.mem.startsWith(u8, modal.lineSlice(content, row + 1), "# ")); + try std.testing.expectEqualStrings(title, modal.lineSlice(content, row + 1)["# ".len..]); + row += 2; + sections += 1; + if (first_break == null) first_break = i; + }; const line = modal.lineSlice(content, row); try std.testing.expect(std.mem.startsWith(u8, line, "Theme ")); try std.testing.expectEqualStrings(theme.name, line["Theme ".len..]); + row += 1; } + try std.testing.expectEqual(pardes.themes.len + 1 + 2 * (sections - 1), std.mem.count(u8, content, "\n")); + // acme is a current theme: it is listed before any break. + const acme = for (pardes.themes, 0..) |t, i| { + if (std.mem.eql(u8, t.name, "acme")) break i; + } else return error.MissingAcme; + const brk = first_break orelse return error.NoSections; + try std.testing.expect(acme < brk); // Opening an imported theme's selector must still begin with the natives. // Walk across the section break without selecting or executing a heading. - for (pardes.themes[0 .. pardes.native_theme_count + 1]) |theme| { + for (pardes.themes[0 .. brk + 1]) |theme| { p.update(.{ .key = .{ .cp = 'n' } }); try std.testing.expectEqual(tid, p.active); const selected = selectedOutputText(list) orelse return error.MissingThemeSelection; @@ -985,9 +1003,9 @@ test "ThemeSel groups native themes first and skips headings in both directions" } p.update(.{ .key = .{ .cp = 'N' } }); const previous = selectedOutputText(list) orelse return error.MissingThemeSelection; - try std.testing.expectEqualStrings(pardes.themes[pardes.native_theme_count - 1].name, previous["Theme ".len..]); + try std.testing.expectEqualStrings(pardes.themes[brk - 1].name, previous["Theme ".len..]); p.update(.{ .key = .{ .cp = Key.tab } }); - try std.testing.expectEqual(pardes.native_theme_count - 1, p.settings.theme); + try std.testing.expectEqual(brk - 1, p.settings.theme); } test "n/N selects command outputs by whole row" { -- cgit v1.3 From df6106af80e13cc4f0121b7f2caf5315a4453a9d Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 29 Sep 2026 10:03:10 -0300 Subject: Find and Grep share one +Search a directory, each run replacing the last Each Grep with a new pattern opened another +Search, until the column refused panes. Find and Grep now reuse their directory's one, as acme reuses +Errors, and the exec reads back the pane it filled; a plain word's LookWord list search keeps a pane a pattern as before. Co-Authored-By: Claude Opus 5.5 --- docs/fs.md | 5 ++++- src/Output.zig | 17 +++++++++++++++-- src/fs.zig | 3 +++ src/ninep/ctl.zig | 9 ++++++++- test/snapshots/find.golden | 16 ++++++++++------ test/snapshots/stepgrain.golden | 32 +++++++++++++++++++------------- 6 files changed, 59 insertions(+), 23 deletions(-) (limited to 'src/Output.zig') diff --git a/docs/fs.md b/docs/fs.md index 9b5b9d64..a0b3dcf7 100644 --- a/docs/fs.md +++ b/docs/fs.md @@ -736,7 +736,10 @@ whose directory is gone says `look: : no such directory` -- and for a Find or Grep that finds nothing, `grep: no match, not found`; Grep walks every pane's directory on this host, passing over panes of the served tree (`/virtual/`, a peer's `/n//`) and directories not there, -so none of them spoils the rest, ENOSPC for no room or +so none of them spoils the rest; Find and Grep share one `+Search` a +directory, each run replacing what the last showed, as acme reuses a +directory's `+Errors` (the exec reads that pane back), while a plain +word's `LookWord list` search keeps a pane a pattern, ENOSPC for no room or slot, EBUSY for a held lock) -- and logs its reason exactly once, as `err : `, with no `msg` for it. A builtin a click runs (Save, get's `Modified`, Tty with no room, Edit) is no exception. What is not a diff --git a/src/Output.zig b/src/Output.zig index b32a40a2..37d25168 100644 --- a/src/Output.zig +++ b/src/Output.zig @@ -406,6 +406,16 @@ pub fn open(p: *Pardes, id: usize, dir: []const u8, from: Origin, arg: []const u return pane; } +/// Find and Grep share one +Search a directory, each run replacing what +/// the last showed, as acme reuses a directory's +Errors; a pane's own +/// search (LookWord list) keeps a pane a pattern. +fn fileSearch(from: Origin) bool { + return switch (from) { + .cmd => |c| c == .Find or c == .Grep, + else => false, + }; +} + pub fn fillResults(p: *Pardes, id: usize, dir: []const u8, from: Origin, arg: []const u8, content: []u8, initial_anchor: ?usize) !void { var result_content = content; errdefer p.gpa.free(result_content); @@ -448,9 +458,12 @@ pub fn fillResults(p: *Pardes, id: usize, dir: []const u8, from: Origin, arg: [] const rp = slot orelse continue; const rf = if (rp.file) |*f| f else continue; const o = if (rf.output) |*x| x else continue; - if (!std.meta.eql(o.from, from)) continue; - if (by_arg and !std.mem.eql(u8, o.arg(), arg)) continue; + const shared = fileSearch(from) and fileSearch(o.from); + if (!shared and !std.meta.eql(o.from, from)) continue; + if (!shared and by_arg and !std.mem.eql(u8, o.arg(), arg)) continue; if (!std.mem.eql(u8, std.fs.path.dirname(rf.path) orelse "", dir)) continue; + o.from = from; + p.fs.refilled = rp.serial; try setArg(o, arg); if (std.mem.eql(u8, rf.content, result_content)) { p.gpa.free(result_content); diff --git a/src/fs.zig b/src/fs.zig index de02e8e8..6feaa972 100644 --- a/src/fs.zig +++ b/src/fs.zig @@ -1316,6 +1316,9 @@ pub const Namespace = struct { /// The serial of the pane the root's exec or look last ran a line at /// (the keyboard's), 0 before one: its err record names that pane. ran_at: u32 = 0, + /// The output pane a search just filled again rather than made + /// (Output.fillResults): what an exec reads back. + refilled: ?u32 = null, /// Every failure said (Messages.reportFailure), counted: a builtin /// that said one while it ran failed. failures: u32 = 0, diff --git a/src/ninep/ctl.zig b/src/ninep/ctl.zig index a474c781..fbda6113 100644 --- a/src/ninep/ctl.zig +++ b/src/ninep/ctl.zig @@ -73,6 +73,7 @@ pub fn run(p: *Pardes, id: usize, exec: bool, text: []const u8, in_tag: bool) vo // An exec answers the pane it went to: a command pane it reused, or // the terminal it typed into. p.look_missed = false; + p.fs.refilled = null; const went: ?usize = if (exec) pardes.exec.execute(p, id, text) else blk: { look.lookAt(p, id, text); break :blk null; @@ -88,6 +89,9 @@ pub fn run(p: *Pardes, id: usize, exec: bool, text: []const u8, in_tag: bool) vo created = true; }; if (created) return; + // A +Search it filled again (Find and Grep reuse one): that is what it + // touched. + if (p.fs.refilled) |serial| if (p.paneBySerial(serial) != null) return noteResult(p, serial); if (went) |dst| if (p.panes[dst]) |pane| return noteResult(p, pane.serial); noteResult(p, if (exec) context else (p.panes[p.active] orelse return).serial); } @@ -1841,7 +1845,8 @@ test "Grep with no hit says grep: no match and opens nothing, a missing pane dir const dir = dir_buf[0..try tmp.dir.realPath(testing.io, &dir_buf)]; var line: [4200]u8 = undefined; _ = wr(p, Node.of(serialOf(p), .name), try std.fmt.bufPrint(&line, "{s}/a.txt\n", .{dir})); - // A hit opens its +Search, a row a line: exec reads it back. + // A hit opens its +Search, a row a line: exec reads it back. Find and + // Grep share it, a directory's one +Search, each run replacing it. try testing.expectEqual(Status.ok, wr(p, Node.of(serialOf(p), .exec), "Grep bravo\n").reply.status); const grepped = p.panes[p.paneBySerial(try std.fmt.parseInt(u32, std.mem.trimEnd(u8, rd(p, root_exec, 0, 64).bytes, "\n"), 10)).?].?; try testing.expectEqual(@as(usize, 2), std.mem.count(u8, grepped.file.?.content, "other.txt:")); @@ -1850,6 +1855,8 @@ test "Grep with no hit says grep: no match and opens nothing, a missing pane dir try testing.expectEqual(Status.ok, wr(p, Node.of(serialOf(p), .exec), "Find other\n").reply.status); const found = p.panes[p.paneBySerial(try std.fmt.parseInt(u32, std.mem.trimEnd(u8, rd(p, root_exec, 0, 64).bytes, "\n"), 10)).?].?; try testing.expect(std.mem.indexOf(u8, found.file.?.content, "other.txt") != null); + try testing.expectEqual(grepped.serial, found.serial); + try testing.expect(std.mem.indexOf(u8, found.file.?.content, "bravo here") == null); // A second pane in a directory that is not there. const other = try th.newPane(p); _ = wr(p, Node.of(other, .name), "/tmp/pardes-no-such-dir-zz/b.txt\n"); diff --git a/test/snapshots/find.golden b/test/snapshots/find.golden index dec8ed1d..a6eae9cf 100644 --- a/test/snapshots/find.golden +++ b/test/snapshots/find.golden @@ -75,13 +75,17 @@ |3: 1 Find Find / |4: |13: 1 gamma body Last -== snap nomatch grid=120x41 cursor=7,8 +== snap nomatch grid=120x41 cursor=7,3 |3: 1 Find +|6: 1 +|7: +|8: |13: 1 gamma body -|18: /tmp/pardes-snap/find/cwd/+Search Save Tty Collapse Del -|19: 1 == snap refit grid=120x41 cursor=7,3 +|6: 1 sub/ZQMARK-beta.txt +|7: 2 sub/nest/zqmark-gamma.txt +|8: 3 zqmark-alpha.txt == snap topbar grid=120x41 cursor=12,16 -|21: /tmp/pardes-snap/find/cwd/+Search Save Tty Collapse Del -|22: 1 zqmark-alpha.txt -|23: 2 +|6: 1 zqmark-alpha.txt +|7: 2 +|8: diff --git a/test/snapshots/stepgrain.golden b/test/snapshots/stepgrain.golden index ef3cc49b..7f18d246 100644 --- a/test/snapshots/stepgrain.golden +++ b/test/snapshots/stepgrain.golden @@ -51,17 +51,23 @@ |8: 0-0 d,#608269, 1-1 d,#0d1410, 2-6 #616f64,#0d1410,b 7-19 #f5f7ee,#3c614a, 20-149 d,#0d1410, == snap step-row3 grid=150x31 cursor=7,10 == snap step-wrap grid=150x31 cursor=7,6 -== snap blank-in-path grid=150x31 cursor=7,13 -|12: /tmp/pardes-snap/stepgrain/cwd/+Search Save Tty Collapse Del -|13: 1 two words.txt -|14: 2 +== snap blank-in-path grid=150x31 cursor=7,6 +|5: /tmp/pardes-snap/stepgrain/cwd/+Search Save Tty Collapse Del +|6: 1 two words.txt +|7: 2 +|8: +|9: +|10: +|11: +|12: == style blank-in-path grid=150x31 -|5: 0-1 #ffffff,#496656, 2-2 d,#1d2824, 3-33 #b2c3b8,#1d2824, 34-40 #d3b0d9,#1d2824, 41-78 #b2c3b8,#1d2824, 79-149 d,#1d2824, -|6: 0-0 d,#608269, 1-1 d,#0d1410, 2-6 #59675c,#0d1410, 7-18 #f5f7ee,#3c614a, 19-149 d,#0d1410, -|8: 0-0 d,#608269, 1-1 d,#0d1410, 2-19 #59675c,#0d1410, 20-149 d,#0d1410, -|11: 0-0 d,#152019, 1-1 d,#0d1410, 2-6 #59675c,#0d1410, 7-12 #f7e4a5,#5e4923, 13-23 #e5eee5,#0d1410, 24-149 d,#0d1410, -|12: 0-1 #000000,#add38a, 2-2 d,#314738, 3-33 #becfc4,#314738, 34-40 #dfbce5,#314738, 41-62 #becfc4,#314738, 63-149 d,#314738, -|13: 0-0 d,#608269, 1-1 d,#0d1410, 2-6 #616f64,#0d1410,b 7-19 #f5f7ee,#3c614a, 20-149 d,#0d1410, -== snap blank-opened grid=150x31 cursor=7,16 -|15: /tmp/pardes-snap/stepgrain/cwd/two words.txt Save Tty Collapse Del -|16: 1 +|5: 0-1 #000000,#add38a, 2-2 d,#314738, 3-33 #becfc4,#314738, 34-40 #dfbce5,#314738, 41-62 #becfc4,#314738, 63-149 d,#314738, +|6: 0-0 d,#608269, 1-1 d,#0d1410, 2-6 #616f64,#0d1410,b 7-19 #f5f7ee,#3c614a, 20-149 d,#0d1410, +|7: 0-0 d,#608269, 1-1 d,#0d1410, 2-6 #59675c,#0d1410, 7-149 d,#0d1410, +|8: 0-0 d,#608269, 1-1 d,#0d1410, 2-6 #59675c,#0d1410, 7-149 d,#0d1410, +|9: 0-0 d,#608269, 1-1 d,#0d1410, 2-6 #59675c,#0d1410, 7-149 d,#0d1410, +|10: 0-0 d,#608269, 1-1 d,#0d1410, 2-6 #59675c,#0d1410, 7-149 d,#0d1410, +|11: 0-0 d,#608269, 1-1 d,#0d1410, 2-6 #59675c,#0d1410, 7-149 d,#0d1410, +== snap blank-opened grid=150x31 cursor=7,9 +|8: /tmp/pardes-snap/stepgrain/cwd/two words.txt Save Tty Collapse Del +|9: 1 -- cgit v1.3 From 2d0c506583d18d6f004fc117282deb2faea1d17e Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 29 Sep 2026 10:30:38 -0300 Subject: Recent lists the files opened lately, closed ones too, and a jump back to a closed file reopens it A file closed by accident, its path forgotten, could not be found again: the jumplist dropped closed panes. Every file opened (a look, a Save of a scratch, a Restore, a rename) goes first in a list of 200, kept once, its dot noted when it closes, kept across sessions in $XDG_STATE_HOME/pardes/ recent. `Recent` (SPC f r) shows it in a reused +Recent, each row `path:line:col open|closed` a look reopens; /recent reads `open|closed `. The jumplist keeps a closed file's entries, +Jumps marks them `(closed)`, and Back to one opens the file at its place. acme has no such thing; its dump and Load are the nearest. Co-Authored-By: Claude Opus 5.5 --- .agents/skills/pardes-9p/SKILL.md | 2 + README.md | 19 ++++++ docs/fs.md | 5 ++ docs/helix-keys.md | 2 +- src/Output.zig | 49 ++++++++++++++++ src/builtins.zig | 10 ++++ src/config.zig | 2 + src/fs-help.txt | 4 +- src/main.zig | 16 +++++ src/ninep/ctl.zig | 54 +++++++++++++++++ src/ninep/events.zig | 2 + src/ninep/pane.zig | 1 + src/ninep/tree.zig | 31 +++++++--- src/pardes.zig | 104 ++++++++++++++++++++++++++++++++- src/recent.zig | 119 ++++++++++++++++++++++++++++++++++++++ test/fs.py | 28 ++++++++- 16 files changed, 434 insertions(+), 14 deletions(-) create mode 100644 src/recent.zig (limited to 'src/Output.zig') diff --git a/.agents/skills/pardes-9p/SKILL.md b/.agents/skills/pardes-9p/SKILL.md index 0575fab7..4678d55a 100644 --- a/.agents/skills/pardes-9p/SKILL.md +++ b/.agents/skills/pardes-9p/SKILL.md @@ -96,6 +96,8 @@ $m/ctl the settings, one a line as a write takes them; write a setting or column word Delcol, which closes that pane's column) go to $m/pane//ctl $m/commands every builtin: `Word`, `Word arg`, then `root`, `pane` or `both` (which ctl takes it), a setting's values comma-joined, then ` -- ` and one sentence of what it does +$m/recent files opened lately, closed ones too, most recent first: `open|closed `; + lost a file you closed? read this, or run Recent and look at its row to reopen it $m/layout one line per column (16 columns at most: Newcol past that fails, no space for a column): serial index x width current|notcurrent empty|full pane-serials...; active $m/tag the workspace tag (> replaces, >> appends, one line); $m/col//tag a column's (serials stay, as panes' do) $m/tagexec a word as a click in the workspace tag (pane//tagexec: in that pane's tag); every exec diff --git a/README.md b/README.md index 49ecfa4d..826f86c8 100644 --- a/README.md +++ b/README.md @@ -103,6 +103,25 @@ pane shells outlive every frontend; a frontend keeps only what needs the human's own display. From inside the editor, `Attach` and `Detach` do the same thing as words. See `docs/detached.md`. +## Recent files + +A file closed by accident is found again. `Recent` (`SPC f r`) lists the +files opened lately, most recent first, closed ones too, each marked `open` +or `closed` at the place its dot was when it closed: + +``` +/home/me/src/main.zig:120:5 closed +/home/me/notes.txt open +``` + +A look at a row opens that file there. The list keeps 200 files, each once, +and lasts across sessions in `$XDG_STATE_HOME/pardes/recent` (else +`~/.local/state/pardes/recent`). The jumplist keeps a closed file's entries +too: `Back` to one opens the file again at its place, and `+Jumps` marks it +`(closed)`. Over 9P, `/recent` reads `open ` or `closed ` a line. +acme has nothing like it (its dump and Load are the nearest); pardes goes +beyond acme here. + ## Tests ``` diff --git a/docs/fs.md b/docs/fs.md index a0b3dcf7..dedfe94f 100644 --- a/docs/fs.md +++ b/docs/fs.md @@ -125,6 +125,11 @@ Existing Plan9port/v9fs clients need a userspace bridge for QUIC. /commands every builtin: word, `arg` if it takes one, `root`, `pane` or `both` (the ctl that takes it: Edit is both, at the active pane from the root; a pane's word such as Undo or Msg is refused at the root), a setting's values, then ` -- ` and what it does +/recent the files opened lately, closed ones too, most recent first, a line each: + `open ` or `closed ` (read-only; `Recent` shows them in a pane, + a look at a row reopening the file at its last dot; kept across sessions + in $XDG_STATE_HOME/pardes/recent, 200 files; acme has none, its dump and + Load the nearest) /layout one line per column (16 at most; the board 6; Newcol past that fails, `no space for a column: 16 max`, ENOSPC), left to right: serial index x width current|notcurrent (the column with the keyboard now) empty|full pane-serials...; then active diff --git a/docs/helix-keys.md b/docs/helix-keys.md index 8874bf08..5d89ba92 100644 --- a/docs/helix-keys.md +++ b/docs/helix-keys.md @@ -143,7 +143,7 @@ language-backend queries, and the shell pipe. | `gd` `gD` `gy` `gi` `gr` | LSP definition / declaration / type-definition / implementation / references. ONE answer jumps straight there; several fill `+Search`, where n/N walk and Enter opens | in-process ZLS (`src/lsp/lsp_zls.zig`), `.zig` only — on a file the backend does not speak these do nothing at all, with no error row. Ctrl+left-click is the mouse spelling of `gd` | out of corpus | | `]d` `[d` / `]D` `[D` | step the diagnostics list / go to its last or first; if no list is up, asking the backend for one is part of the press | | out of corpus | | `=` | `format_selections` — writes a `- old` / `+ new` diff into `+Lsp` | deliberate divergence: the seam returns ROWS, not edits, so this SHOWS the formatting instead of applying it. Not in the corpus, so there is no waiver to name — the query leaves the core as an effect the headless harness has no shell to perform | out of corpus | -| `Ctrl-o` / `Ctrl-i` | jumplist back / forward (also Mouse4 / Mouse5 in SDL, macOS and web); successful navigation clears selections in both panes and places the cursor at the saved location; raw tty forwards both to the child — the `Back` / `Forward` builtins, also on `SPC j o` / `SPC j i`, with `SPC j l` rendering the stack as a buffer | helix binds both keys (`jump_backward` / `jump_forward`) but to a POSITION jumplist; pardes' stack is over panes and focus, so the keys agree and the semantics do not. `Ctrl-i` and Tab are the same byte under the legacy encoding; there Tab keeps meaning execute, and the pair only separates where the host speaks the kitty keyboard protocol | pardes-specific | +| `Ctrl-o` / `Ctrl-i` | jumplist back / forward (also Mouse4 / Mouse5 in SDL, macOS and web); successful navigation clears selections in both panes and places the cursor at the saved location; raw tty forwards both to the child — the `Back` / `Forward` builtins, also on `SPC j o` / `SPC j i`, with `SPC j l` rendering the stack as a buffer; a closed file's entry stays, marked `(closed)`, and a jump to it opens the file again at its place | helix binds both keys (`jump_backward` / `jump_forward`) but to a POSITION jumplist; pardes' stack is over panes and focus, so the keys agree and the semantics do not. `Ctrl-i` and Tab are the same byte under the legacy encoding; there Tab keeps meaning execute, and the pair only separates where the host speaks the kitty keyboard protocol | pardes-specific | | `\|` | pipe every selection through `/bin/sh -c`: its bytes in on stdin, its stdout replacing them, one undo across all cursors | helix's own key and meaning; the command is typed into the pane's tag after a bare `\|` marker rather than into a popup | out of corpus | | `A-\|` | the same, and the output is DISCARDED — the text is not touched at all | helix `shell_pipe_to`. For a command run for its effect. Marker `\|-` | out of corpus | | `!` | run with NO stdin, insert the output BEFORE each selection | helix `shell_insert_output`. Runs ONCE and every cursor gets that one answer, as helix does — ten cursors and `date` give ten identical stamps. Marker `!` | out of corpus | diff --git a/src/Output.zig b/src/Output.zig index 37d25168..dd6ab92a 100644 --- a/src/Output.zig +++ b/src/Output.zig @@ -505,6 +505,12 @@ pub fn openJumps(p: *Pardes, id: usize) !void { var out: std.Io.Writer.Allocating = .init(p.gpa); errdefer out.deinit(); for (p.jumps[0..p.njumps]) |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; + try out.writer.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; var idbuf: [16]u8 = undefined; const pdf_path: ?[]const u8 = if (comptime pardes.pdf_enabled) jp.pdfPath() else null; @@ -532,6 +538,49 @@ pub fn openJumps(p: *Pardes, id: usize) !void { try openStepped(p, id, .{ .cmd = .Jumplist }, content); } +/// The recent list as rows: `:: open|closed`, most recent +/// first; a look at a row opens the file there, as a +Jumps row does. +pub fn recentText(p: *Pardes, w: *std.Io.Writer, look_rows: bool) !void { + for (p.recent.entries.items) |e| { + var is_open = false; + for (p.panes) |slot| if (slot) |pane| if (pane.file) |f| if (f.output == null and std.mem.eql(u8, f.path, e.path)) { + is_open = true; + }; + const state: []const u8 = if (is_open) "open" else "closed"; + if (!look_rows) + try w.print("{s} {s}\n", .{ state, e.path }) + else if (e.line == 0) + try w.print("{s} {s}\n", .{ e.path, state }) + else + try w.print("{s}:{d}:{d} {s}\n", .{ e.path, e.line, e.col, state }); + } +} + +/// Recent: the one +Recent, filled again when it is there (as Find and +/// Grep's +Search is), else opened below the asking pane. +pub fn openRecent(p: *Pardes, id: usize) !void { + var out: std.Io.Writer.Allocating = .init(p.gpa); + errdefer out.deinit(); + try recentText(p, &out.writer, true); + const content = try out.toOwnedSlice(); + for (p.panes, 0..) |slot, i| { + const rp = slot orelse continue; + const rf = if (rp.file) |*f| f else continue; + const o = rf.output orelse continue; + if (!std.meta.eql(o.from, Origin{ .cmd = .Recent })) continue; + File.setContent(p, rf, content); + resetBody(p, rp); + p.fs.refilled = rp.serial; + if (p.panes[id]) |pane| { + pane.search_pane = i; + pane.search_row = null; + } + look.armLookWalk(p, i); + return; + } + try openStepped(p, id, .{ .cmd = .Recent }, content); +} + pub fn openThemes(p: *Pardes, id: usize) !void { var out: std.Io.Writer.Allocating = .init(p.gpa); errdefer out.deinit(); diff --git a/src/builtins.zig b/src/builtins.zig index 7fdf2176..2247fcbb 100644 --- a/src/builtins.zig +++ b/src/builtins.zig @@ -1447,6 +1447,7 @@ pub const Last = struct { while (i > 0) { i -= 1; const j = c.p.jumps[i]; + if (j.serial == 0) continue; // a closed file's: Back reopens it, Last goes to a pane // Restore the cursor without recentering the pane's retained view. if (j.pane != c.id) return look.focusPaneLine(c.p, j.pane, .{ .line = j.line, .col = j.col }, .keep); } @@ -1456,6 +1457,15 @@ pub const Last = struct { } }; +/// List the files opened lately, closed ones too, each a place to open again. +pub const Recent = struct { + pub const scope: Scope = .session; + pub const output: OutputTraits = .{ .name = config.recent_buffer, .steps = true, .locations = true }; + pub fn run(c: Ctx) void { + panes.Output.openRecent(c.p, c.id) catch |err| c.p.reportError(c.id, "recent", err); + } +}; + /// List the places jumped from, each a place to go. pub const Jumplist = struct { pub const scope: Scope = .session; diff --git a/src/config.zig b/src/config.zig index 229c70ea..c7ea5411 100644 --- a/src/config.zig +++ b/src/config.zig @@ -65,6 +65,7 @@ pub const leader_path = paths: { .New = "fn", .Tty = "nt", .Find = "ff", + .Recent = "fr", .Grep = "fg", .Config = "fc", .LocationsConfig = null, @@ -448,6 +449,7 @@ pub const help_buffer = "+Help"; pub const config_buffer = "+Config"; pub const effect_code_buffer = "+EffectCode"; pub const jumps_buffer = "+Jumps"; +pub const recent_buffer = "+Recent"; pub const themes_buffer = "+Themes"; pub const fonts_buffer = "+Fonts"; pub const pdf_sections_buffer = "+PdfSections"; diff --git a/src/fs-help.txt b/src/fs-help.txt index bd822b60..62d4ae48 100644 --- a/src/fs-help.txt +++ b/src/fs-help.txt @@ -11,11 +11,11 @@ listeners the session's dial addresses focus the serial of the pane with the keyboard (empty on a column tag); write a serial to give it the keyboard ctl settings a line; or Newcol, Dump, Restore [f], Exit (asks once), Kill [w], Placement acme|pardes, size C R (--detach) commands every builtin: word, arg if it takes one, root|pane|both (the ctl that takes it), -- what it does +recent files opened lately, closed ones too, most recent first: open|closed layout a line per column: serial index x width current|notcurrent empty|full pane-serials; active tag the workspace tag, tagexec a word as a click in it; col// a column's tag, ctl (Delcol Joincol New Tty), exec; rmdir: empty only pane/new open it to make a pane (/+New) in the active column, filling it if empty; the read answers its serial -pane// name body tag ctl addr dot limit data xdata sel dirty mark scroll errors (write-only: - appended to its directory's +Errors pane) event look exec tagexec, pty/ on terminals; rmdir closes +pane// name body tag ctl addr dot limit data xdata sel dirty mark scroll errors (write-only, to +Errors) event look exec tagexec, pty/ on terminals; rmdir closes os/, src/ the host filesystem; the editor's own sources $m below: $NINE_MOUNT/pardes/; $NINE_MOUNT under 9ns --unix; PARDES_MOUNT in a Tty9p shell. diff --git a/src/main.zig b/src/main.zig index 86c302fe..b784ec97 100644 --- a/src/main.zig +++ b/src/main.zig @@ -369,6 +369,7 @@ fn nativeMain(init: std.process.Init) !void { opts.startup_config = found.bytes; opts.startup_config_path = found.path; opts.config_dir = found.dir; + opts.recent_path = recentPath(init.io, arena, init.environ_map); if (found.dir) |d| @import("crash.zig").setDir(d); if (detach) |name| { const named = if (name.len != 0) @@ -427,3 +428,18 @@ test { if (comptime pardes.platform == .gui) _ = @import("gui/gui.zig"); if (comptime pardes.font_picker) _ = @import("fonts.zig"); } + +/// Where the list of files opened lately is kept: $XDG_STATE_HOME/pardes +/// /recent, else ~/.local/state/pardes/recent, the directory made if need +/// be; null with no home to keep it in (the list then lasts the session). +fn recentPath(io: std.Io, arena: std.mem.Allocator, env: *const std.process.Environ.Map) ?[]const u8 { + const dir = dir: { + if (env.get("XDG_STATE_HOME")) |base| if (base.len != 0 and std.fs.path.isAbsolute(base)) + break :dir std.fs.path.join(arena, &.{ base, "pardes" }) catch return null; + const home = env.get("HOME") orelse return null; + if (home.len == 0) return null; + break :dir std.fs.path.join(arena, &.{ home, ".local", "state", "pardes" }) catch return null; + }; + std.Io.Dir.cwd().createDirPath(io, dir) catch return null; + return std.fs.path.join(arena, &.{ dir, "recent" }) catch null; +} diff --git a/src/ninep/ctl.zig b/src/ninep/ctl.zig index 6631e5f9..22a0923b 100644 --- a/src/ninep/ctl.zig +++ b/src/ninep/ctl.zig @@ -2106,6 +2106,60 @@ test "a column takes panes until their documented minimums fill it, not until no } } +test "a closed file is found again: Recent and /recent list it closed, a look at its row reopens it at its dot, and a jump back does too" { + const p = try withFile(testing.allocator, "x\n"); + defer p.deinit(); + var tmp = testing.tmpDir(.{}); + defer tmp.cleanup(); + try tmp.dir.writeFile(testing.io, .{ .sub_path = "a.txt", .data = "one\ntwo\nthree\n" }); + try tmp.dir.writeFile(testing.io, .{ .sub_path = "b.txt", .data = "bee\n" }); + var dir_buf: [4096]u8 = undefined; + const dir = dir_buf[0..try tmp.dir.realPath(testing.io, &dir_buf)]; + var line: [4200]u8 = undefined; + const a_path = try std.fmt.bufPrint(&line, "{s}/a.txt", .{dir}); + var a_buf: [4200]u8 = undefined; + const a = a_buf[0..a_path.len]; + @memcpy(a, a_path); + // Opened, its dot on line 3, then closed. + try testing.expectEqual(Status.ok, wr(p, root_look, try std.fmt.bufPrint(&line, "{s}:3\n", .{a})).reply.status); + p.sync(); + const opened = p.active; + try testing.expectEqualStrings(a, p.panes[opened].?.file.?.path); + var want: [4300]u8 = undefined; + try testing.expect(std.mem.indexOf(u8, rd(p, @intFromEnum(tree.TopFile.recent), 0, 8192).bytes, try std.fmt.bufPrint(&want, "open {s}\n", .{a})) != null); + // Another file, so the jumplist has somewhere to come back from. + try testing.expectEqual(Status.ok, wr(p, root_look, try std.fmt.bufPrint(&line, "{s}/b.txt\n", .{dir})).reply.status); + p.sync(); + try testing.expectEqual(Status.ok, wr(p, Node.of(p.panes[opened].?.serial, .ctl), "Del\n").reply.status); + p.sync(); + try testing.expect(std.mem.indexOf(u8, rd(p, @intFromEnum(tree.TopFile.recent), 0, 8192).bytes, try std.fmt.bufPrint(&want, "closed {s}\n", .{a})) != null); + // Recent lists it, closed, at its dot; a look at the row opens it there. + try testing.expectEqual(Status.ok, wr(p, root_exec, "Recent\n").reply.status); + const rows = p.panes[p.paneBySerial(try std.fmt.parseInt(u32, std.mem.trimEnd(u8, rd(p, root_exec, 0, 64).bytes, "\n"), 10)).?].?; + const at = std.mem.indexOf(u8, rows.file.?.content, try std.fmt.bufPrint(&want, "{s}:3:", .{a})).?; + const row = rows.file.?.content[at .. std.mem.indexOfScalarPos(u8, rows.file.?.content, at, '\n').?]; + try testing.expect(std.mem.endsWith(u8, row, " closed")); + try testing.expectEqual(Status.ok, wr(p, Node.of(rows.serial, .look), try std.fmt.bufPrint(&line, "{s}\n", .{row[0 .. row.len - " closed".len]})).reply.status); + p.sync(); + const back = p.panes[p.active].?; + try testing.expectEqualStrings(a, back.file.?.path); + try testing.expectEqual(@as(i32, 2), back.body.cur_row); + // Closed again; the jumplist keeps its entry, closed, and a jump back + // to it opens it again. + _ = wr(p, Node.of(back.serial, .ctl), "Del\n"); + p.sync(); + var closed_entry = false; + for (p.jumps[0..p.njumps]) |j| closed_entry = closed_entry or j.serial == 0; + try testing.expect(closed_entry); + var tries: usize = 0; + while (tries < p.njumps) : (tries += 1) { + p.jumpBy(-1); + p.sync(); + if (p.panes[p.active].?.file) |f| if (std.mem.eql(u8, f.path, a)) break; + } + try testing.expectEqualStrings(a, p.panes[p.active].?.file.?.path); +} + test "size is monotonic: growing is never refused, and a size once taken is taken again" { const p = try Pardes.init(testing.allocator, .{ .tty_only = true, .cols = 160, .rows = 60 }); defer p.deinit(); diff --git a/src/ninep/events.zig b/src/ninep/events.zig index 868364a6..690efbe5 100644 --- a/src/ninep/events.zig +++ b/src/ninep/events.zig @@ -140,6 +140,8 @@ pub fn announce(p: *Pardes) void { if (!pane.fs.unannounced) continue; pane.fs.unannounced = false; noteLog(p, .new, pane); + // A file opened (a look, a Restore, a boot): first in Recent. + if (pane.file) |f| if (f.output == null) p.recent.opened(p.recentGpa(), f.path); } } diff --git a/src/ninep/pane.zig b/src/ninep/pane.zig index 1148041a..4370d401 100644 --- a/src/ninep/pane.zig +++ b/src/ninep/pane.zig @@ -683,6 +683,7 @@ pub fn nameBuffer(p: *Pardes, id: usize, full: []const u8, preserve_tag: bool) ! look.invalidateLookHover(p, id); p.emit(.{ .watch = .{ .pane = @intCast(id), .on = false } }); events.noteLog(p, .rename, pane); + if (f.output == null) p.recent.opened(p.recentGpa(), f.path); } /// Diagnostics go to the +Errors buffer of the pane's directory. diff --git a/src/ninep/tree.zig b/src/ninep/tree.zig index 9d2027bf..64089c01 100644 --- a/src/ninep/tree.zig +++ b/src/ninep/tree.zig @@ -219,6 +219,9 @@ pub const TopFile = enum(u5) { tag, col, tagexec, + /// The files opened lately, closed ones too, a line each: + /// `open|closed `, most recent first. + recent, pub fn fileName(f: TopFile) []const u8 { return if (f == .root) "/" else @tagName(f); @@ -228,7 +231,7 @@ pub const TopFile = enum(u5) { return switch (f) { .root, .pane, .col => 0o755, .look, .exec, .log, .focus, .ctl, .tag, .tagexec => 0o666, - .README, .index, .status, .screen, .listeners, .new, .commands, .layout => 0o444, + .README, .index, .status, .screen, .listeners, .new, .commands, .layout, .recent => 0o444, }; } @@ -239,6 +242,13 @@ pub const TopFile = enum(u5) { pub const root: u64 = @intFromEnum(TopFile.root); +fn recentLen(p: *Pardes) u64 { + var buf: [64]u8 = undefined; + var counting: std.Io.Writer.Discarding = .init(&buf); + pardes.panes.Output.recentText(p, &counting.writer, false) catch return 0; + return counting.fullCount(); +} + /// Declaration order is readdir order. pub const PaneFile = enum(u5) { dir = 0, @@ -556,6 +566,7 @@ fn topSize(p: *Pardes, f: TopFile) u64 { }, .ctl => ctl.rootLen(p), .commands => ctl.commandsLen(), + .recent => recentLen(p), .focus => focus: { if (p.header_focus) break :focus 0; const pn = p.panes[p.active] orelse break :focus 0; @@ -653,7 +664,7 @@ fn readdir(p: *Pardes, req: Req, target: Target) Reply { .root => { // The guide, then what describes the session, then the // files that act, then the directories. - inline for (.{ TopFile.README, TopFile.index, TopFile.status, TopFile.focus, TopFile.ctl, TopFile.commands, TopFile.look, TopFile.exec, TopFile.log, TopFile.screen, TopFile.listeners, TopFile.layout, TopFile.tag, TopFile.tagexec, TopFile.pane, TopFile.col }) |t| { + inline for (.{ TopFile.README, TopFile.index, TopFile.status, TopFile.focus, TopFile.ctl, TopFile.commands, TopFile.recent, TopFile.look, TopFile.exec, TopFile.log, TopFile.screen, TopFile.listeners, TopFile.layout, TopFile.tag, TopFile.tagexec, TopFile.pane, TopFile.col }) |t| { if (skip > 0) skip -= 1 else stageDirent(out, p.gpa, @intFromEnum(t), t.dir(), t.fileName()); } if (skip > 0) skip -= 1 else stageDirent(out, p.gpa, fs.os_root, true, "os"); @@ -933,6 +944,12 @@ fn readFile(p: *Pardes, req: Req, target: Target) Reply { .focus => ctl.readFocus(p, req), .ctl => ctl.readRoot(p, req), .commands => ctl.readCommands(p, req), + .recent => recent: { + var text: std.Io.Writer.Allocating = .init(p.scratch.allocator()); + pardes.panes.Output.recentText(p, &text.writer, false) catch break :recent Reply.fail(req.tag, E.NOMEM); + p.fs.stage(p.gpa).appendSlice(p.gpa, text.written()) catch break :recent Reply.fail(req.tag, E.NOMEM); + break :recent stagedReply(p, req); + }, .layout => layout: { var text: std.Io.Writer.Allocating = .init(p.scratch.allocator()); cols.writeLayout(p, &text.writer) catch break :layout Reply.fail(req.tag, E.NOMEM); @@ -1201,13 +1218,13 @@ test "readdir lists the root and a pane directory without creating anything" { @memcpy(top_bytes[0..top_reply.bytes.len], top_reply.bytes); const top = th.dirents(top_bytes[0..top_reply.bytes.len], &buf); try testing.expect(top.len >= 10); - for ([_][]const u8{ "README", "index", "status", "focus", "ctl", "commands", "look", "exec", "log", "screen", "listeners", "layout", "tag", "tagexec", "pane", "col", "os" }, 0..) |name, i| { + for ([_][]const u8{ "README", "index", "status", "focus", "ctl", "commands", "recent", "look", "exec", "log", "screen", "listeners", "layout", "tag", "tagexec", "pane", "col", "os" }, 0..) |name, i| { try testing.expectEqualStrings(name, top[i].name); - try testing.expectEqual(i >= 14, top[i].dir); + try testing.expectEqual(i >= 15, top[i].dir); } - try testing.expectEqual(@intFromEnum(TopFile.pane), top[14].node); - try testing.expectEqual(@intFromEnum(TopFile.col), top[15].node); - try testing.expectEqual(fs.os_root, top[16].node); + try testing.expectEqual(@intFromEnum(TopFile.pane), top[15].node); + try testing.expectEqual(@intFromEnum(TopFile.col), top[16].node); + try testing.expectEqual(fs.os_root, top[17].node); var idbuf: [16]u8 = undefined; try testing.expect(th.nameAt(top, try std.fmt.bufPrint(&idbuf, "{d}", .{serial})) == null); try testing.expect(th.nameAt(top, "self") == null); diff --git a/src/pardes.zig b/src/pardes.zig index f7aee16c..33aff840 100644 --- a/src/pardes.zig +++ b/src/pardes.zig @@ -14,6 +14,7 @@ const tracy = @import("tracy.zig"); pub const panes = @import("panes.zig"); pub const tagline = @import("tagline.zig"); pub const exec = @import("exec.zig"); +const recent_files = @import("recent.zig"); pub const mouse = @import("mouse.zig"); pub const normal = @import("normal.zig"); pub const edit = @import("edit.zig"); @@ -447,11 +448,17 @@ test "a compact tagline anchors at its own pane, and both shells step from the s try std.testing.expectEqual(@as(u16, 3), gridColAt(p, 3.5 * body_w, body_row, body_w, tag_w)); } +const recent_path_cap = limits.host_path_cap; + pub const Loc = struct { pane: u16, + /// 0 once its pane has closed: a file's entry stays, reopened by a + /// jump to it from `path_hash`'s recent entry. serial: u32, line: u32, col: u32, + /// The file it is in (Wyhash of the path), 0 for a pane with none. + path_hash: u64 = 0, }; test { @@ -474,6 +481,7 @@ test { _ = @import("draw.zig"); _ = @import("tag_layer.zig"); _ = @import("dump.zig"); // its tests ran nowhere before + _ = @import("recent.zig"); _ = @import("Presentation.zig"); _ = @import("animation.zig"); } @@ -4232,6 +4240,10 @@ pub const Options = struct { ninep_quic: ?[]const u8 = null, mounts: []const filesystem.Mount = &.{}, config_dir: ?[]const u8 = null, + /// Where the list of files opened lately is kept across sessions + /// (recent.zig), set by the host that has a state directory; none, it + /// lives as long as the session. + recent_path: ?[]const u8 = null, startup_config_path: ?[]const u8 = null, image_allocator: ?std.mem.Allocator = null, pdf_allocator: ?std.mem.Allocator = null, @@ -4298,6 +4310,12 @@ pub const Pardes = struct { presentation: Presentation = .{}, active: usize = 0, + /// The files opened lately, closed ones too (recent.zig): `Recent`, + /// /recent, and the jumplist's way back to a closed pane. + recent: recent_files.List = .{}, + /// The kept list was read (or there was none): only then is it written, + /// so a session never writes over one it did not read. + recent_loaded: bool = false, jumps: [MAX_JUMPS]Loc = undefined, njumps: usize = 0, jcur: usize = 0, @@ -4621,6 +4639,7 @@ pub const Pardes = struct { }, } p.sync(); + p.loadRecent(); exec.applyStartupConfig(p); colors.finishThemeInitialization(p); p.sync(); @@ -4641,7 +4660,58 @@ pub const Pardes = struct { p.col_panes[0][0] = 0; } + /// The recent list's own allocator: it is kept best effort (a file not + /// remembered for want of memory is no failure of what opened it), so + /// on a host it takes from the process heap, not the editor's, whose + /// every failure must be answered. + // ponytail: a host heap for a best-effort list; the board's gpa there. + pub fn recentGpa(p: *const Pardes) std.mem.Allocator { + return if (comptime hosted) std.heap.smp_allocator else p.gpa; + } + + /// The kept list of files opened lately, read once at start. + fn loadRecent(p: *Pardes) void { + const path = p.opts.recent_path orelse return; + if (comptime !hosted) return; + defer p.recent_loaded = true; + const bytes = filesystem.readFile(p.gpa, path) catch return; + defer p.gpa.free(bytes); + p.recent.read(p.recentGpa(), bytes); + } + + /// Written out when it changed, at the end of a step and at the end. + pub fn saveRecent(p: *Pardes) void { + if (!p.recent.dirty) return; + p.recent.dirty = false; + const path = p.opts.recent_path orelse return; + if (comptime !hosted) return; + if (!p.recent_loaded) return; + var out: std.Io.Writer.Allocating = .init(p.gpa); + defer out.deinit(); + p.recent.write(&out.writer) catch return; + turn.yield(); + defer turn.back(); + std.Io.Dir.cwd().writeFile(std.Io.Threaded.global_single_threaded.io(), .{ .sub_path = path, .data = out.written() }) catch {}; + } + + /// A file pane's path and dot, for the recent list (0 when none). + fn recentDot(pane: *const Pane) ?struct { path: []const u8, line: u32, col: u32 } { + const f = pane.file orelse return null; + if (f.output != null) return null; + return .{ .path = f.path, .line = @intCast(@max(0, pane.body.cur_row) + 1), .col = @intCast(@max(0, pane.body.cur_col) + 1) }; + } + + /// The recent entry a closed jump names, by its path's hash. + pub fn recentByHash(p: *const Pardes, hash: u64) ?recent_files.Entry { + for (p.recent.entries.items) |e| if (std.hash.Wyhash.hash(0, e.path) == hash) return e; + return null; + } + pub fn deinit(p: *Pardes) void { + // Every file open now is closed with its dot, and the list kept. + for (p.panes) |slot| if (slot) |pane| if (recentDot(pane)) |d| p.recent.closed(p.recentGpa(), d.path, d.line, d.col); + p.saveRecent(); + p.recent.deinit(p.recentGpa()); look.cancelLookHover(p); if (p.repl_ask) |ask| p.gpa.free(ask.text); for (0..MAX_PANES) |id| p.dropPendingWrite(id); @@ -4750,6 +4820,9 @@ pub const Pardes = struct { } fn retirePane(p: *Pardes, pane: *Pane) void { + // Closed, a file is remembered with its dot: Recent and a jump back + // to it reopen it there. + if (recentDot(pane)) |d| p.recent.closed(p.recentGpa(), d.path, d.line, d.col); const watched = (if (pane.file) |f| f.output == null else false) or pane.hasPdf(); for (p.panes, 0..) |slot, id| if (slot == pane) { if (watched) p.emit(.{ .watch = .{ .pane = @intCast(id), .on = false } }); @@ -5240,6 +5313,7 @@ pub const Pardes = struct { f.saved_revision = f.revision; f.disk_gone = false; ctlfs.events.noteLog(p, .save, pane); + p.recent.opened(p.recentGpa(), f.path); if (filesystem.localPath(f.path) != null) p.emit(.{ .watch = .{ .pane = id, .on = true } }); } @@ -6562,9 +6636,15 @@ pub const Pardes = struct { var cur: usize = 0; for (p.jumps[0..p.njumps], 0..) |j, i| { if (i == p.jcur) cur = w; // survives -> lands at w; dies -> the next one does - const pane = p.panes[j.pane] orelse continue; - if (pane.serial != j.serial) continue; - p.jumps[w] = j; + var kept = j; + const live = if (j.serial == 0) false else if (p.panes[j.pane]) |pane| pane.serial == j.serial else false; + // A file's pane closed: its entry stays, closed, while the recent + // list knows the file, and a jump to it opens it again. + if (!live) { + if (j.path_hash == 0 or p.recentByHash(j.path_hash) == null) continue; + kept.serial = 0; + } + p.jumps[w] = kept; w += 1; } p.njumps = w; @@ -6576,6 +6656,7 @@ pub const Pardes = struct { .serial = pane.serial, .line = if (pane.pdfPage()) |page| @intCast(page + 1) else if (pane.body.cur_pinned) @intCast(@max(0, pane.body.cur_row) + 1) else 0, .col = if (pane.pdfPage() != null) 0 else if (pane.body.cur_pinned) @intCast(@max(0, pane.body.cur_col) + 1) else 0, + .path_hash = if (recentDot(pane)) |d| std.hash.Wyhash.hash(0, d.path) else 0, }; if (p.njumps > 0 and p.samePlace(p.jumps[p.jcur], now)) { p.jumps[p.jcur] = now; // same visit; the entry IS where you are @@ -6604,6 +6685,21 @@ pub const Pardes = struct { if (p.njumps == 0 or next < 0 or next >= p.njumps) return; const j = p.jumps[@intCast(next)]; if (j.pane >= MAX_PANES) return; + // A closed file's entry: opened again at its dot, placed as a look + // places it, and the entry is that pane from here on. + if (j.serial == 0) { + const e = p.recentByHash(j.path_hash) orelse return; + var where: [recent_path_cap + 32]u8 = undefined; + const loc = std.fmt.bufPrint(&where, "{s}:{d}:{d}", .{ e.path, @max(1, j.line), @max(1, j.col) }) catch return; + const from = p.active; + look.lookAt(p, from, loc); + const opened = p.panes[p.active] orelse return; + if (p.active == from) return; + p.jumps[@intCast(next)].pane = @intCast(p.active); + p.jumps[@intCast(next)].serial = opened.serial; + p.jcur = @intCast(next); + return; + } const pane = p.panes[j.pane] orelse return; if (pane.serial != j.serial) return; if (p.panes[p.active]) |source| look.clearNavigationSelection(p, source); @@ -6640,6 +6736,8 @@ pub const Pardes = struct { if (refused) for (0..p.ncol) |c| if (!layout.columnAtMinimums(p, c)) { _ = layout.shareColumn(p, c); }; + // A file opened or closed this step: the kept list follows. + p.saveRecent(); tagline.flattenHeaders(p); if (p.header_column != null and p.columnBarHeight() == 0) { tagline.exitHeader(p); diff --git a/src/recent.zig b/src/recent.zig new file mode 100644 index 00000000..b6a1a66a --- /dev/null +++ b/src/recent.zig @@ -0,0 +1,119 @@ +//! The files opened lately, most recent first, those since closed too, as +//! `Recent` lists them and a jump to a closed pane reopens them: a path +//! and where the dot was when it closed. Kept across sessions in a small +//! file under $XDG_STATE_HOME/pardes (Options.recent_path) when the host +//! gives one. acme has nothing like it (its dump and Load are the nearest): +//! a file closed by accident, its path forgotten, is found here again. + +const std = @import("std"); + +/// At most this many files are remembered, the oldest dropped first. +pub const cap = 200; + +pub const Entry = struct { + path: []u8, + /// Where its dot was when it last closed (1-based; 0 none). + line: u32 = 0, + col: u32 = 0, +}; + +pub const List = struct { + entries: std.ArrayList(Entry) = .empty, + /// Changed since it was last written out. + dirty: bool = false, + + pub fn deinit(l: *List, gpa: std.mem.Allocator) void { + for (l.entries.items) |e| gpa.free(e.path); + l.entries.deinit(gpa); + } + + fn find(l: *const List, path: []const u8) ?usize { + for (l.entries.items, 0..) |e, i| if (std.mem.eql(u8, e.path, path)) return i; + return null; + } + + /// `path` opened: first in the list, once, keeping the dot it closed at. + pub fn opened(l: *List, gpa: std.mem.Allocator, path: []const u8) void { + if (path.len == 0) return; + var entry: Entry = if (l.find(path)) |i| l.entries.orderedRemove(i) else .{ + .path = gpa.dupe(u8, path) catch return, + }; + if (l.entries.items.len >= cap) { + const last = l.entries.pop().?; + gpa.free(last.path); + } + l.entries.insert(gpa, 0, entry) catch { + gpa.free(entry.path); + entry = undefined; + return; + }; + l.dirty = true; + } + + /// `path` closed with its dot at `line`:`col`: where a reopen lands. + /// Its place in the list is its opening's. + pub fn closed(l: *List, gpa: std.mem.Allocator, path: []const u8, line: u32, col: u32) void { + const i = l.find(path) orelse found: { + l.opened(gpa, path); + // Out of memory for it: nothing to note the dot on. + break :found l.find(path) orelse return; + }; + l.entries.items[i].line = line; + l.entries.items[i].col = col; + l.dirty = true; + } + + pub fn get(l: *const List, path: []const u8) ?Entry { + return l.entries.items[l.find(path) orelse return null]; + } + + /// One line a file, ` `, most recent first. + pub fn write(l: *const List, w: *std.Io.Writer) !void { + for (l.entries.items) |e| try w.print("{d} {d} {s}\n", .{ e.line, e.col, e.path }); + } + + /// The lines `write` wrote; a line that is not one is passed over. + pub fn read(l: *List, gpa: std.mem.Allocator, bytes: []const u8) void { + var lines = std.mem.splitScalar(u8, bytes, '\n'); + while (lines.next()) |line| { + if (l.entries.items.len >= cap) break; + var it = std.mem.splitScalar(u8, line, ' '); + const ln = std.fmt.parseInt(u32, it.next() orelse continue, 10) catch continue; + const col = std.fmt.parseInt(u32, it.next() orelse continue, 10) catch continue; + const path = it.rest(); + if (path.len == 0 or path[0] != '/' or l.find(path) != null) continue; + const owned = gpa.dupe(u8, path) catch return; + l.entries.append(gpa, .{ .path = owned, .line = ln, .col = col }) catch { + gpa.free(owned); + return; + }; + } + } +}; + +test "the list keeps a path once, most recent first, its dot from closing, capped" { + const gpa = std.testing.allocator; + var l: List = .{}; + defer l.deinit(gpa); + l.opened(gpa, "/a"); + l.opened(gpa, "/b"); + l.closed(gpa, "/a", 7, 3); + l.opened(gpa, "/a"); + try std.testing.expectEqualStrings("/a", l.entries.items[0].path); + try std.testing.expectEqual(@as(usize, 2), l.entries.items.len); + try std.testing.expectEqual(@as(u32, 7), l.get("/a").?.line); + var buf: [256]u8 = undefined; + var w = std.Io.Writer.fixed(&buf); + try l.write(&w); + try std.testing.expectEqualStrings("7 3 /a\n0 0 /b\n", w.buffered()); + var again: List = .{}; + defer again.deinit(gpa); + again.read(gpa, w.buffered()); + again.read(gpa, "junk\n"); + try std.testing.expectEqual(@as(usize, 2), again.entries.items.len); + for (0..cap + 5) |i| { + var name: [16]u8 = undefined; + l.opened(gpa, std.fmt.bufPrint(&name, "/f{d}", .{i}) catch unreachable); + } + try std.testing.expectEqual(@as(usize, cap), l.entries.items.len); +} diff --git a/test/fs.py b/test/fs.py index 20a9bbff..977b3e45 100644 --- a/test/fs.py +++ b/test/fs.py @@ -161,7 +161,7 @@ def discovery(binary, embedded=False): with session(binary, root, 'discovery') as (client, address): top = client.list('/') # A set: which files the root holds, not the order a listing gives. - assert set(top) - {'src', 'shaders'} == {'README', 'index', 'status', 'focus', 'ctl', 'commands', + assert set(top) - {'src', 'shaders'} == {'README', 'index', 'status', 'focus', 'ctl', 'commands', 'recent', 'look', 'exec', 'log', 'screen', 'listeners', 'layout', 'tag', 'tagexec', 'pane', 'col', 'os'}, top assert 'self' not in top and 'cons' not in top and 'new' not in top, top @@ -539,6 +539,31 @@ def new_terminals_named_once(binary): assert str(made[0]).encode() in b' '.join(r.split()[0] for r in client.read('/index').splitlines()) +def recent_survives_restart(binary): + """A file opened and closed is in /recent closed, and still is in the + next session: the list is kept under $XDG_STATE_HOME (here HOME's + .local/state) across restarts.""" + with tempfile.TemporaryDirectory(prefix='pardes-recent-') as directory: + root = Path(directory) + kept = root / 'kept.txt' + kept.write_bytes(b'one\ntwo\n') + with session(binary, root, 'recent1') as (client, _): + serial = look(client, f'{kept}:2') + assert f'open {kept}\n' in client.read('/recent').decode() + client.write(f'/pane/{serial}/ctl', b'Del\n') + assert f'closed {kept}\n' in client.read('/recent').decode(), client.read('/recent') + assert (root / '.local' / 'state' / 'pardes' / 'recent').exists() + with session(binary, root, 'recent2') as (client, _): + listed = client.read('/recent').decode() + assert f'closed {kept}\n' in listed, listed + # Recent shows it, and a look at its row opens it again. + client.write('/pane/1/exec', b'Recent\n') + rows = int(client.read('/pane/1/exec').split()[-1]) + row = next(r for r in client.read(f'/pane/{rows}/body').decode().splitlines() if r.startswith(f'{kept}:')) + client.write(f'/pane/{rows}/look', (row.split(' ')[0] + '\n').encode()) + assert f'open {kept}\n' in client.read('/recent').decode() + + def workflow_canary(binary): """One session driven as the dogfood agents drive it, asserting the log and the read-backs at every step: the canary for the main paths (the @@ -803,6 +828,7 @@ def test(binary, quic=False): unattended_messages_expire(binary) new_terminals_named_once(binary) workflow_canary(binary) + recent_survives_restart(binary) python_repl_runs_one_line(binary) signal_cleans_up(binary) for options, message in [ -- cgit v1.3 From 5fd713889b6bdeb27c58941b77266c9336bf7b7d Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 29 Sep 2026 10:31:15 -0300 Subject: ThemeSel is Themes and FontSel is Fonts; the old words still work in init files and dumps The user asked for the plainer words. Every use is renamed: the builtins, leader paths, /commands, the docs and tutor, tests, and the themesel golden, re-recorded. An init file's ThemeSel or FontSel runs the new word and says `ThemeSel: renamed to Themes`, as ColumnTags is said; a dump naming an output pane by the old word restores it. Co-Authored-By: Claude Opus 5.5 --- README.md | 2 +- docs/config.md | 6 +++--- docs/design.typ | 2 +- docs/fs.md | 2 +- docs/helix-keys.md | 2 +- docs/macos.md | 2 +- docs/themes.md | 4 ++-- docs/ui-review.md | 4 ++-- src/Output.zig | 9 ++++++--- src/builtins.zig | 4 ++-- src/colors.zig | 2 +- src/config.zig | 4 ++-- src/exec.zig | 28 ++++++++++++++++++++++++++-- src/ninep/ctl.zig | 4 ++-- test/appearance_gallery.py | 8 ++++---- test/output.zig | 10 +++++----- test/snapshots/themesel.golden | 2 +- test/snapshots/themesel.snap | 2 +- 18 files changed, 62 insertions(+), 35 deletions(-) (limited to 'src/Output.zig') diff --git a/README.md b/README.md index 826f86c8..d7548e8c 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ diagnostics and embedded terminal: `orchard` (the near-black default), `dusk`, `daybreak` provide high contrast dark and light choices. Six classic-inspired adaptations add `forge`, `lagoon`, `solarium`, `spectrum`, `harvest`, and `clay`. `forge_black` and `orchard_black` offer pure-black variations; `forge_soft` -offers a deliberately softer contrast. Execute `ThemeSel` to choose native +offers a deliberately softer contrast. Execute `Themes` to choose native themes first, followed by the existing legacy/imported collection. `FocusTint` toggles the active pane and column tag tints (on by default), and `SyntaxBold` toggles bold syntax keywords (off by default), in both GUI and TTY. diff --git a/docs/config.md b/docs/config.md index 96281cd5..9d7446f1 100644 --- a/docs/config.md +++ b/docs/config.md @@ -96,7 +96,7 @@ The SDL GUI also has `WindowOpacity`, which takes one argument. `builtins.Board.enabled` holds, and that build has no config file.) `Theme ` wants one of the names in the compiled ring. Do not derive the -spelling — read it off `ThemeSel` (`SPC t t`), which lists every one as the +spelling — read it off `Themes` (`SPC t t`), which lists every one as the exact `Theme ` line that selects it. `slug` in `tools/gen_themes.zig` lowercases, folds punctuation runs to a single `_` and then TRIMS leading and trailing ones (`penumbra+.toml` is `penumbra`, not `penumbra_`), and every @@ -109,7 +109,7 @@ project gains or loses a file. A name that is not in the ring is ignored. The fifteen [native Pardes themes](themes.md) lead the ring: `orchard` (the default), `dusk`, `ink`, `paper`, `daybreak`, `atelier`, `forge`, `lagoon`, `solarium`, `spectrum`, `harvest`, `clay`, `forge_black`, `forge_soft`, and -`orchard_black`. `ThemeSel` lists them first under Pardes themes, followed by +`orchard_black`. `Themes` lists them first under Pardes themes, followed by a separate legacy/imported section. They add coordinated focus, search, diagnostic and terminal colors; `ink` and `daybreak` are high contrast dark and light options. The original `helix`, `dark` and `acme` @@ -391,7 +391,7 @@ asked for one. Neither reaches the child as a keystroke, so an application that would otherwise answer Ctrl-V by reading the system clipboard itself never gets the chance to read the wrong thing. -`Font` and `FontSel` exist ONLY in the SDL GUI and native macOS builds — a +`Font` and `Fonts` exist ONLY in the SDL GUI and native macOS builds — a terminal's font belongs to its emulator and a browser's to the page — so a `Font` line is one of the silently-ignored ones everywhere else. Both builds resolve the name by walking the font directories on every lookup, so a face diff --git a/docs/design.typ b/docs/design.typ index 639884a9..ed2bbb94 100644 --- a/docs/design.typ +++ b/docs/design.typ @@ -2010,7 +2010,7 @@ one pair per theme, and the three per-button tints and the dimmed extra cursors are mixed off it, so what stays fixed is the distinction between buttons and not the colours. `NextColor` browses the ring one step at a time — at 228 it is no longer how you REACH one — -`Theme ` jumps to one and `ThemeSel` (`SPC t t`) lists them all into an +`Theme ` jumps to one and `Themes` (`SPC t t`) lists them all into an output buffer whose rows are those very commands — execute a row (Tab, middle click) and the theme goes on; n/N select such a row WHOLE, since a command line holds no place to pick out of it — the third grain of that motion, the diff --git a/docs/fs.md b/docs/fs.md index dedfe94f..ceca1dd9 100644 --- a/docs/fs.md +++ b/docs/fs.md @@ -274,7 +274,7 @@ argument to a builtin that takes none, or none to one that needs it (`Msg`, `Mount`, `Find`, a setting's value but a switch's, which flips bare); `bad value in control message "X"` for a setting's value it does not take (for `Theme`, naming the themes that share the name's first letter, since -all of them, `ThemeSel`'s list, are too many for an error); +all of them, `Themes`'s list, are too many for an error); and `not a session control message "X": write it to pane//ctl` or `not a window control message "X": write it to /ctl` for a word of the other ctl. 9ns maps them all to EINVAL, and a write refused here has done nothing. A line that then fails as it runs fails the diff --git a/docs/helix-keys.md b/docs/helix-keys.md index 5d89ba92..b1035ad6 100644 --- a/docs/helix-keys.md +++ b/docs/helix-keys.md @@ -135,7 +135,7 @@ language-backend queries, and the shell pipe. | `SPC y` `SPC Y` `SPC p` `SPC P` `SPC R` | helix's clipboard menu on helix's own letters: yank the selection to the system clipboard (`ClipYank`) or the PRIMARY selection alone (`ClipYankMain`), paste the system clipboard after (`ClipPaste`) / before (`ClipPasteBefore`) the selection, replace the selection with it (`ClipReplace`) | the same as `"+y`, `"+p`, `"+P`, `"+R`: register `+` (and `*`) IS the desktop's clipboard, the only register that reaches it. `SPC y` writes `+` alone, as helix's does, not the default register too. Builtins rather than bare chords because a leader path names a builtin: they land in Help's index and are executable words like every other verb. The clipboard holds one text, so N values go out joined by newlines, as helix sends them. On a tty the write is OSC 52 out and the READ is OSC 52 back, which many terminals refuse or gate — so `SPC y` works there and `SPC p` can be a no-op | out of corpus | | a paste from the OUTER terminal | one `Event.paste`, spliced in at the cursor | the tty shell enables bracketed paste and coalesces `paste_start`..`paste_end` into a single event; before that the bytes arrived as individual key presses and normal mode RAN them, which is how a pasted `d` deleted a line. The bytes deliberately never enter the yank register — clipboard and default register are separate stores in both directions | pardes-specific | | `/` (any pane) | pardes' own plain-substring search into a `+Search` output buffer: the pattern is typed on a line of its own on the pane's notice band, Enter fills the buffer, and its rows are ordinary look targets. Enter also GOES to the first row — the buffer is focused and then the step `n` is and the look Enter is run in it (`Pardes.lookFirstHit`), so `/foo` lands on the first hit with the matched span selected. A pattern that matched nothing opens its empty buffer and moves nothing | KEEP, do not touch; not in the corpus (helix `/` is regex search). Find and Grep answer with OTHER files and deliberately do NOT jump. The stepping half is the next row | pardes-specific | -| `n` / `N` (any pane) | MOTION, not a jump: move the SELECTION to the next / previous look-able text and open NOTHING. Enter — the look chord — on what it leaves selected is what opens it | KEEP, do not touch; not in the corpus (helix's `n`/`N` walk regex search hits). What a step selects is the pane's GRAIN (`output_pane.Grain`, read in `Pardes.lookSpanIn`): in FREE TEXT — a terminal, a file, a PDF, a prose answer buffer — the largest whitespace-delimited run `look.resolve` can act on (`look.lookableSpan`, wrapper punctuation peeled off both ends), several to a line; in a RESULTS BUFFER one stop per ROW, the largest run its head resolves as (`look.lookableLineSpan`), because a row there IS one location and the words after it are the match rather than a second place to go; in a COMMAND list the whole line. The walk is a RING across PANES: every pane that has performed a Look, most recent first (`Pardes.look_src`), then the output buffers that have not, newest first, and only when both are empty the active pane. Exhausting a pane enters the next at its first (forward) / last (backward) span and the end wraps to the start, so `N` is the exact inverse of `n`. What it lands on becomes an EXPLICIT `vsel` with the cursor on its FIRST column, in the pane the walk focuses. ONE motion in every pane kind and every buffer kind — a PDF steps the `+Search` buffer its own search filled, `n` to select the row and Enter to jump. The single thing a buffer may change is that grain, and it changes it by BEING a kind of buffer rather than by a branch: `output_pane.Traits.steps` (a list of locations) makes a step take one row at a time, and `Traits.commands` makes it take the WHOLE LINE, because a command list (`ThemeSel`/`FontSel`) holds words to run and there is no path inside `Theme gruvbox` to pick out. Tab on what `n` selected wears the theme, which is the same middle click on the row is. `]d`/`[d` are helix's diagnostic motions, a different binding, and they do still jump to each diagnostic (`docs/lsp.md`) | pardes-specific | +| `n` / `N` (any pane) | MOTION, not a jump: move the SELECTION to the next / previous look-able text and open NOTHING. Enter — the look chord — on what it leaves selected is what opens it | KEEP, do not touch; not in the corpus (helix's `n`/`N` walk regex search hits). What a step selects is the pane's GRAIN (`output_pane.Grain`, read in `Pardes.lookSpanIn`): in FREE TEXT — a terminal, a file, a PDF, a prose answer buffer — the largest whitespace-delimited run `look.resolve` can act on (`look.lookableSpan`, wrapper punctuation peeled off both ends), several to a line; in a RESULTS BUFFER one stop per ROW, the largest run its head resolves as (`look.lookableLineSpan`), because a row there IS one location and the words after it are the match rather than a second place to go; in a COMMAND list the whole line. The walk is a RING across PANES: every pane that has performed a Look, most recent first (`Pardes.look_src`), then the output buffers that have not, newest first, and only when both are empty the active pane. Exhausting a pane enters the next at its first (forward) / last (backward) span and the end wraps to the start, so `N` is the exact inverse of `n`. What it lands on becomes an EXPLICIT `vsel` with the cursor on its FIRST column, in the pane the walk focuses. ONE motion in every pane kind and every buffer kind — a PDF steps the `+Search` buffer its own search filled, `n` to select the row and Enter to jump. The single thing a buffer may change is that grain, and it changes it by BEING a kind of buffer rather than by a branch: `output_pane.Traits.steps` (a list of locations) makes a step take one row at a time, and `Traits.commands` makes it take the WHOLE LINE, because a command list (`Themes`/`Fonts`) holds words to run and there is no path inside `Theme gruvbox` to pick out. Tab on what `n` selected wears the theme, which is the same middle click on the row is. `]d`/`[d` are helix's diagnostic motions, a different binding, and they do still jump to each diagnostic (`docs/lsp.md`) | pardes-specific | | insert: printable text | file: real edit; terminal: typed run splice | | helix-verified (file) | | insert: `Enter` | newline; keeps the current full indent levels and adds one 4-space logical tab when the text before the cursor ends in `(`, `[`, `{`, or `)` (including `})`) | plain lines match `insert_newline`; delimiter heuristic is pardes-specific | helix-verified (plain) / pardes-specific (delimiter) | | insert: `Backspace` (+ `Shift-Backspace`) | delete prev char, joins lines at col 0; in a line's leading blanks, back to the previous 4-column indent stop (a whole unit when on one; a tab still goes alone) | matches `delete_char_backward` and its dedent; `Ctrl-h` alias in B | helix-verified | diff --git a/docs/macos.md b/docs/macos.md index cf7091e6..8bb81be6 100644 --- a/docs/macos.md +++ b/docs/macos.md @@ -495,7 +495,7 @@ has none: The face is the shell's business and the size is the window's, so the two are reached differently on purpose. -`Font ` and the `FontSel` picker are ordinary core builtins, enabled by +`Font ` and the `Fonts` picker are ordinary core builtins, enabled by `pardes.font_picker` — the frontends that draw their own text, which is now the SDL shell and this one. `src/fonts.zig` moved out of `gui/` for that reason. It walks the platform's font directories and reads four small sfnt tables per file diff --git a/docs/themes.md b/docs/themes.md index 38596819..5349a764 100644 --- a/docs/themes.md +++ b/docs/themes.md @@ -3,11 +3,11 @@ Pardes ships fifteen native palettes: six originals, six classic-inspired adaptations and three contrast variants, designed for tags, text, search, diagnostics and embedded terminals together. `orchard` is the initial theme. -Execute `Theme ` anywhere, or open `ThemeSel` with `SPC t t` and select +Execute `Theme ` anywhere, or open `Themes` with `SPC t t` and select a theme's command. Put the same command in your [startup configuration](config.md) to keep a preference. `NextColor` cycles through the native themes first, then the retained `helix`, `dark` and `acme` themes and imported palettes. -`ThemeSel` groups the new palettes under `Pardes themes`, followed by +`Themes` groups the new palettes under `Pardes themes`, followed by `Legacy and imported themes`; its navigation skips the section headings. See the [Agave visual review](ui-review.md) for the original six-palette gallery. diff --git a/docs/ui-review.md b/docs/ui-review.md index 1180a20e..decf042d 100644 --- a/docs/ui-review.md +++ b/docs/ui-review.md @@ -12,7 +12,7 @@ and silver-blue chrome. `forge_black` and `orchard_black` use pure black; `forge_soft` joins `dusk`, `lagoon` and `solarium` as deliberately softer alternatives. Light and Acme-inspired choices remain available. -`ThemeSel` opens with the native collection, followed by a separate legacy +`Themes` opens with the native collection, followed by a separate legacy and imported section. Keyboard navigation skips both section headings. `Collapse` now transfers all released rows to one expanded pane, preferring @@ -36,7 +36,7 @@ sent to the user's session. - [Six contrast studies, OS screenshot crops](screenshots/theme-preferences.png) - [Neutral Forge, full workspace](screenshots/theme-preferences-forge.png) -- [Native-first ThemeSel, full workspace](screenshots/theme-selector.png) +- [Native-first Themes, full workspace](screenshots/theme-selector.png) ## Compact rails, classic palettes and workspace pets diff --git a/src/Output.zig b/src/Output.zig index dd6ab92a..a75718bf 100644 --- a/src/Output.zig +++ b/src/Output.zig @@ -250,6 +250,9 @@ pub fn fromWord(w: []const u8) ?Origin { if (std.mem.eql(u8, w, "/")) return .search; if (std.mem.eql(u8, w, config.errors_buffer)) return .errors; if (std.mem.eql(u8, w, config.pdf_links_buffer)) return .pdf_links; + // A dump from before the rename names them by their old words. + if (std.mem.eql(u8, w, "ThemeSel")) return .{ .cmd = .Themes }; + if (builtins.capabilities.font_picker) if (std.mem.eql(u8, w, "FontSel")) return .{ .cmd = .Fonts }; if (std.meta.stringToEnum(Builtin, w)) |b| if (builtins.registry.outputTraits(b) != null) return .{ .cmd = b }; if (std.meta.stringToEnum(lsp.Kind, w)) |k| return .{ .query = k }; @@ -591,13 +594,13 @@ pub fn openThemes(p: *Pardes, id: usize) !void { try out.writer.print(comptime config.Runtime.findAction(.theme).?.word ++ " {s}\n", .{t.name}); } const content = try out.toOwnedSlice(); - try openStepped(p, id, .{ .cmd = .ThemeSel }, content); + try openStepped(p, id, .{ .cmd = .Themes }, content); } pub fn isWalkRow(file: *const File.State, row: usize, line: []const u8) bool { const state = file.output orelse return true; if (usesLocationsConfig(state.from)) return isResultRow(file, row); - if (!std.meta.eql(state.from, Origin{ .cmd = .ThemeSel })) return true; + if (!std.meta.eql(state.from, Origin{ .cmd = .Themes })) return true; // Section labels are for reading, not stops in the command walk. return std.mem.startsWith(u8, std.mem.trimStart(u8, line, " \t"), comptime config.Runtime.findAction(.theme).?.word ++ " "); } @@ -611,7 +614,7 @@ pub fn openFonts(p: *Pardes, id: usize) !void { for (font_list) |f| try out.writer.print(comptime config.Runtime.findAction(.font).?.word ++ " {s}\n", .{f.name}); const content = try out.toOwnedSlice(); - try openStepped(p, id, .{ .cmd = .FontSel }, content); + try openStepped(p, id, .{ .cmd = .Fonts }, content); } } diff --git a/src/builtins.zig b/src/builtins.zig index 2247fcbb..041eb1b8 100644 --- a/src/builtins.zig +++ b/src/builtins.zig @@ -741,7 +741,7 @@ pub const NextColor = struct { }; /// List the themes in a pane, each a word to click. -pub const ThemeSel = struct { +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 { @@ -779,7 +779,7 @@ pub const DumpThemes = struct { }; /// List the fonts in a pane, each a word to click. -pub const FontSel = struct { +pub const Fonts = struct { pub const scope: Scope = .session; pub const output: OutputTraits = .{ .name = config.fonts_buffer, .steps = true, .commands = true }; pub const enabled = capabilities.font_picker; diff --git a/src/colors.zig b/src/colors.zig index 8319a112..5694998d 100644 --- a/src/colors.zig +++ b/src/colors.zig @@ -559,7 +559,7 @@ fn invalidateThemeDependentRasters(p: *Pardes) void { } /// Themes whose names share `name`'s first letter, a line of them, for a -/// Theme given a name there is none of: all of them (ThemeSel) are too many +/// Theme given a name there is none of: all of them (Themes) are too many /// for a message or a refused write. pub fn themesNear(buf: []u8, name: []const u8) []const u8 { var w = std.Io.Writer.fixed(buf); diff --git a/src/config.zig b/src/config.zig index c7ea5411..2b5bf280 100644 --- a/src/config.zig +++ b/src/config.zig @@ -88,7 +88,7 @@ pub const leader_path = paths: { .Wrap = "tw", .Tagbottom = "tb", .NextColor = "tn", - .ThemeSel = "tt", + .Themes = "tt", .Theme = null, .Shell = null, .Petscii = "tp", @@ -109,7 +109,7 @@ pub const leader_path = paths: { .Exec = null, }); if (builtins.capabilities.font_picker) { - table.set(.FontSel, "tf"); + table.set(.Fonts, "tf"); table.set(.Font, null); table.set(.TaglineSize, null); } diff --git a/src/exec.zig b/src/exec.zig index 60c4172d..1fc38b9c 100644 --- a/src/exec.zig +++ b/src/exec.zig @@ -811,11 +811,35 @@ pub fn applyStartupConfig(p: *Pardes) void { if (executeBuiltinLine(p, p.active, line)) continue; // A setting pardes no longer has is said, once, and changes nothing. const word = commandText(line); - if (std.mem.eql(u8, word[0 .. std.mem.indexOfAny(u8, word, " \t") orelse word.len], "ColumnTags")) + const head = word[0 .. std.mem.indexOfAny(u8, word, " \t") orelse word.len]; + if (std.mem.eql(u8, head, "ColumnTags")) p.setMessage(p.active, "ColumnTags: column tags are always shown now; the init line is ignored"); + // A word renamed runs as its new name, and says so, once a line. + for ([_][2][]const u8{ .{ "ThemeSel", "Themes" }, .{ "FontSel", "Fonts" } }) |renamed| if (std.mem.eql(u8, head, renamed[0])) { + _ = executeBuiltinLine(p, p.active, renamed[1]); + var said: [64]u8 = undefined; + p.setMessage(p.active, std.fmt.bufPrint(&said, "{s}: renamed to {s}", .{ renamed[0], renamed[1] }) catch "renamed"); + }; } } +test "an init file's ThemeSel runs as Themes and says it was renamed" { + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 80, .rows = 24 }); + defer p.deinit(); + p.opts.startup_config = "ThemeSel\n"; + applyStartupConfig(p); + var listed = false; + for (p.panes) |slot| if (slot) |pane| if (pane.file) |f| if (f.output) |o| { + listed = listed or std.meta.eql(o.from, panes.Output.Origin{ .cmd = .Themes }); + }; + try std.testing.expect(listed); + var said = false; + for (p.panes) |slot| if (slot) |pane| { + said = said or std.mem.eql(u8, pane.msg[0..pane.msg_len], "ThemeSel: renamed to Themes"); + }; + try std.testing.expect(said); +} + test "an init file's retired ColumnTags line is said and ignored" { const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 80, .rows = 24 }); defer p.deinit(); @@ -873,7 +897,7 @@ pub fn applySettingBuiltin(p: *Pardes, setting: config.Runtime.Setting, arg: ?[] if (!p.announce) return; var near: [96]u8 = undefined; var text: [200]u8 = undefined; - return p.reportFailure(p.active, std.fmt.bufPrint(&text, "Theme: no theme \"{s}\"; like it: {s}; ThemeSel lists all", .{ want[0..@min(want.len, 40)], colors.themesNear(&near, want) }) catch "Theme: no such theme"); + return p.reportFailure(p.active, std.fmt.bufPrint(&text, "Theme: no theme \"{s}\"; like it: {s}; Themes lists all", .{ want[0..@min(want.len, 40)], colors.themesNear(&near, want) }) catch "Theme: no such theme"); }, .font => { if (comptime !font_picker) return; diff --git a/src/ninep/ctl.zig b/src/ninep/ctl.zig index 22a0923b..18a7eaa9 100644 --- a/src/ninep/ctl.zig +++ b/src/ninep/ctl.zig @@ -414,7 +414,7 @@ fn checkBuiltin(p: *Pardes, req: Req, line: []const u8, scope: builtins.Scope) ? // `refuse` quotes the line after it, in what is left of 128. var near: [40]u8 = undefined; var why: [104]u8 = undefined; - return refuse(p, req, std.fmt.bufPrint(&why, "bad value in control message; like it: {s}; ThemeSel lists all", .{pardes.colors.themesNear(&near, arg)}) catch "bad value in control message", line); + return refuse(p, req, std.fmt.bufPrint(&why, "bad value in control message; like it: {s}; Themes lists all", .{pardes.colors.themesNear(&near, arg)}) catch "bad value in control message", line); }, .font => config.Runtime.FontSpec.parse(arg) != null, else => probe: { @@ -1093,7 +1093,7 @@ test "the root ctl reads the settings as a write takes them, and takes the sessi try testing.expectEqualStrings("bad value in control message; takes acme, pardes \"Placement east\"", wr(p, root_ctl, "Placement east").reply.ename); const no_theme = wr(p, root_ctl, "Theme no-such-theme").reply.ename; try testing.expectStringStartsWith(no_theme, "bad value in control message; like it: n"); - try testing.expect(std.mem.endsWith(u8, no_theme, "; ThemeSel lists all \"Theme no-such-theme\"")); + try testing.expect(std.mem.endsWith(u8, no_theme, "; Themes lists all \"Theme no-such-theme\"")); try testing.expectEqualStrings("wrong #args in control message \"Newcol 2\"", wr(p, root_ctl, "Newcol 2").reply.ename); try testing.expectEqualStrings("wrong #args in control message \"Theme\"", wr(p, root_ctl, "Theme").reply.ename); // A bare required word fails the check, so the line before never runs. diff --git a/test/appearance_gallery.py b/test/appearance_gallery.py index bc9a7570..46b17dd9 100644 --- a/test/appearance_gallery.py +++ b/test/appearance_gallery.py @@ -51,7 +51,7 @@ Orchard: crisp woodland color Dusk: intentionally soft and warm Theme dusk -ThemeSel: Pardes themes come first. +Themes: Pardes themes come first. ''' @@ -159,16 +159,16 @@ def run(args): if args.theme_selector: command(client, terminal, 'Collapse') before = set(panes(client)) - command(client, right, 'ThemeSel') + command(client, right, 'Themes') selector = require(wait_for(lambda: next((s for s in panes(client) if s not in before), None)), - 'ThemeSel missing') + 'Themes missing') body = client.read(f'/pane/{selector}/body').decode() native, legacy = body.split('# Legacy and imported themes', 1) for theme in ('forge_black', 'forge_soft', 'orchard_black'): require('Theme ' + theme + '\n' in native, 'native contrast variant below legacy heading') require('Theme helix\n' in legacy, 'legacy theme section missing') require('Theme orchard' in ''.join(c[0] for c in client.screen()['cells']), - 'ThemeSel did not open at native first entry') + 'Themes did not open at native first entry') take_frame('theme-selector') report['native_themes_first'] = True client.write(f'/pane/{selector}/exec', b'Del\n') diff --git a/test/output.zig b/test/output.zig index 478f1b4a..21c02e0a 100644 --- a/test/output.zig +++ b/test/output.zig @@ -952,13 +952,13 @@ test "N exactly reverses n across output panes and the ring seam" { try std.testing.expect(saw_first and saw_second); } -test "ThemeSel groups native themes first and skips headings in both directions" { +test "Themes groups native themes first and skips headings in both directions" { const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 40 }); defer p.deinit(); const source = try p.setTestFile("notes\n"); pardes.colors.setThemeIndex(p, pardes.themes.len - 1); const original_theme = p.settings.theme; - try std.testing.expect(p.executeBuiltinLine(0, "ThemeSel")); + try std.testing.expect(p.executeBuiltinLine(0, "Themes")); const tid = source.search_pane orelse return error.MissingThemeList; const list = p.panes[tid].?; const content = list.file.?.content; @@ -979,12 +979,12 @@ test "ThemeSel groups native themes first and skips headings in both directions" for (pardes.themes[0 .. pardes.native_theme_count + 1]) |theme| { p.update(.{ .key = .{ .cp = 'n' } }); try std.testing.expectEqual(tid, p.active); - const selected = selectedOutputText(list) orelse return error.MissingThemeSelection; + const selected = selectedOutputText(list) orelse return error.MissingThemesection; try std.testing.expectEqualStrings(theme.name, selected["Theme ".len..]); try std.testing.expectEqual(original_theme, p.settings.theme); } p.update(.{ .key = .{ .cp = 'N' } }); - const previous = selectedOutputText(list) orelse return error.MissingThemeSelection; + const previous = selectedOutputText(list) orelse return error.MissingThemesection; try std.testing.expectEqualStrings(pardes.themes[pardes.native_theme_count - 1].name, previous["Theme ".len..]); p.update(.{ .key = .{ .cp = Key.tab } }); try std.testing.expectEqual(pardes.native_theme_count - 1, p.settings.theme); @@ -999,7 +999,7 @@ test "n/N selects command outputs by whole row" { defer p.deinit(); p.update(.{ .resize = .{ .cols = 100, .rows = 40 } }); - try std.testing.expect(p.executeBuiltinLine(p.active, "ThemeSel")); + try std.testing.expect(p.executeBuiltinLine(p.active, "Themes")); const tid = p.panes[p.active].?.search_pane orelse return error.MissingThemeList; const themes = p.panes[tid].?; try std.testing.expect(panes.Output.fileTraits(themes.file.?.output).commands); diff --git a/test/snapshots/themesel.golden b/test/snapshots/themesel.golden index 8d453978..92e641f5 100644 --- a/test/snapshots/themesel.golden +++ b/test/snapshots/themesel.golden @@ -31,7 +31,7 @@ | 27 line 27 | 28 line 28 == snap list grid=100x31 cursor=7,3 -|3: 1 line 1 ThemeSel +|3: 1 line 1 Themes |16: /tmp/pardes-snap/themesel/cwd/+Themes Save Tty Collapse Del |17: 1 # Pardes themes |18: 2 Theme orchard diff --git a/test/snapshots/themesel.snap b/test/snapshots/themesel.snap index 04a95d23..2b7b03c4 100644 --- a/test/snapshots/themesel.snap +++ b/test/snapshots/themesel.snap @@ -1,7 +1,7 @@ # RULE: a results buffer is a list of things you can RUN, and its traits say # what a ROW IS. Every list before this one held LOCATIONS — a row with a # `path:LINE:COL` word inside it — so n/N select that word and Enter Looks it. -# `SPC t t` (ThemeSel) opens the first one whose rows are COMMANDS: `Theme +# `SPC t t` (Themes) opens the first one whose rows are COMMANDS: `Theme # `, exactly the line you would type, with no path in it to pick out, so # n/N select the WHOLE ROW. One motion, two grains, and the same split either # way — the step only SELECTS, and Tab (Exec, or the middle button, which is -- cgit v1.3 From d5743f2a58a03539d3c34bee3b2ad18b96b2da55 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 29 Sep 2026 10:44:30 -0300 Subject: A refusal over unsaved panes keeps its list in +Unsaved and shows a short notice MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Exit's refusal (and Restore's, Del's, Delcol's, get's) put its full text on a notice that went: a long list of names, gone before it was read. The list now goes into one +Unsaved pane, filled again by each refusal, a row a pane (`: Modified`) and the `Exit again to discard` line; the notice is short, `3 unsaved panes — Exit again to discard`. The 9P `unsaved` records and the write's err are as they were. Co-Authored-By: Claude Opus 5.5 --- .agents/skills/pardes-9p/SKILL.md | 3 ++- docs/fs.md | 11 +++++--- docs/tags.md | 5 ++-- src/Output.zig | 29 ++++++++++++++++++++- src/builtins.zig | 55 ++++++++++++++++++++++++++++++--------- src/config.zig | 1 + src/ninep/ctl.zig | 13 +++++---- 7 files changed, 92 insertions(+), 25 deletions(-) (limited to 'src/Output.zig') diff --git a/.agents/skills/pardes-9p/SKILL.md b/.agents/skills/pardes-9p/SKILL.md index 4678d55a..1fe2aed8 100644 --- a/.agents/skills/pardes-9p/SKILL.md +++ b/.agents/skills/pardes-9p/SKILL.md @@ -86,7 +86,8 @@ $m/ctl the settings, one a line as a write takes them; write a setting or matching a command line's first word; Exit and Restore refuse once, logging `unsaved ` for each unsaved pane, then failing the write with `: Modified (Exit again to discard)` for one or `4 unsaved panes: Modified (Exit - again to discard)` for more (Restore's says `Restore again`); a second refusal names only the panes edited since the last, + again to discard)` for more (Restore's says `Restore again`); on screen the list stays + in the one +Unsaved pane under a short notice (`3 unsaved panes — Exit again to discard`); a second refusal names only the panes edited since the last, as acme's does, and the same word again with nothing edited since DISCARDS them all -- not a retry, unlike lock's `file in use`; Kill stops a command pane's whole line, `&` jobs included; of a line typed into a shell only the foreground job, and the shell decides the rest (of `sleep 30; echo done` diff --git a/docs/fs.md b/docs/fs.md index ceca1dd9..f20b521a 100644 --- a/docs/fs.md +++ b/docs/fs.md @@ -193,9 +193,11 @@ through a `ctl` write or a click: first one `/log` record per pane, `unsaved `, then the write fails with one line that is never a list cut short, `: Modified (Exit again to discard)` for one pane, `4 unsaved panes: Modified (Exit again to discard)` for more, and -the `err` record says the same; each pane's message row names it, a -`+New` scratch with its serial, as scratches share a name: `/dir/+New -(pane 12): Modified (Exit again to discard)`. Restore, +the `err` record says the same. On screen the notice is short, `3 unsaved +panes — Exit again to discard`, and the whole list stays in one `+Unsaved` +pane, filled again by each refusal: a row a pane, `: Modified` (a +`+New` scratch with its serial, as scratches share a name, `/dir/+New +(pane 12): Modified`), then `Exit again to discard`. Restore, Del and Delcol refuse the same way, with their own word; an `Exit` after more editing refuses again naming only the panes edited since the last refusal, as acme's does, and an `Exit` with nothing edited since quits, throwing all of it away; a scratch or a @@ -580,7 +582,8 @@ length, a reserved zero, the dirty flag, the width in cells, the font and the tab width — followed by rio's `current` or `notcurrent` (rio(4), `wctl`): whether the pane has the keyboard. It takes the pane's builtins (below), `get`, which reloads the buffer from the name it -carries (unsaved edits are refused once, `: Modified (get again to +carries (unsaved edits are refused once, listed in `+Unsaved` with a short +notice as Exit's are, the write failing `: Modified (get again to discard)`, as acme's get asks winclean, exec.c:513). A file that changes on disk reloads by itself only into a buffer with no unsaved edits; one with them keeps its text and stays dirty, says ` changed on disk (get diff --git a/docs/tags.md b/docs/tags.md index 018536e6..d79c64b5 100644 --- a/docs/tags.md +++ b/docs/tags.md @@ -86,8 +86,9 @@ to its `ctl`, they step the body back and forward through its edits, as the `Del` closes a pane and gives its rows to one neighbor; the rest of the column keeps its heights. A pane with unsaved text is refused once, as -acme's Del warns (exec.c del, wind.c winclean): `: Modified (Del again -to discard)`, and the same `Del` again, nothing edited since, closes it and +acme's Del warns (exec.c del, wind.c winclean): a short notice, `1 unsaved +pane — Del again to discard`, the pane listed in a kept `+Unsaved` (`: +Modified`, then `Del again to discard`), and the same `Del` again, nothing edited since, closes it and throws the text away; `Delcol` refuses a column holding such a pane the same way (exec.c delcol). Each word warns on its own, from a key, a tag, `exec` or a ctl, where the refusal fails the write with EIO. `Del k` (or `DelAbove`) gives them to the nearest diff --git a/src/Output.zig b/src/Output.zig index a75718bf..c6012d06 100644 --- a/src/Output.zig +++ b/src/Output.zig @@ -29,6 +29,9 @@ pub const Origin = union(enum) { search, errors, pdf_links, + /// The panes a refusal (Exit, Restore, Del, Delcol, get) is over, kept + /// in +Unsaved rather than a notice that goes. + unsaved, }; pub const max_arg = dump.max_origin_arg; @@ -183,6 +186,7 @@ pub fn traits(o: Origin) Traits { .search => .{ .name = config.search_buffer, .steps = true, .locations = true }, .errors => .{ .name = config.errors_buffer, .doc = true }, .pdf_links => .{ .name = config.pdf_links_buffer, .steps = true, .locations = true }, + .unsaved => .{ .name = config.unsaved_buffer, .doc = true }, .cmd => |b| builtins.registry.outputTraits(b) orelse unreachable, .query => |k| switch (k) { .hover => .{ .name = config.hover_buffer }, @@ -242,6 +246,7 @@ pub fn word(o: Origin) []const u8 { .search => "/", .errors => config.errors_buffer, .pdf_links => config.pdf_links_buffer, + .unsaved => config.unsaved_buffer, }; } @@ -250,6 +255,7 @@ pub fn fromWord(w: []const u8) ?Origin { if (std.mem.eql(u8, w, "/")) return .search; if (std.mem.eql(u8, w, config.errors_buffer)) return .errors; if (std.mem.eql(u8, w, config.pdf_links_buffer)) return .pdf_links; + if (std.mem.eql(u8, w, config.unsaved_buffer)) return .unsaved; // A dump from before the rename names them by their old words. if (std.mem.eql(u8, w, "ThemeSel")) return .{ .cmd = .Themes }; if (builtins.capabilities.font_picker) if (std.mem.eql(u8, w, "FontSel")) return .{ .cmd = .Fonts }; @@ -315,7 +321,7 @@ fn sortResults(arena: std.mem.Allocator, from: Origin, content: []u8, anchor: ?u => {}, else => return anchor, }, - .errors, .pdf_links => return anchor, + .errors, .pdf_links, .unsaved => return anchor, } if (content.len == 0) return anchor; const path_only = std.meta.eql(from, Origin{ .cmd = .Find }); @@ -559,6 +565,27 @@ pub fn recentText(p: *Pardes, w: *std.Io.Writer, look_rows: bool) !void { } } +/// A refusal's list of unsaved panes, kept in the one +Unsaved: filled +/// again when it is there (as +Search is), else opened below `id`. Best +/// effort: with no room for it, the notice and the log still say it. +pub fn openUnsaved(p: *Pardes, id: usize, content: []u8) void { + for (p.panes) |slot| { + const rp = slot orelse continue; + const rf = if (rp.file) |*f| f else continue; + const o = rf.output orelse continue; + if (o.from != .unsaved) continue; + File.setContent(p, rf, content); + resetBody(p, rp); + return; + } + const pane = p.panes[id] orelse return p.gpa.free(content); + const dir = if (pane.file) |f| (std.fs.path.dirname(f.path) orelse "/") else pane.cwdSlice(); + const free = p.freeSlot() orelse return p.gpa.free(content); + _ = open(p, free, dir, .unsaved, "", content) catch return; + exec.placeNew(p, id, id, free, .doc); + p.active = id; +} + /// Recent: the one +Recent, filled again when it is there (as Find and /// Grep's +Search is), else opened below the asking pane. pub fn openRecent(p: *Pardes, id: usize) !void { diff --git a/src/builtins.zig b/src/builtins.zig index 041eb1b8..9025da6d 100644 --- a/src/builtins.zig +++ b/src/builtins.zig @@ -238,7 +238,7 @@ test "Exit asks once about unsaved text, and quits when asked again" { pane.file.?.saved_hash = 0; // edited: what it had is not what it has try std.testing.expect(p.executeBuiltinLine(p.active, "Exit")); try std.testing.expect(!p.quit); - try std.testing.expect(std.mem.endsWith(u8, pane.msg[0..pane.msg_len], ": Modified (Exit again to discard)")); + try std.testing.expect(std.mem.endsWith(u8, unsavedList(p), ": Modified\n\nExit again to discard\n")); // Told once, and nothing edited since: the second Exit quits. try std.testing.expect(p.executeBuiltinLine(p.active, "Exit")); try std.testing.expect(p.quit); @@ -267,6 +267,14 @@ test "Exit over a ctl write or a click names every pane it asks about, a second var rec: [64]u8 = undefined; for ([_]*const Pane{ first, second }) |pane| try std.testing.expect(std.mem.indexOf(u8, log, try std.fmt.bufPrint(&rec, "unsaved {d} ", .{pane.serial})) != null); + // The whole list stays in +Unsaved; the notice is short. + try std.testing.expect(std.mem.indexOf(u8, unsavedList(p), first.file.?.path) != null); + 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"); + }; + try std.testing.expect(noticed); // Edited since: only that one is named again (acme's rule). p.fs.failure_len = 0; panes.File.setContent(p, &second.file.?, try std.testing.allocator.dupe(u8, "y" ** 120)); @@ -274,6 +282,13 @@ test "Exit over a ctl write or a click names every pane it asks about, a second try std.testing.expect(!p.quit); const again = p.fs.failure[0..p.fs.failure_len]; try std.testing.expect(std.mem.indexOf(u8, again, first.file.?.path) == null); + // The one +Unsaved, filled again. + var kept: usize = 0; + for (p.panes) |slot| if (slot) |pane| if (pane.file) |f| if (f.output) |o| { + kept += @intFromBool(o.from == .unsaved); + }; + try std.testing.expectEqual(@as(usize, 1), kept); + try std.testing.expect(std.mem.indexOf(u8, unsavedList(p), first.file.?.path) == null); try std.testing.expect(std.mem.startsWith(u8, again, second.file.?.path)); p.fs.failure_len = 0; try std.testing.expect(p.executeBuiltinLine(p.active, "Exit")); @@ -281,6 +296,12 @@ test "Exit over a ctl write or a click names every pane it asks about, a second } } +/// What +Unsaved holds: the list a refusal over unsaved panes keeps. +fn unsavedList(p: *Pardes) []const u8 { + for (p.panes) |slot| if (slot) |pane| if (pane.file) |f| if (f.output) |o| if (o.from == .unsaved) return f.content; + return ""; +} + /// A dump file that exists, for a Restore to get past reading it. fn testDump(buf: []u8) ![]const u8 { var tmp = std.testing.tmpDir(.{}); @@ -304,7 +325,7 @@ test "Restore asks about unsaved text as Exit does, and restores when asked agai const line = try testDump(&line_buf); try std.testing.expect(p.executeBuiltinLine(p.active, line)); try std.testing.expect(p.restore_req == null); - try std.testing.expect(std.mem.endsWith(u8, pane.msg[0..pane.msg_len], ": Modified (Restore again to discard)")); + try std.testing.expect(std.mem.endsWith(u8, unsavedList(p), ": Modified\n\nRestore again to discard\n")); try std.testing.expect(p.executeBuiltinLine(p.active, line)); try std.testing.expectEqualStrings(line["Restore ".len..], p.restore_req.?); } @@ -336,7 +357,7 @@ test "a Restore's warning is not an Exit's: each word is warned on its own" { // The Restore warned; an Exit after it has not been, and asks. try std.testing.expect(p.executeBuiltinLine(p.active, "Exit")); try std.testing.expect(!p.quit); - try std.testing.expect(std.mem.endsWith(u8, pane.msg[0..pane.msg_len], ": Modified (Exit again to discard)")); + try std.testing.expect(std.mem.endsWith(u8, unsavedList(p), ": Modified\n\nExit again to discard\n")); try std.testing.expect(p.executeBuiltinLine(p.active, "Exit")); try std.testing.expect(p.quit); } @@ -460,7 +481,9 @@ pub const Exec = struct { /// acme's rowclean (editors/acme/wind.c:511-529, winclean), asked before /// what would throw unsaved text away: each pane holding some nobody has -/// been told about says so, `: Modified (Exit again to discard)`, +/// been told about is listed in +Unsaved, `: Modified`, under it +/// `Exit again to discard`, with a short notice, `3 unsaved panes -- Exit +/// again to discard`, /// naming the word asking, since repeating it throws the text away, and is /// then clean for the asking, as winclean clears `dirty`; so the same word /// again, with nothing edited since, goes ahead. Only the same word: a @@ -482,6 +505,9 @@ fn warnModifiedIn(c: Ctx, asking: Pane.Discarding, which: Asked) bool { var count: usize = 0; var one_buf: [limits.host_path_cap + 24]u8 = undefined; var one: []const u8 = ""; + // The whole list goes into +Unsaved, where it stays; the notice is short. + var listed: std.ArrayList(u8) = .empty; + const arena = c.p.scratch.allocator(); for (c.p.panes, 0..) |slot, id| { const pane = slot orelse continue; switch (which) { @@ -508,12 +534,17 @@ fn warnModifiedIn(c: Ctx, asking: Pane.Discarding, which: Asked) bool { // Del, Delcol). var name_buf: [limits.host_path_cap + 24]u8 = undefined; const name = if (scratch) std.fmt.bufPrint(&name_buf, "{s} (pane {d})", .{ f.path, pane.serial }) catch f.path else f.path; - var buf: [limits.host_path_cap + 72]u8 = undefined; pardes.ctlfs.events.noteLog(c.p, .unsaved, pane); - c.p.reportFailure(id, std.fmt.bufPrint(&buf, "{s}: Modified ({s} again to discard)", .{ name, @tagName(asking) }) catch name); + listed.print(arena, "{s}: Modified\n", .{name}) catch {}; if (count == 0) one = std.fmt.bufPrint(&one_buf, "{s}", .{name}) catch name; count += 1; } + if (count > 0) { + listed.print(arena, "\n{s} again to discard\n", .{@tagName(asking)}) catch {}; + if (c.p.gpa.dupe(u8, listed.items)) |content| panes.Output.openUnsaved(c.p, c.id, content) else |_| {} + var short: [96]u8 = undefined; + c.p.reportFailure(c.id, std.fmt.bufPrint(&short, "{d} unsaved pane{s} \u{2014} {s} again to discard", .{ count, if (count == 1) "" else "s", @tagName(asking) }) catch "unsaved panes"); + } if (count > 0 and (c.p.fs.no_prompt or c.p.fs.capturing)) { var said_buf: [limits.host_path_cap + 96]u8 = undefined; const said = (if (count == 1) @@ -1934,15 +1965,15 @@ test "Exit and Restore name a modified +New scratch as well as files" { try std.testing.expect(!p.quit); // Each pane's message row names it; the write's refusal counts them. try std.testing.expectEqualStrings("2 unsaved panes: Modified (Exit again to discard)", p.fs.failure[0..p.fs.failure_len]); - try std.testing.expect(std.mem.indexOf(u8, file.msg[0..file.msg_len], "test.txt") != null); + try std.testing.expect(std.mem.indexOf(u8, unsavedList(p), "test.txt: Modified") != null); const scratch_pane = p.panes[p.active].?; var named: [64]u8 = undefined; - try std.testing.expect(std.mem.indexOf(u8, scratch_pane.msg[0..scratch_pane.msg_len], try std.fmt.bufPrint(&named, "{s} (pane {d})", .{ config.scratch_buffer, scratch_pane.serial })) != null); + try std.testing.expect(std.mem.indexOf(u8, unsavedList(p), try std.fmt.bufPrint(&named, "{s} (pane {d})", .{ config.scratch_buffer, scratch_pane.serial })) != null); // Delcol, Restore and Exit name it the same way. p.fs.failure_len = 0; try std.testing.expect(p.executeBuiltinLine(p.active, "Delcol")); - try std.testing.expect(std.mem.indexOf(u8, scratch_pane.msg[0..scratch_pane.msg_len], "(Delcol again") != null); - try std.testing.expect(std.mem.indexOf(u8, scratch_pane.msg[0..scratch_pane.msg_len], named[0 .. config.scratch_buffer.len + 7]) != null); + try std.testing.expect(std.mem.indexOf(u8, unsavedList(p), "Delcol again to discard") != null); + try std.testing.expect(std.mem.indexOf(u8, unsavedList(p), named[0 .. config.scratch_buffer.len + 7]) != null); } test "Del and Delcol refuse a pane with unsaved text once, as acme's do, and close on the second" { @@ -1954,11 +1985,11 @@ test "Del and Delcol refuse a pane with unsaved text once, as acme's do, and clo const serial = pane.serial; try std.testing.expect(p.executeBuiltinLine(p.active, "Delcol")); try std.testing.expect(p.paneBySerial(serial) != null); - try std.testing.expect(std.mem.endsWith(u8, pane.msg[0..pane.msg_len], ": Modified (Delcol again to discard)")); + try std.testing.expect(std.mem.endsWith(u8, unsavedList(p), ": Modified\n\nDelcol again to discard\n")); // Each word is warned on its own: Del asks too, then closes. try std.testing.expect(p.executeBuiltinLine(p.active, "Del")); try std.testing.expect(p.paneBySerial(serial) != null); - try std.testing.expect(std.mem.endsWith(u8, pane.msg[0..pane.msg_len], ": Modified (Del again to discard)")); + try std.testing.expect(std.mem.endsWith(u8, unsavedList(p), ": Modified\n\nDel again to discard\n")); try std.testing.expect(p.executeBuiltinLine(p.active, "Del")); try std.testing.expect(p.paneBySerial(serial) == null); } diff --git a/src/config.zig b/src/config.zig index 2b5bf280..e96d73be 100644 --- a/src/config.zig +++ b/src/config.zig @@ -450,6 +450,7 @@ pub const config_buffer = "+Config"; pub const effect_code_buffer = "+EffectCode"; pub const jumps_buffer = "+Jumps"; pub const recent_buffer = "+Recent"; +pub const unsaved_buffer = "+Unsaved"; pub const themes_buffer = "+Themes"; pub const fonts_buffer = "+Fonts"; pub const pdf_sections_buffer = "+PdfSections"; diff --git a/src/ninep/ctl.zig b/src/ninep/ctl.zig index 18a7eaa9..477a91fe 100644 --- a/src/ninep/ctl.zig +++ b/src/ninep/ctl.zig @@ -861,12 +861,15 @@ fn getRefused(p: *Pardes, pane: *Pane) ?[]const u8 { if (std.hash.Wyhash.hash(0, f.content) == saved) return null; if (pane.discard_warned) |w| if (w.revision == f.revision and w.by == .get) return null; pane.discard_warned = .{ .revision = f.revision, .by = .get }; - const said = std.fmt.bufPrint(&p.fs.ename, "{s}: Modified (get again to discard)", .{f.path}) catch "Modified (get again to discard)"; - // Shown; the write's err record logs it, not a msg too. + const id = p.paneBySerial(pane.serial).?; + // Kept in +Unsaved, as Exit's refusal is; the notice is short. The + // write's err record logs it, not a msg too. + const listed = std.fmt.allocPrint(p.gpa, "{s}: Modified\n\nget again to discard\n", .{f.path}) catch null; + if (listed) |content| panes.Output.openUnsaved(p, id, content); p.fs.unlogged = true; - defer p.fs.unlogged = false; - p.setMessage(p.paneBySerial(pane.serial).?, said); - return said; + p.setMessage(id, "1 unsaved pane \u{2014} get again to discard"); + p.fs.unlogged = false; + return std.fmt.bufPrint(&p.fs.ename, "{s}: Modified (get again to discard)", .{f.path}) catch "Modified (get again to discard)"; } fn get(p: *Pardes, pane: *Pane, failed: *anyerror) u16 { -- cgit v1.3 From 5db9e71ba32dd6f0a0292eaa341d1d8ba805483c Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 29 Sep 2026 11:09:17 -0300 Subject: A remembered place is clamped to the file as it is now, its selection's two ends kept A Recent row or a jumplist entry for a line the file no longer has failed the look; now it opens at the last line. The selection's anchor is remembered too, so a reopen restores both ends where they fit, and Recent and Jumplist share the (closed) marker. Co-Authored-By: Claude Opus 5.5 --- src/Output.zig | 19 +++++++++++++------ src/look.zig | 44 ++++++++++++++++++++++++++++++++++++++++++++ src/ninep/ctl.zig | 40 ++++++++++++++++++++++++++++++++++++++-- src/pardes.zig | 20 +++++++++++++------- src/recent.zig | 40 +++++++++++++++++++++++++++++++--------- 5 files changed, 139 insertions(+), 24 deletions(-) (limited to 'src/Output.zig') diff --git a/src/Output.zig b/src/Output.zig index 3b8e6a7a..e6d6f46c 100644 --- a/src/Output.zig +++ b/src/Output.zig @@ -555,13 +555,20 @@ pub fn recentText(p: *Pardes, w: *std.Io.Writer, look_rows: bool) !void { for (p.panes) |slot| if (slot) |pane| if (pane.file) |f| if (f.output == null and std.mem.eql(u8, f.path, e.path)) { is_open = true; }; - const state: []const u8 = if (is_open) "open" else "closed"; - if (!look_rows) - try w.print("{s} {s}\n", .{ state, e.path }) - else if (e.line == 0) - try w.print("{s} {s}\n", .{ e.path, state }) - else + const state: []const u8 = if (is_open) "open" else "(closed)"; + if (!look_rows) { + try w.print("{s} {s}\n", .{ if (is_open) "open" else "closed", e.path }); + } else if (e.line == 0) { + try w.print("{s} {s}\n", .{ e.path, state }); + } else if (e.aline != 0 and (e.aline != e.line or e.acol != e.col)) { + // A selection: both its ends, in order, `path:L:C-L2:C2`. + const a_first = e.aline < e.line or (e.aline == e.line and e.acol < e.col); + const s = if (a_first) [2]u32{ e.aline, e.acol } else [2]u32{ e.line, e.col }; + const t = if (a_first) [2]u32{ e.line, e.col } else [2]u32{ e.aline, e.acol }; + try w.print("{s}:{d}:{d}-{d}:{d} {s}\n", .{ e.path, s[0], s[1], t[0], t[1], state }); + } else { try w.print("{s}:{d}:{d} {s}\n", .{ e.path, e.line, e.col, state }); + } } } diff --git a/src/look.zig b/src/look.zig index ca9aa80a..0baa9afc 100644 --- a/src/look.zig +++ b/src/look.zig @@ -1381,8 +1381,52 @@ fn spotAt(text: []const u8, q: u32) struct { line: usize, col: usize } { return .{ .line = line, .col = upto.len - start + 1 }; } +/// A remembered place in `path` (Recent, the jumplist): the file opened or +/// focused, then `at` clamped to it as it is now, a line past the end its +/// last line, never a miss; a selection's two ends restored where they +/// still fit. +pub fn reopenAt(p: *Pardes, from: usize, path: []const u8, at: Spot) void { + lookAt(p, from, path); + const id = p.active; + const pane = p.panes[id] orelse return; + const f = if (pane.file) |*file| file else return; + if (!std.mem.eql(u8, f.path, path)) return; + const n = @max(1, panes.File.nlines(p.gpa, f)); + const clamp = struct { + fn spot(text: []const u8, lines: usize, line: usize, col: usize) [2]usize { + const l = std.math.clamp(line, 1, lines); + const width = modal.lineSlice(text, l - 1).len + 1; + return .{ l, std.math.clamp(col, 1, width) }; + } + }; + const head = clamp.spot(f.content, n, at.line, at.col); + var to: Spot = .{ .line = head[0], .col = head[1] }; + if (at.end_line != 0) { + const end = clamp.spot(f.content, n, at.end_line, at.end_col); + to.end_line = end[0]; + to.end_col = end[1]; + } + clearNavigationSelection(p, pane); + focusPaneLine(p, id, to, .center); +} + +/// Whether `pane` is the +Recent list, whose rows are remembered places. +fn isRecentList(pane: *const Pane) bool { + const f = pane.file orelse return false; + const o = f.output orelse return false; + return std.meta.eql(o.from, panes.Output.Origin{ .cmd = .Recent }); +} + pub fn lookAt(p: *Pardes, id: usize, operand: []const u8) void { const pane = p.panes[id] orelse return; + // A +Recent row is a remembered place: reopened and clamped to the file + // as it is now, never a miss for a line the file no longer has. + if (isRecentList(pane)) { + const row = std.mem.trim(u8, operand, " \t\r\n"); + const loc = row[0 .. std.mem.indexOfScalar(u8, row, ' ') orelse row.len]; + const pl = parsePathLine(loc); + if (pl.path.len > 0 and pl.path[0] == '/' and pl.at.line != 0) return reopenAt(p, id, pl.path, pl.at); + } p.noteHaptic(.look); noteLookSource(p, id); const command = std.mem.trim(u8, operand, " \t\r\n"); diff --git a/src/ninep/ctl.zig b/src/ninep/ctl.zig index 477a91fe..889ee7be 100644 --- a/src/ninep/ctl.zig +++ b/src/ninep/ctl.zig @@ -2141,8 +2141,8 @@ test "a closed file is found again: Recent and /recent list it closed, a look at const rows = p.panes[p.paneBySerial(try std.fmt.parseInt(u32, std.mem.trimEnd(u8, rd(p, root_exec, 0, 64).bytes, "\n"), 10)).?].?; const at = std.mem.indexOf(u8, rows.file.?.content, try std.fmt.bufPrint(&want, "{s}:3:", .{a})).?; const row = rows.file.?.content[at .. std.mem.indexOfScalarPos(u8, rows.file.?.content, at, '\n').?]; - try testing.expect(std.mem.endsWith(u8, row, " closed")); - try testing.expectEqual(Status.ok, wr(p, Node.of(rows.serial, .look), try std.fmt.bufPrint(&line, "{s}\n", .{row[0 .. row.len - " closed".len]})).reply.status); + try testing.expect(std.mem.endsWith(u8, row, " (closed)")); + try testing.expectEqual(Status.ok, wr(p, Node.of(rows.serial, .look), try std.fmt.bufPrint(&line, "{s}\n", .{row[0 .. row.len - " (closed)".len]})).reply.status); p.sync(); const back = p.panes[p.active].?; try testing.expectEqualStrings(a, back.file.?.path); @@ -2163,6 +2163,42 @@ test "a closed file is found again: Recent and /recent list it closed, a look at try testing.expectEqualStrings(a, p.panes[p.active].?.file.?.path); } +test "a remembered place is clamped to the file as it is now, its selection's two ends kept where they fit" { + const p = try withFile(testing.allocator, "x\n"); + defer p.deinit(); + var tmp = testing.tmpDir(.{}); + defer tmp.cleanup(); + try tmp.dir.writeFile(testing.io, .{ .sub_path = "c.txt", .data = "one\ntwo\nthree\nfour\nfive\n" }); + var dir_buf: [4096]u8 = undefined; + const dir = dir_buf[0..try tmp.dir.realPath(testing.io, &dir_buf)]; + var line: [4200]u8 = undefined; + _ = wr(p, root_look, try std.fmt.bufPrint(&line, "{s}/c.txt:2\n", .{dir})); + p.sync(); + const c = p.panes[p.active].?; + // A selection over lines 2 to 4, then closed. + @import("pane.zig").setDot(c, .{ .q0 = 4, .q1 = 19 }); + try testing.expect(c.body.vsel.active); + _ = wr(p, Node.of(c.serial, .ctl), "Del\n"); + p.sync(); + // The file shrinks to two lines while it is closed. + try tmp.dir.writeFile(testing.io, .{ .sub_path = "c.txt", .data = "one\ntwo\n" }); + _ = wr(p, root_exec, "Recent\n"); + const rows = p.panes[p.paneBySerial(try std.fmt.parseInt(u32, std.mem.trimEnd(u8, rd(p, root_exec, 0, 64).bytes, "\n"), 10)).?].?; + const at = std.mem.indexOf(u8, rows.file.?.content, "c.txt:").?; + const row = rows.file.?.content[at .. std.mem.indexOfScalarPos(u8, rows.file.?.content, at, '\n').?]; + // Both ends are in the row, a range. + try testing.expect(std.mem.indexOfScalar(u8, row, '-') != null); + var full: [4400]u8 = undefined; + const loc = try std.fmt.bufPrint(&full, "{s}/{s}\n", .{ dir, row[0 .. std.mem.indexOfScalar(u8, row, ' ').?] }); + // A look at it opens the file, never a miss, clamped to its last line. + try testing.expectEqual(Status.ok, wr(p, Node.of(rows.serial, .look), loc).reply.status); + p.sync(); + const back = p.panes[p.active].?; + try testing.expect(std.mem.endsWith(u8, back.file.?.path, "/c.txt")); + try testing.expect(back.body.cur_row <= 1); + try testing.expect(back.body.vsel.active); +} + test "size is monotonic: growing is never refused, and a size once taken is taken again" { const p = try Pardes.init(testing.allocator, .{ .tty_only = true, .cols = 160, .rows = 60 }); defer p.deinit(); diff --git a/src/pardes.zig b/src/pardes.zig index 0950d13a..5fdcfe3c 100644 --- a/src/pardes.zig +++ b/src/pardes.zig @@ -4700,10 +4700,18 @@ pub const Pardes = struct { } /// A file pane's path and dot, for the recent list (0 when none). - fn recentDot(pane: *const Pane) ?struct { path: []const u8, line: u32, col: u32 } { + fn recentDot(pane: *const Pane) ?struct { path: []const u8, line: u32, col: u32, aline: u32 = 0, acol: u32 = 0 } { const f = pane.file orelse return null; if (f.output != null) return null; - return .{ .path = f.path, .line = @intCast(@max(0, pane.body.cur_row) + 1), .col = @intCast(@max(0, pane.body.cur_col) + 1) }; + // The selection's anchor too, so a reopen restores both its ends. + const sel = pane.body.vsel.active; + return .{ + .path = f.path, + .line = @intCast(@max(0, pane.body.cur_row) + 1), + .col = @intCast(@max(0, pane.body.cur_col) + 1), + .aline = if (sel) @intCast(@max(0, pane.body.vsel.row) + 1) else 0, + .acol = if (sel) @intCast(@max(0, pane.body.vsel.col) + 1) else 0, + }; } /// The recent entry a closed jump names, by its path's hash. @@ -4714,7 +4722,7 @@ pub const Pardes = struct { pub fn deinit(p: *Pardes) void { // Every file open now is closed with its dot, and the list kept. - for (p.panes) |slot| if (slot) |pane| if (recentDot(pane)) |d| p.recent.closed(p.recentGpa(), d.path, d.line, d.col); + for (p.panes) |slot| if (slot) |pane| if (recentDot(pane)) |d| p.recent.closedSel(p.recentGpa(), d.path, d.line, d.col, d.aline, d.acol); p.saveRecent(); p.recent.deinit(p.recentGpa()); look.cancelLookHover(p); @@ -4827,7 +4835,7 @@ pub const Pardes = struct { fn retirePane(p: *Pardes, pane: *Pane) void { // Closed, a file is remembered with its dot: Recent and a jump back // to it reopen it there. - if (recentDot(pane)) |d| p.recent.closed(p.recentGpa(), d.path, d.line, d.col); + if (recentDot(pane)) |d| p.recent.closedSel(p.recentGpa(), d.path, d.line, d.col, d.aline, d.acol); const watched = (if (pane.file) |f| f.output == null else false) or pane.hasPdf(); for (p.panes, 0..) |slot, id| if (slot == pane) { if (watched) p.emit(.{ .watch = .{ .pane = @intCast(id), .on = false } }); @@ -6694,10 +6702,8 @@ pub const Pardes = struct { // places it, and the entry is that pane from here on. if (j.serial == 0) { const e = p.recentByHash(j.path_hash) orelse return; - var where: [recent_path_cap + 32]u8 = undefined; - const loc = std.fmt.bufPrint(&where, "{s}:{d}:{d}", .{ e.path, @max(1, j.line), @max(1, j.col) }) catch return; const from = p.active; - look.lookAt(p, from, loc); + look.reopenAt(p, from, e.path, .{ .line = @max(1, j.line), .col = @max(1, j.col) }); const opened = p.panes[p.active] orelse return; if (p.active == from) return; p.jumps[@intCast(next)].pane = @intCast(p.active); diff --git a/src/recent.zig b/src/recent.zig index b6a1a66a..9f18d737 100644 --- a/src/recent.zig +++ b/src/recent.zig @@ -15,6 +15,9 @@ pub const Entry = struct { /// Where its dot was when it last closed (1-based; 0 none). line: u32 = 0, col: u32 = 0, + /// The selection's other end then (its anchor), 0 when there was none. + aline: u32 = 0, + acol: u32 = 0, }; pub const List = struct { @@ -53,6 +56,11 @@ pub const List = struct { /// `path` closed with its dot at `line`:`col`: where a reopen lands. /// Its place in the list is its opening's. pub fn closed(l: *List, gpa: std.mem.Allocator, path: []const u8, line: u32, col: u32) void { + l.closedSel(gpa, path, line, col, 0, 0); + } + + /// `closed`, with the selection's anchor too (0 0 for none). + pub fn closedSel(l: *List, gpa: std.mem.Allocator, path: []const u8, line: u32, col: u32, aline: u32, acol: u32) void { const i = l.find(path) orelse found: { l.opened(gpa, path); // Out of memory for it: nothing to note the dot on. @@ -60,6 +68,8 @@ pub const List = struct { }; l.entries.items[i].line = line; l.entries.items[i].col = col; + l.entries.items[i].aline = aline; + l.entries.items[i].acol = acol; l.dirty = true; } @@ -67,9 +77,10 @@ pub const List = struct { return l.entries.items[l.find(path) orelse return null]; } - /// One line a file, ` `, most recent first. + /// One line a file, ` `, most recent + /// first. pub fn write(l: *const List, w: *std.Io.Writer) !void { - for (l.entries.items) |e| try w.print("{d} {d} {s}\n", .{ e.line, e.col, e.path }); + for (l.entries.items) |e| try w.print("{d} {d} {d} {d} {s}\n", .{ e.line, e.col, e.aline, e.acol, e.path }); } /// The lines `write` wrote; a line that is not one is passed over. @@ -77,13 +88,21 @@ pub const List = struct { var lines = std.mem.splitScalar(u8, bytes, '\n'); while (lines.next()) |line| { if (l.entries.items.len >= cap) break; - var it = std.mem.splitScalar(u8, line, ' '); - const ln = std.fmt.parseInt(u32, it.next() orelse continue, 10) catch continue; - const col = std.fmt.parseInt(u32, it.next() orelse continue, 10) catch continue; - const path = it.rest(); + // Numbers, then the path (which starts with `/`): two of them in + // a list written before the anchor was kept, four since. + var nums: [4]u32 = @splat(0); + var n: usize = 0; + var rest = line; + while (rest.len > 0 and rest[0] != '/' and n < nums.len) : (n += 1) { + const sp = std.mem.indexOfScalar(u8, rest, ' ') orelse break; + nums[n] = std.fmt.parseInt(u32, rest[0..sp], 10) catch break; + rest = rest[sp + 1 ..]; + } + if (n != 2 and n != 4) continue; + const path = rest; if (path.len == 0 or path[0] != '/' or l.find(path) != null) continue; const owned = gpa.dupe(u8, path) catch return; - l.entries.append(gpa, .{ .path = owned, .line = ln, .col = col }) catch { + l.entries.append(gpa, .{ .path = owned, .line = nums[0], .col = nums[1], .aline = nums[2], .acol = nums[3] }) catch { gpa.free(owned); return; }; @@ -105,12 +124,15 @@ test "the list keeps a path once, most recent first, its dot from closing, cappe var buf: [256]u8 = undefined; var w = std.Io.Writer.fixed(&buf); try l.write(&w); - try std.testing.expectEqualStrings("7 3 /a\n0 0 /b\n", w.buffered()); + try std.testing.expectEqualStrings("7 3 0 0 /a\n0 0 0 0 /b\n", w.buffered()); var again: List = .{}; defer again.deinit(gpa); again.read(gpa, w.buffered()); again.read(gpa, "junk\n"); - try std.testing.expectEqual(@as(usize, 2), again.entries.items.len); + // A list written before the anchor was kept still reads. + again.read(gpa, "4 2 /old\n"); + try std.testing.expectEqual(@as(u32, 4), again.get("/old").?.line); + try std.testing.expectEqual(@as(usize, 3), again.entries.items.len); for (0..cap + 5) |i| { var name: [16]u8 = undefined; l.opened(gpa, std.fmt.bufPrint(&name, "/f{d}", .{i}) catch unreachable); -- cgit v1.3 From ab4bdfb9cbe2ee32889ad7b675dab1f5bfeae707 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 29 Sep 2026 11:17:56 -0300 Subject: A directory's +Search is found by its directory, the pane that ran the search included Find and Grep passed over the pane they ran in when looking for the +Search to fill, so a Grep written to a +Search's own exec made a second one, and the two swapped roles on each run after. Co-Authored-By: Claude Opus 5.5 --- src/Output.zig | 6 ++++-- src/ninep/ctl.zig | 9 +++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) (limited to 'src/Output.zig') diff --git a/src/Output.zig b/src/Output.zig index e6d6f46c..495dbc43 100644 --- a/src/Output.zig +++ b/src/Output.zig @@ -436,7 +436,9 @@ pub fn fillResults(p: *Pardes, id: usize, dir: []const u8, from: Origin, arg: [] const by_arg = std.meta.activeTag(from) != .query; if (p.locations_config.context == 0 and !p.locations_config.tscontext) { for (p.panes, 0..) |slot, i| { - if (i == id) continue; + // A directory's +Search is found by its directory, whatever + // pane ran the search: that +Search itself too. + if (i == id and !fileSearch(from)) continue; const rp = slot orelse continue; const rf = if (rp.file) |*f| f else continue; const output = if (rf.output) |*o| o else continue; @@ -463,11 +465,11 @@ pub fn fillResults(p: *Pardes, id: usize, dir: []const u8, from: Origin, arg: [] anchor = formatted.anchor; } for (p.panes, 0..) |slot, i| { - if (i == id) continue; const rp = slot orelse continue; const rf = if (rp.file) |*f| f else continue; const o = if (rf.output) |*x| x else continue; const shared = fileSearch(from) and fileSearch(o.from); + if (i == id and !shared) continue; if (!shared and !std.meta.eql(o.from, from)) continue; if (!shared and by_arg and !std.mem.eql(u8, o.arg(), arg)) continue; if (!std.mem.eql(u8, std.fs.path.dirname(rf.path) orelse "", dir)) continue; diff --git a/src/ninep/ctl.zig b/src/ninep/ctl.zig index 9bb863cf..40a1a7cd 100644 --- a/src/ninep/ctl.zig +++ b/src/ninep/ctl.zig @@ -1860,6 +1860,15 @@ test "Grep with no hit says grep: no match and opens nothing, a missing pane dir try testing.expect(std.mem.indexOf(u8, found.file.?.content, "other.txt") != null); try testing.expectEqual(grepped.serial, found.serial); try testing.expect(std.mem.indexOf(u8, found.file.?.content, "bravo here") == null); + // A Grep run from the +Search itself fills that one, never a second. + try testing.expectEqual(Status.ok, wr(p, Node.of(found.serial, .exec), "Grep bravo\n").reply.status); + try testing.expectEqualStrings(try std.fmt.bufPrint(&line, "{d}\n", .{found.serial}), rd(p, root_exec, 0, 64).bytes); + var searches: usize = 0; + for (p.panes) |slot| if (slot) |q| if (q.file) |f| if (f.output != null) { + searches += @intFromBool(std.mem.endsWith(u8, f.path, "/+Search")); + }; + try testing.expectEqual(@as(usize, 1), searches); + try testing.expect(std.mem.indexOf(u8, found.file.?.content, "bravo here") != null); // A second pane in a directory that is not there. const other = try th.newPane(p); _ = wr(p, Node.of(other, .name), "/tmp/pardes-no-such-dir-zz/b.txt\n"); -- cgit v1.3 From 23ff1aa588c5dfcb194543c949ebd87cbb12e725 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 29 Sep 2026 11:18:33 -0300 Subject: A repeated identical search reads back the +Search it left as it was When a Find or Grep found exactly what its +Search already held, the pane was kept but not marked as the one the search touched, so the exec read back the pane it ran in. Co-Authored-By: Claude Opus 5.5 --- src/Output.zig | 1 + src/ninep/ctl.zig | 3 +++ 2 files changed, 4 insertions(+) (limited to 'src/Output.zig') diff --git a/src/Output.zig b/src/Output.zig index 495dbc43..99246b4a 100644 --- a/src/Output.zig +++ b/src/Output.zig @@ -448,6 +448,7 @@ pub fn fillResults(p: *Pardes, id: usize, dir: []const u8, from: Origin, arg: [] if (!locations.sameInput(content, rf.content, rf.location_rows, p.locations_config.layout)) continue; try setArg(output, arg); p.gpa.free(content); + p.fs.refilled = rp.serial; p.active = id; if (traits(from).steps) { pane.search_pane = i; diff --git a/src/ninep/ctl.zig b/src/ninep/ctl.zig index 40a1a7cd..2dc3a51b 100644 --- a/src/ninep/ctl.zig +++ b/src/ninep/ctl.zig @@ -1860,6 +1860,9 @@ test "Grep with no hit says grep: no match and opens nothing, a missing pane dir try testing.expect(std.mem.indexOf(u8, found.file.?.content, "other.txt") != null); try testing.expectEqual(grepped.serial, found.serial); try testing.expect(std.mem.indexOf(u8, found.file.?.content, "bravo here") == null); + // The same Find again reads back the +Search, not the pane it ran in. + try testing.expectEqual(Status.ok, wr(p, Node.of(serialOf(p), .exec), "Find other\n").reply.status); + try testing.expectEqualStrings(try std.fmt.bufPrint(&line, "{d}\n", .{found.serial}), rd(p, root_exec, 0, 64).bytes); // A Grep run from the +Search itself fills that one, never a second. try testing.expectEqual(Status.ok, wr(p, Node.of(found.serial, .exec), "Grep bravo\n").reply.status); try testing.expectEqualStrings(try std.fmt.bufPrint(&line, "{d}\n", .{found.serial}), rd(p, root_exec, 0, 64).bytes); -- cgit v1.3 From 53fcf030b175fc035e62d1d471c01c2e0caefc9e Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 29 Sep 2026 11:18:33 -0300 Subject: A Find or Grep that finds nothing empties its directory's +Search It failed with no match but left the last search's rows in the +Search, where they read as this one's. Co-Authored-By: Claude Opus 5.5 --- docs/fs.md | 3 ++- src/Output.zig | 10 ++++++++++ src/look.zig | 5 ++++- src/ninep/ctl.zig | 2 ++ 4 files changed, 18 insertions(+), 2 deletions(-) (limited to 'src/Output.zig') diff --git a/docs/fs.md b/docs/fs.md index 1baa9b2c..6fa612f5 100644 --- a/docs/fs.md +++ b/docs/fs.md @@ -748,7 +748,8 @@ every pane's directory on this host, passing over panes of the served tree (`/virtual/`, a peer's `/n//`) and directories not there, so none of them spoils the rest; Find and Grep share one `+Search` a directory, each run replacing what the last showed, as acme reuses a -directory's `+Errors` (the exec reads that pane back), while a plain +directory's `+Errors` (the exec reads that pane back; one that finds +nothing empties it rather than leave the last rows), while a plain word's `LookWord list` search keeps a pane a pattern, ENOSPC for no room or slot, EBUSY for a held lock) -- and logs its reason exactly once, as `err : `, with no `msg` for it. A builtin a click runs (Save, get's diff --git a/src/Output.zig b/src/Output.zig index 99246b4a..eb9e8db4 100644 --- a/src/Output.zig +++ b/src/Output.zig @@ -418,6 +418,16 @@ pub fn open(p: *Pardes, id: usize, dir: []const u8, from: Origin, arg: []const u /// Find and Grep share one +Search a directory, each run replacing what /// the last showed, as acme reuses a directory's +Errors; a pane's own /// search (LookWord list) keeps a pane a pattern. +/// Whether `dir` has its Find/Grep +Search open. +pub fn hasFileSearch(p: *Pardes, dir: []const u8) bool { + for (p.panes) |slot| { + const f = (slot orelse continue).file orelse continue; + const o = f.output orelse continue; + if (fileSearch(o.from) and std.mem.eql(u8, std.fs.path.dirname(f.path) orelse "", dir)) return true; + } + return false; +} + fn fileSearch(from: Origin) bool { return switch (from) { .cmd => |c| c == .Find or c == .Grep, diff --git a/src/look.zig b/src/look.zig index 0baa9afc..f45fe583 100644 --- a/src/look.zig +++ b/src/look.zig @@ -667,7 +667,10 @@ pub fn runSearch(p: *Pardes, id: usize, pat_raw: []const u8, kind: Search, start nrows += 1; } } - if (!open_empty and nrows == 0) return 0; + // A Find or Grep that finds nothing empties its directory's +Search, if + // there is one, rather than leave the last search's rows looking like + // this one's. + if (!open_empty and nrows == 0 and (kind == .text or !panes.Output.hasFileSearch(p, dir))) return 0; const content = try p.gpa.dupe(u8, out[0..out_len]); // the buffer records WHICH search filled it, pattern and all: Find and // Grep are builtins (words you can execute), the bare `/` is a key diff --git a/src/ninep/ctl.zig b/src/ninep/ctl.zig index 2dc3a51b..a78a9fcd 100644 --- a/src/ninep/ctl.zig +++ b/src/ninep/ctl.zig @@ -1886,6 +1886,8 @@ test "Grep with no hit says grep: no match and opens nothing, a missing pane dir var after: usize = 0; for (p.panes) |slot| after += @intFromBool(slot != null); try testing.expectEqual(count, after); + // The +Search the miss would have filled is emptied, not left stale. + try testing.expectEqualStrings("", found.file.?.content); } test "Unmount of a name not mounted says no such mount, which a mount reads as ENOENT" { -- cgit v1.3 From 35f06a55bad1891e3d5e779630b232b2c322bc83 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 29 Sep 2026 11:30:08 -0300 Subject: /recent shows a name as /index does, a newline in it escaped It printed paths raw, so a name holding a newline read as two rows. Co-Authored-By: Claude Opus 5.5 --- src/Output.zig | 4 +++- src/ninep/ctl.zig | 8 ++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) (limited to 'src/Output.zig') diff --git a/src/Output.zig b/src/Output.zig index eb9e8db4..b3c31be2 100644 --- a/src/Output.zig +++ b/src/Output.zig @@ -570,7 +570,9 @@ pub fn recentText(p: *Pardes, w: *std.Io.Writer, look_rows: bool) !void { }; const state: []const u8 = if (is_open) "open" else "(closed)"; if (!look_rows) { - try w.print("{s} {s}\n", .{ if (is_open) "open" else "closed", e.path }); + // A name as /index shows it: one line, a newline in it `\n`. + var name_buf: [4 * 4096]u8 = undefined; + try w.print("{s} {s}\n", .{ if (is_open) "open" else "closed", pardes.ctlfs.events.shown(e.path, &name_buf) }); } else if (e.line == 0) { try w.print("{s} {s}\n", .{ e.path, state }); } else if (e.aline != 0 and (e.aline != e.line or e.acol != e.col)) { diff --git a/src/ninep/ctl.zig b/src/ninep/ctl.zig index 92342525..4abb6fcd 100644 --- a/src/ninep/ctl.zig +++ b/src/ninep/ctl.zig @@ -2300,6 +2300,14 @@ test "Back and Forward over a closed file's entries: one reopen is that file's p try testing.expectEqual(c_serial, p.panes[p.active].?.serial); } +test "/recent shows a name as /index does, a newline in it escaped" { + const p = try withFile(testing.allocator, "x\n"); + defer p.deinit(); + p.recent.opened(p.recentGpa(), "/tmp/a\nb\\c"); + const text = rd(p, @intFromEnum(tree.TopFile.recent), 0, 8192).bytes; + try testing.expect(std.mem.indexOf(u8, text, "closed /tmp/a\\nb\\\\c\n") != null); +} + test "a remembered place is clamped to the file as it is now, its selection's two ends kept where they fit" { const p = try withFile(testing.allocator, "x\n"); defer p.deinit(); -- cgit v1.3 From 0f16886d2f8f53b8d746341e3e2c9fc55f2446c2 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 29 Sep 2026 11:38:12 -0300 Subject: A list pane opened from a terminal that has not said its directory yet lands in the session's ThemeSel (Themes) in an init file ran at a terminal whose shell had not reported its cwd, so +Themes opened as /+Themes. Co-Authored-By: Claude Opus 5.5 --- src/Output.zig | 5 ++++- src/exec.zig | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) (limited to 'src/Output.zig') diff --git a/src/Output.zig b/src/Output.zig index b3c31be2..1461757f 100644 --- a/src/Output.zig +++ b/src/Output.zig @@ -669,7 +669,10 @@ pub fn openFonts(p: *Pardes, id: usize) !void { fn openStepped(p: *Pardes, id: usize, from: Origin, content: []u8) !void { errdefer p.gpa.free(content); const pane = p.panes[id] orelse return error.MissingPane; - const dir = if (pane.file) |f| (std.fs.path.dirname(f.path) orelse "/") else pane.cwdSlice(); + const own = if (pane.file) |f| (std.fs.path.dirname(f.path) orelse "/") else pane.cwdSlice(); + // A terminal whose shell has not said where it is yet (an init file's + // word at boot): the session's directory, not `/`. + const dir = if (own.len == 0) p.sessionDir() else own; const free = p.freeSlot() orelse return error.NoPaneSlots; _ = try open(p, free, dir, from, "", content); exec.placeNew(p, id, id, free, .doc); diff --git a/src/exec.zig b/src/exec.zig index 421bfd13..0e9fb6d7 100644 --- a/src/exec.zig +++ b/src/exec.zig @@ -831,6 +831,9 @@ test "an init file's ThemeSel runs as Themes and says it was renamed" { listed = listed or std.meta.eql(o.from, panes.Output.Origin{ .cmd = .Themes }); }; try std.testing.expect(listed); + // In the session's directory, not `/`. + for (p.panes) |slot| if (slot) |pane| if (pane.file) |f| if (f.output != null) + try std.testing.expectEqualStrings(p.sessionDir(), std.fs.path.dirname(f.path).?); var said = false; for (p.panes) |slot| if (slot) |pane| { said = said or std.mem.eql(u8, pane.msg[0..pane.msg_len], "ThemeSel: renamed to Themes"); -- cgit v1.3 From 2bd2ae838cd7db2ef5cde9038be50680a59cab97 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 29 Sep 2026 12:37:56 -0300 Subject: Symbols, Diagnostics and every language server list share their directory's one +Search Only Find and Grep reused the directory's +Search; a language server's list made another pane of the same name each time. Every origin named +Search now shares it, but a plain word's search, which keeps a list a pattern for n/N to walk between. Co-Authored-By: Claude Opus 5.5 --- docs/fs.md | 3 ++- src/Output.zig | 9 +++++---- src/ninep/ctl.zig | 15 +++++++++++++++ 3 files changed, 22 insertions(+), 5 deletions(-) (limited to 'src/Output.zig') diff --git a/docs/fs.md b/docs/fs.md index 9cf2db53..fdcbdaf0 100644 --- a/docs/fs.md +++ b/docs/fs.md @@ -767,7 +767,8 @@ plain `zz.txt` is looked for as text, a miss logged as any look's -- and for a Find or Grep that finds nothing, `grep: no match, not found`; Grep walks every pane's directory on this host, passing over panes of the served tree (`/virtual/`, a peer's `/n//`) and directories not there, -so none of them spoils the rest; Find and Grep share one `+Search` a +so none of them spoils the rest; Find, Grep and a language server's lists +(Symbols, Diagnostics, Callers and the rest) share one `+Search` a directory, each run replacing what the last showed, as acme reuses a directory's `+Errors` (the exec reads that pane back; one that finds nothing empties it rather than leave the last rows), while a plain diff --git a/src/Output.zig b/src/Output.zig index 1461757f..f2ab1bda 100644 --- a/src/Output.zig +++ b/src/Output.zig @@ -428,11 +428,12 @@ pub fn hasFileSearch(p: *Pardes, dir: []const u8) bool { return false; } +/// Whether `from` fills its directory's one +Search, whatever filled it +/// last (Find, Grep, Symbols, Diagnostics, any language server's list), +/// each run replacing the last. A plain word's search (in a file or a PDF) +/// keeps a +Search a pattern: n/N walk from one such list to the next. fn fileSearch(from: Origin) bool { - return switch (from) { - .cmd => |c| c == .Find or c == .Grep, - else => false, - }; + return from != .search and std.mem.eql(u8, traits(from).name, config.search_buffer); } pub fn fillResults(p: *Pardes, id: usize, dir: []const u8, from: Origin, arg: []const u8, content: []u8, initial_anchor: ?usize) !void { diff --git a/src/ninep/ctl.zig b/src/ninep/ctl.zig index b79b1ab8..0d3f084d 100644 --- a/src/ninep/ctl.zig +++ b/src/ninep/ctl.zig @@ -2161,6 +2161,21 @@ test "a PDF's body reads its page's text layer, and takes no write" { try testing.expectEqual(E.INVAL, wr(p, body, "more\n").errno()); } +test "Grep, Symbols and Diagnostics share their directory's one +Search" { + const p = try withFile(testing.allocator, "x\n"); + defer p.deinit(); + const id = p.active; + const Output = pardes.panes.Output; + try Output.fillResults(p, id, "/tmp", .{ .cmd = .Grep }, "x", try p.gpa.dupe(u8, "a.txt:1:1 x\n"), null); + try Output.fillResults(p, id, "/tmp", .{ .query = .document_symbols }, "", try p.gpa.dupe(u8, "a.txt:2:1 fn f\n"), null); + try Output.fillResults(p, id, "/tmp", .{ .query = .diagnostics }, "", try p.gpa.dupe(u8, "a.txt:3:1 error\n"), null); + var searches: usize = 0; + for (p.panes) |slot| if (slot) |q| if (q.file) |f| if (f.output != null) { + searches += @intFromBool(std.mem.eql(u8, f.path, "/tmp/+Search")); + }; + try testing.expectEqual(@as(usize, 1), searches); +} + test "every EINVAL a write gets says why, in its err record too; DEL is a control character in a line" { const p = try withFile(testing.allocator, "x\n"); defer p.deinit(); -- cgit v1.3 From 137adecd03be209901efb228d9288282bc36c8de Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 29 Sep 2026 12:42:20 -0300 Subject: +Unsaved drops a pane once it has closed The list kept a pane's Modified row after the pane was closed (discarded), so it named text there was no longer anything to lose of. A pane's closing now takes its row out. Co-Authored-By: Claude Opus 5.5 --- src/Output.zig | 35 +++++++++++++++++++++++++++++++++++ src/ninep/ctl.zig | 25 +++++++++++++++++++++++++ src/pardes.zig | 1 + 3 files changed, 61 insertions(+) (limited to 'src/Output.zig') diff --git a/src/Output.zig b/src/Output.zig index f2ab1bda..b8dd5e34 100644 --- a/src/Output.zig +++ b/src/Output.zig @@ -609,6 +609,41 @@ pub fn openUnsaved(p: *Pardes, id: usize, content: []u8) void { p.active = id; } +/// Pane `gone` closed: its row goes from +Unsaved, which lists only panes +/// still there to lose. +pub fn dropUnsaved(p: *Pardes, gone: *const Pane) void { + const gf = gone.file orelse return; + if (gf.output != null and !(gf.output.?.from == .cmd and gf.output.?.from.cmd == .New)) return; + for (p.panes) |slot| { + const rp = slot orelse continue; + if (rp == gone) continue; + const rf = if (rp.file) |*f| f else continue; + const o = rf.output orelse continue; + if (o.from != .unsaved) continue; + var scratch_name: [limits.host_path_cap + 24]u8 = undefined; + const as_scratch = std.fmt.bufPrint(&scratch_name, "{s} (pane {d}): Modified", .{ gf.path, gone.serial }) catch ""; + var out: std.ArrayList(u8) = .empty; + var lines = std.mem.splitScalar(u8, rf.content, '\n'); + var dropped = false; + var first = true; + while (lines.next()) |line| { + const is_it = std.mem.startsWith(u8, line, gf.path) and std.mem.eql(u8, line[gf.path.len..], ": Modified"); + if (is_it or (as_scratch.len > 0 and std.mem.eql(u8, line, as_scratch))) { + dropped = true; + continue; + } + if (!first) out.append(p.gpa, '\n') catch return out.deinit(p.gpa); + out.appendSlice(p.gpa, line) catch return out.deinit(p.gpa); + first = false; + } + if (!dropped) return out.deinit(p.gpa); + const content = out.toOwnedSlice(p.gpa) catch return out.deinit(p.gpa); + File.setContent(p, rf, content); + resetBody(p, rp); + return; + } +} + /// Recent: the one +Recent, filled again when it is there (as Find and /// Grep's +Search is), else opened below the asking pane. pub fn openRecent(p: *Pardes, id: usize) !void { diff --git a/src/ninep/ctl.zig b/src/ninep/ctl.zig index 0d3f084d..3d7ee91a 100644 --- a/src/ninep/ctl.zig +++ b/src/ninep/ctl.zig @@ -2176,6 +2176,31 @@ test "Grep, Symbols and Diagnostics share their directory's one +Search" { try testing.expectEqual(@as(usize, 1), searches); } +test "+Unsaved drops a pane once it has closed" { + const p = try withFile(testing.allocator, "x\n"); + defer p.deinit(); + const a = try th.newPane(p); + _ = wr(p, Node.of(a, .name), "/tmp/pardes-unsaved-a.txt\n"); + _ = wr(p, Node.of(a, .body), "edited\n"); + const b = try th.newPane(p); + _ = wr(p, Node.of(b, .name), "/tmp/pardes-unsaved-b.txt\n"); + _ = wr(p, Node.of(b, .body), "edited\n"); + const root_ctl = @intFromEnum(tree.TopFile.ctl); + try testing.expectEqual(Status.err, wr(p, root_ctl, "Exit\n").reply.status); + var listed: ?*pardes.Pane = null; + for (p.panes) |slot| if (slot) |q| if (q.file) |f| if (f.output) |o| if (o.from == .unsaved) { + listed = q; + }; + const list = listed.?; + try testing.expect(std.mem.indexOf(u8, list.file.?.content, "/tmp/pardes-unsaved-a.txt: Modified") != null); + // a closes (discarded): its row goes; b's stays. + _ = wr(p, Node.of(a, .ctl), "Del\n"); + _ = wr(p, Node.of(a, .ctl), "Del\n"); + p.sync(); + try testing.expect(p.paneBySerial(a) == null); + try testing.expect(std.mem.indexOf(u8, list.file.?.content, "/tmp/pardes-unsaved-a.txt: Modified") == null); +} + test "every EINVAL a write gets says why, in its err record too; DEL is a control character in a line" { const p = try withFile(testing.allocator, "x\n"); defer p.deinit(); diff --git a/src/pardes.zig b/src/pardes.zig index c405c3d9..2649014a 100644 --- a/src/pardes.zig +++ b/src/pardes.zig @@ -4898,6 +4898,7 @@ pub const Pardes = struct { // Closed, a file is remembered with its dot: Recent and a jump back // to it reopen it there. p.noteClosed(pane); + panes.Output.dropUnsaved(p, pane); const watched = (if (pane.file) |f| f.output == null else false) or pane.hasPdf(); for (p.panes, 0..) |slot, id| if (slot == pane) { if (watched) p.emit(.{ .watch = .{ .pane = @intCast(id), .on = false } }); -- cgit v1.3 From 4e224b7c7e67fafcbe7359fcf534048e254b701d Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 29 Sep 2026 13:19:08 -0300 Subject: The theme's chrome is worked out once, not per grapheme; still post passes let the GUI rest; a perf gate somtrmsz's contrast floors made ChromeTheme.fromTheme run its focus-tint and separator searches (pow calls each), and Output's RowDecoration.styleAt called it for every grapheme of every highlighted row: the 50k-line file's render went from 0.11 ms to 13 ms. Pardes.bodyChrome now keeps the theme's chrome, worked out again only when the theme differs; recolorSyntax asks for it once a decorated row, and a plain row (nearly every row of a file) never asks. ReleaseFast, medium fixture, median us, before -> after (main): render 13150 -> 76 (111), key-down 14658 -> 79 (110), wheel 13589 -> 76 (109), open 14891 -> 2095 (2055), edit-char 16703 -> 3006 (1251; the rest of that gap is editing and tree-sitter, not this). Post.animating asked for frames whenever the window had focus and any pass was ready, so a still pass kept the GUI drawing at the display's rate (Bloom: 49% of a core idle, in a hidden test window). A pass now says whether it moves on its own: the CRT (its hum and dither) and a Shadertoy file whose source reads iTime, iFrame or iDate (shader_build.readsTime; the flag rides the wire's post message); Bloom, Vignette and Grain are still. Bloom idle: 49% -> 1.2%, as with no pass. zig build perf-gate: the 50k-line file's gestures, each's fastest sample within 3x of the recorded baseline's (test/perf-baseline-- .json, recorded from this build), run with every unit-test. On the regressed code it fails at 180x for render. --- build.zig | 15 ++++++++++ src/File.zig | 3 +- src/Output.zig | 15 +++++++--- src/detached/wire.zig | 11 +++++-- src/gui/Post.zig | 27 +++++++++++++++-- src/pardes.zig | 12 ++++++++ src/shader_build.zig | 34 ++++++++++++++++++--- test/perf-baseline-gui-Debug.json | 1 + test/perf-baseline-tty-Debug.json | 1 + test/perf-baseline-tty-ReleaseFast.json | 1 + test/perf.zig | 52 ++++++++++++++++++++++++++++++--- 11 files changed, 155 insertions(+), 17 deletions(-) create mode 100644 test/perf-baseline-gui-Debug.json create mode 100644 test/perf-baseline-tty-Debug.json create mode 100644 test/perf-baseline-tty-ReleaseFast.json (limited to 'src/Output.zig') diff --git a/build.zig b/build.zig index 48987edf..79de8a81 100644 --- a/build.zig +++ b/build.zig @@ -1282,6 +1282,18 @@ pub fn build(b: *std.Build) void { run_perf.setCwd(b.path(".")); const perf_step = b.step("perf", "gesture latency or bounded terminal stress (-- [--json] [--reps N] [--base old.json] [--terminal-mib N])"); perf_step.dependOn(&run_perf.step); + // The gate: the 50k-line file's gestures against the baseline this + // build shape recorded, each within 3x of its best. Record one with + // `zig build perf -Dplatform=P [-Doptimize=O] -- --only medium + // --reps 10 --json > test/perf-baseline-P-O.json` (a build that is + // known good). ponytail: the numbers are this machine's; another + // machine records its own. + const perf_gate = b.addRunArtifact(perf); + perf_gate.has_side_effects = true; + perf_gate.setCwd(b.path(".")); + perf_gate.addArgs(&.{ "--only", "medium", "--reps", "10", "--base", b.fmt("test/perf-baseline-{t}-{t}.json", .{ platform, optimize }), "--max-ratio", "3" }); + const perf_gate_step = b.step("perf-gate", "fail when a gesture on the 50k-line file takes over 3x its recorded baseline (test/perf-baseline--.json)"); + perf_gate_step.dependOn(&perf_gate.step); const perf_tests = b.addTest(.{ .root_module = b.createModule(.{ .target = target, @@ -1430,6 +1442,9 @@ pub fn build(b: *std.Build) void { b.step("history", "compare command output and test/build runtime across jj revisions").dependOn(&run_history.step); const unit_step = b.step("unit-test", "run native shell and module unit tests"); + // The perf gate runs with every unit-test (a regression like a + // contrast search per grapheme costs 100x, far past the gate). + unit_step.dependOn(perf_gate_step); const unit_match = testMatch(b, unit_profile, test_filters, unit_step); const lspbench_tests = b.addTest(.{ .root_module = lspbench.root_module, .filters = test_filters }); const run_lspbench_tests = b.addRunArtifact(lspbench_tests); diff --git a/src/File.zig b/src/File.zig index 5f6d7097..1d838c4f 100644 --- a/src/File.zig +++ b/src/File.zig @@ -1293,6 +1293,7 @@ pub fn recolorSyntax(p: *Pardes, s: *Surface, pane: *Pane, f: *State, r: pardes. const row_index: usize = @intCast(@max(0, pane.wrapAt(vr).line)); const metadata: ?locations.Row = if (row_index < f.location_rows.len) f.location_rows[row_index] else null; const decoration = Output.decorateRow(f.output, line, metadata); + const chrome: ?*const pardes.ChromeTheme = if (decoration.plain()) null else p.bodyChrome(); var c: usize = 0; var screen_c: usize = 0; while (hs + c < limit and prefix_width + screen_c < tw) { @@ -1315,7 +1316,7 @@ pub fn recolorSyntax(p: *Pardes, s: *Surface, pane: *Pane, f: *State, r: pardes. } // Results keep their exact live text. Only the location, // matched source range and diagnostic label gain emphasis. - if (decoration.styleAt(p, hs + c)) |style| { + if (if (chrome) |ch| decoration.styleAt(ch, hs + c) else null) |style| { var fill: usize = 0; while (fill < cells and prefix_width + screen_c + fill < tw) : (fill += 1) { const cell = s.at(tx + @as(u16, @intCast(prefix_width + screen_c + fill)), body_y + vr); diff --git a/src/Output.zig b/src/Output.zig index b8dd5e34..6ea81924 100644 --- a/src/Output.zig +++ b/src/Output.zig @@ -54,10 +54,17 @@ const RowDecoration = struct { mark_end: usize = 0, severity: enum { none, err, warning, info, hint } = .none, - pub fn styleAt(row: RowDecoration, p: *const Pardes, byte: usize) ?pardes.CellStyle { - // Body paper changes immediately, so its ink must change with it - // even while the surrounding tags are still fading. - const chrome = pardes.ChromeTheme.fromTheme(p.theme()); + /// Nothing in the row is decorated: most rows of most files. + pub fn plain(row: RowDecoration) bool { + return !row.declaration and row.location_end == 0 and row.prefix_end == 0 and row.mark_end <= row.mark_start; + } + + /// `chrome` is the theme's own (Pardes.bodyChrome): body paper changes + /// immediately, so its ink must change with it even while the + /// surrounding tags are still fading. Once a frame, never a grapheme: + /// working it out takes the contrast searches' pow calls. + pub fn styleAt(row: RowDecoration, chrome: *const pardes.ChromeTheme, byte: usize) ?pardes.CellStyle { + if (row.plain()) return null; if (row.declaration or byte < @max(row.location_end, row.prefix_end)) return .{ .fg = .{ .rgb = chrome.lineno } }; if (byte < row.mark_start or byte >= row.mark_end) return null; diff --git a/src/detached/wire.zig b/src/detached/wire.zig index ee8c72fb..15d3641c 100644 --- a/src/detached/wire.zig +++ b/src/detached/wire.zig @@ -1178,6 +1178,7 @@ pub fn encodeServer(out: []u8, msg: ServerMsg) Error![]const u8 { // 0 a file, else a bundled scene and one. try w.putByte(if (pass.scene) |scene| @as(u8, @intFromEnum(scene)) + 1 else 0); try w.putByte(pass.level); + try w.putByte(@intFromBool(pass.animated)); try w.putU32(pass.revision); try w.putSlice16(pass.path); try w.putSlice32(pass.spirv); @@ -1206,7 +1207,7 @@ pub fn serverBound(msg: ServerMsg) usize { .open_link => |u| u.len, .post => |p| blk: { var n: usize = 0; - for (p.list()) |pass| n += 12 + pass.path.len + pass.spirv.len; + for (p.list()) |pass| n += 13 + pass.path.len + pass.spirv.len; break :blk n; }, }; @@ -1280,6 +1281,11 @@ pub fn decodeServer(tag: u8, payload: []const u8) Error!ServerMsg { pass.* = .{ .scene = if (kind == 0) null else std.enums.fromInt(Scene, kind - 1) orelse return error.BadValue, .level = try r.getByte(), + .animated = switch (try r.getByte()) { + 0 => false, + 1 => true, + else => return error.BadValue, + }, .revision = try r.getU32(), .path = try r.getSlice16(), .spirv = try r.getSlice32(), @@ -1406,7 +1412,7 @@ test "detached wire: every server message round-trips" { try testing.expectEqualStrings("https://x", (try roundServer(&buf, .{ .open_link = "https://x" })).open_link); var chain: Post = .{ .animation = .always, .len = 2 }; chain.passes[0] = .{ .scene = .bloom, .level = 3 }; - chain.passes[1] = .{ .path = "~/wave.glsl", .spirv = "\x03\x02\x23\x07spirv", .revision = 7 }; + chain.passes[1] = .{ .path = "~/wave.glsl", .spirv = "\x03\x02\x23\x07spirv", .revision = 7, .animated = true }; const back = (try roundServer(&buf, .{ .post = chain })).post; try testing.expectEqual(ShaderAnimation.always, back.animation); try testing.expectEqual(@as(u8, 2), back.len); @@ -1416,6 +1422,7 @@ test "detached wire: every server message round-trips" { try testing.expectEqualStrings("~/wave.glsl", back.passes[1].path); try testing.expectEqualStrings("\x03\x02\x23\x07spirv", back.passes[1].spirv); try testing.expectEqual(@as(u32, 7), back.passes[1].revision); + try testing.expect(back.passes[1].animated and !back.passes[0].animated); } test "detached wire: only the display's own effects are on the wire" { diff --git a/src/gui/Post.zig b/src/gui/Post.zig index 06310b7f..602b2790 100644 --- a/src/gui/Post.zig +++ b/src/gui/Post.zig @@ -94,6 +94,8 @@ pub const Pass = struct { pipeline: ?*Pipeline = null, /// The SPIR-V revision `pipeline` was made from (shader_build.Pass). revision: u32 = 0, + /// It moves on its own (shader_build.Pass). + animated: bool = false, }; passes: [max]Pass = @splat(.{}), @@ -140,7 +142,7 @@ pub fn sync(post: *Post, gpa: std.mem.Allocator, device: *c.SDL_GPUDevice, forma post.bloom_down = makePipeline(device, bloom_format, bloom_down_spv, 1, 1) catch null; post.bloom_up = makePipeline(device, bloom_format, bloom_up_spv, 1, 1) catch null; } - next[i] = .{ .scene = scene, .level = entry.level, .pipeline = post.bundled.get(scene) }; + next[i] = .{ .scene = scene, .level = entry.level, .pipeline = post.bundled.get(scene), .animated = entry.animated }; continue; } // A file already in the chain keeps its pipeline and its path. @@ -151,6 +153,7 @@ pub fn sync(post: *Post, gpa: std.mem.Allocator, device: *c.SDL_GPUDevice, forma break; } else next[i] = .{ .path = gpa.dupe(u8, entry.path) catch &.{} }; const pass = &next[i]; + pass.animated = entry.animated; if (pass.revision == entry.revision or entry.spirv.len == 0) continue; pass.revision = entry.revision; const made = makePipeline(device, format, entry.spirv, 1, 4) catch { @@ -200,8 +203,14 @@ pub fn ready(post: *const Post) bool { } /// The chain redraws on its own (level A) as ShaderAnimation says. +/// Only a pass that moves on its own (shader_build.Pass.animated) asks for +/// frames while idle: a still one (Bloom, Vignette, Grain, a file that reads +/// no clock) is drawn again only with a frame of the core's. pub fn animating(post: *const Post, mode: pardes.config.Runtime.ShaderAnimation) bool { - return post.ready() and switch (mode) { + const moving = for (post.passes[0..post.len]) |pass| { + if (pass.pipeline != null and pass.animated) break true; + } else false; + return moving and switch (mode) { .off => false, .on => post.uniforms.focus != 0, .always => true, @@ -664,3 +673,17 @@ test "a moved cursor becomes the previous one, stamped with the time of the move try std.testing.expectEqual([4]f32{ 1.0 / 255.0, 2.0 / 255.0, 3.0 / 255.0, 1 }, post.uniforms.selection_foreground_color); } + +test "a still pass asks for no idle frames; one that reads the clock does" { + var post: Post = .{}; + const fake: *Pipeline = @ptrFromInt(0x1000); + post.passes[0] = .{ .scene = .bloom, .level = 2, .pipeline = fake }; + post.len = 1; + try std.testing.expect(!post.animating(.on) and !post.animating(.always)); + post.passes[1] = .{ .scene = .crt, .level = 2, .pipeline = fake, .animated = true }; + post.len = 2; + try std.testing.expect(post.animating(.on) and post.animating(.always) and !post.animating(.off)); + // Unfocused, `on` rests. + post.uniforms.focus = 0; + try std.testing.expect(!post.animating(.on) and post.animating(.always)); +} diff --git a/src/pardes.zig b/src/pardes.zig index 1f136f2b..ae04b4e7 100644 --- a/src/pardes.zig +++ b/src/pardes.zig @@ -4380,6 +4380,8 @@ pub const Pardes = struct { tty_filter_palette: panes.Terminal.FilterPalette = .{}, font_request_taken: bool = false, custom_theme: ?Theme = null, + /// bodyChrome's: the theme it was worked out for, and it. + body_chrome: ?struct { theme: Theme, chrome: ChromeTheme } = null, theme_file_path: config.Runtime.Text(limits.host_path_cap) = .{}, theme_file_generation: u32 = 0, theme_file_pane: u8 = 0, @@ -7063,6 +7065,16 @@ pub const Pardes = struct { return &p.chrome_animation.displayed; } + /// The theme's own chrome, not a fade's (`theme()`'s, worked out once + /// per theme: its contrast searches take pow calls, too many for a + /// grapheme or a row). + pub fn bodyChrome(p: *Pardes) *const ChromeTheme { + const th = p.theme(); + if (p.body_chrome) |*cached| if (std.meta.eql(cached.theme, th.*)) return &cached.chrome; + p.body_chrome = .{ .theme = th.*, .chrome = ChromeTheme.fromTheme(th) }; + return &p.body_chrome.?.chrome; + } + /// When core animation next needs a frame, on the `stepped_ns` /// timeline: a frame from now while anything moves, the end of the /// wait while something only waits (a message lingering, a look-hover diff --git a/src/shader_build.zig b/src/shader_build.zig index 8aa7eb5e..c2610fd7 100644 --- a/src/shader_build.zig +++ b/src/shader_build.zig @@ -32,8 +32,24 @@ pub const Pass = struct { path: []const u8 = &.{}, spirv: []const u8 = &.{}, revision: u32 = 0, + /// It moves on its own (reads the clock or the frame count), so the + /// chain redraws while idle; a still pass draws only with a new frame. + animated: bool = false, }; +/// The bundled passes that move on their own: the CRT's hum and dither. +pub fn sceneAnimated(scene: Scene) bool { + return scene == .crt; +} + +/// Whether a Shadertoy source moves on its own: it reads the time +/// (iTime, iTimeDelta and the times of a cursor move or a focus change), +/// the frame count or the date. A mention in a comment counts too. +pub fn readsTime(source: []const u8) bool { + for ([_][]const u8{ "iTime", "iFrame", "iDate" }) |name| if (std.mem.indexOf(u8, source, name) != null) return true; + return false; +} + /// Who to wake when a compile is done: the host's loop. pub const Wake = struct { ctx: ?*anyopaque = null, @@ -47,6 +63,7 @@ const File = struct { source: ?u64 = null, spirv: []u8 = &.{}, revision: u32 = 0, + animated: bool = false, /// Wants a compile: new to the chain, or its directory changed. stale: bool = true, }; @@ -56,7 +73,7 @@ const Result = union(enum) { unchanged, missing, failed: struct { text: []u8, source: u64 }, - spirv: struct { bytes: []u8, source: u64 }, + spirv: struct { bytes: []u8, source: u64, animated: bool }, }; /// One compile of the stale files, on its own thread. @@ -148,8 +165,8 @@ pub fn recheck(b: *Build) void { /// The chain as passes, in its order. pub fn view(b: *const Build, chain: *const Chain, out: *[max]Pass) []const Pass { for (chain.list(), 0..) |entry, i| { - out[i] = if (entry.scene) |scene| .{ .scene = scene, .level = entry.level } else for (b.files[0..b.len]) |file| { - if (std.mem.eql(u8, file.path, entry.path.get())) break .{ .path = file.path, .spirv = file.spirv, .revision = file.revision }; + out[i] = if (entry.scene) |scene| .{ .scene = scene, .level = entry.level, .animated = sceneAnimated(scene) } else for (b.files[0..b.len]) |file| { + if (std.mem.eql(u8, file.path, entry.path.get())) break .{ .path = file.path, .spirv = file.spirv, .revision = file.revision, .animated = file.animated }; } else .{ .path = entry.path.get() }; } return out[0..chain.len]; @@ -211,6 +228,7 @@ fn collect(b: *Build, gpa: std.mem.Allocator, core: *pardes.Pardes, job: *Job) v gpa.free(f.spirv); f.spirv = r.bytes; f.source = r.source; + f.animated = r.animated; f.revision +%= 1; b.revision +%= 1; }, @@ -291,7 +309,7 @@ fn compileOne(gpa: std.mem.Allocator, io: std.Io, path: []const u8, known: ?u64) .exited => |code| code == 0, else => false, }; - if (clean) return .{ .spirv = .{ .bytes = reader.toOwnedSlice(0) catch return .none, .source = source } }; + if (clean) return .{ .spirv = .{ .bytes = reader.toOwnedSlice(0) catch return .none, .source = source, .animated = readsTime(body) } }; const said = reader.toOwnedSlice(1) catch return .none; // glslc calls its input ; the file is what a person knows. defer gpa.free(said); @@ -400,3 +418,11 @@ test "a save that changes a file compiles it again, a failed one keeps the last const second = b.view(&core.settings.post, &out)[0]; try std.testing.expect(second.revision != first.revision and b.revision != at); } + +test "a pass animates when it reads the clock or the frame count, and only the CRT of the bundled ones" { + try std.testing.expect(readsTime("o = vec4(sin(iTime));")); + try std.testing.expect(readsTime("float f = float(iFrame % 64);")); + try std.testing.expect(readsTime("x = iTimeCursorChange;")); + try std.testing.expect(!readsTime("o = texture(iChannel0, p / iResolution.xy);")); + for (std.enums.values(Scene)) |scene| try std.testing.expectEqual(scene == .crt, sceneAnimated(scene)); +} diff --git a/test/perf-baseline-gui-Debug.json b/test/perf-baseline-gui-Debug.json new file mode 100644 index 00000000..fd64ebf9 --- /dev/null +++ b/test/perf-baseline-gui-Debug.json @@ -0,0 +1 @@ +{"harness":"67f85bf9692f1778","build":{"compiler":"0.16.0","target":"x86_64-linux.5.10...6.19-gnu.2.38","cpu":"x86_64","driver_optimize":"ReleaseFast","core_optimize":"Debug","c_optimize":"ReleaseFast","terminal_optimize":"ReleaseSafe","platform":"gui","grammars":"full","mupdf":true,"jpx":true,"tracy":false,"quic":false,"theme_animation":true,"terminal_simd":true,"prebuilt_shaders":false},"cols":120,"rows":40,"reps":10,"only":"medium","fixtures":[{"name":"small","lines":1000,"cols":60,"bytes":62694},{"name":"medium","lines":50000,"cols":60,"bytes":3201944},{"name":"large","lines":300000,"cols":60,"bytes":19464444},{"name":"longline","lines":400,"cols":8000,"bytes":3200400},{"name":"esp32p4","lines":12,"cols":240,"bytes":2892}],"cells":[{"op":"open","fixture":"medium","min_us":1768,"med_us":2025,"p90_us":2122,"max_us":2125},{"op":"render","fixture":"medium","min_us":72,"med_us":75,"p90_us":76,"max_us":83},{"op":"key-down","fixture":"medium","min_us":73,"med_us":76,"p90_us":80,"max_us":84},{"op":"key-right","fixture":"medium","min_us":74,"med_us":77,"p90_us":81,"max_us":84},{"op":"page-down","fixture":"medium","min_us":73,"med_us":74,"p90_us":77,"max_us":79},{"op":"wheel","fixture":"medium","min_us":71,"med_us":75,"p90_us":81,"max_us":81},{"op":"edit-char","fixture":"medium","min_us":2413,"med_us":2674,"p90_us":2943,"max_us":3111}]} diff --git a/test/perf-baseline-tty-Debug.json b/test/perf-baseline-tty-Debug.json new file mode 100644 index 00000000..682ea028 --- /dev/null +++ b/test/perf-baseline-tty-Debug.json @@ -0,0 +1 @@ +{"harness":"67f85bf9692f1778","build":{"compiler":"0.16.0","target":"x86_64-linux.5.10...6.19-gnu.2.38","cpu":"x86_64","driver_optimize":"ReleaseFast","core_optimize":"Debug","c_optimize":"ReleaseFast","terminal_optimize":"ReleaseSafe","platform":"tty","grammars":"full","mupdf":true,"jpx":true,"tracy":false,"quic":false,"theme_animation":true,"terminal_simd":true,"prebuilt_shaders":false},"cols":120,"rows":40,"reps":10,"only":"medium","fixtures":[{"name":"small","lines":1000,"cols":60,"bytes":62694},{"name":"medium","lines":50000,"cols":60,"bytes":3201944},{"name":"large","lines":300000,"cols":60,"bytes":19464444},{"name":"longline","lines":400,"cols":8000,"bytes":3200400},{"name":"esp32p4","lines":12,"cols":240,"bytes":2892}],"cells":[{"op":"open","fixture":"medium","min_us":1944,"med_us":2130,"p90_us":2232,"max_us":2394},{"op":"render","fixture":"medium","min_us":71,"med_us":75,"p90_us":76,"max_us":91},{"op":"key-down","fixture":"medium","min_us":72,"med_us":79,"p90_us":93,"max_us":102},{"op":"key-right","fixture":"medium","min_us":73,"med_us":76,"p90_us":78,"max_us":81},{"op":"page-down","fixture":"medium","min_us":72,"med_us":73,"p90_us":76,"max_us":76},{"op":"wheel","fixture":"medium","min_us":71,"med_us":85,"p90_us":96,"max_us":102},{"op":"edit-char","fixture":"medium","min_us":2612,"med_us":3112,"p90_us":3238,"max_us":3618}]} diff --git a/test/perf-baseline-tty-ReleaseFast.json b/test/perf-baseline-tty-ReleaseFast.json new file mode 100644 index 00000000..4fd96d92 --- /dev/null +++ b/test/perf-baseline-tty-ReleaseFast.json @@ -0,0 +1 @@ +{"harness":"67f85bf9692f1778","build":{"compiler":"0.16.0","target":"x86_64-linux.5.10...6.19-gnu.2.38","cpu":"x86_64","driver_optimize":"ReleaseFast","core_optimize":"ReleaseFast","c_optimize":"ReleaseFast","terminal_optimize":"ReleaseFast","platform":"tty","grammars":"full","mupdf":true,"jpx":true,"tracy":false,"quic":false,"theme_animation":true,"terminal_simd":true,"prebuilt_shaders":false},"cols":120,"rows":40,"reps":10,"only":"medium","fixtures":[{"name":"small","lines":1000,"cols":60,"bytes":62694},{"name":"medium","lines":50000,"cols":60,"bytes":3201944},{"name":"large","lines":300000,"cols":60,"bytes":19464444},{"name":"longline","lines":400,"cols":8000,"bytes":3200400},{"name":"esp32p4","lines":12,"cols":240,"bytes":2892}],"cells":[{"op":"open","fixture":"medium","min_us":1971,"med_us":2259,"p90_us":2308,"max_us":2339},{"op":"render","fixture":"medium","min_us":71,"med_us":75,"p90_us":78,"max_us":79},{"op":"key-down","fixture":"medium","min_us":73,"med_us":77,"p90_us":79,"max_us":95},{"op":"key-right","fixture":"medium","min_us":72,"med_us":77,"p90_us":80,"max_us":88},{"op":"page-down","fixture":"medium","min_us":72,"med_us":76,"p90_us":81,"max_us":83},{"op":"wheel","fixture":"medium","min_us":71,"med_us":75,"p90_us":80,"max_us":91},{"op":"edit-char","fixture":"medium","min_us":2662,"med_us":2999,"p90_us":3375,"max_us":3622}]} diff --git a/test/perf.zig b/test/perf.zig index 8eec1ed0..e244091c 100644 --- a/test/perf.zig +++ b/test/perf.zig @@ -323,6 +323,9 @@ const Options = struct { mini: bool = false, terminal_mib: ?usize = null, self_test: bool = false, + /// A gate: fail when a cell's fastest sample is more than this many + /// times the baseline's fastest (--base's). + max_ratio: ?f64 = null, fn parse(args: []const []const u8) !Options { var opts: Options = .{}; @@ -330,7 +333,7 @@ const Options = struct { while (i < args.len) : (i += 1) { const arg = args[i]; if (!std.mem.startsWith(u8, arg, "--")) return error.UnknownOption; - const option = std.meta.stringToEnum(enum { json, creation, startup, mini, @"terminal-mib", @"self-test", reps, cols, rows, base, only }, arg[2..]) orelse + const option = std.meta.stringToEnum(enum { json, creation, startup, mini, @"terminal-mib", @"self-test", reps, cols, rows, base, only, @"max-ratio" }, arg[2..]) orelse return error.UnknownOption; switch (option) { .json => opts.json = true, @@ -349,6 +352,7 @@ const Options = struct { .base => opts.base = value, .only => opts.only = value, .@"terminal-mib" => opts.terminal_mib = std.fmt.parseInt(usize, value, 10) catch return error.InvalidNumber, + .@"max-ratio" => opts.max_ratio = std.fmt.parseFloat(f64, value) catch return error.InvalidNumber, else => unreachable, } }, @@ -363,6 +367,10 @@ const Options = struct { if (opts.creation or opts.only != null or opts.base != null) return error.IncompatibleOptions; } if (opts.base) |path| if (path.len == 0) return error.MissingValue; + if (opts.max_ratio) |ratio| { + if (opts.base == null) return error.IncompatibleOptions; + if (!(ratio >= 1)) return error.InvalidMeasurement; + } if (opts.mini and (opts.creation or opts.terminal_mib != null or opts.only != null or opts.base != null)) return error.IncompatibleOptions; if (opts.only) |name| { @@ -431,8 +439,28 @@ pub fn main(init: std.process.Init) !void { } } - if (opts.json) return reportJson(init.io, &cells, &term_cells, &bytes, opts); - reportText(&cells, &term_cells, &bytes, reps, opts.base, base); + if (opts.json) try reportJson(init.io, &cells, &term_cells, &bytes, opts) else reportText(&cells, &term_cells, &bytes, reps, opts.base, base); + if (opts.max_ratio) |ratio| try gate(&cells, &base.?, ratio); +} + +/// The performance gate (zig build perf-gate): every measured cell's +/// fastest sample against the baseline's fastest. The fastest, not the +/// median: a loaded machine slows the median, rarely the best of a run, +/// while a regression slows every sample. +fn gate(cells: *const [std.enums.values(Op).len][fixtures.len]Cell, base: *const Base, ratio: f64) !void { + var failed = false; + for (std.enums.values(Op), 0..) |op, oi| for (fixtures, 0..) |fx, fi| { + const then = base.min[oi][fi]; + const now = cells[oi][fi].min_us; + if (then == 0 or now == 0) continue; + const x = @as(f64, @floatFromInt(now)) / @as(f64, @floatFromInt(then)); + if (x > ratio) { + std.debug.print("perf gate: {s} on {s} took {d} us at best, {d:.1}x the baseline's {d} us (limit {d:.1}x)\n", .{ op.label(), fx.name, now, x, then, ratio }); + failed = true; + } + }; + if (failed) return error.PerformanceRegression; + std.debug.print("perf gate: every cell within {d:.1}x of the baseline\n", .{ratio}); } fn measure(op: Op, fx: Fixture, path: []const u8, expected_bytes: usize, reps: usize) !Cell { @@ -1378,6 +1406,7 @@ fn writeJson( const Base = struct { med: [std.enums.values(Op).len][fixtures.len]u64, + min: [std.enums.values(Op).len][fixtures.len]u64 = @splat(@splat(0)), term_med: [std.enums.values(TermOp).len][term_fixtures.len]u64, }; @@ -1443,6 +1472,7 @@ fn parseBase(src: []const u8, opts: Options, bytes: *const [fixtures.len]usize) if (file_seen[oi][index]) return error.BaselineCoverage; file_seen[oi][index] = true; base.med[oi][index] = cell.med_us; + base.min[oi][index] = cell.min_us; } else { if (opts.only != null) return error.BaselineCoverage; const ti = for (term_fixtures, 0..) |fixture, index| { @@ -1487,8 +1517,22 @@ fn selfTest() !void { &.{ "--terminal-mib", "1", "--only", "small" }, &.{ "--terminal-mib", "1", "--creation" }, &.{ "--terminal-mib", "1", "--base", "old.json" }, &.{ "--mini", "--creation" }, &.{ "--mini", "--terminal-mib", "1" }, &.{ "--mini", "--base", "old.json" }, - &.{ "--mini", "--only", "small" }, + &.{ "--mini", "--only", "small" }, &.{ "--max-ratio", "3" }, }) |args| try testing.expectError(error.IncompatibleOptions, Options.parse(args)); + try testing.expectError(error.InvalidMeasurement, Options.parse(&.{ "--base", "old.json", "--max-ratio", "0.5" })); + const gated = try Options.parse(&.{ "--only", "medium", "--base", "old.json", "--max-ratio", "3" }); + try testing.expectEqual(@as(f64, 3), gated.max_ratio.?); + { + // A cell three and a half times its baseline's best fails; the + // rest pass. + var cells: [std.enums.values(Op).len][fixtures.len]Cell = @splat(@splat(.{})); + var base: Base = .{ .med = @splat(@splat(0)), .term_med = @splat(@splat(0)) }; + base.min[1][1] = 100; + cells[1][1] = .{ .min_us = 290, .med_us = 300, .p90_us = 300, .max_us = 300 }; + try gate(&cells, &base, 3); + cells[1][1].min_us = 350; + try testing.expectError(error.PerformanceRegression, gate(&cells, &base, 3)); + } const selected = try Options.parse(&.{ "--only", "small", "--reps", "2", "--cols", "80", "--rows", "24" }); try testing.expectEqual(@as(usize, 2), selected.reps); try testing.expectEqual(@as(u16, 80), selected.cols); -- cgit v1.3 From 97679fee286cc0fd3104f138e9fa14722c614f7f Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 29 Sep 2026 20:24:35 -0300 Subject: Messages.messageLog is Messages.at: the ring's i-th record, read as p.messages.at(i) The rename deferred from the file split; no behaviour changes. Output.zig's one call follows. Co-Authored-By: Claude Opus 5.5 --- src/Messages.zig | 24 ++++++++++++------------ src/Output.zig | 2 +- 2 files changed, 13 insertions(+), 13 deletions(-) (limited to 'src/Output.zig') diff --git a/src/Messages.zig b/src/Messages.zig index 42200863..7dcb22ed 100644 --- a/src/Messages.zig +++ b/src/Messages.zig @@ -51,13 +51,13 @@ pub const LoggedMessage = struct { fn leaderText(p: *const Pardes, buf: *[16]u8) []const u8 { buf.* = @splat(' '); @memcpy(buf[0..3], "SPC"); - var at: usize = 3; + var end: usize = 3; for (p.leader_keys[0..p.leader_n]) |ch| { - if (at + 2 > buf.len) break; - buf[at + 1] = ch; - at += 2; + if (end + 2 > buf.len) break; + buf[end + 1] = ch; + end += 2; } - return buf[0..at]; + return buf[0..end]; } /// How wide a notice chip is, in grid columns: its own text plus a blank @@ -437,7 +437,7 @@ fn logMessage(p: *Pardes, id: usize, text: []const u8) void { } /// The log oldest-first, which is reading order. -pub fn messageLog(m: *const Messages, i: usize) ?*const LoggedMessage { +pub fn at(m: *const Messages, i: usize) ?*const LoggedMessage { if (i >= m.len) return null; const first = (m.head + limits.message_log - m.len) % limits.message_log; return &m.log[(first + i) % limits.message_log]; @@ -580,13 +580,13 @@ test "the message log keeps what the row forgets, and collapses repeats" { setMessage(p, 0, "save: AccessDenied"); try std.testing.expectEqual(@as(usize, 2), p.messages.len); - const first = p.messages.messageLog(0).?; + const first = p.messages.at(0).?; try std.testing.expectEqual(@as(u16, 2), first.repeats); // ...and the NEWEST wording is what survives, so the row carries the last // time it happened rather than the first. try std.testing.expectEqualStrings("14:32:09 saved /x.zig", first.slice()); - try std.testing.expectEqualStrings("save: AccessDenied", p.messages.messageLog(1).?.slice()); - try std.testing.expect(p.messages.messageLog(2) == null); + try std.testing.expectEqualStrings("save: AccessDenied", p.messages.at(1).?.slice()); + try std.testing.expect(p.messages.at(2) == null); // The same text from a DIFFERENT pane is a different event: one pane's // failure must not be recorded as another's. @@ -594,7 +594,7 @@ test "the message log keeps what the row forgets, and collapses repeats" { const other = p.active; setMessage(p, other, "save: AccessDenied"); try std.testing.expectEqual(@as(usize, 3), p.messages.len); - try std.testing.expectEqual(p.panes[other].?.serial, p.messages.messageLog(2).?.serial); + try std.testing.expectEqual(p.panes[other].?.serial, p.messages.at(2).?.serial); // Progress is NOT logged: it arrives several times a second for a whole // index and would push everything else out (`setStatus`). @@ -607,10 +607,10 @@ test "the message log keeps what the row forgets, and collapses repeats" { setMessage(p, 0, std.fmt.bufPrint(&buf, "line {d}", .{i}) catch unreachable); } try std.testing.expectEqual(@as(usize, limits.message_log), p.messages.len); - try std.testing.expectEqualStrings("line 5", p.messages.messageLog(0).?.slice()); + try std.testing.expectEqualStrings("line 5", p.messages.at(0).?.slice()); var last_buf: [32]u8 = undefined; const want_last = std.fmt.bufPrint(&last_buf, "line {d}", .{limits.message_log + 4}) catch unreachable; - try std.testing.expectEqualStrings(want_last, p.messages.messageLog(limits.message_log - 1).?.slice()); + 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" { diff --git a/src/Output.zig b/src/Output.zig index 6ea81924..fb8fe7a3 100644 --- a/src/Output.zig +++ b/src/Output.zig @@ -844,7 +844,7 @@ 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.messageLog(i)) |m| : (i += 1) { + 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}); -- cgit v1.3 From 813a0b2bf3c110f2287d7136f0dfc540c0978cd6 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 29 Sep 2026 22:05:58 -0300 Subject: The GUI embeds its shaders' GLSL from shaders/ always: the 14 prebuilt copies, identical to their sources, go, and so does the label saying which was used shaders/prebuilt/*.glsl were byte-identical to shaders/X.glsl or to prefix.glsl + post/X.glsl (checked with cmp, all 14), kept only so a -Dprebuilt-shaders build could name them; EffectCode and Config then labelled the GUI's shader source as live or prebuilt. The GUI embeds shaderSource (a concatenation, no glslc) either way now; the prebuilt SPIR-V stays, and zig build shaders refreshes only it. Config's report and EffectCode lose their GUI shader source line. Co-Authored-By: Claude Opus 5.5 --- build.zig | 14 +-- shaders/prebuilt/bloom-down.frag.glsl | 39 ------- shaders/prebuilt/bloom-up.frag.glsl | 26 ----- shaders/prebuilt/decor.frag.glsl | 83 -------------- shaders/prebuilt/image.frag.glsl | 45 -------- shaders/prebuilt/image.vert.glsl | 49 -------- shaders/prebuilt/overlay.frag.glsl | 17 --- shaders/prebuilt/overlay.vert.glsl | 11 -- shaders/prebuilt/post-bloom.frag.glsl | 141 ----------------------- shaders/prebuilt/post-crt.frag.glsl | 186 ------------------------------- shaders/prebuilt/post-grain.frag.glsl | 133 ---------------------- shaders/prebuilt/post-vignette.frag.glsl | 139 ----------------------- shaders/prebuilt/post.vert.glsl | 10 -- shaders/prebuilt/ui.frag.glsl | 93 ---------------- shaders/prebuilt/ui.vert.glsl | 82 -------------- src/Output.zig | 7 -- src/config.zig | 7 -- src/effect_sources.zig | 38 +------ test/output.zig | 5 +- 19 files changed, 4 insertions(+), 1121 deletions(-) delete mode 100644 shaders/prebuilt/bloom-down.frag.glsl delete mode 100644 shaders/prebuilt/bloom-up.frag.glsl delete mode 100644 shaders/prebuilt/decor.frag.glsl delete mode 100644 shaders/prebuilt/image.frag.glsl delete mode 100644 shaders/prebuilt/image.vert.glsl delete mode 100644 shaders/prebuilt/overlay.frag.glsl delete mode 100644 shaders/prebuilt/overlay.vert.glsl delete mode 100644 shaders/prebuilt/post-bloom.frag.glsl delete mode 100644 shaders/prebuilt/post-crt.frag.glsl delete mode 100644 shaders/prebuilt/post-grain.frag.glsl delete mode 100644 shaders/prebuilt/post-vignette.frag.glsl delete mode 100644 shaders/prebuilt/post.vert.glsl delete mode 100644 shaders/prebuilt/ui.frag.glsl delete mode 100644 shaders/prebuilt/ui.vert.glsl (limited to 'src/Output.zig') diff --git a/build.zig b/build.zig index a69327ae..e74bf303 100644 --- a/build.zig +++ b/build.zig @@ -168,14 +168,10 @@ pub fn build(b: *std.Build) void { if (!enable_mupdf) pdf_pointer_bench_step.dependOn(&b.addFail("pdf-pointer-bench is unavailable with -Dmupdf=false").step); - const shaders_step = b.step("shaders", "refresh paired shaders/prebuilt/*.spv + *.glsl snapshots (glslc)"); + const shaders_step = b.step("shaders", "refresh the committed shaders/prebuilt/*.spv (glslc)"); const update_shaders = b.addUpdateSourceFiles(); for (gui_shaders) |name| { update_shaders.addCopyFileToSource(compileGlsl(b, name), b.fmt("shaders/prebuilt/{s}.spv", .{name})); - update_shaders.addCopyFileToSource( - shaderSource(b, name), - b.fmt("shaders/prebuilt/{s}.glsl", .{name}), - ); } shaders_step.dependOn(&update_shaders.step); @@ -999,15 +995,12 @@ pub fn build(b: *std.Build) void { const iso_on = b.addOptions(); iso_on.addOption(bool, "isolated", true); - // Consulted only for a gui shell, so `-Dprebuilt-shaders` alone decides it - // here; the platform half of that condition is the branch it sits in. - const gui_effect_source_dir = if (prebuilt_shaders) "shaders/prebuilt" else "shaders"; for (core_mods, core_shells) |mod, shell| { mod.addOptions("pardes_config", if (also_gui and shell == .gui) gui_opts.? else opts); mod.addOptions("pardes_isolation", if (isolated_mod == mod) iso_on else iso_off); if (shell == .gui) for (gui_shaders) |name| mod.addAnonymousImport( b.fmt("effect-source-{s}.glsl", .{name}), - .{ .root_source_file = if (prebuilt_shaders) b.path(b.fmt("{s}/{s}.glsl", .{ gui_effect_source_dir, name })) else shaderSource(b, name) }, + .{ .root_source_file = shaderSource(b, name) }, ); if (shell == .macos) mod.addAnonymousImport("effect-source-crt.ci.metal", .{ .root_source_file = b.path("shaders/crt.ci.metal"), @@ -1948,9 +1941,6 @@ fn shellOptions(b: *std.Build, cfg: ShellConfig, platform: Platform) *std.Build. o.addOption(u16, "esp32p4_rows", cfg.esp32p4_rows); o.addOption(bool, "workspace_tag", cfg.workspace_tag orelse (platform != .macos)); o.addOption(bool, "theme_animation", cfg.theme_animation orelse (platform != .esp32p4)); - // Meaningful only for the SDL shell. Keeping the platform condition here - // prevents Config/EffectCode from describing tty/macOS/web as "prebuilt". - o.addOption(bool, "gui_shader_sources_prebuilt", platform == .gui and cfg.prebuilt_shaders); o.addOption([]const u8, "zls_version", if (cfg.zls_backend) zls_version else "none"); o.addOption(bool, "embed_sources", cfg.embed_sources); o.addOption([]const u8, "version", zon.version); diff --git a/shaders/prebuilt/bloom-down.frag.glsl b/shaders/prebuilt/bloom-down.frag.glsl deleted file mode 100644 index 3465926d..00000000 --- a/shaders/prebuilt/bloom-down.frag.glsl +++ /dev/null @@ -1,39 +0,0 @@ -#version 450 - -// Bloom, down (docs/effects.md G4): one step of a dual Kawase filter, a -// source half as big again sampled at five points, the first step over the -// frame through a bright pass in linear light. Written to a float target. - -layout(set = 2, binding = 0) uniform sampler2D source; -layout(std140, set = 3, binding = 0) uniform BloomStep { - // xy: a source texel; zw: a target texel. - vec4 texels; - // x: the bright pass's threshold on a channel's linear peak (above the - // page's own), 0 for none (a later step); y: its soft knee. - vec4 pass; -} u; - -layout(location = 0) out vec4 o_col; - -vec3 toLinear(vec3 c) { - return mix(pow((c + 0.055) / 1.055, vec3(2.4)), c / 12.92, lessThanEqual(c, vec3(0.04045))); -} - -vec3 tap(vec2 uv) { - vec3 c = texture(source, uv).rgb; - if (u.pass.x <= 0.0) return c; - c = toLinear(c); - float peak = max(c.r, max(c.g, c.b)); - return c * smoothstep(u.pass.x, u.pass.x + u.pass.y, peak); -} - -void main() { - vec2 uv = gl_FragCoord.xy * u.texels.zw; - vec2 h = 0.5 * u.texels.xy; - vec3 sum = tap(uv) * 4.0; - sum += tap(uv - h); - sum += tap(uv + h); - sum += tap(uv + vec2(h.x, -h.y)); - sum += tap(uv - vec2(h.x, -h.y)); - o_col = vec4(sum / 8.0, 1.0); -} diff --git a/shaders/prebuilt/bloom-up.frag.glsl b/shaders/prebuilt/bloom-up.frag.glsl deleted file mode 100644 index 368076ed..00000000 --- a/shaders/prebuilt/bloom-up.frag.glsl +++ /dev/null @@ -1,26 +0,0 @@ -#version 450 - -// Bloom, up (docs/effects.md G4): one step of a dual Kawase filter back up, -// a tent of eight points over the smaller level. Float target. - -layout(set = 2, binding = 0) uniform sampler2D source; -layout(std140, set = 3, binding = 0) uniform BloomStep { - vec4 texels; - vec4 pass; -} u; - -layout(location = 0) out vec4 o_col; - -void main() { - vec2 uv = gl_FragCoord.xy * u.texels.zw; - vec2 h = 0.5 * u.texels.xy; - vec3 sum = texture(source, uv + vec2(-2.0 * h.x, 0.0)).rgb; - sum += texture(source, uv + vec2(-h.x, h.y)).rgb * 2.0; - sum += texture(source, uv + vec2(0.0, 2.0 * h.y)).rgb; - sum += texture(source, uv + vec2(h.x, h.y)).rgb * 2.0; - sum += texture(source, uv + vec2(2.0 * h.x, 0.0)).rgb; - sum += texture(source, uv + vec2(h.x, -h.y)).rgb * 2.0; - sum += texture(source, uv + vec2(0.0, -2.0 * h.y)).rgb; - sum += texture(source, uv + vec2(-h.x, -h.y)).rgb * 2.0; - o_col = vec4(sum / 12.0, 1.0); -} diff --git a/shaders/prebuilt/decor.frag.glsl b/shaders/prebuilt/decor.frag.glsl deleted file mode 100644 index bb1ef0d6..00000000 --- a/shaders/prebuilt/decor.frag.glsl +++ /dev/null @@ -1,83 +0,0 @@ -#version 450 - -// Decor, drawn by ui.vert.glsl like a cell, its track's transition included, -// and blended as the overlay pipeline blends (backgroundLayerBlend). Ink (a -// cursor) is drawn with the opacity uniform at 1. -// -// Flat: a hard-edged fill (a rule, a rail, a grip mark, a bar cursor). Its -// colour rides in the cell's ground (a_bg), its coverage in a_fg.r, so the -// result is the overlay pipeline's exactly. -// -// Checker (flag 0x08000000): two colours in squares, or in stripes, see main. -// -// Soft (flag 0x10000000): a rectangle's shadow, rim or glow blurred by a Gaussian, -// in closed form (the product of two erf edges), on one quad grown by 3 -// sigma: no blur pass. Everything is in the quad's own 0..1 space, so a -// track's transform carries it: sigma per axis in the uv, the caster's -// offset from its shadow in fg.gb, the strength in fg.r. The caster's own -// rectangle is left alone (it is drawn already), and the alpha is pre-warped -// so black darkens in linear light, then dithered so it never bands. - -layout(std140, set = 3, binding = 0) uniform UiUniforms { - float background_opacity; -} u_ui; - -layout(location = 0) in vec2 v_uv; -layout(location = 1) in vec3 v_fg; -layout(location = 2) in vec3 v_bg; -layout(location = 3) in vec2 v_cell_uv; -layout(location = 4) flat in uvec4 v_effect; -layout(location = 5) flat in vec4 v_clip; - -layout(location = 0) out vec4 o_col; - -// erf to about 4e-4 (Winitzki's approximation): smooth, cheap, odd. -float erfApprox(float x) { - float x2 = x * x; - const float a = 0.147; - float e = sqrt(1.0 - exp(-x2 * (1.2732395 + a * x2) / (1.0 + a * x2))); - return x < 0.0 ? -e : e; -} - -// How much of [lo, hi] a Gaussian of sigma s centred at x covers. -float edge(float x, float lo, float hi, float s) { - float k = 0.70710678 / s; - return 0.5 * (erfApprox((x - lo) * k) - erfApprox((x - hi) * k)); -} - -float ign(vec2 p) { - return fract(52.9829189 * fract(dot(p, vec2(0.06711056, 0.00583715)))); -} - -void main() { - if (v_clip.z >= v_clip.x && (gl_FragCoord.x < v_clip.x || gl_FragCoord.x >= v_clip.z || - gl_FragCoord.y < v_clip.y || gl_FragCoord.y >= v_clip.w)) discard; - float opacity = clamp(u_ui.background_opacity, 0.0, 1.0); - // Checker (flag 0x08000000): squares of v_uv.x pixels from the quad's - // own corner, so it moves with its rail, in the ground's colour and the - // ink's (lapis's scroll track). - vec2 in_quad = v_cell_uv / max(vec2(dFdx(v_cell_uv.x), dFdy(v_cell_uv.y)), vec2(1e-6)); - if ((v_effect.x & 0x08000000u) != 0u) { - ivec2 q = ivec2(floor(in_quad / max(v_uv.x, 1.0))); - // v_uv.y set: stripes across the quad (lapis's title bar), not squares. - int k = v_uv.y > 0.5 ? q.y : q.x + q.y; - o_col = vec4(((k & 1) == 0 ? v_bg : v_fg) * opacity, 1.0); - return; - } - if ((v_effect.x & 0x10000000u) == 0u) { - o_col = vec4(v_bg * opacity, v_fg.r); - return; - } - vec2 s = v_uv; - vec2 m = 3.0 * s; - vec2 p = v_cell_uv; - vec2 caster0 = m - v_fg.gb; - vec2 caster1 = 1.0 - m - v_fg.gb; - if (all(greaterThanEqual(p, caster0)) && all(lessThan(p, caster1))) discard; - float a = v_fg.r * edge(p.x, m.x, 1.0 - m.x, s.x) * edge(p.y, m.y, 1.0 - m.y, s.y); - // Black darkens in linear light; a light colour (a rim, a glow) is laid - // on as it is, within §8.2's 25%. - if (all(equal(v_bg, vec3(0.0)))) a = 1.0 - pow(max(1.0 - a, 0.0), 1.0 / 2.2); - a = clamp(a + (ign(gl_FragCoord.xy) - 0.5) / 255.0, 0.0, 1.0); - o_col = vec4(v_bg * opacity, a); -} diff --git a/shaders/prebuilt/image.frag.glsl b/shaders/prebuilt/image.frag.glsl deleted file mode 100644 index 0cc1b2ee..00000000 --- a/shaders/prebuilt/image.frag.glsl +++ /dev/null @@ -1,45 +0,0 @@ -#version 450 - -layout(set = 2, binding = 0) uniform sampler2D u_image; -layout(std140, set = 3, binding = 0) uniform UiUniforms { - float background_opacity; -} u_ui; - -layout(location = 0) in vec2 v_uv; -layout(location = 1) in vec2 v_panel_uv; -layout(location = 2) flat in uvec4 v_effect; -layout(location = 0) out vec4 o_col; - -float cellNoise(uint serial, uint col, uint row) { - uint x = serial ^ (col * 0x9e3779b9u) ^ (row * 0x85ebca6bu); - x ^= x >> 16; - x *= 0x7feb352du; - x ^= x >> 15; - x *= 0x846ca68bu; - x ^= x >> 16; - return float(x & 0xffffu) / 65535.0; -} - -void main() { - vec4 source = texture(u_image, v_uv); - // Keep source coverage for destination subtraction; the pipeline scales - // source alpha by the same opacity through its alpha blend constant. - source.rgb *= clamp(u_ui.background_opacity, 0.0, 1.0); - uint effect = v_effect.x & 0x7fffffffu; - bool oldLayer = (v_effect.x & 0x80000000u) != 0u; - float progress = clamp(uintBitsToFloat(v_effect.y), 0.0, 1.0); - uvec2 dimensions = max( - uvec2(v_effect.w & 0xffffu, v_effect.w >> 16), - uvec2(1u)); - uvec2 cellCoord = min( - uvec2(floor(max(v_panel_uv, vec2(0.0)) * vec2(dimensions))), - dimensions - 1u); - float noise = cellNoise(v_effect.z, cellCoord.x, cellCoord.y); - if (effect == 3u) { - bool reveal = progress >= 1.0 || (progress > 0.0 && noise < progress); - if (oldLayer == reveal) discard; - o_col = source; - return; - } - o_col = source; -} diff --git a/shaders/prebuilt/image.vert.glsl b/shaders/prebuilt/image.vert.glsl deleted file mode 100644 index 04196ce4..00000000 --- a/shaders/prebuilt/image.vert.glsl +++ /dev/null @@ -1,49 +0,0 @@ -#version 450 - -// One instance per Surface image attachment. The CPU has already converted -// the pane's cell rectangle and the aspect-preserving contain fit to NDC. -layout(location = 0) in vec4 a_rect; // x0, y0, x1, y1 -layout(location = 1) in vec4 a_uv_rect; // u0, v0, u1, v1 -layout(location = 2) in vec4 a_panel_rect; -layout(location = 3) in vec4 a_present_rect; -layout(location = 4) in uvec4 a_effect; - -layout(location = 0) out vec2 v_uv; -layout(location = 1) out vec2 v_panel_uv; -layout(location = 2) flat out uvec4 v_effect; - -void main() { - vec2 pos; - int corner = gl_VertexIndex % 6; - if (corner == 0) { - pos = vec2(a_rect.x, a_rect.y); - v_uv = vec2(a_uv_rect.x, a_uv_rect.y); - } else if (corner == 1) { - pos = vec2(a_rect.z, a_rect.y); - v_uv = vec2(a_uv_rect.z, a_uv_rect.y); - } else if (corner == 2) { - pos = vec2(a_rect.z, a_rect.w); - v_uv = vec2(a_uv_rect.z, a_uv_rect.w); - } else if (corner == 3) { - pos = vec2(a_rect.x, a_rect.y); - v_uv = vec2(a_uv_rect.x, a_uv_rect.y); - } else if (corner == 4) { - pos = vec2(a_rect.z, a_rect.w); - v_uv = vec2(a_uv_rect.z, a_uv_rect.w); - } else { - pos = vec2(a_rect.x, a_rect.w); - v_uv = vec2(a_uv_rect.x, a_uv_rect.w); - } - v_panel_uv = v_uv; - uint effect = a_effect.x & 0x7fffffffu; - if (effect != 0u) { - vec2 panel_size = a_panel_rect.zw - a_panel_rect.xy; - panel_size.x = abs(panel_size.x) < 0.000001 ? 0.000001 : panel_size.x; - panel_size.y = abs(panel_size.y) < 0.000001 ? -0.000001 : panel_size.y; - v_panel_uv = (pos - a_panel_rect.xy) / panel_size; - if (effect == 1u || effect == 2u || effect == 5u) - pos = mix(a_present_rect.xy, a_present_rect.zw, v_panel_uv); - } - v_effect = a_effect; - gl_Position = vec4(pos, 0.0, 1.0); -} diff --git a/shaders/prebuilt/overlay.frag.glsl b/shaders/prebuilt/overlay.frag.glsl deleted file mode 100644 index b5ac8d5a..00000000 --- a/shaders/prebuilt/overlay.frag.glsl +++ /dev/null @@ -1,17 +0,0 @@ -#version 450 - -layout(std140, set = 3, binding = 0) uniform UiUniforms { - float background_opacity; -} u_ui; - -layout(location = 0) in vec4 v_color; - -layout(location = 0) out vec4 o_col; - -void main() { - // Preserve shape coverage for destination subtraction. The pipeline uses - // the matching opacity blend constant for source alpha, so graphics laid - // over a background with the same opacity do not accumulate opaque seams. - // Text/cursor draw groups bind opacity 1 instead. - o_col = vec4(v_color.rgb * clamp(u_ui.background_opacity, 0.0, 1.0), v_color.a); -} diff --git a/shaders/prebuilt/overlay.vert.glsl b/shaders/prebuilt/overlay.vert.glsl deleted file mode 100644 index 5f6be593..00000000 --- a/shaders/prebuilt/overlay.vert.glsl +++ /dev/null @@ -1,11 +0,0 @@ -#version 450 - -layout(location = 0) in vec2 a_pos; -layout(location = 1) in vec4 a_color; - -layout(location = 0) out vec4 v_color; - -void main() { - v_color = a_color; - gl_Position = vec4(a_pos, 0.0, 1.0); -} diff --git a/shaders/prebuilt/post-bloom.frag.glsl b/shaders/prebuilt/post-bloom.frag.glsl deleted file mode 100644 index a84cf88a..00000000 --- a/shaders/prebuilt/post-bloom.frag.glsl +++ /dev/null @@ -1,141 +0,0 @@ -#version 450 -// pardes's Shadertoy prefix (docs/render-pipeline.md §6), put before every -// post pass: a bundled one in shaders/post/ at build time, a user's file at -// run time. The uniform names, types and std140 order are ghostty 1.3.2's -// (src/renderer/shaders/shadertoy_prefix.glsl), so a shader written for -// ghostty runs here; only the bindings are SDL GPU's (a fragment shader's -// textures in set 2, its uniform blocks in set 3). Y is down everywhere, as -// on ghostty's Metal renderer: fragCoord, iChannel0's uv and the cursor -// rectangles share one top-left space, and iCurrentCursor is (left x, -// BOTTOM-edge y, width, height) in framebuffer pixels. - -layout(set = 3, binding = 0, std140) uniform Globals { - uniform vec3 iResolution; - uniform float iTime; - uniform float iTimeDelta; - uniform float iFrameRate; - uniform int iFrame; - uniform float iChannelTime[4]; - uniform vec3 iChannelResolution[4]; - uniform vec4 iMouse; - uniform vec4 iDate; - uniform float iSampleRate; - uniform vec4 iCurrentCursor; - uniform vec4 iPreviousCursor; - uniform vec4 iCurrentCursorColor; - uniform vec4 iPreviousCursorColor; - uniform int iCurrentCursorStyle; - uniform int iPreviousCursorStyle; - uniform int iCursorVisible; - uniform float iTimeCursorChange; - uniform float iTimeFocus; - uniform int iFocus; -}; -// ghostty's one block, cut in three: SDL GPU binds at most 4 KiB of a -// uniform block (Vulkan), and the palette alone is 4 KiB. The names and -// their order are ghostty's; each block is a slice of the same memory. -layout(set = 3, binding = 1, std140) uniform Palette { - uniform vec3 iPalette[256]; -}; -layout(set = 3, binding = 2, std140) uniform Colors { - uniform vec3 iBackgroundColor; - uniform vec3 iForegroundColor; - uniform vec3 iCursorColor; - uniform vec3 iCursorText; - uniform vec3 iSelectionForegroundColor; - uniform vec3 iSelectionBackgroundColor; -}; - -// pardes's own: pardesOpaque is 1 when the window is opaque, so a pass -// cannot punch holes in it through its alpha; pardesLevel is a bundled -// pass's strength, 1 to 3 (`Crt 3`), and 0 for a user's file; pardesScale -// is the display's density (2 on a 2x screen), for a pass whose pattern is -// in logical pixels. iResolution, fragCoord and iMouse stay in the display's -// pixels, as ghostty's do. pardesCap is the most a bundled pass may do on -// this theme and still leave its text, and its selection's, at their own -// contrast or 4.5 (docs/effects.md); pardesSpare holds pardesSpareCount -// rectangles (x0, y0, x1, y1 in fragCoord's pixels) a bundled pass leaves -// alone: every tag, grip and notice, and the cursor, so no pass ever touches -// a focus indicator. -layout(set = 3, binding = 3, std140) uniform PardesPost { - float pardesOpaque; - float pardesLevel; - float pardesScale; - float pardesCap; - float pardesSpareCount; - vec4 pardesSpare[32]; -}; - -bool pardesSpared(vec2 p) { - for (int i = 0; i < int(pardesSpareCount); i++) { - vec4 r = pardesSpare[i]; - if (p.x >= r.x && p.y >= r.y && p.x < r.z && p.y < r.w) return true; - } - return false; -} - -// A bundled pass's constant at levels 1, 2 and 3. -float pardesByLevel(float one, float two, float three) { - return pardesLevel < 1.5 ? one : (pardesLevel < 2.5 ? two : three); -} - -#define CURSORSTYLE_BLOCK 0 -#define CURSORSTYLE_BLOCK_HOLLOW 1 -#define CURSORSTYLE_BAR 2 -#define CURSORSTYLE_UNDERLINE 3 -#define CURSORSTYLE_LOCK 4 - -layout(set = 2, binding = 0) uniform sampler2D iChannel0; - -layout(location = 0) out vec4 _fragColor; - -#define texture2D texture - -void mainImage(out vec4 fragColor, in vec2 fragCoord); -void main() { - mainImage(_fragColor, gl_FragCoord.xy); - if (pardesOpaque > 0.5) _fragColor.a = 1.0; -} - -// The shader's own lines count from 1, so glslc's errors name them. -#line 1 -// Bloom: the brightest ink glows, a little. The glow itself is made by the -// shell at half resolution and below (bloom-down, bloom-up: a dual Kawase -// filter over a bright pass, in linear light) and arrives here in -// pardesBloom; this pass adds it to the frame. Only true highlights pass -// the threshold, and the strength stays in §8.2's budget (at most 5%) and -// under pardesCap, so no text or selection loses contrast below its own or -// 4.5. Tags, grips, notices and the cursor are left alone (pardesSpare). -// It is a Shadertoy file: pardes puts its prefix before it. - -layout(set = 2, binding = 1) uniform sampler2D pardesBloom; - -float strength() { return min(pardesByLevel(0.02, 0.035, 0.05), pardesCap); } - -vec3 toLinear(vec3 c) { - return mix(pow((c + 0.055) / 1.055, vec3(2.4)), c / 12.92, lessThanEqual(c, vec3(0.04045))); -} - -vec3 toSrgb(vec3 c) { - c = max(c, vec3(0.0)); - return mix(1.055 * pow(c, vec3(1.0 / 2.4)) - 0.055, c * 12.92, lessThanEqual(c, vec3(0.0031308))); -} - -float ign(vec2 p) { - return fract(52.9829189 * fract(dot(p, vec2(0.06711056, 0.00583715)))); -} - -void mainImage(out vec4 fragColor, in vec2 fragCoord) { - vec2 uv = fragCoord / iResolution.xy; - vec4 frame = texture(iChannel0, uv); - if (pardesSpared(fragCoord)) { - fragColor = frame; - return; - } - vec3 glow = texture(pardesBloom, uv).rgb; - vec3 col = toLinear(frame.rgb) + glow * strength(); - vec3 srgb = toSrgb(col); - // Dithered: a glow's long falloff never bands. - srgb += (ign(fragCoord) - 0.5) / 255.0 * step(1e-4, dot(glow, vec3(1.0))); - fragColor = vec4(clamp(srgb, 0.0, 1.0), frame.a); -} diff --git a/shaders/prebuilt/post-crt.frag.glsl b/shaders/prebuilt/post-crt.frag.glsl deleted file mode 100644 index ca44d014..00000000 --- a/shaders/prebuilt/post-crt.frag.glsl +++ /dev/null @@ -1,186 +0,0 @@ -#version 450 -// pardes's Shadertoy prefix (docs/render-pipeline.md §6), put before every -// post pass: a bundled one in shaders/post/ at build time, a user's file at -// run time. The uniform names, types and std140 order are ghostty 1.3.2's -// (src/renderer/shaders/shadertoy_prefix.glsl), so a shader written for -// ghostty runs here; only the bindings are SDL GPU's (a fragment shader's -// textures in set 2, its uniform blocks in set 3). Y is down everywhere, as -// on ghostty's Metal renderer: fragCoord, iChannel0's uv and the cursor -// rectangles share one top-left space, and iCurrentCursor is (left x, -// BOTTOM-edge y, width, height) in framebuffer pixels. - -layout(set = 3, binding = 0, std140) uniform Globals { - uniform vec3 iResolution; - uniform float iTime; - uniform float iTimeDelta; - uniform float iFrameRate; - uniform int iFrame; - uniform float iChannelTime[4]; - uniform vec3 iChannelResolution[4]; - uniform vec4 iMouse; - uniform vec4 iDate; - uniform float iSampleRate; - uniform vec4 iCurrentCursor; - uniform vec4 iPreviousCursor; - uniform vec4 iCurrentCursorColor; - uniform vec4 iPreviousCursorColor; - uniform int iCurrentCursorStyle; - uniform int iPreviousCursorStyle; - uniform int iCursorVisible; - uniform float iTimeCursorChange; - uniform float iTimeFocus; - uniform int iFocus; -}; -// ghostty's one block, cut in three: SDL GPU binds at most 4 KiB of a -// uniform block (Vulkan), and the palette alone is 4 KiB. The names and -// their order are ghostty's; each block is a slice of the same memory. -layout(set = 3, binding = 1, std140) uniform Palette { - uniform vec3 iPalette[256]; -}; -layout(set = 3, binding = 2, std140) uniform Colors { - uniform vec3 iBackgroundColor; - uniform vec3 iForegroundColor; - uniform vec3 iCursorColor; - uniform vec3 iCursorText; - uniform vec3 iSelectionForegroundColor; - uniform vec3 iSelectionBackgroundColor; -}; - -// pardes's own: pardesOpaque is 1 when the window is opaque, so a pass -// cannot punch holes in it through its alpha; pardesLevel is a bundled -// pass's strength, 1 to 3 (`Crt 3`), and 0 for a user's file; pardesScale -// is the display's density (2 on a 2x screen), for a pass whose pattern is -// in logical pixels. iResolution, fragCoord and iMouse stay in the display's -// pixels, as ghostty's do. pardesCap is the most a bundled pass may do on -// this theme and still leave its text, and its selection's, at their own -// contrast or 4.5 (docs/effects.md); pardesSpare holds pardesSpareCount -// rectangles (x0, y0, x1, y1 in fragCoord's pixels) a bundled pass leaves -// alone: every tag, grip and notice, and the cursor, so no pass ever touches -// a focus indicator. -layout(set = 3, binding = 3, std140) uniform PardesPost { - float pardesOpaque; - float pardesLevel; - float pardesScale; - float pardesCap; - float pardesSpareCount; - vec4 pardesSpare[32]; -}; - -bool pardesSpared(vec2 p) { - for (int i = 0; i < int(pardesSpareCount); i++) { - vec4 r = pardesSpare[i]; - if (p.x >= r.x && p.y >= r.y && p.x < r.z && p.y < r.w) return true; - } - return false; -} - -// A bundled pass's constant at levels 1, 2 and 3. -float pardesByLevel(float one, float two, float three) { - return pardesLevel < 1.5 ? one : (pardesLevel < 2.5 ? two : three); -} - -#define CURSORSTYLE_BLOCK 0 -#define CURSORSTYLE_BLOCK_HOLLOW 1 -#define CURSORSTYLE_BAR 2 -#define CURSORSTYLE_UNDERLINE 3 -#define CURSORSTYLE_LOCK 4 - -layout(set = 2, binding = 0) uniform sampler2D iChannel0; - -layout(location = 0) out vec4 _fragColor; - -#define texture2D texture - -void mainImage(out vec4 fragColor, in vec2 fragCoord); -void main() { - mainImage(_fragColor, gl_FragCoord.xy); - if (pardesOpaque > 0.5) _fragColor.a = 1.0; -} - -// The shader's own lines count from 1, so glslc's errors name them. -#line 1 -// Crt: a slot-mask tube's light, with nothing that moves a pixel. There is -// no barrel: every click lands where it is drawn, rails and grips at the -// window's edges included. What is left is light: a beam profile for the -// scanlines, an aperture mask, a soft bloom of the brightest ink, a faint -// vignette and the hum of a live tube. Everything is worked out in linear -// light and dithered back into 8 bits, so the vignette never bands. It is a -// Shadertoy file: pardes puts its prefix before it (shaders/post/prefix.glsl). - -const float TAU = 6.28318530718; -// Level 3 glows wider and from dimmer ink. -float bloomRadiusPx() { return pardesByLevel(1.75, 1.75, 3.0); } -float bloomThreshold() { return pardesByLevel(0.6, 0.6, 0.3); } // linear-light channel peak -const float BLOOM_SOFTNESS = 0.25; -const float SCAN_PERIOD_PX = 3.0; -const float MASK_PERIOD_PX = 3.0; -const float HUM_HZ = 0.11; - -// Each strength at levels 1, 2 and 3 (`Crt 1`..`Crt 3`): 2 is the default, -// 3 as strong as the old barrel CRT looked. -float chromaPx() { return pardesByLevel(0.2, 0.35, 2.2); } // red and blue apart, at the corners -float bloomStrength() { return pardesByLevel(0.03, 0.05, 0.3); } -float scanStrength() { return pardesByLevel(0.035, 0.07, 0.42); } -float maskStrength() { return pardesByLevel(0.01, 0.018, 0.12); } -float vignetteStrength() { return pardesByLevel(0.06, 0.12, 0.42); } // at the far corners only -float humStrength() { return pardesByLevel(0.002, 0.004, 0.012); } -float exposure() { return pardesByLevel(1.008, 1.015, 1.1); } - -vec3 toLinear(vec3 c) { - return mix(pow((c + 0.055) / 1.055, vec3(2.4)), c / 12.92, lessThanEqual(c, vec3(0.04045))); -} - -vec3 toSrgb(vec3 c) { - c = max(c, vec3(0.0)); - return mix(1.055 * pow(c, vec3(1.0 / 2.4)) - 0.055, c * 12.92, lessThanEqual(c, vec3(0.0031308))); -} - -vec3 scene(vec2 uv) { - return toLinear(texture(iChannel0, uv).rgb); -} - -vec3 brightPass(vec2 uv) { - vec3 c = scene(uv); - float peak = max(c.r, max(c.g, c.b)); - return c * smoothstep(bloomThreshold(), bloomThreshold() + BLOOM_SOFTNESS, peak); -} - -// Interleaved gradient noise: a dither with no visible pattern. -float ign(vec2 p) { - return fract(52.9829189 * fract(dot(p, vec2(0.06711056, 0.00583715)))); -} - -void mainImage(out vec4 fragColor, in vec2 fragCoord) { - vec2 size = iResolution.xy; - vec2 texel = 1.0 / size; - vec2 uv = fragCoord / size; - vec2 cc = uv * 2.0 - 1.0; - float r2 = dot(cc, cc); - - // The beam converges least at the corners: red and blue drift apart - // there, by a third of a pixel. - vec2 chroma = cc * (chromaPx() * r2 * 0.5) * texel; - vec3 col = vec3(scene(uv + chroma).r, scene(uv).g, scene(uv - chroma).b); - - vec2 b = texel * bloomRadiusPx(); - vec3 bloom = brightPass(uv + vec2(b.x, 0.0)) + brightPass(uv - vec2(b.x, 0.0)) + - brightPass(uv + vec2(0.0, b.y)) + brightPass(uv - vec2(0.0, b.y)); - col += bloom * (0.25 * bloomStrength()); - - // A beam is brightest on its line and falls off between lines; the - // mask is three phosphor stripes a triad. Both average to one, so the - // theme keeps its brightness. - // Periods in logical pixels: the same look at any density. - float density = max(1.0, pardesScale); - float line = 0.5 + 0.5 * cos(fragCoord.y * TAU / (SCAN_PERIOD_PX * density)); - col *= 1.0 - scanStrength() * (line * line - 0.375) / 0.625; - col *= 1.0 + maskStrength() * cos(fragCoord.x * TAU / (MASK_PERIOD_PX * density) + vec3(0.0, TAU / 3.0, 2.0 * TAU / 3.0)); - - float vignette = 1.0 - vignetteStrength() * pow(clamp(r2 * 0.5, 0.0, 1.0), 1.6); - float hum = 1.0 + humStrength() * sin((uv.y * 1.35 - iTime * HUM_HZ) * TAU); - col *= vignette * hum * exposure(); - - vec3 srgb = toSrgb(col); - srgb += (ign(fragCoord + float(iFrame % 64) * vec2(5.588238, 5.588238)) - 0.5) / 255.0; - fragColor = vec4(clamp(srgb, 0.0, 1.0), texture(iChannel0, uv).a); -} diff --git a/shaders/prebuilt/post-grain.frag.glsl b/shaders/prebuilt/post-grain.frag.glsl deleted file mode 100644 index a4a02e99..00000000 --- a/shaders/prebuilt/post-grain.frag.glsl +++ /dev/null @@ -1,133 +0,0 @@ -#version 450 -// pardes's Shadertoy prefix (docs/render-pipeline.md §6), put before every -// post pass: a bundled one in shaders/post/ at build time, a user's file at -// run time. The uniform names, types and std140 order are ghostty 1.3.2's -// (src/renderer/shaders/shadertoy_prefix.glsl), so a shader written for -// ghostty runs here; only the bindings are SDL GPU's (a fragment shader's -// textures in set 2, its uniform blocks in set 3). Y is down everywhere, as -// on ghostty's Metal renderer: fragCoord, iChannel0's uv and the cursor -// rectangles share one top-left space, and iCurrentCursor is (left x, -// BOTTOM-edge y, width, height) in framebuffer pixels. - -layout(set = 3, binding = 0, std140) uniform Globals { - uniform vec3 iResolution; - uniform float iTime; - uniform float iTimeDelta; - uniform float iFrameRate; - uniform int iFrame; - uniform float iChannelTime[4]; - uniform vec3 iChannelResolution[4]; - uniform vec4 iMouse; - uniform vec4 iDate; - uniform float iSampleRate; - uniform vec4 iCurrentCursor; - uniform vec4 iPreviousCursor; - uniform vec4 iCurrentCursorColor; - uniform vec4 iPreviousCursorColor; - uniform int iCurrentCursorStyle; - uniform int iPreviousCursorStyle; - uniform int iCursorVisible; - uniform float iTimeCursorChange; - uniform float iTimeFocus; - uniform int iFocus; -}; -// ghostty's one block, cut in three: SDL GPU binds at most 4 KiB of a -// uniform block (Vulkan), and the palette alone is 4 KiB. The names and -// their order are ghostty's; each block is a slice of the same memory. -layout(set = 3, binding = 1, std140) uniform Palette { - uniform vec3 iPalette[256]; -}; -layout(set = 3, binding = 2, std140) uniform Colors { - uniform vec3 iBackgroundColor; - uniform vec3 iForegroundColor; - uniform vec3 iCursorColor; - uniform vec3 iCursorText; - uniform vec3 iSelectionForegroundColor; - uniform vec3 iSelectionBackgroundColor; -}; - -// pardes's own: pardesOpaque is 1 when the window is opaque, so a pass -// cannot punch holes in it through its alpha; pardesLevel is a bundled -// pass's strength, 1 to 3 (`Crt 3`), and 0 for a user's file; pardesScale -// is the display's density (2 on a 2x screen), for a pass whose pattern is -// in logical pixels. iResolution, fragCoord and iMouse stay in the display's -// pixels, as ghostty's do. pardesCap is the most a bundled pass may do on -// this theme and still leave its text, and its selection's, at their own -// contrast or 4.5 (docs/effects.md); pardesSpare holds pardesSpareCount -// rectangles (x0, y0, x1, y1 in fragCoord's pixels) a bundled pass leaves -// alone: every tag, grip and notice, and the cursor, so no pass ever touches -// a focus indicator. -layout(set = 3, binding = 3, std140) uniform PardesPost { - float pardesOpaque; - float pardesLevel; - float pardesScale; - float pardesCap; - float pardesSpareCount; - vec4 pardesSpare[32]; -}; - -bool pardesSpared(vec2 p) { - for (int i = 0; i < int(pardesSpareCount); i++) { - vec4 r = pardesSpare[i]; - if (p.x >= r.x && p.y >= r.y && p.x < r.z && p.y < r.w) return true; - } - return false; -} - -// A bundled pass's constant at levels 1, 2 and 3. -float pardesByLevel(float one, float two, float three) { - return pardesLevel < 1.5 ? one : (pardesLevel < 2.5 ? two : three); -} - -#define CURSORSTYLE_BLOCK 0 -#define CURSORSTYLE_BLOCK_HOLLOW 1 -#define CURSORSTYLE_BAR 2 -#define CURSORSTYLE_UNDERLINE 3 -#define CURSORSTYLE_LOCK 4 - -layout(set = 2, binding = 0) uniform sampler2D iChannel0; - -layout(location = 0) out vec4 _fragColor; - -#define texture2D texture - -void mainImage(out vec4 fragColor, in vec2 fragCoord); -void main() { - mainImage(_fragColor, gl_FragCoord.xy); - if (pardesOpaque > 0.5) _fragColor.a = 1.0; -} - -// The shader's own lines count from 1, so glslc's errors name them. -#line 1 -// Grain: the page's own ground takes a fine, still grain, like paper. Only -// pixels of the page's colour (iBackgroundColor) are grained: no glyph, no -// selection, no tag or rule, and nothing in pardesSpare. The grain averages -// to the page, is a logical pixel big (pardesScale), and never moves, so it -// costs no frames. At most 1.5, 3 and 5 of 255 at levels 1 to 3, and never -// more than pardesCap, which keeps the text on it at its own contrast or 4.5. -// It is a Shadertoy file: pardes puts its prefix before it. - -float amplitude() { return min(pardesByLevel(1.5, 3.0, 5.0) / 255.0, pardesCap); } - -// An integer hash of the grain cell: white, with no pattern to see. -float hash(uvec2 p) { - uint h = p.x * 1664525u + p.y * 1013904223u; - h ^= h >> 16; - h *= 2246822519u; - h ^= h >> 13; - h *= 3266489917u; - h ^= h >> 16; - return float(h) / 4294967295.0; -} - -void mainImage(out vec4 fragColor, in vec2 fragCoord) { - vec2 uv = fragCoord / iResolution.xy; - vec4 frame = texture(iChannel0, uv); - fragColor = frame; - vec3 page = iBackgroundColor.rgb; - if (any(greaterThan(abs(frame.rgb - page), vec3(0.75 / 255.0))) || pardesSpared(fragCoord)) return; - uvec2 cell = uvec2(fragCoord / max(1.0, pardesScale)); - // Two hashes summed: a triangular spread, softer than a flat one. - float n = hash(cell) + hash(cell + uvec2(7919u, 104729u)) - 1.0; - fragColor = vec4(clamp(page + n * amplitude(), 0.0, 1.0), frame.a); -} diff --git a/shaders/prebuilt/post-vignette.frag.glsl b/shaders/prebuilt/post-vignette.frag.glsl deleted file mode 100644 index d5737901..00000000 --- a/shaders/prebuilt/post-vignette.frag.glsl +++ /dev/null @@ -1,139 +0,0 @@ -#version 450 -// pardes's Shadertoy prefix (docs/render-pipeline.md §6), put before every -// post pass: a bundled one in shaders/post/ at build time, a user's file at -// run time. The uniform names, types and std140 order are ghostty 1.3.2's -// (src/renderer/shaders/shadertoy_prefix.glsl), so a shader written for -// ghostty runs here; only the bindings are SDL GPU's (a fragment shader's -// textures in set 2, its uniform blocks in set 3). Y is down everywhere, as -// on ghostty's Metal renderer: fragCoord, iChannel0's uv and the cursor -// rectangles share one top-left space, and iCurrentCursor is (left x, -// BOTTOM-edge y, width, height) in framebuffer pixels. - -layout(set = 3, binding = 0, std140) uniform Globals { - uniform vec3 iResolution; - uniform float iTime; - uniform float iTimeDelta; - uniform float iFrameRate; - uniform int iFrame; - uniform float iChannelTime[4]; - uniform vec3 iChannelResolution[4]; - uniform vec4 iMouse; - uniform vec4 iDate; - uniform float iSampleRate; - uniform vec4 iCurrentCursor; - uniform vec4 iPreviousCursor; - uniform vec4 iCurrentCursorColor; - uniform vec4 iPreviousCursorColor; - uniform int iCurrentCursorStyle; - uniform int iPreviousCursorStyle; - uniform int iCursorVisible; - uniform float iTimeCursorChange; - uniform float iTimeFocus; - uniform int iFocus; -}; -// ghostty's one block, cut in three: SDL GPU binds at most 4 KiB of a -// uniform block (Vulkan), and the palette alone is 4 KiB. The names and -// their order are ghostty's; each block is a slice of the same memory. -layout(set = 3, binding = 1, std140) uniform Palette { - uniform vec3 iPalette[256]; -}; -layout(set = 3, binding = 2, std140) uniform Colors { - uniform vec3 iBackgroundColor; - uniform vec3 iForegroundColor; - uniform vec3 iCursorColor; - uniform vec3 iCursorText; - uniform vec3 iSelectionForegroundColor; - uniform vec3 iSelectionBackgroundColor; -}; - -// pardes's own: pardesOpaque is 1 when the window is opaque, so a pass -// cannot punch holes in it through its alpha; pardesLevel is a bundled -// pass's strength, 1 to 3 (`Crt 3`), and 0 for a user's file; pardesScale -// is the display's density (2 on a 2x screen), for a pass whose pattern is -// in logical pixels. iResolution, fragCoord and iMouse stay in the display's -// pixels, as ghostty's do. pardesCap is the most a bundled pass may do on -// this theme and still leave its text, and its selection's, at their own -// contrast or 4.5 (docs/effects.md); pardesSpare holds pardesSpareCount -// rectangles (x0, y0, x1, y1 in fragCoord's pixels) a bundled pass leaves -// alone: every tag, grip and notice, and the cursor, so no pass ever touches -// a focus indicator. -layout(set = 3, binding = 3, std140) uniform PardesPost { - float pardesOpaque; - float pardesLevel; - float pardesScale; - float pardesCap; - float pardesSpareCount; - vec4 pardesSpare[32]; -}; - -bool pardesSpared(vec2 p) { - for (int i = 0; i < int(pardesSpareCount); i++) { - vec4 r = pardesSpare[i]; - if (p.x >= r.x && p.y >= r.y && p.x < r.z && p.y < r.w) return true; - } - return false; -} - -// A bundled pass's constant at levels 1, 2 and 3. -float pardesByLevel(float one, float two, float three) { - return pardesLevel < 1.5 ? one : (pardesLevel < 2.5 ? two : three); -} - -#define CURSORSTYLE_BLOCK 0 -#define CURSORSTYLE_BLOCK_HOLLOW 1 -#define CURSORSTYLE_BAR 2 -#define CURSORSTYLE_UNDERLINE 3 -#define CURSORSTYLE_LOCK 4 - -layout(set = 2, binding = 0) uniform sampler2D iChannel0; - -layout(location = 0) out vec4 _fragColor; - -#define texture2D texture - -void mainImage(out vec4 fragColor, in vec2 fragCoord); -void main() { - mainImage(_fragColor, gl_FragCoord.xy); - if (pardesOpaque > 0.5) _fragColor.a = 1.0; -} - -// The shader's own lines count from 1, so glslc's errors name them. -#line 1 -// Vignette: the window's corners fall a little into shade, in linear light, -// so the eye settles on the middle. Round, whatever the window's shape; -// nothing within half the way to a corner is touched. At most 28% at the -// far corners (level 3), and never more than pardesCap, so text and its -// selection keep their own contrast or 4.5. Tags, grips, notices and the -// cursor are left alone (pardesSpare): the focus indicators never darken. -// It is a Shadertoy file: pardes puts its prefix before it. - -float strength() { return min(pardesByLevel(0.10, 0.18, 0.28), pardesCap); } - -vec3 toLinear(vec3 c) { - return mix(pow((c + 0.055) / 1.055, vec3(2.4)), c / 12.92, lessThanEqual(c, vec3(0.04045))); -} - -vec3 toSrgb(vec3 c) { - c = max(c, vec3(0.0)); - return mix(1.055 * pow(c, vec3(1.0 / 2.4)) - 0.055, c * 12.92, lessThanEqual(c, vec3(0.0031308))); -} - -float ign(vec2 p) { - return fract(52.9829189 * fract(dot(p, vec2(0.06711056, 0.00583715)))); -} - -void mainImage(out vec4 fragColor, in vec2 fragCoord) { - vec2 uv = fragCoord / iResolution.xy; - vec4 frame = texture(iChannel0, uv); - if (pardesSpared(fragCoord)) { - fragColor = frame; - return; - } - // 0 at the middle, 1 at a corner, on a circle's measure. - vec2 half_size = 0.5 * iResolution.xy; - float r = length(fragCoord - half_size) / length(half_size); - float shade = strength() * pow(smoothstep(0.5, 1.0, r), 1.5); - vec3 srgb = toSrgb(toLinear(frame.rgb) * (1.0 - shade)); - srgb += (ign(fragCoord) - 0.5) / 255.0 * step(1e-4, shade); - fragColor = vec4(clamp(srgb, 0.0, 1.0), frame.a); -} diff --git a/shaders/prebuilt/post.vert.glsl b/shaders/prebuilt/post.vert.glsl deleted file mode 100644 index 86739a65..00000000 --- a/shaders/prebuilt/post.vert.glsl +++ /dev/null @@ -1,10 +0,0 @@ -#version 450 - -// A post pass (docs/render-pipeline.md §6): one fullscreen triangle from -// gl_VertexIndex, no vertex buffer. The Shadertoy fragment shader works from -// gl_FragCoord, y down, as its fragCoord. - -void main() { - vec2 p = vec2(float((gl_VertexIndex << 1) & 2), float(gl_VertexIndex & 2)); - gl_Position = vec4(p * 2.0 - 1.0, 0.0, 1.0); -} diff --git a/shaders/prebuilt/ui.frag.glsl b/shaders/prebuilt/ui.frag.glsl deleted file mode 100644 index 51ec5b8c..00000000 --- a/shaders/prebuilt/ui.frag.glsl +++ /dev/null @@ -1,93 +0,0 @@ -#version 450 - -// Sample the glyph atlas (R = coverage 0..1) and mix the cell's bg up to its fg -// by that coverage. Output is PREMULTIPLIED: an opaque cell is unchanged. -// WindowOpacity changes only the ground's coverage, never the glyph's ink. -// A cell whose background is the see-through ground (config.gui_transparent, -// a theme with no bg of its own) still contributes only its ink, at the ink's -// own coverage, so the compositor keeps the rest. - -layout(set = 2, binding = 0) uniform sampler2D u_atlas; -layout(std140, set = 3, binding = 0) uniform UiUniforms { - float background_opacity; - // A theme's ornament (colors.Decor): the page's dots (rgb, strength), - // their geometry (period, solid radius, faded radius, in pixels), and a - // file name's shadow (rgb, offset in pixels). - vec4 decor_dots; - vec4 decor_dot_geom; - vec4 decor_shadow; -} u_ui; - -layout(location = 0) in vec2 v_uv; -layout(location = 1) in vec3 v_fg; -layout(location = 2) in vec3 v_bg; -layout(location = 3) in vec2 v_cell_uv; -layout(location = 4) flat in uvec4 v_effect; -layout(location = 5) flat in vec4 v_clip; - -layout(location = 0) out vec4 o_col; - -void main() { - if (v_clip.z >= v_clip.x && (gl_FragCoord.x < v_clip.x || gl_FragCoord.x >= v_clip.z || - gl_FragCoord.y < v_clip.y || gl_FragCoord.y >= v_clip.w)) discard; - float a = texture(u_atlas, v_uv).r; - bool oldLayer = (v_effect.x & 0x80000000u) != 0u; - // A block cursor is foreground chrome even though its fill occupies the - // cell background: keep it visible at WindowOpacity 0. Otherwise a clear - // theme ground has no coverage and ordinary backgrounds use the setting. - // The three high flags are shared with ui.vert.glsl and src/gui/gui.zig. - float bgA = (v_effect.x & 0x20000000u) != 0u ? 1.0 - : (v_effect.x & 0x40000000u) != 0u ? 0.0 - : clamp(u_ui.background_opacity, 0.0, 1.0); - uint effect = v_effect.x & 0x07ffffffu; - float progress = clamp(uintBitsToFloat(v_effect.y), 0.0, 1.0); - - // Ink over ground, both premultiplied: v_fg*a + (v_bg*bgA)*(1-a), which is - // mix() with the ground already premultiplied. At bgA = 1 that is exactly - // the mix(v_bg, v_fg, a) at alpha 1 this shader always wrote. - vec3 ground = v_bg; - // 0x10000000: the page's ground under a pane body, dotted (lapis): a - // dot every period pixels, fixed to the window, under the text. - if ((v_effect.x & 0x10000000u) != 0u) { - float period = u_ui.decor_dot_geom.x; - // v_effect.z: how far its pane's text has moved the dots (G13's - // parallax), in pixels, as a float's bits (0 without). - vec2 at = gl_FragCoord.xy - vec2(0.0, uintBitsToFloat(v_effect.z)); - vec2 d = mod(at, period) - 0.5 * period; - float dot_a = 1.0 - smoothstep(u_ui.decor_dot_geom.y, u_ui.decor_dot_geom.z, length(d)); - ground = mix(ground, u_ui.decor_dots.rgb, u_ui.decor_dots.a * dot_a); - } - vec4 under = vec4(ground * bgA, bgA); - // Derivatives outside any branch: a pixel's step in the atlas and in - // the cell, for the shadow's offset. - vec2 step_uv = vec2(dFdx(v_uv.x), dFdy(v_uv.y)) * u_ui.decor_shadow.a; - vec2 step_cell = vec2(dFdx(v_cell_uv.x), dFdy(v_cell_uv.y)) * u_ui.decor_shadow.a; - // 0x08000000: a file name's letters cast a shadow down and right onto - // their own cell's ground (lapis), under the ink; what would fall past - // the cell's edge is not drawn. - if ((v_effect.x & 0x08000000u) != 0u) { - vec2 from = v_cell_uv - step_cell; - float s = all(greaterThanEqual(from, vec2(0.0))) ? texture(u_atlas, v_uv - step_uv).r : 0.0; - under = mix(under, vec4(u_ui.decor_shadow.rgb, 1.0), s); - } - vec4 cell = vec4(mix(under.rgb, v_fg, a), mix(under.a, 1.0, a)); - - // 3 = dissolve, a crossfade (G7): a changed cell's new form is drawn - // first, whole, and its frozen old one over it at 1 - progress, - // premultiplied (the frame's cells blend over, pipeline_over), so the - // old fades out as the new comes in; at the ends, exactly one of them. - // The tty keeps its per-cell swap (panel_animation.dissolveRevealed). - if (effect == 3u) { - if (!oldLayer) { - o_col = cell; - return; - } - if (progress >= 1.0) discard; - o_col = cell * (1.0 - progress); - return; - } - - // FreeType's hinted grayscale bitmap is already the intended coverage. - // Preserve it exactly; weight-changing gamma hacks blur small stems. - o_col = cell; -} diff --git a/shaders/prebuilt/ui.vert.glsl b/shaders/prebuilt/ui.vert.glsl deleted file mode 100644 index de22adee..00000000 --- a/shaders/prebuilt/ui.vert.glsl +++ /dev/null @@ -1,82 +0,0 @@ -#version 450 - -// Terminal cell renderer. The CPU uploads one instance per visible cell; this -// shader expands each instance into a two-triangle quad with gl_VertexIndex. -// The fragment shader mixes fg/bg by the atlas's alpha (a glyph mask in the R -// channel), so background fills and glyph foregrounds draw in a single pass. - -layout(location = 0) in vec4 a_rect; // x0, y0, x1, y1 -layout(location = 1) in vec4 a_uv_rect; // u0, v0, u1, v1 -layout(location = 2) in vec3 a_fg; -layout(location = 3) in vec3 a_bg; -// Final and presented panel rectangles in NDC. The CPU still uploads logical -// final cells; this shader is the only place transition geometry is applied. -layout(location = 4) in vec4 a_panel_rect; -layout(location = 5) in vec4 a_present_rect; -// effect id, eased-progress float bits, pane serial, local row/column packed -// into one uint. The FIVE high effect bits are flags — the frozen-old cell -// layer, a see-through cell background, an opaque block-cursor fill, a soft -// shadow (decor.frag.glsl) or dotted page ground (ui.frag.glsl), and a -// checker (decor) or a file name's shadow (ui) — so the id is what is left -// below them; integer transport preserves the exact -// cross-backend hash. -layout(location = 6) in uvec4 a_effect; -// A clip rectangle in target pixels (x0, y0, x1, y1): the fragment shader -// drops what lies outside it. x1 < x0 is none. A vertical transition clips -// its pane's instances to the box the pane is growing into. -layout(location = 7) in vec4 a_clip; - -layout(location = 0) out vec2 v_uv; -layout(location = 1) out vec3 v_fg; -layout(location = 2) out vec3 v_bg; -layout(location = 3) out vec2 v_cell_uv; -layout(location = 4) flat out uvec4 v_effect; -layout(location = 5) flat out vec4 v_clip; - -void main() { - vec2 pos; - vec2 uv; - int corner = gl_VertexIndex % 6; - if (corner == 0) { - pos = vec2(a_rect.x, a_rect.y); - uv = vec2(a_uv_rect.x, a_uv_rect.y); - v_cell_uv = vec2(0.0, 0.0); - } else if (corner == 1) { - pos = vec2(a_rect.z, a_rect.y); - uv = vec2(a_uv_rect.z, a_uv_rect.y); - v_cell_uv = vec2(1.0, 0.0); - } else if (corner == 2) { - pos = vec2(a_rect.z, a_rect.w); - uv = vec2(a_uv_rect.z, a_uv_rect.w); - v_cell_uv = vec2(1.0, 1.0); - } else if (corner == 3) { - pos = vec2(a_rect.x, a_rect.y); - uv = vec2(a_uv_rect.x, a_uv_rect.y); - v_cell_uv = vec2(0.0, 0.0); - } else if (corner == 4) { - pos = vec2(a_rect.z, a_rect.w); - uv = vec2(a_uv_rect.z, a_uv_rect.w); - v_cell_uv = vec2(1.0, 1.0); - } else { - pos = vec2(a_rect.x, a_rect.w); - uv = vec2(a_uv_rect.x, a_uv_rect.w); - v_cell_uv = vec2(0.0, 1.0); - } - - uint effect = a_effect.x & 0x07ffffffu; - if (effect == 1u || effect == 2u || effect == 5u) { - // NDC y points up, so a top-left/bottom-right box has a NEGATIVE y - // delta. Preserve that sign or every local y is mirrored/outside. - vec2 panel_size = a_panel_rect.zw - a_panel_rect.xy; - panel_size.x = abs(panel_size.x) < 0.000001 ? 0.000001 : panel_size.x; - panel_size.y = abs(panel_size.y) < 0.000001 ? -0.000001 : panel_size.y; - vec2 within = (pos - a_panel_rect.xy) / panel_size; - pos = mix(a_present_rect.xy, a_present_rect.zw, within); - } - v_uv = uv; - v_fg = a_fg; - v_bg = a_bg; - v_effect = a_effect; - v_clip = a_clip; - gl_Position = vec4(pos, 0.0, 1.0); -} diff --git a/src/Output.zig b/src/Output.zig index fb8fe7a3..8cf57591 100644 --- a/src/Output.zig +++ b/src/Output.zig @@ -19,7 +19,6 @@ const Pane = panes.Pane; const File = panes.File; const Builtin = builtins.registry.Builtin(); -const gui_shader_source_mode = effect_sources.guiShaderSourceMode(); const fonts = if (builtins.capabilities.font_picker) @import("fonts.zig") else struct {}; @@ -825,10 +824,6 @@ pub fn openConfig(p: *Pardes, id: usize) !void { .platform = @tagName(pardes.platform), .theme_name = p.theme().name, .compiled_default_shell = config.defaultShell(), - .gui_shader_source_mode = if (gui_shader_source_mode) |mode| - mode.label() - else - null, .hover_delay_frames = config.look_preview_delay_frames, .native_images = p.native_images, .capabilities = builtins.capabilities, @@ -882,8 +877,6 @@ pub fn openEffectCode(p: *Pardes, id: usize, argument: []const u8) !void { var out: std.Io.Writer.Allocating = .init(p.gpa); errdefer out.deinit(); try out.writer.print("EffectCode {s} ({s})\n", .{ setting.word, @tagName(effect_sources.backend) }); - if (gui_shader_source_mode) |mode| - try out.writer.print("GUI shader source: {s}\n", .{mode.label()}); try out.writer.writeByte('\n'); for (paths) |path| try out.writer.print("/virtual/{s}\n", .{path}); const content = try out.toOwnedSlice(); diff --git a/src/config.zig b/src/config.zig index ea7a877a..a8b4c24e 100644 --- a/src/config.zig +++ b/src/config.zig @@ -1267,7 +1267,6 @@ pub const Runtime = struct { platform: []const u8, theme_name: []const u8, compiled_default_shell: []const u8, - gui_shader_source_mode: ?[]const u8 = null, hover_delay_frames: ?u16, /// Where dumps go when `DumpDir` is unset; empty without a host /// filesystem. @@ -1436,8 +1435,6 @@ pub const Runtime = struct { "Default shell ($SHELL, else /bin/sh): {s}\n", .{ context.platform, context.compiled_default_shell }, ); - if (context.gui_shader_source_mode) |mode| - try out.print("GUI shader source: {s}\n", .{mode}); if (context.hover_delay_frames) |frames| try out.print("Look hover delay: {d} frames\n", .{frames}) else @@ -1662,7 +1659,6 @@ pub const Runtime = struct { .platform = "gui", .theme_name = "acme", .compiled_default_shell = "/bin/sh", - .gui_shader_source_mode = "live GLSL compiled during this build", .hover_delay_frames = 18, .native_images = true, .capabilities = .{ @@ -1801,7 +1797,6 @@ pub const Runtime = struct { "Startup config: /tmp/pardes/init\n", "Platform: gui\n", "Default shell ($SHELL, else /bin/sh): /bin/sh\n", - "GUI shader source: live GLSL compiled during this build\n", "Look hover delay: 18 frames\n", "Native images: on\n", }) |expected| try std.testing.expect(std.mem.indexOf(u8, report, expected) != null); @@ -1810,7 +1805,6 @@ pub const Runtime = struct { var defaults_context = context; defaults_context.startup_config_path = null; defaults_context.platform = "tty"; - defaults_context.gui_shader_source_mode = null; defaults_context.hover_delay_frames = null; defaults_context.native_images = false; defaults_context.capabilities = .{ @@ -1832,7 +1826,6 @@ pub const Runtime = struct { try std.testing.expect(std.mem.indexOf(u8, defaults_report, "Shell effective (last spawn) (none)\n") != null); try std.testing.expect(std.mem.indexOf(u8, defaults_report, "Shell pending on\n") != null); try std.testing.expect(std.mem.indexOf(u8, defaults_report, "Startup config: no per-user config path\n") != null); - try std.testing.expect(std.mem.indexOf(u8, defaults_report, "GUI shader source:") == null); try std.testing.expect(std.mem.indexOf(u8, defaults_report, "Font unsupported\n") != null); try std.testing.expect(std.mem.indexOf(u8, defaults_report, "Font requested") == null); try std.testing.expect(std.mem.indexOf(u8, defaults_report, "Panel transition off\n") != null); diff --git a/src/effect_sources.zig b/src/effect_sources.zig index 328ce730..f45bf293 100644 --- a/src/effect_sources.zig +++ b/src/effect_sources.zig @@ -3,10 +3,7 @@ const build_config = @import("pardes_config"); const config = @import("config.zig"); const filesystem = @import("fs.zig"); -const shader_dir = if (build_config.gui_shader_sources_prebuilt) - "shaders/prebuilt/" -else - "shaders/"; +const shader_dir = "shaders/"; const ui_vertex_path = shader_dir ++ "ui.vert.glsl"; const ui_fragment_path = shader_dir ++ "ui.frag.glsl"; const image_vertex_path = shader_dir ++ "image.vert.glsl"; @@ -23,28 +20,6 @@ const bloom_up_path = shader_dir ++ "bloom-up.frag.glsl"; pub const Backend = @TypeOf(build_config.platform); pub const backend: Backend = build_config.platform; -pub const GuiShaderSourceMode = enum { - live, - prebuilt_snapshot, - - pub fn label(mode: GuiShaderSourceMode) []const u8 { - return switch (mode) { - .live => "live GLSL compiled during this build", - .prebuilt_snapshot => "paired GLSL snapshot for committed SPIR-V", - }; - } -}; - -/// Only the SDL backend consumes GLSL/SPIR-V. Other backends deliberately have -/// no shader-source mode rather than being mislabeled "live" or "prebuilt". -pub fn guiShaderSourceMode() ?GuiShaderSourceMode { - if (backend != .gui) return null; - return if (build_config.gui_shader_sources_prebuilt) - .prebuilt_snapshot - else - .live; -} - pub const files = switch (backend) { .tty => [_]filesystem.Source{ .{ .path = "src/tty/panel_compositor.zig", .contents = @embedFile("tty/panel_compositor.zig") }, @@ -123,14 +98,3 @@ test "EffectCode paths resolve uniquely to this backend's archived inputs" { try std.testing.expectEqual(backend == .gui, filesystem.sourceBytes("src/gui/gui.zig") != null); try std.testing.expectEqual(backend == .macos, filesystem.sourceBytes("src/macos/Sources/PardesView.swift") != null); } - -test "shader source provenance is GUI-only and follows the build input" { - if (comptime backend == .gui) { - const expected: GuiShaderSourceMode = if (build_config.gui_shader_sources_prebuilt) - .prebuilt_snapshot - else - .live; - try std.testing.expectEqual(expected, guiShaderSourceMode().?); - try std.testing.expect(expected.label().len > 0); - } else try std.testing.expect(guiShaderSourceMode() == null); -} diff --git a/test/output.zig b/test/output.zig index 1b1b80c9..3a11b101 100644 --- a/test/output.zig +++ b/test/output.zig @@ -591,10 +591,7 @@ test "EffectCode lists readable virtual sources used by this backend" { try std.testing.expect(std.mem.indexOf(u8, out.content, "/virtual/src/layout.zig\n") != null); const backend_source = switch (platform) { .tty => "/virtual/src/tty/panel_compositor.zig", - .gui => if (@import("pardes_config").gui_shader_sources_prebuilt) - "/virtual/shaders/prebuilt/ui.vert.glsl" - else - "/virtual/shaders/ui.vert.glsl", + .gui => "/virtual/shaders/ui.vert.glsl", .macos => "/virtual/src/macos/Sources/ScenePostprocessor.swift", .web, .esp32p4 => unreachable, }; -- cgit v1.3 From f0e162d287f44a562ff79e7c1d2cf81ace00c836 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 29 Sep 2026 22:48:21 -0300 Subject: Dumps and init files from before 0.0.4 load no more of their old tag formats, and three orphan test scripts go A2: a restored pane's tag tail comes from the dump's tag_tail, which every dump since 0.0.4 writes; the 27 earlier default tails that were recognised to upgrade, restoreTail, tailClass, savedPrefix and restoreTailAt, pdf_view's and image's legacySavedPrefix, a terminal's TTY tag prefix and its raw output tail replay, and the ThemeSel, FontSel and ColumnTags words (init lines and dumped output names) go, with their tests; the CHANGELOG says so. A4: test/fs_soak.py, referenced nowhere (monkey9p.py does its work). A6: test/column_grip.py and test/look_placement.py, referenced nowhere; the six review scripts docs/ui-review.md names stay. Co-Authored-By: Claude Opus 5.5 --- src/CHANGELOG.md | 8 ++ src/Output.zig | 3 - src/dump.zig | 1 - src/exec.zig | 50 +-------- src/image.zig | 8 -- src/pardes.zig | 159 +-------------------------- src/pdf_view.zig | 18 ---- src/tagline.zig | 135 +---------------------- src/terminal.zig | 33 +----- test/column_grip.py | 132 ----------------------- test/fs_soak.py | 284 ------------------------------------------------- test/look_placement.py | 143 ------------------------- test/panes.zig | 22 ---- test/pdf.zig | 1 + 14 files changed, 16 insertions(+), 981 deletions(-) delete mode 100644 test/column_grip.py delete mode 100644 test/fs_soak.py delete mode 100644 test/look_placement.py (limited to 'src/Output.zig') diff --git a/src/CHANGELOG.md b/src/CHANGELOG.md index 50149551..a2f493df 100644 --- a/src/CHANGELOG.md +++ b/src/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog +## Unreleased + +- Dumps and init files from before 0.0.4 no longer load their old tag + formats: a restored pane's tag tail is read only from `tag_tail`, and an old + terminal's `TTY` tag or raw output tail is not replayed. `ThemeSel`, + `FontSel` and `ColumnTags` are no longer recognised in init files or dumps + (`Themes` and `Fonts` are the words). + ## 0.0.5 - Over a slow link the terminal build keeps at most one frame in flight: it diff --git a/src/Output.zig b/src/Output.zig index 8cf57591..5bc1f9fc 100644 --- a/src/Output.zig +++ b/src/Output.zig @@ -262,9 +262,6 @@ pub fn fromWord(w: []const u8) ?Origin { if (std.mem.eql(u8, w, config.errors_buffer)) return .errors; if (std.mem.eql(u8, w, config.pdf_links_buffer)) return .pdf_links; if (std.mem.eql(u8, w, config.unsaved_buffer)) return .unsaved; - // A dump from before the rename names them by their old words. - if (std.mem.eql(u8, w, "ThemeSel")) return .{ .cmd = .Themes }; - if (builtins.capabilities.font_picker) if (std.mem.eql(u8, w, "FontSel")) return .{ .cmd = .Fonts }; if (std.meta.stringToEnum(Builtin, w)) |b| if (builtins.registry.outputTraits(b) != null) return .{ .cmd = b }; if (std.meta.stringToEnum(lsp.Kind, w)) |k| return .{ .query = k }; diff --git a/src/dump.zig b/src/dump.zig index 78c2bd7a..2d3c2593 100644 --- a/src/dump.zig +++ b/src/dump.zig @@ -905,7 +905,6 @@ fn initDump(gpa: std.mem.Allocator, opts: Options, zon_bytes: []const u8, previo restored.command_done = true; restored.command_status = t.status; } - if (std.mem.startsWith(u8, src.tag, "TTY ")) restored.body.mode = .tty; if (revive) p.emitSpawn(i, restored.serial, t.cwd); break :terminal restored; }, diff --git a/src/exec.zig b/src/exec.zig index 221de105..8c062f66 100644 --- a/src/exec.zig +++ b/src/exec.zig @@ -870,58 +870,10 @@ pub fn applyStartupConfig(p: *Pardes) void { defer p.announce = true; var lines = std.mem.splitScalar(u8, p.opts.startup_config orelse return, '\n'); while (lines.next()) |line| { - if (executeBuiltinLine(p, p.active, line)) continue; - // A setting pardes no longer has is said, once, and changes nothing. - const word = commandText(line); - const head = word[0 .. std.mem.indexOfAny(u8, word, " \t") orelse word.len]; - if (std.mem.eql(u8, head, "ColumnTags")) - p.setMessage(p.active, "ColumnTags: column tags are always shown now; the init line is ignored"); - // A word renamed runs as its new name, and says so, once a line. - for ([_][2][]const u8{ .{ "ThemeSel", "Themes" }, .{ "FontSel", "Fonts" } }) |renamed| if (std.mem.eql(u8, head, renamed[0])) { - _ = executeBuiltinLine(p, p.active, renamed[1]); - var said: [64]u8 = undefined; - p.setMessage(p.active, std.fmt.bufPrint(&said, "{s}: renamed to {s}", .{ renamed[0], renamed[1] }) catch "renamed"); - }; + _ = executeBuiltinLine(p, p.active, line); } } -test "an init file's ThemeSel runs as Themes and says it was renamed" { - const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 80, .rows = 24, .startup_config = "ThemeSel\n" }); - defer p.deinit(); - var listed = false; - for (p.panes) |slot| if (slot) |pane| if (pane.file) |f| if (f.output) |o| { - listed = listed or std.meta.eql(o.from, panes.Output.Origin{ .cmd = .Themes }); - }; - try std.testing.expect(listed); - // In the session's directory, not `/`. - for (p.panes) |slot| if (slot) |pane| if (pane.file) |f| if (f.output != null) - try std.testing.expectEqualStrings(p.sessionDir(), std.fs.path.dirname(f.path).?); - var said = false; - for (p.panes) |slot| if (slot) |pane| { - said = said or std.mem.eql(u8, pane.msg[0..pane.msg_len], "ThemeSel: renamed to Themes"); - }; - try std.testing.expect(said); - // The panes there at boot are the log's first records, before what the - // init file said. - const th = @import("ninep/testing.zig"); - const log = @intFromEnum(pardes.ctlfs.TopFile.log); - const h = th.call(p, .{ .tag = 1, .op = .open, .node = log }).reply.handle; - defer _ = th.call(p, .{ .tag = 3, .op = .release, .node = log, .handle = h }); - const text = th.call(p, .{ .tag = 2, .op = .read, .node = log, .handle = h, .size = 1 << 16 }).bytes; - try std.testing.expectStringStartsWith(text, "new "); -} - -test "an init file's retired ColumnTags line is said and ignored" { - const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 80, .rows = 24 }); - defer p.deinit(); - p.opts.startup_config = "ColumnTags\nWrap off\n"; - applyStartupConfig(p); - try std.testing.expect(!p.settings.wrap); - try std.testing.expect(p.columnBarHeight() > 0); - const pane = p.panes[p.active].?; - try std.testing.expectEqualStrings("ColumnTags: column tags are always shown now; the init line is ignored", pane.msg[0..pane.msg_len]); -} - pub fn runBuiltin(p: *Pardes, b: Builtin, id: usize, txt: []const u8, arg: ?[]const u8) void { runBuiltinFrom(p, b, id, txt, arg, false); } diff --git a/src/image.zig b/src/image.zig index 7b081ec6..936fe19a 100644 --- a/src/image.zig +++ b/src/image.zig @@ -916,14 +916,6 @@ pub fn tagPrefix(arena: std.mem.Allocator, state: *const State) ![]u8 { ); } -pub fn legacySavedPrefix(state: *const State, saved_tag: []const u8) ?[]const u8 { - const lead = config.tag_image ++ " "; - if (!std.mem.startsWith(u8, saved_tag, lead)) return null; - const path_at = lead.len; - if (!std.mem.startsWith(u8, saved_tag[path_at..], state.path)) return null; - return saved_tag[0 .. path_at + state.path.len]; -} - fn ensureDecoded(p: *pardes.Pardes, state: *State) void { if (state.tried) return; state.tried = true; diff --git a/src/pardes.zig b/src/pardes.zig index 3ecc80ae..151fe7b0 100644 --- a/src/pardes.zig +++ b/src/pardes.zig @@ -751,13 +751,6 @@ test "Collapse builtin keeps content and restores the pane from its default tag" p.sync(); try std.testing.expect(!pane.collapsed); try std.testing.expectEqual(height, p.rects[0].h); - - // Unedited defaults from the preceding version gain the new command. - if (pane.tag.own) |own| p.gpa.free(own); - pane.tag.own = null; - tagline.restoreTailAt(p, pane, tagline.pre_collapse_file_pane_tail, "", .file); - try std.testing.expect(pane.tag.own == null); - try std.testing.expectEqualStrings(tagline.file_pane_tail, tagline.curTail(pane)); } test "LocationsConfig command reports partial updates and survives restore" { @@ -985,129 +978,6 @@ test "compact tag commands stay beside their own prefix across layout changes" { try std.testing.expectEqualStrings(above_tag, try tagline.tagText(p, p.scratch.allocator(), above)); } -test "legacy default tag tails upgrade while custom tails remain owned" { - const gpa = std.testing.allocator; - const p = try Pardes.init(gpa, .{}); - defer p.deinit(); - - const terminal = p.panes[0].?; - const terminal_old = try std.fmt.allocPrint(p.scratch.allocator(), "{s}{s}", .{ - try tagline.tagPrefix(p, terminal), - tagline.legacy_pane_tail, - }); - tagline.restoreTail(p, terminal, terminal_old); - try std.testing.expect(terminal.tag.own == null); - try std.testing.expectEqualStrings(tagline.terminal_pane_tail, tagline.curTail(terminal)); - - const terminal_previous = try std.fmt.allocPrint(p.scratch.allocator(), "{s} New Del", .{ - try tagline.tagPrefix(p, terminal), - }); - tagline.restoreTail(p, terminal, terminal_previous); - try std.testing.expect(terminal.tag.own == null); - try std.testing.expectEqualStrings(tagline.terminal_pane_tail, tagline.curTail(terminal)); - - const terminal_prefilter = try std.fmt.allocPrint(p.scratch.allocator(), "{s}{s}", .{ - try tagline.tagPrefix(p, terminal), - tagline.prev_terminal_pane_tail, - }); - tagline.restoreTail(p, terminal, terminal_prefilter); - try std.testing.expect(terminal.tag.own == null); - try std.testing.expectEqualStrings(tagline.terminal_pane_tail, tagline.curTail(terminal)); - - for ([_][]const u8{ tagline.pre_mode_terminal_pane_tail, tagline.pre_tty_first_terminal_pane_tail, tagline.pre_collapse_terminal_pane_tail }) |old_tail| { - const old = try std.fmt.allocPrint(p.scratch.allocator(), "{s}{s}", .{ try tagline.tagPrefix(p, terminal), old_tail }); - tagline.restoreTail(p, terminal, old); - try std.testing.expect(terminal.tag.own == null); - try std.testing.expectEqualStrings(tagline.terminal_pane_tail, tagline.curTail(terminal)); - } - const custom_mode = try std.fmt.allocPrint(p.scratch.allocator(), "{s}{s} Keep", .{ try tagline.tagPrefix(p, terminal), tagline.pre_mode_terminal_pane_tail }); - tagline.restoreTail(p, terminal, custom_mode); - try std.testing.expect(terminal.tag.own != null); - try std.testing.expectEqualStrings(tagline.pre_mode_terminal_pane_tail ++ " Keep", tagline.curTail(terminal)); - - if (terminal.tag.own) |own| p.gpa.free(own); - terminal.tag.own = null; - const terminal_custom = try std.fmt.allocPrint(p.scratch.allocator(), "{s} Keep Del", .{ - try tagline.tagPrefix(p, terminal), - }); - tagline.restoreTail(p, terminal, terminal_custom); - try std.testing.expect(terminal.tag.own != null); - try std.testing.expectEqualStrings(" Keep Del", tagline.curTail(terminal)); - - if (terminal.tag.own) |own| p.gpa.free(own); - terminal.tag.own = null; - tagline.restoreDumpTail(p, terminal, .{ - .kind = .terminal, - .tag = "TTY /historical/cwd Keep Del", - .body = "", - .terminal = .{ .cwd = "/historical/cwd" }, - }); - try std.testing.expect(terminal.tag.own != null); - try std.testing.expectEqualStrings(" Keep Del", tagline.curTail(terminal)); - - if (terminal.tag.own) |own| p.gpa.free(own); - terminal.tag.own = null; - tagline.restoreDumpTail(p, terminal, .{ - .kind = .terminal, - .tag = "TTY /historical/cwd New Del", - .body = "", - .terminal = .{ .cwd = "/historical/cwd" }, - }); - try std.testing.expect(terminal.tag.own == null); - try std.testing.expectEqualStrings(tagline.terminal_pane_tail, tagline.curTail(terminal)); - - // This happens to be the historical FILE default, but on a terminal it is - // user-owned text and must not be swallowed by migration. - if (terminal.tag.own) |own| p.gpa.free(own); - terminal.tag.own = null; - const terminal_fileish = try std.fmt.allocPrint(p.scratch.allocator(), "{s} Save Del", .{ - try tagline.tagPrefix(p, terminal), - }); - tagline.restoreTail(p, terminal, terminal_fileish); - try std.testing.expect(terminal.tag.own != null); - try std.testing.expectEqualStrings(" Save Del", tagline.curTail(terminal)); - - // A savable file has a distinct old default. Save remains first after the - // migration so the tag's established `:w` route is unchanged. - const file = try p.setTestFile(""); - const file_old = try std.fmt.allocPrint(p.scratch.allocator(), "{s}{s}", .{ - try tagline.tagPrefix(p, file), - tagline.legacy_file_pane_tail, - }); - tagline.restoreTail(p, file, file_old); - try std.testing.expect(file.tag.own == null); - try std.testing.expectEqualStrings(" Save Tty Collapse Del", tagline.curTail(file)); - - const file_custom = try std.fmt.allocPrint(p.scratch.allocator(), "{s} Save Mine Del", .{ - try tagline.tagPrefix(p, file), - }); - tagline.restoreTail(p, file, file_custom); - try std.testing.expect(file.tag.own != null); - try std.testing.expectEqualStrings(" Save Mine Del", tagline.curTail(file)); - - // Conversely the generic pane's current default is a custom edit on a - // savable file. Legacy recognition is scoped to the source pane class. - if (file.tag.own) |own| p.gpa.free(own); - file.tag.own = null; - const file_generic = try std.fmt.allocPrint(p.scratch.allocator(), "{s} New Del", .{ - try tagline.tagPrefix(p, file), - }); - tagline.restoreTail(p, file, file_generic); - try std.testing.expect(file.tag.own != null); - try std.testing.expectEqualStrings(" New Del", tagline.curTail(file)); - - const image_doc = try panes.Image.create(p, 1, "/tmp/legacy image.ppm", &.{}); - try std.testing.expectEqualStrings(" Tty Collapse Del", tagline.curTail(image_doc)); - tagline.restoreDumpTail(p, image_doc, .{ - .kind = .image, - .tag = "img /tmp/legacy image.ppm Keep Del", - .body = "", - .image = .{ .path = "/tmp/legacy image.ppm" }, - }); - try std.testing.expect(image_doc.tag.own != null); - try std.testing.expectEqualStrings(" Keep Del", tagline.curTail(image_doc)); -} - test "Joincol folds the active column into its right neighbor, keeping its panes" { const gpa = std.testing.allocator; const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 100, .rows = 30 }); @@ -1434,14 +1304,6 @@ test "pane defaults keep creation of scratch panes in column tags" { while (words.next()) |word| try std.testing.expect(!std.mem.eql(u8, word, "New")); } try std.testing.expectEqualStrings("New Tty Find Grep Joincol Delcol", tagline.columnTag(p, 0)); - const terminal = p.panes[0].?; - tagline.restoreTailAt(p, terminal, tagline.pre_column_terminal_pane_tail, "", .terminal); - try std.testing.expect(terminal.tag.own == null); - try std.testing.expectEqualStrings(tagline.terminal_pane_tail, tagline.curTail(terminal)); - const file = try p.setTestFile("unchanged\n"); - tagline.restoreTailAt(p, file, tagline.pre_column_file_pane_tail, "", .file); - try std.testing.expect(file.tag.own == null); - try std.testing.expectEqualStrings(tagline.file_pane_tail, tagline.curTail(file)); } test "an unsaved file's tag is its name alone: the grip, not a mark, says it is unsaved" { @@ -2640,27 +2502,8 @@ test "Save reaches every tagline with text behind it and no other" { out.file.?.output = .{ .from = .search }; try std.testing.expectEqualStrings(tagline.locations_pane_tail, tagline.curTail(out)); - // A dump written before Save reached output buffers carries the generic - // tail. That is a DEFAULT and not something typed, so it upgrades. - const dumped = try std.fmt.allocPrint(p.scratch.allocator(), "{s}{s}", .{ - try tagline.tagPrefix(p, out), - tagline.pane_tail, - }); - tagline.restoreTail(p, out, dumped); - try std.testing.expect(out.tag.own == null); - try std.testing.expectEqualStrings(tagline.locations_pane_tail, tagline.curTail(out)); - - // A scratch is an output buffer that has worn the FILE tails all along, - // so its own older default upgrades from that family too. + // A scratch is an output buffer that wears the FILE tails. out.file.?.output = .{ .from = .{ .cmd = std.meta.stringToEnum(Builtin, "New").? } }; - if (out.tag.own) |own| p.gpa.free(own); - out.tag.own = null; - const scratch_dumped = try std.fmt.allocPrint(p.scratch.allocator(), "{s}{s}", .{ - try tagline.tagPrefix(p, out), - tagline.prev_file_pane_tail, - }); - tagline.restoreTail(p, out, scratch_dumped); - try std.testing.expect(out.tag.own == null); try std.testing.expectEqualStrings(" Save Tty Collapse Del", tagline.curTail(out)); // An image's bytes on disk already are what they are: nothing of the diff --git a/src/pdf_view.zig b/src/pdf_view.zig index 8f842cde..5646a92f 100644 --- a/src/pdf_view.zig +++ b/src/pdf_view.zig @@ -57,24 +57,6 @@ pub const RasterPolicy = struct { match_viewport: bool, }; -pub fn legacySavedPrefix(path: []const u8, saved_tag: []const u8) ?[]const u8 { - if (std.mem.startsWith(u8, saved_tag, path) and std.mem.startsWith(u8, saved_tag[path.len..], " [")) { - const start = path.len + 2; - const end = std.mem.indexOfScalarPos(u8, saved_tag, start, ']') orelse return null; - var parts = std.mem.splitScalar(u8, saved_tag[start..end], '/'); - _ = std.fmt.parseInt(usize, parts.next() orelse return null, 10) catch return null; - _ = std.fmt.parseInt(usize, parts.next() orelse return null, 10) catch return null; - if (parts.next() != null) return null; - return saved_tag[0 .. end + 1]; - } - if (!std.mem.startsWith(u8, saved_tag, "pdf ")) return null; - const marker = " PdfSections "; - const marker_at = std.mem.indexOf(u8, saved_tag, marker) orelse return null; - const path_at = marker_at + marker.len; - if (!std.mem.startsWith(u8, saved_tag[path_at..], path)) return null; - return saved_tag[0 .. path_at + path.len]; -} - pub const TintKey = if (enabled) struct { mode: TintMode, colors: pdf.TintColors, diff --git a/src/tagline.zig b/src/tagline.zig index df093925..1923871a 100644 --- a/src/tagline.zig +++ b/src/tagline.zig @@ -23,43 +23,11 @@ pub const context_pane_tail = file_pane_tail ++ " TreeContext"; pub const locations_pane_tail = file_pane_tail ++ " LocationsConfig"; pub const terminal_pane_tail = " " ++ config.terminal_pane_builtins_str; pub const command_pane_tail = " " ++ config.command_pane_builtins_str; -/// The mark a tag carried after an unsaved file's name before the grip -/// showed it; a dump from then still has it in its saved tags. -const dirty_marker = " *"; - /// A file with changes it has not saved. pub fn dirty(pane: *const panes.Pane) bool { const f = pane.file orelse return false; return panes.Output.fileTraits(f.output).saves and (f.revision != f.saved_revision or f.disk_gone); } -pub const legacy_pane_tail = " Del"; -pub const legacy_file_pane_tail = " Save Del"; -// The defaults from the release before Newtty joined every tagline. Recognized -// so a dump written then upgrades instead of keeping the old word as a tail. -const prev_pane_tail = " New Del"; -pub const prev_file_pane_tail = " Save New Del"; -const legacy_terminal_pane_tail = " New Del Filter"; -// ...and the terminal default from the release before Save reached it, when a -// scrollback was not yet something you could write to a path. -pub const prev_terminal_pane_tail = " New Newtty Del Filter"; -const pre_tty_terminal_pane_tail = " Save New Newtty Del Filter"; -const pre_column_pane_tail = " New Newtty Del"; -pub const pre_column_file_pane_tail = " Save New Newtty Del"; -const pre_column_pdf_pane_tail = " New Newtty Del PdfSections PdfTint"; -pub const pre_column_terminal_pane_tail = " Save New Newtty Del Tty Filter"; -const pre_collapse_pane_tail = " Tty Del"; -pub const pre_collapse_file_pane_tail = " Save Tty Del"; -const pre_collapse_pdf_pane_tail = " Tty Del PdfSections PdfTint"; -pub const pre_collapse_terminal_pane_tail = " Save Tty Del Togglettymode Filter"; -pub const pre_tty_first_terminal_pane_tail = " Save Tty Del Togglettymode Filter Collapse"; -pub const pre_mode_terminal_pane_tail = " Tty Save Del Togglettymode Filter Collapse"; -// ...and the defaults from before the closing word moved to the end of every -// tagline, where a click cannot land on it by overshooting the one before. -const pre_close_last_pane_tail = " Tty Del Collapse"; -const pre_close_last_file_pane_tail = " Save Tty Del Collapse"; -const pre_close_last_pdf_pane_tail = " Tty Del PdfSections PdfTint Collapse"; -const pre_close_last_terminal_pane_tail = " Tty Save Del Mode Filter Collapse"; - /// What a column's tag says until someone edits it. pub const column_tag_default = "New Tty Find Grep Joincol Delcol"; @@ -420,106 +388,11 @@ pub fn enterHeader(p: *Pardes, column: ?usize) void { t.normal.clear(); } +/// A dump's tag tail, what was typed after the name: a dump from 0.0.4 on +/// writes it, and an older one's saved tag is not read. pub fn restoreDumpTail(p: *Pardes, pane: *Pane, src: dump.Pane) void { - if (src.tag_tail) |tail| { - pane.tag.own = p.gpa.dupe(u8, tail) catch return; - return; - } - const tail_class = tailClass(pane); - if (src.kind == .image and panes.Pdf.isPath(src.image.?.path)) { - if (panes.Pdf.legacySavedPrefix(src.image.?.path, src.tag)) |prefix| - return restoreTailAt(p, pane, src.tag, prefix, .generic); - } - if (src.kind == .terminal and std.mem.startsWith(u8, src.tag, "TTY ")) { - const legacy = std.fmt.allocPrint(p.scratch.allocator(), "TTY {s}", .{src.terminal.?.cwd}) catch return; - if (std.mem.startsWith(u8, src.tag, legacy)) - return restoreTailAt(p, pane, src.tag, legacy, .terminal); - } - const current = tagPrefix(p, pane) catch return; - if (std.mem.startsWith(u8, src.tag, current)) - return restoreTailAt(p, pane, src.tag, savedPrefix(src.tag, current, tail_class), tail_class); - if (src.kind != .image) return; - const saved = src.image.?; - if (pane.image) |*state| if (panes.Image.legacySavedPrefix(state, src.tag)) |legacy| - return restoreTailAt(p, pane, src.tag, legacy, .generic); - if (panes.Pdf.isPath(saved.path)) if (panes.Pdf.legacySavedPrefix(saved.path, src.tag)) |legacy| - restoreTailAt(p, pane, src.tag, legacy, .generic); -} - -pub fn restoreTail(p: *Pardes, pane: *Pane, saved_tag: []const u8) void { - const pfx = tagPrefix(p, pane) catch return; - const class = tailClass(pane); - restoreTailAt(p, pane, saved_tag, savedPrefix(saved_tag, pfx, class), class); -} - -const TailClass = enum { generic, file, output, terminal }; - -fn tailClass(pane: *const Pane) TailClass { - if (pane.file) |f| return if (f.output == null) .file else .output; - if (pane.isTerminal()) return .terminal; - return .generic; -} - -fn savedPrefix(saved_tag: []const u8, live: []const u8, class: TailClass) []const u8 { - if (class == .generic or class == .terminal) return live; - if (!std.mem.startsWith(u8, saved_tag, live)) return live; - const marked_len = live.len + dirty_marker.len; - if (saved_tag.len >= marked_len and std.mem.eql(u8, saved_tag[live.len..marked_len], dirty_marker)) - return saved_tag[0..marked_len]; - return live; -} - -pub fn restoreTailAt( - p: *Pardes, - pane: *Pane, - saved_tag: []const u8, - pfx: []const u8, - class: TailClass, -) void { - if (!std.mem.startsWith(u8, saved_tag, pfx)) return; - const rest = saved_tag[pfx.len..]; - const said = std.mem.trimStart(u8, rest, " "); - const defaults: []const []const u8 = switch (class) { - .generic => &.{ pdf_pane_tail, pane_tail, pre_close_last_pdf_pane_tail, pre_close_last_pane_tail, pre_collapse_pdf_pane_tail, pre_collapse_pane_tail, pre_column_pdf_pane_tail, pre_column_pane_tail, prev_pane_tail, legacy_pane_tail }, - .file => &.{ context_pane_tail, file_pane_tail, pre_close_last_file_pane_tail, pre_collapse_file_pane_tail, pre_column_file_pane_tail, prev_file_pane_tail, legacy_file_pane_tail }, - .output => &.{ - locations_pane_tail, - file_pane_tail, - pre_close_last_file_pane_tail, - pre_close_last_pane_tail, - prev_file_pane_tail, - legacy_file_pane_tail, - pane_tail, - prev_pane_tail, - legacy_pane_tail, - pre_column_file_pane_tail, - pre_column_pane_tail, - pre_collapse_file_pane_tail, - pre_collapse_pane_tail, - }, - .terminal => &.{ terminal_pane_tail, pre_close_last_terminal_pane_tail, pre_close_last_pane_tail, pre_mode_terminal_pane_tail, pre_tty_first_terminal_pane_tail, pre_collapse_terminal_pane_tail, pre_column_terminal_pane_tail, pre_tty_terminal_pane_tail, prev_terminal_pane_tail, legacy_terminal_pane_tail, pane_tail, pre_collapse_pane_tail, pre_column_pane_tail, prev_pane_tail, legacy_pane_tail }, - }; - // A terminal's saved tag carries what was live about it -- the REPL id - // after its directory, the shell in its Tty word -- which is neither - // dumped nor true of the new shell: its tail is still the default. - var plain = said; - var plain_buf: [256]u8 = undefined; - if (class == .terminal) { - const first = plain[0 .. std.mem.indexOfScalar(u8, plain, ' ') orelse plain.len]; - if (std.mem.lastIndexOfScalar(u8, first, '-')) |dash| if (dash + 2 == first.len and first[dash + 1] >= 'a' and first[dash + 1] <= 'z') { - for (@import("grammar_manifest.zig").all) |g| if (std.mem.eql(u8, g.name, first[0..dash])) { - plain = std.mem.trimStart(u8, plain[first.len..], " "); - break; - }; - }; - if (std.mem.startsWith(u8, plain, "Tty+")) { - const word_end = std.mem.indexOfScalar(u8, plain, ' ') orelse plain.len; - plain = std.fmt.bufPrint(&plain_buf, "Tty{s}", .{plain[word_end..]}) catch plain; - } - } - for (defaults) |default| - if (std.mem.eql(u8, plain, std.mem.trimStart(u8, default, " "))) return; - pane.tag.own = p.gpa.dupe(u8, rest) catch return; + const tail = src.tag_tail orelse return; + pane.tag.own = p.gpa.dupe(u8, tail) catch return; } /// The span a header's selection covers on line `row` of its text, in diff --git a/src/terminal.zig b/src/terminal.zig index c99a92a6..6bf46bef 100644 --- a/src/terminal.zig +++ b/src/terminal.zig @@ -509,13 +509,7 @@ pub fn restore(p: *Pardes, src: dump.Pane, live: bool) !*Pane { pane.ovl = .{ .row = 0, .rows = 1, .text = try p.gpa.dupe(u8, terminal.stream) }; return pane; } - // An older dump's raw output tail cannot come back live: cut off mid - // redraw, or written at sizes the pane no longer has, it replays as - // garbage. Its rendered text can. - const legacy_text = live and !terminal.stream_is_screen and terminal.stream.len > 0; - const bytes = if (legacy_text) - try std.mem.replaceOwned(u8, p.scratch.allocator(), terminal.stream, "\n", "\r\n") - else if (terminal.stream_b64.len > 0) + const bytes = if (terminal.stream_b64.len > 0) try dump.decodeBytes(p.scratch.allocator(), terminal.stream_b64) else &.{}; @@ -759,31 +753,6 @@ test "a restored terminal keeps its history above a marker and gets a shell wher try std.testing.expect(old_at < mark_at); } -test "an older dump comes back live from its rendered text, not its raw output tail" { - if (comptime !enabled) return error.SkipZigTest; - const gpa = std.testing.allocator; - const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 40, .rows = 12 }); - defer p.deinit(); - // A tail cut mid-redraw: relative moves from a cursor it never set. - const tail = try dump.encodeBytes(gpa, "\x1b[7A\x1b[2Kgarbage\x1b[3B\x1b[9Gmore"); - defer gpa.free(tail); - const restored = try restore(p, .{ - .kind = .terminal, - .tag = "", - .body = "", - .cols = 40, - .rows = 12, - .terminal = .{ .stream = "$ ls\na.txt b.txt\n$ ", .stream_b64 = tail }, - }, true); - defer gpa.destroy(restored); - defer deinitEmulator(restored, gpa); - defer deinitPendingCommand(restored); - const text = try screenTextAlloc(restored, gpa); - defer gpa.free(text); - try std.testing.expect(std.mem.indexOf(u8, text, "$ ls\na.txt b.txt") != null); - try std.testing.expect(std.mem.indexOf(u8, text, "garbage") == null); -} - /// Record and parse one live pty read, invalidate its motion surface, and /// follow it only when the body (possibly parked under a tag edit) is raw. pub fn feedOutput(p: *Pardes, pane: *Pane, bytes: []const u8) void { diff --git a/test/column_grip.py b/test/column_grip.py deleted file mode 100644 index ac0341c3..00000000 --- a/test/column_grip.py +++ /dev/null @@ -1,132 +0,0 @@ -#!/usr/bin/env python3 -"""Drag a column grip in the real SDL window with pixel mouse events. - -WAYLAND_DISPLAY=/run/user/1000/wayland-1 \\ - python3 -B test/column_grip.py zig-out/bin/pardes-gui /tmp/pardes-column-grip [--pad 7] - -The window is hidden (PARDES_TEST). Mouse events enter as ESC]777;mouse -sequences on stdin, which the GUI builds into SDL events and dispatches like -its own, so pixel-to-cell and tag hit testing run as they do under a hand. -9P observes the grid; each step leaves a PNG of the GPU frame in the output -directory: grip-rest, grip-resize-drag, grip-reorder-drag, grip-done. -""" -import argparse -import os -from pathlib import Path -import shutil -import subprocess -import time - -from fs import session -from ui_review import require, wait_for - - -def rows(client): - frame = client.screen() - cols = frame['cols'] - return [''.join(cell[0] for cell in frame['cells'][at:at + cols]) for at in range(0, len(frame['cells']), cols)] - - -def rail(client): - """The one column the drag preview's rail runs down, if any.""" - bottom = rows(client)[-1] - found = [x for x, ch in enumerate(bottom) if ch == '╎'] - require(len(found) <= 1, f'more than one rail: {found}') - return found[0] if found else None - - -def grab(root, label): - time.sleep(.5) - def convert(): - shutil.copyfile(root / 'latest.ppm', root / (label + '.ppm')) - return subprocess.run(['magick', str(root / (label + '.ppm')), str(root / (label + '.png'))], - stderr=subprocess.DEVNULL).returncode == 0 - require(wait_for(convert, 8), 'GPU capture did not contain a complete image') - return root / (label + '.png') - - -def pixel(path, x, y): - out = subprocess.run(['magick', str(path), '-format', f'%[pixel:p{{{x},{y}}}]', 'info:'], - capture_output=True, text=True, check=True) - return out.stdout.strip() - - -def run(args): - root = args.output.resolve() - shutil.rmtree(root, ignore_errors=True) - root.mkdir(parents=True, mode=0o700) - (root / 'config/pardes').mkdir(parents=True) - (root / 'config/pardes/init').write_text('Shell /bin/sh\n') - (root / 'w.txt').write_text('alpha\nbeta\n') - name = 'column-grip-' + str(os.getpid()) - launch = ['-c', 'stty cols 100 rows 30; exec "$@"', 'column-grip', - str(args.binary.resolve()), '--9p=' + name, str(root / 'w.txt')] - env = {'PARDES_TEST': '1', 'PARDES_TEST_CAPTURE_DIR': str(root), 'PARDES_TEST_COLS': '100', - 'PARDES_TEST_ROWS': '30', 'PARDES_TEST_PAD': str(args.pad)} - handles = {} - with session('/bin/sh', root, name, socket_name=name, tty=True, launch=launch, - inherited=env, terminal=handles) as (client, _): - def send(data): - os.write(handles['input_fd'], data.encode()) - - def mouse(kind, button, col, row): - # the middle of a grid cell, in window pixels - send(f'\x1b]777;mouse;{kind};{button};{(col + .5) * cw};{(row + .5) * ch}\x07') - time.sleep(.15) - - require(wait_for(lambda: 'Newcol' in rows(client)[0]), 'workspace tag never drew') - send('\x1bn') - time.sleep(.3) - send('\x1bc') - require(wait_for(lambda: rows(client)[1].count('New Tty') == 2), 'no second column') - require(wait_for(lambda: (root / 'latest.ppm').exists(), 8), 'GPU capture missing') - time.sleep(.5) - with open(root / 'latest.ppm', 'rb') as ppm: - ppm.readline() - width, height = map(int, ppm.readline().split()) - frame = client.screen() - cw = (width - args.pad) // frame['cols'] - ch = (height - args.pad) // frame['rows'] - edge = rows(client)[1].index('New Tty', 10) - 3 - - rest = grab(root, 'grip-rest') - mouse('down', 1, edge, 1) - held = grab(root, 'grip-held') - require(pixel(held, int((edge + 1) * cw), int(1.5 * ch)) != pixel(rest, int((edge + 1) * cw), int(1.5 * ch)), - 'a grabbed grip looks the same as a resting one') - require(rail(client) is None, 'a grip held in place previews a move') - - # Short of the left column's middle: the left edge follows, and the - # rail is the seam cell left of where the rule will be. - for col in range(edge, edge - 11, -1): - mouse('motion', 1, col, 1) - require(rail(client) == edge - 11, f'resize rail at {rail(client)}, wanted {edge - 11}') - grab(root, 'grip-resize-drag') - mouse('up', 1, edge - 10, 1) - require(wait_for(lambda: rows(client)[1].index('New Tty', 10) - 3 == edge - 10), 'left edge did not follow the grip') - edge -= 10 - - # Over the left column's left half: it goes first, and the rail runs - # just past the left window edge's scroll rail. - mouse('down', 1, edge, 1) - for col in range(edge, 4, -5): - mouse('motion', 1, col, 10) - require(rail(client) == 1, f'reorder rail at {rail(client)}, wanted 1') - grab(root, 'grip-reorder-drag') - mouse('up', 1, 5, 10) - require(wait_for(lambda: 'alpha' in rows(client)[3][50:]), 'the column did not move first') - require(rail(client) is None, 'the rail outlived the drag') - grab(root, 'grip-done') - print('ok', root) - - -def main(): - parser = argparse.ArgumentParser() - parser.add_argument('binary', type=Path) - parser.add_argument('output', type=Path) - parser.add_argument('--pad', type=int, default=0, help='leftover pixels past the grid (PARDES_TEST_PAD)') - run(parser.parse_args()) - - -if __name__ == '__main__': - main() diff --git a/test/fs_soak.py b/test/fs_soak.py deleted file mode 100644 index a62f03e6..00000000 --- a/test/fs_soak.py +++ /dev/null @@ -1,284 +0,0 @@ -#!/usr/bin/env python3 -import argparse -import json -import os -from pathlib import Path -import random -import socket -import struct -import tempfile -import time - -from fs import new_pane, session -from ninep import Client - - -BODY_LIMIT = 4096 -SCREEN_LIMIT = 4 * 1024 * 1024 -FRAGMENTS = [ - b'const value = 42;\n', b'fn check() void { if (true) return; }\n', - b'\tspaces and tabs\n', 'λ 界 e\u0301 👩\u200d🚀\n'.encode(), b'x', -] -OPERATIONS = ['append', 'range', 'replace', 'read', 'save', 'reload', - 'cycle', 'reconnect', 'screen'] - - -def emit(**record): - print(json.dumps(record, separators=(',', ':')), flush=True) - - -def payload(rng, limit=256): - result = bytearray() - for _ in range(rng.randint(1, 12)): - fragment = rng.choice(FRAGMENTS) - if len(result) + len(fragment) <= limit: - result.extend(fragment) - return bytes(result) or b'x'[:limit] - - -def check_bytes(actual, expected, label): - if actual == expected: - return - at = next((i for i, pair in enumerate(zip(actual, expected)) - if pair[0] != pair[1]), min(len(actual), len(expected))) - raise AssertionError(f'{label}: mismatch at byte {at}; ' - f'length {len(actual)} != {len(expected)}; ' - f'{actual[at:at + 32]!r} != {expected[at:at + 32]!r}') - - -def read_fid(client, fid, limit, count): - result = bytearray() - while chunk := client.read_fid(fid, len(result), count): - result.extend(chunk) - if len(result) > limit: - raise AssertionError(f'read exceeded fixture limit {limit}') - return bytes(result) - - -def check_body(client, pane, count=4096): - fid = client.open(f'/pane/{pane["serial"]}/body') - try: - actual = read_fid(client, fid, BODY_LIMIT, count) - finally: - client.close(fid) - check_bytes(actual, pane['body'], f'pane {pane["serial"]}') - - -def check_screen(data): - screen = json.loads(data) - cols, rows = screen['cols'], screen['rows'] - assert cols > 0 and rows > 0 and cols * rows <= 65536, (cols, rows) - assert len(screen['cells']) == cols * rows - styles = screen['styles'] - assert styles - for cell in screen['cells']: - assert len(cell) == 2 and isinstance(cell[0], str), cell - assert isinstance(cell[1], int) and 0 <= cell[1] < len(styles), cell - - -def session_pid(client): - if not hasattr(socket, 'SO_PEERCRED'): - return None - pid, uid, _ = struct.unpack('3i', client.socket.getsockopt( - socket.SOL_SOCKET, socket.SO_PEERCRED, struct.calcsize('3i'))) - assert pid > 0 and uid == os.getuid(), (pid, uid) - return pid - - -def check_session(client, control, pid): - assert session_pid(control) == pid - if pid is not None: - actual = (session_pid(client) if client.socket.family == socket.AF_UNIX - else int(client.read('/os/proc/self/stat').split()[0])) - assert actual == pid, (actual, pid) - - -def memory(pid): - result = {'rss_bytes': None, 'cumulative_peak_rss_bytes': None} - if pid is None: - return result - try: - for line in Path(f'/proc/{pid}/status').read_text().splitlines(): - fields = line.split() - if fields[0] == 'VmRSS:': - result['rss_bytes'] = int(fields[1]) * 1024 - elif fields[0] == 'VmHWM:': - result['cumulative_peak_rss_bytes'] = int(fields[1]) * 1024 - except OSError: - pass - return result - - -def run(args): - rng = random.Random(args.seed) - started = time.monotonic() - deadline = None - batch = 0 - operation = 'start' - operation_count = 0 - pid = None - try: - with tempfile.TemporaryDirectory(prefix='pardes-soak-') as directory: - root = Path(directory) - options = ['--9p-tcp=tcp!127.0.0.1!0'] if args.transport == 'tcp' else [] - with session(str(args.binary.resolve()), root, 'soak', *options, - tty=args.tty) as (control, unix_address): - pid = session_pid(control) - address = unix_address - if args.transport == 'tcp': - listeners = [line.split('!') for line in - control.read('/listeners').decode().splitlines() - if line.startswith('tcp!')] - assert len(listeners) == 1, listeners - transport, host, port = listeners[0] - assert transport == 'tcp' and host == '127.0.0.1' and 0 < int(port) < 65536, listeners - address = (host, int(port)) - client = Client(address) - panes = [] - try: - check_session(client, control, pid) - for slot in range(4): - body = payload(rng) - serial = 1 if slot == 0 else new_pane(client, body) - base = f'/pane/{serial}' - if slot == 0: - client.write(base + '/body', body, truncate=True) - path = root / f'pane-{slot}-0.zig' - client.write(base + '/name', f'{path}\n'.encode()) - client.write(base + '/exec', b'Save\n') - panes.append({'serial': serial, 'body': body, 'path': path, 'variant': 0}) - emit(kind='start', seed=args.seed, session_pid=pid, - transport=args.transport, host='tty' if args.tty else 'detached', - batches=args.batches, duration_seconds=args.duration, - interval_seconds=args.interval, body_limit_bytes=BODY_LIMIT, - live_panes=len(panes), **memory(pid)) - if args.duration is not None: - deadline = time.monotonic() + args.duration - while (args.batches is None or batch < args.batches) and ( - deadline is None or time.monotonic() < deadline): - batch_started = time.monotonic() - operations = OPERATIONS * 2 - rng.shuffle(operations) - for operation in operations: - slot = rng.randrange(len(panes)) - pane = panes[slot] - base = f'/pane/{pane["serial"]}' - if operation == 'append': - addition = payload(rng, min(256, BODY_LIMIT - len(pane['body']))) - client.write(base + '/body', addition) - pane['body'] += addition - elif operation == 'range': - body = pane['body'] - # Keep range endpoints outside combining and ZWJ clusters. - boundaries = [0] + [i for i in range(1, len(body)) - if body[i - 1] < 128 and body[i] < 128] + [len(body)] - lo, hi = sorted((rng.choice(boundaries), rng.choice(boundaries))) - replacement = payload(rng, min(256, BODY_LIMIT - len(body) + hi - lo)) - if replacement: - client.write(base + '/addr', f'#{lo},#{hi}'.encode()) - client.write(base + '/data', replacement) - pane['body'] = body[:lo] + replacement + body[hi:] - elif operation == 'replace': - pane['body'] = payload(rng, BODY_LIMIT) - client.write(base + '/body', pane['body'], truncate=True) - elif operation == 'read': - check_body(client, pane, rng.choice([97, 251, 1024, 4096])) - elif operation == 'save': - pane['variant'] ^= 1 - pane['path'] = root / f'pane-{slot}-{pane["variant"]}.zig' - client.write(base + '/name', f'{pane["path"]}\n'.encode()) - client.write(base + '/exec', b'Save\n') - check_bytes(pane['path'].read_bytes(), pane['body'], 'saved file') - check_bytes(client.read('/os' + str(pane['path'])), pane['body'], 'OS mount') - elif operation == 'reload': - pane['body'] = payload(rng) - pane['path'].write_bytes(pane['body']) - client.write(base + '/ctl', b'get\n') - elif operation == 'cycle': - old_serial = pane['serial'] - client.remove(base) - pane['body'] = payload(rng) - pane['serial'] = new_pane(client, pane['body']) - assert pane['serial'] != old_serial - base = f'/pane/{pane["serial"]}' - client.write(base + '/name', f'{pane["path"]}\n'.encode()) - client.write(base + '/exec', b'Save\n') - elif operation == 'reconnect': - client.socket.close() - client = Client(address) - check_session(client, control, pid) - check_body(control, pane) - elif operation == 'screen': - frozen = client.open('/screen') - try: - before = read_fid(client, frozen, SCREEN_LIMIT, 4096) - check_screen(before) - addition = payload(rng, min(64, BODY_LIMIT - len(pane['body']))) - client.write(base + '/body', addition) - pane['body'] += addition - after = read_fid(client, frozen, SCREEN_LIMIT, rng.choice([251, 1024])) - check_bytes(after, before, 'frozen screen') - finally: - client.close(frozen) - fresh = client.open('/screen') - try: - check_screen(read_fid(client, fresh, SCREEN_LIMIT, 4096)) - finally: - client.close(fresh) - operation_count += 1 - check_body(client, pane) - expected = {str(pane['serial']) for pane in panes} - assert set(client.list('/pane')) == expected - assert set(control.list('/pane')) == expected - for pane in panes: - check_body(client, pane) - check_body(control, pane) - batch += 1 - emit(kind='batch', seed=args.seed, batch=batch, - duration_seconds=time.monotonic() - batch_started, - elapsed_seconds=time.monotonic() - started, - operations=len(operations), total_operations=operation_count, - model_bytes=sum(len(pane['body']) for pane in panes), **memory(pid)) - delay = args.interval - (time.monotonic() - batch_started) - if deadline is not None: - delay = min(delay, deadline - time.monotonic()) - if delay > 0: - time.sleep(delay) - finally: - client.socket.close() - emit(kind='summary', seed=args.seed, batches=batch, - transport=args.transport, host='tty' if args.tty else 'detached', - operations=operation_count, duration_seconds=time.monotonic() - started, - status='passed') - except BaseException as error: - emit(kind='failure', seed=args.seed, batch=batch + 1, operation=operation, - transport=args.transport, host='tty' if args.tty else 'detached', - operations=operation_count, session_pid=pid, - elapsed_seconds=time.monotonic() - started, error=str(error)) - raise - - -def main(): - parser = argparse.ArgumentParser(description='Deterministic valid-operation editor/9P soak; writes JSONL.') - parser.add_argument('binary', type=Path) - parser.add_argument('--seed', type=int, default=4200) - parser.add_argument('--transport', choices=['unix', 'tcp'], default='unix') - parser.add_argument('--tty', action='store_true', help='run an owned TTY host instead of a detached host') - limit = parser.add_mutually_exclusive_group() - limit.add_argument('--batches', type=int) - limit.add_argument('--duration', type=float, help='seconds, stopping after the current batch') - parser.add_argument('--interval', type=float, default=0, help='minimum seconds between batch starts') - args = parser.parse_args() - if args.batches is None and args.duration is None: - args.batches = 100 - if args.batches is not None and args.batches < 1: - parser.error('--batches must be positive') - if args.duration is not None and not 0 < args.duration < float('inf'): - parser.error('--duration must be finite and positive') - if not 0 <= args.interval < float('inf'): - parser.error('--interval must be finite and nonnegative') - run(args) - - -if __name__ == '__main__': - main() diff --git a/test/look_placement.py b/test/look_placement.py deleted file mode 100644 index 8a31157f..00000000 --- a/test/look_placement.py +++ /dev/null @@ -1,143 +0,0 @@ -#!/usr/bin/env python3 -"""Check narrow-window first-document Look placement in owned SDL/TTY sessions. - -python3 -B test/look_placement.py zig-out/column-review/bin/pardes-gui -python3 -B test/look_placement.py zig-out/column-review/bin/pardes --tty - -Starts the classic three-terminal layout, then opens the first document from -the lower-left or right terminal. Screen-grid geometry must split only that -terminal, immediately below it, and a repeated Look must reuse the file pane. -Use --output DIR to retain grid observations and SDL GPU screenshots. -""" -import argparse -from contextlib import nullcontext -from pathlib import Path -import tempfile - -from fs import session -from ui_review import capture, panes, require, wait_for - - -def geometry(client, markers): - frame = client.screen() - width = frame['cols'] - lines = [''.join(cell[0] for cell in frame['cells'][row * width:(row + 1) * width]) - for row in range(frame['rows'])] - positions = {} - for serial, marker in markers.items(): - hits = [(row, line.index(marker)) for row, line in enumerate(lines) if marker in line] - if len(hits) != 1: - return None - row, offset = hits[0] - column_x = 0 if offset < width // 2 else width // 2 - positions[serial] = (column_x, row) - rectangles = {} - for serial, (column_x, row) in positions.items(): - following = [other_y for other_x, other_y in positions.values() - if other_x == column_x and other_y > row] - end = min(following, default=frame['rows']) - rectangles[serial] = (column_x, row, width // 2, end - row) - return frame, rectangles - - -def rectangle_text(frame, rect): - x, y, width, height = rect - return tuple(tuple(cell[0] for cell in frame['cells'][row * frame['cols'] + x: - row * frame['cols'] + x + width]) - for row in range(y, y + height)) - - -def run_case(args, root, source_index): - root.mkdir(parents=True, exist_ok=True, mode=0o700) - root.chmod(0o700) - config = root / 'config/pardes' - config.mkdir(parents=True) - (config / 'init').write_text('Shell /bin/sh\nTheme forge\n') - target = root / 'opened.txt' - contents = b'First document opened from this terminal.\n' * 40 - target.write_bytes(contents) - name = 'look-placement' - inherited = {} if args.tty else { - 'PARDES_TEST': '1', 'PARDES_TEST_COLS': '150', 'PARDES_TEST_ROWS': '48', - 'PARDES_TEST_CAPTURE_DIR': str(root), 'SDL_VIDEODRIVER': 'x11', - } - # No document argument: the regression concerns the very first document. - launch = ['-c', 'stty cols 150 rows 48; exec "$@"', name, - str(args.binary.resolve()), '--9p=' + name, '-n', '3'] - with session('/bin/sh', root, name, socket_name=name, tty=True, - launch=launch, inherited=inherited) as (client, _): - serials = list(panes(client)) - require(len(serials) == 3, 'classic fixture did not boot three terminals') - markers = {} - for index, serial in enumerate(serials): - pane = f'/pane/{serial}' - require('pty' in client.list(pane), 'fixture contains an existing document') - marker = f'LP_{index}' - markers[serial] = marker - client.write(pane + '/tag', b'', truncate=True) - client.write(pane + '/tag', f' {marker} Tty Del Collapse'.encode()) - # Establish non-pristine shells and a stable prompt before measuring. - client.write(pane + '/pty/data', f"printf 'ready-{index}\\n'\r".encode()) - require(wait_for(lambda: f'\nready-{index}\n'.encode() in - client.read(pane + '/body').replace(b'\r', b'')), - 'terminal did not execute readiness command') - before_frame, before = require(wait_for(lambda: geometry(client, markers)), - 'terminal tags not visible in fixture') - source = serials[source_index] - source_rect = before[source] - require(source_rect[3] >= 8, 'source terminal too short for a local split') - require(before[serials[0]][:2] == (0, 2) and before[serials[1]][0] == 0 and - before[serials[1]][1] > 2 and before[serials[2]][:2] == (75, 2), - f'unexpected initial classic layout: {before}') - client.write(f'/pane/{source}/look', f'{target}\n'.encode()) - opened = require(wait_for(lambda: next((serial for serial in panes(client) - if serial not in serials), None)), - 'Look did not open the first document') - markers[opened] = 'opened.txt' - after_frame, after = require(wait_for(lambda: geometry(client, markers)), - 'Look pane tags not visible') - require(len(panes(client)) == 4, 'Look removed a terminal or added extra panes') - x, y, width, height = source_rect - require(after[source][:3] == (x, y, width), - f'Look moved its originating terminal: {source_rect} -> {after[source]}') - require(after[opened][:3] == (x, y + after[source][3], width) and - after[source][3] + after[opened][3] == height, - f'Look did not split directly below its caller: {after}') - for serial in serials: - if serial == source: - continue - require(after[serial] == before[serial], - f'Look resized or moved unrelated terminal {serial}: {before} -> {after}') - require(rectangle_text(before_frame, before[serial]) == - rectangle_text(after_frame, after[serial]), - f'Look changed unrelated terminal {serial} rendered text') - require(client.read(f'/pane/{opened}/body') == contents, - 'opened document contents differ') - client.write(f'/pane/{source}/look', f'{target}:2\n'.encode()) - require(list(panes(client)) == serials + [opened], 'repeated Look created a duplicate pane') - require(wait_for(lambda: geometry(client, markers)[1] == after), - 'repeated Look changed layout') - require(target.read_bytes() == contents, 'Look modified the fixture on disk') - if args.output: - capture(client, root, 'look-below-caller', not args.tty) - print(f'{"TTY" if args.tty else "SDL"} source {"lower-left" if source_index == 1 else "right"}: ' - 'local split, unchanged other terminals, first-file contents and re-Look reuse passed', flush=True) - - -def run(args): - # Cache-rooted fixtures avoid relying on /tmp quota in developer sessions. - cache = Path.home() / '.cache' - cache.mkdir(exist_ok=True) - context = nullcontext(str(args.output.resolve())) if args.output else tempfile.TemporaryDirectory( - prefix='lp-', dir=cache) - with context as directory: - for source_index, label in [(1, 'left'), (2, 'right')]: - run_case(args, Path(directory) / label, source_index) - - -if __name__ == '__main__': - parser = argparse.ArgumentParser(description=__doc__) - parser.add_argument('binary', type=Path) - parser.add_argument('--tty', action='store_true') - parser.add_argument('--output', type=Path) - run(parser.parse_args()) diff --git a/test/panes.zig b/test/panes.zig index f7ca9fc5..d7fa3514 100644 --- a/test/panes.zig +++ b/test/panes.zig @@ -3134,7 +3134,6 @@ const ImageTests = struct { const togglePalette = panes.Image.togglePalette; const toggleAscii = panes.Image.toggleAscii; const tagPrefix = panes.Image.tagPrefix; - const legacySavedPrefix = panes.Image.legacySavedPrefix; test "pane-local renderer choices are visible in the image tag" { var state: State = .{ .path = @constCast("/tmp/picture.ppm") }; @@ -3147,10 +3146,6 @@ const ImageTests = struct { config.tag_image ++ " petscii:on palette:terminal ascii:off /tmp/picture.ppm", tag, ); - try std.testing.expectEqualStrings( - "img /tmp/picture.ppm", - legacySavedPrefix(&state, "img /tmp/picture.ppm Keep Del").?, - ); } test "dump restore propagates malformed embedded image bytes" { @@ -3173,7 +3168,6 @@ const PdfTests = struct { const Point = panes.Pdf.Point; const Document = panes.Pdf.Document; const isPath = panes.Pdf.isPath; - const legacySavedPrefix = panes.Pdf.legacySavedPrefix; const State = panes.Pdf.State; const probeWord = panes.Pdf.probeWord; const pointAtGeometry = panes.Pdf.pointAtGeometry; @@ -3186,26 +3180,10 @@ const PdfTests = struct { try std.testing.expect(!isPath("pdf")); } - test "legacy PDF prefix is delimited by its stable marker and exact path" { - const path = "/tmp/a document.pdf"; - const tag = "pdf 2/9 height PdfFit full PdfTint PdfSections " ++ path ++ " Keep Del"; - try std.testing.expectEqualStrings( - "pdf 2/9 height PdfFit full PdfTint PdfSections " ++ path, - legacySavedPrefix(path, tag).?, - ); - } - test "feature-off PDF state is zero-sized" { if (!enabled) try std.testing.expectEqual(@as(usize, 0), @sizeOf(State)); } - test "compact PDF saved prefix separates page status from editable commands" { - const path = "/tmp/a document.pdf"; - try std.testing.expectEqualStrings(path ++ " [2/9]", legacySavedPrefix(path, path ++ " [2/9] Keep Del").?); - try std.testing.expect(legacySavedPrefix(path, path ++ " [oops] Keep Del") == null); - try std.testing.expect(legacySavedPrefix(path, path ++ " [2/9/4] Keep Del") == null); - } - test "PDF section rows preserve DFS ordinals and sanitise hierarchy" { if (!enabled) return; const entries = [_]pdf.OutlineEntry{ diff --git a/test/pdf.zig b/test/pdf.zig index 4cb8f3dd..48869de1 100644 --- a/test/pdf.zig +++ b/test/pdf.zig @@ -287,6 +287,7 @@ test "PDF dump fallback remains a byte-preserving file" { const saved_panes = [_]dump.Pane{.{ .kind = .image, .tag = "pdf 3/9 height PdfFit full PdfTint PdfSections " ++ path ++ " Keep Del", + .tag_tail = " Keep Del", .body = "", .scroll = 2, .cols = 80, -- cgit v1.3 From d4960472375ea68f709c56a677d8a37571419ff7 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 29 Sep 2026 22:27:38 -0300 Subject: Config opens the startup file, DumpConfig the settings report, and the workspace tag reads Dump Themes Config Debug Exit Config (SPC f c) opens init, found as the settings report finds it (opts.startup_config_path: $XDG_CONFIG_HOME/pardes/init or ~/.config/pardes/init, and the macOS and Windows paths config.md gives). A pane that already holds it is gone to instead; a file on disk is looked at; with none, an empty pane is named for it, and Save makes its directory and any above it first (File.make_dirs, fs.makeDirs) before writing. Without a configuration directory it says so and opens nothing. The report Config used to open, the startup path and every live setting, is DumpConfig, in a +DumpConfig pane. No alias keeps the old meaning. The workspace tag's default words put Themes where NextColor was, NextColor staying a builtin, and Config beside it. A tag the user edited is kept as it was: a dump stores only an edited one (topbar_custom), and a restore puts back only that. theme.snap types NextColor onto the workspace tag to click it, and tagnav's walk back to Dump takes five long-word steps. The rest of the re-recorded goldens differ in the workspace words and their widths only. Co-Authored-By: Claude Opus 5.5 --- docs/config.md | 11 ++-- docs/macos.md | 4 +- docs/tags.md | 4 +- docs/themes.md | 2 +- docs/ui-review.md | 2 +- src/CHANGELOG.md | 10 +++ src/File.zig | 4 ++ src/Messages.zig | 2 +- src/Output.zig | 2 +- src/builtins.zig | 32 +++++++++- src/config.zig | 11 ++-- src/crash.zig | 2 +- src/fs.zig | 19 ++++++ src/ninep/ctl.zig | 6 +- src/pardes.zig | 10 +-- src/tutor.txt | 4 +- test/appearance_gallery.py | 4 +- test/font_size.py | 4 +- test/output.zig | 98 +++++++++++++++++++++++++++--- test/snapshots/argv.golden | 8 +-- test/snapshots/badutf.golden | 2 +- test/snapshots/boot.golden | 2 +- test/snapshots/builtins.golden | 2 +- test/snapshots/chordcut.golden | 2 +- test/snapshots/cmdexit.golden | 2 +- test/snapshots/cmdword.golden | 2 +- test/snapshots/colgrip.golden | 2 +- test/snapshots/collapse.golden | 6 +- test/snapshots/cornerdrag-left.golden | 2 +- test/snapshots/cornerdrag.golden | 2 +- test/snapshots/cursorline.golden | 2 +- test/snapshots/delask.golden | 2 +- test/snapshots/doccol.golden | 2 +- test/snapshots/dump.golden | 2 +- test/snapshots/edit.golden | 2 +- test/snapshots/emptycol.golden | 2 +- test/snapshots/exec-bigdrag.golden | 2 +- test/snapshots/exec.golden | 2 +- test/snapshots/fileedit.golden | 2 +- test/snapshots/filewatch.golden | 2 +- test/snapshots/find.golden | 2 +- test/snapshots/fsearch.golden | 2 +- test/snapshots/ghostty-mid.golden | 2 +- test/snapshots/grep.golden | 2 +- test/snapshots/headersweep-restored.golden | 4 +- test/snapshots/headersweep.golden | 6 +- test/snapshots/hscroll.golden | 2 +- test/snapshots/images.golden | 4 +- test/snapshots/jumps.golden | 2 +- test/snapshots/layout-close.golden | 2 +- test/snapshots/layout-open.golden | 2 +- test/snapshots/leader.golden | 2 +- test/snapshots/load.golden | 2 +- test/snapshots/logquiet.golden | 2 +- test/snapshots/look-center.golden | 2 +- test/snapshots/look-dir.golden | 2 +- test/snapshots/look-file-1col.golden | 2 +- test/snapshots/look-file.golden | 2 +- test/snapshots/lookloaded.golden | 2 +- test/snapshots/lookpanes.golden | 2 +- test/snapshots/lookrange.golden | 2 +- test/snapshots/lsp-client-edit.golden | 2 +- test/snapshots/lsp-client.golden | 2 +- test/snapshots/lsp-rename.golden | 2 +- test/snapshots/lsp.golden | 2 +- test/snapshots/lspcomplete.golden | 8 +-- test/snapshots/lspcompletemoved.golden | 2 +- test/snapshots/lspdebug.golden | 2 +- test/snapshots/lsprelpath.golden | 4 +- test/snapshots/markup.golden | 4 +- test/snapshots/mini.golden | 12 ++-- test/snapshots/modal.golden | 2 +- test/snapshots/msg.golden | 4 +- test/snapshots/multicursor.golden | 2 +- test/snapshots/nested.golden | 6 +- test/snapshots/ninep.golden | 12 ++-- test/snapshots/pipe.golden | 2 +- test/snapshots/psearch.golden | 2 +- test/snapshots/reflow.golden | 2 +- test/snapshots/respawn.golden | 2 +- test/snapshots/restore.golden | 2 +- test/snapshots/rsearch.golden | 2 +- test/snapshots/savepane.golden | 2 +- test/snapshots/scroll.golden | 2 +- test/snapshots/scrolloff.golden | 2 +- test/snapshots/selarg.golden | 2 +- test/snapshots/selregex.golden | 2 +- test/snapshots/shellset.golden | 2 +- test/snapshots/shrinktag.golden | 2 +- test/snapshots/splitparent.golden | 6 +- test/snapshots/stepgrain.golden | 2 +- test/snapshots/syntax.golden | 2 +- test/snapshots/tag.golden | 2 +- test/snapshots/tagalign.golden | 10 +-- test/snapshots/tagalign2col.golden | 2 +- test/snapshots/tagbottom.golden | 2 +- test/snapshots/tagbottomimage.golden | 2 +- test/snapshots/tagbottomshort.golden | 12 ++-- test/snapshots/tagcmd.golden | 2 +- test/snapshots/tagnav.golden | 8 +-- test/snapshots/tagnav.snap | 4 +- test/snapshots/tagpath.golden | 2 +- test/snapshots/theme.golden | 40 ++++++------ test/snapshots/theme.snap | 8 +++ test/snapshots/themesel.golden | 2 +- test/snapshots/tinywin.golden | 6 +- test/snapshots/topbarexec.golden | 2 +- test/snapshots/tty.golden | 2 +- test/snapshots/ttyclick.golden | 2 +- test/snapshots/ttyedit.golden | 2 +- test/snapshots/ttyfollow.golden | 2 +- test/snapshots/ttyhelp.golden | 2 +- test/snapshots/ttylook.golden | 2 +- test/snapshots/ttyonly.golden | 2 +- test/snapshots/ttypaste.golden | 2 +- test/snapshots/ttyprompt.golden | 2 +- test/snapshots/ttytaken.golden | 2 +- test/snapshots/tutor.golden | 2 +- test/snapshots/wheeldrift.golden | 2 +- test/snapshots/winch.golden | 4 +- test/snapshots/windownav.golden | 2 +- test/snapshots/windowops.golden | 4 +- test/snapshots/wrap.golden | 2 +- test/snapshots/yankpaste.golden | 2 +- test/window_opacity.py | 12 ++-- 125 files changed, 371 insertions(+), 218 deletions(-) (limited to 'src/Output.zig') diff --git a/docs/config.md b/docs/config.md index f25c8746..bc4acf12 100644 --- a/docs/config.md +++ b/docs/config.md @@ -31,10 +31,13 @@ not stop later ones. Text that is no builtin is not run as a shell command (`Exec ...` still is). Key bindings are compile-time choices in `src/config.zig`; `init` does not remap them. -`Config` (`SPC f c`) opens a `+Config` pane with the startup path (a right -click opens it) and every live setting; a setting the frontend cannot show -reads `unsupported`. The root `ctl` file reads the settings back in the -words a write takes ([fs.md](fs.md#the-root-ctl)). +`Config` (`SPC f c`) opens `init` itself in a pane, or goes to its pane when +it is open. With no file there yet, the pane is named for it, empty, and +Save writes it, making its directory first. `DumpConfig` opens a +`+DumpConfig` pane with the startup path (a right click opens it) and every +live setting; a setting the frontend cannot show reads `unsupported`. The +root `ctl` file reads the settings back in the words a write takes +([fs.md](fs.md#the-root-ctl)). ## Settings diff --git a/docs/macos.md b/docs/macos.md index 8bb81be6..5512edbd 100644 --- a/docs/macos.md +++ b/docs/macos.md @@ -525,7 +525,7 @@ what is on screen. Cmd+=, Cmd- and Cmd+0 change the point size, rebuild `Metrics`, and report the new cell through the same resize path a window drag uses. They also observe the -effective face/point tuple through `pardes_font_observe`, so the single `Config` +effective face/point tuple through `pardes_font_observe`, so the single `DumpConfig` report follows a host-owned zoom without resolving a pending face request. The initial system face is observed the same way. Cmd+= rather than Cmd++ because AppKit matches the character and `=` is what is under the finger. @@ -759,7 +759,7 @@ separation is currently macOS-specific; other hosts keep the opaque raster path. `WindowBlur <0..100>` controls the strength of that native backdrop independently of `WindowOpacity`. It is a macOS-only builtin, also accepted in the startup -config and reported by `Config`. It defaults to 0 (off); 100 shows the full +config and reported by `DumpConfig`. It defaults to 0 (off); 100 shows the full AppKit material and intermediate values blend the material with the unblurred backdrop using the effect view's alpha. An opaque themed background hides the effect; lowering `WindowOpacity` makes the remembered strength visible again. diff --git a/docs/tags.md b/docs/tags.md index 8fe63804..93c8a6fa 100644 --- a/docs/tags.md +++ b/docs/tags.md @@ -11,8 +11,8 @@ pane's directory. Over 9P the tags are `/tag`, `/col//tag` and ## Default words -- Workspace: `Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor - Debug Exit`. +- Workspace: `Newcol Joincol Find Grep Help Changelog Tutor Dump Themes + Config Debug Exit`. - Column: `New Tty Find Grep Joincol Delcol`. - File pane: `Save Tty Collapse Del`; a source file with a grammar adds `TreeContext`, a result list `LocationsConfig`. PDF: `manual.pdf [1/12] diff --git a/docs/themes.md b/docs/themes.md index d163b243..c7204173 100644 --- a/docs/themes.md +++ b/docs/themes.md @@ -174,7 +174,7 @@ colors switch directly so syntax and ANSI content stay coherent. `FocusTint` toggles the focused pane's tag tint, which is on by default. `SyntaxBold` toggles bold syntax keywords, which are off by default. Both commands take no argument, work in GUI and TTY, and report their states in -`Config`. Use them in the startup configuration to reverse the defaults. +`DumpConfig`. Use them in the startup configuration to reverse the defaults. The original required roles remain unchanged: nullable `bg` and `fg`, `sel_bg`, `sel_fg`, `tag_bg`, `tag_fg`, `box`, `box_dim`, `kw`, `str`, `num`, diff --git a/docs/ui-review.md b/docs/ui-review.md index decf042d..6702ce31 100644 --- a/docs/ui-review.md +++ b/docs/ui-review.md @@ -206,7 +206,7 @@ pass does not change that environment code or skip the affected tests. The appearance checks cover native palette contrast, old ThemeFile documents, wrapped search matches, selection precedence, immediate body colors during theme fades, light-theme carets and both quiet and bold syntax preferences. -The 9P walkthrough also verifies `FocusTint` and `SyntaxBold` through `Config`. +The 9P walkthrough also verifies `FocusTint` and `SyntaxBold` through `DumpConfig`. All 97 terminal snapshot scripts passed without retries after reviewing and refreshing 32 appearance goldens. Of those, 27 preserve identical visible text, diff --git a/src/CHANGELOG.md b/src/CHANGELOG.md index 50149551..ca37856e 100644 --- a/src/CHANGELOG.md +++ b/src/CHANGELOG.md @@ -1,5 +1,15 @@ # Changelog +## Unreleased + +- `Config` (`SPC f c`) opens the startup file, `init`, in a pane, or goes + to its pane when it is open. With no file yet, it opens an empty pane of + that name, and Save writes it, making the directory first. The settings + report `Config` used to open is `DumpConfig`, in a `+DumpConfig` pane. +- The workspace tag reads `… Dump Themes Config Debug Exit`: `Themes` in + place of `NextColor`, which stays a builtin, and `Config` beside it. A + workspace tag you edited, and one a dump kept, stays as it is. + ## 0.0.5 - Over a slow link the terminal build keeps at most one frame in flight: it diff --git a/src/File.zig b/src/File.zig index 8babb27d..e8a9e2f8 100644 --- a/src/File.zig +++ b/src/File.zig @@ -58,6 +58,10 @@ pub const State = struct { /// as an undo to the save point is in acme. saved_hash: ?u64 = null, watch_after_save: bool = false, + /// Save makes the file's directory, and any above it, first: `Config`'s + /// pane for an init file that is not there yet, whose directory may not + /// be either. + make_dirs: bool = false, /// The file changed on disk under unsaved edits, which were kept (see /// `changed`): its hash, so the same change is said once, until a Save /// or get settles it. A Save warns once before overwriting it, as acme's diff --git a/src/Messages.zig b/src/Messages.zig index 7dcb22ed..d1478ac7 100644 --- a/src/Messages.zig +++ b/src/Messages.zig @@ -782,7 +782,7 @@ test "a message falls in, lingers past the input that dismisses it, and dissolve try std.testing.expect(p.executeBuiltinLine(p.active, "MessageDissolve 0")); try std.testing.expectEqual(@as(u16, 3), messageFrames(p.settings.message_fall_ms)); try std.testing.expectEqual(@as(u16, 1), messageFrames(p.settings.message_dissolve_ms)); - // The Config report reads back as configuration. + // The DumpConfig report reads back as configuration. try std.testing.expect(p.executeBuiltinLine(p.active, "MessageAnimation")); try std.testing.expect(!p.settings.message_animation); try std.testing.expect(p.executeBuiltinLine(p.active, "Msg plain")); diff --git a/src/Output.zig b/src/Output.zig index fb8fe7a3..69e9644c 100644 --- a/src/Output.zig +++ b/src/Output.zig @@ -835,7 +835,7 @@ pub fn openConfig(p: *Pardes, id: usize) !void { .state = &p.settings, }); const content = try out.toOwnedSlice(); - return openRead(p, id, .{ .cmd = .Config }, "", content); + return openRead(p, id, .{ .cmd = .DumpConfig }, "", content); } /// The message-row log, oldest first — the lines that were said in passing and diff --git a/src/builtins.zig b/src/builtins.zig index c549b17f..c40b2e00 100644 --- a/src/builtins.zig +++ b/src/builtins.zig @@ -1283,10 +1283,38 @@ pub const Help = struct { } }; -/// Open the settings in effect, each a word to click. +/// Open the startup file, `init`, in a pane: its pane when it is open, else +/// the file, else a pane of that name for Save to make it and its directory. pub const Config = struct { pub const scope: Scope = .session; - pub const output: OutputTraits = .{ .name = config.config_buffer }; + pub fn run(c: Ctx) void { + const path = c.p.opts.startup_config_path orelse + return c.p.reportFailure(c.id, "Config: no startup file here: no configuration directory"); + var real_buf: [4096]u8 = undefined; + const real = if (pardes.filesystem.resolveOs(path, &real_buf)) |r| r.path else null; + for (c.p.panes, 0..) |slot, id| { + const pane = slot orelse continue; + const f = pane.file orelse continue; + if (f.output != null) continue; + if (!std.mem.eql(u8, f.path, path) and !(if (real) |r| std.mem.eql(u8, f.path, r) else false)) continue; + return look.focusPaneLine(c.p, id, .{}, .keep); + } + if (real != null) return look.lookAt(c.p, c.id, path); + // Not there yet: a pane named for it, which Save makes. + const free = c.p.freeSlot() orelse return c.p.reportError(c.id, "Config", error.NoPaneSlots); + c.p.newScratchFor(c.id, .scratch); + const pane = c.p.panes[free] orelse return; + @import("ninep/pane.zig").nameBuffer(c.p, free, path, false) catch |err| return c.p.reportError(c.id, "Config", err); + pane.file.?.make_dirs = true; + c.p.active = free; + } +}; + +/// Open the settings in effect, each a word to click, and the startup +/// file's path. +pub const DumpConfig = struct { + pub const scope: Scope = .session; + pub const output: OutputTraits = .{ .name = config.dump_config_buffer }; pub fn run(c: Ctx) void { panes.Output.openConfig(c.p, c.id) catch |err| c.p.reportError(c.id, "config", err); } diff --git a/src/config.zig b/src/config.zig index ea7a877a..bb033823 100644 --- a/src/config.zig +++ b/src/config.zig @@ -68,6 +68,7 @@ pub const leader_path = paths: { .Recent = "fr", .Grep = "fg", .Config = "fc", + .DumpConfig = null, .LocationsConfig = null, .Tutor = "ht", .Changelog = "hc", @@ -266,7 +267,7 @@ pub const child_term = "xterm-256color"; pub const child_colorterm = "truecolor"; pub const child_term_program = "pardes"; -pub const topbar_str = "Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit"; +pub const topbar_str = "Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit"; pub const pane_builtins_str = "Tty Collapse Del"; pub const pdf_pane_builtins_str = "Tty PdfSections PdfTint Collapse Del"; @@ -452,7 +453,7 @@ pub const pipe_marker = " |"; pub const search_buffer = "+Search"; pub const help_buffer = "+Help"; -pub const config_buffer = "+Config"; +pub const dump_config_buffer = "+DumpConfig"; pub const effect_code_buffer = "+EffectCode"; pub const jumps_buffer = "+Jumps"; pub const recent_buffer = "+Recent"; @@ -968,7 +969,7 @@ pub const Runtime = struct { } }; - // The builtin registry and Config report share this command table. + // The builtin registry and DumpConfig report share this command table. pub const settings = [_]Setting{ .{ .word = "Colors", .action = .{ .toggle = .colors }, .doc = "Syntax colours in text panes, on or off." }, .{ .word = "Wrap", .action = .{ .toggle = .wrap }, .doc = "Long lines wrap onto the next row, on or off." }, @@ -1292,7 +1293,7 @@ pub const Runtime = struct { /// Each line reads as the command that would set it: the word, then the /// value you would type after it. No colons, no units — `WindowOpacity 70` - /// is both what Config prints and what you write back. + /// is both what DumpConfig prints and what you write back. pub fn writeReport(out: *std.Io.Writer, context: ReportContext) !void { const state = context.state; var wrote_transition = false; @@ -1653,7 +1654,7 @@ pub const Runtime = struct { try std.testing.expect(FontSpec.parse(bad) == null); } - test "Config report observes every simple setting and all live context" { + test "DumpConfig report observes every simple setting and all live context" { var state: Runtime = .{}; // Every setting, every context line: the report outgrows 4K. var storage: [8192]u8 = undefined; diff --git a/src/crash.zig b/src/crash.zig index 10d38591..99822aad 100644 --- a/src/crash.zig +++ b/src/crash.zig @@ -23,7 +23,7 @@ const std = @import("std"); const builtin = @import("builtin"); const pardes = @import("pardes.zig"); -/// Beside `init`, so `Config` opens the directory that holds both. +/// The crash log's name, beside `init` in the configuration directory. pub const name = "crashes"; /// The config directory `config.User.load` resolved, COPIED rather than diff --git a/src/fs.zig b/src/fs.zig index fc3eb98f..1d0bbc22 100644 --- a/src/fs.zig +++ b/src/fs.zig @@ -637,6 +637,25 @@ test "a path with a part over 255 bytes is NameTooLong, never a panic" { try std.testing.expectError(error.NameTooLong, statPath(std.testing.io, long, .{})); } +/// Make `dir` and each directory above it that is missing, as `mkdir -p` +/// does: one already there is no failure. A failure shows at the open +/// that follows. +pub fn makeDirs(dir: []const u8) void { + if (comptime !platform_has_fs) return; + var z: [4096:0]u8 = undefined; + if (dir.len == 0 or dir.len >= z.len) return; + @memcpy(z[0..dir.len], dir); + z[dir.len] = 0; + pardes.turn.yield(); + defer pardes.turn.back(); + for (z[1..dir.len], 1..) |c, i| if (c == '/') { + z[i] = 0; + _ = libc.mkdir(z[0..i :0], 0o755); + z[i] = '/'; + }; + _ = libc.mkdir(z[0..dir.len :0], 0o755); +} + pub fn localPath(path: []const u8) ?[]const u8 { if (std.mem.eql(u8, path, "/n/os")) return "/"; if (std.mem.startsWith(u8, path, "/n/os/")) return path[5..]; diff --git a/src/ninep/ctl.zig b/src/ninep/ctl.zig index 060e0d6c..5ed03c58 100644 --- a/src/ninep/ctl.zig +++ b/src/ninep/ctl.zig @@ -485,7 +485,7 @@ const e_prompt = "control message needs its argument"; /// Every setting, one a line, in the words a write of it takes, so that the /// file read back is the configuration, as webfs's ctl reads (webfs(4)). /// What is not a setting -- platform, themes, where the config came from -- -/// is /status's or the Config window's. +/// is /status's or the DumpConfig window's. fn writeSettings(p: *Pardes, w: *std.Io.Writer) !void { try writeSettingsOf(p, &p.settings, w); try w.writeAll("LocationsConfig "); @@ -523,7 +523,7 @@ pub fn writeSettingsOf(p: *Pardes, s: *const config.Runtime, w: *std.Io.Writer) inline else => |field| try w.print("{s} {s}\n", .{ word, @tagName(@field(s, @tagName(field))) }), }, .message_ms => |which| try w.print("{s} {d}\n", .{ word, @field(s, "message_" ++ @tagName(which) ++ "_ms") }), - // The directory in effect, as Config reports it; bare only when + // The directory in effect, as DumpConfig reports it; bare only when // there is none (no home to put the default in). .dump_dir => { var buf: [900]u8 = undefined; @@ -1165,7 +1165,7 @@ test "the root ctl reads the settings as a write takes them, and takes the sessi try testing.expectEqual(@as(u64, settings.len), call(p, .{ .tag = 1, .op = .getattr, .node = root_ctl }).reply.attr.size); try testing.expect(std.mem.indexOf(u8, settings, "Verbose on\n") != null); try testing.expect(std.mem.indexOf(u8, settings, "LocationsConfig ") != null); - // Settings only: nothing /status or the Config window says. + // Settings only: nothing /status or the DumpConfig window says. try testing.expect(std.mem.indexOf(u8, settings, "Platform") == null); try testing.expect(std.mem.indexOf(u8, settings, "requested") == null); diff --git a/src/pardes.zig b/src/pardes.zig index 18794975..e3db97d9 100644 --- a/src/pardes.zig +++ b/src/pardes.zig @@ -1329,7 +1329,7 @@ test "acme placement: New and 9P's new take the bottom half of the last pane" { try std.testing.expect(p.rects[made].y > was.y + BOX_H); } -test "Placement pardes brings back the old rules, and says so in Config" { +test "Placement pardes brings back the old rules, and says so in DumpConfig" { const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 40 }); defer p.deinit(); try std.testing.expect(p.executeBuiltinLine(p.active, "Placement pardes")); @@ -3493,7 +3493,7 @@ test "s in a header selects in the header's own text" { var ranges: [Text.max_selections]modal.Selection = undefined; const text = try edit.flatSurface(p, &p.global_tag); const got = p.global_tag.ranges(text, 0, &ranges); - try std.testing.expectEqual(@as(usize, 3), got.n); // Newcol, Joincol, NextColor + try std.testing.expectEqual(@as(usize, 2), got.n); // Newcol, Joincol try std.testing.expectEqual(@as(u16, 0), pane.body.nsel); } @@ -5261,7 +5261,7 @@ pub const Pardes = struct { } /// Resolve the request already handed to the GUI host. Requested and - /// effective tuples deliberately remain separate so Config can show both. + /// effective tuples deliberately remain separate so DumpConfig can show both. pub fn acknowledgeFont( p: *Pardes, effective_name: []const u8, @@ -5596,6 +5596,8 @@ pub const Pardes = struct { const was = f.saved_revision; const failures = p.fs.failures; f.saved_revision = f.revision; + if (f.make_dirs) if (filesystem.localPath(f.path)) |local| + filesystem.makeDirs(std.fs.path.dirname(local) orelse "/"); p.hostWriteFile(sf.pane, f.path, f.content); const saved_pane = p.panes[sf.pane] orelse return; if (saved_pane.serial != serial) return; @@ -6721,7 +6723,7 @@ pub const Pardes = struct { } /// A native post pass proved unavailable: the chain is emptied, which - /// Config then reports. + /// DumpConfig then reports. pub fn disableSceneEffects(p: *Pardes) void { p.settings.post.clear(); } diff --git a/src/tutor.txt b/src/tutor.txt index c59deeae..f8aa7aef 100644 --- a/src/tutor.txt +++ b/src/tutor.txt @@ -65,8 +65,8 @@ Every pane has Collapse: hide its body, then execute again to expand it. The top bar is: - Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor - Debug Exit + Newcol Joincol Find Grep Help Changelog Tutor Dump Themes + Config Debug Exit Reach it from the keyboard with `k` off the topmost tagline; `j` comes back down. diff --git a/test/appearance_gallery.py b/test/appearance_gallery.py index 46b17dd9..c321c7c0 100644 --- a/test/appearance_gallery.py +++ b/test/appearance_gallery.py @@ -91,8 +91,8 @@ def run(args): def config_report(): before = set(panes(client)) - command(client, right, 'Config') - pane = require(wait_for(lambda: next((s for s in panes(client) if s not in before), None)), 'Config output missing') + command(client, right, 'DumpConfig') + pane = require(wait_for(lambda: next((s for s in panes(client) if s not in before), None)), 'DumpConfig output missing') text = client.read(f'/pane/{pane}/body').decode() client.write(f'/pane/{pane}/exec', b'Del\n') return text diff --git a/test/font_size.py b/test/font_size.py index b7104099..ef685a9e 100644 --- a/test/font_size.py +++ b/test/font_size.py @@ -25,10 +25,10 @@ def run(args): control = new_pane(client, b'') def report(size): - execute(client, control, 'Config') + execute(client, control, 'DumpConfig') def ready(): for serial, tag in panes(client).items(): - if '/+Config ' in tag: + if '/+DumpConfig ' in tag: body = client.read(f'/pane/{serial}/body').decode() if f'Font effective size {size:.2f} pixels' in body: return body diff --git a/test/output.zig b/test/output.zig index 1b1b80c9..da17eccc 100644 --- a/test/output.zig +++ b/test/output.zig @@ -89,7 +89,7 @@ fn resultId(p: *Pardes) !usize { } test "output callers opt into location highlighting instead of matching prose colons" { - for ([_]panes.Output.Origin{ .{ .cmd = .LocationsConfig }, .{ .cmd = .Config }, .{ .query = .hover } }) |origin| { + for ([_]panes.Output.Origin{ .{ .cmd = .LocationsConfig }, .{ .cmd = .DumpConfig }, .{ .query = .hover } }) |origin| { const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 140, .rows = 30 }); defer p.deinit(); p.locations_config.layout = .@"inline"; @@ -533,12 +533,12 @@ test "Mini failures leave its existing snapshot and focus unchanged" { try std.testing.expectEqual(next, p.freeSlot()); } -test "Config prints the startup path and refreshes its one output" { +test "DumpConfig prints the startup path and refreshes its one output" { const path = "/home/pardes-test/.config/pardes/init"; const p = try Pardes.init(std.testing.allocator, .{ .startup_config_path = path }); defer p.deinit(); - try std.testing.expect(p.executeBuiltinLine(0, "Config")); + try std.testing.expect(p.executeBuiltinLine(0, "DumpConfig")); const opened = p.active; const out = p.panes[opened].?.file.?; for ([_][]const u8{ @@ -549,28 +549,106 @@ test "Config prints the startup path and refreshes its one output" { }) |line| try std.testing.expect(std.mem.indexOf(u8, out.content, line) != null); var default_line: [256]u8 = undefined; try std.testing.expect(std.mem.indexOf(u8, out.content, try std.fmt.bufPrint(&default_line, "Shell requested (new panes) {s} (default)\n", .{config.defaultShell()})) != null); - try std.testing.expectEqualStrings(config.config_buffer, std.fs.path.basename(out.path)); - try std.testing.expectEqual(panes.Output.Origin{ .cmd = .Config }, out.output.?.from); + try std.testing.expectEqualStrings(config.dump_config_buffer, std.fs.path.basename(out.path)); + try std.testing.expectEqual(panes.Output.Origin{ .cmd = .DumpConfig }, out.output.?.from); - try std.testing.expect(p.executeBuiltinLine(0, "Config")); + try std.testing.expect(p.executeBuiltinLine(0, "DumpConfig")); try std.testing.expectEqual(opened, p.active); var buffers: usize = 0; for (p.panes) |slot| { const f = (slot orelse continue).file orelse continue; const origin = (f.output orelse continue).from; - buffers += @intFromBool(std.meta.eql(origin, panes.Output.Origin{ .cmd = .Config })); + buffers += @intFromBool(std.meta.eql(origin, panes.Output.Origin{ .cmd = .DumpConfig })); } try std.testing.expectEqual(@as(usize, 1), buffers); } -test "Config reports the absence of a per-user config path" { +test "DumpConfig reports the absence of a per-user config path" { const p = try Pardes.init(std.testing.allocator, .{}); defer p.deinit(); - try std.testing.expect(p.executeBuiltinLine(0, "Config")); + try std.testing.expect(p.executeBuiltinLine(0, "DumpConfig")); const report = p.panes[p.active].?.file.?.content; try std.testing.expect(std.mem.indexOf(u8, report, "no per-user config path") != null); } +/// The file Config names, in a fresh temporary directory: `pardes/init` +/// under it, written with `content` unless that is null. +fn configFixture(tmp: *std.testing.TmpDir, content: ?[]const u8, buf: *[4096]u8) ![]const u8 { + if (content) |text| { + try tmp.dir.createDirPath(std.testing.io, "pardes"); + try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "pardes/init", .data = text }); + } + const len = try tmp.dir.realPath(std.testing.io, buf); + return std.fmt.bufPrint(buf[len..], "{s}/pardes/init", .{buf[0..len]}) catch unreachable; +} + +test "Config opens the startup file, and a second Config goes back to its pane" { + if (comptime !pardes.hosted) return; + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + var buf: [4096]u8 = undefined; + const path = try configFixture(&tmp, "Theme orchard\n", &buf); + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .startup_config_path = path }); + defer p.deinit(); + const first = p.active; + + try std.testing.expect(p.executeBuiltinLine(first, "Config")); + const opened = p.active; + try std.testing.expect(opened != first); + const f = p.panes[opened].?.file.?; + try std.testing.expectEqualStrings(path, f.path); + try std.testing.expectEqualStrings("Theme orchard\n", f.content); + try std.testing.expect(f.output == null); + + p.active = first; + try std.testing.expect(p.executeBuiltinLine(first, "Config")); + try std.testing.expectEqual(opened, p.active); + var named: usize = 0; + for (p.panes) |slot| if (slot) |pane| if (pane.file) |file| { + named += @intFromBool(std.mem.eql(u8, file.path, path)); + }; + try std.testing.expectEqual(@as(usize, 1), named); +} + +test "Config with no startup file opens a pane of its name, and Save makes its directory" { + if (comptime !pardes.hosted) return; + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + var buf: [4096]u8 = undefined; + const path = try configFixture(&tmp, null, &buf); + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .startup_config_path = path }); + defer p.deinit(); + const first = p.active; + + try std.testing.expect(p.executeBuiltinLine(first, "Config")); + const opened = p.active; + try std.testing.expect(opened != first); + const f = p.panes[opened].?.file.?; + try std.testing.expectEqualStrings(path, f.path); + try std.testing.expectEqualStrings("", f.content); + try std.testing.expect(f.output == null); + + // Again: the same pane, not a second one. + p.active = first; + try std.testing.expect(p.executeBuiltinLine(first, "Config")); + try std.testing.expectEqual(opened, p.active); + + try std.testing.expectError(error.FileNotFound, tmp.dir.statFile(std.testing.io, "pardes", .{})); + // Save's effect, as a host performs it. + try std.testing.expect(p.executeBuiltinLine(opened, "Save")); + p.perform(.{ .save_file = .{ .pane = @intCast(opened) } }); + const made = try tmp.dir.statFile(std.testing.io, "pardes", .{}); + try std.testing.expectEqual(std.Io.File.Kind.directory, made.kind); +} + +test "Config without a configuration directory says so and opens nothing" { + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true }); + defer p.deinit(); + const before = p.freeSlot(); + try std.testing.expect(p.executeBuiltinLine(p.active, "Config")); + try std.testing.expectEqual(before, p.freeSlot()); +} + test "EffectCode lists readable virtual sources used by this backend" { if (comptime !builtins.EffectCode.enabled) return; const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true }); @@ -651,7 +729,7 @@ test "every enabled setting builtin mutates the State Config reports" { } } - try std.testing.expect(p.executeBuiltinLine(p.active, "Config")); + try std.testing.expect(p.executeBuiltinLine(p.active, "DumpConfig")); const report = p.panes[p.active].?.file.?.content; for ([_][]const u8{ "Colors off\n", diff --git a/test/snapshots/argv.golden b/test/snapshots/argv.golden index e4d41d6c..65b0ac71 100644 --- a/test/snapshots/argv.golden +++ b/test/snapshots/argv.golden @@ -1,5 +1,5 @@ == snap noargs grid=100x31 cursor=4,5 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol |$ /tmp/pardes-snap/argv/cwd Tty+bash Save Mode Filter Collapse Del | $ echo ARGV''TTY @@ -23,7 +23,7 @@ | /tmp/pardes-snap/argv/cwd/+New Save Tty Collapse Del | 1 == snap filearg grid=100x31 cursor=7,3 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol | /tmp/pardes-snap/argv/cwd/notes.txt Save Tty Collapse Del | 3 line 3 @@ -34,7 +34,7 @@ | 8 line 8 | 9 == snap filearg-n3 grid=100x31 cursor=7,3 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol | /tmp/pardes-snap/argv/cwd/notes.txt Save Tty Collapse Del | 1 line 1 @@ -47,7 +47,7 @@ | 8 line 8 | 9 == snap dirarg grid=100x31 cursor=4,5 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol | /tmp/pardes-snap/argv/cwd/sub Tty+bash Save Mode Filter Collapse Del | ls diff --git a/test/snapshots/badutf.golden b/test/snapshots/badutf.golden index d013a610..14aa71dc 100644 --- a/test/snapshots/badutf.golden +++ b/test/snapshots/badutf.golden @@ -1,5 +1,5 @@ == snap badbytes grid=100x31 cursor=7,3 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol | /tmp/pardes-snap/badutf/cwd/bad.txt Save Tty Collapse Del | 1 hello �� world diff --git a/test/snapshots/boot.golden b/test/snapshots/boot.golden index 3aedceff..ac674ed2 100644 --- a/test/snapshots/boot.golden +++ b/test/snapshots/boot.golden @@ -1,5 +1,5 @@ == snap boot grid=100x31 cursor=4,5 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol | /tmp/pardes-snap/boot/cwd Tty+bash Save Mode Filter Collapse Del | ls diff --git a/test/snapshots/builtins.golden b/test/snapshots/builtins.golden index f40d563e..6b79d47f 100644 --- a/test/snapshots/builtins.golden +++ b/test/snapshots/builtins.golden @@ -1,5 +1,5 @@ == snap boot grid=120x67 cursor=7,3 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol | /tmp/pardes-snap/builtins/cwd/notes.txt Save Tty Collapse Del | 1 line 1 diff --git a/test/snapshots/chordcut.golden b/test/snapshots/chordcut.golden index f0443a01..817c534c 100644 --- a/test/snapshots/chordcut.golden +++ b/test/snapshots/chordcut.golden @@ -1,5 +1,5 @@ == snap opened grid=120x31 cursor=7,8 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol | /tmp/pardes-snap/chordcut/cwd Tty+bash Save Mode Filter C /tmp/pardes-snap/chordcut/cwd Tty+bash Save Mode Filter C | ollapse Del ollapse Del diff --git a/test/snapshots/cmdexit.golden b/test/snapshots/cmdexit.golden index c5c314b9..7d950a43 100644 --- a/test/snapshots/cmdexit.golden +++ b/test/snapshots/cmdexit.golden @@ -1,5 +1,5 @@ == snap opened grid=120x31 cursor=7,3 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol | /tmp/pardes-snap/cmdexit/cwd/cmds.txt Save Tty Collapse Del | 1 sleep 30 & echo BG''STARTED diff --git a/test/snapshots/cmdword.golden b/test/snapshots/cmdword.golden index 748bf06b..af2fbcb8 100644 --- a/test/snapshots/cmdword.golden +++ b/test/snapshots/cmdword.golden @@ -1,5 +1,5 @@ == snap opened grid=120x31 cursor=7,3 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol | /tmp/pardes-snap/cmdword/cwd/cmds.txt Save Tty Collapse Del | 1 @`echo ZZ''E` @`echo ZZ''L` Look p.txt @`Look .` diff --git a/test/snapshots/colgrip.golden b/test/snapshots/colgrip.golden index 1491a1f3..26a0b1c0 100644 --- a/test/snapshots/colgrip.golden +++ b/test/snapshots/colgrip.golden @@ -26,7 +26,7 @@ == style held grid=100x24 |1: 0-1 d,#887455, 2-2 d,#1d2824, 3-49 #b2c3b8,#1d2824, 50-51 #b2c3b8,#f4c086, 52-52 #b2c3b8,#314738, 53-99 #becfc4,#314738, == snap resize-drag grid=100x24 cursor=54,6 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol ╎ New Tty Find Grep Joincol Delcol | /tmp/pardes-snap/colgrip/cwd/w.txt S╎ve Tty Col /tmp/pardes-snap/colgrip/cwd Tty+bash Save Mode | lapse Del ╎ Filter Collapse Del diff --git a/test/snapshots/collapse.golden b/test/snapshots/collapse.golden index 23dfa8f3..57aafc8f 100644 --- a/test/snapshots/collapse.golden +++ b/test/snapshots/collapse.golden @@ -1,5 +1,5 @@ == snap before grid=160x25 cursor=7,3 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol | /tmp/pardes-snap/collapse/cwd/kept.txt Save Tty Collapse Del | 1 KEEP-FIRST @@ -10,8 +10,8 @@ |4: |5: == 9p middle-collapsed-cursor grid=160x25 cursor=none -|0: Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit -@0: 0-70 #b2c3b8,#1d2824,,tagline 71-159 d,#1d2824,,tagline +|0: Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +@0: 0-74 #b2c3b8,#1d2824,,tagline 75-159 d,#1d2824,,tagline |1: New Tty Find Grep Joincol Delcol @1: 0-1 #ffffff,#887455,,tagline 2-2 d,#314738,,tagline 3-34 #becfc4,#314738,,tagline 35-159 d,#314738,,tagline |2: /tmp/pardes-snap/collapse/cwd/kept.txt Save Tty Collapse Del diff --git a/test/snapshots/cornerdrag-left.golden b/test/snapshots/cornerdrag-left.golden index 22bdd5b7..a5f36319 100644 --- a/test/snapshots/cornerdrag-left.golden +++ b/test/snapshots/cornerdrag-left.golden @@ -1,5 +1,5 @@ == snap right-split grid=100x31 cursor=54,11 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol | /tmp/pardes-snap/cornerdrag-left/cwd Tty+bash S /tmp/pardes-snap/cornerdrag-left/cwd Tty+bash S | ave Mode Filter Collapse Del ave Mode Filter Collapse Del diff --git a/test/snapshots/cornerdrag.golden b/test/snapshots/cornerdrag.golden index 30c1830a..8dd21eff 100644 --- a/test/snapshots/cornerdrag.golden +++ b/test/snapshots/cornerdrag.golden @@ -1,5 +1,5 @@ == snap hover-corner grid=100x31 cursor=4,6 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol ╎ New Tty Find Grep Joincol Delcol | /tmp/pardes-snap/cornerdrag/cwd Tty+bash Save ╎ /tmp/pardes-snap/cornerdrag/cwd Tty+bash Save M | ode Filter Collapse Del ╎ ode Filter Collapse Del diff --git a/test/snapshots/cursorline.golden b/test/snapshots/cursorline.golden index 85c23f7f..6b99a30a 100644 --- a/test/snapshots/cursorline.golden +++ b/test/snapshots/cursorline.golden @@ -1,5 +1,5 @@ == snap top grid=150x31 cursor=7,7 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol | /tmp/pardes-snap/cursorline/cwd Tty+bash Save Mode Filter Collapse Del /tmp/pardes-snap/cursorline/cwd Tty+bash Save Mode Filter Collapse Del | ls ls diff --git a/test/snapshots/delask.golden b/test/snapshots/delask.golden index ed5dd66a..d1487a36 100644 --- a/test/snapshots/delask.golden +++ b/test/snapshots/delask.golden @@ -1,5 +1,5 @@ == snap three grid=100x36 cursor=18,20 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol | /tmp/pardes-snap/delask/cwd/top.txt Save Tty Collapse Del | 1 top-marker diff --git a/test/snapshots/doccol.golden b/test/snapshots/doccol.golden index db2b0074..21424456 100644 --- a/test/snapshots/doccol.golden +++ b/test/snapshots/doccol.golden @@ -1,5 +1,5 @@ == snap boot grid=100x31 cursor=7,4 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol | /tmp/pardes-snap/doccol/cwd/a.txt Save Tty Coll /tmp/pardes-snap/doccol/cwd Tty+bash Save Mode | apse Del Filter Collapse Del diff --git a/test/snapshots/dump.golden b/test/snapshots/dump.golden index 9220c450..b9608741 100644 --- a/test/snapshots/dump.golden +++ b/test/snapshots/dump.golden @@ -4,7 +4,7 @@ .version = 1, .screen = .{ .cols = 100, .rows = 31 }, .active = 0, - .topbar = "Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit", + .topbar = "Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit", .topbar_custom = null, .theme = "orchard", .locations_config = .{ diff --git a/test/snapshots/edit.golden b/test/snapshots/edit.golden index f03f7e24..aa39ed9c 100644 --- a/test/snapshots/edit.golden +++ b/test/snapshots/edit.golden @@ -1,5 +1,5 @@ == snap inserted grid=100x31 cursor=16,10 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol | /tmp/pardes-snap/edit/cwd Tty+bash Save Mode Fi /tmp/pardes-snap/edit/cwd Tty+bash Save Mode Fi | lter Collapse Del lter Collapse Del diff --git a/test/snapshots/emptycol.golden b/test/snapshots/emptycol.golden index 1e3f916d..9bac8492 100644 --- a/test/snapshots/emptycol.golden +++ b/test/snapshots/emptycol.golden @@ -1,5 +1,5 @@ == snap newcol grid=100x24 cursor=53,1 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol | /tmp/pardes-snap/emptycol/cwd/notes.txt Save Tt | y Collapse Del diff --git a/test/snapshots/exec-bigdrag.golden b/test/snapshots/exec-bigdrag.golden index c74fd8f9..a2ac6610 100644 --- a/test/snapshots/exec-bigdrag.golden +++ b/test/snapshots/exec-bigdrag.golden @@ -1,5 +1,5 @@ == snap alive grid=200x61 cursor=119,38 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol | /tmp/pardes-snap/exec-bigdrag/cwd Tty+bash Save Mode Filter Collapse Del /tmp/pardes-snap/exec-bigdrag/cwd Tty+bash Save Mode Filter Collapse Del | ls 2 diff --git a/test/snapshots/exec.golden b/test/snapshots/exec.golden index 216327b3..a9f8716e 100644 --- a/test/snapshots/exec.golden +++ b/test/snapshots/exec.golden @@ -1,5 +1,5 @@ == snap exec grid=140x31 cursor=16,8 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol | /tmp/pardes-snap/exec/cwd Tty+bash Save Mode Filter Collapse Del /tmp/pardes-snap/exec/cwd Tty+bash Save Mode Filter Collapse Del | ls Exec ls diff --git a/test/snapshots/fileedit.golden b/test/snapshots/fileedit.golden index 4c651d3c..5ba6e18a 100644 --- a/test/snapshots/fileedit.golden +++ b/test/snapshots/fileedit.golden @@ -1,5 +1,5 @@ == snap edited grid=150x31 cursor=17,7 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol | /tmp/pardes-snap/fileedit/cwd Tty+bash Save Mode Filter Collapse Del /tmp/pardes-snap/fileedit/cwd Tty+bash Save Mode Filter Collapse Del | ls ls diff --git a/test/snapshots/filewatch.golden b/test/snapshots/filewatch.golden index 589cfc3a..36f51582 100644 --- a/test/snapshots/filewatch.golden +++ b/test/snapshots/filewatch.golden @@ -1,5 +1,5 @@ == snap edited grid=210x31 cursor=15,7 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol | /tmp/pardes-snap/filewatch/cwd Tty+bash Save Mode Filter Collapse Del | ls diff --git a/test/snapshots/find.golden b/test/snapshots/find.golden index 61716d87..c9c6b755 100644 --- a/test/snapshots/find.golden +++ b/test/snapshots/find.golden @@ -1,5 +1,5 @@ == snap group grid=120x41 cursor=7,3 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol | /tmp/pardes-snap/find/cwd/here.txt Save Tty Collapse Del | 1 Find SPC f diff --git a/test/snapshots/fsearch.golden b/test/snapshots/fsearch.golden index d459f8c7..7ba94492 100644 --- a/test/snapshots/fsearch.golden +++ b/test/snapshots/fsearch.golden @@ -1,5 +1,5 @@ == snap opened grid=180x31 cursor=7,7 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol | /tmp/pardes-snap/fsearch/cwd Tty+bash Save Mode Filter Collapse Del /tmp/pardes-snap/fsearch/cwd Tty+bash Save Mode Filter Collapse Del | ls ls diff --git a/test/snapshots/ghostty-mid.golden b/test/snapshots/ghostty-mid.golden index ab117f8a..4bd8bf1f 100644 --- a/test/snapshots/ghostty-mid.golden +++ b/test/snapshots/ghostty-mid.golden @@ -1,5 +1,5 @@ == snap ghostty-mid grid=100x31 cursor=4,8 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol | /tmp/pardes-snap/ghostty-mid/cwd Tty+bash Save /tmp/pardes-snap/ghostty-mid/cwd Tty+bash Save | Mode Filter Collapse Del Mode Filter Collapse Del diff --git a/test/snapshots/grep.golden b/test/snapshots/grep.golden index 65b2fd5b..687d7099 100644 --- a/test/snapshots/grep.golden +++ b/test/snapshots/grep.golden @@ -1,5 +1,5 @@ == snap opened grid=180x31 cursor=7,7 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol | /tmp/pardes-snap/grep/cwd Tty+bash Save Mode Filter Collapse Del /tmp/pardes-snap/grep/cwd Tty+bash Save Mode Filter Collapse Del | ls ls diff --git a/test/snapshots/headersweep-restored.golden b/test/snapshots/headersweep-restored.golden index 765f221f..38b505e7 100644 --- a/test/snapshots/headersweep-restored.golden +++ b/test/snapshots/headersweep-restored.golden @@ -21,7 +21,7 @@ |19: 0-0 d,#608269, 1-59 d,#0d1410, 60-60 d,#608269, 61-119 d,#0d1410, |20: 0-0 d,#608269, 1-59 d,#0d1410, 60-60 d,#608269, 61-119 d,#0d1410, == snap col-swept grid=120x21 cursor=4,9 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit Restore /tmp/pardes-snap/headersweep-restored/du +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit Restore /tmp/pardes-snap/headersweep-restore | New Tty Find Grep Joincol Delcol echo RE''STORED-COL New Tty Find Grep Joincol Delcol | /tmp/pardes-snap/headersweep-restored/cwd Tty+bash Save M /tmp/pardes-snap/headersweep-restored/cwd Tty+bash Save M | ode Filter Collapse Del ode Filter Collapse Del @@ -44,6 +44,6 @@ |7: 0-0 d,#608269, 1-1 d,#0d1410, 2-59 #e5eee5,#0d1410, 60-60 #e5eee5,#608269, 61-119 #e5eee5,#0d1410, |8: 0-0 d,#608269, 1-1 d,#0d1410, 2-59 #e5eee5,#0d1410, 60-60 #e5eee5,#608269, 61-119 #e5eee5,#0d1410, == snap ws-swept grid=120x21 cursor=4,11 -|0: Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit Restore /tmp/pardes-snap/headersweep-restored ec +|0: Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit Restore /tmp/pardes-snap/headersweep-rest ec |9: echo RE''STORED-WS |10: RESTORED-WS diff --git a/test/snapshots/headersweep.golden b/test/snapshots/headersweep.golden index 92d23a1b..38004c08 100644 --- a/test/snapshots/headersweep.golden +++ b/test/snapshots/headersweep.golden @@ -21,7 +21,7 @@ |19: 0-0 d,#608269, 1-59 d,#0d1410, 60-60 d,#608269, 61-119 d,#0d1410, |20: 0-0 d,#608269, 1-59 d,#0d1410, 60-60 d,#608269, 61-119 d,#0d1410, == snap col-swept grid=120x21 cursor=4,8 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol echo SW''EPT-COL New Tty Find Grep Joincol Delcol | /tmp/pardes-snap/headersweep/cwd Tty+bash Save Mode Filte /tmp/pardes-snap/headersweep/cwd Tty+bash Save Mode Filte | r Collapse Del r Collapse Del @@ -38,11 +38,11 @@ | ls | hay.txt == snap ws-swept grid=120x21 cursor=4,10 -|0: Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit echo SW''EPT-WS +|0: Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit echo SW''EPT-WS |8: echo SW''EPT-WS |9: SWEPT-WS == snap ws-looked grid=120x21 cursor=7,19 -|0: Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit echo SW''EPT-WS xxhay.txtxx +|0: Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit echo SW''EPT-WS xxhay.txtxx |17: /tmp/pardes-snap/headersweep/cwd/hay.txt Save Tty Collaps |18: e Del |19: 1 ZQNEEDLE diff --git a/test/snapshots/hscroll.golden b/test/snapshots/hscroll.golden index ddd7bab7..e73bf4c3 100644 --- a/test/snapshots/hscroll.golden +++ b/test/snapshots/hscroll.golden @@ -1,5 +1,5 @@ == snap opened grid=90x31 cursor=7,9 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol | /tmp/pardes-snap/hscroll/cwd Tty+bash Save /tmp/pardes-snap/hscroll/cwd Tty+bash Save | Mode Filter Collapse Del Mode Filter Collapse Del diff --git a/test/snapshots/images.golden b/test/snapshots/images.golden index 940e293e..e888460d 100644 --- a/test/snapshots/images.golden +++ b/test/snapshots/images.golden @@ -1,5 +1,5 @@ == snap img-open grid=150x31 cursor=11,8 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol | /tmp/pardes-snap/images/cwd Tty+bash Save Mode Filter Collapse Del /tmp/pardes-snap/images/cwd Tty+bash Save Mode Filter Collapse Del | ls ls @@ -75,7 +75,7 @@ |15: │█🬝▄ |16: 🬝🬹 == snap tag-edit grid=400x31 cursor=87,6 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol | /tmp/pardes-snap/images/cwd Tty+bash Save Mode Filter Collapse Del /tmp/pardes-snap/images/cwd Tty+bash Save Mode Filter Collapse Del | ls ls diff --git a/test/snapshots/jumps.golden b/test/snapshots/jumps.golden index 65435443..27884f6a 100644 --- a/test/snapshots/jumps.golden +++ b/test/snapshots/jumps.golden @@ -1,5 +1,5 @@ == snap start grid=150x31 cursor=7,3 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol | /tmp/pardes-snap/jumps/cwd/big.txt Save Tty Collapse Del | 1 line 1 diff --git a/test/snapshots/layout-close.golden b/test/snapshots/layout-close.golden index d708d764..95806a16 100644 --- a/test/snapshots/layout-close.golden +++ b/test/snapshots/layout-close.golden @@ -1,5 +1,5 @@ == snap built grid=140x41 cursor=4,16 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol | /tmp/pardes-snap/layout-close/cwd Tty+bash Save Mode Filter Collaps /tmp/pardes-snap/layout-close/cwd Tty+bash Save Mode Filter Collaps | e Del e Del diff --git a/test/snapshots/layout-open.golden b/test/snapshots/layout-open.golden index 91d41790..a3d9dfdd 100644 --- a/test/snapshots/layout-open.golden +++ b/test/snapshots/layout-open.golden @@ -1,5 +1,5 @@ == snap before grid=100x31 cursor=2,9 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol | /tmp/pardes-snap/layout-open/cwd Tty+bash Save /tmp/pardes-snap/layout-open/cwd Tty+bash Save | Mode Filter Collapse Del Mode Filter Collapse Del diff --git a/test/snapshots/leader.golden b/test/snapshots/leader.golden index 6c154c6c..52528cde 100644 --- a/test/snapshots/leader.golden +++ b/test/snapshots/leader.golden @@ -1,5 +1,5 @@ == snap spc grid=100x41 cursor=7,3 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol | /tmp/pardes-snap/leader/cwd/cmds.txt Save Tty Collapse Del | 1 Help SPC diff --git a/test/snapshots/load.golden b/test/snapshots/load.golden index d18fd235..38a6d59b 100644 --- a/test/snapshots/load.golden +++ b/test/snapshots/load.golden @@ -1,5 +1,5 @@ == snap loaded grid=100x31 cursor=4,16 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol | /tmp/pardes-snap/load/cwd Tty+bash Save Mode Fi /tmp/pardes-snap/load/cwd Tty+bash Save Mode Fi | lter Collapse Del lter Collapse Del diff --git a/test/snapshots/logquiet.golden b/test/snapshots/logquiet.golden index 366fc0f7..45b643db 100644 --- a/test/snapshots/logquiet.golden +++ b/test/snapshots/logquiet.golden @@ -1,5 +1,5 @@ == snap quiet grid=100x31 cursor=62,5 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol |$ /tmp/pardes-snap/logquiet/cwd Tty+bash Save Mode Filter Collapse Del | $ ls diff --git a/test/snapshots/look-center.golden b/test/snapshots/look-center.golden index e5db101e..c861bb8f 100644 --- a/test/snapshots/look-center.golden +++ b/test/snapshots/look-center.golden @@ -1,5 +1,5 @@ == snap center-open grid=150x31 cursor=15,12 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol | /tmp/pardes-snap/look-center/cwd Tty+bash Save Mode Filter Collapse Del /tmp/pardes-snap/look-center/cwd Tty+bash Save Mode Filter Collapse Del | ls ls diff --git a/test/snapshots/look-dir.golden b/test/snapshots/look-dir.golden index 7f20fdc6..29e67d5f 100644 --- a/test/snapshots/look-dir.golden +++ b/test/snapshots/look-dir.golden @@ -1,5 +1,5 @@ == snap dir-open grid=100x31 cursor=4,11 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol | /tmp/pardes-snap/look-dir/cwd Tty+bash Save Mod /tmp/pardes-snap/look-dir/cwd Tty+bash Save Mod | e Filter Collapse Del e Filter Collapse Del diff --git a/test/snapshots/look-file-1col.golden b/test/snapshots/look-file-1col.golden index 45f9f20f..81ba4ded 100644 --- a/test/snapshots/look-file-1col.golden +++ b/test/snapshots/look-file-1col.golden @@ -1,5 +1,5 @@ == snap file-open-1col grid=100x31 cursor=14,19 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol | /tmp/pardes-snap/look-file-1col/cwd Tty+bash Save Mode Filter Collapse Del | ls diff --git a/test/snapshots/look-file.golden b/test/snapshots/look-file.golden index 695fd2c1..4d4bbdfe 100644 --- a/test/snapshots/look-file.golden +++ b/test/snapshots/look-file.golden @@ -1,5 +1,5 @@ == snap file-open grid=150x31 cursor=14,12 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol | /tmp/pardes-snap/look-file/cwd Tty+bash Save Mode Filter Collapse Del /tmp/pardes-snap/look-file/cwd Tty+bash Save Mode Filter Collapse Del | ls ls diff --git a/test/snapshots/lookloaded.golden b/test/snapshots/lookloaded.golden index 70b42102..a968a6dc 100644 --- a/test/snapshots/lookloaded.golden +++ b/test/snapshots/lookloaded.golden @@ -1,5 +1,5 @@ == snap file-open grid=100x31 cursor=14,13 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol | /tmp/pardes-snap/lookloaded/cwd Tty+bash Save M /tmp/pardes-snap/lookloaded/cwd Tty+bash Save M | ode Filter Collapse Del ode Filter Collapse Del diff --git a/test/snapshots/lookpanes.golden b/test/snapshots/lookpanes.golden index 98dfd8b9..e0f55f5f 100644 --- a/test/snapshots/lookpanes.golden +++ b/test/snapshots/lookpanes.golden @@ -1,5 +1,5 @@ == snap shells grid=130x51 cursor=122,4 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol | /tmp/pardes-snap/lookpanes/cwd/beta/bmark.txt Save Tty Collaps /tmp/pardes-snap/lookpanes/cwd Tty+bash Save Mode Filter Colla | e Del pse Del diff --git a/test/snapshots/lookrange.golden b/test/snapshots/lookrange.golden index 25306ce1..f57ee457 100644 --- a/test/snapshots/lookrange.golden +++ b/test/snapshots/lookrange.golden @@ -1,5 +1,5 @@ == snap opened grid=150x31 cursor=7,3 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol | /tmp/pardes-snap/lookrange/cwd/look.txt Save Tty Collapse Del | 1 r.txt:3-5 diff --git a/test/snapshots/lsp-client-edit.golden b/test/snapshots/lsp-client-edit.golden index 29ec05af..c36d15be 100644 --- a/test/snapshots/lsp-client-edit.golden +++ b/test/snapshots/lsp-client-edit.golden @@ -1,5 +1,5 @@ == snap formatted grid=100x25 cursor=7,4 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol | * /tmp/pardes-snap/lsp-client-edit/cwd/main.rs Save Tty Collapse Del TreeContext | 1 // formatted by mock formatted 1 range(s) diff --git a/test/snapshots/lsp-client.golden b/test/snapshots/lsp-client.golden index 17eb0d40..23d86e11 100644 --- a/test/snapshots/lsp-client.golden +++ b/test/snapshots/lsp-client.golden @@ -1,5 +1,5 @@ == snap gd-jumped grid=100x25 cursor=16,12 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol | /tmp/pardes-snap/lsp-client/cwd/main.rs Save Tty Collapse Del TreeContext | 1 mod lib; --:--:-- lsp rust-analyzer: ready diff --git a/test/snapshots/lsp-rename.golden b/test/snapshots/lsp-rename.golden index 03fb2311..ba19d8f0 100644 --- a/test/snapshots/lsp-rename.golden +++ b/test/snapshots/lsp-rename.golden @@ -1,5 +1,5 @@ == snap renamed grid=110x25 cursor=17,10 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol | * /tmp/pardes-snap/lsp-rename/cwd/rename.zig Save Tty Collapse Del TreeContext | 1 const std = @import("std"); renamed 2 range(s) diff --git a/test/snapshots/lsp.golden b/test/snapshots/lsp.golden index be0090fb..153ae5cc 100644 --- a/test/snapshots/lsp.golden +++ b/test/snapshots/lsp.golden @@ -1,5 +1,5 @@ == snap opened grid=120x41 cursor=7,3 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol | /tmp/pardes-snap/lsp/cwd/a.zig Save Tty Collapse Del TreeContext | 1 const std = @import("std"); diff --git a/test/snapshots/lspcomplete.golden b/test/snapshots/lspcomplete.golden index 0b29034f..29a81f93 100644 --- a/test/snapshots/lspcomplete.golden +++ b/test/snapshots/lspcomplete.golden @@ -1,5 +1,5 @@ == snap opened grid=120x41 cursor=7,3 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol | /tmp/pardes-snap/lspcomplete/cwd/a.zig Save Tty Collapse Del TreeContext | 1 const Shade = enum { @@ -31,13 +31,13 @@ == snap step grid=120x41 cursor=19,4 |2: * /tmp/pardes-snap/lspcomplete/cwd/a.zig Save Tty Collapse Del TreeContext == snap txtindent grid=120x41 cursor=15,3 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol |^* /tmp/pardes-snap/lspcomplete/cwd/notes.txt Save Tty Collapse Del | 1 abc. def ghi | 2 == snap nosemi grid=100x19 cursor=29,9 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol |^* /tmp/pardes-snap/lspcomplete/cwd/c.zig Save Tty Collapse Del TreeContext | 1 const Shade = enum { @@ -53,7 +53,7 @@ | 2 c.zig:3:5-12 cinnabar cinnabar, | 3 == snap nobrace grid=100x19 cursor=16,10 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol |^* /tmp/pardes-snap/lspcomplete/cwd/d.zig Save Tty Collapse Del TreeContext | 1 const Shade = enum { diff --git a/test/snapshots/lspcompletemoved.golden b/test/snapshots/lspcompletemoved.golden index a033ed56..e759cbd8 100644 --- a/test/snapshots/lspcompletemoved.golden +++ b/test/snapshots/lspcompletemoved.golden @@ -1,5 +1,5 @@ == snap typedthrough grid=120x21 cursor=16,14 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol |^* /tmp/pardes-snap/lspcompletemoved/cwd/a.zig Save Tty Collapse Del TreeContext | 1 const Shade = enum { diff --git a/test/snapshots/lspdebug.golden b/test/snapshots/lspdebug.golden index cf2eb097..650b41b2 100644 --- a/test/snapshots/lspdebug.golden +++ b/test/snapshots/lspdebug.golden @@ -1,5 +1,5 @@ == snap opened grid=120x45 cursor=7,3 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol | /tmp/pardes-snap/lspdebug/cwd/z.zig Save Tty Collapse Del TreeContext | 1 const std = @import("std"); diff --git a/test/snapshots/lsprelpath.golden b/test/snapshots/lsprelpath.golden index 201f6dd4..904e076a 100644 --- a/test/snapshots/lsprelpath.golden +++ b/test/snapshots/lsprelpath.golden @@ -1,5 +1,5 @@ == snap absrow grid=100x35 cursor=16,7 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol |^* /tmp/pardes-snap/lsprelpath/cwd/sub/parent.zig Save Tty Collapse Del TreeContext | 1 const shade = @import("../shade.zig"); @@ -58,7 +58,7 @@ |33: 0-0 d,#608269, 1-99 d,#0d1410, |34: 0-0 d,#608269, 1-99 d,#0d1410, == snap subrow grid=100x35 cursor=16,7 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol |^* /tmp/pardes-snap/lsprelpath/cwd/sub/subdir.zig Save Tty Collapse Del TreeContext | 1 const tint = @import("inner/tint.zig"); diff --git a/test/snapshots/markup.golden b/test/snapshots/markup.golden index 8c712a58..6991cdf6 100644 --- a/test/snapshots/markup.golden +++ b/test/snapshots/markup.golden @@ -1,5 +1,5 @@ == snap typst grid=92x25 cursor=7,3 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol | /tmp/pardes-snap/markup/cwd/paper.typ Save Tty Collapse Del TreeContext | 1 = Typst heading @@ -38,7 +38,7 @@ |23: 0-0 d,#608269, 1-91 d,#0d1410, |24: 0-0 d,#608269, 1-91 d,#0d1410, == snap markdown grid=92x25 cursor=7,3 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol | /tmp/pardes-snap/markup/cwd/notes.md Save Tty Collapse Del TreeContext | 1 # Markdown heading with *italic* diff --git a/test/snapshots/mini.golden b/test/snapshots/mini.golden index cc8dd612..8d0205f7 100644 --- a/test/snapshots/mini.golden +++ b/test/snapshots/mini.golden @@ -1,5 +1,5 @@ == snap opened grid=90x23 cursor=7,6 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol | /tmp/pardes-snap/mini/cwd/commands.txt Save Tty Collapse Del | 1 @`Mini demo.zig` Mini @@ -34,8 +34,8 @@ |21: 0-0 d,#608269, 1-89 d,#0d1410, |22: 0-0 d,#608269, 1-89 d,#0d1410, == 9p opened grid=90x23 cursor=7,6,block -|0: Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit -@0: 0-70 #b2c3b8,#1d2824,,tagline 71-89 d,#1d2824,,tagline +|0: Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +@0: 0-74 #b2c3b8,#1d2824,,tagline 75-89 d,#1d2824,,tagline |1: New Tty Find Grep Joincol Delcol @1: 0-1 #ffffff,#887455,,tagline 2-2 d,#314738,,tagline 3-34 #becfc4,#314738,,tagline 35-89 d,#314738,,tagline |2: /tmp/pardes-snap/mini/cwd/commands.txt Save Tty Collapse Del @@ -105,7 +105,7 @@ |7: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-8 #b9f480,#0d1410, 9-11 #c9a7ed,#0d1410, 12-89 #b9f480,#0d1410, |8: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-17 #e5eee5,#0d1410, 18-19 #f8c082,#0d1410, 20-89 #e5eee5,#0d1410, == snap resized grid=105x27 cursor=7,7 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol | /tmp/pardes-snap/mini/cwd/commands.txt Save Tty Collapse Del | 1 @`Mini demo.zig` @@ -117,8 +117,8 @@ | 3 ⠉⠉⠁⠉⠉⠉⠈⠈⠉⠉⠉⠉⠉⠉ | 4 == 9p resized grid=105x27 cursor=7,7,block -|0: Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit -@0: 0-70 #b2c3b8,#1d2824,,tagline 71-104 d,#1d2824,,tagline +|0: Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +@0: 0-74 #b2c3b8,#1d2824,,tagline 75-104 d,#1d2824,,tagline |1: New Tty Find Grep Joincol Delcol @1: 0-1 #ffffff,#887455,,tagline 2-2 d,#314738,,tagline 3-34 #becfc4,#314738,,tagline 35-104 d,#314738,,tagline |2: /tmp/pardes-snap/mini/cwd/commands.txt Save Tty Collapse Del diff --git a/test/snapshots/modal.golden b/test/snapshots/modal.golden index 4ade84f2..6dc6376d 100644 --- a/test/snapshots/modal.golden +++ b/test/snapshots/modal.golden @@ -1,5 +1,5 @@ == snap top grid=100x31 cursor=2,4 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol | /tmp/pardes-snap/modal/cwd Tty+bash Save Mode F /tmp/pardes-snap/modal/cwd Tty+bash Save Mode F | ilter Collapse Del ilter Collapse Del diff --git a/test/snapshots/msg.golden b/test/snapshots/msg.golden index ff7b39a0..caa234d3 100644 --- a/test/snapshots/msg.golden +++ b/test/snapshots/msg.golden @@ -1,5 +1,5 @@ == snap opened grid=70x15 cursor=7,3 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exi +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug | New Tty Find Grep Joincol Delcol | /tmp/pardes-snap/msg/cwd/a.txt Save Tty Collapse Del | 1 line 1 @@ -12,7 +12,7 @@ == snap saved grid=70x15 cursor=7,3 |3: 1 line 1 --:--:-- saved /tmp/pardes-snap/msg/cwd/a.txt == snap repainted grid=70x17 cursor=7,3 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exi +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug | New Tty Find Grep Joincol Delcol | /tmp/pardes-snap/msg/cwd/a.txt Save Tty Collapse Del | 1 line 1 --:--:-- saved /tmp/pardes-snap/msg/cwd/a.txt diff --git a/test/snapshots/multicursor.golden b/test/snapshots/multicursor.golden index c3d5dbe2..0b3bbcb2 100644 --- a/test/snapshots/multicursor.golden +++ b/test/snapshots/multicursor.golden @@ -1,5 +1,5 @@ == snap three-cursors grid=150x31 cursor=7,9 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol | /tmp/pardes-snap/multicursor/cwd Tty+bash Save Mode Filter Collapse Del /tmp/pardes-snap/multicursor/cwd Tty+bash Save Mode Filter Collapse Del | ls ls diff --git a/test/snapshots/nested.golden b/test/snapshots/nested.golden index 9758c491..07d6148d 100644 --- a/test/snapshots/nested.golden +++ b/test/snapshots/nested.golden @@ -1,5 +1,5 @@ == snap file-arg grid=100x31 cursor=7,6 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol |$ /tmp/pardes-snap/nested/cwd Tty+bash Save Mode Filter Collapse Del | $ $(readlink /proc/$PPID/exe) nested.txt @@ -23,7 +23,7 @@ | /tmp/pardes-snap/nested/cwd/+New Save Tty Collapse Del | 1 == snap no-arg grid=100x31 cursor=4,7 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol |$ /tmp/pardes-snap/nested/cwd Tty+bash Save Mode Filter Collapse Del | $ $(readlink /proc/$PPID/exe) @@ -47,7 +47,7 @@ | /tmp/pardes-snap/nested/cwd/+New Save Tty Collapse Del | 1 == snap dir-arg grid=100x31 cursor=4,8 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol |$ /tmp/pardes-snap/nested/cwd Tty+bash Save Mode Filter Collapse Del | $ $(readlink /proc/$PPID/exe) nestdir diff --git a/test/snapshots/ninep.golden b/test/snapshots/ninep.golden index f3733ab4..c6b5f0af 100644 --- a/test/snapshots/ninep.golden +++ b/test/snapshots/ninep.golden @@ -1,5 +1,5 @@ == snap opened grid=90x15 cursor=7,3 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol | /tmp/pardes-snap/ninep/cwd/demo.zig Save Tty Collapse Del TreeContext | 1 const greeting = "café λ 界 é"; @@ -26,8 +26,8 @@ |13: 0-0 d,#608269, 1-89 d,#0d1410, |14: 0-0 d,#608269, 1-89 d,#0d1410, == 9p opened grid=90x15 cursor=7,3,block -|0: Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit -@0: 0-70 #b2c3b8,#1d2824,,tagline 71-89 d,#1d2824,,tagline +|0: Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +@0: 0-74 #b2c3b8,#1d2824,,tagline 75-89 d,#1d2824,,tagline |1: New Tty Find Grep Joincol Delcol @1: 0-1 #ffffff,#887455,,tagline 2-2 d,#314738,,tagline 3-34 #becfc4,#314738,,tagline 35-89 d,#314738,,tagline |2: /tmp/pardes-snap/ninep/cwd/demo.zig Save Tty Collapse Del TreeContext @@ -148,8 +148,8 @@ |18: 0-0 d,#608269, 1-104 d,#0d1410, |19: 0-0 d,#608269, 1-104 d,#0d1410, == 9p resized grid=105x20 cursor=7,4,block -|0: Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit -@0: 0-70 #b2c3b8,#1d2824,,tagline 71-104 d,#1d2824,,tagline +|0: Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +@0: 0-74 #b2c3b8,#1d2824,,tagline 75-104 d,#1d2824,,tagline |1: New Tty Find Grep Joincol Delcol @1: 0-1 #ffffff,#887455,,tagline 2-2 d,#314738,,tagline 3-34 #becfc4,#314738,,tagline 35-104 d,#314738,,tagline |2: * /tmp/pardes-snap/ninep/cwd/demo.zig Save Tty Collapse Del TreeContext @@ -191,7 +191,7 @@ |19: @19: 0-0 d,#608269,,body 1-1 d,#0d1410,,body 2-6 #59675c,#0d1410,,body 7-104 d,#0d1410,,body == snap resized grid=105x20 cursor=7,4 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol | * /tmp/pardes-snap/ninep/cwd/demo.zig Save Tty Collapse Del TreeContext | 1 // café λ 界 Colors diff --git a/test/snapshots/pipe.golden b/test/snapshots/pipe.golden index b7a8da86..2fd54c27 100644 --- a/test/snapshots/pipe.golden +++ b/test/snapshots/pipe.golden @@ -1,5 +1,5 @@ == snap prompt grid=180x13 cursor=179,3 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol | /tmp/pardes-snap/pipe/cwd/pipe.txt Save Tty Collapse Del | 1 alpha beta |tr a-z A-Z diff --git a/test/snapshots/psearch.golden b/test/snapshots/psearch.golden index 544086c5..e830a206 100644 --- a/test/snapshots/psearch.golden +++ b/test/snapshots/psearch.golden @@ -1,5 +1,5 @@ == snap output grid=140x31 cursor=4,9 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol | /tmp/pardes-snap/psearch/cwd Tty+bash Save Mode Filter Collapse Del | printf 'x MA''RK a\nzz\nx MA''RK b\nzz\nx MA''RK c\n' diff --git a/test/snapshots/reflow.golden b/test/snapshots/reflow.golden index afd4b93f..17c42d0d 100644 --- a/test/snapshots/reflow.golden +++ b/test/snapshots/reflow.golden @@ -1,5 +1,5 @@ == snap widened grid=200x25 cursor=4,16 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol |$ /tmp/pardes-snap/reflow/cwd Tty+bash Save Mode Filter Collapse Del | yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy diff --git a/test/snapshots/respawn.golden b/test/snapshots/respawn.golden index d6d21a81..1e6425d2 100644 --- a/test/snapshots/respawn.golden +++ b/test/snapshots/respawn.golden @@ -1,5 +1,5 @@ == snap respawn grid=140x31 cursor=4,9 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol | /tmp/pardes-snap/respawn/cwd Tty+bash Save Mode Filter Collapse Del /tmp/pardes-snap/respawn/cwd Tty+bash Save Mode Filter Collapse Del | ls ls diff --git a/test/snapshots/restore.golden b/test/snapshots/restore.golden index af2b82c1..0bb53676 100644 --- a/test/snapshots/restore.golden +++ b/test/snapshots/restore.golden @@ -1,5 +1,5 @@ == snap dumped grid=100x31 cursor=4,6 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit Restore /tmp/pardes-snap/res +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit Restore /tmp/pardes-snap | New Tty Find Grep Joincol Delcol |$ /tmp/pardes-snap/restore/cwd Tty+bash Save Mode Filter Collapse Del | $ ls Dump diff --git a/test/snapshots/rsearch.golden b/test/snapshots/rsearch.golden index 89c4f7bd..eb98853a 100644 --- a/test/snapshots/rsearch.golden +++ b/test/snapshots/rsearch.golden @@ -1,5 +1,5 @@ == snap opened grid=210x31 cursor=7,7 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol | /tmp/pardes-snap/rsearch/cwd Tty+bash Save Mode Filter Collapse Del | ls diff --git a/test/snapshots/savepane.golden b/test/snapshots/savepane.golden index 8660a437..bea7146b 100644 --- a/test/snapshots/savepane.golden +++ b/test/snapshots/savepane.golden @@ -1,5 +1,5 @@ == snap scratch grid=100x31 cursor=20,18 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol | /tmp/pardes-snap/savepane/cwd Tty+bash Save Mode Filter Collapse Del | ls diff --git a/test/snapshots/scroll.golden b/test/snapshots/scroll.golden index 9250590a..44b6b264 100644 --- a/test/snapshots/scroll.golden +++ b/test/snapshots/scroll.golden @@ -1,5 +1,5 @@ == snap bottom grid=100x31 cursor=4,16 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol | /tmp/pardes-snap/scroll/cwd Tty+bash Save Mode /tmp/pardes-snap/scroll/cwd Tty+bash Save Mode | Filter Collapse Del Filter Collapse Del diff --git a/test/snapshots/scrolloff.golden b/test/snapshots/scrolloff.golden index 17ca7e7b..299df49d 100644 --- a/test/snapshots/scrolloff.golden +++ b/test/snapshots/scrolloff.golden @@ -1,5 +1,5 @@ == snap top grid=210x16 cursor=7,7 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol | /tmp/pardes-snap/scrolloff/cwd Tty+bash Save Mode Filter Collapse Del | ls diff --git a/test/snapshots/selarg.golden b/test/snapshots/selarg.golden index f41c355b..741864ef 100644 --- a/test/snapshots/selarg.golden +++ b/test/snapshots/selarg.golden @@ -1,5 +1,5 @@ == snap kept grid=100x31 cursor=6,4 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol | /tmp/pardes-snap/selarg/cwd Tty+bash Save Mode /tmp/pardes-snap/selarg/cwd Tty+bash Save Mode | Filter Collapse Del Filter Collapse Del diff --git a/test/snapshots/selregex.golden b/test/snapshots/selregex.golden index c99d48e1..e3f3b2d7 100644 --- a/test/snapshots/selregex.golden +++ b/test/snapshots/selregex.golden @@ -1,5 +1,5 @@ == snap prompt-armed grid=160x25 cursor=159,3 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol | /tmp/pardes-snap/selregex/cwd/m.zig Save Tty Collapse Del TreeContext | 1 const one = 1; Select / diff --git a/test/snapshots/shellset.golden b/test/snapshots/shellset.golden index 0d13f017..9d566be7 100644 --- a/test/snapshots/shellset.golden +++ b/test/snapshots/shellset.golden @@ -1,5 +1,5 @@ == snap boot grid=90x21 cursor=7,3 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol | /tmp/pardes-snap/shellset/cwd/cmd.txt Save Tty Collapse Del | 1 Shell zznosuchshell diff --git a/test/snapshots/shrinktag.golden b/test/snapshots/shrinktag.golden index 9aa29e11..d73c0072 100644 --- a/test/snapshots/shrinktag.golden +++ b/test/snapshots/shrinktag.golden @@ -1,5 +1,5 @@ == snap before grid=100x31 cursor=2,9 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol | /tmp/pardes-snap/shrinktag/cwd Tty+bash Save Mo /tmp/pardes-snap/shrinktag/cwd Tty+bash Save Mo | de Filter Collapse Del de Filter Collapse Del diff --git a/test/snapshots/splitparent.golden b/test/snapshots/splitparent.golden index e626cea7..f83bbb66 100644 --- a/test/snapshots/splitparent.golden +++ b/test/snapshots/splitparent.golden @@ -1,5 +1,5 @@ == snap shrunk grid=100x31 cursor=4,5 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol | /tmp/pardes-snap/splitparent/cwd Tty+bash Save /tmp/pardes-snap/splitparent/cwd Tty+bash Save | Mode Filter Collapse Del Mode Filter Collapse Del @@ -13,14 +13,14 @@ |11: Mode Filter Collapse Del |12: ls == snap tallest grid=100x6 cursor=4,5 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol | /tmp/pardes-snap/splitparent/cwd Tty+bash Save /tmp/pardes-snap/splitparent/cwd Tty+bash Save | /tmp/pardes-snap/splitparent/cwd Tty+bash Save Mode Filter Collapse Del | /tmp/pardes-snap/splitparent/cwd Tty+bash Save ls | e in that column: each keeps its tag and 2 rows == snap regrown grid=100x31 cursor=4,13 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol | /tmp/pardes-snap/splitparent/cwd Tty+bash Save /tmp/pardes-snap/splitparent/cwd Tty+bash Save | Mode Filter Collapse Del Mode Filter Collapse Del diff --git a/test/snapshots/stepgrain.golden b/test/snapshots/stepgrain.golden index bdd506e9..7c445492 100644 --- a/test/snapshots/stepgrain.golden +++ b/test/snapshots/stepgrain.golden @@ -1,5 +1,5 @@ == snap results grid=150x31 cursor=7,3 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol | /tmp/pardes-snap/stepgrain/cwd/a.txt Save Tty Collapse Del | 1 hello ZQMARK one diff --git a/test/snapshots/syntax.golden b/test/snapshots/syntax.golden index 096dab27..2f7a6b74 100644 --- a/test/snapshots/syntax.golden +++ b/test/snapshots/syntax.golden @@ -1,5 +1,5 @@ == snap zig-open grid=150x31 cursor=7,7 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol | /tmp/pardes-snap/syntax/cwd Tty+bash Save Mode Filter Collapse Del /tmp/pardes-snap/syntax/cwd Tty+bash Save Mode Filter Collapse Del | ls ls diff --git a/test/snapshots/tag.golden b/test/snapshots/tag.golden index 0f9af5dc..0d20859a 100644 --- a/test/snapshots/tag.golden +++ b/test/snapshots/tag.golden @@ -1,5 +1,5 @@ == snap tag-focus grid=150x31 cursor=36,2 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol | /tmp/pardes-snap/tag/cwd Tty+bash Save Mode Filter Collapse Del /tmp/pardes-snap/tag/cwd Tty+bash Save Mode Filter Collapse Del | ls ls diff --git a/test/snapshots/tagalign.golden b/test/snapshots/tagalign.golden index 8a522ced..a557ff95 100644 --- a/test/snapshots/tagalign.golden +++ b/test/snapshots/tagalign.golden @@ -1,5 +1,5 @@ == snap aligned grid=100x31 cursor=4,9 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol | /tmp/pardes-snap/tagalign/cwd/deep/nested-project-directory/document.txt Save Tty Collapse Del | 1 alpha @@ -9,7 +9,7 @@ | ls | deep == snap fits grid=87x31 cursor=4,9 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol | /tmp/pardes-snap/tagalign/cwd/deep/nested-project-directory/document.txt Save Tty Co | llapse Del @@ -19,7 +19,7 @@ | ls | deep == snap overby1 grid=86x31 cursor=4,9 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol | /tmp/pardes-snap/tagalign/cwd/deep/nested-project-directory/document.txt Save Tty C | ollapse Del @@ -29,7 +29,7 @@ | ls | deep == snap clicked grid=100x31 cursor=11,2 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol | /tmp/pardes-snap/tagalign/cwd/deep/nested-project-directory/document.txt Save Tty Collapse Del | 1 alpha @@ -39,7 +39,7 @@ | ls | deep == snap revealed grid=70x31 cursor=30,3 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exi +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug | New Tty Find Grep Joincol Delcol | /tmp/pardes-snap/tagalign/cwd/deep/nested-project-directory/documen | t.txt Save Tty Collapse Del diff --git a/test/snapshots/tagalign2col.golden b/test/snapshots/tagalign2col.golden index a35edccb..129141b6 100644 --- a/test/snapshots/tagalign2col.golden +++ b/test/snapshots/tagalign2col.golden @@ -1,5 +1,5 @@ == snap onecol grid=160x31 cursor=7,4 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol | /tmp/pardes-snap/tagalign2col/cwd/deep/proj/document.txt Save Tty Collapse De /tmp/pardes-snap/tagalign2col/cwd Tty+bash Save Mode Filter Collapse Del | l ls Left diff --git a/test/snapshots/tagbottom.golden b/test/snapshots/tagbottom.golden index d5f1f720..8469c741 100644 --- a/test/snapshots/tagbottom.golden +++ b/test/snapshots/tagbottom.golden @@ -1,5 +1,5 @@ == snap boot grid=100x31 cursor=7,3 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol | /tmp/pardes-snap/tagbottom/cwd/top.txt Save Tty Collapse Del | 1 aaa diff --git a/test/snapshots/tagbottomimage.golden b/test/snapshots/tagbottomimage.golden index 89e96f6b..2bf9231e 100644 --- a/test/snapshots/tagbottomimage.golden +++ b/test/snapshots/tagbottomimage.golden @@ -1,5 +1,5 @@ == snap img-top grid=150x31 cursor=11,8 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol | /tmp/pardes-snap/tagbottomimage/cwd Tty+bash Save Mode Filter Collapse Del | ls diff --git a/test/snapshots/tagbottomshort.golden b/test/snapshots/tagbottomshort.golden index 3fd3b180..efa8b3f1 100644 --- a/test/snapshots/tagbottomshort.golden +++ b/test/snapshots/tagbottomshort.golden @@ -1,5 +1,5 @@ == snap roomy grid=80x11 cursor=79,2 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol | 1 one /ZZ | 2 two @@ -11,21 +11,21 @@ | | /tmp/pardes-snap/tagbottomshort/cwd/s.txt Save Tty Collapse Del == snap two-body grid=80x5 cursor=79,2 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol | 1 one /ZZ | 2 two | /tmp/pardes-snap/tagbottomshort/cwd/s.txt Save Tty Collapse Del == snap one-body grid=80x4 cursor=79,2 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol | 1 one /ZZ | /tmp/pardes-snap/tagbottomshort/cwd/s.txt Save Tty Collapse Del == snap tag-only grid=80x2 cursor=79,1 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | /tmp/pardes-snap/tagbottomshort/cwd/s.txt Save Tty Collapse Del == snap regrown grid=80x11 cursor=79,2 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol | 1 one /ZZ | 2 two @@ -37,7 +37,7 @@ | | /tmp/pardes-snap/tagbottomshort/cwd/s.txt Save Tty Collapse Del == snap leader-one-body grid=80x4 cursor=7,2 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol | 1 one SPC | /tmp/pardes-snap/tagbottomshort/cwd/s.txt Save Tty Collapse Del diff --git a/test/snapshots/tagcmd.golden b/test/snapshots/tagcmd.golden index 8f1dc8d2..2c1ca73f 100644 --- a/test/snapshots/tagcmd.golden +++ b/test/snapshots/tagcmd.golden @@ -1,5 +1,5 @@ == snap edited grid=100x31 cursor=13,3 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol | * /tmp/pardes-snap/tagcmd/cwd/c.txt Save Tty Collapse Del | 1 ZZEDITline 1 diff --git a/test/snapshots/tagnav.golden b/test/snapshots/tagnav.golden index e06c578e..a86854a9 100644 --- a/test/snapshots/tagnav.golden +++ b/test/snapshots/tagnav.golden @@ -1,5 +1,5 @@ == snap start grid=100x31 cursor=7,4 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol | /tmp/pardes-snap/tagnav/cwd/w.txt Save Tty Coll /tmp/pardes-snap/tagnav/cwd Tty+bash Save Mode | apse Del Filter Collapse Del @@ -34,13 +34,13 @@ |4: 1 alpha ls == snap workspace-tag grid=100x31 cursor=0,0 |4: 1 alpha Up ls -== snap topbar-dollar grid=100x31 cursor=70,0 +== snap topbar-dollar grid=100x31 cursor=74,0 |4: 1 alpha ls == snap topbar-dump-word grid=100x31 cursor=46,0 == snap topbar-exec grid=100x31 cursor=7,4 -|0: Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit Restore /tmp/pardes-snap/tag +|0: Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit Restore /tmp/pardes-snap |4: 1 alpha Dump ls -== snap topbar-restore-word grid=100x31 cursor=72,0 +== snap topbar-restore-word grid=100x31 cursor=76,0 |4: 1 alpha ls == snap topbar-restored grid=100x31 cursor=7,4 |4: 1 alpha $ ls diff --git a/test/snapshots/tagnav.snap b/test/snapshots/tagnav.snap index f145480e..2f5906bb 100644 --- a/test/snapshots/tagnav.snap +++ b/test/snapshots/tagnav.snap @@ -93,7 +93,7 @@ snap column-word key c-w k stable 400 5000 snap workspace-tag -# `$` is the last cell; four long-word steps back land on `Dump`, and the +# `$` is the last cell; five long-word steps back land on `Dump`, and the # execute key runs it and gives the keyboard back to the body FIRST -- `Exit` # lives up here too, so a builtin that frees the session must never return # into a focused header. Dump grows a `Restore ` word, which is also the @@ -101,7 +101,7 @@ snap workspace-tag key g l stable 400 5000 snap topbar-dollar -key B B B B +key B B B B B stable 400 5000 snap topbar-dump-word key tab diff --git a/test/snapshots/tagpath.golden b/test/snapshots/tagpath.golden index 6f082c7a..1216bdeb 100644 --- a/test/snapshots/tagpath.golden +++ b/test/snapshots/tagpath.golden @@ -1,5 +1,5 @@ == snap start grid=100x31 cursor=7,3 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol | /tmp/pardes-snap/tagpath/cwd/c.txt Save Tty Collapse Del | 1 line 1 diff --git a/test/snapshots/theme.golden b/test/snapshots/theme.golden index 443d639c..351f8905 100644 --- a/test/snapshots/theme.golden +++ b/test/snapshots/theme.golden @@ -1,5 +1,5 @@ -== snap orchard grid=100x31 cursor=4,6 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +== snap orchard grid=100x31 cursor=85,0 +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit NextColor | New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol | /tmp/pardes-snap/theme/cwd Tty+bash Save Mode F /tmp/pardes-snap/theme/cwd Tty+bash Save Mode F | ilter Collapse Del ilter Collapse Del @@ -55,7 +55,7 @@ == snap dusk grid=100x31 cursor=4,6 |4: ls NextColor ls == style dusk grid=100x31 -|0: 0-50 #c6b6c5,#2c2630, 51-59 #fff0eb,#654053, 60-60 #fff0eb,#2c2630, 61-99 #c6b6c5,#2c2630, +|0: 0-75 #c6b6c5,#2c2630, 76-84 #fff0eb,#654053, 85-99 #fff0eb,#2c2630, |1: 0-1 d,#757a5f, 2-2 d,#533d4d, 3-49 #d2c2d1,#533d4d, 50-51 #d2c2d1,#757a5f, 52-52 #d2c2d1,#2c2630, 53-99 #c6b6c5,#2c2630, |2: 0-1 d,#edb092, 2-2 d,#533d4d, 3-29 #d2c2d1,#533d4d, 30-38 #a1d5c4,#533d4d, 39-49 #d2c2d1,#533d4d, 50-51 #d2c2d1,#745469, 52-52 #d2c2d1,#2c2630, 53-79 #c6b6c5,#2c2630, 80-88 #96c9b8,#2c2630, 89-99 #c6b6c5,#2c2630, |3: 0-2 d,#533d4d, 3-49 #d2c2d1,#533d4d, 50-52 #d2c2d1,#2c2630, 53-99 #c6b6c5,#2c2630, @@ -88,7 +88,7 @@ |30: 0-0 d,#8e667c, 1-49 d,#39323b, 50-50 d,#8e667c, 51-99 d,#39323b, == snap ink grid=100x31 cursor=4,6 == style ink grid=100x31 -|0: 0-50 #d5e4f1,#15212c, 51-59 #ffffff,#1b547c, 60-60 #ffffff,#15212c, 61-99 #d5e4f1,#15212c, +|0: 0-75 #d5e4f1,#15212c, 76-84 #ffffff,#1b547c, 85-99 #ffffff,#15212c, |1: 0-1 d,#8f7d5b, 2-2 d,#2b4051, 3-49 #e1eef9,#2b4051, 50-51 #e1eef9,#8f7d5b, 52-52 #e1eef9,#15212c, 53-99 #d5e4f1,#15212c, |2: 0-1 d,#86d8ff, 2-2 d,#2b4051, 3-29 #e1eef9,#2b4051, 30-38 #ffeab8,#2b4051, 39-49 #e1eef9,#2b4051, 50-51 #e1eef9,#5f7990, 52-52 #e1eef9,#15212c, 53-79 #d5e4f1,#15212c, 80-88 #f5e0ac,#15212c, 89-99 #d5e4f1,#15212c, |3: 0-2 d,#2b4051, 3-49 #e1eef9,#2b4051, 50-52 #e1eef9,#15212c, 53-99 #d5e4f1,#15212c, @@ -121,7 +121,7 @@ |30: 0-0 d,#86a8c2, 1-49 d,#000000, 50-50 d,#86a8c2, 51-99 d,#000000, == snap paper grid=100x31 cursor=4,6 == style paper grid=100x31 -|0: 0-50 #52625a,#e8eae3, 51-59 #203e31,#c5e2d0, 60-60 #203e31,#e8eae3, 61-99 #52625a,#e8eae3, +|0: 0-75 #52625a,#e8eae3, 76-84 #203e31,#c5e2d0, 85-99 #203e31,#e8eae3, |1: 0-1 d,#bda27e, 2-2 d,#bdd8ca, 3-49 #4a5a52,#bdd8ca, 50-51 #4a5a52,#bda27e, 52-52 #4a5a52,#e8eae3, 53-99 #52625a,#e8eae3, |2: 0-1 d,#367157, 2-2 d,#bdd8ca, 3-29 #4a5a52,#bdd8ca, 30-38 #69447a,#bdd8ca, 39-49 #4a5a52,#bdd8ca, 50-51 #4a5a52,#8fa594, 52-52 #4a5a52,#e8eae3, 53-79 #52625a,#e8eae3, 80-88 #724c83,#e8eae3, 89-99 #52625a,#e8eae3, |3: 0-2 d,#bdd8ca, 3-49 #4a5a52,#bdd8ca, 50-52 #4a5a52,#e8eae3, 53-99 #52625a,#e8eae3, @@ -154,7 +154,7 @@ |30: 0-0 d,#869d8a, 1-49 d,#f5f3ed, 50-50 d,#869d8a, 51-99 d,#f5f3ed, == snap daybreak grid=100x31 cursor=4,6 == style daybreak grid=100x31 -|0: 0-50 #29465e,#edf2f7, 51-59 #10364f,#b9dffb, 60-60 #10364f,#edf2f7, 61-99 #29465e,#edf2f7, +|0: 0-75 #29465e,#edf2f7, 76-84 #10364f,#b9dffb, 85-99 #10364f,#edf2f7, |1: 0-1 d,#b79a7a, 2-2 d,#c7dcec, 3-49 #213e56,#c7dcec, 50-51 #213e56,#b79a7a, 52-52 #213e56,#edf2f7, 53-99 #29465e,#edf2f7, |2: 0-1 d,#006198, 2-2 d,#c7dcec, 3-29 #213e56,#c7dcec, 30-38 #52255f,#c7dcec, 39-49 #213e56,#c7dcec, 50-51 #213e56,#7b9eb7, 52-52 #213e56,#edf2f7, 53-79 #29465e,#edf2f7, 80-88 #5a2d67,#edf2f7, 89-99 #29465e,#edf2f7, |3: 0-2 d,#c7dcec, 3-49 #213e56,#c7dcec, 50-52 #213e56,#edf2f7, 53-99 #29465e,#edf2f7, @@ -187,7 +187,7 @@ |30: 0-0 d,#6685a0, 1-49 d,#ffffff, 50-50 d,#6685a0, 51-99 d,#ffffff, == snap atelier grid=100x31 cursor=4,6 == style atelier grid=100x31 -|0: 0-50 #3d6055,#e4f0ed, 51-59 #35492d,#edf2a5, 60-60 #35492d,#e4f0ed, 61-99 #3d6055,#e4f0ed, +|0: 0-75 #3d6055,#e4f0ed, 76-84 #35492d,#edf2a5, 85-99 #35492d,#e4f0ed, |1: 0-1 d,#bca481, 2-2 d,#bfdcce, 3-49 #35584d,#bfdcce, 50-51 #35584d,#bca481, 52-52 #35584d,#e4f0ed, 53-99 #3d6055,#e4f0ed, |2: 0-1 d,#36826b, 2-2 d,#bfdcce, 3-29 #35584d,#bfdcce, 30-38 #653f6b,#bfdcce, 39-49 #35584d,#bfdcce, 50-51 #35584d,#95baa2, 52-52 #35584d,#e4f0ed, 53-79 #3d6055,#e4f0ed, 80-88 #6e4774,#e4f0ed, 89-99 #3d6055,#e4f0ed, |3: 0-2 d,#bfdcce, 3-49 #35584d,#bfdcce, 50-52 #35584d,#e4f0ed, 53-99 #3d6055,#e4f0ed, @@ -225,7 +225,7 @@ == snap forge grid=100x31 cursor=4,6 |4: ls NextColor ls == style forge grid=100x31 -|0: 0-50 #c5c9d2,#22252b, 51-59 #e2eef4,#1c5172, 60-60 #e2eef4,#22252b, 61-99 #c5c9d2,#22252b, +|0: 0-75 #c5c9d2,#22252b, 76-84 #e2eef4,#1c5172, 85-99 #e2eef4,#22252b, |1: 0-1 d,#6a7b67, 2-2 d,#374253, 3-49 #d1d5de,#374253, 50-51 #d1d5de,#6a7b67, 52-52 #d1d5de,#22252b, 53-99 #c5c9d2,#22252b, |2: 0-1 d,#9cc3f7, 2-2 d,#374253, 3-29 #d1d5de,#374253, 30-38 #f8cba7,#374253, 39-49 #d1d5de,#374253, 50-51 #d1d5de,#55647b, 52-52 #d1d5de,#22252b, 53-79 #c5c9d2,#22252b, 80-88 #ecbf9b,#22252b, 89-99 #c5c9d2,#22252b, |3: 0-2 d,#374253, 3-49 #d1d5de,#374253, 50-52 #d1d5de,#22252b, 53-99 #c5c9d2,#22252b, @@ -258,7 +258,7 @@ |30: 0-0 d,#708095, 1-49 d,#0c0c0e, 50-50 d,#708095, 51-99 d,#0c0c0e, == snap lagoon grid=100x31 cursor=4,6 == style lagoon grid=100x31 -|0: 0-50 #bbd7cb,#29443f, 51-59 #e6f2f3,#325f6c, 60-60 #e6f2f3,#29443f, 61-99 #bbd7cb,#29443f, +|0: 0-75 #bbd7cb,#29443f, 76-84 #e6f2f3,#325f6c, 85-99 #e6f2f3,#29443f, |1: 0-1 d,#9a7662, 2-2 d,#3a6154, 3-49 #c7e3d7,#3a6154, 50-51 #c7e3d7,#9a7662, 52-52 #c7e3d7,#29443f, 53-99 #bbd7cb,#29443f, |2: 0-1 d,#81cfb7, 2-2 d,#3a6154, 3-29 #c7e3d7,#3a6154, 30-38 #f0cef8,#3a6154, 39-49 #c7e3d7,#3a6154, 50-51 #c7e3d7,#548372, 52-52 #c7e3d7,#29443f, 53-79 #bbd7cb,#29443f, 80-88 #e4c2ec,#29443f, 89-99 #bbd7cb,#29443f, |3: 0-2 d,#3a6154, 3-49 #c7e3d7,#3a6154, 50-52 #c7e3d7,#29443f, 53-99 #bbd7cb,#29443f, @@ -291,7 +291,7 @@ |30: 0-0 d,#6e9b8b, 1-49 d,#34464c, 50-50 d,#6e9b8b, 51-99 d,#34464c, == snap solarium grid=100x31 cursor=4,6 == style solarium grid=100x31 -|0: 0-50 #c7d4bd,#123f43, 51-59 #eee8d5,#1f5c64, 60-60 #eee8d5,#123f43, 61-99 #c7d4bd,#123f43, +|0: 0-75 #c7d4bd,#123f43, 76-84 #eee8d5,#1f5c64, 85-99 #eee8d5,#123f43, |1: 0-1 d,#347a9a, 2-2 d,#2f5c5c, 3-49 #d3e0c9,#2f5c5c, 50-51 #d3e0c9,#347a9a, 52-52 #d3e0c9,#123f43, 53-99 #c7d4bd,#123f43, |2: 0-1 d,#e1c266, 2-2 d,#2f5c5c, 3-29 #d3e0c9,#2f5c5c, 30-38 #f5cdec,#2f5c5c, 39-49 #d3e0c9,#2f5c5c, 50-51 #d3e0c9,#467f76, 52-52 #d3e0c9,#123f43, 53-79 #c7d4bd,#123f43, 80-88 #e9c1e0,#123f43, 89-99 #c7d4bd,#123f43, |3: 0-2 d,#2f5c5c, 3-49 #d3e0c9,#2f5c5c, 50-52 #d3e0c9,#123f43, 53-99 #c7d4bd,#123f43, @@ -324,7 +324,7 @@ |30: 0-0 d,#65978c, 1-49 d,#173e45, 50-50 d,#65978c, 51-99 d,#173e45, == snap spectrum grid=100x31 cursor=4,6 == style spectrum grid=100x31 -|0: 0-50 #ddd8bb,#3b3830, 51-59 #fcfcfa,#513f60, 60-60 #fcfcfa,#3b3830, 61-99 #ddd8bb,#3b3830, +|0: 0-75 #ddd8bb,#3b3830, 76-84 #fcfcfa,#513f60, 85-99 #fcfcfa,#3b3830, |1: 0-1 d,#706596, 2-2 d,#5a523a, 3-49 #e9e4c7,#5a523a, 50-51 #e9e4c7,#706596, 52-52 #e9e4c7,#3b3830, 53-99 #ddd8bb,#3b3830, |2: 0-1 d,#ffd866, 2-2 d,#5a523a, 3-29 #e9e4c7,#5a523a, 30-38 #d7e3ff,#5a523a, 39-49 #e9e4c7,#5a523a, 50-51 #e9e4c7,#92844f, 52-52 #e9e4c7,#3b3830, 53-79 #ddd8bb,#3b3830, 80-88 #c5d7ff,#3b3830, 89-99 #ddd8bb,#3b3830, |3: 0-2 d,#5a523a, 3-49 #e9e4c7,#5a523a, 50-52 #e9e4c7,#3b3830, 53-99 #ddd8bb,#3b3830, @@ -357,7 +357,7 @@ |30: 0-0 d,#948d6f, 1-49 d,#100e11, 50-50 d,#948d6f, 51-99 d,#100e11, == snap harvest grid=100x31 cursor=4,6 == style harvest grid=100x31 -|0: 0-50 #d5d8b8,#343b2e, 51-59 #f3f2cc,#4f5834, 60-60 #f3f2cc,#343b2e, 61-99 #d5d8b8,#343b2e, +|0: 0-75 #d5d8b8,#343b2e, 76-84 #f3f2cc,#4f5834, 85-99 #f3f2cc,#343b2e, |1: 0-1 d,#9b583f, 2-2 d,#4a583e, 3-49 #e1e4c4,#4a583e, 50-51 #e1e4c4,#9b583f, 52-52 #e1e4c4,#343b2e, 53-99 #d5d8b8,#343b2e, |2: 0-1 d,#d8bd83, 2-2 d,#4a583e, 3-29 #e1e4c4,#4a583e, 30-38 #c5e7f7,#4a583e, 39-49 #e1e4c4,#4a583e, 50-51 #e1e4c4,#7b7e4e, 52-52 #e1e4c4,#343b2e, 53-79 #d5d8b8,#343b2e, 80-88 #badbeb,#343b2e, 89-99 #d5d8b8,#343b2e, |3: 0-2 d,#4a583e, 3-49 #e1e4c4,#4a583e, 50-52 #e1e4c4,#343b2e, 53-99 #d5d8b8,#343b2e, @@ -390,7 +390,7 @@ |30: 0-0 d,#888e5e, 1-49 d,#100e0b, 50-50 d,#888e5e, 51-99 d,#100e0b, == snap clay grid=100x31 cursor=4,6 == style clay grid=100x31 -|0: 0-50 #d7d6b6,#343f36, 51-59 #fbf1c7,#505c38, 60-60 #fbf1c7,#343f36, 61-99 #d7d6b6,#343f36, +|0: 0-75 #d7d6b6,#343f36, 76-84 #fbf1c7,#505c38, 85-99 #fbf1c7,#343f36, |1: 0-1 d,#875e65, 2-2 d,#4d5c48, 3-49 #e3e2c2,#4d5c48, 50-51 #e3e2c2,#875e65, 52-52 #e3e2c2,#343f36, 53-99 #d7d6b6,#343f36, |2: 0-1 d,#8ac874, 2-2 d,#4d5c48, 3-29 #e3e2c2,#4d5c48, 30-38 #b5ecec,#4d5c48, 39-49 #e3e2c2,#4d5c48, 50-51 #e3e2c2,#687c4d, 52-52 #e3e2c2,#343f36, 53-79 #d7d6b6,#343f36, 80-88 #aae0e0,#343f36, 89-99 #d7d6b6,#343f36, |3: 0-2 d,#4d5c48, 3-49 #e3e2c2,#4d5c48, 50-52 #e3e2c2,#343f36, 53-99 #d7d6b6,#343f36, @@ -423,7 +423,7 @@ |30: 0-0 d,#8c9467, 1-49 d,#10100e, 50-50 d,#8c9467, 51-99 d,#10100e, == snap forge-black grid=100x31 cursor=4,6 == style forge-black grid=100x31 -|0: 0-50 #c5c9d2,#22252b, 51-59 #e2eef4,#1c5172, 60-60 #e2eef4,#22252b, 61-99 #c5c9d2,#22252b, +|0: 0-75 #c5c9d2,#22252b, 76-84 #e2eef4,#1c5172, 85-99 #e2eef4,#22252b, |1: 0-1 d,#6a7b67, 2-2 d,#374253, 3-49 #d1d5de,#374253, 50-51 #d1d5de,#6a7b67, 52-52 #d1d5de,#22252b, 53-99 #c5c9d2,#22252b, |2: 0-1 d,#9cc3f7, 2-2 d,#374253, 3-29 #d1d5de,#374253, 30-38 #f8cba7,#374253, 39-49 #d1d5de,#374253, 50-51 #d1d5de,#55647b, 52-52 #d1d5de,#22252b, 53-79 #c5c9d2,#22252b, 80-88 #ecbf9b,#22252b, 89-99 #c5c9d2,#22252b, |3: 0-2 d,#374253, 3-49 #d1d5de,#374253, 50-52 #d1d5de,#22252b, 53-99 #c5c9d2,#22252b, @@ -456,7 +456,7 @@ |30: 0-0 d,#708095, 1-49 d,#000000, 50-50 d,#708095, 51-99 d,#000000, == snap forge-soft grid=100x31 cursor=4,6 == style forge-soft grid=100x31 -|0: 0-50 #c5c9d2,#2a2d34, 51-59 #e2eef4,#1c5172, 60-60 #e2eef4,#2a2d34, 61-99 #c5c9d2,#2a2d34, +|0: 0-75 #c5c9d2,#2a2d34, 76-84 #e2eef4,#1c5172, 85-99 #e2eef4,#2a2d34, |1: 0-1 d,#6d7f6c, 2-2 d,#404a58, 3-49 #d1d5de,#404a58, 50-51 #d1d5de,#6d7f6c, 52-52 #d1d5de,#2a2d34, 53-99 #c5c9d2,#2a2d34, |2: 0-1 d,#9cc3f7, 2-2 d,#404a58, 3-29 #d1d5de,#404a58, 30-38 #f8cba7,#404a58, 39-49 #d1d5de,#404a58, 50-51 #d1d5de,#55647b, 52-52 #d1d5de,#2a2d34, 53-79 #c5c9d2,#2a2d34, 80-88 #ecbf9b,#2a2d34, 89-99 #c5c9d2,#2a2d34, |3: 0-2 d,#404a58, 3-49 #d1d5de,#404a58, 50-52 #d1d5de,#2a2d34, 53-99 #c5c9d2,#2a2d34, @@ -489,7 +489,7 @@ |30: 0-0 d,#708095, 1-49 d,#35383e, 50-50 d,#708095, 51-99 d,#35383e, == snap orchard-black grid=100x31 cursor=4,6 == style orchard-black grid=100x31 -|0: 0-50 #b2c3b8,#1d2824, 51-59 #f5f7ee,#3c614a, 60-60 #f5f7ee,#1d2824, 61-99 #b2c3b8,#1d2824, +|0: 0-75 #b2c3b8,#1d2824, 76-84 #f5f7ee,#3c614a, 85-99 #f5f7ee,#1d2824, |1: 0-1 d,#887455, 2-2 d,#314738, 3-49 #becfc4,#314738, 50-51 #becfc4,#887455, 52-52 #becfc4,#1d2824, 53-99 #b2c3b8,#1d2824, |2: 0-1 d,#add38a, 2-2 d,#314738, 3-29 #becfc4,#314738, 30-38 #dfbce5,#314738, 39-49 #becfc4,#314738, 50-51 #becfc4,#496656, 52-52 #becfc4,#1d2824, 53-79 #b2c3b8,#1d2824, 80-88 #d3b0d9,#1d2824, 89-99 #b2c3b8,#1d2824, |3: 0-2 d,#314738, 3-49 #becfc4,#314738, 50-52 #becfc4,#1d2824, 53-99 #b2c3b8,#1d2824, @@ -522,7 +522,7 @@ |30: 0-0 d,#608269, 1-49 d,#000000, 50-50 d,#608269, 51-99 d,#000000, == snap acme grid=100x31 cursor=4,6 == style acme grid=100x31 -|0: 0-50 #000000,#eaffff, 51-59 #000000,#9eeeee, 60-99 #000000,#eaffff, +|0: 0-75 #000000,#eaffff, 76-84 #000000,#9eeeee, 85-99 #000000,#eaffff, |1: 0-1 d,#8888cc, 2-2 d,#eaffff, 3-49 #000000,#eaffff, 50-51 #000000,#8888cc, 52-99 #000000,#eaffff, |2: 0-1 d,#8888cc, 2-2 d,#eaffff, 3-29 #000000,#eaffff, 30-38 #000099,#eaffff, 39-49 #000000,#eaffff, 50-51 #000000,#b9c3e5, 52-79 #000000,#eaffff, 80-88 #000099,#eaffff, 89-99 #000000,#eaffff, |3: 0-2 d,#eaffff, 3-99 #000000,#eaffff, @@ -555,7 +555,7 @@ |30: 0-99 d,#ffffea, == snap lapis grid=100x31 cursor=4,6 == style lapis grid=100x31 -|0: 0-50 #9aa6d9,#0f1a4a, 51-59 #0f1a4a,#e8c46a, 60-60 #0f1a4a,#0f1a4a, 61-99 #9aa6d9,#0f1a4a, +|0: 0-75 #9aa6d9,#0f1a4a, 76-84 #0f1a4a,#e8c46a, 85-99 #0f1a4a,#0f1a4a, |1: 0-1 d,#8a3a3a, 2-2 d,#25397d, 3-49 #eee6d2,#25397d, 50-51 #eee6d2,#8a3a3a, 52-52 #eee6d2,#0f1a4a, 53-99 #9aa6d9,#0f1a4a, |2: 0-1 d,#e8c46a, 2-2 d,#25397d, 3-29 #eee6d2,#25397d, 30-38 #f2d280,#25397d, 39-49 #eee6d2,#25397d, 50-51 #eee6d2,#6a78b1, 52-52 #eee6d2,#0f1a4a, 53-79 #9aa6d9,#0f1a4a, 80-88 #e8c46a,#0f1a4a, 89-99 #9aa6d9,#0f1a4a, |3: 0-2 d,#25397d, 3-49 #eee6d2,#25397d, 50-52 #eee6d2,#0f1a4a, 53-99 #9aa6d9,#0f1a4a, @@ -588,7 +588,7 @@ |30: 0-0 d,#e8c46a, 1-49 d,#0a1030, 50-50 d,#e8c46a, 51-99 d,#0a1030, == snap dark-plus grid=100x31 cursor=4,6 == style dark-plus grid=100x31 -|0: 0-50 #a7a7a7,#3c3c3c, 51-59 #d4d4d4,#264f78, 60-60 #d4d4d4,#3c3c3c, 61-99 #a7a7a7,#3c3c3c, +|0: 0-75 #a7a7a7,#3c3c3c, 76-84 #d4d4d4,#264f78, 85-99 #d4d4d4,#3c3c3c, |1: 0-1 d,#458276, 2-2 d,#1e1e1e, 3-49 #ffffff,#1e1e1e, 50-51 #ffffff,#458276, 52-52 #ffffff,#3c3c3c, 53-99 #a7a7a7,#3c3c3c, |2: 0-1 d,#007fd4, 2-2 d,#1e1e1e, 3-29 #ffffff,#1e1e1e, 30-38 #cbe5fc,#1e1e1e, 39-49 #ffffff,#1e1e1e, 50-51 #ffffff,#1c608e, 52-52 #ffffff,#3c3c3c, 53-79 #a7a7a7,#3c3c3c, 80-88 #68aee9,#3c3c3c, 89-99 #a7a7a7,#3c3c3c, |3: 0-2 d,#1e1e1e, 3-49 #ffffff,#1e1e1e, 50-52 #ffffff,#3c3c3c, 53-99 #a7a7a7,#3c3c3c, @@ -621,7 +621,7 @@ |30: 0-0 d,#424242, 1-49 d,#1e1e1e, 50-50 d,#424242, 51-99 d,#1e1e1e, == snap solarized-dark grid=100x31 cursor=4,6 == style solarized-dark grid=100x31 -|0: 0-50 #01090b,#657b83, 51-59 #002b36,#586e75, 60-60 #002b36,#657b83, 61-99 #01090b,#657b83, +|0: 0-75 #01090b,#657b83, 76-84 #002b36,#586e75, 85-99 #002b36,#657b83, |1: 0-1 d,#758a41, 2-2 d,#93a1a1, 3-49 #073642,#93a1a1, 50-51 #073642,#758a41, 52-52 #073642,#657b83, 53-99 #01090b,#657b83, |2: 0-1 d,#2483c5, 2-2 d,#93a1a1, 3-29 #073642,#93a1a1, 30-38 #2d3502,#93a1a1, 39-49 #073642,#93a1a1, 50-51 #073642,#185986, 52-52 #073642,#657b83, 53-79 #01090b,#657b83, 80-88 #121600,#657b83, 89-99 #01090b,#657b83, |3: 0-2 d,#93a1a1, 3-49 #073642,#93a1a1, 50-52 #073642,#657b83, 53-99 #01090b,#657b83, diff --git a/test/snapshots/theme.snap b/test/snapshots/theme.snap index b770d7f3..4cb360d3 100644 --- a/test/snapshots/theme.snap +++ b/test/snapshots/theme.snap @@ -5,6 +5,14 @@ file t.txt x start 31 100 -n 3 wait 8000 t.txt stable 700 20000 +# NextColor is no default word of the workspace tag: typed onto its end +press left 99 1 +release left 99 1 +key space +text NextColor +key esc +settle 100 +stable 700 10000 snap orchard snapstyle orchard press middle @NextColor 1 diff --git a/test/snapshots/themesel.golden b/test/snapshots/themesel.golden index d9c4f4ba..a82d88f5 100644 --- a/test/snapshots/themesel.golden +++ b/test/snapshots/themesel.golden @@ -1,5 +1,5 @@ == snap boot grid=100x31 cursor=7,3 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol | /tmp/pardes-snap/themesel/cwd/t.txt Save Tty Collapse Del | 1 line 1 diff --git a/test/snapshots/tinywin.golden b/test/snapshots/tinywin.golden index c847a2f1..f4d20a9a 100644 --- a/test/snapshots/tinywin.golden +++ b/test/snapshots/tinywin.golden @@ -1,5 +1,5 @@ == snap stacked grid=100x31 cursor=14,3 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol |$ /tmp/pardes-snap/tinywin/cwd Tty+bash Save Mode Filter Collapse Del | $ :^[n^[n^[n @@ -23,12 +23,12 @@ | /tmp/pardes-snap/tinywin/cwd/+New Save Tty Collapse Del | 1 == snap shrunk grid=60x4 cursor=59,3 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Co | New Tty Find Grep Joincol Delcol |$ /tmp/pardes-snap/tinywin/cwd Tty+bash Save Mode Filter Co | /tmp/pardes-snap/tinywin/cwd/+New Save Tty Collapse Del == snap columns grid=100x31 cursor=23,3 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol |$ /tmp/pardes-snap/tinywin/cwd Tty+bash Save Mode Filter Collapse Del | $ :^[n^[n^[n cn cn cn diff --git a/test/snapshots/topbarexec.golden b/test/snapshots/topbarexec.golden index 500f9f2a..3ede27e8 100644 --- a/test/snapshots/topbarexec.golden +++ b/test/snapshots/topbarexec.golden @@ -1,5 +1,5 @@ == snap selected grid=90x21 cursor=14,5 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol | /tmp/pardes-snap/topbarexec/cwd Tty+bash S /tmp/pardes-snap/topbarexec/cwd Tty+bash S | ave Mode Filter Collapse Del ave Mode Filter Collapse Del diff --git a/test/snapshots/tty.golden b/test/snapshots/tty.golden index b876ace6..981a5c7f 100644 --- a/test/snapshots/tty.golden +++ b/test/snapshots/tty.golden @@ -1,5 +1,5 @@ == snap tty-on grid=100x31 cursor=4,6 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol |$ /tmp/pardes-snap/tty/cwd Tty+bash Save Mode Fil /tmp/pardes-snap/tty/cwd Tty+bash Save Mode Fil | ter Collapse Del ter Collapse Del diff --git a/test/snapshots/ttyclick.golden b/test/snapshots/ttyclick.golden index a69d951f..5076e882 100644 --- a/test/snapshots/ttyclick.golden +++ b/test/snapshots/ttyclick.golden @@ -1,5 +1,5 @@ == snap tty-bodyclick grid=100x31 cursor=4,6 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol |$ /tmp/pardes-snap/ttyclick/cwd Tty+bash Save Mod /tmp/pardes-snap/ttyclick/cwd Tty+bash Save Mod | e Filter Collapse Del e Filter Collapse Del diff --git a/test/snapshots/ttyedit.golden b/test/snapshots/ttyedit.golden index 4411962e..ab1b1b5b 100644 --- a/test/snapshots/ttyedit.golden +++ b/test/snapshots/ttyedit.golden @@ -1,5 +1,5 @@ == snap before grid=100x31 cursor=7,8 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol | /tmp/pardes-snap/ttyedit/cwd Tty+bash Save Mode /tmp/pardes-snap/ttyedit/cwd Tty+bash Save Mode | Filter Collapse Del Filter Collapse Del diff --git a/test/snapshots/ttyfollow.golden b/test/snapshots/ttyfollow.golden index 1527ce86..3fb41e89 100644 --- a/test/snapshots/ttyfollow.golden +++ b/test/snapshots/ttyfollow.golden @@ -1,5 +1,5 @@ == snap held-pre grid=100x31 cursor=4,16 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol | /tmp/pardes-snap/ttyfollow/cwd Tty+bash Save Mo /tmp/pardes-snap/ttyfollow/cwd Tty+bash Save Mo | de Filter Collapse Del de Filter Collapse Del diff --git a/test/snapshots/ttyhelp.golden b/test/snapshots/ttyhelp.golden index c252ff28..7d21bc00 100644 --- a/test/snapshots/ttyhelp.golden +++ b/test/snapshots/ttyhelp.golden @@ -1,5 +1,5 @@ == snap boot grid=100x31 cursor=4,3 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol |$ /tmp/pardes-snap/ttyhelp/cwd Tty+bash Save Mode Filter Collapse Del | $ diff --git a/test/snapshots/ttylook.golden b/test/snapshots/ttylook.golden index a8ed1b95..b839a174 100644 --- a/test/snapshots/ttylook.golden +++ b/test/snapshots/ttylook.golden @@ -1,5 +1,5 @@ == snap tok1 grid=120x31 cursor=2,5 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol | /tmp/pardes-snap/ttylook/cwd Tty+bash Save Mode Filter Co /tmp/pardes-snap/ttylook/cwd Tty+bash Save Mode Filter Co | llapse Del llapse Del diff --git a/test/snapshots/ttyonly.golden b/test/snapshots/ttyonly.golden index 24f54b29..208aa485 100644 --- a/test/snapshots/ttyonly.golden +++ b/test/snapshots/ttyonly.golden @@ -1,5 +1,5 @@ == snap ttyonly grid=100x31 cursor=4,5 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol |$ /tmp/pardes-snap/ttyonly/cwd Tty+bash Save Mode Filter Collapse Del | $ echo TTY''ONLY diff --git a/test/snapshots/ttypaste.golden b/test/snapshots/ttypaste.golden index 40e0ae4c..ec98834e 100644 --- a/test/snapshots/ttypaste.golden +++ b/test/snapshots/ttypaste.golden @@ -1,5 +1,5 @@ == snap bracketed-paste-reached-the-shell grid=100x31 cursor=18,6 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol |$ /tmp/pardes-snap/ttypaste/cwd Tty+bash Save Mod /tmp/pardes-snap/ttypaste/cwd Tty+bash Save Mod | e Filter Collapse Del e Filter Collapse Del diff --git a/test/snapshots/ttyprompt.golden b/test/snapshots/ttyprompt.golden index 0033c78f..eb99f417 100644 --- a/test/snapshots/ttyprompt.golden +++ b/test/snapshots/ttyprompt.golden @@ -1,5 +1,5 @@ == snap greeted grid=100x31 cursor=4,6 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol | /tmp/pardes-snap/ttyprompt/cwd Tty+bash Save Mo /tmp/pardes-snap/ttyprompt/cwd Tty+bash Save Mo | de Filter Collapse Del de Filter Collapse Del diff --git a/test/snapshots/ttytaken.golden b/test/snapshots/ttytaken.golden index d0f2eee9..73a75088 100644 --- a/test/snapshots/ttytaken.golden +++ b/test/snapshots/ttytaken.golden @@ -1,5 +1,5 @@ == snap opened grid=210x31 cursor=4,5 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol | /tmp/pardes-snap/ttytaken/cwd Tty+bash Save Mode Filter Collapse Del | ls diff --git a/test/snapshots/tutor.golden b/test/snapshots/tutor.golden index 9793ca34..1be72b87 100644 --- a/test/snapshots/tutor.golden +++ b/test/snapshots/tutor.golden @@ -1,5 +1,5 @@ == snap tutor grid=150x31 cursor=7,6 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol | /tmp/pardes-snap/tutor/cwd Tty+bash Save Mode Filter Collapse Del /tmp/pardes-snap/tutor/cwd Tty+bash Save Mode Filter Collapse Del | ls Tutor ls diff --git a/test/snapshots/wheeldrift.golden b/test/snapshots/wheeldrift.golden index 256c2999..b5c4d231 100644 --- a/test/snapshots/wheeldrift.golden +++ b/test/snapshots/wheeldrift.golden @@ -1,5 +1,5 @@ == snap home grid=70x17 cursor=7,3 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exi +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug | New Tty Find Grep Joincol Delcol | /tmp/pardes-snap/wheeldrift/cwd/drift.txt Save Tty Collapse Del | 1 line 1_0123456789_abcdefghij_ZEND Wrap diff --git a/test/snapshots/winch.golden b/test/snapshots/winch.golden index a1e8afc4..c6972f79 100644 --- a/test/snapshots/winch.golden +++ b/test/snapshots/winch.golden @@ -1,5 +1,5 @@ == snap storm grid=100x31 cursor=4,8 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol |$ /tmp/pardes-snap/winch/cwd Tty+bash Save Mode F /tmp/pardes-snap/winch/cwd Tty+bash Save Mode F | ilter Collapse Del ilter Collapse Del @@ -20,7 +20,7 @@ | ilter Collapse Del | ls == snap resized grid=106x35 cursor=4,8 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol |$ /tmp/pardes-snap/winch/cwd Tty+bash Save Mode Filt /tmp/pardes-snap/winch/cwd Tty+bash Save Mode Filt | er Collapse Del er Collapse Del diff --git a/test/snapshots/windownav.golden b/test/snapshots/windownav.golden index 13fc7ae7..91e80e6d 100644 --- a/test/snapshots/windownav.golden +++ b/test/snapshots/windownav.golden @@ -1,5 +1,5 @@ == snap start grid=100x31 cursor=7,4 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol | /tmp/pardes-snap/windownav/cwd/w.txt Save Tty C /tmp/pardes-snap/windownav/cwd Tty+bash Save Mo | ollapse Del de Filter Collapse Del diff --git a/test/snapshots/windowops.golden b/test/snapshots/windowops.golden index d729f179..6a48785e 100644 --- a/test/snapshots/windowops.golden +++ b/test/snapshots/windowops.golden @@ -1,5 +1,5 @@ == snap hover-v grid=100x31 cursor=4,6 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol ╎ New Tty Find Grep Joincol Delcol | /tmp/pardes-snap/windowops/cwd Tty+bash Save M╎ /tmp/pardes-snap/windowops/cwd Tty+bash Save Mo | de Filter Collapse Del ╎ de Filter Collapse Del @@ -153,7 +153,7 @@ |10: ╰────────────────────────────────────╯ |20: ls == style debug-on grid=100x31 -|0: 0-60 #b2c3b8,#1d2824, 61-65 #f5f7ee,#3c614a, 66-66 #f5f7ee,#1d2824, 67-99 #b2c3b8,#1d2824, +|0: 0-64 #b2c3b8,#1d2824, 65-69 #f5f7ee,#3c614a, 70-70 #f5f7ee,#1d2824, 71-99 #b2c3b8,#1d2824, |1: 0-1 d,#887455, 2-2 d,#1d2824, 3-39 #b2c3b8,#1d2824, 40-41 #b2c3b8,#887455, 42-42 #b2c3b8,#314738, 43-61 #becfc4,#314738, 62-99 d,d, |2: 0-1 d,#496656, 2-2 d,#1d2824, 3-33 #b2c3b8,#1d2824, 34-39 #d3b0d9,#1d2824, 40-41 #d3b0d9,#add38a, 42-42 #d3b0d9,#314738, 43-61 #becfc4,#314738, 62-62 d,d, 63-79 #b2c3b8,d, 80-98 #b2c3b8,#152019, 99-99 d,d, |3: 0-2 d,#1d2824, 3-5 #d3b0d9,#1d2824, 6-39 #b2c3b8,#1d2824, 40-42 #b2c3b8,#314738, 43-61 #becfc4,#314738, 62-62 d,d, 63-76 #b2c3b8,d, 77-98 #b2c3b8,#152019, 99-99 d,d, diff --git a/test/snapshots/wrap.golden b/test/snapshots/wrap.golden index cc834fc5..b620b2a9 100644 --- a/test/snapshots/wrap.golden +++ b/test/snapshots/wrap.golden @@ -35,7 +35,7 @@ |10: 3 third line |11: 4 == snap on-wide grid=128x15 cursor=7,3 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol | /tmp/pardes-snap/wrap/cwd/long.txt Save Tty Collapse Del | 1 0---------1---------2---------3---------4---------5---------6---------7---------8---------9---------A---------B---------↩ diff --git a/test/snapshots/yankpaste.golden b/test/snapshots/yankpaste.golden index 22cc787f..e81587f8 100644 --- a/test/snapshots/yankpaste.golden +++ b/test/snapshots/yankpaste.golden @@ -1,5 +1,5 @@ == snap linewise-below grid=100x31 cursor=13,6 -|Newcol Joincol Find Grep Help Changelog Tutor Dump NextColor Debug Exit +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol | * /tmp/pardes-snap/yankpaste/cwd/f.txt Save Tty Collapse Del | 1 line 1 diff --git a/test/window_opacity.py b/test/window_opacity.py index a576b1bd..0253e15c 100644 --- a/test/window_opacity.py +++ b/test/window_opacity.py @@ -66,15 +66,15 @@ def run(args): help_text = output('Help') require('WindowOpacity' in help_text and 'FgOpacity' not in help_text, 'help did not replace FgOpacity with WindowOpacity') - settings = output('Config') + settings = output('DumpConfig') require('WindowOpacity: 100%\n' in settings and 'FgOpacity' not in settings, - 'initial Config opacity not applied: ' + settings) + 'initial DumpConfig opacity not applied: ' + settings) require('Wayland opacity: background-only transparent surface' in log.read_text(errors='replace'), 'background-only surface path not selected') report['renderer_path'] = 'background-only transparent surface' def wait_applied(percent): - require(wait_for(lambda: f'WindowOpacity: {percent}%\n' in output('Config')), + require(wait_for(lambda: f'WindowOpacity: {percent}%\n' in output('DumpConfig')), 'opacity did not apply: ' + str(percent)) geometry = None @@ -138,10 +138,10 @@ def run(args): wait_applied(70) require(samples() == baseline, 'opacity altered editor or terminal core RGB/text') capture(70) - settings = output('Config') + settings = output('DumpConfig') require('WindowOpacity: 70%\n' in settings, '70% opacity not applied: ' + settings) command(client, source, 'WindowOpacity 101') - require('WindowOpacity: 70%\n' in output('Config'), 'invalid opacity changed state') + require('WindowOpacity: 70%\n' in output('DumpConfig'), 'invalid opacity changed state') command(client, source, 'WindowOpacity 0') wait_applied(0) require(samples() == baseline, 'zero opacity altered editor or terminal core RGB/text') @@ -207,7 +207,7 @@ def run(args): log.read_text(errors='replace')) require(all(int(value) == 0xffffffff for value in multipliers), 'whole-window alpha modifier would fade foreground text') - require('WindowOpacity: 100%\n' in output('Config'), '100% opacity not restored') + require('WindowOpacity: 100%\n' in output('DumpConfig'), '100% opacity not restored') require(source_path.read_bytes() == original == client.read(f'/pane/{source}/body'), 'source contents changed') client.write(f'/pane/{terminal}/pty/data', b'exit\r') -- cgit v1.3 From fda2f546f66d0bb1b30da0ef6aae77fe82803b1c Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Wed, 30 Sep 2026 11:22:41 -0300 Subject: DumpConfig prints each setting as the ctl word that sets it, reads unsupported for one the frontend lacks, and includes LocationsConfig The report meant to be feedable back as configuration, but several lines were not. Shell and Font each took three to six lines of "requested", "effective" and "pending". The transition read "Panel transition PanelSlide", with no Panel word. WindowOpacity and TaglineSize carried "(pending)" and "(build-time only)". A GUI-only toggle such as Ligatures was left out on the tty, and LocationsConfig was missing altogether. Now every line up to a blank one is a word and its value: - Shell ; - Font :; - one on/off line for each Panel word; - `unsupported` for a setting this frontend does not have; - LocationsConfig as it would be typed. After the blank line comes what is in effect but set by no word, phrased so that none of it starts with a ctl word. The test checks that each line before the blank one starts with a setting word. The GUI scripts that read the font lines (font_size.py, appearance_gallery.py) now read the new ones. Co-Authored-By: Claude Opus 5.5 --- docs/config.md | 7 +- src/Output.zig | 4 ++ src/builtins.zig | 3 +- src/config.zig | 167 +++++++++++++++++++-------------------------- test/appearance_gallery.py | 2 +- test/font_size.py | 6 +- test/output.zig | 26 ++++--- 7 files changed, 98 insertions(+), 117 deletions(-) (limited to 'src/Output.zig') diff --git a/docs/config.md b/docs/config.md index bc4acf12..35f0b6e7 100644 --- a/docs/config.md +++ b/docs/config.md @@ -34,8 +34,11 @@ not stop later ones. Text that is no builtin is not run as a shell command `Config` (`SPC f c`) opens `init` itself in a pane, or goes to its pane when it is open. With no file there yet, the pane is named for it, empty, and Save writes it, making its directory first. `DumpConfig` opens a -`+DumpConfig` pane with the startup path (a right click opens it) and every -live setting; a setting the frontend cannot show reads `unsupported`. The +`+DumpConfig` pane with every live setting, each line the word that sets +it and its value (`Shell /bin/bash`, `PanelSlide off`, `LocationsConfig …`) +and `unsupported` for one the frontend cannot show. After a blank line +come what is in effect but set by no word, such as the last shell spawned +and the font in use, and the startup path (a right click opens it). The root `ctl` file reads the settings back in the words a write takes ([fs.md](fs.md#the-root-ctl)). diff --git a/src/Output.zig b/src/Output.zig index 0581be41..65f6bfe4 100644 --- a/src/Output.zig +++ b/src/Output.zig @@ -815,7 +815,11 @@ pub fn openConfig(p: *Pardes, id: usize) !void { errdefer out.deinit(); var dir_buf: [1024]u8 = undefined; const host_fs = comptime (pardes.platform != .web and pardes.platform != .esp32p4); + var located: std.Io.Writer.Allocating = .init(p.gpa); + defer located.deinit(); + try p.locations_config.write(&located.writer); try config.Runtime.writeReport(&out.writer, .{ + .locations = located.written(), .default_dump_dir = if (host_fs) (pardes.dump.defaultDirectory(&dir_buf) orelse "") else "", .startup_config_path = p.opts.startup_config_path, .platform = @tagName(pardes.platform), diff --git a/src/builtins.zig b/src/builtins.zig index c40b2e00..8fe49649 100644 --- a/src/builtins.zig +++ b/src/builtins.zig @@ -458,7 +458,8 @@ test "Ligatures is a setting only in the shell that shapes text" { .state = &p.settings, }); try std.testing.expectEqual(exists, std.mem.indexOf(u8, storage[0..out.end], "Ligatures off\n") != null); - try std.testing.expectEqual(exists, std.mem.indexOf(u8, storage[0..out.end], "Ligatures") != null); + // A GUI-only setting reads so elsewhere, as every one the shell lacks. + try std.testing.expectEqual(!exists, std.mem.indexOf(u8, storage[0..out.end], "Ligatures unsupported\n") != null); } comptime { diff --git a/src/config.zig b/src/config.zig index a70ae708..94b32b88 100644 --- a/src/config.zig +++ b/src/config.zig @@ -1275,6 +1275,8 @@ pub const Runtime = struct { native_images: bool, capabilities: Capabilities, state: *const Runtime, + /// The `LocationsConfig` argument in effect, as it would be typed. + locations: []const u8 = "", }; fn onOff(value: bool) []const u8 { @@ -1285,23 +1287,19 @@ pub const Runtime = struct { return if (text.len == 0) "(none)" else text; } - fn transitionSettingName(transition: animation.Transition) []const u8 { - if (transition == .off) return "off"; - return findAction(.{ .transition = transition }).?.word; - } - - /// Each line reads as the command that would set it: the word, then the - /// value you would type after it. No colons, no units — `WindowOpacity 70` - /// is both what DumpConfig prints and what you write back. + /// Each setting line reads as the command that would set it: the word, + /// then the value you would type after it (`unsupported` where this + /// shell has no such setting). No colons, no units: `WindowOpacity 70` + /// is both what DumpConfig prints and what you write back. What is in + /// effect but set by no word follows, after a blank line. pub fn writeReport(out: *std.Io.Writer, context: ReportContext) !void { const state = context.state; - var wrote_transition = false; for (settings) |setting| switch (setting.action) { .toggle => |field| { - // A toggle for what this shell does not draw (Ligatures in a - // terminal, whose text its emulator draws) is no setting here: - // it is not a builtin, so the report does not list it either. - if (!setting.enabled(context.capabilities)) continue; + if (!setting.enabled(context.capabilities)) { + try out.print("{s} unsupported\n", .{setting.word}); + continue; + } const value = switch (field) { inline else => |f| @field(state, @tagName(f)), }; @@ -1310,11 +1308,7 @@ pub const Runtime = struct { .theme => try out.print("{s} {s}\n", .{ setting.word, context.theme_name }), .window_opacity => { if (setting.enabled(context.capabilities)) - try out.print("{s} {d}{s}\n", .{ - setting.word, - state.window_opacity, - if (state.window_opacity_pending) " (pending)" else "", - }) + try out.print("{s} {d}\n", .{ setting.word, state.window_opacity }) else try out.print("{s} unsupported\n", .{setting.word}); }, @@ -1333,64 +1327,28 @@ pub const Runtime = struct { } }), .shell => { const chosen = state.shell.requested.get(); - try out.print( - "{s} requested (new panes) {s}{s}\n" ++ - "{s} effective (last spawn) {s}\n" ++ - "{s} pending {s}\n", - .{ - setting.word, - if (chosen.len == 0) context.compiled_default_shell else chosen, - if (chosen.len == 0) " (default)" else "", - setting.word, - shown(state.shell.effective.get()), - setting.word, - onOff(state.shell.pending), - }, - ); + try out.print("{s} {s}\n", .{ setting.word, if (chosen.len == 0) context.compiled_default_shell else chosen }); }, .font => if (!setting.enabled(context.capabilities)) try out.print("{s} unsupported\n", .{setting.word}) else { - if (state.font.requested_size_hundredths == 0) - try out.print("{s} requested size unchanged\n", .{setting.word}) - else - try out.print("{s} requested size {d}.{d:0>2}\n", .{ setting.word, state.font.requested_size_hundredths / 100, state.font.requested_size_hundredths % 100 }); - try out.print( - "{s} requested {s}\n" ++ - "{s} requested path {s}\n" ++ - "{s} effective {s}\n" ++ - "{s} pending {s}\n" ++ - "{s} effective size {d}.{d:0>2} {s}\n", - .{ - setting.word, - shown(state.font.requested_name.get()), - setting.word, - shown(state.font.requested_path.get()), - setting.word, - shown(state.font.effective_name.get()), - setting.word, - onOff(state.font.pending), - setting.word, - state.font.effective_size_hundredths / 100, - state.font.effective_size_hundredths % 100, - @tagName(state.font.effective_size_unit), - }, - ); + // As `Font` takes it, `name:size`: the one asked for, else + // the one in use. + const f = &state.font; + const name = if (f.requested_path.get().len > 0) f.requested_path.get() else if (f.requested_name.get().len > 0) f.requested_name.get() else f.effective_name.get(); + try out.print("{s} {s}", .{ setting.word, name }); + if (f.requested_size_hundredths != 0) try out.print(":{d}.{d:0>2}", .{ f.requested_size_hundredths / 100, f.requested_size_hundredths % 100 }); + try out.writeByte('\n'); }, .tagline_size => if (!context.capabilities.tagline_font_size) try out.print("{s} unsupported\n", .{setting.word}) - else if (!setting.enabled(context.capabilities)) - try out.print("{s} {d} (build-time only)\n", .{ setting.word, state.font.tagline_percent }) else try out.print("{s} {d}\n", .{ setting.word, state.font.tagline_percent }), - .transition => { - if (wrote_transition) continue; - wrote_transition = true; - if (!setting.enabled(context.capabilities)) - try out.writeAll("Panel transition unsupported\n") - else - try out.print("Panel transition {s}\n", .{transitionSettingName(state.panel_transition)}); - }, + // Each a switch of its own, the one in use on. + .transition => |transition| if (!setting.enabled(context.capabilities)) + try out.print("{s} unsupported\n", .{setting.word}) + else + try out.print("{s} {s}\n", .{ setting.word, onOff(state.panel_transition == transition) }), .scene => |effect| { if (!setting.enabled(context.capabilities)) { try out.print("{s} unsupported\n", .{setting.word}); @@ -1426,7 +1384,21 @@ pub const Runtime = struct { .inactive_dim => try out.print("{s} {d}\n", .{ setting.word, state.inactive_dim }), .grip_width => try out.print("{s} {d}\n", .{ setting.word, state.grip_width }), }; - + if (context.locations.len > 0) try out.print("LocationsConfig {s}\n", .{context.locations}); + + // In effect, and set by no word. + try out.writeByte('\n'); + try out.print("Last shell spawned: {s}\n", .{shown(state.shell.effective.get())}); + try out.print("Shell change pending: {s}\n", .{onOff(state.shell.pending)}); + if (find("Font").?.enabled(context.capabilities)) { + const f = &state.font; + try out.print("Font in use: {s} {d}.{d:0>2} {s}\n", .{ shown(f.effective_name.get()), f.effective_size_hundredths / 100, f.effective_size_hundredths % 100, @tagName(f.effective_size_unit) }); + try out.print("Font change pending: {s}\n", .{onOff(f.pending)}); + } + if (find("WindowOpacity").?.enabled(context.capabilities)) + try out.print("Window opacity change pending: {s}\n", .{onOff(state.window_opacity_pending)}); + if (context.capabilities.tagline_font_size and !find("TaglineSize").?.enabled(context.capabilities)) + try out.writeAll("Tagline size: build-time only\n"); if (context.startup_config_path) |path| try out.print("Startup config: {s}\n", .{path}) else @@ -1726,9 +1698,9 @@ pub const Runtime = struct { .chip_shadow => "ChipShadow on\n", .thumb_flash => "ThumbFlash on\n", }, - .shell => "Shell requested (new panes) fish\n", + .shell => "Shell fish\n", .tagline_size => "TaglineSize 73\n", - .window_opacity => "WindowOpacity 85 (pending)\n", + .window_opacity => "WindowOpacity 85\n", .window_blur => "WindowBlur 40\n", .dump_dir => "DumpDir ~/dumps\n", .message_ms => |which| switch (which) { @@ -1738,17 +1710,17 @@ pub const Runtime = struct { }, .transition => |transition| switch (transition) { .off => unreachable, - .slide => "Panel transition PanelSlide\n", - .zoom => "Panel transition PanelZoom\n", - .dissolve => "Panel transition PanelDissolve\n", - .ascii => "Panel transition PanelAscii\n", - .vertical => "Panel transition PanelVertical\n", - .edges => "Panel transition PanelEdges\n", - .fall => "Panel transition PanelFall\n", - .wave => "Panel transition PanelWave\n", - .curtain => "Panel transition PanelCurtain\n", - .scramble => "Panel transition PanelScramble\n", - .typewriter => "Panel transition PanelType\n", + .slide => "PanelSlide on\n", + .zoom => "PanelZoom on\n", + .dissolve => "PanelDissolve on\n", + .ascii => "PanelAscii on\n", + .vertical => "PanelVertical on\n", + .edges => "PanelEdges on\n", + .fall => "PanelFall on\n", + .wave => "PanelWave on\n", + .curtain => "PanelCurtain on\n", + .scramble => "PanelScramble on\n", + .typewriter => "PanelType on\n", }, .scene => |effect| switch (effect) { .crt => "Crt 2\n", @@ -1788,12 +1760,10 @@ pub const Runtime = struct { for ([_][]const u8{ "Theme acme\n", "WindowOpacity 85\n", - "Font requested size 18.50\n", - "Font requested Wanted Mono\n", - "Font requested path /fonts/wanted.ttf\n", - "Font effective Effective Mono\n", - "Font pending on\n", - "Font effective size 13.75 points\n", + "Font /fonts/wanted.ttf:18.50\n", + "Font in use: Effective Mono 13.75 points\n", + "Font change pending: on\n", + "Window opacity change pending: off\n", "TaglineSize 82\n", "Startup config: /tmp/pardes/init\n", "Platform: gui\n", @@ -1823,19 +1793,23 @@ pub const Runtime = struct { try std.testing.expect(std.mem.indexOf(u8, defaults_report, "WindowBlur unsupported\n") != null); try std.testing.expect(!find("WindowBlur").?.enabled(defaults_context.capabilities)); try std.testing.expect(find("WindowOpacity").?.enabled(context.capabilities)); - try std.testing.expect(std.mem.indexOf(u8, defaults_report, "Shell requested (new panes) /bin/sh (default)\n") != null); - try std.testing.expect(std.mem.indexOf(u8, defaults_report, "Shell effective (last spawn) (none)\n") != null); - try std.testing.expect(std.mem.indexOf(u8, defaults_report, "Shell pending on\n") != null); + try std.testing.expect(std.mem.indexOf(u8, defaults_report, "Shell /bin/sh\n") != null); + try std.testing.expect(std.mem.indexOf(u8, defaults_report, "Last shell spawned: (none)\n") != null); + try std.testing.expect(std.mem.indexOf(u8, defaults_report, "Shell change pending: on\n") != null); try std.testing.expect(std.mem.indexOf(u8, defaults_report, "Startup config: no per-user config path\n") != null); try std.testing.expect(std.mem.indexOf(u8, defaults_report, "Font unsupported\n") != null); - try std.testing.expect(std.mem.indexOf(u8, defaults_report, "Font requested") == null); - try std.testing.expect(std.mem.indexOf(u8, defaults_report, "Panel transition off\n") != null); + try std.testing.expect(std.mem.indexOf(u8, defaults_report, "Font in use") == null); + try std.testing.expect(std.mem.indexOf(u8, defaults_report, "PanelSlide off\n") != null); try std.testing.expect(std.mem.indexOf(u8, defaults_report, "Crt unsupported\n") != null); try std.testing.expect(std.mem.indexOf(u8, defaults_report, "TaglineSize unsupported\n") != null); try std.testing.expect(std.mem.indexOf(u8, defaults_report, "Look hover delay: off\n") != null); try std.testing.expect(std.mem.indexOf(u8, defaults_report, "Native images: off\n") != null); - // A shell that does not shape text has no Ligatures setting to report. - try std.testing.expect(std.mem.indexOf(u8, defaults_report, "Ligatures") == null); + // A setting this shell does not have reads so, as a line to write. + try std.testing.expect(std.mem.indexOf(u8, defaults_report, "Ligatures unsupported\n") != null); + // Every line before the blank one is a ctl word and its value. + const words = defaults_report[0..std.mem.indexOf(u8, defaults_report, "\n\n").?]; + var lines = std.mem.splitScalar(u8, words, '\n'); + while (lines.next()) |line| try std.testing.expect(find(line[0..std.mem.indexOfScalar(u8, line, ' ').?]) != null); defaults_context.platform = "web"; defaults_context.capabilities.panel_transitions = false; @@ -1843,8 +1817,9 @@ pub const Runtime = struct { out = .fixed(&storage); try writeReport(&out, defaults_context); const web_report = storage[0..out.end]; - try std.testing.expect(std.mem.indexOf(u8, web_report, "Panel transition unsupported\n") != null); - try std.testing.expect(std.mem.indexOf(u8, web_report, "TaglineSize 100 (build-time only)\n") != null); + try std.testing.expect(std.mem.indexOf(u8, web_report, "PanelSlide unsupported\n") != null); + try std.testing.expect(std.mem.indexOf(u8, web_report, "TaglineSize 100\n") != null); + try std.testing.expect(std.mem.indexOf(u8, web_report, "Tagline size: build-time only\n") != null); } }; diff --git a/test/appearance_gallery.py b/test/appearance_gallery.py index c321c7c0..98420a15 100644 --- a/test/appearance_gallery.py +++ b/test/appearance_gallery.py @@ -98,7 +98,7 @@ def run(args): return text settings = config_report() - require('Font effective size 18.00 pixels' in settings, 'configured font size not applied: ' + settings) + require(' 18.00 pixels\n' in settings, 'configured font size not applied: ' + settings) require('TaglineSize 80' in settings, 'configured tag size missing') (root / 'effective-config.txt').write_text(settings) report['font_effective_pixels'] = 18 diff --git a/test/font_size.py b/test/font_size.py index ef685a9e..878d6472 100644 --- a/test/font_size.py +++ b/test/font_size.py @@ -30,16 +30,16 @@ def run(args): for serial, tag in panes(client).items(): if '/+DumpConfig ' in tag: body = client.read(f'/pane/{serial}/body').decode() - if f'Font effective size {size:.2f} pixels' in body: + if f' {size:.2f} pixels\n' in body and 'Font in use: ' in body: return body return None return require(wait_for(ready), f'Font did not become {size} pixels') initial = report(18) - require('Font requested size 18.00' in initial, 'startup size suffix ignored') + require(':18.00\n' in initial, 'startup size suffix ignored') require(args.font in initial, 'requested font missing') execute(client, control, f'Font {args.font}:20.5') - require('Font requested size 20.50' in report(20.5), 'fractional size ignored') + require(':20.50\n' in report(20.5), 'fractional size ignored') execute(client, control, f'Font {args.font}') report(20.5) # no suffix preserves current size execute(client, control, f'Font {args.font}:900') diff --git a/test/output.zig b/test/output.zig index c67c021e..51d620c0 100644 --- a/test/output.zig +++ b/test/output.zig @@ -544,11 +544,12 @@ test "DumpConfig prints the startup path and refreshes its one output" { for ([_][]const u8{ "Startup config: " ++ path ++ "\n", "Theme orchard\n", - "Shell effective (last spawn) (none)\n", - "Shell pending on\n", + "Last shell spawned: (none)\n", + "Shell change pending: on\n", + "LocationsConfig ", }) |line| try std.testing.expect(std.mem.indexOf(u8, out.content, line) != null); var default_line: [256]u8 = undefined; - try std.testing.expect(std.mem.indexOf(u8, out.content, try std.fmt.bufPrint(&default_line, "Shell requested (new panes) {s} (default)\n", .{config.defaultShell()})) != null); + try std.testing.expect(std.mem.indexOf(u8, out.content, try std.fmt.bufPrint(&default_line, "Shell {s}\n", .{config.defaultShell()})) != null); try std.testing.expectEqualStrings(config.dump_config_buffer, std.fs.path.basename(out.path)); try std.testing.expectEqual(panes.Output.Origin{ .cmd = .DumpConfig }, out.output.?.from); @@ -734,14 +735,14 @@ test "every enabled setting builtin mutates the State Config reports" { "Tagbottom on\n", "Debug on\n", "Theme acme\n", - "Shell requested (new panes) fish\n", + "Shell fish\n", }) |line| try std.testing.expect(std.mem.indexOf(u8, report, line) != null); - const transition = if (builtins.capabilities.panel_transitions) - try std.fmt.bufPrint(&buf, "Panel transition {s}\n", .{ - config.Runtime.findAction(.{ .transition = p.settings.panel_transition }).?.word, - }) + const transition = if (!builtins.capabilities.panel_transitions) + "PanelSlide unsupported\n" + else if (p.settings.panel_transition == .off) + "PanelSlide off\n" else - "Panel transition unsupported\n"; + try std.fmt.bufPrint(&buf, "{s} on\n", .{config.Runtime.findAction(.{ .transition = p.settings.panel_transition }).?.word}); try std.testing.expect(std.mem.indexOf(u8, report, transition) != null); // A bare word turns a bundled pass on at its default level. const scene_status = if (builtins.capabilities.scene_shaders) "2" else "unsupported"; @@ -752,14 +753,11 @@ test "every enabled setting builtin mutates the State Config reports" { const tagline = if (!builtins.capabilities.tagline_font_size) "TaglineSize unsupported\n" else - try std.fmt.bufPrint(&buf, "TaglineSize {d}{s}\n", .{ - p.settings.font.tagline_percent, - if (builtins.capabilities.font_picker) "" else " (build-time only)", - }); + try std.fmt.bufPrint(&buf, "TaglineSize {d}\n", .{p.settings.font.tagline_percent}); try std.testing.expect(std.mem.indexOf(u8, report, tagline) != null); if (chosen_font) |name| { try std.testing.expect(std.mem.indexOf(u8, report, name) != null); - try std.testing.expect(std.mem.indexOf(u8, report, "Font pending on\n") != null); + try std.testing.expect(std.mem.indexOf(u8, report, "Font change pending: on\n") != null); } } -- cgit v1.3 From d6c877f55669869bc4c360e6d94563ded778d26d Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Wed, 30 Sep 2026 12:03:44 -0300 Subject: Help and Find from the workspace or a column tag act in the session's directory, not the keyboard pane's New, Tty and commands clicked in a tag no pane owns ran in the session's directory, but Help named its +Help after the pane with the keyboard, and Find walked that pane's directory. So the same click gave different results depending on which pane was focused. Both now take the session's directory from a header, through execDir as the others do. Co-Authored-By: Claude Opus 5.5 --- src/Output.zig | 6 ++++-- src/look.zig | 5 +++-- src/ninep/cols.zig | 18 ++++++++++++++++++ 3 files changed, 25 insertions(+), 4 deletions(-) (limited to 'src/Output.zig') diff --git a/src/Output.zig b/src/Output.zig index 65f6bfe4..545637b3 100644 --- a/src/Output.zig +++ b/src/Output.zig @@ -916,7 +916,7 @@ pub fn resetBody(p: *Pardes, pane: *Pane) void { fn openRead(p: *Pardes, id: usize, from: Origin, arg: []const u8, content: []u8) !void { errdefer p.gpa.free(content); - const pane = p.panes[id] orelse return error.MissingPane; + if (p.panes[id] == null) return error.MissingPane; for (p.panes, 0..) |slot, i| { const hp = slot orelse continue; const hf = if (hp.file) |*f| f else continue; @@ -928,7 +928,9 @@ fn openRead(p: *Pardes, id: usize, from: Origin, arg: []const u8, content: []u8) p.active = i; return; } - const dir = if (pane.file) |f| (std.fs.path.dirname(f.path) orelse "/") else pane.cwdSlice(); + // Where the word ran: the pane's directory, or from a column's or the + // workspace's tag, the session's. + const dir = p.execDir(id); const free = p.freeSlot() orelse return error.NoPaneSlots; _ = try open(p, free, dir, from, arg, content); exec.placeNew(p, id, id, free, if (from == .errors) .errors else .doc); diff --git a/src/look.zig b/src/look.zig index 65d001a9..36eae75c 100644 --- a/src/look.zig +++ b/src/look.zig @@ -583,8 +583,9 @@ pub fn runSearch(p: *Pardes, id: usize, pat_raw: []const u8, kind: Search, start if (pat.len == 0) return 0; const arena = p.scratch.allocator(); // where the pane lives: a file's directory, a shell's cwd — the walk - // root, and the directory the results buffer is named in. - const dir = Pardes.paneDir(pane); + // root, and the directory the results buffer is named in. From a + // column's or the workspace's tag, the session's. + const dir = if (p.exec_header) p.sessionDir() else Pardes.paneDir(pane); const out = try arena.alloc(u8, filesystem.search_max_output_bytes); var out_len: usize = 0; var nrows: usize = 0; diff --git a/src/ninep/cols.zig b/src/ninep/cols.zig index 1919122d..454cce4a 100644 --- a/src/ninep/cols.zig +++ b/src/ninep/cols.zig @@ -283,6 +283,24 @@ test "a pane's word written to /tagexec or a column's exec is refused, and acts try testing.expectEqual(tree.Status.ok, th.wr(p, col_exec, "New\n").reply.status); } +test "Help and Find at /tagexec act in the session's directory, not the keyboard pane's" { + const p = try th.withFile(testing.allocator, "x\n"); + defer p.deinit(); + var tmp = testing.tmpDir(.{}); + defer tmp.cleanup(); + try tmp.dir.writeFile(testing.io, .{ .sub_path = "needle.txt", .data = "n\n" }); + var buf: [4096]u8 = undefined; + const session = buf[0..try tmp.dir.realPath(testing.io, &buf)]; + @memcpy(p.session_dir[0..session.len], session); + p.session_dir_len = @intCast(session.len); + const tagexec = @intFromEnum(tree.TopFile.tagexec); + for ([_][]const u8{ "Help\n", "Find needle\n" }) |line| { + try testing.expectEqual(tree.Status.ok, th.wr(p, tagexec, line).reply.status); + const made = p.panes[p.active].?.file.?.path; + try testing.expectEqualStrings(session, std.fs.path.dirname(made).?); + } +} + test "New and Tty run at /tagexec and a column's exec, with no pane at all too" { const p = try th.withFile(testing.allocator, "x\n"); defer p.deinit(); -- cgit v1.3 From c4504325deefd4a8fb905db95b4e8b5003fb2a6a Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Wed, 30 Sep 2026 13:34:46 -0300 Subject: Lspinfo, Lspwhy and the other +Lsp answers share one +Lsp pane per directory Each query kind found its own output pane by its origin. So Lspinfo and Lspwhy, which both write `/+Lsp`, opened two panes of the same name in one directory, and so could a code action list or a format diff. The language server's prose now shares one +Lsp per directory, the way the file searches share one +Search, and each answer replaces the last. Co-Authored-By: Claude Opus 5.5 --- src/Output.zig | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'src/Output.zig') diff --git a/src/Output.zig b/src/Output.zig index 545637b3..3541fa57 100644 --- a/src/Output.zig +++ b/src/Output.zig @@ -164,6 +164,23 @@ test "stacked empty previews distinguish separators from trailing newlines" { try std.testing.expect(!locations.sameInput("x.c:1:1 \n", "x.c:1:1\n", &rows, .stacked)); } +test "Lspinfo and Lspwhy fill one +Lsp in a directory" { + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true }); + defer p.deinit(); + _ = try p.setTestFile("x\n"); + try fillResults(p, 0, "/work", .{ .query = .status }, "", try p.gpa.dupe(u8, "servers\n"), null); + try fillResults(p, 0, "/work", .{ .query = .explain }, "", try p.gpa.dupe(u8, "why\n"), null); + var lsp_panes: usize = 0; + for (p.panes) |slot| { + const f = (slot orelse continue).file orelse continue; + if (std.mem.eql(u8, f.path, "/work/+Lsp")) { + lsp_panes += 1; + try std.testing.expectEqualStrings("why\n", f.content); + } + } + try std.testing.expectEqual(@as(usize, 1), lsp_panes); +} + test "plain output does not opt into location decoration" { const report = rowDecoration(.{ .from = .{ .cmd = .LocationsConfig } }, "LocationsConfig context:5 tscontext:on"); try std.testing.expectEqualDeep(RowDecoration{}, report); @@ -439,6 +456,12 @@ fn fileSearch(from: Origin) bool { return from != .search and std.mem.eql(u8, traits(from).name, config.search_buffer); } +/// A language server's prose (Lspinfo, Lspwhy, a code action list, a +/// format diff): one `+Lsp` a directory holds for all of them. +fn lspProse(from: Origin) bool { + return from == .query and std.mem.eql(u8, traits(from).name, config.lsp_buffer); +} + pub fn fillResults(p: *Pardes, id: usize, dir: []const u8, from: Origin, arg: []const u8, content: []u8, initial_anchor: ?usize) !void { var result_content = content; errdefer p.gpa.free(result_content); @@ -483,7 +506,7 @@ pub fn fillResults(p: *Pardes, id: usize, dir: []const u8, from: Origin, arg: [] const rp = slot orelse continue; const rf = if (rp.file) |*f| f else continue; const o = if (rf.output) |*x| x else continue; - const shared = fileSearch(from) and fileSearch(o.from); + const shared = (fileSearch(from) and fileSearch(o.from)) or (lspProse(from) and lspProse(o.from)); if (i == id and !shared) continue; if (!shared and !std.meta.eql(o.from, from)) continue; if (!shared and by_arg and !std.mem.eql(u8, o.arg(), arg)) continue; -- cgit v1.3 From 39149c051a79e7d5148522b9851768a8e5b2ab54 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Wed, 30 Sep 2026 17:33:18 -0300 Subject: A terminal's word looks refill the directory's one +Search, as +Lsp is shared, rather than stacking one per word Each word looked for in a terminal (clicked, or written to look), where no file of that name was, opened another +Search in the same directory, one per word, until the column filled. Such a search now refills the directory's +Search, as the file searches and the +Lsp answers already share theirs. A `/` search keeps a +Search per pattern, which n and N walk across (psearch.snap), so the sharing is marked on the word look alone (Pardes.word_look). Co-Authored-By: Claude Opus 5.5 --- src/Output.zig | 25 ++++++++++++++++++++++++- src/look.zig | 2 ++ src/pardes.zig | 3 +++ 3 files changed, 29 insertions(+), 1 deletion(-) (limited to 'src/Output.zig') diff --git a/src/Output.zig b/src/Output.zig index 3541fa57..01797cbe 100644 --- a/src/Output.zig +++ b/src/Output.zig @@ -164,6 +164,24 @@ test "stacked empty previews distinguish separators from trailing newlines" { try std.testing.expect(!locations.sameInput("x.c:1:1 \n", "x.c:1:1\n", &rows, .stacked)); } +test "two words looked for in a terminal share the directory's one +Search" { + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true }); + defer p.deinit(); + const term = for (p.panes, 0..) |slot, id| { + if (slot) |pane| if (pane.isTerminal()) break id; + } else return error.SkipZigTest; + p.word_look = true; + defer p.word_look = false; + try fillResults(p, term, "/work", .search, "foo", try p.gpa.dupe(u8, "a.txt:1:1 foo\n"), null); + try fillResults(p, term, "/work", .search, "bar", try p.gpa.dupe(u8, "a.txt:2:1 bar\n"), null); + var searches: usize = 0; + for (p.panes) |slot| { + const f = (slot orelse continue).file orelse continue; + searches += @intFromBool(std.mem.eql(u8, f.path, "/work/+Search")); + } + try std.testing.expectEqual(@as(usize, 1), searches); +} + test "Lspinfo and Lspwhy fill one +Lsp in a directory" { const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true }); defer p.deinit(); @@ -506,7 +524,12 @@ pub fn fillResults(p: *Pardes, id: usize, dir: []const u8, from: Origin, arg: [] const rp = slot orelse continue; const rf = if (rp.file) |*f| f else continue; const o = if (rf.output) |*x| x else continue; - const shared = (fileSearch(from) and fileSearch(o.from)) or (lspProse(from) and lspProse(o.from)); + // A file search's rows share the directory's one +Search, and so do + // a terminal's word looks (a look of a word no file names, clicked + // or written): the next word refills it rather than stacking + // another. A `/` search keeps a +Search each, which n and N walk. + const terminal_word = p.word_look and from == .search and pane.isTerminal() and o.from == .search; + const shared = (fileSearch(from) and fileSearch(o.from)) or terminal_word or (lspProse(from) and lspProse(o.from)); if (i == id and !shared) continue; if (!shared and !std.meta.eql(o.from, from)) continue; if (!shared and by_arg and !std.mem.eql(u8, o.arg(), arg)) continue; diff --git a/src/look.zig b/src/look.zig index 0f99722d..e22f5705 100644 --- a/src/look.zig +++ b/src/look.zig @@ -1346,6 +1346,8 @@ fn lookUnresolved(p: *Pardes, id: usize, pane: *Pane, trimmed: []const u8, text: if (pane.image != null or (pane.body.mode == .tty and !p.fs.serving)) return; if (text.len == 0) return; if (p.settings.look_word == .search and pane.file != null) return lookWord(p, id, pane, text); + p.word_look = true; + defer p.word_look = false; const rows = runSearch(p, id, text, .text, .cursor, false) catch |err| { p.reportError(id, "search", err); return; diff --git a/src/pardes.zig b/src/pardes.zig index dc2ec59f..8c6ad5bb 100644 --- a/src/pardes.zig +++ b/src/pardes.zig @@ -4296,6 +4296,9 @@ pub const Pardes = struct { /// (exec.placeNew): closed at the step's end, once whatever made them /// is done with them. unplaced: std.StaticBitSet(MAX_PANES) = .initEmpty(), + /// A look's word search is running (look.lookUnresolved): from a + /// terminal its rows refill the directory's one +Search (Output). + word_look: bool = false, /// The running word came from the workspace's or a column's tag, which /// have no directory of their own: it runs in the session's /// (`sessionDir`), as acme's row and column tags do. -- cgit v1.3 From 939c369aee270067d9f030e2b234d93bae549988 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Wed, 30 Sep 2026 19:26:12 -0300 Subject: After a ThemeFile, the root ctl and DumpConfig say ThemeFile and its path, so what they report writes back Both said Theme and the name inside the .zon, which no Theme knows, so writing the report back to /ctl failed with "no theme". While a loaded ThemeFile is the theme in effect they now say the word that loaded it. A Dump carries the line too, so a Restore reloads the file. Co-Authored-By: Claude Opus 5.5 --- src/Output.zig | 1 + src/colors.zig | 8 ++++++++ src/config.zig | 8 +++++++- src/ninep/ctl.zig | 39 ++++++++++++++++++++++++++++++++++++++- 4 files changed, 54 insertions(+), 2 deletions(-) (limited to 'src/Output.zig') diff --git a/src/Output.zig b/src/Output.zig index 01797cbe..47fcc7e4 100644 --- a/src/Output.zig +++ b/src/Output.zig @@ -870,6 +870,7 @@ pub fn openConfig(p: *Pardes, id: usize) !void { .startup_config_path = p.opts.startup_config_path, .platform = @tagName(pardes.platform), .theme_name = p.theme().name, + .theme_file = pardes.colors.loadedThemeFile(p), .compiled_default_shell = config.defaultShell(), .hover_delay_frames = config.look_preview_delay_frames, .native_images = p.native_images, diff --git a/src/colors.zig b/src/colors.zig index c78043cc..8d541c13 100644 --- a/src/colors.zig +++ b/src/colors.zig @@ -735,6 +735,14 @@ pub fn requestThemeFile(p: *Pardes, id: usize, argument: []const u8) void { p.emit(.{ .theme_file = .{ .generation = generation, .on = true } }); } +/// The .zon a ThemeFile loaded, while it is the theme in effect: what +/// /ctl and DumpConfig say in place of `Theme `, since the name +/// inside the file is no theme `Theme` knows. +pub fn loadedThemeFile(p: *const Pardes) ?[]const u8 { + const path = p.theme_file_path.get(); + return if (p.custom_theme != null and path.len > 0) path else null; +} + pub const ThemeFileRequest = struct { path: []const u8, pane: u8, diff --git a/src/config.zig b/src/config.zig index 592281d3..a7377cfa 100644 --- a/src/config.zig +++ b/src/config.zig @@ -1267,6 +1267,9 @@ pub const Runtime = struct { startup_config_path: ?[]const u8, platform: []const u8, theme_name: []const u8, + /// The ThemeFile in effect, said as `ThemeFile ` in place + /// of the theme's name. + theme_file: ?[]const u8 = null, compiled_default_shell: []const u8, hover_delay_frames: ?u16, /// Where dumps go when `DumpDir` is unset; empty without a host @@ -1305,7 +1308,10 @@ pub const Runtime = struct { }; try out.print("{s} {s}\n", .{ setting.word, onOff(value) }); }, - .theme => try out.print("{s} {s}\n", .{ setting.word, context.theme_name }), + .theme => if (context.theme_file) |path| + try out.print("ThemeFile {s}\n", .{path}) + else + try out.print("{s} {s}\n", .{ setting.word, context.theme_name }), .window_opacity => { if (setting.enabled(context.capabilities)) try out.print("{s} {d}\n", .{ setting.word, state.window_opacity }) diff --git a/src/ninep/ctl.zig b/src/ninep/ctl.zig index 902a9647..bc27f72b 100644 --- a/src/ninep/ctl.zig +++ b/src/ninep/ctl.zig @@ -554,7 +554,9 @@ pub fn writeSettingsOf(p: *Pardes, s: *const config.Runtime, w: *std.Io.Writer) const word = setting.word; switch (setting.action) { .toggle => |field| try w.print("{s} {s}\n", .{ word, if (@field(s, @tagName(field))) "on" else "off" }), - .theme => try w.print("{s} {s}\n", .{ word, if (s == &p.settings) p.theme().name else pardes.themes[s.theme].name }), + .theme => if (s == &p.settings) { + if (pardes.colors.loadedThemeFile(p)) |path| try w.print("ThemeFile {s}\n", .{path}) else try w.print("{s} {s}\n", .{ word, p.theme().name }); + } else try w.print("{s} {s}\n", .{ word, pardes.themes[s.theme].name }), .shell => { const chosen = s.shell.requested.get(); try w.print("{s} {s}\n", .{ word, if (chosen.len > 0) chosen else config.defaultShell() }); @@ -1829,6 +1831,41 @@ test "an error's words give the errno a mount reads: EINVAL for what is malforme } } +test "after a ThemeFile the root ctl and DumpConfig say ThemeFile and its path, which writes back" { + if (comptime !pardes.hosted) return; + const gpa = testing.allocator; + const p = try withFile(gpa, "x\n"); + defer p.deinit(); + const root_ctl = @intFromEnum(tree.TopFile.ctl); + const path = "/tmp/pardes-mine-theme.zon"; + try testing.expectEqual(Status.ok, wr(p, root_ctl, "ThemeFile " ++ path ++ "\n").reply.status); + var custom = pardes.themes[0]; + custom.name = "mine"; + var encoded: std.Io.Writer.Allocating = .init(gpa); + defer encoded.deinit(); + try std.zon.stringify.serialize(custom, .{}, &encoded.writer); + try testing.expect(pardes.colors.loadThemeFile(p, p.theme_file_generation, encoded.written(), false)); + const settings = rd(p, root_ctl, 0, 1 << 16).bytes; + try testing.expect(std.mem.indexOf(u8, settings, "ThemeFile " ++ path ++ "\n") != null); + try testing.expect(std.mem.indexOf(u8, settings, "Theme mine") == null); + var storage: [16384]u8 = undefined; + var out: std.Io.Writer = .fixed(&storage); + try config.Runtime.writeReport(&out, .{ + .startup_config_path = null, + .platform = @tagName(pardes.platform), + .theme_name = p.theme().name, + .theme_file = pardes.colors.loadedThemeFile(p), + .compiled_default_shell = config.defaultShell(), + .hover_delay_frames = null, + .native_images = false, + .capabilities = builtins.capabilities, + .state = &p.settings, + }); + try testing.expect(std.mem.indexOf(u8, out.buffered(), "ThemeFile " ++ path ++ "\n") != null); + // Written back, it is the same request again, not "no theme mine". + try testing.expectEqual(Status.ok, wr(p, root_ctl, "ThemeFile " ++ path ++ "\n").reply.status); +} + test "Joincol with no column to the right and Theme with no such theme say so" { const gpa = testing.allocator; const p = try withFile(gpa, "x\n"); -- cgit v1.3 From 42b68e5ea63c32ff9359f2268ef0d8c08eaafff2 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Wed, 30 Sep 2026 19:28:12 -0300 Subject: Jumplist fills its one +Jumps again, as Recent does, never opening a second Each Jumplist opened another +Jumps below the asking pane, so a few clicks stacked stale copies of the list. Recent's refill of its own pane is now shared, and Jumplist uses it. Co-Authored-By: Claude Opus 5.5 --- src/Output.zig | 14 +++++++++----- src/ninep/ctl.zig | 17 +++++++++++++++++ 2 files changed, 26 insertions(+), 5 deletions(-) (limited to 'src/Output.zig') diff --git a/src/Output.zig b/src/Output.zig index 47fcc7e4..06f2f1dc 100644 --- a/src/Output.zig +++ b/src/Output.zig @@ -606,8 +606,7 @@ pub fn openJumps(p: *Pardes, id: usize) !void { else try out.writer.print("{s}:{d}:{d} {s}\n", .{ loc, j.line, j.col, what[0..cut] }); } - const content = try out.toOwnedSlice(); - try openStepped(p, id, .{ .cmd = .Jumplist }, content); + try refillOrOpen(p, id, .{ .cmd = .Jumplist }, try out.toOwnedSlice()); } /// The recent list as rows: `:: open|closed`, most recent @@ -699,12 +698,17 @@ pub fn openRecent(p: *Pardes, id: usize) !void { var out: std.Io.Writer.Allocating = .init(p.gpa); errdefer out.deinit(); try recentText(p, &out.writer, true); - const content = try out.toOwnedSlice(); + try refillOrOpen(p, id, .{ .cmd = .Recent }, try out.toOwnedSlice()); +} + +/// The one stepped output from `from`, filled again with `content` when it +/// is there (Recent, Jumplist), or opened when it is not. +fn refillOrOpen(p: *Pardes, id: usize, from: Origin, content: []u8) !void { for (p.panes, 0..) |slot, i| { const rp = slot orelse continue; const rf = if (rp.file) |*f| f else continue; const o = rf.output orelse continue; - if (!std.meta.eql(o.from, Origin{ .cmd = .Recent })) continue; + if (!std.meta.eql(o.from, from)) continue; File.setContent(p, rf, content); resetBody(p, rp); p.fs.refilled = rp.serial; @@ -715,7 +719,7 @@ pub fn openRecent(p: *Pardes, id: usize) !void { look.armLookWalk(p, i); return; } - try openStepped(p, id, .{ .cmd = .Recent }, content); + try openStepped(p, id, from, content); } pub fn openThemes(p: *Pardes, id: usize) !void { diff --git a/src/ninep/ctl.zig b/src/ninep/ctl.zig index bc27f72b..4fab699a 100644 --- a/src/ninep/ctl.zig +++ b/src/ninep/ctl.zig @@ -2989,6 +2989,23 @@ test "a column takes panes until their documented minimums fill it, not until no } } +test "Jumplist fills its one +Jumps again, as Recent does, never a second" { + const p = try withFile(testing.allocator, "x\n"); + defer p.deinit(); + const serial = serialOf(p); + var count: [2]usize = undefined; + for (&count) |*n| { + try testing.expectEqual(Status.ok, wr(p, Node.of(serial, .exec), "Jumplist\n").reply.status); + p.sync(); + n.* = 0; + for (p.panes) |slot| if (slot) |pane| if (pane.file) |f| if (f.output) |o| { + n.* += @intFromBool(std.meta.eql(o.from, panes.Output.Origin{ .cmd = .Jumplist })); + }; + } + try testing.expectEqual(@as(usize, 1), count[0]); + try testing.expectEqual(@as(usize, 1), count[1]); +} + test "a Jumplist entry is (closed) only while no pane has its file open" { const p = try withFile(testing.allocator, "x\n"); defer p.deinit(); -- cgit v1.3 From f8fe738416fe3a40a7136f2cb5528e8fd57f40df Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Wed, 30 Sep 2026 20:09:32 -0300 Subject: Recent and /recent keep PDFs and images as they keep files, and an open file's row is where its dot is now Only text files were recorded, so a PDF read yesterday was not there to find again, and an open file's row showed the place it last closed at, stale by however far it had moved since. A PDF is kept at its page and reopened there from its row; an image by its path; an open one's row reads its pane's place at the time of the listing. Co-Authored-By: Claude Opus 5.5 --- docs/fs.md | 7 ++++--- src/Output.zig | 10 ++++++++-- src/look.zig | 5 +++++ src/ninep/ctl.zig | 21 +++++++++++++++++++++ src/ninep/events.zig | 5 +++-- src/pardes.zig | 16 ++++++++++++++-- test/pdf.zig | 23 +++++++++++++++++++++++ 7 files changed, 78 insertions(+), 9 deletions(-) (limited to 'src/Output.zig') diff --git a/docs/fs.md b/docs/fs.md index 5e1c3ffb..7fa33a02 100644 --- a/docs/fs.md +++ b/docs/fs.md @@ -693,9 +693,10 @@ become spaces. - `/commands`: `Word [arg] root|pane|both [values] -- sentence`, one a line, generated from the builtin registry (`both`: Edit, at the active pane from the root). -- `/recent`: up to 200 files, most recent first, `open ` or `closed - `; kept in `$XDG_STATE_HOME/pardes/recent`. `Recent` shows them in a - pane; a look at a row reopens the file at its last dot. +- `/recent`: up to 200 files, PDFs and images, most recent first, `open + ` or `closed `; kept in `$XDG_STATE_HOME/pardes/recent`. + `Recent` shows them in a pane, an open one at its dot now and a closed + one at its last (a PDF's is its page); a look at a row reopens it there. - `/status`: `pid`, `version`, `panes`. - `/os/`: existing regular files take read, write and truncation to zero; create, remove, rename and metadata changes are refused; ownership is diff --git a/src/Output.zig b/src/Output.zig index 06f2f1dc..4aa0c021 100644 --- a/src/Output.zig +++ b/src/Output.zig @@ -612,10 +612,16 @@ pub fn openJumps(p: *Pardes, id: usize) !void { /// The recent list as rows: `:: open|closed`, most recent /// first; a look at a row opens the file there, as a +Jumps row does. pub fn recentText(p: *Pardes, w: *std.Io.Writer, look_rows: bool) !void { - for (p.recent.entries.items) |e| { + for (p.recent.entries.items) |stored| { + // An open one's row is where it is now, not where it last closed. + var e = stored; var is_open = false; - for (p.panes) |slot| if (slot) |pane| if (pane.file) |f| if (f.output == null and std.mem.eql(u8, f.path, e.path)) { + for (p.panes) |slot| if (slot) |pane| if (Pardes.recentPlace(pane)) |d| if (std.mem.eql(u8, d.path, e.path)) { is_open = true; + e.line = d.line; + e.col = d.col; + e.aline = d.aline; + e.acol = d.acol; }; const state: []const u8 = if (is_open) "open" else "(closed)"; if (!look_rows) { diff --git a/src/look.zig b/src/look.zig index 2e8a4b39..36b91545 100644 --- a/src/look.zig +++ b/src/look.zig @@ -1481,6 +1481,11 @@ pub fn reopenAt(p: *Pardes, from: usize, path: []const u8, at: Spot) void { lookAt(p, from, path); const id = p.active; const pane = p.panes[id] orelse return; + // A PDF's place is its page, the last if it has fewer now. + if (comptime pdf_enabled) if (pane.pdf) |*pv| if (std.mem.eql(u8, pv.path, path)) { + if (at.line > 0 and pv.focusLocation(p.pdf_gpa, @min(at.line, pv.page_count), 0)) panes.Pdf.resetPageChrome(pane); + return; + }; const f = if (pane.file) |*file| file else return; if (!std.mem.eql(u8, f.path, path)) return; // The empty "line" after a final newline is no line to land on. diff --git a/src/ninep/ctl.zig b/src/ninep/ctl.zig index eff8003b..75a7eb9a 100644 --- a/src/ninep/ctl.zig +++ b/src/ninep/ctl.zig @@ -3060,6 +3060,27 @@ test "a Jumplist entry is (closed) only while no pane has its file open" { for (p.jumps[0..p.njumps]) |j| try testing.expect(j.serial != 0); } +test "Recent's row for a file still open is where its dot is now, not where it last closed" { + const p = try withFile(testing.allocator, "x\n"); + defer p.deinit(); + var tmp = testing.tmpDir(.{}); + defer tmp.cleanup(); + try tmp.dir.writeFile(testing.io, .{ .sub_path = "a.txt", .data = "one\ntwo\nthree\n" }); + var dir_buf: [4096]u8 = undefined; + const dir = dir_buf[0..try tmp.dir.realPath(testing.io, &dir_buf)]; + var line: [4200]u8 = undefined; + try testing.expectEqual(Status.ok, wr(p, root_look, try std.fmt.bufPrint(&line, "{s}/a.txt:3\n", .{dir})).reply.status); + p.sync(); + const pane = p.panes[p.active].?; + pane.body.vsel.active = false; // the look's selection of line 3 let go + pane.body.cur_row = 1; + pane.body.cur_col = 2; + try testing.expectEqual(Status.ok, wr(p, root_exec, "Recent\n").reply.status); + const rows = p.panes[p.paneBySerial(try std.fmt.parseInt(u32, std.mem.trimEnd(u8, rd(p, root_exec, 0, 64).bytes, "\n"), 10)).?].?; + var want: [4300]u8 = undefined; + try testing.expect(std.mem.indexOf(u8, rows.file.?.content, try std.fmt.bufPrint(&want, "{s}/a.txt:2:3 open\n", .{dir})) != null); +} + test "a closed file is found again: Recent and /recent list it closed, a look at its row reopens it at its dot, and a jump back does too" { const p = try withFile(testing.allocator, "x\n"); defer p.deinit(); diff --git a/src/ninep/events.zig b/src/ninep/events.zig index a09f7278..bacf3ad6 100644 --- a/src/ninep/events.zig +++ b/src/ninep/events.zig @@ -140,8 +140,9 @@ pub fn announce(p: *Pardes) void { if (!pane.fs.unannounced) continue; pane.fs.unannounced = false; noteLog(p, .new, pane); - // A file opened (a look, a Restore, a boot): first in Recent. - if (pane.file) |f| if (f.output == null and pardes.Pardes.recentKeeps(f.path)) p.recent.opened(p.recentGpa(), f.path); + // A file, PDF or image opened (a look, a Restore, a boot): first in + // Recent. + if (pardes.Pardes.recentPlace(pane)) |d| if (pardes.Pardes.recentKeeps(d.path)) p.recent.opened(p.recentGpa(), d.path); } } diff --git a/src/pardes.zig b/src/pardes.zig index bea79b18..fbc19b8a 100644 --- a/src/pardes.zig +++ b/src/pardes.zig @@ -4709,13 +4709,25 @@ pub const Pardes = struct { return exec.isFile(local); } - /// A file pane closing: its place noted in Recent, when Recent keeps it. + /// A file, PDF or image pane closing: its place noted in Recent, when + /// Recent keeps it. fn noteClosed(p: *Pardes, pane: *const Pane) void { - const d = recentDot(pane) orelse return; + const d = recentPlace(pane) orelse return; if (p.recent.get(d.path) == null and !recentKeeps(d.path)) return; p.recent.closedSel(p.recentGpa(), d.path, d.line, d.col, d.aline, d.acol); } + pub const RecentPlace = struct { path: []const u8, line: u32, col: u32, aline: u32 = 0, acol: u32 = 0 }; + + /// Where a pane is, as Recent keeps it: a file's dot, a PDF's page + /// (`:page:1`), an image's path alone (line 0). Null for any other. + pub fn recentPlace(pane: *const Pane) ?RecentPlace { + if (recentDot(pane)) |d| return .{ .path = d.path, .line = d.line, .col = d.col, .aline = d.aline, .acol = d.acol }; + if (pane.pdfPath()) |path| return .{ .path = path, .line = @intCast(pane.pdfPage().? + 1), .col = 1 }; + if (pane.image) |iv| return .{ .path = iv.path, .line = 0, .col = 0 }; + return null; + } + fn recentDot(pane: *const Pane) ?struct { path: []const u8, line: u32, col: u32, aline: u32 = 0, acol: u32 = 0 } { const f = pane.file orelse return null; if (f.output != null) return null; diff --git a/test/pdf.zig b/test/pdf.zig index 2a18ca3c..fbd580b3 100644 --- a/test/pdf.zig +++ b/test/pdf.zig @@ -384,6 +384,29 @@ test "PdfSections on a PDF with no outline says so and opens nothing" { } } +test "Recent keeps a PDF as it keeps a file: open, then closed at its page" { + if (!pdf_enabled or platform == .web) return; + const gpa = std.testing.allocator; + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + const fixture = try pdf_impl.makeNoOutlineTestPdf(gpa); + defer gpa.free(fixture); + try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "plain.pdf", .data = fixture }); + var dir_buf: [4096]u8 = undefined; + const dir = dir_buf[0..try tmp.dir.realPath(std.testing.io, &dir_buf)]; + var path_buf: [4200]u8 = undefined; + const path = try std.fmt.bufPrint(&path_buf, "{s}/plain.pdf", .{dir}); + const p = try Pardes.init(gpa, .{ .cols = 80, .rows = 28 }); + defer p.deinit(); + pardes.look.lookAt(p, p.active, path); + p.update(.{ .resize = .{ .cols = 80, .rows = 28 } }); // an update's end announces it + var out: std.Io.Writer.Allocating = .init(gpa); + defer out.deinit(); + try panes.Output.recentText(p, &out.writer, true); + var want: [4300]u8 = undefined; + try std.testing.expect(std.mem.indexOf(u8, out.written(), try std.fmt.bufPrint(&want, "{s}:1:1 open\n", .{path})) != null); +} + test "a look at a PDF's page past its last is a miss, never the last page" { if (!pdf_enabled or platform == .web) return; const gpa = std.testing.allocator; -- cgit v1.3 From 5761f97293960ee7035f7866f09a9826a9e2f74a Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Wed, 30 Sep 2026 23:24:00 -0300 Subject: A refusal's +Unsaved goes in the session's directory when the active pane's directory is not there Exit or Restore refused over a pane named into a directory that does not exist made +Unsaved in that missing directory, where its rows could not be looked at and a Save of it could only fail. The list now goes in the session's directory when the asking pane's is not on disk. Co-Authored-By: Claude Opus 5.5 --- src/Output.zig | 5 ++++- src/ninep/ctl.zig | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) (limited to 'src/Output.zig') diff --git a/src/Output.zig b/src/Output.zig index 4aa0c021..1160c455 100644 --- a/src/Output.zig +++ b/src/Output.zig @@ -656,7 +656,10 @@ pub fn openUnsaved(p: *Pardes, id: usize, content: []u8) void { return; } const pane = p.panes[id] orelse return p.gpa.free(content); - const dir = if (pane.file) |f| (std.fs.path.dirname(f.path) orelse "/") else pane.cwdSlice(); + const own = if (pane.file) |f| (std.fs.path.dirname(f.path) orelse "/") else pane.cwdSlice(); + // Its directory gone (or never there, a name not yet saved): the list + // goes in the session's, where a look from it can still resolve. + const dir = if (comptime pardes.hosted) (if (pardes.filesystem.localPath(own)) |local| (if (exec.isDirectory(local)) own else p.sessionDir()) else own) else own; const free = p.freeSlot() orelse return p.gpa.free(content); _ = open(p, free, dir, .unsaved, "", content) catch return; exec.placeNew(p, id, id, free, .doc); diff --git a/src/ninep/ctl.zig b/src/ninep/ctl.zig index f8391672..e0c4b21b 100644 --- a/src/ninep/ctl.zig +++ b/src/ninep/ctl.zig @@ -1777,6 +1777,22 @@ test "exec Save writes the named file through the host" { try testing.expectEqualStrings(pane.file.?.content, p.fallback.get("/tmp/renamed.txt").?); } +test "a refusal's +Unsaved goes in the session's directory when the active pane's directory is not there" { + if (comptime !pardes.hosted) return; + const p = try withFile(testing.allocator, "x\n"); + defer p.deinit(); + const serial = serialOf(p); + try testing.expectEqual(Status.ok, wr(p, Node.of(serial, .name), "/tmp/pardes-no-such-dir-zz/x.txt\n").reply.status); + try testing.expectEqual(Status.ok, wr(p, Node.of(serial, .body), "edited\n").reply.status); + try testing.expectEqual(Status.err, wr(p, @intFromEnum(tree.TopFile.ctl), "Exit\n").reply.status); + const unsaved = for (p.panes) |slot| { + const pane = slot orelse continue; + const f = pane.file orelse continue; + if (f.output) |o| if (o.from == .unsaved) break f.path; + } else return error.NoUnsavedPane; + try testing.expectEqualStrings(p.sessionDir(), std.fs.path.dirname(unsaved).?); +} + test "a look at a file it may not read fails the write naming the file" { if (comptime !pardes.hosted) return; const p = try withFile(testing.allocator, "x\n"); -- cgit v1.3 From 77bda7e14e0ea81db5da54c233fc30d218773f47 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Thu, 1 Oct 2026 01:14:37 -0300 Subject: pardes - keeps one +Pager per directory, refilled, named so from its first log record; streams the text in bounded writes; never loses it; handles \r, NUL and BEL as a terminal does Each paged command made another +Pager until placement failed, and then git's text was lost with exit 0; a 130 MB page timed out half written and dirty; a directory whose name held a newline left a stray +New; and the log said new +New then rename. The root ctl's `pager ` now makes the directory's +Pager (named before it is announced, placed without the keyboard) or empties the one there; the text goes into it a line-ended 8 MiB chunk a write, one undo step, up to the file limit and its note, and is left clean. A directory a ctl line cannot name pages into the session's. Any failure prints the text to stderr with why and exits 1. A carriage return keeps a progress line's last state and CRLF is a newline; NUL, BEL, SO and SI go; empty stdin makes no pane. Co-Authored-By: Claude Opus 5.5 --- src/Output.zig | 43 +++++++++++++++++++++++++++ src/main.zig | 88 ++++++++++++++++++++++++++++++++++++++++++++++++------- src/ninep/ctl.zig | 12 ++++++++ test/fs.py | 25 ++++++++++++++++ 4 files changed, 157 insertions(+), 11 deletions(-) (limited to 'src/Output.zig') diff --git a/src/Output.zig b/src/Output.zig index 1160c455..e6448e36 100644 --- a/src/Output.zig +++ b/src/Output.zig @@ -666,6 +666,49 @@ pub fn openUnsaved(p: *Pardes, id: usize, content: []u8) void { p.active = id; } +/// `pardes -`'s pane: the one `/+Pager`, emptied for the next paged +/// text when it is there (a directory's paged commands refill it, as its +/// command pane is reused), else made, named so before it is announced, +/// and placed wherever there is room without taking the keyboard. `dir` +/// empty (or not absolute): the session's directory. Its id; NoPaneRoom +/// or NoPaneSlots when it has no room at all. +pub fn openPager(p: *Pardes, from: usize, dir_arg: []const u8) !usize { + const dir = if (dir_arg.len > 0 and dir_arg[0] == '/') dir_arg else p.sessionDir(); + const path = try std.fs.path.join(p.gpa, &.{ dir, "+Pager" }); + for (p.panes, 0..) |slot, i| { + const pane = slot orelse continue; + const f = if (pane.file) |*file| file else continue; + if (!std.mem.eql(u8, f.path, path)) continue; + p.gpa.free(path); + File.setContent(p, f, try p.gpa.alloc(u8, 0)); + resetBody(p, pane); + f.saved_revision = f.revision; + return i; + } + const free = p.freeSlot() orelse { + p.gpa.free(path); + return error.NoPaneSlots; + }; + const empty = p.gpa.alloc(u8, 0) catch |err| { + p.gpa.free(path); + return err; + }; + const pane = open(p, free, dir, .{ .cmd = .New }, "", empty) catch |err| { + p.gpa.free(path); + return err; + }; + // The pane owns the name from here. + p.gpa.free(pane.file.?.path); + pane.file.?.path = path; + const keyboard = p.active; + exec.placeNew(p, from, null, free, .fs); + if (p.unplaced.isSet(free)) return error.NoPaneRoom; + // Shown, not asked for: the keyboard stays where it was, as a command + // pane's does. + if (p.panes[keyboard] != null) p.active = keyboard; + return free; +} + /// Pane `gone` closed: its row goes from +Unsaved, which lists only panes /// still there to lose. pub fn dropUnsaved(p: *Pardes, gone: *const Pane) void { diff --git a/src/main.zig b/src/main.zig index 8818645e..6627bece 100644 --- a/src/main.zig +++ b/src/main.zig @@ -100,6 +100,58 @@ const help_text = \\ ; +/// `pardes -` inside a session: `text` into the directory's one +Pager +/// (root ctl `pager `, refilled when it is there), streamed into its +/// body a bounded chunk at a time as one undo step, and left clean. A text +/// the session would not take is never lost: it goes to stderr, with why, +/// and the exit is 1. +fn pageInto(io: std.Io, gpa: std.mem.Allocator, dial: []const u8, text: []const u8) void { + const Fail = struct { + fn with(o: std.Io, t: []const u8, what: []const u8, err: anyerror) noreturn { + var words_buf: [128]u8 = undefined; + const why = if (err == error.Remote) ninep_io.Client.lastSaid() else forwardWords(err, &words_buf); + var buf: [512]u8 = undefined; + const head = std.fmt.bufPrint(&buf, "pardes: -: {s}: {s}; the text follows\n", .{ what, why }) catch "pardes: -: refused; the text follows\n"; + std.Io.File.stderr().writeStreamingAll(o, head) catch {}; + std.Io.File.stderr().writeStreamingAll(o, t) catch {}; + std.process.exit(1); + } + }; + // The pane's directory: this one, unless its name could not be one line + // of a ctl (a newline, a control byte): then the session's. + var cwd_buf: [4096]u8 = undefined; + const cwd: []const u8 = if (std.c.getcwd(&cwd_buf, cwd_buf.len)) |c| std.mem.span(@as([*:0]u8, @ptrCast(c))) else ""; + const plain = for (cwd) |c| { + if (c < ' ' or c == 0x7f) break false; + } else true; + var line_buf: [4200]u8 = undefined; + const ctl_line = std.fmt.bufPrint(&line_buf, "pager {s}\n", .{if (plain) cwd else ""}) catch "pager\n"; + ninep_io.Client.write(gpa, dial, "/ctl", ctl_line) catch |err| Fail.with(io, text, "no +Pager pane", err); + const answer = ninep_io.Client.read(gpa, dial, "/exec", "/exec") catch |err| Fail.with(io, text, "no +Pager pane", err); + const serial = std.fmt.parseInt(u32, std.mem.trim(u8, answer, " \n"), 10) catch |err| Fail.with(io, text, "no +Pager pane", err); + var path_buf: [64]u8 = undefined; + const mark = std.fmt.bufPrint(&path_buf, "/pane/{d}/mark", .{serial}) catch unreachable; + // One undo step for the whole text, however many writes carry it. + ninep_io.Client.write(gpa, dial, mark, "0\n") catch |err| Fail.with(io, text, "the +Pager pane went", err); + var body_buf: [64]u8 = undefined; + const body = std.fmt.bufPrint(&body_buf, "/pane/{d}/body", .{serial}) catch unreachable; + // A chunk ends on a line's end (never inside a character), each its own + // write with its own deadline, so a large text arrives whole. + const chunk_max = 8 * 1024 * 1024; + var at: usize = 0; + while (at < text.len) { + var end = @min(text.len, at + chunk_max); + if (end < text.len) if (std.mem.lastIndexOfScalar(u8, text[at..end], '\n')) |nl| { + end = at + nl + 1; + }; + ninep_io.Client.write(gpa, dial, body, text[at..end]) catch |err| Fail.with(io, text[at..], "the +Pager pane would not take it", err); + at = end; + } + ninep_io.Client.write(gpa, dial, mark, "1\n") catch {}; + var ctl_buf: [64]u8 = undefined; + ninep_io.Client.write(gpa, dial, std.fmt.bufPrint(&ctl_buf, "/pane/{d}/ctl", .{serial}) catch unreachable, "clean\n") catch {}; +} + /// Stdin to its end, its terminal escapes stripped (a pager's input is /// coloured for a terminal; a text pane shows text), at most a file's /// limit, a longer one cut there and said so at its end. @@ -167,6 +219,23 @@ pub fn stripEscapes(gpa: std.mem.Allocator, bytes: []const u8) ![]u8 { i += 1; continue; } + // A carriage return: CRLF is a newline; alone, the line starts + // over, as on a terminal, so a progress line keeps its last state. + if (c == '\r') { + if (i + 1 < bytes.len and bytes[i + 1] == '\n') { + i += 1; + continue; + } + const line_start = if (std.mem.lastIndexOfScalar(u8, out.items, '\n')) |nl| nl + 1 else 0; + out.shrinkRetainingCapacity(line_start); + i += 1; + continue; + } + // Bytes a terminal acts on and never shows: NUL, BEL, SO, SI. + if (c == 0 or c == 0x07 or c == 0x0e or c == 0x0f) { + i += 1; + continue; + } out.appendAssumeCapacity(c); i += 1; } @@ -181,6 +250,9 @@ test "stripEscapes takes out colour, other escapes and overstrike, and keeps the .{ "N\x08NA\x08AM\x08ME\x08E _\x08u", "NAME u" }, .{ "plain\ttext\n", "plain\ttext\n" }, .{ "\x1b(Bdone", "done" }, + .{ "a\r\nb\r\n", "a\nb\n" }, + .{ "10%\r50%\r100%\ndone\n", "100%\ndone\n" }, + .{ "x\x00y\x07z\x0e\x0f\n", "xyz\n" }, }; for (cases) |c| { const got = try stripEscapes(gpa, c[0]); @@ -537,17 +609,9 @@ fn nativeMain(init: std.process.Init) !void { // and the body), and back at once: the PAGER a pane's shell gets. if (positional) |word| if (std.mem.eql(u8, word, "-")) { const text = readStdinText(arena) catch |err| Refuse.with(init.io, "stdin", err); - const made = ninep_io.Client.read(arena, parent.dial, "/pane/new", "/pane/new") catch |err| Refuse.with(init.io, "-", err); - const serial = std.fmt.parseInt(u32, std.mem.trim(u8, made, " \n"), 10) catch |err| Refuse.with(init.io, "-", err); - var cwd_buf: [4096]u8 = undefined; - const cwd = if (std.c.getcwd(&cwd_buf, cwd_buf.len)) |c| std.mem.span(@as([*:0]u8, @ptrCast(c))) else "/"; - var path_buf: [64]u8 = undefined; - var line_buf: [4200]u8 = undefined; - const name_line = std.fmt.bufPrint(&line_buf, "{s}/+Pager\n", .{std.mem.trimEnd(u8, cwd, "/")}) catch "/+Pager\n"; - ninep_io.Client.write(arena, parent.dial, try std.fmt.bufPrint(&path_buf, "/pane/{d}/name", .{serial}), name_line) catch |err| Refuse.with(init.io, "-", err); - if (text.len > 0) ninep_io.Client.write(arena, parent.dial, try std.fmt.bufPrint(&path_buf, "/pane/{d}/body", .{serial}), text) catch |err| Refuse.with(init.io, "-", err); - // Shown, not edited: nothing to ask about at Exit. - ninep_io.Client.write(arena, parent.dial, try std.fmt.bufPrint(&path_buf, "/pane/{d}/ctl", .{serial}), "clean\n") catch {}; + // Nothing paged: no pane, and done. + if (text.len == 0) return; + pageInto(init.io, arena, parent.dial, text); return; }; const typed_word = positional orelse { @@ -644,6 +708,8 @@ fn nativeMain(init: std.process.Init) !void { // as `vim -` does; the terminal is /dev/tty, never stdin. if (positional) |a| if (std.mem.eql(u8, a, "-")) { opts.stdin_text = readStdinText(arena) catch |err| badArgs(init.io, "stdin: {s}", .{@errorName(err)}); + // Nothing paged: nothing to show. + if (opts.stdin_text.?.len == 0) return; positional = null; }; if (positional) |a| { diff --git a/src/ninep/ctl.zig b/src/ninep/ctl.zig index fd3418a1..82001f32 100644 --- a/src/ninep/ctl.zig +++ b/src/ninep/ctl.zig @@ -642,6 +642,18 @@ pub fn writeRoot(p: *Pardes, req: Req) Reply { var it = Messages.init(p, req.data); while (it.next()) |line| { if (line.len == 0 or exec_line.isComment(line)) continue; + // `pardes -`'s: the directory's +Pager made or emptied, its + // serial what /exec reads back. + if (std.mem.startsWith(u8, line, "pager ") or std.mem.eql(u8, line, "pager")) { + if (!apply) continue; + const id = pardes.panes.Output.openPager(p, p.active, std.mem.trim(u8, line["pager".len..], " \t")) catch |err| + return tree.failText(req.tag, if (err == error.NoPaneRoom or err == error.NoPaneSlots) E.NOSPC else E.IO, switch (err) { + error.NoPaneRoom, error.NoPaneSlots => "pager: no space for a +Pager pane", + else => "pager: could not make a +Pager pane", + }); + noteResult(p, p.panes[id].?.serial); + continue; + } if (std.mem.startsWith(u8, line, "size ") or std.mem.eql(u8, line, "size")) { const size = sizeOf(line) orelse return refuse(p, req, e_size, line); // A frontend's window is the size; only a session none is diff --git a/test/fs.py b/test/fs.py index fce315fc..b2f52c3e 100644 --- a/test/fs.py +++ b/test/fs.py @@ -1456,7 +1456,32 @@ def test(binary, quic=False): assert client.read(f'/pane/{made_now}/body') == b'bold text\n' row = [r for r in client.read('/index').splitlines() if r.split()[0] == str(made_now).encode()][0] assert row.split()[2] == b'0', row # clean: nothing to ask at Exit + # Its `new` record names it as it is: no +New and a rename. + log_now = client.read('/log').decode() + assert f'\nnew {made_now} {root}/+Pager\n' in '\n' + log_now, log_now[-400:] + assert f'\nrename {made_now} ' not in '\n' + log_now + # The directory's one +Pager: the next paged text refills it. + fed = subprocess.run([binary, '-'], cwd=root, env=env, input=b'again\r\nprogress 10%\rprogress 100%\n', + stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=10) + assert fed.returncode == 0, fed.stderr + assert serials() - before == {made_now}, (serials(), before) + assert client.read(f'/pane/{made_now}/body') == b'again\nprogress 100%\n' client.remove(f'/pane/{made_now}') + # From a directory whose name could not be a ctl line: the + # session's directory's +Pager, the text whole, no stray +New. + odd = root / 'two\nlines' + odd.mkdir() + fed = subprocess.run([binary, '-'], cwd=odd, env=env, input=b'odd dir text\n', + stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=10) + assert fed.returncode == 0, fed.stderr + odd_pane, = serials() - before + assert client.read(f'/pane/{odd_pane}/name') == f'{root}/+Pager\n'.encode() + assert client.read(f'/pane/{odd_pane}/body') == b'odd dir text\n' + client.remove(f'/pane/{odd_pane}') + # Nothing on stdin: no pane, and done. + fed = subprocess.run([binary, '-'], cwd=root, env=env, input=b'', + stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=10) + assert fed.returncode == 0 and serials() == before, (fed, serials()) # A new name in a directory there but not writable: refused now, # not a pane that only fails at Save. shut = root / 'shut-dir' -- cgit v1.3 From 528c5a28ac3b813a2d0c06a019d7758476257915 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Thu, 1 Oct 2026 06:47:48 -0300 Subject: A second LookWord list look in a directory refills its +Search, as a terminal's word looks already did, rather than stacking another Each word looked at with LookWord list opened a +Search of its own in the same directory. Word looks now share the directory's one, the next word refilling it; a `/` search still keeps a +Search each. Co-Authored-By: Claude Opus 5.5 --- src/Output.zig | 9 +++++---- src/ninep/ctl.zig | 23 +++++++++++++++++++++++ test/snapshots/rsearch.golden | 34 ++++++++++++++++++---------------- 3 files changed, 46 insertions(+), 20 deletions(-) (limited to 'src/Output.zig') diff --git a/src/Output.zig b/src/Output.zig index e6448e36..fc300e8b 100644 --- a/src/Output.zig +++ b/src/Output.zig @@ -525,10 +525,11 @@ pub fn fillResults(p: *Pardes, id: usize, dir: []const u8, from: Origin, arg: [] const rf = if (rp.file) |*f| f else continue; const o = if (rf.output) |*x| x else continue; // A file search's rows share the directory's one +Search, and so do - // a terminal's word looks (a look of a word no file names, clicked - // or written): the next word refills it rather than stacking - // another. A `/` search keeps a +Search each, which n and N walk. - const terminal_word = p.word_look and from == .search and pane.isTerminal() and o.from == .search; + // word looks (`LookWord list`, a terminal's word: a look of a word + // no file names, clicked or written): the next word refills it + // rather than stacking another. A `/` search keeps a +Search each, + // which n and N walk. + const terminal_word = p.word_look and from == .search and o.from == .search; const shared = (fileSearch(from) and fileSearch(o.from)) or terminal_word or (lspProse(from) and lspProse(o.from)); if (i == id and !shared) continue; if (!shared and !std.meta.eql(o.from, from)) continue; diff --git a/src/ninep/ctl.zig b/src/ninep/ctl.zig index 70ed51a7..ad427cad 100644 --- a/src/ninep/ctl.zig +++ b/src/ninep/ctl.zig @@ -4165,3 +4165,26 @@ test "`@pN:` looks at pane N as `a.txt:` looks at a.txt, and a line past the end try testing.expect(std.mem.endsWith(u8, said, "/test.txt:99999 has no line 99999")); } } + +test "a second LookWord list look in a directory refills its +Search rather than stacking another" { + if (comptime !pardes.hosted) return; + const gpa = testing.allocator; + var tmp = testing.tmpDir(.{}); + defer tmp.cleanup(); + try tmp.dir.writeFile(testing.io, .{ .sub_path = "words.txt", .data = "alpha beta\nalpha beta\n" }); + var dir_buf: [4096]u8 = undefined; + const dir = dir_buf[0..try tmp.dir.realPath(testing.io, &dir_buf)]; + var path_buf: [4200]u8 = undefined; + const path = try std.fmt.bufPrint(&path_buf, "{s}/words.txt", .{dir}); + const p = try Pardes.init(gpa, .{ .file = path, .tty_only = true, .cols = 80, .rows = 30 }); + defer p.deinit(); + _ = wr(p, @intFromEnum(tree.TopFile.ctl), "LookWord list\n"); + pardes.look.lookAt(p, 0, "alpha"); + pardes.look.lookAt(p, 0, "beta"); + var searches: usize = 0; + for (p.panes) |slot| if (slot) |pn| if (pn.file) |f| if (std.mem.endsWith(u8, f.path, "+Search")) { + searches += 1; + try testing.expectEqualStrings("beta", f.output.?.arg()); + }; + try testing.expectEqual(@as(usize, 1), searches); +} diff --git a/test/snapshots/rsearch.golden b/test/snapshots/rsearch.golden index eb98853a..870831b4 100644 --- a/test/snapshots/rsearch.golden +++ b/test/snapshots/rsearch.golden @@ -18,24 +18,26 @@ |15: 4 count_x again |16: 5 == snap select grid=210x31 cursor=14,10 -|16: /tmp/pardes-snap/rsearch/cwd/+Search Save Tty Collapse Del LocationsConfig -|17: 1 code.txt:4:1-8 -|18: 2 pick two words -|19: 3 -== snap path-open grid=210x31 cursor=16,22 -|19: /tmp/pardes-snap/rsearch/cwd/sub/dep.txt Save Tty Collapse Del -|20: 1 d1 -|21: 2 d2 -|22: 3 DEPTARGET -|23: 4 d4 -|24: 5 d5 -|25: 6 d6 +|12: 1 code.txt:4:1-8 +|13: 2 pick two words +|14: 3 +|15: +|16: +== snap path-open grid=210x31 cursor=16,17 +|14: /tmp/pardes-snap/rsearch/cwd/sub/dep.txt Save Tty Collapse Del +|15: 1 d1 +|16: 2 d2 +|17: 3 DEPTARGET +|18: 4 d4 +|19: 5 d5 +|20: 6 d6 == snap step1 grid=210x31 cursor=13,9 +|12: 2 run count_x now +|13: 3 code.txt:3:1-7 == snap step2 grid=210x31 cursor=13,9 == snap step3 grid=210x31 cursor=13,9 == snap selclick grid=210x31 cursor=14,10 +|12: 1 code.txt:4:1-8 +|13: 2 pick two words == snap outside grid=210x31 cursor=20,10 -|25: /tmp/pardes-snap/rsearch/cwd/+Search Save Tty Collapse Del LocationsConfig -|26: 1 code.txt:4:10-14 -|27: 2 pick two words -|28: 3 +|12: 1 code.txt:4:10-14 -- cgit v1.3 From 12cf44acc4edede7f20440be5ac4fd81a8c7a8c0 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Thu, 1 Oct 2026 08:15:56 -0300 Subject: Find's notes stay at the end, under the names it found, as Grep's do: `1 directory skipped` no longer sorts first Find's rows are sorted by path as they are filled in, and the note line was sorted with them, so it led the list. The rows above the first note are sorted, the notes left where they are. Co-Authored-By: Claude Opus 5.5 --- src/Output.zig | 9 +++++++++ src/ninep/ctl.zig | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) (limited to 'src/Output.zig') diff --git a/src/Output.zig b/src/Output.zig index fc300e8b..5422411f 100644 --- a/src/Output.zig +++ b/src/Output.zig @@ -363,6 +363,15 @@ fn sortResults(arena: std.mem.Allocator, from: Origin, content: []u8, anchor: ?u } if (content.len == 0) return anchor; const path_only = std.meta.eql(from, Origin{ .cmd = .Find }); + // A walk's notes (fs.WalkNotes) stay under the hits: only the rows + // above the first are sorted. + if (path_only) { + var off: usize = 0; + var it = std.mem.splitScalar(u8, content, '\n'); + while (it.next()) |line| : (off += line.len + 1) if (@import("fs.zig").WalkNotes.isNote(line)) { + return if (off == 0) anchor else sortResults(arena, from, content[0..off], anchor); + }; + } const trailing_newline = content[content.len - 1] == '\n'; const body = content[0 .. content.len - @intFromBool(trailing_newline)]; var lines = std.mem.splitScalar(u8, body, '\n'); diff --git a/src/ninep/ctl.zig b/src/ninep/ctl.zig index d4f36bea..3b3873e3 100644 --- a/src/ninep/ctl.zig +++ b/src/ninep/ctl.zig @@ -4262,3 +4262,35 @@ test "a Rename the server answered for this file alone, with other open files sa p.lspResponse(p.lsp_wait.?.id, "util.zig:1:8 sum\nmain.zig: also says add, which the server did not rename\n"); try testing.expect(th.logHas(p, "Rename: previewed, not applied: the server renamed in this file only, and 1 other open file(s) say the name")); } + +test "Find ends with what it skipped, and a Find or Grep that finds nothing leaves the +Search as it was" { + if (comptime !pardes.hosted) return; + const gpa = testing.allocator; + var tmp = testing.tmpDir(.{}); + defer tmp.cleanup(); + try tmp.dir.writeFile(testing.io, .{ .sub_path = "zz-needle.txt", .data = "needle\n" }); + try tmp.dir.createDirPath(testing.io, "locked"); + var dir_buf: [4096]u8 = undefined; + const dir = dir_buf[0..try tmp.dir.realPath(testing.io, &dir_buf)]; + var locked_buf: [4200]u8 = undefined; + const locked = try std.fmt.bufPrintSentinel(&locked_buf, "{s}/locked", .{dir}, 0); + if (std.c.chmod(locked, 0) != 0) return; + defer _ = std.c.chmod(locked, 0o755); + var path_buf: [4200]u8 = undefined; + const path = try std.fmt.bufPrint(&path_buf, "{s}/zz-needle.txt", .{dir}); + const p = try Pardes.init(gpa, .{ .file = path, .tty_only = true, .cols = 80, .rows = 30 }); + defer p.deinit(); + try testing.expect(p.executeBuiltinLine(0, "Find needle")); + const search = p.panes[p.panes[0].?.search_pane.?].?; + const listed = search.file.?.content; + try testing.expect(std.mem.endsWith(u8, listed, "1 directory skipped: permission denied\n")); + try testing.expect(std.mem.startsWith(u8, listed, "zz-needle.txt\n")); + // Nothing found where it looked, and nothing passed over: the miss is + // said, and the +Search keeps the last search's rows. + _ = std.c.chmod(locked, 0o755); + const before = try gpa.dupe(u8, listed); + defer gpa.free(before); + try testing.expect(p.executeBuiltinLine(0, "Find nosuchname")); + try testing.expectEqualStrings(before, search.file.?.content); + try testing.expect(th.logHas(p, "Find: name not found")); +} -- cgit v1.3 From 2dbb047a82523c578cb511058c6e1b745cfc8073 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Thu, 1 Oct 2026 17:36:52 -0300 Subject: A look at a directory opens a pane listing it, as acme's directory window: named dir/, its entries in acme's columns (bytewise, dotfiles kept, a directory's marked /), a look at an entry from there, Get or a look again reads it again, never dirty, Save refused; DirLook terminal keeps ls in a terminal Co-Authored-By: Claude Opus 5.5 --- docs/typ/builtins-gui.json | 1 + docs/typ/builtins-tty.json | 1 + docs/typ/cheatsheet.typ | 2 +- docs/typ/guide.typ | 2 +- docs/typ/reference.typ | 7 +- src/CHANGELOG.md | 4 + src/Dir.zig | 507 ++++++++++++++++++++++++++++++++++++++++++ src/File.zig | 11 + src/Output.zig | 15 +- src/builtins.zig | 10 +- src/config.zig | 14 +- src/exec.zig | 6 + src/host_io.zig | 2 +- src/look.zig | 5 + src/ninep/ctl.zig | 21 +- src/ninep/pane.zig | 2 +- src/panes.zig | 3 + src/pardes.zig | 8 +- src/tagline.zig | 2 + test/fs.py | 26 +++ test/snapshots/cmdword.snap | 3 + test/snapshots/dirpane.golden | 13 ++ test/snapshots/dirpane.snap | 27 +++ test/snapshots/look-dir.snap | 3 + test/snapshots/lookpanes.snap | 3 + test/snapshots/nested.golden | 8 +- test/snapshots/ttylook.snap | 3 + 27 files changed, 684 insertions(+), 25 deletions(-) create mode 100644 src/Dir.zig create mode 100644 test/snapshots/dirpane.golden create mode 100644 test/snapshots/dirpane.snap (limited to 'src/Output.zig') diff --git a/docs/typ/builtins-gui.json b/docs/typ/builtins-gui.json index ec214069..e4a8f611 100644 --- a/docs/typ/builtins-gui.json +++ b/docs/typ/builtins-gui.json @@ -26,6 +26,7 @@ {"name": "Delcol", "leader": "SPC c d", "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Close this column and its panes, refusing once over unsaved text."}, {"name": "Detach", "leader": "SPC s D", "also": [], "arg": false, "scope": "root", "setting": false, "choices": null, "doc": "Detach this pardes from its terminal, leaving the session running."}, {"name": "Diagnostics", "leader": "SPC l d", "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "List the file's diagnostics from the language server."}, + {"name": "DirLook", "leader": null, "also": [], "arg": true, "scope": "root", "setting": true, "choices": "pane, terminal", "doc": "A directory looked at: pane, a pane listing it as acme's directory window, or terminal, ls in a terminal there."}, {"name": "Down", "leader": "SPC w j", "also": ["C-w j", "C-w down"], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Move the keyboard to the pane below, off a tag onto the pane under it."}, {"name": "Dump", "leader": "SPC s d", "also": ["topbar"], "arg": false, "scope": "root", "setting": false, "choices": null, "doc": "Write the session's panes and layout to a dump file, for Restore."}, {"name": "DumpConfig", "leader": null, "also": [], "arg": false, "scope": "root", "setting": false, "choices": null, "doc": "Open the settings in effect, each a word to click, and the startup file's path."}, diff --git a/docs/typ/builtins-tty.json b/docs/typ/builtins-tty.json index 6dd09882..959f88ce 100644 --- a/docs/typ/builtins-tty.json +++ b/docs/typ/builtins-tty.json @@ -23,6 +23,7 @@ {"name": "Delcol", "leader": "SPC c d", "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Close this column and its panes, refusing once over unsaved text."}, {"name": "Detach", "leader": "SPC s D", "also": [], "arg": false, "scope": "root", "setting": false, "choices": null, "doc": "Detach this pardes from its terminal, leaving the session running."}, {"name": "Diagnostics", "leader": "SPC l d", "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "List the file's diagnostics from the language server."}, + {"name": "DirLook", "leader": null, "also": [], "arg": true, "scope": "root", "setting": true, "choices": "pane, terminal", "doc": "A directory looked at: pane, a pane listing it as acme's directory window, or terminal, ls in a terminal there."}, {"name": "Down", "leader": "SPC w j", "also": ["C-w j", "C-w down"], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Move the keyboard to the pane below, off a tag onto the pane under it."}, {"name": "Dump", "leader": "SPC s d", "also": ["topbar"], "arg": false, "scope": "root", "setting": false, "choices": null, "doc": "Write the session's panes and layout to a dump file, for Restore."}, {"name": "DumpConfig", "leader": null, "also": [], "arg": false, "scope": "root", "setting": false, "choices": null, "doc": "Open the settings in effect, each a word to click, and the startup file's path."}, diff --git a/docs/typ/cheatsheet.typ b/docs/typ/cheatsheet.typ index d8ea87ac..e95f5076 100644 --- a/docs/typ/cheatsheet.typ +++ b/docs/typ/cheatsheet.typ @@ -41,7 +41,7 @@ Typed anywhere, then #btn("B3") or #key("Enter"): addr(":40"), [the pane looked from, line 40 (`:40:5`, any address after `:`)], addr("~/x"), [home; also in #word("Save"), #word("Restore"), `pardes ~/x`], addr("@p3:12"), [pane 3 by serial, a terminal's lines too], - addr("src/"), [a directory: `ls` in an idle terminal there, else a new one], + addr("src/"), [a directory: a pane listing it; `Get` reads it again], ) Addresses are sam's: `#n`, `/re/`, `?re?`, `$`, `a,b`. #doc("fs", section: "look-and-exec") diff --git a/docs/typ/guide.typ b/docs/typ/guide.typ index 077c62f1..5bfff0ce 100644 --- a/docs/typ/guide.typ +++ b/docs/typ/guide.typ @@ -157,7 +157,7 @@ pardes. addr("notes.txt"), [opens it, or goes to the pane already showing it], addr("notes.txt:12"), [line 12], addr("notes.txt:/TODO/"), [the next match of `TODO`], - addr("src/"), [`ls` typed into a terminal idle there, else a new terminal there], + addr("src/"), [a pane listing it, as acme's directory window: a #word("Look") at an entry opens it, `..` goes up, `Get` reads it again (#word("DirLook") `terminal`: `ls` in a terminal there)], addr("https://ziglang.org"), [the browser, through `xdg-open` (`open` on macOS); there is no plumber], ) diff --git a/docs/typ/reference.typ b/docs/typ/reference.typ index 29f535ee..a7ac997e 100644 --- a/docs/typ/reference.typ +++ b/docs/typ/reference.typ @@ -403,6 +403,7 @@ word clicked in a tag does. The same lines go in the startup file [#word("Placement") `acme|pardes`], [`acme`: where new panes go (#doc("fs", section: "placement"))], [#word("BootShell") `keep|replace`], [`keep`; `replace` closes the untouched lone shell a dragged document lands beside], [#word("LookWord") `search|list`], [`search`: a word given to #word("Look") selects its next place, or lists all in `+Search`], + [#word("DirLook") `pane|terminal`], [`pane`: #word("Look") on a directory opens a pane listing it, as acme's directory window (#doc("reference", section: "from-acme")); `terminal` types `ls` into a terminal idle there, else opens one], [#word("TermImages") `real|petscii`], [`real`: a new terminal draws its program's kitty graphics (yazi's previews) as pixels where the shell can; #word("Petscii") flips one terminal; a tty under a terminal without kitty graphics draws them as glyph art either way], [#word("Shell") ``], [`$SHELL` when it is executable, else `/bin/sh`: the shell the next terminal and command pane run; a bare name is searched for in the usual bin directories, not `$PATH`; bare #word("Shell"): `$SHELL` if it is executable, else `/bin/sh`], [#word("DumpDir") ``], [`$XDG_DATA_HOME/pardes`, else `~/.local/share/pardes`: where #word("Dump") writes, an absolute or `~` path to a directory that may be written (made if missing); a relative one, or one under a directory that may not be written, is refused; bare returns to the default], @@ -564,7 +565,7 @@ makes its column the active one (a folded pane stays folded); `no such pane`, or while a column or workspace tag has the keyboard. *Pane ctl.* Reading it gives acme's status line: serial, tag length, body -length, isdir (0), dirty, width in cells, font, tab width, undo available, +length, isdir (1 for a directory pane, else 0), dirty, width in cells, font, tab width, undo available, redo available, then `current`/`notcurrent`, a REPL's id if bound, `collapsed` when it is, and for a PDF `fit:width|height tint:disabled|filtered|full`. It @@ -1026,13 +1027,13 @@ with Client(sys.argv[1]) as c: # a socket path, or (ip, port) [`addr` reset on first open], [#file("addr") is the pane's; no open resets it (write `0`)], [OTRUNC on `data` ignored], [`: > data` deletes the addressed text; OTRUNC on #file("body") (`9p write`) replaces it all], [event flags 1, 2, 4, 8], [1, 4 and 8; never 2, so no expansion record follows], - [`Get`], [`get` on the pane's #file("ctl")], + [`Get`], [`get` on the pane's #file("ctl"); `Get` itself only in a directory pane], [`Put`, `Delete`], [#word("Save"); a #word("Del") that does not ask], [`Snarf`, `Cut`, `Paste`], [refused: the chords, #key("y"), #key("p")], [acme's other builtins], [refused: `Putall`, `Zerox`, `Sort`, `Load`, `ID`, `Send`, `Tab`, `Indent`, `Local`, `Incl`, `Abort`], [Edit], [no `< | >`, `X`, `Y`, `b B D e r w f`, no `\1`-`\9`; an alternation takes the first branch that matches, not the longest (#doc("fs", section: "edit"))], [`win`], [#word("Tty") is a VT terminal pane; #file("pty/run") runs a line at its prompt and answers `exit N` and the output; with #word("Repl") bound, #word("Exec") on a source pane types the text into it], - [a directory window], [#word("Look") on a directory types `ls` into a terminal idle there, else opens one], + [a directory window], [as acme's: a text pane named `dir/` (#file("index") kind `text`, #file("ctl") isdir 1), its entries in columns sorted bytewise, dotfiles shown, a directory's marked `/`; blanks pad the columns where acme's tabs do; a #word("Look") at an entry is from that directory, `Get` or a look at it again reads it again, and an edit is kept until then rather than lost to a resize; never dirty, #word("Save") refuses it; #word("DirLook") `terminal` types `ls` into a terminal there instead], [the plumber], [none: #word("Look") on an `http://` or `https://` URL runs `xdg-open` (`open` on macOS); files, addresses and directories follow built-in rules], [#key("Esc") selects what was typed], [#key("Esc") leaves insert mode, or goes back a pane (#doc("tags", section: "modes"))], ) diff --git a/src/CHANGELOG.md b/src/CHANGELOG.md index 941ff2b1..6be39c7a 100644 --- a/src/CHANGELOG.md +++ b/src/CHANGELOG.md @@ -2,6 +2,10 @@ ## 0.23 +- A look at a directory opens a pane listing it, as acme's directory + window does: its entries in columns, a directory's marked `/`. A look at + an entry opens it from there, and `Get` or a look at it again reads it + again. `DirLook terminal` types `ls` into a terminal there, as before. - Restore reads a clean file pane from disk, so a file changed since the Dump comes back as it is now. An unsaved pane keeps its text, and if its file changed on disk its first Save asks before overwriting. A dump holds diff --git a/src/Dir.zig b/src/Dir.zig new file mode 100644 index 00000000..979cd51a --- /dev/null +++ b/src/Dir.zig @@ -0,0 +1,507 @@ +//! Directory panes, acme's directory windows (plan9port acme text.c, +//! textload and textcolumnate): a look at a directory opens a pane named +//! for it with a trailing `/`, its body the directory's entries in columns +//! that fit the pane, a directory's marked with a `/`. A look at an entry +//! is a look from that directory; Get, or a look at the directory again, +//! reads it again. Otherwise it is a text pane like +Errors (Output's +//! `.dir`): searched, selected and edited as any, and never dirty. +const std = @import("std"); +const pardes = @import("pardes.zig"); +const panes = @import("panes.zig"); +const config = @import("config.zig"); +const exec = @import("exec.zig"); +const filesystem = @import("fs.zig"); +const limits = @import("memory.zig").limits; +const Pardes = pardes.Pardes; +const Pane = panes.Pane; +const File = panes.File; + +/// What a directory pane keeps of its listing, as acme's Window keeps +/// dlp/ndl: the entries, for a change of width to lay them out again. +pub const State = struct { + /// The entries, sorted, each ending in a newline; gpa-owned. + names: []u8, + /// The text width they were laid out at (none yet: the most there is), + /// and the text's revision then: a body edited since is left as it is. + width: usize = std.math.maxInt(usize), + revision: u32 = 0, +}; + +/// acme's tab in a directory window (text.c TABDIR), in cells: a column is +/// a whole number of them, at least a cell wider than its widest entry. +const tab = 3; + +/// The directory a pane named `name` works in, as acme's dirname reads a +/// window's name: a directory pane's (ending in `/`) is its own, a file's +/// the one it is in. +pub fn ofName(name: []const u8) []const u8 { + if (std.mem.endsWith(u8, name, "/")) { + const dir = std.mem.trimEnd(u8, name, "/"); + return if (dir.len == 0) "/" else dir; + } + return std.fs.path.dirname(name) orelse "/"; +} + +/// The entries of directory `dir` on this host as acme lists them +/// (plan9port lib9 dirread, acme's dircmp): every name but `.` and `..`, +/// dotfiles too; a directory's, a link to one's too, ending in `/`; sorted +/// bytewise, the `/` counted; each ending in a newline. +pub fn read(gpa: std.mem.Allocator, dir: []const u8) ![]u8 { + if (comptime !filesystem.platform_has_fs) return error.FileNotFound; + const local = filesystem.localPath(dir) orelse return error.NotLocal; + // Its own copy: the caller's may be a pane's, gone while the turn is out. + var own: [4096]u8 = undefined; + if (local.len > own.len) return error.NameTooLong; + @memcpy(own[0..local.len], local); + var entries: std.ArrayList([]u8) = .empty; + defer { + for (entries.items) |entry| gpa.free(entry); + entries.deinit(gpa); + } + var total: usize = 0; + { + pardes.turn.yield(); + defer pardes.turn.back(); + const io = std.Io.Threaded.global_single_threaded.io(); + var d = try std.Io.Dir.cwd().openDir(io, own[0..local.len], .{ .iterate = true }); + defer d.close(io); + var it = d.iterate(); + while (try it.next(io)) |entry| { + if (std.mem.eql(u8, entry.name, ".") or std.mem.eql(u8, entry.name, "..")) continue; + const is_dir = switch (entry.kind) { + .directory => true, + // Followed, as dirread's stat is: a link to a directory is one. + .sym_link, .unknown => if (d.statFile(io, entry.name, .{})) |st| st.kind == .directory else |_| false, + else => false, + }; + total += entry.name.len + 2; + if (total > limits.max_file_bytes) return error.FileTooLarge; + const name = try std.mem.concat(gpa, u8, &.{ entry.name, if (is_dir) "/" else "" }); + entries.append(gpa, name) catch |err| { + gpa.free(name); + return err; + }; + } + } + std.mem.sort([]u8, entries.items, {}, struct { + fn lt(_: void, a: []u8, b: []u8) bool { + return std.mem.lessThan(u8, a, b); + } + }.lt); + var out: std.ArrayList(u8) = .empty; + errdefer out.deinit(gpa); + try out.ensureTotalCapacity(gpa, total); + for (entries.items) |entry| { + out.appendSliceAssumeCapacity(entry); + out.appendAssumeCapacity('\n'); + } + return out.toOwnedSlice(gpa); +} + +/// `entries` in columns at most `width` cells wide, as acme's +/// textcolumnate lays them out with its 3-cell tabs: down each column +/// first, every column as wide as the widest entry and a cell more, +/// rounded up to a tab, and each row ending in a newline. Blanks pad where +/// acme's tabs do: a pardes tab is a fixed width, not a stop. +pub fn columnate(gpa: std.mem.Allocator, entries: []const []const u8, width: usize) ![]u8 { + var colw: usize = 0; + for (entries) |entry| { + const w = File.displayWidth(entry) + 1; + colw = @max(colw, (w + tab - 1) / tab * tab); + } + const ncol = if (colw == 0) 1 else @max(1, width / colw); + const nrow = (entries.len + ncol - 1) / ncol; + var out: std.ArrayList(u8) = .empty; + errdefer out.deinit(gpa); + for (0..nrow) |row| { + var j = row; + while (j < entries.len) : (j += nrow) { + try out.appendSlice(gpa, entries[j]); + if (j + nrow >= entries.len) break; + try out.appendNTimes(gpa, ' ', colw - File.displayWidth(entries[j])); + } + try out.append(gpa, '\n'); + } + return out.toOwnedSlice(gpa); +} + +/// The cells a directory pane `cols` wide lays its entries out in: what +/// is left of a row after the line numbers and the cell a wrap keeps +/// (File.wrapWidth), the numbers as wide as `count` lines would need. +fn textWidth(cols: usize, count: usize) usize { + var lines = count + 1; + var digits: usize = 1; + while (lines >= 10) : (lines /= 10) digits += 1; + return cols -| @max(config.PREFIX_W, digits + 1) -| 1; +} + +/// Lays the pane's entries out again `cols` wide, when the width they need +/// changed and the body is still theirs: a body edited since is kept, as +/// typed, until a Get or a look at the directory reads it again. +pub fn fit(p: *Pardes, pane: *Pane, cols: usize) void { + const f = if (pane.file) |*file| file else return; + const l = if (f.listing) |*listing| listing else return; + const count = std.mem.count(u8, l.names, "\n"); + const width = textWidth(cols, count); + if (f.revision != l.revision or width == l.width) return; + // Not the scratch arena: this runs from sync, on every event. + const entries = p.gpa.alloc([]const u8, count) catch return; + defer p.gpa.free(entries); + var it = std.mem.splitScalar(u8, l.names, '\n'); + for (entries) |*entry| entry.* = it.next().?; + const text = columnate(p.gpa, entries, width) catch return; + if (std.mem.eql(u8, text, f.content)) p.gpa.free(text) else { + File.setContent(p, f, text); + panes.Output.resetBody(p, pane); + } + l.width = width; + l.revision = f.revision; +} + +/// Reads pane `id`'s directory again and lays it out anew, its edits gone, +/// as acme's Get does in a directory window. +pub fn refresh(p: *Pardes, id: usize) !void { + const pane = p.panes[id] orelse return error.NoPane; + const serial = pane.serial; + const names = try read(p.gpa, ofName(pane.file.?.path)); + // The pane may have closed while the turn was out. + const now = p.panes[id] orelse return p.gpa.free(names); + if (now.serial != serial) return p.gpa.free(names); + const f = &now.file.?; + const l = &f.listing.?; + p.gpa.free(l.names); + l.names = names; + l.width = std.math.maxInt(usize); + l.revision = f.revision; + fit(p, now, now.cols); + panes.Output.resetBody(p, now); +} + +/// A look at directory `dir` (look.zig's `.dir`, with `DirLook pane`): its +/// pane, read again, or a new one, placed as a document is. +pub fn look(p: *Pardes, from: usize, dir: []const u8) void { + const name = (if (std.mem.endsWith(u8, dir, "/")) + p.gpa.dupe(u8, dir) + else + std.mem.concat(p.gpa, u8, &.{ dir, "/" })) catch |err| return p.reportError(from, "look", err); + for (p.panes, 0..) |slot, i| { + const pane = slot orelse continue; + const f = pane.file orelse continue; + if (f.listing == null or !std.mem.eql(u8, f.path, name)) continue; + p.gpa.free(name); + return show(p, from, i); + } + var said: [limits.host_path_cap + 16]u8 = undefined; + const what = std.fmt.bufPrint(&said, "look: {s}", .{name[0..@min(name.len, limits.host_path_cap)]}) catch "look"; + const names = read(p.gpa, dir) catch |err| { + p.gpa.free(name); + return p.reportError(from, what, err); + }; + const free = p.freeSlot() orelse { + p.gpa.free(name); + p.gpa.free(names); + return p.reportError(from, "look", error.NoPaneSlots); + }; + const pane = open(p, free, name, names) catch |err| return p.reportError(from, "look", err); + const failures = p.fs.failures; + exec.placeNew(p, from, from, free, .doc); + // Refused a place: that is the look's one failure. + if (p.fs.failures != failures) return; + fit(p, pane, @max(1, p.rects[free].w -| config.GUTTER)); +} + +/// A pane on directory `name` (ending in `/`) with its entries `names`, +/// both taken, in slot `id`, not yet placed and laid out. +pub fn open(p: *Pardes, id: usize, name: []u8, names: []u8) !*Pane { + errdefer p.gpa.free(name); + errdefer p.gpa.free(names); + const content = try p.gpa.dupe(u8, ""); + errdefer p.gpa.free(content); + const history = try File.History.create(p.gpa); + errdefer p.gpa.destroy(history); + const pane = try p.newDocPane(id); + pane.file = .{ + .path = name, + .content = content, + .output = .{ .from = .dir }, + .history = history, + .listing = .{ .names = names }, + }; + pane.body.cur_pinned = true; + return pane; +} + +/// The directory pane `id` read again and given the keyboard, a look at it +/// coming from pane `from`. +pub fn show(p: *Pardes, from: usize, id: usize) void { + const pane = p.panes[id] orelse return; + const serial = pane.serial; + var said: [limits.host_path_cap + 16]u8 = undefined; + const name = pane.file.?.path; + const what = std.fmt.bufPrint(&said, "look: {s}", .{name[0..@min(name.len, limits.host_path_cap)]}) catch "look"; + refresh(p, id) catch |err| return p.reportError(from, what, err); + // Closed while the turn was out: nothing to give the keyboard to. + const now = p.panes[id] orelse return; + if (now.serial == serial) p.active = id; +} + +// ---- tests ---- + +const testing = std.testing; + +fn laidOut(names: []const []const u8, width: usize) ![]u8 { + return columnate(testing.allocator, names, width); +} + +test "entries go down each column first, a column a tab wider than its widest entry, as acme's" { + // The widest, 5 cells, makes 6: two tabs. 20 cells take three columns. + const names = [_][]const u8{ "a", "bb", "ccc/", "ddddd", "e", "f", "g" }; + const text = try laidOut(&names, 20); + defer testing.allocator.free(text); + try testing.expectEqualStrings( + "a ddddd g\n" ++ + "bb e\n" ++ + "ccc/ f\n", + text, + ); +} + +test "a width that is a whole number of tabs takes one more cell, so a column never touches the next" { + // "abc" is 3 cells, a tab exactly: its column is 6, not 3. + const names = [_][]const u8{ "abc", "de", "f" }; + const text = try laidOut(&names, 12); + defer testing.allocator.free(text); + try testing.expectEqualStrings("abc f\nde\n", text); +} + +test "one column when a row has room for no more, and nothing at all for an empty directory" { + const names = [_][]const u8{ "alpha", "beta" }; + const narrow = try laidOut(&names, 4); + defer testing.allocator.free(narrow); + try testing.expectEqualStrings("alpha\nbeta\n", narrow); + const none = try laidOut(&.{}, 80); + defer testing.allocator.free(none); + try testing.expectEqualStrings("", none); +} + +test "a wide character counts its cells, not its bytes" { + // 世界 is 4 cells: its column is 6 cells, padded with two blanks. + const names = [_][]const u8{ "世界", "x" }; + const text = try laidOut(&names, 12); + defer testing.allocator.free(text); + try testing.expectEqualStrings("世界 x\n", text); +} + +test "a directory reads as acme lists it: dotfiles kept, . and .. not, directories and links to them marked, sorted bytewise" { + if (comptime !filesystem.platform_has_fs) return; + var tmp = testing.tmpDir(.{}); + defer tmp.cleanup(); + const io = testing.io; + try tmp.dir.writeFile(io, .{ .sub_path = "b.txt", .data = "" }); + try tmp.dir.writeFile(io, .{ .sub_path = ".hidden", .data = "" }); + try tmp.dir.writeFile(io, .{ .sub_path = "B", .data = "" }); + try tmp.dir.createDir(io, "a", .default_dir); + try tmp.dir.createDir(io, "a.d", .default_dir); + try tmp.dir.symLink(io, "a", "link", .{ .is_directory = true }); + var buf: [4096]u8 = undefined; + const dir = buf[0..try tmp.dir.realPath(io, &buf)]; + const names = try read(testing.allocator, dir); + defer testing.allocator.free(names); + // Bytewise, as dircmp's memcmp: `.` before capitals before small + // letters, and `a.d/` before `a/` because `.` is before `/`. + try testing.expectEqualStrings(".hidden\nB\na.d/\na/\nb.txt\nlink/\n", names); +} + +test "a directory pane's directory is its own name, a file's the one it is in" { + try testing.expectEqualStrings("/a/b", ofName("/a/b/")); + try testing.expectEqualStrings("/", ofName("/")); + try testing.expectEqualStrings("/a", ofName("/a/b")); + try testing.expectEqualStrings("/", ofName("/a")); +} + +/// A session on a file in a fresh directory holding `sub/inner.txt`, +/// `top.txt` and `.dot`: the directory's path in `buf`. +fn session(tmp: *std.testing.TmpDir, buf: *[4096]u8) !struct { p: *Pardes, dir: []const u8 } { + const io = testing.io; + try tmp.dir.createDir(io, "sub", .default_dir); + try tmp.dir.writeFile(io, .{ .sub_path = "sub/inner.txt", .data = "inner\n" }); + try tmp.dir.writeFile(io, .{ .sub_path = "top.txt", .data = "top\n" }); + try tmp.dir.writeFile(io, .{ .sub_path = ".dot", .data = "" }); + const dir = buf[0..try tmp.dir.realPath(io, buf)]; + var path_buf: [4200]u8 = undefined; + const path = try std.fmt.bufPrint(&path_buf, "{s}/top.txt", .{dir}); + const p = try Pardes.init(testing.allocator, .{ .file = path, .tty_only = true, .cols = 80, .rows = 30 }); + while (p.nextEffect()) |_| {} + return .{ .p = p, .dir = dir }; +} + +/// The pane named `name`, and how many are. +fn named(p: *Pardes, name: []const u8) struct { id: ?usize, count: usize } { + var id: ?usize = null; + var count: usize = 0; + for (p.panes, 0..) |slot, i| if (slot) |pane| if (pane.file) |f| if (std.mem.eql(u8, f.path, name)) { + id = i; + count += 1; + }; + return .{ .id = id, .count = count }; +} + +test "a look at a directory opens a pane named for it with a /, its entries in columns, never dirty, its directory its own" { + if (comptime !pardes.hosted) return; + var tmp = testing.tmpDir(.{}); + defer tmp.cleanup(); + var buf: [4096]u8 = undefined; + const s = try session(&tmp, &buf); + defer s.p.deinit(); + const p = s.p; + pardes.look.lookAt(p, 0, s.dir); + p.sync(); + var name_buf: [4200]u8 = undefined; + const name = try std.fmt.bufPrint(&name_buf, "{s}/", .{s.dir}); + const id = named(p, name).id orelse return error.NoDirectoryPane; + try testing.expectEqual(id, p.active); + const pane = p.panes[id].?; + try testing.expectEqualStrings(".dot sub/ top.txt\n", pane.file.?.content); + try testing.expectEqualStrings(@import("tagline.zig").dir_pane_tail, @import("tagline.zig").curTail(pane)); + try testing.expectEqualStrings(s.dir, Pardes.paneDir(pane)); + // Edited, still never dirty, and no Save writes it. + try testing.expect(p.executeBuiltinLine(id, "Edit ,d")); + try testing.expectEqualStrings("", pane.file.?.content); + try testing.expect(!@import("tagline.zig").dirty(pane)); + const failures = p.fs.failures; + try testing.expect(p.executeBuiltinLine(id, "Save")); + try testing.expect(p.executeBuiltinLine(id, "Save elsewhere.txt")); + try testing.expectEqual(failures +% 2, p.fs.failures); + try testing.expect(p.panes[id].?.prompt == .none); +} + +test "a look at an entry is a look from the directory, .. goes up to the open pane, and Get or a look again reads it again" { + if (comptime !pardes.hosted) return; + var tmp = testing.tmpDir(.{}); + defer tmp.cleanup(); + var buf: [4096]u8 = undefined; + const s = try session(&tmp, &buf); + defer s.p.deinit(); + const p = s.p; + var name_buf: [4200]u8 = undefined; + pardes.look.lookAt(p, 0, s.dir); + p.sync(); + const top = named(p, try std.fmt.bufPrint(&name_buf, "{s}/", .{s.dir})).id.?; + // An entry that is a directory: a pane of its own. + pardes.look.lookAt(p, top, "sub/"); + p.sync(); + const sub = named(p, try std.fmt.bufPrint(&name_buf, "{s}/sub/", .{s.dir})).id orelse return error.NoSubPane; + try testing.expectEqualStrings("inner.txt\n", p.panes[sub].?.file.?.content); + // A file in it, by its name alone: that directory's file. + pardes.look.lookAt(p, sub, "inner.txt"); + p.sync(); + try testing.expect(named(p, try std.fmt.bufPrint(&name_buf, "{s}/sub/inner.txt", .{s.dir})).id != null); + // `..`: the open pane above, read again, not a second one. + try tmp.dir.writeFile(testing.io, .{ .sub_path = "new.txt", .data = "" }); + pardes.look.lookAt(p, sub, ".."); + p.sync(); + const again = named(p, try std.fmt.bufPrint(&name_buf, "{s}/", .{s.dir})); + try testing.expectEqual(@as(usize, 1), again.count); + try testing.expectEqual(top, p.active); + try testing.expect(std.mem.indexOf(u8, p.panes[top].?.file.?.content, "new.txt") != null); + // Get, in its tag or its text: read again. + try tmp.dir.writeFile(testing.io, .{ .sub_path = "sub/later.txt", .data = "" }); + try testing.expect(p.executeBuiltinLine(sub, "Get")); + try testing.expectEqualStrings("inner.txt later.txt\n", p.panes[sub].?.file.?.content); + // Get anywhere else is still the acme word pardes has not. + const failures = p.fs.failures; + try testing.expect(p.executeBuiltinLine(0, "Get")); + try testing.expect(p.fs.failures != failures); +} + +test "an exec in a directory pane runs in its directory, and its +Errors goes there" { + if (comptime !pardes.hosted) return; + var tmp = testing.tmpDir(.{}); + defer tmp.cleanup(); + var buf: [4096]u8 = undefined; + const s = try session(&tmp, &buf); + defer s.p.deinit(); + const p = s.p; + var name_buf: [4200]u8 = undefined; + pardes.look.lookAt(p, 0, s.dir); + p.sync(); + const sub_name = try std.fmt.bufPrint(&name_buf, "{s}/sub/", .{s.dir}); + pardes.look.lookAt(p, p.active, sub_name); + p.sync(); + const sub = named(p, sub_name).id.?; + try testing.expectEqualStrings(sub_name[0 .. sub_name.len - 1], p.execDir(sub)); + _ = @import("ninep/pane.zig").appendErrors(p, sub, "oops\n"); + var errors_buf: [4200]u8 = undefined; + try testing.expect(named(p, try std.fmt.bufPrint(&errors_buf, "{s}{s}", .{ sub_name, config.errors_buffer })).id != null); +} + +test "DirLook terminal: a look at a directory opens a terminal there, no pane listing it" { + if (comptime !pardes.hosted) return; + var tmp = testing.tmpDir(.{}); + defer tmp.cleanup(); + var buf: [4096]u8 = undefined; + const s = try session(&tmp, &buf); + defer s.p.deinit(); + const p = s.p; + try testing.expect(p.executeBuiltinLine(0, "DirLook terminal")); + try testing.expectEqual(config.Runtime.DirLook.terminal, p.settings.dir_look); + pardes.look.lookAt(p, 0, s.dir); + p.sync(); + var name_buf: [4200]u8 = undefined; + try testing.expectEqual(@as(usize, 0), named(p, try std.fmt.bufPrint(&name_buf, "{s}/", .{s.dir})).count); + try testing.expect(p.panes[p.active].?.isTerminal()); + try testing.expectEqualStrings(s.dir, p.panes[p.active].?.cwdSlice()); + // Bare, it steps back to pane, the default. + try testing.expect(p.executeBuiltinLine(0, "DirLook")); + try testing.expectEqual(config.Runtime.DirLook.pane, p.settings.dir_look); +} + +test "over 9P a directory pane is a text pane whose name ends in /, its body the listing, ctl's isdir 1, and get reads it again" { + if (comptime !pardes.hosted) return; + const th = @import("ninep/testing.zig"); + const tree = @import("ninep/tree.zig"); + var tmp = testing.tmpDir(.{}); + defer tmp.cleanup(); + var buf: [4096]u8 = undefined; + const s = try session(&tmp, &buf); + defer s.p.deinit(); + const p = s.p; + var line_buf: [4200]u8 = undefined; + _ = th.wr(p, @intFromEnum(tree.TopFile.look), try std.fmt.bufPrint(&line_buf, "{s}\n", .{s.dir})); + p.sync(); + const pane = p.panes[p.active].?; + const index = th.rd(p, @intFromEnum(tree.TopFile.index), 0, 8192).bytes; + try testing.expect(std.mem.indexOf(u8, index, try std.fmt.bufPrint(&line_buf, "{d} text 0 {s}/ ", .{ pane.serial, s.dir })) != null); + try testing.expectEqualStrings(".dot sub/ top.txt\n", th.rd(p, tree.Node.of(pane.serial, .body), 0, 4096).bytes); + var fields = std.mem.tokenizeScalar(u8, th.rd(p, tree.Node.of(pane.serial, .ctl), 0, 4096).bytes, ' '); + for (0..3) |_| _ = fields.next(); + try testing.expectEqualStrings("1", fields.next().?); + try tmp.dir.writeFile(testing.io, .{ .sub_path = "zz", .data = "" }); + try testing.expectEqual(tree.Status.ok, th.wr(p, tree.Node.of(pane.serial, .ctl), "get\n").reply.status); + const after = th.rd(p, tree.Node.of(pane.serial, .body), 0, 4096).bytes; + try testing.expect(std.mem.indexOf(u8, after, "zz") != null); + try testing.expectEqualStrings(pane.file.?.content, after); +} + +test "a directory pane lays its entries out again when its width changes, unless its text was edited" { + if (comptime !pardes.hosted) return; + var tmp = testing.tmpDir(.{}); + defer tmp.cleanup(); + var buf: [4096]u8 = undefined; + const s = try session(&tmp, &buf); + defer s.p.deinit(); + const p = s.p; + pardes.look.lookAt(p, 0, s.dir); + p.sync(); + const pane = p.panes[p.active].?; + // 9 cells a column: two of them want 18 cells and the line numbers. + fit(p, pane, 24); + try testing.expectEqualStrings(".dot top.txt\nsub/\n", pane.file.?.content); + fit(p, pane, 80); + try testing.expectEqualStrings(".dot sub/ top.txt\n", pane.file.?.content); + try testing.expect(p.executeBuiltinLine(p.active, "Edit 1d")); + const edited = try testing.allocator.dupe(u8, pane.file.?.content); + defer testing.allocator.free(edited); + fit(p, pane, 24); + try testing.expectEqualStrings(edited, pane.file.?.content); +} diff --git a/src/File.zig b/src/File.zig index b3c28290..eb11b0e4 100644 --- a/src/File.zig +++ b/src/File.zig @@ -84,6 +84,8 @@ pub const State = struct { mtime: u32 = 0, /// Non-null for a generated output buffer rather than an on-disk file. output: ?Output.State = null, + /// A directory pane's entries (Dir.zig), its output `.dir`. + listing: ?panes.Dir.State = null, mini: ?Mini.State = null, scroll: usize = 0, /// `line_starts[i]` is line i's byte offset. Empty means not built yet. @@ -943,6 +945,14 @@ pub fn restore(p: *Pardes, id: usize, src: dump.Pane) !*Pane { }; pane.cols = @max(1, src.cols); pane.rows = @max(1, src.rows); + // A directory pane is its directory as it is now, laid out at the next + // sync; one that cannot be read keeps the text the dump kept. + if (output) |o| if (o.from == .dir) { + const f = &pane.file.?; + if (panes.Dir.read(p.gpa, panes.Dir.ofName(path))) |names| { + f.listing = .{ .names = names, .revision = f.revision }; + } else |_| f.listing = .{ .names = &.{}, .revision = f.revision -% 1 }; + }; if (output == null and filesystem.localPath(path) != null) p.emit(.{ .watch = .{ .pane = @intCast(id), .on = true, .mode = .baseline_disk } }); // Its file gone from disk since the dump: its text is nowhere else now, // so it comes back as one deleted on disk, dirty, and Del, Exit and @@ -984,6 +994,7 @@ pub fn deinit(p: *Pardes, pane: *Pane, file: *State) void { }; p.gpa.free(file.path); p.gpa.free(file.content); + if (file.listing) |listing| p.gpa.free(listing.names); if (file.mini) |*mini| mini.deinit(p.gpa); if (file.line_starts.len > 0) p.gpa.free(file.line_starts); if (file.highlights.len > 0) p.tree_sitter_gpa.free(file.highlights); diff --git a/src/Output.zig b/src/Output.zig index 5422411f..3bae9ecf 100644 --- a/src/Output.zig +++ b/src/Output.zig @@ -31,6 +31,8 @@ pub const Origin = union(enum) { /// The panes a refusal (Exit, Restore, Del, Delcol, get) is over, kept /// in +Unsaved rather than a notice that goes. unsaved, + /// A directory's entries (Dir.zig), the pane named for it. + dir, }; pub const max_arg = dump.max_origin_arg; @@ -228,6 +230,8 @@ pub fn traits(o: Origin) Traits { .errors => .{ .name = config.errors_buffer, .doc = true }, .pdf_links => .{ .name = config.pdf_links_buffer, .steps = true, .locations = true }, .unsaved => .{ .name = config.unsaved_buffer, .doc = true }, + // Named for its directory, not a `+` name in it. + .dir => .{ .name = "", .doc = true }, .cmd => |b| builtins.registry.outputTraits(b) orelse unreachable, .query => |k| switch (k) { .hover => .{ .name = config.hover_buffer }, @@ -288,15 +292,20 @@ pub fn word(o: Origin) []const u8 { .errors => config.errors_buffer, .pdf_links => config.pdf_links_buffer, .unsaved => config.unsaved_buffer, + .dir => dir_word, }; } +/// A directory pane's origin as a dump names it. +const dir_word = "dir"; + pub fn fromWord(w: []const u8) ?Origin { if (w.len == 0) return null; if (std.mem.eql(u8, w, "/")) return .search; if (std.mem.eql(u8, w, config.errors_buffer)) return .errors; if (std.mem.eql(u8, w, config.pdf_links_buffer)) return .pdf_links; if (std.mem.eql(u8, w, config.unsaved_buffer)) return .unsaved; + if (std.mem.eql(u8, w, dir_word)) return .dir; if (std.meta.stringToEnum(Builtin, w)) |b| if (builtins.registry.outputTraits(b) != null) return .{ .cmd = b }; if (std.meta.stringToEnum(lsp.Kind, w)) |k| return .{ .query = k }; @@ -359,7 +368,7 @@ fn sortResults(arena: std.mem.Allocator, from: Origin, content: []u8, anchor: ?u => {}, else => return anchor, }, - .errors, .pdf_links, .unsaved => return anchor, + .errors, .pdf_links, .unsaved, .dir => return anchor, } if (content.len == 0) return anchor; const path_only = std.meta.eql(from, Origin{ .cmd = .Find }); @@ -666,7 +675,7 @@ pub fn openUnsaved(p: *Pardes, id: usize, content: []u8) void { return; } const pane = p.panes[id] orelse return p.gpa.free(content); - const own = if (pane.file) |f| (std.fs.path.dirname(f.path) orelse "/") else pane.cwdSlice(); + const own = if (pane.file) |f| panes.Dir.ofName(f.path) else pane.cwdSlice(); // Its directory gone (or never there, a name not yet saved): the list // goes in the session's, where a look from it can still resolve. const dir = if (comptime pardes.hosted) (if (pardes.filesystem.localPath(own)) |local| (if (exec.isDirectory(local)) own else p.sessionDir()) else own) else own; @@ -820,7 +829,7 @@ pub fn openFonts(p: *Pardes, id: usize) !void { fn openStepped(p: *Pardes, id: usize, from: Origin, content: []u8) !void { errdefer p.gpa.free(content); const pane = p.panes[id] orelse return error.MissingPane; - const own = if (pane.file) |f| (std.fs.path.dirname(f.path) orelse "/") else pane.cwdSlice(); + const own = if (pane.file) |f| panes.Dir.ofName(f.path) else pane.cwdSlice(); // A terminal whose shell has not said where it is yet (an init file's // word at boot): the session's directory, not `/`. const dir = if (own.len == 0) p.sessionDir() else own; diff --git a/src/builtins.zig b/src/builtins.zig index 1a2f132f..1172fa78 100644 --- a/src/builtins.zig +++ b/src/builtins.zig @@ -1125,6 +1125,12 @@ pub const Save = struct { // silent success. if (c.pane.file == null and !c.pane.isTerminal()) return c.p.reportFailure(c.id, if (c.pane.hasPdf()) "Save: a PDF pane has no text to save" else "Save: an image pane has no text to save"); + // A directory's listing is no file to write, bare or to a path, as + // acme's Put does nothing in a directory window. + if (c.pane.file) |file| if (file.listing != null) { + var said: [limits.host_path_cap + 48]u8 = undefined; + return c.p.reportFailure(c.id, std.fmt.bufPrint(&said, "Save: {s} is a directory", .{file.path[0..@min(file.path.len, limits.host_path_cap)]}) catch "Save: a directory pane has no file to save"); + }; const path = std.mem.trim(u8, c.arg orelse "", " \t\r\n"); if (path.len > 0) return exec.saveTo(c.p, c.id, path); // A `+` name is a generated pane's (+Tutor), no file of its own: @@ -1505,7 +1511,7 @@ pub const LocationsConfig = struct { try c.p.locations_config.write(&out.writer); try out.writer.writeByte('\n'); const content = try out.toOwnedSlice(); - const dir = if (c.pane.file) |file| std.fs.path.dirname(file.path) orelse "/" else c.pane.cwdSlice(); + const dir = if (c.pane.file) |file| panes.Dir.ofName(file.path) else c.pane.cwdSlice(); try panes.Output.fillResults(c.p, c.id, dir, .{ .cmd = .LocationsConfig }, "", content, null); } }; @@ -2085,7 +2091,7 @@ const Board = struct { p.gpa.free(content); return error.MissingPane; }; - const dir = if (pane.file) |f| (std.fs.path.dirname(f.path) orelse "/") else pane.cwdSlice(); + const dir = if (pane.file) |f| panes.Dir.ofName(f.path) else pane.cwdSlice(); try panes.Output.fillResults(p, id, dir, from, "", content, null); } diff --git a/src/config.zig b/src/config.zig index f83e7945..45deb7bb 100644 --- a/src/config.zig +++ b/src/config.zig @@ -81,6 +81,7 @@ pub const leader_path = paths: { .Placement = "cp", .BootShell = null, .LookWord = null, + .DirLook = null, .Pager = null, .PagerColor = null, .TermImages = null, @@ -296,6 +297,8 @@ pub const pdf_pane_builtins_str = "Tty PdfSections PdfTint Collapse Del"; pub const file_pane_builtins_str = "Save Tty Collapse Del"; pub const terminal_pane_builtins_str = "Tty Save Mode Filter Collapse Del"; pub const command_pane_builtins_str = "Kill Save Collapse Del"; +/// A directory pane's (Dir.zig): Get reads it again, as acme's does. +pub const dir_pane_builtins_str = "Get Tty Collapse Del"; // Each mode badge is one codepoint. pub const tag_normal = " "; @@ -774,6 +777,9 @@ pub const Runtime = struct { /// next place in that pane, wrapping; `list`, what pardes did before, /// lists every place in a +Search pane (look.zig, lookWord). look_word: LookWord = .search, + /// A directory looked at: `pane`, acme's, a pane listing it (Dir.zig); + /// `terminal`, what pardes did before, `ls` in a terminal there. + dir_look: DirLook = .pane, /// What a terminal's shell pages through (host_io.ChildEnv): `pardes`, /// PAGER and GIT_PAGER set to `pardes -`, a +Pager pane, where the /// user's environment set neither; `off`, the environment as it is. @@ -790,10 +796,11 @@ pub const Runtime = struct { pub const Placement = enum { acme, pardes }; pub const BootShell = enum { keep, replace }; pub const LookWord = enum { search, list }; + pub const DirLook = enum { pane, terminal }; pub const Pager = enum { pardes, off }; pub const TermImages = enum { real, petscii }; /// A setting that is one of a few words, each an enum field of Runtime. - pub const Choice = enum { placement, boot_shell, look_word, pager, term_images }; + pub const Choice = enum { placement, boot_shell, look_word, dir_look, pager, term_images }; /// shadow: a soft drop shadow. rim: a light hairline along the top of /// the focused pane's tag rows. auto: a shadow on a light page; on a @@ -1058,6 +1065,7 @@ pub const Runtime = struct { .{ .word = "Placement", .action = .{ .choice = .placement }, .doc = "Where a new pane goes: acme, as makenewwindow does, or pardes, the older rules." }, .{ .word = "BootShell", .action = .{ .choice = .boot_shell }, .doc = "A document dropped where a lone untouched shell stands: keep the shell, or replace it." }, .{ .word = "LookWord", .action = .{ .choice = .look_word }, .doc = "A plain word looked at: search selects its next place in the pane, list lists every place in a +Search." }, + .{ .word = "DirLook", .action = .{ .choice = .dir_look }, .doc = "A directory looked at: pane, a pane listing it as acme's directory window, or terminal, ls in a terminal there." }, .{ .word = "Pager", .action = .{ .choice = .pager }, .doc = "What a terminal's commands page through: pardes, a +Pager pane (pardes -), or off, the environment's own; for terminals started after it." }, .{ .word = "PagerColor", .action = .{ .toggle = .pager_color }, .doc = "A +Pager keeps its program's colours, on or off; for the next text paged." }, .{ .word = "TermImages", .action = .{ .choice = .term_images }, .doc = "How a new terminal draws its program's kitty graphics: real, as pixels where it can, or petscii, as glyph art." }, @@ -1745,6 +1753,7 @@ pub const Runtime = struct { .placement => "pardes", .boot_shell => "replace", .look_word => "list", + .dir_look => "terminal", .pager => "off", .term_images => "petscii", }, @@ -1817,6 +1826,7 @@ pub const Runtime = struct { .placement => "Placement pardes\n", .boot_shell => "BootShell replace\n", .look_word => "LookWord list\n", + .dir_look => "DirLook terminal\n", .pager => "Pager off\n", .term_images => "TermImages petscii\n", }, @@ -2188,7 +2198,7 @@ const doc_typ = struct { if (w.end > 0) w.writeByte(' ') catch return false; w.writeAll(x[0 .. std.mem.indexOfScalar(u8, x, '+') orelse x.len]) catch return false; } - const tags = [_][]const u8{ topbar_str, @import("tagline.zig").column_tag_default, pane_builtins_str, pdf_pane_builtins_str, file_pane_builtins_str, terminal_pane_builtins_str, command_pane_builtins_str }; + const tags = [_][]const u8{ topbar_str, @import("tagline.zig").column_tag_default, pane_builtins_str, pdf_pane_builtins_str, file_pane_builtins_str, terminal_pane_builtins_str, command_pane_builtins_str, dir_pane_builtins_str }; for (tags) |d| if (std.mem.eql(u8, d, w.buffered())) return true; return false; } diff --git a/src/exec.zig b/src/exec.zig index 8ddb9abd..92fb6244 100644 --- a/src/exec.zig +++ b/src/exec.zig @@ -968,6 +968,12 @@ pub fn executeBuiltinLine(p: *Pardes, id: usize, txt: []const u8) bool { var renamed: [1024 + 16]u8 = undefined; const cmd = for (acme_words) |w| { if (!std.mem.eql(u8, raw[0..word_end], w.acme)) continue; + // Get in a directory pane, its tag or its text: the directory read + // again (Dir.zig), as acme's Get is in a directory window. + if (std.mem.eql(u8, w.acme, "Get")) if (p.panes[id]) |pane| if (pane.file) |f| if (f.listing != null) { + panes.Dir.show(p, id, id); + return true; + }; const now = w.pardes orelse { var said: [128]u8 = undefined; p.reportFailure(id, std.fmt.bufPrint(&said, "invalid: acme's {s} is not a pardes builtin{s}", .{ w.acme, w.hint }) catch "invalid: an acme word pardes has not"); diff --git a/src/host_io.zig b/src/host_io.zig index 8ff55d74..ee503061 100644 --- a/src/host_io.zig +++ b/src/host_io.zig @@ -174,7 +174,7 @@ pub const Lsp = struct { errdefer gpa.free(source); const arg = try gpa.dupe(u8, req.arg); errdefer gpa.free(arg); - const declared_root = if (file) |f| std.fs.path.dirname(f.path) orelse "/" else pane.cwdSlice(); + const declared_root = if (file) |f| pardes.panes.Dir.ofName(f.path) else pane.cwdSlice(); const root = try gpa.dupe(u8, filesystem.localPath(declared_root) orelse declared_root); errdefer gpa.free(root); job.* = .{ diff --git a/src/look.zig b/src/look.zig index a358b31a..0df1f307 100644 --- a/src/look.zig +++ b/src/look.zig @@ -1787,6 +1787,8 @@ pub fn lookAt(p: *Pardes, id: usize, operand_raw: []const u8) void { if (t.at.line > pv.page_count) return missedPage(p, id, pv.path, t.at.line); if (!pv.hitExists(p.pdf_gpa, @max(1, t.at.line), t.at.col)) return missedHit(p, id, pv.path, @max(1, t.at.line), t.at.col); }; + // A directory's pane, looked at again: read again. + if (target.file) |f| if (f.listing != null) return panes.Dir.show(p, id, t.id); const before = p.active; clearNavigationSelection(p, target); focusPaneLine(p, t.id, t.at, .center); @@ -1800,6 +1802,9 @@ pub fn lookAt(p: *Pardes, id: usize, operand_raw: []const u8) void { var said: [4200]u8 = undefined; return p.reportFailure(id, std.fmt.bufPrint(&said, "look: {s}: no such directory", .{dir[0..@min(dir.len, 4096)]}) catch "look: no such directory"); }; + // acme's: a pane listing it (Dir.zig). `DirLook terminal`, what + // pardes did before: `ls` in a terminal there. + if (p.settings.dir_look == .pane) return panes.Dir.look(p, id, dir); for (p.panes, 0..) |slot, i| { if (slot) |tt| if (std.mem.eql(u8, tt.cwdSlice(), dir) and exec.takesCommandLine(p, i)) { clearNavigationSelection(p, tt); diff --git a/src/ninep/ctl.zig b/src/ninep/ctl.zig index 75e4b823..157bc8b9 100644 --- a/src/ninep/ctl.zig +++ b/src/ninep/ctl.zig @@ -385,10 +385,11 @@ fn writeQuoted(w: *std.Io.Writer, s: []const u8) !void { pub const pane_text_cap = 9 * 12 + 2 * 256 + 4 + "notcurrent ".len + 48 + "collapsed fit:height tint:filtered ".len; /// acme's winctlprint (plan9port wind.c), field for field: serial, tag -/// length, body length, isdir (0), the dirty flag, the width in cells, the -/// font, the tab width, whether Undo has a step, whether Redo has one. Then -/// pardes's own: rio's word for whether the window has the keyboard, -/// `current` or `notcurrent` (rio(4), wctl), and a REPL's id. +/// length, body length, isdir (1 for a directory pane), the dirty flag, +/// the width in cells, the font, the tab width, whether Undo has a step, +/// whether Redo has one. Then pardes's own: rio's word for whether the +/// window has the keyboard, `current` or `notcurrent` (rio(4), wctl), and +/// a REPL's id. pub fn paneText(p: *Pardes, pane: *Pane, buf: []u8) []const u8 { var w = std.Io.Writer.fixed(buf); w.print("{d:>11} {d:>11} {d:>11} {d:>11} {d:>11} {d:>11} ", .{ @@ -396,7 +397,8 @@ pub fn paneText(p: *Pardes, pane: *Pane, buf: []u8) []const u8 { pane_files.tagOf(p, pane).len, // A terminal's body is its history, read whole on an open's first read. if (pane.isTerminal()) panes.terminal.screenTextLen(pane) else pane_files.bodyOf(pane).len, - @as(u32, 0), + // A directory pane is one, as acme's isdir says. + @intFromBool(if (pane.file) |f| f.listing != null else false), @intFromBool(pane_files.dirtyOf(pane)), pane.cols, }) catch return w.buffered(); @@ -1148,6 +1150,14 @@ fn getRefused(p: *Pardes, pane: *Pane) ?[]const u8 { fn get(p: *Pardes, pane: *Pane, failed: *anyerror) u16 { const f = pane_files.fileOf(pane) orelse return 0; + // A directory pane: the directory read again (Dir.zig). + if (f.listing != null) { + panes.Dir.refresh(p, p.paneBySerial(pane.serial).?) catch |err| { + failed.* = err; + return if (err == error.FileNotFound) E.NOENT else E.IO; + }; + return 0; + } if (!panes.Output.fileTraits(f.output).saves) return 0; const bytes = fs.read(p, f.path) catch |err| { failed.* = err; @@ -2661,6 +2671,7 @@ test "a terminal told the directory it already goes by logs no rename" { test "a terminal with text typed at its prompt is never typed into: a look at its directory opens another" { const p = try th.withTerm(testing.allocator); defer p.deinit(); + p.settings.dir_look = .terminal; // `ls` in a terminal, not a directory pane const term = p.paneBySerial(serialOf(p)).?; p.setCwd(term, "/tmp"); p.update(.{ .output = .{ .pane = @intCast(term), .bytes = "\x1b]133;A;aid=pardes\x07$ \x1b]133;B;aid=pardes\x07TYPED" } }); diff --git a/src/ninep/pane.zig b/src/ninep/pane.zig index 92ce8d8a..981c2b0e 100644 --- a/src/ninep/pane.zig +++ b/src/ninep/pane.zig @@ -1014,7 +1014,7 @@ pub fn appendErrors(p: *Pardes, id: usize, text: []const u8) ?usize { if (text.len == 0) return 0; const pane = p.panes[id] orelse return null; const cwd = pane.cwdSlice(); - const dir = if (pane.file) |*f| std.fs.path.dirname(f.path) orelse "/" else if (cwd.len > 0) cwd else "/"; + const dir = if (pane.file) |*f| panes.Dir.ofName(f.path) else if (cwd.len > 0) cwd else "/"; for (p.panes) |slot| { const q = slot orelse continue; const qf = fileOf(q) orelse continue; diff --git a/src/panes.zig b/src/panes.zig index 9d1b7571..89362996 100644 --- a/src/panes.zig +++ b/src/panes.zig @@ -640,6 +640,8 @@ pub const File = @import("File.zig"); pub const Output = @import("Output.zig"); +pub const Dir = @import("Dir.zig"); + pub const mini = @import("mini.zig"); pub const Image = @import("image.zig"); @@ -653,6 +655,7 @@ test { _ = Text; _ = File; _ = Output; + _ = Dir; _ = mini; _ = Image; _ = Pdf; diff --git a/src/pardes.zig b/src/pardes.zig index 1cc1c5b8..164bc253 100644 --- a/src/pardes.zig +++ b/src/pardes.zig @@ -1986,6 +1986,7 @@ test "a Look on a directory does not type ls into an occupied terminal" { const gpa = std.testing.allocator; const p = try Pardes.init(gpa, .{ .cols = 100, .rows = 30 }); defer p.deinit(); + p.settings.dir_look = .terminal; // `ls` in a terminal, not a directory pane while (p.nextEffect()) |_| {} var realbuf: [4096]u8 = undefined; @@ -6433,7 +6434,7 @@ pub const Pardes = struct { .owned => |cwd| return cwd, .none => {}, } - if (pane.file) |f| return std.fs.path.dirname(f.path) orelse "/"; + if (pane.file) |f| return panes.Dir.ofName(f.path); if (comptime pdf_enabled) if (pane.pdf) |pv| return std.fs.path.dirname(pv.path) orelse "/"; if (pane.image) |iv| return std.fs.path.dirname(iv.path) orelse "/"; @@ -6807,7 +6808,7 @@ pub const Pardes = struct { return; } - const dir = if (pane.file) |f| (std.fs.path.dirname(f.path) orelse "/") else pane.cwdSlice(); + const dir = if (pane.file) |f| panes.Dir.ofName(f.path) else pane.cwdSlice(); const content = p.gpa.dupe(u8, rows) catch return; const serial_before = p.next_serial; p.fs.refilled = null; @@ -7260,6 +7261,9 @@ pub const Pardes = struct { pane.rows = rows; if (pane.file) |*file| file.syntax_dirty = true; } + // A directory pane's entries follow its width, as acme's + // columns do (Dir.fit). + if (pane.file) |file| if (file.listing != null and r.h > pane.tag_rows) panes.Dir.fit(p, pane, pane.cols); panes.terminal.releasePendingCommandIfReady(p, id, pane); // 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 diff --git a/src/tagline.zig b/src/tagline.zig index a1ce437d..d13f3c5f 100644 --- a/src/tagline.zig +++ b/src/tagline.zig @@ -23,6 +23,7 @@ pub const context_pane_tail = file_pane_tail ++ " TreeContext"; pub const locations_pane_tail = file_pane_tail ++ " LocationsConfig"; pub const terminal_pane_tail = " " ++ config.terminal_pane_builtins_str; pub const command_pane_tail = " " ++ config.command_pane_builtins_str; +pub const dir_pane_tail = " " ++ config.dir_pane_builtins_str; /// A file with changes it has not saved. pub fn dirty(pane: *const panes.Pane) bool { const f = pane.file orelse return false; @@ -162,6 +163,7 @@ pub fn curTail(pane: *Pane) []const u8 { pub fn defaultTail(pane: *const Pane) []const u8 { if (comptime pdf_enabled) if (pane.pdf != null) return pdf_pane_tail; + if (pane.file) |file| if (file.listing != null) return dir_pane_tail; if (pane.file) |file| if (file.output) |out| if (panes.Output.usesLocationsConfig(out.from)) return locations_pane_tail; if (panes.File.supportsContext(pane)) return context_pane_tail; diff --git a/test/fs.py b/test/fs.py index 204f4b37..65b354d9 100644 --- a/test/fs.py +++ b/test/fs.py @@ -605,6 +605,28 @@ def unattended_messages_expire(binary): assert not shown(), 'an unattended message outlived MessageLinger' +def directory_panes(binary): + """A look at a directory opens a pane listing it, as acme's directory + window: a text pane named with a trailing /, its body the entries (a + directory's marked /), ctl's isdir 1, and get reads it again.""" + with tempfile.TemporaryDirectory(prefix='pardes-dirpane-') as directory: + root = Path(directory).resolve() + listed = root / 'listed' + (listed / 'sub').mkdir(parents=True) + (listed / '.dot').write_bytes(b'') + with session(binary, root, 'dirpane') as (client, _): + serial = look(client, str(listed)) + rows = [row.split() for row in client.read('/index').decode().splitlines()] + row = next(r for r in rows if int(r[0]) == serial) + assert row[1:4] == ['text', '0', f'{listed}/'], row + body = client.read(f'/pane/{serial}/body').decode() + assert body.split() == ['.dot', 'sub/'], body + assert client.read(f'/pane/{serial}/ctl').split()[3] == b'1' + (listed / 'later').write_bytes(b'') + client.write(f'/pane/{serial}/ctl', b'get\n') + assert client.read(f'/pane/{serial}/body').decode().split() == ['.dot', 'later', 'sub/'] + + def new_terminals_named_once(binary): """A terminal started outside the session's directory is named by that directory from its `new` on: no rename to the session's and back.""" @@ -612,6 +634,9 @@ def new_terminals_named_once(binary): root = Path(directory) (root / 'sub').mkdir() with session(binary, root, 'names') as (client, _): + # A look at a directory starts a terminal there (DirLook + # terminal); DirLook pane, the default, lists it in a pane. + client.write('/ctl', b'DirLook terminal\n') made = [look(client, str(root / 'sub'))] before = {int(row.split()[0]) for row in client.read('/index').splitlines()} client.write('/pane/1/ctl', b'Tty\n') @@ -992,6 +1017,7 @@ def test(binary, quic=False): exit_answers(binary) unattended_messages_expire(binary) new_terminals_named_once(binary) + directory_panes(binary) workflow_canary(binary) recent_survives_restart(binary) python_repl_runs_one_line(binary) diff --git a/test/snapshots/cmdword.snap b/test/snapshots/cmdword.snap index 631fab8b..42a91e18 100644 --- a/test/snapshots/cmdword.snap +++ b/test/snapshots/cmdword.snap @@ -23,6 +23,9 @@ file zzmark.txt x # the top of the body -- which would move every row this script clicks. The # verbs are what is under test here, not the announcement. config Verbose off +# a directory looked at opens a terminal there (DirLook terminal), as this +# script was written for; DirLook pane, the default, is dirpane.snap's +config DirLook terminal start 31 120 cmds.txt wait 8000 Newcol Joincol wait 8000 cmds.txt diff --git a/test/snapshots/dirpane.golden b/test/snapshots/dirpane.golden new file mode 100644 index 00000000..3118079f --- /dev/null +++ b/test/snapshots/dirpane.golden @@ -0,0 +1,13 @@ +== snap dir-open grid=80x24 cursor=7,6 +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +| New Tty Find Grep Joincol Delcol +| /tmp/pardes-snap/dirpane/cwd/top.txt Save Tty Collapse Del +| 1 sub +| +| /tmp/pardes-snap/dirpane/cwd/sub/ Get Tty Collapse Del +| 1 .hidden beta-gamma.txt inner.txt +| 2 alpha.txt deeper/ zeta +| 3 +== snap entry-open grid=80x24 cursor=7,9 +|8: /tmp/pardes-snap/dirpane/cwd/sub/inner.txt Save Tty Collapse Del +|9: 1 inner-marker diff --git a/test/snapshots/dirpane.snap b/test/snapshots/dirpane.snap new file mode 100644 index 00000000..a884b12e --- /dev/null +++ b/test/snapshots/dirpane.snap @@ -0,0 +1,27 @@ +# a look at a directory opens a pane named for it with a trailing /, its +# entries in columns as acme's directory window lays them out: down each +# column first, a directory's marked /, dotfiles shown. A look at an entry +# opens it from that directory. No shell anywhere: nothing here races a prompt. +dirmk sub +dirmk sub/deeper +file sub/inner.txt inner-marker +file sub/.hidden x +file sub/alpha.txt x +file sub/beta-gamma.txt x +file sub/zeta x +file top.txt sub +config Verbose off +start 24 80 top.txt +wait 8000 top.txt +stable 700 20000 +press right @sub 4 +release right @sub 4 +wait 8000 inner.txt +stable 700 20000 +snap dir-open +# an entry, by its name alone: sub's inner.txt +press right @inner.txt 7 +release right @inner.txt 7 +wait 8000 inner-marker +stable 700 20000 +snap entry-open diff --git a/test/snapshots/look-dir.snap b/test/snapshots/look-dir.snap index caf29da8..2032d0c0 100644 --- a/test/snapshots/look-dir.snap +++ b/test/snapshots/look-dir.snap @@ -2,6 +2,9 @@ dirmk sub file sub/inner.txt inner-marker file top.txt x +# a directory looked at opens a terminal there (DirLook terminal), as this +# script was written for; DirLook pane, the default, is dirpane.snap's +config DirLook terminal start 31 100 -n 3 wait 8000 top.txt stable 700 20000 diff --git a/test/snapshots/lookpanes.snap b/test/snapshots/lookpanes.snap index e1db907a..2834a4a9 100644 --- a/test/snapshots/lookpanes.snap +++ b/test/snapshots/lookpanes.snap @@ -24,6 +24,9 @@ file beta/bmark.txt both.txt\nb-marker # the top of the body -- which moves every row this script clicks. What the # verbs do is what is under test, not the announcement. config Verbose off +# a directory looked at opens a terminal there (DirLook terminal), as this +# script was written for; DirLook pane, the default, is dirpane.snap's +config DirLook terminal start 51 130 beta/bmark.txt wait 8000 b-marker stable 700 20000 diff --git a/test/snapshots/nested.golden b/test/snapshots/nested.golden index 07d6148d..44ab4b82 100644 --- a/test/snapshots/nested.golden +++ b/test/snapshots/nested.golden @@ -46,15 +46,15 @@ | | /tmp/pardes-snap/nested/cwd/+New Save Tty Collapse Del | 1 -== snap dir-arg grid=100x31 cursor=4,8 +== snap dir-arg grid=100x31 cursor=7,6 |Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol |$ /tmp/pardes-snap/nested/cwd Tty+bash Save Mode Filter Collapse Del | $ $(readlink /proc/$PPID/exe) nestdir | $ -| /tmp/pardes-snap/nested/cwd/nestdir Tty+bash Save Mode Filter Collapse Del -| ls -| inside-nested.txt +| /tmp/pardes-snap/nested/cwd/nestdir/ Get Tty Collapse Del +| 1 inside-nested.txt +| 2 | | | diff --git a/test/snapshots/ttylook.snap b/test/snapshots/ttylook.snap index 5b82bd89..91401a64 100644 --- a/test/snapshots/ttylook.snap +++ b/test/snapshots/ttylook.snap @@ -9,6 +9,9 @@ lines big.txt 40 file plain.txt just text dirmk sub +# a directory looked at opens a terminal there (DirLook terminal), as this +# script was written for; DirLook pane, the default, is dirpane.snap's +config DirLook terminal start 31 120 -n 3 wait 8000 big.txt stable 700 20000 -- cgit v1.3 From 046979b877f02a91cf52cc86b84c5619cb9363d3 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 6 Oct 2026 19:06:32 -0300 Subject: Def and Refs in a language-served file's tag, a diff viewer's tinted word edits, context rows that hold still under a scroll, and the pardes skill Def and Refs (gd, gr, Ctrl-click; chorded 2-1 at the selection) for a file a language server speaks for; hunks.zig stacks a unified diff as a diff viewer does, its changed words on a tinted ground as delta's do; the tree-sitter context rows stay put while the body glides under a scroll; .agents/skills gains the pardes skill beside pardes-9p. --- .agents/skills/pardes-9p/SKILL.md | 110 +++-- .agents/skills/pardes/SKILL.md | 131 ++++++ docs/typ/builtins-gui.json | 6 +- docs/typ/builtins-tty.json | 6 +- docs/typ/guide.typ | 15 +- docs/typ/reference.typ | 27 +- docs/typ/setup.typ | 2 +- src/CHANGELOG.md | 6 + src/File.zig | 69 ++- src/Output.zig | 90 +++- src/builtins.zig | 49 +- src/config.zig | 27 +- src/edit_cmd.zig | 2 + src/gui/gui.zig | 69 ++- src/hunks.zig | 808 +++++++++++++++++++++++++++++++++ src/locations.zig | 4 +- src/look.zig | 12 + src/main.zig | 2 +- src/mouse.zig | 2 +- src/ninep/ctl.zig | 41 +- src/ninep/tree.zig | 2 +- src/normal.zig | 17 +- src/pardes.zig | 115 ++++- src/syntax.zig | 17 +- src/tagline.zig | 18 +- src/terminal.zig | 42 +- test/snapshots/diffview.golden | 6 +- test/snapshots/lsp-client-edit.golden | 8 +- test/snapshots/lsp-client.golden | 4 +- test/snapshots/lsp-rename-files.golden | 4 +- test/snapshots/lsp-rename.golden | 6 +- test/snapshots/lsp.golden | 4 +- test/snapshots/lspcomplete.golden | 10 +- test/snapshots/lspcompletemoved.golden | 2 +- test/snapshots/lspdebug.golden | 2 +- test/snapshots/lsprelpath.golden | 8 +- test/snapshots/ninep.golden | 18 +- test/snapshots/pagercolor.golden | 35 +- test/snapshots/selregex.golden | 6 +- test/snapshots/syntax.golden | 30 +- 40 files changed, 1625 insertions(+), 207 deletions(-) create mode 100644 .agents/skills/pardes/SKILL.md create mode 100644 src/hunks.zig (limited to 'src/Output.zig') diff --git a/.agents/skills/pardes-9p/SKILL.md b/.agents/skills/pardes-9p/SKILL.md index 06edbdf2..2b80c975 100644 --- a/.agents/skills/pardes-9p/SKILL.md +++ b/.agents/skills/pardes-9p/SKILL.md @@ -1,54 +1,104 @@ --- name: pardes-9p -description: Inspect and drive a running Pardes editor through its virtual filesystem (served over 9P), or exercise its panes, builtins, terminal input and rendered output in an isolated session. Use for Pardes interaction, plugin development and end-to-end debugging. +description: Script and drive a running pardes session through its virtual filesystem (served over 9P), or exercise its panes, builtins, terminals, events and rendered screen in an isolated session. Use for reading or editing panes, opening files at places, running commands and reading their output, event helpers and tag words, plugin development and end-to-end debugging. For what pardes is and its keys, use the pardes skill. --- -# Pardes over 9P +# pardes over 9P -Pardes is files: `cat`, `echo >`, `ls` and shell scripts are the whole -interface. The recipes are in the Scripting chapter -([docs/typ/scripting.typ](../../../docs/typ/scripting.typ)), every file's -semantics in the Reference chapter -([docs/typ/reference.typ](../../../docs/typ/reference.typ)), and a running -session serves a summary at `$m/README`. Paths are relative to the -repository root. +pardes is files: `cat`, `echo >`, `ls` and shell scripts are the whole +interface. The recipes and traps are the Scripting chapter +(`docs/typ/scripting.typ`), every file's semantics, refusals and limits the +Reference chapter (`docs/typ/reference.typ`; its "The tree" lists every +file), and a running session serves a one-screen summary at `$m/README`. +Paths are relative to the pardes source tree, the repository this skill +lives in (`readlink -f` this skill's directory if it is reached through a +symlink). ## Find the session +First check that you run inside a live session (the pardes skill's "Am I +in a pardes session?"); a session merely listed under `$NINE_MOUNT/pardes/` +is someone's, not yours to script. + ```sh m=${PARDES_MOUNT:-} [ -n "$m" ] || echo 'no mount: use 9p -a "unix!$PARDES_9P" read index' -cat "$m/index" +cat "$m/index" # serial kind(text|term|cmd|pdf|image) dirty name column ``` Under `9ns --mntgen` every pane gets `$PARDES_MOUNT`, its session as a -directory (also in a `Tty9p` shell). `$PARDES_9P` is the session socket of -the pane you run in, `$PARDES_PANE` that pane's serial. A dead session's -entry answers `Input/output error`: name the session, never glob. Without a -mount, plan9port's `9p -a "unix!$PARDES_9P"` works, and `test/ninep.py` in the source tree (Reference, "Other ways in"). +directory (also in a `Tty9p` shell). `$PARDES_9P` is the session socket, +`$PARDES_PANE` the serial of the pane the shell runs in, `$winid` the pane +a command was clicked in. Without a mount, `cat $m/x` is +`9p -a "unix!$PARDES_9P" read x` (its `write` truncates: on `body` it +replaces the text), and `test/ninep.py` is a Python client for holding a +fid open (Reference, "Other ways in"). A dead session's registry entry +answers `Input/output error`: name the session, never glob. + +## Recipes + +Work through a pane of your own, its own `look` and `exec`: + +```sh +n=$(cat $m/pane/new); p=$m/pane/$n # read pane/new once: each open makes a pane +exec 3<>$p/look; echo "$PWD/main.zig:120" >&3; cat <&3; exec 3<&- # open at a place; read: its pane +printf 'hello\n' > $p/body; echo "$PWD/x.txt" > $p/name; echo Save > $p/ctl +echo 'Msg hello' > $p/exec # a builtin, or else a shell line +echo 'Edit ,x/foo/c/bar/' > $p/ctl # sam's Edit, one undo step +echo /old/ > $p/addr && printf new > $p/data # replace the next match +t=$(awk '$2=="term"{print $1; exit}' $m/index) # a shell (bash or fish) +exec 3<>$m/pane/$t/pty/run; echo make >&3; cat <&3; exec 3<&- # exit N, then output +exec 3<>$m/log; echo 'follow new' >&3; timeout 30 cat <&3; exec 3<&- +rmdir $p # close it +``` + +The Scripting chapter has the rest: a command pane's output, typing into +a terminal, the language server, a tag word on `PATH` (`Fmt`), and event +helpers that own clicks through `pane//event`. ## Traps - A refused write says only `Invalid argument` or `Input/output error`; `grep '^err' $m/log | tail -1` says why. Not the log's last line: after - a refused Del, Exit or Restore that may be `+Unsaved`'s `new`. -- Work through a pane of your own (`n=$(cat $m/pane/new)`) and its own - `look` and `exec`: the root's act at the pane with the keyboard, which another - client, an idle shell or an event helper may own. -- `head` on `index`, `layout`, `log` or `recent` through 9ns says `Illegal - seek`: use `sed -n 1p`. In `index`, `term` is a shell, `cmd` a command's - pane. + a refused Del, Exit or Restore that may be `+Unsaved`'s `new`. A write + that succeeds logs nothing. +- The root `look` and `exec` act at the pane with the keyboard, which + another client, an idle shell or an event helper may own: use a pane's. +- Read `look`, `exec` or `pager` on the open you wrote (`exec 3<>…`): a + fresh open reads the session's last answer, from whichever client. +- A command pane your `exec` open was answered is yours while that open + stays open: read its `body` before you close it. - `addr` is the pane's and moves on: each `/re/` searches from the last address, and a `data` write leaves it just past the text. Write `addr` before each replacement; a failed address leaves none. - An Edit `x` that matches nothing succeeds: check the text afterwards. -- Each open of `pane/new` makes a pane: read it once. -- Through a mount, `printf 'a\nb\n' > ctl` arrives one write per line: send - a block as one write (`cat block > $p/ctl`), ending in a newline. +- Through a mount, `printf 'a\nb\n' > ctl` arrives one write per line: + send a block as one write, ending in a newline (a last line without one + runs after the close, its failure only in the log). +- Read `event` on a descriptor your shell owns (`exec 3<>$p/event`), + never `cat $p/event | while read`: the `cat` outlives the loop and + swallows the next click. +- The session has 64 open records shared by every client (held reads, + write opens of command files, snapshots): close what you open. +- `head` on `index`, `layout`, `log` or `recent` through 9ns says `Illegal + seek`: use `sed -n 1p`. - Pane words (`Save`, `Undo`, `Del`) go to `pane//ctl`, settings and - session words to `$m/ctl`. -- `Exit`, `Restore`, `Del` and `get` refuse once over unsaved text. -- Never experiment on a session someone is using: strip every `PARDES_*` - variable and start your own (Scripting, "An isolated session"); build - with `-Dplatform=tty`, since a bare `zig build` installs over - `~/.local/bin`. + session words to `$m/ctl`. `Exit`, `Restore`, `Del` and `get` refuse once + over unsaved text; the same word again discards. + +## An isolated session + +Never experiment on a session someone is using. Under `9ns --mntgen`: + +```sh +env -i PATH="$PATH" HOME="$(mktemp -d)" XDG_RUNTIME_DIR="$XDG_RUNTIME_DIR" SHELL=/usr/bin/bash pardes --detach=try & +m=$NINE_MOUNT/pardes/try; cat $m/index +echo Exit > $m/exec +``` + +Keep `SHELL` (bash or fish): without it the terminals run `/bin/sh`, +which gets no OSC 133 prompt marks, and `pty/run` answers `error no +prompt marks`. + +To test a change, build with `-Dplatform=tty` (it installs into +`zig-out`): a bare `zig build` installs over `~/.local/bin`. diff --git a/.agents/skills/pardes/SKILL.md b/.agents/skills/pardes/SKILL.md new file mode 100644 index 00000000..d49f8e50 --- /dev/null +++ b/.agents/skills/pardes/SKILL.md @@ -0,0 +1,131 @@ +--- +name: pardes +description: What the pardes editor is and how to use it, with a small cheatsheet (mouse, modes, keys, Look addresses, tags, sessions, config) and a map of its book. Use whenever the user mentions pardes, asks how to do something in it, wants a file opened or text paged in the editor, and to check whether you are running inside a pardes session ($PARDES_PID, $PARDES_9P, $PARDES_PANE, $PARDES_MOUNT) before acting on the user's editor. For scripting or driving a session through its 9P files, use pardes-9p. +--- + +# pardes + +pardes is acme's idea (text is the interface: any word can be looked at or +run) with helix's modal keys, VT terminals and PDFs in panes. Two builtins +carry it: Look (right-click, B3, or Enter in normal mode) opens what the +text names (a file, `file:line`, a directory, a URL), else finds the word's +next place; Exec (middle-click, B2, or Tab) runs the builtin a word names, +else runs it as a shell line. Every session is also a virtual filesystem +served over 9P, so any program that opens files can script it (pardes-9p). + +Paths below are relative to the pardes source tree, the repository this +skill lives in (`readlink -f` this skill's directory if it is reached +through a symlink). + +## Am I in a pardes session? + +Check this first: it decides whether "open it", "show me" or "run it" +can mean the user's editor. Every shell and command pane pardes starts +gets these, and every program started from it (an agent too) inherits them: + +| Variable | | +|---|---| +| `PARDES_PID` | the session's pid (what `status` says) | +| `PARDES_9P` | the session's 9P socket | +| `PARDES_PANE` | the serial of the pane this shell runs in | +| `PARDES_MOUNT` | the session as a directory, only under `9ns --mntgen` or in a `Tty9p` shell | +| `winid` | the pane a command was clicked in (command panes only) | + +A variable can outlive its session (a `--detach` session quit, a shell +moved under tmux), so check that it is live, not just set: + +```sh +if [ -n "${PARDES_9P:-}" ] && [ -S "$PARDES_9P" ] && kill -0 "${PARDES_PID:-}" 2>/dev/null; then + echo "in pardes: session $PARDES_PID, pane $PARDES_PANE, mount ${PARDES_MOUNT:-none}" +else + echo "not in pardes" +fi +``` + +With a mount, `sed -n 1p "$PARDES_MOUNT/status"` answers `pid +$PARDES_PID`. Sessions listed under `$NINE_MOUNT/pardes/` are not proof: +that lists every running session, the user's included, whether or not you +run inside one. Not in a session: say so, and touch no session you merely +found there. + +## Words + +- **tag**: the editable line of words above the workspace, each column and + each pane. A pane's starts with its path. Any word runs from any tag. +- **serial**: a pane's number, never reused (`@p3:12`, `pane/3/`). +- **command pane**: a terminal running one command line; its tag ends in + `running`, then `exit N`. +- **`+` names**: panes pardes makes: `+New` (scratch), `+Search`, `+Pager`, + `+Errors`, `+Unsaved`, `+Diff`. +- **active column**: where the next new pane goes. + +## Cheatsheet + +| Mouse | | +|---|---| +| B1 | select; give the pane the keyboard | +| B2 | Exec the word or sweep | +| B3 | Look at the word or sweep | +| B1+B2 / B1+B3 / B1+B2+B3 | cut / paste / copy (chords) | +| B2+B1 | Exec with the B1 selection as argument | +| Alt-click / Super-click | B2 / B3 for one button | + +| Modes (the box left of a tag) | | +|---|---| +| ` ` normal | helix keys: motions select, edits act on the selection | +| `^` insert | `i a o`…; Esc back to normal | +| `$` raw, terminals | keys go to the program; Ctrl-b toggles raw/normal | +| Esc in normal | back to the previous pane (unlike helix) | + +| Keys pardes adds or changes | | +|---|---| +| `SPC ?` | Help: every builtin, its leader path and keys | +| `:` | to the pane's tag and back | +| `Ctrl-w h/j/k/l` | focus a neighbour | +| `Ctrl-o` / `Ctrl-i` | jump list back / forward | +| `Alt-n` / `Alt-c` | new terminal below / pane to a new column | +| `SPC f s`, `SPC d`, `SPC q` | Save, Del, Exit | +| `SPC f f`, `SPC f g`, `SPC f r` | Find, Grep, Recent | +| `12G`, `n` in a command pane | line 12; next `file:line` error | + +| Look addresses (B3 or Enter) | | +|---|---| +| `file:12`, `file:12:5` | line, byte column | +| `file:/re/`, `file:0/re/` | next match, first match | +| `:40` | line 40 of the pane looked from | +| `@p3:12` | pane 3 by serial | +| `src/` | a directory pane | + +Addresses are sam's (`#n /re/ ?re? $ a,b`). + +| Common words | | +|---|---| +| `Save` `Del` `Get` `Undo` `Edit` | pane; Del/Exit/Restore refuse once over unsaved text, again discards | +| `New` `Tty` `Tty+bash` `Newcol` `Delcol` | panes and columns | +| `Find name` `Grep text` `Recent` | listings in a `+Search` | +| `Kill make` `Repl python` `Filter` `Mode` | terminals and commands | +| `Dump` `Restore` `Config` `DumpConfig` `Theme x` | workspace and settings | + +## From a shell inside pardes + +```sh +pardes notes.txt # open it in this session, return at once +pardes --wait notes.txt # return when its pane closes (EDITOR='pardes --wait') +git log | pardes - # page text into a +Pager +pardes --detach=work & # a session with no screen; --attach=work shows it +``` + +These act on the user's session: do them when asked. Anything more (read +panes, run commands, react to clicks) is the pardes-9p skill. Config is +`~/.config/pardes/init`, a builtin a line; keys are compiled in +(`src/config.zig`). `$NINE_MOUNT/agents`, where present, is cloud9's +read-only view of running coding agents. + +## The book + +`docs/typ/` holds it, one file a chapter, in reading order: `guide.typ` +(day to day), `setup.typ` (9ns, EDITOR, pager, language servers), +`cheatsheet.typ`, `scripting.typ`, `reference.typ` (every 9P file), +`themes.typ`, `building.typ`. `docs/typ/README` says how they build into +the A4 cheatsheet, the book and the website. In the editor: `Help` +(`SPC ?`) and `Tutor` (`SPC h t`). diff --git a/docs/typ/builtins-gui.json b/docs/typ/builtins-gui.json index b42f9c72..83a410dc 100644 --- a/docs/typ/builtins-gui.json +++ b/docs/typ/builtins-gui.json @@ -20,12 +20,15 @@ {"name": "Crt", "leader": "SPC t r", "also": [], "arg": true, "scope": "root", "setting": true, "choices": "on, off, 0-3", "doc": "The bundled CRT post pass over the window, on or off."}, {"name": "CursorBlink", "leader": null, "also": [], "arg": true, "scope": "root", "setting": true, "choices": "on, off", "doc": "The cursor blinks, solid while typing, on or off."}, {"name": "Debug", "leader": "SPC t d", "also": ["topbar"], "arg": true, "scope": "root", "setting": true, "choices": "on, off", "doc": "A small box of frame statistics at the top right, on or off."}, + {"name": "Def", "leader": null, "also": [], "arg": true, "scope": "pane", "setting": false, "choices": null, "doc": "Go to the definition of the symbol under the cursor; with an argument (a 2-1 chord's selection), of that symbol, where it is nearest."}, {"name": "Del", "leader": "SPC d", "also": [], "arg": true, "scope": "pane", "setting": false, "choices": null, "doc": "Close the pane."}, {"name": "DelAbove", "leader": null, "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Close the pane, giving its rows to the pane above it."}, {"name": "DelBelow", "leader": null, "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Close the pane, giving its rows to the pane below it."}, {"name": "Delcol", "leader": "SPC c d", "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Close this column and its panes, refusing once over unsaved text."}, {"name": "Detach", "leader": "SPC s D", "also": [], "arg": false, "scope": "root", "setting": false, "choices": null, "doc": "Detach this pardes from its terminal, leaving the session running."}, {"name": "Diagnostics", "leader": "SPC l d", "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "List the file's diagnostics from the language server."}, + {"name": "Diff", "leader": null, "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Stack a diff's hunks as a diff viewer shows them, each under its place and the declarations around it, in a +Diff; on a +Diff, show the diff itself as text."}, + {"name": "DiffLook", "leader": null, "also": [], "arg": true, "scope": "root", "setting": true, "choices": "hunks, text", "doc": "A .diff or .patch looked at: hunks, a +Diff stacking its hunks, or text, the file itself; Diff goes from one to the other."}, {"name": "DirLook", "leader": null, "also": [], "arg": true, "scope": "root", "setting": true, "choices": "pane, terminal", "doc": "A directory looked at: pane, a pane listing it as acme's directory window, or terminal, ls in a terminal there."}, {"name": "Down", "leader": "SPC w j", "also": ["C-w j", "C-w down"], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Move the keyboard to the pane below, off a tag onto the pane under it."}, {"name": "Dump", "leader": "SPC s d", "also": ["topbar"], "arg": false, "scope": "root", "setting": false, "choices": null, "doc": "Write the session's panes and layout to a dump file, for Restore."}, @@ -36,7 +39,7 @@ {"name": "EffectCode", "leader": null, "also": [], "arg": true, "scope": "root", "setting": false, "choices": null, "doc": "Open the source of a panel transition or post shader, by name."}, {"name": "Exec", "leader": null, "also": ["tab", "middle-click"], "arg": true, "scope": "pane", "setting": false, "choices": null, "doc": "Execute its argument as a middle click on it would, a builtin or a shell command."}, {"name": "Exit", "leader": "SPC q", "also": ["topbar"], "arg": false, "scope": "root", "setting": false, "choices": null, "doc": "Quit the editor, refusing once while a pane holds unsaved text: an Exit with nothing edited since discards it."}, - {"name": "Filter", "leader": null, "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Recolour a terminal's program colours to the theme, or show them as sent, flipping between them."}, + {"name": "Filter", "leader": null, "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Recolour a terminal's or a +Pager's program colours to the theme, or show them as sent, flipping between them."}, {"name": "Find", "leader": "SPC f f", "also": ["topbar"], "arg": true, "scope": "pane", "setting": false, "choices": null, "doc": "List the files below this pane's directory whose names hold its argument, in a +Search."}, {"name": "FocusTint", "leader": null, "also": [], "arg": true, "scope": "root", "setting": true, "choices": "on, off", "doc": "The focused pane's and column's tags are tinted, on or off."}, {"name": "Font", "leader": null, "also": [], "arg": true, "scope": "root", "setting": true, "choices": null, "doc": "The body font, by name or path, and its size."}, @@ -103,6 +106,7 @@ {"name": "Putall", "leader": null, "also": [], "arg": false, "scope": "root", "setting": false, "choices": null, "doc": "acme's Putall: every pane holding unsaved edits to a file is saved, each as its own Save; one that is refused (changed on disk since, a write that fails) says so and the rest are saved all the same."}, {"name": "Recent", "leader": "SPC f r", "also": [], "arg": false, "scope": "root", "setting": false, "choices": null, "doc": "List the files opened lately, closed ones too, each a place to open again."}, {"name": "Redo", "leader": null, "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Redo the last undone edit."}, + {"name": "Refs", "leader": null, "also": [], "arg": true, "scope": "pane", "setting": false, "choices": null, "doc": "List the references to the symbol under the cursor; with an argument (a 2-1 chord's selection), to that symbol, where it is nearest."}, {"name": "Rename", "leader": "SPC l r", "also": [], "arg": true, "scope": "pane", "setting": false, "choices": null, "doc": "Rename the symbol under the cursor everywhere, to its argument."}, {"name": "Repl", "leader": null, "also": [], "arg": true, "scope": "pane", "setting": false, "choices": null, "doc": "Binds this terminal as a language's REPL, so an exec on that language's files is typed into it instead of run."}, {"name": "Restore", "leader": "SPC s r", "also": [], "arg": true, "scope": "root", "setting": false, "choices": null, "doc": "Replace every pane with those of a dump file, the last one Dump wrote when bare."}, diff --git a/docs/typ/builtins-tty.json b/docs/typ/builtins-tty.json index 53bcf033..35e12875 100644 --- a/docs/typ/builtins-tty.json +++ b/docs/typ/builtins-tty.json @@ -17,12 +17,15 @@ {"name": "Colors", "leader": "SPC t c", "also": [], "arg": true, "scope": "root", "setting": true, "choices": "on, off", "doc": "Syntax colours in text panes, on or off."}, {"name": "Config", "leader": "SPC f c", "also": ["topbar"], "arg": false, "scope": "root", "setting": false, "choices": null, "doc": "Open the startup file, `init`, in a pane: its pane when it is open, else the file, else a pane of that name for Save to make it and its directory."}, {"name": "Debug", "leader": "SPC t d", "also": ["topbar"], "arg": true, "scope": "root", "setting": true, "choices": "on, off", "doc": "A small box of frame statistics at the top right, on or off."}, + {"name": "Def", "leader": null, "also": [], "arg": true, "scope": "pane", "setting": false, "choices": null, "doc": "Go to the definition of the symbol under the cursor; with an argument (a 2-1 chord's selection), of that symbol, where it is nearest."}, {"name": "Del", "leader": "SPC d", "also": [], "arg": true, "scope": "pane", "setting": false, "choices": null, "doc": "Close the pane."}, {"name": "DelAbove", "leader": null, "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Close the pane, giving its rows to the pane above it."}, {"name": "DelBelow", "leader": null, "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Close the pane, giving its rows to the pane below it."}, {"name": "Delcol", "leader": "SPC c d", "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Close this column and its panes, refusing once over unsaved text."}, {"name": "Detach", "leader": "SPC s D", "also": [], "arg": false, "scope": "root", "setting": false, "choices": null, "doc": "Detach this pardes from its terminal, leaving the session running."}, {"name": "Diagnostics", "leader": "SPC l d", "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "List the file's diagnostics from the language server."}, + {"name": "Diff", "leader": null, "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Stack a diff's hunks as a diff viewer shows them, each under its place and the declarations around it, in a +Diff; on a +Diff, show the diff itself as text."}, + {"name": "DiffLook", "leader": null, "also": [], "arg": true, "scope": "root", "setting": true, "choices": "hunks, text", "doc": "A .diff or .patch looked at: hunks, a +Diff stacking its hunks, or text, the file itself; Diff goes from one to the other."}, {"name": "DirLook", "leader": null, "also": [], "arg": true, "scope": "root", "setting": true, "choices": "pane, terminal", "doc": "A directory looked at: pane, a pane listing it as acme's directory window, or terminal, ls in a terminal there."}, {"name": "Down", "leader": "SPC w j", "also": ["C-w j", "C-w down"], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Move the keyboard to the pane below, off a tag onto the pane under it."}, {"name": "Dump", "leader": "SPC s d", "also": ["topbar"], "arg": false, "scope": "root", "setting": false, "choices": null, "doc": "Write the session's panes and layout to a dump file, for Restore."}, @@ -33,7 +36,7 @@ {"name": "EffectCode", "leader": null, "also": [], "arg": true, "scope": "root", "setting": false, "choices": null, "doc": "Open the source of a panel transition or post shader, by name."}, {"name": "Exec", "leader": null, "also": ["tab", "middle-click"], "arg": true, "scope": "pane", "setting": false, "choices": null, "doc": "Execute its argument as a middle click on it would, a builtin or a shell command."}, {"name": "Exit", "leader": "SPC q", "also": ["topbar"], "arg": false, "scope": "root", "setting": false, "choices": null, "doc": "Quit the editor, refusing once while a pane holds unsaved text: an Exit with nothing edited since discards it."}, - {"name": "Filter", "leader": null, "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Recolour a terminal's program colours to the theme, or show them as sent, flipping between them."}, + {"name": "Filter", "leader": null, "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Recolour a terminal's or a +Pager's program colours to the theme, or show them as sent, flipping between them."}, {"name": "Find", "leader": "SPC f f", "also": ["topbar"], "arg": true, "scope": "pane", "setting": false, "choices": null, "doc": "List the files below this pane's directory whose names hold its argument, in a +Search."}, {"name": "FocusTint", "leader": null, "also": [], "arg": true, "scope": "root", "setting": true, "choices": "on, off", "doc": "The focused pane's and column's tags are tinted, on or off."}, {"name": "Forward", "leader": "SPC j i", "also": ["C-i"], "arg": false, "scope": "root", "setting": false, "choices": null, "doc": "Ctrl-i: one step forward again, up to wherever Back started."}, @@ -90,6 +93,7 @@ {"name": "Putall", "leader": null, "also": [], "arg": false, "scope": "root", "setting": false, "choices": null, "doc": "acme's Putall: every pane holding unsaved edits to a file is saved, each as its own Save; one that is refused (changed on disk since, a write that fails) says so and the rest are saved all the same."}, {"name": "Recent", "leader": "SPC f r", "also": [], "arg": false, "scope": "root", "setting": false, "choices": null, "doc": "List the files opened lately, closed ones too, each a place to open again."}, {"name": "Redo", "leader": null, "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Redo the last undone edit."}, + {"name": "Refs", "leader": null, "also": [], "arg": true, "scope": "pane", "setting": false, "choices": null, "doc": "List the references to the symbol under the cursor; with an argument (a 2-1 chord's selection), to that symbol, where it is nearest."}, {"name": "Rename", "leader": "SPC l r", "also": [], "arg": true, "scope": "pane", "setting": false, "choices": null, "doc": "Rename the symbol under the cursor everywhere, to its argument."}, {"name": "Repl", "leader": null, "also": [], "arg": true, "scope": "pane", "setting": false, "choices": null, "doc": "Binds this terminal as a language's REPL, so an exec on that language's files is typed into it instead of run."}, {"name": "Restore", "leader": "SPC s r", "also": [], "arg": true, "scope": "root", "setting": false, "choices": null, "doc": "Replace every pane with those of a dump file, the last one Dump wrote when bare."}, diff --git a/docs/typ/guide.typ b/docs/typ/guide.typ index 90e72303..89323766 100644 --- a/docs/typ/guide.typ +++ b/docs/typ/guide.typ @@ -202,8 +202,8 @@ takes the rows: #key("k") above, #key("j") below. = Reviewing diffs -`git diff` run as a command, or a `.diff` or `.patch` opened, is drawn as -a diff, each hunk in its file's language. #btn("B3") on: +`git diff` run as a command, or a `.diff` or `.patch` shown as text (below), +is drawn as a diff, each hunk in its file's language. #btn("B3") on: #pairs( [`diff --git`, `---`, `+++`], [the file], @@ -211,6 +211,17 @@ a diff, each hunk in its file's language. #btn("B3") on: [a line's `+`, `-` or space], [that line in the new file], ) +A `.diff` or `.patch` looked at, and a diff paged (`git show`), opens as +a `+Diff`, stacked as delta shows one: each hunk under its `path:line` +(`n`/`N` step through them, #btn("B3") opens it) and the declarations +around it, a `+`/`-` before each line, the words a changed line changed +tinted and a line added or removed whole faintly. A mailed patch keeps its +message and diffstat above. The files are found from the diff's directory +or one above it. #word("Diff") on a `+Diff` shows the diff itself as +text (a paged one's `+Pager` is folded under it), and on the text stacks +it again; #word("DiffLook") `text` in the startup file opens the text +first. + = `pardes FILE` and `--wait` In a pane's shell: diff --git a/docs/typ/reference.typ b/docs/typ/reference.typ index ed88905a..909c1e1a 100644 --- a/docs/typ/reference.typ +++ b/docs/typ/reference.typ @@ -22,7 +22,7 @@ index a line per pane: serial kind dirty name column @ru status pid, version, panes @other-files look write a line: a #word("Look") at the pane with the keyboard; read: the serials touched @look-and-exec exec write a line: an #word("Exec") there; read: the serials touched @look-and-exec -pager write a directory: its one +Pager, made or emptied; read: its serial @pardes-stdin +pager write a directory: a new +Pager there; read: its serial @pardes-stdin log the event log; write follow to wait for more @log screen the rendered screen as JSON @on-screen listeners dial addresses @other-files @@ -252,7 +252,9 @@ A line written to #file("exec") is #word("Exec"): silently, here and in every ctl. - The language server's words ask about a file pane's text at its cursor (set it with #file("addr") and `dot=addr` first): #word("Hover") fills - `+Hover`; #word("Rename") `new` renames the symbol in the file and says how many + `+Hover`; #word("Def") and #word("Refs"), in the tag of a file a server + speaks for, are `gd` and `gr`, and given a symbol (a 2-1 chord's + selection) ask at its occurrence nearest the cursor; #word("Rename") `new` renames the symbol in the file and says how many ranges it changed (on the message row, and so in the log) without listing them, and fails when there is nothing to rename. One that reaches other files applies nothing: it opens a `+Search` preview of the edits, which @@ -457,7 +459,7 @@ may lower the contrast of text, the selection or a focus indicator. build embeds them. Resting the pointer on text for about 32 ms (`look_preview_delay_frames`, -2 frames, in `src/config.zig`; `null` turns it off) tints what #word("Look") would take, with no other effect. A terminal's +2 frames, in `src/config.zig`; `null` turns it off) tints what #word("Look") would take, with no other effect. A terminal's or a `+Pager`'s #word("Filter") keeps each foreground at least `tty_filter_min_contrast` (WCAG 1.5, `src/config.zig`) against its background. @@ -889,10 +891,10 @@ at 200, ending in `…`. Control characters become spaces. line is the session's; one not there is refused ENOENT, a relative one EINVAL, one you may not write `permission denied`, a regular file `not a directory`, ENOTDIR), one line; what follows that line, on the same open, is the text to - page, escapes and all. A read of that open answers the serial of the - directory's one `+Pager`, made or emptied for it, once the text is in. This is what - `pardes -` uses; from a directory you may not write, it pages into the - session's `+Pager`. + page, escapes and all. A read of that open answers the serial of a new + `+Pager` in the directory, once the text is in. This is what + `pardes -` uses; from a directory you may not write, it pages into a + `+Pager` of the session's. - #file("/listeners"): the session's dial addresses, a line each (#doc("building", section: "listeners")). - #file("/os/"): existing regular files take read, write and truncation to @@ -993,12 +995,13 @@ it was. = pardes - -`pardes -` reads stdin to its end and shows it in the directory's one -`+Pager` pane, made or emptied for it and left clean, opening at its top; -the next paged text refills it. The session parses the text with +`pardes -` reads stdin to its end and shows it in a new `+Pager` pane of +the directory, left clean, opening at its top, with no line numbers; a +`+Pager` already there keeps its page. The session parses the text with ghostty-vt: SGR colours become the `+Pager`'s own display, never part of -its body or any read (#word("PagerColor") `off` pages plain), and every other -escape is dropped; a carriage return keeps a progress line's last state, +its body or any read (#word("PagerColor") `off` pages plain), mapped +through the theme as a terminal's are until its #word("Filter") shows them +as sent; every other escape is dropped; a carriage return keeps a progress line's last state, and CRLF becomes LF. Empty stdin shows nothing. Inside a pardes pane it returns at once; a text the session cannot take is printed to stderr with why, and the exit is 1. From a directory whose name holds a newline or control byte, the pane is the session diff --git a/docs/typ/setup.typ b/docs/typ/setup.typ index df99a45f..f49c9075 100644 --- a/docs/typ/setup.typ +++ b/docs/typ/setup.typ @@ -59,7 +59,7 @@ fi = A pager -#cmd("ls --color=always | pardes - # into the directory's +Pager, colours kept") +#cmd("ls --color=always | pardes - # into a new +Pager there, colours kept") With #word("Pager") `pardes` (the default) a terminal's shell gets `PAGER`, `GIT_PAGER` and `SYSTEMD_PAGER` set to it (and diff --git a/src/CHANGELOG.md b/src/CHANGELOG.md index 6be39c7a..ce2cedc8 100644 --- a/src/CHANGELOG.md +++ b/src/CHANGELOG.md @@ -2,6 +2,12 @@ ## 0.23 +- A file a language server speaks for (by its extension) has `Def` and + `Refs` in its tag: the definition and the references of the symbol at + the cursor, which `gd`, `gr` and a Ctrl-click run too. Chorded 2-1, they + ask at the selected symbol instead, its occurrence nearest the cursor. +- A scroll in the window never moves the tree-sitter context rows: the + body glides under them. - A look at a directory opens a pane listing it, as acme's directory window does: its entries in columns, a directory's marked `/`. A look at an entry opens it from there, and `Get` or a look at it again reads it diff --git a/src/File.zig b/src/File.zig index 875d0f46..31392ebd 100644 --- a/src/File.zig +++ b/src/File.zig @@ -154,8 +154,11 @@ pub const State = struct { /// Its file was deleted on disk: said once (`deleted`) until it is /// written or found again. disk_gone: bool = false, - /// A +Pager pane (`pardes -`) whose text is a diff (`git diff`, `show`, - /// `log -p`): drawn and looked at as a diff (Pane.colorAlgo). + /// A +Pager pane (`pardes -`): no line numbers, its program's colours + /// through Filter until it is toggled off. + pager: bool = false, + /// A +Pager whose text is a diff (`git diff`, `show`, `log -p`): drawn + /// and looked at as a diff (Pane.colorAlgo). pager_diff: bool = false, /// A +Pager's colours, as its program printed them (pager.zig): drawn /// over its text by recolorSyntax, never read over 9P. ponytail: any @@ -562,6 +565,10 @@ pub fn byteAtRowDisplay(pane: *const Pane, row: i32, from_raw: i32, display_col: pub fn gutterWidth(pane: *const Pane) u16 { if (pane.file == null) return 0; const file = &pane.file.?; + // A +Pager, and a +Diff (hunks.zig), show no line numbers, as a + // pager and delta show none. + if (file.pager) return 0; + if (file.output) |o| if (std.meta.eql(o.from, Output.Origin{ .cmd = .Diff })) return 0; var lines = if (file.line_starts.len > 0) file.line_starts.len else lineCount(file.content); var digits: u16 = 1; while (lines >= 10) : (lines /= 10) digits += 1; @@ -1164,7 +1171,7 @@ pub fn setContentSpan(p: *Pardes, f: *State, new: []u8, span_in: ?Span) void { f.highlights = &.{}; f.highlight_start = 0; f.syntax_dirty = true; - if (std.mem.endsWith(u8, f.path, "/+Pager")) f.pager_diff = looksLikeDiff(new[0..@min(new.len, 64 * 1024)]); + if (f.pager) f.pager_diff = looksLikeDiff(new[0..@min(new.len, 64 * 1024)]); for (twins[0..ntwins], 0..) |id, i| { const t = p.panes[id].?; const tf = &t.file.?; @@ -1434,6 +1441,7 @@ test "a +Pager pane holding a diff is drawn and looked at as one; holding other const f = &pane.file.?; p.gpa.free(f.path); f.path = try p.gpa.dupe(u8, "/tmp/+Pager"); + f.pager = true; setContent(p, f, try p.gpa.dupe(u8, "commit abc\n\ndiff --git a/x b/x\n--- a/x\n+++ b/x\n@@ -1 +1 @@\n-a\n+b\n")); try std.testing.expect(pane.colorAlgo() == .diff); try std.testing.expect(pardes.look.diffLines(p, pane) != null); @@ -1715,7 +1723,7 @@ fn fillBody(dst: ?[]u8, pane: *Pane, f: *State, width: usize, record_wrap: bool) var lbuf: [@max(config.PREFIX_W, 32)]u8 = undefined; const prefix = lbuf[0..prefix_width]; @memset(prefix, ' '); - if (at == 0) { + if (at == 0 and prefix.len > 0) { var lineno = row + 1; var digit: usize = prefix.len - 1; while (true) { @@ -1790,6 +1798,12 @@ const SynStyle = struct { fg: [3]u8, bold: bool }; pub const DiffTints = struct { added_bg: [3]u8, removed_bg: [3]u8, + /// The words a changed line changed (hunks.zig), on a stronger ground. + added_emph_bg: [3]u8, + removed_emph_bg: [3]u8, + /// A +Diff line added or removed whole: a faint ground. + added_line_bg: [3]u8, + removed_line_bg: [3]u8, added_fg: [3]u8, removed_fg: [3]u8, @@ -1804,6 +1818,10 @@ pub const DiffTints = struct { return .{ .added_bg = added_bg, .removed_bg = removed_bg, + .added_emph_bg = Colors.mixOklab(page, green, 0.28), + .removed_emph_bg = Colors.mixOklab(page, red, 0.28), + .added_line_bg = Colors.mixOklab(page, green, 0.07), + .removed_line_bg = Colors.mixOklab(page, red, 0.07), .added_fg = legible(green, ink, added_bg), .removed_fg = legible(red, ink, removed_bg), }; @@ -1818,9 +1836,9 @@ pub const DiffTints = struct { /// The row ground and prefix ink for a line's style byte, if it is an /// added or removed line. - pub fn forStyle(t: *const DiffTints, style: u8) ?struct { bg: [3]u8, fg: [3]u8 } { - if (style & syntax.diff_added != 0) return .{ .bg = t.added_bg, .fg = t.added_fg }; - if (style & syntax.diff_removed != 0) return .{ .bg = t.removed_bg, .fg = t.removed_fg }; + pub fn forStyle(t: *const DiffTints, style: u8) ?struct { bg: [3]u8, fg: [3]u8, emph_bg: [3]u8, line_bg: [3]u8 } { + if (style & syntax.diff_added != 0) return .{ .bg = t.added_bg, .fg = t.added_fg, .emph_bg = t.added_emph_bg, .line_bg = t.added_line_bg }; + if (style & syntax.diff_removed != 0) return .{ .bg = t.removed_bg, .fg = t.removed_fg, .emph_bg = t.removed_emph_bg, .line_bg = t.removed_line_bg }; return null; } }; @@ -1855,7 +1873,17 @@ pub fn recolorSyntax(p: *Pardes, s: *Surface, pane: *Pane, f: *State, r: pardes. const prefix_width = gutterWidth(pane); const tz_recolor = tracy.zone(@src(), "synRecolor"); defer tz_recolor.end(); - const tints: ?DiffTints = if (pane.colorAlgo() == .diff and highlights.len > 0) DiffTints.of(p) else null; + // A diff's rows, and a +Diff's (hunks.zig): their markers coloured. + // A diff's whole row is tinted; a +Diff tints only the words a + // changed line changed. + const algo = pane.colorAlgo(); + const tints: ?DiffTints = if ((algo == .diff or algo == .locations) and highlights.len > 0) DiffTints.of(p) else null; + const row_tint = algo == .diff; + var filtered_storage: terminal.FilteredColors = undefined; + const filtered: ?*terminal.FilteredColors = if (comptime terminal.enabled) (if (pane.tty_filter and spans.len > 0) blk: { + filtered_storage = .init(p, null); + break :blk &filtered_storage; + } else null) else null; // indexed start, same as bodyText — an empty tail simply paints nothing var flines = std.mem.splitScalar(u8, f.content[lineStart(p.gpa, f, f.scroll)..], '\n'); const total = nlines(p.gpa, f); @@ -1893,7 +1921,11 @@ pub fn recolorSyntax(p: *Pardes, s: *Surface, pane: *Pane, f: *State, r: pardes. t.forStyle(highlights[base - highlight_start]) else null else null; - if (tint) |t| if (prefix_width < tw) tintRow(s, tx + @as(u16, @intCast(prefix_width)), body_y + vr, tx + tw, t.bg); + if (tint) |t| if (prefix_width < tw) { + // A +Diff line added or removed whole: faintly (hunks.zig). + const whole = highlights[base - highlight_start] & syntax.diff_whole != 0; + if (row_tint or whole) tintRow(s, tx + @as(u16, @intCast(prefix_width)), body_y + vr, tx + tw, if (row_tint) t.bg else t.line_bg); + }; // A +Pager's own colours (pager.zig) on every row but one the diff // look tints: an added or removed line is drawn as pardes draws a // diff, and git's red and green on it would only fight the tint. @@ -1924,6 +1956,11 @@ pub fn recolorSyntax(p: *Pardes, s: *Surface, pane: *Pane, f: *State, r: pardes. cell.style.bold = ss.bold; } } + if (tint) |t| if (highlights[hidx] & syntax.diff_emph != 0) { + var fill: usize = 0; + while (fill < cells and prefix_width + screen_c + fill < tw) : (fill += 1) + s.at(tx + @as(u16, @intCast(prefix_width + screen_c + fill)), body_y + vr).style.bg = .{ .rgb = t.emph_bg }; + }; } } // Results keep their exact live text. Only the location, @@ -1945,10 +1982,16 @@ pub fn recolorSyntax(p: *Pardes, s: *Surface, pane: *Pane, f: *State, r: pardes. while (fill < cells and prefix_width + screen_c + fill < tw) : (fill += 1) { const cell = s.at(tx + @as(u16, @intCast(prefix_width + screen_c + fill)), body_y + vr); if (cell.default) continue; - // A palette colour through the theme's sixteen, as a - // terminal pane's cell; truecolor as it is. - if (st.fg != .default) cell.style.fg = if (st.fg == .index) terminal.palColor(p, st.fg.index) else st.fg; - if (st.bg != .default) cell.style.bg = if (st.bg == .index) terminal.palColor(p, st.bg.index) else st.bg; + // As a terminal pane's cell: through Filter, or a + // palette colour through the theme's sixteen and + // truecolor as it is. + if (filtered) |colors| { + if (st.fg != .default) cell.style.fg = colors.spanColor(st.fg, false); + if (st.bg != .default) cell.style.bg = colors.spanColor(st.bg, true); + } else { + if (st.fg != .default) cell.style.fg = if (st.fg == .index) terminal.palColor(p, st.fg.index) else st.fg; + if (st.bg != .default) cell.style.bg = if (st.bg == .index) terminal.palColor(p, st.bg.index) else st.bg; + } cell.style.bold = cell.style.bold or st.bold; cell.style.dim = st.dim; cell.style.italic = st.italic; diff --git a/src/Output.zig b/src/Output.zig index 3bae9ecf..9e194615 100644 --- a/src/Output.zig +++ b/src/Output.zig @@ -15,6 +15,8 @@ const build_options = @import("pardes_config"); const lsp = @import("lsp/lsp.zig"); const look = @import("look.zig"); const locations = @import("locations.zig"); +const layout = @import("layout.zig"); +const hunks = @import("hunks.zig"); const Pane = panes.Pane; const File = panes.File; @@ -538,6 +540,17 @@ pub fn fillResults(p: *Pardes, id: usize, dir: []const u8, from: Origin, arg: [] result_rows = formatted.rows; anchor = formatted.anchor; } + _ = try fillRows(p, id, dir, from, arg, result_content, result_rows, anchor); +} + +/// Rows already laid out (`content`, `rows` its metadata, both taken +/// when it succeeds, the caller's still when it fails) into the pane they +/// belong in: the one a run of `from` with `arg` in `dir` showed last, +/// refilled, else a new one placed by pane `id`. Its id. +pub fn fillRows(p: *Pardes, id: usize, dir: []const u8, from: Origin, arg: []const u8, result_content: []u8, result_rows: []locations.Row, anchor: ?usize) !usize { + const pane = p.panes[id] orelse return error.MissingPane; + if (arg.len > max_arg) return error.ArgumentTooLong; + const by_arg = std.meta.activeTag(from) != .query; for (p.panes, 0..) |slot, i| { const rp = slot orelse continue; const rf = if (rp.file) |*f| f else continue; @@ -578,7 +591,7 @@ pub fn fillResults(p: *Pardes, id: usize, dir: []const u8, from: Origin, arg: [] pane.search_row = anchor; look.armLookWalk(p, i); } - return; + return i; } const free = p.freeSlot() orelse return error.NoPaneSlots; const np = try open(p, free, dir, from, arg, result_content); @@ -590,6 +603,57 @@ pub fn fillResults(p: *Pardes, id: usize, dir: []const u8, from: Origin, arg: [] pane.search_row = anchor; look.armLookWalk(p, free); } + return free; +} + +/// Diff: `content`, the diff at `path` (a file, a +Pager), stacked as a +/// diff viewer shows it (hunks.zig), in a +Diff where its files are found +/// (hunks.sourceRoot), placed by pane `id`, refilled when it is there. Its +/// arg names the diff (its base name, or its whole path when the +Diff +/// stands elsewhere), for Diff to go back to it. The +Diff's id; +/// NoHunks when there is none in it. +pub fn openDiff(p: *Pardes, id: usize, path: []const u8, content: []const u8) !usize { + const dir = std.fs.path.dirname(path) orelse p.sessionDir(); + const root = hunks.sourceRoot(p, dir, content); + const result = try hunks.format(p, root, content); + errdefer { + p.gpa.free(result.content); + locations.freeRows(p.gpa, result.rows); + } + var has_hunk = false; + for (result.rows) |row| has_hunk = has_hunk or row.kind == .match; + if (!has_hunk) return error.NoHunks; + const arg = if (std.mem.eql(u8, root, dir) or path.len > max_arg) std.fs.path.basename(path) else path; + return fillRows(p, id, root, .{ .cmd = .Diff }, arg, result.content, result.rows, null); +} + +/// Diff on a +Diff: the diff it stacks, as text. A pane holding it +/// already (the newest: a +Pager folded under its +Diff unfolds) is +/// shown; else the file is opened as text, whatever DiffLook says. +pub fn showDiffText(p: *Pardes, id: usize, source: []const u8) void { + var newest: ?usize = null; + for (p.panes, 0..) |slot, i| { + const f = (slot orelse continue).file orelse continue; + if (!std.mem.eql(u8, f.path, source)) continue; + if (newest == null or p.panes[newest.?].?.serial < slot.?.serial) newest = i; + } + if (newest) |i| { + if (p.panes[i].?.collapsed) layout.toggleCollapse(p, i); + p.active = i; + return; + } + p.look_text = true; + defer p.look_text = false; + look.lookAt(p, id, source); +} + +/// The diff a +Diff stacks (openDiff's arg): its path. +pub fn diffSource(p: *Pardes, f: *const File.State) ?[]const u8 { + const o = f.output orelse return null; + if (!std.meta.eql(o.from, Origin{ .cmd = .Diff })) return null; + const arg = o.arg(); + if (arg.len > 0 and arg[0] == '/') return arg; + return std.fs.path.join(p.scratch.allocator(), &.{ std.fs.path.dirname(f.path) orelse "", arg }) catch null; } pub fn openJumps(p: *Pardes, id: usize) !void { @@ -685,25 +749,15 @@ pub fn openUnsaved(p: *Pardes, id: usize, content: []u8) void { p.active = id; } -/// `pardes -`'s pane: the one `/+Pager`, emptied for the next paged -/// text when it is there (a directory's paged commands refill it, as its -/// command pane is reused), else made, named so before it is announced, -/// and placed wherever there is room without taking the keyboard. `dir` -/// empty (or not absolute): the session's directory. Its id; NoPaneRoom -/// or NoPaneSlots when it has no room at all. +/// `pardes -`'s pane: a new `/+Pager` for each paged text, as each +/// run of a pager is its own (one already there keeps its page), named so +/// before it is announced, its colours through Filter, and placed wherever +/// there is room without taking the keyboard. `dir` empty (or not +/// absolute): the session's directory. Its id; NoPaneRoom or NoPaneSlots +/// when it has no room at all. pub fn openPager(p: *Pardes, from: usize, dir_arg: []const u8) !usize { const dir = if (dir_arg.len > 0 and dir_arg[0] == '/') dir_arg else p.sessionDir(); const path = try std.fs.path.join(p.gpa, &.{ dir, "+Pager" }); - for (p.panes, 0..) |slot, i| { - const pane = slot orelse continue; - const f = if (pane.file) |*file| file else continue; - if (!std.mem.eql(u8, f.path, path)) continue; - p.gpa.free(path); - File.setContent(p, f, try p.gpa.alloc(u8, 0)); - resetBody(p, pane); - f.saved_revision = f.revision; - return i; - } const free = p.freeSlot() orelse { p.gpa.free(path); return error.NoPaneSlots; @@ -719,6 +773,8 @@ pub fn openPager(p: *Pardes, from: usize, dir_arg: []const u8) !usize { // The pane owns the name from here. p.gpa.free(pane.file.?.path); pane.file.?.path = path; + pane.file.?.pager = true; + pane.tty_filter = true; const keyboard = p.active; exec.placeNew(p, from, null, free, .fs); if (p.unplaced.isSet(free)) return error.NoPaneRoom; diff --git a/src/builtins.zig b/src/builtins.zig index 77e1169d..c1424b2f 100644 --- a/src/builtins.zig +++ b/src/builtins.zig @@ -46,6 +46,10 @@ pub const PaneKind = enum { /// An image pane, or a terminal, whose program's kitty graphics are /// pictures too. picture, + /// A terminal, or a +Pager: a program's colours. + program_colors, + /// A text pane showing a diff: a .diff, a .patch, a +Pager holding one. + diff, pub fn has(kind: PaneKind, pane: *const panes.Pane) bool { return switch (kind) { @@ -53,6 +57,9 @@ pub const PaneKind = enum { .pdf => pane.hasPdf(), .image => pane.image != null, .picture => pane.image != null or pane.isTerminal(), + .program_colors => pane.isTerminal() or (pane.file != null and pane.file.?.pager), + .diff => if (pane.file) |f| pane.colorAlgo() == .diff or + (f.output != null and std.meta.eql(f.output.?.from, panes.Output.Origin{ .cmd = .Diff })) else false, }; } @@ -62,6 +69,8 @@ pub const PaneKind = enum { .pdf => "a PDF", .image => "an image", .picture => "an image or a terminal", + .program_colors => "a terminal or a +Pager", + .diff => "a diff or a +Diff", }; } }; @@ -1336,14 +1345,28 @@ pub const Del = struct { } }; -/// Recolour a terminal's program colours to the theme, or show them as sent, flipping between them. +/// Recolour a terminal's or a +Pager's program colours to the theme, or show them as sent, flipping between them. pub const Filter = struct { - pub const needs: PaneKind = .terminal; + pub const needs: PaneKind = .program_colors; pub fn run(c: Ctx) void { c.pane.tty_filter = !c.pane.tty_filter; } }; +/// Stack a diff's hunks as a diff viewer shows them, each under its place and the declarations around it, in a +Diff; on a +Diff, show the diff itself as text. +pub const Diff = struct { + pub const needs: PaneKind = .diff; + pub const output: OutputTraits = .{ .name = config.diff_buffer, .steps = true, .locations = true }; + pub fn run(c: Ctx) void { + const f = &c.pane.file.?; + if (panes.Output.diffSource(c.p, f)) |source| return panes.Output.showDiffText(c.p, c.id, source); + _ = panes.Output.openDiff(c.p, c.id, f.path, f.content) catch |err| switch (err) { + error.NoHunks => c.p.reportFailure(c.id, "Diff: no hunk in it"), + else => c.p.reportError(c.id, "hunks", err), + }; + } +}; + /// Cycle the pane's input modes: terminals add raw tty mode to normal/insert. pub const Mode = struct { pub fn run(c: Ctx) void { @@ -1851,6 +1874,28 @@ pub const Jumplist = struct { // ---- the language group ---- +/// Go to the definition of the symbol under the cursor; with an argument +/// (a 2-1 chord's selection), of that symbol, where it is nearest. +pub const Def = struct { + pub const takes_arg = true; + /// Its answer says what it found, a jump or a list or why not; its + /// name would only stack above it, as gd never did. + pub const quiet = true; + pub fn run(c: Ctx) void { + c.p.lspRequest(c.id, .definition, std.mem.trim(u8, c.arg orelse "", " \t\r\n")); + } +}; + +/// List the references to the symbol under the cursor; with an argument +/// (a 2-1 chord's selection), to that symbol, where it is nearest. +pub const Refs = struct { + pub const takes_arg = true; + pub const quiet = true; // as Def + pub fn run(c: Ctx) void { + c.p.lspRequest(c.id, .references, std.mem.trim(u8, c.arg orelse "", " \t\r\n")); + } +}; + /// Ask the language server about the symbol under the cursor. pub const Hover = struct { pub fn run(c: Ctx) void { diff --git a/src/config.zig b/src/config.zig index d6ea7358..c2f51b36 100644 --- a/src/config.zig +++ b/src/config.zig @@ -32,6 +32,8 @@ pub const leader_path = paths: { var table = std.EnumArray(Builtin, ?[]const u8).initDefault(@as(?[]const u8, undecided), .{ .Help = &[_]u8{leader_help}, .Hover = "lk", + .Def = null, // gd + .Refs = null, // gr .Rename = "lr", .CodeAction = "la", .SelectRefs = "lh", @@ -49,6 +51,7 @@ pub const leader_path = paths: { .DelAbove = null, .DelBelow = null, .Filter = null, + .Diff = null, .Mode = null, .Togglettymode = null, .Collapse = null, @@ -87,6 +90,7 @@ pub const leader_path = paths: { .BootShell = null, .LookWord = null, .DirLook = null, + .DiffLook = null, .Pager = null, .PagerColor = null, .TermImages = null, @@ -301,6 +305,16 @@ pub const topbar_str = "Newcol Joincol Find Grep Help Changelog Tutor Dump Theme pub const pane_builtins_str = "Tty Collapse Del"; pub const pdf_pane_builtins_str = "Tty PdfSections PdfTint Collapse Del"; pub const file_pane_builtins_str = "Save Tty Collapse Del"; +/// After a file's, on one a language server speaks for. +pub const lsp_pane_builtins_str = "Def Refs"; +/// A diff's (a .diff, a .patch, a +Pager holding one): Diff. +pub const diff_pane_builtins_str = "Save Tty Diff Collapse Del"; +/// A +Pager's (`pardes -`): Filter, as a terminal's. +pub const pager_pane_builtins_str = "Save Tty Filter Collapse Del"; +/// A +Pager holding a diff (`git show`): Diff too. +pub const pager_diff_pane_builtins_str = "Save Tty Filter Diff Collapse Del"; +/// A +Diff's: Diff again, the diff it stacks as text. +pub const diff_view_builtins_str = "Save Tty Diff Collapse Del"; pub const terminal_pane_builtins_str = "Tty Save Mode Filter Collapse Del"; pub const command_pane_builtins_str = "Kill Save Collapse Del"; /// A directory pane's (Dir.zig): Get reads it again, as acme's does. @@ -500,6 +514,7 @@ pub const unsaved_buffer = "+Unsaved"; pub const themes_buffer = "+Themes"; pub const fonts_buffer = "+Fonts"; pub const pdf_sections_buffer = "+PdfSections"; +pub const diff_buffer = "+Diff"; pub const pdf_links_buffer = "+Links"; pub const hover_buffer = "+Hover"; pub const lsp_buffer = "+Lsp"; @@ -794,6 +809,10 @@ pub const Runtime = struct { /// A directory looked at: `pane`, acme's, a pane listing it (Dir.zig); /// `terminal`, what pardes did before, `ls` in a terminal there. dir_look: DirLook = .pane, + /// A .diff or .patch looked at (a look, `pardes FILE`, `--wait`): + /// `hunks`, a +Diff stacking its hunks (hunks.zig); `text`, the file + /// itself, as pardes showed it before. Diff goes from one to the other. + diff_look: DiffLook = .hunks, /// What a terminal's shell pages through (host_io.ChildEnv): `pardes`, /// PAGER and GIT_PAGER set to `pardes -`, a +Pager pane, where the /// user's environment set neither; `off`, the environment as it is. @@ -818,11 +837,12 @@ pub const Runtime = struct { pub const BootShell = enum { keep, replace }; pub const LookWord = enum { search, list }; pub const DirLook = enum { pane, terminal }; + pub const DiffLook = enum { hunks, text }; pub const Pager = enum { pardes, off }; pub const TermImages = enum { real, petscii }; pub const JumpScope = enum { file, all }; /// A setting that is one of a few words, each an enum field of Runtime. - pub const Choice = enum { placement, boot_shell, look_word, dir_look, pager, term_images, jump_scope }; + pub const Choice = enum { placement, boot_shell, look_word, dir_look, diff_look, pager, term_images, jump_scope }; /// shadow: a soft drop shadow. rim: a light hairline along the top of /// the focused pane's tag rows. auto: a shadow on a light page; on a @@ -1088,6 +1108,7 @@ pub const Runtime = struct { .{ .word = "Placement", .action = .{ .choice = .placement }, .doc = "Where a new pane goes: acme, as makenewwindow does, or pardes, the older rules." }, .{ .word = "BootShell", .action = .{ .choice = .boot_shell }, .doc = "A document dropped where a lone untouched shell stands: keep the shell, or replace it." }, .{ .word = "LookWord", .action = .{ .choice = .look_word }, .doc = "A plain word looked at: search selects its next place in the pane, list lists every place in a +Search." }, + .{ .word = "DiffLook", .action = .{ .choice = .diff_look }, .doc = "A .diff or .patch looked at: hunks, a +Diff stacking its hunks, or text, the file itself; Diff goes from one to the other." }, .{ .word = "DirLook", .action = .{ .choice = .dir_look }, .doc = "A directory looked at: pane, a pane listing it as acme's directory window, or terminal, ls in a terminal there." }, .{ .word = "Pager", .action = .{ .choice = .pager }, .doc = "What a terminal's commands page through: pardes, a +Pager pane (pardes -), or off, the environment's own; for terminals started after it." }, .{ .word = "PagerColor", .action = .{ .toggle = .pager_color }, .doc = "A +Pager keeps its program's colours, on or off; for the next text paged." }, @@ -1787,6 +1808,7 @@ pub const Runtime = struct { .boot_shell => "replace", .look_word => "list", .dir_look => "terminal", + .diff_look => "text", .pager => "off", .term_images => "petscii", .jump_scope => "all", @@ -1862,6 +1884,7 @@ pub const Runtime = struct { .boot_shell => "BootShell replace\n", .look_word => "LookWord list\n", .dir_look => "DirLook terminal\n", + .diff_look => "DiffLook text\n", .pager => "Pager off\n", .term_images => "TermImages petscii\n", .jump_scope => "JumpScope all\n", @@ -2235,7 +2258,7 @@ const doc_typ = struct { if (w.end > 0) w.writeByte(' ') catch return false; w.writeAll(x[0 .. std.mem.indexOfScalar(u8, x, '+') orelse x.len]) catch return false; } - const tags = [_][]const u8{ topbar_str, @import("tagline.zig").column_tag_default, pane_builtins_str, pdf_pane_builtins_str, file_pane_builtins_str, terminal_pane_builtins_str, command_pane_builtins_str, dir_pane_builtins_str }; + const tags = [_][]const u8{ topbar_str, @import("tagline.zig").column_tag_default, pane_builtins_str, pdf_pane_builtins_str, file_pane_builtins_str, diff_pane_builtins_str, pager_pane_builtins_str, pager_diff_pane_builtins_str, diff_view_builtins_str, terminal_pane_builtins_str, command_pane_builtins_str, dir_pane_builtins_str }; for (tags) |d| if (std.mem.eql(u8, d, w.buffered())) return true; return false; } diff --git a/src/edit_cmd.zig b/src/edit_cmd.zig index ebeae223..d3377e09 100644 --- a/src/edit_cmd.zig +++ b/src/edit_cmd.zig @@ -97,7 +97,9 @@ const World = struct { // A look opens it, or finds it open, where a look would; the // keyboard stays where the Edit ran. const was = p.active; + p.look_text = true; look.lookAt(p, w.from, path); + p.look_text = false; if (p.panes[was] != null) p.active = was; for (p.panes, 0..) |slot, id| { const pane = slot orelse continue; diff --git a/src/gui/gui.zig b/src/gui/gui.zig index 65b3f926..5a026664 100644 --- a/src/gui/gui.zig +++ b/src/gui/gui.zig @@ -1873,6 +1873,7 @@ const Gui = struct { scroll_rect: pardes.Rect = .{ .x = 0, .y = 0, .w = 0, .h = 0 }, scroll_body_y: u16 = 0, // that rect's first BODY row (Tagbottom moves it) scroll_body_h: u16 = 0, // and its BODY rows, which a taller tag leaves fewer of + scroll_held_px: f32 = 0, // its tree-sitter context band, which never moves scroll_col: u16 = 0, // where the wheel turned: crossed rows are delivered scroll_row: u16 = 0, // THERE, not wherever the pointer has drifted to since scroll_delta: f32 = 0, // finite raw distance waiting for the render batch @@ -5367,7 +5368,7 @@ fn stepGlide(g: *Gui, core: *pardes.Pardes, gpa: std.mem.Allocator) void { /// The glide's picture: the pane's body rows moved by the offset, and in /// the gap it opens the rows that left, as `emitScrollRows` draws a /// touchpad's fraction. -fn emitGlideRows(g: *Gui, instances: [*]CellInstance, base: u32, surface: *pardes.Surface, layout: CellLayout, win_w: f32, win_h: f32, page: Ground) u32 { +fn emitGlideRows(g: *Gui, instances: [*]CellInstance, base: u32, surface: *pardes.Surface, layout: CellLayout, win_w: f32, win_h: f32, page: Ground, held: u16) u32 { const glide = &g.glide; for (surface.panelTracks()) |track| if (track.active() and track.pane == glide.pane) return 0; @@ -5383,10 +5384,12 @@ fn emitGlideRows(g: *Gui, instances: [*]CellInstance, base: u32, surface: *parde g.scroll_body_h = bh; var shifted = layout; shifted.y_off -= glide.offset * layout.h; + const kept = holdContext(g, surface, glide.pane, held, bh, layout); + shifted.y_off += kept.lift; const cursor_idx: u32 = if (surface.cursor) |cu| @as(u32, cu.y) * surface.cols + cu.x else std.math.maxInt(u32); const cursor_bar = if (surface.cursor) |cu| cu.bar else false; var n: u32 = 0; - var row = y0; + var row = y0 + kept.rows; while (row < y0 + bh) : (row += 1) { const line = surface.cells[@as(usize, row) * surface.cols ..][0..surface.cols]; const row_cursor: ?usize = if (surface.cursor) |cu| if (cu.y == row) cu.x else null else null; @@ -5400,9 +5403,9 @@ fn emitGlideRows(g: *Gui, instances: [*]CellInstance, base: u32, surface: *parde // The gap: rows past the top while the picture lags a move down, past // the bottom for one up; as many as it opens. const gap: u16 = @intFromFloat(@min(@ceil(@abs(glide.offset)), @as(f32, @floatFromInt(bh)))); - const kept = if (glide.offset < 0) glide.nabove else glide.nbelow; + const nkept = if (glide.offset < 0) glide.nabove else glide.nbelow; const rows = if (glide.offset < 0) glide.above else glide.below; - for (0..@min(gap, kept)) |i| { + for (0..@min(gap, nkept)) |i| { const cells = rows[i * bw ..][0..bw]; // Row -1 - i above the body, or bh + i below it, in grid rows. const at_row: i32 = if (glide.offset < 0) @as(i32, y0) - 1 - @as(i32, @intCast(i)) else @as(i32, y0) + bh + @as(i32, @intCast(i)); @@ -5560,8 +5563,9 @@ fn stepScroll(g: *Gui, core: *pardes.Pardes, gpa: std.mem.Allocator) void { if (g.scroll_lag == 0) resetScroll(g); } -fn emitScrollRows(g: *Gui, instances: [*]CellInstance, base: u32, surface: *pardes.Surface, layout: CellLayout, win_w: f32, win_h: f32, page: Ground) u32 { - if (g.glide.offset != 0) return emitGlideRows(g, instances, base, surface, layout, win_w, win_h, page); +fn emitScrollRows(g: *Gui, instances: [*]CellInstance, base: u32, surface: *pardes.Surface, layout: CellLayout, win_w: f32, win_h: f32, page: Ground, held: u16) u32 { + g.scroll_held_px = 0; + if (g.glide.offset != 0) return emitGlideRows(g, instances, base, surface, layout, win_w, win_h, page, held); const scroll_pane = g.scroll_pane orelse return 0; if (g.scroll_lag == 0) return 0; for (surface.panelTracks()) |track| @@ -5575,10 +5579,12 @@ fn emitScrollRows(g: *Gui, instances: [*]CellInstance, base: u32, surface: *pard if (x0 + bw > surface.cols or y0 + bh > surface.rows) return 0; // resized under us var shifted = layout; shifted.y_off -= g.scroll_lag * layout.h; + const kept = holdContext(g, surface, scroll_pane, held, bh, layout); + shifted.y_off += kept.lift; const cursor_idx: u32 = if (surface.cursor) |cu| @as(u32, cu.y) * surface.cols + cu.x else std.math.maxInt(u32); const cursor_bar = if (surface.cursor) |cu| cu.bar else false; var n: u32 = 0; - var row = y0; + var row = y0 + kept.rows; while (row < y0 + bh) : (row += 1) { const line = surface.cells[@as(usize, row) * surface.cols ..][0..surface.cols]; const row_cursor: ?usize = if (surface.cursor) |cu| if (cu.y == row) cu.x else null else null; @@ -5600,12 +5606,52 @@ fn emitScrollRows(g: *Gui, instances: [*]CellInstance, base: u32, surface: *pard return n; } +/// A scrolling body's tree-sitter context rows hold still: the shifted +/// rows start under them and are clipped below their band, and where a +/// body layer stacks them at the tagline's height (TreeContextTagStyle) +/// the rows under them are drawn up to meet them, where the layer has them. +fn holdContext(g: *Gui, surface: *const pardes.Surface, id: usize, held: u16, bh: u16, layout: CellLayout) struct { rows: u16, lift: f32 } { + const rows = @min(held, bh); + const layered = id < surface.body_layers.len and surface.body_layers[id].rows != 0 and surface.body_layers[id].context_rows != 0; + const row_px = if (layered) std.math.clamp(@as(f32, @floatFromInt(g.tagline_height)), 1, @max(1, layout.h)) else layout.h; + g.scroll_held_px = @as(f32, @floatFromInt(rows)) * row_px; + return .{ .rows = rows, .lift = @as(f32, @floatFromInt(rows)) * (row_px - layout.h) }; +} + +test "a scroll's shifted rows start under the context rows, and its scissor below their band" { + var surface: pardes.Surface = .{}; + var g: Gui = undefined; + g.tagline_height = 12; + g.scroll_rect = .{ .x = 0, .y = 0, .w = 40, .h = 20 }; + g.scroll_body_y = 1; + g.scroll_body_h = 19; + const layout: CellLayout = .{ .w = 10, .h = 20, .x_off = 0, .y_off = 0 }; + // On the grid, three body-high rows are held, and nothing moves up. + const grid = holdContext(&g, &surface, 0, 3, 19, layout); + try std.testing.expectEqual(@as(u16, 3), grid.rows); + try std.testing.expectEqual(@as(f32, 0), grid.lift); + const clip = scrollScissor(&g, layout, 400, 400); + try std.testing.expectEqual(@as(c_int, 20 + 3 * 20), clip.y); + try std.testing.expectEqual(@as(c_int, 16 * 20), clip.h); + // In a body layer they are tagline-high: the rows under them move up + // by what each is shorter, to where the layer draws them. + surface.body_layers[0].rows = 30; + surface.body_layers[0].context_rows = 3; + const layered = holdContext(&g, &surface, 0, 3, 19, layout); + try std.testing.expectEqual(@as(f32, 3 * (12 - 20)), layered.lift); + try std.testing.expectEqual(@as(c_int, 20 + 3 * 12), scrollScissor(&g, layout, 400, 400).y); + // None held: the whole body moves. + surface.body_layers[0].rows = 0; + try std.testing.expectEqual(@as(u16, 0), holdContext(&g, &surface, 0, 0, 19, layout).rows); + try std.testing.expectEqual(@as(c_int, 20), scrollScissor(&g, layout, 400, 400).y); +} + fn scrollScissor(g: *const Gui, layout: CellLayout, sw: u32, sh: u32) c.SDL_Rect { const r = g.scroll_rect; const px = layout.x_off + @as(f32, @floatFromInt(r.x + config.GUTTER)) * layout.w; - const py = layout.y_off + @as(f32, @floatFromInt(g.scroll_body_y)) * layout.h; + const py = layout.y_off + @as(f32, @floatFromInt(g.scroll_body_y)) * layout.h + g.scroll_held_px; const pw = @as(f32, @floatFromInt(r.w - config.GUTTER)) * layout.w; - const ph = @as(f32, @floatFromInt(g.scroll_body_h)) * layout.h; + const ph = @max(0, @as(f32, @floatFromInt(g.scroll_body_h)) * layout.h - g.scroll_held_px); const x0 = std.math.clamp(@as(i32, @intFromFloat(@floor(px))), 0, @as(i32, @intCast(sw))); const y0 = std.math.clamp(@as(i32, @intFromFloat(@floor(py))), 0, @as(i32, @intCast(sh))); const x1 = std.math.clamp(@as(i32, @intFromFloat(@ceil(px + pw))), x0, @as(i32, @intCast(sw))); @@ -6426,7 +6472,10 @@ fn renderFrame( } for (groups.items[0..groups.len], 0..) |group, index| std.debug.assert(cell_next[index] == group.cell_start + group.cell_count); - shifted = emitScrollRows(g, instances, cell_total, surface, layout, win_w, win_h, page); + // The body's context rows, which its scroll leaves where they are. + const scrolling: ?usize = if (g.glide.offset != 0) g.glide.pane else g.scroll_pane; + const held: u16 = if (core) |p| if (scrolling) |id| if (p.panes[id]) |pane| pane.context_rows else 0 else 0 else 0; + shifted = emitScrollRows(g, instances, cell_total, surface, layout, win_w, win_h, page, held); // Over a theme's plaques a see-through cell with no ink blends to // the plaque under it, so it draws nothing: its quad goes, and the // cells are drawn unblended (a third of the GPU's frame at 4K) diff --git a/src/hunks.zig b/src/hunks.zig new file mode 100644 index 00000000..73c0654a --- /dev/null +++ b/src/hunks.zig @@ -0,0 +1,808 @@ +//! A unified diff (`.diff`, `.patch`, a paged `git show`) stacked as a +//! diff viewer shows it (Diff): each hunk under its `path:line`, the +//! declarations around it from tree-sitter as a result's context +//! (locations.zig), its lines behind their `+`/`-` markers drawn red and +//! green, coloured as their file, and the words a changed line changed on +//! a tinted ground as delta emphasises them (its edits.rs and align.rs, here as `inferEdits` +//! and `Alignment`). +const std = @import("std"); +const pardes = @import("pardes.zig"); +const diff = @import("diff.zig"); +const syntax = @import("syntax.zig"); +const locations = @import("locations.zig"); + +const Pardes = pardes.Pardes; +const Row = locations.Row; + +/// The rows `content`, a diff, stacks to, for a pane in `dir`, with each +/// row's metadata (Output.fillRows). Text and rows are `p.gpa`'s; all else +/// is the step's scratch. +pub fn format(p: *Pardes, dir: []const u8, content: []const u8) !locations.Result { + const arena = p.scratch.allocator(); + const styles = try syntax.highlightDiff(arena, content, 0, content.len); + var out: Out = .{ .p = p, .text = .init(p.gpa) }; + errdefer out.deinit(); + var walk: diff.Walk = .{}; + var hunk: Hunk = .{}; + var source: SourceMemo = .{}; + var at: usize = 0; + // The empty text after a last newline is no line. + while (at < content.len) { + const nl = std.mem.indexOfScalarPos(u8, content, at, '\n') orelse content.len; + const raw = content[at..nl]; + const got = walk.step(raw); + const line = std.mem.trimEnd(u8, raw, "\r"); + switch (got.kind) { + .context, .added, .removed => { + const skip = @intFromBool(line.len > 0 and std.mem.indexOfScalar(u8, " +-", line[0]) != null); + try hunk.lines.append(arena, .{ + .kind = got.kind, + .code = line[skip..], + .styles = styles[at + skip ..][0 .. line.len - skip], + .old = got.old, + .new = got.new, + }); + }, + // A `\ No newline` belongs to the line above, as delta shows it. + .no_newline => {}, + else => { + try flush(&out, &hunk, &source, dir); + switch (got.kind) { + .hunk => hunk = .{ + .path = walk.path(), + .deleted = walk.deleted(), + .old_start = got.old, + .new_start = got.new, + .header = gitContext(line), + }, + // What is said around the hunks, a mailed patch's + // headers, message and diffstat, as it was written. + .other => try out.row(line, "", .{ .kind = .context, .at = .{} }), + // A section's own words (a new file's mode, a rename, + // `Binary files ... differ`), muted; its `diff` and + // `index` lines say nothing the labels do not. + .meta => if (!std.mem.startsWith(u8, line, "diff ") and !std.mem.startsWith(u8, line, "index ")) + try out.row(line, "", .{ .kind = .context, .declaration = true, .at = .{} }), + else => {}, + } + }, + } + at = nl + 1; + } + try flush(&out, &hunk, &source, dir); + const rows = try out.rows.toOwnedSlice(p.gpa); + errdefer locations.freeRows(p.gpa, rows); + return .{ .content = try out.text.toOwnedSlice(), .rows = rows, .anchor = null }; +} + +const HunkLine = struct { + kind: diff.Kind, + code: []const u8, + /// Its code's style bytes, as the diff pane paints them (syntax.zig + /// highlightDiff), the emphasis bit added by `inferEdits`. + styles: []u8, + old: usize, + new: usize, + /// Paired with a line it changed (inferEdits): its words show that; + /// unpaired, the whole line was added or removed. + paired: bool = false, +}; + +const Hunk = struct { + path: []const u8 = "", + deleted: bool = false, + old_start: usize = 0, + new_start: usize = 0, + /// What git wrote after the `@@`'s second marker (its function line). + header: []const u8 = "", + lines: std.ArrayList(HunkLine) = .empty, +}; + +/// `@@ -a,b +c,d @@ fn foo()`: `fn foo()`. +fn gitContext(line: []const u8) []const u8 { + const close = std.mem.indexOfPos(u8, line, 2, "@@") orelse return ""; + return std.mem.trim(u8, line[close + 2 ..], " \t"); +} + +const Out = struct { + p: *Pardes, + text: std.Io.Writer.Allocating, + rows: std.ArrayList(Row) = .empty, + + fn deinit(out: *Out) void { + out.text.deinit(); + for (out.rows.items) |r| { + out.p.gpa.free(r.path); + out.p.gpa.free(r.colors); + } + out.rows.deinit(out.p.gpa); + } + + const Meta = struct { + kind: @FieldType(Row, "kind"), + declaration: bool = false, + at: @FieldType(Row, "at"), + location_end: usize = 0, + code_start: usize = 0, + colors: []const u8 = &.{}, + }; + + /// One row: its text, a newline, and its metadata. + fn row(out: *Out, text: []const u8, path: []const u8, meta: Meta) !void { + const gpa = out.p.gpa; + try out.text.writer.writeAll(text); + try out.text.writer.writeByte('\n'); + const owned_path = try gpa.dupe(u8, path); + errdefer gpa.free(owned_path); + const colors = try gpa.dupe(u8, meta.colors); + errdefer gpa.free(colors); + try out.rows.append(gpa, .{ + .kind = meta.kind, + .declaration = meta.declaration, + .path = owned_path, + .at = meta.at, + .location_end = meta.location_end, + .code_start = meta.code_start, + .colors = colors, + }); + } +}; + +/// The file a diff section names, as found from the pane's directory or +/// one above it (a patch kept in a subdirectory of its repository). +const SourceMemo = struct { + path: []const u8 = "", + /// The name a look from the pane's directory resolves; null when the + /// file is nowhere to be found. + shown: ?[]const u8 = null, + lines: []const []const u8 = &.{}, + declarations: []const syntax.ContextDeclaration = &.{}, +}; + +/// Where a +Diff of `content`, a diff in `dir`, stands: the directory its +/// first file is found from (`dir` or one above it, as `findSource` looks), +/// so its rows name their files as the diff does; `dir` when none is found. +pub fn sourceRoot(p: *Pardes, dir: []const u8, content: []const u8) []const u8 { + var walk: diff.Walk = .{}; + var lines = std.mem.splitScalar(u8, content, '\n'); + const path = while (lines.next()) |line| { + if (walk.step(line).kind == .hunk and walk.path().len > 0) break walk.path(); + } else return dir; + var base: []const u8 = dir; + for (0..8) |_| { + if (locations.sourceText(p, p.scratch.allocator(), base, path) != null) return base; + base = std.fs.path.dirname(base) orelse return dir; + } + return dir; +} + +fn findSource(p: *Pardes, memo: *SourceMemo, dir: []const u8, path: []const u8) !void { + if (std.mem.eql(u8, memo.path, path)) return; + const arena = p.scratch.allocator(); + memo.* = .{ .path = path }; + // ponytail: eight directories up; a repository deeper than that under + // its patch is looked for from the patch's own directory only. + var base: []const u8 = dir; + for (0..8) |_| { + if (locations.sourceText(p, arena, base, path)) |text| { + memo.shown = if (base.ptr == dir.ptr) path else try std.fs.path.relativePosix(arena, "/", dir, text.path); + var lines: std.ArrayList([]const u8) = .empty; + var split = std.mem.splitScalar(u8, text.bytes, '\n'); + while (split.next()) |line| try lines.append(arena, std.mem.trimEnd(u8, line, "\r")); + memo.lines = lines.items; + var hit = p.locations_cache.get(p.tree_sitter_gpa, text.path, text.bytes, true, false) catch + locations.Cache.Hit{ .analysis = syntax.analyzeSource(arena, text.path, text.bytes, true, false) catch .{} }; + defer hit.deinit(p.tree_sitter_gpa); + // The cache's may go at its next use: kept for the section. + memo.declarations = try arena.dupe(syntax.ContextDeclaration, hit.analysis.declarations); + return; + } + base = std.fs.path.dirname(base) orelse return; + } +} + +/// Which side of the hunk the file on disk holds, the new one (the patch +/// applied) or the old one, and how far the file has moved it from where +/// the hunk says (`shift`, lines), as patch finds a hunk in a file edited +/// since. A file edited inside the hunk too still holds most of its lines: +/// the place holding the most of them wins (the nearer on a tie) if it +/// holds at least half. Only some, at the nearest place, could be a sibling +/// with the same lines (two functions with one signature's tail). The rows +/// are counted on that side, so moved. +const Side = enum { new, old, neither }; +const OnDisk = struct { side: Side, shift: i64 = 0 }; + +/// ponytail: a hunk moved more than this many lines is not looked for; +/// each try compares the hunk's lines, so a wider search costs that more. +const max_shift = 200; + +fn sideOnDisk(memo: *const SourceMemo, hunk: *const Hunk) OnDisk { + if (memo.shown == null) return .{ .side = .neither }; + var best: OnDisk = .{ .side = .neither }; + var best_held: usize = 0; + var best_of: usize = 1; + var shift: i64 = 0; + while (shift <= max_shift) : (shift += 1) { + for ([2]i64{ shift, -shift }) |by| { + inline for (.{ Side.new, Side.old }) |side| { + const start: i64 = @as(i64, @intCast((if (side == .new) hunk.new_start else hunk.old_start) -| 1)) + by; + if (start >= 0) { + const got = heldAt(memo, hunk, side, @intCast(start)); + if (got.held == got.of) return .{ .side = side, .shift = by }; + // A larger share only: the nearer keeps a tie. + if (got.held * best_of > best_held * got.of) { + best = .{ .side = side, .shift = by }; + best_held = got.held; + best_of = got.of; + } + } + } + if (shift == 0) break; + } + } + return if (best_held > 0 and best_held * 2 >= best_of) best else .{ .side = .neither }; +} + +/// How many of the hunk's `side` lines the file holds from row `start` on, +/// of how many: blank lines, which match anywhere, count for neither. +fn heldAt(memo: *const SourceMemo, hunk: *const Hunk, comptime side: Side, start: usize) struct { held: usize, of: usize } { + var row = start; + var held: usize = 0; + var of: usize = 0; + for (hunk.lines.items) |line| { + const skipped = if (side == .new) line.kind == .removed else line.kind == .added; + if (skipped) continue; + defer row += 1; + if (std.mem.trim(u8, line.code, " \t").len == 0) continue; + of += 1; + if (row < memo.lines.len and std.mem.eql(u8, memo.lines[row], line.code)) held += 1; + } + return .{ .held = held, .of = @max(of, 1) }; +} + +fn flush(out: *Out, hunk: *Hunk, memo: *SourceMemo, dir: []const u8) !void { + defer hunk.* = .{}; + if (hunk.path.len == 0 or hunk.lines.items.len == 0) return; + const p = out.p; + const arena = p.scratch.allocator(); + try findSource(p, memo, dir, hunk.path); + const disk = sideOnDisk(memo, hunk); + const side = disk.side; + // A line number of the hunk's, where the file has it now. + const moved = struct { + fn by(n: usize, shift: i64) usize { + return @intCast(@max(0, @as(i64, @intCast(n)) + shift)); + } + }.by; + const shown = if (side == .neither) hunk.path else memo.shown.?; + const lines = hunk.lines.items; + + // Where the hunk changes something, on the side its rows count: the + // place its label opens. + const first_change = for (lines) |line| { + if (line.kind != .context) break line; + } else lines[0]; + const on_old = side == .old or (side == .neither and hunk.deleted); + const start_row = moved(if (on_old) hunk.old_start else hunk.new_start, disk.shift) -| 1; + const change_row = moved(if (on_old) first_change.old else first_change.new, disk.shift) -| 1; + + // The declarations it stands in, outermost first, as a result's + // tree-sitter context: each one's header rows above the hunk. + var depth: usize = 0; + if (side != .neither) for (memo.declarations) |declaration| { + if (declaration.start_line >= start_row) break; + if (declaration.end_line < change_row) continue; + depth += 1; + var row = declaration.start_line; + while (row <= declaration.header_end_line and row < start_row) : (row += 1) { + const at: @FieldType(Row, "at") = .{ .line = row + 1 }; + if (row == declaration.start_line and p.locations_config.tslocations) { + const label = try std.fmt.allocPrint(arena, "{s}:{d}", .{ shown, row + 1 }); + try out.row(label, shown, .{ .kind = .context, .declaration = true, .at = at, .location_end = label.len, .code_start = label.len }); + } + // A blank where a hunk line has its marker: the code aligns. + try out.row(try std.fmt.allocPrint(arena, " {s}", .{memo.lines[row]}), shown, .{ .kind = .context, .declaration = true, .at = at }); + } + }; + + // The hunk's label: a step for n and N, and a look's place. + const line_no = change_row + 1; + var label: std.Io.Writer.Allocating = .init(arena); + try label.writer.print("{s}:{d}", .{ shown, line_no }); + const location_end = label.written().len; + if (depth > 0) { + try label.writer.writeByte(' '); + try label.writer.splatByteAll('*', depth); + } + try out.row(label.written(), shown, .{ .kind = .match, .at = .{ .line = line_no }, .location_end = location_end, .code_start = label.written().len }); + // No file to read declarations from: git's own function line, muted + // the same way. With one, git's guess (the last line before the hunk + // that looked like a function) would only contradict it. + if (side == .neither and hunk.header.len > 0) + try out.row(try std.fmt.allocPrint(arena, " {s}", .{hunk.header}), shown, .{ .kind = .context, .declaration = true, .at = .{ .line = line_no } }); + + // Each run of removed lines and the added lines after it: the words + // they changed. + var i: usize = 0; + while (i < lines.len) { + if (lines[i].kind == .context) { + i += 1; + continue; + } + const minus_start = i; + while (i < lines.len and lines[i].kind == .removed) i += 1; + const plus_start = i; + while (i < lines.len and lines[i].kind == .added) i += 1; + try inferEdits(arena, lines[minus_start..plus_start], lines[plus_start..i]); + } + + // Each line behind its marker, `+`, `-` or a blank, as the diff + // has it: the marker coloured, the line as its file's. + for (lines) |line| { + const flag: u8 = switch (line.kind) { + .added => syntax.diff_added, + .removed => syntax.diff_removed, + else => 0, + } | @as(u8, if (line.kind != .context and !line.paired) syntax.diff_whole else 0); + const text = try std.fmt.allocPrint(arena, "{c}{s}", .{ @as(u8, switch (line.kind) { + .added => '+', + .removed => '-', + else => ' ', + }), line.code }); + const colors = try arena.alloc(u8, text.len); + colors[0] = flag; + @memcpy(colors[1..], line.styles); + const on = moved(if (on_old) line.old else line.new, disk.shift); + try out.row(text, shown, .{ .kind = .preview, .at = .{ .line = @max(1, on) }, .colors = colors }); + } +} + +// ---- the words a changed line changed (delta's edits.rs) ---- + +/// delta's `max-line-distance`: a removed and an added line further apart +/// than this are not one line changed, and neither is emphasised. +const max_line_distance = 0.6; + +/// ponytail: a run of more removed or added lines than this, or a pair +/// whose token table is bigger than `max_cells`, is shown unemphasised +/// rather than aligned at a quadratic cost (delta aligns them all). +const max_run = 256; +const max_cells = 1 << 16; + +/// Pair each removed line with the first added line after the last one +/// paired that is near enough to it, in order, and emphasise in both the +/// tokens one has and the other has not. +fn inferEdits(arena: std.mem.Allocator, minus: []HunkLine, plus: []HunkLine) !void { + if (minus.len == 0 or plus.len == 0 or minus.len > max_run or plus.len > max_run) return; + var plus_index: usize = 0; + for (minus) |*m| { + const m_tokens = try tokenize(arena, m.code); + var j = plus_index; + while (j < plus.len) : (j += 1) { + const p_tokens = try tokenize(arena, plus[j].code); + if ((m_tokens.len + 1) * (p_tokens.len + 1) > max_cells) continue; + var alignment = try Alignment.init(arena, m_tokens, p_tokens); + const marks = try annotate(arena, &alignment, m.code, plus[j].code); + if (marks.distance > max_line_distance) continue; + for (marks.minus) |r| for (m.styles[r[0]..r[1]]) |*b| { + b.* |= syntax.diff_emph; + }; + for (marks.plus) |r| for (plus[j].styles[r[0]..r[1]]) |*b| { + b.* |= syntax.diff_emph; + }; + m.paired = true; + plus[j].paired = true; + plus_index = j + 1; + break; + } + } +} + +/// delta's tokenize with its default `\w+`: a leading empty token, each +/// run of word characters one token, and every other character one. A +/// line starting with no word gets a second empty token, as delta's does. +/// ponytail: any byte past ASCII counts as a word character, close to +/// Unicode `\w` for letters; a non-ASCII punctuation mark joins a word. +fn tokenize(arena: std.mem.Allocator, line: []const u8) ![]const []const u8 { + var tokens: std.ArrayList([]const u8) = .empty; + try tokens.append(arena, ""); + if (line.len > 0 and !isWord(line[0])) try tokens.append(arena, ""); + var at: usize = 0; + while (at < line.len) { + var end = at + 1; + // A byte past ASCII is a word's, so what is left is one byte. + if (isWord(line[at])) while (end < line.len and isWord(line[end])) { + end += 1; + }; + try tokens.append(arena, line[at..end]); + at = end; + } + return tokens.items; +} + +fn isWord(c: u8) bool { + return std.ascii.isAlphanumeric(c) or c == '_' or c >= 0x80; +} + +const Op = enum(u2) { noop, deletion, insertion }; + +/// delta's align.rs: a Needleman-Wunsch table over two token lists, a +/// change costing more where it starts a new run, so changes group. +const Alignment = struct { + x: []const []const u8, + y: []const []const u8, + cells: []Cell, + width: usize, + + const Cell = struct { parent: u32, op: Op, cost: u32 }; + const deletion_cost = 2; + const insertion_cost = 2; + const initial_mismatch_penalty = 1; + const never = std.math.maxInt(u32); + + fn init(arena: std.mem.Allocator, x: []const []const u8, y: []const []const u8) !Alignment { + const width = x.len + 1; + const cells = try arena.alloc(Cell, width * (y.len + 1)); + @memset(cells, .{ .parent = 0, .op = .noop, .cost = 0 }); + var a: Alignment = .{ .x = x, .y = y, .cells = cells, .width = width }; + for (1..width) |i| cells[i] = .{ .parent = 0, .op = .deletion, .cost = @intCast(i * deletion_cost + initial_mismatch_penalty) }; + for (1..y.len + 1) |j| cells[j * width] = .{ .parent = 0, .op = .insertion, .cost = @intCast(j * insertion_cost + initial_mismatch_penalty) }; + for (x, 0..) |x_i, i| for (y, 0..) |y_j, j| { + const left = a.index(i, j + 1); + const diag = a.index(i, j); + const up = a.index(i + 1, j); + // Ties go to the first: an insertion, then a deletion, then a + // match, so a moved token reads as removed then added. + const candidates = [3]Cell{ + .{ .parent = @intCast(up), .op = .insertion, .cost = a.mismatchCost(up, insertion_cost) }, + .{ .parent = @intCast(left), .op = .deletion, .cost = a.mismatchCost(left, deletion_cost) }, + .{ .parent = @intCast(diag), .op = .noop, .cost = if (std.mem.eql(u8, x_i, y_j)) cells[diag].cost else never }, + }; + var best = candidates[0]; + for (candidates[1..]) |c| if (c.cost < best.cost) { + best = c; + }; + cells[a.index(i + 1, j + 1)] = best; + }; + return a; + } + + fn mismatchCost(a: *const Alignment, parent: usize, basic: u32) u32 { + const cell = a.cells[parent]; + return cell.cost +| basic +| @as(u32, if (cell.op == .noop) initial_mismatch_penalty else 0); + } + + fn index(a: *const Alignment, i: usize, j: usize) usize { + return j * a.width + i; + } + + /// The operations read back from the table's far corner, in order, + /// each run as one (op, count). + fn coalesced(a: *const Alignment, arena: std.mem.Allocator) ![]const struct { Op, usize } { + var ops: std.ArrayList(Op) = .empty; + var cell = a.cells[a.index(a.x.len, a.y.len)]; + while (true) { + try ops.append(arena, cell.op); + if (cell.parent == 0) break; + cell = a.cells[cell.parent]; + } + std.mem.reverse(Op, ops.items); + var runs: std.ArrayList(struct { Op, usize }) = .empty; + for (ops.items) |op| { + if (runs.items.len > 0 and runs.items[runs.items.len - 1][0] == op) { + runs.items[runs.items.len - 1][1] += 1; + } else try runs.append(arena, .{ op, 1 }); + } + return runs.items; + } +}; + +const Marks = struct { + /// Byte ranges of the removed and the added line to emphasise. + minus: []const [2]usize, + plus: []const [2]usize, + distance: f64, +}; + +/// delta's annotate: walk the alignment's runs over both lines, marking +/// what each deleted and inserted, and a run of blanks between two changes +/// with them; the distance is the changed width over the whole width (a +/// kept section counting on both lines). +fn annotate(arena: std.mem.Allocator, a: *const Alignment, minus_line: []const u8, plus_line: []const u8) !Marks { + var minus: std.ArrayList([2]usize) = .empty; + var plus: std.ArrayList([2]usize) = .empty; + var x_off: usize = 0; + var y_off: usize = 0; + var m_byte: usize = 0; + var p_byte: usize = 0; + var numer: usize = 0; + var denom: usize = 0; + var minus_prev: Op = .noop; + var plus_prev: Op = .noop; + const Take = struct { + fn section(tokens: []const []const u8, off: *usize, byte: *usize, n: usize, line: []const u8) [2]usize { + const start = byte.*; + const end_tok = @min(tokens.len, off.* + n); + for (tokens[@min(off.*, end_tok)..end_tok]) |t| byte.* += t.len; + off.* = end_tok; + byte.* = @min(byte.*, line.len); + return .{ start, byte.* }; + } + }; + for (try a.coalesced(arena)) |run| { + const op, const n = run; + switch (op) { + .deletion => { + const r = Take.section(a.x, &x_off, &m_byte, n, minus_line); + const w = trimmedWidth(minus_line[r[0]..r[1]]); + numer += w; + denom += w; + try minus.append(arena, r); + minus_prev = .deletion; + }, + .noop => { + const r = Take.section(a.x, &x_off, &m_byte, n, minus_line); + const section = minus_line[r[0]..r[1]]; + denom += 2 * trimmedWidth(section); + const is_space = std.mem.trim(u8, section, " \t").len == 0; + const coalesce = is_space and + ((minus_prev == .deletion and plus_prev == .insertion and + (x_off < a.x.len -| 1 or y_off < a.y.len -| 1)) or + (minus_prev == .noop and plus_prev == .noop)); + if (coalesce and minus_prev == .deletion) try minus.append(arena, r); + const pr = Take.section(a.y, &y_off, &p_byte, n, plus_line); + if (coalesce and plus_prev == .insertion) try plus.append(arena, pr); + minus_prev = .noop; + plus_prev = .noop; + }, + .insertion => { + const r = Take.section(a.y, &y_off, &p_byte, n, plus_line); + const w = trimmedWidth(plus_line[r[0]..r[1]]); + numer += w; + denom += w; + try plus.append(arena, r); + plus_prev = .insertion; + }, + } + } + const distance: f64 = if (denom > 0) @as(f64, @floatFromInt(numer)) / @as(f64, @floatFromInt(denom)) else 0; + return .{ .minus = minus.items, .plus = plus.items, .distance = distance }; +} + +fn trimmedWidth(section: []const u8) usize { + return pardes.panes.File.displayWidth(std.mem.trim(u8, section, " \t")); +} + +// ---- tests ---- + +const testing = std.testing; + +fn emphasised(line: HunkLine) ![]const u8 { + var out: std.ArrayList(u8) = .empty; + for (line.code, line.styles) |c, s| try out.append(testing.allocator, if (s & syntax.diff_emph != 0) c else '.'); + return out.toOwnedSlice(testing.allocator); +} + +fn expectEmphasis(minus: []const u8, plus: []const u8, want_minus: []const u8, want_plus: []const u8) !void { + var arena_state: std.heap.ArenaAllocator = .init(testing.allocator); + defer arena_state.deinit(); + const arena = arena_state.allocator(); + var m = [_]HunkLine{.{ .kind = .removed, .code = minus, .styles = try arena.alloc(u8, minus.len), .old = 1, .new = 1 }}; + var p = [_]HunkLine{.{ .kind = .added, .code = plus, .styles = try arena.alloc(u8, plus.len), .old = 2, .new = 1 }}; + @memset(m[0].styles, 0); + @memset(p[0].styles, 0); + try inferEdits(arena, &m, &p); + const got_minus = try emphasised(m[0]); + defer testing.allocator.free(got_minus); + const got_plus = try emphasised(p[0]); + defer testing.allocator.free(got_plus); + try testing.expectEqualStrings(want_minus, got_minus); + try testing.expectEqualStrings(want_plus, got_plus); +} + +test "delta's emphasis: the word a line changed, in both lines" { + try expectEmphasis(" let x = foo(1);", " let x = bar(1);", "............foo....", "............bar...."); + try expectEmphasis("a b c", "a x c", "..b..", "..x.."); +} + +test "delta's emphasis: lines too far apart are no change of one another" { + try expectEmphasis("completely different text", "nothing alike here at all", ".........................", "........................."); +} + +test "delta's emphasis: a word added keeps the rest plain" { + try expectEmphasis("fn run(a: u32)", "fn run(a: u32, b: u32)", "..............", "............., b: u32."); +} + +test "delta's alignment: kitten to sitting, as align.rs has it" { + var arena_state: std.heap.ArenaAllocator = .init(testing.allocator); + defer arena_state.deinit(); + const arena = arena_state.allocator(); + // One token a letter, as delta's test splits them, behind the empty one. + const x = [_][]const u8{ "", "k", "i", "t", "t", "e", "n" }; + const y = [_][]const u8{ "", "s", "i", "t", "t", "i", "n", "g" }; + const a = try Alignment.init(arena, &x, &y); + var ops: std.ArrayList(Op) = .empty; + for (try a.coalesced(arena)) |run| for (0..run[1]) |_| try ops.append(arena, run[0]); + try testing.expectEqualSlices(Op, &.{ .noop, .deletion, .insertion, .noop, .noop, .noop, .deletion, .insertion, .noop, .insertion }, ops.items); +} + +test "a diff stacks to a label a hunk and its lines, markers gone, tinted and stepped" { + const p = try Pardes.init(testing.allocator, .{ .tty_only = true }); + defer p.deinit(); + const patch = + \\diff --git a/nowhere/x.txt b/nowhere/x.txt + \\--- a/nowhere/x.txt + \\+++ b/nowhere/x.txt + \\@@ -1,3 +1,3 @@ section one + \\ keep + \\-old value + \\+new value + \\ tail + \\ + ; + const result = try format(p, "/pardes-surely-missing-dir", patch); + defer p.gpa.free(result.content); + defer locations.freeRows(p.gpa, result.rows); + try testing.expectEqualStrings("nowhere/x.txt:2\n section one\n keep\n-old value\n+new value\n tail\n", result.content); + try testing.expectEqual(@as(usize, 6), result.rows.len); + try testing.expectEqual(.match, result.rows[0].kind); + try testing.expectEqual(@as(usize, "nowhere/x.txt:2".len), result.rows[0].location_end); + try testing.expect(result.rows[1].declaration); + const removed = result.rows[3]; + try testing.expect(removed.colors[0] & syntax.diff_removed != 0); + // Paired with the line it changed: no whole-line tint. + try testing.expect(removed.colors[0] & syntax.diff_whole == 0); + try testing.expect(removed.colors[1] & syntax.diff_emph != 0); + try testing.expect(removed.colors[5] & syntax.diff_emph == 0); + try testing.expect(result.rows[4].colors[0] & syntax.diff_added != 0); + try testing.expect(result.rows[2].colors[0] & (syntax.diff_added | syntax.diff_removed) == 0); +} + +test "a hunk the file has moved since is found where it went, inside its declaration" { + if (!syntax.supportsPath("a.zig")) return error.SkipZigTest; + const p = try Pardes.init(testing.allocator, .{ .tty_only = true }); + defer p.deinit(); + var tmp = testing.tmpDir(.{}); + defer tmp.cleanup(); + // Two lines more above it than the patch knows of. + try tmp.dir.writeFile(testing.io, .{ .sub_path = "a.zig", .data = "// one\n// two\nconst S = struct {\n fn f() void {\n a();\n b();\n }\n};\n" }); + var buf: [std.fs.max_path_bytes]u8 = undefined; + const dir = buf[0..try tmp.dir.realPath(testing.io, &buf)]; + const patch = + \\--- a.zig + \\+++ a.zig + \\@@ -3,3 +3,3 @@ git's guess + \\ fn f() void { + \\- c(); + \\+ a(); + \\ b(); + \\ + ; + const result = try format(p, dir, patch); + defer p.gpa.free(result.content); + defer locations.freeRows(p.gpa, result.rows); + try testing.expect(std.mem.indexOf(u8, result.content, "a.zig:3\n const S = struct {\na.zig:5 *\n") != null); + try testing.expect(std.mem.indexOf(u8, result.content, "git's guess") == null); +} + +test "a mailed patch keeps its headers, message and diffstat above its hunks" { + const p = try Pardes.init(testing.allocator, .{ .tty_only = true }); + defer p.deinit(); + const patch = + \\From 0123 Mon Sep 17 00:00:00 2001 + \\Subject: [PATCH] change x + \\ + \\Why it changed. + \\--- + \\ x.txt | 2 +- + \\ + \\diff --git a/x.txt b/x.txt + \\index 1..2 100644 + \\--- a/x.txt + \\+++ b/x.txt + \\@@ -1 +1 @@ + \\-a + \\+b + \\ + ; + const result = try format(p, "/pardes-surely-missing-dir", patch); + defer p.gpa.free(result.content); + defer locations.freeRows(p.gpa, result.rows); + try testing.expectEqualStrings("From 0123 Mon Sep 17 00:00:00 2001\nSubject: [PATCH] change x\n\nWhy it changed.\n---\n x.txt | 2 +-\n\nx.txt:1\n-a\n+b\n", result.content); +} + +test "DiffLook hunks: a .patch looked at opens its +Diff; Diff goes to the text and back; DiffLook text opens the text" { + const p = try Pardes.init(testing.allocator, .{ .tty_only = true }); + defer p.deinit(); + var tmp = testing.tmpDir(.{}); + defer tmp.cleanup(); + try tmp.dir.writeFile(testing.io, .{ .sub_path = "x.txt", .data = "b\n" }); + try tmp.dir.writeFile(testing.io, .{ .sub_path = "c.patch", .data = "--- x.txt\n+++ x.txt\n@@ -1 +1 @@\n-a\n+b\n" }); + var buf: [std.fs.max_path_bytes]u8 = undefined; + const dir = buf[0..try tmp.dir.realPath(testing.io, &buf)]; + const patch = try std.fs.path.join(testing.allocator, &.{ dir, "c.patch" }); + defer testing.allocator.free(patch); + const hunks_path = try std.fs.path.join(testing.allocator, &.{ dir, "+Diff" }); + defer testing.allocator.free(hunks_path); + const Count = struct { + fn of(pp: *Pardes, path: []const u8) usize { + var n: usize = 0; + for (pp.panes) |slot| if (slot) |pane| if (pane.file) |f| { + n += @intFromBool(std.mem.eql(u8, f.path, path)); + }; + return n; + } + }; + try testing.expectEqual(pardes.config.Runtime.DiffLook.hunks, p.settings.diff_look); + pardes.look.lookAt(p, 0, patch); + try testing.expectEqual(@as(usize, 1), Count.of(p, hunks_path)); + try testing.expectEqual(@as(usize, 0), Count.of(p, patch)); + const hid = p.active; + try testing.expectEqualStrings(hunks_path, p.panes[hid].?.file.?.path); + try testing.expectEqualStrings("x.txt:1\n-a\n+b\n", p.panes[hid].?.file.?.content); + // Diff on it: the patch as text. + try testing.expect(p.executeBuiltinLine(hid, "Diff")); + try testing.expectEqual(@as(usize, 1), Count.of(p, patch)); + const raw = p.active; + try testing.expectEqualStrings(patch, p.panes[raw].?.file.?.path); + // Diff on the text: the +Diff again, refilled, not another. + try testing.expect(p.executeBuiltinLine(raw, "Diff")); + try testing.expectEqual(@as(usize, 1), Count.of(p, hunks_path)); + // DiffLook text: a look opens the text (here the pane already open). + try testing.expect(p.executeBuiltinLine(0, "DiffLook text")); + try p.removePane(raw, null); + pardes.look.lookAt(p, 0, patch); + try testing.expectEqual(@as(usize, 1), Count.of(p, patch)); +} + +test "a hunk edited since, beside siblings with its signature's tail, is found in its own function" { + if (!syntax.supportsPath("a.rs")) return error.SkipZigTest; + const p = try Pardes.init(testing.allocator, .{ .tty_only = true }); + defer p.deinit(); + var tmp = testing.tmpDir(.{}); + defer tmp.cleanup(); + // Three functions ending in one signature's tail; the patch is for the + // third, which has moved down a line and had a line inside it edited. + try tmp.dir.writeFile(testing.io, .{ .sub_path = "a.rs", .data = + \\// moved + \\fn one( + \\ limit: usize, + \\) -> u32 { + \\ 1 + \\} + \\fn two( + \\ limit: usize, + \\) -> u32 { + \\ 2 + \\} + \\fn three( + \\ limit: usize, + \\) -> u32 { + \\ let guard = enter(); + \\ let a = 3; + \\ let b = a + 1; + \\ let c = b * 2; // edited since + \\ c + \\} + \\ + }); + var buf: [std.fs.max_path_bytes]u8 = undefined; + const dir = buf[0..try tmp.dir.realPath(testing.io, &buf)]; + const patch = + \\--- a.rs + \\+++ a.rs + \\@@ -12,7 +12,8 @@ git's guess + \\ limit: usize, + \\ ) -> u32 { + \\+ let guard = enter(); + \\ let a = 3; + \\ let b = a + 1; + \\ let c = b * 2; + \\ c + \\ + ; + const result = try format(p, dir, patch); + defer p.gpa.free(result.content); + defer locations.freeRows(p.gpa, result.rows); + try testing.expect(std.mem.indexOf(u8, result.content, "a.rs:12\n fn three(\na.rs:15 *\n") != null); +} diff --git a/src/locations.zig b/src/locations.zig index 6a604907..7755f6fd 100644 --- a/src/locations.zig +++ b/src/locations.zig @@ -159,7 +159,9 @@ const Pending = struct { const Source = struct { path: []const u8, bytes: []const u8 }; -fn sourceText(p: *pardes.Pardes, arena: std.mem.Allocator, dir: []const u8, path: []const u8) ?Source { +/// A file's text as a look from `dir` finds it: an open pane's, unsaved +/// edits and all, else the disk's. Null for a PDF or one not there. +pub fn sourceText(p: *pardes.Pardes, arena: std.mem.Allocator, dir: []const u8, path: []const u8) ?Source { if (std.ascii.eqlIgnoreCase(std.fs.path.extension(path), ".pdf")) return null; const lexical = std.fs.path.resolvePosix(arena, &.{ dir, path }) catch return null; var pathbuf: [4096]u8 = undefined; diff --git a/src/look.zig b/src/look.zig index 41cfdc0c..6ba6a8d0 100644 --- a/src/look.zig +++ b/src/look.zig @@ -1869,6 +1869,18 @@ pub fn lookAt(p: *Pardes, id: usize, operand_raw: []const u8) void { const before = p.active; var opened: ?usize = null; if (!focusPaneByPath(p, target.path, target.at)) { + // A .diff or .patch looked at bare: its hunks stacked in a + // +Diff (DiffLook hunks), which takes the keyboard as the + // file would; one with none in it opens as text. + if (p.settings.diff_look == .hunks and !p.look_text and target.at.line == 0 and + (std.mem.endsWith(u8, target.path, ".diff") or std.mem.endsWith(u8, target.path, ".patch"))) + if (filesystem.read(p, target.path)) |bytes| { + defer p.gpa.free(bytes); + if (panes.Output.openDiff(p, id, target.path, bytes)) |hid| { + p.active = hid; + return; + } else |_| {} + } else |_| {}; const free = p.freeSlot() orelse return p.reportError(id, "look", error.NoPaneSlots); const nt = panes.File.open(p, free, target.path, target.at.line) catch |err| return lookOpenFailed(p, id, target.path, err); diff --git a/src/main.zig b/src/main.zig index ed70b624..26259b43 100644 --- a/src/main.zig +++ b/src/main.zig @@ -102,7 +102,7 @@ const help_text = ; /// `pardes -` inside a session: `text`, stdin as it came, escapes and all, -/// into the directory's one +Pager (/pager, refilled when it is there): +/// into a new +Pager of the directory (/pager): /// written after the directory on that one open, the session parses it /// (pager.zig) and puts it in as one undo step, left clean. A text the /// session would not take is never lost: it goes to stderr, a terminal, diff --git a/src/mouse.zig b/src/mouse.zig index 8020fda8..733479dd 100644 --- a/src/mouse.zig +++ b/src/mouse.zig @@ -1288,7 +1288,7 @@ fn dragRelease(p: *Pardes, button: Mouse.Button) void { pane.sel[sel_slot].state = .none; pane.body.vsel = .{ .active = true, .row = @intCast(a.row), .col = @intCast(a.col), .explicit = true }; }; - if (s.ctrl) p.lspRequest(s.id, .definition, ""); + if (s.ctrl) exec.runBuiltin(p, .Def, s.id, "", null); } } else { const clk = pane.sel[b]; diff --git a/src/ninep/ctl.zig b/src/ninep/ctl.zig index c9ce41e1..e6e738a5 100644 --- a/src/ninep/ctl.zig +++ b/src/ninep/ctl.zig @@ -682,7 +682,7 @@ pub fn readRoot(p: *Pardes, req: Req) Reply { } /// /pager, `pardes -`'s: the directory written (empty, or not absolute: the -/// session's) gets its one +Pager, made or emptied; the serial is what a +/// session's) gets a new +Pager; the serial is what a /// read of this same open answers, never another client's. What the open /// writes after that line is the text, held by tree.zig for `fillPager`. pub fn writePager(p: *Pardes, req: Req) Reply { @@ -742,6 +742,16 @@ pub fn fillPager(p: *Pardes, serial: u32, held: *std.ArrayList(u8)) error{OutOfM panes.File.setContent(p, f, page.text); f.pager_spans = page.spans; f.saved_revision = f.revision; + // A diff paged (`git show`, difftui's patches): its hunks stacked in a + // +Diff (DiffLook hunks), the +Pager folded to its tag under it for + // Diff to bring back. The keyboard stays where it was, as a page's. + if (f.pager_diff and p.settings.diff_look == .hunks) { + const keyboard = p.active; + if (panes.Output.openDiff(p, id, f.path, f.content)) |_| { + if (!pane.collapsed) pardes.layout.toggleCollapse(p, id); + } else |_| {} + if (p.panes[keyboard] != null) p.active = keyboard; + } } /// The editor's step: the text of /pager opens closed unread goes in. @@ -2258,7 +2268,8 @@ test "a builtin for one kind of pane is refused on another, and still acts on it .{ "Petscii\n", "Petscii: only an image or a terminal pane takes it" }, .{ "Palette\n", "Palette: only an image pane takes it" }, .{ "Ascii\n", "Ascii: only an image pane takes it" }, - .{ "Filter\n", "Filter: only a terminal pane takes it" }, + .{ "Filter\n", "Filter: only a terminal or a +Pager pane takes it" }, + .{ "Diff\n", "Diff: only a diff or a +Diff pane takes it" }, .{ "Togglettymode\n", "Togglettymode: only a terminal pane takes it" }, }; for (cases) |case| { @@ -4607,10 +4618,15 @@ test "pager answers its +Pager on the open that asked, whatever another client e try testing.expectEqual(E.INVAL, call(p, .{ .tag = 8, .op = .write, .node = pager, .handle = refused, .data = "relative\n" }).errno()); try testing.expectEqualStrings("", call(p, .{ .tag = 9, .op = .read, .node = pager, .handle = refused, .size = 64 }).bytes); _ = call(p, .{ .tag = 10, .op = .release, .node = pager, .handle = refused, .opened = true }); - // Resolved: `/tmp/../tmp/.` is /tmp's +Pager, the one made above. + // Resolved: `/tmp/../tmp/.` is /tmp, a +Pager of its own beside the + // one made above, which keeps its page. const resolved = call(p, .{ .tag = 11, .op = .open, .node = pager, .omode = 2 }).reply.handle; try testing.expectEqual(Status.ok, call(p, .{ .tag = 12, .op = .write, .node = pager, .handle = resolved, .data = "/tmp/../tmp/.\n" }).reply.status); - try testing.expectEqualStrings(want, call(p, .{ .tag = 13, .op = .read, .node = pager, .handle = resolved, .size = 64 }).bytes); + const second = call(p, .{ .tag = 13, .op = .read, .node = pager, .handle = resolved, .size = 64 }).bytes; + try testing.expect(!std.mem.eql(u8, want, second)); + const second_pane = p.panes[p.paneBySerial(try std.fmt.parseInt(u32, std.mem.trim(u8, second, "\n"), 10)).?].?; + try testing.expectEqualStrings("/tmp/+Pager", second_pane.file.?.path); + try testing.expect(p.paneBySerial(paged) != null); _ = call(p, .{ .tag = 14, .op = .release, .node = pager, .handle = resolved, .opened = true }); // One that may not be written is refused, permission denied. try testing.expectEqual(E.PERM, wr(p, pager, "/proc/1\n").errno()); @@ -4667,15 +4683,24 @@ test "what a /pager open writes after its directory is the text: plain in the bo // PagerColor off, and an open closed with no read: the same text, plain, // in at the editor's next step (a close through a mount never waits). p.settings.pager_color = false; + const kept = try testing.allocator.dupe(u8, f.content); + defer testing.allocator.free(kept); const shut = call(p, .{ .tag = 7, .op = .open, .node = pager, .omode = 1 }).reply.handle; try testing.expectEqual(Status.ok, call(p, .{ .tag = 8, .op = .write, .node = pager, .handle = shut, .data = "/tmp\n" }).reply.status); try testing.expectEqual(Status.ok, call(p, .{ .tag = 9, .op = .write, .node = pager, .handle = shut, .data = "\x1b[1;32mgreen\x1b[m\n" }).reply.status); _ = call(p, .{ .tag = 10, .op = .release, .node = pager, .handle = shut, .opened = true }); - try testing.expectEqualStrings("", f.content); + // A new +Pager: the first keeps its page. + try testing.expectEqualStrings(kept, f.content); + const next = for (p.panes) |slot| { + const other = slot orelse continue; + if (other == pn) continue; + if (other.file) |*of| if (std.mem.eql(u8, of.path, "/tmp/+Pager")) break of; + } else return error.NoPager; + try testing.expectEqualStrings("", next.content); fillClosedPagers(p); - try testing.expectEqualStrings("green\n", f.content); - try testing.expectEqual(@as(usize, 0), f.pager_spans.len); - try testing.expectEqual(f.revision, f.saved_revision); + try testing.expectEqualStrings("green\n", next.content); + try testing.expectEqual(@as(usize, 0), next.pager_spans.len); + try testing.expectEqual(next.revision, next.saved_revision); } test "a command pane an exec open was answered is leased to it while it stays open: another client's command gets a pane of its own" { diff --git a/src/ninep/tree.zig b/src/ninep/tree.zig index c78a1aa2..eedab43b 100644 --- a/src/ninep/tree.zig +++ b/src/ninep/tree.zig @@ -258,7 +258,7 @@ pub const TopFile = enum(u5) { /// The files opened lately, closed ones too, a line each: /// `open|closed `, most recent first. recent, - /// `pardes -`'s: a directory written, its +Pager made or emptied; a + /// `pardes -`'s: a directory written, a new +Pager made there; a /// read of the same open answers its serial. pager, diff --git a/src/normal.zig b/src/normal.zig index 93487e88..aec6b983 100644 --- a/src/normal.zig +++ b/src/normal.zig @@ -743,14 +743,15 @@ fn executeNormalAction(p: *Pardes, t: *Text, semantic: modal.Normal.Action) void .undo => return edit.doUndo(p, t), .redo => return edit.doRedo(p, t), }, - .lsp => |request| return p.lspRequest(p.active, switch (request) { - .definition => .definition, - .declaration => .declaration, - .type_definition => .type_definition, - .implementation => .implementation, - .references => .references, - .format => .format, - }, ""), + // gd and gr are the Def and Refs a tag shows, run as a click runs them. + .lsp => |request| return switch (request) { + .definition => exec.runBuiltin(p, .Def, p.active, "", null), + .references => exec.runBuiltin(p, .Refs, p.active, "", null), + .declaration => p.lspRequest(p.active, .declaration, ""), + .type_definition => p.lspRequest(p.active, .type_definition, ""), + .implementation => p.lspRequest(p.active, .implementation, ""), + .format => p.lspRequest(p.active, .format, ""), + }, .adjust_number => |delta| return edit.normalAdjustNumber(p, t, delta), .leader => if (p.macro.replaying == 0) { p.leader_on = true; diff --git a/src/pardes.zig b/src/pardes.zig index 2a74e441..29192c33 100644 --- a/src/pardes.zig +++ b/src/pardes.zig @@ -480,6 +480,7 @@ pub const Loc = struct { test { _ = @import("tagline.zig"); + _ = @import("hunks.zig"); _ = @import("builtins_json.zig"); _ = @import("exec.zig"); _ = @import("look.zig"); @@ -864,7 +865,7 @@ test "TreeContext command and custom tag survive a workspace round trip" { p.gpa.free(pane.file.?.path); pane.file.?.path = path; if (!panes.File.supportsContext(pane)) return error.SkipZigTest; - try std.testing.expectEqualStrings(tagline.context_pane_tail, tagline.curTail(pane)); + try std.testing.expectEqualStrings(if (lsp.speaks("/test.zig")) tagline.lsp_context_pane_tail else tagline.context_pane_tail, tagline.curTail(pane)); try std.testing.expect(!pane.file.?.tree_context); try std.testing.expect(p.executeBuiltinLine(0, "TreeContext on")); try std.testing.expect(pane.file.?.tree_context); @@ -920,7 +921,7 @@ test "Togglettymode builtin and keyboard chord share mode transitions including try std.testing.expectEqualStrings("unchanged\n", file.file.?.content); } -test "Filter is ordered after Del and toggles only its terminal pane" { +test "Filter is ordered after Del and toggles only its terminal or +Pager pane" { const testing = std.testing; const del = std.meta.stringToEnum(Builtin, "Del") orelse return error.MissingDelBuiltin; const filter = std.meta.stringToEnum(Builtin, "Filter") orelse return error.MissingFilterBuiltin; @@ -954,6 +955,17 @@ test "Filter is ordered after Del and toggles only its terminal pane" { try testing.expect(p.executeBuiltinLine(0, "Filter")); try testing.expect(first.tty_filter); try testing.expect(!second.tty_filter); + + // A +Pager opens filtered, with Filter on its tag and no line numbers; + // a second is a pane of its own. + const pager_id = try panes.Output.openPager(p, 0, "/tmp"); + const pager_pane = p.panes[pager_id].?; + try testing.expect(pager_pane.tty_filter); + try testing.expectEqualStrings(tagline.pager_pane_tail, tagline.curTail(pager_pane)); + try testing.expectEqual(@as(u16, 0), panes.File.gutterWidth(pager_pane)); + try testing.expect(p.executeBuiltinLine(pager_id, "Filter")); + try testing.expect(!pager_pane.tty_filter); + try testing.expect(try panes.Output.openPager(p, 0, "/tmp") != pager_id); } test "compact tag commands stay beside their own prefix across layout changes" { @@ -1194,6 +1206,73 @@ test "Lspwhy after a Hover asks to explain that hover, in its file at its place, try std.testing.expect(seen); } +test "Def and Refs are a speaking file's tag words; gd, gr and a 2-1 chord all run them" { + if (!lsp.supports.contains(.definition)) return error.SkipZigTest; + const p = try Pardes.init(std.testing.allocator, .{ .cols = 100, .rows = 24, .tty_only = true }); + defer p.deinit(); + const pane = try p.setTestFile("const alpha = 1;\nconst beta = alpha;\n"); + // A .txt has no server: no Def, no Refs. + try std.testing.expect(std.mem.indexOf(u8, tagline.curTail(pane), "Def") == null); + const f = &pane.file.?; + p.gpa.free(f.path); + f.path = try p.gpa.dupe(u8, "/tmp/x.zig"); + try std.testing.expect(std.mem.endsWith(u8, tagline.curTail(pane), " Def Refs")); + p.sync(); + while (p.nextEffect()) |_| {} + const Asked = struct { + fn one(q: *Pardes, kind: lsp.Kind) !u32 { + var at: ?u32 = null; + while (q.nextEffect()) |e| if (e == .lsp) { + try std.testing.expectEqual(kind, e.lsp.kind); + try std.testing.expectEqualStrings("", e.lsp.arg.slice()); + try std.testing.expect(at == null); + at = e.lsp.offset; + }; + q.lsp_wait = null; + return at orelse error.NothingAsked; + } + }; + // gd and gr: at the cursor, on `alpha`'s declaration. + pane.body.cur_row = 0; + pane.body.cur_col = 8; + p.update(.{ .key = .{ .cp = 'g' } }); + p.update(.{ .key = .{ .cp = 'd' } }); + try std.testing.expectEqual(@as(u32, 8), try Asked.one(p, .definition)); + p.update(.{ .key = .{ .cp = 'g' } }); + p.update(.{ .key = .{ .cp = 'r' } }); + try std.testing.expectEqual(@as(u32, 8), try Asked.one(p, .references)); + + const r = p.rects[0]; + const x0 = r.x + config.GUTTER + panes.File.gutterWidth(pane); + const use_y = p.bodyTop(pane, r) + 1; + const tag = try tagline.tagText(p, p.scratch.allocator(), pane); + for ([_]struct { word: []const u8, kind: lsp.Kind }{ .{ .word = " Def ", .kind = .definition }, .{ .word = " Refs", .kind = .references } }) |w| { + // B1 sweeps the use of `alpha` on the second line (bytes 30..35), + // leaving the cursor at its far end. + p.update(.{ .mouse = .{ .button = config.select_button, .kind = .press, .col = x0 + 13, .row = use_y } }); + p.update(.{ .mouse = .{ .button = config.select_button, .kind = .drag, .col = x0 + 17, .row = use_y } }); + p.update(.{ .mouse = .{ .button = config.select_button, .kind = .release, .col = x0 + 17, .row = use_y } }); + // B2 on the tag word, B1 clicked while it is held: the sweep is its + // argument, and it asks at the start of `alpha`, not at the cursor. + const wx = r.x + TAG_TEXT_INSET + @as(u16, @intCast(std.mem.indexOf(u8, tag, w.word).? + 1)); + p.update(.{ .mouse = .{ .button = config.exec_button, .kind = .press, .col = wx, .row = r.y } }); + p.update(.{ .mouse = .{ .button = config.select_button, .kind = .press, .col = wx, .row = r.y } }); + p.update(.{ .mouse = .{ .button = config.select_button, .kind = .release, .col = wx, .row = r.y } }); + p.update(.{ .mouse = .{ .button = config.exec_button, .kind = .release, .col = wx, .row = r.y } }); + try std.testing.expectEqual(@as(u32, 30), try Asked.one(p, w.kind)); + // Clicked bare, it asks at the cursor, where the sweep left it. + pane.body.cur_row = 0; + pane.body.cur_col = 2; + p.update(.{ .mouse = .{ .button = config.exec_button, .kind = .press, .col = wx, .row = r.y } }); + p.update(.{ .mouse = .{ .button = config.exec_button, .kind = .release, .col = wx, .row = r.y } }); + try std.testing.expectEqual(@as(u32, 2), try Asked.one(p, w.kind)); + } + // A symbol the file does not hold is said, and nothing is asked. + exec.runBuiltin(p, .Def, 0, "", "gamma"); + try std.testing.expectError(error.NothingAsked, Asked.one(p, .definition)); + try std.testing.expectEqualStrings("Def: no gamma in this file", pane.msg[0..pane.msg_len]); +} + test "the Tutor pane is named +Tutor in the session's directory, never a bare path at the root" { const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true }); defer p.deinit(); @@ -4508,6 +4587,9 @@ pub const Pardes = struct { chord_hold: bool = false, /// The look just run found nothing (look.zig missed). look_missed: bool = false, + /// The look being run opens a .diff or .patch as text whatever DiffLook + /// says: Diff going back from a +Diff, Edit's B (it edits the file). + look_text: bool = false, look_hover_wait: ?look.LookHoverWait = null, /// The place a look-hover last found nothing to open: the pointer /// resting there does not ask again every frame (look.noteLookHover). @@ -4748,6 +4830,8 @@ pub const Pardes = struct { const named = try std.fs.path.join(gpa, &.{ dir, "+Pager" }); gpa.free(shown.file.?.path); shown.file.?.path = named; + shown.file.?.pager = true; + shown.tty_filter = true; shown.file.?.pager_diff = panes.File.looksLikeDiff(content[0..@min(content.len, 64 * 1024)]); shown.file.?.pager_spans = page.spans; p.oneColumn(); @@ -6674,7 +6758,8 @@ pub const Pardes = struct { pub const SavePath = Effect.Buf(effect_path_cap); - pub fn lspRequest(p: *Pardes, asked: usize, kind: lsp.Kind, arg: []const u8) void { + pub fn lspRequest(p: *Pardes, asked: usize, kind: lsp.Kind, arg_in: []const u8) void { + var arg = arg_in; if (!normal.multiOnce(p)) return; // one question per keystroke, from the primary // Lspwhy narrates the last query where it was asked -- that pane's // file, place and argument -- from wherever it is run. @@ -6697,10 +6782,30 @@ pub const Pardes = struct { (!zig_buf and std.mem.indexOfAny(u8, arg, " \t\r\n\"\\") != null)) return p.reportFailure(id, std.fmt.bufPrint(&said, "Rename: {s} is no name", .{arg}) catch "Rename: no name"); } - const off = if (pane.file) |f| modal.offsetAt(f.content, .{ + var off = if (pane.file) |f| modal.offsetAt(f.content, .{ .row = @intCast(@max(0, pane.body.cur_row)), .col = @intCast(@max(0, pane.body.cur_col)), }) else 0; + // Def or Refs given a symbol (a 2-1 chord's selection) asks at its + // occurrence nearest the cursor, which a sweep leaves at one end of + // what it selected; the server is asked at a place, never a name. + if ((kind == .definition or kind == .references) and arg.len > 0) { + const content = pane.file.?.content; + var nearest: ?usize = null; + var best: usize = 0; + var from: usize = 0; + while (std.mem.indexOfPos(u8, content, from, arg)) |at_hit| : (from = at_hit + 1) { + const d = if (at_hit > off) at_hit - off else off -| (at_hit + arg.len); + if (nearest != null and at_hit > off and d >= best) break; + if (nearest == null or d < best) { + nearest = at_hit; + best = d; + } + } + off = nearest orelse + return p.reportFailure(id, std.fmt.bufPrint(&said, "{s}: no {s} in this file", .{ lspWord(kind), arg }) catch "no such symbol in this file"); + arg = ""; + } // Lspwhy asks the last query again, narrated: its kind and argument, // at its place when asked from its pane. None yet: a definition. var explained: [160]u8 = undefined; @@ -6858,6 +6963,8 @@ pub const Pardes = struct { fn lspWord(kind: lsp.Kind) []const u8 { return switch (kind) { .hover => "Hover", + .definition => "Def", + .references => "Refs", .explain => "Lspwhy", .incoming_calls => "Callers", .outgoing_calls => "Callees", diff --git a/src/syntax.zig b/src/syntax.zig index b7406b04..89d96239 100644 --- a/src/syntax.zig +++ b/src/syntax.zig @@ -854,7 +854,13 @@ pub fn highlightLocationRows(gpa: std.mem.Allocator, content: []const u8, rows: if (comptime @hasField(@TypeOf(row), "location_end")) { address_only = row.location_end > 0 and source_start == end; } - if (!address_only) { + // A row its producer coloured whole is coloured below: no + // fragment of it to parse. + var coloured = false; + if (comptime @hasField(@TypeOf(row), "colors")) { + coloured = row.colors.len > 0 and row.colors.len >= end - source_start; + } + if (!address_only and !coloured) { sources[source_count] = .{ .index = index, .start = source_start, .len = end - source_start }; source_count += 1; } @@ -1037,10 +1043,15 @@ fn childOfKind(node: ts.Node, kind: []const u8) ?ts.Node { /// A diff line's style byte carries whether the line was added or removed /// over its syntax style (the low bits), so the painter can tint its row -/// and mark its prefix. +/// and mark its prefix; Diff marks the words a changed line changed +/// (hunks.zig), drawn on a stronger tint. pub const diff_added: u8 = 0x80; pub const diff_removed: u8 = 0x40; -pub const syn_bits: u8 = 0x3f; +pub const diff_emph: u8 = 0x20; +/// A +Diff line added or removed whole, paired with no line it changed: +/// its row takes a faint tint, on its marker's byte. +pub const diff_whole: u8 = 0x10; +pub const syn_bits: u8 = 0x0f; /// A file section's hunks are parsed together, each side as one text, in /// pieces: a piece takes whole hunks until it holds `diff_piece_lines` diff --git a/src/tagline.zig b/src/tagline.zig index d13f3c5f..cf0b17fd 100644 --- a/src/tagline.zig +++ b/src/tagline.zig @@ -21,6 +21,13 @@ pub const pdf_pane_tail = " " ++ config.pdf_pane_builtins_str; pub const file_pane_tail = " " ++ config.file_pane_builtins_str; pub const context_pane_tail = file_pane_tail ++ " TreeContext"; pub const locations_pane_tail = file_pane_tail ++ " LocationsConfig"; +/// A file a language server speaks for (by its extension): its jumps too. +pub const lsp_pane_tail = file_pane_tail ++ " " ++ config.lsp_pane_builtins_str; +pub const lsp_context_pane_tail = context_pane_tail ++ " " ++ config.lsp_pane_builtins_str; +pub const pager_pane_tail = " " ++ config.pager_pane_builtins_str; +pub const diff_pane_tail = " " ++ config.diff_pane_builtins_str; +pub const pager_diff_pane_tail = " " ++ config.pager_diff_pane_builtins_str; +pub const diff_view_tail = " " ++ config.diff_view_builtins_str ++ " LocationsConfig"; pub const terminal_pane_tail = " " ++ config.terminal_pane_builtins_str; pub const command_pane_tail = " " ++ config.command_pane_builtins_str; pub const dir_pane_tail = " " ++ config.dir_pane_builtins_str; @@ -164,10 +171,15 @@ pub fn curTail(pane: *Pane) []const u8 { pub fn defaultTail(pane: *const Pane) []const u8 { if (comptime pdf_enabled) if (pane.pdf != null) return pdf_pane_tail; if (pane.file) |file| if (file.listing != null) return dir_pane_tail; - if (pane.file) |file| if (file.output) |out| + if (pane.file) |file| if (file.pager) return if (file.pager_diff) pager_diff_pane_tail else pager_pane_tail; + if (pane.file != null and pane.colorAlgo() == .diff) return diff_pane_tail; + if (pane.file) |file| if (file.output) |out| { + if (std.meta.eql(out.from, panes.Output.Origin{ .cmd = .Diff })) return diff_view_tail; if (panes.Output.usesLocationsConfig(out.from)) return locations_pane_tail; - if (panes.File.supportsContext(pane)) return context_pane_tail; - if (pane.file != null) return file_pane_tail; + }; + const speaks = if (pane.file) |file| file.output == null and file.mini == null and pardes.lsp.speaks(file.path) else false; + if (panes.File.supportsContext(pane)) return if (speaks) lsp_context_pane_tail else context_pane_tail; + if (pane.file != null) return if (speaks) lsp_pane_tail else file_pane_tail; if (pane.command != null) return command_pane_tail; if (pane.isTerminal()) return if (pane.shell_tail_len > 0) pane.shell_tail[0..pane.shell_tail_len] else terminal_pane_tail; return pane_tail; diff --git a/src/terminal.zig b/src/terminal.zig index 3bb1fbda..3190c6e3 100644 --- a/src/terminal.zig +++ b/src/terminal.zig @@ -2041,7 +2041,7 @@ pub fn recolorAnsi(p: *Pardes, s: *Surface, pane: *Pane, r: pardes.Rect, tx: u16 const filtered: ?*FilteredColors = if (pane.tty_filter) blk: { const tz_filter = tracy.zone(@src(), "filterInit"); defer tz_filter.end(); - filtered_storage = FilteredColors.init(p, pane); + filtered_storage = FilteredColors.init(p, &pane.terminal.?.vt); break :blk &filtered_storage; } else null; // DECSCNM, read once: the filtered palette folds it in itself, the raw @@ -2192,7 +2192,9 @@ fn cellStyle(p: *Pardes, ci: ghostty_vt.PageList.Cell, filtered: ?*FilteredColor return cs; } -const FilteredColors = struct { +/// A program's colours mapped to the theme (Filter): a terminal's cells, or +/// a +Pager's spans (`vt` null, the program's palette xterm's own). +pub const FilteredColors = if (enabled) struct { source: GColor.Palette, target: *const GColor.Palette, theme_bg: GColor.RGB, @@ -2212,16 +2214,18 @@ const FilteredColors = struct { cache_key: [256]u8 = undefined, cache_valid: [256]bool = @splat(false), - fn init(p: *Pardes, pane: *const Pane) FilteredColors { + pub fn init(p: *Pardes, vt: ?*const ghostty_vt.Terminal) FilteredColors { var source = GColor.default; - for (&source, 0..) |*rgb, i| - rgb.* = pane.terminal.?.vt.colorForXterm(.{ .palette = @intCast(i) }) orelse rgb.*; + if (vt) |t| { + for (&source, 0..) |*rgb, i| + rgb.* = t.colorForXterm(.{ .palette = @intCast(i) }) orelse rgb.*; + } const theme = p.theme(); var theme_bg = asGhostRgb(theme.bg orelse theme.tag_bg); var theme_fg = asGhostRgb(theme.fg orelse theme.tag_fg); - var dynamic_bg = pane.terminal.?.vt.colorForXterm(.{ .dynamic = .background }); - var dynamic_fg = pane.terminal.?.vt.colorForXterm(.{ .dynamic = .foreground }); - if (pane.terminal.?.vt.modes.get(.reverse_colors)) { + var dynamic_bg = if (vt) |t| t.colorForXterm(.{ .dynamic = .background }) else null; + var dynamic_fg = if (vt) |t| t.colorForXterm(.{ .dynamic = .foreground }) else null; + if (vt != null and vt.?.modes.get(.reverse_colors)) { std.mem.swap(GColor.RGB, &theme_bg, &theme_fg); std.mem.swap(?GColor.RGB, &dynamic_bg, &dynamic_fg); } @@ -2280,6 +2284,18 @@ const FilteredColors = struct { return asPardesColor(self.keyedRgb(style.bg(cell, &self.source).?)); } + /// A +Pager span's colour (pager.zig), as `fg` and `bg` map a cell's. + pub fn spanColor(self: *FilteredColors, color: pardes.Color, is_bg: bool) pardes.Color { + return switch (color) { + .default => color, + .index => |idx| if (is_bg) self.bg_for_palette[idx] else self.fg_for_palette[idx], + .rgb => |rgb| blk: { + const keyed = self.keyedRgb(asGhostRgb(rgb)); + break :blk asPardesColor(if (is_bg) keyed else self.legible(keyed)); + }, + }; + } + fn legible(self: *const FilteredColors, rgb: GColor.RGB) GColor.RGB { if (contrastOf(luminanceOf(rgb), self.default_bg_luminance) >= config.tty_filter_min_contrast) return rgb; @@ -2317,7 +2333,7 @@ const FilteredColors = struct { self.cache_valid[slot] = true; return best; } -}; +} else struct {}; const channel_luminance: [256]f64 = blk: { @setEvalBranchQuota(20000); @@ -2570,7 +2586,7 @@ test "terminal Filter maps the default roles before it maps anything else" { // the null-page fallback that only the legacy dark theme exercises. for (0..9) |t| { p.settings.theme = @intCast(t); - const stage_one = FilteredColors.init(p, pane); + const stage_one = FilteredColors.init(p, &pane.terminal.?.vt); // `dark` declares no background of its own, which is exactly why the // resolver reads the tag colours as the fallback rather than `.?`. const theme = p.theme(); @@ -2584,7 +2600,7 @@ test "terminal Filter maps the default roles before it maps anything else" { p.settings.theme = 0; p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b]11;#5f5f5f\x1b\\" } }); - var moved = FilteredColors.init(p, pane); + var moved = FilteredColors.init(p, &pane.terminal.?.vt); try testing.expect(!moved.default_bg.eql(moved.theme_bg)); try testing.expect(moved.default_bg.eql(moved.keyedRgb(.{ .r = 0x5f, .g = 0x5f, .b = 0x5f }))); } @@ -2609,7 +2625,7 @@ test "terminal Filter refuses a foreground that would collapse onto the page" { for (0..9) |t| { p.settings.theme = @intCast(t); - var fc = FilteredColors.init(p, pane); + var fc = FilteredColors.init(p, &pane.terminal.?.vt); const page = asPardesColor(fc.default_bg); const rescued = asPardesColor(fc.fallback_fg); _ = frame.reset(.retain_capacity); @@ -2661,7 +2677,7 @@ test "terminal Filter holds every projected foreground off the page" { for (0..9) |t| { p.settings.theme = @intCast(t); - var fc = FilteredColors.init(p, pane); + var fc = FilteredColors.init(p, &pane.terminal.?.vt); var refused: usize = 0; for (fc.target, 0..) |projected, key| { const ink = fc.legible(projected); diff --git a/test/snapshots/diffview.golden b/test/snapshots/diffview.golden index 9e171fd8..868e5e85 100644 --- a/test/snapshots/diffview.golden +++ b/test/snapshots/diffview.golden @@ -1,7 +1,7 @@ == snap diff-pane grid=100x31 cursor=7,3 |Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol -| /tmp/pardes-snap/diffview/cwd/change.diff Save Tty Collapse Del +| /tmp/pardes-snap/diffview/cwd/change.diff Save Tty Diff Collapse Del | 1 diff --git a/src/shape.zig b/src/shape.zig | 2 index 1111111..2222222 100644 | 3 --- a/src/shape.zig @@ -55,7 +55,7 @@ |29: 0-0 d,#608269, 1-99 d,#0d1410, |30: 0-0 d,#608269, 1-99 d,#0d1410, == snap look-added-line grid=100x31 cursor=55,22 -|16: /tmp/pardes-snap/diffview/cwd/src/shape.zig Save Tty Collapse Del TreeContext +|16: /tmp/pardes-snap/diffview/cwd/src/shape.zig Save Tty Collapse Del TreeContext Def Refs |17: 1 const std = @import("std"); |18: 2 |19: 3 pub const Shape = union(enum) { @@ -134,7 +134,7 @@ |30: 0-0 d,#152019, 1-99 d,#0d1410, == snap command-look grid=100x31 cursor=23,10 |3: 1 cat change.diff -|5: /tmp/pardes-snap/diffview/cwd/src/shape.zig Save Tty Collapse Del TreeContext +|5: /tmp/pardes-snap/diffview/cwd/src/shape.zig Save Tty Collapse Del TreeContext Def Refs |6: 1 const std = @import("std"); |7: 2 |8: 3 pub const Shape = union(enum) { diff --git a/test/snapshots/lsp-client-edit.golden b/test/snapshots/lsp-client-edit.golden index c36d15be..c9d93379 100644 --- a/test/snapshots/lsp-client-edit.golden +++ b/test/snapshots/lsp-client-edit.golden @@ -1,7 +1,7 @@ == snap formatted grid=100x25 cursor=7,4 |Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol -| * /tmp/pardes-snap/lsp-client-edit/cwd/main.rs Save Tty Collapse Del TreeContext +| * /tmp/pardes-snap/lsp-client-edit/cwd/main.rs Save Tty Collapse Del TreeContext Def Refs | 1 // formatted by mock formatted 1 range(s) | 2 mod lib; | 3 @@ -12,7 +12,7 @@ | 8 } | 9 == snap unformatted grid=100x25 cursor=7,3 -|2: /tmp/pardes-snap/lsp-client-edit/cwd/main.rs Save Tty Collapse Del TreeContext +|2: /tmp/pardes-snap/lsp-client-edit/cwd/main.rs Save Tty Collapse Del TreeContext Def Refs |3: 1 mod lib; |4: 2 |5: 3 fn main() { @@ -23,12 +23,12 @@ |10: 8 |11: == snap renamed grid=100x25 cursor=12,5 -|2: * /tmp/pardes-snap/lsp-client-edit/cwd/main.rs Save Tty Collapse Del TreeContext +|2: * /tmp/pardes-snap/lsp-client-edit/cwd/main.rs Save Tty Collapse Del TreeContext Def Refs |3: 1 mod lib; renamed 2 range(s) |6: 4 let x = sum(1, 2); |7: 5 let y = sum(3, 4); == snap unrenamed grid=100x25 cursor=12,5 -|2: /tmp/pardes-snap/lsp-client-edit/cwd/main.rs Save Tty Collapse Del TreeContext +|2: /tmp/pardes-snap/lsp-client-edit/cwd/main.rs Save Tty Collapse Del TreeContext Def Refs |3: 1 mod lib; |6: 4 let x = add(1, 2); |7: 5 let y = add(3, 4); diff --git a/test/snapshots/lsp-client.golden b/test/snapshots/lsp-client.golden index 23d86e11..13771394 100644 --- a/test/snapshots/lsp-client.golden +++ b/test/snapshots/lsp-client.golden @@ -1,7 +1,7 @@ == snap gd-jumped grid=100x25 cursor=16,12 |Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol -| /tmp/pardes-snap/lsp-client/cwd/main.rs Save Tty Collapse Del TreeContext +| /tmp/pardes-snap/lsp-client/cwd/main.rs Save Tty Collapse Del TreeContext Def Refs | 1 mod lib; --:--:-- lsp rust-analyzer: ready | 2 | 3 fn main() { @@ -9,7 +9,7 @@ | 5 let y = add(3, 4); | 6 let _ = x + y; | 7 } -| /tmp/pardes-snap/lsp-client/cwd/lib.rs Save Tty Collapse Del TreeContext +| /tmp/pardes-snap/lsp-client/cwd/lib.rs Save Tty Collapse Del TreeContext Def Refs | 1 // mock fixture | 2 pub fn add(a: i32, b: i32) -> i32 { | 3 a + b diff --git a/test/snapshots/lsp-rename-files.golden b/test/snapshots/lsp-rename-files.golden index ea093dbf..4f71424e 100644 --- a/test/snapshots/lsp-rename-files.golden +++ b/test/snapshots/lsp-rename-files.golden @@ -1,12 +1,12 @@ == snap opened grid=100x25 cursor=7,8 |Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol -| /tmp/pardes-snap/lsp-rename-files/cwd/lib.rs Save Tty Collapse Del TreeContext +| /tmp/pardes-snap/lsp-rename-files/cwd/lib.rs Save Tty Collapse Del TreeContext Def Refs | 1 // main.rs | 2 pub fn add(a: i32, b: i32) -> i32 { | 3 a + b | 4 } -| /tmp/pardes-snap/lsp-rename-files/cwd/main.rs Save Tty Collapse Del TreeContext +| /tmp/pardes-snap/lsp-rename-files/cwd/main.rs Save Tty Collapse Del TreeContext Def Refs | 1 mod lib; | 2 | 3 fn main() { diff --git a/test/snapshots/lsp-rename.golden b/test/snapshots/lsp-rename.golden index ba19d8f0..6b85822c 100644 --- a/test/snapshots/lsp-rename.golden +++ b/test/snapshots/lsp-rename.golden @@ -1,7 +1,7 @@ == snap renamed grid=110x25 cursor=17,10 |Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol -| * /tmp/pardes-snap/lsp-rename/cwd/rename.zig Save Tty Collapse Del TreeContext +| * /tmp/pardes-snap/lsp-rename/cwd/rename.zig Save Tty Collapse Del TreeContext Def Refs | 1 const std = @import("std"); renamed 2 range(s) | 2 | 3 fn renamed_helper(x: u32) u32 { @@ -18,11 +18,11 @@ | 14 } | 15 == snap undone grid=110x25 cursor=17,10 -|2: /tmp/pardes-snap/lsp-rename/cwd/rename.zig Save Tty Collapse Del TreeContext +|2: /tmp/pardes-snap/lsp-rename/cwd/rename.zig Save Tty Collapse Del TreeContext Def Refs |3: 1 const std = @import("std"); |5: 3 fn helper(x: u32) u32 { |10: 8 _ = helper(41); == snap redone grid=110x25 cursor=17,10 -|2: * /tmp/pardes-snap/lsp-rename/cwd/rename.zig Save Tty Collapse Del TreeContext +|2: * /tmp/pardes-snap/lsp-rename/cwd/rename.zig Save Tty Collapse Del TreeContext Def Refs |5: 3 fn renamed_helper(x: u32) u32 { |10: 8 _ = renamed_helper(41); diff --git a/test/snapshots/lsp.golden b/test/snapshots/lsp.golden index 048d1ed3..2225de00 100644 --- a/test/snapshots/lsp.golden +++ b/test/snapshots/lsp.golden @@ -1,7 +1,7 @@ == snap opened grid=120x41 cursor=7,3 |Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol -| /tmp/pardes-snap/lsp/cwd/a.zig Save Tty Collapse Del TreeContext +| /tmp/pardes-snap/lsp/cwd/a.zig Save Tty Collapse Del TreeContext Def Refs | 1 const std = @import("std"); | 2 | 3 fn helper(x: u32) u32 { @@ -34,4 +34,4 @@ == snap step grid=120x41 cursor=15,3 |3: 1 const std = @import("std"); == snap nothing grid=120x41 cursor=7,5 -|3: 1 const std = @import("std"); definition: not found +|3: 1 const std = @import("std"); Def: not found diff --git a/test/snapshots/lspcomplete.golden b/test/snapshots/lspcomplete.golden index a56101e8..85c26e30 100644 --- a/test/snapshots/lspcomplete.golden +++ b/test/snapshots/lspcomplete.golden @@ -1,7 +1,7 @@ == snap opened grid=120x41 cursor=7,3 |Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol -| /tmp/pardes-snap/lspcomplete/cwd/a.zig Save Tty Collapse Del TreeContext +| /tmp/pardes-snap/lspcomplete/cwd/a.zig Save Tty Collapse Del TreeContext Def Refs | 1 const Shade = enum { | 2 verdigris, | 3 cinnabar, @@ -16,7 +16,7 @@ | 12 // note. see below | 13 == snap indent grid=120x41 cursor=11,12 -|2: ^* /tmp/pardes-snap/lspcomplete/cwd/a.zig Save Tty Collapse Del TreeContext +|2: ^* /tmp/pardes-snap/lspcomplete/cwd/a.zig Save Tty Collapse Del TreeContext Def Refs |12: 10 } == snap commentindent grid=120x41 cursor=19,14 |3: 1 const Shade = enum { --:--:-- lsp zls ready — /tmp/pardes-snap/lspcomplete/cwd @@ -31,7 +31,7 @@ |18: 3 == snap refill grid=120x41 cursor=16,10 == snap step grid=120x41 cursor=16,10 -|2: * /tmp/pardes-snap/lspcomplete/cwd/a.zig Save Tty Collapse Del TreeContext +|2: * /tmp/pardes-snap/lspcomplete/cwd/a.zig Save Tty Collapse Del TreeContext Def Refs == snap txtindent grid=120x41 cursor=15,3 |Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol @@ -41,7 +41,7 @@ == snap nosemi grid=100x19 cursor=29,9 |Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol -|^* /tmp/pardes-snap/lspcomplete/cwd/c.zig Save Tty Collapse Del TreeContext +|^* /tmp/pardes-snap/lspcomplete/cwd/c.zig Save Tty Collapse Del TreeContext Def Refs | 1 const Shade = enum { --:--:-- lsp zls ready — /tmp/pardes-snap/lspcomplete/cwd | 2 verdigris, | 3 cinnabar, @@ -57,7 +57,7 @@ == snap nobrace grid=100x19 cursor=16,10 |Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol -|^* /tmp/pardes-snap/lspcomplete/cwd/d.zig Save Tty Collapse Del TreeContext +|^* /tmp/pardes-snap/lspcomplete/cwd/d.zig Save Tty Collapse Del TreeContext Def Refs | 1 const Shade = enum { --:--:-- lsp zls ready — /tmp/pardes-snap/lspcomplete/cwd | 2 verdigris, | 3 cinnabar, diff --git a/test/snapshots/lspcompletemoved.golden b/test/snapshots/lspcompletemoved.golden index c83e3038..403c6931 100644 --- a/test/snapshots/lspcompletemoved.golden +++ b/test/snapshots/lspcompletemoved.golden @@ -1,7 +1,7 @@ == snap typedthrough grid=120x21 cursor=16,14 |Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol -|^* /tmp/pardes-snap/lspcompletemoved/cwd/a.zig Save Tty Collapse Del TreeContext +|^* /tmp/pardes-snap/lspcompletemoved/cwd/a.zig Save Tty Collapse Del TreeContext Def Refs | 1 const Shade = enum { --:--:-- lsp zls ready — /tmp/pardes-snap/lspcompletemoved/cwd | 2 verdigris, | 3 cinnabar, diff --git a/test/snapshots/lspdebug.golden b/test/snapshots/lspdebug.golden index 75fba98f..4beda019 100644 --- a/test/snapshots/lspdebug.golden +++ b/test/snapshots/lspdebug.golden @@ -1,7 +1,7 @@ == snap opened grid=120x45 cursor=7,3 |Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol -| /tmp/pardes-snap/lspdebug/cwd/z.zig Save Tty Collapse Del TreeContext +| /tmp/pardes-snap/lspdebug/cwd/z.zig Save Tty Collapse Del TreeContext Def Refs | 1 const std = @import("std"); | 2 | 3 fn helper() u32 { diff --git a/test/snapshots/lsprelpath.golden b/test/snapshots/lsprelpath.golden index b4022b1d..a3760316 100644 --- a/test/snapshots/lsprelpath.golden +++ b/test/snapshots/lsprelpath.golden @@ -1,7 +1,7 @@ == snap absrow grid=100x35 cursor=21,16 |Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol -| /tmp/pardes-snap/lsprelpath/cwd/sub/parent.zig Save Tty Collapse Del TreeContext +| /tmp/pardes-snap/lsprelpath/cwd/sub/parent.zig Save Tty Collapse Del TreeContext Def Refs | 1 const shade = @import("../shad --:--:-- lsp zls ready — /tmp/pardes-snap/lsprelpath/cwd/sub | 2 | 3 pub fn pick(s: shade.Shade) u8 { @@ -14,7 +14,7 @@ | 2 pub const Shade = enum { | 3 parent.zig:3:22-26 | 4 pub fn pick(s: shade.Shade) u8 { -| /tmp/pardes-snap/lsprelpath/cwd/shade.zig Save Tty Collapse Del TreeContext +| /tmp/pardes-snap/lsprelpath/cwd/shade.zig Save Tty Collapse Del TreeContext Def Refs | 1 pub const Shade = enum { | 2 verdigris, | 3 cinnabar, @@ -61,7 +61,7 @@ == snap subrow grid=100x35 cursor=20,16 |Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol -| /tmp/pardes-snap/lsprelpath/cwd/sub/subdir.zig Save Tty Collapse Del TreeContext +| /tmp/pardes-snap/lsprelpath/cwd/sub/subdir.zig Save Tty Collapse Del TreeContext Def Refs | 1 const tint = @import("inner/ti --:--:-- lsp zls ready — /tmp/pardes-snap/lsprelpath/cwd/sub | 2 | 3 pub fn hue(t: tint.Tint) u8 { @@ -74,7 +74,7 @@ | 2 pub const Tint = enum { | 3 subdir.zig:3:20-23 | 4 pub fn hue(t: tint.Tint) u8 { -| /tmp/pardes-snap/lsprelpath/cwd/sub/inner/tint.zig Save Tty Collapse Del TreeContext +| /tmp/pardes-snap/lsprelpath/cwd/sub/inner/tint.zig Save Tty Collapse Del TreeContext Def Refs | 1 pub const Tint = enum { | 2 ochre, | 3 indigo, diff --git a/test/snapshots/ninep.golden b/test/snapshots/ninep.golden index c6b5f0af..e524fa30 100644 --- a/test/snapshots/ninep.golden +++ b/test/snapshots/ninep.golden @@ -1,7 +1,7 @@ == snap opened grid=90x15 cursor=7,3 |Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol -| /tmp/pardes-snap/ninep/cwd/demo.zig Save Tty Collapse Del TreeContext +| /tmp/pardes-snap/ninep/cwd/demo.zig Save Tty Collapse Del TreeContext Def Refs | 1 const greeting = "café λ 界 é"; | 2 | 3 pub fn choose(ok: bool) u32 { @@ -30,8 +30,8 @@ @0: 0-74 #b2c3b8,#1d2824,,tagline 75-89 d,#1d2824,,tagline |1: New Tty Find Grep Joincol Delcol @1: 0-1 #ffffff,#887455,,tagline 2-2 d,#314738,,tagline 3-34 #becfc4,#314738,,tagline 35-89 d,#314738,,tagline -|2: /tmp/pardes-snap/ninep/cwd/demo.zig Save Tty Collapse Del TreeContext -@2: 0-1 #000000,#add38a,,tagline 2-2 d,#314738,,tagline 3-29 #becfc4,#314738,,tagline 30-37 #dfbce5,#314738,,tagline 38-71 #becfc4,#314738,,tagline 72-89 d,#314738,,tagline +|2: /tmp/pardes-snap/ninep/cwd/demo.zig Save Tty Collapse Del TreeContext Def Refs +@2: 0-1 #000000,#add38a,,tagline 2-2 d,#314738,,tagline 3-29 #becfc4,#314738,,tagline 30-37 #dfbce5,#314738,,tagline 38-80 #becfc4,#314738,,tagline 81-89 d,#314738,,tagline |3: 1 const greeting = "café λ 界 é"; +3: 28="é" 30="λ" 32="界" 33="" 35="é" @3: 0-0 d,#608269,,body 1-1 d,#0d1410,,body 2-6 #616f64,#0d1410,b,body 7-23 #e5eee5,#0d1410,,body 24-36 #b8d88a,#0d1410,,body 37-37 #e5eee5,#0d1410,,body 38-89 d,#0d1410,,body @@ -73,7 +73,7 @@ |7: 5 return 7; @7: 0-0 d,#608269,,body 1-1 d,#0d1410,,body 2-6 #59675c,#0d1410,,body 7-19 #e5eee5,#0d1410,,body 20-89 d,#0d1410,,body == snap edited-with-colors-off grid=90x15 cursor=7,4 -|2: * /tmp/pardes-snap/ninep/cwd/demo.zig Save Tty Collapse Del TreeContext +|2: * /tmp/pardes-snap/ninep/cwd/demo.zig Save Tty Collapse Del TreeContext Def Refs |3: 1 // café λ 界 |4: 2 const greeting = "café λ 界 é"; |5: 3 @@ -83,8 +83,8 @@ |9: 7 } |10: 8 == 9p edited-with-colors-off grid=90x15 cursor=7,4,block -|2: * /tmp/pardes-snap/ninep/cwd/demo.zig Save Tty Collapse Del TreeContext -@2: 0-0 #000000,#add38a,,tagline 1-1 #000000,#f9cb70,b,tagline 2-2 d,#314738,,tagline 3-29 #becfc4,#314738,,tagline 30-37 #dfbce5,#314738,,tagline 38-71 #becfc4,#314738,,tagline 72-89 d,#314738,,tagline +|2: * /tmp/pardes-snap/ninep/cwd/demo.zig Save Tty Collapse Del TreeContext Def Refs +@2: 0-0 #000000,#add38a,,tagline 1-1 #000000,#f9cb70,b,tagline 2-2 d,#314738,,tagline 3-29 #becfc4,#314738,,tagline 30-37 #dfbce5,#314738,,tagline 38-80 #becfc4,#314738,,tagline 81-89 d,#314738,,tagline |3: 1 // café λ 界 +3: 13="é" 15="λ" 17="界" 18="" @3: 0-0 d,#608269,,body 1-1 d,#0d1410,,body 2-6 #59675c,#0d1410,,body 7-18 #e5eee5,#0d1410,,body 19-89 d,#0d1410,,body @@ -152,8 +152,8 @@ @0: 0-74 #b2c3b8,#1d2824,,tagline 75-104 d,#1d2824,,tagline |1: New Tty Find Grep Joincol Delcol @1: 0-1 #ffffff,#887455,,tagline 2-2 d,#314738,,tagline 3-34 #becfc4,#314738,,tagline 35-104 d,#314738,,tagline -|2: * /tmp/pardes-snap/ninep/cwd/demo.zig Save Tty Collapse Del TreeContext -@2: 0-0 #000000,#add38a,,tagline 1-1 #000000,#f9cb70,b,tagline 2-2 d,#314738,,tagline 3-29 #becfc4,#314738,,tagline 30-37 #dfbce5,#314738,,tagline 38-71 #becfc4,#314738,,tagline 72-104 d,#314738,,tagline +|2: * /tmp/pardes-snap/ninep/cwd/demo.zig Save Tty Collapse Del TreeContext Def Refs +@2: 0-0 #000000,#add38a,,tagline 1-1 #000000,#f9cb70,b,tagline 2-2 d,#314738,,tagline 3-29 #becfc4,#314738,,tagline 30-37 #dfbce5,#314738,,tagline 38-80 #becfc4,#314738,,tagline 81-104 d,#314738,,tagline |3: 1 // café λ 界 Colors +3: 13="é" 15="λ" 17="界" 18="" @3: 0-0 d,#608269,,body 1-1 d,#0d1410,,body 2-6 #59675c,#0d1410,,body 7-18 #b9f480,#0d1410,,body 19-96 d,#0d1410,,body 97-97 d,#1d2824,,tagline 98-103 #b2c3b8,#1d2824,,tagline 104-104 d,#1d2824,,tagline @@ -193,7 +193,7 @@ == snap resized grid=105x20 cursor=7,4 |Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol -| * /tmp/pardes-snap/ninep/cwd/demo.zig Save Tty Collapse Del TreeContext +| * /tmp/pardes-snap/ninep/cwd/demo.zig Save Tty Collapse Del TreeContext Def Refs | 1 // café λ 界 Colors | 2 const greeting = "café λ 界 é"; | 3 diff --git a/test/snapshots/pagercolor.golden b/test/snapshots/pagercolor.golden index 811d3d96..abd264d1 100644 --- a/test/snapshots/pagercolor.golden +++ b/test/snapshots/pagercolor.golden @@ -41,9 +41,8 @@ | | | -| /tmp/pardes-snap/pagercolor/cwd/+Pager Save Tty Collapse Del -| 1 red bold green rgb ul NAME us plain -| 2 +| /tmp/pardes-snap/pagercolor/cwd/+Pager Save Tty Filter Collapse Del +| red bold green rgb ul NAME us plain == style pager-colours grid=100x50 |0: 0-99 #b2c3b8,#1d2824, |1: 0-1 d,#887455, 2-2 d,#314738, 3-99 #becfc4,#314738, @@ -88,8 +87,8 @@ |40: 0-0 d,#608269, 1-99 d,#0d1410, |41: 0-0 d,#608269, 1-99 d,#0d1410, |42: 0-1 d,#496656, 2-2 d,#1d2824, 3-34 #b2c3b8,#1d2824, 35-41 #d3b0d9,#1d2824, 42-99 #b2c3b8,#1d2824, -|43: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-10 #f1a39b,#0d1410, 11-20 #b6ce94,#0d1410,b 21-21 #b6ce94,#0d1410, 22-25 #c86400,#0d1410, 26-27 #e5eee5,#0d1410,u 28-28 #e5eee5,#0d1410, 29-32 #e5eee5,#0d1410,b 33-33 #e5eee5,#0d1410, 34-35 #e5eee5,#0d1410,u 36-99 #e5eee5,#0d1410, -|44: 0-0 d,#608269, 1-4 d,#0d1410, 5-99 #59675c,#0d1410, +|43: 0-0 d,#608269, 1-1 d,#0d1410, 2-5 #f1a39b,#0d1410, 6-15 #b6ce94,#0d1410,b 16-16 #b6ce94,#0d1410, 17-20 #c5917e,#0d1410, 21-22 #e5eee5,#0d1410,u 23-23 #e5eee5,#0d1410, 24-27 #e5eee5,#0d1410,b 28-28 #e5eee5,#0d1410, 29-30 #e5eee5,#0d1410,u 31-99 #e5eee5,#0d1410, +|44: 0-0 d,#608269, 1-99 d,#0d1410, |45: 0-0 d,#608269, 1-99 d,#0d1410, |46: 0-0 d,#608269, 1-99 d,#0d1410, |47: 0-0 d,#608269, 1-99 d,#0d1410, @@ -100,21 +99,19 @@ |6: 3[m\n\033[1m+++ b/x\033[m\n\033[36m@@ -1 +1 @@\033[m\n\033[31m-old\033[m\n\033[32m+new\033[m\n' | |7: $(readlink /proc/$PPID/exe) - |8: $ -|43: 1 commit 0123abc -|44: 2 diff --git a/x b/x -|45: 3 --- a/x -|46: 4 +++ b/x -|47: 5 @@ -1 +1 @@ -|48: 6 -old -|49: 7 +new +|9: /tmp/pardes-snap/pagercolor/cwd/+Diff Save Tty Diff Collapse Del LocationsConfig +|10: commit 0123abc +|11: x:1 +|12: -old +|13: +new +|49: /tmp/pardes-snap/pagercolor/cwd/+Pager Save Tty Filter Diff Collapse Del == style pager-diff-colours grid=100x50 |6: 0-0 d,#608269, 1-1 d,#0d1410, 2-99 #e5eee5,#0d1410, |7: 0-0 d,#608269, 1-1 d,#0d1410, 2-99 #e5eee5,#0d1410, |8: 0-0 d,#608269, 1-1 d,#0d1410, 2-99 #e5eee5,#0d1410, -|43: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-99 #e9c680,#0d1410, -|44: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-24 #b9f480,#0d1410,b 25-99 #b9f480,#0d1410, -|45: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-13 #b9f480,#0d1410,b 14-99 #b9f480,#0d1410, -|46: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-13 #b9f480,#0d1410,b 14-99 #b9f480,#0d1410, -|47: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-99 #b6c59e,#0d1410, -|48: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-7 #f1a39b,#302b25,b 8-99 #f8c082,#302b25, -|49: 0-0 d,#152019, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-7 #b6ce94,#263025,b 8-99 #b8d88a,#263025, +|9: 0-1 d,#496656, 2-2 d,#1d2824, 3-34 #b2c3b8,#1d2824, 35-40 #d3b0d9,#1d2824, 41-99 #b2c3b8,#1d2824, +|10: 0-0 d,#608269, 1-1 d,#0d1410, 2-99 #e5eee5,#0d1410, +|11: 0-0 d,#608269, 1-1 d,#0d1410, 2-99 #59675c,#0d1410, +|12: 0-0 d,#608269, 1-1 d,#0d1410, 2-2 #f1a39b,#1a1d18,b 3-99 #f8c082,#1a1d18, +|13: 0-0 d,#608269, 1-1 d,#0d1410, 2-2 #b6ce94,#171f18,b 3-99 #b8d88a,#171f18, +|49: 0-1 d,#496656, 2-2 d,#1d2824, 3-34 #b2c3b8,#1d2824, 35-41 #d3b0d9,#1d2824, 42-99 #b2c3b8,#1d2824, diff --git a/test/snapshots/selregex.golden b/test/snapshots/selregex.golden index e3f3b2d7..480ad8a2 100644 --- a/test/snapshots/selregex.golden +++ b/test/snapshots/selregex.golden @@ -1,7 +1,7 @@ == snap prompt-armed grid=160x25 cursor=159,3 |Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol -| /tmp/pardes-snap/selregex/cwd/m.zig Save Tty Collapse Del TreeContext +| /tmp/pardes-snap/selregex/cwd/m.zig Save Tty Collapse Del TreeContext Def Refs | 1 const one = 1; Select / | 2 const two = 2; | 3 const three = 3; @@ -51,12 +51,12 @@ |4: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-10 #f5f7ee,#243a2d, 11-11 #3c614a,#f5f7ee, 12-12 #3c614a,#0d1410, 13-18 #e5eee5,#0d1410, 19-19 #f8c082,#0d1410, 20-159 #e5eee5,#0d1410, |5: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-10 #f5f7ee,#243a2d, 11-11 #3c614a,#f5f7ee, 12-12 #3c614a,#0d1410, 13-20 #e5eee5,#0d1410, 21-21 #f8c082,#0d1410, 22-159 #e5eee5,#0d1410, == snap commented grid=160x25 cursor=14,3 -|2: * /tmp/pardes-snap/selregex/cwd/m.zig Save Tty Collapse Del TreeContext +|2: * /tmp/pardes-snap/selregex/cwd/m.zig Save Tty Collapse Del TreeContext Def Refs |3: 1 // const one = 1; |4: 2 // const two = 2; |5: 3 // const three = 3; == snap uncommented grid=160x25 cursor=11,3 -|2: /tmp/pardes-snap/selregex/cwd/m.zig Save Tty Collapse Del TreeContext +|2: /tmp/pardes-snap/selregex/cwd/m.zig Save Tty Collapse Del TreeContext Def Refs |3: 1 const one = 1; |4: 2 const two = 2; |5: 3 const three = 3; diff --git a/test/snapshots/syntax.golden b/test/snapshots/syntax.golden index 2f7a6b74..43bfe485 100644 --- a/test/snapshots/syntax.golden +++ b/test/snapshots/syntax.golden @@ -1,11 +1,12 @@ -== snap zig-open grid=150x31 cursor=7,7 +== snap zig-open grid=150x31 cursor=7,8 |Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol | /tmp/pardes-snap/syntax/cwd Tty+bash Save Mode Filter Collapse Del /tmp/pardes-snap/syntax/cwd Tty+bash Save Mode Filter Collapse Del | ls ls | demo.zig demo.zig | -| /tmp/pardes-snap/syntax/cwd/demo.zig Save Tty Collapse Del TreeContext +| /tmp/pardes-snap/syntax/cwd/demo.zig Save Tty Collapse Del TreeContext D +| ef Refs | 1 const std = @import("std"); // greet | 2 pub fn main() void { | 3 var x: u32 = 42; @@ -15,7 +16,6 @@ | | | -| | /tmp/pardes-snap/syntax/cwd Tty+bash Save Mode Filter Collapse Del | ls | demo.zig @@ -27,12 +27,12 @@ |4: 0-0 d,#608269, 1-1 d,#0d1410, 2-74 #e5eee5,#0d1410, 75-75 #e5eee5,#608269, 76-149 #e5eee5,#0d1410, |5: 0-0 d,#608269, 1-74 d,#0d1410, 75-75 d,#608269, 76-149 d,#0d1410, |6: 0-1 d,#add38a, 2-2 d,#314738, 3-30 #becfc4,#314738, 31-39 #dfbce5,#314738, 40-74 #becfc4,#314738, 75-75 #becfc4,#608269, 76-149 #becfc4,#0d1410, -|7: 0-0 d,#608269, 1-1 d,#0d1410, 2-4 d,#0d1410,b 5-6 #616f64,#0d1410,b 7-18 #e5eee5,#0d1410, 19-25 #c9a7ed,#0d1410, 26-26 #e5eee5,#0d1410, 27-31 #b8d88a,#0d1410, 32-34 #e5eee5,#0d1410, 35-74 #b9f480,#0d1410, 75-75 #b9f480,#608269, 76-149 #b9f480,#0d1410, -|8: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-10 #e5eee5,#0d1410, 11-13 #c9a7ed,#0d1410, 14-74 #e5eee5,#0d1410, 75-75 #e5eee5,#608269, 76-149 #e5eee5,#0d1410, -|9: 0-0 d,#608269, 1-4 d,#0d1410, 5-10 #59675c,#0d1410, 11-23 #e5eee5,#0d1410, 24-25 #f8c082,#0d1410, 26-74 #e5eee5,#0d1410, 75-75 #e5eee5,#608269, 76-149 #e5eee5,#0d1410, -|10: 0-0 d,#608269, 1-4 d,#0d1410, 5-10 #59675c,#0d1410, 11-74 #e5eee5,#0d1410, 75-75 #e5eee5,#608269, 76-149 #e5eee5,#0d1410, -|11: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-74 #e5eee5,#0d1410, 75-75 #e5eee5,#608269, 76-149 #e5eee5,#0d1410, -|12: 0-0 d,#608269, 1-74 d,#0d1410, 75-75 d,#608269, 76-149 d,#0d1410, +|7: 0-2 d,#314738, 3-74 #becfc4,#314738, 75-75 #becfc4,#608269, 76-149 #becfc4,#0d1410, +|8: 0-0 d,#608269, 1-1 d,#0d1410, 2-4 d,#0d1410,b 5-6 #616f64,#0d1410,b 7-18 #e5eee5,#0d1410, 19-25 #c9a7ed,#0d1410, 26-26 #e5eee5,#0d1410, 27-31 #b8d88a,#0d1410, 32-34 #e5eee5,#0d1410, 35-74 #b9f480,#0d1410, 75-75 #b9f480,#608269, 76-149 #b9f480,#0d1410, +|9: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-10 #e5eee5,#0d1410, 11-13 #c9a7ed,#0d1410, 14-74 #e5eee5,#0d1410, 75-75 #e5eee5,#608269, 76-149 #e5eee5,#0d1410, +|10: 0-0 d,#608269, 1-4 d,#0d1410, 5-10 #59675c,#0d1410, 11-23 #e5eee5,#0d1410, 24-25 #f8c082,#0d1410, 26-74 #e5eee5,#0d1410, 75-75 #e5eee5,#608269, 76-149 #e5eee5,#0d1410, +|11: 0-0 d,#608269, 1-4 d,#0d1410, 5-10 #59675c,#0d1410, 11-74 #e5eee5,#0d1410, 75-75 #e5eee5,#608269, 76-149 #e5eee5,#0d1410, +|12: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-74 #e5eee5,#0d1410, 75-75 #e5eee5,#608269, 76-149 #e5eee5,#0d1410, |13: 0-0 d,#608269, 1-74 d,#0d1410, 75-75 d,#608269, 76-149 d,#0d1410, |14: 0-0 d,#608269, 1-74 d,#0d1410, 75-75 d,#608269, 76-149 d,#0d1410, |15: 0-0 d,#608269, 1-74 d,#0d1410, 75-75 d,#608269, 76-149 d,#0d1410, @@ -52,10 +52,10 @@ |29: 0-0 d,#608269, 1-74 d,#0d1410, 75-75 d,#608269, 76-149 d,#0d1410, |30: 0-0 d,#608269, 1-74 d,#0d1410, 75-75 d,#608269, 76-149 d,#0d1410, == style colors-off grid=150x31 -|7: 0-0 d,#608269, 1-1 d,#0d1410, 2-4 d,#0d1410,b 5-6 #616f64,#0d1410,b 7-66 #e5eee5,#0d1410, 67-67 #e5eee5,#1d2824, 68-74 #b2c3b8,#1d2824, 75-75 #b2c3b8,#608269, 76-149 #b2c3b8,#0d1410, -|8: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-74 #e5eee5,#0d1410, 75-75 #e5eee5,#608269, 76-149 #e5eee5,#0d1410, -|9: 0-0 d,#608269, 1-4 d,#0d1410, 5-10 #59675c,#0d1410, 11-74 #e5eee5,#0d1410, 75-75 #e5eee5,#608269, 76-149 #e5eee5,#0d1410, +|8: 0-0 d,#608269, 1-1 d,#0d1410, 2-4 d,#0d1410,b 5-6 #616f64,#0d1410,b 7-66 #e5eee5,#0d1410, 67-67 #e5eee5,#1d2824, 68-74 #b2c3b8,#1d2824, 75-75 #b2c3b8,#608269, 76-149 #b2c3b8,#0d1410, +|9: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-74 #e5eee5,#0d1410, 75-75 #e5eee5,#608269, 76-149 #e5eee5,#0d1410, +|10: 0-0 d,#608269, 1-4 d,#0d1410, 5-10 #59675c,#0d1410, 11-74 #e5eee5,#0d1410, 75-75 #e5eee5,#608269, 76-149 #e5eee5,#0d1410, == style colors-on grid=150x31 -|7: 0-0 d,#608269, 1-1 d,#0d1410, 2-4 d,#0d1410,b 5-6 #616f64,#0d1410,b 7-18 #e5eee5,#0d1410, 19-25 #c9a7ed,#0d1410, 26-26 #e5eee5,#0d1410, 27-31 #b8d88a,#0d1410, 32-34 #e5eee5,#0d1410, 35-66 #b9f480,#0d1410, 67-67 #b9f480,#1d2824, 68-74 #b2c3b8,#1d2824, 75-75 #b2c3b8,#608269, 76-149 #b2c3b8,#0d1410, -|8: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-10 #e5eee5,#0d1410, 11-13 #c9a7ed,#0d1410, 14-74 #e5eee5,#0d1410, 75-75 #e5eee5,#608269, 76-149 #e5eee5,#0d1410, -|9: 0-0 d,#608269, 1-4 d,#0d1410, 5-10 #59675c,#0d1410, 11-23 #e5eee5,#0d1410, 24-25 #f8c082,#0d1410, 26-74 #e5eee5,#0d1410, 75-75 #e5eee5,#608269, 76-149 #e5eee5,#0d1410, +|8: 0-0 d,#608269, 1-1 d,#0d1410, 2-4 d,#0d1410,b 5-6 #616f64,#0d1410,b 7-18 #e5eee5,#0d1410, 19-25 #c9a7ed,#0d1410, 26-26 #e5eee5,#0d1410, 27-31 #b8d88a,#0d1410, 32-34 #e5eee5,#0d1410, 35-66 #b9f480,#0d1410, 67-67 #b9f480,#1d2824, 68-74 #b2c3b8,#1d2824, 75-75 #b2c3b8,#608269, 76-149 #b2c3b8,#0d1410, +|9: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-10 #e5eee5,#0d1410, 11-13 #c9a7ed,#0d1410, 14-74 #e5eee5,#0d1410, 75-75 #e5eee5,#608269, 76-149 #e5eee5,#0d1410, +|10: 0-0 d,#608269, 1-4 d,#0d1410, 5-10 #59675c,#0d1410, 11-23 #e5eee5,#0d1410, 24-25 #f8c082,#0d1410, 26-74 #e5eee5,#0d1410, 75-75 #e5eee5,#608269, 76-149 #e5eee5,#0d1410, -- cgit v1.3 From 1ecb9b720840ea8e4753823fa8cddcf5d6a3a4d2 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Thu, 8 Oct 2026 12:03:46 -0300 Subject: Add a readable static Callstack pane and align tagline text --- docs/typ/builtins-gui.json | 6 + docs/typ/builtins-tty.json | 6 + docs/typ/guide.typ | 33 +++- docs/typ/reference.typ | 10 ++ src/CHANGELOG.md | 15 ++ src/File.zig | 82 ++++++--- src/Output.zig | 79 +++++++-- src/body_layer.zig | 42 ++--- src/builtins.zig | 13 +- src/colors.zig | 10 +- src/config.zig | 46 ++++- src/draw.zig | 18 +- src/dump.zig | 4 +- src/edit.zig | 4 +- src/exec.zig | 16 +- src/host_io.zig | 12 ++ src/layout.zig | 22 +++ src/locations.zig | 179 +++++++++++++++++++- src/look.zig | 17 +- src/lsp/lsp.zig | 10 +- src/lsp/lsp_client.zig | 263 +++++++++++++++++++++++++++-- src/modal.zig | 4 +- src/mouse.zig | 26 ++- src/ninep/ctl.zig | 22 ++- src/normal.zig | 3 +- src/panes.zig | 9 +- src/pardes.zig | 81 +++++++-- src/syntax.zig | 17 +- src/tagline.zig | 19 ++- test/column_drag.zig | 14 +- test/hxcases/waivers.jsonl | 1 + test/panes.zig | 151 ++++++++++++++++- test/snapshots/argv.golden | 26 +-- test/snapshots/badutf.golden | 14 +- test/snapshots/boot.golden | 12 +- test/snapshots/builtins.golden | 10 +- test/snapshots/builtins.snap | 2 + test/snapshots/callstack-inline.golden | 65 +++++++ test/snapshots/callstack-inline.snap | 30 ++++ test/snapshots/callstack.golden | 27 +++ test/snapshots/callstack.snap | 19 +++ test/snapshots/chordcut.golden | 40 ++--- test/snapshots/cmdexit.golden | 10 +- test/snapshots/cmdword.golden | 18 +- test/snapshots/colgrip.golden | 42 ++--- test/snapshots/collapse.golden | 20 +-- test/snapshots/cornerdrag-left.golden | 62 +++---- test/snapshots/cornerdrag.golden | 90 +++++----- test/snapshots/cursorline.golden | 20 +-- test/snapshots/delask.golden | 14 +- test/snapshots/diffview.golden | 32 ++-- test/snapshots/dirpane.golden | 10 +- test/snapshots/doccol.golden | 20 +-- test/snapshots/edit.golden | 24 +-- test/snapshots/emptycol.golden | 20 +-- test/snapshots/exec-bigdrag.golden | 8 +- test/snapshots/exec.golden | 8 +- test/snapshots/fileedit.golden | 10 +- test/snapshots/filewatch.golden | 10 +- test/snapshots/find.golden | 24 +-- test/snapshots/fsearch.golden | 26 +-- test/snapshots/ghostty-mid.golden | 12 +- test/snapshots/grep.golden | 16 +- test/snapshots/headersweep-restored.golden | 40 ++--- test/snapshots/headersweep.golden | 46 ++--- test/snapshots/hscroll.golden | 16 +- test/snapshots/images.golden | 42 ++--- test/snapshots/jumps.golden | 20 +-- test/snapshots/layout-close.golden | 62 +++---- test/snapshots/layout-open.golden | 32 ++-- test/snapshots/leader.golden | 44 +++-- test/snapshots/load.golden | 24 +-- test/snapshots/logquiet.golden | 6 +- test/snapshots/look-center.golden | 10 +- test/snapshots/look-dir.golden | 16 +- test/snapshots/look-file-1col.golden | 8 +- test/snapshots/look-file.golden | 20 +-- test/snapshots/lookloaded.golden | 20 +-- test/snapshots/lookpanes.golden | 52 +++--- test/snapshots/lookrange.golden | 20 +-- test/snapshots/lsp-client-edit.golden | 12 +- test/snapshots/lsp-client.golden | 10 +- test/snapshots/lsp-rename-files.golden | 10 +- test/snapshots/lsp-rename.golden | 10 +- test/snapshots/lsp.golden | 10 +- test/snapshots/lspcomplete.golden | 34 ++-- test/snapshots/lspcompletemoved.golden | 6 +- test/snapshots/lspdebug.golden | 6 +- test/snapshots/lsprelpath.golden | 40 ++--- test/snapshots/markup.golden | 24 +-- test/snapshots/mini.golden | 56 +++--- test/snapshots/modal.golden | 24 +-- test/snapshots/msg.golden | 14 +- test/snapshots/multicursor.golden | 24 +-- test/snapshots/nested-optout.golden | 32 ++-- test/snapshots/nested.golden | 28 +-- test/snapshots/ninep.golden | 56 +++--- test/snapshots/pagercolor.golden | 42 +++-- test/snapshots/pipe.golden | 10 +- test/snapshots/psearch.golden | 26 +-- test/snapshots/reflow.golden | 8 +- test/snapshots/respawn.golden | 8 +- test/snapshots/restore.golden | 8 +- test/snapshots/rsearch.golden | 12 +- test/snapshots/savepane.golden | 10 +- test/snapshots/scroll.golden | 24 +-- test/snapshots/scrolloff.golden | 8 +- test/snapshots/selarg.golden | 12 +- test/snapshots/selregex.golden | 16 +- test/snapshots/shellset.golden | 12 +- test/snapshots/shrinktag.golden | 24 +-- test/snapshots/splitparent.golden | 42 ++--- test/snapshots/stepgrain.golden | 20 +-- test/snapshots/syntax.golden | 24 +-- test/snapshots/tag.golden | 22 +-- test/snapshots/tagalign.golden | 60 ++++--- test/snapshots/tagalign2col.golden | 39 +++-- test/snapshots/tagbottom.golden | 26 +-- test/snapshots/tagbottomimage.golden | 22 +-- test/snapshots/tagbottomshort.golden | 34 ++-- test/snapshots/tagcmd.golden | 12 +- test/snapshots/tagnav.golden | 44 ++--- test/snapshots/tagpath.golden | 30 ++-- test/snapshots/theme.golden | 242 +++++++++++++------------- test/snapshots/themesel.golden | 146 ++++++++-------- test/snapshots/tinywin.golden | 60 +++---- test/snapshots/topbarexec.golden | 28 +-- test/snapshots/tty.golden | 18 +- test/snapshots/ttyclick.golden | 16 +- test/snapshots/ttyedit.golden | 16 +- test/snapshots/ttyfollow.golden | 16 +- test/snapshots/ttyhelp.golden | 10 +- test/snapshots/ttylook.golden | 32 ++-- test/snapshots/ttyonly.golden | 16 +- test/snapshots/ttypaste.golden | 12 +- test/snapshots/ttyprompt.golden | 16 +- test/snapshots/ttytaken.golden | 14 +- test/snapshots/tutor.golden | 10 +- test/snapshots/wheeldrift.golden | 6 +- test/snapshots/winch.golden | 24 +-- test/snapshots/windownav.golden | 12 +- test/snapshots/windowops.golden | 84 ++++----- test/snapshots/wrap.golden | 14 +- test/snapshots/yankpaste.golden | 6 +- 144 files changed, 2646 insertions(+), 1596 deletions(-) create mode 100644 test/snapshots/callstack-inline.golden create mode 100644 test/snapshots/callstack-inline.snap create mode 100644 test/snapshots/callstack.golden create mode 100644 test/snapshots/callstack.snap (limited to 'src/Output.zig') diff --git a/docs/typ/builtins-gui.json b/docs/typ/builtins-gui.json index 83a410dc..f602ee92 100644 --- a/docs/typ/builtins-gui.json +++ b/docs/typ/builtins-gui.json @@ -6,6 +6,10 @@ {"name": "BootShell", "leader": null, "also": [], "arg": true, "scope": "root", "setting": true, "choices": "keep, replace", "doc": "A document dropped where a lone untouched shell stands: keep the shell, or replace it."}, {"name": "Callees", "leader": "SPC l C", "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "List the functions the function under the cursor calls."}, {"name": "Callers", "leader": "SPC l c", "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "List the callers of the function under the cursor."}, + {"name": "Callstack", "leader": "SPC l b", "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Show outermost callers first, with signatures and call sites (gc)."}, + {"name": "CallstackCorners", "leader": null, "also": [], "arg": true, "scope": "root", "setting": true, "choices": "rounded, square", "doc": "Callstack tree corners: rounded (the default) or square; bare, it switches styles. Applies to the next Callstack query."}, + {"name": "CallstackDepth", "leader": null, "also": [], "arg": true, "scope": "root", "setting": true, "choices": null, "doc": "Caller levels collected by Callstack, 1 through 64; default 8. Bare, it says the current limit."}, + {"name": "CallstackLayout", "leader": null, "also": [], "arg": true, "scope": "root", "setting": true, "choices": "inline, stacked", "doc": "Callstack snippets below their locations (stacked, the default) or beside them (inline); bare, it switches layouts. Applies to the next Callstack query."}, {"name": "Changelog", "leader": "SPC h c", "also": ["topbar"], "arg": false, "scope": "root", "setting": false, "choices": null, "doc": "This build's version and what changed to reach it, printed into an output buffer the same way Config prints the live settings."}, {"name": "ChipShadow", "leader": null, "also": [], "arg": true, "scope": "root", "setting": true, "choices": "on, off", "doc": "In a terminal, a notice chip casts a cell's shadow right and down, on or off."}, {"name": "ClipPaste", "leader": "SPC p", "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Paste the system clipboard after the selection."}, @@ -65,6 +69,8 @@ {"name": "Ligatures", "leader": null, "also": [], "arg": true, "scope": "root", "setting": true, "choices": "on, off", "doc": "A font's programming ligatures draw across their cells, on or off."}, {"name": "LocationsConfig", "leader": null, "also": [], "arg": true, "scope": "root", "setting": false, "choices": null, "doc": "Set how location rows are drawn, or show how they are when bare."}, {"name": "Look", "leader": null, "also": ["enter", "right-click"], "arg": true, "scope": "pane", "setting": false, "choices": null, "doc": "Look at its argument: open the file or address it names, else find the word, as a right click does."}, + {"name": "LookNext", "leader": "SPC j n", "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Select the next Look location across panes; Enter opens it."}, + {"name": "LookPrev", "leader": "SPC j p", "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Select the previous Look location across panes; Enter opens it."}, {"name": "LookWord", "leader": null, "also": [], "arg": true, "scope": "root", "setting": true, "choices": "search, list", "doc": "A plain word looked at: search selects its next place in the pane, list lists every place in a +Search."}, {"name": "Lspinfo", "leader": "SPC l i", "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Show which language servers serve this file and their state."}, {"name": "Lspwhy", "leader": "SPC l w", "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Explain how the last language server request was answered, step by step."}, diff --git a/docs/typ/builtins-tty.json b/docs/typ/builtins-tty.json index 35e12875..e02f4201 100644 --- a/docs/typ/builtins-tty.json +++ b/docs/typ/builtins-tty.json @@ -5,6 +5,10 @@ {"name": "BootShell", "leader": null, "also": [], "arg": true, "scope": "root", "setting": true, "choices": "keep, replace", "doc": "A document dropped where a lone untouched shell stands: keep the shell, or replace it."}, {"name": "Callees", "leader": "SPC l C", "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "List the functions the function under the cursor calls."}, {"name": "Callers", "leader": "SPC l c", "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "List the callers of the function under the cursor."}, + {"name": "Callstack", "leader": "SPC l b", "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Show outermost callers first, with signatures and call sites (gc)."}, + {"name": "CallstackCorners", "leader": null, "also": [], "arg": true, "scope": "root", "setting": true, "choices": "rounded, square", "doc": "Callstack tree corners: rounded (the default) or square; bare, it switches styles. Applies to the next Callstack query."}, + {"name": "CallstackDepth", "leader": null, "also": [], "arg": true, "scope": "root", "setting": true, "choices": null, "doc": "Caller levels collected by Callstack, 1 through 64; default 8. Bare, it says the current limit."}, + {"name": "CallstackLayout", "leader": null, "also": [], "arg": true, "scope": "root", "setting": true, "choices": "inline, stacked", "doc": "Callstack snippets below their locations (stacked, the default) or beside them (inline); bare, it switches layouts. Applies to the next Callstack query."}, {"name": "Changelog", "leader": "SPC h c", "also": ["topbar"], "arg": false, "scope": "root", "setting": false, "choices": null, "doc": "This build's version and what changed to reach it, printed into an output buffer the same way Config prints the live settings."}, {"name": "ChipShadow", "leader": null, "also": [], "arg": true, "scope": "root", "setting": true, "choices": "on, off", "doc": "In a terminal, a notice chip casts a cell's shadow right and down, on or off."}, {"name": "ClipPaste", "leader": "SPC p", "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Paste the system clipboard after the selection."}, @@ -55,6 +59,8 @@ {"name": "Left", "leader": "SPC w h", "also": ["C-w h", "C-w left"], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Move the keyboard to the pane, or column tag, to the left."}, {"name": "LocationsConfig", "leader": null, "also": [], "arg": true, "scope": "root", "setting": false, "choices": null, "doc": "Set how location rows are drawn, or show how they are when bare."}, {"name": "Look", "leader": null, "also": ["enter", "right-click"], "arg": true, "scope": "pane", "setting": false, "choices": null, "doc": "Look at its argument: open the file or address it names, else find the word, as a right click does."}, + {"name": "LookNext", "leader": "SPC j n", "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Select the next Look location across panes; Enter opens it."}, + {"name": "LookPrev", "leader": "SPC j p", "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Select the previous Look location across panes; Enter opens it."}, {"name": "LookWord", "leader": null, "also": [], "arg": true, "scope": "root", "setting": true, "choices": "search, list", "doc": "A plain word looked at: search selects its next place in the pane, list lists every place in a +Search."}, {"name": "Lspinfo", "leader": "SPC l i", "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Show which language servers serve this file and their state."}, {"name": "Lspwhy", "leader": "SPC l w", "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Explain how the last language server request was answered, step by step."}, diff --git a/docs/typ/guide.typ b/docs/typ/guide.typ index 55f8a4f0..7058592f 100644 --- a/docs/typ/guide.typ +++ b/docs/typ/guide.typ @@ -218,10 +218,39 @@ around it, a `+`/`-` before each line, the words a changed line changed tinted and a line added or removed whole faintly. A mailed patch keeps its message and diffstat above. The files are found from the diff's directory or one above it. #word("Diff") on a `+Diff` shows the diff itself as -text (a paged one's `+Pager` is folded under it), and on the text stacks +text (a paged one's `+Pager` is closed once stacked), and on the text stacks it again; #word("DiffLook") `text` in the startup file opens the text first. += Call hierarchy + +Put the cursor on a function and run #word("Callstack") (#key("g c") or #key("SPC l b")). +`+Callstack` starts at the outermost callers and follows calls down toward +the selected function, with shared callers grouped and vertical guides +joining the levels with rounded corners. Each caller has a clickable location and its function +signature, extracted by the same tree-sitter context mechanism as other +location results. Signatures and call-site snippets use source syntax colors; +only calls to the selected function receive background emphasis. Guides +continue alongside every line of a multiline signature and through screen +wrapping. Cross-directory Look paths are shortened when possible. +#btn("B3") or #key("Enter") on a location opens and reveals that source +pane. #word("LookNext") / #word("LookPrev") (#keys("SPC j n", "SPC j p")) +select locations without opening them. The view follows the language +server's static call hierarchy; recursive paths are marked `↻`, and a +large hierarchy invites continuing from another function. +#word("CallstackDepth") reports the current caller depth; +`CallstackDepth 16` changes it for subsequent queries. The default is 8 +levels, and the accepted range is 1–64. The view also caps collection at +64 callers. + +`CallstackLayout stacked` (the default) puts each signature and call snippet below its +location, aligned with the location text; `CallstackLayout inline` puts it +beside the location again. A bare #word("CallstackLayout") switches modes. +`CallstackCorners rounded` (the default) uses rounded tree guides; +`CallstackCorners square` restores sharp corners. Bare #word("CallstackCorners") +switches styles. Layout and corner changes apply to the next query. These settings are retained +by #word("Dump") / #word("Restore"). + = `pardes FILE` and `--wait` In a pane's shell: @@ -242,7 +271,7 @@ refusals and `--nested` are in the reference. [#key("x"), #key("v"), #key(";")], [select the line; extend; collapse to the cursor], [#key("s")], [a cursor per regex match; every edit acts at each], [#key("/"), #keys("n", "N")], [substring search; repeat the search in the current text, wrapping at the ends], - [#keys("Space j n", "Space j p")], [#word("LookNext") / #word("LookPrev"): select locations across panes; #key("Enter") opens one], + [#keys("SPC j n", "SPC j p")], [#word("LookNext") / #word("LookPrev"): select locations across panes; #key("Enter") opens one], [#key("g l")], [line end], [`12G`], [line 12; a bare #key("G") does nothing], [#key("SPC ?")], [#word("Help"): every builtin, with its leader path and keys; `SPC w ?` only the paths under `SPC w`; #word("Tutor") (#key("SPC h t")) practises them], diff --git a/docs/typ/reference.typ b/docs/typ/reference.typ index 909c1e1a..05176951 100644 --- a/docs/typ/reference.typ +++ b/docs/typ/reference.typ @@ -262,6 +262,16 @@ A line written to #file("exec") is #word("Exec"): the server answers in this file alone while another open file of its language still holds the old name, a row per such file (zls renaming at a declaration; from a use it reaches every file); + #word("Callstack") (#key("g c") or #key("SPC l b")) opens and focuses `+Callstack`, + with static caller ancestry, tree-sitter signatures and Look locations + for callers and call sites. #word("CallstackDepth") reports or sets the + runtime depth (1–64, default 8) for subsequent queries. + `CallstackLayout stacked` (the default) aligns snippets below their locations; + `CallstackLayout inline` places the snippets beside them. + `CallstackCorners rounded` (the default) or `CallstackCorners square` + selects the tree corner style for the next query; bare, it switches styles. + #word("Callers") and #word("Callees") keep their short + lists and single-result jumps. #word("Diagnostics") and #word("Symbols") list the file's in `+Search`; #word("Lspinfo") fills `+Lsp`, the pane its write answers, with which server serves the file and its state (`not started yet` until its first diff --git a/src/CHANGELOG.md b/src/CHANGELOG.md index e15faca7..4fe0760c 100644 --- a/src/CHANGELOG.md +++ b/src/CHANGELOG.md @@ -2,6 +2,21 @@ ## Unreleased +- Callstack (gc or Space l b) opens a readable static call hierarchy with + outermost callers first, tree-sitter signatures, depth guides and clickable call sites. + `gc` replaces the old move-to-viewport-center binding. + CallstackDepth sets the caller depth at runtime (1–64, default 8). + CallstackLayout stacked is the default, aligning snippets below their + locations with rounded tree corners; inline + keeps them beside the locations. CallstackCorners square restores sharp + tree corners; rounded remains the default. + Signatures use syntax colors; only calls to the queried function get + background emphasis, and tree guides continue through multiline signatures + and wrapped rows. Cross-directory call locations use shorter relative paths. +- Workspace, column and pane tags share a tighter text inset. +- A diff paged into a session (`git show | pardes -`) opens its `+Diff` + alone; the `+Pager` no longer stays folded under it. + - n/N follow Helix search registers, counts, wrapping and select mode. `*` sets a search from the selection; `Alt-*` omits word boundaries. The location ring remains as LookNext/LookPrev (Space j n/p). diff --git a/src/File.zig b/src/File.zig index 31392ebd..c42e39ec 100644 --- a/src/File.zig +++ b/src/File.zig @@ -253,6 +253,8 @@ fn dumpLocationRows(arena: std.mem.Allocator, rows: []const locations.Row) ![]co for (rows, saved) |row, *out| out.* = .{ .kind = @enumFromInt(@intFromEnum(row.kind)), .declaration = row.declaration, + .mark_occurrence = row.mark_occurrence, + .source_column = row.source_column, .path = row.path, .line = row.at.line, .col = row.at.col, @@ -271,6 +273,10 @@ fn sameSavedLocation(a: dump.LocationRow, b: dump.LocationRow) bool { } fn restoreLocationRows(gpa: std.mem.Allocator, content: []const u8, saved: []const dump.LocationRow) ![]locations.Row { + return restoreOutputLocationRows(gpa, content, saved, false); +} + +fn restoreOutputLocationRows(gpa: std.mem.Allocator, content: []const u8, saved: []const dump.LocationRow, callstack: bool) ![]locations.Row { if (saved.len == 0) return &.{}; if (saved.len > std.mem.count(u8, content, "\n") + 1) return error.InvalidLocationRows; const rows = try gpa.alloc(locations.Row, saved.len); @@ -286,29 +292,44 @@ fn restoreLocationRows(gpa: std.mem.Allocator, content: []const u8, saved: []con var previous_line: []const u8 = ""; for (saved, rows, 0..) |row, *out, index| { const line = lines.next() orelse return error.InvalidLocationRows; - if (row.path.len == 0 or row.path.len >= 4096 or + if ((!callstack and row.path.len == 0) or row.path.len >= 4096 or row.location_end > row.code_start or row.code_start > line.len or (row.kind == .match and row.location_end == 0) or (row.declaration and row.kind != .context) or row.line > std.math.maxInt(i32) or row.col > std.math.maxInt(i32) or row.end_line > std.math.maxInt(i32) or row.end_col > std.math.maxInt(i32)) return error.InvalidLocationRows; - const inline_row = row.code_start > row.location_end and row.code_start > 0 and line[row.code_start - 1] == '\t'; - const address_row = !inline_row and row.location_end > 0 and row.code_start == line.len; - const source_row = row.location_end == 0 and row.code_start == 0; - if (!inline_row and !address_row and !source_row) return error.InvalidLocationRows; - if (row.kind == .preview) { - if (!source_row or index == 0) return error.InvalidLocationRows; - const previous = saved[index - 1]; - if (previous.kind != .match or previous.location_end == 0 or previous.code_start != previous_line.len or previous_line[previous_line.len - 1] == '\t' or - !sameSavedLocation(previous, row)) return error.InvalidLocationRows; - } - if (address_row) { - if (index + 1 >= saved.len) return error.InvalidLocationRows; - const following = saved[index + 1]; - const expected: @TypeOf(row.kind) = if (row.kind == .match) .preview else .context; - if (following.kind != expected or following.code_start != 0 or following.location_end != 0 or - following.declaration != row.declaration or !sameSavedLocation(row, following)) return error.InvalidLocationRows; + if (callstack) { + if (row.location_end > 0) { + const prefix = locations.treePrefix(line); + const parsed = locations.parseRaw(line[prefix.end..]); + if (row.kind != .match or parsed.at.line == 0 or + !std.mem.eql(u8, parsed.path, row.path) or + parsed.at.line != row.line or parsed.at.col != row.col or + parsed.at.end_line != row.end_line or parsed.at.end_col != row.end_col or + prefix.end + parsed.end != row.location_end or + prefix.end + parsed.code_start != row.code_start) return error.InvalidLocationRows; + } else if (row.kind == .preview) { + if (index == 0 or saved[index - 1].kind != .match or !sameSavedLocation(saved[index - 1], row)) return error.InvalidLocationRows; + } else if (row.kind != .context or (row.path.len == 0 and (row.line != 0 or row.code_start != line.len))) return error.InvalidLocationRows; + } else { + const inline_row = row.code_start > row.location_end and row.code_start > 0 and line[row.code_start - 1] == '\t'; + const address_row = !inline_row and row.location_end > 0 and row.code_start == line.len; + const source_row = row.location_end == 0 and row.code_start == 0; + if (!inline_row and !address_row and !source_row) return error.InvalidLocationRows; + if (row.kind == .preview) { + if (!source_row or index == 0) return error.InvalidLocationRows; + const previous = saved[index - 1]; + if (previous.kind != .match or previous.location_end == 0 or previous.code_start != previous_line.len or previous_line[previous_line.len - 1] == '\t' or + !sameSavedLocation(previous, row)) return error.InvalidLocationRows; + } + if (address_row) { + if (index + 1 >= saved.len) return error.InvalidLocationRows; + const following = saved[index + 1]; + const expected: @TypeOf(row.kind) = if (row.kind == .match) .preview else .context; + if (following.kind != expected or following.code_start != 0 or following.location_end != 0 or + following.declaration != row.declaration or !sameSavedLocation(row, following)) return error.InvalidLocationRows; + } } const code_len = line.len - row.code_start; if (row.colors_b64.len > std.base64.standard.Encoder.calcSize(code_len)) return error.InvalidLocationRows; @@ -320,6 +341,8 @@ fn restoreLocationRows(gpa: std.mem.Allocator, content: []const u8, saved: []con out.* = .{ .kind = @enumFromInt(@intFromEnum(row.kind)), .declaration = row.declaration, + .mark_occurrence = row.mark_occurrence, + .source_column = row.source_column, .path = path, .at = .{ .line = row.line, .col = row.col, .end_line = row.end_line, .end_col = row.end_col }, .location_end = row.location_end, @@ -992,7 +1015,8 @@ pub fn restore(p: *Pardes, id: usize, src: dump.Pane) !*Pane { } else null; if (saved.location_rows.len != 0 and output == null) return error.InvalidLocationRows; - const location_rows = try restoreLocationRows(p.gpa, content, saved.location_rows); + const is_callstack = if (output) |state| std.meta.eql(state.from, Output.Origin{ .query = .callstack }) else false; + const location_rows = try restoreOutputLocationRows(p.gpa, content, saved.location_rows, is_callstack); errdefer locations.freeRows(p.gpa, location_rows); var mini: ?Mini.State = null; @@ -1707,9 +1731,16 @@ fn fillBody(dst: ?[]u8, pane: *Pane, f: *State, width: usize, record_wrap: bool) const row = if (context) @as(usize, @intCast(pane.wrap_line[i])) else body_line; const at = if (context) 0 else body_at; const text = if (row < total) sourceLine(pane, @intCast(row)) else ""; + var guide_buffer: [1024]u8 = undefined; + const guide = if (at > 0 and width > 1 and f.output != null and + std.meta.eql(f.output.?.from, Output.Origin{ .query = .callstack })) + locations.treeContinuation(text, &guide_buffer, width - 1) + else + ""; + const pad = displayWidth(guide); // Headers use one screen row per source row, preserving signatures // without allowing a long ancestor to consume the whole viewport. - const end = if (width == 0 or context) text.len else fitEnd(text, at, width); + const end = if (width == 0 or context) text.len else fitEnd(text, at, width - pad); const cut = if (pane.hscroll > 0 and width == 0) modal.graphemeStart(text, @min(@as(usize, @intCast(pane.hscroll)), text.len)) else @@ -1717,6 +1748,7 @@ fn fillBody(dst: ?[]u8, pane: *Pane, f: *State, width: usize, record_wrap: bool) if ((width > 0 or pane.context_rows > 0) and record_wrap) { pane.wrap_line[i] = @intCast(row); pane.wrap_col[i] = @intCast(cut); + pane.wrap_pad[i] = @intCast(pad); pane.wrap_n = @intCast(i + 1); } if (row < total) { @@ -1735,6 +1767,8 @@ fn fillBody(dst: ?[]u8, pane: *Pane, f: *State, width: usize, record_wrap: bool) } if (dst) |out| @memcpy(out[written..][0..prefix.len], prefix); written += prefix.len; + if (dst) |out| @memcpy(out[written..][0..guide.len], guide); + written += guide.len; const shown = text[cut..end]; if (dst) |out| @memcpy(out[written..][0..shown.len], shown); written += shown.len; @@ -1935,7 +1969,11 @@ pub fn recolorSyntax(p: *Pardes, s: *Surface, pane: *Pane, f: *State, r: pardes. } }.before); var c: usize = 0; - var screen_c: usize = 0; + const pad: usize = if (vr < pane.wrap_n) pane.wrap_pad[vr] else 0; + for (0..@min(pad, tw -| prefix_width)) |col| { + s.at(tx + @as(u16, @intCast(prefix_width + col)), body_y + vr).style.fg = .{ .rgb = p.bodyChrome().diagnostic_info }; + } + var screen_c: usize = pad; while (hs + c < limit and prefix_width + screen_c < tw) { const grapheme_end = @min(limit, modal.nextGrapheme(line, hs + c)); const cells = graphemeDisplayWidth(line[hs + c .. grapheme_end]); @@ -2218,8 +2256,8 @@ pub fn paintWordSelection( if (next.line == row) hi = @min(hi, next.at); const lo = @max(word_lo, here.at); if (hi <= lo) continue; - const c0 = @as(i32, prefix_width) + displayOffset(pane, row, here.at, lo); - const c1 = @as(i32, prefix_width) + displayEndOffset(pane, row, here.at, hi - 1); + const c0 = @as(i32, prefix_width) + here.pad + displayOffset(pane, row, here.at, lo); + const c1 = @as(i32, prefix_width) + here.pad + displayEndOffset(pane, row, here.at, hi - 1); var col = @max(@as(i32, prefix_width), c0); while (col <= c1 and col < @as(i32, tw)) : (col += 1) { const cell = s.at(tx + @as(u16, @intCast(col)), body_y + @as(u16, @intCast(vr))); diff --git a/src/Output.zig b/src/Output.zig index 9e194615..9ed33ebe 100644 --- a/src/Output.zig +++ b/src/Output.zig @@ -53,13 +53,14 @@ const RowDecoration = struct { location_end: usize = 0, prefix_end: usize = 0, declaration: bool = false, + guide_end: usize = 0, mark_start: usize = 0, mark_end: usize = 0, severity: enum { none, err, warning, info, hint } = .none, /// Nothing in the row is decorated: most rows of most files. pub fn plain(row: RowDecoration) bool { - return !row.declaration and row.location_end == 0 and row.prefix_end == 0 and row.mark_end <= row.mark_start; + return row.guide_end == 0 and !row.declaration and row.location_end == 0 and row.prefix_end == 0 and row.mark_end <= row.mark_start; } /// `chrome` is the theme's own (Pardes.bodyChrome): body paper changes @@ -68,6 +69,7 @@ const RowDecoration = struct { /// working it out takes the contrast searches' pow calls. pub fn styleAt(row: RowDecoration, chrome: *const pardes.ChromeTheme, byte: usize) ?pardes.CellStyle { if (row.plain()) return null; + if (byte < row.guide_end) return .{ .fg = .{ .rgb = chrome.diagnostic_info } }; if (row.declaration or byte < @max(row.location_end, row.prefix_end)) return .{ .fg = .{ .rgb = chrome.lineno } }; if (byte < row.mark_start or byte >= row.mark_end) return null; @@ -91,32 +93,38 @@ fn rowDecoration(output: ?State, line: []const u8) RowDecoration { pub fn decorateRow(output: ?State, line: []const u8, metadata: ?locations.Row) RowDecoration { const origin = (output orelse return .{}).from; + const callstack = std.meta.eql(origin, Origin{ .query = .callstack }); + const prefix = locations.treePrefix(if (callstack) line else ""); + const trimmed = line[prefix.end..]; + const indent = prefix.end; if (!traits(origin).locations) return .{}; - const target = locations.parse(line); + const target = if (callstack) locations.parseRaw(trimmed) else locations.parse(trimmed); const spot = if (metadata) |m| m.at else target.at; if (spot.line == 0) return .{}; var row: RowDecoration = .{ - .location_end = if (metadata) |m| m.location_end else target.end, - .prefix_end = if (metadata) |m| m.code_start else target.end, + .guide_end = indent, + .location_end = if (metadata) |m| m.location_end else indent + target.end, + .prefix_end = if (metadata) |m| m.code_start else indent + target.end, .declaration = if (metadata) |m| m.declaration else false, }; - const source_start = if (metadata) |m| m.code_start else target.code_start; + const source_start = if (metadata) |m| m.code_start else indent + target.code_start; if (source_start >= line.len) return row; if (metadata) |m| if (m.kind == .context) return row; const mark_occurrence = switch (origin) { .search => true, .cmd => |cmd| cmd == .Grep, .query => |kind| switch (kind) { - .definition, .declaration, .type_definition, .implementation, .references => true, + .definition, .declaration, .type_definition, .implementation, .references, .callstack => true, else => false, }, else => false, }; - if (mark_occurrence and spot.col > 0 and spot.end_line == spot.line and + if (mark_occurrence and (if (metadata) |m| m.mark_occurrence else !prefix.branch) and spot.col > 0 and spot.end_line == spot.line and spot.end_col >= spot.col) { - row.mark_start = source_start +| (spot.col - 1); - row.mark_end = @min(line.len, source_start +| spot.end_col); + const source_column = if (metadata) |m| m.source_column else 0; + row.mark_start = source_start +| ((spot.col - 1) -| source_column); + row.mark_end = @min(line.len, source_start +| (spot.end_col -| source_column)); } const is_diagnostic = switch (origin) { .query => |kind| kind == .diagnostics or kind == .workspace_diagnostics, @@ -135,6 +143,25 @@ pub fn decorateRow(output: ?State, line: []const u8, metadata: ?locations.Row) R return row; } +test "callstack guides and Look locations share result decoration" { + const from: State = .{ .from = .{ .query = .callstack } }; + const loc = rowDecoration(from, "└──┬ lib.rs:2:8-10 fn add() {"); + try std.testing.expectEqual(@as(usize, "└──┬ lib.rs:2:8-10".len), loc.location_end); + try std.testing.expect(!loc.declaration); + try std.testing.expect(!usesLocationsConfig(from.from)); + try std.testing.expect(!traits(from.from).jumps); + const call_line = " lib.rs:12:12-20 return calculate(value);"; + const call = rowDecoration(from, call_line); + try std.testing.expectEqualStrings("calculate", call_line[call.mark_start..call.mark_end]); + const reference = rowDecoration(.{ .from = .{ .query = .references } }, call_line[4..]); + try std.testing.expectEqual(reference.mark_start + 4, call.mark_start); + try std.testing.expectEqual(reference.mark_end + 4, call.mark_end); + try std.testing.expectEqual(reference.location_end + 4, call.location_end); + const tab_line = " tab.zig:4:9-11 \treturn run();"; + const tab_call = rowDecoration(from, tab_line); + try std.testing.expectEqualStrings("run", tab_line[tab_call.mark_start..tab_call.mark_end]); +} + test "result decoration follows source byte ranges and diagnostic provenance" { const row = rowDecoration(.{ .from = .search }, "src/a.rs:3:5-7 let abc = 1;"); try std.testing.expectEqualStrings("abc", "src/a.rs:3:5-7 let abc = 1;"[row.mark_start..row.mark_end]); @@ -237,6 +264,7 @@ pub fn traits(o: Origin) Traits { .cmd => |b| builtins.registry.outputTraits(b) orelse unreachable, .query => |k| switch (k) { .hover => .{ .name = config.hover_buffer }, + .callstack => .{ .name = "+Callstack", .steps = true, .locations = true }, // prose: an action list, a diff, a report about the backend .code_action, .format, .status, .explain => .{ .name = config.lsp_buffer }, .rename => .{ .name = config.search_buffer, .steps = true, .locations = true }, @@ -267,7 +295,8 @@ pub fn usesLocationsConfig(from: Origin) bool { const tr = traits(from); return tr.steps and !tr.commands and from != .pdf_links and !std.meta.eql(from, Origin{ .cmd = .Find }) and - !std.meta.eql(from, Origin{ .query = .completion }); + !std.meta.eql(from, Origin{ .query = .completion }) and + !std.meta.eql(from, Origin{ .query = .callstack }); } pub fn fileTraits(out: ?State) Traits { @@ -533,8 +562,11 @@ pub fn fillResults(p: *Pardes, id: usize, dir: []const u8, from: Origin, arg: [] return; } } - if (usesLocationsConfig(from)) { - const formatted = try locations.format(p, dir, content, anchor, true); + if (usesLocationsConfig(from) or std.meta.eql(from, Origin{ .query = .callstack })) { + const formatted = if (std.meta.eql(from, Origin{ .query = .callstack })) + try locations.formatCallstack(p, dir, content) + else + try locations.format(p, dir, content, anchor, true); p.gpa.free(result_content); result_content = formatted.content; result_rows = formatted.rows; @@ -863,7 +895,7 @@ pub fn openThemes(p: *Pardes, id: usize) !void { pub fn isWalkRow(file: *const File.State, row: usize, line: []const u8) bool { const state = file.output orelse return true; - if (usesLocationsConfig(state.from)) return isResultRow(file, row); + if (usesLocationsConfig(state.from) or std.meta.eql(state.from, Origin{ .query = .callstack })) return isResultRow(file, row); if (!std.meta.eql(state.from, Origin{ .cmd = .Themes })) return true; // Section labels are for reading, not stops in the command walk. return std.mem.startsWith(u8, std.mem.trimStart(u8, line, " \t"), comptime config.Runtime.findAction(.theme).?.word ++ " "); @@ -901,11 +933,14 @@ fn openStepped(p: *Pardes, id: usize, from: Origin, content: []u8) !void { fn helpContent(gpa: std.mem.Allocator, prefix: []const u8) ![]u8 { const full_header = "pardes builtins, and how to run each:\nSPC and its keys, a chord, a button, the\ntopbar - or the name, executed anywhere.\n\n"; const group_header = "pardes builtins under SPC"; + const calls_help = "\nCallstack: static caller chains,\nwith signatures and clickable call sites.\nCallers / Callees: one direction at a time.\n"; + const show_calls_help = prefix.len == 0 or std.mem.eql(u8, prefix, "l"); const language_footer = "\nlanguage keys (motions, not words):\n" ++ "gd gD gy gi gr goto: definition,\n" ++ " declaration, type-def,\n" ++ " implementation, refs\n" ++ + "gc Callstack\n" ++ "]d [d ]D [D diagnostics: next,\n" ++ " prev, last, first\n" ++ "= format (applies, one\n" ++ @@ -918,6 +953,7 @@ fn helpContent(gpa: std.mem.Allocator, prefix: []const u8) ![]u8 { full_header.len + language_footer.len else group_header.len + prefix.len * 2 + 2; + if (show_calls_help) len += calls_help.len; for (pardes.builtin_rows) |row| { // a path-less builtin filters as the empty path: in the full listing // (which starts with nothing) and out of every group @@ -948,6 +984,10 @@ fn helpContent(gpa: std.mem.Allocator, prefix: []const u8) ![]u8 { content[at] = '\n'; at += 1; } + if (show_calls_help) { + @memcpy(content[at..][0..calls_help.len], calls_help); + at += calls_help.len; + } if (prefix.len == 0) { @memcpy(content[at..][0..language_footer.len], language_footer); at += language_footer.len; @@ -963,7 +1003,7 @@ pub fn openHelp(p: *Pardes, id: usize, prefix: []const u8) !void { return openRead(p, id, .{ .cmd = .Help }, prefix, content); } -test "full Help renders every builtin row, then the language keys" { +test "full Help renders builtin rows, a call hierarchy guide, then language keys" { const content = try helpContent(std.testing.allocator, ""); defer std.testing.allocator.free(content); @@ -974,17 +1014,22 @@ test "full Help renders every builtin row, then the language keys" { for (pardes.builtin_rows) |row| try std.testing.expectEqualStrings(row.line, lines.next() orelse return error.MissingBuiltinHelpRow); - // ...and after the last row, the language-keys section: the one part of - // the keymap no builtin row can carry, closing the page. + // The short call guide disambiguates the three related commands. + try std.testing.expectEqualStrings("", lines.next() orelse return error.MissingCallHelp); + try std.testing.expectEqualStrings("Callstack: static caller chains,", lines.next() orelse return error.MissingCallHelp); + try std.testing.expectEqualStrings("with signatures and clickable call sites.", lines.next() orelse return error.MissingCallHelp); + try std.testing.expectEqualStrings("Callers / Callees: one direction at a time.", lines.next() orelse return error.MissingCallHelp); + // The language keys close the page. try std.testing.expectEqualStrings("", lines.next() orelse return error.MissingLanguageKeys); try std.testing.expectEqualStrings("language keys (motions, not words):", lines.next() orelse return error.MissingLanguageKeys); try std.testing.expect(std.mem.indexOf(u8, body, "\ngd gD gy gi gr goto: definition,\n") != null); - // the group view stays a pure filter: no footer under a prefix + // The language group also explains call commands, without the motion footer. const group = try helpContent(std.testing.allocator, "l"); defer std.testing.allocator.free(group); try std.testing.expect(std.mem.indexOf(u8, group, "language keys") == null); + try std.testing.expect(std.mem.indexOf(u8, group, "Callstack: static caller chains") != null); } pub fn openConfig(p: *Pardes, id: usize) !void { diff --git a/src/body_layer.zig b/src/body_layer.zig index b24bd6ed..2aa8e5f8 100644 --- a/src/body_layer.zig +++ b/src/body_layer.zig @@ -113,8 +113,8 @@ fn paintSourceSelection(p: *Pardes, s: *Surface, pane: *Pane, r: Rect, rows: []c const lo = @max(start, row.lo); const hi = @min(end, row.hi); if (lo >= hi) continue; - var col = prefix + @as(i32, @intCast(panes.File.rawDisplayCol(line[start..], lo - start))); - const last = if (row.to_edge and hi == end) @as(i32, width) else prefix + @as(i32, @intCast(panes.File.rawDisplayCol(line[start..], hi - start))); + var col = prefix + source.pad + @as(i32, @intCast(panes.File.rawDisplayCol(line[start..], lo - start))); + const last = if (row.to_edge and hi == end) @as(i32, width) else prefix + source.pad + @as(i32, @intCast(panes.File.rawDisplayCol(line[start..], hi - start))); while (col < last and col < width) : (col += 1) { const cell = s.at(tx + @as(u16, @intCast(col)), body_y + @as(u16, @intCast(visible))); cell.default = false; @@ -399,14 +399,14 @@ pub fn renderBody(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane (if (pane.file != null) panes.File.displayOffset(pane, w.line, w.at, bnd.lo_col) else - panes.File.lineDisplayOffset(visible_line, @intCast(@max(0, w.at)), @intCast(@max(0, bnd.lo_col)))) + vpfx + panes.File.lineDisplayOffset(visible_line, @intCast(@max(0, w.at)), @intCast(@max(0, bnd.lo_col)))) + vpfx + w.pad else - vpfx; + vpfx + w.pad; const cend: i32 = if (w.line == bnd.hi_row and @as(usize, @intCast(@max(0, bnd.hi_col))) < past_view) (if (pane.file != null) panes.File.displayEndOffset(pane, w.line, w.at, bnd.hi_col) else - panes.File.lineDisplayEndOffset(visible_line, @intCast(@max(0, w.at)), @intCast(@max(0, bnd.hi_col)))) + vpfx + panes.File.lineDisplayEndOffset(visible_line, @intCast(@max(0, w.at)), @intCast(@max(0, bnd.hi_col)))) + vpfx + w.pad else @as(i32, tw) - 1; var col: i32 = @max(cstart, vpfx); @@ -432,7 +432,7 @@ pub fn renderBody(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane modal.lineSlice(body, @intCast(@max(0, cw.row))), @intCast(@max(0, cw.at)), @intCast(@max(0, sr.col)), - )) + vpfx; + )) + vpfx + cw.pad; if (crow >= pane.tag_rows and crow < @as(i32, body_bottom) and ccol >= vpfx and ccol < tw) { const cell = s.at(tx + @as(u16, @intCast(ccol)), body_y + @as(u16, @intCast(crow - pane.tag_rows))); cell.default = false; @@ -455,7 +455,7 @@ pub fn renderBody(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane const row: i32 = @intCast(pos.row); const wp = pane.wrapRow(row, @intCast(pos.col)); const cx = if (pane.file != null) - @as(i32, panes.File.gutterWidth(pane)) + panes.File.displayOffset(pane, row, wp.at, @intCast(pos.col)) + @as(i32, panes.File.gutterWidth(pane)) + wp.pad + panes.File.displayOffset(pane, row, wp.at, @intCast(pos.col)) else panes.File.lineDisplayOffset(modal.lineSlice(flat, pos.row), @intCast(@max(0, wp.at)), pos.col); if (wp.row >= 0 and wp.row < body_h and cx >= 0 and cx < tw) @@ -478,20 +478,20 @@ pub fn renderBody(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane // Off the view, the cursor is not measured (its column may be // millions of bytes along a line whose start is shown). if (cwp.row >= 0 and prow < body_bottom and !pastView(pane, body, crow, cwp.row, cwp.at, ccol, tw)) { - // Files store source-byte columns; the Surface stores display - // cells, so account for every expanded tab before the cursor. - const cx = if (pane.file != null) - @as(i32, panes.File.gutterWidth(pane)) + panes.File.displayOffset(pane, crow, cwp.at, ccol) - else if (pane.body.cur_pinned) - panes.File.lineDisplayOffset( - modal.lineSlice(body, @intCast(@max(0, cwp.row))), - @intCast(@max(0, cwp.at)), - @intCast(@max(0, ccol)), - ) - else - ccol; - if (prow >= pane.tag_rows and cx >= 0 and prow < body_bottom and cx < tw) - s.cursor = .{ .x = tx + @as(u16, @intCast(cx)), .y = body_y + @as(u16, @intCast(prow - pane.tag_rows)), .bar = pane.body.mode == .insert }; + // Files store source-byte columns; the Surface stores display + // cells, so account for every expanded tab before the cursor. + const cx = if (pane.file != null) + @as(i32, panes.File.gutterWidth(pane)) + cwp.pad + panes.File.displayOffset(pane, crow, cwp.at, ccol) + else if (pane.body.cur_pinned) + panes.File.lineDisplayOffset( + modal.lineSlice(body, @intCast(@max(0, cwp.row))), + @intCast(@max(0, cwp.at)), + @intCast(@max(0, ccol)), + ) + else + ccol; + if (prow >= pane.tag_rows and cx >= 0 and prow < body_bottom and cx < tw) + s.cursor = .{ .x = tx + @as(u16, @intCast(cx)), .y = body_y + @as(u16, @intCast(prow - pane.tag_rows)), .bar = pane.body.mode == .insert }; } } else if (panes.terminal.visibleCursor(pane)) |cur| { if (cur.y + pane.tag_rows < body_bottom and cur.x < tw) diff --git a/src/builtins.zig b/src/builtins.zig index ef769b48..f73c5982 100644 --- a/src/builtins.zig +++ b/src/builtins.zig @@ -236,8 +236,8 @@ pub const registry = struct { // are the default .toggle, .transition, .scene, .dump_dir, .choice, .lift, .shader_animation, .motion, .shell => false, .theme, .font, .tagline_size, .window_opacity, .window_blur, .message_ms, .shader, .inactive_dim, .grip_width => true, - // bare, it says the width (exec.applySettingBuiltin) - .tab => false, + // bare, it says the current value (exec.applySettingBuiltin) + .tab, .callstack_depth => false, }; unreachable; } @@ -1839,6 +1839,7 @@ pub const Forward = struct { /// Select the next Look location across panes; Enter opens it. pub const LookNext = struct { + pub const quiet = true; pub fn run(c: Ctx) void { look.lookWalk(c.p, 1); } @@ -1846,6 +1847,7 @@ pub const LookNext = struct { /// Select the previous Look location across panes; Enter opens it. pub const LookPrev = struct { + pub const quiet = true; pub fn run(c: Ctx) void { look.lookWalk(c.p, -1); } @@ -1952,6 +1954,13 @@ pub const WsDiagnostics = struct { } }; +/// Show outermost callers first, with signatures and call sites (gc). +pub const Callstack = struct { + pub fn run(c: Ctx) void { + c.p.lspRequest(c.id, .callstack, ""); + } +}; + /// List the callers of the function under the cursor. pub const Callers = struct { pub fn run(c: Ctx) void { diff --git a/src/colors.zig b/src/colors.zig index 2dcb906a..379d1301 100644 --- a/src/colors.zig +++ b/src/colors.zig @@ -126,9 +126,11 @@ test "every faithful port meets pardes's chrome floors in its own colours, with } test "a derived separator or tint keeps the theme's own when it already stands off" { - const forge = &themes[for (themes[0..native_count], 0..) |t, i| { - if (std.mem.eql(u8, t.name, "forge")) break i; - } else unreachable]; + const forge = &themes[ + for (themes[0..native_count], 0..) |t, i| { + if (std.mem.eql(u8, t.name, "forge")) break i; + } else unreachable + ]; const chrome = ChromeTheme.fromTheme(forge); try std.testing.expectEqual(forge.border.?, chrome.border); // forge's own tint is 1.23:1 off its tag: pushed on the way it leans. @@ -1075,7 +1077,7 @@ test "render uses target content colors while chrome is in flight" { Color{ .rgb = source_chrome.tag_bg }, surface.at(0, 0).style.bg, ); - const topbar_cell = surface.at(0, 0); + const topbar_cell = surface.at(@import("pardes.zig").TAG_TEXT_INSET, 0); try std.testing.expect(!std.mem.eql(u8, topbar_cell.grapheme(), " ")); try std.testing.expectEqual(FontRole.tagline, topbar_cell.style.font_role); const r = p.rects[0]; diff --git a/src/config.zig b/src/config.zig index fb34b746..50009660 100644 --- a/src/config.zig +++ b/src/config.zig @@ -43,6 +43,7 @@ pub const leader_path = paths: { .WsDiagnostics = "lD", .Lspinfo = "li", .Lspwhy = "lw", + .Callstack = "lb", .Callers = "lc", .Callees = "lC", .Supertypes = "lt", @@ -67,6 +68,9 @@ pub const leader_path = paths: { .Putall = null, .Incl = null, .Tab = null, + .CallstackDepth = null, + .CallstackLayout = null, + .CallstackCorners = null, .Zerox = null, .ClipYank = "y", .ClipYankMain = "Y", @@ -580,7 +584,8 @@ pub const goto_line_down: []const Chord = &.{.{ .cp = 'j' }}; pub const goto_line_up: []const Chord = &.{.{ .cp = 'k' }}; pub const goto_column: []const Chord = &.{.{ .cp = '|' }}; pub const goto_view_top: []const Chord = &.{.{ .cp = 't' }}; -pub const goto_view_center: []const Chord = &.{.{ .cp = 'c' }}; +// gc opens Callstack; it no longer moves the cursor to the viewport center. +pub const goto_view_center: []const Chord = &.{}; pub const goto_view_bottom: []const Chord = &.{.{ .cp = 'b' }}; pub const goto_last_modification: []const Chord = &.{.{ .cp = '.' }}; pub const goto_word: []const Chord = &.{.{ .cp = 'w' }}; @@ -591,6 +596,7 @@ pub const goto_declaration: []const Chord = &.{.{ .cp = 'D' }}; pub const goto_type_definition: []const Chord = &.{.{ .cp = 'y' }}; pub const goto_implementation: []const Chord = &.{.{ .cp = 'i' }}; pub const goto_references: []const Chord = &.{.{ .cp = 'r' }}; +pub const goto_callstack: []const Chord = &.{.{ .cp = 'c' }}; pub const match_bracket: []const Chord = &.{.{ .cp = 'm' }}; pub const match_inside = 'i'; @@ -835,6 +841,9 @@ pub const Runtime = struct { /// acme's Tab: a tab's width in cells, in every pane (config.tab_now /// is what the drawing and the column arithmetic read). tab: u16 = tab_width, + callstack_layout: CallstackLayout = .stacked, + callstack_corners: CallstackCorners = .rounded, + callstack_depth: u8 = @import("lsp/lsp.zig").callstack_default_depth, pub const ShaderAnimation = enum { off, on, always }; pub const Placement = enum { acme, pardes }; @@ -845,8 +854,10 @@ pub const Runtime = struct { pub const Pager = enum { pardes, off }; pub const TermImages = enum { real, petscii }; pub const JumpScope = enum { file, all }; + pub const CallstackLayout = enum { @"inline", stacked }; + pub const CallstackCorners = @import("lsp/lsp.zig").CallstackCorners; /// A setting that is one of a few words, each an enum field of Runtime. - pub const Choice = enum { placement, boot_shell, look_word, dir_look, diff_look, pager, term_images, jump_scope }; + pub const Choice = enum { placement, boot_shell, look_word, dir_look, diff_look, pager, term_images, jump_scope, callstack_layout, callstack_corners }; /// shadow: a soft drop shadow. rim: a light hairline along the top of /// the focused pane's tag rows. auto: a shadow on a light page; on a @@ -1034,6 +1045,7 @@ pub const Runtime = struct { inactive_dim, grip_width, tab, + callstack_depth, transition: animation.Transition, scene: Scene, /// A Shadertoy file into the post chain or out of it; `off` empties @@ -1118,6 +1130,9 @@ pub const Runtime = struct { .{ .word = "PagerColor", .action = .{ .toggle = .pager_color }, .doc = "A +Pager keeps its program's colours, on or off; for the next text paged." }, .{ .word = "TermImages", .action = .{ .choice = .term_images }, .doc = "How a new terminal draws its program's kitty graphics: real, as pixels where it can, or petscii, as glyph art." }, .{ .word = "JumpScope", .action = .{ .choice = .jump_scope }, .doc = "What Back and Forward keep to: file, the focused pane's file until it runs out that way, or all, every place in order." }, + .{ .word = "CallstackLayout", .action = .{ .choice = .callstack_layout }, .doc = "Callstack snippets below their locations (stacked, the default) or beside them (inline); bare, it switches layouts. Applies to the next Callstack query." }, + .{ .word = "CallstackCorners", .action = .{ .choice = .callstack_corners }, .doc = "Callstack tree corners: rounded (the default) or square; bare, it switches styles. Applies to the next Callstack query." }, + .{ .word = "CallstackDepth", .action = .callstack_depth, .doc = "Caller levels collected by Callstack, 1 through 64; default 8. Bare, it says the current limit." }, .{ .word = "Tab", .action = .tab, .doc = "A tab's width in cells, 1 through 16, in every pane; bare, it says the width." }, }; @@ -1319,6 +1334,12 @@ pub const Runtime = struct { if (percent < 50 or percent > 300) return false; state.grip_width = percent; }, + .callstack_depth => { + const text = std.mem.trim(u8, argument orelse return false, " \t\r\n"); + const depth = std.fmt.parseInt(u8, text, 10) catch return false; + if (depth < 1 or depth > @import("lsp/lsp.zig").callstack_max_depth) return false; + state.callstack_depth = depth; + }, .tab => { const text = std.mem.trim(u8, argument orelse return false, " \t\r\n"); const width = std.fmt.parseInt(u16, text, 10) catch return false; @@ -1361,6 +1382,7 @@ pub const Runtime = struct { .inactive_dim, .window_opacity, .window_blur => "0-100 (a percentage)", .grip_width => "50-300 (a percentage)", .tab => "1-16 (cells)", + .callstack_depth => "1-64 (levels)", .tagline_size => std.fmt.comptimePrint("{d}-{d} (a percentage)", .{ tagline_percent_min, tagline_percent_max }), .message_ms => std.fmt.comptimePrint("0-{d} (milliseconds)", .{message_ms_max}), .shell => "a path of at most 255 bytes; bare, $SHELL, else /bin/sh", @@ -1523,6 +1545,7 @@ pub const Runtime = struct { try out.print("# {s} unsupported\n", .{setting.word}), .motion => try out.print("{s} {s}\n", .{ setting.word, @tagName(state.motion) }), .inactive_dim => try out.print("{s} {d}\n", .{ setting.word, state.inactive_dim }), + .callstack_depth => try out.print("{s} {d}\n", .{ setting.word, state.callstack_depth }), .tab => try out.print("{s} {d}\n", .{ setting.word, state.tab }), .grip_width => if (setting.enabled(context.capabilities)) try out.print("{s} {d}\n", .{ setting.word, state.grip_width }) @@ -1816,11 +1839,14 @@ pub const Runtime = struct { .pager => "off", .term_images => "petscii", .jump_scope => "all", + .callstack_layout => "inline", + .callstack_corners => "square", }, .lift => "rim", .motion => "playful", .inactive_dim => "35", .grip_width => "200", + .callstack_depth => "16", .tab => "8", else => null, }; @@ -1892,11 +1918,14 @@ pub const Runtime = struct { .pager => "Pager off\n", .term_images => "TermImages petscii\n", .jump_scope => "JumpScope all\n", + .callstack_layout => "CallstackLayout inline\n", + .callstack_corners => "CallstackCorners square\n", }, .lift => "Lift rim\n", .motion => "Motion playful\n", .inactive_dim => "InactiveDim 35\n", .grip_width => "GripWidth 200\n", + .callstack_depth => "CallstackDepth 16\n", .tab => "Tab 8\n", .theme, .font => unreachable, }; @@ -2474,3 +2503,16 @@ test "reference.typ's #fstree is the tree the session serves, file for file" { }; if (drift) return error.FsTreeDrift; } + +test "CallstackDepth is bounded and keeps the last valid runtime limit" { + var state: Runtime = .{}; + try std.testing.expectEqual(@as(u8, 8), state.callstack_depth); + for ([_][]const u8{ "1", "8", "16", "64" }) |value| { + try std.testing.expect(Runtime.apply(&state, Runtime.find("CallstackDepth").?, value)); + try std.testing.expectEqual(try std.fmt.parseInt(u8, value, 10), state.callstack_depth); + } + for ([_][]const u8{ "0", "65", "256", "-1", "eight", "" }) |value| { + try std.testing.expect(!Runtime.apply(&state, Runtime.find("CallstackDepth").?, value)); + try std.testing.expectEqual(@as(u8, 64), state.callstack_depth); + } +} diff --git a/src/draw.zig b/src/draw.zig index 9fcbb15f..b35d55e8 100644 --- a/src/draw.zig +++ b/src/draw.zig @@ -412,15 +412,15 @@ fn recede(p: *Pardes, s: *Surface, id: usize, amount: f32, focused: bool) void { } } const body = &s.body_layers[id]; - if (body.rows != 0) for (body.cells[0..@as(usize, body.cols) * body.rows]) |*cell| { + if (body.rows != 0) for (body.cells[0 .. @as(usize, body.cols) * body.rows]) |*cell| { if (!(focused and selected(cell, th.sel_bg))) fadeStyle(&cell.style, th.fg, th.bg, palette, amount, &memo); }; if (focused) return; const tag = &s.tag_layers[id]; - if (tag.rows != 0) for (tag.cells[0..@as(usize, tag.cols) * tag.rows]) |*cell| fadeStyle(&cell.style, chrome.tag_fg, tag.bg, palette, amount, &memo); + if (tag.rows != 0) for (tag.cells[0 .. @as(usize, tag.cols) * tag.rows]) |*cell| fadeStyle(&cell.style, chrome.tag_fg, tag.bg, palette, amount, &memo); for (0..Pane.Notices.max) |i| { const notice = &s.tag_layers[NOTICE_LAYER_BASE + id * Pane.Notices.max + i]; - if (notice.rows != 0) for (notice.cells[0..@as(usize, notice.cols) * notice.rows]) |*cell| fadeStyle(&cell.style, chrome.tag_fg, notice.bg, palette, amount, &memo); + if (notice.rows != 0) for (notice.cells[0 .. @as(usize, notice.cols) * notice.rows]) |*cell| fadeStyle(&cell.style, chrome.tag_fg, notice.bg, palette, amount, &memo); } } @@ -978,7 +978,12 @@ pub fn paintHeaders(p: *Pardes, s: *Surface, arena: std.mem.Allocator) !void { if (s.region(.workspace_tag, Region.none)) |region| { const top = if (p.header_focus and p.header_column == null) p.header_top else 0; const layer = &s.tag_layers[MAX_PANES + MAX_COLS]; - try renderHeaderLayer(p, arena, layer, .workspace, 0, region.rect, tagline.topbar(p), top, chrome.tag_bg, chrome.tag_fg); + var viewport = region.rect; + const inset = @min(TAG_TEXT_INSET, viewport.w); + s.fill(viewport.x, viewport.y, inset, viewport.h, .{ .bg = .{ .rgb = chrome.tag_bg }, .fg = .{ .rgb = chrome.tag_fg }, .font_role = .tagline }); + viewport.x += inset; + viewport.w -= inset; + try renderHeaderLayer(p, arena, layer, .workspace, 0, viewport, tagline.topbar(p), top, chrome.tag_bg, chrome.tag_fg); joinHeaderRows(s, layer, chrome.tag_fg); } const column_rows = p.columnBarHeight(); @@ -1348,8 +1353,7 @@ pub fn paintPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pa const at = modal.positionAt(shown.text, shown.fromReal(@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) caret: { + } else if (pane.focus == .tag and pane.prompt == .none) caret: { const real = modal.offsetAt(whole, .{ .row = @intCast(@max(0, pane.tag.cur_row)), .col = @intCast(@max(0, pane.tag.cur_col)) }); const at = modal.positionAt(shown.text, shown.fromReal(real)); if (at.row < top or at.row >= top + rows) break :caret null; @@ -2392,7 +2396,7 @@ test "a pane focus reaches brightens on the same spring the one it leaves dims o // The file's first glyph's ink, in whichever form its body has. fn of(s: *const Surface) [3]u8 { const body = &s.body_layers[0]; - const cells = if (body.rows != 0) body.cells[0..@as(usize, body.cols) * body.rows] else s.cells; + const cells = if (body.rows != 0) body.cells[0 .. @as(usize, body.cols) * body.rows] else s.cells; for (cells) |cell| if (!cell.default and cell.len == 1 and cell.text[0] == 's' and cell.style.font_role == .body) return switch (cell.style.fg) { .rgb => |rgb| rgb, else => .{ 0, 0, 0 }, diff --git a/src/dump.zig b/src/dump.zig index 201f5bf2..402918c4 100644 --- a/src/dump.zig +++ b/src/dump.zig @@ -56,7 +56,7 @@ pub fn outPath(buf: *[1024:0]u8, dir_setting: []const u8) ?[:0]const u8 { const ds = es.getDaySeconds(); var stamp: [32]u8 = undefined; const base = std.fmt.bufPrint(&stamp, "pardes-{d:0>4}{d:0>2}{d:0>2}-{d:0>2}{d:0>2}{d:0>2}", .{ - yd.year, md.month.numeric(), @as(u8, md.day_index) + 1, + yd.year, md.month.numeric(), @as(u8, md.day_index) + 1, ds.getHoursIntoDay(), ds.getMinutesIntoHour(), ds.getSecondsIntoMinute(), }) catch return null; return uniqueIn(buf, dir, base); @@ -194,6 +194,8 @@ pub const Terminal = struct { }; pub const LocationRow = struct { + mark_occurrence: bool = true, + source_column: usize = 0, kind: enum { match, context, preview }, declaration: bool = false, path: []const u8, diff --git a/src/edit.zig b/src/edit.zig index b2909d87..5dbce0bf 100644 --- a/src/edit.zig +++ b/src/edit.zig @@ -241,8 +241,8 @@ pub fn capturePointerSelection(p: *Pardes, pane: *Pane, slot: usize) !void { if (raw) next = .{ .line = source.line + 1, .at = 0 }; const end = if (next.line == source.line) @min(line.len, @as(usize, @intCast(@max(0, next.at)))) else line.len; const start: usize = @intCast(@max(0, source.at)); - const lo = @min(end, panes.File.byteAtDisplayFrom(line, start, @intCast(@max(0, left - prefix)))); - const at = @min(end, panes.File.byteAtDisplayFrom(line, start, @intCast(@max(0, right - prefix)))); + const lo = @min(end, panes.File.byteAtDisplayFrom(line, start, @intCast(@max(0, left - prefix - source.pad)))); + const at = @min(end, panes.File.byteAtDisplayFrom(line, start, @intCast(@max(0, right - prefix - source.pad)))); row.* = .{ .row = source.line, .lo = lo, diff --git a/src/exec.zig b/src/exec.zig index 2a6bd55c..d03a4a48 100644 --- a/src/exec.zig +++ b/src/exec.zig @@ -140,7 +140,7 @@ pub fn operandAt(p: *Pardes, pane: *Pane, clicked: Pane.Sel, borrow: bool, for_l &pane.body, wrapped.line, wrapped.at, - clicked.c0 - (if (pane.file != null) @as(i32, panes.File.gutterWidth(pane)) else 0), + clicked.c0 - wrapped.pad - (if (pane.file != null) @as(i32, panes.File.gutterWidth(pane)) else 0), ) else clicked.c0; @@ -214,9 +214,9 @@ pub fn operandAt(p: *Pardes, pane: *Pane, clicked: Pane.Sel, borrow: bool, for_l const last = pane.wrapRow(row, hi - 1); if (first.row < 0 or last.row < 0) return result; expanded.r0 = first.row + @as(i32, pane.tag_rows); - expanded.c0 = @as(i32, panes.File.gutterWidth(pane)) + panes.File.displayOffset(pane, row, first.at, 0); + expanded.c0 = @as(i32, panes.File.gutterWidth(pane)) + first.pad + panes.File.displayOffset(pane, row, first.at, 0); expanded.r1 = last.row + @as(i32, pane.tag_rows); - expanded.c1 = @as(i32, panes.File.gutterWidth(pane)) + panes.File.displayEndOffset(pane, row, last.at, hi - 1); + expanded.c1 = @as(i32, panes.File.gutterWidth(pane)) + last.pad + panes.File.displayEndOffset(pane, row, last.at, hi - 1); } else { const shown = if (raw) raw_line else line; expanded.c0 = 0; @@ -242,9 +242,9 @@ pub fn operandAt(p: *Pardes, pane: *Pane, clicked: Pane.Sel, borrow: bool, for_l const last = pane.wrapRow(row, hi - 1); if (first.row >= 0 and last.row >= 0) { expanded.r0 = first.row + @as(i32, pane.tag_rows); - expanded.c0 = @as(i32, panes.File.gutterWidth(pane)) + panes.File.displayOffset(pane, row, first.at, lo); + expanded.c0 = @as(i32, panes.File.gutterWidth(pane)) + first.pad + panes.File.displayOffset(pane, row, first.at, lo); expanded.r1 = last.row + @as(i32, pane.tag_rows); - expanded.c1 = @as(i32, panes.File.gutterWidth(pane)) + panes.File.displayEndOffset(pane, row, last.at, hi - 1); + expanded.c1 = @as(i32, panes.File.gutterWidth(pane)) + last.pad + panes.File.displayEndOffset(pane, row, last.at, hi - 1); } result.preview = expanded; result.expanded = expanded; @@ -1120,6 +1120,12 @@ pub fn applySettingBuiltin(p: *Pardes, setting: config.Runtime.Setting, arg: ?[] } if (!p.settings.apply(setting, want)) p.reportFailure(p.active, "Shell: takes " ++ comptime config.Runtime.takes(.shell).?); }, + .callstack_depth => if (arg == null) { + var said: [40]u8 = undefined; + return p.setMessage(p.active, std.fmt.bufPrint(&said, "CallstackDepth {d}", .{p.settings.callstack_depth}) catch "CallstackDepth"); + } else if (!p.settings.apply(setting, arg)) { + p.reportFailure(p.active, "CallstackDepth: takes " ++ comptime config.Runtime.takes(.callstack_depth).?); + }, // Bare, it says the width, as acme's Tab does. .tab => if (arg == null) { var said: [32]u8 = undefined; diff --git a/src/host_io.zig b/src/host_io.zig index 7314affc..a90c903d 100644 --- a/src/host_io.zig +++ b/src/host_io.zig @@ -136,6 +136,8 @@ pub const Lsp = struct { /// One language query, owned by the worker that runs it. pub const Job = struct { + callstack_depth: u8 = pardes.lsp.callstack_default_depth, + callstack_corners: pardes.lsp.CallstackCorners = .rounded, id: u32, kind: pardes.lsp.Kind, offset: u32, @@ -178,6 +180,8 @@ pub const Lsp = struct { const root = try gpa.dupe(u8, filesystem.localPath(declared_root) orelse declared_root); errdefer gpa.free(root); job.* = .{ + .callstack_depth = core.settings.callstack_depth, + .callstack_corners = core.settings.callstack_corners, .id = req.id, .kind = req.kind, .offset = req.offset, @@ -234,6 +238,8 @@ pub const Lsp = struct { .arg = job.arg, .root = job.root, .others = job.others, + .callstack_depth = job.callstack_depth, + .callstack_corners = job.callstack_corners, }, &out.writer) catch { deliver(ctx, job.id, null); return; @@ -250,6 +256,8 @@ pub const Lsp = struct { const core = try pardes.Pardes.init(gpa, .{ .tty_only = true }); defer core.deinit(); + core.settings.callstack_depth = 16; + core.settings.callstack_corners = .square; var needle: [6]u8 = "needle".*; const job = try snapshot(gpa, core, .{ .id = 7, @@ -260,6 +268,10 @@ pub const Lsp = struct { }); defer job.free(gpa); + core.settings.callstack_depth = 2; + core.settings.callstack_corners = .rounded; + try std.testing.expectEqual(pardes.lsp.CallstackCorners.square, job.callstack_corners); + try std.testing.expectEqual(@as(u8, 16), job.callstack_depth); try std.testing.expectEqual(@as(u32, 7), job.id); try std.testing.expectEqual(pardes.lsp.Kind.status, job.kind); try std.testing.expectEqualStrings("needle", job.arg); diff --git a/src/layout.zig b/src/layout.zig index a2211dfd..40bce75a 100644 --- a/src/layout.zig +++ b/src/layout.zig @@ -266,6 +266,28 @@ pub fn setColumnWeights(p: *Pardes, col: usize, heights: *const [MAX_PANES]u16) } } +/// Give a newly opened report enough rows to read, borrowing only space +/// above the other panes' usable minima. Keep their tags and bodies visible. +pub fn givePaneRows(p: *Pardes, id: usize, wanted: u16, context: usize) void { + const at = findPane(p, id) orelse return; + compute(p); + var heights: [MAX_PANES]u16 = @splat(0); + for (p.col_panes[at.col][0..p.col_n[at.col]]) |other| heights[other] = p.rects[other].h; + var missing = wanted -| heights[id]; + for (p.col_panes[at.col][0..p.col_n[at.col]]) |other| { + if (other == id or p.panes[other].?.collapsed) continue; + const body_rows: u16 = if (other == context) 6 else 3; + const minimum = @max(minRows(p, other), p.panes[other].?.tag_rows + body_rows); + const take = @min(missing, heights[other] -| minimum); + heights[other] -= take; + heights[id] += take; + missing -= take; + if (missing == 0) break; + } + setColumnWeights(p, at.col, &heights); + p.sync(); +} + pub fn applyRowSplit(p: *Pardes, cc: usize, k: usize, cur_y: u16) void { if (k + 1 >= p.col_n[cc]) return; const a = p.panes[p.col_panes[cc][k]] orelse return; diff --git a/src/locations.zig b/src/locations.zig index 7755f6fd..745393e5 100644 --- a/src/locations.zig +++ b/src/locations.zig @@ -16,6 +16,8 @@ pub fn isContextLine(line: []const u8) bool { pub const Row = struct { kind: enum { match, context, preview }, declaration: bool = false, + mark_occurrence: bool = true, + source_column: usize = 0, path: []u8, at: look.Spot, location_end: usize, @@ -34,7 +36,7 @@ pub fn freeRows(gpa: std.mem.Allocator, rows: []Row) void { pub fn equalRows(a: []const Row, b: []const Row) bool { if (a.len != b.len) return false; for (a, b) |left, right| { - if (left.kind != right.kind or left.declaration != right.declaration or !std.meta.eql(left.at, right.at) or + if (left.kind != right.kind or left.declaration != right.declaration or left.mark_occurrence != right.mark_occurrence or left.source_column != right.source_column or !std.meta.eql(left.at, right.at) or left.location_end != right.location_end or left.code_start != right.code_start or !std.mem.eql(u8, left.path, right.path) or !std.mem.eql(u8, left.colors, right.colors)) return false; } @@ -119,7 +121,8 @@ pub fn parse(line: []const u8) Parsed { return parseRaw(line); } -fn parseRaw(line: []const u8) Parsed { +/// Native producer rows have one separator byte before untouched source. +pub fn parseRaw(line: []const u8) Parsed { var at: usize = 1; while (at < line.len) : (at += 1) { if (line[at] != ':' or at + 1 == line.len or !std.ascii.isDigit(line[at + 1])) continue; @@ -148,6 +151,8 @@ const Pending = struct { original: ?usize, hidden: bool = false, declaration: bool = false, + mark_occurrence: bool = true, + source_column: usize = 0, depth: usize = 0, colors: []const u8 = &.{}, @@ -174,6 +179,174 @@ pub fn sourceText(p: *pardes.Pardes, arena: std.mem.Allocator, dir: []const u8, return .{ .path = lexical, .bytes = arena.dupe(u8, bytes) catch return null }; } +/// Byte boundary after the guides in a call tree, independent of source indentation. +pub fn treePrefix(line: []const u8) struct { end: usize, branch: bool } { + var at: usize = 0; + while (at < line.len) { + for ([_][]const u8{ "╰──┬ ", "├──╮ ", "╰──╮ ", "├─── ", "╰─── ", "├──┬ ", "└──┬ ", "└─── " }) |branch| { + if (std.mem.startsWith(u8, line[at..], branch)) return .{ .end = at + branch.len, .branch = true }; + } + if (std.mem.startsWith(u8, line[at..], "├─ ") or std.mem.startsWith(u8, line[at..], "└─ ") or std.mem.startsWith(u8, line[at..], "╰─ ")) + return .{ .end = at + "└─ ".len, .branch = false }; + if (std.mem.startsWith(u8, line[at..], "│")) { + at += "│".len; + } else if (line[at] == ' ') { + at += 1; + } else break; + } + return .{ .end = at, .branch = false }; +} + +/// The same tree columns carried across a soft-wrapped display row. This is +/// presentation only: source bytes and Look addresses remain untouched. +pub fn treeContinuation(line: []const u8, buffer: []u8, max_cells: usize) []const u8 { + const prefix = line[0..treePrefix(line).end]; + var out: std.Io.Writer = .fixed(buffer); + var it = (std.unicode.Utf8View.init(prefix) catch return "").iterator(); + var cells: usize = 0; + var end: usize = 0; + while (it.nextCodepoint()) |cp| { + if (cells >= max_cells) break; + out.writeAll(if (cp == '│' or cp == '├' or cp == '┬' or cp == '╮') "│" else " ") catch break; + cells += 1; + if (cp != ' ') end = out.buffered().len; + } + if (end == 0) return ""; + // Keep one cell between the continuation and the wrapped source text. + if (end < out.buffered().len) end += 1; + return out.buffered()[0..end]; +} + +/// Enrich caller nodes on the UI thread, using the same source/declaration cache +/// as LocationsContext. The LSP worker only supplies relationships and addresses. +pub fn formatCallstack(p: *pardes.Pardes, dir: []const u8, input: []const u8) !Result { + const arena = p.scratch.allocator(); + var out: std.Io.Writer.Allocating = .init(p.gpa); + errdefer out.deinit(); + var rows: std.ArrayList(Row) = .empty; + errdefer { + for (rows.items) |row| { + p.gpa.free(row.path); + p.gpa.free(row.colors); + } + rows.deinit(p.gpa); + } + const stacked = p.settings.callstack_layout == .stacked; + var sources: std.StringHashMap(?Source) = .init(arena); + var lines = std.mem.splitScalar(u8, std.mem.trimEnd(u8, input, "\n"), '\n'); + while (lines.next()) |raw| { + const mark = @import("lsp/lsp.zig").callstack_match; + const focus = std.mem.startsWith(u8, raw, mark); + const line = if (focus) raw[mark.len..] else raw; + const prefix = treePrefix(line); + const target = parseRaw(line[prefix.end..]); + if (target.at.line == 0) { + try out.writer.print("{s}\n", .{line}); + try appendMetadata(p.gpa, &rows, .{ .path = "", .at = .{}, .label = "", .code = "", .original = null }, .context, 0, line.len, false); + continue; + } + const entry = try sources.getOrPut(target.path); + if (!entry.found_existing) entry.value_ptr.* = sourceText(p, arena, dir, target.path); + const source = entry.value_ptr.*; + var cached: Cache.Hit = .{ .analysis = .{} }; + defer cached.deinit(p.tree_sitter_gpa); + if (source) |text| cached = p.locations_cache.get(p.tree_sitter_gpa, text.path, text.bytes, true, true) catch .{ .analysis = .{} }; + var code = line[prefix.end + target.code_start ..]; + var colors: []const u8 = &.{}; + var source_row = target.at.line - 1; + if (source) |text| { + const row = target.at.line - 1; + if (prefix.branch) { + // Choose the innermost header containing the server's name range. + var chosen: ?syntax.ContextDeclaration = null; + for (cached.analysis.declarations) |declaration| { + if (declaration.start_line <= row and row <= declaration.header_end_line) { + if (chosen == null or declaration.end_byte - declaration.start_byte < chosen.?.end_byte - chosen.?.start_byte) + chosen = declaration; + } + } + if (chosen) |header| { + code = text.bytes[header.start_byte..header.header_end_byte]; + source_row = header.start_line; + } else { + const fallback = @import("modal.zig").lineSlice(text.bytes, row); + if (fallback.len > 0) code = fallback; + } + } + { + const offset = @import("modal.zig").lineStartOffset(text.bytes, source_row); + if (offset + code.len <= cached.analysis.colors.len and + std.mem.eql(u8, code, text.bytes[offset..][0..code.len])) + colors = cached.analysis.colors[offset..][0..code.len]; + } + } + const recursion = prefix.branch and std.mem.endsWith(u8, line, " ↻ recursion"); + const first_line = code[0 .. std.mem.indexOfScalar(u8, code, '\n') orelse code.len]; + const source_indent = if (stacked) first_line.len - std.mem.trimStart(u8, first_line, " \t").len else 0; + if (stacked) { + const end = prefix.end + target.end; + try out.writer.print("{s}\n", .{line[0..end]}); + try appendMetadata(p.gpa, &rows, .{ .path = target.path, .at = target.at, .label = "", .code = "", .original = null, .mark_occurrence = false }, .match, end, end, false); + } + var header_lines = std.mem.splitScalar(u8, code, '\n'); + var first = true; + var color_offset: usize = 0; + while (header_lines.next()) |code_line| { + const start = out.written().len; + if (stacked) { + var guide_buf: [1024]u8 = undefined; + const guide = treeContinuation(line, &guide_buf, std.math.maxInt(usize)); + try out.writer.writeAll(guide); + const width = pardes.panes.File.displayWidth(line[0..prefix.end]); + try out.writer.splatByteAll(' ', width -| pardes.panes.File.displayWidth(guide)); + } else if (first) { + try out.writer.writeAll(line[0 .. prefix.end + target.end]); + try out.writer.writeByte(' '); + } else { + const branch_start = prefix.end - "└──┬ ".len; + try out.writer.writeAll(line[0..branch_start]); + try out.writer.writeAll(if (std.mem.startsWith(u8, line[branch_start..], "├")) "│ " else " "); + try out.writer.writeAll(if (std.mem.endsWith(u8, line[0..prefix.end], "┬ ") or std.mem.endsWith(u8, line[0..prefix.end], "╮ ")) "│ " else " "); + try out.writer.splatByteAll(' ', pardes.panes.File.displayWidth(line[prefix.end..][0..target.end]) + 1); + } + const code_start = out.written().len - start; + const trim = @min(source_indent, code_line.len - std.mem.trimStart(u8, code_line, " \t").len); + try out.writer.writeAll(code_line[trim..]); + const recursion_note = recursion and first and !std.mem.endsWith(u8, code_line, " ↻ recursion"); + if (recursion_note) try out.writer.writeAll(" ↻ recursion"); + try out.writer.writeByte('\n'); + try appendMetadata(p.gpa, &rows, .{ + .path = target.path, + .at = if (first) target.at else .{ .line = source_row + 1 }, + .label = "", + .code = code_line[trim..], + .source_column = trim, + .original = null, + .mark_occurrence = focus and !prefix.branch, + .colors = if (colors.len >= color_offset + code_line.len) colors[color_offset + trim ..][0 .. code_line.len - trim] else &.{}, + }, if (first) (if (stacked) .preview else .match) else .context, if (first and !stacked) prefix.end + target.end else 0, code_start, true); + // Recursion notes are prose, outside the source snapshot. + if (recursion_note) { + const added = " ↻ recursion".len; + const row = &rows.items[rows.items.len - 1]; + if (row.colors.len > 0) { + const expanded = try p.gpa.alloc(u8, row.colors.len + added); + @memcpy(expanded[0..row.colors.len], row.colors); + @memset(expanded[row.colors.len..], 0); + p.gpa.free(row.colors); + row.colors = expanded; + } + } + color_offset += code_line.len + 1; + source_row += 1; + first = false; + } + } + const owned_rows = try rows.toOwnedSlice(p.gpa); + errdefer freeRows(p.gpa, owned_rows); + return .{ .content = try out.toOwnedSlice(), .rows = owned_rows, .anchor = null }; +} + /// Inputs are sorted results. Expand each source group, merge context with /// matches, then align groups of eight matches. All temporary source data /// stays in the caller's scratch arena; returned text and rows are owned. @@ -334,7 +507,7 @@ fn appendMetadata(gpa: std.mem.Allocator, rows: *std.ArrayList(Row), pending: Pe errdefer gpa.free(path); const colors = try gpa.dupe(u8, if (source) pending.colors else &.{}); errdefer gpa.free(colors); - try rows.append(gpa, .{ .kind = kind, .declaration = pending.declaration, .path = path, .at = pending.at, .location_end = location_end, .code_start = code_start, .colors = colors }); + try rows.append(gpa, .{ .kind = kind, .declaration = pending.declaration, .mark_occurrence = pending.mark_occurrence, .source_column = pending.source_column, .path = path, .at = pending.at, .location_end = location_end, .code_start = code_start, .colors = colors }); } const alignment_entries = 8; diff --git a/src/look.zig b/src/look.zig index 5795979f..1065cb02 100644 --- a/src/look.zig +++ b/src/look.zig @@ -524,7 +524,7 @@ pub fn cursorWordSel(p: *Pardes, pane: *Pane) Pane.Sel { const w = pane.wrapRow(pane.body.cur_row, pane.body.cur_col); const vrow = w.row + @as(i32, pane.tag_rows); const vcol = if (pane.file != null) - panes.File.displayOffset(pane, pane.body.cur_row, w.at, pane.body.cur_col) + @as(i32, panes.File.gutterWidth(pane)) + w.pad + panes.File.displayOffset(pane, pane.body.cur_row, w.at, pane.body.cur_col) + @as(i32, panes.File.gutterWidth(pane)) else blk: { const lines = edit.paneCursorLines(p, &pane.body) catch break :blk pane.body.cur_col; const local = pane.body.cur_row; @@ -892,7 +892,13 @@ fn lookSpanIn(p: *Pardes, pane: *Pane, from: LookFrom, delta: i32, budget: *usiz if (grain == .whole) break :span wholeRowSpan(ln); if (pane.file) |f| if (@as(usize, @intCast(r)) < f.location_rows.len) { const end = f.location_rows[@intCast(r)].location_end; - if (end > 0) break :span @as(?Span, .{ .start = 0, .end = end }); + if (end > 0) { + const start_byte = if (f.output != null and std.meta.eql(f.output.?.from, panes.Output.Origin{ .query = .callstack })) + @import("locations.zig").treePrefix(ln).end + else + 0; + break :span @as(?Span, .{ .start = start_byte, .end = end }); + } }; break :span lineSpan(p, ln, dir, &realbuf); } orelse continue; @@ -1057,6 +1063,7 @@ pub fn focusPaneLine(p: *Pardes, id: usize, at: Spot, landing: enum { center, ke if (id >= MAX_PANES) return; const pane = p.panes[id] orelse return; p.active = id; + if (pane.collapsed) layout.toggleCollapse(p, id); pane.body.normal.clear(); if (pane.hasPdf()) { if (landing == .keep) return; @@ -2677,7 +2684,7 @@ test "Incl's directories find a name found nowhere else, too; bare Incl l try std.testing.expectEqual(@as(usize, 0), p.incl.items.len); } -test "n in a command pane walks its own file:line places, whoever walked last" { +test "LookNext in a command pane walks its own file:line places, whoever walked last" { if (!platform_has_fs) return; var tmp = std.testing.tmpDir(.{}); defer tmp.cleanup(); @@ -2706,12 +2713,12 @@ test "n in a command pane walks its own file:line places, whoever walked last" { cmd.focus = .body; cmd.body.mode = .normal; for ([_]u21{ 'g', 'g' }) |cp| p.update(.{ .key = .{ .cp = cp } }); - p.update(.{ .key = .{ .cp = 'n' } }); + exec.runBuiltin(p, .LookNext, p.active, "", null); try std.testing.expectEqual(dst, p.active); const first = cmd.look_at orelse return error.NoSpot; const lines = try edit.paneCursorLines(p, &cmd.body); try std.testing.expect(std.mem.startsWith(u8, lines[@intCast(first.row)][@intCast(first.col0)..], "x.c:3:1")); - p.update(.{ .key = .{ .cp = 'n' } }); + exec.runBuiltin(p, .LookNext, p.active, "", null); try std.testing.expectEqual(dst, p.active); const second = cmd.look_at orelse return error.NoSpot; try std.testing.expect(std.mem.startsWith(u8, lines[@intCast(second.row)][@intCast(second.col0)..], "y.c:2:1")); diff --git a/src/lsp/lsp.zig b/src/lsp/lsp.zig index 8dc4da4f..96d42bbd 100644 --- a/src/lsp/lsp.zig +++ b/src/lsp/lsp.zig @@ -16,6 +16,7 @@ pub const Kind = enum { format, select_refs, completion, + callstack, incoming_calls, outgoing_calls, supertypes, @@ -24,7 +25,14 @@ pub const Kind = enum { explain, }; +pub const callstack_match = "@callstack-match "; +pub const CallstackCorners = enum { rounded, square }; +pub const callstack_default_depth: u8 = 8; +pub const callstack_max_depth: u8 = 64; + pub const Req = struct { + callstack_depth: u8 = callstack_default_depth, + callstack_corners: CallstackCorners = .rounded, kind: Kind, path: []const u8, source: [:0]const u8, @@ -46,7 +54,7 @@ pub const Doc = struct { path: []const u8, source: [:0]const u8 }; /// file of the server's language is synced before it is asked. pub fn reachesOtherFiles(kind: Kind) bool { return switch (kind) { - .rename, .references, .implementation, .workspace_symbols, .incoming_calls, .outgoing_calls, .supertypes, .subtypes => true, + .rename, .references, .implementation, .workspace_symbols, .callstack, .incoming_calls, .outgoing_calls, .supertypes, .subtypes => true, else => false, }; } diff --git a/src/lsp/lsp_client.zig b/src/lsp/lsp_client.zig index 561195fe..54bbaa79 100644 --- a/src/lsp/lsp_client.zig +++ b/src/lsp/lsp_client.zig @@ -521,7 +521,8 @@ fn run(c: *Conn, si: usize, arena: std.mem.Allocator, req: lsp.Req, out: *std.Io }; const pos = posOf(req.source, req.offset, c.caps.enc); - var cx: Cx = .{ .arena = arena, .base = req.root, .cur_path = req.path, .cur_src = req.source, .out = out }; + var cx: Cx = .{ .arena = arena, .base = req.root, .cur_path = req.path, .cur_src = req.source, .out = out, .relative_parents = req.kind == .callstack, .callstack_corners = req.callstack_corners }; + for (req.others) |doc| try cx.files.append(arena, .{ .path = doc.path, .text = doc.source }); tr.note("server {s} (pid {d}), root {s}, {s} columns", .{ @tagName(c.state), c.pid, c.root, @tagName(c.caps.enc), }); @@ -642,6 +643,7 @@ fn run(c: *Conn, si: usize, arena: std.mem.Allocator, req: lsp.Req, out: *std.Io n += 1; } }, + .callstack => try callstack(c, si, arena, &cx, uri.items, pos, deadline, tr, req.callstack_depth), .incoming_calls => try hierarchy(c, si, arena, &cx, uri.items, pos, deadline, .incoming, tr), .outgoing_calls => try hierarchy(c, si, arena, &cx, uri.items, pos, deadline, .outgoing, tr), .supertypes => try hierarchy(c, si, arena, &cx, uri.items, pos, deadline, .supers, tr), @@ -869,6 +871,184 @@ fn sortEdits(edits: []PutEdit) void { }.lt); } +/// A bounded static hierarchy. Reuse the prepared item verbatim (including +/// server data), and retain every call-site range rather than just a declaration. +fn hierarchyResult(c: *Conn, arena: std.mem.Allocator, item: std.json.Value, method: []const u8, deadline: i64) Err!?std.json.Value { + if (jsonDepth(item, 0) > 96) return null; + var body: std.ArrayList(u8) = .empty; + try app(&body, arena, "\"item\":"); + try app(&body, arena, std.json.Stringify.valueAlloc(arena, item, .{}) catch return error.OutOfMemory); + return call(c, arena, method, body.items, deadline); +} + +const CallTree = struct { + const Site = struct { range: std.json.Value, focus: bool }; + const Node = struct { + item: std.json.Value, + ranges: std.ArrayList(Site) = .empty, + children: std.ArrayList(usize) = .empty, + cycle: bool = false, + }; + nodes: std.ArrayList(Node) = .empty, + roots: std.ArrayList(usize) = .empty, + path: [lsp.callstack_max_depth]std.json.Value = undefined, + depth_limit: usize = lsp.callstack_default_depth, + visited: usize = 0, + limited: bool = false, + siblings: [lsp.callstack_max_depth]bool = @splat(false), + rendered: usize = 0, + + /// Incoming paths arrive nearest-first. Insert them outermost-first, + /// sharing common caller prefixes and retaining all their call sites. + fn addPath(tree: *CallTree, arena: std.mem.Allocator, path: []const std.json.Value, cycle: bool) Err!void { + var parent: ?usize = null; + var at = path.len; + while (at > 0) { + at -= 1; + const entry = path[at]; + const item = get(entry, "from").?; + const children = if (parent) |id| tree.nodes.items[id].children.items else tree.roots.items; + const found = for (children) |id| { + if (sameCall(tree.nodes.items[id].item, item)) break id; + } else null; + const id = found orelse blk: { + const id = tree.nodes.items.len; + try tree.nodes.append(arena, .{ .item = item }); + if (parent) |pid| { + try tree.nodes.items[pid].children.append(arena, id); + } else try tree.roots.append(arena, id); + break :blk id; + }; + const node = &tree.nodes.items[id]; + node.cycle = node.cycle or (cycle and at == 0); + for (items(get(entry, "fromRanges"))) |range| { + const parsed = rangeOf(range) orelse continue; + for (node.ranges.items) |*other| { + if (std.meta.eql(parsed, rangeOf(other.range).?)) { + other.focus = other.focus or at == 0; + break; + } + } else try node.ranges.append(arena, .{ .range = range, .focus = at == 0 }); + } + parent = id; + } + } +}; + +fn sameCall(a: std.json.Value, b: std.json.Value) bool { + const au = str(get(a, "uri")) orelse return false; + const bu = str(get(b, "uri")) orelse return false; + const ar = rangeOf(get(a, "selectionRange") orelse get(a, "range")) orelse return false; + const br = rangeOf(get(b, "selectionRange") orelse get(b, "range")) orelse return false; + return std.mem.eql(u8, au, bu) and std.meta.eql(ar, br); +} + +fn callPrefix(out: *std.Io.Writer, tree: *const CallTree, depth: usize) Err!void { + for (tree.siblings[0..depth]) |more| try out.writeAll(if (more) "│ " else " "); +} + +fn validCaller(entry: std.json.Value) bool { + const from = get(entry, "from") orelse return false; + const uri = str(get(from, "uri")) orelse return false; + return std.mem.startsWith(u8, uri, "file:") and + rangeOf(get(from, "selectionRange") orelse get(from, "range")) != null; +} + +fn callstack(c: *Conn, si: usize, arena: std.mem.Allocator, cx: *Cx, uri: []const u8, pos: Pos, deadline: i64, tr: *Trace, max_depth: u8) Err!void { + if (!c.caps.call_hier) return lsp.none(cx.out, "{s} does not answer call hierarchy (no callHierarchyProvider)", .{specs[si].name}); + const b = try atPos(arena, uri, pos); + const prepared = (try call(c, arena, "textDocument/prepareCallHierarchy", b.items, deadline)) orelse return; + if (items(prepared).len == 0) return lsp.none(cx.out, "no function at this position", .{}); + for (items(prepared)) |item| { + var tree: CallTree = .{ .depth_limit = std.math.clamp(max_depth, 1, lsp.callstack_max_depth) }; + const incoming = try hierarchyResult(c, arena, item, "callHierarchy/incomingCalls", deadline); + const count = try collectCallers(c, arena, item, incoming, deadline, &tree, 0); + if (count == 0) try cx.out.writeAll("No callers reported\n"); + try renderCallers(cx, c.caps.enc, &tree, tree.roots.items, 0); + if (tree.limited) try cx.out.writeAll("… continue from a function above with Callstack\n"); + tr.note("callstack: {d} callers", .{tree.rendered}); + } +} + +fn collectCallers(c: *Conn, arena: std.mem.Allocator, focus: std.json.Value, incoming: ?std.json.Value, deadline: i64, tree: *CallTree, depth: usize) Err!usize { + var count: usize = 0; + for (items(incoming)) |entry| { + if (tree.visited >= 64) { + tree.limited = true; + break; + } + if (!validCaller(entry)) continue; + const from = get(entry, "from").?; + const cycle = sameCall(focus, from) or for (tree.path[0..depth]) |ancestor| { + if (sameCall(get(ancestor, "from").?, from)) break true; + } else false; + tree.path[depth] = entry; + tree.visited += 1; + count += 1; + var children: usize = 0; + if (!cycle) { + if (depth + 1 == tree.depth_limit or tree.visited >= 64) { + tree.limited = true; + } else { + const ancestors = try hierarchyResult(c, arena, from, "callHierarchy/incomingCalls", deadline); + children = try collectCallers(c, arena, focus, ancestors, deadline, tree, depth + 1); + } + } + if (children == 0) try tree.addPath(arena, tree.path[0 .. depth + 1], cycle); + } + return count; +} + +fn callerLess(tree: *const CallTree, a: usize, b: usize) bool { + const left = tree.nodes.items[a].item; + const right = tree.nodes.items[b].item; + const uri_order = std.mem.order(u8, str(get(left, "uri")).?, str(get(right, "uri")).?); + if (uri_order != .eq) return uri_order == .lt; + return callRangeLess({}, get(left, "selectionRange") orelse get(left, "range").?, get(right, "selectionRange") orelse get(right, "range").?); +} + +fn callRangeLess(_: void, a: std.json.Value, b: std.json.Value) bool { + const left = rangeOf(a).?; + const right = rangeOf(b).?; + return left.sl < right.sl or (left.sl == right.sl and left.sc < right.sc); +} + +fn renderCallers(cx: *Cx, enc: Enc, tree: *CallTree, children: []usize, depth: usize) Err!void { + std.mem.sort(usize, children, @as(*const CallTree, tree), callerLess); + for (children, 0..) |id, index| { + if (tree.rendered >= 64) { + tree.limited = true; + return; + } + const node = &tree.nodes.items[id]; + const item = node.item; + const uri = str(get(item, "uri")).?; + const more = index + 1 < children.len; + try callPrefix(cx.out, tree, depth); + const has_children = node.children.items.len > 0 or node.ranges.items.len > 0; + const rounded = cx.callstack_corners == .rounded; + try cx.out.writeAll(if (more) "├" else if (rounded) "╰" else "└"); + try cx.out.writeAll(if (has_children) "──┬ " else "─── "); + const name = flat(cx.arena, str(get(item, "name")) orelse "(unnamed)"); + const label = if (node.cycle) try std.fmt.allocPrint(cx.arena, "{s} ↻ recursion", .{name}) else name; + try emitRange(cx, enc, uri, get(item, "selectionRange") orelse get(item, "range"), label); + tree.rendered += 1; + tree.siblings[depth] = more; + std.mem.sort(CallTree.Site, node.ranges.items, {}, struct { + fn less(_: void, a: CallTree.Site, b: CallTree.Site) bool { + return callRangeLess({}, a.range, b.range); + } + }.less); + for (node.ranges.items, 0..) |site, site_index| { + if (site.focus) try cx.out.writeAll(lsp.callstack_match); + try callPrefix(cx.out, tree, depth + 1); + try cx.out.writeAll(if (node.children.items.len > 0 or site_index + 1 < node.ranges.items.len) "├─ " else if (rounded) "╰─ " else "└─ "); + try emitRange(cx, enc, uri, site.range, ""); + } + try renderCallers(cx, enc, tree, node.children.items, depth + 1); + } +} + const Hier = enum { incoming, outgoing, supers, subs }; /// The two-step hierarchy kinds: prepare at the cursor, then follow every @@ -894,17 +1074,7 @@ fn hierarchy(c: *Conn, si: usize, arena: std.mem.Allocator, cx: *Cx, uri: []cons const b = try atPos(arena, uri, pos); const prepared = (try call(c, arena, prepare, b.items, deadline)) orelse return; for (items(prepared)) |item| { - // the item goes back VERBATIM — servers hide resolution state in - // `data` and a re-serialized subset would come back unresolvable. - // But only if it can round-trip: Stringify panics past its nesting - // limit, so a server that nests a bomb in `data` gets no rows for - // that item, not a dead editor. - if (jsonDepth(item, 0) > 96) continue; - var body: std.ArrayList(u8) = .empty; - try app(&body, arena, "\"item\":"); - const item_json = std.json.Stringify.valueAlloc(arena, item, .{}) catch return error.OutOfMemory; - try app(&body, arena, item_json); - const result = (try call(c, arena, follow, body.items, deadline)) orelse return; + const result = (try hierarchyResult(c, arena, item, follow, deadline)) orelse return; for (items(result)) |entry| switch (h) { .incoming => { // one row per CALL SITE, under the caller's name — that is @@ -965,6 +1135,8 @@ const Cx = struct { cur_src: []const u8, out: *std.Io.Writer, rows: usize = 0, + relative_parents: bool = false, + callstack_corners: lsp.CallstackCorners = .rounded, files: std.ArrayList(struct { path: []const u8, text: []const u8 }) = .empty, fn text(cx: *Cx, path: []const u8) ?[]const u8 { @@ -1018,7 +1190,10 @@ fn emitRange(cx: *Cx, enc: Enc, uri: []const u8, range: ?std.json.Value, note: [ const lntext: []const u8 = if (src) |t| t[@min(bol, t.len)..@min(eol, t.len)] else ""; const col = colBytes(lntext, r.sc, enc); - const shown = lsp.rel(cx.base, path); + const shown = if (cx.relative_parents) blk: { + const relative = std.fs.path.relativePosix(cx.arena, "/", cx.base, path) catch break :blk path; + break :blk if (relative.len < path.len) relative else path; + } else lsp.rel(cx.base, path); // A same-line exclusive end byte offset is also the displayed inclusive // one-based column. Multi-line ranges display only their starting address. const end_col = if (r.el == r.sl and r.ec > r.sc) colBytes(lntext, r.ec, enc) else col; @@ -2131,6 +2306,68 @@ fn coord(v: ?std.json.Value) ?u32 { // ----------------------------------------------------------------- tests +test "caller trees reverse incoming paths and merge shared callers and sites" { + var arena_state = std.heap.ArenaAllocator.init(std.testing.allocator); + defer arena_state.deinit(); + const arena = arena_state.allocator(); + const fixture = try std.json.parseFromSliceLeaky(std.json.Value, arena, "[{\"from\":{\"name\":\"left\",\"uri\":\"file:///test.c\",\"selectionRange\":{\"start\":{\"line\":3,\"character\":0},\"end\":{\"line\":3,\"character\":4}}},\"fromRanges\":[{\"start\":{\"line\":3,\"character\":0},\"end\":{\"line\":3,\"character\":4}}]},{\"from\":{\"name\":\"right\",\"uri\":\"file:///test.c\",\"selectionRange\":{\"start\":{\"line\":4,\"character\":0},\"end\":{\"line\":4,\"character\":4}}},\"fromRanges\":[{\"start\":{\"line\":4,\"character\":0},\"end\":{\"line\":4,\"character\":4}}]},{\"from\":{\"name\":\"page\",\"uri\":\"file:///test.c\",\"selectionRange\":{\"start\":{\"line\":1,\"character\":0},\"end\":{\"line\":1,\"character\":4}}},\"fromRanges\":[{\"start\":{\"line\":1,\"character\":0},\"end\":{\"line\":1,\"character\":4}}]},{\"from\":{\"name\":\"page\",\"uri\":\"file:///test.c\",\"selectionRange\":{\"start\":{\"line\":1,\"character\":0},\"end\":{\"line\":1,\"character\":4}}},\"fromRanges\":[{\"start\":{\"line\":2,\"character\":0},\"end\":{\"line\":2,\"character\":4}}]},{\"from\":{\"name\":\"main\",\"uri\":\"file:///test.c\",\"selectionRange\":{\"start\":{\"line\":0,\"character\":0},\"end\":{\"line\":0,\"character\":4}}},\"fromRanges\":[{\"start\":{\"line\":0,\"character\":0},\"end\":{\"line\":0,\"character\":4}}]}]", .{}); + const entries = items(fixture); + var tree: CallTree = .{}; + try tree.addPath(arena, &.{ entries[0], entries[2], entries[4] }, false); + try tree.addPath(arena, &.{ entries[1], entries[3], entries[4] }, false); + try std.testing.expectEqual(@as(usize, 1), tree.roots.items.len); + try std.testing.expectEqual(@as(usize, 4), tree.nodes.items.len); + const root = tree.nodes.items[tree.roots.items[0]]; + try std.testing.expectEqualStrings("main", str(get(root.item, "name")).?); + try std.testing.expectEqual(@as(usize, 1), root.ranges.items.len); + const page = tree.nodes.items[root.children.items[0]]; + try std.testing.expectEqual(@as(usize, 2), page.children.items.len); + try std.testing.expectEqual(@as(usize, 2), page.ranges.items.len); + try std.testing.expect(!root.ranges.items[0].focus); + for (page.ranges.items) |site| try std.testing.expect(!site.focus); + for (page.children.items) |id| try std.testing.expect(tree.nodes.items[id].ranges.items[0].focus); + var out: std.Io.Writer.Allocating = .init(arena); + var cx: Cx = .{ .arena = arena, .base = "/", .cur_path = "/test.c", .cur_src = "main_call();\npage_left();\npage_right();\nleft_call();\nright_call();\n", .out = &out.writer }; + try renderCallers(&cx, .utf8, &tree, tree.roots.items, 0); + const text = out.written(); + try std.testing.expectEqual(@as(usize, 2), std.mem.count(u8, text, lsp.callstack_match)); + const main_at = std.mem.indexOf(u8, text, " main\n").?; + const page_at = std.mem.indexOf(u8, text, " page\n").?; + const left_at = std.mem.indexOf(u8, text, " left\n").?; + const right_at = std.mem.indexOf(u8, text, " right\n").?; + try std.testing.expect(main_at < page_at and page_at < left_at and left_at < right_at); + try std.testing.expectEqual(@as(usize, 1), std.mem.count(u8, text, "main_call();")); + try std.testing.expect(std.mem.indexOf(u8, text, "page_left();").? < std.mem.indexOf(u8, text, "page_right();").?); + try std.testing.expect(std.mem.indexOf(u8, text, "├──┬ test.c:4:") != null); + try std.testing.expect(std.mem.indexOf(u8, text, "╰──┬ test.c:1:") != null); + cx.callstack_corners = .square; + tree.rendered = 0; + const square_start = out.written().len; + try renderCallers(&cx, .utf8, &tree, tree.roots.items, 0); + const square = out.written()[square_start..]; + try std.testing.expect(std.mem.indexOf(u8, square, "├──┬ test.c:4:") != null); + try std.testing.expect(std.mem.indexOf(u8, square, "└──┬ test.c:1:") != null); + try std.testing.expect(std.mem.indexOf(u8, square, "╰") == null); + try std.testing.expect(std.mem.indexOf(u8, square, "╮") == null); + var recursive: CallTree = .{}; + try recursive.addPath(arena, &.{ entries[0], entries[0] }, true); + try std.testing.expect(!recursive.nodes.items[recursive.roots.items[0]].cycle); + try std.testing.expect(recursive.nodes.items[1].cycle); +} + +test "callstack cross-crate paths remain resolvable without absolute path clutter" { + var arena_state = std.heap.ArenaAllocator.init(std.testing.allocator); + defer arena_state.deinit(); + const arena = arena_state.allocator(); + const range = try std.json.parseFromSliceLeaky(std.json.Value, arena, + \\{"start":{"line":1,"character":3},"end":{"line":1,"character":6}} + , .{}); + var out: std.Io.Writer.Allocating = .init(arena); + var cx: Cx = .{ .arena = arena, .base = "/workspace/merkle-tree/src", .cur_path = "", .cur_src = "", .out = &out.writer, .relative_parents = true }; + try emitRange(&cx, .utf8, "file:///workspace/entry/src/entry.rs", range, "fn run()"); + try std.testing.expectEqualStrings("../../entry/src/entry.rs:2:4-6 fn run()\n", out.written()); +} + test "LSP client rename and format propagate incomplete edit encoding" { const gpa = std.testing.allocator; const uri = "file:///file.c"; diff --git a/src/modal.zig b/src/modal.zig index 548524ae..50e0ddf4 100644 --- a/src/modal.zig +++ b/src/modal.zig @@ -36,6 +36,7 @@ pub const Normal = struct { goto_type_definition, goto_implementation, goto_references, + goto_callstack, view_top, view_center, @@ -320,7 +321,7 @@ pub const Normal = struct { undo, redo, }; - pub const Lsp = enum { definition, declaration, type_definition, implementation, references, format }; + pub const Lsp = enum { definition, declaration, type_definition, implementation, references, callstack, format }; pub const Counted = struct { count: u32, @@ -471,6 +472,7 @@ pub const Normal = struct { if (key.has(.goto_type_definition)) return resultAction(.{ .lsp = .type_definition }); if (key.has(.goto_implementation)) return resultAction(.{ .lsp = .implementation }); if (key.has(.goto_references)) return resultAction(.{ .lsp = .references }); + if (key.has(.goto_callstack)) return resultAction(.{ .lsp = .callstack }); return .ignored; }, .view => { diff --git a/src/mouse.zig b/src/mouse.zig index 733479dd..536a4fdb 100644 --- a/src/mouse.zig +++ b/src/mouse.zig @@ -100,7 +100,7 @@ pub const HeaderSweep = struct { /// as a pane tag's sweep stays on its tag. fn headerPoint(p: *Pardes, column: ?usize, mcol: u16, mrow: u16, clamp: bool) ?struct { t: *panes.Text, text: []const u8, line: u16, at: usize } { const t = if (column) |c| &p.col_tags[c] else &p.global_tag; - const x = if (column) |c| p.col_x[c] + TAG_TEXT_INSET else 0; + const x = if (column) |c| p.col_x[c] + TAG_TEXT_INSET else TAG_TEXT_INSET; const focused = p.header_focus and p.header_column == column; const text = edit.flatSurface(p, t) catch return null; const base = if (column != null) p.topBarHeight() else 0; @@ -588,7 +588,7 @@ pub fn handleMouse(p: *Pardes, event: Mouse) void { p.header_drag = false; return; }; - const x = if (p.header_column) |c| p.col_x[c] + TAG_TEXT_INSET else 0; + const x = if (p.header_column) |c| p.col_x[c] + TAG_TEXT_INSET else TAG_TEXT_INSET; const text = edit.flatSurface(p, t) catch return; // `row` is the header's row on screen, `line` the line of its text // shown there. @@ -612,7 +612,8 @@ pub fn handleMouse(p: *Pardes, event: Mouse) void { pane.closePrompt(); }; var column: ?usize = null; - var x: u16 = 0; + var x: u16 = TAG_TEXT_INSET; + if (mcol < x) return; if (mrow >= p.topBarHeight()) { for (0..p.ncol) |c| if (mcol >= p.col_x[c] and mcol < p.col_x[c] + p.col_w[c]) { column = c; @@ -1047,7 +1048,7 @@ fn gestureRange(p: *Pardes, id: usize, text: []const u8, on_tag: bool, operand: const top = lead[0] - @as(i32, pane.tag_rows); if (top < 0) break :lead null; const w = pane.wrapAt(top); - const col = edit.paneByteAtDisplay(p, &pane.body, w.line, w.at, lead[1] - panes.File.gutterWidth(pane)); + const col = edit.paneByteAtDisplay(p, &pane.body, w.line, w.at, lead[1] - panes.File.gutterWidth(pane) - w.pad); break :lead .{ .row = @intCast(@max(0, w.line)), .col = @intCast(@max(0, col)), @@ -1154,7 +1155,7 @@ fn sweepPoint(p: *Pardes, pane: *panes.Pane, r: i32, c: i32) ?modal.Cursor { if (visible < 0) return null; const w = pane.wrapAt(visible); if (w.line < 0) return null; - const col = edit.paneByteAtDisplay(p, &pane.body, w.line, w.at, c - (if (pane.file != null) @as(i32, panes.File.gutterWidth(pane)) else 0)); + const col = edit.paneByteAtDisplay(p, &pane.body, w.line, w.at, c - w.pad - (if (pane.file != null) @as(i32, panes.File.gutterWidth(pane)) else 0)); return .{ .row = @intCast(w.line), .col = @intCast(@max(0, col)) }; } @@ -1268,7 +1269,7 @@ fn dragRelease(p: *Pardes, button: Mouse.Button) void { &pane.body, w.line, w.at, - sl.c1 - (if (pane.file != null) @as(i32, panes.File.gutterWidth(pane)) else 0), + sl.c1 - w.pad - (if (pane.file != null) @as(i32, panes.File.gutterWidth(pane)) else 0), ); pane.body.cur_pinned = true; if (edit.clampFileCursor(&pane.body)) pane.ensureCursorVisible(); @@ -1312,7 +1313,14 @@ fn dragRelease(p: *Pardes, button: Mouse.Button) void { pane.sel[b] = expanded else if (operand.text == null) pane.sel[b].state = .none; - if (s.button == config.look_button and clk.r0 >= pane.tag_rows and pane.body.mode != .tty) { + if (s.button == config.look_button and clk.r0 >= pane.tag_rows and pane.body.mode != .tty and operand.expanded != null) { + // This click chose a new word. An old keyboard anchor + // must not stretch to it; borrowed selections retain + // their original cursor and extent. + pane.body.vsel.active = false; + pane.body.msel.active = false; + pane.body.nsel = 0; + pane.body.select = false; pane.body.cur_row = operand.row; pane.body.cur_col = operand.col; if (edit.clampFileCursor(&pane.body)) pane.ensureCursorVisible(); @@ -1431,8 +1439,8 @@ fn chordCutPaste(p: *Pardes, cut: bool) void { const w1 = pane.wrapAt(@max(0, sl.r1 - @as(i32, pane.tag_rows))); const row0 = w0.line; const row1 = w1.line; - const col0 = edit.paneByteAtDisplay(p, &pane.body, w0.line, w0.at, sl.c0 - pfx); - const col1 = edit.paneByteAtDisplay(p, &pane.body, w1.line, w1.at, sl.c1 - pfx); + const col0 = edit.paneByteAtDisplay(p, &pane.body, w0.line, w0.at, sl.c0 - pfx - w0.pad); + const col1 = edit.paneByteAtDisplay(p, &pane.body, w1.line, w1.at, sl.c1 - pfx - w1.pad); pane.body.cur_row = row1; pane.body.cur_col = col1; pane.body.cur_pinned = true; diff --git a/src/ninep/ctl.zig b/src/ninep/ctl.zig index e6e738a5..f6457b83 100644 --- a/src/ninep/ctl.zig +++ b/src/ninep/ctl.zig @@ -554,6 +554,7 @@ fn checkBuiltin(p: *Pardes, req: Req, line: []const u8, scope: builtins.Scope) ? .font => config.Runtime.FontSpec.parse(arg) != null, // Bare, it says the width, as from a pane's exec. .tab => arg.len == 0 or (std.fmt.parseInt(u16, arg, 10) catch 0) -% 1 < 16, + .callstack_depth => arg.len == 0 or (std.fmt.parseInt(u8, arg, 10) catch 0) -% 1 < pardes.lsp.callstack_max_depth, else => probe: { var probe = p.settings; break :probe probe.apply(setting, if (arg.len > 0) arg else null); @@ -662,6 +663,7 @@ pub fn writeSettingsOf(p: *Pardes, s: *const config.Runtime, w: *std.Io.Writer) .motion => try w.print("{s} {s}\n", .{ word, @tagName(s.motion) }), .inactive_dim => try w.print("{s} {d}\n", .{ word, s.inactive_dim }), .grip_width => try w.print("{s} {d}\n", .{ word, s.grip_width }), + .callstack_depth => try w.print("{s} {d}\n", .{ word, s.callstack_depth }), .tab => try w.print("{s} {d}\n", .{ word, s.tab }), } } @@ -743,12 +745,13 @@ pub fn fillPager(p: *Pardes, serial: u32, held: *std.ArrayList(u8)) error{OutOfM f.pager_spans = page.spans; f.saved_revision = f.revision; // A diff paged (`git show`, difftui's patches): its hunks stacked in a - // +Diff (DiffLook hunks), the +Pager folded to its tag under it for - // Diff to bring back. The keyboard stays where it was, as a page's. + // +Diff (DiffLook hunks) in the +Pager's place, the +Pager closed. The + // keyboard stays where it was, as a page's. if (f.pager_diff and p.settings.diff_look == .hunks) { const keyboard = p.active; - if (panes.Output.openDiff(p, id, f.path, f.content)) |_| { - if (!pane.collapsed) pardes.layout.toggleCollapse(p, id); + if (panes.Output.openDiff(p, id, f.path, f.content)) |hid| { + // ponytail: the text is gone with it; Diff on the +Diff says no such file. + p.removePane(id, hid) catch {}; } else |_| {} if (p.panes[keyboard] != null) p.active = keyboard; } @@ -1452,6 +1455,8 @@ test "the root ctl reads the settings as a write takes them, and takes the sessi try testing.expectEqual(@as(u64, settings.len), call(p, .{ .tag = 1, .op = .getattr, .node = root_ctl }).reply.attr.size); try testing.expect(std.mem.indexOf(u8, settings, "Verbose on\n") != null); try testing.expect(std.mem.indexOf(u8, settings, "LocationsConfig ") != null); + try testing.expect(std.mem.indexOf(u8, settings, "CallstackDepth 8\n") != null); + try testing.expectEqual(Status.ok, wr(p, root_ctl, "CallstackDepth").reply.status); // Settings only: nothing /status or the DumpConfig window says. try testing.expect(std.mem.indexOf(u8, settings, "Platform") == null); try testing.expect(std.mem.indexOf(u8, settings, "requested") == null); @@ -1494,7 +1499,6 @@ test "the root ctl reads the settings as a write takes them, and takes the sessi try testing.expectEqual(Status.ok, wr(p, root_ctl, "Verbose off").reply.status); } - test "a second lock is refused until the holder unlocks or closes, and binds nobody else" { const p = try withFile(testing.allocator, "one\ntwo\n"); defer p.deinit(); @@ -3920,7 +3924,7 @@ test "a closed file is found again: Recent and /recent list it closed, a look at try testing.expectEqual(Status.ok, wr(p, root_exec, "Recent\n").reply.status); const rows = p.panes[p.paneBySerial(try std.fmt.parseInt(u32, std.mem.trimEnd(u8, rd(p, root_exec, 0, 64).bytes, "\n"), 10)).?].?; const at = std.mem.indexOf(u8, rows.file.?.content, try std.fmt.bufPrint(&want, "{s}:3:", .{a})).?; - const row = rows.file.?.content[at .. std.mem.indexOfScalarPos(u8, rows.file.?.content, at, '\n').?]; + const row = rows.file.?.content[at..std.mem.indexOfScalarPos(u8, rows.file.?.content, at, '\n').?]; try testing.expect(std.mem.endsWith(u8, row, " (closed)")); try testing.expectEqual(Status.ok, wr(p, Node.of(rows.serial, .look), try std.fmt.bufPrint(&line, "{s}\n", .{row[0 .. row.len - " (closed)".len]})).reply.status); p.sync(); @@ -4159,11 +4163,11 @@ test "a remembered place is clamped to the file as it is now, its selection's tw _ = wr(p, root_exec, "Recent\n"); const rows = p.panes[p.paneBySerial(try std.fmt.parseInt(u32, std.mem.trimEnd(u8, rd(p, root_exec, 0, 64).bytes, "\n"), 10)).?].?; const at = std.mem.indexOf(u8, rows.file.?.content, "c.txt:").?; - const row = rows.file.?.content[at .. std.mem.indexOfScalarPos(u8, rows.file.?.content, at, '\n').?]; + const row = rows.file.?.content[at..std.mem.indexOfScalarPos(u8, rows.file.?.content, at, '\n').?]; // Both ends are in the row, a range. try testing.expect(std.mem.indexOfScalar(u8, row, '-') != null); var full: [4400]u8 = undefined; - const loc = try std.fmt.bufPrint(&full, "{s}/{s}\n", .{ dir, row[0 .. std.mem.indexOfScalar(u8, row, ' ').?] }); + const loc = try std.fmt.bufPrint(&full, "{s}/{s}\n", .{ dir, row[0..std.mem.indexOfScalar(u8, row, ' ').?] }); // A look at it opens the file, never a miss, clamped to its last line. try testing.expectEqual(Status.ok, wr(p, Node.of(rows.serial, .look), loc).reply.status); p.sync(); @@ -4350,7 +4354,7 @@ test "every word's /commands description is its own doc comment's first sentence undescribed += 1; continue; }; - const word = line[0 .. std.mem.indexOfScalar(u8, line, ' ').?]; + const word = line[0..std.mem.indexOfScalar(u8, line, ' ').?]; if (config.Runtime.find(word)) |setting| { try testing.expect(std.mem.endsWith(u8, line, setting.doc)); continue; diff --git a/src/normal.zig b/src/normal.zig index fad1836b..77feb7cf 100644 --- a/src/normal.zig +++ b/src/normal.zig @@ -905,10 +905,11 @@ fn executeNormalAction(p: *Pardes, t: *Text, semantic: modal.Normal.Action) void .undo => return edit.doUndo(p, t), .redo => return edit.doRedo(p, t), }, - // gd and gr are the Def and Refs a tag shows, run as a click runs them. + // Language shortcuts run the same builtins as tags and leader commands. .lsp => |request| return switch (request) { .definition => exec.runBuiltin(p, .Def, p.active, "", null), .references => exec.runBuiltin(p, .Refs, p.active, "", null), + .callstack => exec.runBuiltin(p, .Callstack, p.active, "", null), .declaration => p.lspRequest(p.active, .declaration, ""), .type_definition => p.lspRequest(p.active, .type_definition, ""), .implementation => p.lspRequest(p.active, .implementation, ""), diff --git a/src/panes.zig b/src/panes.zig index 89362996..ba1dedb5 100644 --- a/src/panes.zig +++ b/src/panes.zig @@ -219,6 +219,7 @@ pub const Pane = struct { // Visible rows map to source lines and raw/display column origins. wrap_line: [limits.wrap_rows]i32 = undefined, wrap_col: [limits.wrap_rows]i32 = undefined, + wrap_pad: [limits.wrap_rows]u16 = @splat(0), wrap_n: u16 = 0, /// A row map also exists for sticky headers when soft wrapping is off. body_wrapped: bool = false, @@ -493,15 +494,15 @@ pub const Pane = struct { return pane.surfRow(terminal.gridOffset(pane)); } - pub fn wrapAt(pane: *Pane, vr: i32) struct { line: i32, at: i32 } { + pub fn wrapAt(pane: *Pane, vr: i32) struct { line: i32, at: i32, pad: i32 = 0 } { if (pane.wrap_n > 0 and vr >= 0 and vr < @as(i32, pane.wrap_n)) - return .{ .line = pane.wrap_line[@intCast(vr)], .at = pane.wrap_col[@intCast(vr)] }; + return .{ .line = pane.wrap_line[@intCast(vr)], .at = pane.wrap_col[@intCast(vr)], .pad = pane.wrap_pad[@intCast(vr)] }; // unwrapped: rows ARE lines, and the byte column a row starts at is the // horizontal scroll (always 0 on a terminal, which never has one) return .{ .line = pane.scroll() + vr, .at = pane.hscroll }; } - pub fn wrapRow(pane: *Pane, line: i32, col: i32) struct { row: i32, at: i32 } { + pub fn wrapRow(pane: *Pane, line: i32, col: i32) struct { row: i32, at: i32, pad: i32 = 0 } { if (pane.wrap_n == 0) return .{ .row = line - pane.scroll(), .at = pane.hscroll }; var i: u16 = 0; while (i < pane.wrap_n) : (i += 1) { @@ -509,7 +510,7 @@ pub const Pane = struct { // the LAST row of a line owns every column past its start, so a // cursor parked on the trailing newline still has somewhere to draw if (i + 1 < pane.wrap_n and pane.wrap_line[i + 1] == line and col >= pane.wrap_col[i + 1]) continue; - return .{ .row = @intCast(i), .at = pane.wrap_col[i] }; + return .{ .row = @intCast(i), .at = pane.wrap_col[i], .pad = pane.wrap_pad[i] }; } return .{ .row = -1, .at = 0 }; } diff --git a/src/pardes.zig b/src/pardes.zig index 29192c33..5f330712 100644 --- a/src/pardes.zig +++ b/src/pardes.zig @@ -220,7 +220,6 @@ pub const Turn = struct { while (t.lsp_answers == answers) t.settled.wait(t.io.?, &t.mutex) catch return; } - pub fn awaitRestored(t: *Turn, restores: u64) void { while (t.restores == restores) t.settled.wait(t.io.?, &t.mutex) catch return; } @@ -294,7 +293,7 @@ pub const MAX_JUMPS = 64; pub const TOPBAR_H: u16 = 1; pub const COLBAR_H: u16 = 1; pub const BOX_H: u16 = 1; -pub const TAG_GAP: u16 = 1; +pub const TAG_GAP: u16 = 0; pub const TAG_TEXT_INSET: u16 = config.GUTTER + TAG_GAP; pub fn taglineBandOffset(row: u16, canvas_h: f32, cell_h: u32, tagline_h: u32) u32 { @@ -655,25 +654,25 @@ test "topbar hover highlights exactly the executable word" { defer frame.deinit(); _ = try p.render(frame.allocator()); - p.update(.{ .mouse = .{ .button = .none, .kind = .motion, .col = 1, .row = 0 } }); + p.update(.{ .mouse = .{ .button = .none, .kind = .motion, .col = TAG_TEXT_INSET + 1, .row = 0 } }); _ = frame.reset(.retain_capacity); const hovered = try p.render(frame.allocator()); for (0.."Newcol".len) |col| { - const cell = hovered.at(@intCast(col), 0); + const cell = hovered.at(TAG_TEXT_INSET + @as(u16, @intCast(col)), 0); try std.testing.expectEqual(Color{ .rgb = p.theme().sel_bg }, cell.style.bg); try std.testing.expectEqual(Color{ .rgb = p.theme().sel_fg }, cell.style.fg); } - try std.testing.expectEqual(Color{ .rgb = p.chromeTheme().tag_bg }, hovered.at(6, 0).style.bg); + try std.testing.expectEqual(Color{ .rgb = p.chromeTheme().tag_bg }, hovered.at(TAG_TEXT_INSET + 6, 0).style.bg); - p.update(.{ .mouse = .{ .button = .none, .kind = .motion, .col = 6, .row = 0 } }); + p.update(.{ .mouse = .{ .button = .none, .kind = .motion, .col = TAG_TEXT_INSET + 6, .row = 0 } }); _ = frame.reset(.retain_capacity); const whitespace = try p.render(frame.allocator()); - try std.testing.expectEqual(Color{ .rgb = p.chromeTheme().tag_bg }, whitespace.at(1, 0).style.bg); + try std.testing.expectEqual(Color{ .rgb = p.chromeTheme().tag_bg }, whitespace.at(TAG_TEXT_INSET + 1, 0).style.bg); p.update(.pointer_leave); _ = frame.reset(.retain_capacity); const left = try p.render(frame.allocator()); - try std.testing.expectEqual(Color{ .rgb = p.chromeTheme().tag_bg }, left.at(1, 0).style.bg); + try std.testing.expectEqual(Color{ .rgb = p.chromeTheme().tag_bg }, left.at(TAG_TEXT_INSET + 1, 0).style.bg); } test "pane-tag Exec prefers Tty and argument builtins before shell fallback" { @@ -1216,7 +1215,7 @@ test "Def and Refs are a speaking file's tag words; gd, gr and a 2-1 chord all r const f = &pane.file.?; p.gpa.free(f.path); f.path = try p.gpa.dupe(u8, "/tmp/x.zig"); - try std.testing.expect(std.mem.endsWith(u8, tagline.curTail(pane), " Def Refs")); + try std.testing.expect(std.mem.endsWith(u8, tagline.curTail(pane), " Def Refs Del")); p.sync(); while (p.nextEffect()) |_| {} const Asked = struct { @@ -1241,6 +1240,9 @@ test "Def and Refs are a speaking file's tag words; gd, gr and a 2-1 chord all r p.update(.{ .key = .{ .cp = 'g' } }); p.update(.{ .key = .{ .cp = 'r' } }); try std.testing.expectEqual(@as(u32, 8), try Asked.one(p, .references)); + p.update(.{ .key = .{ .cp = 'g' } }); + p.update(.{ .key = .{ .cp = 'c' } }); + try std.testing.expectEqual(@as(u32, 8), try Asked.one(p, .callstack)); const r = p.rects[0]; const x0 = r.x + config.GUTTER + panes.File.gutterWidth(pane); @@ -1525,7 +1527,6 @@ test "unknown Exec from a document runs as a command pane in its directory, type try std.testing.expect(spawned); } - const FakeTtyQuery = struct { taken: [MAX_PANES]bool = @splat(false), asked: usize = 0, @@ -2009,7 +2010,6 @@ test "a command pane shows how its command ended, and the next command there run try std.testing.expectEqual(@as(?usize, null), exec.execute(p, 1, long)); } - test "image dump restores source bytes renderer choices and exact custom tail" { const gpa = std.testing.allocator; const p = try Pardes.init(gpa, .{ .tty_only = true }); @@ -2062,7 +2062,6 @@ test "image dump restores source bytes renderer choices and exact custom tail" { try std.testing.expectEqualStrings(" Keep Del", redump.panes[0].tag_tail.?); } - test "a Look on a directory does not type ls into an occupied terminal" { const gpa = std.testing.allocator; const p = try Pardes.init(gpa, .{ .cols = 100, .rows = 30 }); @@ -3374,9 +3373,9 @@ test "editable workspace and column tags are typed into and persist" { p.acknowledgePanelPresentation(&.{}); try std.testing.expectEqual(TOPBAR_H + COLBAR_H, p.rects[0].y); // a sweep over a header is its selection, the caret where it ended - p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = 0, .row = 0 } }); - p.update(.{ .mouse = .{ .button = .left, .kind = .drag, .col = 6, .row = 0 } }); - p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = 6, .row = 0 } }); + p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = TAG_TEXT_INSET, .row = 0 } }); + p.update(.{ .mouse = .{ .button = .left, .kind = .drag, .col = TAG_TEXT_INSET + 6, .row = 0 } }); + p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = TAG_TEXT_INSET + 6, .row = 0 } }); try std.testing.expect(p.global_tag.vsel.active and p.global_tag.vsel.col == 0 and p.global_tag.cur_col == 6); p.update(.{ .key = .{ .cp = 'H', .text = " Help" } }); try std.testing.expect(std.mem.startsWith(u8, p.global_tag.own.?, "Newcol Help Joincol")); @@ -6966,6 +6965,7 @@ pub const Pardes = struct { .definition => "Def", .references => "Refs", .explain => "Lspwhy", + .callstack => "Callstack", .incoming_calls => "Callers", .outgoing_calls => "Callees", .document_symbols => "Symbols", @@ -7081,6 +7081,18 @@ pub const Pardes = struct { // (a multi-file Rename's preview, Lspinfo's +Lsp), made or filled // again, not the pane it was asked from. p.fs.lsp_result = if (p.next_serial != serial_before) p.next_serial else p.fs.refilled; + if (w.kind == .callstack) { + for (p.panes, 0..) |slot, result_id| if (slot) |result_pane| { + if (result_pane.serial != p.fs.lsp_result) continue; + if (p.next_serial != serial_before) { + const report_rows = std.mem.count(u8, result_pane.file.?.content, "\n"); + const wanted: u16 = @intCast(@min(p.screen_h, report_rows + result_pane.tag_rows)); + layout.givePaneRows(p, result_id, wanted, w.pane); + } + look.focusPaneLine(p, result_id, .{ .line = 1, .col = 1 }, .keep); + break; + }; + } if (w.kind == .rename) { var said_buf: [128]u8 = undefined; // Rows that only name a file the server left alone (lsp_client @@ -7624,7 +7636,6 @@ pub const Pardes = struct { return if (frames) |n| p.stepped_ns + n * animation.frame_ns else null; } - /// A render-time animation is moving (a pane's lift): it is sampled at /// each frame's own `now`, so while it moves the shell draws every loop /// and its present (vsync) paces it, at the display's rate. `nextWake` @@ -8514,6 +8525,44 @@ test "the jump list never holds two entries in a row the same, when the one betw try std.testing.expectEqual(@as(u32, 150), p.jumps[1].line); } +test "Callstack always opens and focuses its own pane, reusing it for another symbol" { + if (!lsp.supports.contains(.callstack)) return; + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true }); + defer p.deinit(); + _ = try p.setTestFile("fn work() {}\n"); + const source = p.panes[0].?; + p.lspRequest(0, .callstack, ""); + const first = p.lsp_wait orelse return error.NoRequest; + p.lspResponse(first.id, "└──┬ /test.txt:1:4-7 work\n@callstack-match └─ /test.txt:1:4-7 fn work() {}\n"); + const report = p.panes[p.active].?; + try std.testing.expect(report != source); + try std.testing.expect(std.mem.endsWith(u8, report.file.?.path, "/+Callstack")); + try std.testing.expectEqual(@as(i32, 0), source.body.cur_row); + const stale_selection = std.mem.indexOfScalar(u8, report.file.?.content, '\n').? + 1; + report.body.setRange(report.file.?.content, 0, .{ .anchor = stale_selection, .head = stale_selection + 6 }, true); + layout.toggleCollapse(p, 0); + var frame = std.heap.ArenaAllocator.init(std.testing.allocator); + defer frame.deinit(); + const surface = try p.render(frame.allocator()); + p.acknowledgePanelPresentation(&.{}); + const r = p.rects[p.active]; + const row = r.y + report.tag_rows; + const col = r.x + config.GUTTER + panes.File.gutterWidth(report) + 7; + try std.testing.expectEqual(.off, surface.at(col, row).style.ul); + p.update(.{ .mouse = .{ .button = .right, .kind = .press, .row = row, .col = col } }); + p.update(.{ .mouse = .{ .button = .right, .kind = .release, .row = row, .col = col } }); + try std.testing.expect(!source.collapsed); + try std.testing.expectEqual(@as(usize, 0), p.active); + try std.testing.expect(!report.body.vsel.active); + try std.testing.expectEqual(@as(usize, 0), report.body.nsel); + const serial = report.serial; + p.lspRequest(0, .callstack, ""); + const second = p.lsp_wait orelse return error.NoRequest; + p.lspResponse(second.id, "No callers reported\n"); + try std.testing.expectEqual(serial, p.panes[p.active].?.serial); + try std.testing.expectEqualStrings("No callers reported\n", p.panes[p.active].?.file.?.content); +} + test "Callers with one answer jumps to it and says where, in a msg" { if (!lsp.supports.contains(.incoming_calls)) return; const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true }); diff --git a/src/syntax.zig b/src/syntax.zig index 89d96239..b2f5ea99 100644 --- a/src/syntax.zig +++ b/src/syntax.zig @@ -414,7 +414,6 @@ pub fn walkNodes(tree_ptr: *anyopaque, walk: NodeWalk, from: usize, to: usize, a return 1; } - /// helix's textobjects, which its `]f`, `mif` and kin select: the name a /// query's captures begin with (`function.around`, `test.inside`). pub const Object = @import("modal.zig").Normal.Object; @@ -940,13 +939,10 @@ pub fn highlightLocationRows(gpa: std.mem.Allocator, content: []const u8, rows: } fn codeAfterLocation(line: []const u8) ?struct { path: []const u8, at: usize, text: []const u8 } { - const token_end = std.mem.indexOfAny(u8, line, " \t") orelse return null; - if (token_end == 0) return null; - const token = line[0..token_end]; - const target = look.parsePathLine(token); - if (target.end != token.len) return null; + const trimmed = std.mem.trimStart(u8, line, " \t"); + const target = @import("locations.zig").parseRaw(trimmed); if (target.at.line == 0) return null; - const at = token_end + 1; + const at = line.len - trimmed.len + target.code_start; if (at >= line.len) return null; return .{ .path = target.path, .at = at, .text = line[at..] }; } @@ -1355,6 +1351,11 @@ test "syntax codeAfterLocation takes whole-token locations and nothing else" { try std.testing.expect(codeAfterLocation("src/x.zig:7:2") == null); try std.testing.expect(codeAfterLocation("") == null); try std.testing.expect(codeAfterLocation(" leading space") == null); + const indented = " some directory/x.zig:7:2-9 return 42;"; + const nested = codeAfterLocation(indented) orelse return error.ShouldBeALocation; + try std.testing.expectEqualStrings("some directory/x.zig", nested.path); + try std.testing.expectEqualStrings(" return 42;", nested.text); + try std.testing.expectEqualStrings(nested.text, indented[nested.at..]); } test "syntax default full grammar set highlights Typst source" { @@ -1736,6 +1737,7 @@ test "syntax result fragments preserve source indentation and inline markup" { defer stop(); const fixtures = [_]struct { path: []const u8, source: []const u8 }{ .{ .path = "a.zig", .source = " const number = 42; // note" }, + .{ .path = " nested path/a.zig", .source = " return call(42, \"hello\"); // note" }, .{ .path = "a.md", .source = "# Heading *slant*" }, .{ .path = "a.md", .source = "**bold** and `code`" }, .{ .path = "a.md", .source = " # this is indented code" }, @@ -1961,4 +1963,3 @@ test "syntax source analysis preserves declarations and injected colors" { try std.testing.expectEqual(@as(usize, 0), unsupported.declarations.len); try std.testing.expectEqual(@as(usize, 0), unsupported.colors.len); } - diff --git a/src/tagline.zig b/src/tagline.zig index cf0b17fd..b6601d61 100644 --- a/src/tagline.zig +++ b/src/tagline.zig @@ -19,15 +19,19 @@ const Pardes = pardes.Pardes; pub const pane_tail = " " ++ config.pane_builtins_str; pub const pdf_pane_tail = " " ++ config.pdf_pane_builtins_str; pub const file_pane_tail = " " ++ config.file_pane_builtins_str; -pub const context_pane_tail = file_pane_tail ++ " TreeContext"; -pub const locations_pane_tail = file_pane_tail ++ " LocationsConfig"; -/// A file a language server speaks for (by its extension): its jumps too. -pub const lsp_pane_tail = file_pane_tail ++ " " ++ config.lsp_pane_builtins_str; -pub const lsp_context_pane_tail = context_pane_tail ++ " " ++ config.lsp_pane_builtins_str; +fn withFileCommands(comptime tail: []const u8, comptime words: []const u8) []const u8 { + std.debug.assert(std.mem.endsWith(u8, tail, " Del")); + return tail[0 .. tail.len - " Del".len] ++ " " ++ words ++ " Del"; +} +pub const context_pane_tail = withFileCommands(file_pane_tail, "TreeContext"); +pub const locations_pane_tail = withFileCommands(file_pane_tail, "LocationsConfig"); +/// Language commands precede the final Del, like other file-pane commands. +pub const lsp_pane_tail = withFileCommands(file_pane_tail, config.lsp_pane_builtins_str); +pub const lsp_context_pane_tail = withFileCommands(context_pane_tail, config.lsp_pane_builtins_str); pub const pager_pane_tail = " " ++ config.pager_pane_builtins_str; pub const diff_pane_tail = " " ++ config.diff_pane_builtins_str; pub const pager_diff_pane_tail = " " ++ config.pager_diff_pane_builtins_str; -pub const diff_view_tail = " " ++ config.diff_view_builtins_str ++ " LocationsConfig"; +pub const diff_view_tail = withFileCommands(" " ++ config.diff_view_builtins_str, "LocationsConfig"); pub const terminal_pane_tail = " " ++ config.terminal_pane_builtins_str; pub const command_pane_tail = " " ++ config.command_pane_builtins_str; pub const dir_pane_tail = " " ++ config.dir_pane_builtins_str; @@ -76,7 +80,7 @@ pub fn revealHeader(p: *Pardes) void { if (cur < p.header_top) p.header_top = cur; if (rows > 0 and cur >= p.header_top + rows) p.header_top = cur + 1 - rows; const line = modal.lineSlice(text, cur); - const width = p.tagCapacity(if (p.header_column) |c| p.col_w[c] -| TAG_TEXT_INSET else p.screen_w); + const width = p.tagCapacity(if (p.header_column) |c| p.col_w[c] -| TAG_TEXT_INSET else p.screen_w -| TAG_TEXT_INSET); const col = panes.File.rawDisplayCol(line, @min(@as(usize, @intCast(@max(0, t.cur_col))), line.len)); if (col < p.header_scroll) p.header_scroll = col; if (col >= p.header_scroll + width) p.header_scroll = col -| (width -| 1); @@ -480,4 +484,3 @@ test "a pane tag wraps a long line onto rows, and offsets map both ways" { try std.testing.expectEqual(@as(usize, 10), shown.toReal(11)); // the 'e' of Del try std.testing.expectEqual(@as(usize, 11), shown.fromReal(10)); } - diff --git a/test/column_drag.zig b/test/column_drag.zig index 89508800..a089ab4a 100644 --- a/test/column_drag.zig +++ b/test/column_drag.zig @@ -153,12 +153,14 @@ test "column grip is separate from compact text and the resize seam" { try std.testing.expectEqual(pardes.FontRole.tagline, surface.at(rect.x + pardes.TAG_TEXT_INSET, pardes.TOPBAR_H).style.font_role); try std.testing.expectEqual(pardes.FontRole.tagline, surface.at(rect.x + pardes.TAG_TEXT_INSET, pane_tag_y).style.font_role); } - const gap_x = p.col_x[1] + config.GUTTER; - try std.testing.expectEqualStrings(" ", p.surface.at(gap_x, pardes.TOPBAR_H).grapheme()); - mouse(p, .press, gap_x); - try std.testing.expect(p.drag != .column_move); - try std.testing.expect(!p.header_drag); - mouse(p, .release, gap_x); + if (pardes.TAG_GAP > 0) { + const gap_x = p.col_x[1] + config.GUTTER; + try std.testing.expectEqualStrings(" ", p.surface.at(gap_x, pardes.TOPBAR_H).grapheme()); + mouse(p, .press, gap_x); + try std.testing.expect(p.drag != .column_move); + try std.testing.expect(!p.header_drag); + mouse(p, .release, gap_x); + } p.update(.{ .mouse = headerMouse(layer, 0, .press) }); try std.testing.expect(p.drag != .column_move); try std.testing.expect(p.header_drag); diff --git a/test/hxcases/waivers.jsonl b/test/hxcases/waivers.jsonl index 6abc7de2..34687480 100644 --- a/test/hxcases/waivers.jsonl +++ b/test/hxcases/waivers.jsonl @@ -1,2 +1,3 @@ {"name":"alt-c-window-op","reason":"Alt-c moves a pane to a new column instead of Helix's change-noyank.","reference":{"name":"alt-c-window-op","text":"bc def\n","mode":"insert","cursor":{"row":0,"col":0},"anchor":{"row":0,"col":0}},"expected":{"name":"alt-c-window-op","text":"abc def\n","mode":"normal","cursor":{"row":0,"col":0},"anchor":{"row":0,"col":0}}} {"name":"msel-ins-checkpoint","reason":"Undo restores the primary range alone: a history entry keeps one range, not every one, so the others stay where the edit left them.","reference":{"name":"msel-ins-checkpoint","text":"Xab\nXab\n","mode":"normal","cursor":{"row":1,"col":1},"anchor":{"row":1,"col":1},"sels":[{"cursor":{"row":0,"col":1},"anchor":{"row":0,"col":1}},{"cursor":{"row":1,"col":1},"anchor":{"row":1,"col":1}}],"primary":1},"expected":{"name":"msel-ins-checkpoint","text":"Xab\nXab\n","mode":"normal","cursor":{"row":1,"col":1},"anchor":{"row":1,"col":1},"sels":[{"cursor":{"row":0,"col":2},"anchor":{"row":0,"col":2}},{"cursor":{"row":1,"col":1},"anchor":{"row":1,"col":1}}],"primary":1}} +{"name":"gc-noscroll","reason":"gc runs the Callstack builtin at the cursor instead of moving to the viewport center; with no language server the cursor stays put.","reference":{"name":"gc-noscroll","text":"l00\nl01\nl02\nl03\nl04\nl05\nl06\nl07\nl08\nl09\nl10\nl11\n","mode":"normal","cursor":{"row":6,"col":0},"anchor":{"row":6,"col":0}},"expected":{"name":"gc-noscroll","text":"l00\nl01\nl02\nl03\nl04\nl05\nl06\nl07\nl08\nl09\nl10\nl11\n","mode":"normal","cursor":{"row":0,"col":0},"anchor":{"row":0,"col":0}}} diff --git a/test/panes.zig b/test/panes.zig index 41061bea..86e52838 100644 --- a/test/panes.zig +++ b/test/panes.zig @@ -121,10 +121,12 @@ const TagLayerTests = struct { try std.testing.expectEqual(second, p.drag.move.id); p.update(.{ .mouse = mouse(layer, grip_edge - 0.1, .release) }); try std.testing.expectEqualStrings(" ", p.surface.at(layer.viewport.x - 1, layer.viewport.y).grapheme()); - p.update(.{ .mouse = mouse(layer, edge - 0.1, .press) }); - try std.testing.expect(p.drag != .move); - try std.testing.expect(p.panes[second].?.focus == .body); - p.update(.{ .mouse = mouse(layer, edge - 0.1, .release) }); + if (pardes.TAG_GAP > 0) { + p.update(.{ .mouse = mouse(layer, edge - 0.1, .press) }); + try std.testing.expect(p.drag != .move); + try std.testing.expect(p.panes[second].?.focus == .body); + p.update(.{ .mouse = mouse(layer, edge - 0.1, .release) }); + } p.update(.{ .mouse = mouse(layer, edge + 0.1, .press) }); p.update(.{ .mouse = mouse(layer, edge + 0.1, .release) }); try std.testing.expectEqual(second, p.active); @@ -164,7 +166,6 @@ const TagLayerTests = struct { } }; - // Rows relative to where the pane's body and tag are, whatever height its // tag has (a tag wraps onto more rows when it is long). fn paneAt(p: *Pardes, r: anytype) *pardes.Pane { @@ -2735,6 +2736,146 @@ const OutputTests = struct { } } + test "stacked Callstack aligns source below locations and keeps exact emphasis and navigation" { + if (!syntax.enabled) return error.SkipZigTest; + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 80, .rows = 30 }); + defer p.deinit(); + const source = " pub fn caller(\n value: u32,\n ) void {\n work(value);\n }\n"; + const pane = try TreeContextTests.setZigFile(p, source); + try std.testing.expectEqual(config.Runtime.CallstackLayout.stacked, p.settings.callstack_layout); + const input = try std.fmt.allocPrint(p.gpa, "╰──╮ {s}:1:12-17 caller\n@callstack-match ╰─ {s}:4:9-12 work(value);\n", .{ pane.file.?.path, pane.file.?.path }); + try fillResults(p, 0, "/", .{ .query = .callstack }, "", input, null); + const result_id = pane.search_pane.?; + const result = p.panes[result_id].?; + const file = &result.file.?; + try std.testing.expectEqual(@as(usize, 6), file.location_rows.len); + try std.testing.expectEqualStrings(" │ pub fn caller(", modal.lineSlice(file.content, 1)); + try std.testing.expectEqualStrings(" │ value: u32,", modal.lineSlice(file.content, 2)); + try std.testing.expectEqualStrings(" │ ) void {", modal.lineSlice(file.content, 3)); + try std.testing.expectEqualStrings(" work(value);", modal.lineSlice(file.content, 5)); + const site = file.location_rows[5]; + try std.testing.expectEqual(@as(usize, 8), site.source_column); + try std.testing.expect(site.colors.len > 0); + const text = modal.lineSlice(file.content, 5); + const decoration = panes.Output.decorateRow(file.output, text, site); + try std.testing.expectEqualStrings("work", text[decoration.mark_start..decoration.mark_end]); + for (file.location_rows, 0..) |row, i| { + try std.testing.expectEqual(i == 0 or i == 4, panes.Output.isResultRow(file, i)); + if (i != 5) try std.testing.expect(!row.mark_occurrence); + } + p.active = result_id; + result.body.cur_row = 4; + result.body.cur_col = " └─ ".len; + p.update(.{ .key = .{ .cp = Key.enter } }); + try std.testing.expectEqual(@as(usize, 0), p.active); + try std.testing.expectEqual(@as(i32, 3), pane.body.cur_row); + try pardes.dump.dumpState(p); + const restored = try pardes.dump.initFromDump(p.gpa, .{ .tty_only = true }, p.dump_out.?); + defer restored.deinit(); + try std.testing.expectEqual(config.Runtime.CallstackLayout.stacked, restored.settings.callstack_layout); + const after = restored.panes[result_id].?.file.?; + try std.testing.expectEqualStrings(file.content, after.content); + try std.testing.expectEqual(@as(usize, 8), after.location_rows[5].source_column); + const restored_decoration = panes.Output.decorateRow(after.output, text, after.location_rows[5]); + try std.testing.expectEqual(decoration, restored_decoration); + try std.testing.expect(p.executeBuiltinLine(0, "CallstackLayout inline")); + try fillResults(p, 0, "/", .{ .query = .callstack }, "", try p.gpa.dupe(u8, "No callers reported\n"), null); + try std.testing.expectEqual(config.Runtime.CallstackLayout.@"inline", p.settings.callstack_layout); + } + + test "Callstack signatures share unsaved tree context and keep guides out of Look selections" { + if (!syntax.enabled) return error.SkipZigTest; + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 110, .rows = 30 }); + defer p.deinit(); + p.settings.callstack_layout = .@"inline"; + const source = "const Box = struct {\n" ++ + " pub fn caller(\n" ++ + " value: u32,\n" ++ + " ) void {\n" ++ + " work(value);\n" ++ + " }\n};\n"; + const pane = try TreeContextTests.setZigFile(p, source); + const path = pane.file.?.path; + const input = try std.fmt.allocPrint(p.gpa, "├──┬ {s}:2:12-17 caller\n@callstack-match │ └─ {s}:5:9-12 work(value);\n└─── missing.zig:3:4-8 other ↻ recursion\n", .{ path, path }); + try fillResults(p, 0, "/", .{ .query = .callstack }, "", input, null); + const result_id = pane.search_pane.?; + const result = p.panes[result_id].?; + const file = &result.file.?; + try std.testing.expect(std.mem.indexOf(u8, file.content, "pub fn caller(") != null); + try std.testing.expect(std.mem.indexOf(u8, file.content, "value: u32,") != null); + try std.testing.expect(std.mem.indexOf(u8, file.content, "const Box") == null); + try std.testing.expect(std.mem.indexOf(u8, file.content, "other ↻ recursion") != null); + try std.testing.expectEqual(@as(usize, 5), file.location_rows.len); + for (file.location_rows[0..3]) |row| { + try std.testing.expect(!row.declaration); + try std.testing.expect(!row.mark_occurrence); + try std.testing.expect(row.colors.len > 0); + } + for (1..3) |index| try std.testing.expect(std.mem.startsWith(u8, modal.lineSlice(file.content, index), "│ │ ")); + const analysis = try syntax.analyzeSource(p.scratch.allocator(), path, source, true, true); + for (file.location_rows[0..3], 1..) |row, source_row| { + const offset = modal.lineStartOffset(source, source_row); + try std.testing.expectEqualSlices(u8, analysis.colors[offset..][0..row.colors.len], row.colors); + } + try std.testing.expect(file.location_rows[3].mark_occurrence); + try std.testing.expect(!file.location_rows[3].declaration); + try std.testing.expect(!panes.Output.isWalkRow(file, 1, modal.lineSlice(file.content, 1))); + p.active = result_id; + result.body.cur_row = 0; + result.body.cur_col = 0; + p.update(.{ .key = .{ .cp = ' ' } }); + p.update(.{ .key = .{ .cp = 'j' } }); + p.update(.{ .key = .{ .cp = 'n' } }); + try std.testing.expectEqual(@as(i32, 0), result.body.cur_row); + try std.testing.expectEqual(@as(i32, "├──┬ ".len), result.body.cur_col); + // Enter on the selected signature address must open source, not a path + // accidentally prefixed with tree glyphs. + p.update(.{ .key = .{ .cp = Key.enter } }); + try std.testing.expectEqual(@as(usize, 0), p.active); + try std.testing.expectEqual(@as(i32, 1), pane.body.cur_row); + p.settings.callstack_depth = 16; + try pardes.dump.dumpState(p); + const restored = try pardes.dump.initFromDump(p.gpa, .{ .tty_only = true }, p.dump_out.?); + defer restored.deinit(); + try std.testing.expectEqual(@as(u8, 16), restored.settings.callstack_depth); + const restored_file = restored.panes[result_id].?.file.?; + try std.testing.expectEqualStrings(file.content, restored_file.content); + try std.testing.expectEqual(file.location_rows.len, restored_file.location_rows.len); + for (file.location_rows, restored_file.location_rows) |before, after| { + try std.testing.expectEqual(before.mark_occurrence, after.mark_occurrence); + try std.testing.expectEqual(before.at, after.at); + try std.testing.expectEqual(before.code_start, after.code_start); + try std.testing.expectEqualSlices(u8, before.colors, after.colors); + } + // Narrow enough that the location itself wraps. The repeated guide + // consumes cells, but neither changes the source address nor steals + // a click from the wrapped portion of that address. + p.active = result_id; + p.row_metrics = .{ .body_w = 10, .body_h = 20, .tagline_w = 8, .tagline_h = 10 }; + p.update(.{ .resize = .{ .cols = 28, .rows = 40 } }); + result.file.?.scroll = 0; + var frame = std.heap.ArenaAllocator.init(p.gpa); + defer frame.deinit(); + _ = try p.render(frame.allocator()); + const wrapped = for (0..result.wrap_n) |vr| { + const w = result.wrapAt(@intCast(vr)); + if (w.line == 0 and w.pad > 0 and w.at < file.location_rows[0].location_end) break vr; + } else return error.MissingWrappedLocation; + const w = result.wrapAt(@intCast(wrapped)); + const shown = try panes.File.bodyText(frame.allocator(), result, file, true); + const shown_line = modal.lineSlice(shown, wrapped); + try std.testing.expect(std.mem.startsWith(u8, shown_line[panes.File.gutterWidth(result)..], "│ │ ")); + const rect = p.rects[result_id]; + const press: pardes.Mouse = .{ .button = .right, .kind = .press, .col = @intCast(rect.x + config.GUTTER + panes.File.gutterWidth(result) + w.pad + 1), .row = @intCast(p.bodyTop(result, rect) + wrapped) }; + + var release = press; + release.kind = .release; + p.update(.{ .mouse = press }); + p.update(.{ .mouse = release }); + try std.testing.expectEqual(@as(usize, 0), p.active); + try std.testing.expectEqual(@as(i32, 1), pane.body.cur_row); + } + test "Locations context uses unsaved sources and navigation visits only matches" { if (!syntax.enabled) return error.SkipZigTest; const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 30 }); diff --git a/test/snapshots/argv.golden b/test/snapshots/argv.golden index 65b0ac71..9dfa35b9 100644 --- a/test/snapshots/argv.golden +++ b/test/snapshots/argv.golden @@ -1,7 +1,7 @@ == snap noargs grid=100x31 cursor=4,5 -|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit -| New Tty Find Grep Joincol Delcol -|$ /tmp/pardes-snap/argv/cwd Tty+bash Save Mode Filter Collapse Del +| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +| New Tty Find Grep Joincol Delcol +|$ /tmp/pardes-snap/argv/cwd Tty+bash Save Mode Filter Collapse Del | $ echo ARGV''TTY | ARGVTTY | $ @@ -20,12 +20,12 @@ | | | -| /tmp/pardes-snap/argv/cwd/+New Save Tty Collapse Del +| /tmp/pardes-snap/argv/cwd/+New Save Tty Collapse Del | 1 == snap filearg grid=100x31 cursor=7,3 -|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit -| New Tty Find Grep Joincol Delcol -| /tmp/pardes-snap/argv/cwd/notes.txt Save Tty Collapse Del +| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +| New Tty Find Grep Joincol Delcol +| /tmp/pardes-snap/argv/cwd/notes.txt Save Tty Collapse Del | 3 line 3 | 4 line 4 | 5 line 5 @@ -34,9 +34,9 @@ | 8 line 8 | 9 == snap filearg-n3 grid=100x31 cursor=7,3 -|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit -| New Tty Find Grep Joincol Delcol -| /tmp/pardes-snap/argv/cwd/notes.txt Save Tty Collapse Del +| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +| New Tty Find Grep Joincol Delcol +| /tmp/pardes-snap/argv/cwd/notes.txt Save Tty Collapse Del | 1 line 1 | 2 line 2 | 3 line 3 @@ -47,8 +47,8 @@ | 8 line 8 | 9 == snap dirarg grid=100x31 cursor=4,5 -|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit -| New Tty Find Grep Joincol Delcol -| /tmp/pardes-snap/argv/cwd/sub Tty+bash Save Mode Filter Collapse Del +| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +| New Tty Find Grep Joincol Delcol +| /tmp/pardes-snap/argv/cwd/sub Tty+bash Save Mode Filter Collapse Del | ls | inside.txt diff --git a/test/snapshots/badutf.golden b/test/snapshots/badutf.golden index 14aa71dc..1cdd5163 100644 --- a/test/snapshots/badutf.golden +++ b/test/snapshots/badutf.golden @@ -1,17 +1,17 @@ == snap badbytes grid=100x31 cursor=7,3 -|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit -| New Tty Find Grep Joincol Delcol -| /tmp/pardes-snap/badutf/cwd/bad.txt Save Tty Collapse Del +| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +| New Tty Find Grep Joincol Delcol +| /tmp/pardes-snap/badutf/cwd/bad.txt Save Tty Collapse Del | 1 hello �� world | 2 latin-1 caf� tail | 3 truncated �� here | 4 end | 5 == snap hscroll-midglyph grid=50x31 cursor=46,4 -|Newcol Joincol Find Grep Help Changelog Tutor Dump -| New Tty Find Grep Joincol Delcol -| /tmp/pardes-snap/badutf/cwd/wide.txt Save Tty C -| ollapse Del +| Newcol Joincol Find Grep Help Changelog Tutor Du +| New Tty Find Grep Joincol Delcol +| /tmp/pardes-snap/badutf/cwd/wide.txt Save Tty Co +| llapse Del | 1 日本語 日本語 日本語 日本語 日本語 tail | 2 | 3 diff --git a/test/snapshots/boot.golden b/test/snapshots/boot.golden index ac674ed2..85b994d7 100644 --- a/test/snapshots/boot.golden +++ b/test/snapshots/boot.golden @@ -1,13 +1,13 @@ == snap boot grid=100x31 cursor=4,5 -|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit -| New Tty Find Grep Joincol Delcol -| /tmp/pardes-snap/boot/cwd Tty+bash Save Mode Filter Collapse Del +| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +| New Tty Find Grep Joincol Delcol +| /tmp/pardes-snap/boot/cwd Tty+bash Save Mode Filter Collapse Del | ls | hello.txt == style boot grid=100x31 -|0: 0-99 #b2c3b8,#1d2824, -|1: 0-1 d,#887455, 2-2 d,#314738, 3-99 #becfc4,#314738, -|2: 0-1 d,#add38a, 2-2 d,#314738, 3-28 #becfc4,#314738, 29-37 #dfbce5,#314738, 38-99 #becfc4,#314738, +|0: 0-1 d,#1d2824, 2-99 #b2c3b8,#1d2824, +|1: 0-1 d,#887455, 2-99 #becfc4,#314738, +|2: 0-1 d,#add38a, 2-27 #becfc4,#314738, 28-36 #dfbce5,#314738, 37-99 #becfc4,#314738, |3: 0-0 d,#608269, 1-1 d,#0d1410, 2-99 #e5eee5,#0d1410, |4: 0-0 d,#608269, 1-1 d,#0d1410, 2-99 #e5eee5,#0d1410, |5: 0-0 d,#608269, 1-99 d,#0d1410, diff --git a/test/snapshots/builtins.golden b/test/snapshots/builtins.golden index 2207ede6..b9d5c5b2 100644 --- a/test/snapshots/builtins.golden +++ b/test/snapshots/builtins.golden @@ -1,7 +1,7 @@ == snap boot grid=120x67 cursor=7,3 -|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit -| New Tty Find Grep Joincol Delcol -| /tmp/pardes-snap/builtins/cwd/notes.txt Save Tty Collapse Del +| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +| New Tty Find Grep Joincol Delcol +| /tmp/pardes-snap/builtins/cwd/notes.txt Save Tty Collapse Del | 1 line 1 | 2 line 2 | 3 line 3 @@ -10,7 +10,7 @@ | 6 line 6 | 7 == snap window-group grid=120x67 cursor=7,10 -|9: /tmp/pardes-snap/builtins/cwd/+Help Save Tty Collapse Del +|9: /tmp/pardes-snap/builtins/cwd/+Help Save Tty Collapse Del |10: 1 pardes builtins under SPC w |11: 2 |12: 3 SPC w h Left C-w h, C-w left @@ -27,7 +27,7 @@ |16: == snap tutor-from-index grid=120x67 cursor=7,16 |10: 1 pardes builtins under SPC h Tutor -|15: /tmp/pardes-snap/builtins/cwd/+Tutor Save Tty Collapse Del +|15: /tmp/pardes-snap/builtins/cwd/+Tutor Save Tty Collapse Del |16: 1 |17: 2 PARDES TUTOR |18: 3 diff --git a/test/snapshots/builtins.snap b/test/snapshots/builtins.snap index 8ae22a62..fc0ab796 100644 --- a/test/snapshots/builtins.snap +++ b/test/snapshots/builtins.snap @@ -30,6 +30,8 @@ wheel up 110 50 wheel up 110 50 wheel up 110 50 wheel up 110 50 +wheel up 110 50 +wheel up 110 50 wait 10000 Look enter, right-click wait 10000 Exec tab, middle-click wait 10000 Filter diff --git a/test/snapshots/callstack-inline.golden b/test/snapshots/callstack-inline.golden new file mode 100644 index 00000000..32213223 --- /dev/null +++ b/test/snapshots/callstack-inline.golden @@ -0,0 +1,65 @@ +== snap hierarchy grid=110x40 cursor=7,14 +| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +| New Tty Find Grep Joincol Delcol +| /tmp/pardes-snap/callstack-inline/cwd/setup.txt Save Tty Collapse Del +| 1 CallstackLayout inline +| 2 main.rs +| /tmp/pardes-snap/callstack-inline/cwd/main.rs Save Tty Collapse TreeContext Def Refs Del +| 1 mod lib; --:--:-- lsp rust-analyzer: ready +| 2 +| 3 fn main() { +| 4 let x = add(1, 2); +| 5 let y = add(3, 4); +| 6 let _ = x + y; +| 7 } +| /tmp/pardes-snap/callstack-inline/cwd/+Callstack Save Tty Collapse Del +| 1 ╰──┬ main.rs:3:4-7 fn main() { +| 2 ├─ main.rs:4:13-15 let x = add(1, 2); +| 3 ├─ main.rs:5:13-15 let y = add(3, 4); +| 4 ╰──┬ main.rs:3:4-7 fn main() { ↻ recursion +| 5 ├─ main.rs:4:13-15 let x = add(1, 2); +| 6 ╰─ main.rs:5:13-15 let y = add(3, 4); +| 7 +== style hierarchy grid=110x40 +|0: 0-1 d,#1d2824, 2-109 #b2c3b8,#1d2824, +|1: 0-1 d,#887455, 2-109 #becfc4,#314738, +|2: 0-1 d,#496656, 2-39 #b2c3b8,#1d2824, 40-49 #d3b0d9,#1d2824, 50-109 #b2c3b8,#1d2824, +|3: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-109 #e5eee5,#0d1410, +|4: 0-0 d,#152019, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-109 #e5eee5,#0d1410, +|5: 0-1 d,#496656, 2-39 #b2c3b8,#1d2824, 40-47 #d3b0d9,#1d2824, 48-109 #b2c3b8,#1d2824, +|6: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-10 #c9a7ed,#0d1410, 11-73 #e5eee5,#0d1410, 74-74 #e5eee5,#1d2824, 75-109 #b2c3b8,#1d2824, +|7: 0-0 d,#608269, 1-4 d,#0d1410, 5-109 #59675c,#0d1410, +|8: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-9 #c9a7ed,#0d1410, 10-109 #e5eee5,#0d1410, +|9: 0-0 d,#608269, 1-4 d,#0d1410, 5-10 #59675c,#0d1410, 11-14 #c9a7ed,#0d1410, 15-109 #e5eee5,#0d1410, +|10: 0-0 d,#608269, 1-4 d,#0d1410, 5-10 #59675c,#0d1410, 11-14 #c9a7ed,#0d1410, 15-109 #e5eee5,#0d1410, +|11: 0-0 d,#608269, 1-4 d,#0d1410, 5-10 #59675c,#0d1410, 11-14 #c9a7ed,#0d1410, 15-109 #e5eee5,#0d1410, +|12: 0-0 d,#152019, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-109 #e5eee5,#0d1410, +|13: 0-1 d,#add38a, 2-39 #becfc4,#314738, 40-50 #dfbce5,#314738, 51-109 #becfc4,#314738, +|14: 0-0 d,#608269, 1-1 d,#0d1410, 2-4 d,#0d1410,b 5-6 #616f64,#0d1410,b 7-11 #92d1de,#0d1410, 12-25 #59675c,#0d1410, 26-28 #c9a7ed,#0d1410, 29-109 #e5eee5,#0d1410, +|15: 0-0 d,#608269, 1-4 d,#0d1410, 5-9 #59675c,#0d1410, 10-12 #92d1de,#0d1410, 13-32 #59675c,#0d1410, 33-36 #c9a7ed,#0d1410, 37-109 #e5eee5,#0d1410, +|16: 0-0 d,#608269, 1-4 d,#0d1410, 5-9 #59675c,#0d1410, 10-12 #92d1de,#0d1410, 13-32 #59675c,#0d1410, 33-36 #c9a7ed,#0d1410, 37-109 #e5eee5,#0d1410, +|17: 0-0 d,#608269, 1-4 d,#0d1410, 5-9 #59675c,#0d1410, 10-14 #92d1de,#0d1410, 15-28 #59675c,#0d1410, 29-31 #c9a7ed,#0d1410, 32-109 #e5eee5,#0d1410, +|18: 0-0 d,#608269, 1-4 d,#0d1410, 5-12 #59675c,#0d1410, 13-15 #92d1de,#0d1410, 16-35 #59675c,#0d1410, 36-39 #c9a7ed,#0d1410, 40-43 #e5eee5,#0d1410, 44-46 #f7e4a5,#5e4923, 47-109 #e5eee5,#0d1410, +|19: 0-0 d,#608269, 1-4 d,#0d1410, 5-12 #59675c,#0d1410, 13-15 #92d1de,#0d1410, 16-35 #59675c,#0d1410, 36-39 #c9a7ed,#0d1410, 40-43 #e5eee5,#0d1410, 44-46 #f7e4a5,#5e4923, 47-109 #e5eee5,#0d1410, +|20: 0-0 d,#608269, 1-4 d,#0d1410, 5-109 #59675c,#0d1410, +|21: 0-0 d,#608269, 1-109 d,#0d1410, +|22: 0-0 d,#608269, 1-109 d,#0d1410, +|23: 0-0 d,#608269, 1-109 d,#0d1410, +|24: 0-0 d,#608269, 1-109 d,#0d1410, +|25: 0-0 d,#608269, 1-109 d,#0d1410, +|26: 0-0 d,#608269, 1-109 d,#0d1410, +|27: 0-0 d,#608269, 1-109 d,#0d1410, +|28: 0-0 d,#608269, 1-109 d,#0d1410, +|29: 0-0 d,#608269, 1-109 d,#0d1410, +|30: 0-0 d,#608269, 1-109 d,#0d1410, +|31: 0-0 d,#608269, 1-109 d,#0d1410, +|32: 0-0 d,#608269, 1-109 d,#0d1410, +|33: 0-0 d,#608269, 1-109 d,#0d1410, +|34: 0-0 d,#608269, 1-109 d,#0d1410, +|35: 0-0 d,#608269, 1-109 d,#0d1410, +|36: 0-0 d,#608269, 1-109 d,#0d1410, +|37: 0-0 d,#608269, 1-109 d,#0d1410, +|38: 0-0 d,#608269, 1-109 d,#0d1410, +|39: 0-0 d,#608269, 1-109 d,#0d1410, +== snap caller grid=110x40 cursor=13,8 +|6: 1 mod lib; diff --git a/test/snapshots/callstack-inline.snap b/test/snapshots/callstack-inline.snap new file mode 100644 index 00000000..9acfa206 --- /dev/null +++ b/test/snapshots/callstack-inline.snap @@ -0,0 +1,30 @@ +# Inline remains an option; source colors, rounded guides and Look navigation are retained. +file main.rs mod lib;\n\nfn main() {\n let x = add(1, 2);\n let y = add(3, 4);\n let _ = x + y;\n}\n +file lib.rs // mock fixture\npub fn add(a: i32, b: i32) -> i32 {\n a + b\n}\n +file setup.txt CallstackLayout inline\nmain.rs\n +start 40 110 setup.txt +wait 8000 CallstackLayout inline +key g g +key x +key tab +stable 300 10000 +key esc +settle 100 +key g g +key j +key home +key enter +wait 8000 add(1, 2) +stable 700 20000 +key g c +wait 10000 Callstack +wait 10000 recursion +stable 700 15000 +snap hierarchy +snapstyle hierarchy +# LookNext selects the caller signature; Enter opens it in the source pane. +key space j n +key enter +wait 10000 fn main +stable 700 15000 +snap caller diff --git a/test/snapshots/callstack.golden b/test/snapshots/callstack.golden new file mode 100644 index 00000000..2970593d --- /dev/null +++ b/test/snapshots/callstack.golden @@ -0,0 +1,27 @@ +== snap hierarchy grid=110x40 cursor=7,11 +| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +| New Tty Find Grep Joincol Delcol +| /tmp/pardes-snap/callstack/cwd/main.rs Save Tty Collapse TreeContext Def Refs Del +| 1 mod lib; --:--:-- lsp rust-analyzer: ready +| 2 +| 3 fn main() { +| 4 let x = add(1, 2); +| 5 let y = add(3, 4); +| 6 let _ = x + y; +| 7 } +| /tmp/pardes-snap/callstack/cwd/+Callstack Save Tty Collapse Del +| 1 ╰──┬ main.rs:3:4-7 +| 2 │ fn main() { +| 3 ├─ main.rs:4:13-15 +| 4 │ let x = add(1, 2); +| 5 ├─ main.rs:5:13-15 +| 6 │ let y = add(3, 4); +| 7 ╰──┬ main.rs:3:4-7 +| 8 │ fn main() { ↻ recursion +| 9 ├─ main.rs:4:13-15 +| 10 │ let x = add(1, 2); +| 11 ╰─ main.rs:5:13-15 +| 12 let y = add(3, 4); +| 13 +== snap caller grid=110x40 cursor=13,5 +|3: 1 mod lib; diff --git a/test/snapshots/callstack.snap b/test/snapshots/callstack.snap new file mode 100644 index 00000000..b32367af --- /dev/null +++ b/test/snapshots/callstack.snap @@ -0,0 +1,19 @@ +# Static call hierarchy in a dedicated pane; sites and declarations are Look targets. +file main.rs mod lib;\n\nfn main() {\n let x = add(1, 2);\n let y = add(3, 4);\n let _ = x + y;\n}\n +file lib.rs // mock fixture\npub fn add(a: i32, b: i32) -> i32 {\n a + b\n}\n +start 40 110 main.rs +wait 8000 add(1, 2) +stable 700 20000 +press left 13 6 +release left 13 6 +key g c +wait 10000 Callstack +wait 10000 recursion +stable 700 15000 +snap hierarchy +# LookNext selects the caller signature; Enter opens it in the source pane. +key space j n +key enter +wait 10000 fn main +stable 700 15000 +snap caller diff --git a/test/snapshots/chordcut.golden b/test/snapshots/chordcut.golden index 817c534c..280dd877 100644 --- a/test/snapshots/chordcut.golden +++ b/test/snapshots/chordcut.golden @@ -1,12 +1,12 @@ == snap opened grid=120x31 cursor=7,8 -|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit -| New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol -| /tmp/pardes-snap/chordcut/cwd Tty+bash Save Mode Filter C /tmp/pardes-snap/chordcut/cwd Tty+bash Save Mode Filter C -| ollapse Del ollapse Del +| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +| New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol +| /tmp/pardes-snap/chordcut/cwd Tty+bash Save Mode Filter Co /tmp/pardes-snap/chordcut/cwd Tty+bash Save Mode Filter Co +| llapse Del llapse Del | ls ls | f.txt g.txt f.txt g.txt | -| /tmp/pardes-snap/chordcut/cwd/f.txt Save Tty Collapse Del +| /tmp/pardes-snap/chordcut/cwd/f.txt Save Tty Collapse Del | 1 line 1 | 2 line 2 | 3 line 3 @@ -16,12 +16,12 @@ | | | -| /tmp/pardes-snap/chordcut/cwd Tty+bash Save Mode Filter C -| ollapse Del +| /tmp/pardes-snap/chordcut/cwd Tty+bash Save Mode Filter Co +| llapse Del | ls | f.txt g.txt == snap cut grid=120x31 cursor=7,9 -|7: * /tmp/pardes-snap/chordcut/cwd/f.txt Save Tty Collapse Del +|7: */tmp/pardes-snap/chordcut/cwd/f.txt Save Tty Collapse Del |9: 2 2 == snap copied grid=120x31 cursor=10,10 == snap pointpaste grid=120x31 cursor=16,11 @@ -32,27 +32,27 @@ |9: 2 2echo B''OO g.txt == snap execafter grid=120x31 cursor=25,9 |8: 1 line 1 Exec -|17: /tmp/pardes-snap/chordcut/cwd Tty+bash Save Mode Filter C /tmp/pardes-snap/chordcut/cwd (echo B''OO) exit 0 Kill Sa -|18: ollapse Del ve Collapse Del +|17: /tmp/pardes-snap/chordcut/cwd Tty+bash Save Mode Filter Co /tmp/pardes-snap/chordcut/cwd (echo B''OO) exit 0 Kill Sav +|18: llapse Del e Collapse Del |19: ls % echo B''OO |20: f.txt g.txt BOO |21: exit 0 == snap cancellook grid=120x31 cursor=25,9 |8: 1 line 1 == snap lookafter grid=120x31 cursor=7,23 -|22: /tmp/pardes-snap/chordcut/cwd/g.txt Save Tty Collapse Del +|22: /tmp/pardes-snap/chordcut/cwd/g.txt Save Tty Collapse Del |23: 1 line 1 |24: 2 line 2 |25: 3 == style chordsel grid=120x31 -|0: 0-119 #b2c3b8,#1d2824, -|1: 0-1 d,#887455, 2-2 d,#314738, 3-59 #becfc4,#314738, 60-61 #becfc4,#887455, 62-62 #becfc4,#1d2824, 63-119 #b2c3b8,#1d2824, -|2: 0-1 d,#496656, 2-2 d,#1d2824, 3-32 #b2c3b8,#1d2824, 33-41 #d3b0d9,#1d2824, 42-59 #b2c3b8,#1d2824, 60-61 #b2c3b8,#496656, 62-92 #b2c3b8,#1d2824, 93-101 #d3b0d9,#1d2824, 102-119 #b2c3b8,#1d2824, -|3: 0-2 d,#1d2824, 3-119 #b2c3b8,#1d2824, +|0: 0-1 d,#1d2824, 2-119 #b2c3b8,#1d2824, +|1: 0-1 d,#887455, 2-59 #becfc4,#314738, 60-61 #becfc4,#887455, 62-119 #b2c3b8,#1d2824, +|2: 0-1 d,#496656, 2-31 #b2c3b8,#1d2824, 32-40 #d3b0d9,#1d2824, 41-59 #b2c3b8,#1d2824, 60-61 #b2c3b8,#496656, 62-91 #b2c3b8,#1d2824, 92-100 #d3b0d9,#1d2824, 101-119 #b2c3b8,#1d2824, +|3: 0-1 d,#1d2824, 2-119 #b2c3b8,#1d2824, |4: 0-0 d,#608269, 1-1 d,#0d1410, 2-59 #e5eee5,#0d1410, 60-60 #e5eee5,#608269, 61-119 #e5eee5,#0d1410, |5: 0-0 d,#608269, 1-1 d,#0d1410, 2-59 #e5eee5,#0d1410, 60-60 #e5eee5,#608269, 61-119 #e5eee5,#0d1410, |6: 0-0 d,#608269, 1-59 d,#0d1410, 60-60 d,#608269, 61-119 d,#0d1410, -|7: 0-0 d,#496656, 1-1 #000000,#f9cb70,b 2-2 #000000,#1d2824, 3-32 #b2c3b8,#1d2824, 33-38 #d3b0d9,#1d2824, 39-59 #b2c3b8,#1d2824, 60-60 #b2c3b8,#608269, 61-119 #b2c3b8,#0d1410, +|7: 0-0 d,#496656, 1-1 #000000,#f9cb70,b 2-31 #b2c3b8,#1d2824, 32-37 #d3b0d9,#1d2824, 38-59 #b2c3b8,#1d2824, 60-60 #b2c3b8,#608269, 61-119 #b2c3b8,#0d1410, |8: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-59 #e5eee5,#0d1410, 60-60 #e5eee5,#608269, 61-119 #e5eee5,#0d1410, |9: 0-0 d,#608269, 1-4 d,#0d1410, 5-7 #59675c,#0d1410, 8-59 #e5eee5,#0d1410, 60-60 #e5eee5,#608269, 61-119 #e5eee5,#0d1410, |10: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-59 #e5eee5,#0d1410, 60-60 #e5eee5,#608269, 61-119 #e5eee5,#0d1410, @@ -62,12 +62,12 @@ |14: 0-0 d,#608269, 1-59 d,#0d1410, 60-60 d,#608269, 61-119 d,#0d1410, |15: 0-0 d,#608269, 1-59 d,#0d1410, 60-60 d,#608269, 61-119 d,#0d1410, |16: 0-0 d,#608269, 1-59 d,#0d1410, 60-60 d,#608269, 61-119 d,#0d1410, -|17: 0-1 d,#496656, 2-2 d,#1d2824, 3-32 #b2c3b8,#1d2824, 33-41 #d3b0d9,#1d2824, 42-59 #b2c3b8,#1d2824, 60-61 #b2c3b8,#496656, 62-119 #b2c3b8,#1d2824, -|18: 0-2 d,#1d2824, 3-119 #b2c3b8,#1d2824, +|17: 0-1 d,#496656, 2-31 #b2c3b8,#1d2824, 32-40 #d3b0d9,#1d2824, 41-59 #b2c3b8,#1d2824, 60-61 #b2c3b8,#496656, 62-119 #b2c3b8,#1d2824, +|18: 0-1 d,#1d2824, 2-119 #b2c3b8,#1d2824, |19: 0-0 d,#608269, 1-1 d,#0d1410, 2-59 #e5eee5,#0d1410, 60-60 #e5eee5,#608269, 61-119 #e5eee5,#0d1410, |20: 0-0 d,#608269, 1-1 d,#0d1410, 2-59 #e5eee5,#0d1410, 60-60 #e5eee5,#608269, 61-119 #e5eee5,#0d1410, |21: 0-0 d,#608269, 1-59 d,#0d1410, 60-60 d,#608269, 61-61 d,#0d1410, 62-119 #e5eee5,#0d1410, -|22: 0-1 d,#add38a, 2-2 d,#314738, 3-32 #becfc4,#314738, 33-38 #dfbce5,#314738, 39-59 #becfc4,#314738, 60-60 #becfc4,#608269, 61-119 #becfc4,#0d1410, +|22: 0-1 d,#add38a, 2-31 #becfc4,#314738, 32-37 #dfbce5,#314738, 38-59 #becfc4,#314738, 60-60 #becfc4,#608269, 61-119 #becfc4,#0d1410, |23: 0-0 d,#608269, 1-1 d,#0d1410, 2-4 d,#0d1410,b 5-6 #616f64,#0d1410,b 7-10 #f5f7ee,#3c614a, 11-11 #f5f7ee,#0d1410, 12-59 #e5eee5,#0d1410, 60-60 #e5eee5,#608269, 61-119 #e5eee5,#0d1410, |24: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-59 #e5eee5,#0d1410, 60-60 #e5eee5,#608269, 61-119 #e5eee5,#0d1410, |25: 0-0 d,#608269, 1-4 d,#0d1410, 5-59 #59675c,#0d1410, 60-60 #59675c,#608269, 61-119 #59675c,#0d1410, @@ -80,7 +80,7 @@ |23: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-59 #e5eee5,#0d1410, 60-60 #e5eee5,#608269, 61-119 #e5eee5,#0d1410, |24: 0-0 d,#608269, 1-1 d,#0d1410, 2-4 d,#0d1410,b 5-6 #616f64,#0d1410,b 7-59 #e5eee5,#0d1410, 60-60 #e5eee5,#608269, 61-119 #e5eee5,#0d1410, == snap ttyprobe grid=120x31 cursor=42,23 -|17: $ /tmp/pardes-snap/chordcut/cwd Tty+bash Save Mode Filter C /tmp/pardes-snap/chordcut/cwd (echo B''OO) exit 0 Kill Sa +|17: $ /tmp/pardes-snap/chordcut/cwd Tty+bash Save Mode Filter Co /tmp/pardes-snap/chordcut/cwd (echo B''OO) exit 0 Kill Sav |19: $ ls % echo B''OO |21: $ stty -icanon -echo; printf '\x1b[?2004h\x1b[?1000h\x1b[? exit 0 |22: 1006h'; cat -v diff --git a/test/snapshots/cmdexit.golden b/test/snapshots/cmdexit.golden index 7d950a43..f2f38217 100644 --- a/test/snapshots/cmdexit.golden +++ b/test/snapshots/cmdexit.golden @@ -1,15 +1,15 @@ == snap opened grid=120x31 cursor=7,3 -|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit -| New Tty Find Grep Joincol Delcol -| /tmp/pardes-snap/cmdexit/cwd/cmds.txt Save Tty Collapse Del +| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +| New Tty Find Grep Joincol Delcol +| /tmp/pardes-snap/cmdexit/cwd/cmds.txt Save Tty Collapse Del | 1 sleep 30 & echo BG''STARTED | 2 exec /dev/null 2>&1; sleep 1; false == snap background grid=120x31 cursor=7,3 -|17: /tmp/pardes-snap/cmdexit/cwd (sleep 30 & echo BG''STARTED) exit 0 Kill Save Collapse Del +|17: /tmp/pardes-snap/cmdexit/cwd (sleep 30 & echo BG''STARTED) exit 0 Kill Save Collapse Del |18: % sleep 30 & echo BG''STARTED |19: BGSTARTED |20: exit 0 == snap letgo grid=120x31 cursor=7,3 -|24: /tmp/pardes-snap/cmdexit/cwd (exec /dev/null 2>&1; sleep 1; false) exit 1 Kill Save Collapse Del +|24: /tmp/pardes-snap/cmdexit/cwd (exec /dev/null 2>&1; sleep 1; false) exit 1 Kill Save Collapse Del |25: % exec /dev/null 2>&1; sleep 1; false |26: exit 1 diff --git a/test/snapshots/cmdword.golden b/test/snapshots/cmdword.golden index af2fbcb8..3b2f5cc9 100644 --- a/test/snapshots/cmdword.golden +++ b/test/snapshots/cmdword.golden @@ -1,28 +1,28 @@ == snap opened grid=120x31 cursor=7,3 -|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit -| New Tty Find Grep Joincol Delcol -| /tmp/pardes-snap/cmdword/cwd/cmds.txt Save Tty Collapse Del +| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +| New Tty Find Grep Joincol Delcol +| /tmp/pardes-snap/cmdword/cwd/cmds.txt Save Tty Collapse Del | 1 @`echo ZZ''E` @`echo ZZ''L` Look p.txt @`Look .` == snap atexec grid=120x31 cursor=7,3 -|17: /tmp/pardes-snap/cmdword/cwd (echo ZZ''E) exit 0 Kill Save Collapse Del +|17: /tmp/pardes-snap/cmdword/cwd (echo ZZ''E) exit 0 Kill Save Collapse Del |18: % echo ZZ''E |19: ZZE |20: exit 0 == snap atlook grid=120x31 cursor=2,24 -|17: /tmp/pardes-snap/cmdword/cwd (echo ZZ''L) exit 0 Kill Save Collapse Del +|17: /tmp/pardes-snap/cmdword/cwd (echo ZZ''L) exit 0 Kill Save Collapse Del |21: % echo ZZ''L |22: ZZL |23: exit 0 == snap lookword grid=120x31 cursor=7,6 -|5: /tmp/pardes-snap/cmdword/cwd/p.txt Save Tty Collapse Del +|5: /tmp/pardes-snap/cmdword/cwd/p.txt Save Tty Collapse Del |6: 1 just text == snap nested grid=120x31 cursor=4,11 -|8: /tmp/pardes-snap/cmdword/cwd Tty+bash Save Mode Filter Collapse Del +|8: /tmp/pardes-snap/cmdword/cwd Tty+bash Save Mode Filter Collapse Del |9: ls |10: cmds.txt p.txt zzmark.txt == snap execword grid=120x31 cursor=4,11 -|8: /tmp/pardes-snap/cmdword/cwd Tty+bash Save Mode Filter Collapse Del Exec +|8: /tmp/pardes-snap/cmdword/cwd Tty+bash Save Mode Filter Collapse Del Exec == snap tagcmd grid=120x31 cursor=4,11 -|8: /tmp/pardes-snap/cmdword/cwd Tty+bash Save Mode Filter Collapse Del Exec @`echo ZZ''T` +|8: /tmp/pardes-snap/cmdword/cwd Tty+bash Save Mode Filter Collapse Del Exec @`echo ZZ''T` |11: echo ZZ''T |12: ZZT diff --git a/test/snapshots/colgrip.golden b/test/snapshots/colgrip.golden index 26a0b1c0..e7881957 100644 --- a/test/snapshots/colgrip.golden +++ b/test/snapshots/colgrip.golden @@ -1,8 +1,8 @@ == style rest grid=100x24 -|0: 0-99 #b2c3b8,#1d2824, -|1: 0-1 d,#887455, 2-2 d,#1d2824, 3-49 #b2c3b8,#1d2824, 50-51 #b2c3b8,#887455, 52-52 #b2c3b8,#314738, 53-99 #becfc4,#314738, -|2: 0-1 d,#496656, 2-2 d,#1d2824, 3-31 #b2c3b8,#1d2824, 32-37 #d3b0d9,#1d2824, 38-49 #b2c3b8,#1d2824, 50-51 #b2c3b8,#add38a, 52-52 #b2c3b8,#314738, 53-81 #becfc4,#314738, 82-90 #dfbce5,#314738, 91-99 #becfc4,#314738, -|3: 0-2 d,#1d2824, 3-49 #b2c3b8,#1d2824, 50-53 #b2c3b8,#314738, 54-99 #becfc4,#314738, +|0: 0-1 d,#1d2824, 2-99 #b2c3b8,#1d2824, +|1: 0-1 d,#887455, 2-49 #b2c3b8,#1d2824, 50-51 #b2c3b8,#887455, 52-99 #becfc4,#314738, +|2: 0-1 d,#496656, 2-30 #b2c3b8,#1d2824, 31-36 #d3b0d9,#1d2824, 37-49 #b2c3b8,#1d2824, 50-51 #b2c3b8,#add38a, 52-80 #becfc4,#314738, 81-89 #dfbce5,#314738, 90-99 #becfc4,#314738, +|3: 0-1 d,#1d2824, 2-49 #b2c3b8,#1d2824, 50-51 #b2c3b8,#314738, 52-99 #becfc4,#314738, |4: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-49 #e5eee5,#0d1410, 50-50 #e5eee5,#608269, 51-99 #e5eee5,#0d1410, |5: 0-0 d,#608269, 1-49 d,#0d1410, 50-50 d,#608269, 51-51 d,#0d1410, 52-99 #e5eee5,#0d1410, |6: 0-0 d,#608269, 1-49 d,#0d1410, 50-50 d,#608269, 51-99 d,#0d1410, @@ -24,12 +24,12 @@ |22: 0-0 d,#608269, 1-49 d,#0d1410, 50-50 d,#608269, 51-99 d,#0d1410, |23: 0-0 d,#608269, 1-49 d,#0d1410, 50-50 d,#608269, 51-99 d,#0d1410, == style held grid=100x24 -|1: 0-1 d,#887455, 2-2 d,#1d2824, 3-49 #b2c3b8,#1d2824, 50-51 #b2c3b8,#f4c086, 52-52 #b2c3b8,#314738, 53-99 #becfc4,#314738, +|1: 0-1 d,#887455, 2-49 #b2c3b8,#1d2824, 50-51 #b2c3b8,#f4c086, 52-99 #becfc4,#314738, == snap resize-drag grid=100x24 cursor=54,6 -|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit -| New Tty Find Grep Joincol Delcol ╎ New Tty Find Grep Joincol Delcol -| /tmp/pardes-snap/colgrip/cwd/w.txt S╎ve Tty Col /tmp/pardes-snap/colgrip/cwd Tty+bash Save Mode -| lapse Del ╎ Filter Collapse Del +| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +| New Tty Find Grep Joincol Delcol ╎ New Tty Find Grep Joincol Delcol +| /tmp/pardes-snap/colgrip/cwd/w.txt Sa╎e Tty Coll /tmp/pardes-snap/colgrip/cwd Tty+bash Save Mode +| apse Del ╎ Filter Collapse Del | 1 x ╎ ls | ╎ w.txt | ╎ @@ -51,9 +51,9 @@ | ╎ | ╎ == style resize-drag grid=100x24 -|1: 0-1 d,#887455, 2-2 d,#1d2824, 3-38 #b2c3b8,#1d2824, 39-49 #f4c086,#1d2824, 50-51 #f4c086,#f4c086, 52-52 #f4c086,#314738, 53-99 #becfc4,#314738, -|2: 0-1 d,#496656, 2-2 d,#1d2824, 3-31 #b2c3b8,#1d2824, 32-37 #d3b0d9,#1d2824, 38-38 #b2c3b8,#1d2824, 39-39 #f4c086,#1d2824, 40-49 #b2c3b8,#1d2824, 50-51 #b2c3b8,#add38a, 52-52 #b2c3b8,#314738, 53-81 #becfc4,#314738, 82-90 #dfbce5,#314738, 91-99 #becfc4,#314738, -|3: 0-2 d,#1d2824, 3-38 #b2c3b8,#1d2824, 39-49 #f4c086,#1d2824, 50-53 #f4c086,#314738, 54-99 #becfc4,#314738, +|1: 0-1 d,#887455, 2-38 #b2c3b8,#1d2824, 39-49 #f4c086,#1d2824, 50-51 #f4c086,#f4c086, 52-99 #becfc4,#314738, +|2: 0-1 d,#496656, 2-30 #b2c3b8,#1d2824, 31-36 #d3b0d9,#1d2824, 37-38 #b2c3b8,#1d2824, 39-39 #f4c086,#1d2824, 40-49 #b2c3b8,#1d2824, 50-51 #b2c3b8,#add38a, 52-80 #becfc4,#314738, 81-89 #dfbce5,#314738, 90-99 #becfc4,#314738, +|3: 0-1 d,#1d2824, 2-38 #b2c3b8,#1d2824, 39-49 #f4c086,#1d2824, 50-51 #f4c086,#314738, 52-99 #becfc4,#314738, |4: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-38 #e5eee5,#0d1410, 39-49 #f4c086,#0d1410, 50-50 #f4c086,#608269, 51-51 #f4c086,#0d1410, 52-99 #e5eee5,#0d1410, |5: 0-0 d,#608269, 1-38 d,#0d1410, 39-49 #f4c086,#0d1410, 50-50 #f4c086,#608269, 51-51 #f4c086,#0d1410, 52-99 #e5eee5,#0d1410, |6: 0-0 d,#608269, 1-38 d,#0d1410, 39-49 #f4c086,#0d1410, 50-50 #f4c086,#608269, 51-99 #f4c086,#0d1410, @@ -75,9 +75,9 @@ |22: 0-0 d,#608269, 1-38 d,#0d1410, 39-49 #f4c086,#0d1410, 50-50 #f4c086,#608269, 51-99 #f4c086,#0d1410, |23: 0-0 d,#608269, 1-38 d,#0d1410, 39-49 #f4c086,#0d1410, 50-50 #f4c086,#608269, 51-99 #f4c086,#0d1410, == snap resize-done grid=100x24 cursor=44,6 -|1: New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol -|2: /tmp/pardes-snap/colgrip/cwd/w.txt Sa /tmp/pardes-snap/colgrip/cwd Tty+bash Save Mode Filter Co -|3: ve Tty Collapse Del llapse Del +|1: New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol +|2: /tmp/pardes-snap/colgrip/cwd/w.txt Sav /tmp/pardes-snap/colgrip/cwd Tty+bash Save Mode Filter Col +|3: e Tty Collapse Del lapse Del |4: 1 x ls |5: w.txt |6: @@ -120,9 +120,9 @@ |22: ╎ |23: ╎ == style reorder-drag grid=100x24 -|1: 0-1 d,#887455, 2-2 d,#1d2824, 3-39 #b2c3b8,#1d2824, 40-41 #b2c3b8,#f4c086, 42-42 #b2c3b8,#314738, 43-99 #becfc4,#314738, -|2: 0-1 d,#496656, 2-2 d,#1d2824, 3-31 #b2c3b8,#1d2824, 32-37 #d3b0d9,#1d2824, 38-39 #b2c3b8,#1d2824, 40-41 #b2c3b8,#add38a, 42-42 #b2c3b8,#314738, 43-71 #becfc4,#314738, 72-80 #dfbce5,#314738, 81-99 #becfc4,#314738, -|3: 0-2 d,#1d2824, 3-39 #b2c3b8,#1d2824, 40-42 #b2c3b8,#314738, 43-99 #becfc4,#314738, +|1: 0-1 d,#887455, 2-39 #b2c3b8,#1d2824, 40-41 #b2c3b8,#f4c086, 42-99 #becfc4,#314738, +|2: 0-1 d,#496656, 2-30 #b2c3b8,#1d2824, 31-36 #d3b0d9,#1d2824, 37-39 #b2c3b8,#1d2824, 40-41 #b2c3b8,#add38a, 42-70 #becfc4,#314738, 71-79 #dfbce5,#314738, 80-99 #becfc4,#314738, +|3: 0-1 d,#1d2824, 2-39 #b2c3b8,#1d2824, 40-41 #b2c3b8,#314738, 42-99 #becfc4,#314738, |4: 0-0 d,#608269, 1-4 #f4c086,#0d1410, 5-6 #59675c,#0d1410, 7-39 #e5eee5,#0d1410, 40-40 #e5eee5,#608269, 41-99 #e5eee5,#0d1410, |5: 0-0 d,#608269, 1-39 #f4c086,#0d1410, 40-40 #f4c086,#608269, 41-41 #f4c086,#0d1410, 42-99 #e5eee5,#0d1410, |6: 0-0 d,#608269, 1-39 #f4c086,#0d1410, 40-40 #f4c086,#608269, 41-99 #f4c086,#0d1410, @@ -144,9 +144,9 @@ |22: 0-0 d,#608269, 1-39 #f4c086,#0d1410, 40-40 #f4c086,#608269, 41-99 #f4c086,#0d1410, |23: 0-0 d,#608269, 1-39 #f4c086,#0d1410, 40-40 #f4c086,#608269, 41-99 #f4c086,#0d1410, == snap reorder-done grid=100x24 cursor=4,6 -|1: New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol -|2: /tmp/pardes-snap/colgrip/cwd Tty+bash Save Mode Filter Co /tmp/pardes-snap/colgrip/cwd/w.txt Sa -|3: llapse Del ve Tty Collapse Del +|1: New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol +|2: /tmp/pardes-snap/colgrip/cwd Tty+bash Save Mode Filter Col /tmp/pardes-snap/colgrip/cwd/w.txt Sav +|3: lapse Del e Tty Collapse Del |4: ls 1 x |5: w.txt |6: diff --git a/test/snapshots/collapse.golden b/test/snapshots/collapse.golden index 57aafc8f..13e1b1f2 100644 --- a/test/snapshots/collapse.golden +++ b/test/snapshots/collapse.golden @@ -1,7 +1,7 @@ == snap before grid=160x25 cursor=7,3 -|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit -| New Tty Find Grep Joincol Delcol -| /tmp/pardes-snap/collapse/cwd/kept.txt Save Tty Collapse Del +| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +| New Tty Find Grep Joincol Delcol +| /tmp/pardes-snap/collapse/cwd/kept.txt Save Tty Collapse Del | 1 KEEP-FIRST | 2 KEEP-SECOND | 3 KEEP-THIRD @@ -10,12 +10,12 @@ |4: |5: == 9p middle-collapsed-cursor grid=160x25 cursor=none -|0: Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit -@0: 0-74 #b2c3b8,#1d2824,,tagline 75-159 d,#1d2824,,tagline -|1: New Tty Find Grep Joincol Delcol -@1: 0-1 #ffffff,#887455,,tagline 2-2 d,#314738,,tagline 3-34 #becfc4,#314738,,tagline 35-159 d,#314738,,tagline -|2: /tmp/pardes-snap/collapse/cwd/kept.txt Save Tty Collapse Del -@2: 0-1 #000000,#add38a,,tagline 2-2 d,#314738,,tagline 3-32 #becfc4,#314738,,tagline 33-40 #dfbce5,#314738,,tagline 41-62 #becfc4,#314738,,tagline 63-159 d,#314738,,tagline +|0: Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +@0: 0-76 #b2c3b8,#1d2824,,tagline 77-159 d,#1d2824,,tagline +|1: New Tty Find Grep Joincol Delcol +@1: 0-1 #ffffff,#887455,,tagline 2-33 #becfc4,#314738,,tagline 34-159 d,#314738,,tagline +|2: /tmp/pardes-snap/collapse/cwd/kept.txt Save Tty Collapse Del +@2: 0-1 #000000,#add38a,,tagline 2-31 #becfc4,#314738,,tagline 32-39 #dfbce5,#314738,,tagline 40-61 #becfc4,#314738,,tagline 62-159 d,#314738,,tagline |3: @3: 0-159 d,#486152,,body |4: @@ -64,7 +64,7 @@ |3: 1 KEEP-FIRST Collapse |4: 2 KEEP-SECOND |5: 3 KEEP-THIRD -== snap tab-collapsed grid=160x25 cursor=51,2 +== snap tab-collapsed grid=160x25 cursor=50,2 |3: |4: |5: diff --git a/test/snapshots/cornerdrag-left.golden b/test/snapshots/cornerdrag-left.golden index a5f36319..4d2d6d43 100644 --- a/test/snapshots/cornerdrag-left.golden +++ b/test/snapshots/cornerdrag-left.golden @@ -1,13 +1,13 @@ == snap right-split grid=100x31 cursor=54,11 -|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit -| New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol -| /tmp/pardes-snap/cornerdrag-left/cwd Tty+bash S /tmp/pardes-snap/cornerdrag-left/cwd Tty+bash S -| ave Mode Filter Collapse Del ave Mode Filter Collapse Del +| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +| New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol +| /tmp/pardes-snap/cornerdrag-left/cwd Tty+bash Sa /tmp/pardes-snap/cornerdrag-left/cwd Tty+bash Sa +| ve Mode Filter Collapse Del ve Mode Filter Collapse Del | ls ls | w.txt w.txt | -| /tmp/pardes-snap/cornerdrag-left/cwd Tty+bash S -| ave Mode Filter Collapse Del +| /tmp/pardes-snap/cornerdrag-left/cwd Tty+bash Sa +| ve Mode Filter Collapse Del | ls | w.txt | @@ -16,19 +16,19 @@ | | | -| /tmp/pardes-snap/cornerdrag-left/cwd Tty+bash S -| ave Mode Filter Collapse Del +| /tmp/pardes-snap/cornerdrag-left/cwd Tty+bash Sa +| ve Mode Filter Collapse Del | ls | w.txt == snap hover-corner grid=100x31 cursor=54,11 -|1: New Tty Find Grep Joincol Delcol ╎ New Tty Find Grep Joincol Delcol -|2: /tmp/pardes-snap/cornerdrag-left/cwd Tty+bash ╎ /tmp/pardes-snap/cornerdrag-left/cwd Tty+bash S -|3: ave Mode Filter Collapse Del ╎ ave Mode Filter Collapse Del +|1: New Tty Find Grep Joincol Delcol ╎ New Tty Find Grep Joincol Delcol +|2: /tmp/pardes-snap/cornerdrag-left/cwd Tty+bash S╎ /tmp/pardes-snap/cornerdrag-left/cwd Tty+bash Sa +|3: ve Mode Filter Collapse Del ╎ ve Mode Filter Collapse Del |4: ls ╎ ls |5: w.txt ╎ w.txt |6: ╎ -|7: ╎ /tmp/pardes-snap/cornerdrag-left/cwd Tty+bash S -|8: ╎ ave Mode Filter Collapse Del +|7: ╎ /tmp/pardes-snap/cornerdrag-left/cwd Tty+bash Sa +|8: ╎ ve Mode Filter Collapse Del |9: ╎ ls |10: ╎ w.txt |11: ╎ @@ -37,8 +37,8 @@ |14: ╎ |15: ╎ |16: ╎ -|17: /tmp/pardes-snap/cornerdrag-left/cwd Tty+bash ╎ -|18: ave Mode Filter Collapse Del ╎ +|17: /tmp/pardes-snap/cornerdrag-left/cwd Tty+bash S╎ +|18: ve Mode Filter Collapse Del ╎ |19: ls ╎ |20: w.txt ╎ |21: ╎ @@ -53,14 +53,14 @@ |30: ╎ == snap hover-left-corner grid=100x31 cursor=54,11 == snap corner-drag grid=100x31 cursor=54,11 -|1: New Tty Find Grep Joincol ╎elcol New Tty Find Grep Joincol Delcol -|2: /tmp/pardes-snap/cornerdra╎-left/cwd Tty+bash S /tmp/pardes-snap/cornerdrag-left/cwd Tty+bash S -|3: ave Mode Filter Collapse D╎l ave Mode Filter Collapse Del +|1: New Tty Find Grep Joincol D╎lcol New Tty Find Grep Joincol Delcol +|2: /tmp/pardes-snap/cornerdrag╎left/cwd Tty+bash Sa /tmp/pardes-snap/cornerdrag-left/cwd Tty+bash Sa +|3: ve Mode Filter Collapse Del╎ ve Mode Filter Collapse Del |4: ls ╎ ls |5: w.txt ╎ w.txt |6: ╎ -|7: ╎ /tmp/pardes-snap/cornerdrag-left/cwd Tty+bash S -|8: ╎ ave Mode Filter Collapse Del +|7: ╎ /tmp/pardes-snap/cornerdrag-left/cwd Tty+bash Sa +|8: ╎ ve Mode Filter Collapse Del |9: ╎ ls |10: ╎ w.txt |11: ╎ @@ -69,8 +69,8 @@ |14: ╎ |15: ╎ |16: ╎ -|17: /tmp/pardes-snap/cornerdra╎-left/cwd Tty+bash S -|18: ave Mode Filter Collapse D╎l +|17: /tmp/pardes-snap/cornerdrag╎left/cwd Tty+bash Sa +|18: ve Mode Filter Collapse Del╎ |19: ls ╎ |20: w.txt ╎ |21: ╎ @@ -84,14 +84,14 @@ |29: ╎ |30: ╎ == snap corner-done grid=100x31 cursor=34,11 -|1: New Tty Find Grep Joincol D New Tty Find Grep Joincol Delcol -|2: /tmp/pardes-snap/cornerdrag /tmp/pardes-snap/cornerdrag-left/cwd Tty+bash Save Mode Filter Coll -|3: -left/cwd Tty+bash Save Mod apse Del -|4: e Filter Collapse Del ls +|1: New Tty Find Grep Joincol De New Tty Find Grep Joincol Delcol +|2: /tmp/pardes-snap/cornerdrag- /tmp/pardes-snap/cornerdrag-left/cwd Tty+bash Save Mode Filter Colla +|3: left/cwd Tty+bash Save Mode pse Del +|4: Filter Collapse Del ls |5: ls w.txt |6: w.txt -|7: /tmp/pardes-snap/cornerdrag-left/cwd Tty+bash Save Mode Filter Coll -|8: apse Del +|7: /tmp/pardes-snap/cornerdrag-left/cwd Tty+bash Save Mode Filter Colla +|8: pse Del |9: ls |10: w.txt |11: @@ -100,9 +100,9 @@ |14: |15: |16: -|17: /tmp/pardes-snap/cornerdrag -|18: -left/cwd Tty+bash Save Mod -|19: e Filter Collapse Del +|17: /tmp/pardes-snap/cornerdrag- +|18: left/cwd Tty+bash Save Mode +|19: Filter Collapse Del |20: ls |21: w.txt |22: diff --git a/test/snapshots/cornerdrag.golden b/test/snapshots/cornerdrag.golden index 8dd21eff..246840bc 100644 --- a/test/snapshots/cornerdrag.golden +++ b/test/snapshots/cornerdrag.golden @@ -1,8 +1,8 @@ == snap hover-corner grid=100x31 cursor=4,6 -|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit -| New Tty Find Grep Joincol Delcol ╎ New Tty Find Grep Joincol Delcol -| /tmp/pardes-snap/cornerdrag/cwd Tty+bash Save ╎ /tmp/pardes-snap/cornerdrag/cwd Tty+bash Save M -| ode Filter Collapse Del ╎ ode Filter Collapse Del +| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +| New Tty Find Grep Joincol Delcol ╎ New Tty Find Grep Joincol Delcol +| /tmp/pardes-snap/cornerdrag/cwd Tty+bash Save M╎ /tmp/pardes-snap/cornerdrag/cwd Tty+bash Save Mo +| de Filter Collapse Del ╎ de Filter Collapse Del | ls ╎ ls | w.txt ╎ w.txt | ╎ @@ -16,8 +16,8 @@ | ╎ | ╎ | ╎ -| /tmp/pardes-snap/cornerdrag/cwd Tty+bash Save ╎ -| ode Filter Collapse Del ╎ +| /tmp/pardes-snap/cornerdrag/cwd Tty+bash Save M╎ +| de Filter Collapse Del ╎ | ls ╎ | w.txt ╎ | ╎ @@ -31,9 +31,9 @@ | ╎ | ╎ == snap edge-drag grid=100x31 cursor=4,6 -|1: New Tty Find Grep Joincol ╎elcol New Tty Find Grep Joincol Delcol -|2: /tmp/pardes-snap/cornerdra╎/cwd Tty+bash Save M /tmp/pardes-snap/cornerdrag/cwd Tty+bash Save M -|3: ode Filter Collapse Del ╎ ode Filter Collapse Del +|1: New Tty Find Grep Joincol D╎lcol New Tty Find Grep Joincol Delcol +|2: /tmp/pardes-snap/cornerdrag╎cwd Tty+bash Save Mo /tmp/pardes-snap/cornerdrag/cwd Tty+bash Save Mo +|3: de Filter Collapse Del ╎ de Filter Collapse Del |4: ls ╎ ls |5: w.txt ╎ w.txt |6: ╎ @@ -47,8 +47,8 @@ |14: ╎ |15: ╎ |16: ╎ -|17: /tmp/pardes-snap/cornerdra╎/cwd Tty+bash Save M -|18: ode Filter Collapse Del ╎ +|17: /tmp/pardes-snap/cornerdrag╎cwd Tty+bash Save Mo +|18: de Filter Collapse Del ╎ |19: ls ╎ |20: w.txt ╎ |21: ╎ @@ -62,10 +62,10 @@ |29: ╎ |30: ╎ == snap edge-done grid=100x31 cursor=4,7 -|1: New Tty Find Grep Joincol D New Tty Find Grep Joincol Delcol -|2: /tmp/pardes-snap/cornerdrag /tmp/pardes-snap/cornerdrag/cwd Tty+bash Save Mode Filter Collapse -|3: /cwd Tty+bash Save Mode Fil Del -|4: ter Collapse Del ls +|1: New Tty Find Grep Joincol De New Tty Find Grep Joincol Delcol +|2: /tmp/pardes-snap/cornerdrag/ /tmp/pardes-snap/cornerdrag/cwd Tty+bash Save Mode Filter Collapse D +|3: cwd Tty+bash Save Mode Filte el +|4: r Collapse Del ls |5: ls w.txt |6: w.txt |7: @@ -78,9 +78,9 @@ |14: |15: |16: -|17: /tmp/pardes-snap/cornerdrag -|18: /cwd Tty+bash Save Mode Fil -|19: ter Collapse Del +|17: /tmp/pardes-snap/cornerdrag/ +|18: cwd Tty+bash Save Mode Filte +|19: r Collapse Del |20: ls |21: w.txt |22: @@ -93,10 +93,10 @@ |29: |30: == snap corner-drag grid=100x31 cursor=4,7 -|1: New Tty Find Grep Joincol D New Tty Find Grep Joincol ╎elcol -|2: /tmp/pardes-snap/cornerdrag /tmp/pardes-snap/cornerdra╎/cwd Tty+bash Save Mode Filter Collapse -|3: /cwd Tty+bash Save Mode Fil Del ╎ -|4: ter Collapse Del ls ╎ +|1: New Tty Find Grep Joincol De New Tty Find Grep Joincol D╎lcol +|2: /tmp/pardes-snap/cornerdrag/ /tmp/pardes-snap/cornerdrag╎cwd Tty+bash Save Mode Filter Collapse D +|3: cwd Tty+bash Save Mode Filte el ╎ +|4: r Collapse Del ls ╎ |5: ls w.txt ╎ |6: w.txt ╎ |7: ╎ @@ -109,9 +109,9 @@ |14: ╎ |15: ╎ |16: ╎ -|17: /tmp/pardes-snap/cornerdrag ╎ -|18: /cwd Tty+bash Save Mode Fil ╎ -|19: ter Collapse Del ╎ +|17: /tmp/pardes-snap/cornerdrag/ ╎ +|18: cwd Tty+bash Save Mode Filte ╎ +|19: r Collapse Del ╎ |20: ls ╎ |21: w.txt ╎ |22: ╎ @@ -124,16 +124,16 @@ |29: ╎ |30: ╎ == snap corner-done grid=100x31 cursor=4,6 -|1: New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol -|2: /tmp/pardes-snap/cornerdrag/cwd Tty+bash Save Mode Filter /tmp/pardes-snap/cornerdrag/cwd Tty+b -|3: Collapse Del ash Save Mode Filter Collapse Del +|1: New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol +|2: /tmp/pardes-snap/cornerdrag/cwd Tty+bash Save Mode Filter /tmp/pardes-snap/cornerdrag/cwd Tty+ba +|3: Collapse Del sh Save Mode Filter Collapse Del |4: ls ls |5: w.txt w.txt |6: |7: |8: -|9: /tmp/pardes-snap/cornerdrag/cwd Tty+bash Save Mode Filter -|10: Collapse Del +|9: /tmp/pardes-snap/cornerdrag/cwd Tty+bash Save Mode Filter +|10: Collapse Del |11: ls |12: w.txt |13: @@ -155,16 +155,16 @@ |29: |30: == snap clamp-x grid=100x31 cursor=4,6 -|1: New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol D╎lcol -|2: /tmp/pardes-snap/cornerdrag/cwd Tty+bash Save Mode Filter /tmp/pardes-snap/cornerdrag╎cwd Tty+b -|3: Collapse Del ash Save Mode Filter Collap╎e Del +|1: New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol De╎col +|2: /tmp/pardes-snap/cornerdrag/cwd Tty+bash Save Mode Filter /tmp/pardes-snap/cornerdrag/╎wd Tty+ba +|3: Collapse Del sh Save Mode Filter Collapse╎Del |4: ls ls ╎ |5: w.txt w.txt ╎ |6: ╎ |7: ╎ |8: ╎ -|9: /tmp/pardes-snap/cornerdrag/cwd Tty+bash Save Mode Filter ╎ -|10: Collapse Del ╎ +|9: /tmp/pardes-snap/cornerdrag/cwd Tty+bash Save Mode Filter ╎ +|10: Collapse Del ╎ |11: ls ╎ |12: w.txt ╎ |13: ╎ @@ -186,16 +186,16 @@ |29: ╎ |30: ╎ == snap clamp-y grid=100x31 cursor=4,6 -|1: New Tty Find Grep Joincol Delcol ╎ New Tty Find Grep Joincol Delcol -|2: /tmp/pardes-snap/cornerdrag/cwd Tty+bash Save Mode Filte╎ /tmp/pardes-snap/cornerdrag/cwd Tty+b -|3: Collapse Del ╎ ash Save Mode Filter Collapse Del +|1: New Tty Find Grep Joincol Delcol ╎ New Tty Find Grep Joincol Delcol +|2: /tmp/pardes-snap/cornerdrag/cwd Tty+bash Save Mode Filter╎ /tmp/pardes-snap/cornerdrag/cwd Tty+ba +|3: Collapse Del ╎ sh Save Mode Filter Collapse Del |4: ls ╎ ls |5: w.txt ╎ w.txt |6: ╎ |7: ╎ |8: ╎ -|9: /tmp/pardes-snap/cornerdrag/cwd Tty+bash Save Mode Filte╎ -|10: Collapse Del ╎ +|9: /tmp/pardes-snap/cornerdrag/cwd Tty+bash Save Mode Filter╎ +|10: Collapse Del ╎ |11: ls ╎ |12: w.txt ╎ |13: ╎ @@ -217,9 +217,9 @@ |29: ╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ |30: ╎ == snap clamp-done grid=100x31 cursor=4,6 -|1: New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol -|2: /tmp/pardes-snap/cornerdrag/cwd Tty+bash Save Mode Filter /tmp/pardes-snap/cornerdrag/cwd Tty+b -|3: Collapse Del ash Save Mode Filter Collapse Del +|1: New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol +|2: /tmp/pardes-snap/cornerdrag/cwd Tty+bash Save Mode Filter /tmp/pardes-snap/cornerdrag/cwd Tty+ba +|3: Collapse Del sh Save Mode Filter Collapse Del |4: ls ls |5: w.txt w.txt |6: @@ -243,7 +243,7 @@ |24: |25: |26: -|27: /tmp/pardes-snap/cornerdrag/cwd Tty+bash Save Mode Filter -|28: Collapse Del +|27: /tmp/pardes-snap/cornerdrag/cwd Tty+bash Save Mode Filter +|28: Collapse Del |29: w.txt |30: diff --git a/test/snapshots/cursorline.golden b/test/snapshots/cursorline.golden index 6b99a30a..277565b3 100644 --- a/test/snapshots/cursorline.golden +++ b/test/snapshots/cursorline.golden @@ -1,11 +1,11 @@ == snap top grid=150x31 cursor=7,7 -|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit -| New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol -| /tmp/pardes-snap/cursorline/cwd Tty+bash Save Mode Filter Collapse Del /tmp/pardes-snap/cursorline/cwd Tty+bash Save Mode Filter Collapse Del +| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +| New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol +| /tmp/pardes-snap/cursorline/cwd Tty+bash Save Mode Filter Collapse Del /tmp/pardes-snap/cursorline/cwd Tty+bash Save Mode Filter Collapse Del | ls ls | cur.txt cur.txt | -| /tmp/pardes-snap/cursorline/cwd/cur.txt Save Tty Collapse Del +| /tmp/pardes-snap/cursorline/cwd/cur.txt Save Tty Collapse Del | 1 line 1 | 2 line 2 | 3 line 3 @@ -16,17 +16,17 @@ | 8 line 8 | 9 line 9 | 10 line 10 -| /tmp/pardes-snap/cursorline/cwd Tty+bash Save Mode Filter Collapse Del +| /tmp/pardes-snap/cursorline/cwd Tty+bash Save Mode Filter Collapse Del | ls | cur.txt == style top grid=150x31 -|0: 0-149 #b2c3b8,#1d2824, -|1: 0-1 d,#887455, 2-2 d,#314738, 3-74 #becfc4,#314738, 75-76 #becfc4,#887455, 77-77 #becfc4,#1d2824, 78-149 #b2c3b8,#1d2824, -|2: 0-1 d,#496656, 2-2 d,#1d2824, 3-34 #b2c3b8,#1d2824, 35-43 #d3b0d9,#1d2824, 44-74 #b2c3b8,#1d2824, 75-76 #b2c3b8,#496656, 77-109 #b2c3b8,#1d2824, 110-118 #d3b0d9,#1d2824, 119-149 #b2c3b8,#1d2824, +|0: 0-1 d,#1d2824, 2-149 #b2c3b8,#1d2824, +|1: 0-1 d,#887455, 2-74 #becfc4,#314738, 75-76 #becfc4,#887455, 77-149 #b2c3b8,#1d2824, +|2: 0-1 d,#496656, 2-33 #b2c3b8,#1d2824, 34-42 #d3b0d9,#1d2824, 43-74 #b2c3b8,#1d2824, 75-76 #b2c3b8,#496656, 77-108 #b2c3b8,#1d2824, 109-117 #d3b0d9,#1d2824, 118-149 #b2c3b8,#1d2824, |3: 0-0 d,#608269, 1-1 d,#0d1410, 2-74 #e5eee5,#0d1410, 75-75 #e5eee5,#608269, 76-149 #e5eee5,#0d1410, |4: 0-0 d,#608269, 1-1 d,#0d1410, 2-74 #e5eee5,#0d1410, 75-75 #e5eee5,#608269, 76-149 #e5eee5,#0d1410, |5: 0-0 d,#608269, 1-74 d,#0d1410, 75-75 d,#608269, 76-149 d,#0d1410, -|6: 0-1 d,#add38a, 2-2 d,#314738, 3-34 #becfc4,#314738, 35-42 #dfbce5,#314738, 43-74 #becfc4,#314738, 75-75 #becfc4,#608269, 76-149 #becfc4,#0d1410, +|6: 0-1 d,#add38a, 2-33 #becfc4,#314738, 34-41 #dfbce5,#314738, 42-74 #becfc4,#314738, 75-75 #becfc4,#608269, 76-149 #becfc4,#0d1410, |7: 0-0 d,#608269, 1-1 d,#0d1410, 2-4 d,#0d1410,b 5-6 #616f64,#0d1410,b 7-74 #e5eee5,#0d1410, 75-75 #e5eee5,#608269, 76-149 #e5eee5,#0d1410, |8: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-74 #e5eee5,#0d1410, 75-75 #e5eee5,#608269, 76-149 #e5eee5,#0d1410, |9: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-74 #e5eee5,#0d1410, 75-75 #e5eee5,#608269, 76-149 #e5eee5,#0d1410, @@ -37,7 +37,7 @@ |14: 0-0 d,#152019, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-74 #e5eee5,#0d1410, 75-75 #e5eee5,#608269, 76-149 #e5eee5,#0d1410, |15: 0-0 d,#152019, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-74 #e5eee5,#0d1410, 75-75 #e5eee5,#608269, 76-149 #e5eee5,#0d1410, |16: 0-0 d,#152019, 1-3 d,#0d1410, 4-6 #59675c,#0d1410, 7-74 #e5eee5,#0d1410, 75-75 #e5eee5,#608269, 76-149 #e5eee5,#0d1410, -|17: 0-1 d,#496656, 2-2 d,#1d2824, 3-34 #b2c3b8,#1d2824, 35-43 #d3b0d9,#1d2824, 44-74 #b2c3b8,#1d2824, 75-75 #b2c3b8,#608269, 76-149 #b2c3b8,#0d1410, +|17: 0-1 d,#496656, 2-33 #b2c3b8,#1d2824, 34-42 #d3b0d9,#1d2824, 43-74 #b2c3b8,#1d2824, 75-75 #b2c3b8,#608269, 76-149 #b2c3b8,#0d1410, |18: 0-0 d,#608269, 1-1 d,#0d1410, 2-74 #e5eee5,#0d1410, 75-75 #e5eee5,#608269, 76-149 #e5eee5,#0d1410, |19: 0-0 d,#608269, 1-1 d,#0d1410, 2-74 #e5eee5,#0d1410, 75-75 #e5eee5,#608269, 76-149 #e5eee5,#0d1410, |20: 0-0 d,#608269, 1-74 d,#0d1410, 75-75 d,#608269, 76-149 d,#0d1410, diff --git a/test/snapshots/delask.golden b/test/snapshots/delask.golden index d1487a36..7d911239 100644 --- a/test/snapshots/delask.golden +++ b/test/snapshots/delask.golden @@ -1,7 +1,7 @@ == snap three grid=100x36 cursor=18,20 -|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit -| New Tty Find Grep Joincol Delcol -| /tmp/pardes-snap/delask/cwd/top.txt Save Tty Collapse Del +| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +| New Tty Find Grep Joincol Delcol +| /tmp/pardes-snap/delask/cwd/top.txt Save Tty Collapse Del | 1 top-marker | | @@ -18,7 +18,7 @@ | | | -| * /tmp/pardes-snap/delask/cwd/+New Save Tty Collapse Del +| */tmp/pardes-snap/delask/cwd/+New Save Tty Collapse Del | 1 middle-pane | | @@ -27,7 +27,7 @@ | | | -| * /tmp/pardes-snap/delask/cwd/+New Save Tty Collapse Del +| */tmp/pardes-snap/delask/cwd/+New Save Tty Collapse Del | 1 bottom-pane Up == snap asked grid=100x36 cursor=18,20 |20: 1 middle-pane Del: give space to k above j below @@ -40,7 +40,7 @@ |29: == snap typed grid=100x36 cursor=27,20 |20: 1 bottom-pane DelBelow -|28: * /tmp/pardes-snap/delask/cwd/+New Save Tty Collapse Del +|28: */tmp/pardes-snap/delask/cwd/+New Save Tty Collapse Del |29: 1 third-pane == snap below-took-click grid=100x36 cursor=17,20 |20: 1 third-pane @@ -48,7 +48,7 @@ |29: == snap four grid=100x36 cursor=7,29 |3: 1 top-marker New -|28: /tmp/pardes-snap/delask/cwd/+New Save Tty Collapse Del +|28: /tmp/pardes-snap/delask/cwd/+New Save Tty Collapse Del |29: 1 == snap mouse-del grid=100x36 cursor=7,29 |3: 1 top-marker diff --git a/test/snapshots/diffview.golden b/test/snapshots/diffview.golden index 868e5e85..b4ce7759 100644 --- a/test/snapshots/diffview.golden +++ b/test/snapshots/diffview.golden @@ -1,7 +1,7 @@ == snap diff-pane grid=100x31 cursor=7,3 -|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit -| New Tty Find Grep Joincol Delcol -| /tmp/pardes-snap/diffview/cwd/change.diff Save Tty Diff Collapse Del +| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +| New Tty Find Grep Joincol Delcol +| /tmp/pardes-snap/diffview/cwd/change.diff Save Tty Diff Collapse Del | 1 diff --git a/src/shape.zig b/src/shape.zig | 2 index 1111111..2222222 100644 | 3 --- a/src/shape.zig @@ -23,9 +23,9 @@ | 19 }; | 20 == style diff-colours grid=100x31 -|0: 0-99 #b2c3b8,#1d2824, -|1: 0-1 d,#887455, 2-2 d,#314738, 3-99 #becfc4,#314738, -|2: 0-1 d,#add38a, 2-2 d,#314738, 3-32 #becfc4,#314738, 33-44 #dfbce5,#314738, 45-99 #becfc4,#314738, +|0: 0-1 d,#1d2824, 2-99 #b2c3b8,#1d2824, +|1: 0-1 d,#887455, 2-99 #becfc4,#314738, +|2: 0-1 d,#add38a, 2-31 #becfc4,#314738, 32-43 #dfbce5,#314738, 44-99 #becfc4,#314738, |3: 0-0 d,#608269, 1-1 d,#0d1410, 2-4 d,#0d1410,b 5-6 #616f64,#0d1410,b 7-99 #b9f480,#0d1410, |4: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-99 #b9f480,#0d1410, |5: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-99 #b9f480,#0d1410, @@ -55,7 +55,7 @@ |29: 0-0 d,#608269, 1-99 d,#0d1410, |30: 0-0 d,#608269, 1-99 d,#0d1410, == snap look-added-line grid=100x31 cursor=55,22 -|16: /tmp/pardes-snap/diffview/cwd/src/shape.zig Save Tty Collapse Del TreeContext Def Refs +|16: /tmp/pardes-snap/diffview/cwd/src/shape.zig Save Tty Collapse TreeContext Def Refs Del |17: 1 const std = @import("std"); |18: 2 |19: 3 pub const Shape = union(enum) { @@ -70,9 +70,9 @@ |28: 12 }; |29: 13 == snap command-pane grid=100x31 cursor=7,3 -|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit -| New Tty Find Grep Joincol Delcol -| /tmp/pardes-snap/diffview/cwd/cmds.txt Save Tty Collapse Del +| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +| New Tty Find Grep Joincol Delcol +| /tmp/pardes-snap/diffview/cwd/cmds.txt Save Tty Collapse Del | 1 cat change.diff Exec | 2 | @@ -87,7 +87,7 @@ | | | -| /tmp/pardes-snap/diffview/cwd (cat change.diff) exit 0 Kill Save Collapse Del +| /tmp/pardes-snap/diffview/cwd (cat change.diff) exit 0 Kill Save Collapse Del | circle: f32, | - square: u8 = 7, | + square: f32, @@ -101,9 +101,9 @@ | }; | exit 0 == style command-colours grid=100x31 -|0: 0-99 #b2c3b8,#1d2824, -|1: 0-1 d,#887455, 2-2 d,#314738, 3-99 #becfc4,#314738, -|2: 0-1 d,#add38a, 2-2 d,#314738, 3-32 #becfc4,#314738, 33-41 #dfbce5,#314738, 42-99 #becfc4,#314738, +|0: 0-1 d,#1d2824, 2-99 #b2c3b8,#1d2824, +|1: 0-1 d,#887455, 2-99 #becfc4,#314738, +|2: 0-1 d,#add38a, 2-31 #becfc4,#314738, 32-40 #dfbce5,#314738, 41-99 #becfc4,#314738, |3: 0-0 d,#608269, 1-1 d,#0d1410, 2-4 d,#0d1410,b 5-6 #616f64,#0d1410,b 7-93 #e5eee5,#0d1410, 94-94 #e5eee5,#1d2824, 95-99 #b2c3b8,#1d2824, |4: 0-0 d,#608269, 1-4 d,#0d1410, 5-99 #59675c,#0d1410, |5: 0-0 d,#608269, 1-99 d,#0d1410, @@ -118,7 +118,7 @@ |14: 0-0 d,#608269, 1-99 d,#0d1410, |15: 0-0 d,#608269, 1-99 d,#0d1410, |16: 0-0 d,#608269, 1-99 d,#0d1410, -|17: 0-1 d,#496656, 2-2 d,#1d2824, 3-99 #b2c3b8,#1d2824, +|17: 0-1 d,#496656, 2-99 #b2c3b8,#1d2824, |18: 0-0 d,#152019, 1-6 d,#0d1410, 7-99 #e5eee5,#0d1410, |19: 0-0 d,#152019, 1-1 d,#0d1410, 2-2 #f1a39b,#302b25,b 3-6 #f1a39b,#302b25, 7-19 #e5eee5,#302b25, 20-20 #f8c082,#302b25, 21-99 #e5eee5,#302b25, |20: 0-0 d,#152019, 1-1 d,#0d1410, 2-2 #b6ce94,#263025,b 3-6 #b6ce94,#263025, 7-99 #e5eee5,#263025, @@ -134,7 +134,7 @@ |30: 0-0 d,#152019, 1-99 d,#0d1410, == snap command-look grid=100x31 cursor=23,10 |3: 1 cat change.diff -|5: /tmp/pardes-snap/diffview/cwd/src/shape.zig Save Tty Collapse Del TreeContext Def Refs +|5: /tmp/pardes-snap/diffview/cwd/src/shape.zig Save Tty Collapse TreeContext Def Refs Del |6: 1 const std = @import("std"); |7: 2 |8: 3 pub const Shape = union(enum) { diff --git a/test/snapshots/dirpane.golden b/test/snapshots/dirpane.golden index 3118079f..960c8913 100644 --- a/test/snapshots/dirpane.golden +++ b/test/snapshots/dirpane.golden @@ -1,13 +1,13 @@ == snap dir-open grid=80x24 cursor=7,6 -|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit -| New Tty Find Grep Joincol Delcol -| /tmp/pardes-snap/dirpane/cwd/top.txt Save Tty Collapse Del +| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +| New Tty Find Grep Joincol Delcol +| /tmp/pardes-snap/dirpane/cwd/top.txt Save Tty Collapse Del | 1 sub | -| /tmp/pardes-snap/dirpane/cwd/sub/ Get Tty Collapse Del +| /tmp/pardes-snap/dirpane/cwd/sub/ Get Tty Collapse Del | 1 .hidden beta-gamma.txt inner.txt | 2 alpha.txt deeper/ zeta | 3 == snap entry-open grid=80x24 cursor=7,9 -|8: /tmp/pardes-snap/dirpane/cwd/sub/inner.txt Save Tty Collapse Del +|8: /tmp/pardes-snap/dirpane/cwd/sub/inner.txt Save Tty Collapse Del |9: 1 inner-marker diff --git a/test/snapshots/doccol.golden b/test/snapshots/doccol.golden index 21424456..0d71dffa 100644 --- a/test/snapshots/doccol.golden +++ b/test/snapshots/doccol.golden @@ -1,25 +1,25 @@ == snap boot grid=100x31 cursor=7,4 -|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit -| New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol -| /tmp/pardes-snap/doccol/cwd/a.txt Save Tty Coll /tmp/pardes-snap/doccol/cwd Tty+bash Save Mode -| apse Del Filter Collapse Del +| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +| New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol +| /tmp/pardes-snap/doccol/cwd/a.txt Save Tty Colla /tmp/pardes-snap/doccol/cwd Tty+bash Save Mode F +| pse Del ilter Collapse Del | 1 AAA ls | a.txt b.txt c.txt == snap two-docs grid=100x31 cursor=7,19 -|17: /tmp/pardes-snap/doccol/cwd/b.txt Save Tty Coll -|18: apse Del +|17: /tmp/pardes-snap/doccol/cwd/b.txt Save Tty Colla +|18: pse Del |19: 1 BBB |20: 2 B-TWO == snap moved grid=100x31 cursor=57,22 |17: |18: |19: -|20: /tmp/pardes-snap/doccol/cwd/b.txt Save Tty Coll -|21: apse Del +|20: /tmp/pardes-snap/doccol/cwd/b.txt Save Tty Colla +|21: pse Del |22: 1 BBB |23: 2 B-TWO == snap worked grid=100x31 cursor=59,23 == snap third grid=100x31 cursor=57,28 -|26: /tmp/pardes-snap/doccol/cwd/c.txt Save Tty Coll -|27: apse Del +|26: /tmp/pardes-snap/doccol/cwd/c.txt Save Tty Colla +|27: pse Del |28: 1 CCC diff --git a/test/snapshots/edit.golden b/test/snapshots/edit.golden index aa39ed9c..2ac4dfcf 100644 --- a/test/snapshots/edit.golden +++ b/test/snapshots/edit.golden @@ -1,8 +1,8 @@ == snap inserted grid=100x31 cursor=16,10 -|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit -| New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol -| /tmp/pardes-snap/edit/cwd Tty+bash Save Mode Fi /tmp/pardes-snap/edit/cwd Tty+bash Save Mode Fi -| lter Collapse Del lter Collapse Del +| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +| New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol +| /tmp/pardes-snap/edit/cwd Tty+bash Save Mode Fil /tmp/pardes-snap/edit/cwd Tty+bash Save Mode Fil +| ter Collapse Del ter Collapse Del | ls ls | e.txt e.txt | @@ -16,15 +16,15 @@ | | | -| /tmp/pardes-snap/edit/cwd Tty+bash Save Mode Fi -| lter Collapse Del +| /tmp/pardes-snap/edit/cwd Tty+bash Save Mode Fil +| ter Collapse Del | ls | e.txt == style inserted grid=100x31 -|0: 0-99 #b2c3b8,#1d2824, -|1: 0-1 d,#887455, 2-2 d,#314738, 3-49 #becfc4,#314738, 50-51 #becfc4,#887455, 52-52 #becfc4,#1d2824, 53-99 #b2c3b8,#1d2824, -|2: 0-1 d,#add38a, 2-2 d,#314738, 3-28 #becfc4,#314738, 29-37 #dfbce5,#314738, 38-49 #becfc4,#314738, 50-51 #becfc4,#496656, 52-52 #becfc4,#1d2824, 53-78 #b2c3b8,#1d2824, 79-87 #d3b0d9,#1d2824, 88-99 #b2c3b8,#1d2824, -|3: 0-2 d,#314738, 3-49 #becfc4,#314738, 50-52 #becfc4,#1d2824, 53-99 #b2c3b8,#1d2824, +|0: 0-1 d,#1d2824, 2-99 #b2c3b8,#1d2824, +|1: 0-1 d,#887455, 2-49 #becfc4,#314738, 50-51 #becfc4,#887455, 52-99 #b2c3b8,#1d2824, +|2: 0-1 d,#add38a, 2-27 #becfc4,#314738, 28-36 #dfbce5,#314738, 37-49 #becfc4,#314738, 50-51 #becfc4,#496656, 52-77 #b2c3b8,#1d2824, 78-86 #d3b0d9,#1d2824, 87-99 #b2c3b8,#1d2824, +|3: 0-1 d,#314738, 2-49 #becfc4,#314738, 50-51 #becfc4,#1d2824, 52-99 #b2c3b8,#1d2824, |4: 0-0 d,#608269, 1-1 d,#0d1410, 2-49 #e5eee5,#0d1410, 50-50 #e5eee5,#608269, 51-99 #e5eee5,#0d1410, |5: 0-0 d,#608269, 1-1 d,#0d1410, 2-49 #e5eee5,#0d1410, 50-50 #e5eee5,#608269, 51-99 #e5eee5,#0d1410, |6: 0-0 d,#608269, 1-49 d,#0d1410, 50-50 d,#608269, 51-99 d,#0d1410, @@ -38,8 +38,8 @@ |14: 0-0 d,#608269, 1-49 d,#0d1410, 50-50 d,#608269, 51-99 d,#0d1410, |15: 0-0 d,#608269, 1-49 d,#0d1410, 50-50 d,#608269, 51-99 d,#0d1410, |16: 0-0 d,#608269, 1-49 d,#0d1410, 50-50 d,#608269, 51-99 d,#0d1410, -|17: 0-1 d,#496656, 2-2 d,#1d2824, 3-28 #b2c3b8,#1d2824, 29-37 #d3b0d9,#1d2824, 38-49 #b2c3b8,#1d2824, 50-50 #b2c3b8,#608269, 51-99 #b2c3b8,#0d1410, -|18: 0-2 d,#1d2824, 3-49 #b2c3b8,#1d2824, 50-50 #b2c3b8,#608269, 51-99 #b2c3b8,#0d1410, +|17: 0-1 d,#496656, 2-27 #b2c3b8,#1d2824, 28-36 #d3b0d9,#1d2824, 37-49 #b2c3b8,#1d2824, 50-50 #b2c3b8,#608269, 51-99 #b2c3b8,#0d1410, +|18: 0-1 d,#1d2824, 2-49 #b2c3b8,#1d2824, 50-50 #b2c3b8,#608269, 51-99 #b2c3b8,#0d1410, |19: 0-0 d,#608269, 1-1 d,#0d1410, 2-49 #e5eee5,#0d1410, 50-50 #e5eee5,#608269, 51-99 #e5eee5,#0d1410, |20: 0-0 d,#608269, 1-1 d,#0d1410, 2-49 #e5eee5,#0d1410, 50-50 #e5eee5,#608269, 51-99 #e5eee5,#0d1410, |21: 0-0 d,#608269, 1-49 d,#0d1410, 50-50 d,#608269, 51-99 d,#0d1410, diff --git a/test/snapshots/emptycol.golden b/test/snapshots/emptycol.golden index 9bac8492..bd00a2cd 100644 --- a/test/snapshots/emptycol.golden +++ b/test/snapshots/emptycol.golden @@ -1,17 +1,17 @@ -== snap newcol grid=100x24 cursor=53,1 -|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit -| New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol -| /tmp/pardes-snap/emptycol/cwd/notes.txt Save Tt -| y Collapse Del +== snap newcol grid=100x24 cursor=52,1 +| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +| New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol +| /tmp/pardes-snap/emptycol/cwd/notes.txt Save Tty +| Collapse Del | 1 one | 2 two == snap filled grid=100x24 cursor=54,6 -|2: /tmp/pardes-snap/emptycol/cwd/notes.txt Save Tt /tmp/pardes-snap/emptycol/cwd Tty+bash Save Mod -|3: y Collapse Del e Filter Collapse Del +|2: /tmp/pardes-snap/emptycol/cwd/notes.txt Save Tty /tmp/pardes-snap/emptycol/cwd Tty+bash Save Mode +|3: Collapse Del Filter Collapse Del |4: 1 one ls |5: 2 two notes.txt -== snap emptied grid=100x24 cursor=53,1 -|2: /tmp/pardes-snap/emptycol/cwd/notes.txt Save Tt -|3: y Collapse Del +== snap emptied grid=100x24 cursor=52,1 +|2: /tmp/pardes-snap/emptycol/cwd/notes.txt Save Tty +|3: Collapse Del |4: 1 one |5: 2 two diff --git a/test/snapshots/exec-bigdrag.golden b/test/snapshots/exec-bigdrag.golden index a2ac6610..f3cd71b1 100644 --- a/test/snapshots/exec-bigdrag.golden +++ b/test/snapshots/exec-bigdrag.golden @@ -1,7 +1,7 @@ == snap alive grid=200x61 cursor=119,38 -|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit -| New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol -| /tmp/pardes-snap/exec-bigdrag/cwd Tty+bash Save Mode Filter Collapse Del /tmp/pardes-snap/exec-bigdrag/cwd Tty+bash Save Mode Filter Collapse Del +| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +| New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol +| /tmp/pardes-snap/exec-bigdrag/cwd Tty+bash Save Mode Filter Collapse Del /tmp/pardes-snap/exec-bigdrag/cwd Tty+bash Save Mode Filter Collapse Del | ls 2 | big.txt bash: 91line: command not found | 802line 2803line 2804line 2805line 2806line 2807line 2808line 2809line 2810line 2811line 2812lin @@ -31,7 +31,7 @@ | 89line 2890line 2891line 2892line 2893line 2894line 2895line 2896line 2897line 2898line 2899line | 2 | bash: 89line: command not found -| /tmp/pardes-snap/exec-bigdrag/cwd Tty+bash Save Mode Filter Collapse Del 900line 2901line 2902line 2903line 2904line 2905line 2906line 2907line 2908line 2909line 2910lin +| /tmp/pardes-snap/exec-bigdrag/cwd Tty+bash Save Mode Filter Collapse Del 900line 2901line 2902line 2903line 2904line 2905line 2906line 2907line 2908line 2909line 2910lin | ls e | big.txt bash: 900line: command not found | 2911line 2912line 2913line 2914line 2915line 2916line 2917line 2918line 2919line 2920line 2921li diff --git a/test/snapshots/exec.golden b/test/snapshots/exec.golden index a9f8716e..df49336c 100644 --- a/test/snapshots/exec.golden +++ b/test/snapshots/exec.golden @@ -1,7 +1,7 @@ == snap exec grid=140x31 cursor=16,8 -|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit -| New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol -| /tmp/pardes-snap/exec/cwd Tty+bash Save Mode Filter Collapse Del /tmp/pardes-snap/exec/cwd Tty+bash Save Mode Filter Collapse Del +| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +| New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol +| /tmp/pardes-snap/exec/cwd Tty+bash Save Mode Filter Collapse Del /tmp/pardes-snap/exec/cwd Tty+bash Save Mode Filter Collapse Del | ls Exec ls | e.txt e.txt | @@ -16,7 +16,7 @@ | | | -| /tmp/pardes-snap/exec/cwd Tty+bash Save Mode Filter Collapse Del +| /tmp/pardes-snap/exec/cwd Tty+bash Save Mode Filter Collapse Del | ls | e.txt == snap kept grid=140x31 cursor=6,3 diff --git a/test/snapshots/fileedit.golden b/test/snapshots/fileedit.golden index 5ba6e18a..b484177b 100644 --- a/test/snapshots/fileedit.golden +++ b/test/snapshots/fileedit.golden @@ -1,11 +1,11 @@ == snap edited grid=150x31 cursor=17,7 -|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit -| New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol -| /tmp/pardes-snap/fileedit/cwd Tty+bash Save Mode Filter Collapse Del /tmp/pardes-snap/fileedit/cwd Tty+bash Save Mode Filter Collapse Del +| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +| New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol +| /tmp/pardes-snap/fileedit/cwd Tty+bash Save Mode Filter Collapse Del /tmp/pardes-snap/fileedit/cwd Tty+bash Save Mode Filter Collapse Del | ls ls | f.txt f.txt | -| * /tmp/pardes-snap/fileedit/cwd/f.txt Save Tty Collapse Del +| */tmp/pardes-snap/fileedit/cwd/f.txt Save Tty Collapse Del | 1 liEDIT''MEne 1 | 2 line 2 | 3 line 3 @@ -16,7 +16,7 @@ | 8 line 8 | 9 line 9 | 10 line 10 -| /tmp/pardes-snap/fileedit/cwd Tty+bash Save Mode Filter Collapse Del +| /tmp/pardes-snap/fileedit/cwd Tty+bash Save Mode Filter Collapse Del | ls | f.txt == snap deleted grid=150x31 cursor=7,8 diff --git a/test/snapshots/filewatch.golden b/test/snapshots/filewatch.golden index 36f51582..ebd68fee 100644 --- a/test/snapshots/filewatch.golden +++ b/test/snapshots/filewatch.golden @@ -1,11 +1,11 @@ == snap edited grid=210x31 cursor=15,7 -|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit -| New Tty Find Grep Joincol Delcol -| /tmp/pardes-snap/filewatch/cwd Tty+bash Save Mode Filter Collapse Del +| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +| New Tty Find Grep Joincol Delcol +| /tmp/pardes-snap/filewatch/cwd Tty+bash Save Mode Filter Collapse Del | ls | sub w.txt | -| * /tmp/pardes-snap/filewatch/cwd/w.txt Save Tty Collapse Del +| */tmp/pardes-snap/filewatch/cwd/w.txt Save Tty Collapse Del | 1 liMYEDITne 1 | 2 line 2 | 3 /tmp/pardes-snap/filewatch/cwd/sub/s.txt @@ -18,7 +18,7 @@ | 10 line 10 | 11 line 11 | 12 line 12 -| /tmp/pardes-snap/filewatch/cwd/sub/s.txt Save Tty Collapse Del +| /tmp/pardes-snap/filewatch/cwd/sub/s.txt Save Tty Collapse Del | 1 line 1 | 2 line 2 | 3 line 3 diff --git a/test/snapshots/find.golden b/test/snapshots/find.golden index c9c6b755..47480b83 100644 --- a/test/snapshots/find.golden +++ b/test/snapshots/find.golden @@ -1,7 +1,7 @@ == snap group grid=120x41 cursor=7,3 -|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit -| New Tty Find Grep Joincol Delcol -| /tmp/pardes-snap/find/cwd/here.txt Save Tty Collapse Del +| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +| New Tty Find Grep Joincol Delcol +| /tmp/pardes-snap/find/cwd/here.txt Save Tty Collapse Del | 1 Find SPC f == snap armed grid=120x41 cursor=119,4 |3: 1 Find Find @@ -11,25 +11,25 @@ |4: == snap results grid=120x41 cursor=7,3 |3: 1 Find -|5: /tmp/pardes-snap/find/cwd/+Search Save Tty Collapse Del +|5: /tmp/pardes-snap/find/cwd/+Search Save Tty Collapse Del |6: 1 sub/ZQMARK-beta.txt |7: 2 sub/nest/zqmark-gamma.txt |8: 3 zqmark-alpha.txt |9: 4 == snap first grid=120x41 cursor=7,10 -|9: /tmp/pardes-snap/find/cwd/sub/ZQMARK-beta.txt Save Tty Collapse Del +|9: /tmp/pardes-snap/find/cwd/sub/ZQMARK-beta.txt Save Tty Collapse Del |10: 1 beta body == style first grid=120x41 -|0: 0-119 #b2c3b8,#1d2824, -|1: 0-1 d,#887455, 2-2 d,#314738, 3-119 #becfc4,#314738, -|2: 0-1 d,#496656, 2-2 d,#1d2824, 3-28 #b2c3b8,#1d2824, 29-37 #d3b0d9,#1d2824, 38-119 #b2c3b8,#1d2824, +|0: 0-1 d,#1d2824, 2-119 #b2c3b8,#1d2824, +|1: 0-1 d,#887455, 2-119 #becfc4,#314738, +|2: 0-1 d,#496656, 2-27 #b2c3b8,#1d2824, 28-36 #d3b0d9,#1d2824, 37-119 #b2c3b8,#1d2824, |3: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-119 #e5eee5,#0d1410, |4: 0-0 d,#608269, 1-119 d,#0d1410, -|5: 0-1 d,#496656, 2-2 d,#1d2824, 3-28 #b2c3b8,#1d2824, 29-36 #d3b0d9,#1d2824, 37-119 #b2c3b8,#1d2824, +|5: 0-1 d,#496656, 2-27 #b2c3b8,#1d2824, 28-35 #d3b0d9,#1d2824, 36-119 #b2c3b8,#1d2824, |6: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-119 #e5eee5,#0d1410, |7: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-119 #e5eee5,#0d1410, |8: 0-0 d,#152019, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-119 #e5eee5,#0d1410, -|9: 0-1 d,#add38a, 2-2 d,#314738, 3-32 #becfc4,#314738, 33-48 #dfbce5,#314738, 49-119 #becfc4,#314738, +|9: 0-1 d,#add38a, 2-31 #becfc4,#314738, 32-47 #dfbce5,#314738, 48-119 #becfc4,#314738, |10: 0-0 d,#608269, 1-1 d,#0d1410, 2-4 d,#0d1410,b 5-6 #616f64,#0d1410,b 7-119 #e5eee5,#0d1410, |11: 0-0 d,#608269, 1-119 d,#0d1410, |12: 0-0 d,#608269, 1-119 d,#0d1410, @@ -62,10 +62,10 @@ |39: 0-0 d,#608269, 1-119 d,#0d1410, |40: 0-0 d,#608269, 1-119 d,#0d1410, == snap second grid=120x41 cursor=7,13 -|12: /tmp/pardes-snap/find/cwd/sub/nest/zqmark-gamma.txt Save Tty Collapse Del +|12: /tmp/pardes-snap/find/cwd/sub/nest/zqmark-gamma.txt Save Tty Collapse Del |13: 1 gamma body == snap third grid=120x41 cursor=7,16 -|15: /tmp/pardes-snap/find/cwd/zqmark-alpha.txt Save Tty Collapse Del +|15: /tmp/pardes-snap/find/cwd/zqmark-alpha.txt Save Tty Collapse Del |16: 1 alpha body == snap back grid=120x41 cursor=7,13 == snap word grid=120x41 cursor=7,13 diff --git a/test/snapshots/fsearch.golden b/test/snapshots/fsearch.golden index 7ba94492..62c37c25 100644 --- a/test/snapshots/fsearch.golden +++ b/test/snapshots/fsearch.golden @@ -1,11 +1,11 @@ == snap opened grid=180x31 cursor=7,7 -|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit -| New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol -| /tmp/pardes-snap/fsearch/cwd Tty+bash Save Mode Filter Collapse Del /tmp/pardes-snap/fsearch/cwd Tty+bash Save Mode Filter Collapse Del +| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +| New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol +| /tmp/pardes-snap/fsearch/cwd Tty+bash Save Mode Filter Collapse Del /tmp/pardes-snap/fsearch/cwd Tty+bash Save Mode Filter Collapse Del | ls ls | g.txt g.txt | -| /tmp/pardes-snap/fsearch/cwd/g.txt Save Tty Collapse Del +| /tmp/pardes-snap/fsearch/cwd/g.txt Save Tty Collapse Del | 1 l1 | 2 MARK a | 3 l3 @@ -16,14 +16,14 @@ | 8 l8 | 9 l9 | 10 MARK c -| /tmp/pardes-snap/fsearch/cwd Tty+bash Save Mode Filter Collapse Del +| /tmp/pardes-snap/fsearch/cwd Tty+bash Save Mode Filter Collapse Del | ls | g.txt == snap typing grid=180x31 cursor=89,7 |7: 1 l1 /MARK == snap results grid=180x31 cursor=10,8 |7: 1 l1 -|21: /tmp/pardes-snap/fsearch/cwd/+Search Save Tty Collapse Del LocationsConfig +|21: /tmp/pardes-snap/fsearch/cwd/+Search Save Tty Collapse LocationsConfig Del |22: 1 g.txt:2:1-4 |23: 2 MARK a |24: 3 g.txt:6:1-4 @@ -32,13 +32,13 @@ |27: 6 MARK c |28: 7 == style results grid=180x31 -|0: 0-179 #b2c3b8,#1d2824, -|1: 0-1 d,#887455, 2-2 d,#314738, 3-89 #becfc4,#314738, 90-91 #becfc4,#887455, 92-92 #becfc4,#1d2824, 93-179 #b2c3b8,#1d2824, -|2: 0-1 d,#496656, 2-2 d,#1d2824, 3-31 #b2c3b8,#1d2824, 32-40 #d3b0d9,#1d2824, 41-89 #b2c3b8,#1d2824, 90-91 #b2c3b8,#496656, 92-121 #b2c3b8,#1d2824, 122-130 #d3b0d9,#1d2824, 131-179 #b2c3b8,#1d2824, +|0: 0-1 d,#1d2824, 2-179 #b2c3b8,#1d2824, +|1: 0-1 d,#887455, 2-89 #becfc4,#314738, 90-91 #becfc4,#887455, 92-179 #b2c3b8,#1d2824, +|2: 0-1 d,#496656, 2-30 #b2c3b8,#1d2824, 31-39 #d3b0d9,#1d2824, 40-89 #b2c3b8,#1d2824, 90-91 #b2c3b8,#496656, 92-120 #b2c3b8,#1d2824, 121-129 #d3b0d9,#1d2824, 130-179 #b2c3b8,#1d2824, |3: 0-0 d,#608269, 1-1 d,#0d1410, 2-89 #e5eee5,#0d1410, 90-90 #e5eee5,#608269, 91-179 #e5eee5,#0d1410, |4: 0-0 d,#608269, 1-1 d,#0d1410, 2-89 #e5eee5,#0d1410, 90-90 #e5eee5,#608269, 91-179 #e5eee5,#0d1410, |5: 0-0 d,#608269, 1-89 d,#0d1410, 90-90 d,#608269, 91-179 d,#0d1410, -|6: 0-1 d,#add38a, 2-2 d,#314738, 3-31 #becfc4,#314738, 32-37 #dfbce5,#314738, 38-89 #becfc4,#314738, 90-90 #becfc4,#608269, 91-179 #becfc4,#0d1410, +|6: 0-1 d,#add38a, 2-30 #becfc4,#314738, 31-36 #dfbce5,#314738, 37-89 #becfc4,#314738, 90-90 #becfc4,#608269, 91-179 #becfc4,#0d1410, |7: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-89 #e5eee5,#0d1410, 90-90 #e5eee5,#608269, 91-179 #e5eee5,#0d1410, |8: 0-0 d,#608269, 1-1 d,#0d1410, 2-4 d,#0d1410,b 5-6 #616f64,#0d1410,b 7-10 #f5f7ee,#3c614a, 11-11 #f5f7ee,#0d1410, 12-89 #e5eee5,#0d1410, 90-90 #e5eee5,#608269, 91-179 #e5eee5,#0d1410, |9: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-89 #e5eee5,#0d1410, 90-90 #e5eee5,#608269, 91-179 #e5eee5,#0d1410, @@ -49,11 +49,11 @@ |14: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-89 #e5eee5,#0d1410, 90-90 #e5eee5,#608269, 91-179 #e5eee5,#0d1410, |15: 0-0 d,#152019, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-89 #e5eee5,#0d1410, 90-90 #e5eee5,#608269, 91-179 #e5eee5,#0d1410, |16: 0-0 d,#152019, 1-3 d,#0d1410, 4-6 #59675c,#0d1410, 7-89 #e5eee5,#0d1410, 90-90 #e5eee5,#608269, 91-179 #e5eee5,#0d1410, -|17: 0-1 d,#496656, 2-2 d,#1d2824, 3-31 #b2c3b8,#1d2824, 32-40 #d3b0d9,#1d2824, 41-89 #b2c3b8,#1d2824, 90-90 #b2c3b8,#608269, 91-179 #b2c3b8,#0d1410, +|17: 0-1 d,#496656, 2-30 #b2c3b8,#1d2824, 31-39 #d3b0d9,#1d2824, 40-89 #b2c3b8,#1d2824, 90-90 #b2c3b8,#608269, 91-179 #b2c3b8,#0d1410, |18: 0-0 d,#608269, 1-1 d,#0d1410, 2-89 #e5eee5,#0d1410, 90-90 #e5eee5,#608269, 91-179 #e5eee5,#0d1410, |19: 0-0 d,#608269, 1-1 d,#0d1410, 2-89 #e5eee5,#0d1410, 90-90 #e5eee5,#608269, 91-179 #e5eee5,#0d1410, |20: 0-0 d,#608269, 1-89 d,#0d1410, 90-90 d,#608269, 91-179 d,#0d1410, -|21: 0-1 d,#496656, 2-2 d,#1d2824, 3-31 #b2c3b8,#1d2824, 32-39 #d3b0d9,#1d2824, 40-89 #b2c3b8,#1d2824, 90-90 #b2c3b8,#608269, 91-179 #b2c3b8,#0d1410, +|21: 0-1 d,#496656, 2-30 #b2c3b8,#1d2824, 31-38 #d3b0d9,#1d2824, 39-89 #b2c3b8,#1d2824, 90-90 #b2c3b8,#608269, 91-179 #b2c3b8,#0d1410, |22: 0-0 d,#608269, 1-4 d,#0d1410, 5-89 #59675c,#0d1410, 90-90 #59675c,#608269, 91-179 #59675c,#0d1410, |23: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-10 #f7e4a5,#5e4923, 11-11 #f7e4a5,#0d1410, 12-89 #e5eee5,#0d1410, 90-90 #e5eee5,#608269, 91-179 #e5eee5,#0d1410, |24: 0-0 d,#608269, 1-4 d,#0d1410, 5-89 #59675c,#0d1410, 90-90 #59675c,#608269, 91-179 #59675c,#0d1410, @@ -88,7 +88,7 @@ |16: 10 MARK c == snap cancel grid=180x31 cursor=10,12 == snap nomatch grid=180x31 cursor=7,26 -|11: /tmp/pardes-snap/fsearch/cwd/+Search Save Tty Collapse Del LocationsConfig +|11: /tmp/pardes-snap/fsearch/cwd/+Search Save Tty Collapse LocationsConfig Del |12: 1 |13: |14: diff --git a/test/snapshots/ghostty-mid.golden b/test/snapshots/ghostty-mid.golden index 4bd8bf1f..6f61736e 100644 --- a/test/snapshots/ghostty-mid.golden +++ b/test/snapshots/ghostty-mid.golden @@ -1,8 +1,8 @@ == snap ghostty-mid grid=100x31 cursor=4,8 -|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit -| New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol -| /tmp/pardes-snap/ghostty-mid/cwd Tty+bash Save /tmp/pardes-snap/ghostty-mid/cwd Tty+bash Save -| Mode Filter Collapse Del Mode Filter Collapse Del +| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +| New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol +| /tmp/pardes-snap/ghostty-mid/cwd Tty+bash Save M /tmp/pardes-snap/ghostty-mid/cwd Tty+bash Save M +| ode Filter Collapse Del ode Filter Collapse Del | ZZPAD ls | ./g.sh g.txt | ./g.sh @@ -16,7 +16,7 @@ | | | -| /tmp/pardes-snap/ghostty-mid/cwd Tty+bash Save -| Mode Filter Collapse Del +| /tmp/pardes-snap/ghostty-mid/cwd Tty+bash Save M +| ode Filter Collapse Del | ls | g.txt diff --git a/test/snapshots/grep.golden b/test/snapshots/grep.golden index 687d7099..957096c3 100644 --- a/test/snapshots/grep.golden +++ b/test/snapshots/grep.golden @@ -1,11 +1,11 @@ == snap opened grid=180x31 cursor=7,7 -|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit -| New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol -| /tmp/pardes-snap/grep/cwd Tty+bash Save Mode Filter Collapse Del /tmp/pardes-snap/grep/cwd Tty+bash Save Mode Filter Collapse Del +| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +| New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol +| /tmp/pardes-snap/grep/cwd Tty+bash Save Mode Filter Collapse Del /tmp/pardes-snap/grep/cwd Tty+bash Save Mode Filter Collapse Del | ls ls | a.txt noise.txt sub a.txt noise.txt sub | -| /tmp/pardes-snap/grep/cwd/a.txt Save Tty Collapse Del +| /tmp/pardes-snap/grep/cwd/a.txt Save Tty Collapse Del | 1 hello TARGET one | 2 nothing here | 3 last TARGET line @@ -16,25 +16,25 @@ | | | -| /tmp/pardes-snap/grep/cwd Tty+bash Save Mode Filter Collapse Del +| /tmp/pardes-snap/grep/cwd Tty+bash Save Mode Filter Collapse Del | ls | a.txt noise.txt sub == snap typing grid=180x31 cursor=89,7 |7: 1 hello TARGET one Grep /TARGET == snap results grid=180x31 cursor=7,7 |7: 1 hello TARGET one -|21: /tmp/pardes-snap/grep/cwd/+Search Save Tty Collapse Del LocationsConfig +|21: /tmp/pardes-snap/grep/cwd/+Search Save Tty Collapse LocationsConfig Del |22: 1 a.txt:1:7-12 hello TARGET one |23: 2 a.txt:3:6-11 last TARGET line |24: 3 sub/b.txt:2:1-6 TARGET inside sub |25: 4 == snap first grid=180x31 cursor=18,7 == snap opened-hit grid=180x31 cursor=12,12 -|10: /tmp/pardes-snap/grep/cwd/sub/b.txt Save Tty Collapse Del +|10: /tmp/pardes-snap/grep/cwd/sub/b.txt Save Tty Collapse Del |11: 1 deep |12: 2 TARGET inside sub == snap nomatch grid=180x31 cursor=2,4 -|25: /tmp/pardes-snap/grep/cwd/sub/+Search Save Tty Collapse Del LocationsConfig +|25: /tmp/pardes-snap/grep/cwd/sub/+Search Save Tty Collapse LocationsConfig Del |26: 1 == snap chordsel grid=180x31 cursor=19,7 == snap chord grid=180x31 cursor=19,7 diff --git a/test/snapshots/headersweep-restored.golden b/test/snapshots/headersweep-restored.golden index 176520dd..522945bd 100644 --- a/test/snapshots/headersweep-restored.golden +++ b/test/snapshots/headersweep-restored.golden @@ -1,8 +1,8 @@ == style col-sweeping grid=120x21 -|0: 0-119 #b2c3b8,#1d2824, -|1: 0-1 d,#887455, 2-2 d,#314738, 3-35 #becfc4,#314738, 36-43 #f5f7ee,#5b7e5a, 44-59 #becfc4,#314738, 60-61 #becfc4,#887455, 62-62 #becfc4,#1d2824, 63-119 #b2c3b8,#1d2824, -|2: 0-1 d,#add38a, 2-2 d,#314738, 3-44 #becfc4,#314738, 45-53 #dfbce5,#314738, 54-59 #becfc4,#314738, 60-61 #becfc4,#496656, 62-62 #becfc4,#1d2824, 63-104 #b2c3b8,#1d2824, 105-113 #d3b0d9,#1d2824, 114-119 #b2c3b8,#1d2824, -|3: 0-2 d,#314738, 3-59 #becfc4,#314738, 60-62 #becfc4,#1d2824, 63-119 #b2c3b8,#1d2824, +|0: 0-1 d,#1d2824, 2-119 #b2c3b8,#1d2824, +|1: 0-1 d,#887455, 2-34 #becfc4,#314738, 35-42 #f5f7ee,#5b7e5a, 43-59 #becfc4,#314738, 60-61 #becfc4,#887455, 62-119 #b2c3b8,#1d2824, +|2: 0-1 d,#add38a, 2-43 #becfc4,#314738, 44-52 #dfbce5,#314738, 53-59 #becfc4,#314738, 60-61 #becfc4,#496656, 62-103 #b2c3b8,#1d2824, 104-112 #d3b0d9,#1d2824, 113-119 #b2c3b8,#1d2824, +|3: 0-1 d,#314738, 2-59 #becfc4,#314738, 60-61 #becfc4,#1d2824, 62-119 #b2c3b8,#1d2824, |4: 0-0 d,#608269, 1-1 d,#0d1410, 2-59 #e5eee5,#0d1410, 60-60 #e5eee5,#608269, 61-119 #e5eee5,#0d1410, |5: 0-0 d,#608269, 1-1 d,#0d1410, 2-59 #e5eee5,#0d1410, 60-60 #e5eee5,#608269, 61-119 #e5eee5,#0d1410, |6: 0-0 d,#608269, 1-1 d,#0d1410, 2-23 #e5eee5,#0d1410,f 24-59 #e5eee5,#0d1410, 60-60 #e5eee5,#608269, 61-61 #e5eee5,#0d1410, 62-83 #e5eee5,#0d1410,f 84-119 #e5eee5,#0d1410, @@ -11,8 +11,8 @@ |9: 0-0 d,#608269, 1-59 d,#0d1410, 60-60 d,#608269, 61-119 d,#0d1410, |10: 0-0 d,#608269, 1-59 d,#0d1410, 60-60 d,#608269, 61-119 d,#0d1410, |11: 0-0 d,#608269, 1-59 d,#0d1410, 60-60 d,#608269, 61-119 d,#0d1410, -|12: 0-1 d,#496656, 2-2 d,#1d2824, 3-44 #b2c3b8,#1d2824, 45-53 #d3b0d9,#1d2824, 54-59 #b2c3b8,#1d2824, 60-60 #b2c3b8,#608269, 61-119 #b2c3b8,#0d1410, -|13: 0-2 d,#1d2824, 3-59 #b2c3b8,#1d2824, 60-60 #b2c3b8,#608269, 61-119 #b2c3b8,#0d1410, +|12: 0-1 d,#496656, 2-43 #b2c3b8,#1d2824, 44-52 #d3b0d9,#1d2824, 53-59 #b2c3b8,#1d2824, 60-60 #b2c3b8,#608269, 61-119 #b2c3b8,#0d1410, +|13: 0-1 d,#1d2824, 2-59 #b2c3b8,#1d2824, 60-60 #b2c3b8,#608269, 61-119 #b2c3b8,#0d1410, |14: 0-0 d,#608269, 1-1 d,#0d1410, 2-59 #e5eee5,#0d1410, 60-60 #e5eee5,#608269, 61-119 #e5eee5,#0d1410, |15: 0-0 d,#608269, 1-1 d,#0d1410, 2-59 #e5eee5,#0d1410, 60-60 #e5eee5,#608269, 61-119 #e5eee5,#0d1410, |16: 0-0 d,#608269, 1-1 d,#0d1410, 2-23 #e5eee5,#0d1410,f 24-59 #e5eee5,#0d1410, 60-60 #e5eee5,#608269, 61-119 #e5eee5,#0d1410, @@ -21,10 +21,10 @@ |19: 0-0 d,#608269, 1-59 d,#0d1410, 60-60 d,#608269, 61-119 d,#0d1410, |20: 0-0 d,#608269, 1-59 d,#0d1410, 60-60 d,#608269, 61-119 d,#0d1410, == snap col-swept grid=120x21 cursor=4,7 -|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit Restore /tmp/pardes-snap/headersweep-restore -| New Tty Find Grep Joincol Delcol echo RE''STORED-COL New Tty Find Grep Joincol Delcol -| /tmp/pardes-snap/headersweep-restored/cwd Tty+bash Save M /tmp/pardes-snap/headersweep-restored/cwd Tty+bash Save M -| ode Filter Collapse Del ode Filter Collapse Del +| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit Restore /tmp/pardes-snap/headersweep-resto +| New Tty Find Grep Joincol Delcol echo RE''STORED-COL New Tty Find Grep Joincol Delcol +| /tmp/pardes-snap/headersweep-restored/cwd Tty+bash Save Mo /tmp/pardes-snap/headersweep-restored/cwd Tty+bash Save Mo +| de Filter Collapse Del de Filter Collapse Del | $ ls $ ls | $ $ | ── restored history ── ── restored history ── @@ -33,22 +33,22 @@ | | | -| /tmp/pardes-snap/headersweep-restored/cwd Tty+bash Save M -| ode Filter Collapse Del +| /tmp/pardes-snap/headersweep-restored/cwd Tty+bash Save Mo +| de Filter Collapse Del | $ | ── restored history ── | -| /tmp/pardes-snap/headersweep-restored/cwd (echo RE''STORE -| D-COL) exit 0 Kill Save Collapse Del +| /tmp/pardes-snap/headersweep-restored/cwd (echo RE''STORED +| -COL) exit 0 Kill Save Collapse Del | exit 0 == style ws-sweeping grid=120x21 -|0: 0-100 #b2c3b8,#1d2824, 101-108 #f5f7ee,#5b7e5a, 109-119 #b2c3b8,#1d2824, -|1: 0-1 d,#887455, 2-2 d,#314738, 3-59 #becfc4,#314738, 60-61 #becfc4,#887455, 62-62 #becfc4,#1d2824, 63-119 #b2c3b8,#1d2824, +|0: 0-1 d,#1d2824, 2-100 #b2c3b8,#1d2824, 101-108 #f5f7ee,#5b7e5a, 109-119 #b2c3b8,#1d2824, +|1: 0-1 d,#887455, 2-59 #becfc4,#314738, 60-61 #becfc4,#887455, 62-119 #b2c3b8,#1d2824, |15: 0-0 d,#608269, 1-1 d,#0d1410, 2-23 #e5eee5,#0d1410,f 24-59 #e5eee5,#0d1410, 60-60 #e5eee5,#608269, 61-119 #e5eee5,#0d1410, |16: 0-0 d,#152019, 1-59 d,#0d1410, 60-60 d,#608269, 61-119 d,#0d1410, -|17: 0-1 d,#496656, 2-2 d,#1d2824, 3-59 #b2c3b8,#1d2824, 60-60 #b2c3b8,#608269, 61-119 #b2c3b8,#0d1410, -|18: 0-2 d,#1d2824, 3-59 #b2c3b8,#1d2824, 60-60 #b2c3b8,#608269, 61-119 #b2c3b8,#0d1410, +|17: 0-1 d,#496656, 2-59 #b2c3b8,#1d2824, 60-60 #b2c3b8,#608269, 61-119 #b2c3b8,#0d1410, +|18: 0-1 d,#1d2824, 2-59 #b2c3b8,#1d2824, 60-60 #b2c3b8,#608269, 61-119 #b2c3b8,#0d1410, |19: 0-0 d,#152019, 1-1 d,#0d1410, 2-59 #e5eee5,#0d1410, 60-60 #e5eee5,#608269, 61-119 #e5eee5,#0d1410, == snap ws-swept grid=120x21 cursor=4,7 -|0: Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit Restore /tmp/pardes-snap/headersweep-rest ec -|18: D-WS) exit 0 Kill Save Collapse Del +|0: Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit Restore /tmp/pardes-snap/headersweep-re ec +|18: -WS) exit 0 Kill Save Collapse Del diff --git a/test/snapshots/headersweep.golden b/test/snapshots/headersweep.golden index c22120ca..a178306f 100644 --- a/test/snapshots/headersweep.golden +++ b/test/snapshots/headersweep.golden @@ -1,7 +1,7 @@ == style col-sweeping grid=120x21 -|0: 0-119 #b2c3b8,#1d2824, -|1: 0-1 d,#887455, 2-2 d,#314738, 3-35 #becfc4,#314738, 36-43 #f5f7ee,#5b7e5a, 44-59 #becfc4,#314738, 60-61 #becfc4,#887455, 62-62 #becfc4,#1d2824, 63-119 #b2c3b8,#1d2824, -|2: 0-1 d,#add38a, 2-2 d,#314738, 3-35 #becfc4,#314738, 36-44 #dfbce5,#314738, 45-59 #becfc4,#314738, 60-61 #becfc4,#496656, 62-62 #becfc4,#1d2824, 63-95 #b2c3b8,#1d2824, 96-104 #d3b0d9,#1d2824, 105-119 #b2c3b8,#1d2824, +|0: 0-1 d,#1d2824, 2-119 #b2c3b8,#1d2824, +|1: 0-1 d,#887455, 2-34 #becfc4,#314738, 35-42 #f5f7ee,#5b7e5a, 43-59 #becfc4,#314738, 60-61 #becfc4,#887455, 62-119 #b2c3b8,#1d2824, +|2: 0-1 d,#add38a, 2-34 #becfc4,#314738, 35-43 #dfbce5,#314738, 44-59 #becfc4,#314738, 60-61 #becfc4,#496656, 62-94 #b2c3b8,#1d2824, 95-103 #d3b0d9,#1d2824, 104-119 #b2c3b8,#1d2824, |3: 0-2 d,#314738, 3-59 #becfc4,#314738, 60-62 #becfc4,#1d2824, 63-119 #b2c3b8,#1d2824, |4: 0-0 d,#608269, 1-1 d,#0d1410, 2-59 #e5eee5,#0d1410, 60-60 #e5eee5,#608269, 61-119 #e5eee5,#0d1410, |5: 0-0 d,#608269, 1-1 d,#0d1410, 2-59 #e5eee5,#0d1410, 60-60 #e5eee5,#608269, 61-119 #e5eee5,#0d1410, @@ -11,7 +11,7 @@ |9: 0-0 d,#608269, 1-59 d,#0d1410, 60-60 d,#608269, 61-119 d,#0d1410, |10: 0-0 d,#608269, 1-59 d,#0d1410, 60-60 d,#608269, 61-119 d,#0d1410, |11: 0-0 d,#608269, 1-59 d,#0d1410, 60-60 d,#608269, 61-119 d,#0d1410, -|12: 0-1 d,#496656, 2-2 d,#1d2824, 3-35 #b2c3b8,#1d2824, 36-44 #d3b0d9,#1d2824, 45-59 #b2c3b8,#1d2824, 60-60 #b2c3b8,#608269, 61-119 #b2c3b8,#0d1410, +|12: 0-1 d,#496656, 2-34 #b2c3b8,#1d2824, 35-43 #d3b0d9,#1d2824, 44-59 #b2c3b8,#1d2824, 60-60 #b2c3b8,#608269, 61-119 #b2c3b8,#0d1410, |13: 0-2 d,#1d2824, 3-59 #b2c3b8,#1d2824, 60-60 #b2c3b8,#608269, 61-119 #b2c3b8,#0d1410, |14: 0-0 d,#608269, 1-1 d,#0d1410, 2-59 #e5eee5,#0d1410, 60-60 #e5eee5,#608269, 61-119 #e5eee5,#0d1410, |15: 0-0 d,#608269, 1-1 d,#0d1410, 2-59 #e5eee5,#0d1410, 60-60 #e5eee5,#608269, 61-119 #e5eee5,#0d1410, @@ -21,10 +21,10 @@ |19: 0-0 d,#608269, 1-59 d,#0d1410, 60-60 d,#608269, 61-119 d,#0d1410, |20: 0-0 d,#608269, 1-59 d,#0d1410, 60-60 d,#608269, 61-119 d,#0d1410, == snap col-swept grid=120x21 cursor=4,6 -|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit -| New Tty Find Grep Joincol Delcol echo SW''EPT-COL New Tty Find Grep Joincol Delcol -| /tmp/pardes-snap/headersweep/cwd Tty+bash Save Mode Filte /tmp/pardes-snap/headersweep/cwd Tty+bash Save Mode Filte -| r Collapse Del r Collapse Del +| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +| New Tty Find Grep Joincol Delcol echo SW''EPT-COL New Tty Find Grep Joincol Delcol +| /tmp/pardes-snap/headersweep/cwd Tty+bash Save Mode Filter /tmp/pardes-snap/headersweep/cwd Tty+bash Save Mode Filter +| Collapse Del Collapse Del | ls ls | hay.txt hay.txt | @@ -33,31 +33,31 @@ | | | -| /tmp/pardes-snap/headersweep/cwd Tty+bash Save Mode Filte -| r Collapse Del +| /tmp/pardes-snap/headersweep/cwd Tty+bash Save Mode Filter +| Collapse Del | ls | hay.txt | -| /tmp/pardes-snap/headersweep/cwd (echo SW''EPT-COL) exit -| 0 Kill Save Collapse Del +| /tmp/pardes-snap/headersweep/cwd (echo SW''EPT-COL) exit 0 +| Kill Save Collapse Del | exit 0 == snap ws-swept grid=120x21 cursor=4,6 -|0: Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit echo SW''EPT-WS -|17: /tmp/pardes-snap/headersweep/cwd (echo SW''EPT-WS) exit 0 -|18: Kill Save Collapse Del +|0: Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit echo SW''EPT-WS +|17: /tmp/pardes-snap/headersweep/cwd (echo SW''EPT-WS) exit 0 +|18: Kill Save Collapse Del == snap ws-looked grid=120x21 cursor=7,9 -|0: Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit echo SW''EPT-WS xxhay.txtxx -|7: /tmp/pardes-snap/headersweep/cwd/hay.txt Save Tty Collaps -|8: e Del +|0: Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit echo SW''EPT-WS xxhay.txtxx +|7: /tmp/pardes-snap/headersweep/cwd/hay.txt Save Tty Collapse +|8: Del |9: 1 ZQNEEDLE == snap cancelled grid=120x21 cursor=7,9 == style selected grid=120x21 -|1: 0-1 d,#887455, 2-2 d,#1d2824, 3-59 #b2c3b8,#1d2824, 60-61 #b2c3b8,#887455, 62-62 #b2c3b8,#314738, 63-70 #becfc4,#314738, 71-79 #f5f7ee,#3c614a, 80-80 #f5f7ee,#314738, 81-119 #becfc4,#314738, -|2: 0-1 d,#496656, 2-2 d,#1d2824, 3-35 #b2c3b8,#1d2824, 36-44 #d3b0d9,#1d2824, 45-59 #b2c3b8,#1d2824, 60-61 #b2c3b8,#add38a, 62-62 #b2c3b8,#314738, 63-95 #becfc4,#314738, 96-104 #dfbce5,#314738, 105-119 #becfc4,#314738, +|1: 0-1 d,#887455, 2-59 #b2c3b8,#1d2824, 60-61 #b2c3b8,#887455, 62-69 #becfc4,#314738, 70-78 #f5f7ee,#3c614a, 79-79 #f5f7ee,#314738, 80-119 #becfc4,#314738, +|2: 0-1 d,#496656, 2-34 #b2c3b8,#1d2824, 35-43 #d3b0d9,#1d2824, 44-59 #b2c3b8,#1d2824, 60-61 #b2c3b8,#add38a, 62-94 #becfc4,#314738, 95-103 #dfbce5,#314738, 104-119 #becfc4,#314738, |3: 0-2 d,#1d2824, 3-59 #b2c3b8,#1d2824, 60-62 #b2c3b8,#314738, 63-119 #becfc4,#314738, -|7: 0-1 d,#496656, 2-2 d,#1d2824, 3-35 #b2c3b8,#1d2824, 36-43 #d3b0d9,#1d2824, 44-59 #b2c3b8,#1d2824, 60-60 #b2c3b8,#608269, 61-119 #b2c3b8,#0d1410, +|7: 0-1 d,#496656, 2-34 #b2c3b8,#1d2824, 35-42 #d3b0d9,#1d2824, 43-59 #b2c3b8,#1d2824, 60-60 #b2c3b8,#608269, 61-119 #b2c3b8,#0d1410, |8: 0-2 d,#1d2824, 3-59 #b2c3b8,#1d2824, 60-60 #b2c3b8,#608269, 61-119 #b2c3b8,#0d1410, |9: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-59 #e5eee5,#0d1410, 60-60 #e5eee5,#608269, 61-119 #e5eee5,#0d1410, -|17: 0-1 d,#496656, 2-2 d,#1d2824, 3-59 #b2c3b8,#1d2824, 60-60 #b2c3b8,#608269, 61-119 #b2c3b8,#0d1410, -|18: 0-3 d,#1d2824, 4-59 #b2c3b8,#1d2824, 60-60 #b2c3b8,#608269, 61-119 #b2c3b8,#0d1410, +|17: 0-1 d,#496656, 2-59 #b2c3b8,#1d2824, 60-60 #b2c3b8,#608269, 61-119 #b2c3b8,#0d1410, +|18: 0-1 d,#1d2824, 2-59 #b2c3b8,#1d2824, 60-60 #b2c3b8,#608269, 61-119 #b2c3b8,#0d1410, |19: 0-0 d,#152019, 1-1 d,#0d1410, 2-59 #e5eee5,#0d1410, 60-60 #e5eee5,#608269, 61-119 #e5eee5,#0d1410, diff --git a/test/snapshots/hscroll.golden b/test/snapshots/hscroll.golden index e73bf4c3..23bb6279 100644 --- a/test/snapshots/hscroll.golden +++ b/test/snapshots/hscroll.golden @@ -1,13 +1,13 @@ == snap opened grid=90x31 cursor=7,9 -|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit -| New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol -| /tmp/pardes-snap/hscroll/cwd Tty+bash Save /tmp/pardes-snap/hscroll/cwd Tty+bash Save -| Mode Filter Collapse Del Mode Filter Collapse Del +| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +| New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol +| /tmp/pardes-snap/hscroll/cwd Tty+bash Save /tmp/pardes-snap/hscroll/cwd Tty+bash Save +| Mode Filter Collapse Del Mode Filter Collapse Del | ls ls | wide.txt wide.txt | -| /tmp/pardes-snap/hscroll/cwd/wide.txt Save -| Tty Collapse Del +| /tmp/pardes-snap/hscroll/cwd/wide.txt Save +| Tty Collapse Del | 1 short1 END_A_MARKER_WAY_OUT_RIGHT_padp | | @@ -16,8 +16,8 @@ | | | -| /tmp/pardes-snap/hscroll/cwd Tty+bash Save -| Mode Filter Collapse Del +| /tmp/pardes-snap/hscroll/cwd Tty+bash Save +| Mode Filter Collapse Del | ls | wide.txt == snap wheeled grid=90x31 cursor=7,9 diff --git a/test/snapshots/images.golden b/test/snapshots/images.golden index 0f15804b..51cb4922 100644 --- a/test/snapshots/images.golden +++ b/test/snapshots/images.golden @@ -1,12 +1,12 @@ == snap img-open grid=150x31 cursor=11,8 -|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit -| New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol -| /tmp/pardes-snap/images/cwd Tty+bash Save Mode Filter Collapse Del /tmp/pardes-snap/images/cwd Tty+bash Save Mode Filter Collapse Del +| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +| New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol +| /tmp/pardes-snap/images/cwd Tty+bash Save Mode Filter Collapse Del /tmp/pardes-snap/images/cwd Tty+bash Save Mode Filter Collapse Del | ls ls | pic.ppm pic.ppm | -| img petscii:on palette:commodore ascii:on /tmp/pardes-snap/images/cwd/pi -| c.ppm Tty Collapse Del +| img petscii:on palette:commodore ascii:on /tmp/pardes-snap/images/cwd/pic +| .ppm Tty Collapse Del | x🬱\╲🬌\~▄🬥4▟g*🬺🬶_🬆🬻 | >A8🬌Cq&.\H&🬹🬜C▛🬻 | >0p' | $ '\033_Ga=q,i=1,s=1,v=1,f=24,t=d;AAAA\033\\\033[>0p'Gi=1;OK diff --git a/test/snapshots/look-center.golden b/test/snapshots/look-center.golden index c861bb8f..fcc65ceb 100644 --- a/test/snapshots/look-center.golden +++ b/test/snapshots/look-center.golden @@ -1,11 +1,11 @@ == snap center-open grid=150x31 cursor=15,12 -|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit -| New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol -| /tmp/pardes-snap/look-center/cwd Tty+bash Save Mode Filter Collapse Del /tmp/pardes-snap/look-center/cwd Tty+bash Save Mode Filter Collapse Del +| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +| New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol +| /tmp/pardes-snap/look-center/cwd Tty+bash Save Mode Filter Collapse Del /tmp/pardes-snap/look-center/cwd Tty+bash Save Mode Filter Collapse Del | ls ls | big.txt big.txt | -| /tmp/pardes-snap/look-center/cwd/big.txt Save Tty Collapse Del +| /tmp/pardes-snap/look-center/cwd/big.txt Save Tty Collapse Del | 95 line 95 | 96 line 96 | 97 line 97 @@ -16,7 +16,7 @@ | 102 line 102 | 103 line 103 | 104 line 104 -| /tmp/pardes-snap/look-center/cwd Tty+bash Save Mode Filter Collapse Del +| /tmp/pardes-snap/look-center/cwd Tty+bash Save Mode Filter Collapse Del | ls | big.txt == snap center-dedup grid=150x31 cursor=15,12 diff --git a/test/snapshots/look-dir.golden b/test/snapshots/look-dir.golden index 29e67d5f..4acc0d79 100644 --- a/test/snapshots/look-dir.golden +++ b/test/snapshots/look-dir.golden @@ -1,13 +1,13 @@ == snap dir-open grid=100x31 cursor=4,11 -|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit -| New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol -| /tmp/pardes-snap/look-dir/cwd Tty+bash Save Mod /tmp/pardes-snap/look-dir/cwd Tty+bash Save Mod -| e Filter Collapse Del e Filter Collapse Del +| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +| New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol +| /tmp/pardes-snap/look-dir/cwd Tty+bash Save Mode /tmp/pardes-snap/look-dir/cwd Tty+bash Save Mode +| Filter Collapse Del Filter Collapse Del | ls ls | sub top.txt sub top.txt | -| /tmp/pardes-snap/look-dir/cwd/sub Tty+bash Save -| Mode Filter Collapse Del +| /tmp/pardes-snap/look-dir/cwd/sub Tty+bash Save +| Mode Filter Collapse Del | ls | inner.txt | @@ -16,7 +16,7 @@ | | | -| /tmp/pardes-snap/look-dir/cwd Tty+bash Save Mod -| e Filter Collapse Del +| /tmp/pardes-snap/look-dir/cwd Tty+bash Save Mode +| Filter Collapse Del | ls | sub top.txt diff --git a/test/snapshots/look-file-1col.golden b/test/snapshots/look-file-1col.golden index 81ba4ded..53fc4237 100644 --- a/test/snapshots/look-file-1col.golden +++ b/test/snapshots/look-file-1col.golden @@ -1,11 +1,11 @@ == snap file-open-1col grid=100x31 cursor=14,19 -|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit -| New Tty Find Grep Joincol Delcol -| /tmp/pardes-snap/look-file-1col/cwd Tty+bash Save Mode Filter Collapse Del +| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +| New Tty Find Grep Joincol Delcol +| /tmp/pardes-snap/look-file-1col/cwd Tty+bash Save Mode Filter Collapse Del | ls | big.txt | -| /tmp/pardes-snap/look-file-1col/cwd/big.txt Save Tty Collapse Del +| /tmp/pardes-snap/look-file-1col/cwd/big.txt Save Tty Collapse Del | 28 line 28 | 29 line 29 | 30 line 30 diff --git a/test/snapshots/look-file.golden b/test/snapshots/look-file.golden index 4d4bbdfe..bf46f854 100644 --- a/test/snapshots/look-file.golden +++ b/test/snapshots/look-file.golden @@ -1,11 +1,11 @@ == snap file-open grid=150x31 cursor=14,12 -|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit -| New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol -| /tmp/pardes-snap/look-file/cwd Tty+bash Save Mode Filter Collapse Del /tmp/pardes-snap/look-file/cwd Tty+bash Save Mode Filter Collapse Del +| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +| New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol +| /tmp/pardes-snap/look-file/cwd Tty+bash Save Mode Filter Collapse Del /tmp/pardes-snap/look-file/cwd Tty+bash Save Mode Filter Collapse Del | ls ls | big.txt big.txt | -| /tmp/pardes-snap/look-file/cwd/big.txt Save Tty Collapse Del +| /tmp/pardes-snap/look-file/cwd/big.txt Save Tty Collapse Del | 35 line 35 | 36 line 36 | 37 line 37 @@ -16,17 +16,17 @@ | 42 line 42 | 43 line 43 | 44 line 44 -| /tmp/pardes-snap/look-file/cwd Tty+bash Save Mode Filter Collapse Del +| /tmp/pardes-snap/look-file/cwd Tty+bash Save Mode Filter Collapse Del | ls | big.txt == style file-open grid=150x31 -|0: 0-149 #b2c3b8,#1d2824, -|1: 0-1 d,#887455, 2-2 d,#314738, 3-74 #becfc4,#314738, 75-76 #becfc4,#887455, 77-77 #becfc4,#1d2824, 78-149 #b2c3b8,#1d2824, -|2: 0-1 d,#496656, 2-2 d,#1d2824, 3-33 #b2c3b8,#1d2824, 34-42 #d3b0d9,#1d2824, 43-74 #b2c3b8,#1d2824, 75-76 #b2c3b8,#496656, 77-108 #b2c3b8,#1d2824, 109-117 #d3b0d9,#1d2824, 118-149 #b2c3b8,#1d2824, +|0: 0-1 d,#1d2824, 2-149 #b2c3b8,#1d2824, +|1: 0-1 d,#887455, 2-74 #becfc4,#314738, 75-76 #becfc4,#887455, 77-149 #b2c3b8,#1d2824, +|2: 0-1 d,#496656, 2-32 #b2c3b8,#1d2824, 33-41 #d3b0d9,#1d2824, 42-74 #b2c3b8,#1d2824, 75-76 #b2c3b8,#496656, 77-107 #b2c3b8,#1d2824, 108-116 #d3b0d9,#1d2824, 117-149 #b2c3b8,#1d2824, |3: 0-0 d,#608269, 1-1 d,#0d1410, 2-74 #e5eee5,#0d1410, 75-75 #e5eee5,#608269, 76-149 #e5eee5,#0d1410, |4: 0-0 d,#608269, 1-1 d,#0d1410, 2-74 #e5eee5,#0d1410, 75-75 #e5eee5,#608269, 76-149 #e5eee5,#0d1410, |5: 0-0 d,#608269, 1-74 d,#0d1410, 75-75 d,#608269, 76-149 d,#0d1410, -|6: 0-1 d,#add38a, 2-2 d,#314738, 3-33 #becfc4,#314738, 34-41 #dfbce5,#314738, 42-74 #becfc4,#314738, 75-75 #becfc4,#608269, 76-149 #becfc4,#0d1410, +|6: 0-1 d,#add38a, 2-32 #becfc4,#314738, 33-40 #dfbce5,#314738, 41-74 #becfc4,#314738, 75-75 #becfc4,#608269, 76-149 #becfc4,#0d1410, |7: 0-0 d,#152019, 1-3 d,#0d1410, 4-6 #59675c,#0d1410, 7-74 #e5eee5,#0d1410, 75-75 #e5eee5,#608269, 76-149 #e5eee5,#0d1410, |8: 0-0 d,#152019, 1-3 d,#0d1410, 4-6 #59675c,#0d1410, 7-74 #e5eee5,#0d1410, 75-75 #e5eee5,#608269, 76-149 #e5eee5,#0d1410, |9: 0-0 d,#152019, 1-3 d,#0d1410, 4-6 #59675c,#0d1410, 7-74 #e5eee5,#0d1410, 75-75 #e5eee5,#608269, 76-149 #e5eee5,#0d1410, @@ -37,7 +37,7 @@ |14: 0-0 d,#152019, 1-3 d,#0d1410, 4-6 #59675c,#0d1410, 7-74 #e5eee5,#0d1410, 75-75 #e5eee5,#608269, 76-149 #e5eee5,#0d1410, |15: 0-0 d,#152019, 1-3 d,#0d1410, 4-6 #59675c,#0d1410, 7-74 #e5eee5,#0d1410, 75-75 #e5eee5,#608269, 76-149 #e5eee5,#0d1410, |16: 0-0 d,#152019, 1-3 d,#0d1410, 4-6 #59675c,#0d1410, 7-74 #e5eee5,#0d1410, 75-75 #e5eee5,#608269, 76-149 #e5eee5,#0d1410, -|17: 0-1 d,#496656, 2-2 d,#1d2824, 3-33 #b2c3b8,#1d2824, 34-42 #d3b0d9,#1d2824, 43-74 #b2c3b8,#1d2824, 75-75 #b2c3b8,#608269, 76-149 #b2c3b8,#0d1410, +|17: 0-1 d,#496656, 2-32 #b2c3b8,#1d2824, 33-41 #d3b0d9,#1d2824, 42-74 #b2c3b8,#1d2824, 75-75 #b2c3b8,#608269, 76-149 #b2c3b8,#0d1410, |18: 0-0 d,#608269, 1-1 d,#0d1410, 2-74 #e5eee5,#0d1410, 75-75 #e5eee5,#608269, 76-149 #e5eee5,#0d1410, |19: 0-0 d,#608269, 1-1 d,#0d1410, 2-74 #e5eee5,#0d1410, 75-75 #e5eee5,#608269, 76-149 #e5eee5,#0d1410, |20: 0-0 d,#608269, 1-74 d,#0d1410, 75-75 d,#608269, 76-149 d,#0d1410, diff --git a/test/snapshots/lookloaded.golden b/test/snapshots/lookloaded.golden index a968a6dc..62028dc6 100644 --- a/test/snapshots/lookloaded.golden +++ b/test/snapshots/lookloaded.golden @@ -1,13 +1,13 @@ == snap file-open grid=100x31 cursor=14,13 -|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit -| New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol -| /tmp/pardes-snap/lookloaded/cwd Tty+bash Save M /tmp/pardes-snap/lookloaded/cwd Tty+bash Save M -| ode Filter Collapse Del ode Filter Collapse Del +| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +| New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol +| /tmp/pardes-snap/lookloaded/cwd Tty+bash Save Mo /tmp/pardes-snap/lookloaded/cwd Tty+bash Save Mo +| de Filter Collapse Del de Filter Collapse Del | ls ls | big.txt big.txt | -| /tmp/pardes-snap/lookloaded/cwd/big.txt Save Tt -| y Collapse Del +| /tmp/pardes-snap/lookloaded/cwd/big.txt Save Tty +| Collapse Del | 36 line 36 | 37 line 37 | 38 line 38 @@ -16,15 +16,15 @@ | 41 line 41 | 42 line 42 | 43 line 43 -| /tmp/pardes-snap/lookloaded/cwd Tty+bash Save M -| ode Filter Collapse Del +| /tmp/pardes-snap/lookloaded/cwd Tty+bash Save Mo +| de Filter Collapse Del | ls | big.txt == snap removed grid=100x31 cursor=54,8 |6: rm big.txt; echo GO''NE -|7: * /tmp/pardes-snap/lookloaded/cwd/big.txt Save Tt GONE +|7: */tmp/pardes-snap/lookloaded/cwd/big.txt Save Tty GONE == snap look-noFS grid=100x31 cursor=14,13 -|8: y Collapse Del big.txt:10 +|8: Collapse Del big.txt:10 |9: 6 line 6 |10: 7 line 7 |11: 8 line 8 diff --git a/test/snapshots/lookpanes.golden b/test/snapshots/lookpanes.golden index e0f55f5f..6689c710 100644 --- a/test/snapshots/lookpanes.golden +++ b/test/snapshots/lookpanes.golden @@ -1,48 +1,48 @@ == snap shells grid=130x51 cursor=122,4 -|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit -| New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol -| /tmp/pardes-snap/lookpanes/cwd/beta/bmark.txt Save Tty Collaps /tmp/pardes-snap/lookpanes/cwd Tty+bash Save Mode Filter Colla -| e Del pse Del +| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +| New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol +| /tmp/pardes-snap/lookpanes/cwd/beta/bmark.txt Save Tty Collapse /tmp/pardes-snap/lookpanes/cwd Tty+bash Save Mode Filter Collap +| Del se Del | 1 both.txt ls zqonly.txt pick.txt twin.txt | 2 b-marker alpha beta zzboot.txt | -| /tmp/pardes-snap/lookpanes/cwd/alpha Tty+bash Save Mode Filter -| Collapse Del +| /tmp/pardes-snap/lookpanes/cwd/alpha Tty+bash Save Mode Filter +| Collapse Del | ls | amark.txt both.txt pick.txt twin.txt zqonly.txt == snap other-dir grid=130x51 cursor=7,8 -|6: /tmp/pardes-snap/lookpanes/cwd/alpha/zqonly.txt Save Tty Colla -|7: pse Del /tmp/pardes-snap/lookpanes/cwd/alpha Tty+bash Save Mode Filter -|8: 1 ONLY-IN-ALPHA Collapse Del +|6: /tmp/pardes-snap/lookpanes/cwd/alpha/zqonly.txt Save Tty Collap +|7: se Del /tmp/pardes-snap/lookpanes/cwd/alpha Tty+bash Save Mode Filter +|8: 1 ONLY-IN-ALPHA Collapse Del == snap clicked-wins grid=130x51 cursor=7,12 -|10: /tmp/pardes-snap/lookpanes/cwd/beta/both.txt Save Tty Collapse amark.txt both.txt pick.txt twin.txt zqonly.txt -|11: Del +|10: /tmp/pardes-snap/lookpanes/cwd/beta/both.txt Save Tty Collapse amark.txt both.txt pick.txt twin.txt zqonly.txt +|11: Del |12: 1 BOTH-FROM-BETA == snap mru-alpha grid=130x51 cursor=72,14 -|12: 1 BOTH-FROM-BETA /tmp/pardes-snap/lookpanes/cwd/alpha/pick.txt Save Tty Collaps -|13: e Del +|12: 1 BOTH-FROM-BETA /tmp/pardes-snap/lookpanes/cwd/alpha/pick.txt Save Tty Collapse +|13: Del |14: 1 PICK-FROM-ALPHA == snap mru-beta grid=130x51 cursor=7,16 -|14: /tmp/pardes-snap/lookpanes/cwd/beta/twin.txt Save Tty Collapse 1 PICK-FROM-ALPHA -|15: Del +|14: /tmp/pardes-snap/lookpanes/cwd/beta/twin.txt Save Tty Collapse 1 PICK-FROM-ALPHA +|15: Del |16: 1 TWIN-FROM-BETA == style mru-beta grid=130x51 -|0: 0-129 #b2c3b8,#1d2824, -|1: 0-1 d,#887455, 2-2 d,#314738, 3-64 #becfc4,#314738, 65-66 #becfc4,#887455, 67-67 #becfc4,#1d2824, 68-129 #b2c3b8,#1d2824, -|2: 0-1 d,#496656, 2-2 d,#1d2824, 3-38 #b2c3b8,#1d2824, 39-48 #d3b0d9,#1d2824, 49-64 #b2c3b8,#1d2824, 65-66 #b2c3b8,#496656, 67-98 #b2c3b8,#1d2824, 99-107 #d3b0d9,#1d2824, 108-129 #b2c3b8,#1d2824, +|0: 0-1 d,#1d2824, 2-129 #b2c3b8,#1d2824, +|1: 0-1 d,#887455, 2-64 #becfc4,#314738, 65-66 #becfc4,#887455, 67-129 #b2c3b8,#1d2824, +|2: 0-1 d,#496656, 2-37 #b2c3b8,#1d2824, 38-47 #d3b0d9,#1d2824, 48-64 #b2c3b8,#1d2824, 65-66 #b2c3b8,#496656, 67-97 #b2c3b8,#1d2824, 98-106 #d3b0d9,#1d2824, 107-129 #b2c3b8,#1d2824, |3: 0-2 d,#1d2824, 3-129 #b2c3b8,#1d2824, |4: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-64 #e5eee5,#0d1410, 65-65 #e5eee5,#608269, 66-129 #e5eee5,#0d1410, |5: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-64 #e5eee5,#0d1410, 65-65 #e5eee5,#608269, 66-129 #e5eee5,#0d1410, -|6: 0-1 d,#496656, 2-2 d,#1d2824, 3-39 #b2c3b8,#1d2824, 40-50 #d3b0d9,#1d2824, 51-64 #b2c3b8,#1d2824, 65-65 #b2c3b8,#608269, 66-129 #b2c3b8,#0d1410, -|7: 0-2 d,#1d2824, 3-64 #b2c3b8,#1d2824, 65-66 #b2c3b8,#496656, 67-104 #b2c3b8,#1d2824, 105-113 #d3b0d9,#1d2824, 114-129 #b2c3b8,#1d2824, -|8: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-64 #e5eee5,#0d1410, 65-68 #e5eee5,#1d2824, 69-129 #b2c3b8,#1d2824, +|6: 0-1 d,#496656, 2-38 #b2c3b8,#1d2824, 39-49 #d3b0d9,#1d2824, 50-64 #b2c3b8,#1d2824, 65-65 #b2c3b8,#608269, 66-129 #b2c3b8,#0d1410, +|7: 0-1 d,#1d2824, 2-64 #b2c3b8,#1d2824, 65-66 #b2c3b8,#496656, 67-103 #b2c3b8,#1d2824, 104-112 #d3b0d9,#1d2824, 113-129 #b2c3b8,#1d2824, +|8: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-64 #e5eee5,#0d1410, 65-66 #e5eee5,#1d2824, 67-129 #b2c3b8,#1d2824, |9: 0-0 d,#608269, 1-64 d,#0d1410, 65-65 d,#608269, 66-66 d,#0d1410, 67-129 #e5eee5,#0d1410, -|10: 0-1 d,#496656, 2-2 d,#1d2824, 3-38 #b2c3b8,#1d2824, 39-47 #d3b0d9,#1d2824, 48-64 #b2c3b8,#1d2824, 65-65 #b2c3b8,#608269, 66-66 #b2c3b8,#0d1410, 67-129 #e5eee5,#0d1410, -|11: 0-3 d,#1d2824, 4-64 #b2c3b8,#1d2824, 65-65 #b2c3b8,#608269, 66-129 #b2c3b8,#0d1410, -|12: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-64 #e5eee5,#0d1410, 65-66 #e5eee5,#496656, 67-67 #e5eee5,#1d2824, 68-104 #b2c3b8,#1d2824, 105-113 #d3b0d9,#1d2824, 114-129 #b2c3b8,#1d2824, +|10: 0-1 d,#496656, 2-37 #b2c3b8,#1d2824, 38-46 #d3b0d9,#1d2824, 47-64 #b2c3b8,#1d2824, 65-65 #b2c3b8,#608269, 66-66 #b2c3b8,#0d1410, 67-129 #e5eee5,#0d1410, +|11: 0-1 d,#1d2824, 2-64 #b2c3b8,#1d2824, 65-65 #b2c3b8,#608269, 66-129 #b2c3b8,#0d1410, +|12: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-64 #e5eee5,#0d1410, 65-66 #e5eee5,#496656, 67-103 #b2c3b8,#1d2824, 104-112 #d3b0d9,#1d2824, 113-129 #b2c3b8,#1d2824, |13: 0-0 d,#608269, 1-64 d,#0d1410, 65-67 d,#1d2824, 68-129 #b2c3b8,#1d2824, -|14: 0-1 d,#add38a, 2-2 d,#314738, 3-38 #becfc4,#314738, 39-47 #dfbce5,#314738, 48-64 #becfc4,#314738, 65-65 #becfc4,#608269, 66-69 #becfc4,#0d1410, 70-71 #59675c,#0d1410, 72-129 #e5eee5,#0d1410, -|15: 0-3 d,#314738, 4-64 #becfc4,#314738, 65-65 #becfc4,#608269, 66-129 #becfc4,#0d1410, +|14: 0-1 d,#add38a, 2-37 #becfc4,#314738, 38-46 #dfbce5,#314738, 47-64 #becfc4,#314738, 65-65 #becfc4,#608269, 66-69 #becfc4,#0d1410, 70-71 #59675c,#0d1410, 72-129 #e5eee5,#0d1410, +|15: 0-1 d,#314738, 2-64 #becfc4,#314738, 65-65 #becfc4,#608269, 66-129 #becfc4,#0d1410, |16: 0-0 d,#608269, 1-1 d,#0d1410, 2-4 d,#0d1410,b 5-6 #616f64,#0d1410,b 7-64 #e5eee5,#0d1410, 65-65 #e5eee5,#608269, 66-129 #e5eee5,#0d1410, |17: 0-0 d,#608269, 1-64 d,#0d1410, 65-65 d,#608269, 66-129 d,#0d1410, |18: 0-0 d,#608269, 1-64 d,#0d1410, 65-65 d,#608269, 66-129 d,#0d1410, diff --git a/test/snapshots/lookrange.golden b/test/snapshots/lookrange.golden index f57ee457..4a286faa 100644 --- a/test/snapshots/lookrange.golden +++ b/test/snapshots/lookrange.golden @@ -1,13 +1,13 @@ == snap opened grid=150x31 cursor=7,3 -|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit -| New Tty Find Grep Joincol Delcol -| /tmp/pardes-snap/lookrange/cwd/look.txt Save Tty Collapse Del +| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +| New Tty Find Grep Joincol Delcol +| /tmp/pardes-snap/lookrange/cwd/look.txt Save Tty Collapse Del | 1 r.txt:3-5 | 2 r.txt:7:4-9 | 3 r.txt:3:2-5:3 | 4 r.txt:8:6-99:9 == snap wholelines grid=150x31 cursor=11,12 -|7: /tmp/pardes-snap/lookrange/cwd/r.txt Save Tty Collapse Del +|7: /tmp/pardes-snap/lookrange/cwd/r.txt Save Tty Collapse Del |8: 1 aaaa |9: 2 bbbb |10: 3 cccc dccc @@ -18,14 +18,14 @@ |15: 8 hhhh NEEDLE |16: 9 iiii == style wholelines grid=150x31 -|0: 0-149 #b2c3b8,#1d2824, -|1: 0-1 d,#887455, 2-2 d,#314738, 3-149 #becfc4,#314738, -|2: 0-1 d,#496656, 2-2 d,#1d2824, 3-33 #b2c3b8,#1d2824, 34-42 #d3b0d9,#1d2824, 43-149 #b2c3b8,#1d2824, +|0: 0-1 d,#1d2824, 2-149 #b2c3b8,#1d2824, +|1: 0-1 d,#887455, 2-149 #becfc4,#314738, +|2: 0-1 d,#496656, 2-32 #b2c3b8,#1d2824, 33-41 #d3b0d9,#1d2824, 42-149 #b2c3b8,#1d2824, |3: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-149 #e5eee5,#0d1410, |4: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-149 #e5eee5,#0d1410, |5: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-149 #e5eee5,#0d1410, |6: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-149 #e5eee5,#0d1410, -|7: 0-1 d,#add38a, 2-2 d,#314738, 3-33 #becfc4,#314738, 34-39 #dfbce5,#314738, 40-149 #becfc4,#314738, +|7: 0-1 d,#add38a, 2-32 #becfc4,#314738, 33-38 #dfbce5,#314738, 39-149 #becfc4,#314738, |8: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-149 #e5eee5,#0d1410, |9: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-149 #e5eee5,#0d1410, |10: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-149 #f5f7ee,#3c614a, @@ -69,7 +69,7 @@ |15: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-11 #e5eee5,#0d1410, 12-149 #f5f7ee,#3c614a, |16: 0-0 d,#608269, 1-1 d,#0d1410, 2-4 d,#0d1410,b 5-6 #616f64,#0d1410,b 7-10 #f5f7ee,#3c614a, 11-149 #f5f7ee,#0d1410, == snap hit1 grid=150x31 cursor=15,14 -|17: /tmp/pardes-snap/lookrange/cwd/+Search Save Tty Collapse Del LocationsConfig +|17: /tmp/pardes-snap/lookrange/cwd/+Search Save Tty Collapse LocationsConfig Del |18: 1 r.txt:7:4-9 |19: 2 gg NEEDLE gg |20: 3 r.txt:8:6-11 @@ -79,7 +79,7 @@ |14: 0-0 d,#608269, 1-1 d,#0d1410, 2-4 d,#0d1410,b 5-6 #616f64,#0d1410,b 7-9 #e5eee5,#0d1410, 10-15 #f5f7ee,#3c614a, 16-16 #f5f7ee,#0d1410, 17-149 #e5eee5,#0d1410, |15: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-149 #e5eee5,#0d1410, |16: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-149 #e5eee5,#0d1410, -|17: 0-1 d,#496656, 2-2 d,#1d2824, 3-33 #b2c3b8,#1d2824, 34-41 #d3b0d9,#1d2824, 42-149 #b2c3b8,#1d2824, +|17: 0-1 d,#496656, 2-32 #b2c3b8,#1d2824, 33-40 #d3b0d9,#1d2824, 41-149 #b2c3b8,#1d2824, |18: 0-0 d,#608269, 1-4 d,#0d1410, 5-149 #59675c,#0d1410, |19: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-9 #e5eee5,#0d1410, 10-15 #f7e4a5,#5e4923, 16-16 #f7e4a5,#0d1410, 17-149 #e5eee5,#0d1410, |20: 0-0 d,#608269, 1-4 d,#0d1410, 5-149 #59675c,#0d1410, diff --git a/test/snapshots/lsp-client-edit.golden b/test/snapshots/lsp-client-edit.golden index c9d93379..b4a16b22 100644 --- a/test/snapshots/lsp-client-edit.golden +++ b/test/snapshots/lsp-client-edit.golden @@ -1,7 +1,7 @@ == snap formatted grid=100x25 cursor=7,4 -|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit -| New Tty Find Grep Joincol Delcol -| * /tmp/pardes-snap/lsp-client-edit/cwd/main.rs Save Tty Collapse Del TreeContext Def Refs +| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +| New Tty Find Grep Joincol Delcol +| */tmp/pardes-snap/lsp-client-edit/cwd/main.rs Save Tty Collapse TreeContext Def Refs Del | 1 // formatted by mock formatted 1 range(s) | 2 mod lib; | 3 @@ -12,7 +12,7 @@ | 8 } | 9 == snap unformatted grid=100x25 cursor=7,3 -|2: /tmp/pardes-snap/lsp-client-edit/cwd/main.rs Save Tty Collapse Del TreeContext Def Refs +|2: /tmp/pardes-snap/lsp-client-edit/cwd/main.rs Save Tty Collapse TreeContext Def Refs Del |3: 1 mod lib; |4: 2 |5: 3 fn main() { @@ -23,12 +23,12 @@ |10: 8 |11: == snap renamed grid=100x25 cursor=12,5 -|2: * /tmp/pardes-snap/lsp-client-edit/cwd/main.rs Save Tty Collapse Del TreeContext Def Refs +|2: */tmp/pardes-snap/lsp-client-edit/cwd/main.rs Save Tty Collapse TreeContext Def Refs Del |3: 1 mod lib; renamed 2 range(s) |6: 4 let x = sum(1, 2); |7: 5 let y = sum(3, 4); == snap unrenamed grid=100x25 cursor=12,5 -|2: /tmp/pardes-snap/lsp-client-edit/cwd/main.rs Save Tty Collapse Del TreeContext Def Refs +|2: /tmp/pardes-snap/lsp-client-edit/cwd/main.rs Save Tty Collapse TreeContext Def Refs Del |3: 1 mod lib; |6: 4 let x = add(1, 2); |7: 5 let y = add(3, 4); diff --git a/test/snapshots/lsp-client.golden b/test/snapshots/lsp-client.golden index 13771394..c9fad7b7 100644 --- a/test/snapshots/lsp-client.golden +++ b/test/snapshots/lsp-client.golden @@ -1,7 +1,7 @@ == snap gd-jumped grid=100x25 cursor=16,12 -|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit -| New Tty Find Grep Joincol Delcol -| /tmp/pardes-snap/lsp-client/cwd/main.rs Save Tty Collapse Del TreeContext Def Refs +| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +| New Tty Find Grep Joincol Delcol +| /tmp/pardes-snap/lsp-client/cwd/main.rs Save Tty Collapse TreeContext Def Refs Del | 1 mod lib; --:--:-- lsp rust-analyzer: ready | 2 | 3 fn main() { @@ -9,7 +9,7 @@ | 5 let y = add(3, 4); | 6 let _ = x + y; | 7 } -| /tmp/pardes-snap/lsp-client/cwd/lib.rs Save Tty Collapse Del TreeContext Def Refs +| /tmp/pardes-snap/lsp-client/cwd/lib.rs Save Tty Collapse TreeContext Def Refs Del | 1 // mock fixture | 2 pub fn add(a: i32, b: i32) -> i32 { | 3 a + b @@ -17,7 +17,7 @@ | 5 == snap gr-list grid=100x25 cursor=21,6 |3: 1 mod lib; -|15: /tmp/pardes-snap/lsp-client/cwd/+Search Save Tty Collapse Del LocationsConfig +|15: /tmp/pardes-snap/lsp-client/cwd/+Search Save Tty Collapse LocationsConfig Del |16: 1 lib.rs:2:8-10 |17: 2 pub fn add(a: i32, b: i32) -> i32 { |18: 3 main.rs:4:13-15 diff --git a/test/snapshots/lsp-rename-files.golden b/test/snapshots/lsp-rename-files.golden index 4f71424e..1d239d34 100644 --- a/test/snapshots/lsp-rename-files.golden +++ b/test/snapshots/lsp-rename-files.golden @@ -1,12 +1,12 @@ == snap opened grid=100x25 cursor=7,8 -|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit -| New Tty Find Grep Joincol Delcol -| /tmp/pardes-snap/lsp-rename-files/cwd/lib.rs Save Tty Collapse Del TreeContext Def Refs +| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +| New Tty Find Grep Joincol Delcol +| /tmp/pardes-snap/lsp-rename-files/cwd/lib.rs Save Tty Collapse TreeContext Def Refs Del | 1 // main.rs | 2 pub fn add(a: i32, b: i32) -> i32 { | 3 a + b | 4 } -| /tmp/pardes-snap/lsp-rename-files/cwd/main.rs Save Tty Collapse Del TreeContext Def Refs +| /tmp/pardes-snap/lsp-rename-files/cwd/main.rs Save Tty Collapse TreeContext Def Refs Del | 1 mod lib; | 2 | 3 fn main() { @@ -17,7 +17,7 @@ | 8 == snap previewed grid=100x25 cursor=14,4 |3: 1 // main.rs Rename: 3 edit(s) across files, previewed, not applied -|15: /tmp/pardes-snap/lsp-rename-files/cwd/+Search Save Tty Collapse Del LocationsConfig +|15: /tmp/pardes-snap/lsp-rename-files/cwd/+Search Save Tty Collapse LocationsConfig Del |16: 1 lib.rs:2:8-10 |17: 2 sum |18: 3 main.rs:4:13-15 diff --git a/test/snapshots/lsp-rename.golden b/test/snapshots/lsp-rename.golden index 6b85822c..f5dc718d 100644 --- a/test/snapshots/lsp-rename.golden +++ b/test/snapshots/lsp-rename.golden @@ -1,7 +1,7 @@ == snap renamed grid=110x25 cursor=17,10 -|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit -| New Tty Find Grep Joincol Delcol -| * /tmp/pardes-snap/lsp-rename/cwd/rename.zig Save Tty Collapse Del TreeContext Def Refs +| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +| New Tty Find Grep Joincol Delcol +| */tmp/pardes-snap/lsp-rename/cwd/rename.zig Save Tty Collapse TreeContext Def Refs Del | 1 const std = @import("std"); renamed 2 range(s) | 2 | 3 fn renamed_helper(x: u32) u32 { @@ -18,11 +18,11 @@ | 14 } | 15 == snap undone grid=110x25 cursor=17,10 -|2: /tmp/pardes-snap/lsp-rename/cwd/rename.zig Save Tty Collapse Del TreeContext Def Refs +|2: /tmp/pardes-snap/lsp-rename/cwd/rename.zig Save Tty Collapse TreeContext Def Refs Del |3: 1 const std = @import("std"); |5: 3 fn helper(x: u32) u32 { |10: 8 _ = helper(41); == snap redone grid=110x25 cursor=17,10 -|2: * /tmp/pardes-snap/lsp-rename/cwd/rename.zig Save Tty Collapse Del TreeContext Def Refs +|2: */tmp/pardes-snap/lsp-rename/cwd/rename.zig Save Tty Collapse TreeContext Def Refs Del |5: 3 fn renamed_helper(x: u32) u32 { |10: 8 _ = renamed_helper(41); diff --git a/test/snapshots/lsp.golden b/test/snapshots/lsp.golden index 2225de00..de52523c 100644 --- a/test/snapshots/lsp.golden +++ b/test/snapshots/lsp.golden @@ -1,7 +1,7 @@ == snap opened grid=120x41 cursor=7,3 -|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit -| New Tty Find Grep Joincol Delcol -| /tmp/pardes-snap/lsp/cwd/a.zig Save Tty Collapse Del TreeContext Def Refs +| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +| New Tty Find Grep Joincol Delcol +| /tmp/pardes-snap/lsp/cwd/a.zig Save Tty Collapse TreeContext Def Refs Del | 1 const std = @import("std"); | 2 | 3 fn helper(x: u32) u32 { @@ -17,13 +17,13 @@ |3: 1 const std = @import("std"); --:--:-- lsp zls ready — /tmp/pardes-snap/lsp/cwd == snap hover grid=120x41 cursor=15,5 |3: 1 const std = @import("std"); Hover -|12: /tmp/pardes-snap/lsp/cwd/+Hover Save Tty Collapse Del +|12: /tmp/pardes-snap/lsp/cwd/+Hover Save Tty Collapse Del |13: 1 fn helper(x: u32) u32 |14: 2 (fn (u32) u32) |15: 3 == snap symbols grid=120x41 cursor=15,5 |3: 1 const std = @import("std"); Symbols -|15: /tmp/pardes-snap/lsp/cwd/+Search Save Tty Collapse Del LocationsConfig +|15: /tmp/pardes-snap/lsp/cwd/+Search Save Tty Collapse LocationsConfig Del |16: 1 a.zig:1:7-9 |17: 2 std |18: 3 a.zig:3:4-9 diff --git a/test/snapshots/lspcomplete.golden b/test/snapshots/lspcomplete.golden index 85c26e30..dd1e5c7e 100644 --- a/test/snapshots/lspcomplete.golden +++ b/test/snapshots/lspcomplete.golden @@ -1,7 +1,7 @@ == snap opened grid=120x41 cursor=7,3 -|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit -| New Tty Find Grep Joincol Delcol -| /tmp/pardes-snap/lspcomplete/cwd/a.zig Save Tty Collapse Del TreeContext Def Refs +| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +| New Tty Find Grep Joincol Delcol +| /tmp/pardes-snap/lspcomplete/cwd/a.zig Save Tty Collapse TreeContext Def Refs Del | 1 const Shade = enum { | 2 verdigris, | 3 cinnabar, @@ -16,7 +16,7 @@ | 12 // note. see below | 13 == snap indent grid=120x41 cursor=11,12 -|2: ^* /tmp/pardes-snap/lspcomplete/cwd/a.zig Save Tty Collapse Del TreeContext Def Refs +|2: ^*/tmp/pardes-snap/lspcomplete/cwd/a.zig Save Tty Collapse TreeContext Def Refs Del |12: 10 } == snap commentindent grid=120x41 cursor=19,14 |3: 1 const Shade = enum { --:--:-- lsp zls ready — /tmp/pardes-snap/lspcomplete/cwd @@ -25,23 +25,23 @@ |3: 1 const Shade = enum { |10: 8 . == snap completion grid=120x41 cursor=16,10 -|15: /tmp/pardes-snap/lspcomplete/cwd/+Search Save Tty Collapse Del +|15: /tmp/pardes-snap/lspcomplete/cwd/+Search Save Tty Collapse Del |16: 1 a.zig:8:10 verdigris |17: 2 a.zig:8:10 cinnabar |18: 3 == snap refill grid=120x41 cursor=16,10 == snap step grid=120x41 cursor=16,10 -|2: * /tmp/pardes-snap/lspcomplete/cwd/a.zig Save Tty Collapse Del TreeContext Def Refs +|2: */tmp/pardes-snap/lspcomplete/cwd/a.zig Save Tty Collapse TreeContext Def Refs Del == snap txtindent grid=120x41 cursor=15,3 -|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit -| New Tty Find Grep Joincol Delcol -|^* /tmp/pardes-snap/lspcomplete/cwd/notes.txt Save Tty Collapse Del +| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +| New Tty Find Grep Joincol Delcol +|^*/tmp/pardes-snap/lspcomplete/cwd/notes.txt Save Tty Collapse Del | 1 abc. def ghi | 2 == snap nosemi grid=100x19 cursor=29,9 -|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit -| New Tty Find Grep Joincol Delcol -|^* /tmp/pardes-snap/lspcomplete/cwd/c.zig Save Tty Collapse Del TreeContext Def Refs +| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +| New Tty Find Grep Joincol Delcol +|^*/tmp/pardes-snap/lspcomplete/cwd/c.zig Save Tty Collapse TreeContext Def Refs Del | 1 const Shade = enum { --:--:-- lsp zls ready — /tmp/pardes-snap/lspcomplete/cwd | 2 verdigris, | 3 cinnabar, @@ -50,14 +50,14 @@ | 6 pub fn nosemi() void { | 7 const z: Shade = . | 8 } -| /tmp/pardes-snap/lspcomplete/cwd/+Search Save Tty Collapse Del +| /tmp/pardes-snap/lspcomplete/cwd/+Search Save Tty Collapse Del | 1 c.zig:7:23 verdigris Shade | 2 c.zig:7:23 cinnabar Shade | 3 == snap nobrace grid=100x19 cursor=16,10 -|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit -| New Tty Find Grep Joincol Delcol -|^* /tmp/pardes-snap/lspcomplete/cwd/d.zig Save Tty Collapse Del TreeContext Def Refs +| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +| New Tty Find Grep Joincol Delcol +|^*/tmp/pardes-snap/lspcomplete/cwd/d.zig Save Tty Collapse TreeContext Def Refs Del | 1 const Shade = enum { --:--:-- lsp zls ready — /tmp/pardes-snap/lspcomplete/cwd | 2 verdigris, | 3 cinnabar, @@ -65,7 +65,7 @@ | 5 | 6 pub fn nobrace(s: Shade) void { | 7 switch (s) { -| /tmp/pardes-snap/lspcomplete/cwd/+Search Save Tty Collapse Del +| /tmp/pardes-snap/lspcomplete/cwd/+Search Save Tty Collapse Del | 1 d.zig:8:10 verdigris | 2 d.zig:8:10 cinnabar | 3 diff --git a/test/snapshots/lspcompletemoved.golden b/test/snapshots/lspcompletemoved.golden index 403c6931..7b3ed250 100644 --- a/test/snapshots/lspcompletemoved.golden +++ b/test/snapshots/lspcompletemoved.golden @@ -1,7 +1,7 @@ == snap typedthrough grid=120x21 cursor=16,14 -|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit -| New Tty Find Grep Joincol Delcol -|^* /tmp/pardes-snap/lspcompletemoved/cwd/a.zig Save Tty Collapse Del TreeContext Def Refs +| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +| New Tty Find Grep Joincol Delcol +|^*/tmp/pardes-snap/lspcompletemoved/cwd/a.zig Save Tty Collapse TreeContext Def Refs Del | 1 const Shade = enum { --:--:-- lsp zls ready — /tmp/pardes-snap/lspcompletemoved/cwd | 2 verdigris, | 3 cinnabar, diff --git a/test/snapshots/lspdebug.golden b/test/snapshots/lspdebug.golden index 4beda019..5c415033 100644 --- a/test/snapshots/lspdebug.golden +++ b/test/snapshots/lspdebug.golden @@ -1,7 +1,7 @@ == snap opened grid=120x45 cursor=7,3 -|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit -| New Tty Find Grep Joincol Delcol -| /tmp/pardes-snap/lspdebug/cwd/z.zig Save Tty Collapse Del TreeContext Def Refs +| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +| New Tty Find Grep Joincol Delcol +| /tmp/pardes-snap/lspdebug/cwd/z.zig Save Tty Collapse TreeContext Def Refs Del | 1 const std = @import("std"); | 2 | 3 fn helper() u32 { diff --git a/test/snapshots/lsprelpath.golden b/test/snapshots/lsprelpath.golden index a3760316..d961d6bd 100644 --- a/test/snapshots/lsprelpath.golden +++ b/test/snapshots/lsprelpath.golden @@ -1,7 +1,7 @@ == snap absrow grid=100x35 cursor=21,16 -|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit -| New Tty Find Grep Joincol Delcol -| /tmp/pardes-snap/lsprelpath/cwd/sub/parent.zig Save Tty Collapse Del TreeContext Def Refs +| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +| New Tty Find Grep Joincol Delcol +| /tmp/pardes-snap/lsprelpath/cwd/sub/parent.zig Save Tty Collapse TreeContext Def Refs Del | 1 const shade = @import("../shad --:--:-- lsp zls ready — /tmp/pardes-snap/lsprelpath/cwd/sub | 2 | 3 pub fn pick(s: shade.Shade) u8 { @@ -9,12 +9,12 @@ | 5 | 6 }; | 7 } -| /tmp/pardes-snap/lsprelpath/cwd/sub/+Search Save Tty Collapse Del LocationsConfig +| /tmp/pardes-snap/lsprelpath/cwd/sub/+Search Save Tty Collapse LocationsConfig Del | 1 /tmp/pardes-snap/lsprelpath/cwd/shade.zig:1:11-15 | 2 pub const Shade = enum { | 3 parent.zig:3:22-26 | 4 pub fn pick(s: shade.Shade) u8 { -| /tmp/pardes-snap/lsprelpath/cwd/shade.zig Save Tty Collapse Del TreeContext Def Refs +| /tmp/pardes-snap/lsprelpath/cwd/shade.zig Save Tty Collapse TreeContext Def Refs Del | 1 pub const Shade = enum { | 2 verdigris, | 3 cinnabar, @@ -23,9 +23,9 @@ == snap abslook grid=100x35 cursor=32,5 |3: 1 const shade = @import("../shade.zig"); == style abslook grid=100x35 -|0: 0-99 #b2c3b8,#1d2824, -|1: 0-1 d,#887455, 2-2 d,#314738, 3-99 #becfc4,#314738, -|2: 0-1 d,#add38a, 2-2 d,#314738, 3-38 #becfc4,#314738, 39-49 #dfbce5,#314738, 50-99 #becfc4,#314738, +|0: 0-1 d,#1d2824, 2-99 #b2c3b8,#1d2824, +|1: 0-1 d,#887455, 2-99 #becfc4,#314738, +|2: 0-1 d,#add38a, 2-37 #becfc4,#314738, 38-48 #dfbce5,#314738, 49-99 #becfc4,#314738, |3: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-20 #e5eee5,#0d1410, 21-27 #c9a7ed,#0d1410, 28-28 #e5eee5,#0d1410, 29-42 #b8d88a,#0d1410, 43-99 #e5eee5,#0d1410, |4: 0-0 d,#608269, 1-4 d,#0d1410, 5-99 #59675c,#0d1410, |5: 0-0 d,#608269, 1-1 d,#0d1410, 2-4 d,#0d1410,b 5-6 #616f64,#0d1410,b 7-10 #e5eee5,#0d1410, 11-13 #c9a7ed,#0d1410, 14-27 #e5eee5,#0d1410, 28-32 #f5f7ee,#3c614a, 33-99 #e5eee5,#0d1410, @@ -33,12 +33,12 @@ |7: 0-0 d,#608269, 1-4 d,#0d1410, 5-99 #59675c,#0d1410, |8: 0-0 d,#608269, 1-4 d,#0d1410, 5-10 #59675c,#0d1410, 11-99 #e5eee5,#0d1410, |9: 0-0 d,#152019, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-99 #e5eee5,#0d1410, -|10: 0-1 d,#496656, 2-2 d,#1d2824, 3-38 #b2c3b8,#1d2824, 39-46 #d3b0d9,#1d2824, 47-99 #b2c3b8,#1d2824, +|10: 0-1 d,#496656, 2-37 #b2c3b8,#1d2824, 38-45 #d3b0d9,#1d2824, 46-99 #b2c3b8,#1d2824, |11: 0-0 d,#608269, 1-4 d,#0d1410, 5-99 #59675c,#0d1410, |12: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-16 #e5eee5,#0d1410, 17-21 #f7e4a5,#5e4923, 22-22 #f7e4a5,#0d1410, 23-24 #e5eee5,#0d1410, 25-29 #c9a7ed,#0d1410, 30-99 #e5eee5,#0d1410, |13: 0-0 d,#608269, 1-4 d,#0d1410, 5-99 #59675c,#0d1410, |14: 0-0 d,#152019, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-10 #e5eee5,#0d1410, 11-13 #c9a7ed,#0d1410, 14-27 #e5eee5,#0d1410, 28-32 #f7e4a5,#5e4923, 33-99 #e5eee5,#0d1410, -|15: 0-1 d,#496656, 2-2 d,#1d2824, 3-34 #b2c3b8,#1d2824, 35-44 #d3b0d9,#1d2824, 45-99 #b2c3b8,#1d2824, +|15: 0-1 d,#496656, 2-33 #b2c3b8,#1d2824, 34-43 #d3b0d9,#1d2824, 44-99 #b2c3b8,#1d2824, |16: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-16 #e5eee5,#0d1410, 17-21 #f5f7ee,#3c614a, 22-22 #f5f7ee,#0d1410, 23-24 #e5eee5,#0d1410, 25-29 #c9a7ed,#0d1410, 30-99 #e5eee5,#0d1410, |17: 0-0 d,#608269, 1-4 d,#0d1410, 5-10 #59675c,#0d1410, 11-99 #e5eee5,#0d1410, |18: 0-0 d,#608269, 1-4 d,#0d1410, 5-10 #59675c,#0d1410, 11-99 #e5eee5,#0d1410, @@ -59,9 +59,9 @@ |33: 0-0 d,#608269, 1-99 d,#0d1410, |34: 0-0 d,#608269, 1-99 d,#0d1410, == snap subrow grid=100x35 cursor=20,16 -|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit -| New Tty Find Grep Joincol Delcol -| /tmp/pardes-snap/lsprelpath/cwd/sub/subdir.zig Save Tty Collapse Del TreeContext Def Refs +| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +| New Tty Find Grep Joincol Delcol +| /tmp/pardes-snap/lsprelpath/cwd/sub/subdir.zig Save Tty Collapse TreeContext Def Refs Del | 1 const tint = @import("inner/ti --:--:-- lsp zls ready — /tmp/pardes-snap/lsprelpath/cwd/sub | 2 | 3 pub fn hue(t: tint.Tint) u8 { @@ -69,12 +69,12 @@ | 5 | 6 }; | 7 } -| /tmp/pardes-snap/lsprelpath/cwd/sub/+Search Save Tty Collapse Del LocationsConfig +| /tmp/pardes-snap/lsprelpath/cwd/sub/+Search Save Tty Collapse LocationsConfig Del | 1 inner/tint.zig:1:11-14 | 2 pub const Tint = enum { | 3 subdir.zig:3:20-23 | 4 pub fn hue(t: tint.Tint) u8 { -| /tmp/pardes-snap/lsprelpath/cwd/sub/inner/tint.zig Save Tty Collapse Del TreeContext Def Refs +| /tmp/pardes-snap/lsprelpath/cwd/sub/inner/tint.zig Save Tty Collapse TreeContext Def Refs Del | 1 pub const Tint = enum { | 2 ochre, | 3 indigo, @@ -83,9 +83,9 @@ == snap sublook grid=100x35 cursor=29,5 |3: 1 const tint = @import("inner/tint.zig"); == style sublook grid=100x35 -|0: 0-99 #b2c3b8,#1d2824, -|1: 0-1 d,#887455, 2-2 d,#314738, 3-99 #becfc4,#314738, -|2: 0-1 d,#add38a, 2-2 d,#314738, 3-38 #becfc4,#314738, 39-49 #dfbce5,#314738, 50-99 #becfc4,#314738, +|0: 0-1 d,#1d2824, 2-99 #b2c3b8,#1d2824, +|1: 0-1 d,#887455, 2-99 #becfc4,#314738, +|2: 0-1 d,#add38a, 2-37 #becfc4,#314738, 38-48 #dfbce5,#314738, 49-99 #becfc4,#314738, |3: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-19 #e5eee5,#0d1410, 20-26 #c9a7ed,#0d1410, 27-27 #e5eee5,#0d1410, 28-43 #b8d88a,#0d1410, 44-99 #e5eee5,#0d1410, |4: 0-0 d,#608269, 1-4 d,#0d1410, 5-99 #59675c,#0d1410, |5: 0-0 d,#608269, 1-1 d,#0d1410, 2-4 d,#0d1410,b 5-6 #616f64,#0d1410,b 7-10 #e5eee5,#0d1410, 11-13 #c9a7ed,#0d1410, 14-25 #e5eee5,#0d1410, 26-29 #f5f7ee,#3c614a, 30-99 #e5eee5,#0d1410, @@ -93,12 +93,12 @@ |7: 0-0 d,#608269, 1-4 d,#0d1410, 5-99 #59675c,#0d1410, |8: 0-0 d,#608269, 1-4 d,#0d1410, 5-10 #59675c,#0d1410, 11-99 #e5eee5,#0d1410, |9: 0-0 d,#152019, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-99 #e5eee5,#0d1410, -|10: 0-1 d,#496656, 2-2 d,#1d2824, 3-38 #b2c3b8,#1d2824, 39-46 #d3b0d9,#1d2824, 47-99 #b2c3b8,#1d2824, +|10: 0-1 d,#496656, 2-37 #b2c3b8,#1d2824, 38-45 #d3b0d9,#1d2824, 46-99 #b2c3b8,#1d2824, |11: 0-0 d,#608269, 1-4 d,#0d1410, 5-99 #59675c,#0d1410, |12: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-16 #e5eee5,#0d1410, 17-20 #f7e4a5,#5e4923, 21-21 #f7e4a5,#0d1410, 22-23 #e5eee5,#0d1410, 24-28 #c9a7ed,#0d1410, 29-99 #e5eee5,#0d1410, |13: 0-0 d,#608269, 1-4 d,#0d1410, 5-99 #59675c,#0d1410, |14: 0-0 d,#152019, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-10 #e5eee5,#0d1410, 11-13 #c9a7ed,#0d1410, 14-25 #e5eee5,#0d1410, 26-29 #f7e4a5,#5e4923, 30-99 #e5eee5,#0d1410, -|15: 0-1 d,#496656, 2-2 d,#1d2824, 3-44 #b2c3b8,#1d2824, 45-53 #d3b0d9,#1d2824, 54-99 #b2c3b8,#1d2824, +|15: 0-1 d,#496656, 2-43 #b2c3b8,#1d2824, 44-52 #d3b0d9,#1d2824, 53-99 #b2c3b8,#1d2824, |16: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-16 #e5eee5,#0d1410, 17-20 #f5f7ee,#3c614a, 21-21 #f5f7ee,#0d1410, 22-23 #e5eee5,#0d1410, 24-28 #c9a7ed,#0d1410, 29-99 #e5eee5,#0d1410, |17: 0-0 d,#608269, 1-4 d,#0d1410, 5-10 #59675c,#0d1410, 11-99 #e5eee5,#0d1410, |18: 0-0 d,#608269, 1-4 d,#0d1410, 5-10 #59675c,#0d1410, 11-99 #e5eee5,#0d1410, diff --git a/test/snapshots/markup.golden b/test/snapshots/markup.golden index 6991cdf6..0d086770 100644 --- a/test/snapshots/markup.golden +++ b/test/snapshots/markup.golden @@ -1,7 +1,7 @@ == snap typst grid=92x25 cursor=7,3 -|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit -| New Tty Find Grep Joincol Delcol -| /tmp/pardes-snap/markup/cwd/paper.typ Save Tty Collapse Del TreeContext +| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +| New Tty Find Grep Joincol Delcol +| /tmp/pardes-snap/markup/cwd/paper.typ Save Tty Collapse TreeContext Del | 1 = Typst heading | 2 | 3 Prose with *bold* and _italic_ words, a `raw` span, @@ -12,9 +12,9 @@ | 8 ``` | 9 == style typst grid=92x25 -|0: 0-91 #b2c3b8,#1d2824, -|1: 0-1 d,#887455, 2-2 d,#314738, 3-91 #becfc4,#314738, -|2: 0-1 d,#add38a, 2-2 d,#314738, 3-30 #becfc4,#314738, 31-40 #dfbce5,#314738, 41-91 #becfc4,#314738, +|0: 0-1 d,#1d2824, 2-91 #b2c3b8,#1d2824, +|1: 0-1 d,#887455, 2-91 #becfc4,#314738, +|2: 0-1 d,#add38a, 2-29 #becfc4,#314738, 30-39 #dfbce5,#314738, 40-91 #becfc4,#314738, |3: 0-0 d,#608269, 1-1 d,#0d1410, 2-4 d,#0d1410,b 5-6 #616f64,#0d1410,b 7-91 #c9a7ed,#0d1410, |4: 0-0 d,#608269, 1-4 d,#0d1410, 5-91 #59675c,#0d1410, |5: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-17 #e5eee5,#0d1410, 18-24 #b9f480,#0d1410, 25-28 #e5eee5,#0d1410, 29-37 #f8c082,#0d1410, 38-46 #e5eee5,#0d1410, 47-52 #b8d88a,#0d1410, 53-91 #e5eee5,#0d1410, @@ -38,9 +38,9 @@ |23: 0-0 d,#608269, 1-91 d,#0d1410, |24: 0-0 d,#608269, 1-91 d,#0d1410, == snap markdown grid=92x25 cursor=7,3 -|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit -| New Tty Find Grep Joincol Delcol -| /tmp/pardes-snap/markup/cwd/notes.md Save Tty Collapse Del TreeContext +| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +| New Tty Find Grep Joincol Delcol +| /tmp/pardes-snap/markup/cwd/notes.md Save Tty Collapse TreeContext Del | 1 # Markdown heading with *italic* | 2 | 3 Prose with **bold**, *italic* and an `inline` span. @@ -50,9 +50,9 @@ | 7 ``` | 8 == style markdown grid=92x25 -|0: 0-91 #b2c3b8,#1d2824, -|1: 0-1 d,#887455, 2-2 d,#314738, 3-91 #becfc4,#314738, -|2: 0-1 d,#add38a, 2-2 d,#314738, 3-30 #becfc4,#314738, 31-39 #dfbce5,#314738, 40-91 #becfc4,#314738, +|0: 0-1 d,#1d2824, 2-91 #b2c3b8,#1d2824, +|1: 0-1 d,#887455, 2-91 #becfc4,#314738, +|2: 0-1 d,#add38a, 2-29 #becfc4,#314738, 30-38 #dfbce5,#314738, 39-91 #becfc4,#314738, |3: 0-0 d,#608269, 1-1 d,#0d1410, 2-4 d,#0d1410,b 5-6 #616f64,#0d1410,b 7-8 #e5eee5,#0d1410, 9-30 #c9a7ed,#0d1410, 31-91 #f8c082,#0d1410, |4: 0-0 d,#608269, 1-4 d,#0d1410, 5-91 #59675c,#0d1410, |5: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-17 #e5eee5,#0d1410, 18-25 #b9f480,#0d1410, 26-27 #e5eee5,#0d1410, 28-36 #f8c082,#0d1410, 37-43 #e5eee5,#0d1410, 44-52 #b8d88a,#0d1410, 53-91 #e5eee5,#0d1410, diff --git a/test/snapshots/mini.golden b/test/snapshots/mini.golden index 8d0205f7..cba3c6d0 100644 --- a/test/snapshots/mini.golden +++ b/test/snapshots/mini.golden @@ -1,21 +1,21 @@ == snap opened grid=90x23 cursor=7,6 -|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit -| New Tty Find Grep Joincol Delcol -| /tmp/pardes-snap/mini/cwd/commands.txt Save Tty Collapse Del +| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +| New Tty Find Grep Joincol Delcol +| /tmp/pardes-snap/mini/cwd/commands.txt Save Tty Collapse Del | 1 @`Mini demo.zig` Mini | -| /tmp/pardes-snap/mini/cwd/Mini demo.zig Save Tty Collapse Del +| /tmp/pardes-snap/mini/cwd/Mini demo.zig Save Tty Collapse Del | 1 ⠭⠍⣥⢩⣭⡭⣭⣬⣌⢭⣭⠌⠬⠅⠍⠁ | 2 ⣂⢀⣉⣉⢉⣈⢁⣀⣀⢀⣀⣀⣀⢀⣀⣀⣀⣀⣀ | 3 ⠉⠉⠁⠉⠉⠉⠈⠈⠉⠉⠉⠉⠉⠉ | 4 == style opened grid=90x23 -|0: 0-89 #b2c3b8,#1d2824, -|1: 0-1 d,#887455, 2-2 d,#314738, 3-89 #becfc4,#314738, -|2: 0-1 d,#496656, 2-2 d,#1d2824, 3-28 #b2c3b8,#1d2824, 29-41 #d3b0d9,#1d2824, 42-89 #b2c3b8,#1d2824, +|0: 0-1 d,#1d2824, 2-89 #b2c3b8,#1d2824, +|1: 0-1 d,#887455, 2-89 #becfc4,#314738, +|2: 0-1 d,#496656, 2-27 #b2c3b8,#1d2824, 28-40 #d3b0d9,#1d2824, 41-89 #b2c3b8,#1d2824, |3: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-83 #e5eee5,#0d1410, 84-84 #e5eee5,#1d2824, 85-89 #b2c3b8,#1d2824, |4: 0-0 d,#608269, 1-89 d,#0d1410, -|5: 0-1 d,#add38a, 2-2 d,#314738, 3-28 #becfc4,#314738, 29-42 #dfbce5,#314738, 43-89 #becfc4,#314738, +|5: 0-1 d,#add38a, 2-27 #becfc4,#314738, 28-41 #dfbce5,#314738, 42-89 #becfc4,#314738, |6: 0-0 d,#608269, 1-1 d,#0d1410, 2-4 d,#0d1410,b 5-6 #616f64,#0d1410,b 7-8 #e5eee5,#0d1410, 9-9 #c9a7ed,#0d1410, 10-12 #e5eee5,#0d1410, 13-15 #c9a7ed,#0d1410, 16-21 #b8d88a,#0d1410, 22-89 #e5eee5,#0d1410, |7: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-8 #b9f480,#0d1410, 9-11 #c9a7ed,#0d1410, 12-89 #b9f480,#0d1410, |8: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-17 #e5eee5,#0d1410, 18-19 #f8c082,#0d1410, 20-89 #e5eee5,#0d1410, @@ -34,18 +34,18 @@ |21: 0-0 d,#608269, 1-89 d,#0d1410, |22: 0-0 d,#608269, 1-89 d,#0d1410, == 9p opened grid=90x23 cursor=7,6,block -|0: Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit -@0: 0-74 #b2c3b8,#1d2824,,tagline 75-89 d,#1d2824,,tagline -|1: New Tty Find Grep Joincol Delcol -@1: 0-1 #ffffff,#887455,,tagline 2-2 d,#314738,,tagline 3-34 #becfc4,#314738,,tagline 35-89 d,#314738,,tagline -|2: /tmp/pardes-snap/mini/cwd/commands.txt Save Tty Collapse Del -@2: 0-1 #ffffff,#496656,,tagline 2-2 d,#1d2824,,tagline 3-28 #b2c3b8,#1d2824,,tagline 29-40 #d3b0d9,#1d2824,,tagline 41-62 #b2c3b8,#1d2824,,tagline 63-89 d,#1d2824,,tagline +|0: Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +@0: 0-76 #b2c3b8,#1d2824,,tagline 77-89 d,#1d2824,,tagline +|1: New Tty Find Grep Joincol Delcol +@1: 0-1 #ffffff,#887455,,tagline 2-33 #becfc4,#314738,,tagline 34-89 d,#314738,,tagline +|2: /tmp/pardes-snap/mini/cwd/commands.txt Save Tty Collapse Del +@2: 0-1 #ffffff,#496656,,tagline 2-27 #b2c3b8,#1d2824,,tagline 28-39 #d3b0d9,#1d2824,,tagline 40-61 #b2c3b8,#1d2824,,tagline 62-89 d,#1d2824,,tagline |3: 1 @`Mini demo.zig` Mini @3: 0-0 d,#608269,,body 1-1 d,#0d1410,,body 2-6 #59675c,#0d1410,,body 7-22 #e5eee5,#0d1410,,body 23-83 d,#0d1410,,body 84-84 d,#1d2824,,tagline 85-88 #b2c3b8,#1d2824,,tagline 89-89 d,#1d2824,,tagline |4: @4: 0-0 d,#608269,,body 1-1 d,#0d1410,,body 2-6 #59675c,#0d1410,,body 7-89 d,#0d1410,,body -|5: /tmp/pardes-snap/mini/cwd/Mini demo.zig Save Tty Collapse Del -@5: 0-1 #000000,#add38a,,tagline 2-2 d,#314738,,tagline 3-28 #becfc4,#314738,,tagline 29-41 #dfbce5,#314738,,tagline 42-63 #becfc4,#314738,,tagline 64-89 d,#314738,,tagline +|5: /tmp/pardes-snap/mini/cwd/Mini demo.zig Save Tty Collapse Del +@5: 0-1 #000000,#add38a,,tagline 2-27 #becfc4,#314738,,tagline 28-40 #dfbce5,#314738,,tagline 41-62 #becfc4,#314738,,tagline 63-89 d,#314738,,tagline |6: 1 ⠭⠍⣥⢩⣭⡭⣭⣬⣌⢭⣭⠌⠬⠅⠍⠁ +6: 7="⠭" 8="⠍" 9="⣥" 10="⢩" 11="⣭" 12="⡭" 13="⣭" 14="⣬" 15="⣌" 16="⢭" 17="⣭" 18="⠌" 19="⠬" 20="⠅" 21="⠍" 22="⠁" @6: 0-0 d,#608269,,body 1-1 d,#0d1410,,body 2-6 #616f64,#0d1410,b,body 7-8 #e5eee5,#0d1410,,body 9-9 #c9a7ed,#0d1410,,body 10-12 #e5eee5,#0d1410,,body 13-15 #c9a7ed,#0d1410,,body 16-21 #b8d88a,#0d1410,,body 22-22 #e5eee5,#0d1410,,body 23-89 d,#0d1410,,body @@ -105,32 +105,32 @@ |7: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-8 #b9f480,#0d1410, 9-11 #c9a7ed,#0d1410, 12-89 #b9f480,#0d1410, |8: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-17 #e5eee5,#0d1410, 18-19 #f8c082,#0d1410, 20-89 #e5eee5,#0d1410, == snap resized grid=105x27 cursor=7,7 -|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit -| New Tty Find Grep Joincol Delcol -| /tmp/pardes-snap/mini/cwd/commands.txt Save Tty Collapse Del +| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +| New Tty Find Grep Joincol Delcol +| /tmp/pardes-snap/mini/cwd/commands.txt Save Tty Collapse Del | 1 @`Mini demo.zig` | | -| /tmp/pardes-snap/mini/cwd/Mini demo.zig Save Tty Collapse Del +| /tmp/pardes-snap/mini/cwd/Mini demo.zig Save Tty Collapse Del | 1 ⠭⠍⣥⢩⣭⡭⣭⣬⣌⢭⣭⠌⠬⠅⠍⠁ Colors | 2 ⣂⢀⣉⣉⢉⣈⢁⣀⣀⢀⣀⣀⣀⢀⣀⣀⣀⣀⣀ | 3 ⠉⠉⠁⠉⠉⠉⠈⠈⠉⠉⠉⠉⠉⠉ | 4 == 9p resized grid=105x27 cursor=7,7,block -|0: Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit -@0: 0-74 #b2c3b8,#1d2824,,tagline 75-104 d,#1d2824,,tagline -|1: New Tty Find Grep Joincol Delcol -@1: 0-1 #ffffff,#887455,,tagline 2-2 d,#314738,,tagline 3-34 #becfc4,#314738,,tagline 35-104 d,#314738,,tagline -|2: /tmp/pardes-snap/mini/cwd/commands.txt Save Tty Collapse Del -@2: 0-1 #ffffff,#496656,,tagline 2-2 d,#1d2824,,tagline 3-28 #b2c3b8,#1d2824,,tagline 29-40 #d3b0d9,#1d2824,,tagline 41-62 #b2c3b8,#1d2824,,tagline 63-104 d,#1d2824,,tagline +|0: Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +@0: 0-76 #b2c3b8,#1d2824,,tagline 77-104 d,#1d2824,,tagline +|1: New Tty Find Grep Joincol Delcol +@1: 0-1 #ffffff,#887455,,tagline 2-33 #becfc4,#314738,,tagline 34-104 d,#314738,,tagline +|2: /tmp/pardes-snap/mini/cwd/commands.txt Save Tty Collapse Del +@2: 0-1 #ffffff,#496656,,tagline 2-27 #b2c3b8,#1d2824,,tagline 28-39 #d3b0d9,#1d2824,,tagline 40-61 #b2c3b8,#1d2824,,tagline 62-104 d,#1d2824,,tagline |3: 1 @`Mini demo.zig` @3: 0-0 d,#608269,,body 1-1 d,#0d1410,,body 2-6 #59675c,#0d1410,,body 7-22 #e5eee5,#0d1410,,body 23-104 d,#0d1410,,body |4: @4: 0-0 d,#608269,,body 1-1 d,#0d1410,,body 2-6 #59675c,#0d1410,,body 7-104 d,#0d1410,,body |5: @5: 0-0 d,#608269,,body 1-1 d,#0d1410,,body 2-6 #59675c,#0d1410,,body 7-104 d,#0d1410,,body -|6: /tmp/pardes-snap/mini/cwd/Mini demo.zig Save Tty Collapse Del -@6: 0-1 #000000,#add38a,,tagline 2-2 d,#314738,,tagline 3-28 #becfc4,#314738,,tagline 29-41 #dfbce5,#314738,,tagline 42-63 #becfc4,#314738,,tagline 64-104 d,#314738,,tagline +|6: /tmp/pardes-snap/mini/cwd/Mini demo.zig Save Tty Collapse Del +@6: 0-1 #000000,#add38a,,tagline 2-27 #becfc4,#314738,,tagline 28-40 #dfbce5,#314738,,tagline 41-62 #becfc4,#314738,,tagline 63-104 d,#314738,,tagline |7: 1 ⠭⠍⣥⢩⣭⡭⣭⣬⣌⢭⣭⠌⠬⠅⠍⠁ Colors +7: 7="⠭" 8="⠍" 9="⣥" 10="⢩" 11="⣭" 12="⡭" 13="⣭" 14="⣬" 15="⣌" 16="⢭" 17="⣭" 18="⠌" 19="⠬" 20="⠅" 21="⠍" 22="⠁" @7: 0-0 d,#608269,,body 1-1 d,#0d1410,,body 2-6 #616f64,#0d1410,b,body 7-8 #e5eee5,#0d1410,,body 9-9 #c9a7ed,#0d1410,,body 10-12 #e5eee5,#0d1410,,body 13-15 #c9a7ed,#0d1410,,body 16-21 #b8d88a,#0d1410,,body 22-22 #e5eee5,#0d1410,,body 23-96 d,#0d1410,,body 97-97 d,#1d2824,,tagline 98-103 #b2c3b8,#1d2824,,tagline 104-104 d,#1d2824,,tagline diff --git a/test/snapshots/modal.golden b/test/snapshots/modal.golden index 6dc6376d..9ebc72e9 100644 --- a/test/snapshots/modal.golden +++ b/test/snapshots/modal.golden @@ -1,8 +1,8 @@ == snap top grid=100x31 cursor=2,4 -|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit -| New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol -| /tmp/pardes-snap/modal/cwd Tty+bash Save Mode F /tmp/pardes-snap/modal/cwd Tty+bash Save Mode F -| ilter Collapse Del ilter Collapse Del +| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +| New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol +| /tmp/pardes-snap/modal/cwd Tty+bash Save Mode Fi /tmp/pardes-snap/modal/cwd Tty+bash Save Mode Fi +| lter Collapse Del lter Collapse Del | ls ls | words.txt words.txt | printf 'one two three\nfour five six\nseven ei @@ -16,17 +16,17 @@ | | | -| /tmp/pardes-snap/modal/cwd Tty+bash Save Mode F -| ilter Collapse Del +| /tmp/pardes-snap/modal/cwd Tty+bash Save Mode Fi +| lter Collapse Del | ls | words.txt == snap moved grid=100x31 cursor=8,6 == snap xsel grid=100x31 cursor=48,6 == style xsel grid=100x31 -|0: 0-99 #b2c3b8,#1d2824, -|1: 0-1 d,#887455, 2-2 d,#314738, 3-49 #becfc4,#314738, 50-51 #becfc4,#887455, 52-52 #becfc4,#1d2824, 53-99 #b2c3b8,#1d2824, -|2: 0-1 d,#add38a, 2-2 d,#314738, 3-29 #becfc4,#314738, 30-38 #dfbce5,#314738, 39-49 #becfc4,#314738, 50-51 #becfc4,#496656, 52-52 #becfc4,#1d2824, 53-79 #b2c3b8,#1d2824, 80-88 #d3b0d9,#1d2824, 89-99 #b2c3b8,#1d2824, -|3: 0-2 d,#314738, 3-49 #becfc4,#314738, 50-52 #becfc4,#1d2824, 53-99 #b2c3b8,#1d2824, +|0: 0-1 d,#1d2824, 2-99 #b2c3b8,#1d2824, +|1: 0-1 d,#887455, 2-49 #becfc4,#314738, 50-51 #becfc4,#887455, 52-99 #b2c3b8,#1d2824, +|2: 0-1 d,#add38a, 2-28 #becfc4,#314738, 29-37 #dfbce5,#314738, 38-49 #becfc4,#314738, 50-51 #becfc4,#496656, 52-78 #b2c3b8,#1d2824, 79-87 #d3b0d9,#1d2824, 88-99 #b2c3b8,#1d2824, +|3: 0-1 d,#314738, 2-49 #becfc4,#314738, 50-51 #becfc4,#1d2824, 52-99 #b2c3b8,#1d2824, |4: 0-0 d,#608269, 1-1 d,#0d1410, 2-49 #e5eee5,#0d1410, 50-50 #e5eee5,#608269, 51-99 #e5eee5,#0d1410, |5: 0-0 d,#608269, 1-1 d,#0d1410, 2-49 #e5eee5,#0d1410, 50-50 #e5eee5,#608269, 51-99 #e5eee5,#0d1410, |6: 0-0 d,#608269, 1-1 d,#0d1410, 2-48 #f5f7ee,#3c614a, 49-49 #f5f7ee,#0d1410, 50-50 #f5f7ee,#608269, 51-99 #f5f7ee,#0d1410, @@ -40,8 +40,8 @@ |14: 0-0 d,#608269, 1-49 d,#0d1410, 50-50 d,#608269, 51-99 d,#0d1410, |15: 0-0 d,#608269, 1-49 d,#0d1410, 50-50 d,#608269, 51-99 d,#0d1410, |16: 0-0 d,#608269, 1-49 d,#0d1410, 50-50 d,#608269, 51-99 d,#0d1410, -|17: 0-1 d,#496656, 2-2 d,#1d2824, 3-29 #b2c3b8,#1d2824, 30-38 #d3b0d9,#1d2824, 39-49 #b2c3b8,#1d2824, 50-50 #b2c3b8,#608269, 51-99 #b2c3b8,#0d1410, -|18: 0-2 d,#1d2824, 3-49 #b2c3b8,#1d2824, 50-50 #b2c3b8,#608269, 51-99 #b2c3b8,#0d1410, +|17: 0-1 d,#496656, 2-28 #b2c3b8,#1d2824, 29-37 #d3b0d9,#1d2824, 38-49 #b2c3b8,#1d2824, 50-50 #b2c3b8,#608269, 51-99 #b2c3b8,#0d1410, +|18: 0-1 d,#1d2824, 2-49 #b2c3b8,#1d2824, 50-50 #b2c3b8,#608269, 51-99 #b2c3b8,#0d1410, |19: 0-0 d,#608269, 1-1 d,#0d1410, 2-49 #e5eee5,#0d1410, 50-50 #e5eee5,#608269, 51-99 #e5eee5,#0d1410, |20: 0-0 d,#608269, 1-1 d,#0d1410, 2-49 #e5eee5,#0d1410, 50-50 #e5eee5,#608269, 51-99 #e5eee5,#0d1410, |21: 0-0 d,#608269, 1-49 d,#0d1410, 50-50 d,#608269, 51-99 d,#0d1410, diff --git a/test/snapshots/msg.golden b/test/snapshots/msg.golden index caa234d3..24018546 100644 --- a/test/snapshots/msg.golden +++ b/test/snapshots/msg.golden @@ -1,7 +1,7 @@ == snap opened grid=70x15 cursor=7,3 -|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug -| New Tty Find Grep Joincol Delcol -| /tmp/pardes-snap/msg/cwd/a.txt Save Tty Collapse Del +| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Deb +| New Tty Find Grep Joincol Delcol +| /tmp/pardes-snap/msg/cwd/a.txt Save Tty Collapse Del | 1 line 1 | 2 line 2 | 3 line 3 @@ -12,9 +12,9 @@ == snap saved grid=70x15 cursor=7,3 |3: 1 line 1 --:--:-- saved /tmp/pardes-snap/msg/cwd/a.txt == snap repainted grid=70x17 cursor=7,3 -|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug -| New Tty Find Grep Joincol Delcol -| /tmp/pardes-snap/msg/cwd/a.txt Save Tty Collapse Del +| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Deb +| New Tty Find Grep Joincol Delcol +| /tmp/pardes-snap/msg/cwd/a.txt Save Tty Collapse Del | 1 line 1 --:--:-- saved /tmp/pardes-snap/msg/cwd/a.txt | 2 line 2 | 3 line 3 @@ -45,7 +45,7 @@ |3: 1 AGAIN |4: 2 == snap msgbuiltin grid=70x17 cursor=29,5 -|2: * /tmp/pardes-snap/msg/cwd/a.txt Save Tty Collapse Del +|2: */tmp/pardes-snap/msg/cwd/a.txt Save Tty Collapse Del |3: 1 AGAIN hand-written report |5: 3 Msg hand-written report == snap msgtail grid=70x17 cursor=32,7 diff --git a/test/snapshots/multicursor.golden b/test/snapshots/multicursor.golden index 0b3bbcb2..48ccefbf 100644 --- a/test/snapshots/multicursor.golden +++ b/test/snapshots/multicursor.golden @@ -1,11 +1,11 @@ == snap three-cursors grid=150x31 cursor=7,9 -|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit -| New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol -| /tmp/pardes-snap/multicursor/cwd Tty+bash Save Mode Filter Collapse Del /tmp/pardes-snap/multicursor/cwd Tty+bash Save Mode Filter Collapse Del +| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +| New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol +| /tmp/pardes-snap/multicursor/cwd Tty+bash Save Mode Filter Collapse Del /tmp/pardes-snap/multicursor/cwd Tty+bash Save Mode Filter Collapse Del | ls ls | f.txt f.txt | -| /tmp/pardes-snap/multicursor/cwd/f.txt Save Tty Collapse Del +| /tmp/pardes-snap/multicursor/cwd/f.txt Save Tty Collapse Del | 1 line 1 | 2 line 2 | 3 line 3 @@ -16,17 +16,17 @@ | 8 line 8 | 9 line 9 | 10 line 10 -| /tmp/pardes-snap/multicursor/cwd Tty+bash Save Mode Filter Collapse Del +| /tmp/pardes-snap/multicursor/cwd Tty+bash Save Mode Filter Collapse Del | ls | f.txt == style three-cursors grid=150x31 -|0: 0-149 #b2c3b8,#1d2824, -|1: 0-1 d,#887455, 2-2 d,#314738, 3-74 #becfc4,#314738, 75-76 #becfc4,#887455, 77-77 #becfc4,#1d2824, 78-149 #b2c3b8,#1d2824, -|2: 0-1 d,#496656, 2-2 d,#1d2824, 3-35 #b2c3b8,#1d2824, 36-44 #d3b0d9,#1d2824, 45-74 #b2c3b8,#1d2824, 75-76 #b2c3b8,#496656, 77-110 #b2c3b8,#1d2824, 111-119 #d3b0d9,#1d2824, 120-149 #b2c3b8,#1d2824, +|0: 0-1 d,#1d2824, 2-149 #b2c3b8,#1d2824, +|1: 0-1 d,#887455, 2-74 #becfc4,#314738, 75-76 #becfc4,#887455, 77-149 #b2c3b8,#1d2824, +|2: 0-1 d,#496656, 2-34 #b2c3b8,#1d2824, 35-43 #d3b0d9,#1d2824, 44-74 #b2c3b8,#1d2824, 75-76 #b2c3b8,#496656, 77-109 #b2c3b8,#1d2824, 110-118 #d3b0d9,#1d2824, 119-149 #b2c3b8,#1d2824, |3: 0-0 d,#608269, 1-1 d,#0d1410, 2-74 #e5eee5,#0d1410, 75-75 #e5eee5,#608269, 76-149 #e5eee5,#0d1410, |4: 0-0 d,#608269, 1-1 d,#0d1410, 2-74 #e5eee5,#0d1410, 75-75 #e5eee5,#608269, 76-149 #e5eee5,#0d1410, |5: 0-0 d,#608269, 1-74 d,#0d1410, 75-75 d,#608269, 76-149 d,#0d1410, -|6: 0-1 d,#add38a, 2-2 d,#314738, 3-35 #becfc4,#314738, 36-41 #dfbce5,#314738, 42-74 #becfc4,#314738, 75-75 #becfc4,#608269, 76-149 #becfc4,#0d1410, +|6: 0-1 d,#add38a, 2-34 #becfc4,#314738, 35-40 #dfbce5,#314738, 41-74 #becfc4,#314738, 75-75 #becfc4,#608269, 76-149 #becfc4,#0d1410, |7: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-7 #3c614a,#f5f7ee, 8-74 #e5eee5,#0d1410, 75-75 #e5eee5,#608269, 76-149 #e5eee5,#0d1410, |8: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-7 #3c614a,#f5f7ee, 8-74 #e5eee5,#0d1410, 75-75 #e5eee5,#608269, 76-149 #e5eee5,#0d1410, |9: 0-0 d,#608269, 1-1 d,#0d1410, 2-4 d,#0d1410,b 5-6 #616f64,#0d1410,b 7-74 #e5eee5,#0d1410, 75-75 #e5eee5,#608269, 76-149 #e5eee5,#0d1410, @@ -37,7 +37,7 @@ |14: 0-0 d,#152019, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-74 #e5eee5,#0d1410, 75-75 #e5eee5,#608269, 76-149 #e5eee5,#0d1410, |15: 0-0 d,#152019, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-74 #e5eee5,#0d1410, 75-75 #e5eee5,#608269, 76-149 #e5eee5,#0d1410, |16: 0-0 d,#152019, 1-3 d,#0d1410, 4-6 #59675c,#0d1410, 7-74 #e5eee5,#0d1410, 75-75 #e5eee5,#608269, 76-149 #e5eee5,#0d1410, -|17: 0-1 d,#496656, 2-2 d,#1d2824, 3-35 #b2c3b8,#1d2824, 36-44 #d3b0d9,#1d2824, 45-74 #b2c3b8,#1d2824, 75-75 #b2c3b8,#608269, 76-149 #b2c3b8,#0d1410, +|17: 0-1 d,#496656, 2-34 #b2c3b8,#1d2824, 35-43 #d3b0d9,#1d2824, 44-74 #b2c3b8,#1d2824, 75-75 #b2c3b8,#608269, 76-149 #b2c3b8,#0d1410, |18: 0-0 d,#608269, 1-1 d,#0d1410, 2-74 #e5eee5,#0d1410, 75-75 #e5eee5,#608269, 76-149 #e5eee5,#0d1410, |19: 0-0 d,#608269, 1-1 d,#0d1410, 2-74 #e5eee5,#0d1410, 75-75 #e5eee5,#608269, 76-149 #e5eee5,#0d1410, |20: 0-0 d,#608269, 1-74 d,#0d1410, 75-75 d,#608269, 76-149 d,#0d1410, @@ -52,13 +52,13 @@ |29: 0-0 d,#608269, 1-74 d,#0d1410, 75-75 d,#608269, 76-149 d,#0d1410, |30: 0-0 d,#608269, 1-74 d,#0d1410, 75-75 d,#608269, 76-149 d,#0d1410, == snap edited-at-three grid=150x31 cursor=9,9 -|6: * /tmp/pardes-snap/multicursor/cwd/f.txt Save Tty Collapse Del +|6: */tmp/pardes-snap/multicursor/cwd/f.txt Save Tty Collapse Del |7: 1 >>line 1 |8: 2 >>line 2 |9: 3 >>line 3 == snap three-selections grid=150x31 cursor=8,9 == style three-selections grid=150x31 -|6: 0-0 d,#add38a, 1-1 #000000,#f9cb70,b 2-2 #000000,#314738, 3-35 #becfc4,#314738, 36-41 #dfbce5,#314738, 42-74 #becfc4,#314738, 75-75 #becfc4,#608269, 76-149 #becfc4,#0d1410, +|6: 0-0 d,#add38a, 1-1 #000000,#f9cb70,b 2-34 #becfc4,#314738, 35-40 #dfbce5,#314738, 41-74 #becfc4,#314738, 75-75 #becfc4,#608269, 76-149 #becfc4,#0d1410, |7: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-7 #f5f7ee,#243a2d, 8-8 #3c614a,#f5f7ee, 9-74 #e5eee5,#0d1410, 75-75 #e5eee5,#608269, 76-149 #e5eee5,#0d1410, |8: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-7 #f5f7ee,#243a2d, 8-8 #3c614a,#f5f7ee, 9-74 #e5eee5,#0d1410, 75-75 #e5eee5,#608269, 76-149 #e5eee5,#0d1410, |9: 0-0 d,#608269, 1-1 d,#0d1410, 2-4 d,#0d1410,b 5-6 #616f64,#0d1410,b 7-8 #f5f7ee,#3c614a, 9-74 #e5eee5,#0d1410, 75-75 #e5eee5,#608269, 76-149 #e5eee5,#0d1410, diff --git a/test/snapshots/nested-optout.golden b/test/snapshots/nested-optout.golden index 3539a16c..0cb3b742 100644 --- a/test/snapshots/nested-optout.golden +++ b/test/snapshots/nested-optout.golden @@ -1,10 +1,10 @@ == snap optout-file grid=100x31 cursor=9,6 -|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit -| New Tty Find Grep Joincol Delcol -|$ /tmp/pardes-snap/nested-optout/cwd Tty+bash Save Mode Filter Collapse Del | Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit -| New Tty Find Grep Joincol Delcol -| /tmp/pardes-snap/nested-optout/cwd/nested.txt Save Tty Collapse Del +| New Tty Find Grep Joincol Delcol +|$ /tmp/pardes-snap/nested-optout/cwd Tty+bash Save Mode Filter Collapse Del +| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +| New Tty Find Grep Joincol Delcol +| /tmp/pardes-snap/nested-optout/cwd/nested.txt Save Tty Collapse Del | 1 optout-marker | 2 second-optout-line | 3 @@ -20,15 +20,15 @@ | | | -| /tmp/pardes-snap/nested-optout/cwd/+New Save Tty Collapse Del +| /tmp/pardes-snap/nested-optout/cwd/+New Save Tty Collapse Del | 1 == snap inner-shell grid=100x31 cursor=6,6 -|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit -| New Tty Find Grep Joincol Delcol -|$ /tmp/pardes-snap/nested-optout/cwd Tty+bash Save Mode Filter Collapse Del | Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit -| New Tty Find Grep Joincol Delcol -| $ /tmp/pardes-snap/nested-optout/cwd/innerdir Tty+bash Save Mode Filter Collapse Del +| New Tty Find Grep Joincol Delcol +|$ /tmp/pardes-snap/nested-optout/cwd Tty+bash Save Mode Filter Collapse Del +| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +| New Tty Find Grep Joincol Delcol +| $ /tmp/pardes-snap/nested-optout/cwd/innerdir Tty+bash Save Mode Filter Collapse Del | $ | | @@ -39,16 +39,16 @@ | | | -| /tmp/pardes-snap/nested-optout/cwd/innerdir/+New Save Tty Collapse Del +| /tmp/pardes-snap/nested-optout/cwd/innerdir/+New Save Tty Collapse Del | 1 | | | -| /tmp/pardes-snap/nested-optout/cwd/+New Save Tty Collapse Del +| /tmp/pardes-snap/nested-optout/cwd/+New Save Tty Collapse Del | 1 == snap inner-launch grid=100x31 cursor=11,9 -|6: Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit -|7: New Tty Find Grep Joincol Delcol -|8: /tmp/pardes-snap/nested-optout/cwd/innerdir/deeper.txt Save Tty Collapse Del +|6: Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +|7: New Tty Find Grep Joincol Delcol +|8: /tmp/pardes-snap/nested-optout/cwd/innerdir/deeper.txt Save Tty Collapse Del |9: 1 deepest-marker |10: 2 diff --git a/test/snapshots/nested.golden b/test/snapshots/nested.golden index 44ab4b82..466c34ae 100644 --- a/test/snapshots/nested.golden +++ b/test/snapshots/nested.golden @@ -1,10 +1,10 @@ == snap file-arg grid=100x31 cursor=7,6 -|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit -| New Tty Find Grep Joincol Delcol -|$ /tmp/pardes-snap/nested/cwd Tty+bash Save Mode Filter Collapse Del +| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +| New Tty Find Grep Joincol Delcol +|$ /tmp/pardes-snap/nested/cwd Tty+bash Save Mode Filter Collapse Del | $ $(readlink /proc/$PPID/exe) nested.txt | $ -| /tmp/pardes-snap/nested/cwd/nested.txt Save Tty Collapse Del +| /tmp/pardes-snap/nested/cwd/nested.txt Save Tty Collapse Del | 1 hello-from-nested | 2 second-nested-line | 3 @@ -20,12 +20,12 @@ | | | -| /tmp/pardes-snap/nested/cwd/+New Save Tty Collapse Del +| /tmp/pardes-snap/nested/cwd/+New Save Tty Collapse Del | 1 == snap no-arg grid=100x31 cursor=4,7 -|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit -| New Tty Find Grep Joincol Delcol -|$ /tmp/pardes-snap/nested/cwd Tty+bash Save Mode Filter Collapse Del +| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +| New Tty Find Grep Joincol Delcol +|$ /tmp/pardes-snap/nested/cwd Tty+bash Save Mode Filter Collapse Del | $ $(readlink /proc/$PPID/exe) | pardes: this shell is already inside pardes, and a pardes inside a pardes | is spicy. Name a file or a directory and the outer session opens it, or @@ -44,15 +44,15 @@ | | | -| /tmp/pardes-snap/nested/cwd/+New Save Tty Collapse Del +| /tmp/pardes-snap/nested/cwd/+New Save Tty Collapse Del | 1 == snap dir-arg grid=100x31 cursor=7,6 -|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit -| New Tty Find Grep Joincol Delcol -|$ /tmp/pardes-snap/nested/cwd Tty+bash Save Mode Filter Collapse Del +| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +| New Tty Find Grep Joincol Delcol +|$ /tmp/pardes-snap/nested/cwd Tty+bash Save Mode Filter Collapse Del | $ $(readlink /proc/$PPID/exe) nestdir | $ -| /tmp/pardes-snap/nested/cwd/nestdir/ Get Tty Collapse Del +| /tmp/pardes-snap/nested/cwd/nestdir/ Get Tty Collapse Del | 1 inside-nested.txt | 2 | @@ -68,5 +68,5 @@ | | | -| /tmp/pardes-snap/nested/cwd/+New Save Tty Collapse Del +| /tmp/pardes-snap/nested/cwd/+New Save Tty Collapse Del | 1 diff --git a/test/snapshots/ninep.golden b/test/snapshots/ninep.golden index e524fa30..d10c7181 100644 --- a/test/snapshots/ninep.golden +++ b/test/snapshots/ninep.golden @@ -1,7 +1,7 @@ == snap opened grid=90x15 cursor=7,3 -|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit -| New Tty Find Grep Joincol Delcol -| /tmp/pardes-snap/ninep/cwd/demo.zig Save Tty Collapse Del TreeContext Def Refs +| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +| New Tty Find Grep Joincol Delcol +| /tmp/pardes-snap/ninep/cwd/demo.zig Save Tty Collapse TreeContext Def Refs Del | 1 const greeting = "café λ 界 é"; | 2 | 3 pub fn choose(ok: bool) u32 { @@ -10,9 +10,9 @@ | 6 } | 7 == style opened grid=90x15 -|0: 0-89 #b2c3b8,#1d2824, -|1: 0-1 d,#887455, 2-2 d,#314738, 3-89 #becfc4,#314738, -|2: 0-1 d,#add38a, 2-2 d,#314738, 3-29 #becfc4,#314738, 30-38 #dfbce5,#314738, 39-89 #becfc4,#314738, +|0: 0-1 d,#1d2824, 2-89 #b2c3b8,#1d2824, +|1: 0-1 d,#887455, 2-89 #becfc4,#314738, +|2: 0-1 d,#add38a, 2-28 #becfc4,#314738, 29-37 #dfbce5,#314738, 38-89 #becfc4,#314738, |3: 0-0 d,#608269, 1-1 d,#0d1410, 2-4 d,#0d1410,b 5-6 #616f64,#0d1410,b 7-23 #e5eee5,#0d1410, 24-32 #b8d88a,#0d1410, 33-33 d,d, 34-34 d,#0d1410, 35-36 #b8d88a,#0d1410, 37-89 #e5eee5,#0d1410, |4: 0-0 d,#608269, 1-4 d,#0d1410, 5-89 #59675c,#0d1410, |5: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-10 #e5eee5,#0d1410, 11-13 #c9a7ed,#0d1410, 14-89 #e5eee5,#0d1410, @@ -26,12 +26,12 @@ |13: 0-0 d,#608269, 1-89 d,#0d1410, |14: 0-0 d,#608269, 1-89 d,#0d1410, == 9p opened grid=90x15 cursor=7,3,block -|0: Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit -@0: 0-74 #b2c3b8,#1d2824,,tagline 75-89 d,#1d2824,,tagline -|1: New Tty Find Grep Joincol Delcol -@1: 0-1 #ffffff,#887455,,tagline 2-2 d,#314738,,tagline 3-34 #becfc4,#314738,,tagline 35-89 d,#314738,,tagline -|2: /tmp/pardes-snap/ninep/cwd/demo.zig Save Tty Collapse Del TreeContext Def Refs -@2: 0-1 #000000,#add38a,,tagline 2-2 d,#314738,,tagline 3-29 #becfc4,#314738,,tagline 30-37 #dfbce5,#314738,,tagline 38-80 #becfc4,#314738,,tagline 81-89 d,#314738,,tagline +|0: Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +@0: 0-76 #b2c3b8,#1d2824,,tagline 77-89 d,#1d2824,,tagline +|1: New Tty Find Grep Joincol Delcol +@1: 0-1 #ffffff,#887455,,tagline 2-33 #becfc4,#314738,,tagline 34-89 d,#314738,,tagline +|2: /tmp/pardes-snap/ninep/cwd/demo.zig Save Tty Collapse TreeContext Def Refs Del +@2: 0-1 #000000,#add38a,,tagline 2-28 #becfc4,#314738,,tagline 29-36 #dfbce5,#314738,,tagline 37-79 #becfc4,#314738,,tagline 80-89 d,#314738,,tagline |3: 1 const greeting = "café λ 界 é"; +3: 28="é" 30="λ" 32="界" 33="" 35="é" @3: 0-0 d,#608269,,body 1-1 d,#0d1410,,body 2-6 #616f64,#0d1410,b,body 7-23 #e5eee5,#0d1410,,body 24-36 #b8d88a,#0d1410,,body 37-37 #e5eee5,#0d1410,,body 38-89 d,#0d1410,,body @@ -73,7 +73,7 @@ |7: 5 return 7; @7: 0-0 d,#608269,,body 1-1 d,#0d1410,,body 2-6 #59675c,#0d1410,,body 7-19 #e5eee5,#0d1410,,body 20-89 d,#0d1410,,body == snap edited-with-colors-off grid=90x15 cursor=7,4 -|2: * /tmp/pardes-snap/ninep/cwd/demo.zig Save Tty Collapse Del TreeContext Def Refs +|2: */tmp/pardes-snap/ninep/cwd/demo.zig Save Tty Collapse TreeContext Def Refs Del |3: 1 // café λ 界 |4: 2 const greeting = "café λ 界 é"; |5: 3 @@ -83,8 +83,8 @@ |9: 7 } |10: 8 == 9p edited-with-colors-off grid=90x15 cursor=7,4,block -|2: * /tmp/pardes-snap/ninep/cwd/demo.zig Save Tty Collapse Del TreeContext Def Refs -@2: 0-0 #000000,#add38a,,tagline 1-1 #000000,#f9cb70,b,tagline 2-2 d,#314738,,tagline 3-29 #becfc4,#314738,,tagline 30-37 #dfbce5,#314738,,tagline 38-80 #becfc4,#314738,,tagline 81-89 d,#314738,,tagline +|2: */tmp/pardes-snap/ninep/cwd/demo.zig Save Tty Collapse TreeContext Def Refs Del +@2: 0-0 #000000,#add38a,,tagline 1-1 #000000,#f9cb70,b,tagline 2-28 #becfc4,#314738,,tagline 29-36 #dfbce5,#314738,,tagline 37-79 #becfc4,#314738,,tagline 80-89 d,#314738,,tagline |3: 1 // café λ 界 +3: 13="é" 15="λ" 17="界" 18="" @3: 0-0 d,#608269,,body 1-1 d,#0d1410,,body 2-6 #59675c,#0d1410,,body 7-18 #e5eee5,#0d1410,,body 19-89 d,#0d1410,,body @@ -104,7 +104,7 @@ |10: 8 @10: 0-0 d,#608269,,body 1-1 d,#0d1410,,body 2-6 #59675c,#0d1410,,body 7-89 d,#0d1410,,body == style colors-on grid=90x15 -|2: 0-0 d,#add38a, 1-1 #000000,#f9cb70,b 2-2 #000000,#314738, 3-29 #becfc4,#314738, 30-38 #dfbce5,#314738, 39-89 #becfc4,#314738, +|2: 0-0 d,#add38a, 1-1 #000000,#f9cb70,b 2-28 #becfc4,#314738, 29-37 #dfbce5,#314738, 38-89 #becfc4,#314738, |3: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-17 #b9f480,#0d1410, 18-18 d,d, 19-81 d,#0d1410, 82-82 d,#1d2824, 83-89 #b2c3b8,#1d2824, |4: 0-0 d,#608269, 1-1 d,#0d1410, 2-4 d,#0d1410,b 5-6 #616f64,#0d1410,b 7-23 #e5eee5,#0d1410, 24-32 #b8d88a,#0d1410, 33-33 d,d, 34-34 d,#0d1410, 35-36 #b8d88a,#0d1410, 37-89 #e5eee5,#0d1410, |5: 0-0 d,#608269, 1-4 d,#0d1410, 5-89 #59675c,#0d1410, @@ -127,9 +127,9 @@ |8: 6 return 7; @8: 0-0 d,#608269,,body 1-1 d,#0d1410,,body 2-6 #59675c,#0d1410,,body 7-10 #e5eee5,#0d1410,,body 11-16 #c9a7ed,#0d1410,,body 17-17 #e5eee5,#0d1410,,body 18-18 #f8c082,#0d1410,,body 19-19 #e5eee5,#0d1410,,body 20-89 d,#0d1410,,body == style resized grid=105x20 -|0: 0-104 #b2c3b8,#1d2824, -|1: 0-1 d,#887455, 2-2 d,#314738, 3-104 #becfc4,#314738, -|2: 0-0 d,#add38a, 1-1 #000000,#f9cb70,b 2-2 #000000,#314738, 3-29 #becfc4,#314738, 30-38 #dfbce5,#314738, 39-104 #becfc4,#314738, +|0: 0-1 d,#1d2824, 2-104 #b2c3b8,#1d2824, +|1: 0-1 d,#887455, 2-104 #becfc4,#314738, +|2: 0-0 d,#add38a, 1-1 #000000,#f9cb70,b 2-28 #becfc4,#314738, 29-37 #dfbce5,#314738, 38-104 #becfc4,#314738, |3: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-17 #b9f480,#0d1410, 18-18 d,d, 19-96 d,#0d1410, 97-97 d,#1d2824, 98-104 #b2c3b8,#1d2824, |4: 0-0 d,#608269, 1-1 d,#0d1410, 2-4 d,#0d1410,b 5-6 #616f64,#0d1410,b 7-23 #e5eee5,#0d1410, 24-32 #b8d88a,#0d1410, 33-33 d,d, 34-34 d,#0d1410, 35-36 #b8d88a,#0d1410, 37-104 #e5eee5,#0d1410, |5: 0-0 d,#608269, 1-4 d,#0d1410, 5-104 #59675c,#0d1410, @@ -148,12 +148,12 @@ |18: 0-0 d,#608269, 1-104 d,#0d1410, |19: 0-0 d,#608269, 1-104 d,#0d1410, == 9p resized grid=105x20 cursor=7,4,block -|0: Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit -@0: 0-74 #b2c3b8,#1d2824,,tagline 75-104 d,#1d2824,,tagline -|1: New Tty Find Grep Joincol Delcol -@1: 0-1 #ffffff,#887455,,tagline 2-2 d,#314738,,tagline 3-34 #becfc4,#314738,,tagline 35-104 d,#314738,,tagline -|2: * /tmp/pardes-snap/ninep/cwd/demo.zig Save Tty Collapse Del TreeContext Def Refs -@2: 0-0 #000000,#add38a,,tagline 1-1 #000000,#f9cb70,b,tagline 2-2 d,#314738,,tagline 3-29 #becfc4,#314738,,tagline 30-37 #dfbce5,#314738,,tagline 38-80 #becfc4,#314738,,tagline 81-104 d,#314738,,tagline +|0: Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +@0: 0-76 #b2c3b8,#1d2824,,tagline 77-104 d,#1d2824,,tagline +|1: New Tty Find Grep Joincol Delcol +@1: 0-1 #ffffff,#887455,,tagline 2-33 #becfc4,#314738,,tagline 34-104 d,#314738,,tagline +|2: */tmp/pardes-snap/ninep/cwd/demo.zig Save Tty Collapse TreeContext Def Refs Del +@2: 0-0 #000000,#add38a,,tagline 1-1 #000000,#f9cb70,b,tagline 2-28 #becfc4,#314738,,tagline 29-36 #dfbce5,#314738,,tagline 37-79 #becfc4,#314738,,tagline 80-104 d,#314738,,tagline |3: 1 // café λ 界 Colors +3: 13="é" 15="λ" 17="界" 18="" @3: 0-0 d,#608269,,body 1-1 d,#0d1410,,body 2-6 #59675c,#0d1410,,body 7-18 #b9f480,#0d1410,,body 19-96 d,#0d1410,,body 97-97 d,#1d2824,,tagline 98-103 #b2c3b8,#1d2824,,tagline 104-104 d,#1d2824,,tagline @@ -191,9 +191,9 @@ |19: @19: 0-0 d,#608269,,body 1-1 d,#0d1410,,body 2-6 #59675c,#0d1410,,body 7-104 d,#0d1410,,body == snap resized grid=105x20 cursor=7,4 -|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit -| New Tty Find Grep Joincol Delcol -| * /tmp/pardes-snap/ninep/cwd/demo.zig Save Tty Collapse Del TreeContext Def Refs +| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +| New Tty Find Grep Joincol Delcol +| */tmp/pardes-snap/ninep/cwd/demo.zig Save Tty Collapse TreeContext Def Refs Del | 1 // café λ 界 Colors | 2 const greeting = "café λ 界 é"; | 3 diff --git a/test/snapshots/pagercolor.golden b/test/snapshots/pagercolor.golden index abd264d1..e84359d8 100644 --- a/test/snapshots/pagercolor.golden +++ b/test/snapshots/pagercolor.golden @@ -1,7 +1,7 @@ == snap pager grid=100x50 cursor=4,5 -|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit -| New Tty Find Grep Joincol Delcol -|$ /tmp/pardes-snap/pagercolor/cwd Tty+bash Save Mode Filter Collapse Del +| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +| New Tty Find Grep Joincol Delcol +|$ /tmp/pardes-snap/pagercolor/cwd Tty+bash Save Mode Filter Collapse Del | $ printf '\033]0;title\007\033[31mred\033[m \033[1;32mbold green\033[m \033[38;2;200;100;0mrgb\033 | [m \033[4mul\033[m N\bNA\bAM\bME\bE _\bu_\bs plain\n' | $(readlink /proc/$PPID/exe) - | $ @@ -33,7 +33,7 @@ | | | -| /tmp/pardes-snap/pagercolor/cwd/+New Save Tty Collapse Del +| /tmp/pardes-snap/pagercolor/cwd/+New Save Tty Collapse Del | 1 | | @@ -41,12 +41,12 @@ | | | -| /tmp/pardes-snap/pagercolor/cwd/+Pager Save Tty Filter Collapse Del +| /tmp/pardes-snap/pagercolor/cwd/+Pager Save Tty Filter Collapse Del | red bold green rgb ul NAME us plain == style pager-colours grid=100x50 -|0: 0-99 #b2c3b8,#1d2824, -|1: 0-1 d,#887455, 2-2 d,#314738, 3-99 #becfc4,#314738, -|2: 0-1 #000000,#add38a, 2-2 #000000,#314738, 3-34 #becfc4,#314738, 35-43 #dfbce5,#314738, 44-99 #becfc4,#314738, +|0: 0-1 d,#1d2824, 2-99 #b2c3b8,#1d2824, +|1: 0-1 d,#887455, 2-99 #becfc4,#314738, +|2: 0-1 #000000,#add38a, 2-33 #becfc4,#314738, 34-42 #dfbce5,#314738, 43-99 #becfc4,#314738, |3: 0-0 d,#608269, 1-1 d,#0d1410, 2-99 #e5eee5,#0d1410, |4: 0-0 d,#608269, 1-1 d,#0d1410, 2-99 #e5eee5,#0d1410, |5: 0-0 d,#608269, 1-1 d,#0d1410, 2-99 #e5eee5,#0d1410, @@ -78,7 +78,7 @@ |31: 0-0 d,#608269, 1-99 d,#0d1410, |32: 0-0 d,#608269, 1-99 d,#0d1410, |33: 0-0 d,#608269, 1-99 d,#0d1410, -|34: 0-1 d,#496656, 2-2 d,#1d2824, 3-34 #b2c3b8,#1d2824, 35-39 #d3b0d9,#1d2824, 40-99 #b2c3b8,#1d2824, +|34: 0-1 d,#496656, 2-33 #b2c3b8,#1d2824, 34-38 #d3b0d9,#1d2824, 39-99 #b2c3b8,#1d2824, |35: 0-0 d,#608269, 1-4 d,#0d1410, 5-99 #59675c,#0d1410, |36: 0-0 d,#608269, 1-99 d,#0d1410, |37: 0-0 d,#608269, 1-99 d,#0d1410, @@ -86,7 +86,7 @@ |39: 0-0 d,#608269, 1-99 d,#0d1410, |40: 0-0 d,#608269, 1-99 d,#0d1410, |41: 0-0 d,#608269, 1-99 d,#0d1410, -|42: 0-1 d,#496656, 2-2 d,#1d2824, 3-34 #b2c3b8,#1d2824, 35-41 #d3b0d9,#1d2824, 42-99 #b2c3b8,#1d2824, +|42: 0-1 d,#496656, 2-33 #b2c3b8,#1d2824, 34-40 #d3b0d9,#1d2824, 41-99 #b2c3b8,#1d2824, |43: 0-0 d,#608269, 1-1 d,#0d1410, 2-5 #f1a39b,#0d1410, 6-15 #b6ce94,#0d1410,b 16-16 #b6ce94,#0d1410, 17-20 #c5917e,#0d1410, 21-22 #e5eee5,#0d1410,u 23-23 #e5eee5,#0d1410, 24-27 #e5eee5,#0d1410,b 28-28 #e5eee5,#0d1410, 29-30 #e5eee5,#0d1410,u 31-99 #e5eee5,#0d1410, |44: 0-0 d,#608269, 1-99 d,#0d1410, |45: 0-0 d,#608269, 1-99 d,#0d1410, @@ -99,19 +99,33 @@ |6: 3[m\n\033[1m+++ b/x\033[m\n\033[36m@@ -1 +1 @@\033[m\n\033[31m-old\033[m\n\033[32m+new\033[m\n' | |7: $(readlink /proc/$PPID/exe) - |8: $ -|9: /tmp/pardes-snap/pagercolor/cwd/+Diff Save Tty Diff Collapse Del LocationsConfig +|9: /tmp/pardes-snap/pagercolor/cwd/+Diff Save Tty Diff Collapse LocationsConfig Del |10: commit 0123abc |11: x:1 |12: -old |13: +new -|49: /tmp/pardes-snap/pagercolor/cwd/+Pager Save Tty Filter Diff Collapse Del +|34: +|35: +|38: /tmp/pardes-snap/pagercolor/cwd/+New Save Tty Collapse Del +|39: 1 +|42: +|43: +|46: /tmp/pardes-snap/pagercolor/cwd/+Pager Save Tty Filter Collapse Del +|47: red bold green rgb ul NAME us plain == style pager-diff-colours grid=100x50 |6: 0-0 d,#608269, 1-1 d,#0d1410, 2-99 #e5eee5,#0d1410, |7: 0-0 d,#608269, 1-1 d,#0d1410, 2-99 #e5eee5,#0d1410, |8: 0-0 d,#608269, 1-1 d,#0d1410, 2-99 #e5eee5,#0d1410, -|9: 0-1 d,#496656, 2-2 d,#1d2824, 3-34 #b2c3b8,#1d2824, 35-40 #d3b0d9,#1d2824, 41-99 #b2c3b8,#1d2824, +|9: 0-1 d,#496656, 2-33 #b2c3b8,#1d2824, 34-39 #d3b0d9,#1d2824, 40-99 #b2c3b8,#1d2824, |10: 0-0 d,#608269, 1-1 d,#0d1410, 2-99 #e5eee5,#0d1410, |11: 0-0 d,#608269, 1-1 d,#0d1410, 2-99 #59675c,#0d1410, |12: 0-0 d,#608269, 1-1 d,#0d1410, 2-2 #f1a39b,#1a1d18,b 3-99 #f8c082,#1a1d18, |13: 0-0 d,#608269, 1-1 d,#0d1410, 2-2 #b6ce94,#171f18,b 3-99 #b8d88a,#171f18, -|49: 0-1 d,#496656, 2-2 d,#1d2824, 3-34 #b2c3b8,#1d2824, 35-41 #d3b0d9,#1d2824, 42-99 #b2c3b8,#1d2824, +|34: 0-0 d,#608269, 1-99 d,#0d1410, +|35: 0-0 d,#608269, 1-99 d,#0d1410, +|38: 0-1 d,#496656, 2-33 #b2c3b8,#1d2824, 34-38 #d3b0d9,#1d2824, 39-99 #b2c3b8,#1d2824, +|39: 0-0 d,#608269, 1-4 d,#0d1410, 5-99 #59675c,#0d1410, +|42: 0-0 d,#608269, 1-99 d,#0d1410, +|43: 0-0 d,#608269, 1-99 d,#0d1410, +|46: 0-1 d,#496656, 2-33 #b2c3b8,#1d2824, 34-40 #d3b0d9,#1d2824, 41-99 #b2c3b8,#1d2824, +|47: 0-0 d,#608269, 1-1 d,#0d1410, 2-5 #f1a39b,#0d1410, 6-15 #b6ce94,#0d1410,b 16-16 #b6ce94,#0d1410, 17-20 #c5917e,#0d1410, 21-22 #e5eee5,#0d1410,u 23-23 #e5eee5,#0d1410, 24-27 #e5eee5,#0d1410,b 28-28 #e5eee5,#0d1410, 29-30 #e5eee5,#0d1410,u 31-99 #e5eee5,#0d1410, diff --git a/test/snapshots/pipe.golden b/test/snapshots/pipe.golden index 2fd54c27..8818499e 100644 --- a/test/snapshots/pipe.golden +++ b/test/snapshots/pipe.golden @@ -1,12 +1,12 @@ == snap prompt grid=180x13 cursor=179,3 -|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit -| New Tty Find Grep Joincol Delcol -| /tmp/pardes-snap/pipe/cwd/pipe.txt Save Tty Collapse Del +| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +| New Tty Find Grep Joincol Delcol +| /tmp/pardes-snap/pipe/cwd/pipe.txt Save Tty Collapse Del | 1 alpha beta |tr a-z A-Z | 2 gamma delta == snap filtered grid=180x13 cursor=17,3 -|2: * /tmp/pardes-snap/pipe/cwd/pipe.txt Save Tty Collapse Del +|2: */tmp/pardes-snap/pipe/cwd/pipe.txt Save Tty Collapse Del |3: 1 ALPHA BETA == snap undone grid=180x13 cursor=17,3 -|2: /tmp/pardes-snap/pipe/cwd/pipe.txt Save Tty Collapse Del +|2: /tmp/pardes-snap/pipe/cwd/pipe.txt Save Tty Collapse Del |3: 1 alpha beta diff --git a/test/snapshots/psearch.golden b/test/snapshots/psearch.golden index e830a206..2a845a34 100644 --- a/test/snapshots/psearch.golden +++ b/test/snapshots/psearch.golden @@ -1,7 +1,7 @@ == snap output grid=140x31 cursor=4,9 -|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit -| New Tty Find Grep Joincol Delcol -| /tmp/pardes-snap/psearch/cwd Tty+bash Save Mode Filter Collapse Del +| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +| New Tty Find Grep Joincol Delcol +| /tmp/pardes-snap/psearch/cwd Tty+bash Save Mode Filter Collapse Del | printf 'x MA''RK a\nzz\nx MA''RK b\nzz\nx MA''RK c\n' | x MARK a | zz @@ -20,13 +20,13 @@ | | | -| /tmp/pardes-snap/psearch/cwd/+New Save Tty Collapse Del +| /tmp/pardes-snap/psearch/cwd/+New Save Tty Collapse Del | 1 == snap typing grid=140x31 cursor=139,3 |3: printf 'x MA''RK a\nzz\nx MA''RK b\nzz\nx MA''RK c\n' /MARK == snap results grid=140x31 cursor=7,4 |3: printf 'x MA''RK a\nzz\nx MA''RK b\nzz\nx MA''RK c\n' -|10: /tmp/pardes-snap/psearch/cwd/+Search Save Tty Collapse Del LocationsConfig +|10: /tmp/pardes-snap/psearch/cwd/+Search Save Tty Collapse LocationsConfig Del |11: 1 @p1:2:3-6 |12: 2 x MARK a |13: 3 @p1:4:3-6 @@ -35,9 +35,9 @@ |16: 6 x MARK c |17: 7 == style results grid=140x31 -|0: 0-139 #b2c3b8,#1d2824, -|1: 0-1 d,#887455, 2-2 d,#314738, 3-139 #becfc4,#314738, -|2: 0-1 d,#add38a, 2-2 d,#314738, 3-31 #becfc4,#314738, 32-40 #dfbce5,#314738, 41-139 #becfc4,#314738, +|0: 0-1 d,#1d2824, 2-139 #b2c3b8,#1d2824, +|1: 0-1 d,#887455, 2-139 #becfc4,#314738, +|2: 0-1 d,#add38a, 2-30 #becfc4,#314738, 31-39 #dfbce5,#314738, 40-139 #becfc4,#314738, |3: 0-0 d,#608269, 1-1 d,#0d1410, 2-139 #e5eee5,#0d1410, |4: 0-0 d,#608269, 1-1 d,#0d1410, 2-3 #e5eee5,#0d1410, 4-7 #f5f7ee,#3c614a, 8-8 #f5f7ee,#0d1410, 9-139 #e5eee5,#0d1410, |5: 0-0 d,#608269, 1-1 d,#0d1410, 2-139 #e5eee5,#0d1410, @@ -45,7 +45,7 @@ |7: 0-0 d,#608269, 1-1 d,#0d1410, 2-139 #e5eee5,#0d1410, |8: 0-0 d,#608269, 1-1 d,#0d1410, 2-139 #e5eee5,#0d1410, |9: 0-0 d,#608269, 1-139 d,#0d1410, -|10: 0-1 d,#496656, 2-2 d,#1d2824, 3-31 #b2c3b8,#1d2824, 32-39 #d3b0d9,#1d2824, 40-139 #b2c3b8,#1d2824, +|10: 0-1 d,#496656, 2-30 #b2c3b8,#1d2824, 31-38 #d3b0d9,#1d2824, 39-139 #b2c3b8,#1d2824, |11: 0-0 d,#608269, 1-4 d,#0d1410, 5-139 #59675c,#0d1410, |12: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-8 #e5eee5,#0d1410, 9-12 #f7e4a5,#5e4923, 13-13 #f7e4a5,#0d1410, 14-139 #e5eee5,#0d1410, |13: 0-0 d,#608269, 1-4 d,#0d1410, 5-139 #59675c,#0d1410, @@ -56,7 +56,7 @@ |18: 0-0 d,#608269, 1-139 d,#0d1410, |19: 0-0 d,#608269, 1-139 d,#0d1410, |20: 0-0 d,#608269, 1-139 d,#0d1410, -|21: 0-1 d,#496656, 2-2 d,#1d2824, 3-31 #b2c3b8,#1d2824, 32-36 #d3b0d9,#1d2824, 37-139 #b2c3b8,#1d2824, +|21: 0-1 d,#496656, 2-30 #b2c3b8,#1d2824, 31-35 #d3b0d9,#1d2824, 36-139 #b2c3b8,#1d2824, |22: 0-0 d,#608269, 1-4 d,#0d1410, 5-139 #59675c,#0d1410, |23: 0-0 d,#608269, 1-139 d,#0d1410, |24: 0-0 d,#608269, 1-139 d,#0d1410, @@ -69,13 +69,13 @@ == snap second grid=140x31 cursor=7,6 == snap back grid=140x31 cursor=7,4 == snap nomatch grid=140x31 cursor=7,13 -|24: /tmp/pardes-snap/psearch/cwd/+Search Save Tty Collapse Del LocationsConfig +|24: /tmp/pardes-snap/psearch/cwd/+Search Save Tty Collapse LocationsConfig Del |25: 1 == snap ttyinert grid=140x31 cursor=4,9 -|2: $ /tmp/pardes-snap/psearch/cwd Tty+bash Save Mode Filter Collapse Del +|2: $ /tmp/pardes-snap/psearch/cwd Tty+bash Save Mode Filter Collapse Del |3: $ printf 'x MA''RK a\nzz\nx MA''RK b\nzz\nx MA''RK c\n' |9: $ == snap rightsearch grid=140x31 cursor=7,6 -|2: /tmp/pardes-snap/psearch/cwd Tty+bash Save Mode Filter Collapse Del +|2: /tmp/pardes-snap/psearch/cwd Tty+bash Save Mode Filter Collapse Del |3: printf 'x MA''RK a\nzz\nx MA''RK b\nzz\nx MA''RK c\n' |9: diff --git a/test/snapshots/reflow.golden b/test/snapshots/reflow.golden index 17c42d0d..db4b5a77 100644 --- a/test/snapshots/reflow.golden +++ b/test/snapshots/reflow.golden @@ -1,7 +1,7 @@ == snap widened grid=200x25 cursor=4,16 -|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit -| New Tty Find Grep Joincol Delcol -|$ /tmp/pardes-snap/reflow/cwd Tty+bash Save Mode Filter Collapse Del +| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +| New Tty Find Grep Joincol Delcol +|$ /tmp/pardes-snap/reflow/cwd Tty+bash Save Mode Filter Collapse Del | yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy | yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy | yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy @@ -16,5 +16,5 @@ | yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy | yyyyyyyyyyyyyyyyyyyyyyyyyyyyyydone | $ -| /tmp/pardes-snap/reflow/cwd/+New Save Tty Collapse Del +| /tmp/pardes-snap/reflow/cwd/+New Save Tty Collapse Del | 1 diff --git a/test/snapshots/respawn.golden b/test/snapshots/respawn.golden index 1e6425d2..4810f9d3 100644 --- a/test/snapshots/respawn.golden +++ b/test/snapshots/respawn.golden @@ -1,10 +1,10 @@ == snap respawn grid=140x31 cursor=4,9 -|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit -| New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol -| /tmp/pardes-snap/respawn/cwd Tty+bash Save Mode Filter Collapse Del /tmp/pardes-snap/respawn/cwd Tty+bash Save Mode Filter Collapse Del +| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +| New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol +| /tmp/pardes-snap/respawn/cwd Tty+bash Save Mode Filter Collapse Del /tmp/pardes-snap/respawn/cwd Tty+bash Save Mode Filter Collapse Del | ls ls | -|$ /tmp/pardes-snap/respawn/cwd Tty+bash Save Mode Filter Collapse Del +|$ /tmp/pardes-snap/respawn/cwd Tty+bash Save Mode Filter Collapse Del | $ ls | $ echo RESP''AWNOK | RESPAWNOK diff --git a/test/snapshots/restore.golden b/test/snapshots/restore.golden index 0bb53676..a8e39308 100644 --- a/test/snapshots/restore.golden +++ b/test/snapshots/restore.golden @@ -1,12 +1,12 @@ == snap dumped grid=100x31 cursor=4,6 -|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit Restore /tmp/pardes-snap -| New Tty Find Grep Joincol Delcol -|$ /tmp/pardes-snap/restore/cwd Tty+bash Save Mode Filter Collapse Del +| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit Restore /tmp/pardes-sn +| New Tty Find Grep Joincol Delcol +|$ /tmp/pardes-snap/restore/cwd Tty+bash Save Mode Filter Collapse Del | $ ls Dump | $ echo KEEP''ME | KEEPME | $ == snap restored grid=100x31 cursor=4,8 -|2: /tmp/pardes-snap/restore/cwd Tty+bash Save Mode Filter Collapse Del +|2: /tmp/pardes-snap/restore/cwd Tty+bash Save Mode Filter Collapse Del |3: $ ls |7: ── restored history ── diff --git a/test/snapshots/rsearch.golden b/test/snapshots/rsearch.golden index 870831b4..d69feb7a 100644 --- a/test/snapshots/rsearch.golden +++ b/test/snapshots/rsearch.golden @@ -1,17 +1,17 @@ == snap opened grid=210x31 cursor=7,7 -|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit -| New Tty Find Grep Joincol Delcol -| /tmp/pardes-snap/rsearch/cwd Tty+bash Save Mode Filter Collapse Del +| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +| New Tty Find Grep Joincol Delcol +| /tmp/pardes-snap/rsearch/cwd Tty+bash Save Mode Filter Collapse Del | ls | code.txt sub | -| /tmp/pardes-snap/rsearch/cwd/code.txt Save Tty Collapse Del +| /tmp/pardes-snap/rsearch/cwd/code.txt Save Tty Collapse Del | 1 run count_x now | 2 open sub/dep.txt:3 here | 3 count_x again | 4 pick two words == snap search grid=210x31 cursor=13,9 -|11: /tmp/pardes-snap/rsearch/cwd/+Search Save Tty Collapse Del LocationsConfig +|11: /tmp/pardes-snap/rsearch/cwd/+Search Save Tty Collapse LocationsConfig Del |12: 1 code.txt:1:5-11 |13: 2 run count_x now |14: 3 code.txt:3:1-7 @@ -24,7 +24,7 @@ |15: |16: == snap path-open grid=210x31 cursor=16,17 -|14: /tmp/pardes-snap/rsearch/cwd/sub/dep.txt Save Tty Collapse Del +|14: /tmp/pardes-snap/rsearch/cwd/sub/dep.txt Save Tty Collapse Del |15: 1 d1 |16: 2 d2 |17: 3 DEPTARGET diff --git a/test/snapshots/savepane.golden b/test/snapshots/savepane.golden index bea7146b..256b0074 100644 --- a/test/snapshots/savepane.golden +++ b/test/snapshots/savepane.golden @@ -1,7 +1,7 @@ == snap scratch grid=100x31 cursor=20,18 -|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit -| New Tty Find Grep Joincol Delcol -| /tmp/pardes-snap/savepane/cwd Tty+bash Save Mode Filter Collapse Del +| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +| New Tty Find Grep Joincol Delcol +| /tmp/pardes-snap/savepane/cwd Tty+bash Save Mode Filter Collapse Del | ls | | @@ -16,13 +16,13 @@ | | | -| * /tmp/pardes-snap/savepane/cwd/+New Save Tty Collapse Del +| */tmp/pardes-snap/savepane/cwd/+New Save Tty Collapse Del | 1 scratch bytes == snap prompt grid=100x31 cursor=99,19 |18: 1 scratch bytes Save |19: Save /tmp/pardes-snap/savepane/cwd/ == snap saved grid=100x31 cursor=20,18 -|17: /tmp/pardes-snap/savepane/cwd/saved.txt Save Tty Collapse Del +|17: /tmp/pardes-snap/savepane/cwd/saved.txt Save Tty Collapse Del |18: 1 scratch bytes --:--:-- saved /tmp/pardes-snap/savepane/cwd/saved.txt |19: == file bytes diff --git a/test/snapshots/scroll.golden b/test/snapshots/scroll.golden index 44b6b264..25bcd6ac 100644 --- a/test/snapshots/scroll.golden +++ b/test/snapshots/scroll.golden @@ -1,8 +1,8 @@ == snap bottom grid=100x31 cursor=4,16 -|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit -| New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol -| /tmp/pardes-snap/scroll/cwd Tty+bash Save Mode /tmp/pardes-snap/scroll/cwd Tty+bash Save Mode -| Filter Collapse Del Filter Collapse Del +| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +| New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol +| /tmp/pardes-snap/scroll/cwd Tty+bash Save Mode F /tmp/pardes-snap/scroll/cwd Tty+bash Save Mode F +| ilter Collapse Del ilter Collapse Del | 189 ls | 190 s.txt | 191 @@ -16,8 +16,8 @@ | 199 | 200 | -| /tmp/pardes-snap/scroll/cwd Tty+bash Save Mode -| Filter Collapse Del +| /tmp/pardes-snap/scroll/cwd Tty+bash Save Mode F +| ilter Collapse Del | ls | s.txt == snap wheel3 grid=100x31 cursor=4,16 @@ -77,10 +77,10 @@ |15: 193 |16: 194 == style wheel-down grid=100x31 -|0: 0-99 #b2c3b8,#1d2824, -|1: 0-1 d,#887455, 2-2 d,#314738, 3-49 #becfc4,#314738, 50-51 #becfc4,#887455, 52-52 #becfc4,#1d2824, 53-99 #b2c3b8,#1d2824, -|2: 0-1 d,#add38a, 2-2 d,#314738, 3-30 #becfc4,#314738, 31-39 #dfbce5,#314738, 40-49 #becfc4,#314738, 50-51 #becfc4,#496656, 52-52 #becfc4,#1d2824, 53-80 #b2c3b8,#1d2824, 81-89 #d3b0d9,#1d2824, 90-99 #b2c3b8,#1d2824, -|3: 0-2 d,#314738, 3-49 #becfc4,#314738, 50-52 #becfc4,#1d2824, 53-99 #b2c3b8,#1d2824, +|0: 0-1 d,#1d2824, 2-99 #b2c3b8,#1d2824, +|1: 0-1 d,#887455, 2-49 #becfc4,#314738, 50-51 #becfc4,#887455, 52-99 #b2c3b8,#1d2824, +|2: 0-1 d,#add38a, 2-29 #becfc4,#314738, 30-38 #dfbce5,#314738, 39-49 #becfc4,#314738, 50-51 #becfc4,#496656, 52-79 #b2c3b8,#1d2824, 80-88 #d3b0d9,#1d2824, 89-99 #b2c3b8,#1d2824, +|3: 0-1 d,#314738, 2-49 #becfc4,#314738, 50-51 #becfc4,#1d2824, 52-99 #b2c3b8,#1d2824, |4: 0-0 d,#152019, 1-1 d,#0d1410, 2-49 #e5eee5,#0d1410, 50-50 #e5eee5,#608269, 51-99 #e5eee5,#0d1410, |5: 0-0 d,#152019, 1-1 d,#0d1410, 2-49 #e5eee5,#0d1410, 50-50 #e5eee5,#608269, 51-99 #e5eee5,#0d1410, |6: 0-0 d,#152019, 1-1 d,#0d1410, 2-49 #e5eee5,#0d1410, 50-50 #e5eee5,#608269, 51-99 #e5eee5,#0d1410, @@ -94,8 +94,8 @@ |14: 0-0 d,#152019, 1-1 d,#0d1410, 2-49 #e5eee5,#0d1410, 50-50 #e5eee5,#608269, 51-99 #e5eee5,#0d1410, |15: 0-0 d,#608269, 1-1 d,#0d1410, 2-49 #e5eee5,#0d1410, 50-50 #e5eee5,#608269, 51-99 #e5eee5,#0d1410, |16: 0-0 d,#152019, 1-1 d,#0d1410, 2-49 #e5eee5,#0d1410, 50-50 #e5eee5,#608269, 51-99 #e5eee5,#0d1410, -|17: 0-1 d,#496656, 2-2 d,#1d2824, 3-30 #b2c3b8,#1d2824, 31-39 #d3b0d9,#1d2824, 40-49 #b2c3b8,#1d2824, 50-50 #b2c3b8,#608269, 51-99 #b2c3b8,#0d1410, -|18: 0-2 d,#1d2824, 3-49 #b2c3b8,#1d2824, 50-50 #b2c3b8,#608269, 51-99 #b2c3b8,#0d1410, +|17: 0-1 d,#496656, 2-29 #b2c3b8,#1d2824, 30-38 #d3b0d9,#1d2824, 39-49 #b2c3b8,#1d2824, 50-50 #b2c3b8,#608269, 51-99 #b2c3b8,#0d1410, +|18: 0-1 d,#1d2824, 2-49 #b2c3b8,#1d2824, 50-50 #b2c3b8,#608269, 51-99 #b2c3b8,#0d1410, |19: 0-0 d,#608269, 1-1 d,#0d1410, 2-49 #e5eee5,#0d1410, 50-50 #e5eee5,#608269, 51-99 #e5eee5,#0d1410, |20: 0-0 d,#608269, 1-1 d,#0d1410, 2-49 #e5eee5,#0d1410, 50-50 #e5eee5,#608269, 51-99 #e5eee5,#0d1410, |21: 0-0 d,#608269, 1-49 d,#0d1410, 50-50 d,#608269, 51-99 d,#0d1410, diff --git a/test/snapshots/scrolloff.golden b/test/snapshots/scrolloff.golden index 299df49d..b56d2c36 100644 --- a/test/snapshots/scrolloff.golden +++ b/test/snapshots/scrolloff.golden @@ -1,11 +1,11 @@ == snap top grid=210x16 cursor=7,7 -|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit -| New Tty Find Grep Joincol Delcol -| /tmp/pardes-snap/scrolloff/cwd Tty+bash Save Mode Filter Collapse Del +| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +| New Tty Find Grep Joincol Delcol +| /tmp/pardes-snap/scrolloff/cwd Tty+bash Save Mode Filter Collapse Del | ls | g.txt | -| /tmp/pardes-snap/scrolloff/cwd/g.txt Save Tty Collapse Del +| /tmp/pardes-snap/scrolloff/cwd/g.txt Save Tty Collapse Del | 1 line 1 | 2 line 2 | 3 line 3 diff --git a/test/snapshots/selarg.golden b/test/snapshots/selarg.golden index 741864ef..33338c6e 100644 --- a/test/snapshots/selarg.golden +++ b/test/snapshots/selarg.golden @@ -1,8 +1,8 @@ == snap kept grid=100x31 cursor=6,4 -|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit -| New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol -| /tmp/pardes-snap/selarg/cwd Tty+bash Save Mode /tmp/pardes-snap/selarg/cwd Tty+bash Save Mode -| Filter Collapse Del Filter Collapse Del +| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +| New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol +| /tmp/pardes-snap/selarg/cwd Tty+bash Save Mode F /tmp/pardes-snap/selarg/cwd Tty+bash Save Mode F +| ilter Collapse Del ilter Collapse Del | ZZARG ZZVEE ./c.sh | | @@ -16,8 +16,8 @@ | | | -| /tmp/pardes-snap/selarg/cwd Tty+bash Save Mode -| Filter Collapse Del +| /tmp/pardes-snap/selarg/cwd Tty+bash Save Mode F +| ilter Collapse Del | ls | s.txt == snap crosspane grid=100x31 cursor=6,4 diff --git a/test/snapshots/selregex.golden b/test/snapshots/selregex.golden index 480ad8a2..3fdab698 100644 --- a/test/snapshots/selregex.golden +++ b/test/snapshots/selregex.golden @@ -1,7 +1,7 @@ == snap prompt-armed grid=160x25 cursor=159,3 -|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit -| New Tty Find Grep Joincol Delcol -| /tmp/pardes-snap/selregex/cwd/m.zig Save Tty Collapse Del TreeContext Def Refs +| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +| New Tty Find Grep Joincol Delcol +| /tmp/pardes-snap/selregex/cwd/m.zig Save Tty Collapse TreeContext Def Refs Del | 1 const one = 1; Select / | 2 const two = 2; | 3 const three = 3; @@ -9,9 +9,9 @@ == snap preview grid=160x25 cursor=159,3 |3: 1 const one = 1; Select /const == style preview grid=160x25 -|0: 0-159 #b2c3b8,#1d2824, -|1: 0-1 d,#887455, 2-2 d,#314738, 3-159 #becfc4,#314738, -|2: 0-1 d,#add38a, 2-2 d,#314738, 3-32 #becfc4,#314738, 33-38 #dfbce5,#314738, 39-159 #becfc4,#314738, +|0: 0-1 d,#1d2824, 2-159 #b2c3b8,#1d2824, +|1: 0-1 d,#887455, 2-159 #becfc4,#314738, +|2: 0-1 d,#add38a, 2-31 #becfc4,#314738, 32-37 #dfbce5,#314738, 38-159 #becfc4,#314738, |3: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-10 #f5f7ee,#3c614a, 11-11 #3c614a,#f5f7ee, 12-12 #3c614a,#0d1410, 13-18 #e5eee5,#0d1410, 19-19 #f8c082,#0d1410, 20-143 #e5eee5,#0d1410, 144-145 #e5eee5,#1d2824, 146-159 #b2c3b8,#1d2824, |4: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-10 #f5f7ee,#243a2d, 11-11 #3c614a,#f5f7ee, 12-12 #3c614a,#0d1410, 13-18 #e5eee5,#0d1410, 19-19 #f8c082,#0d1410, 20-159 #e5eee5,#0d1410, |5: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-10 #f5f7ee,#243a2d, 11-11 #3c614a,#f5f7ee, 12-12 #3c614a,#0d1410, 13-20 #e5eee5,#0d1410, 21-21 #f8c082,#0d1410, 22-159 #e5eee5,#0d1410, @@ -51,12 +51,12 @@ |4: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-10 #f5f7ee,#243a2d, 11-11 #3c614a,#f5f7ee, 12-12 #3c614a,#0d1410, 13-18 #e5eee5,#0d1410, 19-19 #f8c082,#0d1410, 20-159 #e5eee5,#0d1410, |5: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-10 #f5f7ee,#243a2d, 11-11 #3c614a,#f5f7ee, 12-12 #3c614a,#0d1410, 13-20 #e5eee5,#0d1410, 21-21 #f8c082,#0d1410, 22-159 #e5eee5,#0d1410, == snap commented grid=160x25 cursor=14,3 -|2: * /tmp/pardes-snap/selregex/cwd/m.zig Save Tty Collapse Del TreeContext Def Refs +|2: */tmp/pardes-snap/selregex/cwd/m.zig Save Tty Collapse TreeContext Def Refs Del |3: 1 // const one = 1; |4: 2 // const two = 2; |5: 3 // const three = 3; == snap uncommented grid=160x25 cursor=11,3 -|2: /tmp/pardes-snap/selregex/cwd/m.zig Save Tty Collapse Del TreeContext Def Refs +|2: /tmp/pardes-snap/selregex/cwd/m.zig Save Tty Collapse TreeContext Def Refs Del |3: 1 const one = 1; |4: 2 const two = 2; |5: 3 const three = 3; diff --git a/test/snapshots/shellset.golden b/test/snapshots/shellset.golden index 9d566be7..21875eca 100644 --- a/test/snapshots/shellset.golden +++ b/test/snapshots/shellset.golden @@ -1,13 +1,13 @@ == snap boot grid=90x21 cursor=7,3 -|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit -| New Tty Find Grep Joincol Delcol -| /tmp/pardes-snap/shellset/cwd/cmd.txt Save Tty Collapse Del +| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +| New Tty Find Grep Joincol Delcol +| /tmp/pardes-snap/shellset/cwd/cmd.txt Save Tty Collapse Del | 1 Shell zznosuchshell == snap builtin-ran grid=90x21 cursor=25,3 |3: Shell: shell "zznosuchshell" not found (a name on the usual paths, or a path to one) == snap fallback-shell grid=90x21 cursor=49,6 -|1: New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol -|2: /tmp/pardes-snap/shellset/cwd/cmd.txt Save /tmp/pardes-snap/shellset/cwd Tty+bash Sav -|3: Tty Collapse Del e Mode Filter Collapse Del +|1: New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol +|2: /tmp/pardes-snap/shellset/cwd/cmd.txt Save /tmp/pardes-snap/shellset/cwd Tty+bash Save +|3: Tty Collapse Del Mode Filter Collapse Del |4: 1 Shell zznosuchshell ls |5: cmd.txt zmarkfile.txt diff --git a/test/snapshots/shrinktag.golden b/test/snapshots/shrinktag.golden index 6e64d89b..dc27a579 100644 --- a/test/snapshots/shrinktag.golden +++ b/test/snapshots/shrinktag.golden @@ -1,8 +1,8 @@ == snap before grid=100x31 cursor=4,9 -|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit -| New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol -| /tmp/pardes-snap/shrinktag/cwd Tty+bash Save Mo /tmp/pardes-snap/shrinktag/cwd Tty+bash Save Mo -| de Filter Collapse Del de Filter Collapse Del +| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +| New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol +| /tmp/pardes-snap/shrinktag/cwd Tty+bash Save Mod /tmp/pardes-snap/shrinktag/cwd Tty+bash Save Mod +| e Filter Collapse Del e Filter Collapse Del | ls ls | w.txt w.txt | @@ -16,15 +16,15 @@ | | | -| /tmp/pardes-snap/shrinktag/cwd Tty+bash Save Mo -| de Filter Collapse Del +| /tmp/pardes-snap/shrinktag/cwd Tty+bash Save Mod +| e Filter Collapse Del | ls | w.txt == snap shrunk grid=100x31 cursor=4,9 |4: w.txt ls |5: w.txt -|6: /tmp/pardes-snap/shrinktag/cwd Tty+bash Save Mo -|7: de Filter Collapse Del +|6: /tmp/pardes-snap/shrinktag/cwd Tty+bash Save Mod +|7: e Filter Collapse Del |8: ls |9: w.txt |17: @@ -40,8 +40,8 @@ |7: |8: echo one; echo two |9: -|17: /tmp/pardes-snap/shrinktag/cwd Tty+bash Save Mo -|18: de Filter Collapse Del +|17: /tmp/pardes-snap/shrinktag/cwd Tty+bash Save Mod +|18: e Filter Collapse Del |19: ls |20: w.txt == snap bottom-shrunk grid=100x31 cursor=4,9 @@ -49,6 +49,6 @@ |18: |19: |20: -|27: /tmp/pardes-snap/shrinktag/cwd Tty+bash Save Mo -|28: de Filter Collapse Del +|27: /tmp/pardes-snap/shrinktag/cwd Tty+bash Save Mod +|28: e Filter Collapse Del |29: w.txt diff --git a/test/snapshots/splitparent.golden b/test/snapshots/splitparent.golden index f83bbb66..0e870a37 100644 --- a/test/snapshots/splitparent.golden +++ b/test/snapshots/splitparent.golden @@ -1,35 +1,35 @@ == snap shrunk grid=100x31 cursor=4,5 -|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit -| New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol -| /tmp/pardes-snap/splitparent/cwd Tty+bash Save /tmp/pardes-snap/splitparent/cwd Tty+bash Save -| Mode Filter Collapse Del Mode Filter Collapse Del +| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +| New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol +| /tmp/pardes-snap/splitparent/cwd Tty+bash Save M /tmp/pardes-snap/splitparent/cwd Tty+bash Save M +| ode Filter Collapse Del ode Filter Collapse Del | ls ls | -| /tmp/pardes-snap/splitparent/cwd Tty+bash Save -| Mode Filter Collapse Del +| /tmp/pardes-snap/splitparent/cwd Tty+bash Save M +| ode Filter Collapse Del | ls == snap swap-parent grid=100x31 cursor=4,13 -|10: /tmp/pardes-snap/splitparent/cwd Tty+bash Save -|11: Mode Filter Collapse Del +|10: /tmp/pardes-snap/splitparent/cwd Tty+bash Save M +|11: ode Filter Collapse Del |12: ls == snap tallest grid=100x6 cursor=4,5 -|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit -| New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol -| /tmp/pardes-snap/splitparent/cwd Tty+bash Save /tmp/pardes-snap/splitparent/cwd Tty+bash Save -| /tmp/pardes-snap/splitparent/cwd Tty+bash Save Mode Filter Collapse Del -| /tmp/pardes-snap/splitparent/cwd Tty+bash Save ls +| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +| New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol +| /tmp/pardes-snap/splitparent/cwd Tty+bash Save M /tmp/pardes-snap/splitparent/cwd Tty+bash Save M +| /tmp/pardes-snap/splitparent/cwd Tty+bash Save M ode Filter Collapse Del +| /tmp/pardes-snap/splitparent/cwd Tty+bash Save M ls | e in that column: each keeps its tag and 2 rows == snap regrown grid=100x31 cursor=4,13 -|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit -| New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol -| /tmp/pardes-snap/splitparent/cwd Tty+bash Save /tmp/pardes-snap/splitparent/cwd Tty+bash Save -| Mode Filter Collapse Del Mode Filter Collapse Del +| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +| New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol +| /tmp/pardes-snap/splitparent/cwd Tty+bash Save M /tmp/pardes-snap/splitparent/cwd Tty+bash Save M +| ode Filter Collapse Del ode Filter Collapse Del | ls ls | -| /tmp/pardes-snap/splitparent/cwd Tty+bash Save -| Mode Filter Collapse Del +| /tmp/pardes-snap/splitparent/cwd Tty+bash Save M +| ode Filter Collapse Del | ls | -| /tmp/pardes-snap/splitparent/cwd Tty+bash Save -| Mode Filter Collapse Del +| /tmp/pardes-snap/splitparent/cwd Tty+bash Save M +| ode Filter Collapse Del | e in that column: each keeps its tag and 2 rows diff --git a/test/snapshots/stepgrain.golden b/test/snapshots/stepgrain.golden index 7c445492..3101b920 100644 --- a/test/snapshots/stepgrain.golden +++ b/test/snapshots/stepgrain.golden @@ -1,10 +1,10 @@ == snap results grid=150x31 cursor=7,3 -|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit -| New Tty Find Grep Joincol Delcol -| /tmp/pardes-snap/stepgrain/cwd/a.txt Save Tty Collapse Del +| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +| New Tty Find Grep Joincol Delcol +| /tmp/pardes-snap/stepgrain/cwd/a.txt Save Tty Collapse Del | 1 hello ZQMARK one | 2 see also sub/b.txt for ZQMARK two -| /tmp/pardes-snap/stepgrain/cwd/+Search Save Tty Collapse Del LocationsConfig +| /tmp/pardes-snap/stepgrain/cwd/+Search Save Tty Collapse LocationsConfig Del | 1 a.txt:1:7-12 | 2 hello ZQMARK one | 3 a.txt:2:24-29 @@ -14,12 +14,12 @@ | 7 == snap step-row1 grid=150x31 cursor=7,6 == style step-row1 grid=150x31 -|0: 0-149 #b2c3b8,#1d2824, -|1: 0-1 d,#887455, 2-2 d,#314738, 3-149 #becfc4,#314738, -|2: 0-1 d,#496656, 2-2 d,#1d2824, 3-33 #b2c3b8,#1d2824, 34-39 #d3b0d9,#1d2824, 40-149 #b2c3b8,#1d2824, +|0: 0-1 d,#1d2824, 2-149 #b2c3b8,#1d2824, +|1: 0-1 d,#887455, 2-149 #becfc4,#314738, +|2: 0-1 d,#496656, 2-32 #b2c3b8,#1d2824, 33-38 #d3b0d9,#1d2824, 39-149 #b2c3b8,#1d2824, |3: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-149 #e5eee5,#0d1410, |4: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-149 #e5eee5,#0d1410, -|5: 0-1 d,#add38a, 2-2 d,#314738, 3-33 #becfc4,#314738, 34-41 #dfbce5,#314738, 42-149 #becfc4,#314738, +|5: 0-1 d,#add38a, 2-32 #becfc4,#314738, 33-40 #dfbce5,#314738, 41-149 #becfc4,#314738, |6: 0-0 d,#608269, 1-1 d,#0d1410, 2-4 d,#0d1410,b 5-6 #616f64,#0d1410,b 7-18 #f5f7ee,#3c614a, 19-149 #f5f7ee,#0d1410, |7: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-12 #e5eee5,#0d1410, 13-18 #f7e4a5,#5e4923, 19-19 #f7e4a5,#0d1410, 20-149 #e5eee5,#0d1410, |8: 0-0 d,#608269, 1-4 d,#0d1410, 5-149 #59675c,#0d1410, @@ -52,7 +52,7 @@ == snap step-row3 grid=150x31 cursor=7,10 == snap step-wrap grid=150x31 cursor=7,6 == snap blank-in-path grid=150x31 cursor=7,6 -|5: /tmp/pardes-snap/stepgrain/cwd/+Search Save Tty Collapse Del +|5: /tmp/pardes-snap/stepgrain/cwd/+Search Save Tty Collapse Del |6: 1 two words.txt |7: 2 |8: @@ -69,5 +69,5 @@ |11: 0-0 d,#608269, 1-149 d,#0d1410, |12: 0-0 d,#608269, 1-149 d,#0d1410, == snap blank-opened grid=150x31 cursor=7,9 -|8: /tmp/pardes-snap/stepgrain/cwd/two words.txt Save Tty Collapse Del +|8: /tmp/pardes-snap/stepgrain/cwd/two words.txt Save Tty Collapse Del |9: 1 diff --git a/test/snapshots/syntax.golden b/test/snapshots/syntax.golden index 43bfe485..c4f44b86 100644 --- a/test/snapshots/syntax.golden +++ b/test/snapshots/syntax.golden @@ -1,12 +1,12 @@ == snap zig-open grid=150x31 cursor=7,8 -|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit -| New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol -| /tmp/pardes-snap/syntax/cwd Tty+bash Save Mode Filter Collapse Del /tmp/pardes-snap/syntax/cwd Tty+bash Save Mode Filter Collapse Del +| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +| New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol +| /tmp/pardes-snap/syntax/cwd Tty+bash Save Mode Filter Collapse Del /tmp/pardes-snap/syntax/cwd Tty+bash Save Mode Filter Collapse Del | ls ls | demo.zig demo.zig | -| /tmp/pardes-snap/syntax/cwd/demo.zig Save Tty Collapse Del TreeContext D -| ef Refs +| /tmp/pardes-snap/syntax/cwd/demo.zig Save Tty Collapse TreeContext Def Re +| fs Del | 1 const std = @import("std"); // greet | 2 pub fn main() void { | 3 var x: u32 = 42; @@ -16,18 +16,18 @@ | | | -| /tmp/pardes-snap/syntax/cwd Tty+bash Save Mode Filter Collapse Del +| /tmp/pardes-snap/syntax/cwd Tty+bash Save Mode Filter Collapse Del | ls | demo.zig == style zig-open grid=150x31 -|0: 0-149 #b2c3b8,#1d2824, -|1: 0-1 d,#887455, 2-2 d,#314738, 3-74 #becfc4,#314738, 75-76 #becfc4,#887455, 77-77 #becfc4,#1d2824, 78-149 #b2c3b8,#1d2824, -|2: 0-1 d,#496656, 2-2 d,#1d2824, 3-30 #b2c3b8,#1d2824, 31-39 #d3b0d9,#1d2824, 40-74 #b2c3b8,#1d2824, 75-76 #b2c3b8,#496656, 77-105 #b2c3b8,#1d2824, 106-114 #d3b0d9,#1d2824, 115-149 #b2c3b8,#1d2824, +|0: 0-1 d,#1d2824, 2-149 #b2c3b8,#1d2824, +|1: 0-1 d,#887455, 2-74 #becfc4,#314738, 75-76 #becfc4,#887455, 77-149 #b2c3b8,#1d2824, +|2: 0-1 d,#496656, 2-29 #b2c3b8,#1d2824, 30-38 #d3b0d9,#1d2824, 39-74 #b2c3b8,#1d2824, 75-76 #b2c3b8,#496656, 77-104 #b2c3b8,#1d2824, 105-113 #d3b0d9,#1d2824, 114-149 #b2c3b8,#1d2824, |3: 0-0 d,#608269, 1-1 d,#0d1410, 2-74 #e5eee5,#0d1410, 75-75 #e5eee5,#608269, 76-149 #e5eee5,#0d1410, |4: 0-0 d,#608269, 1-1 d,#0d1410, 2-74 #e5eee5,#0d1410, 75-75 #e5eee5,#608269, 76-149 #e5eee5,#0d1410, |5: 0-0 d,#608269, 1-74 d,#0d1410, 75-75 d,#608269, 76-149 d,#0d1410, -|6: 0-1 d,#add38a, 2-2 d,#314738, 3-30 #becfc4,#314738, 31-39 #dfbce5,#314738, 40-74 #becfc4,#314738, 75-75 #becfc4,#608269, 76-149 #becfc4,#0d1410, -|7: 0-2 d,#314738, 3-74 #becfc4,#314738, 75-75 #becfc4,#608269, 76-149 #becfc4,#0d1410, +|6: 0-1 d,#add38a, 2-29 #becfc4,#314738, 30-38 #dfbce5,#314738, 39-74 #becfc4,#314738, 75-75 #becfc4,#608269, 76-149 #becfc4,#0d1410, +|7: 0-1 d,#314738, 2-74 #becfc4,#314738, 75-75 #becfc4,#608269, 76-149 #becfc4,#0d1410, |8: 0-0 d,#608269, 1-1 d,#0d1410, 2-4 d,#0d1410,b 5-6 #616f64,#0d1410,b 7-18 #e5eee5,#0d1410, 19-25 #c9a7ed,#0d1410, 26-26 #e5eee5,#0d1410, 27-31 #b8d88a,#0d1410, 32-34 #e5eee5,#0d1410, 35-74 #b9f480,#0d1410, 75-75 #b9f480,#608269, 76-149 #b9f480,#0d1410, |9: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-10 #e5eee5,#0d1410, 11-13 #c9a7ed,#0d1410, 14-74 #e5eee5,#0d1410, 75-75 #e5eee5,#608269, 76-149 #e5eee5,#0d1410, |10: 0-0 d,#608269, 1-4 d,#0d1410, 5-10 #59675c,#0d1410, 11-23 #e5eee5,#0d1410, 24-25 #f8c082,#0d1410, 26-74 #e5eee5,#0d1410, 75-75 #e5eee5,#608269, 76-149 #e5eee5,#0d1410, @@ -37,7 +37,7 @@ |14: 0-0 d,#608269, 1-74 d,#0d1410, 75-75 d,#608269, 76-149 d,#0d1410, |15: 0-0 d,#608269, 1-74 d,#0d1410, 75-75 d,#608269, 76-149 d,#0d1410, |16: 0-0 d,#608269, 1-74 d,#0d1410, 75-75 d,#608269, 76-149 d,#0d1410, -|17: 0-1 d,#496656, 2-2 d,#1d2824, 3-30 #b2c3b8,#1d2824, 31-39 #d3b0d9,#1d2824, 40-74 #b2c3b8,#1d2824, 75-75 #b2c3b8,#608269, 76-149 #b2c3b8,#0d1410, +|17: 0-1 d,#496656, 2-29 #b2c3b8,#1d2824, 30-38 #d3b0d9,#1d2824, 39-74 #b2c3b8,#1d2824, 75-75 #b2c3b8,#608269, 76-149 #b2c3b8,#0d1410, |18: 0-0 d,#608269, 1-1 d,#0d1410, 2-74 #e5eee5,#0d1410, 75-75 #e5eee5,#608269, 76-149 #e5eee5,#0d1410, |19: 0-0 d,#608269, 1-1 d,#0d1410, 2-74 #e5eee5,#0d1410, 75-75 #e5eee5,#608269, 76-149 #e5eee5,#0d1410, |20: 0-0 d,#608269, 1-74 d,#0d1410, 75-75 d,#608269, 76-149 d,#0d1410, diff --git a/test/snapshots/tag.golden b/test/snapshots/tag.golden index 0d20859a..6e86f042 100644 --- a/test/snapshots/tag.golden +++ b/test/snapshots/tag.golden @@ -1,7 +1,7 @@ -== snap tag-focus grid=150x31 cursor=36,2 -|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit -| New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol -| /tmp/pardes-snap/tag/cwd Tty+bash Save Mode Filter Collapse Del /tmp/pardes-snap/tag/cwd Tty+bash Save Mode Filter Collapse Del +== snap tag-focus grid=150x31 cursor=35,2 +| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +| New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol +| /tmp/pardes-snap/tag/cwd Tty+bash Save Mode Filter Collapse Del /tmp/pardes-snap/tag/cwd Tty+bash Save Mode Filter Collapse Del | ls ls | t.txt t.txt | @@ -16,15 +16,15 @@ | | | -| /tmp/pardes-snap/tag/cwd Tty+bash Save Mode Filter Collapse Del +| /tmp/pardes-snap/tag/cwd Tty+bash Save Mode Filter Collapse Del | ls | t.txt -== snap tag-typed grid=150x31 cursor=42,2 -|2: /tmp/pardes-snap/tag/cwd Tty+bash t.txt Save Mode Filter Collapse Del /tmp/pardes-snap/tag/cwd Tty+bash Save Mode Filter Collapse Del -== snap tag-del grid=150x31 cursor=38,2 -|2: /tmp/pardes-snap/tag/cwd Tty+bash t Save Mode Filter Collapse Del /tmp/pardes-snap/tag/cwd Tty+bash Save Mode Filter Collapse Del +== snap tag-typed grid=150x31 cursor=41,2 +|2: /tmp/pardes-snap/tag/cwd Tty+bash t.txt Save Mode Filter Collapse Del /tmp/pardes-snap/tag/cwd Tty+bash Save Mode Filter Collapse Del +== snap tag-del grid=150x31 cursor=37,2 +|2: /tmp/pardes-snap/tag/cwd Tty+bash t Save Mode Filter Collapse Del /tmp/pardes-snap/tag/cwd Tty+bash Save Mode Filter Collapse Del == snap tag-exit grid=150x31 cursor=4,5 -|2: /tmp/pardes-snap/tag/cwd Tty+bash t.txt Save Mode Filter Collapse Del /tmp/pardes-snap/tag/cwd Tty+bash Save Mode Filter Collapse Del +|2: /tmp/pardes-snap/tag/cwd Tty+bash t.txt Save Mode Filter Collapse Del /tmp/pardes-snap/tag/cwd Tty+bash Save Mode Filter Collapse Del == snap tag-look grid=150x31 cursor=7,7 -|6: /tmp/pardes-snap/tag/cwd/t.txt Save Tty Collapse Del +|6: /tmp/pardes-snap/tag/cwd/t.txt Save Tty Collapse Del |7: 1 ZZLOOKED diff --git a/test/snapshots/tagalign.golden b/test/snapshots/tagalign.golden index a557ff95..0fa4807a 100644 --- a/test/snapshots/tagalign.golden +++ b/test/snapshots/tagalign.golden @@ -1,60 +1,58 @@ == snap aligned grid=100x31 cursor=4,9 -|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit -| New Tty Find Grep Joincol Delcol -| /tmp/pardes-snap/tagalign/cwd/deep/nested-project-directory/document.txt Save Tty Collapse Del +| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +| New Tty Find Grep Joincol Delcol +| /tmp/pardes-snap/tagalign/cwd/deep/nested-project-directory/document.txt Save Tty Collapse Del | 1 alpha | 2 beta | 3 gamma -| /tmp/pardes-snap/tagalign/cwd Tty+bash Save Mode Filter Collapse Del +| /tmp/pardes-snap/tagalign/cwd Tty+bash Save Mode Filter Collapse Del | ls | deep == snap fits grid=87x31 cursor=4,9 -|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit -| New Tty Find Grep Joincol Delcol -| /tmp/pardes-snap/tagalign/cwd/deep/nested-project-directory/document.txt Save Tty Co -| llapse Del +| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +| New Tty Find Grep Joincol Delcol +| /tmp/pardes-snap/tagalign/cwd/deep/nested-project-directory/document.txt Save Tty Col +| lapse Del | 1 alpha | 2 beta -| /tmp/pardes-snap/tagalign/cwd Tty+bash Save Mode Filter Collapse Del +| /tmp/pardes-snap/tagalign/cwd Tty+bash Save Mode Filter Collapse Del | ls | deep == snap overby1 grid=86x31 cursor=4,9 -|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit -| New Tty Find Grep Joincol Delcol -| /tmp/pardes-snap/tagalign/cwd/deep/nested-project-directory/document.txt Save Tty C -| ollapse Del +| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +| New Tty Find Grep Joincol Delcol +| /tmp/pardes-snap/tagalign/cwd/deep/nested-project-directory/document.txt Save Tty Co +| llapse Del | 1 alpha | 2 beta -| /tmp/pardes-snap/tagalign/cwd Tty+bash Save Mode Filter Collapse Del +| /tmp/pardes-snap/tagalign/cwd Tty+bash Save Mode Filter Collapse Del | ls | deep == snap clicked grid=100x31 cursor=11,2 -|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit -| New Tty Find Grep Joincol Delcol -| /tmp/pardes-snap/tagalign/cwd/deep/nested-project-directory/document.txt Save Tty Collapse Del +| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +| New Tty Find Grep Joincol Delcol +| /tmp/pardes-snap/tagalign/cwd/deep/nested-project-directory/document.txt Save Tty Collapse Del | 1 alpha | 2 beta | 3 gamma -| /tmp/pardes-snap/tagalign/cwd Tty+bash Save Mode Filter Collapse Del +| /tmp/pardes-snap/tagalign/cwd Tty+bash Save Mode Filter Collapse Del | ls | deep -== snap revealed grid=70x31 cursor=30,3 -|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug -| New Tty Find Grep Joincol Delcol -| /tmp/pardes-snap/tagalign/cwd/deep/nested-project-directory/documen -| t.txt Save Tty Collapse Del +== snap revealed grid=70x31 cursor=28,3 +| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Deb +| New Tty Find Grep Joincol Delcol +| /tmp/pardes-snap/tagalign/cwd/deep/nested-project-directory/document +| .txt Save Tty Collapse Del | 1 alpha | 2 beta -| /tmp/pardes-snap/tagalign/cwd Tty+bash Save Mode Filter Collapse De -| l +| /tmp/pardes-snap/tagalign/cwd Tty+bash Save Mode Filter Collapse Del | ls | deep -== snap alone grid=70x31 cursor=4,6 -|2: /tmp/pardes-snap/tagalign/cwd Tty+bash Save Mode Filter Collapse De -|3: l -|4: ls -|5: deep +== snap alone grid=70x31 cursor=4,5 +|2: /tmp/pardes-snap/tagalign/cwd Tty+bash Save Mode Filter Collapse Del +|3: ls +|4: deep +|5: |6: |7: |8: -|9: diff --git a/test/snapshots/tagalign2col.golden b/test/snapshots/tagalign2col.golden index 129141b6..6c4b997a 100644 --- a/test/snapshots/tagalign2col.golden +++ b/test/snapshots/tagalign2col.golden @@ -1,26 +1,25 @@ -== snap onecol grid=160x31 cursor=7,4 -|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit -| New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol -| /tmp/pardes-snap/tagalign2col/cwd/deep/proj/document.txt Save Tty Collapse De /tmp/pardes-snap/tagalign2col/cwd Tty+bash Save Mode Filter Collapse Del -| l ls Left -| 1 alpha deep -| 2 beta +== snap onecol grid=160x31 cursor=7,3 +| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +| New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol +| /tmp/pardes-snap/tagalign2col/cwd/deep/proj/document.txt Save Tty Collapse Del /tmp/pardes-snap/tagalign2col/cwd Tty+bash Save Mode Filter Collapse Del +| 1 alpha ls Left +| 2 beta deep | 3 gamma -== snap aligned grid=160x31 cursor=4,10 -|3: l ls -|7: /tmp/pardes-snap/tagalign2col/cwd Tty+bash Save Mode Filter Collapse Del -|8: ls -|9: deep -== snap widened grid=160x31 cursor=4,10 -|1: New Tty Find Grep Joincol Delcol ╎ New Tty Find Grep Joincol Delcol -|2: /tmp/pardes-snap/tagalign2col/cwd/deep/proj/document.txt Save Tty Collapse Del ╎ /tmp/pardes-snap/tagalign2col/cwd Tty+bash Save Mode Filt -|3: 1 alpha ╎ er Collapse Del +== snap aligned grid=160x31 cursor=4,9 +|3: 1 alpha ls +|6: /tmp/pardes-snap/tagalign2col/cwd Tty+bash Save Mode Filter Collapse Del +|7: ls +|8: deep +== snap widened grid=160x31 cursor=4,9 +|1: New Tty Find Grep Joincol Delcol ╎ New Tty Find Grep Joincol Delcol +|2: /tmp/pardes-snap/tagalign2col/cwd/deep/proj/document.txt Save Tty Collapse Del ╎ /tmp/pardes-snap/tagalign2col/cwd Tty+bash Save Mode Filte +|3: 1 alpha ╎ r Collapse Del |4: 2 beta ╎ ls |5: 3 gamma ╎ deep -|6: ╎ -|7: /tmp/pardes-snap/tagalign2col/cwd Tty+bash Save Mode Filter Collapse Del ╎ -|8: ls ╎ -|9: deep ╎ +|6: /tmp/pardes-snap/tagalign2col/cwd Tty+bash Save Mode Filter Collapse Del ╎ +|7: ls ╎ +|8: deep ╎ +|9: ╎ |10: ╎ |11: ╎ |12: ╎ diff --git a/test/snapshots/tagbottom.golden b/test/snapshots/tagbottom.golden index 8469c741..ef1bab3a 100644 --- a/test/snapshots/tagbottom.golden +++ b/test/snapshots/tagbottom.golden @@ -1,7 +1,7 @@ == snap boot grid=100x31 cursor=7,3 -|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit -| New Tty Find Grep Joincol Delcol -| /tmp/pardes-snap/tagbottom/cwd/top.txt Save Tty Collapse Del +| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +| New Tty Find Grep Joincol Delcol +| /tmp/pardes-snap/tagbottom/cwd/top.txt Save Tty Collapse Del | 1 aaa | 2 bbb | 3 ccc @@ -56,9 +56,9 @@ |26: 25 yyy |27: 26 zzz |28: -|30: /tmp/pardes-snap/tagbottom/cwd/top.txt Save Tty Collapse Del +|30: /tmp/pardes-snap/tagbottom/cwd/top.txt Save Tty Collapse Del == snap off grid=100x31 cursor=7,3 -|2: /tmp/pardes-snap/tagbottom/cwd/top.txt Save Tty Collapse Del +|2: /tmp/pardes-snap/tagbottom/cwd/top.txt Save Tty Collapse Del |3: 1 aaa |4: 2 bbb |5: 3 ccc @@ -86,7 +86,7 @@ |27: 25 yyy |28: 26 zzz |30: -== snap tag-typed grid=100x31 cursor=74,30 +== snap tag-typed grid=100x31 cursor=73,30 |2: 1 aaa |3: 2 bbb |4: 3 ccc @@ -114,9 +114,9 @@ |26: 25 yyy |27: 26 zzz |28: -|30: /tmp/pardes-snap/tagbottom/cwd/top.txt Save Tty Collapse Del bottom.txt +|30: /tmp/pardes-snap/tagbottom/cwd/top.txt Save Tty Collapse Del bottom.txt == snap look-bottom-tag grid=100x31 cursor=7,16 -|15: /tmp/pardes-snap/tagbottom/cwd/top.txt Save Tty Collapse Del bottom.txt +|15: /tmp/pardes-snap/tagbottom/cwd/top.txt Save Tty Collapse Del bottom.txt |16: 1 ZZONE |17: 2 ZZTWO |18: @@ -129,11 +129,11 @@ |25: |26: |27: -|30: /tmp/pardes-snap/tagbottom/cwd/bottom.txt Save Tty Collapse Del +|30: /tmp/pardes-snap/tagbottom/cwd/bottom.txt Save Tty Collapse Del == snap body-cursor grid=100x31 cursor=9,6 == snap seam-noop grid=100x31 cursor=12,16 == snap seam-dragged grid=100x31 cursor=12,12 -|11: /tmp/pardes-snap/tagbottom/cwd/top.txt Save Tty Collapse Del bottom.txt +|11: /tmp/pardes-snap/tagbottom/cwd/top.txt Save Tty Collapse Del bottom.txt |12: 1 ZZONE |13: 2 ZZTWO |14: @@ -164,7 +164,7 @@ |8: 7 mmm |9: 8 nnn |10: 9 ooo -|11: * /tmp/pardes-snap/tagbottom/cwd/top.txt Save Tty Collapse Del bottom.txt +|11: */tmp/pardes-snap/tagbottom/cwd/top.txt Save Tty Collapse Del bottom.txt |12: 1 ZZONE == file cut-buffer aaa @@ -200,9 +200,9 @@ zzz |19: 18 xxx |20: 19 yyy |21: 20 zzz -|30: /tmp/pardes-snap/tagbottom/cwd/top.txt Save Tty Collapse Del bottom.txt +|30: /tmp/pardes-snap/tagbottom/cwd/top.txt Save Tty Collapse Del bottom.txt == snap off-again grid=100x31 cursor=7,6 -|2: /tmp/pardes-snap/tagbottom/cwd/top.txt Save Tty Collapse Del bottom.txt +|2: /tmp/pardes-snap/tagbottom/cwd/top.txt Save Tty Collapse Del bottom.txt |3: 1 aaa |4: 2 bbb |5: 3 ccc diff --git a/test/snapshots/tagbottomimage.golden b/test/snapshots/tagbottomimage.golden index ce6948bf..9f3ff2fd 100644 --- a/test/snapshots/tagbottomimage.golden +++ b/test/snapshots/tagbottomimage.golden @@ -1,11 +1,11 @@ == snap img-top grid=150x31 cursor=11,8 -|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit -| New Tty Find Grep Joincol Delcol -| /tmp/pardes-snap/tagbottomimage/cwd Tty+bash Save Mode Filter Collapse Del +| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +| New Tty Find Grep Joincol Delcol +| /tmp/pardes-snap/tagbottomimage/cwd Tty+bash Save Mode Filter Collapse Del | ls | pic.ppm | -| img petscii:on palette:commodore ascii:on /tmp/pardes-snap/tagbottomimage/cwd/pic.ppm Tty Collapse Del +| img petscii:on palette:commodore ascii:on /tmp/pardes-snap/tagbottomimage/cwd/pic.ppm Tty Collapse Del | 4*🬹~F~N🬰|G🬏▚Y~KF🬴s>T&zZ/🬻iTY=`S~╳bkZR37v🬦🬵d4QHZ8X▛▟ | ^🬪🬛$}DrydNU&wsz=`*r🬒🬓🬳🬟*Y🬴G6🬧f🬮/>t🬧u🬲1Rg1t🬝🬻█ @@ -34,7 +34,7 @@ |2: ls |3: pic.ppm |4: -|5: /tmp/pardes-snap/tagbottomimage/cwd Tty+bash Save Mode Filter Collapse Del +|5: /tmp/pardes-snap/tagbottomimage/cwd Tty+bash Save Mode Filter Collapse Del |6: Tagbottom |7: {DbgY🬲s▜M^#▐FUJ[zNq=🬝g/y╱?V@🬱🬙▌UK╱🬍("🬕KJ8hSo🬝🬻 |8: tX🬆s>🬌`🬵 Date: Fri, 23 Oct 2026 10:56:33 -0300 Subject: Audit (core, modal): goto/insert/select tables, edit through sam.Op and sam.apply, Turn.bump and awaitPast, dead helpers out Co-Authored-By: Claude Opus 5.5 --- src/9p_io.zig | 12 +-- src/Output.zig | 2 +- src/builtins.zig | 2 +- src/detached/server.zig | 2 +- src/edit.zig | 107 +++++++-------------- src/edit_cmd.zig | 6 +- src/exec.zig | 82 +++++++--------- src/gui/gui.zig | 32 +++---- src/look.zig | 4 +- src/macos.zig | 4 +- src/mini.zig | 6 +- src/modal.zig | 76 +++------------ src/ninep/ctl.zig | 4 +- src/ninep/pane.zig | 2 +- src/pardes.zig | 244 +++++++++++++++--------------------------------- src/sam_edit.zig | 36 +++---- src/tty/tty.zig | 2 +- test/output.zig | 2 +- test/panes.zig | 44 ++++----- test/pdf.zig | 18 ++-- 20 files changed, 237 insertions(+), 450 deletions(-) (limited to 'src/Output.zig') diff --git a/src/9p_io.zig b/src/9p_io.zig index 87972b43..a825475f 100644 --- a/src/9p_io.zig +++ b/src/9p_io.zig @@ -343,7 +343,7 @@ pub const Listener = struct { @memcpy(words, reply.ename[0..words.len]); var waited = reply; waited.ename = words; - pardes.turn.awaitSettled(epoch); + pardes.turn.awaitPast(&pardes.turn.epoch, epoch); return conn.reply(&waited, ""); } // Any other refusal answers at once, for the same buffer's sake. @@ -371,11 +371,11 @@ pub const Listener = struct { core.fs.late_failure_len = 0; // What fails while this waits is this write's err, never a msg too. core.fs.write_waits = true; - if (core.effects_len != 0) pardes.turn.awaitSettled(epoch); + if (core.effects_len != 0) pardes.turn.awaitPast(&pardes.turn.epoch, epoch); if (core.fs.lsp_answer_at) |n| { core.fs.lsp_answer_at = null; core.fs.lsp_result = null; - pardes.turn.awaitLsp(n); + pardes.turn.awaitPast(&pardes.turn.lsp_answers, n); // The answer filled a pane (a Rename's preview): that is what // this write's open reads back, as look and exec answer. if (l.core == core) if (core.fs.lsp_result) |serial| { @@ -410,7 +410,7 @@ pub const Listener = struct { // hears that it happened rather than a cut; a failed one leaves the // connection and says why on the message row and in the log. if (restoring) { - if (l.core == core) pardes.turn.awaitRestored(restores); + if (l.core == core) pardes.turn.awaitPast(&pardes.turn.restores, restores); return conn.reply(&reply, ""); } // Once a wait returns `core` may be gone: a Restore meanwhile put a @@ -695,8 +695,8 @@ pub const Listener = struct { // fids it names are the old editor's. A client that connects now // is the replacement's, and stays. l.cut_before = l.accepts.load(.acquire); - pardes.turn.settle(); - pardes.turn.restoreSettled(); + pardes.turn.bump(&pardes.turn.epoch); + pardes.turn.bump(&pardes.turn.restores); pardes.turn.rest(); const flush_by = nowMs() +| 200; while (nowMs() < flush_by) { diff --git a/src/Output.zig b/src/Output.zig index 9ed33ebe..3fc08d9a 100644 --- a/src/Output.zig +++ b/src/Output.zig @@ -774,7 +774,7 @@ pub fn openUnsaved(p: *Pardes, id: usize, content: []u8) void { const own = if (pane.file) |f| panes.Dir.ofName(f.path) else pane.cwdSlice(); // Its directory gone (or never there, a name not yet saved): the list // goes in the session's, where a look from it can still resolve. - const dir = if (comptime pardes.hosted) (if (pardes.filesystem.localPath(own)) |local| (if (exec.isDirectory(local)) own else p.sessionDir()) else own) else own; + const dir = if (comptime pardes.hosted) (if (pardes.filesystem.localPath(own)) |local| (if (exec.kindOf(local) == .directory) own else p.sessionDir()) else own) else own; const free = p.freeSlot() orelse return p.gpa.free(content); _ = open(p, free, dir, .unsaved, "", content) catch return; exec.placeNew(p, id, id, free, .doc); diff --git a/src/builtins.zig b/src/builtins.zig index fdce534b..7b1541ac 100644 --- a/src/builtins.zig +++ b/src/builtins.zig @@ -1226,7 +1226,7 @@ pub const Incl = struct { return p.reportFailure(c.id, std.fmt.bufPrint(&said, "Incl: invalid directory: {s} is relative", .{shown}) catch "Incl: invalid directory"); var home_buf: [4096]u8 = undefined; const expanded = @import("fs.zig").expandHome(dir_word, &home_buf); - if (comptime pardes.hosted) if (@import("fs.zig").localPath(expanded)) |local| if (!exec.isDirectory(local)) + if (comptime pardes.hosted) if (@import("fs.zig").localPath(expanded)) |local| if (exec.kindOf(local) != .directory) return p.reportFailure(c.id, if (exec.kindOf(local) != null) std.fmt.bufPrint(&said, "Incl: not a directory: {s}", .{shown}) catch "Incl: not a directory" else diff --git a/src/detached/server.zig b/src/detached/server.zig index 989bdc0f..62dff011 100644 --- a/src/detached/server.zig +++ b/src/detached/server.zig @@ -1288,7 +1288,7 @@ pub fn run(init: std.process.Init, opts: pardes.Options, name: []const u8) !void for ([_]std.posix.SIG{ .HUP, .INT, .TERM }) |sig| std.posix.sigaction(sig, &on_quit, null); defer quit_wake = -1; while (!session.core.quit and !quit_signalled.load(.acquire)) { - pardes.turn.restoreSettled(); + pardes.turn.bump(&pardes.turn.restores); try session.core.pump(h); if (session.core.quit) break; if (session.core.takeRestore()) |path| restore: { diff --git a/src/edit.zig b/src/edit.zig index 55365692..c9477c29 100644 --- a/src/edit.zig +++ b/src/edit.zig @@ -8,6 +8,7 @@ const mouse = @import("mouse.zig"); const normal = @import("normal.zig"); const std = @import("std"); const modal = @import("modal.zig"); +const sam = @import("sam_edit.zig"); const panes = @import("panes.zig"); const body_layer = @import("body_layer.zig"); const config = @import("config.zig"); @@ -1318,23 +1319,10 @@ pub fn normalChange(p: *Pardes, t: *Text) void { const r1 = @max(t.msel.r0, t.msel.r1); pushUndo(p, t); const eb = editText(p, t, r0, r1 + 1, -1) orelse return; - const arena = p.scratch.allocator(); const lo: usize = @intCast(@max(0, r0 - eb.row0)); const hi: usize = @intCast(@max(0, r1 - eb.row0)); - var total: usize = hi - lo; - for (lo..hi + 1) |r| total += modal.lineSlice(eb.text, r).len; - const buf = arena.alloc(u8, total) catch return; - var at: usize = 0; - for (lo..hi + 1) |r| { - if (r > lo) { - buf[at] = '\n'; - at += 1; - } - const line = modal.lineSlice(eb.text, r); - @memcpy(buf[at..][0..line.len], line); - at += line.len; - } - setYank(p, buf); + // the lines are adjacent in the text already, their newlines and all + setYank(p, eb.text[modal.lineStartOffset(eb.text, lo)..modal.lineEndOffset(eb.text, hi)]); var body: []u8 = eb.text; if (hi > lo) { const d = modal.deleteLines(p.gpa, body, lo + 1, hi) catch { @@ -1485,45 +1473,22 @@ pub fn normalCase(p: *Pardes, t: *Text, op: modal.CaseOp) void { setEditText(p, t, new); } -/// a change to apply to file content: delete [from, to), insert `ins` at -/// `from`. Ascending and disjoint. -const TextChange = struct { from: usize, to: usize, ins: []const u8 }; - -fn mapThroughChanges(chs: []const TextChange, pos: usize) usize { +/// Where `pos` lands after `chs`, which are ascending and disjoint. +fn mapThroughChanges(chs: []const sam.Op, pos: usize) usize { var delta: i64 = 0; for (chs) |ch| { - if (pos < ch.from) break; - if (ch.from == ch.to) { - delta += @intCast(ch.ins.len); + if (pos < ch.q0) break; + if (ch.q0 == ch.q1) { + delta += @intCast(ch.text.len); continue; } - if (pos == ch.from) break; - if (pos < ch.to) return @intCast(@as(i64, @intCast(ch.from)) + delta); - delta += @as(i64, @intCast(ch.ins.len)) - @as(i64, @intCast(ch.to - ch.from)); + if (pos == ch.q0) break; + if (pos < ch.q1) return @intCast(@as(i64, @intCast(ch.q0)) + delta); + delta += @as(i64, @intCast(ch.text.len)) - @as(i64, @intCast(ch.q1 - ch.q0)); } return @intCast(@as(i64, @intCast(pos)) + delta); } -/// apply a change list. gpa-owned result. -fn applyChanges(p: *Pardes, text: []const u8, chs: []const TextChange) ![]u8 { - var total = text.len; - for (chs) |ch| total = total - (ch.to - ch.from) + ch.ins.len; - const out = try p.gpa.alloc(u8, total); - errdefer p.gpa.free(out); - var copied: usize = 0; - var at: usize = 0; - for (chs) |ch| { - const unchanged = text[copied..ch.from]; - @memcpy(out[at..][0..unchanged.len], unchanged); - at += unchanged.len; - @memcpy(out[at..][0..ch.ins.len], ch.ins); - at += ch.ins.len; - copied = ch.to; - } - @memcpy(out[at..], text[copied..]); - return out; -} - /// `J` / `Alt-J`: join every range's lines with the next, in ONE edit /// (helix join_selections): the newline and the next line's leading blanks /// become one space, or nothing when that line is blank, and a line two @@ -1545,7 +1510,7 @@ pub fn normalJoin(p: *Pardes, t: *Text, select_space: bool) void { // counted from the top, a J in a 7 MB file was 8 ms. const nlines = lineCountOf(p, t, text); const arena = p.scratch.allocator(); - var changes: std.ArrayList(TextChange) = .empty; + var changes: std.ArrayList(sam.Op) = .empty; var next: usize = 0; // lines below this one are joined already for (rs[0..got.n]) |r| { // Text.rangeLineSpan, through rowOf @@ -1562,7 +1527,7 @@ pub fn normalJoin(p: *Pardes, t: *Text, select_space: bool) void { while (to < text.len and (text[to] == ' ' or text[to] == '\t')) to += 1; const last = lineAt(p, t, text, @min(l + 1, nlines - 1)); const sep: []const u8 = if (to == last.start + last.line.len) "" else " "; - changes.append(arena, .{ .from = from, .to = to, .ins = sep }) catch return; + changes.append(arena, .{ .q0 = @intCast(from), .q1 = @intCast(to), .text = sep }) catch return; } next = @max(next, end); } @@ -1570,7 +1535,7 @@ pub fn normalJoin(p: *Pardes, t: *Text, select_space: bool) void { const chs_len = chs.len; if (chs_len == 0) return; pushUndo(p, t); - const new = applyChanges(p, text, chs[0..chs_len]) catch return; + const new = sam.apply(p.gpa, text, chs[0..chs_len]) catch return; // every range's cells ride through the edit; Alt-J replaces them with // the spaces, when it put any in var cells: [Text.max_selections]Text.SelRange = undefined; @@ -1579,9 +1544,9 @@ pub fn normalJoin(p: *Pardes, t: *Text, select_space: bool) void { if (select_space) { var delta: i64 = 0; for (chs[0..chs_len]) |ch| { - const at: usize = @intCast(@as(i64, @intCast(ch.from)) + delta); - delta += @as(i64, @intCast(ch.ins.len)) - @as(i64, @intCast(ch.to - ch.from)); - if (ch.ins.len == 0 or n == cells.len) continue; + const at: usize = @intCast(@as(i64, @intCast(ch.q0)) + delta); + delta += @as(i64, @intCast(ch.text.len)) - @as(i64, @intCast(ch.q1 - ch.q0)); + if (ch.text.len == 0 or n == cells.len) continue; const pos = modal.positionAt(new, at); cells[n] = .{ .row = @as(i32, @intCast(pos.row)) + eb.row0, .col = @intCast(pos.col), .arow = @as(i32, @intCast(pos.row)) + eb.row0, .acol = @intCast(pos.col) }; n += 1; @@ -1627,23 +1592,23 @@ pub fn normalRotateContents(p: *Pardes, t: *Text, forward: bool, cnt: usize) voi const n = got.n; if (n < 2) return; const by = @min(cnt, n); - var chs: [Text.max_selections]TextChange = undefined; + var chs: [Text.max_selections]sam.Op = undefined; for (rs[0..n], 0..) |r, i| { const src = rs[if (forward) (i + n - by) % n else (i + by) % n]; chs[i] = .{ - .from = @min(r.anchor, r.head), - .to = @max(r.anchor, r.head), - .ins = text[@min(src.anchor, src.head)..@max(src.anchor, src.head)], + .q0 = @intCast(@min(r.anchor, r.head)), + .q1 = @intCast(@max(r.anchor, r.head)), + .text = text[@min(src.anchor, src.head)..@max(src.anchor, src.head)], }; } pushUndo(p, t); - const new = applyChanges(p, text, chs[0..n]) catch return; + const new = sam.apply(p.gpa, text, chs[0..n]) catch return; var cells: [Text.max_selections]Text.SelRange = undefined; var delta: i64 = 0; for (chs[0..n], rs[0..n], 0..) |ch, r, i| { - const from: usize = @intCast(@as(i64, @intCast(ch.from)) + delta); - delta += @as(i64, @intCast(ch.ins.len)) - @as(i64, @intCast(ch.to - ch.from)); - const to = from + ch.ins.len; + const from: usize = @intCast(@as(i64, @intCast(ch.q0)) + delta); + delta += @as(i64, @intCast(ch.text.len)) - @as(i64, @intCast(ch.q1 - ch.q0)); + const to = from + ch.text.len; const c = Text.rangeCells(new, if (r.anchor > r.head) .{ .anchor = to, .head = from } else .{ .anchor = from, .head = to }); const cc = modal.positionAt(new, c.cur); const ac = modal.positionAt(new, c.anc); @@ -1700,7 +1665,7 @@ pub fn normalAlign(p: *Pardes, t: *Text) void { // each column's head position, left to right for (1..n) |i| widths[i] += widths[i - 1]; const arena = p.scratch.allocator(); - var chs: [Text.max_selections]TextChange = undefined; + var chs: [Text.max_selections]sam.Op = undefined; var m: usize = 0; line = std.math.maxInt(usize); for (rs[0..n], 0..) |r, i| { @@ -1716,12 +1681,12 @@ pub fn normalAlign(p: *Pardes, t: *Text) void { const spaces = arena.alloc(u8, pad) catch return; @memset(spaces, ' '); const at = @min(r.anchor, r.head); - chs[m] = .{ .from = at, .to = at, .ins = spaces }; + chs[m] = .{ .q0 = @intCast(at), .q1 = @intCast(at), .text = spaces }; m += 1; } if (m == 0) return; pushUndo(p, t); - const new = applyChanges(p, text, chs[0..m]) catch return; + const new = sam.apply(p.gpa, text, chs[0..m]) catch return; var cells: [Text.max_selections]Text.SelRange = undefined; for (rs[0..n], 0..) |r, i| { const c = Text.rangeCells(text, r); @@ -1751,7 +1716,7 @@ pub fn normalIndent(p: *Pardes, t: *Text, cnt: usize, add: bool) void { // one run of spaces, sliced per line: `>` never inserts more than this const pad = arena.alloc(u8, modal.INDENT_W * cnt) catch return; @memset(pad, ' '); - const chs = arena.alloc(TextChange, span.end - span.start + 1) catch return; + const chs = arena.alloc(sam.Op, span.end - span.start + 1) catch return; var chs_len: usize = 0; var l = span.start; while (l <= span.end) : (l += 1) { @@ -1762,7 +1727,7 @@ pub fn normalIndent(p: *Pardes, t: *Text, cnt: usize, add: bool) void { if (nw == line.len) continue; // blank lines stay blank (helix) if (add) { const ins = modal.INDENT_W * cnt - (nw % modal.INDENT_W); - chs[chs_len] = .{ .from = ls, .to = ls, .ins = pad[0..ins] }; + chs[chs_len] = .{ .q0 = @intCast(ls), .q1 = @intCast(ls), .text = pad[0..ins] }; chs_len += 1; } else { const want = modal.INDENT_W * cnt; @@ -1778,7 +1743,7 @@ pub fn normalIndent(p: *Pardes, t: *Text, cnt: usize, add: bool) void { if (w >= want) break; } if (pos > 0) { - chs[chs_len] = .{ .from = ls, .to = ls + pos, .ins = "" }; + chs[chs_len] = .{ .q0 = @intCast(ls), .q1 = @intCast(ls + pos), .text = "" }; chs_len += 1; } } @@ -1790,7 +1755,7 @@ pub fn normalIndent(p: *Pardes, t: *Text, cnt: usize, add: bool) void { modal.offsetAt(text, .{ .row = @intCast(@max(0, t.vsel.row - eb.row0)), .col = @intCast(@max(0, t.vsel.col)) }) else cur_off; - const new = applyChanges(p, text, chs[0..chs_len]) catch return; + const new = sam.apply(p.gpa, text, chs[0..chs_len]) catch return; const nc = mapThroughChanges(chs[0..chs_len], cur_off); const na = mapThroughChanges(chs[0..chs_len], anc_off); setEditText(p, t, new); @@ -1864,7 +1829,7 @@ pub fn normalToggleComment(p: *Pardes, t: *Text) void { } if (live == 0) return; // nothing but blank lines const ins = std.fmt.allocPrint(arena, "{s} ", .{token}) catch return; - const chs = arena.alloc(TextChange, lines_len) catch return; + const chs = arena.alloc(sam.Op, lines_len) catch return; var chs_len: usize = 0; for (lines[0..lines_len]) |l| { const ls = modal.lineStartOffset(text, l); @@ -1875,16 +1840,16 @@ pub fn normalToggleComment(p: *Pardes, t: *Text) void { // the @min can never bind: margin is 1 only when every line has a // space after its own token, which is a byte past `at + token.len` chs[chs_len] = if (commented) - .{ .from = at, .to = @min(at + token.len + margin, le), .ins = "" } + .{ .q0 = @intCast(at), .q1 = @intCast(@min(at + token.len + margin, le)), .text = "" } else - .{ .from = at, .to = at, .ins = ins }; + .{ .q0 = @intCast(at), .q1 = @intCast(at), .text = ins }; chs_len += 1; } pushUndo(p, t); // one edit, and the WHOLE selection rides through it (helix maps the // selection with the transaction) var cells: [Text.max_selections]Text.SelRange = undefined; - const new = applyChanges(p, text, chs[0..chs_len]) catch return; + const new = sam.apply(p.gpa, text, chs[0..chs_len]) catch return; for (rs[0..got.n], 0..) |r, i| { const c = Text.rangeCells(new, .{ .anchor = mapThroughChanges(chs[0..chs_len], r.anchor), diff --git a/src/edit_cmd.zig b/src/edit_cmd.zig index c8473e99..9542f4a9 100644 --- a/src/edit_cmd.zig +++ b/src/edit_cmd.zig @@ -78,7 +78,7 @@ const World = struct { } if (comptime !pardes.hosted) return true; const local = filesystem.localPath(path) orelse return true; - if (@import("exec.zig").isDirectory(local)) return said(bool, why, "B: {s} is a directory", .{path}) orelse false; + if (@import("exec.zig").kindOf(local) == .directory) return said(bool, why, "B: {s} is a directory", .{path}) orelse false; var buf: [4096]u8 = undefined; if (filesystem.resolveOs(local, &buf) == null) return said(bool, why, "B: {s}: no such file", .{path}) orelse false; return true; @@ -93,7 +93,7 @@ const World = struct { fn open(ctx: *anyopaque, path: []const u8, why: *sam.Why) ?sam.File { const w: *World = @ptrCast(@alignCast(ctx)); const p = w.p; - if (comptime pardes.hosted) if (filesystem.localPath(path)) |local| if (@import("exec.zig").isDirectory(local)) + if (comptime pardes.hosted) if (filesystem.localPath(path)) |local| if (@import("exec.zig").kindOf(local) == .directory) return said(sam.File, why, "B: {s} is a directory", .{path}); // A look opens it, or finds it open, where a look would; the // keyboard stays where the Edit ran. @@ -113,7 +113,7 @@ const World = struct { fn read(ctx: *anyopaque, arena: std.mem.Allocator, path: []const u8, why: *sam.Why) ?[]const u8 { const w: *World = @ptrCast(@alignCast(ctx)); - if (comptime pardes.hosted) if (filesystem.localPath(path)) |local| if (@import("exec.zig").isDirectory(local)) + if (comptime pardes.hosted) if (filesystem.localPath(path)) |local| if (@import("exec.zig").kindOf(local) == .directory) return said([]const u8, why, "{s} is a directory", .{path}); const bytes = filesystem.read(w.p, path) catch |err| { // In the words Get says them (builtins.Get). diff --git a/src/exec.zig b/src/exec.zig index c9f304b0..eb15dbc9 100644 --- a/src/exec.zig +++ b/src/exec.zig @@ -210,13 +210,7 @@ pub fn operandAt(p: *Pardes, pane: *Pane, clicked: Pane.Sel, borrow: bool, for_l var expanded = clicked; if (pane.file != null) { result.file_word = .{ .row = row, .lo = 0, .hi = hi }; - const first = pane.wrapRow(row, 0); - const last = pane.wrapRow(row, hi - 1); - if (first.row < 0 or last.row < 0) return result; - expanded.r0 = first.row + @as(i32, pane.tag_rows); - expanded.c0 = @as(i32, panes.File.gutterWidth(pane)) + first.pad + panes.File.displayOffset(pane, row, first.at, 0); - expanded.r1 = last.row + @as(i32, pane.tag_rows); - expanded.c1 = @as(i32, panes.File.gutterWidth(pane)) + last.pad + panes.File.displayEndOffset(pane, row, last.at, hi - 1); + expanded = fileWordCells(pane, clicked, row, 0, hi) orelse return result; } else { const shown = if (raw) raw_line else line; expanded.c0 = 0; @@ -236,16 +230,7 @@ pub fn operandAt(p: *Pardes, pane: *Pane, clicked: Pane.Sel, borrow: bool, for_l const hi = std.math.cast(i32, b.hi) orelse return result; result.text = line[b.lo..b.hi]; result.file_word = .{ .row = row, .lo = lo, .hi = hi }; - - var expanded = clicked; - const first = pane.wrapRow(row, lo); - const last = pane.wrapRow(row, hi - 1); - if (first.row >= 0 and last.row >= 0) { - expanded.r0 = first.row + @as(i32, pane.tag_rows); - expanded.c0 = @as(i32, panes.File.gutterWidth(pane)) + first.pad + panes.File.displayOffset(pane, row, first.at, lo); - expanded.r1 = last.row + @as(i32, pane.tag_rows); - expanded.c1 = @as(i32, panes.File.gutterWidth(pane)) + last.pad + panes.File.displayEndOffset(pane, row, last.at, hi - 1); - } + const expanded = fileWordCells(pane, clicked, row, lo, hi) orelse clicked; result.preview = expanded; result.expanded = expanded; return result; @@ -259,16 +244,35 @@ pub fn operandAt(p: *Pardes, pane: *Pane, clicked: Pane.Sel, borrow: bool, for_l return result; } +/// The cells bytes `lo..hi` of a file pane's line `row` take on screen, +/// soft-wrapped or not, as `clicked` reshaped; null when scrolled off. +fn fileWordCells(pane: *Pane, clicked: Pane.Sel, row: i32, lo: i32, hi: i32) ?Pane.Sel { + const first = pane.wrapRow(row, lo); + const last = pane.wrapRow(row, hi - 1); + if (first.row < 0 or last.row < 0) return null; + var cells = clicked; + cells.r0 = first.row + @as(i32, pane.tag_rows); + cells.c0 = @as(i32, panes.File.gutterWidth(pane)) + first.pad + panes.File.displayOffset(pane, row, first.at, lo); + cells.r1 = last.row + @as(i32, pane.tag_rows); + cells.c1 = @as(i32, panes.File.gutterWidth(pane)) + last.pad + panes.File.displayEndOffset(pane, row, last.at, hi - 1); + return cells; +} + +/// Where a held selection is looked for, step `k` of `p.panes.len + 2`: +/// `first`, then the active pane, then the rest; null for one seen. +fn heldPane(p: *Pardes, first: usize, k: usize) ?*Pane { + const i = switch (k) { + 0 => first, + 1 => p.active, + else => k - 2, + }; + if (k > 0 and (i == first or (k > 1 and i == p.active))) return null; + return p.panes[i]; +} + pub fn heldSelection(p: *Pardes, first: usize) ?[]const u8 { - var k: usize = 0; - while (k < p.panes.len + 2) : (k += 1) { - const i = switch (k) { - 0 => first, - 1 => p.active, - else => k - 2, - }; - if (k > 0 and (i == first or (k > 1 and i == p.active))) continue; - const t = p.panes[i] orelse continue; + for (0..p.panes.len + 2) |k| { + const t = heldPane(p, first, k) orelse continue; if (comptime pdf_enabled) if (p.native_images) if (t.pdf) |pv| { if (pv.selection != null and pv.selection_text.len > 0) return pv.selection_text; @@ -285,15 +289,8 @@ pub fn heldSelection(p: *Pardes, first: usize) ?[]const u8 { /// Where the selection `heldSelection` would give is, as acme's argument /// location (exec.c:162, getbytearg): `path:#q0,#q1` of a file pane's dot. pub fn heldSelectionPlace(p: *Pardes, first: usize, buf: []u8) ?[]const u8 { - var k: usize = 0; - while (k < p.panes.len + 2) : (k += 1) { - const i = switch (k) { - 0 => first, - 1 => p.active, - else => k - 2, - }; - if (k > 0 and (i == first or (k > 1 and i == p.active))) continue; - const t = p.panes[i] orelse continue; + for (0..p.panes.len + 2) |k| { + const t = heldPane(p, first, k) orelse continue; if (t.sel[sel_slot].state == .done) return null; // a pointer selection: no byte range kept if ((t.body.vsel.active and t.body.vsel.explicit) or t.body.msel.active) { const f = t.file orelse return null; @@ -464,18 +461,7 @@ pub fn missingDir(p: *Pardes, dir: []const u8) bool { // the shell would start: no command or terminal runs there, and none // is made to say `exit 127`. const local = @import("fs.zig").localPath(dir) orelse return std.mem.startsWith(u8, dir, "/n/"); - return !isDirectory(local); -} - -/// Whether `path` is a directory on this host, the turn out while it asks -/// (it may be inside a mount this editor serves). -pub fn isDirectory(path: []const u8) bool { - var buf: [4096]u8 = undefined; - const z = std.fmt.bufPrintSentinel(&buf, "{s}", .{path}, 0) catch return false; - pardes.turn.yield(); - defer pardes.turn.back(); - const stat = @import("fs.zig").statPath(std.Io.Threaded.global_single_threaded.io(), z, .{}) catch return false; - return stat.kind == .directory; + return kindOf(local) != .directory; } /// Whether `path` is a plain file on this host, the turn out while it asks. @@ -484,7 +470,7 @@ pub fn isFile(path: []const u8) bool { } /// What `path` is on this host, null when it is not there; the turn out -/// while it asks. +/// while it asks (it may be inside a mount this editor serves). pub fn kindOf(path: []const u8) ?std.Io.File.Kind { var buf: [4096]u8 = undefined; const z = std.fmt.bufPrintSentinel(&buf, "{s}", .{path}, 0) catch return null; diff --git a/src/gui/gui.zig b/src/gui/gui.zig index a31c6548..d3734fac 100644 --- a/src/gui/gui.zig +++ b/src/gui/gui.zig @@ -2567,7 +2567,7 @@ fn localSession( defer host_io.setExitWake(null, null); while (!core.quit) { - pardes.turn.restoreSettled(); + pardes.turn.bump(&pardes.turn.restores); try core.pump(host); if (core.quit) break; // a session that ended does not restore into one if (core.takeAttach()) |req| { @@ -2785,7 +2785,7 @@ test "an attached frontend draws the session's chrome from its frame alone" { try std.testing.expect(pardes.layout.splitColumn(core, 0, 1, false)); core.settings.focus_tint = true; try std.testing.expect(core.executeBuiltinLine(0, "Msg a notice with a rule under it")); - pardes.test_api.sync(core); + core.sync(); // Past its slide into place, where its rule shows. for (0..30) |_| core.update(.tick); const s = try core.render(core.scratch.allocator()); @@ -7016,7 +7016,7 @@ test "every pixel of a grip column is band, button or ring, and the button sits core.settings.tag_bottom = bottom; core.active = focus; pane.file.?.revision = pane.file.?.saved_revision + @intFromBool(dirty); - pardes.test_api.sync(core); + core.sync(); const s = try core.render(core.scratch.allocator()); var g: Gui = undefined; g.words = .{}; @@ -7327,7 +7327,7 @@ test "lapis plaques stay in their tag's band, clear of every grip; only the focu try std.testing.expect(pardes.layout.splitColumn(core, 0, 1, false)); try std.testing.expect(core.executeBuiltinLine(0, "Theme lapis")); for (0..40) |_| core.update(.tick); - pardes.test_api.sync(core); + core.sync(); const s = try core.render(core.scratch.allocator()); try std.testing.expect(s.chrome.decor_box_border != null and s.chrome.decor_checker != null and s.chrome.decor_dots != null and s.chrome.decor_title != null); var g: Gui = undefined; @@ -8878,7 +8878,7 @@ test "a lift never touches a tag, a grip or a header, on a light theme or a dark core.settings.lift = style; try std.testing.expect(core.executeBuiltinLine(0, "Msg a floating notice")); core.advance(core.now_ns + 2 * std.time.ns_per_s); - pardes.test_api.sync(core); + core.sync(); const s = try core.render(core.scratch.allocator()); core.advance(core.now_ns + 2 * std.time.ns_per_s); const settled = try core.render(core.scratch.allocator()); @@ -9748,7 +9748,7 @@ test "a theme's own rules and scrollbar are drawn at its widths: acme's 2px blac try std.testing.expect(pardes.layout.splitColumn(core, 0, 1, false)); try std.testing.expect(core.executeBuiltinLine(0, "Theme acme")); for (0..40) |_| core.update(.tick); - pardes.test_api.sync(core); + core.sync(); const s = try core.render(core.scratch.allocator()); try std.testing.expectEqual(@as(u8, 2), s.chrome.rule_px); // acme's 12px, at GripWidth's 150% default. @@ -9805,7 +9805,7 @@ test "the scrollbar thumb moves by the pixel and follows a glide" { // The thumb's top, in window pixels. fn top(gui: *Gui, p: *pardes.Pardes) !f32 { gui.decor.clearRetainingCapacity(); - pardes.test_api.sync(p); + p.sync(); const s = try p.render(p.scratch.allocator()); var groups = makeGroups(&.{}, false); try buildDecor(gui, std.testing.allocator, s, &groups, fixedCellLayout(gui), 800, 480, true); @@ -9839,7 +9839,7 @@ test "the rule between stacked panes stays in the tag band's slack, at any tagli defer core.deinit(); _ = try core.newShell(1, ""); core.newScratchBelow(0); - pardes.test_api.sync(core); + core.sync(); const s = try core.render(core.scratch.allocator()); const lower = for (s.regionList()) |region| { if (region.kind == .tag and region.rect.y > 2) break region; @@ -9879,7 +9879,7 @@ test "an empty column is ruled on both sides, as between two filled ones" { try std.testing.expect(pardes.layout.splitColumn(core, 0, 1, false)); // Newcol from the left pane: an empty column between the two filled ones. core.newColumn(0); - pardes.test_api.sync(core); + core.sync(); try std.testing.expectEqual(@as(usize, 3), core.ncol); try std.testing.expectEqual(@as(usize, 0), core.col_n[1]); const s = try core.render(core.scratch.allocator()); @@ -9917,7 +9917,7 @@ test "at a 2x display every logical pixel is two: rules, the tag rule, the grip' try std.testing.expect(pardes.layout.splitColumn(core, 0, 1, false)); try std.testing.expect(core.executeBuiltinLine(0, "Theme acme")); for (0..40) |_| core.update(.tick); - pardes.test_api.sync(core); + core.sync(); const s = try core.render(core.scratch.allocator()); for ([_]f32{ 1, 2 }) |scale| { display_scale = scale; @@ -9987,7 +9987,7 @@ test "decor is read from the regions, each pane's in its own group" { defer core.deinit(); _ = try core.newShell(1, ""); try std.testing.expect(pardes.layout.splitColumn(core, 0, 1, false)); - pardes.test_api.sync(core); + core.sync(); const s = try core.render(core.scratch.allocator()); var g: Gui = undefined; g.decor = .empty; @@ -10055,7 +10055,7 @@ test "a pane on the move casts a shadow on the other panes' bodies alone, most a try std.testing.expect(pardes.layout.splitColumn(core, 0, 1, false)); try std.testing.expect(core.executeBuiltinLine(0, "Theme acme")); for (0..40) |_| core.update(.tick); - pardes.test_api.sync(core); + core.sync(); const s = try core.render(core.scratch.allocator()); var g: Gui = undefined; g.decor = .empty; @@ -10100,7 +10100,7 @@ test "the selection glows round its block, on the body only, fading in over 100 defer core.deinit(); _ = try core.setTestFile(std.mem.asBytes(&@as([30][20]u8, @splat("some text on a line\n".*)))); core.settings.selection_glow = true; - pardes.test_api.sync(core); + core.sync(); const s = try core.render(core.scratch.allocator()); try std.testing.expectEqual(@as(u8, 1), s.chrome.fx); // Two rows of a selection in the body, as the core paints one. @@ -10153,7 +10153,7 @@ test "a hovered word glows along its foot, never over the cursor, fading in over defer core.deinit(); _ = try core.setTestFile(std.mem.asBytes(&@as([30][20]u8, @splat("some text on a line\n".*)))); core.settings.hover_glow = true; - pardes.test_api.sync(core); + core.sync(); const s = try core.render(core.scratch.allocator()); try std.testing.expectEqual(@as(u8, 2), s.chrome.fx); const body = for (s.regionList()) |region| { @@ -10206,7 +10206,7 @@ test "occlusion shades each body's edges, inside it, never a tag, a grip or the defer core.deinit(); _ = try core.setTestFile(std.mem.asBytes(&@as([30][20]u8, @splat("some text on a line\n".*)))); core.settings.occlusion = true; - pardes.test_api.sync(core); + core.sync(); const s = try core.render(core.scratch.allocator()); try std.testing.expectEqual(@as(u8, 4), s.chrome.fx); const body = for (s.regionList()) |region| { @@ -10251,7 +10251,7 @@ test "a body tells its first line, and lapis's dots under it move a quarter as f try std.testing.expect(core.executeBuiltinLine(0, "Theme lapis")); core.settings.parallax = true; for (0..40) |_| core.update(.tick); - pardes.test_api.sync(core); + core.sync(); const s = try core.render(core.scratch.allocator()); const body = for (s.regionList()) |region| { if (region.kind == .body) break region; diff --git a/src/look.zig b/src/look.zig index 02754fff..588574ed 100644 --- a/src/look.zig +++ b/src/look.zig @@ -1453,7 +1453,7 @@ fn lookUnresolved(p: *Pardes, id: usize, pane: *Pane, trimmed: []const u8, text: if (filesystem.dotRelative(trimmed)) { const dir = Pardes.paneDir(pane); var said: [4200]u8 = undefined; - const gone = if (comptime pardes.hosted) if (filesystem.localPath(dir)) |local| !exec.isDirectory(local) else false else true; + const gone = if (comptime pardes.hosted) if (filesystem.localPath(dir)) |local| exec.kindOf(local) != .directory else false else true; if (gone) return p.reportFailure(id, std.fmt.bufPrint(&said, "look: {s}: no such directory", .{dir[0..@min(dir.len, 4096)]}) catch "look: no such directory"); // A file not there is a miss, as `x` and `/abs/x` are: said and // logged, the write answered with nothing. @@ -1893,7 +1893,7 @@ pub fn lookAt(p: *Pardes, id: usize, operand_raw: []const u8) void { .dir => |dir| { // A directory that is not there (the pane's own, gone): said, // ENOENT, no terminal made in it. - if (comptime pardes.hosted) if (filesystem.localPath(dir)) |local| if (!exec.isDirectory(local)) { + if (comptime pardes.hosted) if (filesystem.localPath(dir)) |local| if (exec.kindOf(local) != .directory) { var said: [4200]u8 = undefined; return p.reportFailure(id, std.fmt.bufPrint(&said, "look: {s}: no such directory", .{dir[0..@min(dir.len, 4096)]}) catch "look: no such directory"); }; diff --git a/src/macos.zig b/src/macos.zig index 55f6b3f6..d2122967 100644 --- a/src/macos.zig +++ b/src/macos.zig @@ -1378,9 +1378,9 @@ export fn pardes_tick() bool { did = true; st.core.perform(effect); } - pardes.turn.settle(); + pardes.turn.bump(&pardes.turn.epoch); if (restoreCore(st)) did = true; - pardes.turn.restoreSettled(); + pardes.turn.bump(&pardes.turn.restores); return did; } diff --git a/src/mini.zig b/src/mini.zig index 8d8ea0b2..9f7d865d 100644 --- a/src/mini.zig +++ b/src/mini.zig @@ -52,11 +52,7 @@ const Row = struct { // unreachable below: `generate` refuses a source that is no UTF-8 const n = std.unicode.utf8ByteSequenceLength(grapheme[0]) catch unreachable; const cp = std.unicode.utf8Decode(grapheme[0..n]) catch unreachable; - const blank = switch (cp) { - '\t'...'\r', ' ', 0x85, 0xa0, 0x1680, 0x2000...0x200a, 0x2028, 0x2029, 0x202f, 0x205f, 0x3000 => true, - else => false, - }; - row.ink = !blank or grapheme.len != n; + row.ink = !modal.isUnicodeWhitespace(cp) or grapheme.len != n; row.color = if (styles.len == 0) 0 else styles[row.base + row.at]; row.at = end; } diff --git a/src/modal.zig b/src/modal.zig index ad06833f..7e10a877 100644 --- a/src/modal.zig +++ b/src/modal.zig @@ -454,25 +454,12 @@ pub const Normal = struct { switch (state.prefix) { .goto => { state.prefix = .none; - if (key.has(.goto_file_start)) return resultAction(.{ .goto = .{ .target = .file_start, .count = count, .explicit_count = counted.explicit } }); - if (key.has(.goto_last_line)) return resultAction(.{ .goto = .{ .target = .last_line, .count = count, .explicit_count = counted.explicit } }); - if (key.has(.goto_line_start)) return resultAction(.{ .goto = .{ .target = .line_start, .count = count, .explicit_count = counted.explicit } }); - if (key.has(.goto_line_end)) return resultAction(.{ .goto = .{ .target = .line_end, .count = count, .explicit_count = counted.explicit } }); - if (key.has(.goto_first_nonws)) return resultAction(.{ .goto = .{ .target = .first_nonws, .count = count, .explicit_count = counted.explicit } }); - if (key.has(.goto_line_down)) return resultAction(.{ .goto = .{ .target = .line_down, .count = count, .explicit_count = counted.explicit } }); - if (key.has(.goto_line_up)) return resultAction(.{ .goto = .{ .target = .line_up, .count = count, .explicit_count = counted.explicit } }); - if (key.has(.goto_column)) return resultAction(.{ .goto = .{ .target = .column, .count = count, .explicit_count = counted.explicit } }); - if (key.has(.goto_view_top)) return resultAction(.{ .goto = .{ .target = .view_top, .count = count, .explicit_count = counted.explicit } }); - if (key.has(.goto_view_center)) return resultAction(.{ .goto = .{ .target = .view_center, .count = count, .explicit_count = counted.explicit } }); - if (key.has(.goto_view_bottom)) return resultAction(.{ .goto = .{ .target = .view_bottom, .count = count, .explicit_count = counted.explicit } }); + // each target's role is its name after `goto_` + inline for (comptime std.enums.values(Goto)) |target| + if (key.has(@field(Role, "goto_" ++ @tagName(target)))) return resultAction(.{ .goto = .{ .target = target, .count = count, .explicit_count = counted.explicit } }); if (key.has(.goto_word)) return resultAction(.goto_word); - if (key.has(.goto_last_modification)) return resultAction(.{ .goto = .{ .target = .last_modification, .count = count, .explicit_count = counted.explicit } }); - if (key.has(.goto_definition)) return resultAction(.{ .lsp = .definition }); - if (key.has(.goto_declaration)) return resultAction(.{ .lsp = .declaration }); - if (key.has(.goto_type_definition)) return resultAction(.{ .lsp = .type_definition }); - if (key.has(.goto_implementation)) return resultAction(.{ .lsp = .implementation }); - if (key.has(.goto_references)) return resultAction(.{ .lsp = .references }); - if (key.has(.goto_callstack)) return resultAction(.{ .lsp = .callstack }); + inline for (.{ .definition, .declaration, .type_definition, .implementation, .references, .callstack }) |lsp| + if (key.has(@field(Role, "goto_" ++ @tagName(lsp)))) return resultAction(.{ .lsp = lsp }); return .ignored; }, .view => { @@ -608,20 +595,11 @@ pub const Normal = struct { if (key.has(.page_down)) return resultAction(.{ .page = .{ .kind = .down, .count = count } }); if (key.has(.page_up)) return resultAction(.{ .page = .{ .kind = .up, .count = count } }); - if (key.has(.insert)) return resultAction(.{ .insert = .{ .kind = .at, .count = count } }); - if (key.has(.append)) return resultAction(.{ .insert = .{ .kind = .append, .count = count } }); - if (key.has(.insert_line_start)) return resultAction(.{ .insert = .{ .kind = .line_start, .count = count } }); - if (key.has(.insert_line_end)) return resultAction(.{ .insert = .{ .kind = .line_end, .count = count } }); - if (key.has(.open_below)) return resultAction(.{ .insert = .{ .kind = .open_below, .count = count } }); - if (key.has(.open_above)) return resultAction(.{ .insert = .{ .kind = .open_above, .count = count } }); - - if (key.has(.select_mode)) return resultAction(.{ .select = .{ .kind = .mode, .count = count } }); - if (key.has(.select_line)) return resultAction(.{ .select = .{ .kind = .line, .count = count } }); - if (key.has(.select_line_bounds)) return resultAction(.{ .select = .{ .kind = .line_bounds, .count = count } }); - if (key.has(.shrink_to_line_bounds)) return resultAction(.{ .select = .{ .kind = .shrink_to_line_bounds, .count = count } }); - if (key.has(.collapse_selection)) return resultAction(.{ .select = .{ .kind = .collapse, .count = count } }); - if (key.has(.flip_selection)) return resultAction(.{ .select = .{ .kind = .flip, .count = count } }); - if (key.has(.select_all)) return resultAction(.{ .select = .{ .kind = .all, .count = count } }); + inline for (.{ .{ .insert, .at }, .{ .append, .append }, .{ .insert_line_start, .line_start }, .{ .insert_line_end, .line_end }, .{ .open_below, .open_below }, .{ .open_above, .open_above } }) |pair| + if (key.has(pair[0])) return resultAction(.{ .insert = .{ .kind = pair[1], .count = count } }); + + inline for (.{ .{ .select_mode, .mode }, .{ .select_line, .line }, .{ .select_line_bounds, .line_bounds }, .{ .shrink_to_line_bounds, .shrink_to_line_bounds }, .{ .collapse_selection, .collapse }, .{ .flip_selection, .flip }, .{ .select_all, .all } }) |pair| + if (key.has(pair[0])) return resultAction(.{ .select = .{ .kind = pair[1], .count = count } }); if (key.has(.copy_sel_below)) return resultAction(.{ .multi = .{ .kind = .copy_below, .count = count } }); if (key.has(.copy_sel_above)) return resultAction(.{ .multi = .{ .kind = .copy_above, .count = count } }); @@ -788,7 +766,7 @@ fn codepointAt(text: []const u8, off: usize) u21 { return std.unicode.utf8Decode(text[off .. off + n]) catch 0xFFFD; } -fn isUnicodeWhitespace(cp: u21) bool { +pub fn isUnicodeWhitespace(cp: u21) bool { if (cp == ' ' or (cp >= '\t' and cp <= '\r') or cp == 0x85) return true; return switch (uucode.get(.general_category, cp)) { .separator_space, .separator_line, .separator_paragraph => true, @@ -857,13 +835,6 @@ pub fn firstNonWs(line: []const u8) usize { return i; } -pub fn firstNonWsOf(lines: []const []const u8, c: Cursor) Cursor { - // the row can sit past the content (mouse click below a short pane's - // last line) — out of range reads as an empty line, like lineLenOf - if (c.row >= lines.len) return .{ .row = c.row, .col = 0 }; - return .{ .row = c.row, .col = firstNonWs(lines[c.row]) }; -} - pub fn charLeft(lines: []const []const u8, c: Cursor) Cursor { if (c.row >= lines.len) return .{ .row = c.row, .col = 0 }; return .{ .row = c.row, .col = prevGrapheme(lines[c.row], @min(c.col, lines[c.row].len)) }; @@ -1717,18 +1688,6 @@ pub fn moveParagraph(text: []const u8, r: Selection, count: usize, fwd: bool, ex return .{ .anchor = anchor, .head = head }; } -/// j/k target: helix move_vertically — goal_col clamps to the line's content -/// length, i.e. the cursor may land ON the '\n' of a shorter line. -pub fn verticalTarget(text: []const u8, pos: usize, down: bool, count: usize, goal_col: usize) usize { - const nlines = cursorLineCount(text); - const line = lineAtOffset(text, pos); - const nline = if (down) @min(line + @max(1, count), nlines - 1) else line -| @max(1, count); - const s = lineStartOffset(text, nline); - // lineEndOffset(text, nline) without its second walk to nline (see offsetAt) - const e = std.mem.indexOfScalarPos(u8, text, s, '\n') orelse text.len; - return s + graphemeStart(text[s..e], @min(goal_col, e - s)); -} - /// f/F/t/T target cell. helix find_char: the exclusive (till) search starts /// one further out so repeats make progress; not-found = null (no move). pub fn findTarget(text: []const u8, cursor: usize, ch: u21, fwd: bool, till: bool, count: usize) ?usize { @@ -1976,14 +1935,6 @@ test "paragraph selections cross blank lines" { try std.testing.expectEqual(@as(usize, 7), r.head); } -test "vertical target clamps the goal column onto the newline cell" { - const t = "abcdef\nab\nabcdef\n"; - // from (0,5) down: line "ab" clamps to its '\n' at offset 9 - try std.testing.expectEqual(@as(usize, 9), verticalTarget(t, 5, true, 1, 5)); - // two down with the same goal restores col 5 - try std.testing.expectEqual(@as(usize, 15), verticalTarget(t, 9, true, 1, 5)); -} - test "find targets count matches and skip adjacent till targets" { const t = "abcabc\n"; try std.testing.expectEqual(@as(usize, 2), findTarget(t, 0, 'c', true, false, 1).?); @@ -2148,14 +2099,11 @@ test "codepoint classes distinguish words punctuation and whitespace" { try std.testing.expectEqual(Kind.ws, kindOfCodepoint('\n')); } -test "insert cursor steps characters and skips indentation" { +test "insert cursor steps characters" { const lines = [_][]const u8{ "alpha beta", " two words", "x" }; const c = Cursor{ .row = 0, .col = 5 }; try std.testing.expectEqual(Cursor{ .row = 0, .col = 4 }, charLeft(&.{"hello"}, c)); try std.testing.expectEqual(Cursor{ .row = 0, .col = 6 }, charRight(&lines, c)); - try std.testing.expectEqual(Cursor{ .row = 1, .col = 2 }, firstNonWsOf(&lines, Cursor{ .row = 1, .col = 0 })); - // cursor row past the content (mouse click below a short pane): no panic - try std.testing.expectEqual(Cursor{ .row = 24, .col = 0 }, firstNonWsOf(&lines, Cursor{ .row = 24, .col = 3 })); } test "lineSpan agrees with the whole-document scans it replaces" { diff --git a/src/ninep/ctl.zig b/src/ninep/ctl.zig index 480c1dc7..f9bec775 100644 --- a/src/ninep/ctl.zig +++ b/src/ninep/ctl.zig @@ -110,7 +110,7 @@ pub fn run(p: *Pardes, id: usize, exec: bool, text: []const u8, in_tag: bool) vo /// A write's messages, a line each, except that an `Edit` line takes the /// lines after it while its `{` group or `a`/`c`/`i` text block is open -/// (sam_edit.needsMore): a block written whole reaches Edit whole, never +/// (sam_edit.waitsFor): a block written whole reaches Edit whole, never /// as lines of their own. const Messages = struct { p: *Pardes, @@ -708,7 +708,7 @@ pub fn writePager(p: *Pardes, req: Req) Reply { var shown: [256]u8 = undefined; return tree.failText(req.tag, E.INVAL, std.fmt.bufPrint(&p.fs.ename, "pager: invalid directory \"{s}\": must be absolute", .{blanked(dir[0..@min(dir.len, shown.len)], &shown)}) catch "pager: invalid directory: must be absolute"); } - if (comptime pardes.hosted) if (dir.len > 0) if (pardes.filesystem.localPath(dir)) |local| if (!exec_line.isDirectory(local)) { + if (comptime pardes.hosted) if (dir.len > 0) if (pardes.filesystem.localPath(dir)) |local| if (exec_line.kindOf(local) != .directory) { // A file there is no directory, ENOTDIR; nothing there, ENOENT. if (exec_line.kindOf(local) != null) return tree.failText(req.tag, E.NOTDIR, std.fmt.bufPrint(&p.fs.ename, "pager: {s}: not a directory", .{dir[0..@min(dir.len, 256)]}) catch "pager: not a directory"); diff --git a/src/ninep/pane.zig b/src/ninep/pane.zig index dc104e4b..f9112ae2 100644 --- a/src/ninep/pane.zig +++ b/src/ninep/pane.zig @@ -963,7 +963,7 @@ fn writeName(p: *Pardes, req: Req, id: usize, pane: *Pane) Reply { // A directory (`~`, `/`, `foo/`) is no file to name a pane after: a // Save could only fail. Said now, EISDIR. const is_dir = name[name.len - 1] == '/' or std.mem.eql(u8, full, "/") or - (if (comptime pardes.hosted) (if (fs.localPath(full)) |local| exec.isDirectory(local) else false) else false); + (if (comptime pardes.hosted) (if (fs.localPath(full)) |local| exec.kindOf(local) == .directory else false) else false); if (is_dir) return tree.failText(req.tag, E.ISDIR, std.fmt.bufPrint(&p.fs.ename, "name: {s} is a directory, not a file", .{full[0..@min(full.len, 256)]}) catch "name: is a directory, not a file"); nameBuffer(p, id, full, false) catch |err| return Reply.fail(req.tag, switch (err) { error.OutOfMemory => E.NOMEM, diff --git a/src/pardes.zig b/src/pardes.zig index c2a3ba21..80ff3495 100644 --- a/src/pardes.zig +++ b/src/pardes.zig @@ -188,40 +188,20 @@ pub const Turn = struct { t.release(); } - /// The editor performed the core's effects. - pub fn settle(t: *Turn) void { + /// One of `epoch`, `restores` or `lsp_answers` moved on: the editor + /// performed the core's effects, a shell attempted a Restore (at the + /// top of each loop step, when the previous step's attempt is over), + /// or a language server's answer was taken in. + pub fn bump(t: *Turn, counter: *u64) void { const io = t.io orelse return; - t.epoch +%= 1; + counter.* +%= 1; t.settled.broadcast(io); } - /// With the turn: waits, turn given up meanwhile, until the editor has - /// performed past `epoch`; stopping ends the wait early. - pub fn awaitSettled(t: *Turn, epoch: u64) void { - while (t.epoch == epoch) t.settled.wait(t.io.?, &t.mutex) catch return; - } - - /// The shell attempted the Restore the core asked for, whichever way it - /// went; called at the top of each loop step, when the previous step's - /// attempt is over. - pub fn restoreSettled(t: *Turn) void { - const io = t.io orelse return; - t.restores +%= 1; - t.settled.broadcast(io); - } - - pub fn lspAnswered(t: *Turn) void { - const io = t.io orelse return; - t.lsp_answers +%= 1; - t.settled.broadcast(io); - } - - pub fn awaitLsp(t: *Turn, answers: u64) void { - while (t.lsp_answers == answers) t.settled.wait(t.io.?, &t.mutex) catch return; - } - - pub fn awaitRestored(t: *Turn, restores: u64) void { - while (t.restores == restores) t.settled.wait(t.io.?, &t.mutex) catch return; + /// With the turn: waits, turn given up meanwhile, until `counter` has + /// moved past `seen`; stopping ends the wait early. + pub fn awaitPast(t: *Turn, counter: *const u64, seen: u64) void { + while (counter.* == seen) t.settled.wait(t.io.?, &t.mutex) catch return; } fn release(t: *Turn) void { @@ -520,18 +500,6 @@ pub const test_api = if (@import("builtin").is_test) struct { exec.runBuiltin(p, command, id, txt, arg); return true; } - - pub fn sync(p: *Pardes) void { - p.sync(); - } - - pub fn searchStep(p: *Pardes, id: usize, delta: i32) bool { - return look.searchStep(p, id, delta); - } - - pub fn heldSelection(p: *Pardes, first: usize) ?[]const u8 { - return exec.heldSelection(p, first); - } } else struct {}; fn drainForSavePath(p: *Pardes, buf: []u8) ?[]const u8 { @@ -2982,89 +2950,36 @@ fn chordName(comptime c: config.Chord) []const u8 { } } -fn shortcutCount(comptime b: Builtin) comptime_int { - var count = 0; - if (b == .Window) count += 1; - for (config.jump_keys) |jk| if (jk.cmd == b) { - count += 1; - }; - if (config.look_cmd == b) count += config.look_key.len + 1; - if (config.exec_cmd == b) count += config.exec_key.len + 1; - var it = std.mem.tokenizeScalar(u8, config.topbar_str, ' '); - while (it.next()) |w| if (std.mem.eql(u8, w, @tagName(b))) { - count += 1; - }; - return count; -} - fn shortcuts(comptime b: Builtin) []const u8 { comptime { @setEvalBranchQuota(20000); - var parts: [shortcutCount(b)][]const u8 = undefined; - var part: usize = 0; - if (b == .Window) { - parts[part] = chordName(config.window_prefix[0]); - part += 1; - } - for (config.jump_keys) |jk| { - if (jk.cmd == b) { - parts[part] = chordName(jk.chord); - part += 1; - } - } + // each part after ", "; the first one's is cut off at the end + var s: []const u8 = ""; + if (b == .Window) s = s ++ ", " ++ chordName(config.window_prefix[0]); + for (config.jump_keys) |jk| if (jk.cmd == b) { + s = s ++ ", " ++ chordName(jk.chord); + }; if (config.look_cmd == b) { - for (config.look_key) |k| { - parts[part] = chordName(k); - part += 1; - } - parts[part] = @tagName(config.look_button) ++ "-click"; - part += 1; + for (config.look_key) |k| s = s ++ ", " ++ chordName(k); + s = s ++ ", " ++ @tagName(config.look_button) ++ "-click"; } if (config.exec_cmd == b) { - for (config.exec_key) |k| { - parts[part] = chordName(k); - part += 1; - } - parts[part] = @tagName(config.exec_button) ++ "-click"; - part += 1; + for (config.exec_key) |k| s = s ++ ", " ++ chordName(k); + s = s ++ ", " ++ @tagName(config.exec_button) ++ "-click"; } var it = std.mem.tokenizeScalar(u8, config.topbar_str, ' '); - while (it.next()) |w| { - if (std.mem.eql(u8, w, @tagName(b))) { - parts[part] = "topbar"; - part += 1; - } - } - var len: usize = if (parts.len == 0) 0 else 2 * (parts.len - 1); - for (parts) |text| len += text.len; - var out: [len]u8 = undefined; - var at: usize = 0; - for (parts, 0..) |text, i| { - if (i > 0) { - @memcpy(out[at..][0..2], ", "); - at += 2; - } - @memcpy(out[at..][0..text.len], text); - at += text.len; - } - return &out; + while (it.next()) |w| if (std.mem.eql(u8, w, @tagName(b))) { + s = s ++ ", topbar"; + }; + return if (s.len == 0) s else s[2..]; } } fn leaderKeys(comptime path: []const u8) []const u8 { comptime { - var out: [4 + 2 * path.len - 1]u8 = undefined; - @memcpy(out[0..4], "SPC "); - var at: usize = 4; - for (path, 0..) |c, i| { - if (i > 0) { - out[at] = ' '; - at += 1; - } - out[at] = c; - at += 1; - } - return &out; + var s: []const u8 = "SPC"; + for (path) |c| s = s ++ " " ++ [_]u8{c}; + return s; } } @@ -5658,6 +5573,21 @@ pub const Pardes = struct { if (!p.fallback.writeFile(path, bytes)) p.saveFailed(pane, path, error.OutOfMemory); } + /// Writes `bytes` to `path` for pane `id`, its directories made first: + /// the pane after it, if it is still the one `serial` names and the + /// write did not fail. A failed write changes nothing: its file goes + /// back to the saved revision `was`, dirty as it was. + fn writeChecked(p: *Pardes, id: u8, serial: u32, path: []const u8, bytes: []const u8, was: u32) ?*Pane { + const failures = p.fs.failures; + makeParents(path); + p.hostWriteFile(id, path, bytes); + const pane = p.panes[id] orelse return null; + if (pane.serial != serial) return null; + if (p.fs.failures == failures) return pane; + if (pane.file) |*f| f.saved_revision = was; + return null; + } + /// A write of `path` the host could not do: the pane stays dirty, the /// message row says `Save : `, and the 9P write that asked /// for it, waiting on the save, fails with that (`fs.late_failure`). @@ -5740,6 +5670,18 @@ pub const Pardes = struct { filesystem.makeDirs(std.fs.path.dirname(local) orelse "/"); } + /// The directory a write of `path` that failed with `err` went into: + /// what is there (a directory when it is no local path), whether it is + /// missing, and whether that is because one above refuses (EACCES). + fn parentTrouble(path: []const u8, err: anyerror) struct { dir: []const u8, kind: ?std.Io.File.Kind, missing: bool, denied: bool } { + const dir = std.fs.path.dirname(path) orelse "/"; + const local = if (comptime hosted) filesystem.localPath(dir) else null; + const kind: ?std.Io.File.Kind = if (comptime hosted) (if (local) |l| exec.kindOf(l) else .directory) else .directory; + const missing = err == error.FileNotFound or err == error.NotDir or kind != .directory; + const denied = missing and (if (comptime hosted) (if (local) |l| filesystem.deniedAbove(l) else false) else false); + return .{ .dir = dir, .kind = kind, .missing = missing, .denied = denied }; + } + pub fn saveFailed(p: *Pardes, id: u8, path: []const u8, err: anyerror) void { if (p.panes[id]) |pane| if (pane.file) |*f| { // The `-%` spelling fs.zig already uses for "make this dirty". @@ -5747,15 +5689,11 @@ pub const Pardes = struct { }; var what: [limits.host_path_cap + 32]u8 = undefined; // A write into a directory that is not there: said so, in the words - // a mount reads as ENOENT. - const parent = std.fs.path.dirname(path) orelse "/"; - const no_dir = err == error.FileNotFound or err == error.NotDir or - (if (comptime hosted) (if (filesystem.localPath(parent)) |local| !exec.isDirectory(local) else false) else false); - // Not there because one above refuses: that is the reason, EACCES. - const denied = no_dir and (if (comptime hosted) (if (filesystem.localPath(parent)) |local| filesystem.deniedAbove(local) else false) else false); - if (denied) + // a mount reads as ENOENT; EACCES when one above refuses. + const parent = parentTrouble(path, err); + if (parent.denied) p.reportFailure(id, std.fmt.bufPrint(&what, "Save {s}: permission denied", .{path}) catch "Save: permission denied") - else if (no_dir) + else if (parent.missing) p.reportFailure(id, std.fmt.bufPrint(&what, "Save {s}: no such directory", .{path}) catch "Save: no such directory") else p.reportError(id, std.fmt.bufPrint(&what, "Save {s}", .{path}) catch "Save", err); @@ -5770,18 +5708,14 @@ pub const Pardes = struct { const operation = std.fmt.bufPrint(&what, "Dump {s}", .{path}) catch "Dump"; // Into a DumpDir that is not there: said so, ENOENT, as a Save is; // one that is there but no directory (`/dev/null`) says that. - const parent = std.fs.path.dirname(path) orelse "/"; - const kind: ?std.Io.File.Kind = if (comptime hosted) (if (filesystem.localPath(parent)) |local| exec.kindOf(local) else .directory) else .directory; - const no_dir = err == error.FileNotFound or err == error.NotDir or kind != .directory; - // Not there because one above refuses: that is why, EACCES. - const denied = no_dir and kind == null and (if (comptime hosted) (if (filesystem.localPath(parent)) |local| filesystem.deniedAbove(local) else false) else false); - if (denied) { + const parent = parentTrouble(path, err); + if (parent.denied and parent.kind == null) { var said: [limits.host_path_cap + 48]u8 = undefined; p.reportFailure(p.active, std.fmt.bufPrint(&said, "{s}: permission denied", .{operation}) catch "Dump: permission denied"); - } else if (kind != null and kind != .directory) { + } else if (parent.kind != null and parent.kind != .directory) { var said: [limits.host_path_cap + 48]u8 = undefined; - p.reportFailure(p.active, std.fmt.bufPrint(&said, "{s}: {s} is not a directory", .{ operation, parent }) catch "Dump: not a directory"); - } else if (no_dir) { + p.reportFailure(p.active, std.fmt.bufPrint(&said, "{s}: {s} is not a directory", .{ operation, parent.dir }) catch "Dump: not a directory"); + } else if (parent.missing) { var said: [limits.host_path_cap + 48]u8 = undefined; p.reportFailure(p.active, std.fmt.bufPrint(&said, "{s}: no such directory", .{operation}) catch "Dump: no such directory"); } else p.reportError(p.active, operation, err); @@ -5836,22 +5770,13 @@ pub const Pardes = struct { .save_file => |sf| { const pane = p.panes[sf.pane] orelse return; const f = if (pane.file) |*file| file else return; - const serial = pane.serial; const was = f.saved_revision; - const failures = p.fs.failures; f.saved_revision = f.revision; - makeParents(f.path); - p.hostWriteFile(sf.pane, f.path, f.content); - const saved_pane = p.panes[sf.pane] orelse return; - if (saved_pane.serial != serial) return; - const saved = if (saved_pane.file) |*file| file else return; // A save the host could not do (saveFailed) is its err // record alone, not a `save`, and changes nothing: a clean // file stays clean. - if (p.fs.failures != failures) { - saved.saved_revision = was; - return; - } + const saved_pane = p.writeChecked(sf.pane, pane.serial, f.path, f.content, was) orelse return; + const saved = if (saved_pane.file) |*file| file else return; // Edited while it was written: what is on disk is not this. if (saved.saved_revision != saved.revision) return; saved.disk_gone = false; @@ -5867,28 +5792,16 @@ pub const Pardes = struct { const pane = p.panes[st.pane] orelse return; if (pane.serial != st.serial) return; // a recycled slot: not ours if (pane.file) |*f| { - const was = f.saved_revision; - const failures = p.fs.failures; - makeParents(st.path.slice()); - p.hostWriteFile(st.pane, st.path.slice(), f.content); - const after = p.panes[st.pane] orelse return; - if (after.serial != st.serial) return; - const g = if (after.file) |*file| file else return; // Failed, it changes nothing: not the name, not dirty. - if (p.fs.failures != failures) { - g.saved_revision = was; - return; - } + const after = p.writeChecked(st.pane, st.serial, st.path.slice(), f.content, f.saved_revision) orelse return; + if (after.file == null) return; if (st.promote) p.promoteSaved(st.pane, st.path.slice()) else ctlfs.events.noteLogAs(p, .save, after, st.path.slice()); return; } if (!pane.isTerminal()) return; const text = panes.terminal.screenTextAlloc(pane, p.gpa) catch return; defer p.gpa.free(text); - makeParents(st.path.slice()); - const failures = p.fs.failures; - p.hostWriteFile(st.pane, st.path.slice(), text); - if (p.fs.failures == failures) if (p.panes[st.pane]) |still| if (still.serial == st.serial) + if (p.writeChecked(st.pane, st.serial, st.path.slice(), text, 0)) |still| ctlfs.events.noteLogAs(p, .save, still, st.path.slice()); }, .write_dump => { @@ -5929,17 +5842,9 @@ pub const Pardes = struct { } for (writes.items) |w| { const was = if (p.panes[w.pane]) |pane| (if (pane.file) |f| f.saved_revision else 0) else 0; - const failures = p.fs.failures; - makeParents(w.path); - p.hostWriteFile(w.pane, w.path, w.bytes); - const pane = p.panes[w.pane] orelse continue; - if (pane.serial != w.serial) continue; - const f = if (pane.file) |*file| file else continue; // Failed, it changes nothing, as save_text's does not. - if (p.fs.failures != failures) { - f.saved_revision = was; - continue; - } + const pane = p.writeChecked(w.pane, w.serial, w.path, w.bytes, was) orelse continue; + const f = if (pane.file) |*file| file else continue; if (w.promote) { p.promoteSaved(w.pane, w.path); } else if (w.clean != null and w.clean.? == f.revision) { @@ -5994,7 +5899,7 @@ pub const Pardes = struct { ctlfs.runClosedLines(p); while (p.nextQueued()) |ev| p.update(ev); while (p.nextEffect()) |e| p.perform(e); - turn.settle(); + turn.bump(&turn.epoch); // A quitting frame has already freed what it would draw. if (p.quit) return; if (v.poll_frame) |f| f(h.ctx); @@ -6234,10 +6139,7 @@ pub const Pardes = struct { // ---- tag + selection text (chord sources) ---- pub fn paneIdOf(p: *const Pardes, pane: *const Pane) ?usize { - for (p.panes, 0..) |slot, id| if (slot) |sp| { - if (sp == pane) return id; - }; - return null; + return std.mem.findScalar(?*const Pane, &p.panes, pane); } /// Cycle only the body modes supported by this pane. @@ -7036,7 +6938,7 @@ pub const Pardes = struct { } pub fn lspResponse(p: *Pardes, id: u32, response: ?[]const u8) void { - defer turn.lspAnswered(); + defer turn.bump(&turn.lsp_answers); const w = p.lsp_wait orelse return; if (w.id != id) return; // superseded by a newer press, or the pane died p.lsp_wait = null; diff --git a/src/sam_edit.zig b/src/sam_edit.zig index 94b76816..73cd6ecd 100644 --- a/src/sam_edit.zig +++ b/src/sam_edit.zig @@ -187,9 +187,12 @@ pub fn run(arena: std.mem.Allocator, files: []const File, cur: usize, command: [ /// an a, c or i text block, or the `}` of a group. pub const Wait = enum { none, text, group }; -/// As `needsMore`, saying which: while a text block is open only a `.` -/// line can end it, so a caller need not parse the block again for every -/// line of text in it (ninep/ctl.zig, editEnd), which was quadratic. +/// Whether `command` stops inside a `{` group or an `a`, `c` or `i` text +/// block still waiting for its `.` line, and which: a writer of lines (a +/// ctl, exec) hands an Edit the lines after it until it does not. While a +/// text block is open only a `.` line can end it, so a caller need not +/// parse the block again for every line of text in it (ninep/ctl.zig, +/// editEnd), which was quadratic. pub fn waitsFor(arena: std.mem.Allocator, command: []const u8) Wait { var why: Why = .{}; const src = std.fmt.allocPrint(arena, "{s}\n", .{command}) catch return .none; @@ -217,19 +220,6 @@ fn groupOpen(command: []const u8) bool { return depth > 0; } -/// Whether `command` stops inside a `{` group or an `a`, `c` or `i` text -/// block still waiting for its `.` line: a writer of lines (a ctl, exec) -/// hands an Edit the lines after it until it does not. -pub fn needsMore(arena: std.mem.Allocator, command: []const u8) bool { - var why: Why = .{}; - const src = std.fmt.allocPrint(arena, "{s}\n", .{command}) catch return false; - var ps: Parser = .{ .arena = arena, .src = src, .why = &why }; - while (true) { - const c = ps.parse(0) catch return std.mem.eql(u8, why.text(), "unmatched `{'") or ps.open_text; - if (c == null) return ps.open_text; - } -} - /// Whether `command` holds a `<`, `|` or `>`: its write is answered only /// when they have run (ninep/ctl.zig refuses other lines beside it). pub fn runsCommands(arena: std.mem.Allocator, command: []const u8) bool { @@ -1191,13 +1181,13 @@ test "an Edit wants the lines after it until its braces and text blocks close" { var arena_state = std.heap.ArenaAllocator.init(std.testing.allocator); defer arena_state.deinit(); const a = arena_state.allocator(); - try std.testing.expect(needsMore(a, ",x/foo/{")); - try std.testing.expect(needsMore(a, ",x/foo/{\ni/[/")); - try std.testing.expect(!needsMore(a, ",x/foo/{\ni/[/\n}")); - try std.testing.expect(needsMore(a, "$a\nline one")); - try std.testing.expect(!needsMore(a, "$a\nline one\n.")); - try std.testing.expect(!needsMore(a, ",s/{/x/")); - try std.testing.expect(!needsMore(a, ",x/foo/c/bar/")); + try std.testing.expect(waitsFor(a, ",x/foo/{") != .none); + try std.testing.expect(waitsFor(a, ",x/foo/{\ni/[/") != .none); + try std.testing.expectEqual(Wait.none, waitsFor(a, ",x/foo/{\ni/[/\n}")); + try std.testing.expect(waitsFor(a, "$a\nline one") != .none); + try std.testing.expectEqual(Wait.none, waitsFor(a, "$a\nline one\n.")); + try std.testing.expectEqual(Wait.none, waitsFor(a, ",s/{/x/")); + try std.testing.expectEqual(Wait.none, waitsFor(a, ",x/foo/c/bar/")); } test "the dot an Edit leaves selects what a change put where it stood" { diff --git a/src/tty/tty.zig b/src/tty/tty.zig index 5eecb3e9..8f5f102a 100644 --- a/src/tty/tty.zig +++ b/src/tty/tty.zig @@ -1403,7 +1403,7 @@ fn localSession( } } frames: while (!core.quit) { - pardes.turn.restoreSettled(); + pardes.turn.bump(&pardes.turn.restores); try core.pump(host); if (core.takeRestore()) |rp| blk: { const bytes = filesystem.readRestore(gpa, rp, core.settings.dump_dir.get()) catch |err| { diff --git a/test/output.zig b/test/output.zig index 8403effa..523e8129 100644 --- a/test/output.zig +++ b/test/output.zig @@ -387,7 +387,7 @@ test "result stepping reaches an unterminated last row" { const source = try p.setTestFile("one\ntwo\n"); const rows = try std.fmt.allocPrint(p.gpa, "{s}:1:1 first\n{s}:2:1 last", .{ source.file.?.path, source.file.?.path }); try panes.Output.fillResults(p, 0, "/tmp", .search, "", rows, 0); - try std.testing.expect(pardes.test_api.searchStep(p, 0, 1)); + try std.testing.expect(pardes.look.searchStep(p, 0, 1)); try std.testing.expectEqual(@as(usize, 1), source.search_row.?); const result = p.panes[source.search_pane.?].?; try std.testing.expectEqual(@as(i32, 1), result.body.cur_row); diff --git a/test/panes.zig b/test/panes.zig index 1b1b3eea..28f14d94 100644 --- a/test/panes.zig +++ b/test/panes.zig @@ -610,7 +610,7 @@ const BodyHitTests = struct { // Release at a different source row without an intermediate drag event. p.update(.{ .mouse = mouse(layer, last, prefix + 14, .release) }); // A stream: the last row from its start, indentation and all. - try std.testing.expect(std.mem.endsWith(u8, pardes.test_api.heldSelection(p, 0).?, "// body") and std.mem.startsWith(u8, pardes.test_api.heldSelection(p, 0).?, "body\n")); + try std.testing.expect(std.mem.endsWith(u8, pardes.exec.heldSelection(p, 0).?, "// body") and std.mem.startsWith(u8, pardes.exec.heldSelection(p, 0).?, "body\n")); p.update(.{ .mouse = mouse(layer, last, 10, .press) }); p.update(.{ .mouse = mouse(layer, last, 10, .release) }); try std.testing.expectEqual(expected, pane.body.cur_row); @@ -915,7 +915,7 @@ const TtySelectionTests = struct { JumpSelectionTests.drag(p, x + @as(u16, if (prompt) 0 else 1), y, x + 3, y + @as(u16, if (prompt) 0 else 1)); const expected = if (prompt) "$ ab" else "lpha\nbrav"; try std.testing.expectEqual(panes.Text.Mode.tty, pane.body.mode); - try std.testing.expectEqualStrings(expected, pardes.test_api.heldSelection(p, 0).?); + try std.testing.expectEqualStrings(expected, pardes.exec.heldSelection(p, 0).?); try std.testing.expectEqualStrings(expected, p.registers.text(p.gpa, '"') orelse return error.MissingAutomaticTtyYank); try noChildInput(p); @@ -934,7 +934,7 @@ const TtySelectionTests = struct { try std.testing.expect(!std.meta.eql(selected, normal.at(x + 4, y + 1).style.bg)); try std.testing.expect(!std.meta.eql(selected, normal.at(x, y).style.bg)); } - try std.testing.expectEqualStrings(expected, pardes.test_api.heldSelection(p, 0).?); + try std.testing.expectEqualStrings(expected, pardes.exec.heldSelection(p, 0).?); p.update(.{ .key = .{ .cp = 'y' } }); try std.testing.expectEqualStrings(expected, p.registers.text(p.gpa, '"').?); try noChildInput(p); @@ -942,11 +942,11 @@ const TtySelectionTests = struct { try std.testing.expectEqual(panes.Text.Mode.tty, pane.body.mode); try noChildInput(p); _ = try p.render(frame.allocator()); - try std.testing.expectEqualStrings(expected, pardes.test_api.heldSelection(p, 0).?); + try std.testing.expectEqualStrings(expected, pardes.exec.heldSelection(p, 0).?); p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b]133;C\x07" ++ std.mem.asBytes(&@as([30][12]u8, @splat("\r\nnew output".*))) } }); _ = try p.render(frame.allocator()); try std.testing.expectEqual(panes.Text.Mode.tty, pane.body.mode); - try std.testing.expectEqualStrings(expected, pardes.test_api.heldSelection(p, 0).?); + try std.testing.expectEqualStrings(expected, pardes.exec.heldSelection(p, 0).?); try std.testing.expectEqualStrings(expected, p.registers.text(p.gpa, '"').?); try noChildInput(p); } @@ -1007,7 +1007,7 @@ const TtySelectionTests = struct { try std.testing.expectEqualStrings(expected, written.written()); try std.testing.expectEqual(panes.Text.Mode.tty, p.panes[0].?.body.mode); try std.testing.expectEqual(panes.Text.Mode.tty, p.panes[1].?.body.mode); - try std.testing.expectEqualStrings("lpha\nbrav", pardes.test_api.heldSelection(p, 0).?); + try std.testing.expectEqualStrings("lpha\nbrav", pardes.exec.heldSelection(p, 0).?); } } } @@ -1277,7 +1277,7 @@ const ClickCursorTests = struct { const x = rect.x + config.GUTTER + panes.File.gutterWidth(pane); const y = bodyY(p, rect); JumpSelectionTests.drag(p, x + 1, y + 4, x + 3, y + 4); - try std.testing.expectEqualStrings("lph", pardes.test_api.heldSelection(p, 0).?); + try std.testing.expectEqualStrings("lph", pardes.exec.heldSelection(p, 0).?); for (0..2) |_| p.update(.{ .mouse = .{ .button = .wheel_down, .kind = .press, .col = x + 2, .row = y + 4 } }); try std.testing.expectEqual(@as(usize, 2), pane.file.?.scroll); _ = try p.render(frame.allocator()); @@ -1339,7 +1339,7 @@ const JumpSelectionTests = struct { else drag(p, x + first_col, y, x + last_col, y + 1); - const selected = try p.gpa.dupe(u8, pardes.test_api.heldSelection(p, 0) orelse return error.MissingMouseSelection); + const selected = try p.gpa.dupe(u8, pardes.exec.heldSelection(p, 0) orelse return error.MissingMouseSelection); defer p.gpa.free(selected); if (expected) |want| try std.testing.expectEqualStrings(want, selected); try std.testing.expect(std.mem.indexOfScalar(u8, selected, '\n') != null); @@ -1358,7 +1358,7 @@ const JumpSelectionTests = struct { try std.testing.expect(pane.file.?.scroll > 20); try LookResetTests.cleared(pane); try std.testing.expect(!pane.body.vsel.active); - try std.testing.expect(pardes.test_api.heldSelection(p, 0) == null); + try std.testing.expect(pardes.exec.heldSelection(p, 0) == null); try std.testing.expectEqual(@as(i32, 59), pane.body.cur_row); try std.testing.expectEqual(@as(i32, 0), pane.body.cur_col); @@ -1366,7 +1366,7 @@ const JumpSelectionTests = struct { // Back announces itself, so the body sits under a notice band now. const y2 = p.bodyTop(pane, p.rects[0]); drag(p, x + 1, y2, x + 3, y2 + 1); - try std.testing.expect(pardes.test_api.heldSelection(p, 0) != null); + try std.testing.expect(pardes.exec.heldSelection(p, 0) != null); p.update(.{ .key = .{ .cp = 'i', .ctrl = true } }); _ = frame.reset(.retain_capacity); _ = try p.render(frame.allocator()); @@ -1374,7 +1374,7 @@ const JumpSelectionTests = struct { try std.testing.expectEqual(@as(usize, 0), pane.file.?.scroll); try LookResetTests.cleared(pane); try std.testing.expect(!pane.body.vsel.active); - try std.testing.expect(pardes.test_api.heldSelection(p, 0) == null); + try std.testing.expect(pardes.exec.heldSelection(p, 0) == null); try std.testing.expectEqual(@as(i32, 0), pane.body.cur_row); try std.testing.expectEqual(@as(i32, 0), pane.body.cur_col); } @@ -1392,10 +1392,10 @@ const JumpSelectionTests = struct { // From the press to the end of its line, the line between whole, the // last from its start: no line numbers, no rectangle. drag(p, x + 2, y, x + 1, y + 2); - try std.testing.expectEqualStrings("pha\nbravo\nch", pardes.test_api.heldSelection(p, 0).?); + try std.testing.expectEqualStrings("pha\nbravo\nch", pardes.exec.heldSelection(p, 0).?); // Upward, the same text. drag(p, x + 1, y + 2, x + 2, y); - try std.testing.expectEqualStrings("pha\nbravo\nch", pardes.test_api.heldSelection(p, 0).?); + try std.testing.expectEqualStrings("pha\nbravo\nch", pardes.exec.heldSelection(p, 0).?); // A tag of several rows sweeps the same way. if (pane.tag.own) |own| p.gpa.free(own); pane.tag.own = try p.gpa.dupe(u8, "Save Del\nLook Edit"); @@ -2919,17 +2919,17 @@ const OutputTests = struct { } try std.testing.expectEqual(@as(usize, 2), count); try std.testing.expectEqual(matches[1], pane.search_row.?); - try std.testing.expect(pardes.test_api.searchStep(p, 0, -1)); + try std.testing.expect(pardes.look.searchStep(p, 0, -1)); try std.testing.expectEqual(matches[0], pane.search_row.?); try std.testing.expectEqual(@as(i32, 3), pane.body.cur_row); - try std.testing.expect(pardes.test_api.searchStep(p, 0, 1)); + try std.testing.expect(pardes.look.searchStep(p, 0, 1)); try std.testing.expectEqual(matches[1], pane.search_row.?); try std.testing.expectEqual(@as(i32, 5), pane.body.cur_row); - try std.testing.expect(pardes.test_api.searchStep(p, 0, 1)); + try std.testing.expect(pardes.look.searchStep(p, 0, 1)); try std.testing.expectEqual(matches[1], pane.search_row.?); pane.search_row = null; - try std.testing.expect(pardes.test_api.searchStep(p, 0, 1)); + try std.testing.expect(pardes.look.searchStep(p, 0, 1)); try std.testing.expectEqual(matches[0], pane.search_row.?); var frame = std.heap.ArenaAllocator.init(p.gpa); defer frame.deinit(); @@ -2971,11 +2971,11 @@ const OutputTests = struct { // still governs stepping when that output is attached to a source. restored_source.search_pane = restored_id; restored_source.search_row = null; - try std.testing.expect(pardes.test_api.searchStep(restored, 0, 1)); + try std.testing.expect(pardes.look.searchStep(restored, 0, 1)); try std.testing.expectEqual(matches[0], restored_source.search_row.?); - try std.testing.expect(pardes.test_api.searchStep(restored, 0, 1)); + try std.testing.expect(pardes.look.searchStep(restored, 0, 1)); try std.testing.expectEqual(matches[1], restored_source.search_row.?); - try std.testing.expect(pardes.test_api.searchStep(restored, 0, -1)); + try std.testing.expect(pardes.look.searchStep(restored, 0, -1)); try std.testing.expectEqual(matches[0], restored_source.search_row.?); // Editing drops source metadata; hidden context padding still keeps @@ -2983,9 +2983,9 @@ const OutputTests = struct { panes.File.setContent(p, file, try p.gpa.dupe(u8, file.content)); try std.testing.expectEqual(@as(usize, 0), file.location_rows.len); pane.search_row = null; - try std.testing.expect(pardes.test_api.searchStep(p, 0, 1)); + try std.testing.expect(pardes.look.searchStep(p, 0, 1)); try std.testing.expectEqual(matches[0], pane.search_row.?); - try std.testing.expect(pardes.test_api.searchStep(p, 0, 1)); + try std.testing.expect(pardes.look.searchStep(p, 0, 1)); try std.testing.expectEqual(matches[1], pane.search_row.?); } diff --git a/test/pdf.zig b/test/pdf.zig index cc4a258d..ea23f90a 100644 --- a/test/pdf.zig +++ b/test/pdf.zig @@ -1610,7 +1610,7 @@ test "PdfTint cycles pane-local state without adding tag clutter" { // here rather than inherited from init. _ = try p.newShell(1, ""); _ = layout.splitColumn(p, 0, 1, false); - pardes.test_api.sync(p); // rects for the new column, exactly as the two-pane boot did + p.sync(); // rects for the new column, exactly as the two-pane boot did try std.testing.expect(!hasPdf(p.panes[1].?)); try std.testing.expect(pardes.test_api.runBuiltin( p, @@ -1852,7 +1852,7 @@ test "PDF pane geometry change preserves its page-relative position" { // so the divider drag below needs a second column to take the width from. _ = try p.newShell(1, ""); _ = layout.splitColumn(p, 0, 1, false); - pardes.test_api.sync(p); // rects for the new column, exactly as the two-pane boot did + p.sync(); // rects for the new column, exactly as the two-pane boot did const pane = p.panes[0].?; const pv = &pane.pdf.?; p.native_images = true; @@ -1949,7 +1949,7 @@ test "PDF n/N addresses and reveals distinct MuPDF hits on one page" { var frame = std.heap.ArenaAllocator.init(gpa); defer frame.deinit(); - try std.testing.expect(pardes.test_api.searchStep(p, 0, 1)); + try std.testing.expect(pardes.look.searchStep(p, 0, 1)); try std.testing.expectEqual(@as(usize, 0), pv.search_hit); try std.testing.expectEqual(@as(usize, 0), pane.search_row.?); const first = try p.render(frame.allocator()); @@ -1968,14 +1968,14 @@ test "PDF n/N addresses and reveals distinct MuPDF hits on one page" { try std.testing.expect(first_y >= first_geometry.src.y and first_y < first_geometry.src.y + first_geometry.src.h); - try std.testing.expect(pardes.test_api.searchStep(p, 0, 1)); + try std.testing.expect(pardes.look.searchStep(p, 0, 1)); try std.testing.expectEqual(@as(usize, 1), pv.search_hit); try std.testing.expectEqual(@as(usize, 2), pane.search_row.?); _ = frame.reset(.retain_capacity); const second = try p.render(frame.allocator()); try std.testing.expectEqual(revision, second.images[0].?.native.revision); - try std.testing.expect(pardes.test_api.searchStep(p, 0, 1)); + try std.testing.expect(pardes.look.searchStep(p, 0, 1)); try std.testing.expectEqual(@as(usize, 2), pv.search_hit); try std.testing.expectEqual(@as(usize, 4), pane.search_row.?); _ = frame.reset(.retain_capacity); @@ -2092,7 +2092,7 @@ test "PDF native mouse selection, Look, and highlights share page geometry" { }; const word_col = selected_col orelse return error.PdfMouseMappingMissedWord; try std.testing.expect(std.ascii.findIgnoreCase( - pardes.test_api.heldSelection(p, 0).?, + pardes.exec.heldSelection(p, 0).?, "Pardes", ) != null); @@ -2368,7 +2368,7 @@ test "Esc back into a PDF keeps the offset within its page" { const doc = p.active; const dp = p.panes[doc].?; try std.testing.expect(dp.pdf != null); - pardes.test_api.sync(p); + p.sync(); // Read a little way DOWN the page you are on, then step away. const pv = &dp.pdf.?; @@ -2376,12 +2376,12 @@ test "Esc back into a PDF keeps the offset within its page" { const mid = pv.document_scroll_y; pv.scroll_to_page_pending = false; p.update(.{ .key = .{ .cp = 'n', .alt = true } }); // a shell under the doc - pardes.test_api.sync(p); + p.sync(); const shell = p.active; try std.testing.expect(shell != doc); p.update(.{ .key = .{ .cp = Key.escape } }); // Esc: back into the PDF - pardes.test_api.sync(p); + p.sync(); try std.testing.expectEqual(doc, p.active); // The jumps stack records a PDF as its PAGE, so returning revealed the page -- cgit v1.3 From 80314064f6e81c8828340e010202b446f0e1f36d Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Fri, 23 Oct 2026 11:00:44 -0300 Subject: Audit (misc): std mkdir -p and JSON escaping, a 9P late failure's errno from ctl.failureErrno, dead switches and dumpHex out Co-Authored-By: Claude Opus 5.5 --- src/9p_io.zig | 112 +++++++++++++++++++++----------------------------- src/File.zig | 5 +-- src/Output.zig | 52 ++++++----------------- src/builtins.zig | 86 ++++++++++++-------------------------- src/builtins_json.zig | 22 +++------- src/config.zig | 75 ++++++--------------------------- src/dump.zig | 11 +---- src/esp32p4/uart.zig | 16 -------- src/fs.zig | 12 +----- src/gui/gui.zig | 13 ++---- src/hunks.zig | 6 +-- src/locations.zig | 25 +++++------ src/look.zig | 8 ++-- src/main.zig | 40 +++++++----------- src/syntax.zig | 5 +-- src/tagline.zig | 7 +--- src/terminal.zig | 4 +- src/web.zig | 59 +++++--------------------- 18 files changed, 156 insertions(+), 402 deletions(-) (limited to 'src/Output.zig') diff --git a/src/9p_io.zig b/src/9p_io.zig index a825475f..a089a7cf 100644 --- a/src/9p_io.zig +++ b/src/9p_io.zig @@ -11,10 +11,7 @@ const quic = if (quic_enabled) @import("9p_quic.zig") else struct {}; const log = std.log.scoped(.ninep); -pub const darwin = switch (builtin.os.tag) { - .macos, .ios, .tvos, .watchos, .visionos => true, - else => false, -}; +pub const darwin = builtin.os.tag.isDarwin(); pub const supported = builtin.os.tag == .linux or darwin; pub const sun_path_len = @typeInfo(@FieldType(libc.sockaddr.un, "path")).array.len; @@ -47,15 +44,8 @@ pub fn statNoFollow(path: [:0]const u8) ?FileFacts { pub fn ensureSocketDir(dir: [:0]const u8) bool { if (dir.len == 0) return false; - var partial: [sun_path_len:0]u8 = undefined; - @memcpy(partial[0 .. dir.len + 1], dir[0 .. dir.len + 1]); - for (1..dir.len) |i| { - if (dir[i] != '/') continue; - partial[i] = 0; - _ = libc.mkdir(partial[0..i :0], 0o700); - partial[i] = '/'; - } - _ = libc.mkdir(dir, 0o700); + // A failure shows in the stat below. + _ = std.Io.Dir.cwd().createDirPathStatus(std.Io.Threaded.global_single_threaded.io(), dir, .fromMode(0o700)) catch {}; const stat = statNoFollow(dir) orelse return false; return stat.mode & 0o170000 == 0o040000 and stat.uid == libc.getuid() and stat.mode & 0o077 == 0; } @@ -394,11 +384,11 @@ pub const Listener = struct { // settle in the same wait is told to this write too. if (l.core == core and core.fs.late_failure_len != 0) { const late = core.fs.late_failure[0..core.fs.late_failure_len]; - // What is not there (`no such directory`) is ENOENT, as a - // builtin's failure saying so is (ctl.failureErrno). - const errno = if (std.mem.indexOf(u8, late, "no such") != null or std.mem.indexOf(u8, late, "not found") != null) - pardes.ctlfs.E.NOENT - else if (std.mem.indexOf(u8, late, "no space") != null) pardes.ctlfs.E.NOSPC else if (std.mem.indexOf(u8, late, "permission denied") != null) pardes.ctlfs.E.PERM else if (std.mem.indexOf(u8, late, "invalid") != null) pardes.ctlfs.E.INVAL else pardes.ctlfs.E.IO; + // The errno a builtin's failure in the same words has; what + // that leaves EIO and says `no space` (a full disk under a + // Save) is ENOSPC. + const said = @import("ninep/ctl.zig").failureErrno(late); + const errno = if (said == pardes.ctlfs.E.IO and std.mem.indexOf(u8, late, "no space") != null) pardes.ctlfs.E.NOSPC else said; const failed = pardes.ctlfs.failText(req.tag, errno, late); // Its err record says it (the path in it), the one record: it // was said with no msg while this waited (fs.write_waits). @@ -1017,21 +1007,11 @@ fn onFatalSignal(s: std.posix.SIG) callconv(.c) void { pub fn sweepDeadSockets(io: std.Io, dir: [:0]const u8) void { if (comptime !supported) return; var names: [8192]u8 = undefined; - var staged: usize = 0; - { - const d = std.Io.Dir.openDirAbsolute(io, dir, .{ .iterate = true }) catch return; - defer d.close(io); - var read_buf: [std.Io.Dir.Iterator.reader_buffer_len]u8 align(@alignOf(usize)) = undefined; - var reader: std.Io.Dir.Reader = .init(d, &read_buf); - while (true) { - const listed = (reader.next(io) catch break) orelse break; - if (deadSocketPid(listed.name) == null) continue; - if (staged + 1 + listed.name.len > names.len) break; - names[staged] = @intCast(listed.name.len); - @memcpy(names[staged + 1 ..][0..listed.name.len], listed.name); - staged += 1 + listed.name.len; + const staged = stageNames(io, dir, &names, struct { + fn keep(name: []const u8) bool { + return deadSocketPid(name) != null; } - } + }.keep); var i: usize = 0; while (i < staged) { const name = names[i + 1 ..][0..names[i]]; @@ -1048,6 +1028,28 @@ pub fn sweepDeadSockets(io: std.Io, dir: [:0]const u8) void { } } +/// The names in `dir` that `keep` takes (all with none), into `names` as a length byte and +/// the name each, until it is full; the bytes staged. They are staged +/// before anything is unlinked, so a sweep never asks a directory to keep +/// reading while it is being edited. +fn stageNames(io: std.Io, dir: [:0]const u8, names: []u8, comptime keep: ?fn ([]const u8) bool) usize { + const d = std.Io.Dir.openDirAbsolute(io, dir, .{ .iterate = true }) catch return 0; + defer d.close(io); + var read_buf: [std.Io.Dir.Iterator.reader_buffer_len]u8 align(@alignOf(usize)) = undefined; + var reader: std.Io.Dir.Reader = .init(d, &read_buf); + var staged: usize = 0; + while (true) { + const listed = (reader.next(io) catch break) orelse break; + if (listed.name.len == 0 or listed.name.len > 255) continue; + if (keep) |takes| if (!takes(listed.name)) continue; + if (staged + 1 + listed.name.len > names.len) break; + names[staged] = @intCast(listed.name.len); + @memcpy(names[staged + 1 ..][0..listed.name.len], listed.name); + staged += 1 + listed.name.len; + } + return staged; +} + /// The pid a `pardes-9p-.sock` name carries, or null for any other. fn deadSocketPid(name: []const u8) ?std.c.pid_t { if (!std.mem.startsWith(u8, name, prefix) or !std.mem.endsWith(u8, name, ".sock")) return null; @@ -1279,24 +1281,8 @@ fn ourSocket(target: []const u8, sockets: []const u8) bool { fn sweepRegistry(io: std.Io, svc: [:0]const u8, sockets: []const u8) void { if (comptime !supported) return; - // The names are staged before anything is unlinked, so the sweep - // never asks a directory to keep reading while it is being edited. var names: [4096]u8 = undefined; - var staged: usize = 0; - { - const dir = std.Io.Dir.openDirAbsolute(io, svc, .{ .iterate = true }) catch return; - defer dir.close(io); - var read_buf: [std.Io.Dir.Iterator.reader_buffer_len]u8 align(@alignOf(usize)) = undefined; - var reader: std.Io.Dir.Reader = .init(dir, &read_buf); - while (true) { - const listed = (reader.next(io) catch break) orelse break; - if (listed.name.len == 0 or listed.name.len > 255) continue; - if (staged + 1 + listed.name.len > names.len) break; - names[staged] = @intCast(listed.name.len); - @memcpy(names[staged + 1 ..][0..listed.name.len], listed.name); - staged += 1 + listed.name.len; - } - } + const staged = stageNames(io, svc, &names, null); var reaped: usize = 0; var i: usize = 0; @@ -2179,10 +2165,8 @@ pub const Client = struct { if (comptime !supported) return error.Unsupported; var names: [max_depth][]const u8 = undefined; const n = try elements(path, &names); - var sock_buf: [sun_path_len]u8 = undefined; - const sock = try resolve(&sock_buf, dial); var remote: RemoteError = .{}; - return fetchBytes(gpa, sock, names[0..n], &remote, null, display_path, @min(max_bytes, limits.max_file_bytes)) catch |err| { + return fetchBytes(gpa, dial, names[0..n], &remote, null, display_path, @min(max_bytes, limits.max_file_bytes)) catch |err| { if (err == error.Remote) said = remote; return err; }; @@ -2209,10 +2193,8 @@ pub const Client = struct { if (comptime !supported) return error.Unsupported; var names: [max_depth][]const u8 = undefined; const n = try elements(path, &names); - var sock_buf: [sun_path_len]u8 = undefined; - const sock = try resolve(&sock_buf, dial); var remote: RemoteError = .{}; - const result = fetchBytes(gpa, sock, names[0..n], &remote, bytes, path, limits.max_file_bytes) catch |err| { + const result = fetchBytes(gpa, dial, names[0..n], &remote, bytes, path, limits.max_file_bytes) catch |err| { if (err == error.Remote) said = remote; return err; }; @@ -2470,7 +2452,7 @@ pub const Client = struct { fn fetchBytes( gpa: std.mem.Allocator, - sock: Dial, + dial: []const u8, names: []const []const u8, remote: *RemoteError, write_bytes: ?[]const u8, @@ -2478,7 +2460,7 @@ pub const Client = struct { read_limit: usize, ) ![]u8 { if (comptime !supported) return Error.Dial; - const s = try startSession(gpa, sock, display_path); + const s = try startSession(gpa, dial, display_path); defer endSession(gpa, s); var out: std.Io.Writer.Allocating = .init(gpa); errdefer out.deinit(); @@ -2486,8 +2468,10 @@ pub const Client = struct { return out.toOwnedSlice(); } - /// A connected session whose requests have the usual deadline. - fn startSession(gpa: std.mem.Allocator, sock: Dial, display_path: []const u8) !*Session { + /// A connected session at `dial` whose requests have the usual deadline. + fn startSession(gpa: std.mem.Allocator, dial: []const u8, display_path: []const u8) !*Session { + var sock_buf: [sun_path_len]u8 = undefined; + const sock = try resolve(&sock_buf, dial); const deadline = nowMs() +| budget_ms; const s = try gpa.create(Session); s.* = .{ .fd = -1, .deadline = deadline, .display_path = display_path }; @@ -2518,11 +2502,9 @@ pub const Client = struct { if (comptime !supported) return error.Unsupported; var names: [max_depth][]const u8 = undefined; const n = try elements(path, &names); - var sock_buf: [sun_path_len]u8 = undefined; - const sock = try resolve(&sock_buf, dial); var remote: RemoteError = .{}; errdefer said = remote; - const s = try startSession(gpa, sock, path); + const s = try startSession(gpa, dial, path); defer endSession(gpa, s); const fid = (try walkTo(s, names[0..n], &remote)).fid; _ = try s.ask(.{ .open = .{ .fid = fid, .mode = ninep.ordwr } }, &remote); @@ -2562,10 +2544,8 @@ pub const Client = struct { if (comptime !supported) return error.Unsupported; var names: [max_depth][]const u8 = undefined; const n = try elements(path, &names); - var sock_buf: [sun_path_len]u8 = undefined; - const sock = try resolve(&sock_buf, dial); var remote: RemoteError = .{}; - const s = try startSession(gpa, sock, path); + const s = try startSession(gpa, dial, path); defer endSession(gpa, s); const fid = (try walkTo(s, names[0..n], &remote)).fid; _ = try s.ask(.{ .open = .{ .fid = fid, .mode = ninep.ordwr } }, &remote); @@ -2642,7 +2622,7 @@ pub const Client = struct { const before = nowMs(); try testing.expectError( Error.Dial, - fetchBytes(testing.allocator, .{ .unix = "/tmp/pardes-9p-no-such-socket.sock" }, names[0..n], &remote, null, "/pane/1/body", limits.max_file_bytes), + fetchBytes(testing.allocator, "/tmp/pardes-9p-no-such-socket.sock", names[0..n], &remote, null, "/pane/1/body", limits.max_file_bytes), ); try testing.expect(nowMs() - before < budget_ms); } diff --git a/src/File.zig b/src/File.zig index e92efaba..b1a4271f 100644 --- a/src/File.zig +++ b/src/File.zig @@ -2153,15 +2153,14 @@ pub const DiffOutput = struct { text[at] = '\n'; at += 1; } + // An empty slot, else the least recently used. var oldest: usize = 0; for (&o.slots, 0..) |*slot, i| { const e = slot.* orelse { oldest = i; break; }; - if (o.slots[oldest]) |old| if (e.used < old.used) { - oldest = i; - }; + if (e.used < o.slots[oldest].?.used) oldest = i; } if (o.slots[oldest]) |old| { p.gpa.free(old.text); diff --git a/src/Output.zig b/src/Output.zig index 3fc08d9a..9a11b2fc 100644 --- a/src/Output.zig +++ b/src/Output.zig @@ -949,51 +949,23 @@ fn helpContent(gpa: std.mem.Allocator, prefix: []const u8) ![]u8 { "C-left-click definition, by mouse\n" ++ "SPC l ... hover, rename, symbols,\n" ++ " calls, types: above\n"; - var len: usize = if (prefix.len == 0) - full_header.len + language_footer.len - else - group_header.len + prefix.len * 2 + 2; - if (show_calls_help) len += calls_help.len; + var out: std.Io.Writer.Allocating = .init(gpa); + errdefer out.deinit(); + const w = &out.writer; + if (prefix.len == 0) try w.writeAll(full_header) else { + try w.writeAll(group_header); + for (prefix) |c| try w.print(" {c}", .{c}); + try w.writeAll("\n\n"); + } for (pardes.builtin_rows) |row| { // a path-less builtin filters as the empty path: in the full listing // (which starts with nothing) and out of every group if (!std.mem.startsWith(u8, row.path orelse "", prefix)) continue; - len += row.line.len + 1; - } - const content = try gpa.alloc(u8, len); - var at: usize = 0; - if (prefix.len == 0) { - @memcpy(content[0..full_header.len], full_header); - at = full_header.len; - } else { - @memcpy(content[0..group_header.len], group_header); - at = group_header.len; - for (prefix) |c| { - content[at] = ' '; - content[at + 1] = c; - at += 2; - } - content[at] = '\n'; - content[at + 1] = '\n'; - at += 2; - } - for (pardes.builtin_rows) |row| { - if (!std.mem.startsWith(u8, row.path orelse "", prefix)) continue; - @memcpy(content[at..][0..row.line.len], row.line); - at += row.line.len; - content[at] = '\n'; - at += 1; - } - if (show_calls_help) { - @memcpy(content[at..][0..calls_help.len], calls_help); - at += calls_help.len; - } - if (prefix.len == 0) { - @memcpy(content[at..][0..language_footer.len], language_footer); - at += language_footer.len; + try w.print("{s}\n", .{row.line}); } - std.debug.assert(at == content.len); - return content; + if (show_calls_help) try w.writeAll(calls_help); + if (prefix.len == 0) try w.writeAll(language_footer); + return out.toOwnedSlice(); } pub fn openHelp(p: *Pardes, id: usize, prefix: []const u8) !void { diff --git a/src/builtins.zig b/src/builtins.zig index 7b1541ac..64710554 100644 --- a/src/builtins.zig +++ b/src/builtins.zig @@ -109,54 +109,27 @@ pub fn absentWhy(name: []const u8) ?[]const u8 { return null; } -fn manualBuiltinCount() comptime_int { +fn manualBuiltinList() []const type { comptime { - var count = 0; + @setEvalBranchQuota(4000); + var list: []const type = &.{}; for (@typeInfo(@This()).@"struct".decl_names) |d| { if (@TypeOf(@field(@This(), d)) != type) continue; const T = @field(@This(), d); if (@typeInfo(T) != .@"struct" or !@hasDecl(T, "run") or !isEnabled(T)) continue; if (@TypeOf(T.run) != fn (Ctx) void) @compileError(d ++ ".run must have signature fn (Ctx) void"); - count += 1; - } - return count; - } -} - -fn manualBuiltinList() [manualBuiltinCount()]type { - comptime { - @setEvalBranchQuota(4000); - var list: [manualBuiltinCount()]type = undefined; - var count = 0; - for (@typeInfo(@This()).@"struct".decl_names) |d| { - if (@TypeOf(@field(@This(), d)) != type) continue; - const T = @field(@This(), d); - if (@typeInfo(T) != .@"struct" or !@hasDecl(T, "run") or !isEnabled(T)) continue; - list[count] = T; - count += 1; + list = list ++ .{T}; } return list; } } -fn settingCount() comptime_int { +fn settingList() []const config.Runtime.Setting { comptime { - var count = 0; + var list: []const config.Runtime.Setting = &.{}; for (config.Runtime.settings) |setting| if (setting.enabled(capabilities)) { - count += 1; - }; - return count; - } -} - -fn settingList() [settingCount()]config.Runtime.Setting { - comptime { - var list: [settingCount()]config.Runtime.Setting = undefined; - var count = 0; - for (config.Runtime.settings) |setting| if (setting.enabled(capabilities)) { - list[count] = setting; - count += 1; + list = list ++ .{setting}; }; return list; } @@ -197,11 +170,17 @@ pub const registry = struct { return @Enum(Tag, .exhaustive, &names, &std.simd.iota(Tag, count)); } + /// What a hand-written builtin says as `name` (`pub const takes_arg = + /// true;`), `default` when it says nothing, and `setting` for a setting. + fn declOr(b: Builtin(), comptime name: []const u8, default: anytype, setting: @TypeOf(default)) @TypeOf(default) { + inline for (comptime manualBuiltinList(), 0..) |T, i| + if (@backingInt(b) == i) return if (@hasDecl(T, name)) @field(T, name) else default; + return setting; + } + pub fn takesArg(b: Builtin()) bool { - inline for (manualBuiltinList(), 0..) |T, i| - if (@backingInt(b) == i) return @hasDecl(T, "takes_arg") and T.takes_arg; // Every setting takes its value, and a switch flips when bare. - return true; + return declOr(b, "takes_arg", false, true); } /// Whether the word takes its argument joined by a `+` as one word a @@ -209,9 +188,7 @@ pub const registry = struct { /// that says `pub const plus_arg = true;`: others have arguments a `+` /// may be in (`Dump+2024.zon` is a name, not Dump's argument). pub fn plusArg(b: Builtin()) bool { - inline for (manualBuiltinList(), 0..) |T, i| - if (@backingInt(b) == i) return @hasDecl(T, "plus_arg") and T.plus_arg; - return false; + return declOr(b, "plus_arg", false, false); } /// Whether the word means nothing without its argument (`Mount`, @@ -222,15 +199,11 @@ pub const registry = struct { /// it says `pub const needs: PaneKind = .terminal;`, and on any other /// pane it is refused (exec.runBuiltinFrom), as Repl and Edit are. pub fn needs(b: Builtin()) ?PaneKind { - inline for (manualBuiltinList(), 0..) |T, i| - if (@backingInt(b) == i) return if (@hasDecl(T, "needs")) T.needs else null; - return null; + return declOr(b, "needs", @as(?PaneKind, null), null); } pub fn requiresArg(b: Builtin()) bool { - inline for (manualBuiltinList(), 0..) |T, i| - if (@backingInt(b) == i) return @hasDecl(T, "requires_arg") and T.requires_arg; - inline for (comptime settingList(), manualBuiltinCount()..) |setting, i| + inline for (comptime settingList(), comptime manualBuiltinList().len..) |setting, i| if (@backingInt(b) == i) return switch (setting.action) { // a switch flips bare, a choice steps, and DumpDir and Shell bare // are the default @@ -239,35 +212,28 @@ pub const registry = struct { // bare, it says the current value (exec.applySettingBuiltin) .tab, .callstack_depth => false, }; - unreachable; + return declOr(b, "requires_arg", false, false); } pub fn scope(b: Builtin()) Scope { - inline for (manualBuiltinList(), 0..) |T, i| - if (@backingInt(b) == i) return if (@hasDecl(T, "scope")) T.scope else .pane; - return .session; // a setting + return declOr(b, "scope", Scope.pane, .session); } pub fn outputTraits(b: Builtin()) ?OutputTraits { - inline for (manualBuiltinList(), 0..) |T, i| - if (@backingInt(b) == i) return if (@hasDecl(T, "output")) T.output else null; - inline for (comptime settingList(), manualBuiltinCount()..) |_, i| - if (@backingInt(b) == i) return null; - unreachable; + return declOr(b, "output", @as(?OutputTraits, null), null); } /// Does this builtin say its own name on the message row before it runs? /// The ones that own that row themselves declare `quiet` and do not. pub fn announces(b: Builtin()) bool { - inline for (manualBuiltinList(), 0..) |T, i| - if (@backingInt(b) == i) return !(@hasDecl(T, "quiet") and T.quiet); - return true; // a setting builtin changes something invisible; say so + // a setting builtin changes something invisible; say so + return !declOr(b, "quiet", false, false); } pub fn dispatch(b: Builtin(), c: Ctx) void { - inline for (manualBuiltinList(), 0..) |T, i| + inline for (comptime manualBuiltinList(), 0..) |T, i| if (@backingInt(b) == i) return T.run(c); - inline for (comptime settingList(), manualBuiltinCount()..) |setting, i| + inline for (comptime settingList(), comptime manualBuiltinList().len..) |setting, i| if (@backingInt(b) == i) return exec.applySettingBuiltin(c.p, setting, c.arg); unreachable; } diff --git a/src/builtins_json.zig b/src/builtins_json.zig index 7f998388..4440130d 100644 --- a/src/builtins_json.zig +++ b/src/builtins_json.zig @@ -11,17 +11,7 @@ const builtins = @import("builtins.zig"); const config = @import("config.zig"); const ctl = @import("ninep/ctl.zig"); -fn str(w: *std.Io.Writer, s: []const u8) !void { - try w.writeByte('"'); - for (s) |c| switch (c) { - '"' => try w.writeAll("\\\""), - '\\' => try w.writeAll("\\\\"), - '\n' => try w.writeAll("\\n"), - 0...9, 11...0x1f => try w.print("\\u{x:0>4}", .{c}), - else => try w.writeByte(c), - }; - try w.writeByte('"'); -} +const str = std.json.Stringify.encodeJsonString; const Entry = struct { name: []const u8, row: usize }; @@ -39,7 +29,7 @@ pub fn write(w: *std.Io.Writer) !void { const b = row.cmd; const name = @tagName(b); try w.writeAll(" {\"name\": "); - try str(w, name); + try str(name, .{}, w); try w.writeAll(", \"leader\": "); if (row.path) |p| { try w.writeAll("\"SPC"); @@ -55,21 +45,21 @@ pub fn write(w: *std.Io.Writer) !void { while (parts.next()) |part| if (part.len > 0) { if (!first) try w.writeAll(", "); first = false; - try str(w, part); + try str(part, .{}, w); }; try w.writeAll("], \"arg\": "); try w.writeAll(if (builtins.registry.takesArg(b)) "true" else "false"); try w.writeAll(", \"scope\": "); - try str(w, if (b == .Edit) "both" else if (builtins.registry.scope(b) == .session) "root" else "pane"); + try str(if (b == .Edit) "both" else if (builtins.registry.scope(b) == .session) "root" else "pane", .{}, w); const setting = config.Runtime.find(name); try w.writeAll(", \"setting\": "); try w.writeAll(if (setting != null) "true" else "false"); try w.writeAll(", \"choices\": "); - if (setting) |s| if (config.Runtime.choices(s.action)) |v| try str(w, v) else try w.writeAll("null") else try w.writeAll("null"); + if (setting) |s| if (config.Runtime.choices(s.action)) |v| try str(v, .{}, w) else try w.writeAll("null") else try w.writeAll("null"); var buf: [2048]u8 = undefined; const doc = if (setting) |s| s.doc else ctl.summaryOf(name, &buf); try w.writeAll(", \"doc\": "); - try str(w, doc); + try str(doc, .{}, w); try w.writeAll(if (n + 1 < order.len) "},\n" else "}\n"); } try w.writeAll("]\n"); diff --git a/src/config.zig b/src/config.zig index 5251b1e5..1fbf0d1b 100644 --- a/src/config.zig +++ b/src/config.zig @@ -293,9 +293,6 @@ pub const back_out: []const Chord = &.{.{ .cp = Key.escape, .shift = true }}; pub const tty_toggle_default: u21 = 'b'; -// OSC 133 prompt cells are hidden in normal mode; input columns stay intact. -pub const tty_blank: enum { prompt, prompt_and_input } = .prompt; - // Projected colors below this contrast use the theme's more legible anchor. pub const tty_filter_min_contrast: f64 = 1.5; @@ -386,9 +383,6 @@ pub const gui_topbar_pane_border_px: u8 = 1; // null follows the theme's scrollbar track. pub const gui_topbar_pane_border_rgb: ?[3]u8 = null; -// Transparency requires the SDL readback/blit path, even with an opaque theme. -pub const gui_transparent: bool = false; - // A vertical wheel tick suppresses this many subsequent horizontal ticks. pub const wheel_guard_ticks: u8 = 3; @@ -1428,12 +1422,12 @@ pub const Runtime = struct { /// effect but set by no word follows, after a blank line. pub fn writeReport(out: *std.Io.Writer, context: ReportContext) !void { const state = context.state; - for (settings) |setting| switch (setting.action) { + // TaglineSize is said wherever the shell sizes its tag, by its word + // or only at build time. + for (settings) |setting| if (!(if (setting.action == .tagline_size) context.capabilities.tagline_font_size else setting.enabled(context.capabilities))) + try out.print("# {s} unsupported\n", .{setting.word}) + else switch (setting.action) { .toggle => |field| { - if (!setting.enabled(context.capabilities)) { - try out.print("# {s} unsupported\n", .{setting.word}); - continue; - } const value = switch (field) { inline else => |f| @field(state, @tagName(f)), }; @@ -1443,18 +1437,8 @@ pub const Runtime = struct { try out.print("ThemeFile {s}\n", .{path}) else try out.print("{s} {s}\n", .{ setting.word, context.theme_name }), - .window_opacity => { - if (setting.enabled(context.capabilities)) - try out.print("{s} {d}\n", .{ setting.word, state.window_opacity }) - else - try out.print("# {s} unsupported\n", .{setting.word}); - }, - .window_blur => { - if (setting.enabled(context.capabilities)) - try out.print("{s} {d}\n", .{ setting.word, state.window_blur }) - else - try out.print("# {s} unsupported\n", .{setting.word}); - }, + .window_opacity => try out.print("{s} {d}\n", .{ setting.word, state.window_opacity }), + .window_blur => try out.print("{s} {d}\n", .{ setting.word, state.window_blur }), .dump_dir => { const dir = if (state.dump_dir.len > 0) state.dump_dir.get() else context.default_dump_dir; if (dir.len > 0) try out.print("{s} {s}\n", .{ setting.word, dir }) else try out.print("# {s} (none)\n", .{setting.word}); @@ -1466,9 +1450,7 @@ pub const Runtime = struct { const chosen = state.shell.requested.get(); try out.print("{s} {s}\n", .{ setting.word, if (chosen.len == 0) context.compiled_default_shell else chosen }); }, - .font => if (!setting.enabled(context.capabilities)) - try out.print("# {s} unsupported\n", .{setting.word}) - else { + .font => { // As `Font` takes it, `name:size`: the one asked for, else // the one in use. const f = &state.font; @@ -1483,28 +1465,14 @@ pub const Runtime = struct { if (f.requested_size_hundredths != 0) try out.print(":{d}.{d:0>2}", .{ f.requested_size_hundredths / 100, f.requested_size_hundredths % 100 }); try out.writeByte('\n'); }, - .tagline_size => if (!context.capabilities.tagline_font_size) - try out.print("# {s} unsupported\n", .{setting.word}) - else - try out.print("{s} {d}\n", .{ setting.word, state.font.tagline_percent }), + .tagline_size => try out.print("{s} {d}\n", .{ setting.word, state.font.tagline_percent }), // Each a switch of its own, the one in use on. - .transition => |transition| if (!setting.enabled(context.capabilities)) - try out.print("# {s} unsupported\n", .{setting.word}) - else - try out.print("{s} {s}\n", .{ setting.word, onOff(state.panel_transition == transition) }), + .transition => |transition| try out.print("{s} {s}\n", .{ setting.word, onOff(state.panel_transition == transition) }), .scene => |effect| { - if (!setting.enabled(context.capabilities)) { - try out.print("# {s} unsupported\n", .{setting.word}); - continue; - } const level = state.post.level(effect); if (level == 0) try out.print("{s} off\n", .{setting.word}) else try out.print("{s} {d}\n", .{ setting.word, level }); }, .shader => { - if (!setting.enabled(context.capabilities)) { - try out.print("# {s} unsupported\n", .{setting.word}); - continue; - } var files: usize = 0; for (state.post.list()) |entry| if (entry.scene == null) { try out.print("{s} {s}\n", .{ setting.word, entry.path.get() }); @@ -1512,25 +1480,16 @@ pub const Runtime = struct { }; if (files == 0) try out.print("{s} off\n", .{setting.word}); }, - .shader_animation => if (setting.enabled(context.capabilities)) - try out.print("{s} {s}\n", .{ setting.word, @tagName(state.shader_animation) }) - else - try out.print("# {s} unsupported\n", .{setting.word}), + .shader_animation => try out.print("{s} {s}\n", .{ setting.word, @tagName(state.shader_animation) }), .choice => |which| switch (which) { inline else => |field| try out.print("{s} {s}\n", .{ setting.word, @tagName(@field(state, @tagName(field))) }), }, - .lift => if (setting.enabled(context.capabilities)) - try out.print("{s} {s}\n", .{ setting.word, @tagName(state.lift) }) - else - try out.print("# {s} unsupported\n", .{setting.word}), + .lift => try out.print("{s} {s}\n", .{ setting.word, @tagName(state.lift) }), .motion => try out.print("{s} {s}\n", .{ setting.word, @tagName(state.motion) }), .inactive_dim => try out.print("{s} {d}\n", .{ setting.word, state.inactive_dim }), .callstack_depth => try out.print("{s} {d}\n", .{ setting.word, state.callstack_depth }), .tab => try out.print("{s} {d}\n", .{ setting.word, state.tab }), - .grip_width => if (setting.enabled(context.capabilities)) - try out.print("{s} {d}\n", .{ setting.word, state.grip_width }) - else - try out.print("# {s} unsupported\n", .{setting.word}), + .grip_width => try out.print("{s} {d}\n", .{ setting.word, state.grip_width }), }; if (context.locations.len > 0) try out.print("LocationsConfig {s}\n", .{context.locations}); @@ -1566,14 +1525,6 @@ pub const Runtime = struct { try out.print("# Pet: {s}\n", .{@tagName(state.pet)}); } - test "setting names are unique" { - for (settings, 0..) |setting, i| { - try std.testing.expect(setting.word.len > 0); - for (settings[i + 1 ..]) |later| - try std.testing.expect(!std.mem.eql(u8, setting.word, later.word)); - } - } - test "panel and scene effects flip bare and are set by on and off" { var state: Runtime = .{}; const slide = findAction(.{ .transition = .slide }).?; diff --git a/src/dump.zig b/src/dump.zig index 67934e0a..c8c302ab 100644 --- a/src/dump.zig +++ b/src/dump.zig @@ -38,16 +38,7 @@ pub fn outPath(buf: *[1024:0]u8, dir_setting: []const u8) ?[:0]const u8 { return std.fmt.bufPrintSentinel(buf, "{s}", .{std.mem.span(p)}, 0) catch null; var dir_buf: [900]u8 = undefined; const dir = directory(&dir_buf, dir_setting) orelse return null; - var dz: [901:0]u8 = undefined; - @memcpy(dz[0..dir.len], dir); - dz[dir.len] = 0; - // Each missing directory on the way, as `mkdir -p`: EEXIST is fine. - for (dz[1..dir.len], 1..) |c, i| if (c == '/') { - dz[i] = 0; - _ = std.c.mkdir(dz[0..i :0], 0o755); - dz[i] = '/'; - }; - _ = std.c.mkdir(dz[0..dir.len :0], 0o755); + _ = std.Io.Dir.cwd().createDirPathStatus(std.Io.Threaded.global_single_threaded.io(), dir, .fromMode(0o755)) catch {}; var ts: std.c.timespec = undefined; _ = std.c.clock_gettime(.REALTIME, &ts); const es: std.time.epoch.EpochSeconds = .{ .secs = @intCast(@max(0, ts.sec)) }; diff --git a/src/esp32p4/uart.zig b/src/esp32p4/uart.zig index 5690520c..a185737d 100644 --- a/src/esp32p4/uart.zig +++ b/src/esp32p4/uart.zig @@ -126,22 +126,6 @@ pub fn writeByte(b: u8) void { uart0.pushByte(b); } -/// Emit `n` bytes read from `addr` as two hex digits each, computing the digits arithmetically so -/// nothing here reads a lookup table. Used to answer "does a load from this address return what the -/// linker put there", which is not a question a string literal can be trusted to ask. -pub fn dumpHex(addr: u32, n: u32) void { - const p: [*]const volatile u8 = @ptrFromInt(addr); - var i: u32 = 0; - while (i < n) : (i += 1) { - const byte = p[i]; - for ([2]u8{ byte >> 4, byte & 0xf }) |nib| { - writeByte(if (nib < 10) '0' + nib else 'a' + (nib - 10)); - } - } - writeByte('\r'); - writeByte('\n'); -} - /// A u32 as eight hex digits, reading no memory at all. pub fn dumpWord(v: u32) void { var shift: u5 = 28; diff --git a/src/fs.zig b/src/fs.zig index 032ab9c0..e809eda5 100644 --- a/src/fs.zig +++ b/src/fs.zig @@ -686,18 +686,10 @@ test "a path with a part over 255 bytes is NameTooLong, never a panic" { /// that follows. pub fn makeDirs(dir: []const u8) void { if (comptime !platform_has_fs) return; - var z: [4096:0]u8 = undefined; - if (dir.len == 0 or dir.len >= z.len) return; - @memcpy(z[0..dir.len], dir); - z[dir.len] = 0; + if (dir.len == 0) return; pardes.turn.yield(); defer pardes.turn.back(); - for (z[1..dir.len], 1..) |c, i| if (c == '/') { - z[i] = 0; - _ = libc.mkdir(z[0..i :0], 0o755); - z[i] = '/'; - }; - _ = libc.mkdir(z[0..dir.len :0], 0o755); + _ = std.Io.Dir.cwd().createDirPathStatus(std.Io.Threaded.global_single_threaded.io(), dir, .fromMode(0o755)) catch {}; } /// Whether `dir` is not there to make because one above it refuses: its diff --git a/src/gui/gui.zig b/src/gui/gui.zig index 2d01db33..795ea743 100644 --- a/src/gui/gui.zig +++ b/src/gui/gui.zig @@ -54,11 +54,6 @@ const Ground = struct { } }; -fn ground(theme_bg: ?[3]u8, transparent: bool) Ground { - if (theme_bg) |rgb| return .opaqueRgb(rgb); - return .{ .rgb = bg_default, .clear = transparent }; -} - const p9_arrow_clr = [32]u8{ 0xFF, 0xFF, 0x80, 0x01, 0x80, 0x02, 0x80, 0x0C, 0x80, 0x10, 0x80, 0x10, 0x80, 0x08, 0x80, 0x04, @@ -1769,7 +1764,6 @@ const Gui = struct { capture_xfer_size: u32 = 0, soft_present: bool = false, - transparent: bool = false, surface_opacity: bool = false, applied_window_opacity: u8 = 100, soft_renderer: ?*c.SDL_Renderer = null, @@ -2187,7 +2181,7 @@ fn runNative(init: std.process.Init, opts_in: pardes.Options, attach: ?[]const u const native_wayland = !test_mode and std.mem.eql(u8, std.mem.span(c.SDL_GetCurrentVideoDriver()), "wayland"); // Background-only opacity needs per-pixel alpha; whole-window compositor // opacity would dim the text as well. SDL requires this flag at creation. - const surface_opacity = config.gui_transparent or native_wayland; + const surface_opacity = native_wayland; if (surface_opacity) win_flags |= c.SDL_WINDOW_TRANSPARENT; const window = c.SDL_CreateWindow("pardes", 1120, 720, win_flags) orelse { log.err("SDL_CreateWindow: {s}", .{c.SDL_GetError()}); @@ -2391,7 +2385,6 @@ fn runNative(init: std.process.Init, opts_in: pardes.Options, attach: ?[]const u .capture_series = test_mode and env.get("PARDES_TEST_SERIES") != null, .capture_dir = capture_dir orelse "", .soft_present = soft_present, - .transparent = config.gui_transparent, .surface_opacity = surface_opacity, .soft_renderer = soft_renderer, }; @@ -6092,7 +6085,7 @@ fn renderFrame( coverFrame(previous_covered, surface.cols, surface.rows, surface.previous_body_layers, surface.previous_tag_layers, surface.previous_regions); try buildDecor(g, gpa, surface, &groups, layout, win_w, win_h, cursors_shown); - const page = ground(chrome.page, g.transparent); + const page: Ground = .opaqueRgb(chrome.page orelse bg_default); const background_opacity = backgroundOpacity(g.applied_window_opacity); var color_target = std.mem.zeroes(c.SDL_GPUColorTargetInfo); color_target.texture = scene; @@ -8449,7 +8442,7 @@ fn softPresentFrame(g: *Gui, cmd: *c.SDL_GPUCommandBuffer, target: *c.SDL_GPUTex // The cell shader already produced premultiplied backgrounds with opaque // foreground ink. Copy that alpha unchanged; never modulate the full frame. _ = c.SDL_SetRenderDrawBlendMode(renderer, c.SDL_BLENDMODE_NONE); - _ = c.SDL_SetRenderDrawColor(renderer, 0, 0, 0, if (g.transparent or g.surface_opacity) 0 else 255); + _ = c.SDL_SetRenderDrawColor(renderer, 0, 0, 0, if (g.surface_opacity) 0 else 255); _ = c.SDL_RenderClear(renderer); _ = c.SDL_RenderTexture(renderer, texture, null, null); _ = c.SDL_RenderPresent(renderer); diff --git a/src/hunks.zig b/src/hunks.zig index 24aaf63d..8cd5c43a 100644 --- a/src/hunks.zig +++ b/src/hunks.zig @@ -111,11 +111,7 @@ const Out = struct { fn deinit(out: *Out) void { out.text.deinit(); - for (out.rows.items) |r| { - out.p.gpa.free(r.path); - out.p.gpa.free(r.colors); - } - out.rows.deinit(out.p.gpa); + locations.freeRowList(out.p.gpa, &out.rows); } const Meta = struct { diff --git a/src/locations.zig b/src/locations.zig index 1e4a20cf..6f086214 100644 --- a/src/locations.zig +++ b/src/locations.zig @@ -33,6 +33,15 @@ pub fn freeRows(gpa: std.mem.Allocator, rows: []Row) void { gpa.free(rows); } +/// A list of rows being built, given up: each row's own bytes, then the list. +pub fn freeRowList(gpa: std.mem.Allocator, rows: *std.ArrayList(Row)) void { + for (rows.items) |row| { + gpa.free(row.path); + gpa.free(row.colors); + } + rows.deinit(gpa); +} + pub fn equalRows(a: []const Row, b: []const Row) bool { if (a.len != b.len) return false; for (a, b) |left, right| { @@ -316,13 +325,7 @@ pub fn formatCallstack(p: *pardes.Pardes, dir: []const u8, input: []const u8) !R var out: std.Io.Writer.Allocating = .init(p.gpa); errdefer out.deinit(); var rows: std.ArrayList(Row) = .empty; - errdefer { - for (rows.items) |row| { - p.gpa.free(row.path); - p.gpa.free(row.colors); - } - rows.deinit(p.gpa); - } + errdefer freeRowList(p.gpa, &rows); const stacked = p.settings.callstack_layout == .stacked; const resolved = try resolveCallstack(p, arena, dir, input); var lines = std.mem.splitScalar(u8, std.mem.trimEnd(u8, input, "\n"), '\n'); @@ -496,13 +499,7 @@ pub fn format(p: *pardes.Pardes, dir: []const u8, input: []const u8, anchor: ?us var out: std.Io.Writer.Allocating = .init(p.gpa); errdefer out.deinit(); var rows: std.ArrayList(Row) = .empty; - errdefer { - for (rows.items) |row| { - p.gpa.free(row.path); - p.gpa.free(row.colors); - } - rows.deinit(p.gpa); - } + errdefer freeRowList(p.gpa, &rows); var mapped = anchor; if (p.locations_config.layout == .stacked) { for (pending.items, 0..) |row, index| { diff --git a/src/look.zig b/src/look.zig index 588574ed..2d97cb9f 100644 --- a/src/look.zig +++ b/src/look.zig @@ -32,9 +32,7 @@ const Key = pardes.Key; const Event = pardes.Event; const Pardes = pardes.Pardes; -extern "c" fn fork() c_int; extern "c" fn execv(path: [*:0]const u8, argv: [*:null]const ?[*:0]const u8) c_int; -extern "c" fn _exit(status: c_int) noreturn; const opener_path: ?[*:0]const u8 = switch (builtin.os.tag) { .linux => "/usr/bin/xdg-open", @@ -46,15 +44,15 @@ pub fn openLink(url: []const u8) void { const opener = opener_path orelse return; var buf: [1024]u8 = undefined; const url_z = std.fmt.bufPrintSentinel(&buf, "{s}", .{url}, 0) catch return; - const pid = fork(); + const pid = libc.fork(); if (pid < 0) return; if (pid == 0) { - if (fork() == 0) { + if (libc.fork() == 0) { @import("host_io.zig").resetChildSignals(); const argv: [3:null]?[*:0]const u8 = .{ opener, url_z.ptr, null }; _ = execv(opener, &argv); } - _exit(0); + libc._exit(0); } _ = libc.waitpid(pid, null, 0); } diff --git a/src/main.zig b/src/main.zig index ea2db917..52093b9a 100644 --- a/src/main.zig +++ b/src/main.zig @@ -144,32 +144,22 @@ fn pageInto(io: std.Io, gpa: std.mem.Allocator, dial: []const u8, text: []const /// Stdin to its end, as it came (its escapes are the session's to parse, /// pager.zig), at most a file's limit, a longer one cut there and said so /// at its end. -fn readStdinText(gpa: std.mem.Allocator) ![]u8 { +fn readStdinText(io: std.Io, gpa: std.mem.Allocator) ![]u8 { const limit = pardes.memory.limits.max_file_bytes; var raw: std.ArrayList(u8) = .empty; var chunk: [64 * 1024]u8 = undefined; - var cut = false; - while (true) { - const n = std.c.read(0, &chunk, chunk.len); - if (n < 0) { - if (std.posix.errno(n) == .INTR) continue; - return error.ReadFailed; - } - if (n == 0) break; - const got: usize = @intCast(n); - if (raw.items.len + got > limit) { - try raw.appendSlice(gpa, chunk[0 .. limit - raw.items.len]); - cut = true; - break; - } - try raw.appendSlice(gpa, chunk[0..got]); - } - if (cut) { - // CAN ends an escape the cut left half sent, and SGR 0 its colour, - // so the note is never swallowed or tinted. - const said = "\x18\x1b[m\n[pardes: the rest of stdin is cut: a pane holds at most a file's limit]\n"; - try raw.appendSlice(gpa, said); - } + var stdin = std.Io.File.stdin().readerStreaming(io, &chunk); + // One byte past the limit says there is more. + stdin.interface.appendRemaining(gpa, &raw, .limited(limit + 1)) catch |err| switch (err) { + error.StreamTooLong => { + raw.shrinkRetainingCapacity(limit); + // CAN ends an escape the cut left half sent, and SGR 0 its colour, + // so the note is never swallowed or tinted. + const said = "\x18\x1b[m\n[pardes: the rest of stdin is cut: a pane holds at most a file's limit]\n"; + try raw.appendSlice(gpa, said); + }, + else => |e| return e, + }; return raw.toOwnedSlice(gpa); } @@ -561,7 +551,7 @@ fn nativeMain(std_init: std.process.Init) !void { // made of it (as acme's `B` has no stdin, through pane/new, a name // and the body), and back at once: the PAGER a pane's shell gets. if (positional) |word| if (std.mem.eql(u8, word, "-")) { - const text = readStdinText(arena) catch |err| Refuse.with(init.io, "stdin", err); + const text = readStdinText(init.io, arena) catch |err| Refuse.with(init.io, "stdin", err); // Nothing paged: no pane, and done. if (text.len == 0) return; pageInto(init.io, arena, parent.dial, text); @@ -676,7 +666,7 @@ fn nativeMain(std_init: std.process.Init) !void { // `pardes -` outside a session: an editor whose first pane holds stdin, // as `vim -` does; the terminal is /dev/tty, never stdin. if (positional) |a| if (std.mem.eql(u8, a, "-")) { - opts.stdin_text = readStdinText(arena) catch |err| badArgs(init.io, "stdin: {s}", .{@errorName(err)}); + opts.stdin_text = readStdinText(init.io, arena) catch |err| badArgs(init.io, "stdin: {s}", .{@errorName(err)}); // Nothing paged: nothing to show. if (opts.stdin_text.?.len == 0) return; positional = null; diff --git a/src/syntax.zig b/src/syntax.zig index 1c09c9f3..803d815a 100644 --- a/src/syntax.zig +++ b/src/syntax.zig @@ -1172,15 +1172,14 @@ fn paintDiffPiece(gpa: std.mem.Allocator, window: anytype, bytes: []const u8, at errdefer syntax_allocator.free(colored); try paintHunk(gpa, colored, bytes, kinds, sel); window.put(at, colored); + // An empty slot, else the least recently used. var oldest: usize = 0; for (&diff_pieces, 0..) |*slot, i| { const piece = slot.* orelse { oldest = i; break; }; - if (diff_pieces[oldest]) |o| if (piece.used < o.used) { - oldest = i; - }; + if (piece.used < diff_pieces[oldest].?.used) oldest = i; } if (diff_pieces[oldest]) |old| syntax_allocator.free(old.styles); diff_pieces[oldest] = .{ .hash = hash, .styles = colored, .used = diff_clock }; diff --git a/src/tagline.zig b/src/tagline.zig index b6601d61..e668419d 100644 --- a/src/tagline.zig +++ b/src/tagline.zig @@ -192,12 +192,7 @@ pub fn defaultTail(pane: *const Pane) []const u8 { /// The tag as it is shown, read and pointed at: its computed prefix and /// its own text after it. pub fn tagText(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) ![]u8 { - const prefix = try tagPrefix(p, pane); - const tail = curTail(pane); - const out = try arena.alloc(u8, prefix.len + tail.len); - @memcpy(out[0..prefix.len], prefix); - @memcpy(out[prefix.len..], tail); - return out; + return std.mem.concat(arena, u8, &.{ try tagPrefix(p, pane), curTail(pane) }); } /// Give the keyboard to the tag in normal mode (`:`), its cursor where diff --git a/src/terminal.zig b/src/terminal.zig index 05054521..755fde6c 100644 --- a/src/terminal.zig +++ b/src/terminal.zig @@ -1363,7 +1363,8 @@ const Rows = struct { const empty_grid = [1][]const u8{""}; /// What LEAVING raw tty mode does to one prompt row, decided from its cells -/// alone. See config.tty_blank for why any of this happens. +/// alone: OSC 133 prompt cells are hidden in normal mode, what was typed at +/// them stays. const PromptCut = union(enum) { /// show the row exactly as ghostty dumped it keep, @@ -1375,7 +1376,6 @@ const PromptCut = union(enum) { }; fn promptCut(pin: ghostty_vt.Pin) PromptCut { - if (config.tty_blank == .prompt_and_input) return .blank; const cells = pin.cells(.all); var cols: usize = 0; while (cols < cells.len and cells[cols].semantic_content == .prompt) cols += 1; diff --git a/src/web.zig b/src/web.zig index f89aa7e9..fd6371c0 100644 --- a/src/web.zig +++ b/src/web.zig @@ -15,58 +15,19 @@ const mouse = @import("mouse.zig"); const gpa = std.heap.wasm_allocator; const embedded_dump = @embedFile("embedded.dump.zon"); const input_capacity = 64 * 1024; -const c_alloc_header_size = 16; const attr_tagline: u16 = 1 << 7; +/// Tree-sitter's C runtime is linked into this module: its malloc, calloc, +/// realloc and free are the wasm allocator's, as the Zig core's are. A var, +/// as c_heap compares the allocator it is at run time (wasm_allocator's +/// `ptr` is undefined, which comptime refuses to compare). +var c_allocator: std.mem.Allocator = gpa; +const c_heap = @import("c_heap").Heap(&c_allocator); comptime { - if (c_alloc_header_size < @sizeOf(usize)) @compileError("C allocation header is too small"); -} - -/// Tree-sitter's C runtime is linked into this module. Its conventional -/// allocation symbols share the same wasm allocator as the Zig core and keep -/// the original allocation size in a 16-byte, max-aligned prefix. -export fn malloc(size_arg: usize) callconv(.c) ?*anyopaque { - const size = @max(size_arg, 1); - const total = std.math.add(usize, c_alloc_header_size, size) catch return null; - const bytes = gpa.alignedAlloc(u8, .@"16", total) catch return null; - const header: *align(16) usize = @ptrCast(bytes.ptr); - header.* = total; - return @ptrCast(bytes.ptr + c_alloc_header_size); -} - -export fn calloc(count: usize, size: usize) callconv(.c) ?*anyopaque { - const len = std.math.mul(usize, count, size) catch return null; - const ptr = malloc(len) orelse return null; - if (len != 0) { - const bytes: [*]u8 = @ptrCast(ptr); - @memset(bytes[0..len], 0); - } - return ptr; -} - -export fn free(ptr: ?*anyopaque) callconv(.c) void { - const data = ptr orelse return; - const data_bytes: [*]u8 = @ptrCast(data); - const base: [*]align(16) u8 = @ptrCast(@alignCast(data_bytes - c_alloc_header_size)); - const header: *align(16) usize = @ptrCast(base); - gpa.free(base[0..header.*]); -} - -export fn realloc(ptr: ?*anyopaque, size: usize) callconv(.c) ?*anyopaque { - if (ptr == null) return malloc(size); - if (size == 0) { - free(ptr); - return null; - } - const data_bytes: [*]u8 = @ptrCast(ptr.?); - const base: [*]align(16) u8 = @ptrCast(@alignCast(data_bytes - c_alloc_header_size)); - const header: *align(16) usize = @ptrCast(base); - const old_size = header.* - c_alloc_header_size; - const replacement = malloc(size) orelse return null; - const replacement_bytes: [*]u8 = @ptrCast(replacement); - @memcpy(replacement_bytes[0..@min(old_size, size)], data_bytes[0..@min(old_size, size)]); - free(ptr); - return replacement; + @export(&c_heap.malloc, .{ .name = "malloc" }); + @export(&c_heap.calloc, .{ .name = "calloc" }); + @export(&c_heap.realloc, .{ .name = "realloc" }); + @export(&c_heap.free, .{ .name = "free" }); } pub const std_options: std.Options = .{ .logFn = logFn }; -- cgit v1.3 From 51903dd947f90381d1a908c488a019289a1c8413 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Sat, 24 Oct 2026 11:57:26 -0300 Subject: Search converge 3/6: the query pane, line 1 the query and its first word the source, rows made live like Callstack's, the owner's places showing the set, a +Preview promoted in place, Enter freezes, Esc restores --- docs/typ/builtins-gui.json | 7 +- docs/typ/builtins-tty.json | 7 +- src/File.zig | 2 + src/Names.zig | 446 +++++++++ src/Output.zig | 8 +- src/Places.zig | 39 +- src/Query.zig | 2155 ++++++++++++++++++++++++++++++++++++++++++++ src/Text.zig | 5 +- src/body_layer.zig | 1 + src/builtins.zig | 35 +- src/config.zig | 54 +- src/edit.zig | 20 + src/exec.zig | 20 + src/fs.zig | 2 +- src/layout.zig | 18 +- src/look.zig | 2 + src/mouse.zig | 9 + src/ninep/ctl.zig | 16 +- src/normal.zig | 16 +- src/panes.zig | 7 + src/pardes.zig | 54 +- src/tagline.zig | 8 + test/output.zig | 59 +- 23 files changed, 2921 insertions(+), 69 deletions(-) create mode 100644 src/Names.zig create mode 100644 src/Query.zig (limited to 'src/Output.zig') diff --git a/docs/typ/builtins-gui.json b/docs/typ/builtins-gui.json index de8fde9c..a502836e 100644 --- a/docs/typ/builtins-gui.json +++ b/docs/typ/builtins-gui.json @@ -102,6 +102,7 @@ {"name": "PanelVertical", "leader": "SPC a v", "also": [], "arg": true, "scope": "root", "setting": true, "choices": "on, off", "doc": "Panes open and close with a vertical wipe, on or off."}, {"name": "PanelWave", "leader": "SPC a w", "also": [], "arg": true, "scope": "root", "setting": true, "choices": "on, off", "doc": "Panes open and close in a wave, on or off."}, {"name": "PanelZoom", "leader": "SPC a z", "also": [], "arg": true, "scope": "root", "setting": true, "choices": "on, off", "doc": "Panes zoom in and out as they open and close, on or off."}, + {"name": "Panes", "leader": null, "also": [], "arg": true, "scope": "pane", "setting": false, "choices": null, "doc": "Pick an open pane by its name in a query pane under this one (SPC b b)."}, {"name": "Parallax", "leader": null, "also": [], "arg": true, "scope": "root", "setting": true, "choices": "on, off", "doc": "A theme's page pattern moves with the text at a quarter of its speed, on or off."}, {"name": "PdfFit", "leader": "SPC t z", "also": [], "arg": true, "scope": "pane", "setting": false, "choices": null, "doc": "Fit the PDF page to the pane by width or by height, flipping between them (or to the one named, `width|height`)."}, {"name": "PdfSections", "leader": "SPC t s", "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "List the PDF's sections in a pane, each a place to go."}, @@ -111,7 +112,7 @@ {"name": "Placement", "leader": "SPC c p", "also": [], "arg": true, "scope": "root", "setting": true, "choices": "acme, pardes", "doc": "Where a new pane goes: acme, as makenewwindow does, or pardes, the older rules."}, {"name": "ProgramEsc", "leader": null, "also": [], "arg": true, "scope": "root", "setting": true, "choices": "on, off", "doc": "In a raw terminal, Esc goes to the program and Shift-Esc backs out, on; off (the default) swaps them."}, {"name": "Putall", "leader": null, "also": [], "arg": false, "scope": "root", "setting": false, "choices": null, "doc": "acme's Putall: every pane holding unsaved edits to a file is saved, each as its own Save; one that is refused (changed on disk since, a write that fails) says so and the rest are saved all the same."}, - {"name": "Recent", "leader": "SPC f r", "also": [], "arg": false, "scope": "root", "setting": false, "choices": null, "doc": "List the files opened lately, closed ones too, each a place to open again."}, + {"name": "Recent", "leader": "SPC f r", "also": [], "arg": true, "scope": "root", "setting": false, "choices": null, "doc": "List the files opened lately, closed ones too, each a place to open again."}, {"name": "Redo", "leader": null, "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Redo the last undone edit."}, {"name": "Refs", "leader": null, "also": [], "arg": true, "scope": "pane", "setting": false, "choices": null, "doc": "List the references to the symbol under the cursor; with an argument (a 2-1 chord's selection), to that symbol, where it is nearest."}, {"name": "Rename", "leader": "SPC l r", "also": [], "arg": true, "scope": "pane", "setting": false, "choices": null, "doc": "Rename the symbol under the cursor everywhere, to its argument."}, @@ -119,6 +120,10 @@ {"name": "Restore", "leader": "SPC s r", "also": [], "arg": true, "scope": "root", "setting": false, "choices": null, "doc": "Replace every pane with those of a dump file, the last one Dump wrote when bare."}, {"name": "Right", "leader": null, "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Move the keyboard to the pane, or column tag, to the right."}, {"name": "Save", "leader": "SPC f s", "also": [], "arg": true, "scope": "pane", "setting": false, "choices": null, "doc": "Write the pane's text to its file, or to the file its argument names."}, + {"name": "Search", "leader": null, "also": [], "arg": true, "scope": "pane", "setting": false, "choices": null, "doc": "Search in a query pane under this pane, line 1 the argument (`Panes`, `Symbols lay`, `All needle`, `/re`, any of its words); bare, `/`."}, + {"name": "SearchPane", "leader": null, "also": [], "arg": true, "scope": "root", "setting": true, "choices": "reuse, new", "doc": "A search from a pane that has a query pane: reuse it, or open a new one and leave the last where it is."}, + {"name": "SearchPlace", "leader": null, "also": [], "arg": true, "scope": "root", "setting": true, "choices": "attached, column", "doc": "Where a query pane goes: attached, under the pane that asked, out of its rows alone, or column, in the finder column."}, + {"name": "SearchRows", "leader": null, "also": [], "arg": true, "scope": "root", "setting": true, "choices": null, "doc": "The rows a query pane is born with under its line 1, 1 through 100; default 8. It never resizes itself."}, {"name": "SelectRefs", "leader": "SPC l h", "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Select every reference to the symbol under the cursor."}, {"name": "SelectionGlow", "leader": null, "also": [], "arg": true, "scope": "root", "setting": true, "choices": "on, off", "doc": "A soft halo of the selection's colour round it in the body, on or off."}, {"name": "Shader", "leader": null, "also": [], "arg": true, "scope": "root", "setting": true, "choices": null, "doc": "A Shadertoy file into the post chain, or out of it, compiled again when saved; off empties the chain."}, diff --git a/docs/typ/builtins-tty.json b/docs/typ/builtins-tty.json index 4db29e6e..7e9ba678 100644 --- a/docs/typ/builtins-tty.json +++ b/docs/typ/builtins-tty.json @@ -91,6 +91,7 @@ {"name": "PanelVertical", "leader": "SPC a v", "also": [], "arg": true, "scope": "root", "setting": true, "choices": "on, off", "doc": "Panes open and close with a vertical wipe, on or off."}, {"name": "PanelWave", "leader": "SPC a w", "also": [], "arg": true, "scope": "root", "setting": true, "choices": "on, off", "doc": "Panes open and close in a wave, on or off."}, {"name": "PanelZoom", "leader": "SPC a z", "also": [], "arg": true, "scope": "root", "setting": true, "choices": "on, off", "doc": "Panes zoom in and out as they open and close, on or off."}, + {"name": "Panes", "leader": null, "also": [], "arg": true, "scope": "pane", "setting": false, "choices": null, "doc": "Pick an open pane by its name in a query pane under this one (SPC b b)."}, {"name": "PdfFit", "leader": "SPC t z", "also": [], "arg": true, "scope": "pane", "setting": false, "choices": null, "doc": "Fit the PDF page to the pane by width or by height, flipping between them (or to the one named, `width|height`)."}, {"name": "PdfSections", "leader": "SPC t s", "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "List the PDF's sections in a pane, each a place to go."}, {"name": "PdfTint", "leader": "SPC t i", "also": [], "arg": true, "scope": "pane", "setting": false, "choices": null, "doc": "Tint the PDF page to the theme, or show it as printed, stepping through them (or to the one named, `disabled|filtered|full`)."}, @@ -98,7 +99,7 @@ {"name": "Placement", "leader": "SPC c p", "also": [], "arg": true, "scope": "root", "setting": true, "choices": "acme, pardes", "doc": "Where a new pane goes: acme, as makenewwindow does, or pardes, the older rules."}, {"name": "ProgramEsc", "leader": null, "also": [], "arg": true, "scope": "root", "setting": true, "choices": "on, off", "doc": "In a raw terminal, Esc goes to the program and Shift-Esc backs out, on; off (the default) swaps them."}, {"name": "Putall", "leader": null, "also": [], "arg": false, "scope": "root", "setting": false, "choices": null, "doc": "acme's Putall: every pane holding unsaved edits to a file is saved, each as its own Save; one that is refused (changed on disk since, a write that fails) says so and the rest are saved all the same."}, - {"name": "Recent", "leader": "SPC f r", "also": [], "arg": false, "scope": "root", "setting": false, "choices": null, "doc": "List the files opened lately, closed ones too, each a place to open again."}, + {"name": "Recent", "leader": "SPC f r", "also": [], "arg": true, "scope": "root", "setting": false, "choices": null, "doc": "List the files opened lately, closed ones too, each a place to open again."}, {"name": "Redo", "leader": null, "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Redo the last undone edit."}, {"name": "Refs", "leader": null, "also": [], "arg": true, "scope": "pane", "setting": false, "choices": null, "doc": "List the references to the symbol under the cursor; with an argument (a 2-1 chord's selection), to that symbol, where it is nearest."}, {"name": "Rename", "leader": "SPC l r", "also": [], "arg": true, "scope": "pane", "setting": false, "choices": null, "doc": "Rename the symbol under the cursor everywhere, to its argument."}, @@ -106,6 +107,10 @@ {"name": "Restore", "leader": "SPC s r", "also": [], "arg": true, "scope": "root", "setting": false, "choices": null, "doc": "Replace every pane with those of a dump file, the last one Dump wrote when bare."}, {"name": "Right", "leader": null, "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Move the keyboard to the pane, or column tag, to the right."}, {"name": "Save", "leader": "SPC f s", "also": [], "arg": true, "scope": "pane", "setting": false, "choices": null, "doc": "Write the pane's text to its file, or to the file its argument names."}, + {"name": "Search", "leader": null, "also": [], "arg": true, "scope": "pane", "setting": false, "choices": null, "doc": "Search in a query pane under this pane, line 1 the argument (`Panes`, `Symbols lay`, `All needle`, `/re`, any of its words); bare, `/`."}, + {"name": "SearchPane", "leader": null, "also": [], "arg": true, "scope": "root", "setting": true, "choices": "reuse, new", "doc": "A search from a pane that has a query pane: reuse it, or open a new one and leave the last where it is."}, + {"name": "SearchPlace", "leader": null, "also": [], "arg": true, "scope": "root", "setting": true, "choices": "attached, column", "doc": "Where a query pane goes: attached, under the pane that asked, out of its rows alone, or column, in the finder column."}, + {"name": "SearchRows", "leader": null, "also": [], "arg": true, "scope": "root", "setting": true, "choices": null, "doc": "The rows a query pane is born with under its line 1, 1 through 100; default 8. It never resizes itself."}, {"name": "SelectRefs", "leader": "SPC l h", "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Select every reference to the symbol under the cursor."}, {"name": "Shell", "leader": null, "also": [], "arg": true, "scope": "root", "setting": true, "choices": null, "doc": "The shell new terminals run; bare, $SHELL if it is executable, else /bin/sh."}, {"name": "Subtypes", "leader": "SPC l T", "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "List the subtypes of the type under the cursor."}, diff --git a/src/File.zig b/src/File.zig index 3db22f95..f633cad0 100644 --- a/src/File.zig +++ b/src/File.zig @@ -598,6 +598,8 @@ pub fn gutterWidth(pane: *const Pane) u16 { // pager and delta show none. if (file.pager) return 0; if (file.output) |o| if (std.meta.eql(o.from, Output.Origin{ .cmd = .Diff })) return 0; + // A query pane's rows carry their own line numbers (Query.zig). + if (pane.query != null) return 0; var lines = if (file.line_starts.len > 0) file.line_starts.len else lineCount(file.content); var digits: u16 = 1; while (lines >= 10) : (lines /= 10) digits += 1; diff --git a/src/Names.zig b/src/Names.zig new file mode 100644 index 00000000..48447f56 --- /dev/null +++ b/src/Names.zig @@ -0,0 +1,446 @@ +//! Names a query pane picks from by a fuzzy query: the files under a +//! directory (walked a slice a frame), the recent files, the open panes, +//! a file's declarations. Each keystroke scores them again with a small +//! fzf-style scorer (subsequence, Smith-Waterman with affine gaps, bonuses +//! at the starts of words and path segments), a frame's budget at a time, +//! the best kept first. Lifted from the pick prototype (Pick.zig), whose +//! scorer took ~1 ms for 20k paths in a release build. Embedded in a +//! Query; the rows it shows are the Query's to make. +const Names = @This(); + +const std = @import("std"); +const pardes = @import("pardes.zig"); +const panes = @import("panes.zig"); +const config = @import("config.zig"); +const filesystem = @import("fs.zig"); +const Pardes = pardes.Pardes; + +/// The candidates' rows, back to back, no newlines. +bytes: std.ArrayList(u8) = .empty, +/// `bytes` in lowercase, for a lowercase query to match without folding. +lower: std.ArrayList(u8) = .empty, +cands: std.ArrayList(Cand) = .empty, +/// The candidates `query` matches, best first. +hits: std.ArrayList(Hit) = .empty, +/// `cands[0..scored]` were scored against `query` (in `hits` or not): the +/// ones a walk adds past it are scored as they come. +scored: u32 = 0, +/// Candidates to score before `cands[scored..]`: what the last query +/// matched, when this one only grew from it. +pending: std.ArrayList(u32) = .empty, +pending_at: usize = 0, +query_buf: [max_query]u8 = undefined, +query_len: u8 = 0, +/// The files walk, while it lasts (Find in a query pane until the disk +/// engine has it). +walk: ?Walk = null, +/// Bumped whenever `hits` change: the rows are made again only then. +gen: u32 = 0, + +pub const Cand = struct { + /// The row: `bytes[start..][0..len]`. + start: u32, + len: u16, + /// What is scored: the row's `[key..][0..key_len]` (a path, a + /// declaration's text, a name), its basename from `base` within it. + key: u16, + key_len: u16, + base: u16, + /// What the row is of: a line of the owner (Symbols, 1-based), a + /// pane's serial (Panes); 0 for a path. + ref: u32 = 0, +}; + +pub const Hit = struct { cand: u32, score: i32 }; + +/// The most rows shown: the rest are counted. +pub const max_rows = 200; +pub const max_query = 64; +/// A candidate is scored over its first this many bytes. +const max_text = 512; +const max_cands = 200_000; +/// Entries a walk reads a frame: ~1-3 ms warm. +const walk_slice = 2000; +const walk_max_depth = 16; +/// A keystroke's scoring, and a frame's: what is left waits a frame. +const score_budget_ns = 4 * std.time.ns_per_ms; + +const Walk = struct { + root: std.Io.Dir, + walker: std.Io.Dir.SelectiveWalker, + done: bool = false, + skipped: u32 = 0, + + fn deinit(w: *Walk) void { + const io = std.Io.Threaded.global_single_threaded.io(); + // The walker closes a directory only as it leaves it: the ones it + // is still in (all but the root, which is ours) are closed here. + if (w.walker.stack.items.len > 1) for (w.walker.stack.items[1..]) |*item| item.iter.reader.dir.close(io); + w.walker.deinit(); + w.root.close(io); + } +}; + +pub fn deinit(n: *Names, gpa: std.mem.Allocator) void { + if (n.walk) |*w| w.deinit(); + n.bytes.deinit(gpa); + n.lower.deinit(gpa); + n.cands.deinit(gpa); + n.hits.deinit(gpa); + n.pending.deinit(gpa); + n.* = .{}; +} + +/// No candidates, no walk: for a source filled again. +pub fn reset(n: *Names) void { + if (n.walk) |*w| w.deinit(); + n.walk = null; + n.bytes.clearRetainingCapacity(); + n.lower.clearRetainingCapacity(); + n.cands.clearRetainingCapacity(); + n.hits.clearRetainingCapacity(); + n.pending.clearRetainingCapacity(); + n.pending_at = 0; + n.scored = 0; + n.gen +%= 1; +} + +pub fn queryText(n: *const Names) []const u8 { + return n.query_buf[0..n.query_len]; +} + +pub fn add(n: *Names, gpa: std.mem.Allocator, row_in: []const u8, key: usize, key_len: usize, base: u16, ref: u32) !void { + if (n.cands.items.len >= max_cands) return; + const text = row_in[0..@min(row_in.len, std.math.maxInt(u16))]; + try n.cands.append(gpa, .{ + .start = @intCast(n.bytes.items.len), + .len = @intCast(text.len), + .key = @intCast(@min(key, text.len)), + .key_len = @intCast(@min(key_len, text.len - @min(key, text.len))), + .base = base, + .ref = ref, + }); + try n.bytes.appendSlice(gpa, text); + try n.lower.ensureUnusedCapacity(gpa, text.len); + for (text) |c| n.lower.appendAssumeCapacity(std.ascii.toLower(c)); +} + +pub 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; +} + +pub fn baseOf(path: []const u8) u16 { + const slash = std.mem.lastIndexOfScalar(u8, std.mem.trimEnd(u8, path, "/"), '/') orelse return 0; + return @intCast(@min(slash + 1, max_text)); +} + +/// The files under `dir`, walked from now on a slice a frame (`walkSlice`): +/// the first slice now, so a small tree is whole before the first frame. +pub fn startWalk(n: *Names, gpa: std.mem.Allocator, dir: []const u8) !void { + if (comptime !filesystem.platform_has_fs) return error.NoFilesystem; + const io = std.Io.Threaded.global_single_threaded.io(); + pardes.turn.yield(); + defer pardes.turn.back(); + var dir_handle = try std.Io.Dir.cwd().openDir(io, dir, .{ .iterate = true }); + errdefer dir_handle.close(io); + n.walk = .{ .root = dir_handle, .walker = try dir_handle.walkSelectively(gpa) }; + n.walkSlice(gpa); +} + +/// One frame's slice of a walk: up to `walk_slice` entries, files kept, +/// what a Find skips skipped and dot-directories too. +pub fn walkSlice(n: *Names, gpa: std.mem.Allocator) void { + const w = if (n.walk) |*w| w else return; + if (w.done) return; + const io = std.Io.Threaded.global_single_threaded.io(); + pardes.turn.yield(); + defer pardes.turn.back(); + var steps: usize = 0; + walk: while (steps < walk_slice) : (steps += 1) { + const e = (w.walker.next(io) catch { + w.skipped += 1; + continue; + }) orelse { + w.done = true; + break; + }; + if (e.kind != .directory) { + n.add(gpa, e.path, 0, e.path.len, baseOf(e.path), 0) catch { + w.done = true; + break; + }; + if (n.cands.items.len >= max_cands) { + w.done = true; + break; + } + continue; + } + if (e.depth() >= walk_max_depth or e.basename[0] == '.') continue; + for (filesystem.find_skip) |s| if (std.mem.eql(u8, e.basename, s)) continue :walk; + w.walker.enter(io, e) catch { + w.skipped += 1; + }; + } +} + +pub fn walking(n: *const Names) bool { + return if (n.walk) |w| !w.done else false; +} + +/// Still walking, or still scoring what it has: it wants the next frame. +pub fn busy(n: *const Names) bool { + return n.walking() or n.scored < n.cands.items.len or n.pending_at < n.pending.items.len; +} + +/// A new query: scored again, from what the last one matched when it only +/// grew from it. +pub fn typed(n: *Names, gpa: std.mem.Allocator, text: []const u8) void { + const q = text[0..@min(text.len, max_query)]; + if (std.mem.eql(u8, q, n.queryText()) and n.scored > 0) return; + // A query that only grew matches a subset of what the last one did: + // only those are scored again (and then the ones not yet scored). + const grew = n.query_len > 0 and std.mem.startsWith(u8, q, n.queryText()) and std.mem.indexOfScalar(u8, q[n.query_len..], ' ') == null; + n.query_len = @intCast(q.len); + @memcpy(n.query_buf[0..q.len], q); + if (grew) { + const pending = n.pending.items[n.pending_at..]; + std.mem.copyForwards(u32, n.pending.items[0..pending.len], pending); + n.pending.items.len = pending.len; + n.pending.ensureUnusedCapacity(gpa, n.hits.items.len) catch return; + for (n.hits.items) |h| n.pending.appendAssumeCapacity(h.cand); + } else { + n.scored = 0; + n.pending.clearRetainingCapacity(); + } + n.pending_at = 0; + n.hits.clearRetainingCapacity(); + n.rescore(gpa); +} + +/// Scores the pending candidates, then `cands[scored..]`, into `hits`, and +/// sorts them: at most `score_budget_ns` of it a call, the rest on the +/// next frames while the best so far is shown. +pub fn rescore(n: *Names, gpa: std.mem.Allocator) void { + const q = n.queryText(); + const empty = std.mem.trim(u8, q, " ").len == 0; + const io = std.Io.Threaded.global_single_threaded.io(); + const started = std.Io.Clock.awake.now(io); + const had = n.hits.items.len; + const was_scored = n.scored; + var count: usize = 0; + while (true) : (count += 1) { + const i: u32 = if (n.pending_at < n.pending.items.len) blk: { + n.pending_at += 1; + break :blk n.pending.items[n.pending_at - 1]; + } else if (n.scored < n.cands.items.len) blk: { + n.scored += 1; + break :blk n.scored - 1; + } else break; + const c = n.cands.items[i]; + const key = n.bytes.items[c.start + c.key ..][0..c.key_len]; + const s = if (empty) 0 else match(q, key, n.lower.items[c.start + c.key ..][0..c.key_len], c.base, null, null, null); + if (s) |score| n.hits.append(gpa, .{ .cand = i, .score = score }) catch break; + // The clock every 256 candidates: reading it is not free either. + if (!empty and count % 256 == 255 and + started.durationTo(std.Io.Clock.awake.now(io)).toNanoseconds() > score_budget_ns) break; + } + // An empty query keeps the source's order (the walk's, recency): no + // row moves as the walk goes on, it only grows at the foot. + if (!empty) std.sort.pdq(Hit, n.hits.items, n.cands.items, struct { + fn lt(cands: []const Cand, a: Hit, b: Hit) bool { + if (a.score != b.score) return a.score > b.score; + const la = cands[a.cand].key_len; + const lb = cands[b.cand].key_len; + if (la != lb) return la < lb; + return a.cand < b.cand; + } + }.lt); + if (n.hits.items.len != had or n.scored != was_scored or count > 0) n.gen +%= 1; +} + +/// The row of hit `i` and, in `marks`, the bytes of it the query matched. +pub fn row(n: *const Names, i: usize, marks: []u16, nmarks: *usize) []const u8 { + const c = n.cands.items[n.hits.items[i].cand]; + nmarks.* = 0; + const q = n.queryText(); + if (std.mem.trim(u8, q, " ").len > 0) { + const key = n.bytes.items[c.start + c.key ..][0..c.key_len]; + _ = match(q, key, n.lower.items[c.start + c.key ..][0..c.key_len], c.base, marks, nmarks, &dp_trace); + for (marks[0..nmarks.*]) |*m| m.* += c.key; + } + return n.bytes.items[c.start..][0..c.len]; +} + +// ---- the scorer (pick's) ---- + +const neg: i32 = -(1 << 24); +const score_match = 16; +const gap_start = 3; +const gap_ext = 1; +const bonus_consecutive = 7; +/// At the start of the text or of a path segment. +const bonus_start = 12; +/// After `_ - . : space`. +const bonus_delim = 9; +/// A camelCase hump, or a word after other punctuation. +const bonus_camel = 8; +/// Each matched character in the basename. +const bonus_base = 2; + +/// The scorer's two rows, and the whole table the marks are backtracked +/// through: the main loop's, one score at a time. Not locals: a safe build +/// fills an undefined local, 4 KB a candidate, which was most of a +/// keystroke's time. +var dp_rows: [2][max_text]i32 = undefined; +var dp_trace: [max_query * max_text]i32 = undefined; + +fn bonusAt(text: []const u8, j: usize) i32 { + if (j == 0) return bonus_start; + const prev = text[j - 1]; + const c = text[j]; + if (prev == '/') return bonus_start; + switch (prev) { + '_', '-', '.', ':', ' ', '\t' => return bonus_delim, + else => {}, + } + if (std.ascii.isLower(prev) and std.ascii.isUpper(c)) return bonus_camel; + if (!std.ascii.isAlphanumeric(prev) and std.ascii.isAlphanumeric(c)) return bonus_camel; + return 0; +} + +/// `query`'s score against `text` (`lower` its lowercase copy, its +/// basename from `base`), null if some term of it is not a subsequence of +/// `text`. Terms split on spaces are ANDed; smart case per term. With +/// `marks`, the bytes matched are written there, ascending. +pub fn match(query: []const u8, text_in: []const u8, lower_in: []const u8, base: usize, marks: ?[]u16, marks_len: ?*usize, trace: ?[]i32) ?i32 { + const text = text_in[0..@min(text_in.len, max_text)]; + const lower = lower_in[0..text.len]; + var total: i32 = 0; + var nmarks: usize = 0; + var terms = std.mem.tokenizeScalar(u8, query, ' '); + while (terms.next()) |term_in| { + const term = term_in[0..@min(term_in.len, max_query)]; + const m = term.len; + const sensitive = for (term) |c| { + if (std.ascii.isUpper(c)) break true; + } else false; + // A lowercase term is matched against the lowercase copy. + var low_buf: [max_query]u8 = undefined; + const want = if (sensitive) term else std.ascii.lowerString(&low_buf, term); + const hay = if (sensitive) text else lower; + // The window a match can be in: from the first character's first + // place to the last one's last place, else no match at all. + const lo = std.mem.indexOfScalar(u8, hay, want[0]) orelse return null; + var pos = lo + 1; + for (want[1..]) |c| pos = (std.mem.indexOfScalarPos(u8, hay, pos, c) orelse return null) + 1; + const end = std.mem.lastIndexOfScalar(u8, hay, want[m - 1]).? + 1; + // D[i][j]: the best score with term[i] matched at text[j]. + var prev = &dp_rows[0]; + var cur = &dp_rows[1]; + const width = text.len; + const keep = if (trace) |t| t.len >= m * width else false; + for (0..m) |i| { + var gapped: i32 = neg; // max over k <= j-2 of D[i-1][k], less the gap to j + for (lo..end) |col| { + var best: i32 = neg; + if (i > 0 and col >= lo + 2) gapped = @max(gapped - gap_ext, prev[col - 2] - gap_start); + if (hay[col] == want[i]) { + const own: i32 = score_match + bonusAt(text, col) + @as(i32, if (col >= base) bonus_base else 0); + if (i == 0) { + best = own; + } else if (col > lo) { + const from = @max(if (prev[col - 1] > neg) prev[col - 1] + bonus_consecutive else neg, gapped); + if (from > neg) best = from + own; + } + } + cur[col] = best; + if (keep) trace.?[i * width + col] = best; + } + const t = prev; + prev = cur; + cur = t; + } + var best: i32 = neg; + var at: usize = lo; + for (lo..end) |col| if (prev[col] > best) { + best = prev[col]; + at = col; + }; + if (best <= neg) return null; + total += best; + // Back from the best end, the place each character was matched at. + if (keep and marks != null) { + const out = marks.?; + const t = trace.?; + var i = m; + var col = at; + while (i > 0) { + i -= 1; + if (nmarks < out.len) { + out[nmarks] = @intCast(col); + nmarks += 1; + } + if (i == 0) break; + const here = t[i * width + col]; + const own: i32 = score_match + bonusAt(text, col) + @as(i32, if (col >= base) bonus_base else 0); + if (col > lo and t[(i - 1) * width + col - 1] > neg and t[(i - 1) * width + col - 1] + bonus_consecutive + own == here) { + col -= 1; + continue; + } + var found = col - 1; + if (col >= lo + 2) { + var k = col - 2; + while (true) { + const d = t[(i - 1) * width + k]; + if (d > neg and d - gap_start - @as(i32, @intCast(col - 2 - k)) * gap_ext + own == here) { + found = k; + break; + } + if (k == lo) break; + k -= 1; + } + } + col = found; + } + } + } + if (marks_len) |count| { + if (marks) |out| std.mem.sort(u16, out[0..nmarks], {}, std.sort.asc(u16)); + count.* = nmarks; + } + return total; +} + +const test_paths = [_][]const u8{ + "src/layout.zig", "src/locations.zig", "src/Output.zig", "src/hunks.zig", + "src/pardes.zig", "src/pdf.zig", "src/look.zig", "src/syntax.zig", + "src/body_layer.zig", "build.zig", "src/ninep/ctl.zig", "docs/helix-keys.md", + "notes/helix-keys.md", "src/gui/Post.zig", "cmd/tool/ui_review.py", +}; + +fn topFor(q: []const u8) []const u8 { + var best: ?[]const u8 = null; + var best_score: i32 = std.math.minInt(i32); + for (test_paths) |path| { + var low: [256]u8 = undefined; + const s = match(q, path, std.ascii.lowerString(&low, path), baseOf(path), null, null, null) orelse continue; + if (s > best_score or (s == best_score and path.len < best.?.len)) { + best = path; + best_score = s; + } + } + return best orelse ""; +} + +test "Names ranks real paths as the pick prototype did" { + try std.testing.expectEqualStrings("src/layout.zig", topFor("layout")); + try std.testing.expectEqualStrings("src/Output.zig", topFor("out")); + try std.testing.expectEqualStrings("src/pardes.zig", topFor("prz")); + try std.testing.expectEqualStrings("src/body_layer.zig", topFor("bl")); + try std.testing.expectEqualStrings("src/ninep/ctl.zig", topFor("ctl ninep")); + try std.testing.expectEqualStrings("docs/helix-keys.md", topFor("helkey")); + try std.testing.expectEqualStrings("src/gui/Post.zig", topFor("gui/po")); + try std.testing.expectEqualStrings("src/Output.zig", topFor("Out")); +} diff --git a/src/Output.zig b/src/Output.zig index 9a11b2fc..1e62b04a 100644 --- a/src/Output.zig +++ b/src/Output.zig @@ -35,6 +35,9 @@ pub const Origin = union(enum) { unsaved, /// A directory's entries (Dir.zig), the pane named for it. dir, + /// A query pane's +Preview (Query.zig): a file's text shown, not yet + /// its pane; Enter promotes it to one where it stands. + preview, }; pub const max_arg = dump.max_origin_arg; @@ -259,6 +262,7 @@ pub fn traits(o: Origin) Traits { .errors => .{ .name = config.errors_buffer, .doc = true }, .pdf_links => .{ .name = config.pdf_links_buffer, .steps = true, .locations = true }, .unsaved => .{ .name = config.unsaved_buffer, .doc = true }, + .preview => .{ .name = config.preview_buffer, .doc = true }, // Named for its directory, not a `+` name in it. .dir => .{ .name = "", .doc = true }, .cmd => |b| builtins.registry.outputTraits(b) orelse unreachable, @@ -324,6 +328,7 @@ pub fn word(o: Origin) []const u8 { .pdf_links => config.pdf_links_buffer, .unsaved => config.unsaved_buffer, .dir => dir_word, + .preview => config.preview_buffer, }; } @@ -337,6 +342,7 @@ pub fn fromWord(w: []const u8) ?Origin { if (std.mem.eql(u8, w, config.pdf_links_buffer)) return .pdf_links; if (std.mem.eql(u8, w, config.unsaved_buffer)) return .unsaved; if (std.mem.eql(u8, w, dir_word)) return .dir; + if (std.mem.eql(u8, w, config.preview_buffer)) return .preview; if (std.meta.stringToEnum(Builtin, w)) |b| if (builtins.registry.outputTraits(b) != null) return .{ .cmd = b }; if (std.meta.stringToEnum(lsp.Kind, w)) |k| return .{ .query = k }; @@ -399,7 +405,7 @@ fn sortResults(arena: std.mem.Allocator, from: Origin, content: []u8, anchor: ?u => {}, else => return anchor, }, - .errors, .pdf_links, .unsaved, .dir => return anchor, + .errors, .pdf_links, .unsaved, .dir, .preview => return anchor, } if (content.len == 0) return anchor; const path_only = std.meta.eql(from, Origin{ .cmd = .Find }); diff --git a/src/Places.zig b/src/Places.zig index 435a138a..cff7c22e 100644 --- a/src/Places.zig +++ b/src/Places.zig @@ -207,7 +207,8 @@ pub fn search(set: *Places, p: *Pardes, pane: *Pane, provenance: Provenance, fro set.revision = f.revision +% 1; // `fill` starts it over for the text as it is set.seek = seek; set.seek_moves = moves; - set.fill(p, pane, frame_bytes, frame_steps); + // The keystroke's share: the view; the rest a frame's slice a tick. + set.fill(p, pane, 0, frame_steps); } /// A list's places in this text, as it gives them (sorted here), in place @@ -589,7 +590,7 @@ pub fn step(set: *Places, p: *Pardes, pane: *Pane, forward: bool, count: u32, ad /// Whether n and N in this pane are these places' to step: a list's or a /// query's always; a search's while it is what the register says (an `s`, /// a `/` elsewhere or `"a` since makes them helix's register search again). -pub fn answersN(set: *const Places, p: *Pardes, pane: *const Pane) bool { +pub fn answersN(set: *const Places, p: *Pardes, pane: *Pane) bool { if (!set.shows(pane) and !set.started) return false; if (set.provenance != .search) return p.register == 0; const name = if (p.register != 0) p.register else p.registers.last_search; @@ -634,10 +635,11 @@ pub fn forget(set: *Places, gpa: std.mem.Allocator) void { set.snap = &.{}; } -/// Where the query began: the primary selection's end when it was -/// remembered, else now. -pub fn origin(set: *const Places, pane: *const Pane) usize { - if (set.snap.len > 0) return @max(set.snap[set.snap_pri].anchor, set.snap[set.snap_pri].head); +/// Where the query began: the primary selection's start when it was +/// remembered, else now; a place there counts (helix's `/` from the +/// cursor). +pub fn origin(set: *const Places, pane: *Pane) usize { + if (set.snap.len > 0) return @min(set.snap[set.snap_pri].anchor, set.snap[set.snap_pri].head); const f = pane.file orelse return 0; const r = pane.body.primaryRange(f.content, 0); return @min(r.anchor, r.head); @@ -847,3 +849,28 @@ test "places: a big file costs a keystroke its view, the ticks find the rest, an if (std.c.getenv("PLACES_TIMES") != null) std.debug.print("places: first key {d} us, {d} ticks, an edit {d} us (the text's own splice {d} us)\n", .{ first_ns / 1000, ticks, edit_ns / 1000, text_ns / 1000 }); } + +test "zz stress analysis cost" { + const path = "/home/goblin/00-projects/0x4200.cafe/pardes-s-converge/.scratch/stress/src/layout.zig"; + if (std.c.getenv("PLACES_TIMES") == null) return error.SkipZigTest; + const io = std.testing.io; + const bytes = try std.Io.Dir.cwd().readFileAlloc(io, path, std.testing.allocator, .limited(4 << 20)); + defer std.testing.allocator.free(bytes); + const syntax = @import("syntax.zig"); + syntax.start(std.testing.allocator); + defer syntax.stop(); + const tp = nowNs(); + const tree = syntax.parseTree(path, bytes); + const tq = nowNs(); + if (tree) |t| syntax.freeTree(t); + std.debug.print("parse alone {d} us\n", .{(tq - tp) / 1000}); + const t0 = nowNs(); + const d = try syntax.contextDeclarations(std.testing.allocator, path, bytes); + const t1 = nowNs(); + std.testing.allocator.free(d); + const a = try syntax.analyzeSource(std.testing.allocator, path, bytes, true, true); + const t2 = nowNs(); + std.testing.allocator.free(a.declarations); + std.testing.allocator.free(a.colors); + std.debug.print("decls {d} us ({d}), analysis with colours {d} us\n", .{ (t1 - t0) / 1000, d.len, (t2 - t1) / 1000 }); +} diff --git a/src/Query.zig b/src/Query.zig new file mode 100644 index 00000000..fbce95b2 --- /dev/null +++ b/src/Query.zig @@ -0,0 +1,2155 @@ +//! The query pane: the one pane search is. A +Search attached under the +//! pane that asked (its owner, layout.zig "Attached panes"), born at a +//! fixed height, whose body's line 1 is the query, editable text, and +//! whose rows below are made live from a source, read-only while live. +//! Line 1's first word names the source: `/pat` the owner's text (smart- +//! case regex), `Find pat` the files under its directory, `Grep pat` the +//! lines of those files, `Recent pat`, `Panes pat`, `Symbols pat` (the +//! owner's declarations), `All pat` (every open pane's text), and the +//! language server's `Refs`, `Def`, `Impl`, `Diagnostics`. Names are +//! matched fuzzy (Names.zig), text by regex. Editing the word changes +//! the source. +//! +//! The rows look like a Callstack's: the hit line with the match tinted +//! under a gutter line number, under the declaration it is in (when the +//! owner's parse exists: never made here on the loop), under its file +//! (Grep) or under `@pN name (count)` (All). They are addresses, all text: +//! B3 on one looks, B2 on line 1 runs it again. Wherever a row points into +//! an open pane's text, that pane's places (Places.zig) show the set: +//! tints, rail ticks, the current one selected. A row pointing at a file +//! no pane shows is shown in the +Preview attached under this pane; Enter +//! promotes the preview to the file's pane where it stands. +//! +//! Nothing moves while you type: the pane never closes, resizes or +//! rewrites line 1 on its own; zero hits is a state (`0` in the tag). +//! Enter lands on the current hit and freezes the rows into ordinary text; +//! Esc while typing puts every view back and closes the pane (or brings a +//! reused pane's frozen rows back); Del closes it. One per owner, reused +//! (SearchPane reuse|new). +const Query = @This(); + +const std = @import("std"); +const pardes = @import("pardes.zig"); +const panes = @import("panes.zig"); +const config = @import("config.zig"); +const edit = @import("edit.zig"); +const exec = @import("exec.zig"); +const layout = @import("layout.zig"); +const locations = @import("locations.zig"); +const look = @import("look.zig"); +const modal = @import("modal.zig"); +const normal = @import("normal.zig"); +const syntax = @import("syntax.zig"); +const tagline = @import("tagline.zig"); +const filesystem = @import("fs.zig"); +const colors = @import("colors.zig"); +const memory = @import("memory.zig"); +const Names = @import("Names.zig"); +const Places = @import("Places.zig"); +const Surface = @import("surface.zig").Surface; +const Pardes = pardes.Pardes; +const Pane = panes.Pane; +const File = panes.File; +const Output = panes.Output; +const Key = pardes.Key; +const hit = pardes.hit; + +pub const Source = enum { text, find, grep, recent, panes, symbols, all, refs, defs, impls, diagnostics }; + +/// Line 1's words, each the source it names. `/` is vim's spelling, no +/// space after it; the others take one. +pub const words = [_]struct { word: []const u8, source: Source }{ + .{ .word = "Find", .source = .find }, + .{ .word = "Grep", .source = .grep }, + .{ .word = "Recent", .source = .recent }, + .{ .word = "Panes", .source = .panes }, + .{ .word = "Symbols", .source = .symbols }, + .{ .word = "All", .source = .all }, + .{ .word = "Refs", .source = .refs }, + .{ .word = "Def", .source = .defs }, + .{ .word = "Impl", .source = .impls }, + .{ .word = "Diagnostics", .source = .diagnostics }, +}; + +/// What a line 1 asks: its source and what follows its word. Null when it +/// starts with no word this knows (the user rewrote it): the rows say so. +pub fn parse(line: []const u8) ?struct { source: Source, pat: []const u8 } { + if (line.len > 0 and line[0] == '/') return .{ .source = .text, .pat = line[1..] }; + for (words) |w| { + if (std.mem.startsWith(u8, line, w.word) and (line.len == w.word.len or line[w.word.len] == ' ')) + return .{ .source = w.source, .pat = std.mem.trim(u8, line[w.word.len..], " \t") }; + } + return null; +} + +/// The word line 1 starts with for `source`, as typed after it. +pub fn wordOf(source: Source) []const u8 { + if (source == .text) return "/"; + for (words) |w| if (w.source == source) return w.word; + unreachable; +} + +/// A source whose rows can point at files no pane shows: its group is +/// made with a +Preview from the start, so nothing moves later. +fn previews(source: Source) bool { + return switch (source) { + .find, .grep, .recent, .refs, .defs, .impls, .diagnostics => true, + .text, .panes, .symbols, .all => false, + }; +} + +/// The most rows of hits a frozen list keeps: the rest are counted, and +/// said in a row. +pub const max_rows = 2000; +/// While typed, the rows are a window of this many around the current +/// place: the pane shows a few, and a row is two allocations a refill. +pub const live_rows = 100; + +/// One row's model, row `i + 1` of the pane (line 1 is the query): a hit, +/// a header (a declaration, a file, a pane) or a note. Where a row points +/// is in its locations.Row (path, at); a hit in an open pane's text also +/// knows its places there, `hit` and the `n` of them on its line. +pub const Item = struct { + kind: enum { hit, header, note }, + /// The pane whose text it is in (by serial), 0 when it is a file's. + serial: u32 = 0, + hit: usize = 0, + n: usize = 0, + /// A Panes row's pane, a Symbols row's line: Names.Cand.ref. + ref: u32 = 0, +}; + +/// A line a Grep found: its path and code in `found_bytes`. +pub const Found = struct { path: u32, path_len: u16, line: u32, col: u32, end: u32, code: u32, code_len: u32 }; + +/// The pane it answers for, by serial. +owner: u32, +/// Line 1 as the rows were last made for (gpa). +asked: []u8 = &.{}, +source: Source = .text, +/// Enter answered it: its rows are ordinary text from here, nothing remade. +frozen: bool = false, +items: std.ArrayList(Item) = .empty, +/// The current item, which Enter lands on and the places show. +current: ?usize = null, +/// The tag's `k/N`: how many places or names the rows are of, and where +/// the current one is among them (1-based; 0, none); `more` while counting. +total: usize = 0, +k: usize = 0, +more: bool = false, +/// What the rows were made of: the places' or names' generation and the +/// owner's text, so that a frame with nothing new makes nothing. +made_gen: u64 = std.math.maxInt(u64), +made_rev: u32 = 0, +/// The owner's revision seen last tick: rows follow an edit of the owner +/// once it has stood a frame (the rows refresh on idle frames). +seen_rev: u32 = 0, +/// The body cursor's row as last seen: B1, j or k on a row makes it current. +seen_row: i32 = 0, +/// The places a `/`'s rows are a window of: [lo, hi) of its owner's hits. +window: struct { lo: usize = 0, hi: usize = 0 } = .{}, +/// Ticks the rows waited while the places are still being found: they are +/// made every third, the frame's time going to the finding. +waited: u8 = 0, +names: Names = .{}, +/// A Grep's lines, found a slice a frame (Query.grepSlice). +found: std.ArrayList(Found) = .empty, +found_bytes: std.ArrayList(u8) = .empty, +grep_next: usize = 0, +grep_gen: u32 = 0, +/// The language server's rows for Refs, Def, Impl, Diagnostics, as it gave +/// them (`path:line:col text`, gpa), filtered by what follows the word. +lsp_rows: []u8 = &.{}, +/// The +Preview under this pane, by serial; 0, none. +preview: u32 = 0, +/// A reused pane's frozen rows when a new query began in it: Esc brings +/// them back. +saved: ?Saved = null, + +pub const Saved = struct { + content: []u8, + rows: []locations.Row, + asked: []u8, + source: Source, + items: []Item, + current: ?usize, + total: usize, + k: usize, +}; + +pub fn deinit(q: *Query, gpa: std.mem.Allocator) void { + gpa.free(q.asked); + q.items.deinit(gpa); + q.names.deinit(gpa); + q.found.deinit(gpa); + q.found_bytes.deinit(gpa); + gpa.free(q.lsp_rows); + if (q.saved) |s| freeSaved(gpa, s); + q.* = undefined; +} + +fn freeSaved(gpa: std.mem.Allocator, s: Saved) void { + gpa.free(s.content); + locations.freeRows(gpa, s.rows); + gpa.free(s.asked); + gpa.free(s.items); +} + +/// The query pane `pane` is, if it is one. +pub fn of(pane: *Pane) ?*Query { + return pane.query; +} + +/// The owner's query pane (attached to it, or left where it was by +/// SearchPane new): the one a later search from it reuses. +pub fn ofOwner(p: *Pardes, owner_serial: u32) ?usize { + var found: ?usize = null; + for (p.panes, 0..) |slot, i| { + const pane = slot orelse continue; + const q = pane.query orelse continue; + if (q.owner != owner_serial) continue; + // the attached one first: an unattached one is a kept result + if (pane.attached_to == owner_serial) return i; + found = found orelse i; + } + return found; +} + +fn lineOne(content: []const u8) []const u8 { + return content[0 .. std.mem.indexOfScalar(u8, content, '\n') orelse content.len]; +} + +// ---- opening ---- + +/// A search from pane `from`: its owner's query pane, made under the owner +/// (with a +Preview when `source` can need one) or reused, line 1 the +/// source's word and `arg`. With `focus` the keyboard goes to line 1's end +/// in insert mode, as to a prompt; without (`*`), it stays where it is. +pub fn open(p: *Pardes, from: usize, source: Source, arg: []const u8, focus: bool) void { + const asker = p.panes[from] orelse return; + // Asked from a query pane (`/` in it, its own SPC f g): its own line 1; + // from a +Preview, its query pane's. + var owner_id = from; + if (asker.query) |q| owner_id = p.paneBySerial(q.owner) orelse from else if (isPreview(p, asker)) |qid| { + owner_id = p.paneBySerial(p.panes[qid].?.query.?.owner) orelse from; + } + const owner = p.panes[owner_id] orelse return; + if (asker.query != null and arg.len == 0 and asker.query.?.source == source and !asker.query.?.frozen) { + // Back to typing the query it has. + if (focus) toLineOne(p, from); + return; + } + const line = std.mem.concat(p.scratch.allocator(), u8, &.{ wordOf(source), if (source == .text) "" else " ", arg }) catch return; + var id: usize = undefined; + const existing = ofOwner(p, owner.serial); + if (existing != null and (p.settings.search_pane == .reuse or existing.? == from)) { + id = existing.?; + const rp = p.panes[id].?; + const q = rp.query.?; + // Its frozen rows, kept for an Esc to bring back. + if (q.frozen and q.saved == null) q.saved = save(p, rp, q) catch null; + q.frozen = false; + const f = &rp.file.?; + const new = std.mem.concat(p.gpa, u8, &.{ line, "\n" }) catch return; + File.setContent(p, f, new); + q.reset(p); + if (rp.collapsed) layout.toggleCollapse(p, id); + } else { + if (existing) |old| { + // SearchPane new: the last one stays where it is, a result of + // its own; its places are the new one's to feed. + p.panes[old].?.attached_to = null; + } + id = create(p, owner_id, line, source) orelse return; + } + // Every view as the search found it, for Esc to put back. + owner.places.remember(p, owner); + // Before the first key: a names source lists every candidate at once. + produce(p, id, false); + // What a 9P exec reads back: the pane it filled (ninep/ctl.zig). + p.fs.refilled = p.panes[id].?.serial; + if (focus) toLineOne(p, id) else p.active = from; +} + +/// A new query pane under pane `owner_id`, `rows` of the owner's rows (the +/// SearchRows setting), its +Preview under it when `source` can need one. +fn create(p: *Pardes, owner_id: usize, line: []const u8, source: Source) ?usize { + const owner = p.panes[owner_id] orelse return null; + const free = p.freeSlot() orelse { + p.reportError(owner_id, "search", error.NoPaneSlots); + return null; + }; + const dir = if (p.exec_header) p.sessionDir() else Pardes.paneDir(owner); + const content = std.mem.concat(p.gpa, u8, &.{ line, "\n" }) catch return null; + const np = Output.open(p, free, dir, .search, "", content) catch |err| { + p.gpa.free(content); + p.reportError(owner_id, "search", err); + return null; + }; + const q = p.gpa.create(Query) catch { + p.reportError(owner_id, "search", error.OutOfMemory); + return null; + }; + q.* = .{ .owner = owner.serial }; + np.query = q; + const body: u16 = 1 + p.settings.search_rows; + const tag = @max(pardes.BOX_H, np.tag_rows); + const with_preview = previews(source); + // The preview, made right after, takes its own rows from the owner. + const want = tag + body; + if (p.settings.search_place == .column) { + // The finder column (phase 6): until it exists, under the owner. + if (!layout.attach(p, owner_id, free, want)) exec.placeNew(p, owner_id, owner_id, free, .doc); + } else if (!layout.attach(p, owner_id, free, want)) { + // An owner too short to give a query pane its rows: placed as any + // new pane is, the one place a search moves another pane. + exec.placeNew(p, owner_id, owner_id, free, .doc); + } + if (with_preview) _ = makePreview(p, free); + return free; +} + +/// The keyboard to the end of line 1 of query pane `id`, in insert mode. +pub fn toLineOne(p: *Pardes, id: usize) void { + const rp = p.panes[id] orelse return; + tagline.exitHeader(p); + p.active = id; + if (layout.findPane(p, id)) |at| p.setActiveColumn(at.col); + rp.focus = .body; + const t = &rp.body; + if (t.mode == .insert) edit.exitInsert(p, t); + t.cur_row = 0; + t.cur_col = @intCast(lineOne(rp.file.?.content).len); + t.vsel.active = false; + t.nsel = 0; + t.cur_pinned = true; + rp.query.?.seen_row = 0; + edit.enterInsert(p, t, .line_end, 1); + showCurrent(rp); +} + +/// The rows' state for a new question: nothing found yet. +fn reset(q: *Query, p: *Pardes) void { + q.items.clearRetainingCapacity(); + q.current = null; + q.total = 0; + q.k = 0; + q.more = false; + q.made_gen = std.math.maxInt(u64); + p.gpa.free(q.asked); + q.asked = &.{}; +} + +fn save(p: *Pardes, rp: *Pane, q: *Query) !Saved { + const f = &rp.file.?; + const content = try p.gpa.dupe(u8, f.content); + errdefer p.gpa.free(content); + const rows = try p.gpa.alloc(locations.Row, f.location_rows.len); + var made: usize = 0; + errdefer { + for (rows[0..made]) |r| { + p.gpa.free(r.path); + p.gpa.free(r.colors); + } + p.gpa.free(rows); + } + for (f.location_rows, 0..) |r, i| { + rows[i] = r; + rows[i].path = try p.gpa.dupe(u8, r.path); + rows[i].colors = p.gpa.dupe(u8, r.colors) catch |err| { + p.gpa.free(rows[i].path); + return err; + }; + made += 1; + } + const asked = try p.gpa.dupe(u8, q.asked); + errdefer p.gpa.free(asked); + return .{ .content = content, .rows = rows, .asked = asked, .source = q.source, .items = try p.gpa.dupe(Item, q.items.items), .current = q.current, .total = q.total, .k = q.k }; +} + +// ---- making the rows ---- + +/// After every step: each live query pane whose line 1 changed, or whose +/// source has something new, has its rows made again. A walk takes a slice +/// on a tick. Nothing here is synchronous with an edit of the owner: its +/// places shift (Places.shift) and the rows follow once it stands a frame. +pub fn produceAll(p: *Pardes, tick: bool) void { + for (p.panes, 0..) |slot, id| { + const pane = slot orelse continue; + if (pane.query == null) continue; + produce(p, id, tick); + } +} + +/// The frames a query pane still owes (a walk, scoring): nextWake's. +pub fn busy(p: *const Pardes) bool { + for (p.panes) |slot| { + const pane = slot orelse continue; + const q = pane.query orelse continue; + if (q.frozen) continue; + if (q.names.busy() or (q.source == .grep and q.grep_next < q.names.cands.items.len) or q.made_rev != q.seen_rev) return true; + } + return false; +} + +fn produce(p: *Pardes, id: usize, tick: bool) void { + const rp = p.panes[id] orelse return; + const q = rp.query orelse return; + const f = if (rp.file) |*file| file else return; + const line = lineOne(f.content); + const changed = !std.mem.eql(u8, line, q.asked); + if (q.frozen and !changed) return; + if (q.frozen) { + // Line 1 of a frozen pane edited: it is a live query again. + if (q.saved) |s| freeSaved(p.gpa, s); + q.saved = null; + q.frozen = false; + } + const owner_id = p.paneBySerial(q.owner); + const asked = parse(line); + if (changed) { + const was = q.source; + const new_asked = p.gpa.dupe(u8, line) catch return; + p.gpa.free(q.asked); + q.asked = new_asked; + q.made_gen = std.math.maxInt(u64); + if (asked) |a| { + if (a.source != was or q.names.cands.items.len == 0) startSource(p, id, q, a.source, owner_id); + q.source = a.source; + } + // The places this fed are another question's now. + if (asked == null or asked.?.source != .text) clearPlaces(p, q, rp.serial, owner_id, asked); + } + const a = asked orelse return noteRows(p, id, " line 1 asks: /text, Find, Grep, Recent, Panes, Symbols, All, Refs, Def, Impl or Diagnostics, then what to find\n"); + // A row clicked or stepped onto (B1, j, k): current, and shown. + if (rp.body.cur_row != q.seen_row) { + q.seen_row = rp.body.cur_row; + if (rp.body.cur_row > 0 and rp.body.cur_row <= q.items.items.len) { + const i: usize = @intCast(rp.body.cur_row - 1); + if (q.items.items[i].kind == .hit) setCurrent(p, id, i, true); + } + } + switch (a.source) { + .text => { + const oid = owner_id orelse return noteRows(p, id, " the pane this searched is gone: Del, or / in another\n"); + const owner = p.panes[oid].?; + const of_ = owner.file orelse return noteRows(p, id, " a terminal's text is not searched here yet: / in a file\n"); + const set = &owner.places; + if (changed) { + if (a.pat.len == 0) { + if (set.from == rp.serial) set.clear(p.gpa); + set.restore(p, owner); + } else set.search(p, owner, .typed, rp.serial, a.pat, false, set.origin(owner), p.active == id); + } + // The owner edited: its places shifted at once; the rows follow + // once its text has stood a frame. + if (!changed and of_.revision != q.made_rev) { + if (!tick or of_.revision != q.seen_rev) { + q.seen_rev = of_.revision; + return; + } + } + q.seen_rev = of_.revision; + const gen: u64 = (@as(u64, set.hits_gen) << 32) | of_.revision; + if (gen == q.made_gen and !changed) return showPlacesCurrent(p, id); + if (a.pat.len > 0 and set.from != rp.serial) return; + if (!changed and !set.complete() and q.made_gen != std.math.maxInt(u64) and q.waited < 2) { + q.waited += 1; + return showPlacesCurrent(p, id); + } + q.waited = 0; + q.made_gen = gen; + q.made_rev = of_.revision; + makeTextRows(p, id, oid, false) catch |err| p.reportError(id, "search", err); + }, + .all => { + if (changed) for (p.panes) |slot| { + const tp = slot orelse continue; + if (!searchable(tp)) continue; + if (a.pat.len == 0) { + if (tp.places.from == rp.serial) tp.places.clear(p.gpa); + continue; + } + tp.places.search(p, tp, .list, rp.serial, a.pat, false, null, false); + }; + var gen: u64 = 0; + for (p.panes) |slot| if (slot) |tp| if (tp.places.from == rp.serial) { + gen +%= tp.places.hits_gen +% (@as(u64, tp.serial) << 20); + }; + if (gen == q.made_gen and !changed) return; + if (!changed and !tick) return; + q.made_gen = gen; + makeAllRows(p, id) catch |err| p.reportError(id, "search", err); + }, + .find, .recent, .panes, .symbols => { + if (tick) q.names.walkSlice(p.gpa); + if (changed) q.names.typed(p.gpa, a.pat) else if (q.names.busy()) q.names.rescore(p.gpa); + if (q.names.gen == q.made_gen and !changed) return; + q.made_gen = q.names.gen; + makeNameRows(p, id, a.pat) catch |err| p.reportError(id, "search", err); + }, + .grep => { + if (changed) { + q.found.clearRetainingCapacity(); + q.found_bytes.clearRetainingCapacity(); + q.grep_next = 0; + q.grep_gen +%= 1; + } + if (a.pat.len == 0) { + if (changed) makeGrepRows(p, id) catch {}; + return; + } + if (tick or changed) { + q.names.walkSlice(p.gpa); + grepSlice(p, q, rp, a.pat); + } + const gen: u64 = (@as(u64, q.grep_gen) << 32) | q.found.items.len; + if (gen == q.made_gen and !changed and !(q.grep_next >= q.names.cands.items.len and q.more)) return; + q.made_gen = gen; + makeGrepRows(p, id) catch |err| p.reportError(id, "search", err); + if (changed or q.current == null) feedGrepPlaces(p, q, rp.serial, a.pat); + }, + .refs, .defs, .impls, .diagnostics => { + if (changed and q.lsp_rows.len == 0) { + // Typed, not answered: asked of the language server at the + // owner's cursor; its answer fills these rows (fillList). + // An answer opening the pane is no typing. + if (p.active != id) return; + if (owner_id) |oid| p.lspRequest(oid, switch (a.source) { + .refs => .references, + .defs => .definition, + .impls => .implementation, + else => .diagnostics, + }, ""); + return noteRows(p, id, " asked of the language server...\n"); + } + if (!changed) return; + makeListRows(p, id, a.pat) catch |err| p.reportError(id, "search", err); + }, + } +} + +/// Whether pane `tp`'s text is one 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; +} + +/// A source begun: its candidates gathered (names), its walk started. +fn startSource(p: *Pardes, id: usize, q: *Query, source: Source, owner_id: ?usize) void { + const rp = p.panes[id].?; + q.names.reset(); + q.found.clearRetainingCapacity(); + q.found_bytes.clearRetainingCapacity(); + q.grep_next = 0; + const dir = std.fs.path.dirname(rp.file.?.path) orelse "/"; + const gpa = p.gpa; + switch (source) { + .find, .grep => q.names.startWalk(gpa, dir) catch |err| p.reportError(id, "search", err), + .recent => { + var out: std.Io.Writer.Allocating = .init(gpa); + defer out.deinit(); + Output.recentText(p, &out.writer, true) catch {}; + var lines = std.mem.splitScalar(u8, out.written(), '\n'); + while (lines.next()) |ln| { + if (ln.len == 0) continue; + const rel = Names.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; + } + }, + .panes => for (p.panes) |slot| { + const other = slot orelse continue; + if (other == rp 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, Names.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; + }, + .symbols => { + const oid = owner_id orelse return; + const owner = p.panes[oid].?; + const f = if (owner.file) |*file| file else return; + const decls = ownerDecls(p, f, true) orelse return; + for (decls) |d| { + const header = f.content[d.start_byte..@min(d.header_end_byte, f.content.len)]; + 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; + } + }, + else => {}, + } +} + +/// The owner's declarations, from a parse that already exists: its sticky +/// headers' (TreeContext) at this revision, or the locations cache's. None +/// is made here, on the loop, unless `small` and the text is small: a +/// tree-sitter parse of a 1.2 MB file is seconds in a Debug build. +/// ponytail: no grouping for a big file until the disk engine's worker +/// parses it (phase 4). +fn ownerDecls(p: *Pardes, f: *File.State, small: bool) ?[]const syntax.ContextDeclaration { + if (f.context_revision) |rev| if (rev == f.revision and f.context_declarations.len > 0) return f.context_declarations; + const cache = &p.locations_cache; + for (cache.entries[0..cache.len]) |entry| { + if (entry.declarations_ready and std.mem.eql(u8, entry.path, f.path) and std.mem.eql(u8, entry.source, f.content)) return entry.analysis.declarations; + } + if (!small or f.content.len > small_parse_bytes or !syntax.supportsPath(f.path)) return null; + var got = p.locations_cache.get(p.tree_sitter_gpa, f.path, f.content, true, false) catch return null; + if (got.owned) { + got.deinit(p.tree_sitter_gpa); + return null; + } + return got.analysis.declarations; +} + +/// A text this small is parsed on the loop for its declarations when a +/// Symbols query asks (about 40 ms in a Debug build). +const small_parse_bytes = 64 << 10; + +/// The rows as `note` says, and nothing else: no hits. +fn noteRows(p: *Pardes, id: usize, note: []const u8) void { + const rp = p.panes[id].?; + const q = rp.query.?; + q.items.clearRetainingCapacity(); + q.items.append(p.gpa, .{ .kind = .note }) catch return; + q.current = null; + q.total = 0; + q.k = 0; + q.more = false; + var out: std.ArrayList(u8) = .empty; + defer out.deinit(p.gpa); + var rows: std.ArrayList(locations.Row) = .empty; + writeRow(p, &out, &rows, note[0 .. note.len - 1], .{ .kind = .context, .path = &.{}, .at = .{}, .location_end = 0, .code_start = 0 }) catch return; + setRows(p, rp, &out, &rows); +} + +/// One row: its text and its metadata, the path copied. +fn writeRow(p: *Pardes, out: *std.ArrayList(u8), rows: *std.ArrayList(locations.Row), text: []const u8, meta: locations.Row) !void { + try out.appendSlice(p.gpa, text); + try out.append(p.gpa, '\n'); + var m = meta; + m.path = try p.gpa.dupe(u8, meta.path); + errdefer p.gpa.free(m.path); + // Coloured whole (zeros where nothing coloured it): the pane's syntax + // pass then parses no fragment of it, per refill. + const code = text[@min(meta.code_start, text.len)..]; + m.colors = if (meta.colors.len >= code.len) try p.gpa.dupe(u8, meta.colors[0..code.len]) else blk: { + const c = try p.gpa.alloc(u8, code.len); + @memset(c, 0); + @memcpy(c[0..meta.colors.len], meta.colors); + break :blk c; + }; + rows.append(p.gpa, m) catch |err| { + p.gpa.free(m.path); + p.gpa.free(m.colors); + return err; + }; +} + +/// The rows made into the pane: line 1 as it is (the user's), then `out`, +/// with `rows` their metadata. The keyboard's place is left where it was. +fn setRows(p: *Pardes, rp: *Pane, out: *std.ArrayList(u8), rows: *std.ArrayList(locations.Row)) void { + defer locations.freeRowList(p.gpa, rows); + const f = &rp.file.?; + const line = lineOne(f.content); + const content = std.mem.concat(p.gpa, u8, &.{ line, "\n", out.items }) catch return; + const meta = p.gpa.alloc(locations.Row, rows.items.len + 1) catch { + p.gpa.free(content); + return; + }; + meta[0] = .{ .kind = .context, .path = p.gpa.dupe(u8, "") catch &.{}, .at = .{}, .location_end = 0, .code_start = 0 }; + @memcpy(meta[1..], rows.items); + rows.clearRetainingCapacity(); + const kept_row = rp.body.cur_row; + const kept_col = rp.body.cur_col; + if (std.mem.eql(u8, content, f.content)) { + // Same text: the metadata alone, no undo step, no syntax pass. + p.gpa.free(content); + if (locations.equalRows(f.location_rows, meta)) { + locations.freeRows(p.gpa, meta); + } else { + locations.freeRows(p.gpa, f.location_rows); + f.location_rows = meta; + f.syntax_dirty = true; + } + } else { + File.setContent(p, f, content); + locations.freeRows(p.gpa, f.location_rows); + f.location_rows = meta; + f.saved_revision = f.revision; + } + gpa_free_pager(p, f); + // The cursor stays where it was typing; on a row that went, the last. + const last: i32 = @intCast(File.nlines(p.gpa, f) -| 1); + rp.body.cur_row = @min(kept_row, last); + rp.body.cur_col = if (rp.body.cur_row == kept_row) kept_col else 0; + if (rp.body.cur_row == 0 and rp.body.cur_col > line.len) rp.body.cur_col = @intCast(line.len); + rp.query.?.seen_row = rp.body.cur_row; +} + +fn gpa_free_pager(p: *Pardes, f: *File.State) void { + if (f.pager_spans.len == 0) return; + p.gpa.free(f.pager_spans); + f.pager_spans = &.{}; +} + +/// The gutter a file of `nlines` lines numbers its rows in: two spaces, +/// the number right-aligned, two spaces. +fn gutterWidth(nlines: usize) usize { + var digits: usize = 1; + var n = nlines; + while (n >= 10) : (n /= 10) digits += 1; + return 2 + @max(3, digits) + 2; +} + +fn writeHitRow(p: *Pardes, out: *std.ArrayList(u8), rows: *std.ArrayList(locations.Row), width: usize, path: []const u8, line_no: usize, whole: []const u8, col: usize, end: usize, shade: []const u8) !void { + var lead: usize = 0; + while (lead < whole.len and (whole[lead] == ' ' or whole[lead] == '\t')) lead += 1; + const code = std.mem.trimEnd(u8, whole[lead..], "\r"); + var buf: [4096 + 32]u8 = undefined; + var num: [24]u8 = undefined; + const number = std.fmt.bufPrint(&num, "{d}", .{line_no}) catch ""; + const pad = width -| 2 -| number.len; + if (pad + number.len + 2 + code.len > buf.len) return; + @memset(buf[0..pad], ' '); + @memcpy(buf[pad..][0..number.len], number); + @memcpy(buf[pad + number.len ..][0..2], " "); + @memcpy(buf[pad + number.len + 2 ..][0..code.len], code); + const text = buf[0 .. pad + number.len + 2 + code.len]; + const gutter = pad + number.len + 2; + try writeRow(p, out, rows, text, .{ + .kind = .match, + .source_column = lead, + .path = @constCast(path), + .at = .{ .line = line_no, .col = col + 1, .end_line = line_no, .end_col = @max(col + 1, end) }, + .location_end = gutter, + .code_start = gutter, + .colors = @constCast(if (shade.len >= lead) shade[lead..][0..@min(shade.len - lead, code.len)] else &.{}), + }); +} + +/// The path a row of pane `tp`'s text says: its file's, or `@pN` for a +/// text that is no file (a list, a scratch). +fn addressOf(arena: std.mem.Allocator, tp: *const Pane) []const u8 { + const f = tp.file orelse return ""; + if (f.output == null and !std.mem.startsWith(u8, std.fs.path.basename(f.path), "+")) return f.path; + return std.fmt.allocPrint(arena, config.pane_addr ++ "{d}", .{tp.serial}) catch ""; +} + +/// Rows from pane `tp`'s places: one a line with any (two on a line are +/// one row: everywhere's bug), the declaration they are in over them when +/// its parse exists, from place `from` on, `budget` rows at most. The +/// place it stopped before. +fn writePlacesRows(p: *Pardes, q: *Query, out: *std.ArrayList(u8), rows: *std.ArrayList(locations.Row), tp: *Pane, from: usize, budget: *usize) !usize { + const f = &tp.file.?; + const set = &tp.places; + const hits = set.hits.items; + const index = try File.lineIndex(p.gpa, f); + const width = gutterWidth(index.len); + const path = addressOf(p.scratch.allocator(), tp); + const decls = ownerDecls(p, f, false) orelse &.{}; + var decl_now: ?usize = null; + var i: usize = @min(from, hits.len); + // the line of the first, found in the index + var line: usize = if (i < hits.len) blk: { + var lo: usize = 0; + var hi = index.len; + while (lo < hi) { + const mid = lo + (hi - lo) / 2; + if (index[mid] <= hits[i].start) lo = mid + 1 else hi = mid; + } + break :blk lo -| 1; + } else 0; + // a window begins at a line's first place + while (i > 0 and hits[i - 1].start >= index[line]) i -= 1; + while (i < hits.len) { + while (line + 1 < index.len and index[line + 1] <= hits[i].start) line += 1; + // the places on this line + var n: usize = 1; + const ls = index[line]; + const le = if (line + 1 < index.len) index[line + 1] - 1 else f.content.len; + while (i + n < hits.len and hits[i + n].start <= le) n += 1; + if (budget.* == 0) { + q.more = true; + break; + } + budget.* -= 1; + // the innermost declaration around it, its first line once + var inner: ?usize = null; + for (decls, 0..) |d, di| { + if (d.start_line > line) break; + if (d.end_line < line) continue; + inner = di; + } + if (inner != decl_now) { + decl_now = inner; + if (inner) |di| if (decls[di].start_line != line) { + const head_ls = index[decls[di].start_line]; + const head_le = if (decls[di].start_line + 1 < index.len) index[decls[di].start_line + 1] - 1 else f.content.len; + const head = std.mem.trim(u8, f.content[head_ls..head_le], " \t\r"); + var hb: [600]u8 = undefined; + const text = std.fmt.bufPrint(&hb, " {s}", .{head[0..@min(head.len, 560)]}) catch ""; + try q.items.append(p.gpa, .{ .kind = .header, .serial = tp.serial }); + try writeRow(p, out, rows, text, .{ .kind = .context, .declaration = true, .path = @constCast(path), .at = .{ .line = decls[di].start_line + 1 }, .location_end = 0, .code_start = 0 }); + }; + } + const shade: []const u8 = if (f.highlights.len > 0 and ls >= f.highlight_start and le <= f.highlight_start + f.highlights.len) f.highlights[ls - f.highlight_start .. le - f.highlight_start] else &.{}; + try q.items.append(p.gpa, .{ .kind = .hit, .serial = tp.serial, .hit = i, .n = n }); + try writeHitRow(p, out, rows, width, path, line + 1, f.content[ls..le], hits[i].start - ls, @min(hits[i].end, le) - ls, shade); + i += n; + } + return i; +} + +/// The rows of a `/`: while typed, a window of `live_rows` around the +/// current place; `full` (frozen), the whole list up to `max_rows`. +fn makeTextRows(p: *Pardes, id: usize, oid: usize, full: bool) !void { + const rp = p.panes[id].?; + const q = rp.query.?; + const owner = p.panes[oid].?; + const set = &owner.places; + q.items.clearRetainingCapacity(); + q.more = false; + var out: std.ArrayList(u8) = .empty; + defer out.deinit(p.gpa); + var rows: std.ArrayList(locations.Row) = .empty; + var budget: usize = if (full) max_rows else live_rows; + const at = set.current orelse (if (set.seek) |s| Places.firstFrom(set.hits.items, s) else 0); + const from = if (full) 0 else at -| live_rows / 2; + q.window = .{ .lo = from, .hi = from }; + if (set.started and set.from == rp.serial) { + if (from > 0) { + var hb: [64]u8 = undefined; + try noteRow(p, q, &out, &rows, std.fmt.bufPrint(&hb, " ... {d} places before these", .{from}) catch " ..."); + } + q.window.hi = try writePlacesRows(p, q, &out, &rows, owner, from, &budget); + q.window.lo = @min(from, q.window.hi); + } + if (q.more) try noteRow(p, q, &out, &rows, " ... and more: the count says how many"); + setRows(p, rp, &out, &rows); + showPlacesCurrent(p, id); +} + +fn noteRow(p: *Pardes, q: *Query, out: *std.ArrayList(u8), rows: *std.ArrayList(locations.Row), text: []const u8) !void { + try q.items.append(p.gpa, .{ .kind = .note }); + try writeRow(p, out, rows, text, .{ .kind = .context, .path = &.{}, .at = .{}, .location_end = 0, .code_start = 0 }); +} + +/// The current row from the places of the pane its rows are in, the count +/// with them: for `/`, the owner's. +fn showPlacesCurrent(p: *Pardes, id: usize) void { + const rp = p.panes[id].?; + const q = rp.query.?; + const owner = p.panes[p.paneBySerial(q.owner) orelse return].?; + const set = &owner.places; + q.total = if (set.from == rp.serial) set.hits.items.len else 0; + q.more = q.more or (set.from == rp.serial and !set.complete()); + q.k = if (set.current) |c| c + 1 else 0; + if (set.from != rp.serial) q.k = 0; + q.current = null; + // By line, not by the rows' place indices: the rows may lag the places + // a tick while they are still being found. + if (set.current) |c| if (c < set.hits.items.len) { + const at = lineOfOffset(p, &owner.file.?, set.hits.items[c].start) + 1; + const rows = rp.file.?.location_rows; + for (q.items.items, 0..) |it, i| { + if (it.kind != .hit or it.serial != owner.serial or i + 1 >= rows.len) continue; + if (rows[i + 1].at.line == at) { + q.current = i; + break; + } + } + }; + // Stepped out of the window the live rows are: made again around it. + if (q.current == null and set.current != null and !q.frozen and set.from == rp.serial) q.made_gen = std.math.maxInt(u64); + showCurrent(rp); +} + +/// Every open pane's rows for All, grouped under `@pN name (count)` in +/// the order of the panes' serials (everywhere's other bug: it went by +/// column). +fn makeAllRows(p: *Pardes, id: usize) !void { + const rp = p.panes[id].?; + const q = rp.query.?; + q.items.clearRetainingCapacity(); + q.more = false; + var out: std.ArrayList(u8) = .empty; + defer out.deinit(p.gpa); + var rows: std.ArrayList(locations.Row) = .empty; + var order: [pardes.MAX_PANES]usize = undefined; + var n: usize = 0; + for (p.panes, 0..) |slot, i| if (slot) |tp| if (tp.places.from == rp.serial and tp.places.started) { + order[n] = i; + n += 1; + }; + std.mem.sort(usize, order[0..n], p, struct { + fn lt(pp: *Pardes, a: usize, b: usize) bool { + return pp.panes[a].?.serial < pp.panes[b].?.serial; + } + }.lt); + var budget: usize = max_rows; + q.total = 0; + for (order[0..n]) |tid| { + const tp = p.panes[tid].?; + const set = &tp.places; + if (!set.shows(tp) or set.hits.items.len == 0) { + q.more = q.more or !set.complete(); + continue; + } + q.total += set.hits.items.len; + q.more = q.more or !set.complete(); + var hb: [600]u8 = undefined; + const name = if (tp.file) |f| Names.relative(f.path, std.fs.path.dirname(rp.file.?.path) orelse "") else ""; + const head = std.fmt.bufPrint(&hb, config.pane_addr ++ "{d} {s} ({d})", .{ tp.serial, name[0..@min(name.len, 500)], set.hits.items.len }) catch ""; + try q.items.append(p.gpa, .{ .kind = .header, .serial = tp.serial }); + try writeRow(p, &out, &rows, head, .{ .kind = .context, .declaration = true, .path = @constCast(addressOf(p.scratch.allocator(), tp)), .at = .{}, .location_end = 0, .code_start = 0 }); + _ = try writePlacesRows(p, q, &out, &rows, tp, 0, &budget); + } + if (budget == 0) try noteRow(p, q, &out, &rows, " ... and more: the count says how many"); + setRows(p, rp, &out, &rows); + // The current one: the first hit row, until a step moves it. + if (q.current == null or q.current.? >= q.items.items.len) q.current = firstHit(q); + countCurrent(q); + showCurrent(rp); +} + +fn firstHit(q: *const Query) ?usize { + for (q.items.items, 0..) |it, i| if (it.kind == .hit) return i; + return null; +} + +/// `k` from the current row: the hits on the rows before it, and its own. +fn countCurrent(q: *Query) void { + q.k = 0; + const c = q.current orelse return; + for (q.items.items[0..c]) |it| q.k += if (it.kind == .hit) @max(1, it.n) else 0; + q.k += 1; +} + +/// The names the query matches, best first, `Names.max_rows` of them: each +/// a row as its source has it, the matched bytes tinted. +fn makeNameRows(p: *Pardes, id: usize, pat: []const u8) !void { + _ = pat; + const rp = p.panes[id].?; + const q = rp.query.?; + const dir = std.fs.path.dirname(rp.file.?.path) orelse "/"; + const was_current: ?u32 = if (q.current) |c| (if (c < q.items.items.len) q.items.items[c].ref else null) else null; + _ = was_current; + q.items.clearRetainingCapacity(); + var out: std.ArrayList(u8) = .empty; + defer out.deinit(p.gpa); + var rows: std.ArrayList(locations.Row) = .empty; + var spans: std.ArrayList(pardes.pager.Span) = .empty; + errdefer spans.deinit(p.gpa); + const chrome = p.bodyChrome(); + const tint: pardes.CellStyle = .{ .fg = .{ .rgb = chrome.search_fg }, .bg = .{ .rgb = chrome.search_bg }, .bold = true }; + const shown = @min(q.names.hits.items.len, Names.max_rows); + var marks: [Names.max_query * 4]u16 = undefined; + const base = lineOne(rp.file.?.content).len + 1; + for (0..shown) |i| { + var nmarks: usize = 0; + const row = q.names.row(i, &marks, &nmarks); + const cand = q.names.cands.items[q.names.hits.items[i].cand]; + const at = base + out.items.len; + // Where it points: a path (Find, Recent), a pane (Panes), a line + // of the owner (Symbols). + var meta: locations.Row = .{ .kind = .match, .path = &.{}, .at = .{}, .location_end = 0, .code_start = 0, .mark_occurrence = false }; + var pathbuf: [4096 + 32]u8 = undefined; + switch (q.source) { + .find => meta.path = @constCast(std.fmt.bufPrint(&pathbuf, "{s}/{s}", .{ std.mem.trimEnd(u8, dir, "/"), row }) catch row), + .recent => { + const t = look.parsePathLine(row); + meta.path = @constCast(if (t.path.len > 0 and t.path[0] == '/') t.path else std.fmt.bufPrint(&pathbuf, "{s}/{s}", .{ std.mem.trimEnd(u8, dir, "/"), t.path }) catch t.path); + meta.at = t.at; + }, + .panes => meta.path = @constCast(std.fmt.bufPrint(&pathbuf, config.pane_addr ++ "{d}", .{cand.ref}) catch ""), + .symbols => { + const owner = p.panes[p.paneBySerial(q.owner) orelse 0]; + meta.path = @constCast(if (owner) |o| addressOf(p.scratch.allocator(), o) else ""); + meta.at = .{ .line = cand.ref }; + }, + else => {}, + } + try q.items.append(p.gpa, .{ .kind = .hit, .ref = cand.ref }); + try writeRow(p, &out, &rows, row, meta); + var k: usize = 0; + while (k < nmarks) { + var e = k + 1; + while (e < nmarks and marks[e] == marks[e - 1] + 1) e += 1; + try spans.append(p.gpa, .{ .start = @intCast(at + marks[k]), .end = @intCast(at + marks[e - 1] + 1), .style = tint }); + k = e; + } + } + if (q.names.hits.items.len > shown) try noteRow(p, q, &out, &rows, " ... and more: type more of the name"); + setRows(p, rp, &out, &rows); + const f = &rp.file.?; + f.pager_spans = spans.toOwnedSlice(p.gpa) catch &.{}; + q.total = q.names.hits.items.len; + q.more = q.names.busy(); + // The best is current until a step or a click moves it. + q.current = if (shown > 0) 0 else null; + countCurrent(q); + showCurrent(rp); + showTarget(p, id); +} + +/// A slice of a Grep: the files the walk has found so far read and +/// searched, about 4 ms of them a frame, each line holding the pattern +/// (a literal, smart case: a capital makes it exact) kept. +/// ponytail: on the loop, a file a step; the disk engine's worker (phase +/// 4) takes this over. +fn grepSlice(p: *Pardes, q: *Query, rp: *Pane, pat: []const u8) void { + const started = Places.nowNs(); + const dir = std.fs.path.dirname(rp.file.?.path) orelse "/"; + const fold = for (pat) |c| { + if (std.ascii.isUpper(c)) break false; + } else true; + var low_buf: [256]u8 = undefined; + const needle = if (fold) std.ascii.lowerString(low_buf[0..@min(pat.len, low_buf.len)], pat[0..@min(pat.len, low_buf.len)]) else pat; + while (q.grep_next < q.names.cands.items.len) { + if (q.found.items.len >= grep_cap) break; + const c = q.names.cands.items[q.grep_next]; + q.grep_next += 1; + const rel = q.names.bytes.items[c.start..][0..c.len]; + var pathbuf: [4096 + 8]u8 = undefined; + const path = std.fmt.bufPrint(&pathbuf, "{s}/{s}", .{ std.mem.trimEnd(u8, dir, "/"), rel }) catch continue; + const bytes = blk: { + pardes.turn.yield(); + defer pardes.turn.back(); + break :blk filesystem.read(p, path) catch continue; + }; + defer p.gpa.free(bytes); + if (std.mem.indexOfScalar(u8, bytes[0..@min(bytes.len, 8000)], 0) != null) continue; + var line_no: u32 = 1; + var ls: usize = 0; + while (ls <= bytes.len) { + const le = std.mem.indexOfScalarPos(u8, bytes, ls, '\n') orelse bytes.len; + const ln = bytes[ls..le]; + const at = if (fold) std.ascii.findIgnoreCase(ln, needle) else std.mem.indexOf(u8, ln, needle); + if (at) |col| { + const path_at: u32 = @intCast(q.found_bytes.items.len); + q.found_bytes.appendSlice(p.gpa, rel) catch return; + const code_at: u32 = @intCast(q.found_bytes.items.len); + const code = ln[0..@min(ln.len, 400)]; + q.found_bytes.appendSlice(p.gpa, code) catch return; + q.found.append(p.gpa, .{ .path = path_at, .path_len = @intCast(rel.len), .line = line_no, .col = @intCast(col), .end = @intCast(col + needle.len), .code = code_at, .code_len = @intCast(code.len) }) catch return; + if (q.found.items.len >= grep_cap) break; + } + if (le == bytes.len) break; + ls = le + 1; + line_no += 1; + } + if (started != 0 and Places.nowNs() - started > Places.frame_ns) break; + } +} + +/// A Grep keeps this many lines: the rest wait (the disk engine's `More`). +pub const grep_cap = 2000; + +fn makeGrepRows(p: *Pardes, id: usize) !void { + const rp = p.panes[id].?; + const q = rp.query.?; + const dir = std.fs.path.dirname(rp.file.?.path) orelse "/"; + q.items.clearRetainingCapacity(); + var out: std.ArrayList(u8) = .empty; + defer out.deinit(p.gpa); + var rows: std.ArrayList(locations.Row) = .empty; + var last_path: []const u8 = ""; + var pathbuf: [4096 + 8]u8 = undefined; + for (q.found.items, 0..) |fd, i| { + const rel = q.found_bytes.items[fd.path..][0..fd.path_len]; + const path = std.fmt.bufPrint(&pathbuf, "{s}/{s}", .{ std.mem.trimEnd(u8, dir, "/"), rel }) catch continue; + if (!std.mem.eql(u8, rel, last_path)) { + last_path = rel; + try q.items.append(p.gpa, .{ .kind = .header }); + try writeRow(p, &out, &rows, rel, .{ .kind = .context, .path = @constCast(path), .at = .{}, .location_end = 0, .code_start = 0 }); + } + const code = q.found_bytes.items[fd.code..][0..fd.code_len]; + try q.items.append(p.gpa, .{ .kind = .hit, .hit = i, .n = 1 }); + try writeHitRow(p, &out, &rows, 9, path, fd.line, code, fd.col, fd.end, &.{}); + } + const walking = q.names.walking() or q.grep_next < q.names.cands.items.len; + if (q.found.items.len >= grep_cap) try noteRow(p, q, &out, &rows, " ... stopped at 2000 lines: type more of it"); + setRows(p, rp, &out, &rows); + q.total = q.found.items.len; + q.more = walking and q.found.items.len < grep_cap; + if (q.current == null or q.current.? >= q.items.items.len) q.current = firstHit(q); + countCurrent(q); + showCurrent(rp); +} + +/// A Grep's hits in each open file are that pane's places: its tints, +/// ticks and n/N. +fn feedGrepPlaces(p: *Pardes, q: *Query, serial: u32, pat: []const u8) void { + _ = q; + for (p.panes) |slot| { + const tp = slot orelse continue; + const f = tp.file orelse continue; + if (f.output != null or tp.query != null) continue; + tp.places.search(p, tp, .list, serial, pat, true, null, false); + } +} + +/// The language server's answer for an owner's Refs, Def, Impl or +/// Diagnostics, into its query pane (made or reused) with line 1 the word: +/// what follows the word filters the rows; the places in the owner's text +/// are its places. `rows` are `path:line:col text`, as the server's +/// answer is written (lsp_client). +pub fn fillList(p: *Pardes, owner_id: usize, source: Source, rows: []const u8) void { + const owner = p.panes[owner_id] orelse return; + var id = ofOwner(p, owner.serial); + if (id == null or p.panes[id.?].?.query.?.source != source) { + open(p, owner_id, source, "", false); + id = ofOwner(p, owner.serial); + } + const qid = id orelse return; + const rp = p.panes[qid].?; + const q = rp.query.?; + const copy = p.gpa.dupe(u8, rows) catch return; + p.gpa.free(q.lsp_rows); + q.lsp_rows = copy; + const line = lineOne(rp.file.?.content); + const a = parse(line) orelse return; + makeListRows(p, qid, a.pat) catch |err| p.reportError(qid, "search", err); + toLineOne(p, qid); +} + +fn makeListRows(p: *Pardes, id: usize, pat: []const u8) !void { + const rp = p.panes[id].?; + const q = rp.query.?; + const dir = std.fs.path.dirname(rp.file.?.path) orelse "/"; + q.items.clearRetainingCapacity(); + var out: std.ArrayList(u8) = .empty; + defer out.deinit(p.gpa); + var rows: std.ArrayList(locations.Row) = .empty; + const owner_id = p.paneBySerial(q.owner); + const owner_path: []const u8 = if (owner_id) |oid| (if (p.panes[oid].?.file) |f| f.path else "") else ""; + var feed: std.ArrayList(Places.Hit) = .empty; + defer feed.deinit(p.gpa); + // In order: by path, then place, as a list of places reads. + var sorted: std.ArrayList([]const u8) = .empty; + defer sorted.deinit(p.gpa); + var split = std.mem.splitScalar(u8, q.lsp_rows, '\n'); + while (split.next()) |ln| if (ln.len > 0) try sorted.append(p.gpa, ln); + std.mem.sort([]const u8, sorted.items, {}, struct { + fn lt(_: void, a: []const u8, b: []const u8) bool { + const ta = look.parsePathLine(a); + const tb = look.parsePathLine(b); + const order = std.mem.order(u8, ta.path, tb.path); + if (order != .eq) return order == .lt; + if (ta.at.line != tb.at.line) return ta.at.line < tb.at.line; + return ta.at.col < tb.at.col; + } + }.lt); + var last_path: []const u8 = ""; + var pathbuf: [4096 + 8]u8 = undefined; + var n: usize = 0; + for (sorted.items) |ln| { + if (ln.len == 0) continue; + if (pat.len > 0 and std.ascii.findIgnoreCase(ln, pat) == null) continue; + const t = look.parsePathLine(ln); + if (t.at.line == 0) continue; + const path = if (t.path.len > 0 and t.path[0] == '/') t.path else std.fmt.bufPrint(&pathbuf, "{s}/{s}", .{ std.mem.trimEnd(u8, dir, "/"), t.path }) catch continue; + if (!std.mem.eql(u8, t.path, last_path)) { + last_path = t.path; + try q.items.append(p.gpa, .{ .kind = .header }); + try writeRow(p, &out, &rows, Names.relative(t.path, dir), .{ .kind = .context, .path = @constCast(path), .at = .{}, .location_end = 0, .code_start = 0 }); + } + const rest = std.mem.trimStart(u8, ln[@min(t.end, ln.len)..], " \t:"); + const col0 = t.at.col -| 1; + try q.items.append(p.gpa, .{ .kind = .hit, .n = 1 }); + // The row's text: the line in the owner when it is the owner's, + // else as the server said it. + var code: []const u8 = rest; + var col = col0; + var end = if (t.at.end_col > 0 and t.at.end_line == t.at.line) t.at.end_col else col0 + 1; + if (owner_id) |oid| if (std.mem.eql(u8, path, owner_path)) { + const owner_f = &p.panes[oid].?.file.?; + if (t.at.line <= File.nlines(p.gpa, owner_f)) { + const ls = File.lineStart(p.gpa, owner_f, t.at.line - 1); + const nx = File.lineStart(p.gpa, owner_f, t.at.line); + const le = if (nx > ls and owner_f.content[nx - 1] == '\n') nx - 1 else nx; + code = owner_f.content[ls..le]; + col = @min(col0, code.len); + end = @min(@max(end, col + 1), code.len); + feed.append(p.gpa, .{ .start = ls + col, .end = ls + @max(end, col + 1) }) catch {}; + } + } else { + col = 0; + end = 0; + }; + try writeHitRow(p, &out, &rows, 9, path, t.at.line, code, col, end, &.{}); + n += 1; + } + if (n == 0) try noteRow(p, q, &out, &rows, " nothing"); + setRows(p, rp, &out, &rows); + q.total = n; + q.more = false; + q.current = firstHit(q); + if (owner_id) |oid| { + const owner = p.panes[oid].?; + // Current: the first place after where it was asked (the answer + // may come after the cursor moved), shown in the owner. + const asked_at: usize = if (p.lsp_last) |last| (if (last.serial == owner.serial) last.offset else owner.places.origin(owner)) else owner.places.origin(owner); + owner.places.feed(p, owner, rp.serial, feed.items, null); + const hits = owner.places.hits.items; + var next: ?usize = null; + for (hits, 0..) |h, i| if (h.start > asked_at) { + next = i; + break; + }; + if (next == null and hits.len > 0) next = 0; + if (next) |hi| { + owner.places.goTo(owner, hi, false); + for (q.items.items, 0..) |it, i| if (it.kind == .hit and i + 1 < rp.file.?.location_rows.len) { + const meta = rp.file.?.location_rows[i + 1]; + if (!std.mem.eql(u8, meta.path, owner_path)) continue; + const ls = File.lineStart(p.gpa, &owner.file.?, meta.at.line -| 1); + if (ls + meta.at.col -| 1 == hits[hi].start) { + q.current = i; + break; + } + }; + } + } + countCurrent(q); + showCurrent(rp); +} + +/// The places query `serial` fed in panes other than the owner, cleared +/// (a new source or pattern makes its own); the owner's too when the new +/// line is no `/`. +fn clearPlaces(p: *Pardes, q: *Query, serial: u32, owner_id: ?usize, asked: anytype) void { + _ = q; + _ = asked; + for (p.panes, 0..) |slot, i| { + const tp = slot orelse continue; + if (tp.places.from != serial) continue; + if (owner_id != null and owner_id.? == i) tp.places.restore(p, tp); + tp.places.clear(p.gpa); + } +} + +// ---- the current row ---- + +/// The current row drawn as the visited row is (a line selection), while +/// the keyboard is on line 1 or elsewhere; on the rows, the cursor itself +/// is current. Scrolled into view, line 1 kept when it can be. +fn showCurrent(rp: *Pane) void { + const q = rp.query orelse return; + if (rp.body.cur_row != 0 and rp.focus == .body) return; + const c = q.current orelse { + rp.body.msel.active = false; + return; + }; + const r: i32 = @intCast(c + 1); + rp.body.msel = .{ .active = true, .r0 = r, .r1 = r }; + const off = rp.scroll(); + const shown = off + @as(i32, rp.rows) - 1; + if (r > shown) rp.scrollBy(r - shown) else if (r < off) rp.scrollBy(r - off); +} + +/// The line (0-based) of byte `at` of `f`'s text. +fn lineOfOffset(p: *Pardes, f: *File.State, at: usize) usize { + const index = File.lineIndex(p.gpa, f) catch return 0; + var lo: usize = 0; + var hi = index.len; + while (lo < hi) { + const mid = lo + (hi - lo) / 2; + if (index[mid] <= at) lo = mid + 1 else hi = mid; + } + return lo -| 1; +} + +/// The first of pane `tp`'s places on line `line` (1-based), if any. +fn placeOnLine(p: *Pardes, tp: *Pane, line: usize) ?usize { + const f = &tp.file.?; + if (line == 0 or line > File.nlines(p.gpa, f)) return null; + const ls = File.lineStart(p.gpa, f, line - 1); + const next = File.lineStart(p.gpa, f, line); + const hits = tp.places.hits.items; + const i = Places.firstFrom(hits, ls); + if (i < hits.len and (hits[i].start < next or (next == ls))) return i; + return null; +} + +/// Item `i` current, and shown where it points (`show`). +fn setCurrent(p: *Pardes, id: usize, i: usize, show: bool) void { + const rp = p.panes[id].?; + const q = rp.query.?; + q.current = i; + const it = q.items.items[i]; + const rows = rp.file.?.location_rows; + if (it.serial != 0 and i + 1 < rows.len) if (p.paneBySerial(it.serial)) |tid| { + const tp = p.panes[tid].?; + if (placeOnLine(p, tp, rows[i + 1].at.line)) |hi| { + tp.places.current = hi; + tp.places.gen +%= 1; + if (tp.places.from == rp.serial and tp.serial == q.owner) q.k = hi + 1 else countCurrent(q); + } else countCurrent(q); + } else countCurrent(q) else countCurrent(q); + showCurrent(rp); + if (show) showTarget(p, id); +} + +/// Step the current row `delta` hits on, round the end silently: Ctrl-n, +/// Ctrl-p, Down and Up on line 1, n and N in the pane. +pub fn step(p: *Pardes, id: usize, delta: i32) void { + const rp = p.panes[id] orelse return; + const q = rp.query orelse return; + // A `/`: the owner's places step, the rows follow them. + if (q.source == .text) if (p.paneBySerial(q.owner)) |oid| { + const owner = p.panes[oid].?; + if (owner.places.from == rp.serial) { + const keyboard = p.active; + owner.places.step(p, owner, delta > 0, 1, false); + p.active = keyboard; + showPlacesCurrent(p, id); + return; + } + }; + const items = q.items.items; + if (items.len == 0) return; + var i: usize = q.current orelse (if (delta > 0) items.len - 1 else 0); + for (0..items.len) |_| { + if (delta > 0) i = if (i + 1 >= items.len) 0 else i + 1 else i = if (i == 0) items.len - 1 else i - 1; + if (items[i].kind == .hit) break; + } else return; + setCurrent(p, id, i, true); +} + +/// Where the current row points, shown with the keyboard left where it is: +/// a place in an open pane's text selected there (its places' current), +/// in view; a file an open pane shows, its line there; any other file in +/// the +Preview under this pane. Every pane it moves remembers its view +/// first, for Esc. +fn showTarget(p: *Pardes, id: usize) void { + const rp = p.panes[id] orelse return; + const q = rp.query orelse return; + const c = q.current orelse return; + const f = &rp.file.?; + if (c + 1 >= f.location_rows.len) return; + const it = q.items.items[c]; + const meta = f.location_rows[c + 1]; + const keyboard = p.active; + defer p.active = keyboard; + if (it.serial != 0) { + const tid = p.paneBySerial(it.serial) orelse return; + const tp = p.panes[tid].?; + if (tp.places.snap.len == 0) tp.places.remember(p, tp); + if (placeOnLine(p, tp, meta.at.line)) |hi| tp.places.goTo(tp, hi, false); + return; + } + if (q.source == .symbols) { + const oid = p.paneBySerial(q.owner) orelse return; + look.focusPaneLine(p, oid, .{ .line = it.ref }, .center); + return; + } + if (q.source == .panes) return; + if (meta.path.len == 0) return; + // A file open in a pane: shown there. + for (p.panes, 0..) |slot, i| { + const tp = slot orelse continue; + const tf = tp.file orelse continue; + if (tf.output != null or !std.mem.eql(u8, tf.path, meta.path)) continue; + if (tp.places.snap.len == 0) tp.places.remember(p, tp); + const line0 = meta.at.line -| 1; + const visible = line0 >= tf.scroll and line0 < tf.scroll + tp.rows; + if (meta.at.line > 0) look.focusPaneLine(p, i, meta.at, if (visible) .keep else .center); + return; + } + displayPreview(p, id, meta.path, meta.at); +} + +// ---- the +Preview ---- + +/// The +Preview under query pane `qid`, if it has one: by serial. +fn previewOf(p: *Pardes, qid: usize) ?usize { + const q = p.panes[qid].?.query.?; + if (q.preview == 0) return null; + return p.paneBySerial(q.preview) orelse { + q.preview = 0; + return null; + }; +} + +/// Whether `pane` is a query pane's +Preview: that query pane's slot. +pub fn isPreview(p: *Pardes, pane: *const Pane) ?usize { + const f = pane.file orelse return null; + const o = f.output orelse return null; + if (o.from != .preview) return null; + for (p.panes, 0..) |slot, i| if (slot) |qp| if (qp.query) |q| if (q.preview == pane.serial) return i; + return null; +} + +/// A +Preview made under query pane `qid`, out of its rows alone. +fn makePreview(p: *Pardes, qid: usize) ?usize { + const rp = p.panes[qid].?; + const free = p.freeSlot() orelse return null; + const dir = std.fs.path.dirname(rp.file.?.path) orelse "/"; + const content = p.gpa.dupe(u8, "") catch return null; + const np = Output.open(p, free, dir, .preview, "", content) catch { + p.gpa.free(content); + return null; + }; + layout.compute(p); + const rows = @max(pardes.BOX_H, np.tag_rows) + p.settings.search_rows; + // Out of the group's root, the text that asked: the query pane keeps + // the rows it was typed into with (made later, for a reused pane). + if (!layout.attachFrom(p, qid, free, rows, layout.groupRoot(p, qid))) { + p.removePane(free, qid) catch {}; + return null; + } + rp.query.?.preview = np.serial; + return free; +} + +/// File `path` at `at` in the +Preview: its text read (once a file: a +/// file open in a pane would be shown there instead), the place centred +/// and selected. Made when the pane has none and its owner has the rows. +fn displayPreview(p: *Pardes, qid: usize, path: []const u8, at: look.Spot) void { + const id = previewOf(p, qid) orelse makePreview(p, qid) orelse return; + const pane = p.panes[id].?; + const f = &pane.file.?; + if (!std.mem.eql(u8, f.path, path)) { + if (exec.kindOf(path)) |kind| if (kind != .file) return; + const bytes = blk: { + pardes.turn.yield(); + defer pardes.turn.back(); + break :blk filesystem.read(p, path) catch return; + }; + if (std.mem.indexOfScalar(u8, bytes[0..@min(bytes.len, 8000)], 0) != null) { + p.gpa.free(bytes); + return; + } + const owned_path = p.gpa.dupe(u8, path) catch { + p.gpa.free(bytes); + return; + }; + p.gpa.free(f.path); + f.path = owned_path; + File.setContent(p, f, bytes); + f.saved_revision = f.revision; + f.scroll = 0; + f.syntax_dirty = true; + pane.hscroll = 0; + p.sync(); + } + look.clearNavigationSelection(p, pane); + if (at.line == 0 or at.line > File.nlines(p.gpa, f)) { + f.scroll = 0; + f.syntax_dirty = true; + pane.body.cur_row = 0; + pane.body.cur_col = 0; + pane.body.cur_pinned = true; + return; + } + look.focusPaneLine(p, id, at, .center); + if (at.end_line == 0 or at.end_col <= at.col) + pane.body.msel = .{ .active = true, .r0 = @intCast(at.line - 1), .r1 = @intCast(at.line - 1) }; +} + +/// The +Preview becomes the file's pane where it stands: same slot, same +/// serial, same rect, its scroll and selection as the preview left them. +/// It is a file pane from here: an empty undo history, the Recent entry, +/// the watch, a file's tag; and a pane of its own, no longer attached (it +/// stays when its query pane goes). +fn promote(p: *Pardes, qid: usize, id: usize) void { + const pane = p.panes[id] orelse return; + const f = &pane.file.?; + f.output = null; + if (pane.tag.own) |own| p.gpa.free(own); + pane.tag.own = null; + f.saved_revision = f.revision; + f.saved_hash = null; + f.saved_len = null; + f.disk_gone = false; + f.syntax_dirty = true; + pane.attached_to = null; + if (Pardes.recentKeeps(f.path)) p.recent.opened(p.recentGpa(), f.path); + if (filesystem.localPath(f.path) != null) p.emit(.{ .watch = .{ .pane = @intCast(id), .on = true } }); + pardes.ctlfs.events.noteLog(p, .rename, pane); + p.panes[qid].?.query.?.preview = 0; +} + +// ---- Enter, Esc ---- + +/// Enter on line 1 (or on a row, `row`): the keyboard to the current hit +/// in its pane (the +Preview promoted to the file's pane when it shows +/// it), a `/` into the register, and the rows frozen into ordinary text. +pub fn land(p: *Pardes, id: usize, row: ?usize) void { + const rp = p.panes[id] orelse return; + const q = rp.query orelse return; + if (row) |r| if (r < q.items.items.len and q.items.items[r].kind == .hit) setCurrent(p, id, r, true); + const t = &rp.body; + if (t.mode == .insert) edit.exitInsert(p, t); + freeze(p, id); + const owner_id = p.paneBySerial(q.owner); + if (q.source == .text) { + const oid = owner_id orelse return; + const owner = p.panes[oid].?; + const set = &owner.places; + // The whole list now, once, every place found: a result from here. + if (set.started and set.from == rp.serial) { + set.fill(p, owner, std.math.maxInt(usize), @import("regexp.zig").Regex.budget); + makeTextRows(p, id, oid, true) catch {}; + } + if (set.started and set.from == rp.serial) { + if (set.literal) { + var escaped: std.ArrayList(u8) = .empty; + normal.appendSearchLiteral(&escaped, p.scratch.allocator(), set.pattern) catch {}; + p.registers.put(p.gpa, '/', escaped.items, 0, 1, true); + } else p.registers.put(p.gpa, '/', set.pattern, 0, 1, true); + p.registers.last_search = '/'; + set.provenance = .search; + } + p.jump_force = true; + p.active = oid; + return; + } + const c = q.current orelse { + if (owner_id) |oid| p.active = oid; + return; + }; + const f = &rp.file.?; + const it = q.items.items[c]; + const meta = f.location_rows[c + 1]; + p.jump_force = true; + if (it.serial != 0) { + if (p.paneBySerial(it.serial)) |tid| { + p.active = tid; + if (layout.findPane(p, tid)) |at| p.setActiveColumn(at.col); + } + return; + } + switch (q.source) { + .symbols => if (owner_id) |oid| { + look.focusPaneLine(p, oid, .{ .line = it.ref }, .center); + return; + }, + .panes => if (p.paneBySerial(it.ref)) |tid| { + p.active = tid; + if (layout.findPane(p, tid)) |at| p.setActiveColumn(at.col); + return; + }, + else => {}, + } + // The preview shows it: promoted where it stands. + if (previewOf(p, id)) |pid| if (std.mem.eql(u8, p.panes[pid].?.file.?.path, meta.path)) { + promote(p, id, pid); + p.active = pid; + if (q.source == .grep) { + const a = parse(q.asked) orelse return; + const pp = p.panes[pid].?; + pp.places.search(p, pp, .list, rp.serial, a.pat, true, null, false); + } + return; + }; + var buf: [4096 + 64]u8 = undefined; + const address = if (meta.at.line > 0) + std.fmt.bufPrint(&buf, "{s}:{d}:{d}", .{ meta.path, meta.at.line, meta.at.col }) catch meta.path + else + meta.path; + look.lookAt(p, id, address); +} + +/// The rows frozen: ordinary text from here, Save works on them; the +/// places they fed stay, while the pane lives; every view stays where the +/// search left it; the preview, of no more use, goes. +fn freeze(p: *Pardes, id: usize) void { + const rp = p.panes[id] orelse return; + const q = rp.query orelse return; + q.frozen = true; + if (q.saved) |s| freeSaved(p.gpa, s); + q.saved = null; + for (p.panes) |slot| if (slot) |tp| if (tp.places.from == rp.serial or tp.serial == q.owner) tp.places.forget(p.gpa); + if (previewOf(p, id)) |pid| { + const pv = p.panes[pid].?; + // A preview showing the current row is promoted by `land`: one + // showing another file goes. + _ = pv; + } +} + +/// Esc on line 1 while typing: every view as the search found it, the +/// places it fed gone, and the pane closed (nothing was answered); a +/// reused pane's frozen rows come back instead, and their places. +pub fn cancel(p: *Pardes, id: usize) void { + const rp = p.panes[id] orelse return; + const q = rp.query orelse return; + const t = &rp.body; + if (t.mode == .insert) edit.exitInsert(p, t); + const owner_id = p.paneBySerial(q.owner); + for (p.panes) |slot| if (slot) |tp| { + if (tp.places.from != rp.serial and tp.serial != q.owner) continue; + tp.places.restore(p, tp); + tp.places.forget(p.gpa); + if (tp.places.from == rp.serial) tp.places.clear(p.gpa); + }; + if (q.saved) |s| { + q.saved = null; + // A preview made for the query Esc took back has no use: its rows + // go to the text whose rows they were. + if (previewOf(p, id)) |pid| { + p.panes[pid].?.attached_to = null; + p.removePane(pid, owner_id) catch {}; + q.preview = 0; + } + const f = &rp.file.?; + File.setContent(p, f, s.content); + locations.freeRows(p.gpa, f.location_rows); + f.location_rows = s.rows; + p.gpa.free(q.asked); + q.asked = s.asked; + q.source = s.source; + q.items.clearRetainingCapacity(); + q.items.appendSlice(p.gpa, s.items) catch {}; + p.gpa.free(s.items); + q.current = s.current; + q.total = s.total; + q.k = s.k; + q.frozen = true; + rp.body.cur_row = 0; + rp.body.cur_col = 0; + showCurrent(rp); + // Its places again, as Enter left them. + if (q.source == .text) if (owner_id) |oid| if (parse(q.asked)) |a| { + const owner = p.panes[oid].?; + owner.places.search(p, owner, .search, rp.serial, a.pat, false, null, false); + }; + if (owner_id) |oid| p.active = oid; + return; + } + if (owner_id) |oid| { + p.removePane(id, oid) catch {}; + p.active = oid; + if (layout.findPane(p, oid)) |at| p.setActiveColumn(at.col); + } else p.removePane(id, null) catch {}; +} + +/// The pane going (Del, its owner's Del): the places it fed go with it. +pub fn release(p: *Pardes, pane: *Pane) void { + for (p.panes) |slot| if (slot) |tp| if (tp.places.from == pane.serial) { + tp.places.forget(p.gpa); + tp.places.clear(p.gpa); + }; +} + +// ---- keys, the mouse, edits ---- + +/// The keys a query pane answers itself, before its text has them. On +/// line 1, typing: Enter lands, Esc cancels, Ctrl-n, Ctrl-p, Down and Up +/// step the current row. In normal mode: Enter on a hit row lands on it, +/// n and N step. Anything else is ordinary text editing (line 1) or is +/// refused (the rows, while live: clampEdit). Tab stays the exec chord. +pub fn key(p: *Pardes, id: usize, k: Key) bool { + const rp = p.panes[id] orelse return false; + const q = rp.query orelse return false; + if (rp.focus != .body) return false; + const t = &rp.body; + if (q.frozen) return false; + if (t.mode == .normal) { + if (t.normal.prefix != .none or k.ctrl or k.alt or t.normal.count != 0) return false; + if (k.cp == 'n' or k.cp == 'N') { + step(p, id, if (k.cp == 'n') 1 else -1); + return true; + } + if (hit(k, config.look_key) and t.cur_row > 0) { + land(p, id, @intCast(t.cur_row - 1)); + return true; + } + return false; + } + if (t.cur_row != 0 or t.mode != .insert or t.reg_wait) return false; + if (hit(k, config.escape)) { + cancel(p, id); + return true; + } + if (k.cp == Key.enter and !k.ctrl and !k.alt and !k.shift) { + land(p, id, null); + return true; + } + const down = (k.cp == Key.down and !k.ctrl and !k.alt) or (k.ctrl and !k.alt and k.cp == 'n'); + const up = (k.cp == Key.up and !k.ctrl and !k.alt) or (k.ctrl and !k.alt and k.cp == 'p'); + if (down or up) { + step(p, id, if (down) 1 else -1); + return true; + } + return false; +} + +/// An edit of a live query pane's text (edit.setEditTextSpan): inside line +/// 1, as typed; one from line 1 into the rows, cut at line 1's end (and a +/// newline put in it, a blank); one wholly in the rows refused, as a tag's +/// prefix refuses one. Null: refused. Lifted from queryline. +pub fn clampEdit(p: *Pardes, t: *panes.Text, old: []const u8, new: []u8) ?[]u8 { + const end = std.mem.indexOfScalar(u8, old, '\n') orelse old.len; + const span = File.spanOf(old, new); + const old_to = old.len - span.tail; + const put = new[span.head .. new.len - span.tail]; + const rows_same = old_to <= end and std.mem.indexOfScalar(u8, put, '\n') == null; + if (rows_same) return new; + if (span.head > end or (span.head == end and old_to > end and put.len == 0 and end < old.len)) { + t.refused = true; + if (t.pane()) |pane| if (p.paneIdOf(pane)) |id| + p.setMessage(id, "the rows are line 1's: edit the query (Enter keeps them as text)"); + return null; + } + // From inside line 1 into the rows: what it put in, flat, and what is + // left of line 1 after it; the rows as they were. + const kept = if (old_to < end) old[old_to..end] else ""; + const out = std.mem.concat(p.gpa, u8, &.{ old[0..span.head], put, kept, old[end..] }) catch return null; + for (out[0 .. span.head + put.len + kept.len]) |*c| if (c.* == '\n') { + c.* = ' '; + }; + return out; +} + +/// B3 on a row's gutter (its line number): the row's address, as a +Diff +/// line's prefix is its place (exec.operandAt). Null off a gutter. +pub fn rowAddress(pane: *const Pane, row: usize, col: usize, buf: []u8) ?[]const u8 { + if (pane.query == null) return null; + const f = pane.file orelse return null; + if (row == 0 or row >= f.location_rows.len) return null; + const meta = f.location_rows[row]; + if (meta.kind != .match or meta.path.len == 0 or meta.location_end == 0 or col >= meta.location_end) return null; + if (meta.at.line == 0) return std.fmt.bufPrint(buf, "{s}", .{meta.path}) catch null; + return std.fmt.bufPrint(buf, "{s}:{d}:{d}", .{ meta.path, meta.at.line, meta.at.col }) catch null; +} + +/// The tag's start for a query pane: its name and where it is, `+Search +/// 3/27`, `0` with nothing found, `+` while it still counts. +pub fn tagPrefix(q: *const Query, arena: std.mem.Allocator, path: []const u8) ![]const u8 { + const name = std.fs.path.basename(path); + const more = if (q.more and !q.frozen) "+" else ""; + if (q.total == 0) return std.fmt.allocPrint(arena, "{s} 0{s}", .{ name, more }); + if (q.k == 0) return std.fmt.allocPrint(arena, "{s} {d}{s}", .{ name, q.total, more }); + return std.fmt.allocPrint(arena, "{s} {d}/{d}{s}", .{ name, q.k, q.total, more }); +} + +/// The other places on a hit row's line tinted, from the pane its rows are +/// in (the first is the row's own mark, Output.decorateRow): the current +/// one strongest, as in that pane's text. +pub fn paint(p: *Pardes, s: *Surface, pane: *Pane, r: pardes.Rect, body_h: u16) void { + const q = pane.query orelse return; + const f = if (pane.file) |*file| file else return; + const th = p.theme(); + const strong = p.chromeTheme().search_bg; + const quiet = colors.mix(th.bg orelse th.tag_bg, strong); + var vr: i32 = 0; + var last: i32 = -1; + while (vr < body_h) : (vr += 1) { + const row = pane.wrapAt(vr).line; + if (row == last or row < 1) continue; + last = row; + const i: usize = @intCast(row - 1); + if (i >= q.items.items.len or @as(usize, @intCast(row)) >= f.location_rows.len) continue; + const it = q.items.items[i]; + if (it.kind != .hit or it.serial == 0) continue; + const tid = p.paneBySerial(it.serial) orelse continue; + const tp = p.panes[tid].?; + const set = &tp.places; + if (!set.shows(tp)) continue; + const tf = &tp.file.?; + const meta = f.location_rows[@intCast(row)]; + // Its line's places as they are now, found by the line: the rows + // may be a tick behind the places. + if (meta.at.line == 0 or meta.at.line > File.nlines(p.gpa, tf)) continue; + const ls = File.lineStart(p.gpa, tf, meta.at.line - 1); + const next = File.lineStart(p.gpa, tf, meta.at.line); + const line = modal.lineSlice(f.content, @intCast(row)); + var hi = Places.firstFrom(set.hits.items, ls); + while (hi < set.hits.items.len and set.hits.items[hi].start < next) : (hi += 1) { + const h = set.hits.items[hi]; + if (h.start < ls + meta.source_column) continue; + const a = meta.code_start + (h.start - ls - meta.source_column); + const b = @min(line.len, meta.code_start + (@min(h.end, next) - ls - meta.source_column)); + if (b <= a or a >= line.len) continue; + const current = set.current != null and set.current.? == hi; + File.paintWordSelection(p, s, pane, r, row, @intCast(a), @intCast(b), if (current) strong else quiet); + } + } +} + +// ---- tests ---- + +fn typeKeys(p: *Pardes, text: []const u8) void { + for (text) |c| p.update(.{ .key = .{ .cp = c, .text = &[_]u8{c} } }); +} + +fn queryPane(p: *Pardes) ?usize { + for (p.panes, 0..) |slot, i| if (slot) |pane| if (pane.query != null) return i; + return null; +} + +test "parse: line 1's first word names the source" { + try std.testing.expectEqual(Source.text, parse("/alpha").?.source); + try std.testing.expectEqualStrings("alpha", parse("/alpha").?.pat); + try std.testing.expectEqual(Source.find, parse("Find lay").?.source); + try std.testing.expectEqualStrings("lay", parse("Find lay").?.pat); + try std.testing.expectEqual(Source.grep, parse("Grep").?.source); + try std.testing.expectEqual(Source.all, parse("All x y").?.source); + try std.testing.expectEqualStrings("x y", parse("All x y").?.pat); + try std.testing.expectEqual(Source.refs, parse("Refs").?.source); + try std.testing.expect(parse("Findx") == null); + try std.testing.expect(parse("grep x") == null); + try std.testing.expect(parse("") == null); +} + +test "a / query: keystroke by keystroke, the owner shows the set, rows from its own rows alone, zero hits a state, Esc puts all back" { + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 40 }); + defer p.deinit(); + const pane = try p.setTestFile("alpha one\nbeta\nalphabet\ngamma alpha\nalpha two\ndelta\n"); + p.newScratchBelow(0); + const below = p.col_panes[0][1]; + p.active = 0; + layout.compute(p); + const before = p.rects; + // cursor on line 3 (row 2) + pane.body.cur_row = 2; + pane.body.cur_col = 0; + typeKeys(p, "/"); + const qid = queryPane(p).?; + const qp = p.panes[qid].?; + try std.testing.expectEqual(@as(?usize, 0), layout.ownerOf(p, qid)); + try std.testing.expectEqual(qid, p.active); + try std.testing.expectEqualDeep(before[below], p.rects[below]); + const born = p.rects[qid]; + try std.testing.expectEqualStrings("/", lineOne(qp.file.?.content)); + // keystroke 1 + typeKeys(p, "a"); + const q = qp.query.?; + try std.testing.expectEqual(Source.text, q.source); + try std.testing.expect(pane.places.started and pane.places.from == qp.serial); + try std.testing.expect(q.total > 0); + try std.testing.expectEqualDeep(born, p.rects[qid]); + // keystroke 2 .. `alph`: four places on four lines (rows), the + // current the first at or after the cursor (line 3's alphabet) + typeKeys(p, "lph"); + try std.testing.expectEqual(@as(usize, 4), q.total); + try std.testing.expectEqual(@as(usize, 2), q.k); + try std.testing.expectEqual(@as(?usize, 1), pane.places.current); + const sel = pane.body.primaryRange(pane.file.?.content, 0); + try std.testing.expectEqual(@as(usize, 15), @min(sel.anchor, sel.head)); + try std.testing.expectEqualDeep(born, p.rects[qid]); + try std.testing.expectEqualDeep(before[below], p.rects[below]); + try std.testing.expectEqual(qid, p.active); + // Ctrl-n steps, the owner follows + p.update(.{ .key = .{ .cp = 'n', .ctrl = true } }); + try std.testing.expectEqual(@as(usize, 3), q.k); + // drawn: rows, tints, ticks + var frame = std.heap.ArenaAllocator.init(std.testing.allocator); + defer frame.deinit(); + _ = try p.render(frame.allocator()); + try std.testing.expect(p.surface.nrail_ticks > 0); + // zero hits: a state, the pane stays where it was, line 1 as typed + typeKeys(p, "zz"); + try std.testing.expectEqual(@as(usize, 0), q.total); + try std.testing.expect(p.panes[qid] != null); + try std.testing.expectEqualStrings("/alphzz", lineOne(qp.file.?.content)); + try std.testing.expectEqualDeep(born, p.rects[qid]); + const tag = try tagline.pathPrefix(p, p.scratch.allocator(), qp); + try std.testing.expectEqualStrings("+Search 0", tag); + // Esc: the pane gone, its rows back to the owner, the owner as it was + p.update(.{ .key = .{ .cp = Key.escape } }); + try std.testing.expect(p.panes[qid] == null); + try std.testing.expectEqual(@as(usize, 0), p.active); + layout.compute(p); + try std.testing.expectEqualDeep(before[0], p.rects[0]); + try std.testing.expectEqualDeep(before[below], p.rects[below]); + try std.testing.expect(!pane.places.started); + try std.testing.expectEqual(@as(i32, 2), pane.body.cur_row); +} + +test "a / query: Enter lands and freezes, the register filled, n and N step silently, a later / reuses the pane and Esc brings the frozen rows back" { + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 40 }); + defer p.deinit(); + const pane = try p.setTestFile("alpha one\nbeta\nalphabet\ngamma alpha\nalpha two\ndelta\n"); + typeKeys(p, "/alpha"); + const qid = queryPane(p).?; + const qp = p.panes[qid].?; + const q = qp.query.?; + p.update(.{ .key = .{ .cp = Key.enter } }); + try std.testing.expect(q.frozen); + try std.testing.expectEqual(@as(usize, 0), p.active); + try std.testing.expectEqualStrings("alpha", p.registers.value('/', 0).?); + try std.testing.expectEqual(Places.Provenance.search, pane.places.provenance); + const frozen = try std.testing.allocator.dupe(u8, qp.file.?.content); + defer std.testing.allocator.free(frozen); + // the rows: one a line (gamma alpha has one), a gutter number each + try std.testing.expect(std.mem.indexOf(u8, frozen, " 1 alpha one\n") != null); + // n and N in the owner step the same set, round the end silently + const logged = p.messages.len; + try std.testing.expectEqual(@as(?usize, 0), pane.places.current); + typeKeys(p, "nnn"); + try std.testing.expectEqual(@as(?usize, 3), pane.places.current); + typeKeys(p, "n"); + try std.testing.expectEqual(@as(?usize, 0), pane.places.current); + try std.testing.expect(pane.places.wrapped); + try std.testing.expectEqual(logged, p.messages.len); + typeKeys(p, "N"); + try std.testing.expectEqual(@as(?usize, 3), pane.places.current); + // a later `/` reuses the pane: line 1 fresh, the rows the new query's + typeKeys(p, "/"); + try std.testing.expectEqual(qid, queryPane(p).?); + try std.testing.expectEqual(qid, p.active); + try std.testing.expect(!q.frozen); + typeKeys(p, "beta"); + try std.testing.expectEqual(@as(usize, 1), q.total); + // Esc: the frozen rows of `/alpha` again, the owner's places with them + p.update(.{ .key = .{ .cp = Key.escape } }); + try std.testing.expect(p.panes[qid] != null); + try std.testing.expect(q.frozen); + try std.testing.expectEqualStrings(frozen, qp.file.?.content); + try std.testing.expectEqualStrings("alpha", pane.places.pattern); + // Del closes it, its places with it + exec.runBuiltin(p, .Del, qid, "", null); + try std.testing.expect(p.panes[qid] == null); + try std.testing.expect(!pane.places.started); +} + +/// A test's file pane in `tmp`, named `name`, holding `text`. +fn testFileIn(p: *Pardes, tmp: *std.testing.TmpDir, name: []const u8, text: []const u8) !*Pane { + try tmp.dir.writeFile(std.testing.io, .{ .sub_path = name, .data = text }); + var base_buf: [std.fs.max_path_bytes]u8 = undefined; + const dir = base_buf[0..try tmp.dir.realPath(std.testing.io, &base_buf)]; + const pane = try p.setTestFile(text); + p.gpa.free(pane.file.?.path); + pane.file.?.path = try std.fs.path.join(p.gpa, &.{ dir, name }); + return pane; +} + +fn leader(p: *Pardes, keys: []const u8) void { + p.update(.{ .key = .{ .cp = ' ', .text = " " } }); + typeKeys(p, keys); +} + +fn settle(p: *Pardes) void { + var frames: usize = 0; + while (busy(p) and frames < 2000) : (frames += 1) p.update(.tick); + p.update(.tick); +} + +test "Find: names fuzzy per keystroke, the group born with its +Preview, nothing else moves, Enter promotes the preview in place" { + if (!filesystem.platform_has_fs) return; + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + try tmp.dir.createDirPath(std.testing.io, "src"); + for ([_][]const u8{ "src/layout.zig", "src/look.zig", "notes.md" }) |name| + 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(); + _ = try testFileIn(p, &tmp, "x.txt", "x\n"); + p.newScratchBelow(0); + const other = p.col_panes[0][1]; + try std.testing.expect(layout.splitColumn(p, other, other, false)); + p.active = 0; + layout.compute(p); + const before = p.rects; + leader(p, "ff"); + const qid = queryPane(p).?; + const q = p.panes[qid].?.query.?; + try std.testing.expectEqual(Source.find, q.source); + try std.testing.expectEqualStrings("Find ", lineOne(p.panes[qid].?.file.?.content)); + // the group: owner, query pane, +Preview, out of the owner's rows alone + const pv = previewOf(p, qid).?; + try std.testing.expectEqual(@as(usize, 0), layout.groupRoot(p, pv)); + try std.testing.expectEqualDeep(before[other], p.rects[other]); + try std.testing.expectEqual(before[0].h, p.rects[0].h + p.rects[qid].h + p.rects[pv].h); + settle(p); + // an empty query lists every name + try std.testing.expectEqual(@as(usize, 4), q.total); + const born = p.rects; + typeKeys(p, "lay"); + settle(p); + try std.testing.expectEqual(@as(usize, 1), q.total); + try std.testing.expectEqualDeep(born[qid], p.rects[qid]); + try std.testing.expectEqualDeep(born[pv], p.rects[pv]); + // the current one in the preview, never by the pointer + try std.testing.expect(std.mem.endsWith(u8, p.panes[pv].?.file.?.path, "src/layout.zig")); + try std.testing.expectEqual(qid, p.active); + const serial = p.panes[pv].?.serial; + const rect = p.rects[pv]; + p.update(.{ .key = .{ .cp = Key.enter } }); + // promoted where it stands: same slot, serial, rect; a file pane now + try std.testing.expectEqual(pv, p.active); + try std.testing.expectEqual(serial, p.panes[pv].?.serial); + try std.testing.expect(p.panes[pv].?.file.?.output == null); + try std.testing.expect(p.panes[pv].?.attached_to == null); + layout.compute(p); + try std.testing.expectEqualDeep(rect, p.rects[pv]); + try std.testing.expect(q.frozen); + try std.testing.expectEqualDeep(before[other], p.rects[other]); +} + +test "Grep: lines of the files under the owner's directory, under their file; All: every pane's, under @pN in serial order, a line once" { + if (!filesystem.platform_has_fs) return; + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + 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(); + const a = try testFileIn(p, &tmp, "a.txt", "one needle\ntwo\n"); + leader(p, "fg"); + const qid = queryPane(p).?; + const q = p.panes[qid].?.query.?; + typeKeys(p, "needle"); + settle(p); + // a.txt's one, b.zig's three lines + try std.testing.expectEqual(@as(usize, 3), q.total); + const body = p.panes[qid].?.file.?.content; + try std.testing.expect(std.mem.indexOf(u8, body, "\nb.zig\n") != null); + // the open file's hits are its places + try std.testing.expect(a.places.started and a.places.hits.items.len == 1); + p.update(.{ .key = .{ .cp = Key.escape } }); + try std.testing.expect(p.panes[qid] == null); + try std.testing.expect(!a.places.started); + + // All: a second pane, both searched, grouped by serial + p.newScratchBelow(0); + const s = p.active; + const sf = &p.panes[s].?.file.?; + File.setContent(p, sf, try p.gpa.dupe(u8, "needle needle twice\n")); + p.active = 0; + leader(p, "/"); + const aid = queryPane(p).?; + const aq = p.panes[aid].?.query.?; + try std.testing.expectEqual(Source.all, aq.source); + typeKeys(p, "needle"); + settle(p); + try std.testing.expectEqual(@as(usize, 3), aq.total); + const all = p.panes[aid].?.file.?.content; + var hb: [32]u8 = undefined; + const first = std.mem.indexOf(u8, all, try std.fmt.bufPrint(&hb, config.pane_addr ++ "{d} ", .{a.serial})).?; + const second = std.mem.indexOf(u8, all, try std.fmt.bufPrint(&hb, config.pane_addr ++ "{d} ", .{p.panes[s].?.serial})).?; + try std.testing.expect(a.serial < p.panes[s].?.serial and first < second); + try std.testing.expect(second < std.mem.indexOf(u8, all, "twice").?); + // two places on one line are one row + try std.testing.expectEqual(@as(usize, 1), std.mem.count(u8, all, "twice")); +} + +test "zz query timings on the 1.2 MB stress file (QUERY_TIMES=)" { + const path_z = std.c.getenv("QUERY_TIMES") orelse return error.SkipZigTest; + const path = std.mem.span(path_z); + const io = std.testing.io; + const bytes = try std.Io.Dir.cwd().readFileAlloc(io, path, std.testing.allocator, .limited(8 << 20)); + defer std.testing.allocator.free(bytes); + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 160, .rows = 50 }); + defer p.deinit(); + const pane = try p.setTestFile(bytes); + p.gpa.free(pane.file.?.path); + pane.file.?.path = try p.gpa.dupe(u8, path); + var frame = std.heap.ArenaAllocator.init(std.testing.allocator); + defer frame.deinit(); + _ = try p.render(frame.allocator()); + pane.body.cur_row = 15000; + pane.ensureCursorVisible(); + _ = frame.reset(.retain_capacity); + _ = try p.render(frame.allocator()); + const Clock = struct { + fn step(pp: *Pardes, fr: *std.heap.ArenaAllocator, ev: pardes.Event) !u64 { + const t0 = Places.nowNs(); + pp.update(ev); + _ = fr.reset(.retain_capacity); + _ = try pp.render(fr.allocator()); + return Places.nowNs() - t0; + } + }; + var report: std.ArrayList(u8) = .empty; + defer report.deinit(std.testing.allocator); + var base: u64 = 0; + for (0..10) |_| base += try Clock.step(p, &frame, .{ .key = .{ .cp = 'j', .text = "j" } }); + try report.print(std.testing.allocator, "a cursor move and its frame, no search: {d} us\n", .{base / 10 / 1000}); + const t_open = try Clock.step(p, &frame, .{ .key = .{ .cp = '/', .text = "/" } }); + try report.print(std.testing.allocator, "open / {d} us\n", .{t_open / 1000}); + for ("pane.v") |c| { + const t = try Clock.step(p, &frame, .{ .key = .{ .cp = c, .text = &[_]u8{c} } }); + var ticks: usize = 0; + var worst: u64 = 0; + while (busy(p) or pane.places.busy(pane)) : (ticks += 1) { + if (ticks > 500) break; + worst = @max(worst, try Clock.step(p, &frame, .tick)); + } + const qid = queryPane(p).?; + try report.print(std.testing.allocator, "key '{c}': {d} us, then {d} ticks (worst {d} us), {d} places\n", .{ c, t / 1000, ticks, worst / 1000, p.panes[qid].?.query.?.total }); + } + // Enter: frozen; then edits in the owner with the pane open. + _ = try Clock.step(p, &frame, .{ .key = .{ .cp = Key.enter } }); + _ = try Clock.step(p, &frame, .{ .key = .{ .cp = 'i', .text = "i" } }); + var worst_edit: u64 = 0; + var sum: u64 = 0; + for (0..20) |_| { + const t = try Clock.step(p, &frame, .{ .key = .{ .cp = 'x', .text = "x" } }); + worst_edit = @max(worst_edit, t); + sum += t; + const t2 = try Clock.step(p, &frame, .tick); + worst_edit = @max(worst_edit, t2); + } + try report.print(std.testing.allocator, "edit in the owner (insert x, then a tick): mean {d} us, worst {d} us\n", .{ sum / 20 / 1000, worst_edit / 1000 }); + // The same edits with no query pane at all, for the editor's own cost. + p.update(.{ .key = .{ .cp = Key.escape } }); + exec.runBuiltin(p, .Del, queryPane(p).?, "", null); + p.update(.tick); + p.update(.{ .key = .{ .cp = 'i', .text = "i" } }); + sum = 0; + for (0..20) |_| sum += try Clock.step(p, &frame, .{ .key = .{ .cp = 'x', .text = "x" } }); + try report.print(std.testing.allocator, "the same edit, no search: mean {d} us\n", .{sum / 20 / 1000}); + std.debug.print("{s}", .{report.items}); +} + +test "* seeds line 1 and keeps the keyboard; SPC b b picks a pane, SPC s s a declaration; SearchPane new leaves the last where it is" { + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 120, .rows = 48 }); + defer p.deinit(); + 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"); + // `*` on `const`: line 1 `/\bconst\b`, the keyboard still in the text + typeKeys(p, "e*"); + const qid = queryPane(p).?; + try std.testing.expectEqual(@as(usize, 0), p.active); + try std.testing.expect(std.mem.startsWith(u8, lineOne(p.panes[qid].?.file.?.content), "/")); + try std.testing.expect(pane.places.started); + typeKeys(p, "n"); + try std.testing.expectEqual(@as(?usize, 0), pane.places.current); + // SPC b b: the open panes by name; Enter goes to the marked one + p.newScratchBelow(0); + const other = p.active; + p.active = 0; + leader(p, "bb"); + const bid = queryPane(p).?; + try std.testing.expectEqual(bid, qid); + try std.testing.expectEqual(Source.panes, p.panes[bid].?.query.?.source); + try std.testing.expect(p.panes[bid].?.query.?.total >= 1); + // SPC s s: the declarations, fuzzy; Enter lands on the line + p.update(.{ .key = .{ .cp = Key.escape } }); + p.active = 0; + leader(p, "ss"); + const sid = queryPane(p).?; + try std.testing.expectEqual(Source.symbols, p.panes[sid].?.query.?.source); + // (context declarations span lines: a one-line fn is none of them) + typeKeys(p, "bet"); + try std.testing.expectEqual(@as(usize, 1), p.panes[sid].?.query.?.total); + p.update(.{ .key = .{ .cp = Key.enter } }); + try std.testing.expectEqual(@as(usize, 0), p.active); + try std.testing.expectEqual(@as(i32, 1), pane.body.cur_row); + _ = other; + // SearchPane new: the frozen one stays, unattached; a new one under the owner + p.settings.search_pane = .new; + typeKeys(p, "/"); + const nid = queryPane2(p, sid).?; + try std.testing.expect(nid != sid); + try std.testing.expect(p.panes[sid].?.attached_to == null); + try std.testing.expectEqual(@as(?usize, 0), layout.ownerOf(p, nid)); +} + +fn queryPane2(p: *Pardes, not: usize) ?usize { + for (p.panes, 0..) |slot, i| if (slot) |pane| if (pane.query != null and i != not) return i; + return null; +} diff --git a/src/Text.zig b/src/Text.zig index cef76b3b..88630f83 100644 --- a/src/Text.zig +++ b/src/Text.zig @@ -182,7 +182,10 @@ pub fn primaryRange(t: *Text, text: []const u8, row0: i32) modal.Selection { const e = if (r1 + 1 >= modal.cursorLineCount(text)) text.len else modal.lineStartOffset(text, r1 + 1); return .{ .anchor = s, .head = @max(e, modal.nextGrapheme(text, c)) }; } - if (t.vsel.active) return cellRange(text, t.vsel.row - row0, t.vsel.col, t.cur_row - row0, t.cur_col); + // Both ends through the line index, as the cursor's: cellRange counts + // lines from the top for each, a pass over a big file per call (the + // places' settle and every insert-mode key asked it). + if (t.vsel.active) return cellOffRange(text, File.textOffset(t, text, .{ .row = @intCast(@max(0, t.vsel.row - row0)), .col = @intCast(@max(0, t.vsel.col)) }), c); return .{ .anchor = c, .head = modal.nextGrapheme(text, c) }; } diff --git a/src/body_layer.zig b/src/body_layer.zig index d44045a6..e50b7e3e 100644 --- a/src/body_layer.zig +++ b/src/body_layer.zig @@ -275,6 +275,7 @@ pub fn renderBody(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane panes.File.recolorSyntax(p, s, pane, f, r, tx, tw, body_h); panes.File.drawWrapMarkers(p, s, pane, r, tx, tw, body_h, pane_bg); pane.places.paint(p, s, pane, r, body_h); + panes.Query.paint(p, s, pane, r, body_h); } else if (pane.isTerminal() and p.settings.colors) { panes.terminal.recolorAnsi(p, s, pane, r, tx, tw, body_h, body); panes.File.recolorDiffOutput(p, s, pane, r, tx, tw, body_h, body); diff --git a/src/builtins.zig b/src/builtins.zig index 1ec33d88..7cdee9de 100644 --- a/src/builtins.zig +++ b/src/builtins.zig @@ -210,7 +210,7 @@ pub const registry = struct { .toggle, .transition, .scene, .dump_dir, .choice, .lift, .shader_animation, .motion, .shell => false, .theme, .font, .tagline_size, .window_opacity, .window_blur, .message_ms, .shader, .inactive_dim, .grip_width => true, // bare, it says the current value (exec.applySettingBuiltin) - .tab, .callstack_depth => false, + .tab, .callstack_depth, .search_rows => false, }; return declOr(b, "requires_arg", false, false); } @@ -1721,7 +1721,8 @@ pub const Find = struct { if (rows == 0) c.p.reportFailure(c.id, e_search_miss_find); return; } - c.p.startPrompt(c.pane, &c.pane.body, .{ .search = config.find_marker }); + // Bare (SPC f f): the query pane, line 1 `Find `, typed into. + panes.Query.open(c.p, c.id, .find, "", true); } }; @@ -1738,7 +1739,29 @@ pub const Grep = struct { if (rows == 0) c.p.reportFailure(c.id, e_search_miss_grep); return; } - c.p.startPrompt(c.pane, &c.pane.body, .{ .search = config.grep_marker }); + // Bare (SPC f g): the query pane, line 1 `Grep `, typed into. + panes.Query.open(c.p, c.id, .grep, "", true); + } +}; + +/// Search in a query pane under this pane, line 1 the argument (`Panes`, +/// `Symbols lay`, `All needle`, `/re`, any of its words); bare, `/`. +pub const Search = struct { + pub const takes_arg = true; + pub const quiet = true; + 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).?; + panes.Query.open(c.p, c.id, asked.source, asked.pat, true); + } +}; + +/// Pick an open pane by its name in a query pane under this one (SPC b b). +pub const Panes = struct { + pub const takes_arg = true; + pub const quiet = true; + pub fn run(c: Ctx) void { + panes.Query.open(c.p, c.id, .panes, std.mem.trim(u8, c.arg orelse "", " \t\r\n"), true); } }; @@ -1866,9 +1889,13 @@ pub const Last = struct { /// List the files opened lately, closed ones too, each a place to open again. pub const Recent = struct { pub const scope: Scope = .session; + pub const takes_arg = true; pub const output: OutputTraits = .{ .name = config.recent_buffer, .steps = true, .locations = true }; pub fn run(c: Ctx) void { - panes.Output.openRecent(c.p, c.id) catch |err| c.p.reportError(c.id, "recent", err); + // From a pane: the query pane under it, line 1 `Recent `, typed + // into; from a header, which no pane owns, the +Recent list. + if (c.p.exec_header or c.p.panes[c.id] == null) return panes.Output.openRecent(c.p, c.id) catch |err| c.p.reportError(c.id, "recent", err); + panes.Query.open(c.p, c.id, .recent, std.mem.trim(u8, c.arg orelse "", " \t\r\n"), true); } }; diff --git a/src/config.zig b/src/config.zig index 06eec2d9..2fa4a55d 100644 --- a/src/config.zig +++ b/src/config.zig @@ -26,6 +26,26 @@ pub const leader_help: u8 = '?'; const undecided: []const u8 = ""; +/// Leader paths that run a builtin WITH an argument (the pick prototype's): +/// the query pane's sources that have no word of their own, `Search` and +/// line 1. `SPC s` is the session group (Dump, Restore, Attach), so the +/// declarations are `SPC s s`, a key from helix's. +pub const leader_args = [_]struct { path: []const u8, cmd: Builtin, arg: []const u8 }{ + .{ .path = "bb", .cmd = .Search, .arg = "Panes" }, + .{ .path = "ss", .cmd = .Search, .arg = "Symbols" }, + .{ .path = "/", .cmd = .Search, .arg = "All" }, +}; + +comptime { + @setEvalBranchQuota(20_000); + // A path here is a leaf: no builtin's path is it or runs past it, and + // none of it is a builtin's whole path. + for (leader_args) |la| for (std.enums.values(Builtin)) |b| if (leader_path.get(b)) |path| { + if (std.mem.startsWith(u8, path, la.path) or std.mem.startsWith(u8, la.path, path)) + @compileError("leader_args path collides with " ++ @tagName(b) ++ ": " ++ la.path); + }; +} + // null means word/chord-only. Every enabled builtin must explicitly choose a path. pub const leader_path = paths: { @setEvalBranchQuota(10_000); // a check per builtin, and they grow @@ -94,6 +114,11 @@ pub const leader_path = paths: { .Delcol = "cd", .Joincol = "cj", .Placement = "cp", + .SearchPlace = null, + .SearchPane = null, + .SearchRows = null, + .Search = null, + .Panes = null, .BootShell = null, .LookWord = null, .DirLook = null, @@ -517,6 +542,7 @@ pub const dump_config_buffer = "+DumpConfig"; pub const effect_code_buffer = "+EffectCode"; pub const jumps_buffer = "+Jumps"; pub const recent_buffer = "+Recent"; +pub const preview_buffer = "+Preview"; pub const unsaved_buffer = "+Unsaved"; pub const themes_buffer = "+Themes"; pub const fonts_buffer = "+Fonts"; @@ -846,6 +872,15 @@ pub const Runtime = struct { callstack_layout: CallstackLayout = .stacked, callstack_corners: CallstackCorners = .rounded, callstack_depth: u8 = @import("lsp/lsp.zig").callstack_default_depth, + /// Where a query pane goes (Query.zig): `attached`, under the pane that + /// asked, out of its rows alone; `column`, in the finder column. + search_place: SearchPlace = .attached, + /// A search from a pane that has a query pane: `reuse` it (its frozen + /// rows back on Esc), or open a `new` one, the last left where it is. + search_pane: SearchPane = .reuse, + /// The body rows a query pane is born with under its line 1 (and its + /// +Preview with): it never resizes itself after. + search_rows: u16 = 8, pub const ShaderAnimation = enum { off, on, always }; pub const Placement = enum { acme, pardes }; @@ -858,8 +893,10 @@ pub const Runtime = struct { pub const JumpScope = enum { file, all }; pub const CallstackLayout = enum { @"inline", stacked }; pub const CallstackCorners = @import("lsp/lsp.zig").CallstackCorners; + pub const SearchPlace = enum { attached, column }; + pub const SearchPane = enum { reuse, new }; /// A setting that is one of a few words, each an enum field of Runtime. - pub const Choice = enum { placement, boot_shell, look_word, dir_look, diff_look, pager, term_images, jump_scope, callstack_layout, callstack_corners }; + pub const Choice = enum { placement, boot_shell, look_word, dir_look, diff_look, pager, term_images, jump_scope, callstack_layout, callstack_corners, search_place, search_pane }; /// shadow: a soft drop shadow. rim: a light hairline along the top of /// the focused pane's tag rows. auto: a shadow on a light page; on a @@ -1048,6 +1085,7 @@ pub const Runtime = struct { grip_width, tab, callstack_depth, + search_rows, transition: animation.Transition, scene: Scene, /// A Shadertoy file into the post chain or out of it; `off` empties @@ -1137,6 +1175,9 @@ pub const Runtime = struct { .{ .word = "CallstackCorners", .action = .{ .choice = .callstack_corners }, .doc = "Callstack tree corners: rounded (the default) or square; bare, it switches styles. Applies to the next Callstack query." }, .{ .word = "CallstackDepth", .action = .callstack_depth, .doc = "Caller levels collected by Callstack, 1 through 64; default 8. Bare, it says the current limit." }, .{ .word = "Tab", .action = .tab, .doc = "A tab's width in cells, 1 through 16, in every pane; bare, it says the width." }, + .{ .word = "SearchPlace", .action = .{ .choice = .search_place }, .doc = "Where a query pane goes: attached, under the pane that asked, out of its rows alone, or column, in the finder column." }, + .{ .word = "SearchPane", .action = .{ .choice = .search_pane }, .doc = "A search from a pane that has a query pane: reuse it, or open a new one and leave the last where it is." }, + .{ .word = "SearchRows", .action = .search_rows, .doc = "The rows a query pane is born with under its line 1, 1 through 100; default 8. It never resizes itself." }, }; pub fn find(name: []const u8) ?Setting { @@ -1311,6 +1352,7 @@ pub const Runtime = struct { .grip_width => state.grip_width = number(u16, argument, " \t\r\n%", 50, 300) orelse return false, .callstack_depth => state.callstack_depth = number(u8, argument, " \t\r\n", 1, @import("lsp/lsp.zig").callstack_max_depth) orelse return false, .tab => state.tab = number(u16, argument, " \t\r\n", 1, 16) orelse return false, + .search_rows => state.search_rows = number(u16, argument, " \t\r\n", 1, 100) orelse return false, .theme, .font => return false, } return true; @@ -1348,6 +1390,7 @@ pub const Runtime = struct { .grip_width => "50-300 (a percentage)", .tab => "1-16 (cells)", .callstack_depth => "1-64 (levels)", + .search_rows => "1-100 (rows)", .tagline_size => std.fmt.comptimePrint("{d}-{d} (a percentage)", .{ tagline_percent_min, tagline_percent_max }), .message_ms => std.fmt.comptimePrint("0-{d} (milliseconds)", .{message_ms_max}), .shell => "a path of at most 255 bytes; bare, $SHELL, else /bin/sh", @@ -1490,6 +1533,7 @@ pub const Runtime = struct { .inactive_dim => try out.print("{s} {d}\n", .{ setting.word, state.inactive_dim }), .callstack_depth => try out.print("{s} {d}\n", .{ setting.word, state.callstack_depth }), .tab => try out.print("{s} {d}\n", .{ setting.word, state.tab }), + .search_rows => try out.print("{s} {d}\n", .{ setting.word, state.search_rows }), .grip_width => try out.print("{s} {d}\n", .{ setting.word, state.grip_width }), }; if (context.locations.len > 0) try out.print("LocationsConfig {s}\n", .{context.locations}); @@ -1773,6 +1817,8 @@ pub const Runtime = struct { .jump_scope => "all", .callstack_layout => "inline", .callstack_corners => "square", + .search_place => "column", + .search_pane => "new", }, .lift => "rim", .motion => "playful", @@ -1780,6 +1826,7 @@ pub const Runtime = struct { .grip_width => "200", .callstack_depth => "16", .tab => "8", + .search_rows => "12", else => null, }; try std.testing.expect(apply(&state, setting, argument)); @@ -1853,6 +1900,8 @@ pub const Runtime = struct { .jump_scope => "JumpScope all\n", .callstack_layout => "CallstackLayout inline\n", .callstack_corners => "CallstackCorners square\n", + .search_place => "SearchPlace column\n", + .search_pane => "SearchPane new\n", }, .lift => "Lift rim\n", .motion => "Motion playful\n", @@ -1860,6 +1909,7 @@ pub const Runtime = struct { .grip_width => "GripWidth 200\n", .callstack_depth => "CallstackDepth 16\n", .tab => "Tab 8\n", + .search_rows => "SearchRows 12\n", .theme, .font => unreachable, }; try std.testing.expect(std.mem.indexOf(u8, report, expected) != null); @@ -2212,6 +2262,7 @@ const doc_typ = struct { if (n == 0) return leader.len == 1 and leader[0].cp == ' '; for (std.enums.values(Builtin)) |b| if (leader_path.get(b)) |p| if (std.mem.eql(u8, p, path[0..n])) return true; + for (leader_args) |la| if (std.mem.eql(u8, la.path, path[0..n])) return true; return false; } toks.reset(); @@ -2308,6 +2359,7 @@ const doc_tutor = struct { fn path(keys: []const u8) bool { for (std.enums.values(Builtin)) |b| if (leader_path.get(b)) |p| if (std.mem.startsWith(u8, p, keys)) return true; + for (leader_args) |la| if (std.mem.startsWith(u8, la.path, keys)) return true; return false; } diff --git a/src/edit.zig b/src/edit.zig index c9477c29..a06f5f2d 100644 --- a/src/edit.zig +++ b/src/edit.zig @@ -568,6 +568,26 @@ fn setEditTextSpan(p: *Pardes, t: *Text, new: []u8, known_end: ?modal.Cursor, sp return; } const pane = t.pane() orelse return retireEditText(p, new); + // A live query pane's rows are its line 1's (Query.zig): an edit there + // is refused, as a tag's prefix refuses one, and one from line 1 into + // them is cut at its end. The rows' metadata stays theirs across an + // edit of the line, which moves no row. + if (pane.file) |*f| if (pane.query) |q| if (!q.frozen) { + const kept = panes.Query.clampEdit(p, t, f.content, new) orelse return retireEditText(p, new); + if (kept.ptr != new.ptr) retireEditText(p, new); + const end = modal.positionAt(kept, kept.len - panes.File.spanOf(f.content, kept).tail); + t.last_edit = .{ .row = @intCast(end.row), .col = @intCast(end.col) }; + const rows = f.location_rows; + const spans = f.pager_spans; + f.location_rows = &.{}; + f.pager_spans = &.{}; + panes.File.setContentSpan(p, f, kept, null); + if (f.location_rows.len > 0) @import("locations.zig").freeRows(p.gpa, f.location_rows); + p.gpa.free(f.pager_spans); + f.location_rows = rows; + f.pager_spans = spans; + return; + }; // what changed ended where the texts agree again from their ends const old: []const u8, const row0: i32 = if (pane.file) |f| .{ f.content, 0 } else if (pane.ovl) |o| .{ o.text, o.row } else .{ "", 0 }; // ponytail: O(file), for the edits that do not say what they changed diff --git a/src/exec.zig b/src/exec.zig index a9c11049..2bc1a3e5 100644 --- a/src/exec.zig +++ b/src/exec.zig @@ -194,6 +194,20 @@ pub fn operandAt(p: *Pardes, pane: *Pane, clicked: Pane.Sel, borrow: bool, for_l // the look is of the address it names (look.diffAddress), a regular // look from there. A hunk line's code is words, looked at as ever: // the code's, the prefix never one of them. + // A query pane's row pointed at on its gutter (its line number): the + // look is of the row's address (Query.rowAddress), as a +Diff line's + // prefix is its place; the row's code is words, looked at as ever. + if (for_look and pane.query != null and clicked.r0 >= pane.tag_rows and clicked.r0 == clicked.r1 and clicked.c0 == clicked.c1 and row >= 0 and col >= 0) gutter: { + var address_buf: [4096 + 32]u8 = undefined; + const address = panes.Query.rowAddress(pane, @intCast(row), @intCast(col), &address_buf) orelse break :gutter; + const meta = pane.file.?.location_rows[@intCast(row)]; + result.text = p.scratch.allocator().dupe(u8, address) catch break :gutter; + result.file_word = .{ .row = row, .lo = 0, .hi = @intCast(meta.location_end) }; + const expanded = fileWordCells(pane, clicked, row, 0, @intCast(meta.location_end)) orelse return result; + result.preview = expanded; + result.expanded = expanded; + return result; + } var word_from: usize = 0; if (for_look and clicked.r0 >= pane.tag_rows and clicked.r0 == clicked.r1 and clicked.c0 == clicked.c1 and row >= 0) diff: { var address_buf: [4096 + 32]u8 = undefined; @@ -1118,6 +1132,12 @@ pub fn applySettingBuiltin(p: *Pardes, setting: config.Runtime.Setting, arg: ?[] } else if (!p.settings.apply(setting, arg)) { p.reportFailure(p.active, "CallstackDepth: takes " ++ comptime config.Runtime.takes(.callstack_depth).?); }, + .search_rows => if (arg == null) { + var said: [40]u8 = undefined; + return p.setMessage(p.active, std.fmt.bufPrint(&said, "SearchRows {d}", .{p.settings.search_rows}) catch "SearchRows"); + } else if (!p.settings.apply(setting, arg)) { + p.reportFailure(p.active, "SearchRows: takes " ++ comptime config.Runtime.takes(.search_rows).?); + }, // Bare, it says the width, as acme's Tab does. .tab => if (arg == null) { var said: [32]u8 = undefined; diff --git a/src/fs.zig b/src/fs.zig index e809eda5..cb813262 100644 --- a/src/fs.zig +++ b/src/fs.zig @@ -1119,7 +1119,7 @@ const find_max_steps = 100_000; /// One root's Find or Grep rows at most: its hits, each a path and a line. pub const search_root_output_bytes = find_max_hits * (4096 + 320); -const find_skip = [_][]const u8{ +pub const find_skip = [_][]const u8{ ".git", ".jj", "target", "node_modules", ".venv", "__pycache__", ".zig-cache", "zig-out", }; diff --git a/src/layout.zig b/src/layout.zig index f0689b10..dac0aa7e 100644 --- a/src/layout.zig +++ b/src/layout.zig @@ -1016,21 +1016,31 @@ pub fn keepGroups(p: *Pardes) void { /// False, `id` in no column, when the owner has not the rows for its tag /// and the attachment's minimum. pub fn attach(p: *Pardes, owner: usize, id: usize, rows: u16) bool { + return attachFrom(p, owner, id, rows, owner); +} + +/// attach, the rows given by `giver`: the owner itself or a pane of its +/// group (a +Preview added under a query pane later takes the text's rows, +/// so the query pane, typed into, keeps its own). +pub fn attachFrom(p: *Pardes, owner: usize, id: usize, rows: u16, giver: usize) bool { const o = p.panes[owner] orelse return false; + const g = p.panes[giver] orelse return false; const nw = p.panes[id] orelse return false; if (o.collapsed) toggleCollapse(p, owner); + if (g.collapsed) toggleCollapse(p, giver); compute(p); const f = findPane(p, owner) orelse return false; + if (giver != owner and groupRoot(p, owner) != groupRoot(p, giver)) return false; // Its tag wraps at the column's width: measured there. p.rects[id].w = p.col_w[f.col]; - const oh = p.rects[owner].h; + const oh = p.rects[giver].h; const least = minRows(p, id); if (oh < least + BOX_H) return false; - const owner_keeps = if (oh >= least + minRows(p, owner)) minRows(p, owner) else BOX_H; - const give = std.math.clamp(rows, least, oh - owner_keeps); + const giver_keeps = if (oh >= least + minRows(p, giver)) minRows(p, giver) else BOX_H; + const give = std.math.clamp(rows, least, oh - giver_keeps); snapColWeights(p, f.col); insert(p, f.col, groupEnd(p, f.col, f.idx), id); - o.vweight = @floatFromInt(oh - give); + g.vweight = @floatFromInt(oh - give); nw.vweight = @floatFromInt(give); nw.attached_to = o.serial; compute(p); diff --git a/src/look.zig b/src/look.zig index 2d97cb9f..eed3dbd9 100644 --- a/src/look.zig +++ b/src/look.zig @@ -1719,6 +1719,8 @@ pub fn reopenAt(p: *Pardes, from: usize, path: []const u8, at: Spot) void { /// Whether `pane` is the +Recent or the Jumplist list, whose rows are /// remembered places: a look at one clamps to the file as it is now. fn isRecentList(pane: *const Pane) bool { + // A query pane over the recent files: its rows are remembered places. + if (pane.query) |q| if (q.source == .recent) return true; const f = pane.file orelse return false; const o = f.output orelse return false; return std.meta.eql(o.from, panes.Output.Origin{ .cmd = .Recent }) or std.meta.eql(o.from, panes.Output.Origin{ .cmd = .Jumplist }); diff --git a/src/mouse.zig b/src/mouse.zig index ec5560d0..3400afbe 100644 --- a/src/mouse.zig +++ b/src/mouse.zig @@ -1083,6 +1083,15 @@ pub fn dispatchPointerBuiltin( // nothing, as acme's look3 and execute return on an empty expansion. const operand = text orelse return; if (gesture) |g| if (reportGesture(p, id, cmd, operand, g.on_tag, g.operand, arg)) return; + // B2 anywhere on a query pane's line 1 is the line: run again, whatever + // word of it was clicked (Query.zig). + if (gesture) |g| if (!g.on_tag and g.operand.row == 0 and cmd == config.exec_cmd) if (p.panes[id]) |pane| if (pane.query) |q| { + p.gpa.free(q.asked); + q.asked = &.{}; + q.frozen = false; + panes.Query.produceAll(p, false); + return; + }; // A middle click on a body is the exec a bound REPL may take. exec.runBuiltinFrom(p, cmd, id, "", exec.withArg(p, operand, arg), gesture != null and !gesture.?.on_tag); } diff --git a/src/ninep/ctl.zig b/src/ninep/ctl.zig index f9bec775..45336a1e 100644 --- a/src/ninep/ctl.zig +++ b/src/ninep/ctl.zig @@ -89,6 +89,8 @@ pub fn run(p: *Pardes, id: usize, exec: bool, text: []const u8, in_tag: bool) vo const after = Serials.snapshot(p); var created = false; for (after.list[0..after.len]) |serial| if (std.mem.indexOfScalar(u32, before.list[0..before.len], serial) == null) { + // A query pane's +Preview is its query pane's: that answers. + if (p.paneBySerial(serial)) |made| if (p.panes[made].?.file) |f| if (f.output) |o| if (o.from == .preview) continue; // A look that made a +Search pane (LookWord list, a terminal) // answers it: that is where the places it found are. noteResult(p, serial); @@ -555,6 +557,7 @@ fn checkBuiltin(p: *Pardes, req: Req, line: []const u8, scope: builtins.Scope) ? // Bare, it says the width, as from a pane's exec. .tab => arg.len == 0 or (std.fmt.parseInt(u16, arg, 10) catch 0) -% 1 < 16, .callstack_depth => arg.len == 0 or (std.fmt.parseInt(u8, arg, 10) catch 0) -% 1 < pardes.lsp.callstack_max_depth, + .search_rows => arg.len == 0 or (std.fmt.parseInt(u16, arg, 10) catch 0) -% 1 < 100, else => probe: { var probe = p.settings; break :probe probe.apply(setting, if (arg.len > 0) arg else null); @@ -664,6 +667,7 @@ pub fn writeSettingsOf(p: *Pardes, s: *const config.Runtime, w: *std.Io.Writer) .inactive_dim => try w.print("{s} {d}\n", .{ word, s.inactive_dim }), .grip_width => try w.print("{s} {d}\n", .{ word, s.grip_width }), .callstack_depth => try w.print("{s} {d}\n", .{ word, s.callstack_depth }), + .search_rows => try w.print("{s} {d}\n", .{ word, s.search_rows }), .tab => try w.print("{s} {d}\n", .{ word, s.tab }), } } @@ -3890,8 +3894,10 @@ test "Recent's row for a file still open is where its dot is now, not where it l pane.body.cur_col = 2; try testing.expectEqual(Status.ok, wr(p, root_exec, "Recent\n").reply.status); const rows = p.panes[p.paneBySerial(try std.fmt.parseInt(u32, std.mem.trimEnd(u8, rd(p, root_exec, 0, 64).bytes, "\n"), 10)).?].?; - var want: [4300]u8 = undefined; - try testing.expect(std.mem.indexOf(u8, rows.file.?.content, try std.fmt.bufPrint(&want, "{s}/a.txt:2:3 open\n", .{dir})) != null); + // A query pane under the file (line 1 `Recent `), its rows said from + // its directory. + try testing.expect(std.mem.startsWith(u8, rows.file.?.content, "Recent \n")); + try testing.expect(std.mem.indexOf(u8, rows.file.?.content, "\na.txt:2:3 open\n") != null); } test "a closed file is found again: Recent and /recent list it closed, a look at its row reopens it at its dot, and a jump back does too" { @@ -3924,7 +3930,8 @@ test "a closed file is found again: Recent and /recent list it closed, a look at // Recent lists it, closed, at its dot; a look at the row opens it there. try testing.expectEqual(Status.ok, wr(p, root_exec, "Recent\n").reply.status); const rows = p.panes[p.paneBySerial(try std.fmt.parseInt(u32, std.mem.trimEnd(u8, rd(p, root_exec, 0, 64).bytes, "\n"), 10)).?].?; - const at = std.mem.indexOf(u8, rows.file.?.content, try std.fmt.bufPrint(&want, "{s}:3:", .{a})).?; + // Its query pane's rows are said from its directory, a.txt's. + const at = std.mem.indexOf(u8, rows.file.?.content, "\na.txt:3:").? + 1; const row = rows.file.?.content[at..std.mem.indexOfScalarPos(u8, rows.file.?.content, at, '\n').?]; try testing.expect(std.mem.endsWith(u8, row, " (closed)")); try testing.expectEqual(Status.ok, wr(p, Node.of(rows.serial, .look), try std.fmt.bufPrint(&line, "{s}\n", .{row[0 .. row.len - " (closed)".len]})).reply.status); @@ -3939,6 +3946,9 @@ test "a closed file is found again: Recent and /recent list it closed, a look at var closed_entry = false; for (p.jumps[0..p.njumps]) |j| closed_entry = closed_entry or j.serial == 0; try testing.expect(closed_entry); + // Every entry in order (JumpScope all): which file has the focus after + // a Del is the layout's to choose, and Back keeps to it first. + p.settings.jump_scope = .all; var tries: usize = 0; while (tries < p.njumps) : (tries += 1) { p.jumpBy(-1); diff --git a/src/normal.zig b/src/normal.zig index 808ac886..ebace536 100644 --- a/src/normal.zig +++ b/src/normal.zig @@ -930,7 +930,12 @@ fn executeNormalAction(p: *Pardes, t: *Text, semantic: modal.Normal.Action) void .body, .input => tagline.enterTag(p, pane), }, .pipe_selection => |how| return p.startPrompt(pane, t, .{ .pipe = how }), - .search => return p.startPrompt(pane, &pane.body, .{ .search = config.search_marker }), + // `/` in a text is its query pane's line 1 (Query.zig); a + // terminal's still asks on the notice band. + .search => if (pane.file != null and t.what == .body) + panes.Query.open(p, p.active, .text, "", true) + else + return p.startPrompt(pane, &pane.body, .{ .search = config.search_marker }), // In a file's text, n and N step its places while they answer for // the register (Places.answersN); else helix's search of the register. .search_step => |step| if (t.what == .body and pane.file != null and pane.places.answersN(p, pane)) @@ -939,12 +944,13 @@ fn executeNormalAction(p: *Pardes, t: *Text, semantic: modal.Normal.Action) void return searchStep(p, t, text, step.direction, step.count), .search_selection => |boundary| { searchSelection(p, t, text, boundary); - // The pattern's places: the selection is already on one of them. - if (t.what == .body and pane.file != null) { + // The pattern is line 1 of this text's query pane, made or + // reused, the keyboard staying here: n and N step its places. + if (t.what == .body and pane.file != null and !pane.hasPdf() and pane.query == null) { const name = if (p.register != 0) p.register else '/'; const pat = p.registers.value(name, 0) orelse return; - const r = pane.body.primaryRange(text, 0); - pane.places.search(p, pane, .search, 0, pat, false, @min(r.anchor, r.head), false); + panes.Query.open(p, p.active, .text, pat, false); + pane.places.provenance = .search; } }, .node => |walk| return nodeSelect(p, pane, t, walk), diff --git a/src/panes.zig b/src/panes.zig index 73794b91..e0eb3fec 100644 --- a/src/panes.zig +++ b/src/panes.zig @@ -108,6 +108,9 @@ pub const Pane = struct { /// gone, or a pane no longer right under its owner's group, leaves it /// an ordinary pane (layout.keepGroups). attached_to: ?u32 = null, + /// This pane is a query pane: its line 1 the query, its rows made live + /// from a source (Query.zig, gpa-owned). + query: ?*Query = null, cols: u16, rows: u16, greet: bool = false, @@ -463,6 +466,8 @@ pub const Pane = struct { if (f.mini != null) return .source; if (std.mem.endsWith(u8, f.path, ".diff") or std.mem.endsWith(u8, f.path, ".patch") or f.pager_diff) return .diff; if (f.output != null) { + // A +Preview is a file's text: coloured as the file. + if (f.output.?.from == .preview) return .source; const tr = Output.fileTraits(f.output); if (tr.locations) return .locations; if (!tr.saves) return .none; @@ -655,6 +660,8 @@ pub const Output = @import("Output.zig"); pub const Places = @import("Places.zig"); +pub const Query = @import("Query.zig"); + pub const Dir = @import("Dir.zig"); pub const mini = @import("mini.zig"); diff --git a/src/pardes.zig b/src/pardes.zig index c4011f7d..1b4e9920 100644 --- a/src/pardes.zig +++ b/src/pardes.zig @@ -486,6 +486,8 @@ test { _ = @import("animation.zig"); _ = @import("pager.zig"); _ = @import("Places.zig"); + _ = @import("Query.zig"); + _ = @import("Names.zig"); } pub const Builtin = builtins.registry.Builtin(); @@ -4402,6 +4404,9 @@ pub const Pardes = struct { jumps: [MAX_JUMPS]Loc = undefined, njumps: usize = 0, jcur: usize = 0, + /// The next place tracked is an entry of its own however near the last + /// (a query answered: Ctrl-o goes back to where it was asked). + jump_force: bool = false, look_src: [MAX_PANES]u32 = undefined, n_look_src: usize = 0, look_walk_owner: ?u32 = null, @@ -5049,6 +5054,8 @@ pub const Pardes = struct { // to it reopen it there. p.noteClosed(pane); panes.Output.dropUnsaved(p, pane); + // A query pane's places, in whatever panes it fed, go with it. + if (pane.query != null) panes.Query.release(p, pane); if (pane.file) |*file| panes.File.leaveTwins(p, file); const watched = (if (pane.file) |f| f.output == null else false) or pane.hasPdf(); for (p.panes, 0..) |slot, id| if (slot == pane) { @@ -5084,6 +5091,11 @@ pub const Pardes = struct { pane.input.deinit(p.gpa); pane.jump.deinit(p.gpa); pane.places.deinit(p.gpa); + if (pane.query) |q| { + q.deinit(p.gpa); + p.gpa.destroy(q); + pane.query = null; + } panes.terminal.deinitEmulator(pane, p.gpa); pane.clearCwd(); pane.fs.deinit(p.gpa); @@ -6121,6 +6133,8 @@ pub const Pardes = struct { // Each pane's places find a frame's more on a tick, and on any other // step the ones an edit or a scroll left unfound in the view. for (p.panes) |slot| if (slot) |pane| pane.places.settle(p, pane, ev == .tick); + // Each live query pane's rows, made from what changed this step. + panes.Query.produceAll(p, ev == .tick); _ = p.scratch.reset(.{ .retain_with_limit = memory.limits.scratch_kept }); p.sync(); p.fsReport(); @@ -6450,6 +6464,9 @@ pub const Pardes = struct { 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 + // itself (Query.zig). + if (t == &pane.body and header == null and pane.query != null and panes.Query.key(p, p.active, key)) return; if (t.mode == .normal and p.macro.replaying == 0 and (hit(key, config.look_key) or hit(key, config.exec_key))) { // A header's words are the workspace's and column's commands, so // Enter runs them there, as the execute key does. @@ -6564,6 +6581,12 @@ pub const Pardes = struct { p.leader_keys[p.leader_n] = c; p.leader_n += 1; const pfx = p.leader_keys[0..p.leader_n]; + // A path that runs a builtin with its argument (the query pane's + // sources with no word of their own). + for (config.leader_args) |la| if (std.mem.eql(u8, la.path, pfx)) return exec.runBuiltin(p, la.cmd, p.active, "", la.arg); + for (config.leader_args) |la| if (std.mem.startsWith(u8, la.path, pfx)) { + p.leader_on = true; + }; // a path-less builtin is a row here too (it is the same index Help // reads), and SPC cannot reach one — so both scans skip it for (builtin_rows) |row| { @@ -7017,6 +7040,21 @@ pub const Pardes = struct { return; } + // 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) { + .references => .refs, + .definition => .defs, + .implementation => .impls, + .diagnostics => .diagnostics, + else => null, + }; + if (listed) |source| if (pane.file != null and pane.query == null and !p.exec_header) { + p.fs.refilled = null; + panes.Query.fillList(p, w.pane, source, rows); + p.fs.lsp_result = if (panes.Query.ofOwner(p, pane.serial)) |qid| p.panes[qid].?.serial else null; + return; + }; const dir = if (pane.file) |f| panes.Dir.ofName(f.path) else pane.cwdSlice(); // A Callstack page that stops short ends in its marker: said as a // row naming the word that shows the next page, and kept. @@ -7285,6 +7323,11 @@ pub const Pardes = struct { p.jcur = @min(cur, w -| 1); const pane = p.panes[p.active] orelse return; + // A query being typed moves the owner's selection to show, never a + // jump; its pane is no place to come back to either. + if (pane.query) |q| if (!q.frozen) return; + const force = p.jump_force; + p.jump_force = false; const now: Loc = .{ .pane = @intCast(p.active), .serial = pane.serial, @@ -7292,14 +7335,14 @@ pub const Pardes = struct { .col = if (pane.pdfPage() != null) 0 else if (pane.body.cur_pinned) @intCast(@max(0, pane.body.cur_col) + 1) else 0, .path_hash = if (recentDot(pane)) |d| std.hash.Wyhash.hash(0, d.path) else 0, }; - if (p.njumps > 0 and p.samePlace(p.jumps[p.jcur], now)) { + if (!force and p.njumps > 0 and p.samePlace(p.jumps[p.jcur], now)) { p.jumps[p.jcur] = now; // same visit; the entry IS where you are return; } // a new jump made from the middle of the list drops everything ahead of // it, the way vim's does: the future you did not take is not history. if (p.njumps > 0) p.njumps = p.jcur + 1; - if (p.njumps >= 2 and p.samePlace(p.jumps[p.njumps - 2], now)) { + if (!force and p.njumps >= 2 and p.samePlace(p.jumps[p.njumps - 2], now)) { p.jumps[p.njumps - 2] = p.jumps[p.njumps - 1]; p.jumps[p.njumps - 1] = now; p.jcur = p.njumps - 1; @@ -7588,6 +7631,7 @@ pub const Pardes = struct { if (p.chrome_animation.isActive() or p.presentation.animating()) return next; // Places still to find resume on the next frame. for (p.panes) |slot| if (slot) |pane| if (pane.places.busy(pane)) return next; + if (panes.Query.busy(p)) return next; var frames: ?u64 = null; if (p.look_hover_wait) |waiting| { const delay = config.look_preview_delay_frames orelse return next; @@ -8003,11 +8047,13 @@ test "a prompt is typed on its own line in the notice band and leaves the tag ro const tag_before = try std.testing.allocator.dupe(Cell, p.surface.tag_layers[0].cells); defer std.testing.allocator.free(tag_before); - p.update(.{ .key = .{ .cp = '/' } }); + // `s` keeps a prompt on the band (a text's `/` is its query pane's + // line 1 now, Query.zig). + p.update(.{ .key = .{ .cp = 's' } }); p.update(.{ .key = .{ .cp = 't', .text = "tw" } }); p.update(.{ .key = .{ .cp = Key.left } }); try std.testing.expect(pane.prompt == .search and pane.focus == .body); - try std.testing.expectEqualStrings(config.search_marker ++ "tw", pane.promptText().?); + try std.testing.expectEqualStrings(config.select_marker ++ "tw", pane.promptText().?); _ = frame.reset(.retain_capacity); _ = try p.render(frame.allocator()); // The tagline is exactly what it was: nothing of the prompt is in it. diff --git a/src/tagline.zig b/src/tagline.zig index e668419d..89152a3a 100644 --- a/src/tagline.zig +++ b/src/tagline.zig @@ -35,6 +35,10 @@ pub const diff_view_tail = withFileCommands(" " ++ config.diff_view_builtins_str pub const terminal_pane_tail = " " ++ config.terminal_pane_builtins_str; pub const command_pane_tail = " " ++ config.command_pane_builtins_str; pub const dir_pane_tail = " " ++ config.dir_pane_builtins_str; +/// A query pane's while its rows are made (Query.zig), and once Enter froze +/// them into text a Save keeps; Unattach leaves it where it stands. +pub const query_live_tail = " Del"; +pub const query_frozen_tail = " Save Unattach Del"; /// A file with changes it has not saved. pub fn dirty(pane: *const panes.Pane) bool { const f = pane.file orelse return false; @@ -135,6 +139,9 @@ pub fn pathPrefix(p: *const Pardes, arena: std.mem.Allocator, pane: *Pane) ![]co var idbuf: [48]u8 = undefined; return std.fmt.allocPrint(arena, "{s} {s}", .{ (try shownDir(arena, pane)), exec.replId(&idbuf, pane) }); } + // A query pane: its name and where it is among its hits, `+Search + // 3/27` (Query.zig): its owner is right above it. + if (pane.query) |q| if (pane.file) |f| if (pane.prompt != .name) return panes.Query.tagPrefix(q, arena, f.path); // Unsaved text shows on the grip, as acme's modbutton does, not as a // mark in the text: the prefix is the name alone. if (pane.file) |f| return if (pane.prompt == .name) pane.input.own orelse f.path else f.path; @@ -174,6 +181,7 @@ pub fn curTail(pane: *Pane) []const u8 { pub fn defaultTail(pane: *const Pane) []const u8 { if (comptime pdf_enabled) if (pane.pdf != null) return pdf_pane_tail; + if (pane.query) |q| return if (q.frozen) query_frozen_tail else query_live_tail; if (pane.file) |file| if (file.listing != null) return dir_pane_tail; if (pane.file) |file| if (file.pager) return if (file.pager_diff) pager_diff_pane_tail else pager_pane_tail; if (pane.file != null and pane.colorAlgo() == .diff) return diff_pane_tail; diff --git a/test/output.zig b/test/output.zig index 523e8129..8ba2f357 100644 --- a/test/output.zig +++ b/test/output.zig @@ -185,7 +185,7 @@ test "ranked choices and prose retain their supplied order" { } } -test "reference Look selects the next sorted row from the captured request and keeps navigation there" { +test "references fill the asking text's query pane: sorted under their files, the next after where it was asked current, the owner's places the refs in it" { if (!pardes.lsp.supports.contains(.references)) return error.SkipZigTest; var tmp = std.testing.tmpDir(.{}); defer tmp.cleanup(); @@ -194,53 +194,38 @@ test "reference Look selects the next sorted row from the captured request and k try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "z.zig", .data = "z\n" }); var path_buf: [256]u8 = undefined; const path = try std.fmt.bufPrint(&path_buf, ".zig-cache/tmp/{s}/m.zig", .{tmp.sub_path}); - const p = try Pardes.init(std.testing.allocator, .{ .file = path, .cols = 80, .rows = 24 }); + const p = try Pardes.init(std.testing.allocator, .{ .file = path, .cols = 80, .rows = 40 }); defer p.deinit(); - p.locations_config.layout = .@"inline"; const source = p.panes[0].?; const response = "m.zig:5:5-8 later\nz.zig:1:1 last-file\nm.zig:1:7-10 earlier\nm.zig:3:5-8 current\na.zig:1:1 first-file\nm.zig:4:5-8 next\n"; - const sorted = "a.zig:1:1 first-file\nm.zig:1:7-10 earlier\nm.zig:3:5-8 current\nm.zig:4:5-8 next\nm.zig:5:5-8 later\nz.zig:1:1 last-file\n"; source.body.cur_row = 2; source.body.cur_col = 4; p.lspRequest(0, .references, ""); const request = p.lsp_wait.?.id; + // the cursor moves before the answer: it is placed by where it was asked source.body.cur_row = 4; p.lspResponse(request, response); - const rid = source.search_pane orelse return error.MissingResults; - const results = p.panes[rid].?; - try expectResultRows(sorted, &results.file.?); - try std.testing.expectEqual(@as(usize, 0), p.active); + const qid = panes.Query.ofOwner(p, source.serial) orelse return error.MissingResults; + const results = p.panes[qid].?; + const content = results.file.?.content; + try std.testing.expect(std.mem.startsWith(u8, content, "Refs \n")); + // under their files, in order + const a_at = std.mem.indexOf(u8, content, "\na.zig\n").?; + const m_at = std.mem.indexOf(u8, content, "\nm.zig\n").?; + const z_at = std.mem.indexOf(u8, content, "\nz.zig\n").?; + try std.testing.expect(a_at < m_at and m_at < z_at); + // the owner's places are its four refs; the current the one after line 3 + try std.testing.expectEqual(@as(usize, 4), source.places.hits.items.len); + try std.testing.expectEqual(@as(?usize, 2), source.places.current); try std.testing.expectEqual(@as(i32, 3), source.body.cur_row); - try std.testing.expect(source.body.vsel.active); - try std.testing.expectEqual(@as(i32, 4), @min(source.body.cur_col, source.body.vsel.col)); - try std.testing.expectEqual(@as(i32, 7), @max(source.body.cur_col, source.body.vsel.col)); - try std.testing.expectEqual(@as(i32, 3), results.body.cur_row); - try std.testing.expectEqual(@as(usize, 3), source.search_row.?); - try std.testing.expectEqual(results.serial, p.look_walk_owner.?); - try std.testing.expectEqual(@as(i32, 3), results.look_at.?.row); - const available = p.freeSlot(); - lookKey(p, 'n'); - try std.testing.expectEqual(rid, p.active); - try std.testing.expectEqual(@as(i32, 4), results.body.cur_row); - try std.testing.expectEqual(available, p.freeSlot()); - lookKey(p, 'N'); - try std.testing.expectEqual(@as(i32, 3), results.body.cur_row); - + try std.testing.expectEqual(@as(usize, 6), results.query.?.total); + // n in the owner steps them, round the end without a word p.active = 0; - source.body.cur_row = 4; - source.body.cur_col = 4; - p.lspRequest(0, .references, ""); - p.lspResponse(p.lsp_wait.?.id, response); - try std.testing.expect(std.mem.endsWith(u8, p.panes[p.active].?.file.?.path, "/z.zig")); - try std.testing.expectEqual(@as(i32, 5), results.body.cur_row); - try std.testing.expectEqual(@as(usize, 5), source.search_row.?); - const last = p.active; - p.lspRequest(last, .references, ""); - p.lspResponse(p.lsp_wait.?.id, response); - try std.testing.expect(std.mem.endsWith(u8, p.panes[p.active].?.file.?.path, "/a.zig")); - const wrapped = p.panes[p.panes[last].?.search_pane.?].?; - try std.testing.expectEqual(@as(i32, 0), wrapped.body.cur_row); - try std.testing.expectEqual(wrapped.serial, p.look_walk_owner.?); + p.update(.{ .key = .{ .cp = 'n' } }); + try std.testing.expectEqual(@as(?usize, 3), source.places.current); + p.update(.{ .key = .{ .cp = 'n' } }); + try std.testing.expectEqual(@as(?usize, 0), source.places.current); + try std.testing.expectEqual(@as(usize, 0), p.active); } test "location sorting leaves mixed prose alone and preserves newline shape" { -- cgit v1.3 From 1af098381515fbe3a4fe678cd023c7fd74418ae1 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Sat, 24 Oct 2026 12:43:02 -0300 Subject: Search converge 5/6: the old search pipeline phased out, the notice-band / for texts, Find/Grep prompts and walks on the loop, +Recent, n/N as Look-the-next-row; docs, tutor, Help and goldens to the query pane --- docs/helix-keys.md | 8 +- docs/typ/builtins-gui.json | 2 +- docs/typ/builtins-tty.json | 2 +- docs/typ/cheatsheet.typ | 6 +- docs/typ/guide.typ | 46 +++++- docs/typ/reference.typ | 28 ++-- src/Output.zig | 31 ++-- src/Query.zig | 176 +++++++++++++++------ src/builtins.zig | 41 ++--- src/config.zig | 7 +- src/fs.zig | 285 +---------------------------------- src/look.zig | 83 ++-------- src/ninep/ctl.zig | 50 +++--- src/normal.zig | 28 ++-- src/tagline.zig | 1 + src/tutor.txt | 16 +- test/output.zig | 9 ++ test/pdf.zig | 4 +- test/snapshots/builtins.snap | 23 +++ test/snapshots/dump.golden | 3 + test/snapshots/find.golden | 146 +++++++----------- test/snapshots/find.snap | 126 +++++----------- test/snapshots/fsearch.golden | 111 +++++++------- test/snapshots/fsearch.snap | 63 +++----- test/snapshots/grep.golden | 44 +++--- test/snapshots/grep.snap | 91 +++-------- test/snapshots/lookrange.golden | 47 +++--- test/snapshots/lookrange.snap | 22 ++- test/snapshots/lsp-client.golden | 23 +-- test/snapshots/lsp-client.snap | 11 +- test/snapshots/lspdebug.snap | 7 +- test/snapshots/lsprelpath.golden | 170 ++++++++++++--------- test/snapshots/lsprelpath.snap | 35 ++--- test/snapshots/msg.golden | 4 +- test/snapshots/msg.snap | 2 +- test/snapshots/stepgrain.golden | 123 ++++++++------- test/snapshots/stepgrain.snap | 59 ++------ test/snapshots/tagbottom.golden | 13 +- test/snapshots/tagbottomshort.golden | 38 ++--- test/snapshots/topbarexec.golden | 22 ++- 40 files changed, 858 insertions(+), 1148 deletions(-) (limited to 'src/Output.zig') diff --git a/docs/helix-keys.md b/docs/helix-keys.md index 8155685f..fa06c9a6 100644 --- a/docs/helix-keys.md +++ b/docs/helix-keys.md @@ -134,14 +134,14 @@ language-backend queries, and the shell pipe. | `Space` (normal, body) | starts the pardes LEADER: a key path runs the same builtin words used by tags and the topbar. The main groups are `f` files, `h` docs, `c` columns, `t` toggles/effects, `a` panel animations, `s` session, `j` jumps, `l` language, and `w` directional focus; `SPC ?` lists every path and ` ?` lists one group in `+Help`. Neither `Exit` (quits the editor, acme's Exit) nor `Kill` (stops the commands pardes typed into terminals, acme's Kill) has a leader path: both are the topbar's and the root `ctl`'s. The pending path appears on the active pane's transient body/message row. Esc or an unmapped key abandons it. Paths, Help rows, and dispatch are all generated from the builtin registry at comptime; the leader applies only to a BODY in normal mode because tags and tty programs own their input | pardes-specific; helix spends Space on pickers/LSP (section C), while pardes uses acme-style executable words | | `SPC y` `SPC Y` `SPC p` `SPC P` `SPC R` | helix's clipboard menu on helix's own letters: yank the selection to the system clipboard (`ClipYank`) or the PRIMARY selection alone (`ClipYankMain`), paste the system clipboard after (`ClipPaste`) / before (`ClipPasteBefore`) the selection, replace the selection with it (`ClipReplace`) | the same as `"+y`, `"+p`, `"+P`, `"+R`: register `+` (and `*`) IS the desktop's clipboard, the only register that reaches it. `SPC y` writes `+` alone, as helix's does, not the default register too. Builtins rather than bare chords because a leader path names a builtin: they land in Help's index and are executable words like every other verb. The clipboard holds one text, so N values go out joined by newlines, as helix sends them. On a tty the write is OSC 52 out and the READ is OSC 52 back, which many terminals refuse or gate — so `SPC y` works there and `SPC p` can be a no-op | out of corpus | | a paste from the OUTER terminal | one `Event.paste`, spliced in at the cursor | the tty shell enables bracketed paste and coalesces `paste_start`..`paste_end` into a single event; before that the bytes arrived as individual key presses and normal mode RAN them, which is how a pasted `d` deleted a line. The bytes deliberately never enter the yank register — clipboard and default register are separate stores in both directions | pardes-specific | -| `/` (any pane) | pardes' own plain-substring search into a `+Search` output buffer: the pattern is typed on a line of its own on the pane's notice band, Enter fills the buffer, and its rows are ordinary look targets. Enter also goes to the first row using `Pardes.lookFirstHit`, so `/foo` lands on the first hit with the matched span selected. A pattern that matched nothing opens its empty buffer and moves nothing | kept as-is; not in the corpus (helix `/` is regex search). Find and Grep answer with other files and deliberately do not jump. `LookNext` / `LookPrev` select subsequent result rows | pardes-specific | -| `n` / `N` | next / previous regex match in the current text, using the last search register; counts repeat and ends wrap | only the primary selection is replaced; in select mode each match is added and becomes primary. Named registers work. `*` sets the pattern from selections with word boundaries, `Alt-*` without. The former Look ring is `LookNext` / `LookPrev`, `SPC j n` / `SPC j p`. The change is bookmarked `pardes-nN-helix`; its predecessor is `pardes-nN-before-helix`. PDFs retain their location-result navigation | helix-verified | +| `/` (a text) | a query pane under the pane (`src/Query.zig`): a `+Search` whose line 1 is the query, typed into; helix's regex with smart case, every match tinted and ticked on the rail as you type (the pane's places, `src/Places.zig`), the first after the cursor selected (helix's incremental preview). `Ctrl-n`/`Ctrl-p` step while typing; Enter lands, fills `/` and keeps the rows as text; Esc while typing restores the text and closes the pane. Line 1's first word names the source (`/`, `Find`, `Grep`, `Recent`, `Panes`, `Symbols`, `All`, `Refs`, `Def`, `Impl`, `Diagnostics`), helix's pickers as one pane. A terminal's and a PDF's `/` keep the notice-band prompt and its `+Search` | helix's `/` semantics (regex, smart case, preview); the pane is pardes' | pardes-specific | +| `n` / `N` | next / previous match of the text's places when a query pane fed them (a `/`, a list's places in this text: refs, diagnostics, a Grep's hits), round the ends without a message; else the last search register's regex in the current text, as before; counts repeat | only the primary selection is replaced; in select mode each match is added and becomes primary. Named registers work. `*` sets the pattern from selections with word boundaries (`Alt-*` without) and seeds the text's query pane with it, the keyboard staying. The former Look ring is `LookNext` / `LookPrev`, `SPC j n` / `SPC j p`. PDFs retain their location-result navigation | helix-verified | | insert: printable text | file: real edit; terminal: typed run splice | | helix-verified (file) | | insert: `Enter` | newline; keeps the current full indent levels and adds one 4-space logical tab when the text before the cursor ends in `(`, `[`, `{`, or `)` (including `})`) | plain lines match `insert_newline`; delimiter heuristic is pardes-specific | helix-verified (plain) / pardes-specific (delimiter) | | insert: `Backspace` (+ `Shift-Backspace`) | delete prev char, joins lines at col 0; in a line's leading blanks, back to the previous 4-column indent stop (a whole unit when on one; a tab still goes alone) | matches `delete_char_backward` and its dedent; `Ctrl-h` alias in B | helix-verified | | insert: `Up` `Down` `Left` `Right` | move cursor | matches helix's "not recommended" insert arrows | helix-verified | -| `gd` `gD` `gy` `gi` `gr` | LSP definition / declaration / type-definition / implementation / references. One answer jumps straight there; several fill `+Search`, where `LookNext` / `LookPrev` walk and Enter opens | Ctrl+left-click is the mouse spelling of `gd`; language support depends on the configured backend | out of corpus | +| `gd` `gD` `gy` `gi` `gr` | LSP definition / declaration / type-definition / implementation / references. One answer jumps straight there; several (definition, implementation, references) fill the text's query pane, line 1 `Def`/`Impl`/`Refs`, their places in the text tinted and stepped by `n`/`N`; the others fill `+Search`, where `LookNext` / `LookPrev` walk and Enter opens | Ctrl+left-click is the mouse spelling of `gd`; language support depends on the configured backend | out of corpus | | `]d` `[d` / `]D` `[D` | step the diagnostics list / go to its last or first; if no list is up, asking the backend for one is part of the press | | out of corpus | | `=` | `format_selections` — writes a `- old` / `+ new` diff into `+Lsp` | deliberate divergence: the seam returns ROWS, not edits, so this SHOWS the formatting instead of applying it. Not in the corpus, so there is no waiver to name — the query leaves the core as an effect the headless harness has no shell to perform | out of corpus | | `Ctrl-o` / `Ctrl-i` | jumplist back / forward (also Mouse4 / Mouse5 in SDL, macOS and web); successful navigation clears selections in both panes and places the cursor at the saved location; raw tty forwards both to the child — the `Back` / `Forward` builtins, also on `SPC j o` / `SPC j i`, with `SPC j l` rendering the stack as a buffer; a closed file's entry stays, marked `(closed)`, and a jump to it opens the file again at its place | helix binds both keys (`jump_backward` / `jump_forward`) but to a POSITION jumplist; pardes' stack is over panes and focus, so the keys agree and the semantics do not. `Ctrl-i` and Tab are the same byte under the legacy encoding; there Tab keeps meaning execute, and the pair only separates where the host speaks the kitty keyboard protocol | pardes-specific | @@ -353,7 +353,7 @@ text. | Key(s) | Helix behavior | Reason | | --- | --- | --- | -| `?` | reverse search prompt | pardes keeps its own `/` plain substring search into an output buffer. `*`, `Alt-*` and search-repeat `n`/`N` are implemented and verified above | +| `?` | reverse search prompt | pardes' `/` is a query pane (above); `N` steps backward. `*`, `Alt-*` and search-repeat `n`/`N` are implemented and verified above | | `Space` mode: `f F e . b j g G ' w c C Alt-c / ?` | pickers, global search, palette | pickers and the command palette do not exist here — but the KEY is taken: pardes' own leader runs the acme builtins (section A). Two halves of helix's space mode DO exist and are in section A: the clipboard menu (`y Y p P R`, helix's letters on helix's leader) and the LSP menu, moved one prefix deeper to `SPC l k/r/a/h/s/S/d/D` because `d`, `k`, `s` and `h` were already pardes' most-pressed keys | | Popup `Ctrl-u`/`Ctrl-d`, Completion menu, Signature help tables | LSP popups | LSP | | Picker table (all rows), Prompt table (all rows) | picker / prompt internals | pickers — pardes' tag line is its own one-line editor | diff --git a/docs/typ/builtins-gui.json b/docs/typ/builtins-gui.json index c238955c..88c9d864 100644 --- a/docs/typ/builtins-gui.json +++ b/docs/typ/builtins-gui.json @@ -51,7 +51,7 @@ {"name": "Forward", "leader": "SPC j i", "also": ["C-i"], "arg": false, "scope": "root", "setting": false, "choices": null, "doc": "Ctrl-i: one step forward again, up to wherever Back started."}, {"name": "Get", "leader": null, "also": [], "arg": true, "scope": "pane", "setting": false, "choices": null, "doc": "acme's Get: the pane's file read again, its unsaved edits refused once as Del refuses them."}, {"name": "Grain", "leader": null, "also": [], "arg": true, "scope": "root", "setting": true, "choices": "on, off, 0-3", "doc": "The page takes a fine, still grain, like paper: a level, 0 (off) through 3."}, - {"name": "Grep", "leader": "SPC f g", "also": ["topbar"], "arg": true, "scope": "pane", "setting": false, "choices": null, "doc": "Find's sibling: Find matches file NAMES under this pane's directory, Grep matches file CONTENTS under every pane's directory at once."}, + {"name": "Grep", "leader": "SPC f g", "also": ["topbar"], "arg": true, "scope": "pane", "setting": false, "choices": null, "doc": "Find's sibling: Find matches file NAMES under this pane's directory, Grep matches the LINES of those files, on the disk engine's worker."}, {"name": "GripWidth", "leader": null, "also": [], "arg": true, "scope": "root", "setting": true, "choices": null, "doc": "The grip and scrollbar width, as a percent of the theme's rail."}, {"name": "Help", "leader": "SPC ?", "also": ["topbar"], "arg": false, "scope": "root", "setting": false, "choices": null, "doc": "Open the help: every key and every builtin."}, {"name": "Hover", "leader": "SPC l k", "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Ask the language server about the symbol under the cursor."}, diff --git a/docs/typ/builtins-tty.json b/docs/typ/builtins-tty.json index 791eef63..01ae6bc5 100644 --- a/docs/typ/builtins-tty.json +++ b/docs/typ/builtins-tty.json @@ -45,7 +45,7 @@ {"name": "FocusTint", "leader": null, "also": [], "arg": true, "scope": "root", "setting": true, "choices": "on, off", "doc": "The focused pane's and column's tags are tinted, on or off."}, {"name": "Forward", "leader": "SPC j i", "also": ["C-i"], "arg": false, "scope": "root", "setting": false, "choices": null, "doc": "Ctrl-i: one step forward again, up to wherever Back started."}, {"name": "Get", "leader": null, "also": [], "arg": true, "scope": "pane", "setting": false, "choices": null, "doc": "acme's Get: the pane's file read again, its unsaved edits refused once as Del refuses them."}, - {"name": "Grep", "leader": "SPC f g", "also": ["topbar"], "arg": true, "scope": "pane", "setting": false, "choices": null, "doc": "Find's sibling: Find matches file NAMES under this pane's directory, Grep matches file CONTENTS under every pane's directory at once."}, + {"name": "Grep", "leader": "SPC f g", "also": ["topbar"], "arg": true, "scope": "pane", "setting": false, "choices": null, "doc": "Find's sibling: Find matches file NAMES under this pane's directory, Grep matches the LINES of those files, on the disk engine's worker."}, {"name": "Help", "leader": "SPC ?", "also": ["topbar"], "arg": false, "scope": "root", "setting": false, "choices": null, "doc": "Open the help: every key and every builtin."}, {"name": "Hover", "leader": "SPC l k", "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Ask the language server about the symbol under the cursor."}, {"name": "InactiveDim", "leader": null, "also": [], "arg": true, "scope": "root", "setting": true, "choices": null, "doc": "Fade the unfocused panes' text by a percentage, 0 through 100, 0 off."}, diff --git a/docs/typ/cheatsheet.typ b/docs/typ/cheatsheet.typ index 7b140a04..76f4b866 100644 --- a/docs/typ/cheatsheet.typ +++ b/docs/typ/cheatsheet.typ @@ -59,7 +59,7 @@ Helix-style: motions *select*, then an edit acts on the selection. Mode box: bla [#keys("i", "a", "I", "A", "o", "O")], [insert; #key("Esc") back to normal], [#keys("s", "S")], [regex: a cursor per match, split], [#keys("C", ",")], [cursor on next line; keep primary], - [#keys("/", "n", "N")], [search, next, previous], + [#keys("/", "n", "N")], [search (a query pane), next, previous], [#keys("m i", "m m")], [textobject, matching bracket], [#key("|")], [pipe each selection through the shell], [#keys("g d", "g r")], [definition, references (language server)], @@ -87,6 +87,8 @@ Helix-style: motions *select*, then an edit acts on the selection. Mode box: bla key("SPC f f"), word("Find"), key("SPC f g"), word("Grep"), key("SPC f r"), word("Recent"), + key("SPC b b"), word("Panes"), + key("SPC s s"), [declarations], key("SPC f c"), word("Config"), key("SPC d"), word("Del"), key("SPC n t"), word("Tty"), @@ -119,7 +121,7 @@ Helix-style: motions *select*, then an edit acts on the selection. Mode box: bla `git diff` output is a diff: #btn("B3") on a file line, an `@@` or a line's `+`/`-` jumps there. #doc("tags", section: "reviewing-diffs") == Finding things -- #word("Find") `name`, #word("Grep") `text` (literal): a `+Search` listing. #word("Recent"): files lately. #word("Help"), #word("Tutor"). +- A query pane under the pane: line 1 the query, its first word the source: `/pat`, `Find name` (fuzzy), `Grep text` (literal), `Recent`, `Panes`, `Symbols`, `All`. #keys("Ctrl-n", "Ctrl-p") step, #key("Enter") lands and keeps the rows, #key("Esc") puts things back. #word("Help"), #word("Tutor"). == Sessions `pardes --detach=work`; `--attach=work` or #word("Attach") `work`; #word("Detach") leaves it running. #doc("detached") diff --git a/docs/typ/guide.typ b/docs/typ/guide.typ index e60b4231..65c7334d 100644 --- a/docs/typ/guide.typ +++ b/docs/typ/guide.typ @@ -20,9 +20,9 @@ [the session's directory], [where pardes started, or the directory `pardes DIR` named; workspace and column tags run there], [active column], [where the next new pane goes (below)], [command pane], [a terminal that runs one command line and shows its output], - [`+` names], [panes pardes makes, named in their directory: `+New` a scratch (text with no file yet), `+Search` a listing of places, `+Pager` paged text, `+Errors` output, `+Unsaved` the panes holding unsaved text], + [`+` names], [panes pardes makes, named in their directory: `+New` a scratch (text with no file yet), `+Search` a query pane or a listing of places, `+Pager` paged text, `+Errors` output, `+Unsaved` the panes holding unsaved text], [serial], [a pane's number, never reused: the `3` in `@p3:12` and in 9P paths], - [message row], [the line where pardes says what happened, and asks: answer a prompt (a search, #word("Save")'s path) with #key("Enter"), cancel it with #key("Esc")], + [message row], [the line where pardes says what happened, and asks: answer a prompt (#key("s")'s regex, #word("Save")'s path) with #key("Enter"), cancel it with #key("Esc")], ) = Modes @@ -166,11 +166,45 @@ on the cheatsheet. A relative path is found in the directory of the pane the #word("Look") came from, then of each pane on the jump list, most recent first. += Search + +#key("/") opens a query pane under the pane: a `+Search` whose first line +is the query, typed into, and whose rows are what it finds, made again at +each key. It takes its rows from the pane it searches and from no other, +is born #word("SearchRows") rows tall and never resizes itself; nothing +found is a count of `0` in its tag, not an exit. + #pairs( - [#key("/") `TODO` #key("Enter")], [a `+Search` of the lines holding `TODO`, the cursor on the first; #keys("n", "N") select the next or previous match], - [#word("Find") `conf`], [a `+Search` of the files below the pane's directory with `conf` in their names], - [#word("Grep") `TODO`], [a `+Search` of the lines holding `TODO`, literally, under every pane's directory], + [#key("/") `vw`], [every match in the text tinted and ticked on its scroll rail, the first after the cursor selected; the rows under line 1 are the lines holding it, a line number in the gutter, each under the declaration it is in], + [#keys("Ctrl-n", "Ctrl-p")], [the next or previous match, typing; the text follows it], + [#key("Enter")], [the keyboard on the match, the pattern in `/`, the rows kept as text (#word("Save") keeps them as a file)], + [#keys("n", "N")], [the next or previous match in the text, round the end without a word], + [#key("Esc")], [typing: the text as it was, the query pane closed], + [#key("*")], [the selection as line 1, the keyboard staying in the text], ) + +Line 1's first word names what it searches, and editing the word changes it: + +#pairs( + [`/pat`], [the pane's own text: a regex, any case unless it has a capital (#key("/"))], + [`Find name`], [the files below the pane's directory, by a fuzzy match of their names (#key("SPC f f"), #word("Find"))], + [`Grep text`], [the lines of those files holding `text`, literally (#key("SPC f g"), #word("Grep")); past 2000 lines #word("More") goes on], + [`Recent name`], [the files opened lately (#key("SPC f r"), #word("Recent"))], + [`Panes name`], [the open panes (#key("SPC b b"), #word("Panes"))], + [`Symbols name`], [the text's declarations (#key("SPC s s"))], + [`All pat`], [every open pane's text, its rows under each pane (#key("SPC /"))], + [`Refs`, `Def`, `Impl`, `Diagnostics`], [the language server's lists; their places in the text tinted as a `/`'s are, `]d` stepping the diagnostics], +) + +A row in a file no pane shows is shown in a `+Preview` under the query +pane, following #keys("Ctrl-n", "Ctrl-p") and #btn("B1"), never the +pointer; #key("Enter") makes the preview that file's pane where it stands. +#btn("B3") on a row's line number looks at the row; #btn("B2") on line 1 +runs it again. The next search from the same pane reuses its query pane, +its kept rows back on #key("Esc") (#word("SearchPane") `new`: a pane each; +#word("SearchPlace") `column`: in a finder column at the right). A PDF's +and a terminal's #key("/") still ask on the message row and list a +`+Search`. #clip("search") = Unsaved panes @@ -281,7 +315,7 @@ refusals and `--nested` are in the reference. [#key("w") #key("d")], [select a word, delete it: motions select, edits act on the selection], [#key("x"), #key("v"), #key(";")], [select the line; extend; collapse to the cursor], [#key("s")], [a cursor per regex match; every edit acts at each], - [#key("/"), #keys("n", "N")], [substring search; repeat the search in the current text, wrapping at the ends], + [#key("/"), #keys("n", "N")], [search the text in a query pane (#link()[Search]); step its matches, round the ends], [#keys("SPC j n", "SPC j p")], [#word("LookNext") / #word("LookPrev"): select locations across panes; #key("Enter") opens one], [#key("g l")], [line end], [`12G`], [line 12; a bare #key("G") does nothing], diff --git a/docs/typ/reference.typ b/docs/typ/reference.typ index c14ad659..386b9f0f 100644 --- a/docs/typ/reference.typ +++ b/docs/typ/reference.typ @@ -909,7 +909,8 @@ at 200, ending in `…`. Control characters become spaces. pane from the root). - #file("/recent"): up to 200 files, PDFs and images, most recent first, `open ` or `closed `; kept in `$XDG_STATE_HOME/pardes/recent`. - #word("Recent") shows them in a pane, an open one at its dot now and a + #word("Recent") lists them in a query pane (line 1 `Recent`, the rest + narrowing them by a fuzzy match), an open one at its dot now and a closed one at its last (a PDF's is its page); a #word("Look") of a row reopens it there. - #file("/status"): `pid`, `version`, `panes`. @@ -972,15 +973,22 @@ one a #file("exec") open still holds is never reused. In a command pane, #key("n = Find and Grep -#word("Find") matches file names, #word("Grep") the text of lines, both literally and -ignoring ASCII case. #word("Grep") reads whole files and stops at 512 -hits, #word("Find") at 512 names. The walk stops at 20000 files or 100000 entries, -16 deep, and passes over `.git`, `.jj`, `target`, `node_modules`, -`.venv`, `__pycache__`, `.zig-cache` and `zig-out`. A cap hit, or a -directory it could not open, is said at the end: `cut at 512 hits`, `walk cut at N entries`, `N -directories skipped: permission denied`. A search that finds nothing and -skipped nothing fails, `Grep: text not found`, and leaves the `+Search` as -it was. +Both fill the asking pane's query pane (#doc("guide", section: "search")), +line 1 `Find name` or `Grep text`, and run on a worker thread, never on +the loop that draws: `rg` when it is on `PATH` (`rg --files` and `rg --json +--fixed-strings --smart-case`, so `.gitignore` is honoured and hidden files +are passed over), else pardes's own walk, sorted, 16 deep, passing over +dot-directories, `.git`, `.jj`, `target`, `node_modules`, `.venv`, +`__pycache__`, `.zig-cache` and `zig-out`. #word("Find") lists the files once +and matches their names fuzzily at each key (the best first, 200 shown); +#word("Grep") matches the text of lines literally, any case unless the text +has a capital, once the typing pauses (80 ms), and stops at 2000 lines: +#word("More") (in the query pane's tag) goes on for 2000 more. A directory the +walk could not open is said under the rows: `N directories skipped: +permission denied`. A new query cancels the last; rows of a query no +longer asked never land. Written to #file("exec") (a script) the search runs +to its end before the write is answered, and one that finds nothing fails, +`Grep: text not found`, `Find: name not found`, its query pane's count `0`. = On screen diff --git a/src/Output.zig b/src/Output.zig index 1e62b04a..01e3e0f1 100644 --- a/src/Output.zig +++ b/src/Output.zig @@ -857,15 +857,6 @@ pub fn dropUnsaved(p: *Pardes, gone: *const Pane) void { } } -/// Recent: the one +Recent, filled again when it is there (as Find and -/// Grep's +Search is), else opened below the asking pane. -pub fn openRecent(p: *Pardes, id: usize) !void { - var out: std.Io.Writer.Allocating = .init(p.gpa); - errdefer out.deinit(); - try recentText(p, &out.writer, true); - try refillOrOpen(p, id, .{ .cmd = .Recent }, try out.toOwnedSlice()); -} - /// The one stepped output from `from`, filled again with `content` when it /// is there (Recent, Jumplist), or opened when it is not. fn refillOrOpen(p: *Pardes, id: usize, from: Origin, content: []u8) !void { @@ -971,6 +962,28 @@ fn helpContent(gpa: std.mem.Allocator, prefix: []const u8) ![]u8 { } if (show_calls_help) try w.writeAll(calls_help); if (prefix.len == 0) try w.writeAll(language_footer); + // The paths that run a builtin with a word (config.leader_args), and how + // a query pane is driven: under SPC f, b, s and in the whole listing. + const search_group = for (config.leader_args) |la| { + if (std.mem.startsWith(u8, la.path, prefix)) break true; + } else std.mem.eql(u8, prefix, "f"); + if (prefix.len == 0 or search_group) { + try w.writeAll("\nsearch: a query pane under the text,\nits line 1 the query, its first word\nthe source (/ Find Grep Recent Panes\nSymbols All Refs Def Impl Diagnostics)\n"); + for (config.leader_args) |la| { + if (!std.mem.startsWith(u8, la.path, prefix)) continue; + var keys: [16]u8 = @splat(' '); + for (la.path, 0..) |c, i| keys[2 * i] = c; + try w.print("{s} {s} {s}\n", .{ keys[0..8], @tagName(la.cmd), la.arg }); + } + if (prefix.len == 0) try w.writeAll( + "/ * the text (* seeds it)\n" ++ + "C-n C-p Up Down step, typing on line 1\n" ++ + "n N step the text's places\n" ++ + "Enter land there, keep the rows\n" ++ + "Esc put every view back\n" ++ + "More a Grep past 2000 lines\n", + ); + } return out.toOwnedSlice(); } diff --git a/src/Query.zig b/src/Query.zig index 48378a18..3a75a7f5 100644 --- a/src/Query.zig +++ b/src/Query.zig @@ -153,8 +153,10 @@ window: struct { lo: usize = 0, hi: usize = 0 } = .{}, /// made every third, the frame's time going to the finding. waited: u8 = 0, names: Names = .{}, -/// A Grep's lines, as the disk engine sends them (Stream.zig, `take`). +/// A Grep's lines, as the disk engine sends them (Stream.zig, `take`), and +/// the current one's index among them. found: std.ArrayList(Found) = .empty, +grep_at: usize = 0, found_bytes: std.ArrayList(u8) = .empty, grep_gen: u32 = 0, /// The language server's rows for Refs, Def, Impl, Diagnostics, as it gave @@ -256,6 +258,10 @@ pub fn open(p: *Pardes, from: usize, source: Source, arg: []const u8, focus: boo File.setContent(p, f, new); q.reset(p); if (rp.collapsed) layout.toggleCollapse(p, id); + // A source that previews gets its +Preview now, at the key that + // asked, not under the typing later. + if (previews(source) and previewOf(p, id) == null) + _ = makePreview(p, id, @max(pardes.BOX_H, rp.tag_rows) + p.settings.search_rows, layout.groupRoot(p, id)); } else { if (existing) |old| { // SearchPane new: the last one stays where it is, a result of @@ -297,8 +303,20 @@ fn create(p: *Pardes, owner_id: usize, line: []const u8, source: Source) ?usize const body: u16 = 1 + p.settings.search_rows; const tag = @max(pardes.BOX_H, np.tag_rows); const with_preview = previews(source); - // The preview, made right after, takes its own rows from the owner. - const want = tag + body; + // The preview, made right after, takes its own rows from the owner: + // when the owner has not the rows for both, they share what it has, so + // the group is whole from the first key and nothing moves later. + var want: u16 = tag + body; + var preview_rows: u16 = tag + p.settings.search_rows; + if (with_preview) { + layout.compute(p); + const spare = p.rects[owner_id].h -| layout.minRows(p, owner_id); + if (spare < want + preview_rows) { + const both = want + preview_rows; + want = @max(tag + 2, @as(u16, @intCast(@as(u32, spare) * want / both))); + preview_rows = spare -| want; + } + } if (p.settings.search_place == .column) { // The finder column (phase 6): until it exists, under the owner. if (!layout.attach(p, owner_id, free, want)) exec.placeNew(p, owner_id, owner_id, free, .doc); @@ -307,7 +325,7 @@ fn create(p: *Pardes, owner_id: usize, line: []const u8, source: Source) ?usize // new pane is, the one place a search moves another pane. exec.placeNew(p, owner_id, owner_id, free, .doc); } - if (with_preview) _ = makePreview(p, free); + if (with_preview) _ = makePreview(p, free, preview_rows, owner_id); return free; } @@ -495,9 +513,14 @@ fn produce(p: *Pardes, id: usize, tick: bool) void { q.found.clearRetainingCapacity(); q.found_bytes.clearRetainingCapacity(); q.grep_gen +%= 1; + q.grep_at = 0; q.current = null; // On the disk engine's worker, once the typing pauses. - if (a.pat.len > 0) Stream.query(p, rp.serial, .grep, a.pat, dir, .typed) else if (p.stream.target == rp.serial) { + // A script's (a 9P write): run to its end before it answers. + if (a.pat.len > 0) { + Stream.query(p, rp.serial, .grep, a.pat, dir, if (p.fs.serving) .now else .typed); + if (p.fs.serving) Stream.step(p); + } else if (p.stream.target == rp.serial) { _ = p.stream.stop(); } feedGrepPlaces(p, q, rp.serial, a.pat); @@ -548,7 +571,10 @@ fn startSource(p: *Pardes, id: usize, q: *Query, source: Source, owner_id: ?usiz switch (source) { // The files under the directory, listed once on the disk engine's // worker (rg --files, else the walk); each keystroke scores them. - .find => Stream.query(p, rp.serial, .files, "", dir, .now), + .find => { + Stream.query(p, rp.serial, .files, "", dir, .now); + if (p.fs.serving) Stream.step(p); + }, .recent => { var out: std.Io.Writer.Allocating = .init(gpa); defer out.deinit(); @@ -828,7 +854,9 @@ fn makeTextRows(p: *Pardes, id: usize, oid: usize, full: bool) !void { // Grouped once a parse of the text exists: asked of the worker now. if (ownerDecls(p, &owner.file.?, false) == null) Stream.parseFor(p, oid); const at = set.current orelse (if (set.seek) |s| Places.firstFrom(set.hits.items, s) else 0); - const from = if (full) 0 else at -| live_rows / 2; + // While typed, a window of rows from just before the current place, so + // it sits under line 1. + const from = if (full) 0 else at -| 2; q.window = .{ .lo = from, .hi = from }; if (set.started and set.from == rp.serial) { if (from > 0) { @@ -856,7 +884,9 @@ fn showPlacesCurrent(p: *Pardes, id: usize) void { const owner = p.panes[p.paneBySerial(q.owner) orelse return].?; const set = &owner.places; q.total = if (set.from == rp.serial) set.hits.items.len else 0; - q.more = q.more or (set.from == rp.serial and !set.complete()); + // still counting: the places not all found yet (the rows' own cut is + // said in a row of theirs) + q.more = set.from == rp.serial and !set.complete(); q.k = if (set.current) |c| c + 1 else 0; if (set.from != rp.serial) q.k = 0; q.current = null; @@ -995,6 +1025,7 @@ fn makeNameRows(p: *Pardes, id: usize, pat: []const u8) !void { } } if (q.names.hits.items.len > shown) try noteRow(p, q, &out, &rows, " ... and more: type more of the name"); + if (q.source == .find) try skippedRow(p, q, rp, &out, &rows); setRows(p, rp, &out, &rows); const f = &rp.file.?; f.pager_spans = spans.toOwnedSlice(p.gpa) catch &.{}; @@ -1004,7 +1035,7 @@ fn makeNameRows(p: *Pardes, id: usize, pat: []const u8) !void { q.current = if (shown > 0) 0 else null; countCurrent(q); showCurrent(rp); - showTarget(p, id); + if (q.current == null) blankPreview(p, id) else showTarget(p, id); } /// A Grep keeps this many lines: the rest wait (the disk engine's `More`). @@ -1016,14 +1047,14 @@ fn makeGrepRows(p: *Pardes, id: usize, full: bool) !void { const rp = p.panes[id].?; const q = rp.query.?; const dir = std.fs.path.dirname(rp.file.?.path) orelse "/"; - const at: usize = if (q.current) |c| (if (c < q.items.items.len) q.items.items[c].hit else 0) else 0; + const at: usize = @min(q.grep_at, q.found.items.len -| 1); q.items.clearRetainingCapacity(); var out: std.ArrayList(u8) = .empty; defer out.deinit(p.gpa); var rows: std.ArrayList(locations.Row) = .empty; var last_path: []const u8 = ""; var pathbuf: [4096 + 8]u8 = undefined; - const lo = if (full) 0 else at -| live_rows / 2; + const lo = if (full) 0 else at -| 2; const hi = if (full) q.found.items.len else @min(q.found.items.len, lo + live_rows); if (lo > 0) { var hb: [64]u8 = undefined; @@ -1048,12 +1079,23 @@ fn makeGrepRows(p: *Pardes, id: usize, full: bool) !void { try noteRow(p, q, &out, &rows, std.fmt.bufPrint(&hb, " ... {d} lines after these", .{q.found.items.len - hi}) catch " ..."); } if (p.stream.target == rp.serial and p.stream.state == .capped) try noteRow(p, q, &out, &rows, " ... stopped at 2000 lines: More in the tag goes on"); + try skippedRow(p, q, rp, &out, &rows); setRows(p, rp, &out, &rows); q.total = q.found.items.len; q.more = p.stream.busyFor(rp.serial); q.current = current orelse firstHit(q); countGrepCurrent(q); showCurrent(rp); + if (q.current == null) blankPreview(p, id); +} + +/// What the disk walk passed over, said under the rows: a search that +/// found nothing where it could not look says so, never just nothing. +fn skippedRow(p: *Pardes, q: *Query, rp: *Pane, out: *std.ArrayList(u8), rows: *std.ArrayList(locations.Row)) !void { + const n = p.stream.skipped; + if (p.stream.target != rp.serial or n == 0) return; + var hb: [96]u8 = undefined; + try noteRow(p, q, out, rows, std.fmt.bufPrint(&hb, " {d} director{s} skipped: permission denied", .{ n, if (n == 1) "y" else "ies" }) catch " directories skipped"); } /// `k` for a Grep: the current row's line among all the lines sent. @@ -1128,7 +1170,9 @@ pub fn fillList(p: *Pardes, owner_id: usize, source: Source, rows: []const u8) v const line = lineOne(rp.file.?.content); const a = parse(line) orelse return; makeListRows(p, qid, a.pat) catch |err| p.reportError(qid, "search", err); - toLineOne(p, qid); + // A list to pick from, typed into; diagnostics are a jump (]d): the + // keyboard stays on the place in the text. + if (source != .diagnostics) toLineOne(p, qid) else p.active = owner_id; } fn makeListRows(p: *Pardes, id: usize, pat: []const u8) !void { @@ -1141,8 +1185,10 @@ fn makeListRows(p: *Pardes, id: usize, pat: []const u8) !void { var rows: std.ArrayList(locations.Row) = .empty; const owner_id = p.paneBySerial(q.owner); const owner_path: []const u8 = if (owner_id) |oid| (if (p.panes[oid].?.file) |f| f.path else "") else ""; - var feed: std.ArrayList(Places.Hit) = .empty; - defer feed.deinit(p.gpa); + // Each open file's places in the list, its tints and n/N: the owner's + // and any other pane's the rows land in. + var feeds: [pardes.MAX_PANES]std.ArrayList(Places.Hit) = @splat(.empty); + defer for (&feeds) |*f| f.deinit(p.gpa); // In order: by path, then place, as a list of places reads. var sorted: std.ArrayList([]const u8) = .empty; defer sorted.deinit(p.gpa); @@ -1174,27 +1220,28 @@ fn makeListRows(p: *Pardes, id: usize, pat: []const u8) !void { } const rest = std.mem.trimStart(u8, ln[@min(t.end, ln.len)..], " \t:"); const col0 = t.at.col -| 1; - try q.items.append(p.gpa, .{ .kind = .hit, .n = 1 }); - // The row's text: the line in the owner when it is the owner's, - // else as the server said it. + // The row's text: the line as an open pane has it, when one shows + // the file, else as the server said it. var code: []const u8 = rest; - var col = col0; - var end = if (t.at.end_col > 0 and t.at.end_line == t.at.line) t.at.end_col else col0 + 1; - if (owner_id) |oid| if (std.mem.eql(u8, path, owner_path)) { - const owner_f = &p.panes[oid].?.file.?; - if (t.at.line <= File.nlines(p.gpa, owner_f)) { - const ls = File.lineStart(p.gpa, owner_f, t.at.line - 1); - const nx = File.lineStart(p.gpa, owner_f, t.at.line); - const le = if (nx > ls and owner_f.content[nx - 1] == '\n') nx - 1 else nx; - code = owner_f.content[ls..le]; - col = @min(col0, code.len); - end = @min(@max(end, col + 1), code.len); - feed.append(p.gpa, .{ .start = ls + col, .end = ls + @max(end, col + 1) }) catch {}; - } - } else { - col = 0; - end = 0; - }; + var col = @min(col0, rest.len); + var end = @min(if (t.at.end_col > 0 and t.at.end_line == t.at.line) t.at.end_col else col0 + 1, rest.len); + var shown_in: u32 = 0; + for (p.panes, 0..) |slot, i| { + const tp = slot orelse continue; + if (!searchable(tp)) continue; + const tf = &tp.file.?; + if (tf.output != null or !std.mem.eql(u8, tf.path, path) or t.at.line > File.nlines(p.gpa, tf)) continue; + const ls = File.lineStart(p.gpa, tf, t.at.line - 1); + const nx = File.lineStart(p.gpa, tf, t.at.line); + const le = if (nx > ls and tf.content[nx - 1] == '\n') nx - 1 else nx; + code = tf.content[ls..le]; + col = @min(col0, code.len); + end = @min(@max(end, col + 1), code.len); + feeds[i].append(p.gpa, .{ .start = ls + col, .end = ls + @max(end, col + 1) }) catch {}; + shown_in = tp.serial; + break; + } + try q.items.append(p.gpa, .{ .kind = .hit, .n = 1, .serial = shown_in }); try writeHitRow(p, &out, &rows, 9, path, t.at.line, code, col, end, &.{}); n += 1; } @@ -1203,12 +1250,14 @@ fn makeListRows(p: *Pardes, id: usize, pat: []const u8) !void { q.total = n; q.more = false; q.current = firstHit(q); + for (p.panes, 0..) |slot, i| if (slot) |tp| { + if (feeds[i].items.len > 0) tp.places.feed(p, tp, rp.serial, feeds[i].items, null) else if (tp.places.from == rp.serial) tp.places.clear(p.gpa); + }; if (owner_id) |oid| { const owner = p.panes[oid].?; // Current: the first place after where it was asked (the answer // may come after the cursor moved), shown in the owner. const asked_at: usize = if (p.lsp_last) |last| (if (last.serial == owner.serial) last.offset else owner.places.origin(owner)) else owner.places.origin(owner); - owner.places.feed(p, owner, rp.serial, feed.items, null); const hits = owner.places.hits.items; var next: ?usize = null; for (hits, 0..) |h, i| if (h.start > asked_at) { @@ -1261,6 +1310,13 @@ fn showCurrent(rp: *Pane) void { }; const r: i32 = @intCast(c + 1); rp.body.msel = .{ .active = true, .r0 = r, .r1 = r }; + // Typed into, line 1 stays in view whatever the current row: what you + // type is never scrolled away (the live rows start just before the + // current one, so it sits under line 1). Frozen, the row is scrolled to. + if (!q.frozen) { + if (rp.scroll() != 0) rp.scrollBy(-rp.scroll()); + return; + } const off = rp.scroll(); const shown = off + @as(i32, rp.rows) - 1; if (r > shown) rp.scrollBy(r - shown) else if (r < off) rp.scrollBy(r - off); @@ -1296,6 +1352,7 @@ fn setCurrent(p: *Pardes, id: usize, i: usize, show: bool) void { const q = rp.query.?; q.current = i; const it = q.items.items[i]; + if (q.source == .grep and it.kind == .hit) q.grep_at = it.hit; const rows = rp.file.?.location_rows; if (it.serial != 0 and i + 1 < rows.len) if (p.paneBySerial(it.serial)) |tid| { const tp = p.panes[tid].?; @@ -1325,6 +1382,17 @@ pub fn step(p: *Pardes, id: usize, delta: i32) void { return; } }; + // A Grep: by its lines, the window made again when the next is past it. + if (q.source == .grep and q.found.items.len > 0) { + const n = q.found.items.len; + q.grep_at = if (delta > 0) (q.grep_at + 1) % n else (q.grep_at + n - 1) % n; + const in_window = for (q.items.items) |it| { + if (it.kind == .hit and it.hit == q.grep_at) break true; + } else false; + if (!in_window) makeGrepRows(p, id, q.frozen) catch {}; + for (q.items.items, 0..) |it, i| if (it.kind == .hit and it.hit == q.grep_at) return setCurrent(p, id, i, true); + return; + } const items = q.items.items; if (items.len == 0) return; var i: usize = q.current orelse (if (delta > 0) items.len - 1 else 0); @@ -1335,6 +1403,26 @@ pub fn step(p: *Pardes, id: usize, delta: i32) void { setCurrent(p, id, i, true); } +/// Nothing current (a query that matches nothing): the +Preview shows +/// nothing, rather than a file the query no longer names. +fn blankPreview(p: *Pardes, qid: usize) void { + const pid = previewOf(p, qid) orelse return; + const pane = p.panes[pid].?; + const f = &pane.file.?; + if (f.content.len == 0) return; + const dir = std.fs.path.dirname(p.panes[qid].?.file.?.path) orelse "/"; + const path = std.fmt.allocPrint(p.gpa, "{s}/{s}", .{ dir, config.preview_buffer }) catch return; + const empty = p.gpa.alloc(u8, 0) catch { + p.gpa.free(path); + return; + }; + p.gpa.free(f.path); + f.path = path; + File.setContent(p, f, empty); + f.saved_revision = f.revision; + f.scroll = 0; +} + /// Where the current row points, shown with the keyboard left where it is: /// a place in an open pane's text selected there (its places' current), /// in view; a file an open pane shows, its line there; any other file in @@ -1399,8 +1487,11 @@ pub fn isPreview(p: *Pardes, pane: *const Pane) ?usize { return null; } -/// A +Preview made under query pane `qid`, out of its rows alone. -fn makePreview(p: *Pardes, qid: usize) ?usize { +/// A +Preview made under query pane `qid`, `rows` tall, out of `giver`'s +/// rows: the text that asked, at the key that asked; the query pane itself +/// when its source word was edited to one that previews while typing (its +/// line 1 stays where it is). +fn makePreview(p: *Pardes, qid: usize, rows: u16, giver: usize) ?usize { const rp = p.panes[qid].?; const free = p.freeSlot() orelse return null; const dir = std.fs.path.dirname(rp.file.?.path) orelse "/"; @@ -1410,10 +1501,7 @@ fn makePreview(p: *Pardes, qid: usize) ?usize { return null; }; layout.compute(p); - const rows = @max(pardes.BOX_H, np.tag_rows) + p.settings.search_rows; - // Out of the group's root, the text that asked: the query pane keeps - // the rows it was typed into with (made later, for a reused pane). - if (!layout.attachFrom(p, qid, free, rows, layout.groupRoot(p, qid))) { + if (!layout.attachFrom(p, qid, free, rows, giver)) { p.removePane(free, qid) catch {}; return null; } @@ -1425,7 +1513,7 @@ fn makePreview(p: *Pardes, qid: usize) ?usize { /// file open in a pane would be shown there instead), the place centred /// and selected. Made when the pane has none and its owner has the rows. fn displayPreview(p: *Pardes, qid: usize, path: []const u8, at: look.Spot) void { - const id = previewOf(p, qid) orelse makePreview(p, qid) orelse return; + const id = previewOf(p, qid) orelse makePreview(p, qid, p.rects[qid].h / 2, qid) orelse return; const pane = p.panes[id].?; const f = &pane.file.?; if (!std.mem.eql(u8, f.path, path)) { @@ -1706,8 +1794,8 @@ pub fn key(p: *Pardes, id: usize, k: Key) bool { land(p, id, null); return true; } - const down = (k.cp == Key.down and !k.ctrl and !k.alt) or (k.ctrl and !k.alt and k.cp == 'n'); - const up = (k.cp == Key.up and !k.ctrl and !k.alt) or (k.ctrl and !k.alt and k.cp == 'p'); + const down = hit(k, config.query_next); + const up = hit(k, config.query_prev); if (down or up) { step(p, id, if (down) 1 else -1); return true; diff --git a/src/builtins.zig b/src/builtins.zig index c8909e66..cda962de 100644 --- a/src/builtins.zig +++ b/src/builtins.zig @@ -1712,38 +1712,42 @@ const e_search_miss_grep = "Grep: text not found"; /// List the files below this pane's directory whose names hold its argument, in a +Search. pub const Find = struct { pub const takes_arg = true; + // A script's Find names what to find (bare, it is a key's prompt). pub const requires_arg = true; pub const output: OutputTraits = .{ .name = config.search_buffer, .steps = true }; pub fn run(c: Ctx) void { + // A query pane under this pane, line 1 `Find ` and the word: bare + // (SPC f f) typed into; with a word (B2, a script) listed, the + // keyboard left where it was, a script told of a miss. const pat = std.mem.trim(u8, c.arg orelse "", " \t\r\n"); - if (pat.len > 0) { - const rows = look.runSearch(c.p, c.id, pat, .find, .top, false) catch |err| return c.p.reportError(c.id, "Find", err); - if (rows == 0) c.p.reportFailure(c.id, e_search_miss_find); - return; - } - // Bare (SPC f f): the query pane, line 1 `Find `, typed into. - panes.Query.open(c.p, c.id, .find, "", true); + panes.Query.open(c.p, c.id, .find, pat, pat.len == 0); + if (pat.len > 0) missed(c, e_search_miss_find); } }; /// Find's sibling: Find matches file NAMES under this pane's directory, Grep -/// matches file CONTENTS under every pane's directory at once. +/// matches the LINES of those files, on the disk engine's worker. pub const Grep = struct { pub const takes_arg = true; pub const requires_arg = true; pub const output: OutputTraits = .{ .name = config.search_buffer, .steps = true, .locations = true }; pub fn run(c: Ctx) void { const pat = std.mem.trim(u8, c.arg orelse "", " \t\r\n"); - if (pat.len > 0) { - const rows = look.runSearch(c.p, c.id, pat, .grep, .top, false) catch |err| return c.p.reportError(c.id, "Grep", err); - if (rows == 0) c.p.reportFailure(c.id, e_search_miss_grep); - return; - } - // Bare (SPC f g): the query pane, line 1 `Grep `, typed into. - panes.Query.open(c.p, c.id, .grep, "", true); + panes.Query.open(c.p, c.id, .grep, pat, pat.len == 0); + if (pat.len > 0) missed(c, e_search_miss_grep); } }; +/// A script's Find or Grep (a 9P write runs it to its end before it +/// answers) that found nothing fails as one: the query pane stays, its +/// count 0, and the write hears `not found`. +fn missed(c: Ctx, text: []const u8) void { + if (!c.p.fs.serving) return; + const qid = panes.Query.ofOwner(c.p, c.pane.serial) orelse return; + const q = c.p.panes[qid].?.query.?; + if (q.total == 0) c.p.reportFailure(c.id, text); +} + /// Search in a query pane under this pane, line 1 the argument (`Panes`, /// `Symbols lay`, `All needle`, `/re`, any of its words); bare, `/`. pub const Search = struct { @@ -1898,11 +1902,10 @@ pub const Last = struct { pub const Recent = struct { pub const scope: Scope = .session; pub const takes_arg = true; - pub const output: OutputTraits = .{ .name = config.recent_buffer, .steps = true, .locations = true }; pub fn run(c: Ctx) void { - // From a pane: the query pane under it, line 1 `Recent `, typed - // into; from a header, which no pane owns, the +Recent list. - if (c.p.exec_header or c.p.panes[c.id] == null) return panes.Output.openRecent(c.p, c.id) catch |err| c.p.reportError(c.id, "recent", err); + // 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"); panes.Query.open(c.p, c.id, .recent, std.mem.trim(u8, c.arg orelse "", " \t\r\n"), true); } }; diff --git a/src/config.zig b/src/config.zig index 25c9dc5a..fff99ad2 100644 --- a/src/config.zig +++ b/src/config.zig @@ -365,6 +365,11 @@ pub const command_line: []const Chord = &.{.{ .cp = ':' }}; pub const search: []const Chord = &.{.{ .cp = '/' }}; pub const search_next: []const Chord = &.{.{ .cp = 'n' }}; pub const search_prev: []const Chord = &.{.{ .cp = 'N' }}; +/// Typing on a query pane's line 1 (Query.zig): the next and the previous +/// hit current, the text following (helix's prompt walks its history with +/// these; a query has none). Tab stays the exec chord. +pub const query_next: []const Chord = &.{ .{ .cp = 'n', .ctrl = true }, .{ .cp = Key.down } }; +pub const query_prev: []const Chord = &.{ .{ .cp = 'p', .ctrl = true }, .{ .cp = Key.up } }; pub const search_selection: []const Chord = &.{.{ .cp = '*', .alt = true }}; pub const search_selection_word: []const Chord = &.{.{ .cp = '*' }}; pub const pipe_selection: []const Chord = &.{.{ .cp = '|' }}; @@ -526,8 +531,6 @@ pub const comment_tokens: []const struct { exts: []const []const u8, token: []co }; pub const search_marker = " /"; -pub const find_marker = " Find /"; -pub const grep_marker = " Grep /"; pub const rename_marker = " Rename /"; pub const symbol_marker = " WsSymbols /"; pub const save_marker = " Save "; diff --git a/src/fs.zig b/src/fs.zig index cb813262..08379697 100644 --- a/src/fs.zig +++ b/src/fs.zig @@ -1115,297 +1115,16 @@ pub const WalkNotes = struct { } }; const find_max_depth = 16; -const find_max_steps = 100_000; -/// One root's Find or Grep rows at most: its hits, each a path and a line. -pub const search_root_output_bytes = find_max_hits * (4096 + 320); pub const find_skip = [_][]const u8{ ".git", ".jj", "target", "node_modules", ".venv", "__pycache__", ".zig-cache", "zig-out", }; -/// A directory the walk may not open or read is passed over and counted in -/// `notes.skipped`, its siblings' hits kept: one locked directory is not -/// every search's failure. A cap the walk hit is noted too. -pub fn find(arena: std.mem.Allocator, dir: []const u8, pat: []const u8, out: []u8, notes: *WalkNotes) !usize { - var hits: [find_max_hits][]const u8 = undefined; - var hits_len: usize = 0; - if (platform_has_fs) { - pardes.turn.yield(); - defer pardes.turn.back(); - const io = std.Io.Threaded.global_single_threaded.io(); - var root = try std.Io.Dir.cwd().openDir(io, dir, .{ .iterate = true }); - defer root.close(io); - var w = try root.walkSelectively(arena); - defer w.deinit(); - var steps: usize = 0; - walk: while (steps < find_max_steps and hits_len < hits.len) { - steps += 1; // an unreadable dir burns a step too, so it cannot spin - const e = (w.next(io) catch { - notes.skipped += 1; - continue; - }) orelse break; - if (std.ascii.findIgnoreCase(e.basename, pat) != null) { - hits[hits_len] = try arena.dupe(u8, e.path); - hits_len += 1; - } - if (e.kind != .directory or e.depth() >= find_max_depth) continue; - for (find_skip) |s| if (std.mem.eql(u8, e.basename, s)) continue :walk; - w.enter(io, e) catch { - notes.skipped += 1; - }; - } - if (hits_len >= hits.len) notes.hits_cut = true; - if (steps >= find_max_steps) notes.walk_cut = find_max_steps; - } else { - for (sources) |s| { - if (hits_len >= hits.len) break; - if (std.ascii.findIgnoreCase(std.fs.path.basename(s.path), pat) != null) { - hits[hits_len] = s.path; - hits_len += 1; - } - } - } - std.mem.sort([]const u8, hits[0..hits_len], {}, struct { - fn lt(_: void, a: []const u8, b: []const u8) bool { - return std.mem.lessThan(u8, a, b); - } - }.lt); - var written: usize = 0; - for (hits[0..hits_len]) |h| { - if (h.len + 1 > out.len - written) break; - @memcpy(out[written..][0..h.len], h); - written += h.len; - out[written] = '\n'; - written += 1; - } - return written; -} - -const grep_max_bytes = 256 * 1024; +// Find and Grep walk on the disk engine's worker now (Stream.zig); what is +// left here is what their notes and skips were. const grep_max_files = 20_000; -const GrepResult = struct { bytes: usize, hits: usize }; - -/// `text` starts at line `first_line` + 1 of its file. -fn grepText(path: []const u8, text: []const u8, pat: []const u8, out: []u8, budget: usize, first_line: usize) GrepResult { - var result: GrepResult = .{ .bytes = 0, .hits = 0 }; - var line: usize = first_line; - var it = std.mem.splitScalar(u8, text, '\n'); - while (it.next()) |raw| { - line += 1; - if (result.hits >= budget) break; - const at = std.ascii.findIgnoreCase(raw, pat) orelse continue; - const ln = std.mem.trimEnd(u8, raw, " \t\r"); - var cut = @min(ln.len, 200); - while (cut > 0 and cut < ln.len and ln[cut] & 0xc0 == 0x80) cut -= 1; - const row = std.fmt.bufPrint(out[result.bytes..], "{s}:{d}:{d}{c}{d} {s}\n", .{ - path, line, at + 1, config.range_sep, at + pat.len, ln[0..cut], - }) catch break; - result.bytes += row.len; - result.hits += 1; - } - return result; -} - -pub fn grep(arena: std.mem.Allocator, gpa: std.mem.Allocator, dir: []const u8, base: []const u8, pat: []const u8, out: []u8, notes: *WalkNotes) !usize { - var hits: usize = 0; - var written: usize = 0; - if (!platform_has_fs) { - for (sources) |s| { - if (hits >= find_max_hits or written == out.len) break; - const result = grepText(s.path, s.contents, pat, out[written..], find_max_hits - hits, 0); - hits += result.hits; - written += result.bytes; - } - return written; - } - const root_path = std.mem.trimEnd(u8, dir, "/"); - const home = std.mem.trimEnd(u8, base, "/"); - const files = try arena.alloc([]const u8, grep_max_files); - var files_len: usize = 0; - // A walk and thousands of reads: the turn goes out for all of it. - pardes.turn.yield(); - defer pardes.turn.back(); - { - const io = std.Io.Threaded.global_single_threaded.io(); - var root = try std.Io.Dir.cwd().openDir(io, dir, .{ .iterate = true }); - defer root.close(io); - var w = try root.walkSelectively(arena); - defer w.deinit(); - var steps: usize = 0; - walk: while (steps < find_max_steps and files_len < files.len) { - steps += 1; - const e = (w.next(io) catch { - notes.skipped += 1; - continue; - }) orelse break; - if (e.kind == .directory) { - if (e.depth() >= find_max_depth) continue; - for (find_skip) |s| if (std.mem.eql(u8, e.basename, s)) continue :walk; - w.enter(io, e) catch { - notes.skipped += 1; - }; - continue; - } - if (e.kind != .file) continue; - files[files_len] = try std.fmt.allocPrint(arena, "{s}/{s}", .{ root_path, e.path }); - files_len += 1; - } - if (files_len >= files.len) notes.walk_cut = grep_max_files else if (steps >= find_max_steps) notes.walk_cut = find_max_steps; - } - std.mem.sort([]const u8, files[0..files_len], {}, struct { - fn lt(_: void, a: []const u8, b: []const u8) bool { - return std.mem.lessThan(u8, a, b); - } - }.lt); - const buf = try gpa.alloc(u8, grep_max_bytes); - defer gpa.free(buf); - for (files[0..files_len]) |path| { - if (hits >= find_max_hits or written == out.len) { - notes.hits_cut = true; - break; - } - var pathbuf: [4096]u8 = undefined; - const path_z = std.fmt.bufPrintSentinel(&pathbuf, "{s}", .{path}, 0) catch return error.PathTooLong; - const fd = libc.open(path_z, .{ .ACCMODE = .RDONLY, .CLOEXEC = true, .NONBLOCK = true }); - if (fd < 0) continue; - defer _ = libc.close(fd); - // The whole file, a buffer at a time: each searched through its last - // whole line, the rest carried into the next. - const shown = lsp.rel(home, path); - var len: usize = 0; - var lines_before: usize = 0; - var first = true; - file: while (true) { - var eof = false; - while (len < buf.len) { - const n = libc.read(fd, buf[len..].ptr, buf.len - len); - if (n < 0) { - if (libc.errno(n) == .INTR) continue; - break :file; - } - if (n == 0) { - eof = true; - break; - } - len += @intCast(n); - } - if (first and std.mem.indexOfScalar(u8, buf[0..@min(len, 1024)], 0) != null) break; - first = false; - // A line longer than the buffer is searched in buffer-sized parts. - const end = if (eof) len else if (std.mem.lastIndexOfScalar(u8, buf[0..len], '\n')) |nl| nl + 1 else len; - const result = grepText(shown, buf[0..end], pat, out[written..], find_max_hits - hits, lines_before); - hits += result.hits; - written += result.bytes; - if (eof or hits >= find_max_hits or written == out.len) break; - lines_before += std.mem.count(u8, buf[0..end], "\n"); - std.mem.copyForwards(u8, buf[0 .. len - end], buf[end..len]); - len -= end; - } - if (hits >= find_max_hits) notes.hits_cut = true; - } - return written; -} - -test "grep skips a file it cannot read instead of abandoning the search" { - if (!platform_has_fs) return; - const gpa = std.testing.allocator; - var tmp = std.testing.tmpDir(.{}); - defer tmp.cleanup(); - var base_buf: [std.fs.max_path_bytes]u8 = undefined; - const dir = base_buf[0..try tmp.dir.realPath(std.testing.io, &base_buf)]; - - try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "a-locked.txt", .data = "needle here\n" }); - try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "b-open.txt", .data = "needle here\n" }); - var locked_buf: [std.fs.max_path_bytes]u8 = undefined; - const locked = try std.fmt.bufPrintSentinel(&locked_buf, "{s}/a-locked.txt", .{dir}, 0); - if (libc.chmod(locked, 0) != 0) return; - const probe = libc.open(locked, .{ .ACCMODE = .RDONLY }); - if (probe >= 0) { - _ = libc.close(probe); - _ = libc.chmod(locked, 0o644); - return error.SkipZigTest; - } - - var arena: std.heap.ArenaAllocator = .init(gpa); - defer arena.deinit(); - const out = try gpa.alloc(u8, 64 * 1024); - defer gpa.free(out); - var notes: WalkNotes = .{}; - const n = try grep(arena.allocator(), gpa, dir, dir, "needle", out, ¬es); - _ = libc.chmod(locked, 0o644); // so `tmp.cleanup` can remove it - - try std.testing.expect(std.mem.indexOf(u8, out[0..n], "b-open.txt") != null); - try std.testing.expect(std.mem.indexOf(u8, out[0..n], "a-locked.txt") == null); -} - -test "a directory the walk may not open is skipped and counted: Grep and Find keep every other hit" { - if (!platform_has_fs) return; - const gpa = std.testing.allocator; - var tmp = std.testing.tmpDir(.{}); - defer tmp.cleanup(); - var base_buf: [std.fs.max_path_bytes]u8 = undefined; - const dir = base_buf[0..try tmp.dir.realPath(std.testing.io, &base_buf)]; - try tmp.dir.createDirPath(std.testing.io, "locked"); - try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "locked/needle-in.txt", .data = "needle\n" }); - try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "needle-out.txt", .data = "needle\n" }); - var locked_buf: [std.fs.max_path_bytes]u8 = undefined; - const locked = try std.fmt.bufPrintSentinel(&locked_buf, "{s}/locked", .{dir}, 0); - if (libc.chmod(locked, 0) != 0) return; - defer _ = libc.chmod(locked, 0o755); // so `tmp.cleanup` can remove it - if (isDir(locked)) return error.SkipZigTest; // root reads it anyway - var arena: std.heap.ArenaAllocator = .init(gpa); - defer arena.deinit(); - const out = try gpa.alloc(u8, 64 * 1024); - defer gpa.free(out); - var notes: WalkNotes = .{}; - var n = try grep(arena.allocator(), gpa, dir, dir, "needle", out, ¬es); - try std.testing.expect(std.mem.indexOf(u8, out[0..n], "needle-out.txt:1:") != null); - try std.testing.expectEqual(@as(usize, 1), notes.skipped); - notes = .{}; - n = try find(arena.allocator(), dir, "needle", out, ¬es); - try std.testing.expect(std.mem.indexOf(u8, out[0..n], "needle-out.txt") != null); - try std.testing.expectEqual(@as(usize, 1), notes.skipped); -} - -test "Grep reads a long file to its end, and says when its hits were cut" { - if (!platform_has_fs) return; - const gpa = std.testing.allocator; - var tmp = std.testing.tmpDir(.{}); - defer tmp.cleanup(); - var base_buf: [std.fs.max_path_bytes]u8 = undefined; - const dir = base_buf[0..try tmp.dir.realPath(std.testing.io, &base_buf)]; - // A match past the first buffer of a long file, on its own line number. - const long = try gpa.alloc(u8, grep_max_bytes + 64); - defer gpa.free(long); - @memset(long, 'x'); - for (0..long.len / 64) |i| long[i * 64] = '\n'; - @memcpy(long[long.len - 8 ..][0..7], "needle\n"); - try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "long.txt", .data = long }); - var arena: std.heap.ArenaAllocator = .init(gpa); - defer arena.deinit(); - const out = try gpa.alloc(u8, 256 * 1024); - defer gpa.free(out); - var notes: WalkNotes = .{}; - var n = try grep(arena.allocator(), gpa, dir, dir, "needle", out, ¬es); - var want_buf: [64]u8 = undefined; - const want = try std.fmt.bufPrint(&want_buf, "long.txt:{d}:", .{std.mem.count(u8, long, "\n")}); - try std.testing.expect(std.mem.startsWith(u8, out[0..n], want)); - // More hits than the cap. - var many: std.ArrayList(u8) = .empty; - defer many.deinit(gpa); - for (0..find_max_hits + 10) |_| try many.appendSlice(gpa, "needle\n"); - try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "many.txt", .data = many.items }); - notes = .{}; - n = try grep(arena.allocator(), gpa, dir, dir, "needle", out, ¬es); - try std.testing.expect(notes.hits_cut); - var said: [256]u8 = undefined; - const lines = said[0..notes.write(&said)]; - try std.testing.expectEqualStrings("cut at 512 hits\n", lines); - try std.testing.expect(WalkNotes.isNote("cut at 512 hits") and WalkNotes.isNote("2 directories skipped: permission denied") and !WalkNotes.isNote("src/2 directories.txt")); -} - fn isDir(path: [*:0]const u8) bool { const fd = libc.open(path, .{ .ACCMODE = .RDONLY, .DIRECTORY = true, .CLOEXEC = true }); if (fd < 0) return false; diff --git a/src/look.zig b/src/look.zig index eed3dbd9..cd8df4fc 100644 --- a/src/look.zig +++ b/src/look.zig @@ -532,7 +532,6 @@ pub fn cursorWordSel(p: *Pardes, pane: *Pane) Pane.Sel { return .{ .state = .done, .c0 = vcol, .c1 = vcol, .r0 = vrow, .r1 = vrow }; } -const Search = enum { text, find, grep }; const SearchStart = enum { top, cursor }; @@ -550,20 +549,13 @@ pub fn submitSearch(p: *Pardes, id: usize) void { const slash = std.mem.indexOfScalar(u8, armed, '/') orelse return; if (std.mem.startsWith(u8, armed, config.rename_marker)) return p.lspRequest(id, .rename, armed[slash + 1 ..]); if (std.mem.startsWith(u8, armed, config.symbol_marker)) return p.lspRequest(id, .workspace_symbols, armed[slash + 1 ..]); - const kind: Search = if (std.mem.startsWith(u8, armed, config.find_marker)) - .find - else if (std.mem.startsWith(u8, armed, config.grep_marker)) - .grep - else - .text; - _ = runSearch(p, id, armed[slash + 1 ..], kind, .top, true) catch |err| return p.reportError(id, "search", err); - if (kind == .text) { - var pattern: std.ArrayList(u8) = .empty; - normal.appendSearchLiteral(&pattern, p.scratch.allocator(), armed[slash + 1 ..]) catch return; - p.registers.put(p.gpa, '/', pattern.items, 0, 1, true); - p.registers.last_search = '/'; - lookFirstHit(p, id); - } + // A PDF's `/` and a terminal's: a text's is its query pane (Query.zig). + _ = runSearch(p, id, armed[slash + 1 ..], .top, true) catch |err| return p.reportError(id, "search", err); + var pattern: std.ArrayList(u8) = .empty; + normal.appendSearchLiteral(&pattern, p.scratch.allocator(), armed[slash + 1 ..]) catch return; + p.registers.put(p.gpa, '/', pattern.items, 0, 1, true); + p.registers.last_search = '/'; + lookFirstHit(p, id); } fn lookFirstHit(p: *Pardes, id: usize) void { @@ -589,7 +581,7 @@ fn lookFirstHit(p: *Pardes, id: usize) void { /// of rows: past it, the rows stop and say where. pub const search_text_output_bytes = 16 << 20; -pub fn runSearch(p: *Pardes, id: usize, pat_raw: []const u8, kind: Search, start: SearchStart, open_empty: bool) !usize { +pub fn runSearch(p: *Pardes, id: usize, pat_raw: []const u8, start: SearchStart, open_empty: bool) !usize { const pane = p.panes[id] orelse return 0; // Blanks at either end are the pattern's (a look of an indented line); // a builtin's argument comes trimmed already. @@ -607,49 +599,7 @@ pub fn runSearch(p: *Pardes, id: usize, pat_raw: []const u8, kind: Search, start var nrows: usize = 0; var anchor: ?usize = null; var notes: filesystem.WalkNotes = .{}; - if (kind == .grep) { - var roots: [MAX_PANES][]const u8 = undefined; - var nroots: usize = 0; - for (p.panes) |slot| { - const pp = slot orelse continue; - // A pane of the served tree (/virtual/, /n//) has no - // directory on this host to walk, and one that named `/` would - // swallow every other root: passed over. - const d = filesystem.localPath(Pardes.paneDir(pp)) orelse continue; - if (filesystem.isVirtual(if (pp.file) |f| f.path else d)) continue; - var covered = false; - var k: usize = 0; - while (k < nroots) { - if (pathUnder(d, roots[k])) { - covered = true; - break; - } - if (pathUnder(roots[k], d)) { // this one swallows a root already kept - nroots -= 1; - roots[k] = roots[nroots]; - continue; - } - k += 1; - } - if (covered) continue; - roots[nroots] = d; - nroots += 1; - } - out = try @import("memory.zig").unfilled(arena, @max(1, nroots) * filesystem.search_root_output_bytes); - // A pane's directory that is not there (a scratch named into one - // not made yet, a peer's) has nothing to grep: passed over, not the - // search's failure. - for (roots[0..nroots]) |r| - out_len += filesystem.grep(arena, p.gpa, r, dir, pat, out[out_len..], ¬es) catch |err| switch (err) { - error.FileNotFound, error.NotDir, error.AccessDenied => continue, - else => return err, - }; - nrows = std.mem.count(u8, out[0..out_len], "\n"); - } else if (kind == .find) { - out = try @import("memory.zig").unfilled(arena, filesystem.search_root_output_bytes); - out_len = try filesystem.find(arena, dir, pat, out, ¬es); - nrows = std.mem.count(u8, out[0..out_len], "\n"); - } else if (pane.hasPdf()) { + if (pane.hasPdf()) { out = try @import("memory.zig").unfilled(arena, search_text_output_bytes); if (comptime pdf_enabled) { const found = try panes.Pdf.searchRows( @@ -700,19 +650,10 @@ pub fn runSearch(p: *Pardes, id: usize, pat_raw: []const u8, kind: Search, start const noted = notes.write(out[out_len..]); out_len += noted; nrows += std.mem.count(u8, out[out_len - noted .. out_len], "\n"); - // A Find or Grep that finds nothing leaves its directory's +Search as - // it was: the failure says why, and the last search's rows are still - // that search's (its tag names it). + // A word looked for that is nowhere opens nothing. if (!open_empty and nrows == 0) return 0; const content = try p.gpa.dupe(u8, out[0..out_len]); - // the buffer records WHICH search filled it, pattern and all: Find and - // Grep are builtins (words you can execute), the bare `/` is a key - const from: panes.Output.Origin = switch (kind) { - .text => .search, - .find => .{ .cmd = .Find }, - .grep => .{ .cmd = .Grep }, - }; - try panes.Output.fillResults(p, id, dir, from, pat, content, anchor); + try panes.Output.fillResults(p, id, dir, .search, pat, content, anchor); return nrows; } @@ -1466,7 +1407,7 @@ fn lookUnresolved(p: *Pardes, id: usize, pane: *Pane, trimmed: []const u8, text: if (p.settings.look_word == .search and pane.file != null) return lookWord(p, id, pane, text); p.word_look = true; defer p.word_look = false; - const rows = runSearch(p, id, text, .text, .cursor, false) catch |err| { + const rows = runSearch(p, id, text, .cursor, false) catch |err| { p.reportError(id, "search", err); return; }; diff --git a/src/ninep/ctl.zig b/src/ninep/ctl.zig index 45336a1e..635e03a6 100644 --- a/src/ninep/ctl.zig +++ b/src/ninep/ctl.zig @@ -3017,7 +3017,7 @@ test "a builtin that needs its argument, written bare to an exec, is EINVAL as t } } -test "Grep with no hit says grep: no match and opens nothing, a missing pane directory passed over" { +test "a script's Grep and Find fill the pane's one query pane, a row a line under its file; a miss says not found and opens nothing" { const p = try withFile(testing.allocator, "x\n"); defer p.deinit(); var tmp = testing.tmpDir(.{}); @@ -3028,22 +3028,26 @@ test "Grep with no hit says grep: no match and opens nothing, a missing pane dir const dir = dir_buf[0..try tmp.dir.realPath(testing.io, &dir_buf)]; var line: [4200]u8 = undefined; _ = wr(p, Node.of(serialOf(p), .name), try std.fmt.bufPrint(&line, "{s}/a.txt\n", .{dir})); - // A hit opens its +Search, a row a line: exec reads it back. Find and - // Grep share it, a directory's one +Search, each run replacing it. + // A hit fills the pane's query pane, line 1 the command, its rows under + // the file they are in: exec reads it back. Find and Grep share it, the + // pane's one query pane, each run replacing it. try testing.expectEqual(Status.ok, wr(p, Node.of(serialOf(p), .exec), "Grep bravo\n").reply.status); const grepped = p.panes[p.paneBySerial(try std.fmt.parseInt(u32, std.mem.trimEnd(u8, rd(p, root_exec, 0, 64).bytes, "\n"), 10)).?].?; - try testing.expectEqual(@as(usize, 2), std.mem.count(u8, grepped.file.?.content, "other.txt:")); - try testing.expect(std.mem.indexOf(u8, grepped.file.?.content, "other.txt:2") != null); - try testing.expect(std.mem.indexOf(u8, grepped.file.?.content, "other.txt:3") != null); + const rows = grepped.file.?.content; + try testing.expect(std.mem.startsWith(u8, rows, "Grep bravo\n")); + try testing.expect(std.mem.indexOf(u8, rows, "\nother.txt\n") != null); + try testing.expect(std.mem.indexOf(u8, rows, "2 bravo here\n") != null); + try testing.expect(std.mem.indexOf(u8, rows, "3 three bravo\n") != null); + try testing.expectEqual(@as(usize, 2), grepped.query.?.total); try testing.expectEqual(Status.ok, wr(p, Node.of(serialOf(p), .exec), "Find other\n").reply.status); const found = p.panes[p.paneBySerial(try std.fmt.parseInt(u32, std.mem.trimEnd(u8, rd(p, root_exec, 0, 64).bytes, "\n"), 10)).?].?; - try testing.expect(std.mem.indexOf(u8, found.file.?.content, "other.txt") != null); try testing.expectEqual(grepped.serial, found.serial); + try testing.expect(std.mem.indexOf(u8, found.file.?.content, "\nother.txt\n") != null); try testing.expect(std.mem.indexOf(u8, found.file.?.content, "bravo here") == null); - // The same Find again reads back the +Search, not the pane it ran in. + // The same Find again reads back the query pane, not the pane it ran in. try testing.expectEqual(Status.ok, wr(p, Node.of(serialOf(p), .exec), "Find other\n").reply.status); try testing.expectEqualStrings(try std.fmt.bufPrint(&line, "{d}\n", .{found.serial}), rd(p, root_exec, 0, 64).bytes); - // A Grep run from the +Search itself fills that one, never a second. + // A Grep run from the query pane itself fills that one, never a second. try testing.expectEqual(Status.ok, wr(p, Node.of(found.serial, .exec), "Grep bravo\n").reply.status); try testing.expectEqualStrings(try std.fmt.bufPrint(&line, "{d}\n", .{found.serial}), rd(p, root_exec, 0, 64).bytes); var searches: usize = 0; @@ -3052,23 +3056,19 @@ test "Grep with no hit says grep: no match and opens nothing, a missing pane dir }; try testing.expectEqual(@as(usize, 1), searches); try testing.expect(std.mem.indexOf(u8, found.file.?.content, "bravo here") != null); - // A second pane in a directory that is not there. - const other = try th.newPane(p); - _ = wr(p, Node.of(other, .name), "/tmp/pardes-no-such-dir-zz/b.txt\n"); var count: usize = 0; for (p.panes) |slot| count += @intFromBool(slot != null); + // A miss: said to the script, the query pane's count 0, nothing opened. const missed = wr(p, Node.of(serialOf(p), .exec), "Grep zzqqnomatchzz\n"); try testing.expectEqual(E.NOENT, missed.errno()); try testing.expectEqualStrings("Grep: text not found", missed.reply.ename); + try testing.expectEqual(@as(usize, 0), found.query.?.total); const unfound = wr(p, Node.of(serialOf(p), .exec), "Find zzqqnomatchzz\n"); try testing.expectEqual(E.NOENT, unfound.errno()); try testing.expectEqualStrings("Find: name not found", unfound.reply.ename); var after: usize = 0; for (p.panes) |slot| after += @intFromBool(slot != null); try testing.expectEqual(count, after); - // The +Search a miss would have filled keeps the last search's rows: - // the miss is said, and its tag names what they are of. - try testing.expect(std.mem.indexOf(u8, found.file.?.content, "bravo here") != null); } test "Unmount of a name not mounted says no such mount, which a mount reads as ENOENT" { @@ -4911,7 +4911,7 @@ test "a Rename the server answered for this file alone, with other open files sa try testing.expect(th.logHas(p, "Rename: previewed, not applied: the server renamed in this file only, and 1 other open file(s) say the name")); } -test "Find ends with what it skipped, and a Find or Grep that finds nothing leaves the +Search as it was" { +test "Find says what it skipped under its names, and a script's Find that finds nothing is told so" { if (comptime !pardes.hosted) return; const gpa = testing.allocator; var tmp = testing.tmpDir(.{}); @@ -4928,18 +4928,18 @@ test "Find ends with what it skipped, and a Find or Grep that finds nothing leav const path = try std.fmt.bufPrint(&path_buf, "{s}/zz-needle.txt", .{dir}); const p = try Pardes.init(gpa, .{ .file = path, .tty_only = true, .cols = 80, .rows = 30 }); defer p.deinit(); - try testing.expect(p.executeBuiltinLine(0, "Find needle")); - const search = p.panes[p.panes[0].?.search_pane.?].?; + // the walk's own skips are what is said (rg would pass over in silence) + p.stream.engine = .walk; + try testing.expectEqual(Status.ok, wr(p, Node.of(serialOf(p), .exec), "Find needle\n").reply.status); + const search = p.panes[pardes.panes.Query.ofOwner(p, p.panes[0].?.serial).?].?; const listed = search.file.?.content; try testing.expect(std.mem.endsWith(u8, listed, "1 directory skipped: permission denied\n")); - try testing.expect(std.mem.startsWith(u8, listed, "zz-needle.txt\n")); - // Nothing found where it looked, and nothing passed over: the miss is - // said, and the +Search keeps the last search's rows. + try testing.expect(std.mem.startsWith(u8, listed, "Find needle\nzz-needle.txt\n")); + // Nothing found: the miss is said, the query pane's count 0. _ = std.c.chmod(locked, 0o755); - const before = try gpa.dupe(u8, listed); - defer gpa.free(before); - try testing.expect(p.executeBuiltinLine(0, "Find nosuchname")); - try testing.expectEqualStrings(before, search.file.?.content); + const missed = wr(p, Node.of(serialOf(p), .exec), "Find nosuchname\n"); + try testing.expectEqual(E.NOENT, missed.errno()); + try testing.expectEqual(@as(usize, 0), search.query.?.total); try testing.expect(th.logHas(p, "Find: name not found")); } diff --git a/src/normal.zig b/src/normal.zig index ebace536..f5bdb9dc 100644 --- a/src/normal.zig +++ b/src/normal.zig @@ -757,22 +757,18 @@ fn executeNormalAction(p: *Pardes, t: *Text, semantic: modal.Normal.Action) void .add_newline => |newline| return edit.addNewline(p, t, newline.direction == .forward, newline.count), .diagnostic => |diagnostic| { const fwd = diagnostic.direction == .forward; - if (!diagnostic.endpoint) { - if (panes.Output.resultsFrom(p, pane, .{ .query = .diagnostics }) and - look.searchStep(p, p.active, if (fwd) 1 else -1)) return; - return p.lspRequest(p.active, .diagnostics, ""); - } - if (!panes.Output.resultsFrom(p, pane, .{ .query = .diagnostics })) - return p.lspRequest(p.active, .diagnostics, ""); - if (!fwd) { - pane.search_row = null; - _ = look.searchStep(p, p.active, 1); - return; - } - const rp = p.panes[pane.search_pane orelse return] orelse return; - const rf = rp.file orelse return; - pane.search_row = std.mem.count(u8, rf.content, "\n"); - _ = look.searchStep(p, p.active, -1); + // Once a Diagnostics query fed them, the diagnostics are this + // text's places: ]d and [d step them as n and N do, ]D and [D + // go to the last and the first. Until then, asked for. + 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 p.lspRequest(p.active, .diagnostics, ""); + if (!diagnostic.endpoint) return set.step(p, pane, fwd, 1, false); + if (set.hits.items.len == 0) return; + set.goTo(pane, if (fwd) set.hits.items.len - 1 else 0, false); }, .move => |move| switch (move.motion) { .left => { diff --git a/src/tagline.zig b/src/tagline.zig index 3c8dd3e1..c057772d 100644 --- a/src/tagline.zig +++ b/src/tagline.zig @@ -184,6 +184,7 @@ pub fn curTail(pane: *Pane) []const u8 { pub fn defaultTail(pane: *const Pane) []const u8 { if (comptime pdf_enabled) if (pane.pdf != null) return pdf_pane_tail; if (pane.query) |q| return if (q.frozen) query_frozen_tail else if (q.capped) query_capped_tail else query_live_tail; + if (pane.file) |file| if (file.output) |out| if (out.from == .preview) return query_live_tail; if (pane.file) |file| if (file.listing != null) return dir_pane_tail; if (pane.file) |file| if (file.pager) return if (file.pager_diff) pager_diff_pane_tail else pager_pane_tail; if (pane.file != null and pane.colorAlgo() == .diff) return diff_pane_tail; diff --git a/src/tutor.txt b/src/tutor.txt index 083a5028..188a485d 100644 --- a/src/tutor.txt +++ b/src/tutor.txt @@ -101,8 +101,10 @@ 1. `Look` :20 here: the cursor goes to line 20 of this pane. 2. Drag across :/^=.*UNSAVED/ with B3 held: `Look` takes exactly what you swept, a regex here, and goes to Part 7's heading. - 3. Press /, type keys, press Enter: a +Search lists the lines with - keys and the cursor goes to the first. n and N select search matches. + 3. Press / and type keys: a +Search opens under this pane, its first + line the query; each match lights up and is listed as you type, and + Ctrl-n steps. Enter puts the cursor on it and keeps the list; n and N + step them. Esc while typing puts everything back. -> Guide: Look @@ -259,9 +261,9 @@ typed ] p, [ p step by paragraph; ] d, [ d by diagnostic ] space a blank line below; [ space above | filter every selection through the shell - / case-insensitive SUBSTRING search, one hit a line; the - regex lives on s and S - n / N next/previous search match (Helix); v adds matches + / search in a query pane under the text: a regex, any + case unless it has a capital; line 1 is the query + n / N next/previous match, round the end; v adds matches SPC j n/p `LookNext`/`LookPrev`: select locations; Enter opens Ctrl-c comment or uncomment the lines @@ -344,11 +346,11 @@ typed ; collapses first bare G does nothing; ge is the START of the last line s / S regex cursors; m i/a textobjects; m s/r/d surround - / is a case-insensitive SUBSTRING search, not a regex + / opens a query pane: line 1 the query, Enter lands SPC is the leader (SPC ? is `Help`) vs HELIX selection is LINE-first (x), v for characters; / is a - substring search; n/N repeat it in the current text. + pane: Find, Grep, Recent are its line 1's first word. vs VIM no verb+noun: the motion already selected, so wd is what dw was; Esc goes back a pane; bare G does nothing. vs BOTH a terminal is just a pane, and the session can outlive diff --git a/test/output.zig b/test/output.zig index 8ba2f357..8eb389c8 100644 --- a/test/output.zig +++ b/test/output.zig @@ -219,6 +219,15 @@ test "references fill the asking text's query pane: sorted under their files, th try std.testing.expectEqual(@as(?usize, 2), source.places.current); try std.testing.expectEqual(@as(i32, 3), source.body.cur_row); try std.testing.expectEqual(@as(usize, 6), results.query.?.total); + // Ctrl-n on line 1, Enter: the keyboard on that ref in the text + try std.testing.expectEqual(qid, p.active); + p.update(.{ .key = .{ .cp = 'n', .ctrl = true } }); + try std.testing.expectEqual(@as(?usize, 3), source.places.current); + p.update(.{ .key = .{ .cp = Key.enter } }); + try std.testing.expectEqual(@as(usize, 0), p.active); + try std.testing.expectEqual(@as(i32, 4), source.body.cur_row); + p.update(.{ .key = .{ .cp = 'N' } }); + try std.testing.expectEqual(@as(?usize, 2), source.places.current); // n in the owner steps them, round the end without a word p.active = 0; p.update(.{ .key = .{ .cp = 'n' } }); diff --git a/test/pdf.zig b/test/pdf.zig index ea23f90a..d4efdfaf 100644 --- a/test/pdf.zig +++ b/test/pdf.zig @@ -1053,7 +1053,7 @@ test "MuPDF pane renders, navigates, searches, and round-trips its page" { try std.testing.expect(pane.pdf.?.document_scroll_y > before_height_scroll); const revision_before_search = active_raster.revision; - _ = try pardes.look.runSearch(p, 0, "Pardes", .text, .top, true); + _ = try pardes.look.runSearch(p, 0, "Pardes", .top, true); try std.testing.expectEqualStrings("Pardes", pane.pdf.?.search_query); try std.testing.expectEqual(revision_before_search, active_raster.revision); const results_id = pane.search_pane orelse return error.MissingPdfSearchResults; @@ -1915,7 +1915,7 @@ test "PDF n/N addresses and reveals distinct MuPDF hits on one page" { p.locations_config.context = 2; p.locations_config.tscontext = true; - _ = try pardes.look.runSearch(p, 0, "Pardes", .text, .top, true); + _ = try pardes.look.runSearch(p, 0, "Pardes", .top, true); const results_id = pane.search_pane orelse return error.MissingPdfSearchResults; const results = p.panes[results_id].?.file.?; var found: [3]bool = @splat(false); diff --git a/test/snapshots/builtins.snap b/test/snapshots/builtins.snap index 73509c24..cf367c5a 100644 --- a/test/snapshots/builtins.snap +++ b/test/snapshots/builtins.snap @@ -37,6 +37,29 @@ wheel up 110 50 wheel up 110 50 wheel up 110 50 wheel up 110 50 +wheel up 110 50 +wheel up 110 50 +wheel up 110 50 +wheel up 110 50 +wheel up 110 50 +wheel up 110 50 +wheel up 110 50 +wheel up 110 50 +wheel up 110 50 +wheel up 110 50 +wheel up 110 50 +wheel up 110 50 +wheel up 110 50 +wheel up 110 50 +wheel up 110 50 +wheel up 110 50 +wheel up 110 50 +wheel up 110 50 +wheel up 110 50 +wheel up 110 50 +wheel up 110 50 +wheel up 110 50 +wheel up 110 50 wait 10000 Look enter, right-click wait 10000 Exec tab, middle-click wait 10000 Filter diff --git a/test/snapshots/dump.golden b/test/snapshots/dump.golden index 571bacbc..72bb85a7 100644 --- a/test/snapshots/dump.golden +++ b/test/snapshots/dump.golden @@ -37,6 +37,7 @@ .collapsed = false, .serial = 1, .tag_tail = null, + .attached_to = null, .terminal = .{ .cwd = "/tmp/pardes-snap/dump/cwd", .shell = "", @@ -62,6 +63,7 @@ .collapsed = false, .serial = 2, .tag_tail = null, + .attached_to = null, .terminal = .{ .cwd = "/tmp/pardes-snap/dump/cwd", .shell = "", @@ -87,6 +89,7 @@ .collapsed = false, .serial = 3, .tag_tail = null, + .attached_to = null, .terminal = .{ .cwd = "/tmp/pardes-snap/dump/cwd", .shell = "", diff --git a/test/snapshots/find.golden b/test/snapshots/find.golden index 47480b83..e5c11193 100644 --- a/test/snapshots/find.golden +++ b/test/snapshots/find.golden @@ -2,91 +2,61 @@ | Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol | /tmp/pardes-snap/find/cwd/here.txt Save Tty Collapse Del -| 1 Find SPC f -== snap armed grid=120x41 cursor=119,4 -|3: 1 Find Find -|4: Find / -== snap typing grid=120x41 cursor=119,3 -|3: 1 Find Find /zqm -|4: -== snap results grid=120x41 cursor=7,3 -|3: 1 Find -|5: /tmp/pardes-snap/find/cwd/+Search Save Tty Collapse Del -|6: 1 sub/ZQMARK-beta.txt -|7: 2 sub/nest/zqmark-gamma.txt -|8: 3 zqmark-alpha.txt -|9: 4 -== snap first grid=120x41 cursor=7,10 -|9: /tmp/pardes-snap/find/cwd/sub/ZQMARK-beta.txt Save Tty Collapse Del -|10: 1 beta body -== style first grid=120x41 -|0: 0-1 d,#1d2824, 2-119 #b2c3b8,#1d2824, -|1: 0-1 d,#887455, 2-119 #becfc4,#314738, -|2: 0-1 d,#496656, 2-27 #b2c3b8,#1d2824, 28-36 #d3b0d9,#1d2824, 37-119 #b2c3b8,#1d2824, -|3: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-119 #e5eee5,#0d1410, -|4: 0-0 d,#608269, 1-119 d,#0d1410, -|5: 0-1 d,#496656, 2-27 #b2c3b8,#1d2824, 28-35 #d3b0d9,#1d2824, 36-119 #b2c3b8,#1d2824, -|6: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-119 #e5eee5,#0d1410, -|7: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-119 #e5eee5,#0d1410, -|8: 0-0 d,#152019, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-119 #e5eee5,#0d1410, -|9: 0-1 d,#add38a, 2-31 #becfc4,#314738, 32-47 #dfbce5,#314738, 48-119 #becfc4,#314738, -|10: 0-0 d,#608269, 1-1 d,#0d1410, 2-4 d,#0d1410,b 5-6 #616f64,#0d1410,b 7-119 #e5eee5,#0d1410, -|11: 0-0 d,#608269, 1-119 d,#0d1410, -|12: 0-0 d,#608269, 1-119 d,#0d1410, -|13: 0-0 d,#608269, 1-119 d,#0d1410, -|14: 0-0 d,#608269, 1-119 d,#0d1410, -|15: 0-0 d,#608269, 1-119 d,#0d1410, -|16: 0-0 d,#608269, 1-119 d,#0d1410, -|17: 0-0 d,#608269, 1-119 d,#0d1410, -|18: 0-0 d,#608269, 1-119 d,#0d1410, -|19: 0-0 d,#608269, 1-119 d,#0d1410, -|20: 0-0 d,#608269, 1-119 d,#0d1410, -|21: 0-0 d,#608269, 1-119 d,#0d1410, -|22: 0-0 d,#608269, 1-119 d,#0d1410, -|23: 0-0 d,#608269, 1-119 d,#0d1410, -|24: 0-0 d,#608269, 1-119 d,#0d1410, -|25: 0-0 d,#608269, 1-119 d,#0d1410, -|26: 0-0 d,#608269, 1-119 d,#0d1410, -|27: 0-0 d,#608269, 1-119 d,#0d1410, -|28: 0-0 d,#608269, 1-119 d,#0d1410, -|29: 0-0 d,#608269, 1-119 d,#0d1410, -|30: 0-0 d,#608269, 1-119 d,#0d1410, -|31: 0-0 d,#608269, 1-119 d,#0d1410, -|32: 0-0 d,#608269, 1-119 d,#0d1410, -|33: 0-0 d,#608269, 1-119 d,#0d1410, -|34: 0-0 d,#608269, 1-119 d,#0d1410, -|35: 0-0 d,#608269, 1-119 d,#0d1410, -|36: 0-0 d,#608269, 1-119 d,#0d1410, -|37: 0-0 d,#608269, 1-119 d,#0d1410, -|38: 0-0 d,#608269, 1-119 d,#0d1410, -|39: 0-0 d,#608269, 1-119 d,#0d1410, -|40: 0-0 d,#608269, 1-119 d,#0d1410, -== snap second grid=120x41 cursor=7,13 -|12: /tmp/pardes-snap/find/cwd/sub/nest/zqmark-gamma.txt Save Tty Collapse Del -|13: 1 gamma body -== snap third grid=120x41 cursor=7,16 -|15: /tmp/pardes-snap/find/cwd/zqmark-alpha.txt Save Tty Collapse Del -|16: 1 alpha body -== snap back grid=120x41 cursor=7,13 -== snap word grid=120x41 cursor=7,13 -|3: 1 Find Find -|4: Find / -== snap cancel grid=120x41 cursor=7,7 -|3: 1 Find Find / -|4: -|13: 1 gamma body Last -== snap nomatch grid=120x41 cursor=7,3 -|3: 1 Find -|6: 1 -|7: -|8: -|13: 1 gamma body -== snap refit grid=120x41 cursor=7,3 -|6: 1 sub/ZQMARK-beta.txt -|7: 2 sub/nest/zqmark-gamma.txt -|8: 3 zqmark-alpha.txt -== snap topbar grid=120x41 cursor=12,16 -|6: 1 zqmark-alpha.txt -|7: 2 -|8: -|16: 1 alpha body Find +| 1 Find zqm SPC f +== snap armed grid=120x41 cursor=7,23 +|3: 1 Find zqm Find +|22: ^ +Search 1/5 Del +|23: Find +|24: here.txt +|25: other.txt +|26: sub/ZQMARK-beta.txt +|27: sub/nest/zqmark-gamma.txt +|28: zqmark-alpha.txt +|32: /tmp/pardes-snap/find/cwd/+Preview Del +|33: 1 +== snap typing grid=120x41 cursor=10,23 +|3: 1 Find zqm +|22: ^ +Search 1/3 Del +|23: Find zqm +|24: zqmark-alpha.txt +|25: sub/ZQMARK-beta.txt +|26: sub/nest/zqmark-gamma.txt +|27: +|28: +|32: /tmp/pardes-snap/find/cwd/zqmark-alpha.txt Del +|33: 1 alpha body +== snap next grid=120x41 cursor=10,23 +|22: ^ +Search 2/3 Del +|32: /tmp/pardes-snap/find/cwd/sub/ZQMARK-beta.txt Del +|33: 1 beta body +== snap promoted grid=120x41 cursor=7,33 +|22: +Search 2/3 Save Unattach Del +|32: /tmp/pardes-snap/find/cwd/sub/ZQMARK-beta.txt Save Tty Collapse Del +== snap nomatch grid=120x41 cursor=11,14 +|13: ^ +Search 0 Del +|14: Find zzqq +|22: +|23: /tmp/pardes-snap/find/cwd/+Preview Del +|24: 1 +|25: +|26: +== snap cancel grid=120x41 cursor=7,3 +|13: +|14: +|22: +Search 2/3 Save Unattach Del +|23: Find zqm +|24: zqmark-alpha.txt +|25: sub/ZQMARK-beta.txt +|26: sub/nest/zqmark-gamma.txt +== snap topbar grid=120x41 cursor=14,3 +|3: 1 Find zqm Find +|13: +Search 1/3 Del +|14: Find zqm +|15: zqmark-alpha.txt +|16: sub/ZQMARK-beta.txt +|17: sub/nest/zqmark-gamma.txt +|22: +|23: /tmp/pardes-snap/find/cwd/zqmark-alpha.txt Del +|24: 1 alpha body +|25: +|26: diff --git a/test/snapshots/find.snap b/test/snapshots/find.snap index b2e36973..17470040 100644 --- a/test/snapshots/find.snap +++ b/test/snapshots/find.snap @@ -1,19 +1,18 @@ -# The Find builtin (SPC f f) = `fd`, in-core: it arms the SAME tag input `/` -# does, but Enter walks the pane's DIRECTORY instead of its text and writes one -# matching path per row into a "+Search" OUTPUT BUFFER. Every row is therefore -# an ordinary look target, which is the whole point: n/N SELECT the next/prev -# one with no code of their own, and the look chord — Enter, the same one that -# opens a path anywhere else — is what OPENS it. Focus then follows the file -# that opened, but the look was made FROM the results buffer, so the next n -# resumes stepping that same list. Where each pane lands is acme's placement -# (docs/typ/guide.typ, where new panes go): under the text of the pane with the -# most blank rows. The walk skips .git, matches the NAME -# case-insensitively, and sorts (readdir order is not stable). `SPC f s` is -# Save, which moved out of `w` to make this group. +# SPC f f: a query pane under the pane (Query.zig), line 1 `Find `, typed +# into. The files below the pane's directory are listed once, on the disk +# engine's worker (rg --files when it is on PATH, else the sorted walk: both +# pass over .git), and each key scores them fuzzily (pick's scorer), the best +# first, the matched letters tinted. The current one is shown in the +# +Preview under the query pane, born with it so nothing moves later; +# Ctrl-n / Ctrl-p step it, never the pointer. Enter makes the preview the +# file's pane where it stands. Esc while typing closes the query pane and +# gives its rows back. A query that matches nothing is a count of 0, not an +# exit. B2 on `Find` with a selection asks with that word, the keyboard +# staying in the text. dirmk sub dirmk sub/nest dirmk .git -file here.txt Find +file here.txt Find zqm file zqmark-alpha.txt alpha body file sub/ZQMARK-beta.txt beta body file sub/nest/zqmark-gamma.txt gamma body @@ -22,108 +21,51 @@ file .git/zqmark-hidden.txt hidden body start 41 120 here.txt wait 8000 here.txt stable 700 20000 -# SPC f is a GROUP now (Find + New + Save): the indicator stays on the tag +# SPC f is a group (Find, New, Save, Recent, Grep): the indicator waits key space key f stable 400 5000 snap group -# ... and the second f arms the input, marker visible in the tag +# the second f opens the query pane: every file listed, line 1 `Find ` key f -stable 400 5000 +wait 10000 zqmark-alpha.txt +stable 700 15000 snap armed text zqm -stable 400 5000 -snap typing -# Enter walks: three hits, sorted, .git's copy skipped, other.txt not matched -key enter -wait 10000 zqmark-alpha.txt stable 700 15000 -snap results -# n SELECTS row 1 and Enter looks it — a path, so the file OPENS, under the -# list's text, and each file after it under the one before. -key space j n -key enter +snap typing +# the next one current, its text in the preview +key c-n wait 10000 beta body stable 700 15000 -snap first -snapstyle first -key space j n -key enter -wait 10000 gamma body -stable 700 15000 -snap second -key space j n -key enter -wait 10000 alpha body -stable 700 15000 -snap third -# N walks back up one row; Enter looks it, and the file is already open, so -# the look just focuses it -key space j p +snap next +# Enter: the preview is that file's pane now, where it stood key enter stable 700 15000 -snap back -# executing the WORD Find (middle-click in a body) arms the same input — the -# enum IS the dispatch — and Esc abandons it. The input is its own line, so an -# abandoned one leaves nothing behind in the tag -press middle 8 4 -release middle 8 4 -stable 700 10000 -snap word -key esc -settle 100 -stable 400 5000 -snap cancel -# every search is asked from a PANE, and both a look and now a step leave you -# somewhere else — so click back into here.txt first. That is not bookkeeping: -# a search never refills the buffer it was asked FROM (fillResults skips it), -# so `owned by here.txt` is the whole premise of the two steps below. +snap promoted +# a second Find from here.txt reuses its query pane; nothing found is 0 press left 8 4 release left 8 4 stable 400 5000 -# a no-match walk opens an empty list of its own, under the last file's text. key space key f key f text zzqq -key enter -stable 700 10000 -# n does not stop on the empty list, because the walk is a RING across panes -# rather than one buffer's rows: with nothing look-able here it carries on -# into the list that DOES have some — the zqm one — and resumes it one row -# past where the N above left it. Nothing opens; only the selection moved. -key space j n -stable 400 5000 +stable 700 15000 snap nomatch -# ... and asking for `zqm` AGAIN re-arms the list it ALREADY filled instead of -# stacking an identical twin under the empty one — even though the step above -# left the cursor sitting in the zqm list, so the reuse is by what a buffer -# HOLDS (this search, this pattern, this directory), not by which one anything -# happens to point at. Asked from here.txt again (the click, as above), and -# the LIST it rewrites is therefore the `nomatch` frame unchanged, down to the -# byte — only the cursor comes back with it. -press left 8 4 -release left 8 4 -stable 400 5000 -key space -key f -key f -text zqm -key enter -wait 10000 zqmark-alpha.txt +# Esc: the kept rows of the last query are back +key esc +settle 100 stable 700 15000 -snap refit -# Find is a TOPBAR word too: the same -# builtin the leader path runs, reached with the mouse. Chorded — a selection -# held when it runs IS the argument — so dragging over `alpha` and clicking -# Find walks for that name with nothing typed and no input armed. Row 17 is -# `alpha body`: the three found files stack in the order the looks above -# OPENED them, which is beta, gamma, alpha down the column. -press left 8 17 -drag left 13 17 -release left 13 17 +snap cancel +# B2 on Find with `zqm` selected in here.txt: the query pane under it, the +# keyboard still in here.txt +press left 13 4 +drag left 15 4 +release left 15 4 stable 400 5000 press middle @Find 1 release middle @Find 1 +wait 10000 Find zqm stable 700 15000 snap topbar diff --git a/test/snapshots/fsearch.golden b/test/snapshots/fsearch.golden index 62c37c25..5de12bab 100644 --- a/test/snapshots/fsearch.golden +++ b/test/snapshots/fsearch.golden @@ -19,78 +19,69 @@ | /tmp/pardes-snap/fsearch/cwd Tty+bash Save Mode Filter Collapse Del | ls | g.txt -== snap typing grid=180x31 cursor=89,7 -|7: 1 l1 /MARK -== snap results grid=180x31 cursor=10,8 -|7: 1 l1 -|21: /tmp/pardes-snap/fsearch/cwd/+Search Save Tty Collapse LocationsConfig Del -|22: 1 g.txt:2:1-4 -|23: 2 MARK a -|24: 3 g.txt:6:1-4 -|25: 4 MARK b -|26: 5 g.txt:10:1-4 -|27: 6 MARK c -|28: 7 -== style results grid=180x31 +== snap slash grid=180x31 cursor=3,10 +|9: ^ +Search 0 Del +|10: / +|11: +|12: +|13: +|14: +|15: +|16: +== snap typing grid=180x31 cursor=7,10 +|9: ^ +Search 1/3 Del +|10: /MARK +|11: 2 MARK a +|12: 6 MARK b +|13: 10 MARK c +== style typing grid=180x31 |0: 0-1 d,#1d2824, 2-179 #b2c3b8,#1d2824, |1: 0-1 d,#887455, 2-89 #becfc4,#314738, 90-91 #becfc4,#887455, 92-179 #b2c3b8,#1d2824, |2: 0-1 d,#496656, 2-30 #b2c3b8,#1d2824, 31-39 #d3b0d9,#1d2824, 40-89 #b2c3b8,#1d2824, 90-91 #b2c3b8,#496656, 92-120 #b2c3b8,#1d2824, 121-129 #d3b0d9,#1d2824, 130-179 #b2c3b8,#1d2824, |3: 0-0 d,#608269, 1-1 d,#0d1410, 2-89 #e5eee5,#0d1410, 90-90 #e5eee5,#608269, 91-179 #e5eee5,#0d1410, |4: 0-0 d,#608269, 1-1 d,#0d1410, 2-89 #e5eee5,#0d1410, 90-90 #e5eee5,#608269, 91-179 #e5eee5,#0d1410, |5: 0-0 d,#608269, 1-89 d,#0d1410, 90-90 d,#608269, 91-179 d,#0d1410, -|6: 0-1 d,#add38a, 2-30 #becfc4,#314738, 31-36 #dfbce5,#314738, 37-89 #becfc4,#314738, 90-90 #becfc4,#608269, 91-179 #becfc4,#0d1410, -|7: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-89 #e5eee5,#0d1410, 90-90 #e5eee5,#608269, 91-179 #e5eee5,#0d1410, -|8: 0-0 d,#608269, 1-1 d,#0d1410, 2-4 d,#0d1410,b 5-6 #616f64,#0d1410,b 7-10 #f5f7ee,#3c614a, 11-11 #f5f7ee,#0d1410, 12-89 #e5eee5,#0d1410, 90-90 #e5eee5,#608269, 91-179 #e5eee5,#0d1410, -|9: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-89 #e5eee5,#0d1410, 90-90 #e5eee5,#608269, 91-179 #e5eee5,#0d1410, -|10: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-89 #e5eee5,#0d1410, 90-90 #e5eee5,#608269, 91-179 #e5eee5,#0d1410, -|11: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-89 #e5eee5,#0d1410, 90-90 #e5eee5,#608269, 91-179 #e5eee5,#0d1410, -|12: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-89 #e5eee5,#0d1410, 90-90 #e5eee5,#608269, 91-179 #e5eee5,#0d1410, -|13: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-89 #e5eee5,#0d1410, 90-90 #e5eee5,#608269, 91-179 #e5eee5,#0d1410, -|14: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-89 #e5eee5,#0d1410, 90-90 #e5eee5,#608269, 91-179 #e5eee5,#0d1410, -|15: 0-0 d,#152019, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-89 #e5eee5,#0d1410, 90-90 #e5eee5,#608269, 91-179 #e5eee5,#0d1410, -|16: 0-0 d,#152019, 1-3 d,#0d1410, 4-6 #59675c,#0d1410, 7-89 #e5eee5,#0d1410, 90-90 #e5eee5,#608269, 91-179 #e5eee5,#0d1410, +|6: 0-1 d,#496656, 2-30 #b2c3b8,#1d2824, 31-36 #d3b0d9,#1d2824, 37-89 #b2c3b8,#1d2824, 90-90 #b2c3b8,#608269, 91-179 #b2c3b8,#0d1410, +|7: 0-0 d,#5e4923, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-89 #e5eee5,#0d1410, 90-90 #e5eee5,#608269, 91-179 #e5eee5,#0d1410, +|8: 0-0 d,#5e4923, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-10 #f5f7ee,#3c614a, 11-11 #f5f7ee,#0d1410, 12-89 #e5eee5,#0d1410, 90-90 #e5eee5,#608269, 91-179 #e5eee5,#0d1410, +|9: 0-1 #000000,#add38a, 2-89 #becfc4,#314738, 90-90 #becfc4,#608269, 91-179 #becfc4,#0d1410, +|10: 0-0 d,#608269, 1-1 d,#0d1410, 2-89 #e5eee5,#0d1410, 90-90 #e5eee5,#608269, 91-179 #e5eee5,#0d1410, +|11: 0-0 d,#608269, 1-5 d,#0d1410, 6-8 #59675c,#0d1410, 9-12 #f7e4a5,#5e4923, 13-13 #f7e4a5,#0d1410, 14-89 #e5eee5,#0d1410, 90-90 #e5eee5,#608269, 91-179 #e5eee5,#0d1410, +|12: 0-0 d,#608269, 1-5 d,#0d1410, 6-8 #59675c,#0d1410, 9-12 #f7e4a5,#352e19, 13-13 #f7e4a5,#0d1410, 14-89 #e5eee5,#0d1410, 90-90 #e5eee5,#608269, 91-179 #e5eee5,#0d1410, +|13: 0-0 d,#608269, 1-4 d,#0d1410, 5-8 #59675c,#0d1410, 9-12 #f7e4a5,#352e19, 13-13 #f7e4a5,#0d1410, 14-89 #e5eee5,#0d1410, 90-90 #e5eee5,#608269, 91-179 #e5eee5,#0d1410, +|14: 0-0 d,#608269, 1-89 d,#0d1410, 90-90 d,#608269, 91-179 d,#0d1410, +|15: 0-0 d,#608269, 1-89 d,#0d1410, 90-90 d,#608269, 91-179 d,#0d1410, +|16: 0-0 d,#608269, 1-89 d,#0d1410, 90-90 d,#608269, 91-179 d,#0d1410, |17: 0-1 d,#496656, 2-30 #b2c3b8,#1d2824, 31-39 #d3b0d9,#1d2824, 40-89 #b2c3b8,#1d2824, 90-90 #b2c3b8,#608269, 91-179 #b2c3b8,#0d1410, |18: 0-0 d,#608269, 1-1 d,#0d1410, 2-89 #e5eee5,#0d1410, 90-90 #e5eee5,#608269, 91-179 #e5eee5,#0d1410, |19: 0-0 d,#608269, 1-1 d,#0d1410, 2-89 #e5eee5,#0d1410, 90-90 #e5eee5,#608269, 91-179 #e5eee5,#0d1410, |20: 0-0 d,#608269, 1-89 d,#0d1410, 90-90 d,#608269, 91-179 d,#0d1410, -|21: 0-1 d,#496656, 2-30 #b2c3b8,#1d2824, 31-38 #d3b0d9,#1d2824, 39-89 #b2c3b8,#1d2824, 90-90 #b2c3b8,#608269, 91-179 #b2c3b8,#0d1410, -|22: 0-0 d,#608269, 1-4 d,#0d1410, 5-89 #59675c,#0d1410, 90-90 #59675c,#608269, 91-179 #59675c,#0d1410, -|23: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-10 #f7e4a5,#5e4923, 11-11 #f7e4a5,#0d1410, 12-89 #e5eee5,#0d1410, 90-90 #e5eee5,#608269, 91-179 #e5eee5,#0d1410, -|24: 0-0 d,#608269, 1-4 d,#0d1410, 5-89 #59675c,#0d1410, 90-90 #59675c,#608269, 91-179 #59675c,#0d1410, -|25: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-10 #f7e4a5,#5e4923, 11-11 #f7e4a5,#0d1410, 12-89 #e5eee5,#0d1410, 90-90 #e5eee5,#608269, 91-179 #e5eee5,#0d1410, -|26: 0-0 d,#608269, 1-4 d,#0d1410, 5-89 #59675c,#0d1410, 90-90 #59675c,#608269, 91-179 #59675c,#0d1410, -|27: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-10 #f7e4a5,#5e4923, 11-11 #f7e4a5,#0d1410, 12-89 #e5eee5,#0d1410, 90-90 #e5eee5,#608269, 91-179 #e5eee5,#0d1410, -|28: 0-0 d,#608269, 1-4 d,#0d1410, 5-89 #59675c,#0d1410, 90-90 #59675c,#608269, 91-179 #59675c,#0d1410, +|21: 0-0 d,#608269, 1-89 d,#0d1410, 90-90 d,#608269, 91-179 d,#0d1410, +|22: 0-0 d,#608269, 1-89 d,#0d1410, 90-90 d,#608269, 91-179 d,#0d1410, +|23: 0-0 d,#608269, 1-89 d,#0d1410, 90-90 d,#608269, 91-179 d,#0d1410, +|24: 0-0 d,#608269, 1-89 d,#0d1410, 90-90 d,#608269, 91-179 d,#0d1410, +|25: 0-0 d,#608269, 1-89 d,#0d1410, 90-90 d,#608269, 91-179 d,#0d1410, +|26: 0-0 d,#608269, 1-89 d,#0d1410, 90-90 d,#608269, 91-179 d,#0d1410, +|27: 0-0 d,#608269, 1-89 d,#0d1410, 90-90 d,#608269, 91-179 d,#0d1410, +|28: 0-0 d,#608269, 1-89 d,#0d1410, 90-90 d,#608269, 91-179 d,#0d1410, |29: 0-0 d,#608269, 1-89 d,#0d1410, 90-90 d,#608269, 91-179 d,#0d1410, |30: 0-0 d,#608269, 1-89 d,#0d1410, 90-90 d,#608269, 91-179 d,#0d1410, -== snap second grid=180x31 cursor=10,12 -== snap third grid=180x31 cursor=10,12 +== snap ctrln grid=180x31 cursor=7,10 |7: 5 l5 |8: 6 MARK b -|9: 7 l7 -|10: 8 l8 -|11: 9 l9 -|12: 10 MARK c -|13: 11 l11 -|14: 12 l12 -|15: -|16: -== snap back grid=180x31 cursor=10,12 -|7: 1 l1 -|8: 2 MARK a -|9: 3 l3 -|10: 4 l4 -|11: 5 l5 -|12: 6 MARK b -|13: 7 l7 -|14: 8 l8 -|15: 9 l9 -|16: 10 MARK c -== snap cancel grid=180x31 cursor=10,12 -== snap nomatch grid=180x31 cursor=7,26 -|11: /tmp/pardes-snap/fsearch/cwd/+Search Save Tty Collapse LocationsConfig Del -|12: 1 +|9: ^ +Search 2/3 Del +== snap landed grid=180x31 cursor=10,8 +|9: +Search 2/3 Save Unattach Del +== snap n grid=180x31 cursor=10,8 +|7: 9 l9 +|8: 10 MARK c +== snap N grid=180x31 cursor=10,7 +|7: 6 MARK b +|8: 7 l7 +== snap cancel grid=180x31 cursor=10,7 +== snap nomatch grid=180x31 cursor=7,10 +|9: ^ +Search 0 Del +|10: /zzqq +|11: +|12: |13: -|14: -|15: -|16: diff --git a/test/snapshots/fsearch.snap b/test/snapshots/fsearch.snap index 431e7126..fbb9baeb 100644 --- a/test/snapshots/fsearch.snap +++ b/test/snapshots/fsearch.snap @@ -1,13 +1,13 @@ -# `/` file search: the pattern types into the tag (persistent, no popup); -# Enter searches the buffer in-core and writes `path:LINE:COL-ENDCOL text` into -# a +Search OUTPUT BUFFER (a file pane with no file behind it — no Save in its -# tag) — AND GOES TO THE FIRST HIT, which is the step `n` is and the look Enter -# is, run for you in that buffer. From there n/N SELECT the next/prev row and -# open nothing, and Enter — the look chord — is what scrolls the file pane to -# the hit AND SELECTS IT: the row names the match's whole span, not just where -# it starts. Esc abandons the input; a no-match search opens an EMPTY buffer -# (every search gets its own, stacked under the pane) with nothing in it for n -# to stop on, and goes nowhere. +# `/` in a file: its query pane under it (Query.zig), line 1 `/` and the +# pattern, typed into; nothing on the notice band. Each key searches the +# file again (a regex, any case unless it has a capital): every match is +# tinted and ticked on the scroll rail, the first at or after the cursor +# selected and in view, and the rows under line 1 are the lines holding a +# match, a line number in the gutter. Ctrl-n steps while typing; Enter puts +# the keyboard on the match, the pattern in `/`, and keeps the rows as text; +# n / N then step the matches in the file, round the end without a word. A +# later `/` reuses the pane; Esc while typing brings the kept rows back. A +# pattern that matches nothing is a count of 0, not an exit. file g.txt l1\nMARK a\nl3\nl4\nl5\nMARK b\nl7\nl8\nl9\nMARK c\nl11\nl12 # Builtins announce themselves by default, and an announcement is a band at # the top of the body -- which moves every row this script clicks. What the @@ -30,51 +30,32 @@ release right 6 9 wait 10000 MARK a stable 700 15000 snap opened -# / starts the search input in the tag; the pattern is visible while typing key / stable 400 5000 +snap slash text MARK stable 400 5000 snap typing +snapstyle typing +key c-n +stable 400 5000 +snap ctrln key enter -# Locations stack the target under its line now, so the two halves are -# two rows: wait for both rather than for one joined line. -wait 10000 g.txt:2:1-4 -wait 10000 MARK a stable 700 10000 -# ...and the submit already looked result 1: the file scrolled to line 2 and -# the four cells the pattern matched there came up selected — the styles below -# are what prove the second half of that. No `n` was pressed to get here. -snap results -snapstyle results -# n/N walk on from there, one row of the list per press, Enter looking what -# the step selected -key space j n -key enter -stable 700 15000 -snap second -key space j n -key enter -stable 700 15000 -snap third -# N walks back up to result 2 (line 6), Enter looks it -key space j p -key enter -stable 700 15000 -snap back -# Esc abandons the input: the tag tail is restored +snap landed +text n +stable 400 5000 +snap n +text N +stable 400 5000 +snap N key / text zz key esc settle 100 stable 400 5000 snap cancel -# a no-match search: nothing in the empty list for n to stop on, so the ring -# carries it back into the list that has rows and it resumes there key / text zzqq -key enter stable 700 10000 -key space j n -stable 400 5000 snap nomatch diff --git a/test/snapshots/grep.golden b/test/snapshots/grep.golden index 957096c3..6dbe19fa 100644 --- a/test/snapshots/grep.golden +++ b/test/snapshots/grep.golden @@ -19,22 +19,28 @@ | /tmp/pardes-snap/grep/cwd Tty+bash Save Mode Filter Collapse Del | ls | a.txt noise.txt sub -== snap typing grid=180x31 cursor=89,7 -|7: 1 hello TARGET one Grep /TARGET -== snap results grid=180x31 cursor=7,7 -|7: 1 hello TARGET one -|21: /tmp/pardes-snap/grep/cwd/+Search Save Tty Collapse LocationsConfig Del -|22: 1 a.txt:1:7-12 hello TARGET one -|23: 2 a.txt:3:6-11 last TARGET line -|24: 3 sub/b.txt:2:1-6 TARGET inside sub -|25: 4 -== snap first grid=180x31 cursor=18,7 -== snap opened-hit grid=180x31 cursor=12,12 -|10: /tmp/pardes-snap/grep/cwd/sub/b.txt Save Tty Collapse Del -|11: 1 deep -|12: 2 TARGET inside sub -== snap nomatch grid=180x31 cursor=2,4 -|25: /tmp/pardes-snap/grep/cwd/sub/+Search Save Tty Collapse LocationsConfig Del -|26: 1 -== snap chordsel grid=180x31 cursor=19,7 -== snap chord grid=180x31 cursor=19,7 +== snap typing grid=180x31 cursor=13,10 +|9: ^ +Search 1/3 Del +|10: Grep TARGET +|11: a.txt +|12: 1 hello TARGET one +|13: /tmp/pardes-snap/grep/cwd/+Preview Del +|14: 1 +== snap second grid=180x31 cursor=13,10 +|7: 2 nothing here +|8: 3 last TARGET line +|9: ^ +Search 2/3 Del +== snap preview grid=180x31 cursor=13,10 +|9: ^ +Search 3/3 Del +|13: /tmp/pardes-snap/grep/cwd/sub/b.txt Del +|14: 1 deep +|15: 2 TARGET inside sub +== snap opened-hit grid=180x31 cursor=12,15 +|9: +Search 3/3 Save Unattach Del +|13: /tmp/pardes-snap/grep/cwd/sub/b.txt Save Tty Collapse Del +== snap nomatch grid=180x31 cursor=11,15 +|14: ^ +Search 0 Del +|15: Grep zzqq +== snap esc grid=180x31 cursor=12,15 +|14: 1 deep +|15: 2 TARGET inside sub diff --git a/test/snapshots/grep.snap b/test/snapshots/grep.snap index b3ce2947..16e61d20 100644 --- a/test/snapshots/grep.snap +++ b/test/snapshots/grep.snap @@ -1,31 +1,20 @@ -# The Grep builtin (topbar word, `SPC f g`): `grep -R`, in-core. It arms the -# SAME tag input `/` and Find use, but the walk reads file CONTENTS under every -# pane's directory at once — minus any directory another pane's already -# contains, so a tree two panes sit in is searched ONCE and every hit appears -# once. A row is `path:LINE:COL-ENDCOL text` — the match's whole span, so -# looking it SELECTS the hit — with the path RELATIVE to the directory -# of the pane that asked — the same directory its results buffer is named in, -# so the short name resolves; only a hit from outside that tree stays absolute. -# n/N SELECT the next/prev row like any other result list and open nothing — -# one press per row, the location at its head, never the matched text after it; -# Enter looks what they leave selected, and a row pointing into a file nothing -# has open yet opens it. +# The Grep builtin (topbar word, `SPC f g`): the query pane under the pane +# that asked, line 1 `Grep ` and the text, the lines of the files below its +# directory holding it (literally, any case unless it has a capital), on the +# disk engine's worker once the typing pauses: rg --json when it is on PATH, +# else the sorted walk. The rows sit under their file's name, a line number +# in the gutter. A hit in a file an open pane shows is shown there; one in a +# file nothing shows, in the +Preview under the query pane, which Enter makes +# the file's pane. A query that matches nothing is a count of 0, and Esc +# while typing brings the kept rows back. dirmk sub file a.txt hello TARGET one\nnothing here\nlast TARGET line file sub/b.txt deep\nTARGET inside sub file noise.txt nothing to see -# Builtins announce themselves by default, and an announcement is a band at -# the top of the body -- which moves every row this script clicks. What the -# verbs do is what is under test, not the announcement. config Verbose off -# The stacked layout spends two rows on each hit, which puts the third one -# below the fold of this results pane; the claim here is which hits there are. -config LocationsConfig layout:inline start 31 180 -n 3 wait 8000 a.txt stable 700 20000 -# open a.txt: a SECOND pane, whose directory the shell's cwd already covers — -# its root is dropped, which is what keeps the hits below un-duplicated press left 5 9 release left 5 9 stable 400 5000 @@ -39,70 +28,34 @@ release right 6 9 wait 10000 hello TARGET stable 700 15000 snap opened -# middle-click Grep on the topbar: the input -# arms on the ACTIVE pane's tag, exactly where `/` would have typed +# middle-click Grep on the topbar: the query pane under a.txt, typed into press middle @Grep 1 release middle @Grep 1 stable 400 5000 text TARGET -stable 400 5000 -snap typing -# Enter walks: two hits in a.txt, one in sub/b.txt, sorted by path — and the -# file that holds none of them contributes no row. -key enter -wait 10000 sub/b.txt:2:1 +# three lines (the pane is short: its count says how many) +wait 10000 +Search 1/3 stable 700 15000 -snap results -# n selects the first row and Enter looks it: absolute path, line 1, columns -# 7..12 (`TARGET`), and those six cells come up selected -key space j n -key enter +snap typing +# a.txt's hits are shown in a.txt; sub/b.txt's in the preview +key c-n stable 700 15000 -snap first -# ...and stepping on into sub/b.txt, then looking it, opens the file nothing -# had open -key space j n -key enter +snap second +key c-n +wait 10000 deep stable 700 15000 -key space j n +snap preview key enter -wait 10000 TARGET inside sub stable 700 15000 snap opened-hit -# a pattern nothing holds: an empty list of its own, with nothing in it for n -# to stop on — so the ring carries that step out of it and on round. It lands -# in the SHELL, whose `ls` row is free text and steps word by word: the TARGET -# list is standing on its last row, and a row-grained walk has nothing left in -# it to offer. The look above is why these read the way they do: it left the -# cursor in sub/b.txt, so the empty list is named in sub/ rather than cwd/, and -# it left the hit SELECTED there (a ranged result row is one a look selects). -# Armed from the LEADER, not the topbar word, because of that selection: a -# topbar execute chords whatever is selected into its argument, so a -# middle-click here would run `Grep TARGET` and never ask for a pattern at -# all. The leader path runs the builtin with no argument, which is what this -# step is about; the chord itself is the last two snaps below. key space key f key g stable 400 5000 text zzqq -key enter stable 700 10000 -key space j n -stable 400 5000 snap nomatch -# the acme chord: a builtin executed with a SELECTION held takes it as the -# argument, so dragging over `TARGET` in a.txt and then clicking Grep runs the -# walk on that word at once — no tag input, nothing typed. TARGET already has -# a list open from above, so this refills THAT one; only the zzqq list below is -# a second buffer, because only it is a different search. -press left @TARGET 8 -drag left @TARGET+6 8 -release left @TARGET+6 8 +key esc +settle 100 stable 400 5000 -snap chordsel -press middle @Grep 1 -release middle @Grep 1 -wait 10000 sub/b.txt:2:1 -stable 700 15000 -snap chord +snap esc diff --git a/test/snapshots/lookrange.golden b/test/snapshots/lookrange.golden index 4a286faa..86a4b0ac 100644 --- a/test/snapshots/lookrange.golden +++ b/test/snapshots/lookrange.golden @@ -68,28 +68,31 @@ |12: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-149 #e5eee5,#0d1410, |15: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-11 #e5eee5,#0d1410, 12-149 #f5f7ee,#3c614a, |16: 0-0 d,#608269, 1-1 d,#0d1410, 2-4 d,#0d1410,b 5-6 #616f64,#0d1410,b 7-10 #f5f7ee,#3c614a, 11-149 #f5f7ee,#0d1410, -== snap hit1 grid=150x31 cursor=15,14 -|17: /tmp/pardes-snap/lookrange/cwd/+Search Save Tty Collapse LocationsConfig Del -|18: 1 r.txt:7:4-9 -|19: 2 gg NEEDLE gg -|20: 3 r.txt:8:6-11 -|21: 4 hhhh NEEDLE -|22: 5 +== snap hit1 grid=150x31 cursor=17,15 +|21: +Search 2/2 Save Unattach Del +|22: /NEEDLE +|23: 7 gg NEEDLE gg +|24: 8 hhhh NEEDLE == style hit1 grid=150x31 -|14: 0-0 d,#608269, 1-1 d,#0d1410, 2-4 d,#0d1410,b 5-6 #616f64,#0d1410,b 7-9 #e5eee5,#0d1410, 10-15 #f5f7ee,#3c614a, 16-16 #f5f7ee,#0d1410, 17-149 #e5eee5,#0d1410, -|15: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-149 #e5eee5,#0d1410, -|16: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-149 #e5eee5,#0d1410, -|17: 0-1 d,#496656, 2-32 #b2c3b8,#1d2824, 33-40 #d3b0d9,#1d2824, 41-149 #b2c3b8,#1d2824, -|18: 0-0 d,#608269, 1-4 d,#0d1410, 5-149 #59675c,#0d1410, -|19: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-9 #e5eee5,#0d1410, 10-15 #f7e4a5,#5e4923, 16-16 #f7e4a5,#0d1410, 17-149 #e5eee5,#0d1410, -|20: 0-0 d,#608269, 1-4 d,#0d1410, 5-149 #59675c,#0d1410, -|21: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-11 #e5eee5,#0d1410, 12-17 #f7e4a5,#5e4923, 18-149 #f7e4a5,#0d1410, -|22: 0-0 d,#608269, 1-4 d,#0d1410, 5-149 #59675c,#0d1410, -== snap hit2 grid=150x31 cursor=17,15 -== style hit2 grid=150x31 -|14: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-149 #e5eee5,#0d1410, +|14: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-9 #e5eee5,#0d1410, 10-15 #e5eee5,#352e19, 16-149 #e5eee5,#0d1410, |15: 0-0 d,#608269, 1-1 d,#0d1410, 2-4 d,#0d1410,b 5-6 #616f64,#0d1410,b 7-11 #e5eee5,#0d1410, 12-17 #f5f7ee,#3c614a, 18-149 #f5f7ee,#0d1410, -== snap back grid=150x31 cursor=15,14 -== style back grid=150x31 +|16: 0-0 d,#5e4923, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-149 #e5eee5,#0d1410, +|18: 0-0 d,#e5eee5, 1-149 d,#0d1410, +|21: 0-1 d,#496656, 2-149 #b2c3b8,#1d2824, +|22: 0-0 d,#608269, 1-1 d,#0d1410, 2-149 #e5eee5,#0d1410, +|23: 0-0 d,#608269, 1-5 d,#0d1410, 6-8 #59675c,#0d1410, 9-11 #e5eee5,#0d1410, 12-17 #f7e4a5,#352e19, 18-18 #f7e4a5,#0d1410, 19-149 #e5eee5,#0d1410, +|24: 0-0 d,#608269, 1-1 d,#0d1410, 2-5 d,#3c614a, 6-149 #f5f7ee,#3c614a, +== snap hit2 grid=150x31 cursor=15,14 +== style hit2 grid=150x31 |14: 0-0 d,#608269, 1-1 d,#0d1410, 2-4 d,#0d1410,b 5-6 #616f64,#0d1410,b 7-9 #e5eee5,#0d1410, 10-15 #f5f7ee,#3c614a, 16-16 #f5f7ee,#0d1410, 17-149 #e5eee5,#0d1410, -|15: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-149 #e5eee5,#0d1410, +|15: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-11 #e5eee5,#0d1410, 12-17 #e5eee5,#352e19, 18-149 #e5eee5,#0d1410, +|16: 0-0 d,#e5eee5, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-149 #e5eee5,#0d1410, +|18: 0-0 d,#5e4923, 1-149 d,#0d1410, +|23: 0-0 d,#608269, 1-5 d,#0d1410, 6-8 #59675c,#0d1410, 9-11 #e5eee5,#0d1410, 12-17 #f7e4a5,#5e4923, 18-18 #f7e4a5,#0d1410, 19-149 #e5eee5,#0d1410, +== snap back grid=150x31 cursor=17,15 +== style back grid=150x31 +|14: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-9 #e5eee5,#0d1410, 10-15 #e5eee5,#352e19, 16-149 #e5eee5,#0d1410, +|15: 0-0 d,#608269, 1-1 d,#0d1410, 2-4 d,#0d1410,b 5-6 #616f64,#0d1410,b 7-11 #e5eee5,#0d1410, 12-17 #f5f7ee,#3c614a, 18-149 #f5f7ee,#0d1410, +|16: 0-0 d,#5e4923, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-149 #e5eee5,#0d1410, +|18: 0-0 d,#e5eee5, 1-149 d,#0d1410, +|23: 0-0 d,#608269, 1-5 d,#0d1410, 6-8 #59675c,#0d1410, 9-11 #e5eee5,#0d1410, 12-17 #f7e4a5,#352e19, 18-18 #f7e4a5,#0d1410, 19-149 #e5eee5,#0d1410, diff --git a/test/snapshots/lookrange.snap b/test/snapshots/lookrange.snap index eb1db60a..5133e911 100644 --- a/test/snapshots/lookrange.snap +++ b/test/snapshots/lookrange.snap @@ -51,28 +51,24 @@ release right 12 7 stable 700 15000 snap stale snapstyle stale -# --- and now the first consumer. The look above left r.txt focused, so `/` -# arms on it: the rows it writes carry the match's span, and the submit goes -# straight to the first of them — with the word itself selected, which is the -# whole reason the row spells a range and not a position. +# --- and `/`: its query pane under r.txt, line 1 the pattern, the lines +# holding it as rows (a line number in the gutter, the match tinted); Enter +# puts the keyboard on the match after the cursor, the word itself selected. key / text NEEDLE -key enter -# Locations stack the target under its line now: two rows, two waits. -wait 10000 r.txt:7:4-9 wait 10000 gg NEEDLE gg stable 700 15000 +key enter +stable 700 15000 snap hit1 snapstyle hit1 -# n selects the next row, and the Enter after it goes to that hit -key space j n -key enter +# n: the next match in the text, selected +text n stable 700 15000 snap hit2 snapstyle hit2 -# N walks back onto the first hit; Enter looks it, still selected -key space j p -key enter +# N walks back onto the first, still selected +text N stable 700 15000 snap back snapstyle back diff --git a/test/snapshots/lsp-client.golden b/test/snapshots/lsp-client.golden index c9fad7b7..18ccd775 100644 --- a/test/snapshots/lsp-client.golden +++ b/test/snapshots/lsp-client.golden @@ -15,15 +15,16 @@ | 3 a + b | 4 } | 5 -== snap gr-list grid=100x25 cursor=21,6 +== snap gr-list grid=100x25 cursor=7,14 |3: 1 mod lib; -|15: /tmp/pardes-snap/lsp-client/cwd/+Search Save Tty Collapse LocationsConfig Del -|16: 1 lib.rs:2:8-10 -|17: 2 pub fn add(a: i32, b: i32) -> i32 { -|18: 3 main.rs:4:13-15 -|19: 4 let x = add(1, 2); -|20: 5 main.rs:5:13-15 -|21: 6 let y = add(3, 4); -|22: 7 -== snap gr-opened grid=100x25 cursor=21,7 -== snap gr-back grid=100x25 cursor=21,6 +|13: ^ +Search 1/3 Del +|14: Refs +|15: lib.rs +|16: 2 pub fn add(a: i32, b: i32) -> i32 { +|17: main.rs +|18: 4 let x = add(1, 2); +|19: /tmp/pardes-snap/lsp-client/cwd/+Preview Del +|20: 1 +== snap gr-opened grid=100x25 cursor=21,6 +|13: +Search 2/3 Save Unattach Del +== snap gr-back grid=100x25 cursor=21,7 diff --git a/test/snapshots/lsp-client.snap b/test/snapshots/lsp-client.snap index db94525e..d9827a2a 100644 --- a/test/snapshots/lsp-client.snap +++ b/test/snapshots/lsp-client.snap @@ -6,7 +6,8 @@ # gd on a cross-file Location -> a look: lib.rs opens with `add` selected, # and the message row still carries the server's settled state # ("lsp lspmock: ready") because nothing has cleared it yet. -# gr -> sorted rows, selecting the next occurrence; n/N continue there. +# gr -> the text's query pane, line 1 `Refs`, rows under their files, +# the next occurrence current; n/N step the places in the text. file main.rs mod lib;\n\nfn main() {\n let x = add(1, 2);\n let y = add(3, 4);\n let _ = x + y;\n}\n file lib.rs // mock fixture\npub fn add(a: i32, b: i32) -> i32 {\n a + b\n}\n start 25 100 main.rs @@ -26,12 +27,12 @@ key r wait 10000 add(3, 4) stable 700 15000 snap gr-list -# step from the selected middle row to the last hit, then return -key space j n +# Ctrl-n on line 1 steps to the next hit, Enter lands there; N in the text +# goes back to the one before, round the places in main.rs +key c-n key enter stable 700 15000 snap gr-opened -key space j p -key enter +text N stable 700 15000 snap gr-back diff --git a/test/snapshots/lspdebug.snap b/test/snapshots/lspdebug.snap index ec8d136d..22fa097b 100644 --- a/test/snapshots/lspdebug.snap +++ b/test/snapshots/lspdebug.snap @@ -39,11 +39,8 @@ text client queries key enter wait 10000 client queries wait 10000 definition -# the report sits between the source and the results, so Del asks where its -# rows go: k, back to the source above -key space d -key k -key space w j enter +# Enter left the keyboard in the report, on the match; its query pane is +# attached to it, so one Del closes both, their rows back to the source key space d stable 700 15000 snap report-closed diff --git a/test/snapshots/lsprelpath.golden b/test/snapshots/lsprelpath.golden index d961d6bd..59a3c5d0 100644 --- a/test/snapshots/lsprelpath.golden +++ b/test/snapshots/lsprelpath.golden @@ -1,4 +1,4 @@ -== snap absrow grid=100x35 cursor=21,16 +== snap absrow grid=100x35 cursor=7,17 | Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol | /tmp/pardes-snap/lsprelpath/cwd/sub/parent.zig Save Tty Collapse TreeContext Def Refs Del @@ -9,56 +9,70 @@ | 5 | 6 }; | 7 } -| /tmp/pardes-snap/lsprelpath/cwd/sub/+Search Save Tty Collapse LocationsConfig Del -| 1 /tmp/pardes-snap/lsprelpath/cwd/shade.zig:1:11-15 -| 2 pub const Shade = enum { -| 3 parent.zig:3:22-26 -| 4 pub fn pick(s: shade.Shade) u8 { -| /tmp/pardes-snap/lsprelpath/cwd/shade.zig Save Tty Collapse TreeContext Def Refs Del -| 1 pub const Shade = enum { -| 2 verdigris, -| 3 cinnabar, -| 4 }; -| 5 -== snap abslook grid=100x35 cursor=32,5 +| 8 +| +| +| +| +| +|^ +Search 2/2 Del +| Refs +| /tmp/pardes-snap/lsprelpath/cwd/shade.zig +| 1 pub const Shade = enum { +| parent.zig +| 3 pub fn pick(s: shade.Shade) u8 { +| +| +| +| +| /tmp/pardes-snap/lsprelpath/cwd/sub/+Preview Del +| 1 +== snap abslook grid=100x35 cursor=21,27 |3: 1 const shade = @import("../shade.zig"); +|16: +Search 1/2 Save Unattach Del +|26: /tmp/pardes-snap/lsprelpath/cwd/shade.zig Save Tty Collapse TreeContext Def Refs Del +|27: 1 pub const Shade = enum { +|28: 2 verdigris, +|29: 3 cinnabar, +|30: 4 }; +|31: 5 == style abslook grid=100x35 |0: 0-1 d,#1d2824, 2-99 #b2c3b8,#1d2824, |1: 0-1 d,#887455, 2-99 #becfc4,#314738, -|2: 0-1 d,#add38a, 2-37 #becfc4,#314738, 38-48 #dfbce5,#314738, 49-99 #becfc4,#314738, +|2: 0-1 d,#496656, 2-37 #b2c3b8,#1d2824, 38-48 #d3b0d9,#1d2824, 49-99 #b2c3b8,#1d2824, |3: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-20 #e5eee5,#0d1410, 21-27 #c9a7ed,#0d1410, 28-28 #e5eee5,#0d1410, 29-42 #b8d88a,#0d1410, 43-99 #e5eee5,#0d1410, |4: 0-0 d,#608269, 1-4 d,#0d1410, 5-99 #59675c,#0d1410, -|5: 0-0 d,#608269, 1-1 d,#0d1410, 2-4 d,#0d1410,b 5-6 #616f64,#0d1410,b 7-10 #e5eee5,#0d1410, 11-13 #c9a7ed,#0d1410, 14-27 #e5eee5,#0d1410, 28-32 #f5f7ee,#3c614a, 33-99 #e5eee5,#0d1410, -|6: 0-0 d,#608269, 1-4 d,#0d1410, 5-10 #59675c,#0d1410, 11-24 #c9a7ed,#0d1410, 25-99 #e5eee5,#0d1410, +|5: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-10 #e5eee5,#0d1410, 11-13 #c9a7ed,#0d1410, 14-27 #e5eee5,#0d1410, 28-32 #f5f7ee,#3c614a, 33-99 #e5eee5,#0d1410, +|6: 0-0 d,#e5eee5, 1-4 d,#0d1410, 5-10 #59675c,#0d1410, 11-24 #c9a7ed,#0d1410, 25-99 #e5eee5,#0d1410, |7: 0-0 d,#608269, 1-4 d,#0d1410, 5-99 #59675c,#0d1410, |8: 0-0 d,#608269, 1-4 d,#0d1410, 5-10 #59675c,#0d1410, 11-99 #e5eee5,#0d1410, -|9: 0-0 d,#152019, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-99 #e5eee5,#0d1410, -|10: 0-1 d,#496656, 2-37 #b2c3b8,#1d2824, 38-45 #d3b0d9,#1d2824, 46-99 #b2c3b8,#1d2824, -|11: 0-0 d,#608269, 1-4 d,#0d1410, 5-99 #59675c,#0d1410, -|12: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-16 #e5eee5,#0d1410, 17-21 #f7e4a5,#5e4923, 22-22 #f7e4a5,#0d1410, 23-24 #e5eee5,#0d1410, 25-29 #c9a7ed,#0d1410, 30-99 #e5eee5,#0d1410, -|13: 0-0 d,#608269, 1-4 d,#0d1410, 5-99 #59675c,#0d1410, -|14: 0-0 d,#152019, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-10 #e5eee5,#0d1410, 11-13 #c9a7ed,#0d1410, 14-27 #e5eee5,#0d1410, 28-32 #f7e4a5,#5e4923, 33-99 #e5eee5,#0d1410, -|15: 0-1 d,#496656, 2-33 #b2c3b8,#1d2824, 34-43 #d3b0d9,#1d2824, 44-99 #b2c3b8,#1d2824, -|16: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-16 #e5eee5,#0d1410, 17-21 #f5f7ee,#3c614a, 22-22 #f5f7ee,#0d1410, 23-24 #e5eee5,#0d1410, 25-29 #c9a7ed,#0d1410, 30-99 #e5eee5,#0d1410, -|17: 0-0 d,#608269, 1-4 d,#0d1410, 5-10 #59675c,#0d1410, 11-99 #e5eee5,#0d1410, -|18: 0-0 d,#608269, 1-4 d,#0d1410, 5-10 #59675c,#0d1410, 11-99 #e5eee5,#0d1410, -|19: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-99 #e5eee5,#0d1410, -|20: 0-0 d,#608269, 1-4 d,#0d1410, 5-99 #59675c,#0d1410, -|21: 0-0 d,#608269, 1-99 d,#0d1410, +|9: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-99 #e5eee5,#0d1410, +|10: 0-0 d,#608269, 1-4 d,#0d1410, 5-99 #59675c,#0d1410, +|11: 0-0 d,#608269, 1-99 d,#0d1410, +|12: 0-0 d,#608269, 1-99 d,#0d1410, +|13: 0-0 d,#608269, 1-99 d,#0d1410, +|14: 0-0 d,#608269, 1-99 d,#0d1410, +|15: 0-0 d,#608269, 1-99 d,#0d1410, +|16: 0-1 d,#496656, 2-99 #b2c3b8,#1d2824, +|17: 0-0 d,#608269, 1-1 d,#0d1410, 2-99 #e5eee5,#0d1410, +|18: 0-0 d,#608269, 1-1 d,#0d1410, 2-99 #e5eee5,#0d1410, +|19: 0-0 d,#608269, 1-7 d,#0d1410, 8-10 #59675c,#0d1410, 11-20 #e5eee5,#0d1410, 21-25 #f7e4a5,#5e4923, 26-26 #f7e4a5,#0d1410, 27-99 #e5eee5,#0d1410, +|20: 0-0 d,#608269, 1-1 d,#0d1410, 2-99 #e5eee5,#0d1410, +|21: 0-0 d,#608269, 1-7 d,#0d1410, 8-10 #59675c,#0d1410, 11-31 #e5eee5,#0d1410, 32-36 #f7e4a5,#5e4923, 37-99 #e5eee5,#0d1410, |22: 0-0 d,#608269, 1-99 d,#0d1410, |23: 0-0 d,#608269, 1-99 d,#0d1410, |24: 0-0 d,#608269, 1-99 d,#0d1410, |25: 0-0 d,#608269, 1-99 d,#0d1410, -|26: 0-0 d,#608269, 1-99 d,#0d1410, -|27: 0-0 d,#608269, 1-99 d,#0d1410, -|28: 0-0 d,#608269, 1-99 d,#0d1410, -|29: 0-0 d,#608269, 1-99 d,#0d1410, -|30: 0-0 d,#608269, 1-99 d,#0d1410, -|31: 0-0 d,#608269, 1-99 d,#0d1410, +|26: 0-1 d,#add38a, 2-33 #becfc4,#314738, 34-43 #dfbce5,#314738, 44-99 #becfc4,#314738, +|27: 0-0 d,#608269, 1-1 d,#0d1410, 2-4 d,#0d1410,b 5-6 #616f64,#0d1410,b 7-16 #e5eee5,#0d1410, 17-21 #f5f7ee,#3c614a, 22-22 #f5f7ee,#0d1410, 23-24 #e5eee5,#0d1410, 25-29 #c9a7ed,#0d1410, 30-99 #e5eee5,#0d1410, +|28: 0-0 d,#608269, 1-4 d,#0d1410, 5-10 #59675c,#0d1410, 11-99 #e5eee5,#0d1410, +|29: 0-0 d,#608269, 1-4 d,#0d1410, 5-10 #59675c,#0d1410, 11-99 #e5eee5,#0d1410, +|30: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-99 #e5eee5,#0d1410, +|31: 0-0 d,#608269, 1-4 d,#0d1410, 5-99 #59675c,#0d1410, |32: 0-0 d,#608269, 1-99 d,#0d1410, |33: 0-0 d,#608269, 1-99 d,#0d1410, |34: 0-0 d,#608269, 1-99 d,#0d1410, -== snap subrow grid=100x35 cursor=20,16 +== snap subrow grid=100x35 cursor=7,17 | Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol | /tmp/pardes-snap/lsprelpath/cwd/sub/subdir.zig Save Tty Collapse TreeContext Def Refs Del @@ -69,53 +83,67 @@ | 5 | 6 }; | 7 } -| /tmp/pardes-snap/lsprelpath/cwd/sub/+Search Save Tty Collapse LocationsConfig Del -| 1 inner/tint.zig:1:11-14 -| 2 pub const Tint = enum { -| 3 subdir.zig:3:20-23 -| 4 pub fn hue(t: tint.Tint) u8 { -| /tmp/pardes-snap/lsprelpath/cwd/sub/inner/tint.zig Save Tty Collapse TreeContext Def Refs Del -| 1 pub const Tint = enum { -| 2 ochre, -| 3 indigo, -| 4 }; -| 5 -== snap sublook grid=100x35 cursor=29,5 +| 8 +| +| +| +| +| +|^ +Search 2/2 Del +| Refs +| inner/tint.zig +| 1 pub const Tint = enum { +| subdir.zig +| 3 pub fn hue(t: tint.Tint) u8 { +| +| +| +| +| /tmp/pardes-snap/lsprelpath/cwd/sub/+Preview Del +| 1 +== snap sublook grid=100x35 cursor=20,27 |3: 1 const tint = @import("inner/tint.zig"); +|16: +Search 1/2 Save Unattach Del +|26: /tmp/pardes-snap/lsprelpath/cwd/sub/inner/tint.zig Save Tty Collapse TreeContext Def Refs Del +|27: 1 pub const Tint = enum { +|28: 2 ochre, +|29: 3 indigo, +|30: 4 }; +|31: 5 == style sublook grid=100x35 |0: 0-1 d,#1d2824, 2-99 #b2c3b8,#1d2824, |1: 0-1 d,#887455, 2-99 #becfc4,#314738, -|2: 0-1 d,#add38a, 2-37 #becfc4,#314738, 38-48 #dfbce5,#314738, 49-99 #becfc4,#314738, +|2: 0-1 d,#496656, 2-37 #b2c3b8,#1d2824, 38-48 #d3b0d9,#1d2824, 49-99 #b2c3b8,#1d2824, |3: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-19 #e5eee5,#0d1410, 20-26 #c9a7ed,#0d1410, 27-27 #e5eee5,#0d1410, 28-43 #b8d88a,#0d1410, 44-99 #e5eee5,#0d1410, |4: 0-0 d,#608269, 1-4 d,#0d1410, 5-99 #59675c,#0d1410, -|5: 0-0 d,#608269, 1-1 d,#0d1410, 2-4 d,#0d1410,b 5-6 #616f64,#0d1410,b 7-10 #e5eee5,#0d1410, 11-13 #c9a7ed,#0d1410, 14-25 #e5eee5,#0d1410, 26-29 #f5f7ee,#3c614a, 30-99 #e5eee5,#0d1410, -|6: 0-0 d,#608269, 1-4 d,#0d1410, 5-10 #59675c,#0d1410, 11-24 #c9a7ed,#0d1410, 25-99 #e5eee5,#0d1410, +|5: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-10 #e5eee5,#0d1410, 11-13 #c9a7ed,#0d1410, 14-25 #e5eee5,#0d1410, 26-29 #f5f7ee,#3c614a, 30-99 #e5eee5,#0d1410, +|6: 0-0 d,#e5eee5, 1-4 d,#0d1410, 5-10 #59675c,#0d1410, 11-24 #c9a7ed,#0d1410, 25-99 #e5eee5,#0d1410, |7: 0-0 d,#608269, 1-4 d,#0d1410, 5-99 #59675c,#0d1410, |8: 0-0 d,#608269, 1-4 d,#0d1410, 5-10 #59675c,#0d1410, 11-99 #e5eee5,#0d1410, -|9: 0-0 d,#152019, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-99 #e5eee5,#0d1410, -|10: 0-1 d,#496656, 2-37 #b2c3b8,#1d2824, 38-45 #d3b0d9,#1d2824, 46-99 #b2c3b8,#1d2824, -|11: 0-0 d,#608269, 1-4 d,#0d1410, 5-99 #59675c,#0d1410, -|12: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-16 #e5eee5,#0d1410, 17-20 #f7e4a5,#5e4923, 21-21 #f7e4a5,#0d1410, 22-23 #e5eee5,#0d1410, 24-28 #c9a7ed,#0d1410, 29-99 #e5eee5,#0d1410, -|13: 0-0 d,#608269, 1-4 d,#0d1410, 5-99 #59675c,#0d1410, -|14: 0-0 d,#152019, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-10 #e5eee5,#0d1410, 11-13 #c9a7ed,#0d1410, 14-25 #e5eee5,#0d1410, 26-29 #f7e4a5,#5e4923, 30-99 #e5eee5,#0d1410, -|15: 0-1 d,#496656, 2-43 #b2c3b8,#1d2824, 44-52 #d3b0d9,#1d2824, 53-99 #b2c3b8,#1d2824, -|16: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-16 #e5eee5,#0d1410, 17-20 #f5f7ee,#3c614a, 21-21 #f5f7ee,#0d1410, 22-23 #e5eee5,#0d1410, 24-28 #c9a7ed,#0d1410, 29-99 #e5eee5,#0d1410, -|17: 0-0 d,#608269, 1-4 d,#0d1410, 5-10 #59675c,#0d1410, 11-99 #e5eee5,#0d1410, -|18: 0-0 d,#608269, 1-4 d,#0d1410, 5-10 #59675c,#0d1410, 11-99 #e5eee5,#0d1410, -|19: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-99 #e5eee5,#0d1410, -|20: 0-0 d,#608269, 1-4 d,#0d1410, 5-99 #59675c,#0d1410, -|21: 0-0 d,#608269, 1-99 d,#0d1410, +|9: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-99 #e5eee5,#0d1410, +|10: 0-0 d,#608269, 1-4 d,#0d1410, 5-99 #59675c,#0d1410, +|11: 0-0 d,#608269, 1-99 d,#0d1410, +|12: 0-0 d,#608269, 1-99 d,#0d1410, +|13: 0-0 d,#608269, 1-99 d,#0d1410, +|14: 0-0 d,#608269, 1-99 d,#0d1410, +|15: 0-0 d,#608269, 1-99 d,#0d1410, +|16: 0-1 d,#496656, 2-99 #b2c3b8,#1d2824, +|17: 0-0 d,#608269, 1-1 d,#0d1410, 2-99 #e5eee5,#0d1410, +|18: 0-0 d,#608269, 1-1 d,#0d1410, 2-99 #e5eee5,#0d1410, +|19: 0-0 d,#608269, 1-7 d,#0d1410, 8-10 #59675c,#0d1410, 11-20 #e5eee5,#0d1410, 21-24 #f7e4a5,#5e4923, 25-25 #f7e4a5,#0d1410, 26-99 #e5eee5,#0d1410, +|20: 0-0 d,#608269, 1-1 d,#0d1410, 2-99 #e5eee5,#0d1410, +|21: 0-0 d,#608269, 1-7 d,#0d1410, 8-10 #59675c,#0d1410, 11-29 #e5eee5,#0d1410, 30-33 #f7e4a5,#5e4923, 34-99 #e5eee5,#0d1410, |22: 0-0 d,#608269, 1-99 d,#0d1410, |23: 0-0 d,#608269, 1-99 d,#0d1410, |24: 0-0 d,#608269, 1-99 d,#0d1410, |25: 0-0 d,#608269, 1-99 d,#0d1410, -|26: 0-0 d,#608269, 1-99 d,#0d1410, -|27: 0-0 d,#608269, 1-99 d,#0d1410, -|28: 0-0 d,#608269, 1-99 d,#0d1410, -|29: 0-0 d,#608269, 1-99 d,#0d1410, -|30: 0-0 d,#608269, 1-99 d,#0d1410, -|31: 0-0 d,#608269, 1-99 d,#0d1410, +|26: 0-1 d,#add38a, 2-43 #becfc4,#314738, 44-52 #dfbce5,#314738, 53-99 #becfc4,#314738, +|27: 0-0 d,#608269, 1-1 d,#0d1410, 2-4 d,#0d1410,b 5-6 #616f64,#0d1410,b 7-16 #e5eee5,#0d1410, 17-20 #f5f7ee,#3c614a, 21-21 #f5f7ee,#0d1410, 22-23 #e5eee5,#0d1410, 24-28 #c9a7ed,#0d1410, 29-99 #e5eee5,#0d1410, +|28: 0-0 d,#608269, 1-4 d,#0d1410, 5-10 #59675c,#0d1410, 11-99 #e5eee5,#0d1410, +|29: 0-0 d,#608269, 1-4 d,#0d1410, 5-10 #59675c,#0d1410, 11-99 #e5eee5,#0d1410, +|30: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-99 #e5eee5,#0d1410, +|31: 0-0 d,#608269, 1-4 d,#0d1410, 5-99 #59675c,#0d1410, |32: 0-0 d,#608269, 1-99 d,#0d1410, |33: 0-0 d,#608269, 1-99 d,#0d1410, |34: 0-0 d,#608269, 1-99 d,#0d1410, -== snap clicked grid=100x35 cursor=15,12 +== snap clicked grid=100x35 cursor=29,5 diff --git a/test/snapshots/lsprelpath.snap b/test/snapshots/lsprelpath.snap index a83abf46..8420e134 100644 --- a/test/snapshots/lsprelpath.snap +++ b/test/snapshots/lsprelpath.snap @@ -8,7 +8,8 @@ # short to be called. # # A row in the SAME directory shortens to a bare basename; the two that a -# prefix strip can actually get wrong are here, one app each, as `gr` rows: +# prefix strip can actually get wrong are here, one app each, as `gr` rows +# (the file headers of the asking text's query pane, line 1 `Refs`): # # PARENT the enum is one level UP from the asking file, so nothing is # stripped and the row carries `/tmp/.../cwd/shade.zig`. This is @@ -32,26 +33,25 @@ file sub/subdir.zig const tint = @import("inner/tint.zig");\n\npub fn hue(t: tin start 35 100 sub/parent.zig wait 8000 fn pick stable 700 20000 -# `gr` on `Shade` in the signature (file line 3, click row 6): its -# declaration's row is in the parent directory. press left 31 6 release left 31 6 stable 400 5000 key g key r -wait 15000 cwd/shade.zig:1: +# the query pane under parent.zig, line 1 `Refs`, the rows under each file: +# shade.zig's spelled whole, its directory being above +wait 15000 cwd/shade.zig stable 700 15000 snap absrow -key esc -settle 100 -# An absolute row has to keep resolving — it is the spelling every row had -# before this, and the one every hit outside the tree still has. -key space j n +# the current row is parent.zig's own; the one before it is shade.zig's, +# shown in the +Preview, which Enter makes shade.zig's pane +key c-p +wait 10000 verdigris +stable 700 15000 key enter stable 700 15000 snap abslook snapstyle abslook -# ---- SUBDIRECTORY: under it, so the strip leaves `inner/tint.zig` ---- start 35 100 sub/subdir.zig wait 8000 fn hue stable 700 20000 @@ -60,23 +60,16 @@ release left 29 6 stable 400 5000 key g key r -wait 15000 inner/tint.zig:1: +wait 15000 inner/tint.zig stable 700 15000 snap subrow -key esc -settle 100 -key space j n +key c-p +wait 10000 ochre +stable 700 15000 key enter stable 700 15000 snap sublook snapstyle sublook -# The mouse spelling, on the OTHER row (grid row 12, 1-based click row 13). A -# right click expands to the file-ish word under the cursor -# (config.wordBounds), which has to take `inner/tint.zig:3:5-10` WHOLE — the -# separator inside a stripped path is a file char, so the scan runs back over -# `inner/` and stops on the space of the line-number prefix. A look focuses -# what it opens, so the header's cursor is the assertion: the end of `indigo` -# on line 3 of tint.zig. press right 12 13 release right 12 13 stable 700 15000 diff --git a/test/snapshots/msg.golden b/test/snapshots/msg.golden index 24018546..950c4d67 100644 --- a/test/snapshots/msg.golden +++ b/test/snapshots/msg.golden @@ -37,10 +37,10 @@ |8: |9: == snap prompt grid=70x17 cursor=69,3 -|3: 1 EXTERNAL /EXT +|3: 1 EXTERNAL Select /EXT == snap prompt-wins grid=70x17 cursor=69,4 |3: 1 AGAIN --:--:-- reloaded /tmp/pardes-snap/msg/cwd/a.txt -|4: 2 /EXT +|4: 2 Select /EXT == snap esc grid=70x17 cursor=7,4 |3: 1 AGAIN |4: 2 diff --git a/test/snapshots/msg.snap b/test/snapshots/msg.snap index 5252508a..64a77bb2 100644 --- a/test/snapshots/msg.snap +++ b/test/snapshots/msg.snap @@ -58,7 +58,7 @@ snap reloaded # its builtins instead of losing them to a long pattern. Note the tag row above # ends at `Del`: the marker and the pattern are no longer on it at all. (The # `/` keystroke also cleared the reload message, which is the rule above.) -key / +key s text EXT stable 700 15000 snap prompt diff --git a/test/snapshots/stepgrain.golden b/test/snapshots/stepgrain.golden index 3101b920..43445ed4 100644 --- a/test/snapshots/stepgrain.golden +++ b/test/snapshots/stepgrain.golden @@ -1,43 +1,55 @@ -== snap results grid=150x31 cursor=7,3 +== snap results grid=150x31 cursor=13,13 | Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol | /tmp/pardes-snap/stepgrain/cwd/a.txt Save Tty Collapse Del | 1 hello ZQMARK one | 2 see also sub/b.txt for ZQMARK two -| /tmp/pardes-snap/stepgrain/cwd/+Search Save Tty Collapse LocationsConfig Del -| 1 a.txt:1:7-12 -| 2 hello ZQMARK one -| 3 a.txt:2:24-29 -| 4 see also sub/b.txt for ZQMARK two -| 5 sub/b.txt:1:1-6 -| 6 ZQMARK inside sub -| 7 -== snap step-row1 grid=150x31 cursor=7,6 -== style step-row1 grid=150x31 +| +| +| +| +| +| +| +|^ +Search 1/3 Del +| Grep ZQMARK +| a.txt +| 1 hello ZQMARK one +| 2 see also sub/b.txt for ZQMARK two +| sub/b.txt +| 1 ZQMARK inside sub +| +| +| +| /tmp/pardes-snap/stepgrain/cwd/+Preview Del +| 1 +== snap step-row2 grid=150x31 cursor=13,13 +|12: ^ +Search 2/3 Del +== style step-row2 grid=150x31 |0: 0-1 d,#1d2824, 2-149 #b2c3b8,#1d2824, |1: 0-1 d,#887455, 2-149 #becfc4,#314738, |2: 0-1 d,#496656, 2-32 #b2c3b8,#1d2824, 33-38 #d3b0d9,#1d2824, 39-149 #b2c3b8,#1d2824, -|3: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-149 #e5eee5,#0d1410, -|4: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-149 #e5eee5,#0d1410, -|5: 0-1 d,#add38a, 2-32 #becfc4,#314738, 33-40 #dfbce5,#314738, 41-149 #becfc4,#314738, -|6: 0-0 d,#608269, 1-1 d,#0d1410, 2-4 d,#0d1410,b 5-6 #616f64,#0d1410,b 7-18 #f5f7ee,#3c614a, 19-149 #f5f7ee,#0d1410, -|7: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-12 #e5eee5,#0d1410, 13-18 #f7e4a5,#5e4923, 19-19 #f7e4a5,#0d1410, 20-149 #e5eee5,#0d1410, -|8: 0-0 d,#608269, 1-4 d,#0d1410, 5-149 #59675c,#0d1410, -|9: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-29 #e5eee5,#0d1410, 30-35 #f7e4a5,#5e4923, 36-36 #f7e4a5,#0d1410, 37-149 #e5eee5,#0d1410, -|10: 0-0 d,#608269, 1-4 d,#0d1410, 5-149 #59675c,#0d1410, -|11: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-12 #f7e4a5,#5e4923, 13-13 #f7e4a5,#0d1410, 14-149 #e5eee5,#0d1410, -|12: 0-0 d,#608269, 1-4 d,#0d1410, 5-149 #59675c,#0d1410, -|13: 0-0 d,#608269, 1-149 d,#0d1410, -|14: 0-0 d,#608269, 1-149 d,#0d1410, -|15: 0-0 d,#608269, 1-149 d,#0d1410, -|16: 0-0 d,#608269, 1-149 d,#0d1410, -|17: 0-0 d,#608269, 1-149 d,#0d1410, -|18: 0-0 d,#608269, 1-149 d,#0d1410, +|3: 0-0 d,#5e4923, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-12 #e5eee5,#0d1410, 13-18 #e5eee5,#352e19, 19-149 #e5eee5,#0d1410, +|4: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-29 #e5eee5,#0d1410, 30-35 #f5f7ee,#3c614a, 36-36 #f5f7ee,#0d1410, 37-149 #e5eee5,#0d1410, +|5: 0-0 d,#608269, 1-149 d,#0d1410, +|6: 0-0 d,#608269, 1-149 d,#0d1410, +|7: 0-0 d,#e5eee5, 1-149 d,#0d1410, +|8: 0-0 d,#608269, 1-149 d,#0d1410, +|9: 0-0 d,#608269, 1-149 d,#0d1410, +|10: 0-0 d,#608269, 1-149 d,#0d1410, +|11: 0-0 d,#608269, 1-149 d,#0d1410, +|12: 0-1 #000000,#add38a, 2-149 #becfc4,#314738, +|13: 0-0 d,#608269, 1-1 d,#0d1410, 2-149 #e5eee5,#0d1410, +|14: 0-0 d,#608269, 1-1 d,#0d1410, 2-149 #e5eee5,#0d1410, +|15: 0-0 d,#608269, 1-7 d,#0d1410, 8-10 #59675c,#0d1410, 11-16 #e5eee5,#0d1410, 17-22 #f7e4a5,#5e4923, 23-23 #f7e4a5,#0d1410, 24-149 #e5eee5,#0d1410, +|16: 0-0 d,#608269, 1-7 d,#0d1410, 8-10 #59675c,#0d1410, 11-33 #e5eee5,#0d1410, 34-39 #f7e4a5,#5e4923, 40-40 #f7e4a5,#0d1410, 41-149 #e5eee5,#0d1410, +|17: 0-0 d,#608269, 1-1 d,#0d1410, 2-149 #e5eee5,#0d1410, +|18: 0-0 d,#608269, 1-7 d,#0d1410, 8-10 #59675c,#0d1410, 11-16 #f7e4a5,#5e4923, 17-17 #f7e4a5,#0d1410, 18-149 #e5eee5,#0d1410, |19: 0-0 d,#608269, 1-149 d,#0d1410, |20: 0-0 d,#608269, 1-149 d,#0d1410, |21: 0-0 d,#608269, 1-149 d,#0d1410, -|22: 0-0 d,#608269, 1-149 d,#0d1410, -|23: 0-0 d,#608269, 1-149 d,#0d1410, +|22: 0-1 d,#496656, 2-32 #b2c3b8,#1d2824, 33-41 #d3b0d9,#1d2824, 42-149 #b2c3b8,#1d2824, +|23: 0-0 d,#608269, 1-4 d,#0d1410, 5-149 #59675c,#0d1410, |24: 0-0 d,#608269, 1-149 d,#0d1410, |25: 0-0 d,#608269, 1-149 d,#0d1410, |26: 0-0 d,#608269, 1-149 d,#0d1410, @@ -45,29 +57,32 @@ |28: 0-0 d,#608269, 1-149 d,#0d1410, |29: 0-0 d,#608269, 1-149 d,#0d1410, |30: 0-0 d,#608269, 1-149 d,#0d1410, -== snap step-row2 grid=150x31 cursor=7,8 -== style step-row2 grid=150x31 -|6: 0-0 d,#608269, 1-4 d,#0d1410, 5-149 #59675c,#0d1410, -|8: 0-0 d,#608269, 1-1 d,#0d1410, 2-4 d,#0d1410,b 5-6 #616f64,#0d1410,b 7-19 #f5f7ee,#3c614a, 20-149 #f5f7ee,#0d1410, -== snap step-row3 grid=150x31 cursor=7,10 -== snap step-wrap grid=150x31 cursor=7,6 -== snap blank-in-path grid=150x31 cursor=7,6 -|5: /tmp/pardes-snap/stepgrain/cwd/+Search Save Tty Collapse Del -|6: 1 two words.txt -|7: 2 -|8: -|9: -|10: -|11: -|12: +== snap step-row3 grid=150x31 cursor=13,13 +|12: ^ +Search 3/3 Del +|22: /tmp/pardes-snap/stepgrain/cwd/sub/b.txt Del +|23: 1 ZQMARK inside sub +== snap step-wrap grid=150x31 cursor=13,13 +|12: ^ +Search 1/3 Del +== snap blank-in-path grid=150x31 cursor=12,13 +|12: ^ +Search 1/1 Del +|13: Find words +|14: two words.txt +|15: +|16: +|17: +|18: +|22: /tmp/pardes-snap/stepgrain/cwd/two words.txt Del +|23: 1 == style blank-in-path grid=150x31 -|6: 0-0 d,#608269, 1-1 d,#0d1410, 2-4 d,#0d1410,b 5-6 #616f64,#0d1410,b 7-19 #f5f7ee,#3c614a, 20-149 #f5f7ee,#0d1410, -|7: 0-0 d,#608269, 1-4 d,#0d1410, 5-149 #59675c,#0d1410, -|8: 0-0 d,#608269, 1-149 d,#0d1410, -|9: 0-0 d,#608269, 1-149 d,#0d1410, -|10: 0-0 d,#608269, 1-149 d,#0d1410, -|11: 0-0 d,#608269, 1-149 d,#0d1410, -|12: 0-0 d,#608269, 1-149 d,#0d1410, -== snap blank-opened grid=150x31 cursor=7,9 -|8: /tmp/pardes-snap/stepgrain/cwd/two words.txt Save Tty Collapse Del -|9: 1 +|3: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-149 #e5eee5,#0d1410, +|4: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-149 #e5eee5,#0d1410, +|7: 0-0 d,#608269, 1-149 d,#0d1410, +|14: 0-0 d,#608269, 1-1 d,#0d1410, 2-5 #e5eee5,#0d1410, 6-10 #f7e4a5,#5e4923,b 11-149 #e5eee5,#0d1410, +|15: 0-0 d,#608269, 1-149 d,#0d1410, +|16: 0-0 d,#608269, 1-149 d,#0d1410, +|17: 0-0 d,#608269, 1-149 d,#0d1410, +|18: 0-0 d,#608269, 1-149 d,#0d1410, +|22: 0-1 d,#496656, 2-32 #b2c3b8,#1d2824, 33-46 #d3b0d9,#1d2824, 47-149 #b2c3b8,#1d2824, +== snap blank-opened grid=150x31 cursor=7,23 +|12: +Search 1/1 Save Unattach Del +|22: /tmp/pardes-snap/stepgrain/cwd/two words.txt Save Tty Collapse Del diff --git a/test/snapshots/stepgrain.snap b/test/snapshots/stepgrain.snap index 0f555ff8..e807981c 100644 --- a/test/snapshots/stepgrain.snap +++ b/test/snapshots/stepgrain.snap @@ -1,22 +1,11 @@ -# WHAT ONE PRESS OF `n` TAKES, and why that is not one answer. A pane's rows -# decide it (output_pane.Grain, read in Pardes.lookSpanIn): +# ONE PRESS, ONE ROW. A query pane's rows are one a line with a hit, the +# hit's line under a gutter number, and Ctrl-n / Ctrl-p (typing on line 1) +# step them a row at a time, round the end: row 2 below matched on a line +# that mentions `sub/b.txt`, and the step does not stop on that word, as the +# old word-grained walk did; the fourth press wraps back to row 1. # -# free text — a terminal, a file, a PDF — is stepped WORD by word, several -# stops to a line, because a line of it may name several places at once (the -# `ls` row in ttylook.snap hops big.txt -> plain.txt -> sub); -# -# a RESULTS BUFFER is stepped ROW by row, on the location at the head of the -# row, because a row there IS one location and the words after it are the -# MATCHED TEXT — the same hit, spelled out. That text is full of look-able -# words, and stopping on them was stopping on the same result twice. -# -# This script is the second rule. Row 2 below matched on a line that mentions -# `sub/b.txt`, so the old word-grained walk stopped there before it ever -# reached row 3; now `n` presses and rows correspond one to one, and the fourth -# press wraps the ring back to row 1. -# -# LARGEST from the head, so a path with a BLANK in it is one span rather than -# the word in front of it: `two words.txt` selects whole and opens. +# A path with a BLANK in it is one name: `two words.txt` is found whole by +# Find and Enter opens exactly it. dirmk sub file a.txt hello ZQMARK one\nsee also sub/b.txt for ZQMARK two file sub/b.txt ZQMARK inside sub @@ -24,52 +13,36 @@ run touch 'two words.txt' start 31 150 a.txt wait 8000 hello ZQMARK stable 700 20000 -# Grep from the leader: three hits, sorted by path, the empty file contributing -# none. Row 2 is the one whose TEXT holds a path. +# Grep from the leader: three hits, under their files, the empty file +# contributing none. Row 2 is the one whose TEXT holds a path. key space key f key g stable 400 5000 text ZQMARK -key enter -wait 10000 sub/b.txt:1:1 +wait 10000 ZQMARK inside sub stable 700 15000 snap results -# one press, one row: the head of row 1... -key space j n -stable 400 5000 -snap step-row1 -snapstyle step-row1 -# ...the head of row 2, and NOT the `sub/b.txt` sitting in its matched text — -# the cursor column is the assertion -key space j n +key c-n stable 400 5000 snap step-row2 snapstyle step-row2 -# ...row 3, and then the ring comes round to row 1 again -key space j n +key c-n stable 400 5000 snap step-row3 -key space j n +key c-n stable 400 5000 snap step-wrap -# Back into the file, so the Find below is asked from a pane that is not a -# results buffer (fillResults never refills the buffer it was asked from). -press left 8 4 -release left 8 4 +key esc +settle 100 stable 400 5000 -# A path with a blank in it: the row is one span from its first cell, because -# the walk asks about the LONGEST run of the row first and the filesystem is -# what vouches for it. Enter then opens exactly what is selected. +# Find `words`: the name with a blank in it, whole key space key f key f text words -key enter wait 10000 two words.txt stable 700 15000 -key space j n -stable 400 5000 snap blank-in-path snapstyle blank-in-path key enter diff --git a/test/snapshots/tagbottom.golden b/test/snapshots/tagbottom.golden index ef1bab3a..cf690a40 100644 --- a/test/snapshots/tagbottom.golden +++ b/test/snapshots/tagbottom.golden @@ -150,10 +150,19 @@ |8: 8 hhh |9: 9 iii |10: 10 jjj -== snap search-prompt grid=100x31 cursor=99,12 -|12: 1 ZZONE /ZZ +== snap search-prompt grid=100x31 cursor=5,21 +|20: /tmp/pardes-snap/tagbottom/cwd/bottom.txt Save Tty Collapse Del +|21: /ZZ +|22: 1 ZZONE +|23: 2 ZZTWO +|30: ^ +Search 1/2 Del == snap leader grid=100x31 cursor=9,13 |12: 1 ZZONE SPC +|20: +|21: +|22: +|23: +|30: /tmp/pardes-snap/tagbottom/cwd/bottom.txt Save Tty Collapse Del == snap cut-down grid=100x31 cursor=7,5 |2: 1 aaa |3: 2 bbb diff --git a/test/snapshots/tagbottomshort.golden b/test/snapshots/tagbottomshort.golden index 00d8cad0..1979cc60 100644 --- a/test/snapshots/tagbottomshort.golden +++ b/test/snapshots/tagbottomshort.golden @@ -1,41 +1,41 @@ -== snap roomy grid=80x11 cursor=79,2 +== snap roomy grid=80x11 cursor=5,5 | Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol -| 1 one /ZZ +| 1 one | 2 two -| 3 three -| 4 four -| 5 five -| 6 six +| /tmp/pardes-snap/tagbottomshort/cwd/s.txt Save Tty Collapse Del +| /ZZ | | -| /tmp/pardes-snap/tagbottomshort/cwd/s.txt Save Tty Collapse Del -== snap two-body grid=80x5 cursor=79,2 +| +| +|^ +Search 0 Del +== snap two-body grid=80x5 cursor=5,3 | Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol -| 1 one /ZZ -| 2 two | /tmp/pardes-snap/tagbottomshort/cwd/s.txt Save Tty Collapse Del -== snap one-body grid=80x4 cursor=79,2 +| /ZZ +|^ +Search 0 Del +== snap one-body grid=80x4 cursor=79,3 | Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol -| 1 one /ZZ | /tmp/pardes-snap/tagbottomshort/cwd/s.txt Save Tty Collapse Del +|^ +Search 0 Del == snap tag-only grid=80x2 cursor=79,1 | Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | /tmp/pardes-snap/tagbottomshort/cwd/s.txt Save Tty Collapse Del -== snap regrown grid=80x11 cursor=79,2 +== snap regrown grid=80x11 cursor=5,5 | Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol -| 1 one /ZZ +| 1 one | 2 two -| 3 three -| 4 four -| 5 five -| 6 six +| /tmp/pardes-snap/tagbottomshort/cwd/s.txt Save Tty Collapse Del +| /ZZ | | -| /tmp/pardes-snap/tagbottomshort/cwd/s.txt Save Tty Collapse Del +| +| +|^ +Search 0 Del == snap leader-one-body grid=80x4 cursor=7,2 | Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol diff --git a/test/snapshots/topbarexec.golden b/test/snapshots/topbarexec.golden index 5b7d2234..63ed382c 100644 --- a/test/snapshots/topbarexec.golden +++ b/test/snapshots/topbarexec.golden @@ -26,14 +26,20 @@ |8: │pinch 1.0000 │ |9: │tscroll 0.0000 │ |10: ╰────────────────────────────────────╯ -== snap arg-still-spliced grid=90x21 cursor=14,5 +== snap arg-still-spliced grid=90x21 cursor=14,4 |1: New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol |2: /tmp/pardes-snap/topbarexec/cwd Tty+bash Sa /tmp/pardes-snap/topbarexec/cwd Tty+bash Sa |3: ve Mode Filter Collapse Del ve Mode Filter Collapse Del -|4: ls Find ls -|5: zmarkfile.txt zmarkfile.txt -|6: -|7: /tmp/pardes-snap/topbarexec/cwd/+Search Sav -|8: e Tty Collapse Del -|9: 1 zmarkfile.txt -|10: 2 +|4: zmarkfile.txt Find ls +|5: zmarkfile.txt +|6: +Search 1/1 Del +|7: Find zmarkfile.txt +|8: zmarkfile.txt +|9: /tmp/pardes-snap/topbarexec/cwd/zmarkfile.t +|10: xt Del +|11: 1 hay ZQNEEDLE stack +|12: +|13: /tmp/pardes-snap/topbarexec/cwd Tty+bash Sa +|14: ve Mode Filter Collapse Del +|15: ls +|16: zmarkfile.txt -- cgit v1.3 From c8ad18df1d46265c30721861760a744227e57b31 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Sun, 25 Oct 2026 11:08:56 -0300 Subject: pdfrender 3: a PDF's place on the jumplist is its page and how far down it (a fraction, which a zoom or a resize keeps), its file's hash, so Back and Forward land on the exact offset through the motion system (a far one as one body's slide), places on one page more than a body apart are two entries, JumpScope file keeps to the PDF, and a closed PDF reopens at its place; the Jumplist pane prints a PDF's place as path:page --- src/Output.zig | 7 ++++ src/pardes.zig | 43 +++++++++++++++++----- src/pdf_view.zig | 50 +++++++++++++++++++++++++ test/pdf.zig | 110 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 201 insertions(+), 9 deletions(-) (limited to 'src/Output.zig') diff --git a/src/Output.zig b/src/Output.zig index 01e3e0f1..a17b0459 100644 --- a/src/Output.zig +++ b/src/Output.zig @@ -701,6 +701,11 @@ pub fn openJumps(p: *Pardes, id: usize) !void { // 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 PDF's `col` is how far down its page, no Look's column. + if (j.pdf) { + try out.writer.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) }); continue; } @@ -724,6 +729,8 @@ pub fn openJumps(p: *Pardes, id: usize) !void { 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] }) + else if (j.pdf) + try out.writer.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] }); } diff --git a/src/pardes.zig b/src/pardes.zig index 26b167d5..a23039ef 100644 --- a/src/pardes.zig +++ b/src/pardes.zig @@ -462,6 +462,9 @@ pub const Loc = struct { col: u32, /// The file it is in (Wyhash of the path), 0 for a pane with none. path_hash: u64 = 0, + /// A PDF's place: `line` its page (one-based), `col` how far down it + /// (pdf_view.Place.at, a fraction of the page in 2^-32). + pdf: bool = false, }; test { @@ -4924,6 +4927,12 @@ pub const Pardes = struct { return null; } + /// The file a jump in `pane` is in: a text's, a PDF's. + fn jumpPath(pane: *const Pane) ?[]const u8 { + if (recentDot(pane)) |d| return d.path; + return pane.pdfPath(); + } + fn recentDot(pane: *const Pane) ?struct { path: []const u8, line: u32, col: u32, aline: u32 = 0, acol: u32 = 0 } { const f = pane.file orelse return null; if (f.output != null) return null; @@ -7355,6 +7364,14 @@ pub const Pardes = struct { fn samePlace(p: *const Pardes, a: Loc, b: Loc) bool { if (a.pane != b.pane or a.serial != b.serial) return false; + // A PDF's places by where they stand on its strip, as a text's by + // lines: within a body of each other, one visit. + if (a.pdf and b.pdf) if (p.panes[b.pane]) |pane| { + const view = panes.Pdf.paneViewport(p, pane) orelse return a.line == b.line; + const ya = panes.Pdf.placeY(pane, .{ .page = a.line - 1, .at = a.col }) orelse return a.line == b.line; + const yb = panes.Pdf.placeY(pane, .{ .page = b.line - 1, .at = b.col }) orelse return a.line == b.line; + return @abs(ya - yb) <= @as(f64, @floatFromInt(view.pixel_h)); + }; if (a.line == 0 or b.line == 0) return true; const body = @max(1, p.rects[b.pane].h -| BOX_H); return @max(a.line, b.line) - @min(a.line, b.line) <= body; @@ -7374,8 +7391,8 @@ pub const Pardes = struct { kept.serial = 0; // Open again in some pane (a look, Recent): the entry is that // pane's, and closed only while no pane has the file. - for (p.panes, 0..) |slot, id| if (slot) |pane| if (recentDot(pane)) |d| { - if (std.hash.Wyhash.hash(0, d.path) != j.path_hash) continue; + for (p.panes, 0..) |slot, id| if (slot) |pane| if (jumpPath(pane)) |path| { + if (std.hash.Wyhash.hash(0, path) != j.path_hash) continue; kept.pane = @intCast(id); kept.serial = pane.serial; break; @@ -7399,12 +7416,14 @@ pub const Pardes = struct { if (pane.query) |q| if (!q.frozen) return; const force = p.jump_force; p.jump_force = false; + const pdf_place = panes.Pdf.place(pane); const now: Loc = .{ .pane = @intCast(p.active), .serial = pane.serial, - .line = if (pane.pdfPage()) |page| @intCast(page + 1) else if (pane.body.cur_pinned) @intCast(@max(0, pane.body.cur_row) + 1) else 0, - .col = if (pane.pdfPage() != null) 0 else if (pane.body.cur_pinned) @intCast(@max(0, pane.body.cur_col) + 1) else 0, - .path_hash = if (recentDot(pane)) |d| std.hash.Wyhash.hash(0, d.path) else 0, + .line = if (pdf_place) |at| @intCast(at.page + 1) else if (pane.body.cur_pinned) @intCast(@max(0, pane.body.cur_row) + 1) else 0, + .col = if (pdf_place) |at| at.at else if (pane.body.cur_pinned) @intCast(@max(0, pane.body.cur_col) + 1) else 0, + .path_hash = if (jumpPath(pane)) |path| std.hash.Wyhash.hash(0, path) else 0, + .pdf = pdf_place != null, }; if (!force and p.njumps > 0 and p.samePlace(p.jumps[p.jcur], now)) { p.jumps[p.jcur] = now; // same visit; the entry IS where you are @@ -7447,7 +7466,7 @@ pub const Pardes = struct { var next = if (older) p.jcur - 1 else p.jcur + 1; // A terminal or a scratch has no file to keep to: the step is global. if (p.settings.jump_scope == .file) if (p.panes[p.active]) |here| if (recentPlace(here)) |place| if (place.path.len > 0) { - const hash = if (recentDot(here)) |d| std.hash.Wyhash.hash(0, d.path) else 0; + const hash = if (jumpPath(here)) |path| std.hash.Wyhash.hash(0, path) else 0; // The nearest of this pane's own wins over a nearer one of this // file in another pane: the step does not move the keyboard. var pick: ?usize = null; @@ -7492,10 +7511,11 @@ pub const Pardes = struct { return p.jumpBy(delta); } const from = p.active; - look.reopenAt(p, from, e.path, .{ .line = @max(1, j.line), .col = @max(1, j.col) }); + look.reopenAt(p, from, e.path, .{ .line = @max(1, j.line), .col = if (j.pdf) 0 else @max(1, j.col) }); const opened = p.panes[p.active] orelse return; - const f = opened.file orelse return; - if (!std.mem.eql(u8, f.path, e.path)) return; // it did not open + const opened_path = jumpPath(opened) orelse return; + if (!std.mem.eql(u8, opened_path, e.path)) return; // it did not open + if (j.pdf) panes.Pdf.landAt(p, opened, .{ .page = j.line -| 1, .at = j.col }); // Every entry of that file is the reopened pane from here on, so // a step onto another of them moves in it rather than reopening. for (p.jumps[0..p.njumps]) |*k| if (k.serial == 0 and k.path_hash == j.path_hash) { @@ -7510,6 +7530,11 @@ pub const Pardes = struct { if (p.panes[p.active]) |source| look.clearNavigationSelection(p, source); if (p.active != j.pane) look.clearNavigationSelection(p, pane); p.jcur = next; + if (pane.pdfPath() != null) { + look.focusPaneLine(p, j.pane, .{ .line = 0, .col = 0 }, .keep); + panes.Pdf.landAt(p, pane, .{ .page = j.line -| 1, .at = if (j.pdf) j.col else 0 }); + return; + } look.focusPaneLine(p, j.pane, .{ .line = j.line, .col = j.col }, .center); } diff --git a/src/pdf_view.zig b/src/pdf_view.zig index bcca11b4..f6d26eac 100644 --- a/src/pdf_view.zig +++ b/src/pdf_view.zig @@ -3070,6 +3070,56 @@ pub fn revealOutlineDestination( _ = ensurePaneLayout(core, pane); } +/// A PDF's place, as the jumplist keeps it: the page at the strip's top and +/// how far down that page it stands, a fraction in 2^-32 of the page. A +/// fraction, not pixels: a zoom, a fit change or a resize scales every page, +/// and a fraction of one lands on the same line of print after it. +pub const Place = struct { page: usize, at: u32 }; +const place_scale: f64 = std.math.maxInt(u32); + +pub fn place(pane: *const pardes.Pane) ?Place { + if (comptime !enabled) return null; + const state = if (pane.pdf) |*pv| pv else return null; + if (!state.layout_valid or state.document_height == 0) return .{ .page = state.page, .at = 0 }; + const page = pageAtOffset(state, state.document_scroll_y); + const start: f64 = @floatFromInt(state.page_starts[page]); + const height: f64 = @floatFromInt(@max(1, state.page_heights[page])); + const fraction = std.math.clamp((state.document_scroll_y - start) / height, 0, 1); + return .{ .page = page, .at = @intFromFloat(@round(fraction * place_scale)) }; +} + +/// Where `at` stands on the strip as laid out now, in document pixels. +pub fn placeY(pane: *const pardes.Pane, at: Place) ?f64 { + if (comptime !enabled) return null; + const state = if (pane.pdf) |*pv| pv else return null; + if (!state.layout_valid) return null; + const page = @min(at.page, state.page_count -| 1); + return @as(f64, @floatFromInt(state.page_starts[page])) + + @as(f64, @floatFromInt(at.at)) / place_scale * @as(f64, @floatFromInt(state.page_heights[page])); +} + +/// A jump to `at` (Back, Forward): the core is there at once and the strip +/// follows through the motion system, a far one as one body's slide, the +/// page rendered where it comes to rest. Not laid out yet (a pane just +/// reopened), it is anchored there for the first layout. +pub fn landAt(core: *pardes.Pardes, pane: *pardes.Pane, at: Place) void { + if (comptime !enabled) return; + const state = &(pane.pdf orelse return); + const page = @min(at.page, state.page_count -| 1); + activatePage(core, pane, page, false); + state.scroll_to_page_pending = false; + if (placeY(pane, .{ .page = page, .at = at.at })) |y| { + state.layout_anchor_pending = false; + // Where it stands already (half a pixel is the place's rounding): + // not moved, not kicked. + if (@abs(y - state.document_scroll_y) >= 0.5) state.document_scroll_y = y; + } else { + state.layout_anchor_pending = true; + state.layout_anchor_page = page; + state.layout_anchor_fraction = @as(f64, @floatFromInt(at.at)) / place_scale; + } +} + pub fn setPage(core: *pardes.Pardes, pane: *pardes.Pane, page: usize) void { activatePage(core, pane, page, true); } diff --git a/test/pdf.zig b/test/pdf.zig index 5f7ebc52..bbb0da66 100644 --- a/test/pdf.zig +++ b/test/pdf.zig @@ -2448,3 +2448,113 @@ test "a PDF's fit and tint, and Collapse, read in its ctl and come back from a D try std.testing.expectEqualStrings("height", @tagName(pv.fit)); try std.testing.expectEqualStrings("full", @tagName(pv.tint)); } + +/// The jumplist's PDF (pdfrender): the Intel SDM (5363 pages, the author's +/// stress file) when this machine has it, else the docs' PDF; the same +/// checks either way. +fn jumpPdf() []const u8 { + const sdm = "/home/goblin/00-projects/kvmctf/harnesses/contained-official/visor-uefi/intel-ia32-manual.pdf"; + std.Io.Dir.accessAbsolute(std.testing.io, sdm, .{}) catch return "docs/design.pdf"; + return sdm; +} + +/// Lays the PDF pane out (a frame drawn) and syncs, so the jumplist sees it. +fn jumpFrame(p: *Pardes) !void { + var frame: std.heap.ArenaAllocator = .init(std.testing.allocator); + defer frame.deinit(); + _ = try p.render(frame.allocator()); + p.sync(); +} + +fn stripAtPlace(p: *Pardes, pane: *pardes.Pane, page: usize, fraction: f64) !f64 { + const pv = &pane.pdf.?; + pv.document_scroll_y = @as(f64, @floatFromInt(pv.page_starts[page])) + fraction * @as(f64, @floatFromInt(pv.page_heights[page])); + try jumpFrame(p); + return pv.document_scroll_y; +} + +test "a PDF's jumps: Back after a far jump returns to the exact offset, two places on one page are two entries" { + if (!pdf_enabled or platform == .web) return error.SkipZigTest; + const p = try Pardes.init(std.testing.allocator, .{ .file = jumpPdf(), .cols = 80, .rows = 28 }); + defer p.deinit(); + p.native_images = true; + p.presentation.enabled = false; + const id = p.active; + const pane = p.panes[id].?; + const pv = &pane.pdf.?; + try jumpFrame(p); + try std.testing.expect(pv.page_count > 3); + // Two places on page 1, more than a body apart: two entries. + const before = p.njumps; + _ = try stripAtPlace(p, pane, 1, 0.05); + const near = try stripAtPlace(p, pane, 1, 0.8); + try std.testing.expectEqual(before + 2, p.njumps); + try std.testing.expect(p.jumps[p.njumps - 1].pdf); + // A far jump (a Look at a page), then Back: the exact offset, not the + // page's top, and its page. + look.lookAt(p, id, if (pv.page_count > 3000) ":3000" else ":4"); + try jumpFrame(p); + try std.testing.expect(pv.page >= 3); + p.jumpBy(-1); + try jumpFrame(p); + try std.testing.expectEqual(@as(usize, 1), pv.page); + try std.testing.expectApproxEqAbs(near, pv.document_scroll_y, 0.5); + // A wheel's small steps are the same visit: the entry follows them. + const n = p.njumps; + for (0..4) |_| { + _ = panes.Pdf.scrollPane(p, pane, 30, true); + try jumpFrame(p); + } + try std.testing.expectEqual(n, p.njumps); +} + +test "a PDF's jumps: JumpScope file keeps to the PDF, and a closed PDF reopens at its place" { + if (!pdf_enabled or platform == .web) return error.SkipZigTest; + // Recent keeps a file by the path it was opened as: a real one here, + // as a Look opens one. + var cwd_buf: [4096]u8 = undefined; + const cwd = cwd_buf[0..try std.Io.Dir.cwd().realPath(std.testing.io, &cwd_buf)]; + var path_buf: [4200]u8 = undefined; + const path = try std.fmt.bufPrint(&path_buf, "{s}/docs/design.pdf", .{cwd}); + const p = try Pardes.init(std.testing.allocator, .{ .file = path, .cols = 80, .rows = 28 }); + defer p.deinit(); + p.native_images = true; + p.presentation.enabled = false; + try std.testing.expectEqual(config.Runtime.JumpScope.file, p.settings.jump_scope); + const doc = p.active; + const pane = p.panes[doc].?; + try jumpFrame(p); + const first = try stripAtPlace(p, pane, 1, 0.3); + // A text between, then a far place in the PDF. + look.lookAt(p, doc, "../build.zig:10"); + try jumpFrame(p); + try std.testing.expect(p.active != doc); + p.active = doc; + _ = try stripAtPlace(p, pane, 3, 0.5); + // Back from the PDF keeps to it: its own earlier place, not the text. + p.jumpBy(-1); + try jumpFrame(p); + try std.testing.expectEqual(doc, p.active); + try std.testing.expectApproxEqAbs(first, pane.pdf.?.document_scroll_y, 0.5); + // Closed, its entries stay; Back from the text reopens it at the place. + p.jumpBy(1); + try jumpFrame(p); + try p.removePane(doc, null); + try jumpFrame(p); + var closed = false; + for (p.jumps[0..p.njumps]) |j| closed = closed or (j.serial == 0 and j.pdf); + try std.testing.expect(closed); + var tries: usize = 0; + while (tries < 4) : (tries += 1) { + p.jumpBy(-1); + try jumpFrame(p); + if (p.panes[p.active].?.pdf != null) break; + } + const reopened = p.panes[p.active].?; + try std.testing.expect(reopened.pdf != null); + const pv = &reopened.pdf.?; + // The newest PDF place before the text: page 4, half way down. + try std.testing.expectEqual(@as(usize, 3), pv.page); + const want = @as(f64, @floatFromInt(pv.page_starts[3])) + 0.5 * @as(f64, @floatFromInt(pv.page_heights[3])); + try std.testing.expectApproxEqAbs(want, pv.document_scroll_y, 0.5); +} -- cgit v1.3