From 266515537a917154ef4736a1d6b1cc97be23fced Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Mon, 16 Nov 2026 22:17:47 -0300 Subject: mouse: no drag guides, and columns resize by their grips alone A drag draws no guide lines: the dashes where a pane or column would land, the carried column's rail and the held seam's dashes are gone, with the guide region kind, Surface.overlayDash, the rail's Region.clip and MAX_GUIDES; the gui's floating draw group is the debug box's alone. The line between two columns is no resize handle: Drag.border_v and its corner variant are gone, with clampBorderCol and the unused chromeTarget. A press there is a press in the pane under it (a sweep). A column resizes by its grip, a pane by its grip or, in a window, the rule above it (border_h, unchanged). Tests: the corner and border-drag unit tests and the cornerdrag and cornerdrag-left tty cases are deleted; windowops loses its border drag and tagalign2col widens its column by the grip; colgrip, shrinktag and windowops goldens drop the guides; a unit test pins that a press on the line between columns sweeps and resizes nothing. The cheatsheet, themes, render-pipeline notes and changelog say so. Co-Authored-By: Claude Opus 5.5 --- docs/render-pipeline.md | 2 +- docs/typ/cheatsheet.typ | 2 +- docs/typ/themes.typ | 2 +- src/CHANGELOG.md | 7 + src/body_layer.zig | 2 +- src/draw.zig | 95 +------------ src/gui/gui.zig | 14 +- src/layout.zig | 14 +- src/mouse.zig | 261 +++------------------------------- src/surface.zig | 18 +-- test/column_drag.zig | 58 +------- test/process/tty_images.zig | 2 +- test/process/tty_layout.zig | 141 ++---------------- test/snapshots/colgrip.golden | 147 ++++--------------- test/snapshots/cornerdrag-left.golden | 86 ----------- test/snapshots/cornerdrag.golden | 239 ------------------------------- test/snapshots/shrinktag.golden | 1 - test/snapshots/windowops.golden | 162 +++++++-------------- 18 files changed, 138 insertions(+), 1115 deletions(-) delete mode 100644 test/snapshots/cornerdrag-left.golden delete mode 100644 test/snapshots/cornerdrag.golden diff --git a/docs/render-pipeline.md b/docs/render-pipeline.md index 64fa4e65..05bc8cfa 100644 --- a/docs/render-pipeline.md +++ b/docs/render-pipeline.md @@ -62,7 +62,7 @@ core. ## The window's composition Four fixed draw groups, bottom to top: the page and the panes, the -notices, the guides and the debug box the core paints over them, and the +notices, the debug box the core paints over them, and the ink (bar cursors); then the overlay (the pet, a jump's trail, the caret's quad). Decor is flat: rules, rails, grips, spines, notice rules and bar cursors as hard-edged rectangles read from the regions. diff --git a/docs/typ/cheatsheet.typ b/docs/typ/cheatsheet.typ index 5e373fac..e931effa 100644 --- a/docs/typ/cheatsheet.typ +++ b/docs/typ/cheatsheet.typ @@ -10,7 +10,7 @@ btn("B2"), [#word("Exec") the word or selection: a builtin, else a shell line.], btn("B3"), [#word("Look"): open the file, address, directory or URL, else find the word's next place. Resting the pointer tints what #btn("B3") would take.], [sweep], [drag #btn("B2") or #btn("B3") to #word("Exec") or #word("Look") exactly what you swept.], - [grip], [drag the box left of a tag: up/down resizes, onto another column moves the pane. A column's right edge drags its width.], + [grip], [drag the box left of a tag: up/down resizes, onto another column moves the pane. A column's box: sideways resizes, past a neighbour's middle moves the column.], ) === Chords: hold the first, click the next #pairs( diff --git a/docs/typ/themes.typ b/docs/typ/themes.typ index 97b42748..a78cf66c 100644 --- a/docs/typ/themes.typ +++ b/docs/typ/themes.typ @@ -109,7 +109,7 @@ take `null`, so older files stay valid: [`tag_active_bg`, `tag_active_fg`], [the focused pane's tag; a ground closer than 1.25:1 to `tag_bg` is pushed further the way it leans, as far as its text keeps its contrast. Absent: `tag_bg`, `tag_fg`], [`tagline_bg`, `tagline_fg`], [the tagline, the workspace row: an editor's status bar in its own colours (`dark_plus` has VS Code's blue). Absent: the tag's], [`tag_name_fg`, `tag_active_name_fg`], [the file name's or a terminal's #word("Term") tint, in normal and focused tags. Absent: the tag's foreground], - [`column_box`, `column_box_dim`], [a column's grip held (and its drag rail), and at rest. Absent: `num`; a mix of `column_box` and `tag_bg`], + [`column_box`, `column_box_dim`], [a column's grip held, and at rest. Absent: `num`; a mix of `column_box` and `tag_bg`], [`border`], [quiet separators, lifted to 1.6:1 when under 1.5:1 off the page. Absent: `scroll_track`], [`empty_col`], [a column with no pane, under its tag (acme: white). Absent: `border`], [`lineno_active`], [the current line number. Absent: `lineno`], diff --git a/src/CHANGELOG.md b/src/CHANGELOG.md index 633687e8..afc14a0c 100644 --- a/src/CHANGELOG.md +++ b/src/CHANGELOG.md @@ -2,6 +2,13 @@ ## Unreleased +- A drag draws no guide lines: no dashes where a pane or column would + land, no rail for a carried column, no dashed seam under a pane rule + held. The line between two columns no longer resizes them (nor, at a + pane's corner, the panes too): a press there is a press in the pane. + A column resizes by its box, left of its tag; a pane by its own box, + or in a window by the rule above it. + - zstbi is upstream's again (zig-gamedev/zstbi, its main): the fork pinned for Zig 0.17 was deleted, and a fresh checkout could not fetch it. diff --git a/src/body_layer.zig b/src/body_layer.zig index 76aec179..dbf0156d 100644 --- a/src/body_layer.zig +++ b/src/body_layer.zig @@ -195,7 +195,7 @@ pub fn joinBody(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, layer.id = @intCast(id); layer.serial = pane.serial; const body = s.region(.body, id).?; - layer.viewport = .{ .x = body.rect.x, .y = body.rect.y, .w = body.rect.w - body.clip, .h = body.rect.h }; + layer.viewport = .{ .x = body.rect.x, .y = body.rect.y, .w = body.rect.w, .h = body.rect.h }; layer.cols = width; layer.rows = @intCast(logical_rows); layer.context_rows = pane.context_rows; diff --git a/src/draw.zig b/src/draw.zig index fc90586e..4809ebd4 100644 --- a/src/draw.zig +++ b/src/draw.zig @@ -116,24 +116,6 @@ pub fn place(p: *Pardes, s: *Surface) void { } if (p.settings.workspace_tag) s.addRegion(.{ .kind = .workspace_tag, .rect = .{ .x = 0, .y = 0, .w = s.cols, .h = p.topBarHeight() } }); - // A column carried to the window's right edge shows where it lands as a - // rail in the last cell: the layers under it stop a cell short. - if (v.drag == .column_move) rail: { - const d = v.drag.column_move; - const source = layout.columnBySerial(p, d.serial) orelse break :rail; - const edge: u16 = switch (layout.columnDrop(p, source, d.cur_x, d.grab)) { - .stay => break :rail, - .reorder => |target| if (target < source) v.col_x[target] else v.col_x[target] + v.col_w[target], - .edge => |x| x, - }; - if (edge != s.cols) break :rail; - for (s.regions[0..s.nregions]) |*region| switch (region.kind) { - .body, .tag, .notice, .column_tag => if (region.rect.x + region.rect.w == s.cols) { - region.clip = 1; - }, - else => {}, - }; - } } /// A pane's grip in the grid: `box` focused, else halfway between its ring @@ -252,8 +234,6 @@ fn joinNotice(p: *Pardes, s: *Surface, arena: std.mem.Allocator, region: Region) if (layer.cursor) |caret| { if (caret.x >= skip) s.cursor = .{ .x = region.rect.x + caret.x - @as(u16, @intCast(skip)), .y = region.rect.y, .bar = caret.bar }; } - // Laid out at its full width; only shown short of the rail. - layer.viewport.w -|= region.clip; } pub fn render(p: *Pardes, arena: std.mem.Allocator) !*Surface { @@ -327,77 +307,6 @@ pub fn render(p: *Pardes, arena: std.mem.Allocator) !*Surface { try paintHeaders(p, s); - switch (v.drag) { - .border_v => |d| { - if (d.cur_x < s.cols) { - var row: u16 = p.topBarHeight(); - while (row < s.rows) : (row += 1) s.overlayDash(d.cur_x, row, "╎"); - s.addRegion(.{ .kind = .guide, .rect = .{ .x = d.cur_x, .y = p.topBarHeight(), .w = 1, .h = s.rows -| p.topBarHeight() } }); - } - if (d.corner) |k| if (d.cur_y < s.rows) { - const first = if (k.col == d.left_col) v.col_x[k.col] else d.cur_x +| 1; - const end = if (k.col == d.left_col) d.cur_x else v.col_x[k.col] +| v.col_w[k.col] -| 1; - var col = first; - while (col <= end and col < s.cols) : (col += 1) s.overlayDash(col, d.cur_y, "╌"); - if (col > first) s.addRegion(.{ .kind = .guide, .rect = .{ .x = first, .y = d.cur_y, .w = col - first, .h = 1 } }); - }; - }, - // A column that went away mid-drag has nothing to guide. - .border_h => |d| if (d.cur_y < s.rows and d.col < v.ncol and v.col_x[d.col] < s.cols) { - const end = @min(s.cols, v.col_x[d.col] + v.col_w[d.col]); - var col = v.col_x[d.col]; - while (col < end) : (col += 1) s.overlayDash(col, d.cur_y, "╌"); - s.addRegion(.{ .kind = .guide, .rect = .{ .x = v.col_x[d.col], .y = d.cur_y, .w = end - v.col_x[d.col], .h = 1 } }); - }, - .column_move => |d| rail: { - const source = layout.columnBySerial(p, d.serial) orelse break :rail; - if (s.cols == 0) break :rail; - // Where the column's left edge would land, reordered or not. - const edge: u16 = switch (layout.columnDrop(p, source, d.cur_x, d.grab)) { - .stay => break :rail, - .reorder => |target| if (target < source) v.col_x[target] else v.col_x[target] + v.col_w[target], - .edge => |x| x, - }; - // The layers under an outside rail stop a cell short of it: - // `place` clipped them. - // The rail runs in the seam cell left of the edge, where a - // border drag's does: the edge cell itself is a gutter, which - // the GUI paints as a scroll rail that swallowed the dashes. - // At the window's left edge there is no seam, so it runs just - // past that scroll rail instead. It takes the lit grip's - // color: this is where the grabbed column lands. - const x = @min(if (edge == 0) config.GUTTER - 1 else edge - 1, s.cols -| 1); - var row: u16 = p.topBarHeight(); - // A guide region for each run of it the tags do not break. - var run: u16 = row; - while (row < s.rows) : (row += 1) { - // Past the left edge's scroll rail the rail would cut - // through column 0's grip and pane boxes: leave them whole. - if (edge == 0 and s.at(x, row).style.font_role == .tagline) { - if (row > run) s.addRegion(.{ .kind = .guide, .rect = .{ .x = x, .y = run, .w = 1, .h = row - run } }); - run = row + 1; - continue; - } - s.overlayDash(x, row, "╎"); - s.at(x, row).style.fg = .{ .rgb = chrome.column_box }; - } - if (row > run) s.addRegion(.{ .kind = .guide, .rect = .{ .x = x, .y = run, .w = 1, .h = row - run } }); - }, - .move => |d| if (d.cur_x < s.cols) { - if (layout.movePlacement(p, d.id, d.cur_x, d.cur_y)) |placement| if (placement.row < s.rows and v.col_x[placement.preview_col] + v.col_w[placement.preview_col] <= s.cols) { - var col: u16 = v.col_x[placement.preview_col]; - while (col < v.col_x[placement.preview_col] + v.col_w[placement.preview_col]) : (col += 1) { - s.set(col, placement.row, "╌", .{ .fg = .{ .rgb = chrome.lineno } }); - } - s.set(d.cur_x, placement.row, "▌", .{ .fg = .{ .rgb = chrome.lineno } }); - s.addRegion(.{ .kind = .guide, .rect = .{ .x = v.col_x[placement.preview_col], .y = placement.row, .w = v.col_w[placement.preview_col], .h = 1 } }); - s.addRegion(.{ .kind = .guide, .rect = .{ .x = d.cur_x, .y = placement.row, .w = 1, .h = 1 } }); - }; - }, - // A hover draws no hint: columns resize by their grips. - .none, .select => {}, - } - // debug overlay: a small stats box drawn last, top-right ("Debug") if (p.settings.debug) if (p.panes[v.active]) |at| { var nlive: usize = 0; @@ -606,8 +515,6 @@ fn paintHeaders(p: *Pardes, s: *Surface) !void { const layer = &s.tag_layers[MAX_PANES + c]; try renderHeaderLayer(p, layer, .column, @intCast(c), region.rect, tagline.columnTag(p, c), top, bg, fg); if (v.col_x[c] < s.cols) joinHeaderRows(s, layer, fg); - // Laid out at its full width; only shown short of the rail. - layer.viewport.w -|= region.clip; }; } @@ -809,7 +716,7 @@ fn joinPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r layer.kind = .pane; layer.id = @intCast(id); layer.serial = pane.serial; - layer.viewport = .{ .x = region.rect.x, .y = region.rect.y, .w = region.rect.w - region.clip, .h = rows }; + layer.viewport = .{ .x = region.rect.x, .y = region.rect.y, .w = region.rect.w, .h = rows }; layer.cols = columns; layer.rows = rows; layer.context_rows = 0; diff --git a/src/gui/gui.zig b/src/gui/gui.zig index 537271f1..120a4595 100644 --- a/src/gui/gui.zig +++ b/src/gui/gui.zig @@ -861,12 +861,12 @@ const Group = struct { }; /// The frame's draw groups, bottom to top: the page and the panes, the -/// notices floating over them, the guides and the debug box the core paints -/// over those, and ink (the bar cursors; the cursor's glide draws after it). +/// notices floating over them, the debug box the core paints over those, +/// and ink (the bar cursors; the cursor's glide draws after it). const Groups = struct { items: [4]Group = @splat(.{}), notices: usize = 1, - guides: usize = 2, + debug: usize = 2, ink: usize = 3, len: usize = 4, }; @@ -876,7 +876,7 @@ const Groups = struct { const Cover = packed struct(u16) { /// A layer draws it; the grid's copy is not drawn. layer: bool = false, - /// Under a guide or the debug box: drawn from the grid over the panes. + /// Under the debug box: drawn from the grid over the panes. floating: bool = false, /// In a pane's grip, `grip_offset` cells from its left: the grip's /// glyph is the cell that far to the left. @@ -943,7 +943,7 @@ fn coverFrame(cover: []Cover, cols: u16, rows: u16, body_layers: []const pardes. mark.rect(cover, cols, rows, .{ .x = region.rect.x, .y = 0, .w = 1, .h = rows }, "anchor", true); if (region.active) if (bar) |b| mark.rect(cover, cols, rows, .{ .x = region.rect.x, .y = b.y, .w = region.rect.w, .h = b.h }, "focus", true); }, - .guide, .debug => mark.rect(cover, cols, rows, region.rect, "floating", true), + .debug => mark.rect(cover, cols, rows, region.rect, "floating", true), else => {}, }; } @@ -4548,7 +4548,7 @@ fn renderFrame( while (col < surface.cols) : (col += 1) { const at = @as(usize, row) * surface.cols + col; if (covered[at].layer and !covered[at].floating) continue; - const group_index = if (covered[at].floating) groups.guides else 0; + const group_index = if (covered[at].floating) groups.debug else 0; groups.items[group_index].cell_count = std.math.add(u32, groups.items[group_index].cell_count, cellInstanceCount(&surface.cells[at])) catch return error.GpuCapacity; } } @@ -4597,7 +4597,7 @@ fn renderFrame( while (col < surface.cols) : (col += 1) { const at = @as(usize, row) * surface.cols + col; if (covered[at].layer and !covered[at].floating) continue; - const group_index = if (covered[at].floating) groups.guides else 0; + const group_index = if (covered[at].floating) groups.debug else 0; emitSurfaceCell( g, chrome, diff --git a/src/layout.zig b/src/layout.zig index fca4c846..0cfbf04a 100644 --- a/src/layout.zig +++ b/src/layout.zig @@ -180,8 +180,8 @@ pub fn columnDrop(p: *const Pardes, source: usize, x: u16, grab: u16) ColumnDrop } /// Share out the width of columns `left` and `left + 1` so the left one is -/// `left_width` cells, neither below MINW. A border drag and a column grip -/// dropped inside its own place both end here. +/// `left_width` cells, neither below MINW. A column grip dropped inside its +/// own place ends here. pub fn setColumnPairWidth(p: *Pardes, left: usize, left_width: u64) void { const v = p.view(); if (left + 1 >= v.ncol) return; @@ -2099,15 +2099,7 @@ test "repeated non-dyadic column splits preserve every unrelated boundary" { try std.testing.expect(splitColumn(p, 0, 1, false)); p.sync(); - const handle = p.view().col_x[0] + p.view().col_w[0] - 1; - const untouched = weightsOf(p); - p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = handle, .row = TOPBAR_H + 1 } }); - p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = handle, .row = TOPBAR_H + 1 } }); - try std.testing.expectEqual(untouched, weightsOf(p)); - - p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = handle, .row = TOPBAR_H + 1 } }); - p.update(.{ .mouse = .{ .button = .left, .kind = .drag, .col = 417, .row = TOPBAR_H + 1 } }); - p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = 417, .row = TOPBAR_H + 1 } }); + setColumnPairWidth(p, 0, 418); p.sync(); try std.testing.expectEqual(@as(u16, 418), p.view().rects[0].w); diff --git a/src/mouse.zig b/src/mouse.zig index 783b12b7..2ca984ba 100644 --- a/src/mouse.zig +++ b/src/mouse.zig @@ -1,6 +1,5 @@ //! The mouse: what a pointer is over, the three buttons' presses, drags and -//! releases (acme's chords, border and seam drags, gestures), and the -//! chrome targets a shell asks about. +//! releases (acme's chords, grip and seam drags, gestures). const pardes = @import("pardes.zig"); const tagline = @import("tagline.zig"); const exec = @import("exec.zig"); @@ -19,7 +18,6 @@ const Pane = panes.Pane; const MAX_PANES = pardes.MAX_PANES; const Layer = @import("Layer.zig"); const Jump = @import("Jump.zig"); -const TOPBAR_H = pardes.TOPBAR_H; const BOX_H = pardes.BOX_H; const TAG_TEXT_INSET = pardes.TAG_TEXT_INSET; const Builtin = pardes.Builtin; @@ -29,7 +27,6 @@ const Pardes = pardes.Pardes; pub const Drag = union(enum) { none, - border_v: struct { left_col: usize, cur_x: u16, corner: ?struct { col: usize, idx: usize } = null, cur_y: u16 = 0 }, border_h: struct { col: usize, top_idx: usize, cur_y: u16 }, move: struct { id: usize, cur_x: u16, cur_y: u16 }, /// `grab`: how far into the grip it was pressed, so the column's left @@ -58,7 +55,7 @@ pub const Drag = union(enum) { fn button(drag: Drag) ?Mouse.Button { return switch (drag) { .none => null, - .border_v, .border_h, .move, .column_move => config.select_button, + .border_h, .move, .column_move => config.select_button, .select => |selection| selection.button, }; } @@ -126,38 +123,6 @@ fn seamRowOf(p: *const Pardes, c: usize, k: usize) u16 { return r.y + r.h -| 1; } -pub const ChromeTarget = struct { col: u16, row: u16 }; - -/// The chrome a press at `col`, `row` takes: the tag rows; then, -/// on the cell, a pane's grip, a column's handle or a seam; then a cell -/// away, any of a pane's tag, a handle or a seam. -pub fn chromeTarget(p: *const Pardes, col: u16, row: u16) ?ChromeTarget { - const v = p.view(); - if (row < p.topBarHeight() + layout.columnBarHeight(p)) return .{ .col = col, .row = row }; - for ([_]u16{ 0, 1 }) |slack| { - for (p.panes, 0..) |slot, id| { - const pane = slot orelse continue; - const rect = v.rects[id]; - const tag = p.tagTop(pane, rect); - const edge = if (slack == 0) rect.x + config.GUTTER else rect.x + rect.w; - if (row >= tag and row < tag + pane.tag_rows and col >= rect.x and col < rect.x + rect.w and col < edge) - return .{ .col = col, .row = row }; - } - for (0..p.view().ncol -| 1) |column| { - const handle = v.col_x[column] + v.col_w[column] -| 1; - if (@max(col, handle) - @min(col, handle) == slack) return .{ .col = handle, .row = row }; - } - for (0..p.view().ncol) |column| { - if (col < v.col_x[column] or col >= v.col_x[column] + v.col_w[column]) continue; - for (0..p.view().cols[column].n -| 1) |index| { - const seam = seamRowOf(p, column, index); - if (@max(row, seam) - @min(row, seam) == slack) return .{ .col = col, .row = seam }; - } - } - } - return null; -} - pub fn paneAt(p: *const Pardes, col: u16, row: u16) ?usize { for (p.panes, 0..) |slot, id| { if (slot == null) continue; @@ -781,18 +746,6 @@ pub fn handleMouse(p: *Pardes, event: Mouse) void { return; } } - for (0..p.view().ncol -| 1) |c| { - if (mcol == v.col_x[c] + v.col_w[c] -| 1) { - const corner: @FieldType(@FieldType(Drag, "border_v"), "corner") = if (seamIdxAt(p, c, mrow)) |k| - .{ .col = c, .idx = k } - else if (seamIdxAt(p, c + 1, mrow)) |k| - .{ .col = c + 1, .idx = k } - else - null; - v.drag = .{ .border_v = .{ .left_col = c, .cur_x = mcol, .corner = corner, .cur_y = mrow } }; - return; - } - } // Two panes are resized on the rule between them, never on a // row of text; with no rule, by the grip, as acme moves a // window by its button. @@ -923,12 +876,6 @@ fn seamIdxAt(p: *const Pardes, c: usize, mrow: u16) ?usize { return null; } -fn clampBorderCol(lx: u16, lw: u16, rw: u16, mcol: u16) u16 { - const lo = lx + config.MINW; - const hi = lx +| lw +| rw -| config.MINW; - return if (lo <= hi) std.math.clamp(mcol, lo, hi) else mcol; -} - fn clampBorderRow(ay: u16, ah: u16, bh: u16, mrow: u16) u16 { const lo = ay + BOX_H - 1; const hi = ay +| ah +| bh -| (BOX_H + 1); @@ -938,20 +885,6 @@ fn clampBorderRow(ay: u16, ah: u16, bh: u16, mrow: u16) u16 { pub fn dragUpdate(p: *Pardes, mcol: u16, mrow: u16, body_hit: ?Mouse.BodyHit) void { const v = p.view(); switch (v.drag) { - .border_v => |*d| { - const c = d.left_col; - d.cur_x = if (c + 1 < v.ncol) - clampBorderCol(v.col_x[c], v.col_w[c], v.col_w[c + 1], mcol) - else - mcol; - if (d.corner) |k| if (k.idx + 1 < v.cols[k.col].n) { - const a = v.rects[v.cols[k.col].panes[k.idx]]; - const b = v.rects[v.cols[k.col].panes[k.idx + 1]]; - d.cur_y = clampBorderRow(a.y, a.h, b.h, mrow); - } else { - d.cur_y = mrow; - }; - }, .border_h => |*d| { const cc = d.col; const k = d.top_idx; @@ -1239,18 +1172,6 @@ fn dragRelease(p: *Pardes, button: Mouse.Button) void { defer v.drag = .none; defer v.chord_hold = false; switch (v.drag) { - .border_v => |d| { - const c = d.left_col; - const old_seam = v.col_x[c] + v.col_w[c] -| 1; - // the handle is the left pane's LAST column (inclusive), so - // the new width includes it — a no-drag click changes nothing - if (c + 1 < v.ncol and d.cur_x != old_seam) - layout.setColumnPairWidth(p, c, (d.cur_x + 1) -| v.col_x[c]); - if (d.corner) |k| { - if (d.cur_y != seamRowOf(p, k.col, k.idx)) - layout.applyRowSplit(p, k.col, k.idx, d.cur_y); - } - }, .border_h => |d| if (d.cur_y != seamRowOf(p, d.col, d.top_idx)) 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)) { @@ -1391,7 +1312,7 @@ fn dragRelease(p: *Pardes, button: Mouse.Button) void { const test_metrics: pardes.RowMetrics = .{ .body_w = 10, .body_h = 20, .tagline_w = 6, .tagline_h = 12 }; -fn cornerFixture(gpa: std.mem.Allocator) !*Pardes { +fn twoColumns(gpa: std.mem.Allocator) !*Pardes { const p = try Pardes.init(gpa, .{ .cols = 100, .rows = 30, .shells = 3 }); p.update(.{ .resize = .{ .cols = 100, .rows = 30 } }); p.view().active = p.view().cols[1].panes[0]; @@ -1463,7 +1384,7 @@ fn layerCenter(layer: *const Layer, col: u16, comptime tag: bool) [2]f32 { } test "a pane's last row of text is no resize handle; the rule over the next pane is" { - const p = try cornerFixture(std.testing.allocator); + const p = try twoColumns(std.testing.allocator); defer p.deinit(); const seam = seamRowOf(p, 1, 0); const inside = p.view().col_x[1] + p.view().col_w[1] / 2; @@ -1473,8 +1394,22 @@ test "a pane's last row of text is no resize handle; the rule over the next pane try std.testing.expect(nudgeRightSeam(p, 2) == seam + 2); } +test "the line between two columns is no resize handle: a press there is a sweep in the pane" { + const p = try twoColumns(std.testing.allocator); + defer p.deinit(); + const line = p.view().col_x[0] + p.view().col_w[0] - 1; + const row = p.view().rects[p.view().cols[0].panes[0]].y + BOX_H + 1; + const weight = p.view().cols[0].weight; + p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = line, .row = row } }); + try std.testing.expect(p.view().drag == .select); + p.update(.{ .mouse = .{ .button = .left, .kind = .drag, .col = line + 8, .row = row } }); + p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = line + 8, .row = row } }); + p.sync(); + try std.testing.expectEqual(weight, p.view().cols[0].weight); +} + test "a pane's grip dragged up or down its own column moves its top, down to the floor of the pane above" { - const p = try cornerFixture(std.testing.allocator); + const p = try twoColumns(std.testing.allocator); defer p.deinit(); const upper = p.view().cols[1].panes[0]; const lower = p.view().cols[1].panes[1]; @@ -1499,26 +1434,6 @@ test "a pane's grip dragged up or down its own column moves its top, down to the try std.testing.expectEqual(to, p.view().rects[lower].y); } -test "a press near chrome takes it: the tag rows, a column's handle or a seam on its cell or a cell away, a pane's tag; nothing in a body" { - const p = try cornerFixture(std.testing.allocator); - defer p.deinit(); - // Column 0's two panes share its rows evenly; column 1's lower one is - // tall, its middle a body row. - const handle = p.view().col_x[0] + p.view().col_w[0] - 1; - const seam = seamRowOf(p, 0, 0); - const mid = p.view().col_x[0] + p.view().col_w[0] / 2; - const top = p.view().rects[p.view().cols[0].panes[0]].y; - const low = p.view().rects[p.view().cols[1].panes[1]]; - const body = low.y + low.h / 2; - try std.testing.expectEqual(ChromeTarget{ .col = 5, .row = 0 }, chromeTarget(p, 5, 0).?); - try std.testing.expectEqual(ChromeTarget{ .col = handle, .row = body }, chromeTarget(p, handle, body).?); - try std.testing.expectEqual(ChromeTarget{ .col = handle, .row = body }, chromeTarget(p, handle + 1, body).?); - try std.testing.expectEqual(ChromeTarget{ .col = mid, .row = seam }, chromeTarget(p, mid, seam).?); - try std.testing.expectEqual(ChromeTarget{ .col = mid, .row = seam }, chromeTarget(p, mid, seam - 1).?); - try std.testing.expectEqual(ChromeTarget{ .col = mid, .row = top }, chromeTarget(p, mid, top).?); - try std.testing.expect(chromeTarget(p, mid, seam - 3) == null); -} - test "plain left click clears explicit modal selection" { const gpa = std.testing.allocator; // Wide enough for the tag on one row: the body starts under it. @@ -1558,144 +1473,6 @@ test "a selection drag and its release leave the selection done" { try std.testing.expectEqual(.done, pane.sel[sel_slot].state); } -test "a corner drag's two axes clamp independently" { - // a 100-wide window split 50/50, and a 30-row column split 15/14 under the - // topbar: the shape windowops.snap drives - const lx: u16 = 0; - const lw: u16 = 50; - const rw: u16 = 50; - const ay: u16 = TOPBAR_H; - const ah: u16 = 15; - const bh: u16 = 14; - const row_lo: u16 = ay + BOX_H - 1; - const row_hi: u16 = ay + ah + bh - (BOX_H + 1); - - // each axis alone, at both walls - try std.testing.expectEqual(@as(u16, config.MINW), clampBorderCol(lx, lw, rw, 0)); - try std.testing.expectEqual(@as(u16, 100 - config.MINW), clampBorderCol(lx, lw, rw, 999)); - try std.testing.expectEqual(row_lo, clampBorderRow(ay, ah, bh, 0)); - try std.testing.expectEqual(row_hi, clampBorderRow(ay, ah, bh, 999)); - - // THE corner property: drag off the right edge while staying mid-height — - // x sits at its wall, y still tracks the mouse row exactly - try std.testing.expectEqual(@as(u16, 100 - config.MINW), clampBorderCol(lx, lw, rw, 999)); - try std.testing.expectEqual(@as(u16, 12), clampBorderRow(ay, ah, bh, 12)); - // and the mirror: pinned at the bottom, x still free - try std.testing.expectEqual(row_hi, clampBorderRow(ay, ah, bh, 999)); - try std.testing.expectEqual(@as(u16, 40), clampBorderCol(lx, lw, rw, 40)); - // both pinned at once is just both walls, not a stuck gesture - try std.testing.expectEqual(@as(u16, config.MINW), clampBorderCol(lx, lw, rw, 0)); - try std.testing.expectEqual(row_hi, clampBorderRow(ay, ah, bh, 999)); - - // degenerate pairs pass through untouched, each on its own terms: a pane - // pair with no room stays draggable even when the column pair has room - try std.testing.expectEqual(@as(u16, 7), clampBorderCol(0, 5, 5, 7)); - try std.testing.expectEqual(@as(u16, 40), clampBorderCol(lx, lw, rw, 40)); - try std.testing.expectEqual(@as(u16, 9), clampBorderRow(TOPBAR_H, 1, 0, 9)); -} - -test "a v-handle press at the RIGHT column's seam drags both boundaries" { - const p = try cornerFixture(std.testing.allocator); - defer p.deinit(); - try std.testing.expectEqual(@as(usize, 2), p.view().cols[1].n); - - const handle = p.view().col_x[0] + p.view().col_w[0] - 1; - const right_seam = nudgeRightSeam(p, 3); - try std.testing.expect(right_seam != seamRowOf(p, 0, 0)); - - const w0 = p.view().cols[0].weight; - const v_left = p.panes[p.view().cols[0].panes[0]].?.vweight; - const v_right = p.panes[p.view().cols[1].panes[0]].?.vweight; - - p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = handle, .row = right_seam } }); - try std.testing.expect(p.view().drag == .border_v); - const corner = p.view().drag.border_v.corner orelse return error.NoCorner; - try std.testing.expectEqual(@as(usize, 1), corner.col); - try std.testing.expectEqual(@as(usize, 0), corner.idx); - - p.update(.{ .mouse = .{ .button = .left, .kind = .drag, .col = handle + 8, .row = right_seam - 4 } }); - p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = handle + 8, .row = right_seam - 4 } }); - p.sync(); - - // both halves committed: the column pair widened, and the RIGHT column's - // pane pair reweighted — while the left column's panes stayed put - try std.testing.expect(p.view().cols[0].weight > w0); - try std.testing.expect(p.panes[p.view().cols[1].panes[0]].?.vweight != v_right); - try std.testing.expectEqual(v_left, p.panes[p.view().cols[0].panes[0]].?.vweight); -} - -test "a tie row still moves the LEFT column's pane pair only" { - const p = try cornerFixture(std.testing.allocator); - defer p.deinit(); - - // put column 1's seam exactly on column 0's, the row the eye reads as one - // line across the whole window - const left_seam = seamRowOf(p, 0, 0); - _ = nudgeRightSeam(p, @as(i32, left_seam) - @as(i32, seamRowOf(p, 1, 0))); - try std.testing.expectEqual(left_seam, seamRowOf(p, 1, 0)); - - const handle = p.view().col_x[0] + p.view().col_w[0] - 1; - const v_left = p.panes[p.view().cols[0].panes[0]].?.vweight; - const v_right = p.panes[p.view().cols[1].panes[0]].?.vweight; - - p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = handle, .row = left_seam } }); - const corner = p.view().drag.border_v.corner orelse return error.NoCorner; - try std.testing.expectEqual(@as(usize, 0), corner.col); - - p.update(.{ .mouse = .{ .button = .left, .kind = .drag, .col = handle, .row = left_seam - 4 } }); - p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = handle, .row = left_seam - 4 } }); - p.sync(); - try std.testing.expect(p.panes[p.view().cols[0].panes[0]].?.vweight != v_left); - try std.testing.expectEqual(v_right, p.panes[p.view().cols[1].panes[0]].?.vweight); -} - -test "a v-handle press at nobody's seam is still a plain edge drag" { - const p = try cornerFixture(std.testing.allocator); - defer p.deinit(); - const right_seam = nudgeRightSeam(p, 3); - const left_seam = seamRowOf(p, 0, 0); - - const handle = p.view().col_x[0] + p.view().col_w[0] - 1; - var row: u16 = TOPBAR_H + 1; - while (row == left_seam or row == right_seam) row += 1; - - const w0 = p.view().cols[0].weight; - const v_left = p.panes[p.view().cols[0].panes[0]].?.vweight; - const v_right = p.panes[p.view().cols[1].panes[0]].?.vweight; - p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = handle, .row = row } }); - try std.testing.expect(p.view().drag == .border_v); - try std.testing.expect(p.view().drag.border_v.corner == null); - p.update(.{ .mouse = .{ .button = .left, .kind = .drag, .col = handle + 8, .row = row + 5 } }); - p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = handle + 8, .row = row + 5 } }); - p.sync(); - // exactly ONE boundary moved - try std.testing.expect(p.view().cols[0].weight > w0); - try std.testing.expectEqual(v_left, p.panes[p.view().cols[0].panes[0]].?.vweight); - try std.testing.expectEqual(v_right, p.panes[p.view().cols[1].panes[0]].?.vweight); -} - -test "a RIGHT-column corner's two axes clamp independently" { - const p = try cornerFixture(std.testing.allocator); - defer p.deinit(); - const right_seam = nudgeRightSeam(p, 3); - const handle = p.view().col_x[0] + p.view().col_w[0] - 1; - p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = handle, .row = right_seam } }); - try std.testing.expectEqual(@as(usize, 1), (p.view().drag.border_v.corner orelse return error.NoCorner).col); - - // off the right edge at mid-height: x parks at its MINW wall, y is the mouse - p.update(.{ .mouse = .{ .button = .left, .kind = .drag, .col = 999, .row = right_seam } }); - try std.testing.expectEqual(@as(u16, 100 - config.MINW), p.view().drag.border_v.cur_x); - try std.testing.expectEqual(right_seam, p.view().drag.border_v.cur_y); - - // and the mirror: below the bottom at mid-width. y parks, x tracks again - p.update(.{ .mouse = .{ .button = .left, .kind = .drag, .col = handle, .row = 999 } }); - try std.testing.expectEqual(handle, p.view().drag.border_v.cur_x); - const a = p.view().rects[p.view().cols[1].panes[0]]; - const b = p.view().rects[p.view().cols[1].panes[1]]; - try std.testing.expectEqual(clampBorderRow(a.y, a.h, b.h, 999), p.view().drag.border_v.cur_y); - p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = handle, .row = 999 } }); -} - 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(); diff --git a/src/surface.zig b/src/surface.zig index 9333a75e..ca517d3b 100644 --- a/src/surface.zig +++ b/src/surface.zig @@ -205,8 +205,6 @@ pub const Region = struct { /// A column below the workspace tag, its bar and panes: its left /// edge is the spine a pixel shell rules down it. column, - /// A drag's guide or a seam's hover hint, drawn over the panes. - guide, /// The debug stats box, drawn over the panes. debug, }; @@ -244,15 +242,9 @@ pub const Region = struct { /// it shows, in pixels. Its placements are laid at the whole pixel; a /// pixel frontend draws them the fraction higher. scroll_px: f64 = 0, - /// Cells the column-move rail takes off the right edge while it runs - /// there: layers and pixel shells stop short of them, the grid does not. - clip: u16 = 0, }; -/// Guides a frame can draw: a run of a column-move rail per pane it skips -/// the tags of, and a handful of border and hover dashes. -pub const MAX_GUIDES = MAX_PANES + 4; -pub const MAX_REGIONS = 1 + MAX_PANES * (4 + panes.Pane.Notices.max) + pardes.MAX_COLS * 3 + 1 + MAX_GUIDES + 1; +pub const MAX_REGIONS = 1 + MAX_PANES * (4 + panes.Pane.Notices.max) + pardes.MAX_COLS * 3 + 1 + 1; /// The colours a pixel shell draws its chrome in (rules, rails, grips, the /// tag underlay), resolved by the core each frame, so a frontend attached @@ -470,14 +462,6 @@ pub const Surface = struct { while (xx < x + w) : (xx += 1) s.at(xx, yy).* = .{}; } } - - /// swap ONLY the glyph, keeping the cell's colors — the resize-handle hint - pub fn overlayDash(s: *Surface, x: u16, y: u16, glyph: []const u8) void { - const c = s.at(x, y); - @memcpy(c.text[0..glyph.len], glyph); - c.len = @intCast(glyph.len); - c.default = false; - } }; test "cell visual equality ignores dead grapheme tail bytes" { diff --git a/test/column_drag.zig b/test/column_drag.zig index e64656e3..a12ca16f 100644 --- a/test/column_drag.zig +++ b/test/column_drag.zig @@ -84,7 +84,6 @@ test "column grip drag moves only its interval and keeps tag caret with the colu try std.testing.expect(p.view().drag == .column_move); mouse(p, .drag, target); _ = try p.render(frame.allocator()); - try std.testing.expectEqual(p.view().col_w[3] - pardes.TAG_TEXT_INSET - 1, (try tagLayer(p, 3)).viewport.w); try std.testing.expectEqual(last_rect, p.view().rects[p.view().cols[3].panes[0]]); try std.testing.expectEqual(last_columns, (try tagLayer(p, 3)).cols); try expectOrder(p, &before, &.{ 0, 1, 2, 3 }); @@ -121,7 +120,7 @@ test "column grip drag moves only its interval and keeps tag caret with the colu try std.testing.expect(p.view().drag == .none); } -test "column grip is separate from compact text and the resize seam" { +test "column grip is separate from compact text" { const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 24 }); defer p.deinit(); _ = try p.setTestFile("body\n"); @@ -160,11 +159,6 @@ test "column grip is separate from compact text and the resize seam" { mouse(p, .press, p.view().col_x[1] + config.GUTTER - 1); try std.testing.expect(p.view().drag == .column_move); mouse(p, .release, p.view().col_x[1] + config.GUTTER - 1); - const seam = p.view().col_x[0] + p.view().col_w[0] - 1; - const body_row = p.view().rects[p.view().cols[0].panes[0]].y + pardes.BOX_H + 1; - p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = seam, .row = body_row } }); - try std.testing.expect(p.view().drag == .border_v); - p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = seam, .row = body_row } }); } test "column grips stay blank, and muted across focus and hover until grabbed" { @@ -238,32 +232,7 @@ test "column grip dropped in its own place moves the column's left edge" { try std.testing.expectEqual(serials[0], p.view().cols[1].serial); } -/// The column of the drag preview's rail, checked to run the full height -/// below the workspace tag in the grabbed grip's color, except through the -/// grip and pane boxes at the window's left edge. -fn previewRail(p: *Pardes, frame: *std.heap.ArenaAllocator) !?u16 { - _ = frame.reset(.retain_capacity); - const surface = try p.render(frame.allocator()); - const lit: pardes.Color = .{ .rgb = p.chromeTheme().column_box }; - var found: ?u16 = null; - for (0..surface.cols) |x| { - if (!std.mem.eql(u8, surface.at(@intCast(x), surface.rows - 1).grapheme(), "╎")) continue; - try std.testing.expect(found == null); - found = @intCast(x); - for (p.topBarHeight()..surface.rows) |row| { - const cell = surface.at(@intCast(x), @intCast(row)); - if (x < config.GUTTER and cell.style.font_role == .tagline) { - try std.testing.expect(!std.mem.eql(u8, cell.grapheme(), "╎")); - continue; - } - try std.testing.expectEqualStrings("╎", cell.grapheme()); - try std.testing.expectEqual(lit, cell.style.fg); - } - } - return found; -} - -test "column grip drag previews where the column lands, in the seam beside its rule" { +test "column grip drag lands where it is carried, lighting no word on the way" { const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 120, .rows = 24 }); defer p.deinit(); _ = try p.setTestFile("body\n"); @@ -278,15 +247,10 @@ test "column grip drag previews where the column lands, in the seam beside its r _ = try p.render(frame.allocator()); const serials = .{ p.view().cols[0].serial, p.view().cols[1].serial, p.view().cols[2].serial }; - // Held on its own grip it lands nowhere new: no rail. + // Over the first column's left half it goes first. mouse(p, .press, p.view().col_x[1]); - mouse(p, .drag, p.view().col_x[1] + 1); - try std.testing.expectEqual(@as(?u16, null), try previewRail(p, &frame)); - // Over the first column's left half it goes first. The window edge has - // no seam, and the gutter there is the GUI's scroll rail, so the rail - // runs in the gutter's last cell. mouse(p, .drag, 3); - try std.testing.expectEqual(@as(?u16, config.GUTTER - 1), try previewRail(p, &frame)); + _ = try p.render(frame.allocator()); // The pointer is over the first column's "New", but a carried column // aims at a place: no word lights under it. for (0..p.view().screen_w) |x| try std.testing.expect(!std.meta.eql(p.surface.at(@intCast(x), pardes.TOPBAR_H).style.bg, pardes.Color{ .rgb = p.theme().sel_bg })); @@ -294,28 +258,18 @@ test "column grip drag previews where the column lands, in the seam beside its r try std.testing.expectEqual(serials[1], p.view().cols[0].serial); try std.testing.expectEqual(serials[0], p.view().cols[1].serial); - // Past the middle column's middle it lands after it: the rail is in the - // seam cell left of the last column's rule, where a border drag's is. + // Past the last column's middle it goes last. mouse(p, .press, p.view().col_x[0]); - const past = p.view().col_x[1] + p.view().col_w[1] - 2; - mouse(p, .drag, past); - try std.testing.expectEqual(@as(?u16, p.view().col_x[2] - 1), try previewRail(p, &frame)); - // Past the last column's middle: the window's last cell. mouse(p, .drag, p.view().col_x[2] + p.view().col_w[2] - 1); - try std.testing.expectEqual(@as(?u16, p.view().screen_w - 1), try previewRail(p, &frame)); mouse(p, .release, p.view().col_x[2] + p.view().col_w[2] - 1); try std.testing.expectEqual(serials[0], p.view().cols[0].serial); try std.testing.expectEqual(serials[2], p.view().cols[1].serial); try std.testing.expectEqual(serials[1], p.view().cols[2].serial); - // Short of a neighbour's middle the left edge moves, and the preview - // is the seam that edge will have: exactly where the release puts it. + // Short of a neighbour's middle the left edge moves. const edge = p.view().col_x[2]; mouse(p, .press, edge + 1); - mouse(p, .drag, edge + 1 - 6); - try std.testing.expectEqual(@as(?u16, edge - 6 - 1), try previewRail(p, &frame)); mouse(p, .release, edge + 1 - 6); _ = try p.render(frame.allocator()); try std.testing.expectEqual(edge - 6, p.view().col_x[2]); - try std.testing.expectEqual(@as(?u16, null), try previewRail(p, &frame)); } diff --git a/test/process/tty_images.zig b/test/process/tty_images.zig index dea9feef..5c39d4f3 100644 --- a/test/process/tty_images.zig +++ b/test/process/tty_images.zig @@ -50,7 +50,7 @@ fn images(gpa: std.mem.Allocator, exe: [:0]const u8) !void { // the tag takes an edit like any other pane's now — nothing live left in it to // protect, so the image early-return in enterTagEdit is gone. The image-state // prefix is wider than this source-local column, so widen the grid for this - // final assertion. (A column-border drag intentionally takes width from only + // final assertion. (A column grip drag intentionally takes width from only // one neighbour, which cannot expose this 82-column prefix.) Then click the // visible tail itself, at its `Term`. This proves the image tag is an ordinary // editor rather than accidentally typing at a clipped read-only path. diff --git a/test/process/tty_layout.zig b/test/process/tty_layout.zig index 84f76be7..08a02488 100644 --- a/test/process/tty_layout.zig +++ b/test/process/tty_layout.zig @@ -5,8 +5,6 @@ const Tty = @import("../tty.zig").Tty; pub const cases = .{ .{ "tty layout: colgrip", colgrip }, .{ "tty layout: collapse", collapse }, - .{ "tty layout: cornerdrag", cornerdrag }, - .{ "tty layout: cornerdrag-left", cornerdrag_left }, .{ "tty layout: delask", delask }, .{ "tty layout: emptycol", emptycol }, .{ "tty layout: layout-close", layout_close }, @@ -20,7 +18,7 @@ pub const cases = .{ }; // Column grips: the two cells left of a column tag carry the column. A grabbed -// grip lights, and a rail in its color stands where the column will land. +// grip lights. // The right column is at x 50; its grip is cells 51-52 (1-based) on row 2. fn colgrip(gpa: std.mem.Allocator, exe: [:0]const u8) !void { var t = try Tty.init(gpa, exe, "colgrip"); @@ -34,12 +32,11 @@ fn colgrip(gpa: std.mem.Allocator, exe: [:0]const u8) !void { try t.key("a-c"); try t.stable(700, 15000); try t.style("rest"); - // held on its own grip: lit, and no rail, since it lands where it is + // held on its own grip: lit try t.press("left", "51", 2); try t.stable(400, 5000); try t.style("held"); - // dropped short of the left column's middle, the left edge moves: the rail is - // in the seam cell left of where the column's rule will be + // dropped short of the left column's middle, the left edge moves try t.drag("left", "41", 2); try t.stable(400, 5000); try t.snap("resize-drag"); @@ -47,8 +44,7 @@ fn colgrip(gpa: std.mem.Allocator, exe: [:0]const u8) !void { try t.release("left", "41", 2); try t.stable(700, 15000); try t.snap("resize-done"); - // carried over the left column's left half it goes first; the window edge - // has no seam, so the rail runs in the gutter's last cell + // carried over the left column's left half it goes first try t.press("left", "41", 2); try t.drag("left", "10", 2); try t.stable(400, 5000); @@ -107,109 +103,6 @@ fn collapse(gpa: std.mem.Allocator, exe: [:0]const u8) !void { try t.done(); } -// corner grabs: where a column edge crosses a pane edge, ONE drag moves both. -// Only the left column's h-splits make a corner — the v handle IS that column's -// last cell, so that is the only pane pair whose horizontal hint runs through -// it, and a corner therefore sits exactly where the two lines visibly cross. -// The layout is windowops': col 0 (x 0, w 50) holds panes 0 (rows 1-15) and 1 -// (rows 16-29), col 1 holds one pane. The corner is col 49, row 15. -fn cornerdrag(gpa: std.mem.Allocator, exe: [:0]const u8) !void { - var t = try Tty.init(gpa, exe, "cornerdrag"); - defer t.deinit(); - try t.file("w.txt", "x"); - try t.start(31, 100, &.{ "-n", "3" }); - try t.wait(8000, "w.txt"); - try t.stable(700, 20000); - // hover the corner: no hints (columns resize by their grips); the frame - // stays empty - try t.motion("50", 16); - try t.stable(400, 5000); - try t.snap("hover-corner"); - // CONTROL: the same vertical edge ten rows off the crossing is a plain edge. - // The identical diagonal drag moves the column and nothing else — pane 0 still - // ends on row 15, and the preview is one dash, not two - try t.press("left", "50", 7); - try t.drag("left", "30", 25); - try t.stable(400, 5000); - try t.snap("edge-drag"); - try t.release("left", "30", 25); - try t.motion("45", 25); - try t.stable(500, 8000); - try t.snap("edge-done"); - // the corner itself, now at col 0's new last col (29) and still row 15: drag it - // up and to the right and both boundaries follow the one mouse - try t.press("left", "30", 17); - try t.drag("left", "60", 9); - try t.stable(400, 5000); - try t.snap("corner-drag"); - try t.release("left", "60", 9); - try t.motion("45", 25); - try t.stable(500, 8000); - try t.snap("corner-done"); - // clamp interaction, half one: shove the corner off the right edge while - // staying mid-height. The column preview parks at its MINW stop; the row - // preview keeps tracking the mouse exactly - try t.press("left", "60", 9); - try t.drag("left", "99", 21); - try t.stable(400, 5000); - try t.snap("clamp-x"); - // half two, the mirror: below the bottom at mid-width. Now the ROW preview - // parks (the lower pane keeps its tag row) and the COLUMN keeps tracking - try t.drag("left", "60", 31); - try t.stable(400, 5000); - try t.snap("clamp-y"); - try t.release("left", "60", 31); - try t.motion("45", 25); - try t.stable(500, 8000); - try t.snap("clamp-done"); - try t.done(); -} - -// corner grabs on the RIGHT column's side of the v border. The v handle is the -// LEFT column's last cell, so that column's own h hint runs THROUGH it while the -// right column's hints start one cell further right — the crossing there reads as -// a T butting into the junction rather than a full cross, and it is grabbable all -// the same: one drag moves the column edge and the RIGHT column's pane edge. -// Layout: windowops' -n 3 (col 0 x 0 w 50, panes on rows 1-15 and 16-29; col 1 -// x 50 w 50), then focus right and Alt-n so col 1 holds two panes as well, split -// at ITS own row. The two corners on col 49 are then row 16 (col 0's seam, the -// one that already worked) and row 5 (col 1's, the one this script is about). -fn cornerdrag_left(gpa: std.mem.Allocator, exe: [:0]const u8) !void { - var t = try Tty.init(gpa, exe, "cornerdrag-left"); - defer t.deinit(); - try t.file("w.txt", "x"); - try t.start(31, 100, &.{ "-n", "3" }); - try t.wait(8000, "w.txt"); - try t.stable(700, 20000); - // a second pane in the RIGHT column - try t.key("c-w l enter"); - try t.stable(400, 5000); - try t.key("a-n"); - try t.stable(700, 15000); - try t.snap("right-split"); - // hover col 1's corner: hovering draws no hints any more, so the frame is - // empty; the drags below still show their previews - try t.motion("50", 5); - try t.stable(400, 5000); - try t.snap("hover-corner"); - // CONTROL: col 0's own seam, hovered: no hint either - try t.motion("50", 16); - try t.stable(400, 5000); - try t.snap("hover-left-corner"); - // grab col 1's corner and drag down-left: the column preview and col 1's row - // preview both follow the one mouse, the row dashes lying to the RIGHT of the v - // line because they are the right column's - try t.press("left", "50", 6); - try t.drag("left", "30", 13); - try t.stable(400, 5000); - try t.snap("corner-drag"); - try t.release("left", "30", 13); - try t.motion("45", 25); - try t.stable(500, 8000); - try t.snap("corner-done"); - try t.done(); -} - // Del from the keyboard on a pane with open panes above AND below asks, on the // 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. @@ -479,8 +372,8 @@ fn shrinktag(gpa: std.mem.Allocator, exe: [:0]const u8) !void { try t.motion("40", 25); try t.stable(500, 8000); try t.snap("shrunk"); - // the shrunk pane's gutter box grabs a move: preview one into the right - // column, abort by releasing over the pane itself + // the shrunk pane's gutter box grabs a move: carried into the right column + // nothing shows until the release, aborted by releasing over the pane itself try t.press("left", "1", 3); try t.drag("left", "70", 9); try t.stable(400, 5000); @@ -576,10 +469,11 @@ fn tagalign2col(gpa: std.mem.Allocator, exe: [:0]const u8) !void { try t.key("a-n"); try t.stable(700, 15000); try t.snap("aligned"); - // Resizing moves the right column as a whole and clips without hidden spaces. - try t.press("left", "80", 11); - try t.drag("left", "100", 11); - try t.release("left", "100", 11); + // Resizing by the right column's grip moves it as a whole and clips + // without hidden spaces. + try t.press("left", "81", 2); + try t.drag("left", "101", 2); + try t.release("left", "101", 2); try t.stable(700, 15000); try t.snap("widened"); try t.done(); @@ -665,7 +559,7 @@ fn windownav(gpa: std.mem.Allocator, exe: [:0]const u8) !void { try t.done(); } -// hover (no hints), border drags, grip resize, move drag, Alt-n, Ctrl-w focus (window mode), Debug box +// hover (no hints), grip resize, move drag, Alt-n, Ctrl-w focus (window mode), Debug box fn windowops(gpa: std.mem.Allocator, exe: [:0]const u8) !void { var t = try Tty.init(gpa, exe, "windowops"); defer t.deinit(); @@ -681,14 +575,6 @@ fn windowops(gpa: std.mem.Allocator, exe: [:0]const u8) !void { try t.motion("20", 16); try t.stable(400, 5000); try t.snap("hover-h"); - // drag the vertical border 10 cols left - try t.press("left", "50", 11); - try t.drag("left", "40", 11); - try t.stable(400, 5000); - try t.snap("border-drag"); - try t.release("left", "40", 11); - try t.stable(500, 8000); - try t.snap("border-done"); // resize the left pair by the lower pane's grip, 4 rows up (a terminal has no // rule between panes; pane 0's last row is now 13) try t.press("left", "1", 18); @@ -696,7 +582,8 @@ fn windowops(gpa: std.mem.Allocator, exe: [:0]const u8) !void { try t.release("left", "1", 14); try t.stable(500, 8000); try t.snap("hborder-done"); - // move pane 1 (its gutter box) into the right column + // move pane 1 (its gutter box) into the right column: nothing shows until + // the release try t.press("left", "1", 18); try t.drag("left", "70", 9); try t.stable(400, 5000); diff --git a/test/snapshots/colgrip.golden b/test/snapshots/colgrip.golden index a76642b1..a64be69c 100644 --- a/test/snapshots/colgrip.golden +++ b/test/snapshots/colgrip.golden @@ -27,143 +27,46 @@ |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 History Debug Exit -| New Term Find Grep Joincol Delcol ╎ New Term Find Grep Joincol Delcol -| /tmp/pardes-snap/colgrip/cwd/w.txt Sa╎e Term Col /tmp/pardes-snap/colgrip/cwd Term+bash Save Mode -| lapse Follow Del ╎ Filter Collapse Del -| 1 x ╎ ls -| ╎ w.txt -| ╎ -| ╎ -| ╎ -| ╎ -| ╎ -| ╎ -| ╎ -| ╎ -| ╎ -| ╎ -| ╎ -| ╎ -| ╎ -| ╎ -| ╎ -| ╎ -| ╎ -| ╎ +| New Term Find Grep Joincol Delcol New Term Find Grep Joincol Delcol +| /tmp/pardes-snap/colgrip/cwd/w.txt Save Term Col /tmp/pardes-snap/colgrip/cwd Term+bash Save Mode +| lapse Follow Del Filter Collapse Del +| 1 x ls +| w.txt == style resize-drag grid=100x24 -|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-90 #dfbce5,#314738, 91-99 #becfc4,#314738, -|3: 0-1 d,#1d2824, 2-38 #b2c3b8,#1d2824, 39-49 #f4c086,#1d2824, 50-52 #f4c086,#314738, 53-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, -|7: 0-0 d,#608269, 1-38 d,#0d1410, 39-49 #f4c086,#0d1410, 50-50 #f4c086,#608269, 51-99 #f4c086,#0d1410, -|8: 0-0 d,#608269, 1-38 d,#0d1410, 39-49 #f4c086,#0d1410, 50-50 #f4c086,#608269, 51-99 #f4c086,#0d1410, -|9: 0-0 d,#608269, 1-38 d,#0d1410, 39-49 #f4c086,#0d1410, 50-50 #f4c086,#608269, 51-99 #f4c086,#0d1410, -|10: 0-0 d,#608269, 1-38 d,#0d1410, 39-49 #f4c086,#0d1410, 50-50 #f4c086,#608269, 51-99 #f4c086,#0d1410, -|11: 0-0 d,#608269, 1-38 d,#0d1410, 39-49 #f4c086,#0d1410, 50-50 #f4c086,#608269, 51-99 #f4c086,#0d1410, -|12: 0-0 d,#608269, 1-38 d,#0d1410, 39-49 #f4c086,#0d1410, 50-50 #f4c086,#608269, 51-99 #f4c086,#0d1410, -|13: 0-0 d,#608269, 1-38 d,#0d1410, 39-49 #f4c086,#0d1410, 50-50 #f4c086,#608269, 51-99 #f4c086,#0d1410, -|14: 0-0 d,#608269, 1-38 d,#0d1410, 39-49 #f4c086,#0d1410, 50-50 #f4c086,#608269, 51-99 #f4c086,#0d1410, -|15: 0-0 d,#608269, 1-38 d,#0d1410, 39-49 #f4c086,#0d1410, 50-50 #f4c086,#608269, 51-99 #f4c086,#0d1410, -|16: 0-0 d,#608269, 1-38 d,#0d1410, 39-49 #f4c086,#0d1410, 50-50 #f4c086,#608269, 51-99 #f4c086,#0d1410, -|17: 0-0 d,#608269, 1-38 d,#0d1410, 39-49 #f4c086,#0d1410, 50-50 #f4c086,#608269, 51-99 #f4c086,#0d1410, -|18: 0-0 d,#608269, 1-38 d,#0d1410, 39-49 #f4c086,#0d1410, 50-50 #f4c086,#608269, 51-99 #f4c086,#0d1410, -|19: 0-0 d,#608269, 1-38 d,#0d1410, 39-49 #f4c086,#0d1410, 50-50 #f4c086,#608269, 51-99 #f4c086,#0d1410, -|20: 0-0 d,#608269, 1-38 d,#0d1410, 39-49 #f4c086,#0d1410, 50-50 #f4c086,#608269, 51-99 #f4c086,#0d1410, -|21: 0-0 d,#608269, 1-38 d,#0d1410, 39-49 #f4c086,#0d1410, 50-50 #f4c086,#608269, 51-99 #f4c086,#0d1410, -|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 Term Find Grep Joincol Delcol New Term Find Grep Joincol Delcol |2: /tmp/pardes-snap/colgrip/cwd/w.txt Sav /tmp/pardes-snap/colgrip/cwd Term+bash Save Mode Filter Co |3: e Term Collapse Follow Del llapse Del |4: 1 x ls |5: w.txt -|6: -|7: -|8: -|9: -|10: -|11: -|12: -|13: -|14: -|15: -|16: -|17: -|18: -|19: -|20: -|21: -|22: -|23: == snap reorder-drag grid=100x24 cursor=44,6 -|4: ╎ 1 x ls -|5: ╎ w.txt -|6: ╎ -|7: ╎ -|8: ╎ -|9: ╎ -|10: ╎ -|11: ╎ -|12: ╎ -|13: ╎ -|14: ╎ -|15: ╎ -|16: ╎ -|17: ╎ -|18: ╎ -|19: ╎ -|20: ╎ -|21: ╎ -|22: ╎ -|23: ╎ == style reorder-drag grid=100x24 |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-80 #dfbce5,#314738, 81-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, -|7: 0-0 d,#608269, 1-39 #f4c086,#0d1410, 40-40 #f4c086,#608269, 41-99 #f4c086,#0d1410, -|8: 0-0 d,#608269, 1-39 #f4c086,#0d1410, 40-40 #f4c086,#608269, 41-99 #f4c086,#0d1410, -|9: 0-0 d,#608269, 1-39 #f4c086,#0d1410, 40-40 #f4c086,#608269, 41-99 #f4c086,#0d1410, -|10: 0-0 d,#608269, 1-39 #f4c086,#0d1410, 40-40 #f4c086,#608269, 41-99 #f4c086,#0d1410, -|11: 0-0 d,#608269, 1-39 #f4c086,#0d1410, 40-40 #f4c086,#608269, 41-99 #f4c086,#0d1410, -|12: 0-0 d,#608269, 1-39 #f4c086,#0d1410, 40-40 #f4c086,#608269, 41-99 #f4c086,#0d1410, -|13: 0-0 d,#608269, 1-39 #f4c086,#0d1410, 40-40 #f4c086,#608269, 41-99 #f4c086,#0d1410, -|14: 0-0 d,#608269, 1-39 #f4c086,#0d1410, 40-40 #f4c086,#608269, 41-99 #f4c086,#0d1410, -|15: 0-0 d,#608269, 1-39 #f4c086,#0d1410, 40-40 #f4c086,#608269, 41-99 #f4c086,#0d1410, -|16: 0-0 d,#608269, 1-39 #f4c086,#0d1410, 40-40 #f4c086,#608269, 41-99 #f4c086,#0d1410, -|17: 0-0 d,#608269, 1-39 #f4c086,#0d1410, 40-40 #f4c086,#608269, 41-99 #f4c086,#0d1410, -|18: 0-0 d,#608269, 1-39 #f4c086,#0d1410, 40-40 #f4c086,#608269, 41-99 #f4c086,#0d1410, -|19: 0-0 d,#608269, 1-39 #f4c086,#0d1410, 40-40 #f4c086,#608269, 41-99 #f4c086,#0d1410, -|20: 0-0 d,#608269, 1-39 #f4c086,#0d1410, 40-40 #f4c086,#608269, 41-99 #f4c086,#0d1410, -|21: 0-0 d,#608269, 1-39 #f4c086,#0d1410, 40-40 #f4c086,#608269, 41-99 #f4c086,#0d1410, -|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, +|4: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-39 #e5eee5,#0d1410, 40-40 #e5eee5,#608269, 41-99 #e5eee5,#0d1410, +|5: 0-0 d,#608269, 1-39 d,#0d1410, 40-40 d,#608269, 41-41 d,#0d1410, 42-99 #e5eee5,#0d1410, +|6: 0-0 d,#608269, 1-39 d,#0d1410, 40-40 d,#608269, 41-99 d,#0d1410, +|7: 0-0 d,#608269, 1-39 d,#0d1410, 40-40 d,#608269, 41-99 d,#0d1410, +|8: 0-0 d,#608269, 1-39 d,#0d1410, 40-40 d,#608269, 41-99 d,#0d1410, +|9: 0-0 d,#608269, 1-39 d,#0d1410, 40-40 d,#608269, 41-99 d,#0d1410, +|10: 0-0 d,#608269, 1-39 d,#0d1410, 40-40 d,#608269, 41-99 d,#0d1410, +|11: 0-0 d,#608269, 1-39 d,#0d1410, 40-40 d,#608269, 41-99 d,#0d1410, +|12: 0-0 d,#608269, 1-39 d,#0d1410, 40-40 d,#608269, 41-99 d,#0d1410, +|13: 0-0 d,#608269, 1-39 d,#0d1410, 40-40 d,#608269, 41-99 d,#0d1410, +|14: 0-0 d,#608269, 1-39 d,#0d1410, 40-40 d,#608269, 41-99 d,#0d1410, +|15: 0-0 d,#608269, 1-39 d,#0d1410, 40-40 d,#608269, 41-99 d,#0d1410, +|16: 0-0 d,#608269, 1-39 d,#0d1410, 40-40 d,#608269, 41-99 d,#0d1410, +|17: 0-0 d,#608269, 1-39 d,#0d1410, 40-40 d,#608269, 41-99 d,#0d1410, +|18: 0-0 d,#608269, 1-39 d,#0d1410, 40-40 d,#608269, 41-99 d,#0d1410, +|19: 0-0 d,#608269, 1-39 d,#0d1410, 40-40 d,#608269, 41-99 d,#0d1410, +|20: 0-0 d,#608269, 1-39 d,#0d1410, 40-40 d,#608269, 41-99 d,#0d1410, +|21: 0-0 d,#608269, 1-39 d,#0d1410, 40-40 d,#608269, 41-99 d,#0d1410, +|22: 0-0 d,#608269, 1-39 d,#0d1410, 40-40 d,#608269, 41-99 d,#0d1410, +|23: 0-0 d,#608269, 1-39 d,#0d1410, 40-40 d,#608269, 41-99 d,#0d1410, == snap reorder-done grid=100x24 cursor=4,6 |1: New Term Find Grep Joincol Delcol New Term Find Grep Joincol Delcol |2: /tmp/pardes-snap/colgrip/cwd Term+bash Save Mode Filter Co /tmp/pardes-snap/colgrip/cwd/w.txt Sav |3: llapse Del e Term Collapse Follow Del |4: ls 1 x |5: w.txt -|6: -|7: -|8: -|9: -|10: -|11: -|12: -|13: -|14: -|15: -|16: -|17: -|18: -|19: -|20: -|21: -|22: -|23: diff --git a/test/snapshots/cornerdrag-left.golden b/test/snapshots/cornerdrag-left.golden deleted file mode 100644 index d5c7b7fd..00000000 --- a/test/snapshots/cornerdrag-left.golden +++ /dev/null @@ -1,86 +0,0 @@ -== snap right-split grid=100x31 cursor=54,11 -| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config History Debug Exit -| New Term Find Grep Joincol Delcol New Term Find Grep Joincol Delcol -| /tmp/pardes-snap/cornerdrag-left/cwd Term+bash S /tmp/pardes-snap/cornerdrag-left/cwd Term+bash S -| ave Mode Filter Collapse Del ave Mode Filter Collapse Del -| ls ls -| w.txt w.txt -| -| /tmp/pardes-snap/cornerdrag-left/cwd Term+bash S -| ave Mode Filter Collapse Del -| ls -| w.txt -| -| -| -| -| -| -| /tmp/pardes-snap/cornerdrag-left/cwd Term+bash S -| ave Mode Filter Collapse Del -| ls -| w.txt -== snap hover-corner grid=100x31 cursor=54,11 -== snap hover-left-corner grid=100x31 cursor=54,11 -== snap corner-drag grid=100x31 cursor=54,11 -|1: New Term Find Grep Joincol ╎elcol New Term Find Grep Joincol Delcol -|2: /tmp/pardes-snap/cornerdrag╎left/cwd Term+bash S /tmp/pardes-snap/cornerdrag-left/cwd Term+bash S -|3: ave Mode Filter Collapse De╎ ave Mode Filter Collapse Del -|4: ls ╎ ls -|5: w.txt ╎ w.txt -|6: ╎ -|7: ╎ /tmp/pardes-snap/cornerdrag-left/cwd Term+bash S -|8: ╎ ave Mode Filter Collapse Del -|9: ╎ ls -|10: ╎ w.txt -|11: ╎ -|12: ╎ -|13: ╎ -|14: ╎ -|15: ╎ -|16: ╎ -|17: /tmp/pardes-snap/cornerdrag╎left/cwd Term+bash S -|18: ave Mode Filter Collapse De╎ -|19: ls ╎ -|20: w.txt ╎ -|21: ╎ -|22: ╎ -|23: ╎ -|24: ╎ -|25: ╎ -|26: ╎ -|27: ╎ -|28: ╎ -|29: ╎ -|30: ╎ -== snap corner-done grid=100x31 cursor=34,11 -|1: New Term Find Grep Joincol D New Term Find Grep Joincol Delcol -|2: /tmp/pardes-snap/cornerdrag- /tmp/pardes-snap/cornerdrag-left/cwd Term+bash Save Mode Filter Coll -|3: left/cwd Term+bash Save Mode apse Del -|4: Filter Collapse Del ls -|5: ls w.txt -|6: w.txt -|7: /tmp/pardes-snap/cornerdrag-left/cwd Term+bash Save Mode Filter Coll -|8: apse Del -|9: ls -|10: w.txt -|11: -|12: -|13: -|14: -|15: -|16: -|17: /tmp/pardes-snap/cornerdrag- -|18: left/cwd Term+bash Save Mode -|19: Filter Collapse Del -|20: ls -|21: w.txt -|22: -|23: -|24: -|25: -|26: -|27: -|28: -|29: -|30: diff --git a/test/snapshots/cornerdrag.golden b/test/snapshots/cornerdrag.golden deleted file mode 100644 index bd552949..00000000 --- a/test/snapshots/cornerdrag.golden +++ /dev/null @@ -1,239 +0,0 @@ -== snap hover-corner grid=100x31 cursor=4,6 -| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config History Debug Exit -| New Term Find Grep Joincol Delcol New Term Find Grep Joincol Delcol -| /tmp/pardes-snap/cornerdrag/cwd Term+bash Save M /tmp/pardes-snap/cornerdrag/cwd Term+bash Save M -| ode Filter Collapse Del ode Filter Collapse Del -| ls ls -| w.txt w.txt -| -| -| -| -| -| -| -| -| -| -| -| /tmp/pardes-snap/cornerdrag/cwd Term+bash Save M -| ode Filter Collapse Del -| ls -| w.txt -== snap edge-drag grid=100x31 cursor=4,6 -|1: New Term Find Grep Joincol ╎elcol New Term Find Grep Joincol Delcol -|2: /tmp/pardes-snap/cornerdrag╎cwd Term+bash Save M /tmp/pardes-snap/cornerdrag/cwd Term+bash Save M -|3: ode Filter Collapse Del ╎ ode Filter Collapse Del -|4: ls ╎ ls -|5: w.txt ╎ w.txt -|6: ╎ -|7: ╎ -|8: ╎ -|9: ╎ -|10: ╎ -|11: ╎ -|12: ╎ -|13: ╎ -|14: ╎ -|15: ╎ -|16: ╎ -|17: /tmp/pardes-snap/cornerdrag╎cwd Term+bash Save M -|18: ode Filter Collapse Del ╎ -|19: ls ╎ -|20: w.txt ╎ -|21: ╎ -|22: ╎ -|23: ╎ -|24: ╎ -|25: ╎ -|26: ╎ -|27: ╎ -|28: ╎ -|29: ╎ -|30: ╎ -== snap edge-done grid=100x31 cursor=4,7 -|1: New Term Find Grep Joincol D New Term Find Grep Joincol Delcol -|2: /tmp/pardes-snap/cornerdrag/ /tmp/pardes-snap/cornerdrag/cwd Term+bash Save Mode Filter Collapse -|3: cwd Term+bash Save Mode Filt Del -|4: er Collapse Del ls -|5: ls w.txt -|6: w.txt -|7: -|8: -|9: -|10: -|11: -|12: -|13: -|14: -|15: -|16: -|17: /tmp/pardes-snap/cornerdrag/ -|18: cwd Term+bash Save Mode Filt -|19: er Collapse Del -|20: ls -|21: w.txt -|22: -|23: -|24: -|25: -|26: -|27: -|28: -|29: -|30: -== snap corner-drag grid=100x31 cursor=4,7 -|1: New Term Find Grep Joincol D New Term Find Grep Joincol ╎elcol -|2: /tmp/pardes-snap/cornerdrag/ /tmp/pardes-snap/cornerdrag╎cwd Term+bash Save Mode Filter Collapse -|3: cwd Term+bash Save Mode Filt Del ╎ -|4: er Collapse Del ls ╎ -|5: ls w.txt ╎ -|6: w.txt ╎ -|7: ╎ -|8: ╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ -|9: ╎ -|10: ╎ -|11: ╎ -|12: ╎ -|13: ╎ -|14: ╎ -|15: ╎ -|16: ╎ -|17: /tmp/pardes-snap/cornerdrag/ ╎ -|18: cwd Term+bash Save Mode Filt ╎ -|19: er Collapse Del ╎ -|20: ls ╎ -|21: w.txt ╎ -|22: ╎ -|23: ╎ -|24: ╎ -|25: ╎ -|26: ╎ -|27: ╎ -|28: ╎ -|29: ╎ -|30: ╎ -== snap corner-done grid=100x31 cursor=4,6 -|1: New Term Find Grep Joincol Delcol New Term Find Grep Joincol Delcol -|2: /tmp/pardes-snap/cornerdrag/cwd Term+bash Save Mode Filter /tmp/pardes-snap/cornerdrag/cwd Term+b -|3: Collapse Del ash Save Mode Filter Collapse Del -|4: ls ls -|5: w.txt w.txt -|6: -|7: -|8: -|9: /tmp/pardes-snap/cornerdrag/cwd Term+bash Save Mode Filter -|10: Collapse Del -|11: ls -|12: w.txt -|13: -|14: -|15: -|16: -|17: -|18: -|19: -|20: -|21: -|22: -|23: -|24: -|25: -|26: -|27: -|28: -|29: -|30: -== snap clamp-x grid=100x31 cursor=4,6 -|1: New Term Find Grep Joincol Delcol New Term Find Grep Joincol D╎lcol -|2: /tmp/pardes-snap/cornerdrag/cwd Term+bash Save Mode Filter /tmp/pardes-snap/cornerdrag/╎wd Term+b -|3: Collapse Del ash Save Mode Filter Collaps╎ Del -|4: ls ls ╎ -|5: w.txt w.txt ╎ -|6: ╎ -|7: ╎ -|8: ╎ -|9: /tmp/pardes-snap/cornerdrag/cwd Term+bash Save Mode Filter ╎ -|10: Collapse Del ╎ -|11: ls ╎ -|12: w.txt ╎ -|13: ╎ -|14: ╎ -|15: ╎ -|16: ╎ -|17: ╎ -|18: ╎ -|19: ╎ -|20: ╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ -|21: ╎ -|22: ╎ -|23: ╎ -|24: ╎ -|25: ╎ -|26: ╎ -|27: ╎ -|28: ╎ -|29: ╎ -|30: ╎ -== snap clamp-y grid=100x31 cursor=4,6 -|1: New Term Find Grep Joincol Delcol ╎ New Term Find Grep Joincol Delcol -|2: /tmp/pardes-snap/cornerdrag/cwd Term+bash Save Mode Filte╎ /tmp/pardes-snap/cornerdrag/cwd Term+b -|3: Collapse Del ╎ ash Save Mode Filter Collapse Del -|4: ls ╎ ls -|5: w.txt ╎ w.txt -|6: ╎ -|7: ╎ -|8: ╎ -|9: /tmp/pardes-snap/cornerdrag/cwd Term+bash Save Mode Filte╎ -|10: Collapse Del ╎ -|11: ls ╎ -|12: w.txt ╎ -|13: ╎ -|14: ╎ -|15: ╎ -|16: ╎ -|17: ╎ -|18: ╎ -|19: ╎ -|20: ╎ -|21: ╎ -|22: ╎ -|23: ╎ -|24: ╎ -|25: ╎ -|26: ╎ -|27: ╎ -|28: ╎ -|29: ╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ -|30: ╎ -== snap clamp-done grid=100x31 cursor=4,6 -|1: New Term Find Grep Joincol Delcol New Term Find Grep Joincol Delcol -|2: /tmp/pardes-snap/cornerdrag/cwd Term+bash Save Mode Filter /tmp/pardes-snap/cornerdrag/cwd Term+b -|3: Collapse Del ash Save Mode Filter Collapse Del -|4: ls ls -|5: w.txt w.txt -|6: -|7: -|8: -|9: -|10: -|11: -|12: -|13: -|14: -|15: -|16: -|17: -|18: -|19: -|20: -|21: -|22: -|23: -|24: -|25: -|26: -|27: /tmp/pardes-snap/cornerdrag/cwd Term+bash Save Mode Filter -|28: Collapse Del -|29: w.txt -|30: diff --git a/test/snapshots/shrinktag.golden b/test/snapshots/shrinktag.golden index d2167e86..bfca20e3 100644 --- a/test/snapshots/shrinktag.golden +++ b/test/snapshots/shrinktag.golden @@ -32,7 +32,6 @@ |19: |20: == snap move-preview grid=100x31 cursor=4,9 -|8: ls ╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌▌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ == snap restored grid=100x31 cursor=4,9 |4: ls ls |5: w.txt w.txt diff --git a/test/snapshots/windowops.golden b/test/snapshots/windowops.golden index 6d27586b..ab97a868 100644 --- a/test/snapshots/windowops.golden +++ b/test/snapshots/windowops.golden @@ -21,71 +21,9 @@ | ls | w.txt == snap hover-h grid=100x31 cursor=4,6 -== snap border-drag grid=100x31 cursor=4,6 -|1: New Term Find Grep Joincol Delcol ╎ New Term Find Grep Joincol Delcol -|2: /tmp/pardes-snap/windowops/cwd Term+b╎sh Save Mo /tmp/pardes-snap/windowops/cwd Term+bash Save Mo -|3: de Filter Collapse Del ╎ de Filter Collapse Del -|4: ls ╎ ls -|5: w.txt ╎ w.txt -|6: ╎ -|7: ╎ -|8: ╎ -|9: ╎ -|10: ╎ -|11: ╎ -|12: ╎ -|13: ╎ -|14: ╎ -|15: ╎ -|16: ╎ -|17: /tmp/pardes-snap/windowops/cwd Term+b╎sh Save Mo -|18: de Filter Collapse Del ╎ -|19: ls ╎ -|20: w.txt ╎ -|21: ╎ -|22: ╎ -|23: ╎ -|24: ╎ -|25: ╎ -|26: ╎ -|27: ╎ -|28: ╎ -|29: ╎ -|30: ╎ -== snap border-done grid=100x31 cursor=4,6 -|1: New Term Find Grep Joincol Delcol New Term Find Grep Joincol Delcol -|2: /tmp/pardes-snap/windowops/cwd Term+ba /tmp/pardes-snap/windowops/cwd Term+bash Save Mode Filter -|3: sh Save Mode Filter Collapse Del Collapse Del -|4: ls ls -|5: w.txt w.txt -|6: -|7: -|8: -|9: -|10: -|11: -|12: -|13: -|14: -|15: -|16: -|17: /tmp/pardes-snap/windowops/cwd Term+ba -|18: sh Save Mode Filter Collapse Del -|19: ls -|20: w.txt -|21: -|22: -|23: -|24: -|25: -|26: -|27: -|28: -|29: -|30: == snap hborder-done grid=100x31 cursor=4,6 -|13: /tmp/pardes-snap/windowops/cwd Term+ba -|14: sh Save Mode Filter Collapse Del +|13: /tmp/pardes-snap/windowops/cwd Term+bash Save Mo +|14: de Filter Collapse Del |15: ls |16: w.txt |17: @@ -95,63 +33,63 @@ == snap move-preview grid=100x31 cursor=4,17 == snap moved grid=100x31 cursor=4,17 == snap altn grid=100x31 cursor=4,22 -|18: /tmp/pardes-snap/windowops/cwd Term+ba -|19: sh Save Mode Filter Collapse Del +|18: /tmp/pardes-snap/windowops/cwd Term+bash Save Mo +|19: de Filter Collapse Del |20: ls |21: w.txt -== snap focus-right grid=100x31 cursor=44,6 -== snap debug-on grid=100x31 cursor=44,6 -|1: New Term Find Grep Joincol Delcol New Term Find Grep J╭────────────────────────────────────╮ -|2: /tmp/pardes-snap/windowops/cwd Term+ba /tmp/pardes-snap/win│pardes resizes=1 │ -|3: sh Save Mode Filter Collapse Del Collapse Del │theme orchard │ -|4: ls ls │font default │ -|5: w.txt w.txt │terms 4 cols 2 │ -|6: │active #2 58x27 │ +== snap focus-right grid=100x31 cursor=54,6 +== snap debug-on grid=100x31 cursor=54,6 +|1: New Term Find Grep Joincol Delcol New Term F╭────────────────────────────────────╮ +|2: /tmp/pardes-snap/windowops/cwd Term+bash Save Mo /tmp/parde│pardes resizes=1 │ +|3: de Filter Collapse Del de Filter │theme orchard │ +|4: ls ls │font default │ +|5: w.txt w.txt │terms 4 cols 2 │ +|6: │active #2 48x27 │ |7: │scroll 0/27 │ |8: │frame virtual clock │ |9: │ │ |10: │ │ |11: │ │ |12: │ │ -|13: /tmp/pardes-snap/windowops/cwd Term+ba ╰────────────────────────────────────╯ +|13: /tmp/pardes-snap/windowops/cwd Term+bash Save Mo ╰────────────────────────────────────╯ == style debug-on grid=100x31 |0: 0-1 d,#1d2824, 2-74 #b2c3b8,#1d2824, 75-79 #f5f7ee,#3c614a, 80-80 #f5f7ee,#1d2824, 81-99 #b2c3b8,#1d2824, -|1: 0-1 d,#887455, 2-39 #b2c3b8,#1d2824, 40-41 #b2c3b8,#887455, 42-61 #becfc4,#314738, 62-99 d,d, -|2: 0-1 d,#496656, 2-32 #b2c3b8,#1d2824, 33-39 #d3b0d9,#1d2824, 40-41 #d3b0d9,#add38a, 42-61 #becfc4,#314738, 62-62 d,d, 63-79 #b2c3b8,d, 80-98 #b2c3b8,#152019, 99-99 d,d, -|3: 0-1 d,#1d2824, 2-4 #d3b0d9,#1d2824, 5-39 #b2c3b8,#1d2824, 40-41 #b2c3b8,#314738, 42-61 #becfc4,#314738, 62-62 d,d, 63-76 #b2c3b8,d, 77-98 #b2c3b8,#152019, 99-99 d,d, -|4: 0-0 d,#608269, 1-1 d,#0d1410, 2-39 #e5eee5,#0d1410, 40-40 #e5eee5,#608269, 41-61 #e5eee5,#0d1410, 62-62 d,d, 63-76 #b2c3b8,d, 77-98 #b2c3b8,#152019, 99-99 d,d, -|5: 0-0 d,#608269, 1-1 d,#0d1410, 2-39 #e5eee5,#0d1410, 40-40 #e5eee5,#608269, 41-61 #e5eee5,#0d1410, 62-62 d,d, 63-77 #b2c3b8,d, 78-98 #b2c3b8,#152019, 99-99 d,d, -|6: 0-0 d,#608269, 1-39 d,#0d1410, 40-40 d,#608269, 41-61 d,#0d1410, 62-62 d,d, 63-78 #b2c3b8,d, 79-98 #b2c3b8,#152019, 99-99 d,d, -|7: 0-0 d,#608269, 1-39 d,#0d1410, 40-40 d,#608269, 41-61 d,#0d1410, 62-62 d,d, 63-73 #b2c3b8,d, 74-98 #b2c3b8,#152019, 99-99 d,d, -|8: 0-0 d,#608269, 1-39 d,#0d1410, 40-40 d,#608269, 41-61 d,#0d1410, 62-62 d,d, 63-82 #b2c3b8,d, 83-98 #b2c3b8,#152019, 99-99 d,d, -|9: 0-0 d,#608269, 1-39 d,#0d1410, 40-40 d,#608269, 41-61 d,#0d1410, 62-62 d,d, 63-98 d,#152019, 99-99 d,d, -|10: 0-0 d,#608269, 1-39 d,#0d1410, 40-40 d,#608269, 41-61 d,#0d1410, 62-62 d,d, 63-98 d,#152019, 99-99 d,d, -|11: 0-0 d,#608269, 1-39 d,#0d1410, 40-40 d,#608269, 41-61 d,#0d1410, 62-62 d,d, 63-98 d,#152019, 99-99 d,d, -|12: 0-0 d,#608269, 1-39 d,#0d1410, 40-40 d,#608269, 41-61 d,#0d1410, 62-62 d,d, 63-98 d,#152019, 99-99 d,d, -|13: 0-1 d,#496656, 2-32 #b2c3b8,#1d2824, 33-39 #d3b0d9,#1d2824, 40-40 #d3b0d9,#608269, 41-61 #d3b0d9,#0d1410, 62-99 d,d, -|14: 0-1 d,#1d2824, 2-4 #d3b0d9,#1d2824, 5-39 #b2c3b8,#1d2824, 40-40 #b2c3b8,#608269, 41-99 #b2c3b8,#0d1410, -|15: 0-0 d,#608269, 1-1 d,#0d1410, 2-39 #e5eee5,#0d1410, 40-40 #e5eee5,#608269, 41-99 #e5eee5,#0d1410, -|16: 0-0 d,#608269, 1-1 d,#0d1410, 2-39 #e5eee5,#0d1410, 40-40 #e5eee5,#608269, 41-99 #e5eee5,#0d1410, -|17: 0-0 d,#608269, 1-39 d,#0d1410, 40-40 d,#608269, 41-99 d,#0d1410, -|18: 0-1 d,#496656, 2-32 #b2c3b8,#1d2824, 33-39 #d3b0d9,#1d2824, 40-40 #d3b0d9,#608269, 41-99 #d3b0d9,#0d1410, -|19: 0-1 d,#1d2824, 2-4 #d3b0d9,#1d2824, 5-39 #b2c3b8,#1d2824, 40-40 #b2c3b8,#608269, 41-99 #b2c3b8,#0d1410, -|20: 0-0 d,#608269, 1-1 d,#0d1410, 2-39 #e5eee5,#0d1410, 40-40 #e5eee5,#608269, 41-99 #e5eee5,#0d1410, -|21: 0-0 d,#608269, 1-1 d,#0d1410, 2-39 #e5eee5,#0d1410, 40-40 #e5eee5,#608269, 41-99 #e5eee5,#0d1410, -|22: 0-0 d,#608269, 1-39 d,#0d1410, 40-40 d,#608269, 41-99 d,#0d1410, -|23: 0-0 d,#608269, 1-39 d,#0d1410, 40-40 d,#608269, 41-99 d,#0d1410, -|24: 0-0 d,#608269, 1-39 d,#0d1410, 40-40 d,#608269, 41-99 d,#0d1410, -|25: 0-0 d,#608269, 1-39 d,#0d1410, 40-40 d,#608269, 41-99 d,#0d1410, -|26: 0-0 d,#608269, 1-39 d,#0d1410, 40-40 d,#608269, 41-99 d,#0d1410, -|27: 0-0 d,#608269, 1-39 d,#0d1410, 40-40 d,#608269, 41-99 d,#0d1410, -|28: 0-0 d,#608269, 1-39 d,#0d1410, 40-40 d,#608269, 41-99 d,#0d1410, -|29: 0-0 d,#608269, 1-39 d,#0d1410, 40-40 d,#608269, 41-99 d,#0d1410, -|30: 0-0 d,#608269, 1-39 d,#0d1410, 40-40 d,#608269, 41-99 d,#0d1410, -== snap debug-off grid=100x31 cursor=44,6 -|1: New Term Find Grep Joincol Delcol New Term Find Grep Joincol Delcol -|2: /tmp/pardes-snap/windowops/cwd Term+ba /tmp/pardes-snap/windowops/cwd Term+bash Save Mode Filter -|3: sh Save Mode Filter Collapse Del Collapse Del -|4: ls ls Debug -|5: w.txt w.txt +|1: 0-1 d,#887455, 2-49 #b2c3b8,#1d2824, 50-51 #b2c3b8,#887455, 52-61 #becfc4,#314738, 62-99 d,d, +|2: 0-1 d,#496656, 2-32 #b2c3b8,#1d2824, 33-42 #d3b0d9,#1d2824, 43-49 #b2c3b8,#1d2824, 50-51 #b2c3b8,#add38a, 52-61 #becfc4,#314738, 62-62 d,d, 63-79 #b2c3b8,d, 80-98 #b2c3b8,#152019, 99-99 d,d, +|3: 0-1 d,#1d2824, 2-49 #b2c3b8,#1d2824, 50-51 #b2c3b8,#314738, 52-61 #becfc4,#314738, 62-62 d,d, 63-76 #b2c3b8,d, 77-98 #b2c3b8,#152019, 99-99 d,d, +|4: 0-0 d,#608269, 1-1 d,#0d1410, 2-49 #e5eee5,#0d1410, 50-50 #e5eee5,#608269, 51-61 #e5eee5,#0d1410, 62-62 d,d, 63-76 #b2c3b8,d, 77-98 #b2c3b8,#152019, 99-99 d,d, +|5: 0-0 d,#608269, 1-1 d,#0d1410, 2-49 #e5eee5,#0d1410, 50-50 #e5eee5,#608269, 51-61 #e5eee5,#0d1410, 62-62 d,d, 63-77 #b2c3b8,d, 78-98 #b2c3b8,#152019, 99-99 d,d, +|6: 0-0 d,#608269, 1-49 d,#0d1410, 50-50 d,#608269, 51-61 d,#0d1410, 62-62 d,d, 63-78 #b2c3b8,d, 79-98 #b2c3b8,#152019, 99-99 d,d, +|7: 0-0 d,#608269, 1-49 d,#0d1410, 50-50 d,#608269, 51-61 d,#0d1410, 62-62 d,d, 63-73 #b2c3b8,d, 74-98 #b2c3b8,#152019, 99-99 d,d, +|8: 0-0 d,#608269, 1-49 d,#0d1410, 50-50 d,#608269, 51-61 d,#0d1410, 62-62 d,d, 63-82 #b2c3b8,d, 83-98 #b2c3b8,#152019, 99-99 d,d, +|9: 0-0 d,#608269, 1-49 d,#0d1410, 50-50 d,#608269, 51-61 d,#0d1410, 62-62 d,d, 63-98 d,#152019, 99-99 d,d, +|10: 0-0 d,#608269, 1-49 d,#0d1410, 50-50 d,#608269, 51-61 d,#0d1410, 62-62 d,d, 63-98 d,#152019, 99-99 d,d, +|11: 0-0 d,#608269, 1-49 d,#0d1410, 50-50 d,#608269, 51-61 d,#0d1410, 62-62 d,d, 63-98 d,#152019, 99-99 d,d, +|12: 0-0 d,#608269, 1-49 d,#0d1410, 50-50 d,#608269, 51-61 d,#0d1410, 62-62 d,d, 63-98 d,#152019, 99-99 d,d, +|13: 0-1 d,#496656, 2-32 #b2c3b8,#1d2824, 33-42 #d3b0d9,#1d2824, 43-49 #b2c3b8,#1d2824, 50-50 #b2c3b8,#608269, 51-61 #b2c3b8,#0d1410, 62-99 d,d, +|14: 0-1 d,#1d2824, 2-49 #b2c3b8,#1d2824, 50-50 #b2c3b8,#608269, 51-99 #b2c3b8,#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,#608269, 1-1 d,#0d1410, 2-49 #e5eee5,#0d1410, 50-50 #e5eee5,#608269, 51-99 #e5eee5,#0d1410, +|17: 0-0 d,#608269, 1-49 d,#0d1410, 50-50 d,#608269, 51-99 d,#0d1410, +|18: 0-1 d,#496656, 2-32 #b2c3b8,#1d2824, 33-42 #d3b0d9,#1d2824, 43-49 #b2c3b8,#1d2824, 50-50 #b2c3b8,#608269, 51-99 #b2c3b8,#0d1410, +|19: 0-1 d,#1d2824, 2-49 #b2c3b8,#1d2824, 50-50 #b2c3b8,#608269, 51-99 #b2c3b8,#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-1 d,#0d1410, 2-49 #e5eee5,#0d1410, 50-50 #e5eee5,#608269, 51-99 #e5eee5,#0d1410, +|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, +|24: 0-0 d,#608269, 1-49 d,#0d1410, 50-50 d,#608269, 51-99 d,#0d1410, +|25: 0-0 d,#608269, 1-49 d,#0d1410, 50-50 d,#608269, 51-99 d,#0d1410, +|26: 0-0 d,#608269, 1-49 d,#0d1410, 50-50 d,#608269, 51-99 d,#0d1410, +|27: 0-0 d,#608269, 1-49 d,#0d1410, 50-50 d,#608269, 51-99 d,#0d1410, +|28: 0-0 d,#608269, 1-49 d,#0d1410, 50-50 d,#608269, 51-99 d,#0d1410, +|29: 0-0 d,#608269, 1-49 d,#0d1410, 50-50 d,#608269, 51-99 d,#0d1410, +|30: 0-0 d,#608269, 1-49 d,#0d1410, 50-50 d,#608269, 51-99 d,#0d1410, +== snap debug-off grid=100x31 cursor=54,6 +|1: New Term Find Grep Joincol Delcol New Term Find Grep Joincol Delcol +|2: /tmp/pardes-snap/windowops/cwd Term+bash Save Mo /tmp/pardes-snap/windowops/cwd Term+bash Save Mo +|3: de Filter Collapse Del de Filter Collapse Del +|4: ls ls Debug +|5: w.txt w.txt |6: |7: |8: @@ -159,4 +97,4 @@ |10: |11: |12: -|13: /tmp/pardes-snap/windowops/cwd Term+ba +|13: /tmp/pardes-snap/windowops/cwd Term+bash Save Mo -- cgit v1.3 From fa504c392b5f3c04a7cfce74566e23cb94ddd6cf Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Mon, 16 Nov 2026 23:58:16 -0300 Subject: test: a +Diff pinned before it moves: process-test's `diffstack` pages a patch into `pardes -` and snaps the +Diff it is restacked into (its hunk found two lines down where the file moved it, under the declaration it stands in, `a.zig:3` and `const S = struct {`, its label one level deep, `a.zig:5 *`; the changed word on a stronger ground in both lines, a line added whole on a faint one, the markers in their tints' hue), as text and as styles; replicas opens with a .patch looked at by the authority and as the replica's own input, the first stopped at its first read and confirmed with no rollback, the replica's digest and +Diff the authority's either way; the soak's fixture is a repository whose last commit changes code.zig, and `gitshow` pages `git show HEAD` into `pardes -` from a shell Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- test/process/tty_editing.zig | 24 +++++++++++++ test/replicas.zig | 76 ++++++++++++++++++++++++++++++++++++++++- test/snapshots/diffstack.golden | 61 +++++++++++++++++++++++++++++++++ test/soak.py | 21 +++++++++++- 4 files changed, 180 insertions(+), 2 deletions(-) create mode 100644 test/snapshots/diffstack.golden diff --git a/test/process/tty_editing.zig b/test/process/tty_editing.zig index 72cbb573..b5f0495c 100644 --- a/test/process/tty_editing.zig +++ b/test/process/tty_editing.zig @@ -35,6 +35,7 @@ pub const cases = .{ .{ "tty editing: lsp-rename-files", lsp_rename_files }, .{ "tty editing: callstack", callstack }, .{ "tty editing: diffview", diffview }, + .{ "tty editing: diffstack", diffstack }, .{ "tty editing: dirpane", dirpane }, .{ "tty editing: scrolloff", scrolloff }, .{ "tty editing: wrap", wrap }, @@ -2018,6 +2019,29 @@ fn diffview(gpa: std.mem.Allocator, exe: [:0]const u8) !void { try t.done(); } +// A diff paged (`pardes -`) is stacked in a +Diff: its hunk found where the +// file has moved it since (two lines further down), under the declaration it +// stands in (`a.zig:3`, `const S = struct {`) and its label one level deep +// (`a.zig:5 *`); a changed line's changed word on a stronger ground in both +// lines (`c` and `a`), and a line added whole (`log();`) on a faint one, each +// marker in its tint's hue. +fn diffstack(gpa: std.mem.Allocator, exe: [:0]const u8) !void { + var t = try Tty.init(gpa, exe, "diffstack"); + defer t.deinit(); + try t.file("a.zig", "// one\n// two\nconst S = struct {\n fn f() void {\n a();\n b();\n log();\n }\n};\n"); + try t.file("change.patch", "--- a.zig\n+++ a.zig\n@@ -3,4 +3,5 @@ git's guess\n fn f() void {\n- c();\n+ a();\n b();\n+ log();\n }\n"); + try t.start(31, 100, &.{}); + try t.wait(8000, "$"); + try t.stable(700, 20000); + try t.send("cat change.patch | $(readlink /proc/$PPID/exe) -"); + try t.key("enter"); + try t.wait(20000, "a.zig:5 *"); + try t.stable(700, 20000); + try t.snap("diff-stack"); + try t.style("diff-stack-colours"); + try t.done(); +} + // 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 diff --git a/test/replicas.zig b/test/replicas.zig index f50fb04f..038d747a 100644 --- a/test/replicas.zig +++ b/test/replicas.zig @@ -213,6 +213,13 @@ fn writeFile(path: [:0]const u8, lines: usize) !void { } } +fn writeText(path: [:0]const u8, text: []const u8) !void { + const fd = libc.open(path, .{ .ACCMODE = .WRONLY, .CREAT = true, .TRUNC = true }, @as(libc.mode_t, 0o644)); + if (fd < 0) return error.OpenFailed; + defer _ = libc.close(fd); + if (libc.write(fd, text.ptr, text.len) != @as(isize, @intCast(text.len))) return error.WriteFailed; +} + const Run = struct { seed: u64, rtt_ms: u64, steps: usize, clients: u16, shared: bool, flood_mb: u64 }; /// The terminal pane's screen as a hash of screen_state's dump of it. @@ -470,6 +477,73 @@ fn run(r: Run, dir: []const u8, totals: *Totals) !void { } } +/// A .patch looked at opens a +Diff, whose rows are made from files read +/// in the step (hunks.zig: the patch, the file each section names, its +/// declarations). Looked at by the authority, a replica replays the reads +/// the unit carries and makes the same +Diff; looked at as the replica's own +/// input, the first read poisons the speculation, which shows nothing and +/// waits for the authority's unit (no rollback of what it showed). Either +/// way the replica's digest and the +Diff's text are the authority's. +fn diffCase(dir: []const u8) !bool { + var host: Host = .{}; + defer { + for (host.echo.items) |e| gpa.free(e.bytes); + host.echo.deinit(gpa); + } + var buf: [256]u8 = undefined; + const source = try std.fmt.bufPrintSentinel(&buf, "{s}/a.zig", .{dir}, 0); + try writeText(source, "// one\n// two\nconst S = struct {\n fn f() void {\n a();\n b();\n log();\n }\n};\n"); + var pbuf: [256]u8 = undefined; + const patch = try std.fmt.bufPrintSentinel(&pbuf, "{s}/change.patch", .{dir}, 0); + try writeText(patch, "--- a.zig\n+++ a.zig\n@@ -3,4 +3,5 @@\n fn f() void {\n- c();\n+ a();\n b();\n+ log();\n }\n"); + var lbuf: [300]u8 = undefined; + const look = try std.fmt.bufPrint(&lbuf, "Look {s}", .{patch}); + var ok = true; + for ([_]bool{ false, true }) |own| { + const a = try replica.Authority.init(gpa, .{ .cols = 100, .rows = 30, .boot = .tty }, host.host(), true); + defer a.deinit(); + const first = try gpa.dupe(u8, try a.unit(0, 0)); + defer gpa.free(first); + const rp = try replica.Replica.init(gpa, 1, first, true); + defer rp.deinit(); + if (own) { + const msg = try gpa.dupe(u8, try rp.input(.{ .command = look })); + defer gpa.free(msg); + if (rp.stats.stopped != 1) { + std.debug.print("diff: the replica's own look at a .patch was not stopped at its first read ({d} stopped, {d} applied)\n", .{ rp.stats.stopped, rp.stats.speculated }); + ok = false; + } + if (try a.pending()) |batch| rp.confirm(batch); + rp.confirm(try a.take(msg)); + } else rp.confirm(try a.local(.{ .command = look })); + rp.settle(); + const named = for (a.core.panes, 0..) |slot, pid| { + const f = (slot orelse continue).file orelse continue; + if (std.mem.endsWith(u8, f.path, "/+Diff")) break pid; + } else null; + const mine = if (named) |pid| if (rp.core().panes[pid]) |pane| pane.file else null else null; + if (named == null or mine == null or !std.mem.eql(u8, a.core.panes[named.?].?.file.?.content, mine.?.content) or + std.mem.indexOf(u8, mine.?.content, "a.zig:5 *") == null) + { + std.debug.print("diff: {s}: the replica holds no +Diff of the authority's\n", .{if (own) "its own look" else "the authority's look"}); + ok = false; + } + if (rp.diverged) |why| { + std.debug.print("diff: {s}: the replica diverged: {s}\n", .{ if (own) "its own look" else "the authority's look", why }); + ok = false; + } else if (!rp.quiet() or rp.digest() != replica.digestOf(a)) { + std.debug.print("diff: {s}: the replica's digest is not the authority's\n", .{if (own) "its own look" else "the authority's look"}); + ok = false; + } + if (rp.stats.mispredicted + rp.stats.foreign != 0) { + std.debug.print("diff: {s}: {d} rollbacks\n", .{ if (own) "its own look" else "the authority's look", rp.stats.mispredicted + rp.stats.foreign }); + ok = false; + } + } + std.debug.print("diff: a .patch looked at by the authority and as a replica's own input: {s}\n", .{if (ok) "the same +Diff" else "FAILED"}); + return ok; +} + fn push(q: *std.PriorityQueue(Msg, void, Msg.order), nn: *u64, m: Msg) !void { var mm = m; mm.n = nn.*; @@ -1437,7 +1511,7 @@ pub fn main(init: std.process.Init) !void { if (!try echoMain(seeds, first, rtts)) std.process.exit(1); return; } - var failed = false; + var failed = !try diffCase(dir); std.debug.print("{d} seeds x {d} inputs from each of {d} clients, {s}, a TUI then {d} MB of yes in the shell; costs in us (frame {d})\n", .{ seeds, steps, clients, if (shared) "sharing one view" else "a view each", flood_mb, frame_us }); std.debug.print(" rtt inputs at-once stopped view units fast rollback(mis+foreign) rate rebase spec p50/p99 copy p50/p99 (KB) rollback p50/p99 diverged unequal\n", .{}); var term_lines: std.ArrayList(u8) = .empty; diff --git a/test/snapshots/diffstack.golden b/test/snapshots/diffstack.golden new file mode 100644 index 00000000..51251c4c --- /dev/null +++ b/test/snapshots/diffstack.golden @@ -0,0 +1,61 @@ +== snap diff-stack grid=100x31 cursor=4,4 +| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config History Debug Exit +| New Term Find Grep Joincol Delcol +|$ /tmp/pardes-snap/diffstack/cwd Term+bash Save Mode Filter Collapse Del +| $ cat change.patch | $(readlink /proc/$PPID/exe) - +| $ +| /tmp/pardes-snap/diffstack/cwd/+Diff Save Term Diff Collapse LocationsConfig Del +| a.zig:3 +| const S = struct { +| a.zig:5 * +| fn f() void { +| - c(); +| + a(); +| b(); +| + log(); +| } +| +| +| +| +| +| +| +| +| +| +| +| /tmp/pardes-snap/diffstack/cwd/+New Save Term Collapse Follow Del +| 1 +== style diff-stack-colours grid=100x31 +|0: 0-1 d,#1d2824, 2-99 #b2c3b8,#1d2824, +|1: 0-1 d,#887455, 2-99 #becfc4,#314738, +|2: 0-1 #000000,#add38a, 2-32 #becfc4,#314738, 33-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-1 d,#496656, 2-32 #b2c3b8,#1d2824, 33-38 #d3b0d9,#1d2824, 39-99 #b2c3b8,#1d2824, +|6: 0-0 d,#608269, 1-1 d,#0d1410, 2-99 #59675c,#0d1410, +|7: 0-0 d,#608269, 1-2 d,#0d1410, 3-99 #59675c,#0d1410, +|8: 0-0 d,#608269, 1-1 d,#0d1410, 2-99 #59675c,#0d1410, +|9: 0-0 d,#608269, 1-6 d,#0d1410, 7-9 #c9a7ed,#0d1410, 10-99 #e5eee5,#0d1410, +|10: 0-0 d,#608269, 1-1 d,#0d1410, 2-2 #f1a39b,#0d1410,b 3-10 #f1a39b,#0d1410, 11-11 #e5eee5,#453832, 12-99 #e5eee5,#0d1410, +|11: 0-0 d,#608269, 1-1 d,#0d1410, 2-2 #b6ce94,#0d1410,b 3-10 #b6ce94,#0d1410, 11-11 #e5eee5,#364131, 12-99 #e5eee5,#0d1410, +|12: 0-0 d,#608269, 1-10 d,#0d1410, 11-99 #e5eee5,#0d1410, +|13: 0-0 d,#608269, 1-1 d,#0d1410, 2-2 #b6ce94,#171f18,b 3-10 #b6ce94,#171f18, 11-99 #e5eee5,#171f18, +|14: 0-0 d,#608269, 1-6 d,#0d1410, 7-99 #e5eee5,#0d1410, +|15: 0-0 d,#608269, 1-99 d,#0d1410, +|16: 0-0 d,#608269, 1-99 d,#0d1410, +|17: 0-0 d,#608269, 1-99 d,#0d1410, +|18: 0-0 d,#608269, 1-99 d,#0d1410, +|19: 0-0 d,#608269, 1-99 d,#0d1410, +|20: 0-0 d,#608269, 1-99 d,#0d1410, +|21: 0-0 d,#608269, 1-99 d,#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-1 d,#496656, 2-32 #b2c3b8,#1d2824, 33-37 #d3b0d9,#1d2824, 38-99 #b2c3b8,#1d2824, +|27: 0-0 d,#608269, 1-4 d,#0d1410, 5-99 #59675c,#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, diff --git a/test/soak.py b/test/soak.py index 401cb84e..faf447ab 100644 --- a/test/soak.py +++ b/test/soak.py @@ -148,6 +148,15 @@ def fixture(at, rng): sub.mkdir(exist_ok=True) (sub / 'inner.txt').write_text(''.join(f'inner {i} {rng.choice(WORDS)}\n' for i in range(60))) (sub / 'more.md').write_text('# More\n\n' + ''.join(f'- item {i} {rng.choice(WORDS)}\n' for i in range(40))) + # A repository whose last commit changes code.zig, for act_gitshow. + if shutil.which('git'): + git = ['git', '-c', 'user.name=soak', '-c', 'user.email=soak@invalid', '-c', 'init.defaultBranch=main'] + subprocess.run(git + ['init', '-q'], cwd=at, check=True) + subprocess.run(git + ['add', 'code.zig'], cwd=at, check=True) + subprocess.run(git + ['commit', '-qm', 'code'], cwd=at, check=True) + code = (at / 'code.zig').read_text().replace('return x * 7 +', 'return x * 8 +').replace('pub fn f9(', 'pub fn nine(') + (at / 'code.zig').write_text(code) + subprocess.run(git + ['commit', '-qam', 'change'], cwd=at, check=True) # ---- terminals ---- @@ -681,6 +690,16 @@ def act_shell(c, rng, k): k(rng.choice([b'k', b'j', b''])) +def act_gitshow(c, rng, k): + # A commit paged into `pardes -` (git's pager): the +Pager restacked into + # a +Diff, whose rows come from the files the step reads (hunks.zig). + k(b' nt') + time.sleep(rng.uniform(0.8, 1.5)) + k(b'git show HEAD | "$(readlink /proc/$PPID/exe)" -\r') + time.sleep(rng.uniform(1.0, 2.0)) + k(b'\x02') + + def act_window(c, rng, k): # Enter ends window mode, as a person would: left open, it took the next # action's keys, and a `k` at a column's top went to its tag, where `SPC q` ran Exit @@ -762,7 +781,7 @@ ACTIONS = [ ('panes', 3, act_panes), ('find', 3, act_find), ('shell', 3, act_shell), ('window', 4, act_window), ('column', 1, act_column), ('del', 2, act_del), ('new', 2, act_new), ('esc', 4, act_esc), ('click', 8, act_click), ('wheel', 8, act_wheel), ('hover', 6, act_hover), ('paste', 2, act_paste), - ('settings', 1, act_settings), ('idle', 6, act_idle), + ('settings', 1, act_settings), ('gitshow', 1, act_gitshow), ('idle', 6, act_idle), ] -- cgit v1.3 From c50226bdad46ed69643079e7c6f3e8ade3a034a1 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 17 Nov 2026 00:05:09 -0300 Subject: colors: a style byte's four high bits are grounds a theme resolves, not a diff's: syntax.ground_add and ground_del (a row's hue), ground_emph (the stronger ground), ground_line (the faint one), the byte as it was; DiffTints moves from File.zig to colors.zig as Grounds (an add and a del Ground: row, emph, line, ink), the same Oklab mixes and marker contrast; the painter has one rule, a row's first byte says its ground (emph the stronger to the pane's edge, line the faint, neither none, its marker in the hue) and a later byte's emph is its cell's, so it stops asking the pane's colour algorithm (`row_tint = algo == .diff`) and works the grounds out once a frame only for a row that names a hue; highlightDiff marks an added or removed line's first byte emph, the strong row a .diff's rows always had; recolorDiffOutput reads the same Grounds; goldens unchanged (diffview, pagercolor, diffstack), render of the 50k-line file 11,723,421 user instructions a frame before and 11,724,208 after (+0.007%, perf stat over ReleaseFast pardes-perf, 210 frames less 10) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- src/File.zig | 97 +++++++++++++--------------------------------------------- src/colors.zig | 37 ++++++++++++++++++++++ src/hunks.zig | 24 +++++++-------- src/syntax.zig | 57 +++++++++++++++++++--------------- 4 files changed, 102 insertions(+), 113 deletions(-) diff --git a/src/File.zig b/src/File.zig index 5150f1cd..1988fb89 100644 --- a/src/File.zig +++ b/src/File.zig @@ -1835,59 +1835,6 @@ fn fillBody(dst: ?[]u8, pane: *Pane, f: *State, width: usize, record_wrap: bool) const SynStyle = struct { fg: [3]u8, bold: bool }; -/// How added and removed diff lines are told apart in every theme: a row -/// ground a little way from the page toward green or red (the theme's own -/// ANSI green and red where it has a palette), and the prefix column in -/// that hue, pushed toward the ink until it reads on that ground. The -/// syntax colours are drawn over the ground unchanged. -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, - - pub fn of(p: *Pardes) DiffTints { - const th = p.theme(); - const page = th.bg orelse th.tag_bg; - const ink = th.fg orelse th.tag_fg; - const green: [3]u8 = if (th.palette) |pal| pal[2] else .{ 0x2e, 0xa0, 0x43 }; - const red: [3]u8 = if (th.palette) |pal| pal[1] else .{ 0xcf, 0x22, 0x2e }; - const added_bg = Colors.mixOklab(page, green, 0.18); - const removed_bg = Colors.mixOklab(page, red, 0.18); - 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), - }; - } - - fn legible(hue: [3]u8, ink: [3]u8, ground: [3]u8) [3]u8 { - var fg = hue; - var step: usize = 0; - while (step < 4 and Colors.contrast(fg, ground) < 3) : (step += 1) fg = Colors.mixOklab(fg, ink, 0.4); - return fg; - } - - /// 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, 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; - } -}; - fn synStyle(p: *Pardes, sy: syntax.Syn) ?SynStyle { return .{ .fg = Colors.synInk(p.theme(), sy) orelse return null, .bold = false }; } @@ -1902,12 +1849,9 @@ 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(); - // 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; + // A row whose first byte names a hue (syntax.ground_add, _del): its + // grounds, the theme's, worked out once a frame and only for one. + var grounds: ?Colors.Grounds = null; var filtered_storage: terminal.FilteredColors = undefined; const filtered: ?*terminal.FilteredColors = if (pane.tty_filter and spans.len > 0) blk: { filtered_storage = .init(p, null); @@ -1945,19 +1889,20 @@ pub fn recolorSyntax(p: *Pardes, s: *Surface, pane: *Pane, f: *State, r: pardes. 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(); - // An added or removed line's row, every wrapped row of it, is tinted. - const tint = if (tints) |*t| if (base >= highlight_start and base - highlight_start < highlights.len) - t.forStyle(highlights[base - highlight_start]) - else - null else null; + // The row's first byte: its hue and its ground, on every wrapped + // row of it (syntax.ground_add). + const lead: u8 = if (base >= highlight_start and base - highlight_start < highlights.len) highlights[base - highlight_start] else 0; + const tint: ?Colors.Grounds.Ground = if (lead & (syntax.ground_add | syntax.ground_del) == 0) null else (grounds orelse ground: { + grounds = .of(p.theme()); + break :ground grounds.?; + }).forStyle(lead); 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) s.tint(tx + @as(u16, @intCast(prefix_width)), body_y + vr, tw -| @as(u16, @intCast(prefix_width)), if (row_tint) t.bg else t.line_bg, null); + const ground: ?[3]u8 = if (lead & syntax.ground_emph != 0) t.row else if (lead & syntax.ground_line != 0) t.line else null; + if (ground) |g| s.tint(tx + @as(u16, @intCast(prefix_width)), body_y + vr, tw -| @as(u16, @intCast(prefix_width)), g, null); }; - // 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. + // A +Pager's own colours (pager.zig) on every row but one in a hue: + // 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. var span_at = if (tint != null) spans.len else std.sort.partitionPoint(pardes.pager.Span, spans, base + hs, struct { fn before(at: usize, span: pardes.pager.Span) bool { return span.end <= at; @@ -1991,7 +1936,7 @@ pub fn recolorSyntax(p: *Pardes, s: *Surface, pane: *Pane, f: *State, r: pardes. const hidx = idx - highlight_start; if (hidx < highlights.len) { if (if (tint != null and hs + c == 0) - SynStyle{ .fg = tint.?.fg, .bold = true } + SynStyle{ .fg = tint.?.ink, .bold = true } else synStyle(p, @fromBackingInt(@intCast(highlights[hidx] & syntax.syn_bits)))) |ss| { @@ -2003,10 +1948,10 @@ 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) { + if (tint) |t| if (highlights[hidx] & syntax.ground_emph != 0 and hs + c > 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 }; + s.at(tx + @as(u16, @intCast(prefix_width + screen_c + fill)), body_y + vr).style.bg = .{ .rgb = t.emph }; }; } } @@ -2175,7 +2120,7 @@ pub fn recolorDiffOutput(p: *Pardes, s: *Surface, pane: *Pane, r: pardes.Rect, t } if (lo > hi) return; const styles = syntax.highlightDiffRows(arena, flat, lo, hi, true) catch return; - const tints = DiffTints.of(p); + const tints: Colors.Grounds = .of(p.theme()); const ink = p.theme().fg orelse p.theme().tag_fg; const body_y = p.bodyTop(pane, r); shown = std.mem.splitScalar(u8, body, '\n'); @@ -2184,7 +2129,7 @@ pub fn recolorDiffOutput(p: *Pardes, s: *Surface, pane: *Pane, r: pardes.Rect, t const view = maybe orelse continue; const base = @intFromPtr(rows[view.row].ptr) - flat_start - lo; const tint = if (base < styles.len) tints.forStyle(styles[base]) else null; - if (tint) |t| s.tint(tx, body_y + @as(u16, @intCast(vr)), tw, t.bg, null); + if (tint) |t| s.tint(tx, body_y + @as(u16, @intCast(vr)), tw, t.row, null); var c: usize = 0; var screen_c: usize = 0; while (c < line.len and screen_c < tw) { @@ -2196,7 +2141,7 @@ pub fn recolorDiffOutput(p: *Pardes, s: *Surface, pane: *Pane, r: pardes.Rect, t // On an added or removed line, what the program coloured red or // green is the tint's to say now: its code takes the page's ink. const paint: ?SynStyle = if (tint != null and prefix) - .{ .fg = tint.?.fg, .bold = true } + .{ .fg = tint.?.ink, .bold = true } else if (synStyle(p, @fromBackingInt(@intCast(style & syntax.syn_bits)))) |ss| ss else if (tint != null) diff --git a/src/colors.zig b/src/colors.zig index 1713ba24..e2e00ea8 100644 --- a/src/colors.zig +++ b/src/colors.zig @@ -322,6 +322,43 @@ pub fn synInk(th: *const Theme, sy: @import("syntax.zig").Syn) ?[3]u8 { }; } +/// The grounds a style byte's high bits name (syntax.ground_add and the +/// rest) in a theme: a row added or removed on a ground a little way from +/// the page toward the theme's green or red (its own ANSI ones where it has +/// a palette), a stronger one, a faint one, and the row's marker in that +/// hue, pushed toward the ink until it reads on the row's ground. Syntax +/// colours are drawn over a ground unchanged. +pub const Grounds = struct { + add: Ground, + del: Ground, + + pub const Ground = struct { row: [3]u8, emph: [3]u8, line: [3]u8, ink: [3]u8 }; + + pub fn of(th: *const Theme) Grounds { + const page = th.bg orelse th.tag_bg; + const ink = th.fg orelse th.tag_fg; + const green: [3]u8 = if (th.palette) |pal| pal[2] else .{ 0x2e, 0xa0, 0x43 }; + const red: [3]u8 = if (th.palette) |pal| pal[1] else .{ 0xcf, 0x22, 0x2e }; + return .{ .add = ground(page, ink, green), .del = ground(page, ink, red) }; + } + + fn ground(page: [3]u8, ink: [3]u8, hue: [3]u8) Ground { + const row = mixOklab(page, hue, 0.18); + var marker = hue; + var step: usize = 0; + while (step < 4 and contrast(marker, row) < 3) : (step += 1) marker = mixOklab(marker, ink, 0.4); + return .{ .row = row, .emph = mixOklab(page, hue, 0.28), .line = mixOklab(page, hue, 0.07), .ink = marker }; + } + + /// The ground of a byte's hue, if it has one. + pub fn forStyle(g: *const Grounds, style: u8) ?Ground { + const syntax = @import("syntax.zig"); + if (style & syntax.ground_add != 0) return g.add; + if (style & syntax.ground_del != 0) return g.del; + return null; + } +}; + /// One family, its twelve backgrounds a theme each (`curated`). const seoul256 = @import("themes/seoul256.zig"); diff --git a/src/hunks.zig b/src/hunks.zig index 8f4b4233..19246392 100644 --- a/src/hunks.zig +++ b/src/hunks.zig @@ -331,10 +331,10 @@ fn flush(out: *Out, hunk: *Hunk, memo: *SourceMemo, dir: []const u8) !void { // 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, + .added => syntax.ground_add, + .removed => syntax.ground_del, else => 0, - } | @as(u8, if (line.kind != .context and !line.paired) syntax.diff_whole else 0); + } | @as(u8, if (line.kind != .context and !line.paired) syntax.ground_line else 0); const text = try std.fmt.allocPrint(arena, "{c}{s}", .{ @as(u8, switch (line.kind) { .added => '+', .removed => '-', @@ -389,10 +389,10 @@ fn inferEdits(arena: std.mem.Allocator, minus: []HunkLine, plus: []HunkLine) !vo const marks = annotate(pair, &alignment, m.code, plus[j].code) catch continue; if (marks.distance > max_line_distance) continue; for (marks.minus) |r| for (m.styles[r[0]..r[1]]) |*b| { - b.* |= syntax.diff_emph; + b.* |= syntax.ground_emph; }; for (marks.plus) |r| for (plus[j].styles[r[0]..r[1]]) |*b| { - b.* |= syntax.diff_emph; + b.* |= syntax.ground_emph; }; m.paired = true; plus[j].paired = true; @@ -583,7 +583,7 @@ 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 '.'); + for (line.code, line.styles) |c, s| try out.append(testing.allocator, if (s & syntax.ground_emph != 0) c else '.'); return out.toOwnedSlice(testing.allocator); } @@ -653,13 +653,13 @@ test "a diff stacks to a label a hunk and its lines, markers gone, tinted and st 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); + try testing.expect(removed.colors[0] & syntax.ground_del != 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); + try testing.expect(removed.colors[0] & syntax.ground_line == 0); + try testing.expect(removed.colors[1] & syntax.ground_emph != 0); + try testing.expect(removed.colors[5] & syntax.ground_emph == 0); + try testing.expect(result.rows[4].colors[0] & syntax.ground_add != 0); + try testing.expect(result.rows[2].colors[0] & (syntax.ground_add | syntax.ground_del) == 0); } test "a hunk the file has moved since is found where it went, inside its declaration" { diff --git a/src/syntax.zig b/src/syntax.zig index 8533aaa9..70399bf7 100644 --- a/src/syntax.zig +++ b/src/syntax.zig @@ -933,16 +933,17 @@ fn childOfKind(node: ts.Node, kind: []const u8) ?ts.Node { return null; } -/// 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; 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 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; +/// A style byte: a Syn in its low bits (syn_bits), and over them the +/// grounds a theme resolves (colors.Grounds): `ground_add` or `ground_del`, +/// a row added or removed (its hue); `ground_emph`, the stronger ground; +/// `ground_line`, the faint one. A row's first byte says its row's ground: +/// emph the stronger to the pane's edge, line the faint one, neither none +/// (only its marker in the hue). Any later byte's emph is its own cell's +/// ground: the words a changed line changed (hunks.zig). +pub const ground_add: u8 = 0x80; +pub const ground_del: u8 = 0x40; +pub const ground_emph: u8 = 0x20; +pub const ground_line: u8 = 0x10; pub const syn_bits: u8 = 0x0f; /// A file section's hunks are parsed together, each side as one text, in @@ -967,7 +968,8 @@ var diff_clock: u64 = 0; /// the file its section names. A hunk's old side (context and removed /// lines) and new side (context and added lines) are each parsed whole, so /// a string or comment that spans lines colours as it does in the file. -/// Added and removed lines carry `diff_added`/`diff_removed`. A file in no +/// Added and removed lines carry `ground_add`/`ground_del`, the first byte +/// the strong row ground too (`ground_emph`). A file in no /// language pardes knows keeps the plain colours: added lines as strings, /// removed ones as numbers. pub fn highlightDiff(gpa: std.mem.Allocator, content: []const u8, start_raw: usize, end_raw: usize) ![]u8 { @@ -1082,13 +1084,14 @@ fn paintDiffPiece(gpa: std.mem.Allocator, window: DiffWindow, bytes: []const u8, for (kinds) |kind| { const line = lines.next() orelse break; const style: u8 = switch (kind) { - .added => @backingInt(Syn.string) | diff_added, - .removed => @backingInt(Syn.number) | diff_removed, + .added => @backingInt(Syn.string) | ground_add, + .removed => @backingInt(Syn.number) | ground_del, .no_newline => @backingInt(Syn.comment), .hunk => @backingInt(Syn.keyword), else => 0, }; if (style != 0) window.fill(at + offset, line.len, style); + if (style & (ground_add | ground_del) != 0 and line.len > 0) window.fill(at + offset, 1, style | ground_emph); offset += line.len + 1; } } @@ -1170,13 +1173,14 @@ fn paintHunk(gpa: std.mem.Allocator, out: []u8, bytes: []const u8, kinds: []cons if (kind == .context or kind == .removed) old_at += code_len + 1; if (kind == .context or kind == .added) new_at += code_len + 1; const flag: u8 = switch (kind) { - .added => diff_added, - .removed => diff_removed, + .added => ground_add, + .removed => ground_del, else => 0, }; if (flag != 0) for (out[offset..][0..line.len]) |*b| { b.* |= flag; }; + if (flag != 0 and line.len > 0) out[offset] |= ground_emph; } } @@ -1577,9 +1581,12 @@ test "syntax highlightDiff colors unified diff lines by prefix" { // A file in no known language: each line in one colour, and tinted. try std.testing.expectEqual(Syn.number, diffSynAt(styles, diff_text, "-old line", 0)); try std.testing.expectEqual(Syn.string, diffSynAt(styles, diff_text, "+new line", 0)); - try std.testing.expect(styles[std.mem.indexOf(u8, diff_text, "-old line").?] & diff_removed != 0); - try std.testing.expect(styles[std.mem.indexOf(u8, diff_text, "+new line").? + 4] & diff_added != 0); - try std.testing.expect(styles[std.mem.indexOf(u8, diff_text, " context").?] & (diff_added | diff_removed) == 0); + try std.testing.expect(styles[std.mem.indexOf(u8, diff_text, "-old line").?] & ground_del != 0); + try std.testing.expect(styles[std.mem.indexOf(u8, diff_text, "+new line").? + 4] & ground_add != 0); + try std.testing.expect(styles[std.mem.indexOf(u8, diff_text, " context").?] & (ground_add | ground_del) == 0); + // The row's ground on its first byte: the strong one, its other bytes none. + try std.testing.expect(styles[std.mem.indexOf(u8, diff_text, "-old line").?] & ground_emph != 0); + try std.testing.expect(styles[std.mem.indexOf(u8, diff_text, "+new line").? + 4] & (ground_emph | ground_line) == 0); } test "syntax a Zig hunk is coloured as Zig, each side parsed whole" { @@ -1611,9 +1618,9 @@ test "syntax a Zig hunk is coloured as Zig, each side parsed whole" { try std.testing.expectEqual(Syn.string, diffSynAt(styles, diff_text, "new words defer", 10)); // The prefix is no code: it carries the tint alone. const added = std.mem.indexOf(u8, diff_text, "+ side").?; - try std.testing.expectEqual(diff_added, styles[added]); - try std.testing.expect(styles[std.mem.indexOf(u8, diff_text, "42").?] & diff_added != 0); - try std.testing.expect(styles[std.mem.indexOf(u8, diff_text, "7,").?] & diff_removed != 0); + try std.testing.expectEqual(ground_add | ground_emph, styles[added]); + try std.testing.expect(styles[std.mem.indexOf(u8, diff_text, "42").?] & ground_add != 0); + try std.testing.expect(styles[std.mem.indexOf(u8, diff_text, "7,").?] & ground_del != 0); try std.testing.expectEqual(Syn.comment, diffSynAt(styles, diff_text, "index 111", 0)); // A window in the middle is coloured as the whole is. @@ -1660,7 +1667,7 @@ test "syntax a deleted file's lines are coloured in its language" { defer std.testing.allocator.free(styles); try std.testing.expectEqual(Syn.keyword, diffSynAt(styles, diff_text, "enum", 0)); try std.testing.expectEqual(Syn.comment, diffSynAt(styles, diff_text, "// the end", 3)); - try std.testing.expect(styles[std.mem.indexOf(u8, diff_text, "enum").?] & diff_removed != 0); + try std.testing.expect(styles[std.mem.indexOf(u8, diff_text, "enum").?] & ground_del != 0); try std.testing.expectEqual(Syn.comment, diffSynAt(styles, diff_text, "deleted file", 0)); } @@ -1709,9 +1716,9 @@ test "syntax git diff output in a command pane is told and coloured by its rows" try std.testing.expectEqual(Syn.keyword, diffSynAt(styles, text, "fn main", 0)); try std.testing.expectEqual(Syn.number, diffSynAt(styles, text, "42", 0)); // The wrapped row stays an added line, and inside the comment. - try std.testing.expect(styles[std.mem.indexOf(u8, text, "wrapped rest").?] & diff_added != 0); + try std.testing.expect(styles[std.mem.indexOf(u8, text, "wrapped rest").?] & ground_add != 0); try std.testing.expectEqual(Syn.comment, diffSynAt(styles, text, "wrapped rest", 0)); - try std.testing.expect(styles[std.mem.indexOf(u8, text, "return").?] & diff_removed != 0); + try std.testing.expect(styles[std.mem.indexOf(u8, text, "return").?] & ground_del != 0); } test "syntax a section's small hunks share one parse" { @@ -1733,7 +1740,7 @@ test "syntax a section's small hunks share one parse" { try std.testing.expectEqual(@as(usize, 2), cached); // x.zig's three hunks, and y.zig's try std.testing.expectEqual(Syn.keyword, diffSynAt(styles, diff_text, "@@ -10", 0)); try std.testing.expectEqual(Syn.number, diffSynAt(styles, diff_text, "2;\n@@ -20", 0)); - try std.testing.expect(styles[std.mem.indexOf(u8, diff_text, "@@ -10").?] & (diff_added | diff_removed) == 0); + try std.testing.expect(styles[std.mem.indexOf(u8, diff_text, "@@ -10").?] & (ground_add | ground_del) == 0); } test "syntax a hunk painted once is kept, and a long one is parsed in pieces" { -- cgit v1.3 From 5caef6d571f51e98eab3a48c063678ad35e09cce Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 17 Nov 2026 00:25:19 -0300 Subject: hunks: format stacks for a narrow Ctx, not a *Pardes: its two allocators, `source(dir, path)` (a file as a look from dir finds it), `declarations(path, bytes)` and the one setting, tslocations; Output.openDiff gives the editor's, its reads the same taped sites as before (locations.sourceText: an open pane's text, else fs.read) and its declarations the locations cache's, so a replica still replays the authority's bytes; displayWidth from File.zig itself; the four format tests read the disk through a Ctx of their own and stop booting a whole Pardes (the look and refill tests still drive the editor); goldens unchanged Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- src/Output.zig | 29 ++++++++++- src/hunks.zig | 151 ++++++++++++++++++++++++++++++++++++++------------------- 2 files changed, 128 insertions(+), 52 deletions(-) diff --git a/src/Output.zig b/src/Output.zig index 0c6fdfc2..d4be640c 100644 --- a/src/Output.zig +++ b/src/Output.zig @@ -490,8 +490,33 @@ pub fn fillRows(p: *Pardes, id: usize, dir: []const u8, from: Origin, arg: []con /// NoHunks when there is none in it. pub fn openDiff(p: *Pardes, id: usize, path: []const u8, content: []const u8) !usize { const dir = std.Io.Dir.path.dirname(path) orelse p.sessionDir(); - const root = hunks.sourceRoot(p, dir, content); - const result = try hunks.format(p, root, content); + // Each file read is a site of the step's tape (fs.zig): a replica + // replays the authority's bytes and reads no disk of its own. + const Read = struct { + fn source(ctx: *const hunks.Ctx, from: []const u8, name: []const u8) ?hunks.Source { + const pp: *Pardes = @ptrCast(@alignCast(ctx.host)); + const text = locations.sourceText(pp, ctx.arena, from, name) orelse return null; + return .{ .path = text.path, .bytes = text.bytes }; + } + fn declarations(ctx: *const hunks.Ctx, name: []const u8, bytes: []const u8) error{OutOfMemory}![]const @import("syntax.zig").ContextDeclaration { + const pp: *Pardes = @ptrCast(@alignCast(ctx.host)); + var hit = pp.locations_cache.get(pp.tree_sitter_gpa, name, bytes, true, false) catch + locations.Cache.Hit{ .analysis = @import("syntax.zig").analyzeSource(ctx.arena, name, bytes, true, false) catch .{} }; + defer hit.deinit(pp.tree_sitter_gpa); + // The cache's may go at its next use: kept for the call. + return ctx.arena.dupe(@import("syntax.zig").ContextDeclaration, hit.analysis.declarations); + } + }; + const ctx: hunks.Ctx = .{ + .gpa = p.gpa, + .arena = p.scratch.allocator(), + .source = Read.source, + .declarations = Read.declarations, + .host = p, + .tslocations = p.locations_config.tslocations, + }; + const root = hunks.sourceRoot(&ctx, dir, content); + const result = try hunks.format(&ctx, root, content); errdefer { p.gpa.free(result.content); locations.freeRows(p.gpa, result.rows); diff --git a/src/hunks.zig b/src/hunks.zig index 19246392..28fffa38 100644 --- a/src/hunks.zig +++ b/src/hunks.zig @@ -6,21 +6,43 @@ //! 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; +/// What `format` takes of the editor it stacks for: its allocators, the +/// files a diff names read as the editor reads them (in pardes an open +/// pane's text, else the disk's, each read a site of the step's tape: +/// Output.openDiff), their declarations, and one setting. +pub const Ctx = struct { + /// The text and rows made, the caller's. + gpa: std.mem.Allocator, + /// All else, the call's. + arena: std.mem.Allocator, + /// `path` as a look from `dir` finds it, its text the arena's (or the + /// editor's, good for the call); null when it is not there. + source: *const fn (ctx: *const Ctx, dir: []const u8, path: []const u8) ?Source, + /// The declarations of `bytes`, the file at `path`, outermost first + /// (syntax.analyzeSource's), the arena's. + declarations: *const fn (ctx: *const Ctx, path: []const u8, bytes: []const u8) error{OutOfMemory}![]const syntax.ContextDeclaration, + /// The two above's own. + host: *anyopaque, + /// A declaration above a hunk gets its `path:line` row too + /// (LocationsConfig's tslocations). + tslocations: bool, +}; + +/// A file's text, and its path as `dir` and the path named resolve. +pub const Source = struct { path: []const u8, bytes: []const u8 }; + /// 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(); +/// row's metadata (Output.fillRows). Text and rows are `ctx.gpa`'s. +pub fn format(ctx: *const Ctx, dir: []const u8, content: []const u8) !locations.Result { + const arena = ctx.arena; const styles = try syntax.highlightDiff(arena, content, 0, content.len); - var out: Out = .{ .p = p, .text = .init(p.gpa) }; + var out: Out = .{ .gpa = ctx.gpa, .text = .init(ctx.gpa) }; errdefer out.deinit(); var walk: diff.Walk = .{}; var hunk: Hunk = .{}; @@ -46,7 +68,7 @@ pub fn format(p: *Pardes, dir: []const u8, content: []const u8) !locations.Resul // A `\ No newline` belongs to the line above, as delta shows it. .no_newline => {}, else => { - try flush(&out, &hunk, &source, dir); + try flush(ctx, &out, &hunk, &source, dir); switch (got.kind) { .hunk => hunk = .{ .path = walk.path(), @@ -69,9 +91,9 @@ pub fn format(p: *Pardes, dir: []const u8, content: []const u8) !locations.Resul } at = nl + 1; } - try flush(&out, &hunk, &source, dir); - const rows = try out.rows.toOwnedSlice(p.gpa); - errdefer locations.freeRows(p.gpa, rows); + try flush(ctx, &out, &hunk, &source, dir); + const rows = try out.rows.toOwnedSlice(ctx.gpa); + errdefer locations.freeRows(ctx.gpa, rows); return .{ .content = try out.text.toOwnedSlice(), .rows = rows, .anchor = null }; } @@ -105,13 +127,13 @@ fn gitContext(line: []const u8) []const u8 { } const Out = struct { - p: *Pardes, + gpa: std.mem.Allocator, text: std.Io.Writer.Allocating, rows: std.ArrayList(Row) = .empty, fn deinit(out: *Out) void { out.text.deinit(); - locations.freeRowList(out.p.gpa, &out.rows); + locations.freeRowList(out.gpa, &out.rows); } const Meta = struct { @@ -127,7 +149,7 @@ const Out = struct { fn row(out: *Out, text: []const u8, path: []const u8, meta: Meta) !void { try out.text.writer.writeAll(text); try out.text.writer.writeByte('\n'); - try locations.appendRow(out.p.gpa, &out.rows, .{ + try locations.appendRow(out.gpa, &out.rows, .{ .kind = meta.kind, .declaration = meta.declaration, .path = @constCast(path), @@ -153,7 +175,7 @@ const SourceMemo = struct { /// 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 { +pub fn sourceRoot(ctx: *const Ctx, 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| { @@ -161,31 +183,27 @@ pub fn sourceRoot(p: *Pardes, dir: []const u8, content: []const u8) []const u8 { } else return dir; var base: []const u8 = dir; for (0..8) |_| { - if (locations.sourceText(p, p.scratch.allocator(), base, path) != null) return base; + if (ctx.source(ctx, base, path) != null) return base; base = std.Io.Dir.path.dirname(base) orelse return dir; } return dir; } -fn findSource(p: *Pardes, memo: *SourceMemo, dir: []const u8, path: []const u8) !void { +fn findSource(ctx: *const Ctx, memo: *SourceMemo, dir: []const u8, path: []const u8) !void { if (std.mem.eql(u8, memo.path, path)) return; - const arena = p.scratch.allocator(); + const arena = ctx.arena; 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| { + if (ctx.source(ctx, base, path)) |text| { memo.shown = if (base.ptr == dir.ptr) path else try std.Io.Dir.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); + memo.declarations = try ctx.declarations(ctx, text.path, text.bytes); return; } base = std.Io.Dir.path.dirname(base) orelse return; @@ -251,12 +269,11 @@ fn heldAt(memo: *const SourceMemo, hunk: *const Hunk, comptime side: Side, start return .{ .held = held, .of = @max(of, 1) }; } -fn flush(out: *Out, hunk: *Hunk, memo: *SourceMemo, dir: []const u8) !void { +fn flush(ctx: *const Ctx, 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 arena = ctx.arena; + try findSource(ctx, 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. @@ -287,7 +304,7 @@ fn flush(out: *Out, hunk: *Hunk, memo: *SourceMemo, dir: []const u8) !void { 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) { + if (row == declaration.start_line and ctx.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 }); } @@ -574,13 +591,40 @@ fn annotate(arena: std.mem.Allocator, a: *const Alignment, minus_line: []const u } fn trimmedWidth(section: []const u8) usize { - return pardes.panes.File.displayWidth(std.mem.trim(u8, section, " \t")); + return @import("File.zig").displayWidth(std.mem.trim(u8, section, " \t")); } // ---- tests ---- const testing = std.testing; +/// A Ctx over the disk, as the editor's is without panes or a cache. +const TestCtx = struct { + arena_state: std.heap.ArenaAllocator, + ctx: Ctx, + + fn init(t: *TestCtx) void { + t.arena_state = .init(testing.allocator); + t.ctx = .{ .gpa = testing.allocator, .arena = t.arena_state.allocator(), .source = source, .declarations = declarations, .host = t, .tslocations = true }; + syntax.start(testing.allocator); + } + + fn deinit(t: *TestCtx) void { + syntax.stop(); + t.arena_state.deinit(); + } + + fn source(ctx: *const Ctx, dir: []const u8, path: []const u8) ?Source { + const full = std.Io.Dir.path.resolvePosix(ctx.arena, &.{ dir, path }) catch return null; + const bytes = std.Io.Dir.cwd().readFileAlloc(testing.io, full, ctx.arena, .limited(1 << 20)) catch return null; + return .{ .path = full, .bytes = bytes }; + } + + fn declarations(ctx: *const Ctx, path: []const u8, bytes: []const u8) error{OutOfMemory}![]const syntax.ContextDeclaration { + return (syntax.analyzeSource(ctx.arena, path, bytes, true, false) catch return &.{}).declarations; + } +}; + 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.ground_emph != 0) c else '.'); @@ -631,8 +675,9 @@ test "delta's alignment: kitten to sitting, as align.rs has it" { } 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(); + var t: TestCtx = undefined; + t.init(); + defer t.deinit(); const patch = \\diff --git a/nowhere/x.txt b/nowhere/x.txt \\--- a/nowhere/x.txt @@ -644,9 +689,9 @@ test "a diff stacks to a label a hunk and its lines, markers gone, tinted and st \\ tail \\ ; - const result = try format(p, "/pardes-surely-missing-dir", patch); - defer p.gpa.free(result.content); - defer locations.freeRows(p.gpa, result.rows); + const result = try format(&t.ctx, "/pardes-surely-missing-dir", patch); + defer testing.allocator.free(result.content); + defer locations.freeRows(testing.allocator, 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); @@ -664,8 +709,9 @@ test "a diff stacks to a label a hunk and its lines, markers gone, tinted and st 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 t: TestCtx = undefined; + t.init(); + defer t.deinit(); var tmp = testing.tmpDir(.{}); defer tmp.cleanup(); // Two lines more above it than the patch knows of. @@ -682,16 +728,17 @@ test "a hunk the file has moved since is found where it went, inside its declara \\ b(); \\ ; - const result = try format(p, dir, patch); - defer p.gpa.free(result.content); - defer locations.freeRows(p.gpa, result.rows); + const result = try format(&t.ctx, dir, patch); + defer testing.allocator.free(result.content); + defer locations.freeRows(testing.allocator, 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(); + var t: TestCtx = undefined; + t.init(); + defer t.deinit(); const patch = \\From 0123 Mon Sep 17 00:00:00 2001 \\Subject: [PATCH] change x @@ -709,12 +756,15 @@ test "a mailed patch keeps its headers, message and diffstat above its hunks" { \\+b \\ ; - const result = try format(p, "/pardes-surely-missing-dir", patch); - defer p.gpa.free(result.content); - defer locations.freeRows(p.gpa, result.rows); + const result = try format(&t.ctx, "/pardes-surely-missing-dir", patch); + defer testing.allocator.free(result.content); + defer locations.freeRows(testing.allocator, 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); } +const pardes = @import("pardes.zig"); +const Pardes = pardes.Pardes; + test "a .patch looked at opens its +Diff, and Diff goes to the text and back" { const p = try Pardes.init(testing.allocator, .{ .tty_only = true }); defer p.deinit(); @@ -755,8 +805,9 @@ test "a .patch looked at opens its +Diff, and Diff goes to the text and back" { 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 t: TestCtx = undefined; + t.init(); + defer t.deinit(); var tmp = testing.tmpDir(.{}); defer tmp.cleanup(); // Three functions ending in one signature's tail; the patch is for the @@ -799,9 +850,9 @@ test "a hunk edited since, beside siblings with its signature's tail, is found i \\ c \\ ; - const result = try format(p, dir, patch); - defer p.gpa.free(result.content); - defer locations.freeRows(p.gpa, result.rows); + const result = try format(&t.ctx, dir, patch); + defer testing.allocator.free(result.content); + defer locations.freeRows(testing.allocator, result.rows); try testing.expect(std.mem.indexOf(u8, result.content, "a.rs:12\n fn three(\na.rs:15 *\n") != null); } -- cgit v1.3 From 383b60b79146937e12c82abaaca2ce213d210b7f Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Mon, 16 Nov 2026 22:43:18 -0300 Subject: syntax: the highlight queries are filtered by the build, not in every compile: colorQuery kept each grammar's patterns whose captures pardes colours by scanning the 29 highlights.scm byte by byte at comptime, a quarter of a full recompile of the core (and again in each of the ~15 artifacts that import it); build.zig's treeSitter now runs the same filter once over the query it reads (grammar_manifest.colorQuery, a plain function, with Syn and synFor's capture-to-class table beside it, the one copy both the build and syntax.zig read), so ts_queries' _highlights is the filtered query and Spec.query_src a field read; typst's supplement is the manifest's highlights_extra, appended before the filter as before; _highlights_unfiltered is the whole query, for the test that the filter keeps every colour; a package that depends on pardes gets the same through library's treeSitter, for its own grammar set; proven byte-identical before the comptime path went (29 grammars, 28,398 filtered bytes of 79,678); core-test's forced full recompile 12.7-12.9 s wall / 17.5 s CPU to 9.7-10.1 s / 14.6 s; syntax snapshots unchanged; the changelog says so --- build.zig | 8 +++- src/CHANGELOG.md | 6 +++ src/grammar_manifest.zig | 108 ++++++++++++++++++++++++++++++++++++++++++-- src/syntax.zig | 114 +++-------------------------------------------- 4 files changed, 122 insertions(+), 114 deletions(-) diff --git a/build.zig b/build.zig index 0e67b61e..c7604c62 100644 --- a/build.zig +++ b/build.zig @@ -2101,8 +2101,12 @@ fn treeSitter(b: *std.Build, io: std.Io, target: std.Build.ResolvedTarget, c_opt (tree_sitter_grammars == .zig and g.tier == .zig)) grammar: { const dep = b.lazyDependency(g.dep, .{}) orelse break :grammar; - const query = configureRead(b, io, dep.builder.root, g.query, 0x100000) catch @panic("read " ++ g.name ++ " highlights"); - ts_queries.addOption([]const u8, g.name ++ "_highlights", query); + const upstream = configureRead(b, io, dep.builder.root, g.query, 0x100000) catch @panic("read " ++ g.name ++ " highlights"); + // the patterns that colour, filtered here once and not in + // every compile, and the whole query, the filter's test's + const query = std.mem.concat(b.allocator, u8, &.{ upstream, g.highlights_extra }) catch @panic("OOM"); + ts_queries.addOption([]const u8, g.name ++ "_highlights_unfiltered", query); + ts_queries.addOption([]const u8, g.name ++ "_highlights", grammar_manifest.colorQuery(query, b.allocator.alloc(u8, query.len) catch @panic("OOM"))); // helix's textobject queries, vendored (vendor/queries); a // grammar without one gets none const objects = configureRead(b, io, b.root, "vendor/queries/" ++ g.name ++ "/textobjects.scm", 0x100000) catch ""; diff --git a/src/CHANGELOG.md b/src/CHANGELOG.md index dc130be1..3b139f00 100644 --- a/src/CHANGELOG.md +++ b/src/CHANGELOG.md @@ -2,6 +2,12 @@ ## Unreleased +- An edit to the core recompiles it about 3 s sooner (`core-test`, 13 s to + 10 s): the build keeps each grammar's highlight patterns that pardes + colours once, where every compile of every program that takes the core + did it again, a quarter of its time. A package that depends on pardes + is given the same filtered queries. + - Commit patches open as `+Diff-` and reuse only their own commit's pane, so another paged patch no longer replaces one already open. diff --git a/src/grammar_manifest.zig b/src/grammar_manifest.zig index 38c54916..711c31a4 100644 --- a/src/grammar_manifest.zig +++ b/src/grammar_manifest.zig @@ -1,6 +1,7 @@ //! Dependency-free tree-sitter grammar metadata shared by build.zig and the -//! runtime syntax registry. Keep target symbols and query values out of this -//! file: the build runner imports it as host code. +//! runtime syntax registry, and the highlight-query filter the build runs. +//! Keep target symbols and query values out of this file: the build runner +//! imports it as host code. const std = @import("std"); @@ -14,6 +15,8 @@ pub const Grammar = struct { src: []const u8 = "src", scanner: bool = false, query: []const u8 = "queries/highlights.scm", + /// Patterns appended to the highlights query before it is filtered. + highlights_extra: []const u8 = "", }; pub const all = [_]Grammar{ @@ -48,7 +51,13 @@ pub const all = [_]Grammar{ .{ .name = "ruby", .dep = "ts_ruby", .exts = &.{ ".rb", ".rake" }, .tier = .full, .scanner = true }, .{ .name = "rust", .dep = "ts_rust", .exts = &.{".rs"}, .tier = .full, .scanner = true }, .{ .name = "scala", .dep = "ts_scala", .exts = &.{ ".scala", ".sc" }, .tier = .full, .scanner = true }, - .{ .name = "typst", .dep = "ts_typst", .exts = &.{ ".typ", ".typst" }, .tier = .full, .scanner = true, .query = "queries/typst/highlights.scm" }, + .{ .name = "typst", .dep = "ts_typst", .exts = &.{ ".typ", ".typst" }, .tier = .full, .scanner = true, .query = "queries/typst/highlights.scm", .highlights_extra = + \\ + \\(call item: (ident) @keyword) + \\(call item: (field field: (ident) @keyword)) + \\"#" @keyword + \\ + }, .{ .name = "zig", .dep = "ts_zig", .exts = &.{ ".zig", ".zon" }, .tier = .zig }, }; @@ -92,3 +101,96 @@ pub fn byPath(path: []const u8) ?usize { for (all, 0..) |g, i| for (g.exts) |e| if (std.ascii.eqlIgnoreCase(ext, e)) return i; return null; } + +/// pardes's syntax classes: what a capture colours a byte as. +pub const Syn = enum(u8) { none, keyword, string, number, comment }; + +pub fn synFor(name: []const u8) Syn { + for ([_]struct { []const u8, Syn }{ + .{ "comment", .comment }, + .{ "string", .string }, + .{ "character", .string }, + .{ "number", .number }, + .{ "numeric", .number }, + .{ "float", .number }, + .{ "boolean", .number }, + .{ "keyword", .keyword }, + .{ "include", .keyword }, + .{ "conditional", .keyword }, + .{ "repeat", .keyword }, + .{ "title", .keyword }, + .{ "uri", .string }, + .{ "reference", .number }, + .{ "heading", .keyword }, + .{ "strong", .comment }, + .{ "bold", .comment }, + .{ "emphasis", .number }, + .{ "italic", .number }, + .{ "literal", .string }, + .{ "raw", .string }, + }) |m| { + if (std.mem.indexOf(u8, name, m[0]) != null) return m[1]; + } + return .none; +} + +/// The patterns of highlights query `source` that capture a class (synFor), +/// written to `out` (source.len bytes): what a grammar's query compiles to. +/// build.zig filters each one with it, ts_queries' `_highlights`. +pub fn colorQuery(source: []const u8, out: []u8) []u8 { + var written: usize = 0; + var at: usize = 0; + while (at < source.len) { + while (at < source.len) { + if (std.ascii.isWhitespace(source[at])) { + at += 1; + } else if (source[at] == ';') { + while (at < source.len and source[at] != '\n') at += 1; + } else break; + } + const begin = at; + var depth: usize = 0; + var colored = false; + var complete = false; + while (at < source.len) { + const byte = source[at]; + if (complete and (byte == '(' or byte == '[' or byte == '"')) break; + if (byte == ';') { + while (at < source.len and source[at] != '\n') at += 1; + continue; + } + if (byte == '"') { + at += 1; + while (at < source.len) : (at += 1) { + if (source[at] == '\\') { + at += 1; + } else if (source[at] == '"') { + at += 1; + break; + } + } + if (depth == 0) complete = true; + continue; + } + if (byte == '(' or byte == '[') depth += 1; + if (byte == ')' or byte == ']') { + depth -= 1; + if (depth == 0) complete = true; + } + if (byte == '@') { + const name = at + 1; + at = name; + while (at < source.len and (std.ascii.isAlphanumeric(source[at]) or + source[at] == '_' or source[at] == '.' or source[at] == '-')) at += 1; + colored = colored or synFor(source[name..at]) != .none; + continue; + } + at += 1; + } + if (colored) { + @memcpy(out[written..][0 .. at - begin], source[begin..at]); + written += at - begin; + } + } + return out[0..written]; +} diff --git a/src/syntax.zig b/src/syntax.zig index 2526e113..8533aaa9 100644 --- a/src/syntax.zig +++ b/src/syntax.zig @@ -22,7 +22,7 @@ const ts_queries = if (enabled) @import("ts_queries") else struct {}; const LanguageFn = *const fn () callconv(.c) *const ts.Language; -pub const Syn = enum(u8) { none, keyword, string, number, comment }; +pub const Syn = grammar_manifest.Syn; /// A query compiled when first asked for: "" for none, null when it fails. const Lazy = struct { src: []const u8 = "", query: ?*ts.Query = null, failed: bool = false }; @@ -55,81 +55,6 @@ fn specCount() comptime_int { } return count; } -const typst_supplement = - \\ - \\(call item: (ident) @keyword) - \\(call item: (field field: (ident) @keyword)) - \\"#" @keyword - \\ -; - -fn querySrc(comptime g: grammar_manifest.Grammar) []const u8 { - const base = @field(ts_queries, g.name ++ "_highlights"); - const source = if (comptime std.mem.eql(u8, g.name, "typst")) base ++ typst_supplement else base; - return comptime colorQuery(source); -} - -fn colorQuery(comptime source: []const u8) []const u8 { - @setEvalBranchQuota(2_000_000); - var result: [source.len]u8 = undefined; - var written: usize = 0; - var at: usize = 0; - while (at < source.len) { - while (at < source.len) { - if (std.ascii.isWhitespace(source[at])) { - at += 1; - } else if (source[at] == ';') { - while (at < source.len and source[at] != '\n') at += 1; - } else break; - } - const begin = at; - var depth: usize = 0; - var colored = false; - var complete = false; - while (at < source.len) { - const byte = source[at]; - if (complete and (byte == '(' or byte == '[' or byte == '"')) break; - if (byte == ';') { - while (at < source.len and source[at] != '\n') at += 1; - continue; - } - if (byte == '"') { - at += 1; - while (at < source.len) : (at += 1) { - if (source[at] == '\\') { - at += 1; - } else if (source[at] == '"') { - at += 1; - break; - } - } - if (depth == 0) complete = true; - continue; - } - if (byte == '(' or byte == '[') depth += 1; - if (byte == ')' or byte == ']') { - depth -= 1; - if (depth == 0) complete = true; - } - if (byte == '@') { - const name = at + 1; - at = name; - while (at < source.len and (std.ascii.isAlphanumeric(source[at]) or - source[at] == '_' or source[at] == '.' or source[at] == '-')) at += 1; - colored = colored or synFor(source[name..at]) != .none; - continue; - } - at += 1; - } - if (colored) { - @memcpy(result[written..][0 .. at - begin], source[begin..at]); - written += at - begin; - } - } - const filtered = result[0..written].*; - return &filtered; -} - fn initSpecs() [specCount()]Spec { var out: [specCount()]Spec = undefined; var i = 0; @@ -139,7 +64,7 @@ fn initSpecs() [specCount()]Spec { .name = g.name, .exts = g.exts, .language = @extern(LanguageFn, .{ .name = "tree_sitter_" ++ g.name }), - .query_src = querySrc(g), + .query_src = @field(ts_queries, g.name ++ "_highlights"), .objects = .{ .src = @field(ts_queries, g.name ++ "_textobjects") }, .indents = .{ .src = @field(ts_queries, g.name ++ "_indents") }, }; @@ -219,7 +144,7 @@ fn ensure(spec: *Spec) !Selected { const capture_styles = spec.capture_styles[0..query.captureCount()]; for (capture_styles, 0..) |*style, id| { const name = query.captureNameForId(@intCast(id)) orelse ""; - style.* = @backingInt(synFor(name)); + style.* = @backingInt(grammar_manifest.synFor(name)); if (style.* == 0) query.disableCapture(name); } const parser = ts.Parser.create(); @@ -260,34 +185,6 @@ fn runQuery(styles: []u8, sel: Selected, tree: *ts.Tree, base: usize) void { } } -fn synFor(name: []const u8) Syn { - for ([_]struct { []const u8, Syn }{ - .{ "comment", .comment }, - .{ "string", .string }, - .{ "character", .string }, - .{ "number", .number }, - .{ "numeric", .number }, - .{ "float", .number }, - .{ "boolean", .number }, - .{ "keyword", .keyword }, - .{ "include", .keyword }, - .{ "conditional", .keyword }, - .{ "repeat", .keyword }, - .{ "title", .keyword }, - .{ "uri", .string }, - .{ "reference", .number }, - .{ "heading", .keyword }, - .{ "strong", .comment }, - .{ "bold", .comment }, - .{ "emphasis", .number }, - .{ "italic", .number }, - .{ "literal", .string }, - .{ "raw", .string }, - }) |m| { - if (std.mem.indexOf(u8, name, m[0]) != null) return m[1]; - } - return .none; -} pub fn highlightFileRange(gpa: std.mem.Allocator, path: []const u8, content: []const u8, start_raw: usize, end_raw: usize) ![]u8 { const zone = tracy.zone(@src(), "highlightFileRange"); defer zone.end(); @@ -1909,8 +1806,7 @@ test "syntax query filtering preserves upstream colors" { inline for (grammar_manifest.all) |grammar| { if (comptime grammarSelected(grammar)) { const selected = (try forLang(grammar.name)).?; - const raw_source = @field(ts_queries, grammar.name ++ "_highlights") ++ - (if (comptime std.mem.eql(u8, grammar.name, "typst")) typst_supplement else ""); + const raw_source = @field(ts_queries, grammar.name ++ "_highlights_unfiltered"); var error_offset: u32 = 0; const raw_query = try ts.Query.create(selected.lang, raw_source, &error_offset); defer raw_query.destroy(); @@ -1918,7 +1814,7 @@ test "syntax query filtering preserves upstream colors" { reference.query = raw_query; reference.capture_styles = try std.testing.allocator.alloc(u8, raw_query.captureCount()); defer std.testing.allocator.free(reference.capture_styles); - for (reference.capture_styles, 0..) |*style, id| style.* = @backingInt(synFor(raw_query.captureNameForId(@intCast(id)) orelse "")); + for (reference.capture_styles, 0..) |*style, id| style.* = @backingInt(grammar_manifest.synFor(raw_query.captureNameForId(@intCast(id)) orelse "")); const tree = selected.parser.parseString(source, null) orelse return error.ParseFailed; defer tree.destroy(); var expected: [source.len]u8 = @splat(0); -- cgit v1.3 From 6d9272b83d122585ad7bbe7214c078f65351c3c0 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 17 Nov 2026 00:25:19 -0300 Subject: lib: the diff is a language of pardes-syntax: `diff` (Walk, targetAt), `highlightDiff`, the style byte's `syn_bits` and grounds and colors.Grounds, a theme's colours for them; test/lib colours a C patch through it (each side's code as C, the rows' grounds, Orchard's, and the place a `+` row names) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- src/lib_syntax.zig | 19 +++++++++++++++++++ test/lib/lib.zig | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+) diff --git a/src/lib_syntax.zig b/src/lib_syntax.zig index 395a02f0..a25af884 100644 --- a/src/lib_syntax.zig +++ b/src/lib_syntax.zig @@ -51,6 +51,25 @@ pub const SourceAnalysis = syntax.SourceAnalysis; pub const ContextDeclaration = syntax.ContextDeclaration; pub const analyzeSource = syntax.analyzeSource; +/// A unified diff as a language: `diff` walks one a line at a time +/// (`Walk`: a line's kind, the file its section names, the hunk's line +/// numbers) and says what a row of it points at (`targetAt`); +/// `highlightDiff` is a style byte for each byte of `content[start..end]`, +/// the caller's to free: headers as comments, `@@` lines as keywords, each +/// hunk's code in the language of the file its section names (old and new +/// side each parsed whole), and over that an added or removed line's +/// grounds (`ground_add`, `ground_del`; its first byte `ground_emph`, the +/// strong row). A byte's low bits (`syn_bits`) are a `Syn`; `Grounds` are +/// a theme's colours for the rest. +pub const diff = @import("diff.zig"); +pub const highlightDiff = syntax.highlightDiff; +pub const syn_bits = syntax.syn_bits; +pub const ground_add = syntax.ground_add; +pub const ground_del = syntax.ground_del; +pub const ground_emph = syntax.ground_emph; +pub const ground_line = syntax.ground_line; +pub const Grounds = colors.Grounds; + /// The tree-sitter bindings a tree is read through: `tree.rootNode()`, and /// a node's `kind()`, `startByte()`, `endByte()`, `child(i)`, `parent()`. pub const ts = syntax.ts; diff --git a/test/lib/lib.zig b/test/lib/lib.zig index a3f99b56..7e297920 100644 --- a/test/lib/lib.zig +++ b/test/lib/lib.zig @@ -102,6 +102,60 @@ test "a C and a Zig source are coloured, outlined and walked as pardes has them, try std.testing.expectEqual(null, pardes.theme("no such theme")); } +test "a diff is a language: its hunks coloured as their file's, its added and removed rows on a theme's grounds" { + const gpa = std.testing.allocator; + pardes.start(gpa); + defer pardes.stop(); + const patch = + \\diff --git a/main.c b/main.c + \\--- a/main.c + \\+++ b/main.c + \\@@ -1,3 +1,3 @@ + \\ int main(void) { + \\- return 1; + \\+ return 0; + \\ } + \\ + ; + const styles = try pardes.highlightDiff(gpa, patch, 0, patch.len); + defer gpa.free(styles); + try std.testing.expectEqual(patch.len, styles.len); + const syn = struct { + fn at(s: []const u8, text: []const u8, needle: []const u8) pardes.Syn { + return @fromBackingInt(s[std.mem.indexOf(u8, text, needle).?] & pardes.syn_bits); + } + }.at; + try std.testing.expectEqual(pardes.Syn.comment, syn(styles, patch, "--- a/main.c")); + try std.testing.expectEqual(pardes.Syn.keyword, syn(styles, patch, "@@ -1,3")); + // each side's code as C, behind its marker + try std.testing.expectEqual(pardes.Syn.keyword, syn(styles, patch, "return 1")); + try std.testing.expectEqual(pardes.Syn.keyword, syn(styles, patch, "return 0")); + try std.testing.expectEqual(pardes.Syn.number, syn(styles, patch, "0;")); + const added = std.mem.indexOf(u8, patch, "+ return 0").?; + const removed = std.mem.indexOf(u8, patch, "- return 1").?; + try std.testing.expectEqual(pardes.ground_add | pardes.ground_emph, styles[added]); + try std.testing.expect(styles[added + 5] & pardes.ground_add != 0 and styles[added + 5] & pardes.ground_emph == 0); + try std.testing.expectEqual(pardes.ground_del | pardes.ground_emph, styles[removed]); + try std.testing.expectEqual(0, styles[std.mem.indexOf(u8, patch, " int main").?] & (pardes.ground_add | pardes.ground_del)); + + // a row's hue in a theme: a ground between the page and the theme's green, a stronger and a fainter one + const th = pardes.theme("Orchard").?; + const g = pardes.Grounds.of(th); + const ground = g.forStyle(styles[added]).?; + try std.testing.expectEqual(g.add, ground); + try std.testing.expectEqual(g.del, g.forStyle(styles[removed]).?); + try std.testing.expectEqual(null, g.forStyle(@backingInt(pardes.Syn.keyword))); + try std.testing.expect(!std.mem.eql(u8, &ground.row, &pardes.page(th)) and !std.mem.eql(u8, &ground.row, &ground.emph) and !std.mem.eql(u8, &ground.row, &ground.line)); + + // what a row points at: the new line a `+` row is + var lines: std.ArrayList([]const u8) = .empty; + defer lines.deinit(gpa); + var it = std.mem.splitScalar(u8, patch, '\n'); + while (it.next()) |line| try lines.append(gpa, line); + var buf: [64]u8 = undefined; + try std.testing.expectEqualStrings("main.c:2", pardes.diff.targetAt(lines.items, 6, false).?.address(&buf).?); +} + test "every name the library has compiles outside pardes" { std.testing.refAllDecls(pardes); } -- cgit v1.3 From 218d574b59abd7fb8dd6fe027b12927fc31c3506 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 17 Nov 2026 00:25:32 -0300 Subject: output: a results pane's refill identity is its name too, so fillRows loses its diff.commitHash case: fillRows takes the name its producer gives the pane (null: its origin's own, as open names it) and refills only a pane of that name, with that origin and arg, in that directory; openDiff names a commit's +Diff `+Diff-<12 hex>` through it rather than renaming the pane after, so each commit keeps its own +Diff and the same commit refills it, as before (hunks.zig's last test); goldens unchanged Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- src/Output.zig | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/src/Output.zig b/src/Output.zig index d4be640c..5bad7ab7 100644 --- a/src/Output.zig +++ b/src/Output.zig @@ -414,17 +414,19 @@ 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); + _ = try fillRows(p, id, dir, from, null, 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, +/// belong in: the one named `name` (null: its origin's own name, as `open` +/// gives it) that 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 { +pub fn fillRows(p: *Pardes, id: usize, dir: []const u8, from: Origin, name: ?[]const u8, 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; + const own = name orelse if (from == .kind) arg else traits(from).name; for (p.panes, 0..) |slot, i| { const rp = slot orelse continue; const rf = if (rp.file) |*f| f else continue; @@ -440,8 +442,7 @@ pub fn fillRows(p: *Pardes, id: usize, dir: []const u8, from: Origin, arg: []con 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.Io.Dir.path.dirname(rf.path) orelse "", dir)) continue; - if (std.meta.eql(from, Origin{ .cmd = .Diff }) and - !std.mem.eql(u8, diff.commitHash(rf.content) orelse "", diff.commitHash(result_content) orelse "")) continue; + if (!std.mem.eql(u8, std.Io.Dir.path.basename(rf.path), std.Io.Dir.path.basename(own))) continue; o.from = from; p.fs.refilled = rp.serial; try setArg(o, arg); @@ -470,7 +471,13 @@ pub fn fillRows(p: *Pardes, id: usize, dir: []const u8, from: Origin, arg: []con return i; } const free = p.freeSlot() orelse return error.NoPaneSlots; + const path = if (name) |named| try std.fmt.allocPrint(p.gpa, "{s}/{s}", .{ std.mem.trimEnd(u8, dir, "/"), named }) else null; + errdefer if (path) |owned| p.gpa.free(owned); const np = try open(p, free, dir, from, arg, result_content); + if (path) |owned| { + p.gpa.free(np.file.?.path); + np.file.?.path = owned; + } np.file.?.location_rows = result_rows; layout.placeNew(p, id, id, free, .doc); p.view().active = id; @@ -486,8 +493,10 @@ pub fn fillRows(p: *Pardes, id: usize, dir: []const u8, from: Origin, arg: []con /// 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. +/// stands elsewhere), for Diff to go back to it; a commit's (`git show`, a +/// mailed patch) is named for it too, `+Diff-<12 hex>`, so each commit +/// keeps a +Diff of its own. 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.Io.Dir.path.dirname(path) orelse p.sessionDir(); // Each file read is a site of the step's tape (fs.zig): a replica @@ -525,18 +534,12 @@ pub fn openDiff(p: *Pardes, id: usize, path: []const u8, content: []const u8) !u 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.Io.Dir.path.basename(path) else path; - const title = if (diff.commitHash(content)) |hash| - try std.fmt.allocPrint(p.gpa, "{s}/{s}-{s}", .{ std.mem.trimEnd(u8, root, "/"), config.diff_buffer, hash[0..@min(hash.len, 12)] }) + var name_buf: [config.diff_buffer.len + 13]u8 = undefined; + const name = if (diff.commitHash(content)) |hash| + std.fmt.bufPrint(&name_buf, "{s}-{s}", .{ config.diff_buffer, hash[0..@min(hash.len, 12)] }) catch unreachable else null; - errdefer if (title) |name| p.gpa.free(name); - const hid = try fillRows(p, id, root, .{ .cmd = .Diff }, arg, result.content, result.rows, null); - if (title) |name| { - const f = &p.panes[hid].?.file.?; - p.gpa.free(f.path); - f.path = name; - } - return hid; + return fillRows(p, id, root, .{ .cmd = .Diff }, name, arg, result.content, result.rows, null); } /// Diff on a +Diff: the diff it stacks, as text. A pane holding it -- cgit v1.3 From 797e1b05324a8de7217b7e483496f44c1e7bcdbd Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 17 Nov 2026 00:22:38 -0300 Subject: docs/next-plumber.md: the plumber in pardes's core, the design record of 2026-11-16: Plan 9's plumber and acme's use of it read from the sources (the message, the rules language, the files, the order acme asks it in), what pardes's Look decides today and which of it is plumbing, the design (Plumb.zig owning the rules as their text, a pure matcher over the existing regex convention with isfile and isdir at the taped resolve sites, pardes reading its own ports as acme reads edit, plumb start as pardes's exec), the files, Look after the plumber with the default rule file in full, the phases and their gates; the four questions decided: submatches refused in words, an open pane first, the Plumb word opening /plumbing, start as exec Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- docs/next-plumber.md | 896 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 896 insertions(+) create mode 100644 docs/next-plumber.md diff --git a/docs/next-plumber.md b/docs/next-plumber.md new file mode 100644 index 00000000..76a86bea --- /dev/null +++ b/docs/next-plumber.md @@ -0,0 +1,896 @@ +# The plumber in pardes's core: the design record + +> it's really about time to write the acme plumber, it's a real part of the +> core that we're missing. You may use its code at principia softwarica as a +> reference. + +Said 2026-11-16, while ruling on the diff viewer ("Keep the diff compiled in +and do the changes that it asks for pardes as a library"). The diff survey +had found three diff decisions hard-coded in Look and the pager that are +plumbing with no general form, because pardes's `Plumb` word has no +`matches` test and cannot start anything (.scratch/sketch/reports/diff-module.md +§3 row 12, §5 M3). The coordinator's ruling: the three hooks become default +plumbing rules when the plumber lands (PLAN.md §7 Dv). + +This is round 1 of a design discussion. It is written to be committed as +`docs/next-plumber.md`, and an implementation agent follows it. Nothing was +built or run: every number below is a count from reading or an estimate. Plan +9 paths are under `~/05-genizah/principia-softwarica` unless they say +`plan9port/` (`~/05-genizah/plan9port`). pardes paths are the working copy, +including the user's uncommitted edits. + +## 0. Summary + +- **What Plan 9's plumber is.** A small language-driven file server. A message + is six header lines (src, dst, wdir, type, attr, ndata) and then the data. The + rules are blank-line-separated rule sets of `object verb args` lines, and the + first rule set whose patterns all hold takes the message. Its actions are + `plumb to `, `plumb start ` and `plumb client `. The files are + `send`, `rules` and one file per port. +- **What acme does with it.** acme asks the plumber first. A write that fails + means no rule matched, and acme then does its own look, which opens a file or + searches for the word (plan9port acme/look.c:147-223). acme reads the `edit` + port itself: it opens a file at an `addr`, or shows the data when + `action=showdata` (acme.c:556-564). +- **What pardes has.** A one-line `Plumb` word with four tests and three ports + (look.zig:155-261). Its rules sit in the middle of `resolve`, which also + hard-codes four other decisions: + - http(s) URLs (look.zig:263-265, :1601); + - a bare `.diff`/`.patch` stacked in a +Diff (:1622-1633); + - a commit hash run through `git show` (:1092, :1118-1143); + - a diff paged into a +Pager restacked (ninep/ctl.zig:721-731). + + No user rule exists today: the user's init has no `Plumb` line. Two tests pin + the word: look.zig:2688 and test/behaviour/addons.zig:188. +- **The design.** + - `src/Plumb.zig` owns the rules as text, which is replicated and dumped core + state, plus the ports this session has named. + - Its matcher is a pure function of the rules and a message. The exceptions + are `isfile`/`isdir`, which resolve a name exactly as Look does, through + taped `.resolve` sites. + - `matches` uses mvzr through regexp.zig, with no engine work. The price is + `$0` but no `$1`–`$9`, because mvzr has no capture groups. + - pardes reads three kinds of port itself, as acme reads `edit`: `edit` (Look's + open), `web` (the host's link opener) and every loaded kind by its name. + Other ports are 9P files that external programs read, with the tree's held + reads. + - `plumb start` runs the expanded line as pardes's exec runs a line from the + message's pane, so a builtin such as `Diff $file` runs in place. + - The files are `plumb/send`, `plumb/rules` and `plumb/`, in Plan 9's + text form and with Plan 9's error words. +- **Look after it.** The pane-context readings stay first: History, Recent, a + diff line, a command word, `file:/re/`, and a name already open in a pane. + Then the plumber runs. If it takes nothing, pardes's own look runs on the + target it already resolved. The default rule file (§5.2) reproduces today's + behaviour, and the three diff hooks and the URL become rules. `Diff` gains an + argument (a file or a revision) and a way to decline silently, which is what + keeps the fallback byte-identical. +- **Size.** About 600 lines of new code and 400 lines of tests. look.zig loses + about 150 lines. +- **Phases.** + 1. The language and the files. + 2. Look sends to the plumber. + 3. External ports. + 4. The pager as a sender. + + Deferred: the click attribute, the hover asking the matcher, and + `pardes plumb`. +- **Four taste questions** (§8): + 1. submatches; + 2. whether an open pane comes before the rules; + 3. the `Plumb` word's form; + 4. whether `start` of a program is a command pane or detached. + +## 1. What Plan 9's plumber is + +### 1.1 The message + +- **Six lines of header, then the data.** The lines are src, dst, wdir, type, + attr and ndata, followed by ndata bytes of data with no terminating newline + (include/ipc/plumb.h:5-28; plumb.ms:223-263). + - Any header line may be empty except ndata. + - Only `type=text` is supported (plumb(6), ROOT/docs/man/6/plumb:49-59). +- **attr** is `name=value` pairs separated by blanks. + - A value holding a blank, a quote, `=` or a tab is quoted rc-style: `'…'`, + with `''` for a quote (libplumb/mesg.c:76-103 quote, :260-338 + plumbunpackattr). + - A value cannot hold a newline. +- **Packing and unpacking** are plumbpack (mesg.c:157-193) and + plumbunpackpartial (:382-432). + - Unpacking tells "not yet complete" (`*morep` bytes still to come) apart from + "malformed". + - That is how the plumber assembles a message written in pieces + (fsys.c:858-887). + +### 1.2 The rules language + +Taken from rules.c and match.c, which are authoritative where the man page +differs. + +- **Lines.** + - `#` starts a comment, which counts as a blank line. + - A blank line ends a rule set. + - `include file` substitutes a file: an absolute path, `./` or `../`, else the + plumber's directory, then `/lib/plumb` (principia patched this from + `/sys/lib/plumb`). It is limited to depth 10 (rules.c:89-112, :398-432). + - `name=value` defines a variable, one per line (:376-396). +- **A rule line** is `object verb arg…`. + - The objects are `arg attr data dst plumb src type wdir`. `kind` is an old + spelling of `type` (rules.c:46-57, :474-480). + - The verbs are `add client delete is isdir isfile matches set start to` + (:59-72). +- **Parse checks** (rules.c:348-374, :531-613): + - `plumb` takes only `to`, `start` and `client`, and only `plumb` takes them. + - `add` and `delete` take only `attr`. + - A rule set needs patterns and actions, with at most one `start` or `client` + and at most one `to`. + - A rule set of nothing but `plumb to X` lines declares ports. + - The port names `.`, `..` and `send` are illegal. +- **Arguments are expanded twice.** + - At parse time, with the variables only (`qarg`). A `matches` regex is + compiled then, so `'$addr'` in a pattern is the macro (rules.c:351, :364-366). + - At match time, with the message's variables too. + - Expansion is rc quoting: `'…'` is literal, `''` is a quote, and `$` outside + quotes is a variable (rules.c:294-336). +- **The variables** (rules.c:249-292): + - `$0`–`$9`: the last `data matches` and its parenthesised submatches; + - `$src`, `$dst`, `$type`, `$wdir`, `$data`; + - `$attr`: the packed attributes; + - `$file` and `$dir`: what `isfile`/`isdir` found. Without one they are data + joined to wdir (filename, :228-247). + - An unknown `$x` stays as written (:322-325). +- **Patterns run in order, and a rewrite is permanent even if a later pattern + fails** (plumb(6) :140-145; match.c:366-386 mutates the message in place). +- **Each verb:** + - `is`: string equality on data, dst, type, wdir or src (match.c:17-36). + - `isfile`/`isdir`: the expanded arg (or data, or wdir) is made absolute in + wdir and cleaned (not realpath'd), then stat'd. Success sets `$file`/`$dir` + (match.c:131-189, absolute :149-159). + - `set`: replaces data, dst, type, wdir or src. A `data set` clears the click + span (:191-231). + - `add`: appends attributes (:233-245). + - `delete`: removes an attribute. **The code fails the pattern when the + attribute is absent** (:247-264). The man page says it matches anyway + (plumb(6) :155-161). pardes follows the code. +- **`matches`** (match.c:75-129): + - Without a `click` attribute, the regex must match the **whole** object + (:119-126). + - With `click=N` on data, the plumber tries the regex from each offset 0..N. + The first match that contains offset N wins, where N counts runes + (clickmatch, :55-73). + - Every `data matches` in the rule set must then match that same span + (:99-100). The data is cut to that span and the click attribute removed when + the set matches (rewrite, :318-344). + - This is Pike's two-patterns trick: one pattern finds the run of file + characters, the next checks its suffix, so `horse.gift` is no `.gif` + (plumb.ms:444-514). + - Plan 9's regexp is leftmost-longest (plumb.ms:481). +- **First match wins**, then dispose (fsys.c:892-902): + - A message that names a dst only tries rule sets whose `to` names that port + (match.c:372-373). A set without `to` still tries. + - A matching set with `to` sets dst when dst was empty (:380-383). + - No set matches: a message that names a dst goes there unchanged. Anything + else is the write error `no matching plumb rule`. +- **Dispose** (fsys.c:524-556, startup match.c:438-463): + - dst empty: run the `start`/`client` command, or fail `couldn't find + destination for message`. + - dst is a port with readers: queue the message to each of them (fan-out). + - dst is a port with no reader: run `start`, which discards the message, or + `client`, which holds it until the port is opened. Otherwise fail `no start + action for plumb message`. +- **`start` and `client`** split the expanded arguments into argv and **exec + them directly, with no shell**, stdin `/dev/null`, falling back to `/bin/x` + (match.c:346-364, :419-436). Rules that need a pipe say `rc -c '…'` + (ROOT/lib/plumb/basic:13, :95). The man page's "a shell program" (plumb(6) + :254-260) is loose. + +### 1.3 The files + +- **The directory** is `rules` (0600), `send` (0200) and one file per port + (0400), each port created the first time a rule names it. Ports are never + deleted (fsys.c:94-99, :161-182; plumber(4) :85-101). At most 50 entries + (NDIR). +- **`send`**: a write is a message, assembled across writes (fsys.c:858-887). It + is answered once the message is matched and queued, so the sender never + waits on the reader (plumb.ms:724-760). An error comes back as the write's + error string. +- **A port**: opening it makes the opener a reader. A message goes to every fid + open when it was sent (queuesend, fsys.c:337-362). + - A read blocks until a message arrives, and a message may take several reads + (drainqueue, :377-436). + - A flush cancels a held read (:439-459). + - A clunk drops what that fid had not read (:462-491). + - Messages held for a `client` go to the first opener (queueheld on open, + :510-522, :754). +- **`rules`**: + - A read gives the parsed rules printed back: variables, port declarations, + then each set as `obj\tverb\targ` (printrules, rules.c:695-710). + - A write appends. Complete rule sets, as judged by a blank line, are parsed + at each write and the rest at close, and a parse error is that write's + error (morerules :722-760, writerules :762-784, fsysclunk :943-952). + - An `OTRUNC` open clears the rules (fsys.c:707-711, :742-745). There is one + writer at a time (`file already open`, :732-741). +- **Startup.** The plumber reads `$home/lib/plumbing` (plumber.c:60-72), which is + usually just `include basic` (ROOT/usr/pad/lib/plumbing; plan9port + plumb/initial.plumbing: `editor = acme`, `include basic`). + +### 1.4 What acme does around it + +Read in plan9port's acme (principia's acme predates the plumber's use). + +- **A pane with an event reader comes first.** The look goes to that reader as + an `l`/`L` event and is never plumbed (look.c:98-146). +- **Otherwise acme sends a message** (look.c:147-195): + - src is `acme`; + - wdir is the window's directory, or acme's own (:152-162); + - type is `text`; + - the data is the selection when there is one. With no selection it is the + whitespace-delimited word around the click, plus `click=` + (:166-182). + - A write that succeeds ends the look. A failed write (no rule matched) falls + through (:189-194). +- **acme's own look** opens a file or address (openfile, which also handles + directories and acme's `includename` search) or searches the window for the + word (:197-223). +- **acme reads the `edit` port** (plumbthread, look.c:25-72, which reconnects to + a restarted plumber). It acts on a message by its `action` attribute + (acme.c:556-564): + - none or `showfile`: open the file at the message's `addr` attribute + (plumblook, look.c:241-271); + - `showdata`: a new window holding the data, named by the `filename` + attribute or `Untitled-N`, and clean (plumbshow, :273-311). + + `plumb -i` adds `action=showdata` (plumb(1) :69-77). That is how the stock + rules show `man` output and `doc2txt` output in the editor (plumb.ms:993-1033; + plan9port plumb/basic:139-142). +- **Plan 9's own limit**: the language cannot look inside files, only at names + (plumb.ms:1298-1314). + +## 2. What pardes has today, measured + +### 2.1 The `Plumb` word + +- **Builtin**: builtins.zig:941-978, with session scope. It takes one line, + ` [word…] to `, checked by look.plumbRuleError (look.zig:160-186). +- **Tests**: `prefix` (the text starts so), `suffix` (an existing file's + resolved path ends so, in any case), `isdir`, `isfile`. +- **Ports**: `url`, `dir`, `file` or a loaded kind's name (look.zig:158). A port + naming a kind that is not loaded is refused. +- **Forms**: bare lists the rules on the message row; `Plumb -` empties them. +- **State**: the field `Core.plumb: ArrayList([]u8)` (Core.zig:211-213), which + is digested and dumped (it is not in `replica`'s lists, Core.zig:401-418). +- **Matching**: inside `resolve` (look.zig:227-261). The user's rules come after + an `@p` pane address (:214-225) and after resolveLookTarget's open-pane check + (:881, :894-897), and before the URL test and the disk. +- **Who uses it.** + - The user's init: none (grep of ~/.config/pardes/init). + - Tests: look.zig:2688-2735, and test/behaviour/addons.zig:188-209 (a rule to + the image kind). + - Docs: reference.typ:1355, guide.typ:177. + +### 2.2 Everything Look decides, and which of it is plumbing + +lookAt (look.zig:1493-1688) runs these steps in order. The last column says what +each step is in acme's terms. + +| # | decision | code | in acme | +|---|---|---|---| +| 1 | a +History row restores a dump | look.zig:1507-1512 | the window's own (an event reader's): **not plumbing** | +| 2 | a +Recent/+Jumplist row reopens, clamped | :1515-1520 | the window's own: not plumbing | +| 3 | a whole diff line written over 9P is its address | :1524-1527 (diffLineAddress :1423) | the window's own rows (M4's row address): not plumbing | +| 4 | a `` @`…` `` command word executes | :1528-1531 | exec: not plumbing | +| 5 | `~`, `` and a trailing `:` | :1500-1502, :1536-1540 | the sender's expansion (acme's `expand`) | +| 6 | `file:3:0` refused | :1546 | address syntax: not plumbing | +| 7 | `file:/re/`, `:addr` | :1547 (addressed :1028; lookAddress :1148) | plumbing in Plan 9 (fileaddr's `$addr`), but evaluated by the editor; stays here (see §5.1) | +| 8 | `:N` in a kind's pane | :1550-1551 | the window's own | +| 9 | an `@p` address | resolve :214-225 | pardes's names: not plumbing | +| 10 | a name open in a pane, first by path, then joined to each candidate directory | resolveLookTarget :881, :894-897 | acme's `lookfile` inside openfile, after the plumber | +| 11 | the user's Plumb rules | resolve :227-261 | **plumbing** | +| 12 | http(s):// opens the browser | resolve :263-265; lookAt :1601 (emits `open_link`, Effect.zig:48, :131-134; the hosts' `look.openLink`, look.zig:39-54, double-fork xdg-open or `open`) | **plumbing** (`plumb to web`, plan9port plumb/basic:18-22) | +| 13 | a name found in the pane's directory, then the jump list's directories, then Incl's | resolveLookTarget :877-911; fs.resolve fs.zig:341-381 (taped `.resolve`, fs.zig:436-446) | acme's openfile plus includename (its own look) | +| 14 | a directory opens a listing pane | resolve :268; lookAt :1602-1611 | acme's openfile, not the plumber | +| 15 | a kind's extension opens that kind | resolve :269; lookAt :1654-1686 | **plumbing** in Plan 9 (`plumb to image`); in pardes, the editor choosing the kind of pane | +| 16 | a file opens at its line and column | lookAt :1612-1653 | the `edit` port (plumblook) | +| 17 | **a bare `.diff`/`.patch` opens as a +Diff** | :1622-1633 | **plumbing** | +| 18 | a `./` name that is not there is a miss | lookUnresolved :1078-1087 | acme's own | +| 19 | no search in a raw terminal or a kind's pane | :1090 | the window's own | +| 20 | **a commit hash in a git work tree runs `git show` paged** | :1092, lookCommit :1118-1131, isCommitHash :1133-1143; command_pages panes.zig:173-175, :704-707 | **plumbing** | +| 21 | a word is searched in its pane, or in a +Search | lookWord :1011-1023; :1093-1110 | acme's search: **not plumbing** | +| 22 | **a diff paged into a +Pager is restacked** | ninep/ctl.zig:721-731; the sniff File.zig:752 | `plumb -i … action=showdata` arriving at the editor: **plumbing** | + +The hover, the n/N walk and lineSpan ask `resolve` what is lookable (look.zig:133-153, +:622-632). acme underlines nothing, so that is not plumbing. They keep asking +`resolve` (§7, deferred). + +## 3. The plumber as part of the core + +### 3.1 Where the rules live + +`src/Plumb.zig` is one type file owning its fields, with its tests at its end. + +```zig +//! The plumber (Plan 9's plumber(4), windows/plumb/): the rules, and a +//! message matched against them and sent where they say. +text: std.ArrayList(u8) = .empty, // the rules in force, as plumb/rules reads them +ports: std.ArrayList([]u8) = .empty, // every port a rule named this session, never dropped +``` + +- **The rules are stored as their printed text.** The text is what Plan 9's + printrules prints, with includes already flattened. It is parsed on every + send. Parsing is a few kilobytes of lines and has not been measured. +- **Why text and not a parsed table.** + - Digest, dump and replication are then one byte string; walk.zig needs + nothing new. + - `plumb/rules` returns the text as is. + - No compiled regex is kept: regexp.zig's `Regex` holds a 512-operation mvzr + program and 64 sets (regexp.zig:32-33). + - An `include` needs a disk read, and that read happens only when rules are + written, never when a message is sent. +- **The field.** `Core.plumber: Plumb` replaces `Core.plumb`. The rename keeps an + old dump's `plumb` (a list of strings) from meeting a new type of the same + name. How walk.Load treats a field that has gone is not verified; + dump.zig:1145 shows a precedent for skipping removed fields. +- **Bounds.** At most 64 KiB of rule text (Plan 9's whole basic is about 4 KiB), + 32 ports (Plan 9's 50, less the fixed files), 32 variables and include depth + 10. A write past a bound is refused in words. +- **How rules change.** Each of these is an input, so a replica replays it or + receives it in a dump: + - at boot: the user's `plumbing` file if it exists, else `include basic` (§4.3); + - a write to `plumb/rules`: a 9P `serve_fs` input on the authority, taped, + tape.zig:39; + - saving the `plumbing` file in a pane: the same hook as the init file, + host_io.zig:3006 → exec.reapplyInitFile. Whether that call is itself taped + was not traced. + +### 3.2 The matcher, a pure function + +```zig +pub const Msg = struct { src: []const u8, dst: []const u8, wdir: []const u8, + type: []const u8, attr: []const u8, data: []const u8 }; // attr in its packed text form +pub const Verdict = struct { msg: Msg, set: u16, port: ?[]const u8, + start: ?[]const u8, client: bool }; // in the step's scratch +pub fn match(p: *Pardes, id: usize, rules: []const u8, m: Msg) ?Verdict +``` + +It follows Plan 9's match.c line for line (§1.2), except: + +- **`isfile`/`isdir` resolve a name the way Look does.** + - A place written after the name (`:12`, `:12:5`, `:12-14`) is not part of the + name; parsePathLine reads it (look.zig:70). + - A relative name is tried in wdir, then in the jump list's pane directories, + then in Incl's, through the same function resolveLookTarget uses + (look.zig:886-909, fs.resolve). + - `$file`/`$dir` are the resolved real path, where Plan 9 gives the cleaned + join (match.c:149-159). + - Both differences keep today's behaviour byte-identical (§5). Each is acme's + own look's behaviour moved one step earlier: openfile and includename do + this search in acme. + - Each stat is a taped `.resolve` site (fs.zig:440). A per-send memo of name + to result keeps two rules asking about one name to one syscall. +- **Determinism.** A replica replaying a unit gets the authority's recorded + answers to those sites. A speculating replica is poisoned at the first one and + waits a round trip (tape.zig:934-939), as every Look of a file does today. A + rule set with no `isfile`/`isdir` (the URL, the hash) never touches a site, + so its look speculates fully, as today's URL look does. +- **Every other verb** is pure string work over the message. +- **Expansion** has a fixed 4 KiB buffer, Plan 9's `ebuf` (rules.c:36). An + expansion past it gives Plan 9's `string-too-long`, and the rule fails. That + also keeps a megabyte of paged data out of `$data` (§5.4). + +### 3.3 `matches` on mvzr, through regexp.zig's convention + +- **No engine work.** + - A `matches` with no click compiles `^(` pattern `)$` with regexp.zig's + `Regex.compile` (regexp.zig:102) and asks `find` for a match over the + object (:371). + - Anchoring makes mvzr backtrack into a later alternative when a first one + would match short. So whole-match is exact even though mvzr takes the first + alternative and not the longest (regexp.zig:22-25). + - With `click=N`, the matcher tries `find` from each offset 0..N, as + clickmatch does, and N counts runes. + - regexp.zig's step budget bounds every call; `TooSlow` counts as no match. +- **Plan 9 regexp features in the stock rule files, and what mvzr does with + them** (ROOT/lib/plumb/basic, plan9port plumb/basic; mvzr's list in + zig-pkg/mvzr-0.3.9…/README.md:36-77): + +| feature | used in | mvzr through regexp.zig | +|---|---|---| +| classes with ranges, `\-` `\.` `\^` escaped in them; `[.$]` | everywhere | yes | +| `?` `*` `+`, groups, `\|` | everywhere | yes (greedy; first alternative, not longest: harmless under the `^(…)$` anchoring) | +| `\.`, `\(`, `\)` outside classes | images, man | yes | +| `.*` | `Local (.*)` (basic:116) | yes (`.` is a byte, or not a newline in a pattern naming `\n`: regexp.zig:9-13) | +| the rune range `¡-￿` (U+00A1–U+FFFF) | file, image, man classes | **no**: regexp.zig spells non-ASCII ranges out rune by rune and refuses ones wider than 256 (`WideRange`, regexp.zig:78-79). Written instead as an alternation with a high-byte class, `([a-zA-Z0-9_\-./]\|[\x80-\xff])` (UTF-8 is self-synchronising, so a run of these is whole runes). regexp.zig's own rewrite emits high-byte `\x` classes (regexp.zig:300-330); this exact class is not verified | +| leftmost-longest | clickmatch's choice of span | approximated: the first match from each offset, greedy. A click inside a run of file characters finds that run in every stock rule | +| `$1`–`$9` submatches | `arg isfile $1`, `attr add addr=$3`, `man $2 $1` | **no**: mvzr has no capture groups (README.md:77). Phase 1 refuses a `$1`–`$9` outside quotes at parse, in words (Q1). The defaults need none (§5.2). | +| `{m,n}` | nowhere in Plan 9 | mvzr has it (README.md:52): pardes's rules may use it, and the default hash rule does | + +### 3.4 Ports + +- **One comptime table in Plumb.zig names the ports pardes reads itself.** + pardes is always one of their readers, as acme always reads `edit`. + - `edit`: opens the data as Look opens a name. It takes a file, a directory or + a kind's file by extension, at the place written after it or given as + `addr=`. With `action=showdata` it shows the data. With `action=showdiff` + it shows the data stacked as a +Diff (§5.4). + - From the look that sent the message, in the same step, the handler runs + lookAt's final switch on the target Look already resolved. That is no + second resolution, and the same code as today. + - From anyone else (`plumb/send`), the handler resolves the data itself, + joined to the message's wdir when the data is relative. + - `web`: the host's link opener (`open_link`, at most 256 bytes as today, + look.zig:1601). + - every loaded kind by its name (`image`, `pdf`): the file opened in that + kind. While the kind is not loaded nobody reads its port, so Plan 9's rules + apply: `start`/`client` run, or the send fails and Look falls back to its + own look. That is today's "a kind gone since is passed over". +- **Every other port is a file that external programs read** (§4.1). If a rule + names `edit` or `web`, an external reader of it gets a copy too (Plan 9's + fan-out). Diverting a message is done with a rule, not by holding the port. +- **Whether a port has an external reader** is the authority's 9P state. + - The matcher asks it through `tape.authority` as a bool, the way mouse.zig + asks whether a pane's events are read (mouse.zig:1024-1044). + - A speculation guesses the last answer, and the unit confirms it or rolls it + back (tape.zig:884-901). + - Queues live in `p.fs`, which is authority-only (Core.zig:416). A push to a + port with no opens does nothing, as events.noteAction returns when nobody + reads (ninep/events.zig:602-611). + +### 3.5 `plumb start`, and a compiled-in word as what is started + +- **What it runs.** `plumb start ` expands its arguments (§1.2) and runs + them as pardes's exec runs a line from the message's pane, `exec.execute` + (exec.zig:651-722): + - A builtin or a kind's word runs in place, through executeBuiltinLine + (exec.zig:870-906). So `plumb start Diff $file` runs the compiled-in + stacker. + - Any other line is a command pane in the message's wdir. That is the pane's + directory for a look. For a `plumb/send` with another wdir, runCommand takes + an override field, as it takes `exec_column` (exec.zig:752). + - Each expanded word goes to `$SHELL -c` single-quoted, so a word stays one + argument whatever it holds. This is Plan 9's argv exec (match.c:346-364) + spoken to pardes's exec, which runs lines through a shell. A rule that wants + a pipe writes `plumb start sh -c '…'`, as Plan 9's write `rc -c '…'`. + - Plan 9's start is detached and windowless, and Q4 asks whether to keep that. + pardes's exec is already acme's, and nothing in the defaults starts a + program. +- **A started word may decline.** + - `Ctx` gains `plumbed: bool`. A word started by the plumber that cannot do + what the message asks (Diff on a file with no hunk, Diff on a revision + outside a git work tree) sets `p.plumb_declined` and says nothing. + - The plumber then fails the send. Look falls back to its own look, as acme + does when the plumber's write fails (§1.4). + - Any other failure of a started word is the word's, said as usual. Plan 9's + sender never hears of a start that fails later. +- **`Diff` gains an argument** (builtins.zig:1092-1103): + - `Diff ` stacks that file's hunks. It reads the file at a taped + `.read_file` site and calls Output.openDiff (Output.zig:491), which is + today's look.zig:1627-1631 moved. + - `Diff ` (7 to 40 lowercase hex digits with a letter and a digit, the + old isCommitHash) finds `.git` above the pane's directory and runs + `git show ` paged: lookCommit, look.zig:1118-1131, moved whole with its + `command_pages`. + - Bare `Diff` is as today. + - A diff pane is needed only when Diff is bare: the `needs` check at + exec.zig:985 applies to the bare form. +- **`plumb client `** is `start` plus a hold. The message waits, bounded, + in the port's hold list and goes to the port's first opener (Plan 9's + queueheld). Rules in the defaults never use it. Two uses it gives: + - a helper started on demand; + - `plumb client Addon load image`, holding the message until the kind + registers and pardes starts reading its port. + +## 4. The surface + +### 4.1 The 9P files + +`plumb/` is a new top directory. It needs `TopFile.plumb` (tree.zig:230-289; the +u5 enum has 6 values free) and a third node family beside panes and columns for +the ports, with a bit as `col_bit` has (tree.zig:367). + +| file | mode | read | write | +|---|---|---|---| +| `plumb/rules` | 0666 | the rules in force: variables, port declarations, rule sets, as printrules prints them | appends rule text. Complete sets (ended by a blank line) are parsed at each write, the rest at release. A parse error fails that write with the line number and Plan 9's words. An open with OTRUNC (`> plumb/rules`) clears the rules first. One writer at a time: `file in use` (tree.zig:62) | +| `plumb/send` | 0222 | — | a message in the text form of §1.1, assembled across writes. Answered when it is matched and disposed. The error words are Plan 9's: `bad plumb message format`, `no matching plumb rule`, `couldn't find destination for message`, `no start action for plumb message`, `no port for "client" rule`, `empty argument list` (fsys.c:147-156, match.c:450-460) | +| `plumb/` | 0444 | one message a read, packed. A short read takes the front of a message and the next read the rest, as the event file does (events.zig:104-115). A read with nothing waiting is held (`.again`, Open.held, tree.zig:165-172). Messages sent before the open are not this open's; a release drops what the open did not read | — | + +- **Opens.** A port open is an `Open.what` of its own holding a bounded queue: an + `events.Queue`, 64 KiB, oldest dropped (events.zig:21-60). A message bigger + than the queue is not delivered to that reader, and the log gets an `err` + saying so. +- **readdir order** is Plan 9's: `rules`, `send`, then the ports in the order + rules named them. +- **Reserved port names**: `.`, `..` and `send` (Plan 9's badports, + rules.c:38-44), plus `rules`, which Plan 9 forgets. +- **Wake-ups.** `plumb/send` and `plumb/rules` writes go through `needsQuiet`, as + every write does (tree.zig:82-90). A held port read is answered by the + listener when `p.fs.news` is set, as event reads are. + +### 4.2 The `Plumb` word + +The one-line form is replaced. + +- **Bare `Plumb`** opens the user's `plumbing` file in the configuration + directory, beside `init`, as `Config` opens init (builtins.zig:1338-1360). + - If the file is not there yet, the pane holds `include basic`, which Save + makes. That is plan9port's initial.plumbing, less the editor variable. + - Saving the file replaces the rules, through the same hook that applies a + saved init (host_io.zig:3006). It is `cp lib/plumbing /mnt/plumb/rules` + done for you (plumb.ms:784-787). A parse error is said with its line, and + the rules stay as they were. +- **`Plumb `** is refused in words: "Plumb takes no rule now: rules are + plumb(6) rule sets, in /plumbing (Plumb opens it) or written to + plumb/rules". An old init line `Plumb suffix .svg to image` is said the same + way, as an init line that fails is (exec.zig:941-954). The user's init has + none. Q3 asks whether a one-line form stays. +- **Converting an old rule by hand.** `suffix .svg to image` becomes: + +``` +type is text +data matches '.*\.([sS][vV][gG])' +arg isfile $data +plumb to image +``` + +### 4.3 Where the default rules live + +- **Location.** `src/plumbing`, the default rules file, compiled in with + `@embedFile`. `include basic` names it, as Plan 9's `include basic` names + `/lib/plumb/basic`. +- **Other includes.** Any other relative include is read from the configuration + directory, and an absolute one from where it says. Both are taped `.read_file` + sites, read only when rules are written. +- **Boot.** pardes reads `/plumbing` the way it reads init: main.zig + puts it in Options beside `startup_config` (main.zig:725-728). Without the + file, the rules are `include basic`, so `Pardes.init` in every test has the + defaults. +- **Where it is shown.** + - `plumb/rules`; + - the `Plumb` pane (after `include basic`, the flattened rules are in + `plumb/rules`); + - the reference, which quotes `src/plumbing` whole (§6). + +## 5. Look after the plumber + +### 5.1 The order + +1. **The pane's own readings**, unchanged: + - an event reader takes the look first (mouse.zig:1034, acme's look.c:98); + - History, Recent, a diff line, a command word (§2.2 rows 1-4); + - the sender's expansion (row 5); + - the zero column (row 6); + - `file:/re/` and `:addr` (rows 7-8). lookAddress calls lookAt on the path, + which plumbs it, so `x.diff:/re/` behaves as today. +2. **resolveLookTarget** as today, minus the user's rules (row 11), which are + gone from `resolve`. A `.pane` result (a name open in a pane, or `@p`) is + focused as today and never plumbed. This is not acme's order (Q2). +3. **The plumber**, with this message: + - `src`: `pardes`; `term` when the look came from a terminal in raw mode and + not over 9P (the condition at look.zig:1090); the kind's name in a kind's + pane; + - `dst`: empty; + - `wdir`: Pardes.paneDir; + - `type`: `text`; + - `attr`: empty, so no click in phase 2 (§7); + - `data`: the trimmed name reading (look.zig:1540). + + Skipped when `p.look_text` is set. That flag now means "a look that opens as + text, unplumbed": showDiffText and Edit's `B` (Output.zig:532, + edit_cmd.zig:100). +4. **If the send failed**, lookAt's switch runs on the target from step 2, as + today, minus the hooks that became rules: + - the `.url` arm becomes lookUnresolved, since acme's own look opens no URL; + - the `.diff` hook goes from the `.file` arm; + - lookCommit goes from lookUnresolved. + +### 5.2 The default rule file (`src/plumbing`), in full + +``` +# pardes's plumbing rules, in plumb(6)'s language. The first rule set +# whose patterns all hold takes the message; one that none takes is +# Look's own (a file or directory opened, else the word searched for). +# A look sends what it looks at: type text, src pardes (term from a +# terminal's raw mode, a kind's name from its pane), wdir its pane's +# directory, data the name as Look reads it. + +# urls go to the web browser (the host's: xdg-open, open on macOS) +type is text +data matches 'https?://.*' +plumb to web + +# a diff or patch looked at bare is stacked in a +Diff; one with no +# hunk in it opens as text +type is text +data matches '.*\.(diff|patch)' +arg isfile $data +plumb start Diff $file + +# existing directories, and existing files at the place written after +# them, go to the editor; a file a kind shows (a picture, a PDF) to +# that kind +type is text +arg isdir $data +plumb to edit + +type is text +arg isfile $data +plumb to edit + +# a commit hash looked at in the editor, in a git work tree: git show, +# stacked in a +Diff (outside one, Diff declines and the word is +# searched for) +type is text +src is pardes +data matches '[0-9a-f]{7,40}' +data matches '[0-9a-f]*[0-9][0-9a-f]*' +data matches '[0-9a-f]*[a-f][0-9a-f]*' +plumb start Diff $0 + +# a diff paged (git show, git log -p) is shown stacked in a +Diff in +# its +Pager's place +type is text/x-diff +attr delete action +attr add action=showdiff +plumb to edit +``` + +**Why each rule matches today's code byte for byte:** + +- **web.** Today it is `startsWith(trimmed, "http://" | "https://")` + (look.zig:263-265). The rule is a whole match of `https?://.*` over the same + `trimmed`. It runs after the open-pane check, as today's URL test does, and + needs no disk site, so a replica speculates it fully as today. The handler + keeps the 256-byte cap. +- **diff/patch.** Today the hook is: target `.file`, no line given, not + `look_text`, and the path ends in `.diff` or `.patch` (look.zig:1625-1626). + - In the rule: a data that ends so and has no `:N` (the whole match fails on + `x.diff:12`); isfile, which is a file and not a directory, found where Look + finds it; `look_text` skips the plumber; and an open pane was focused + already in step 2. + - No hunk: Diff declines (§3.5), so Look opens the file as text, which is + today's fall-through (:1632). + - **One difference**: a symlink not named `.diff` that resolves to a `.diff` + file is stacked today (the test is on the resolved path) and opens as text + after. Plan 9 cannot test `$file` by pattern without a permanent + `data set`. Accepted. +- **edit, two sets.** They make the hash rule come after file and directory + resolution, as lookCommit came after it (look.zig:1092 is inside + lookUnresolved). The handler is today's switch on today's target. +- **hash.** Today: the whole `trimmed` is 7-40 lowercase hex with a digit and a + letter (isCommitHash), the pane is no kind's and not in raw mode + (look.zig:1090), `.git` is above the pane's directory, and git show runs from + that pane. + - The rule tests the same, with `src is pardes` covering the pane test. + - `Diff ` does the `.git` walk, the exec and the paging exactly as + lookCommit did. + - Outside a work tree, Diff declines, so Look's search runs as today. +- **paged diff.** The pager's send (§5.4) carries `type text/x-diff` exactly when + File.looksLikeDiff said so (File.zig:752: today's `pager_diff`). The edit + port's `showdiff` is today's restack code (ctl.zig:724-730) moved. + - The code's `attr delete` fails when the attribute is absent (match.c:258), + and the pager always sets `action`. + - Without this rule, the explicit dst `edit` delivers the message unchanged + and the +Pager stays as text. + +**What is deliberately not a rule:** directories in Plan 9's sense (acme's +openfile handles them, and so does pardes's `edit`), kinds by extension (the +`edit` port's choice of pane, so that today's `Addon load` of a new kind needs +no rule), Incl, `@p`, addresses, and the search. + +### 5.3 What changes for a user + +- **Rules now see a look before any of pardes's own decisions** except steps 1 + and 2. Today the user's rules came after the `@p` and open-pane checks too, + so that part is unchanged. +- **A rule to a port no one reads is no longer refused at write.** Plan 9 never + refuses it (test/behaviour/addons.zig:199-200 changes). +- **The hover, the n/N walk and the lookable span** no longer see the user's + rules. Today they did, through `resolve` (look.zig:133-153, :227). That is + deferred (§7). No user rule exists. + +### 5.4 The pager as a sender (acme's `plumb -i … action=showdata`) + +- **Today.** `pardes -` writes a directory to `/pager`, which makes the +Pager, + and then the text. fillPager fills the pane and, for a diff, stacks it and + closes the +Pager (ctl.zig:705-731). +- **After.** fillPager fills the pane as today, then sends: + - `src pager`; + - `dst edit`; + - `wdir` the +Pager's directory; + - `type text/x-diff` when the text is a diff, else `text`; + - `attr action=showdata filename=`; + - the text as data. +- **The `edit` port's actions.** + - `showdata`: nothing more, since the +Pager is shown. + - `showdiff`: today's restack. It opens a +Diff from the pane `filename` + names, closes the +Pager and keeps the keyboard where it was. +- **The look rules do not see this message.** They all say `type is text`, and + an expansion of `$data` past 4 KiB fails (§3.2). +- **External readers of `plumb/edit`** get the paged text when it fits their + queue. + +## 6. One definition, several sinks + +| the one definition | its sinks | +|---|---| +| `src/plumbing` (embedded) | `include basic`; the boot rules; the reference's plumber section, which quotes the file. Typst reading `src/` from docs/typ is not verified; otherwise build.zig copies it next to the generated builtins JSON | +| `Plumb.text` (the rules in force) | `plumb/rules`; the `Plumb` pane's file after a save; a dump | +| Plumb.zig's table of pardes's own ports, each with a line saying what it does | `plumb/` readdir (with the ports rules named); the reference's port table; fs-help.txt's `plumb/` line (one line, as every directory has there, src/fs-help.txt:20-23) | +| Plumb.zig's error words (Plan 9's) | `plumb/send` and `plumb/rules` write errors; the `Plumb` pane's save error; the reference | +| the message's text form (one pack, one unpack in Plumb.zig) | `plumb/send`, the ports, a later `pardes plumb [-s src] [-d dst] [-w wdir] [-t type] [-a attr] -i \| data…` (plumb(1); PLAN.md §7 C+L's `fs write` over the tree) | + +## 7. Phases + +Each phase lands alone. Sizes are estimates from reading, as lines of code plus +lines of tests. + +**Phase 1: the language and the files.** About 450 + 300. +- What it builds: + - Plumb.zig: pack and unpack; parse, print, variables and include; expand; + match, including click; dispose to `start` and to pardes's own ports; + - `src/plumbing`; + - `plumb/rules` and `plumb/send` in the tree; + - the field `Core.plumber`. +- Nothing calls the plumber from Look yet. External ports answer `no such plumb + port` on open. +- **Gates.** Tests at the end of Plumb.zig: + - every parse error in Plan 9's words; + - a print/parse round trip; + - plan9port's basic, with its `¡-￿` classes rewritten and its `$1`/`$3` rule + sets dropped, parses; + - whole match and click match, each with Plan 9's `horse.gift` case; + - rc quoting; + - `attr delete` of an absent attribute fails; + - dst/port filtering; + - a dump keeps the rules. +- One T1 behaviour test writes `plumb/rules` and reads it back, then sends a + message to `web` and sees `open_link` recorded (`p.fallback.setLink`, + host_io.zig:314). +- Known base failures as RULES.md lists them. + +**Phase 2: Look sends.** About 120 + 100. look.zig loses about 150 lines: +- Port, plumbRuleError, plumbTarget, the rules block, lookCommit, + isCommitHash and the `.diff` hook go; +- the sender comes in. +- What else changes: + - Diff takes an argument and declines; + - `Plumb` is rewritten as in §4.2; + - the hover keeps `resolve`. +- **Gates**, all unchanged byte for byte: + - look.zig's 28 tests, with the Plumb test at :2688 rewritten onto + `plumb/rules`; + - hunks.zig:718 (`.patch` look, Diff to text and back) and :808 (pagers by + commit); + - test/behaviour/look_and_exec.zig (36 tests), addresses.zig (7), mouse.zig, + event.zig; + - addons.zig:188, rewritten to a rule in plumb/rules: same panes; + - process goldens look-center, look-file, look-file-1col, lookloaded, + lookpanes, lookrange, diffview, dirpane (test/process/tty_editing.zig), + ttylook and look-fd-deep (tty_terminals.zig), pagercolor (tty_themes.zig). +- New tests: + - a hash looked at inside and outside a git work tree, so lookCommit's path + gets the end-to-end test it never had; + - a URL with the web rule removed is searched for. +- **Replica gate** (this step changes which sites a look reads): + - test/replicas.zig gains a look at a `.patch`, at a URL and at a hash on the + authority, with digests equal. These are diff-module.md R2.1's missing + cases (a)-(c). + - A speculated URL look is confirmed with no rollback. + - The real-use soak, tty and window, local and on the box, as + replica-soak-gate asks. + +**Phase 3: external ports.** About 120 + 80. +- What it builds: + - per-open queues, held reads, fan-out, `client` holds; + - the `tape.authority` question "is this port read". +- **Gates:** + - a T1 test with two opens of `plumb/edit` sees one look's message each, an + open made after the send sees none, and a `client` message reaches the + first opener; + - monkey9p.zig gains the `plumb/` files; + - a replica speculating a look whose rule names an external port is + confirmed. + +**Phase 4: the pager sends.** About 40 + 30. +- What it builds: fillPager's send, and the `edit` port's `showdata`/`showdiff`. +- **Gates:** + - pagercolor; + - hunks.zig:808; + - a test that removes the paged-diff rule and keeps the +Pager; + - a soak task paging `git show`, which is diff-module.md R2.1 (c). + +**Deferred, and why:** +- **The click attribute from Look** (acme's whitespace-delimited word plus + `click`). Look's own expansion (config.isFileChar, look.zig:318-325) would + give way to the rules' `matches`, and every click golden would move. Plan 9 + fidelity says yes one day. Byte-identity says not with the plumber's first + landing. `plumb/send` honours `click` from phase 1, for external senders. +- **The hover asking the matcher**, as a dry run without dispose. It would put a + rule set's regexes in the per-frame hover path; measure first. +- **`$1`–`$9`**, unless Q1 decides otherwise. +- **`pardes plumb`** and `pardes -` as `plumb -i -d edit`. These wait for the + CLI work (PLAN.md §7 C+L). +- **Types other than text.** Plan 9 never did them (plumb(6) :49-51). + +## 8. Questions only the user can answer, and what was decided + +Decided 2026-11-17 by the coordinator, the user asked where marked: + +1. **Submatches: (a).** `$1`–`$9` are refused in words at parse: the regex + library has no capture groups, and the user's standing rule is never to + write or vendor a regex engine. Rules use `$0` and several `matches`. The + user has been asked whether they want more. +2. **An open pane first: (a).** A name already open in a pane is focused + before the rules run, as today, so every existing look test and golden + stays byte-identical. +3. **The `Plumb` word: (a).** Bare, it opens `/plumbing` as `Config` + opens the init; Save applies it; an argument is refused in words. Without + that file the rules are `include basic`, the embedded `src/plumbing`. +4. **`plumb start` of a program: (a).** It runs as pardes's exec does: a + builtin in place, a command as a command does today. The user has been + asked whether a started program should run detached with no pane, as Plan + 9's does; the place where that is decided is one spot (Plumb.zig's + `start`). + +The options as round 1 put them: + + +1. **Submatches (`$1`–`$9`).** mvzr has no capture groups, and writing a regex + engine is ruled out. + - (a) **Refuse them in words, and write rules with `$0`, several `matches` + and isfile reading a name past its address.** Shell splitting is the + escape hatch: `plumb start sh -c '…' $0`. The defaults need nothing more. + *Leaning (a).* + - (b) Recover top-level groups by testing candidate splits with anchored + whole matches of each group's sub-pattern. That is about 100 lines and no + engine, but the spans are approximate where Plan 9's leftmost-longest + would choose otherwise. More of plan9port's basic would paste in as is. +2. **Does a name open in a pane come before the rules?** + - (a) **Yes, as today and as today's `Plumb` rules see it.** A `.diff` + already open as text is focused, not restacked. *Leaning (a): byte-identity, + and acme has only one window per file to find anyway.* + - (b) acme's order: the rules first, and the `edit` port finds the open + pane. A user rule then wins over an open pane, and looking again at an open + `.diff` stacks it again. +3. **The `Plumb` word.** + - (a) **Bare `Plumb` opens `/plumbing`, Save applies it, and an + argument is refused.** *Leaning (a): Plan 9 keeps rules in a file, and a + rule set is several lines.* + - (b) Also keep a one-line `Plumb ` for tags and init, its lines + separated by `;`. But `;` is in Plan 9's `$addr` regexes, so this needs an + escape. + - (c) Remove the word, so rules live only in the file and in `plumb/rules`. +4. **`plumb start` of a program.** + - (a) **A command pane in wdir, as pardes's exec.** Its output and exit + status show, and the defaults start only words. *Leaning (a).* + - (b) Plan 9's: a detached child, with no pane, stdin `/dev/null`, and output + discarded or logged as an `err`. That is closer to plan9port's rules (`web + $0`, `9 page $file`), at the cost of a host effect generalising + `open_link`. + +## Not verified + +- **Nothing was built or run.** All sizes are estimates, and the test counts are + greps. +- **mvzr.** + - Whether one mvzr class may mix ASCII and high bytes, and that + `[\x80-\xff]` compiles. regexp.zig emits similar `\x` classes; this one was + not tried. + - The cost of compiling the rules' regexes on every send, and the size of a + compiled `Regex`. +- **Dumps and boot.** + - How walk.Load treats the removed `plumb` field of an old dump. + - Whether the init-file reapply call at host_io.zig:3006 is a taped input. + - Whether Typst can read `src/plumbing` from docs/typ. +- **Replicas.** That a replica's pushes to its own `p.fs` port queues are + harmless. That is assumed from events.noteAction's pattern; replica.zig was + not read for it. +- **Behaviour** read in the code but never run: + - git paging into a +Pager under `command_pages` (host_io.zig:2103-2107); + - the exec `needs` check for Diff with an argument (exec.zig:985). +- **Sources.** + - plan9port's acme was read for acme's side (look.c, acme.c). principia's + acme (editors/acme) was not, nor libplumb's event.c or plumb.c. + - The `¡-￿` range in the principia rule files was read through `cat`, as + UTF-8. +- **The symlinked-`.diff` difference** (§5.2) is the only behaviour difference + found. Others may exist in paths no test covers. -- cgit v1.3 From d7b3d57ed0ba649f01559356fbf2bf89561990ca Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 17 Nov 2026 00:35:08 -0300 Subject: rows: a pane's rows from outside, one definition and two sinks: File.setRows is the one writer of a pane's rows (locations.Row, the stored form as it was: digest, dump and blobs unchanged), refusing what its text cannot hold (more rows than lines, an offset or styles past a line's end) and keeping the painting of equal rows; Output.fillRows keeps what is the editor's (the pane, its refill identity, the steps) and hands its rows to it, as the query panes' three writers do; locations.formatRows and parseRows are its text, a line a row, fields a blank apart and the path last (kind m c p with d and u, line col end_line end_col source_column location_end code_start, styles as `-` or `N:start+len=role,...` a role a syntax class and grounds joined by dots); each pane directory over 9P has `rows`, read as that text (+Search's, +Callstack's addresses as data) and written whole lines at a time, at 0 replacing and later following (a line cut by a mount waits for its open's next write; tree.writeLines passes a line on at the offset it was begun at), `>` emptying them; tests: the rows of a +Search, a +Callstack and a +Diff read back from their text equal, byte for byte, and the file read, written whole and across writes, refused and emptied; README, reference and changelog say so Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- docs/typ/reference.typ | 1 + src/CHANGELOG.md | 10 +++ src/File.zig | 23 +++++++ src/Output.zig | 17 ++--- src/Query.zig | 35 +++------- src/fs-help.txt | 4 +- src/locations.zig | 176 +++++++++++++++++++++++++++++++++++++++++++++++++ src/ninep/pane.zig | 93 +++++++++++++++++++++++++- src/ninep/pty.zig | 4 +- src/ninep/tree.zig | 14 ++-- 10 files changed, 331 insertions(+), 46 deletions(-) diff --git a/docs/typ/reference.typ b/docs/typ/reference.typ index 7360179f..637d9c72 100644 --- a/docs/typ/reference.typ +++ b/docs/typ/reference.typ @@ -64,6 +64,7 @@ pane/ the panes @pa look a #word("Look") at this pane @look-and-exec exec an #word("Exec") at this pane @look-and-exec tagexec a word clicked in this pane's tag @look-and-exec + rows a line a row: where it points, how it is coloured (README) @panes pty/ terminals only @pty ctl winsize, sig, exec @pty status cols rows busy @pty diff --git a/src/CHANGELOG.md b/src/CHANGELOG.md index da489b82..a64de8e1 100644 --- a/src/CHANGELOG.md +++ b/src/CHANGELOG.md @@ -2,6 +2,16 @@ ## Unreleased +- Each pane's directory over 9P has a `rows` file: a line a body row of a + results pane (+Search, +Callstack, +Diff, a language server's list), + where it points (`path`, line, column, the address's end, where its code + starts) and how it is coloured (runs of `keyword`, `string`, ... and the + grounds `add`, `del`, `emph`, `line`), so a 9P client reads their + addresses as data, not by parsing the text. A write at offset 0 replaces + a pane's rows, a later one adds to them; rows its text cannot hold are + refused. An edit drops them, as before. The editor's own producers set + rows the same one way. + - A drag draws no guide lines: no dashes where a pane or column would land, no rail for a carried column, no dashed seam under a pane rule held. The line between two columns no longer resizes them (nor, at a diff --git a/src/File.zig b/src/File.zig index 1988fb89..84e88dff 100644 --- a/src/File.zig +++ b/src/File.zig @@ -660,6 +660,29 @@ pub fn setContent(p: *Pardes, f: *State, new: []u8) void { setContentSpan(p, f, new, null); } +/// `rows`, a row a line of the text from its first (where each points, how +/// it is coloured: locations.Row), made the pane's, taken: the one way a +/// pane's rows are set, by a producer in the editor (Output.fillRows, a +/// query pane) or from outside (the pane's `rows` file). RowsMismatch, the +/// rows still the caller's, for rows the text cannot hold: more of them +/// than it has lines, or an offset or styles past its line's end. Rows +/// equal to the pane's keep its painting; others drop it, to be painted +/// from them. An edit of the text drops them (setContentSpan). +pub fn setRows(p: *Pardes, f: *State, rows: []locations.Row) error{RowsMismatch}!void { + var lines = std.mem.splitScalar(u8, f.content, '\n'); + for (rows) |row| { + const line = lines.next() orelse return error.RowsMismatch; + if (row.location_end > line.len or row.code_start > line.len or row.colors.len > line.len - row.code_start) return error.RowsMismatch; + } + if (locations.equalRows(f.location_rows, rows)) return locations.freeRows(p.gpa, rows); + locations.freeRows(p.gpa, f.location_rows); + f.location_rows = rows; + if (f.highlights.len > 0) p.tree_sitter_gpa.free(f.highlights); + f.highlights = &.{}; + f.highlight_start = 0; + f.syntax_dirty = true; +} + /// `setContent` for a splice that knows what it left alone at either end, /// so it is not found again by comparing the whole text. The edit is what /// lies between them, made by `edit`, which takes `new`, a whole text its diff --git a/src/Output.zig b/src/Output.zig index 5bad7ab7..3bcc3fa5 100644 --- a/src/Output.zig +++ b/src/Output.zig @@ -452,16 +452,10 @@ pub fn fillRows(p: *Pardes, id: usize, dir: []const u8, from: Origin, name: ?[]c File.setContent(p, rf, result_content); resetBody(p, rp); } - if (locations.equalRows(rf.location_rows, result_rows)) { + File.setRows(p, rf, result_rows) catch |err| { 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.reportError(id, "rows", err); + }; p.view().active = id; if (traits(from).steps) { pane.search_pane = i; @@ -478,7 +472,10 @@ pub fn fillRows(p: *Pardes, id: usize, dir: []const u8, from: Origin, name: ?[]c p.gpa.free(np.file.?.path); np.file.?.path = owned; } - np.file.?.location_rows = result_rows; + File.setRows(p, &np.file.?, result_rows) catch |err| { + locations.freeRows(p.gpa, result_rows); + p.reportError(id, "rows", err); + }; layout.placeNew(p, id, id, free, .doc); p.view().active = id; if (traits(from).steps) { diff --git a/src/Query.zig b/src/Query.zig index caf64d54..c1a89164 100644 --- a/src/Query.zig +++ b/src/Query.zig @@ -859,19 +859,14 @@ fn setRows(p: *Pardes, rp: *Pane, out: *std.ArrayList(u8), rows: *std.ArrayList( 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; - dropHighlights(p, f); - } } else { File.setContent(p, f, content); - locations.freeRows(p.gpa, f.location_rows); - f.location_rows = meta; f.saved_revision = f.revision; } + File.setRows(p, f, meta) catch |err| { + locations.freeRows(p.gpa, meta); + if (p.paneBySerial(rp.serial)) |id| p.reportError(id, "rows", err); + }; if (f.pager_spans.len > 0) p.gpa.free(f.pager_spans); f.pager_spans = &.{}; // The cursor stays where it was typing; on a row that went, the last. @@ -996,24 +991,10 @@ pub fn recolor(p: *Pardes) void { fresh = rows; @memcpy(rows[i].colors[0..got.len], got); } - if (fresh) |rows| { - locations.freeRows(p.gpa, f.location_rows); - f.location_rows = rows; - dropHighlights(p, f); - } + if (fresh) |rows| File.setRows(p, f, rows) catch locations.freeRows(p.gpa, rows); } } -/// The pane's painted colours let go, so the next frame paints them from -/// its rows again: with its text the same, a frame would keep the old ones -/// (refreshHighlights keeps a painting that covers the view). -fn dropHighlights(p: *Pardes, f: *File.State) void { - if (f.highlights.len > 0) p.tree_sitter_gpa.free(f.highlights); - f.highlights = &.{}; - f.highlight_start = 0; - f.syntax_dirty = true; -} - /// 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 { @@ -1910,8 +1891,10 @@ pub fn cancel(p: *Pardes, id: usize) void { } const f = &rp.file.?; File.setContent(p, f, s.content); - locations.freeRows(p.gpa, f.location_rows); - f.location_rows = s.rows; + File.setRows(p, f, s.rows) catch |err| { + locations.freeRows(p.gpa, s.rows); + p.reportError(id, "query", err); + }; p.gpa.free(q.asked); q.asked = s.asked; q.source = s.source; diff --git a/src/fs-help.txt b/src/fs-help.txt index bc699418..e6a48491 100644 --- a/src/fs-help.txt +++ b/src/fs-help.txt @@ -20,12 +20,12 @@ dumps the dumps the state file keeps, the newest first: