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 --- 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 +++++++---------------- 8 files changed, 96 insertions(+), 740 deletions(-) delete mode 100644 test/snapshots/cornerdrag-left.golden delete mode 100644 test/snapshots/cornerdrag.golden (limited to 'test') 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 (limited to 'test') 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 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(+) (limited to 'test') 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 65612a1cc13dd2a7e866f88176dbf6db5dd83467 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 17 Nov 2026 00:41:40 -0300 Subject: plumber: Plan 9's plumber in the core, its language and its files (docs/next-plumber.md, phase 1): src/Plumb.zig owns the rules, kept as their text (Core.plumber, digested and dumped; `include basic`'s, the embedded src/plumbing, until any are written, so a session and a dump from before it start with the defaults) and parsed again for each message, and a matcher over them read from rules.c and match.c: the message's pack and unpack (plumbunpackpartial's whole, short of its data, malformed), packed attributes read and quoted rc's way, rule sets of `object verb arg` lines, variables, include (basic, the configuration directory's, an absolute path, through the taped read site), rc's quoting and `$` expansion at parse and at match, every parse refusal in rules.c's words with its file and line, `$1`-`$9` refused in words (the regular expressions have no capture groups), `matches` over regexp.zig whole (`^(...)$`) or around a click counted in runes with Pike's two patterns, `is`, `set` rewriting for good, `add`, `delete` failing on an attribute not there as match.c's code does, `isfile` and `isdir` finding a name as Look does (past its place, the message's directory, a look's jump list's, Incl's) at the taped resolve sites, once a send; dispose to a port pardes reads (edit: opened as a look opens it, at addr=; web: the host's link opener; a loaded kind by its name), to a rule set's start or client run as exec runs a line (a builtin in place, else a command pane in the message's wdir: Core.exec_dir, exec.runCommand's reuse skipping the sender), or Plan 9's words for what went nowhere; rules print back in the order they were written, a variable where it was set, so a printed text reads back the same; plumb/rules (a write adds rule sets as each is whole, the rest at the close, `>` replaces them, one writer at a time) and plumb/send (a message put together across writes) in the tree, with fs-help's line, the reference's section and tree, and the fstree test's paths; nothing calls the plumber from Look yet; test: Plumb.zig's eleven (every parse error, print and read back, plan9port's basic less its submatch rule sets, its ¡-￿ classes UTF-8's bytes, whole and click matches with horse.gift, quoting, a set's rewrite kept, delete of an absent attribute, dst filtering, isfile and isdir, dispose, a dump keeping the rules), test/behaviour/plumber.zig's two through the tree (Session records the link a host would open); the root's listings in tree.zig's and the process tests gain plumb, and the README folds a blank line to stay 45 lines; the changelog says so MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- docs/typ/reference.typ | 48 ++ src/CHANGELOG.md | 11 + src/Core.zig | 9 + src/Plumb.zig | 1241 ++++++++++++++++++++++++++++++++++++++++++++ src/config.zig | 1 + src/exec.zig | 4 +- src/fs-help.txt | 2 +- src/ninep/tree.zig | 130 ++++- src/pardes.zig | 1 + src/plumbing | 23 + test/behaviour.zig | 1 + test/behaviour/plumber.zig | 65 +++ test/process/tree.zig | 2 +- test/session.zig | 3 + 14 files changed, 1518 insertions(+), 23 deletions(-) create mode 100644 src/Plumb.zig create mode 100644 src/plumbing create mode 100644 test/behaviour/plumber.zig (limited to 'test') diff --git a/docs/typ/reference.typ b/docs/typ/reference.typ index 7360179f..d0fdd1dd 100644 --- a/docs/typ/reference.typ +++ b/docs/typ/reference.typ @@ -38,6 +38,9 @@ addons the kinds of pane here, compiled in or an addon's @add layout a line per column, then active @columns-and-tags tag the workspace tag @columns-and-tags tagexec a word clicked in the workspace tag @columns-and-tags +plumb/ the plumber's: plumb(6) rules, and messages sent by them @plumber + rules the rules in force; a write adds rule sets, > replaces them @plumber + send write a message: six header lines, then its data @plumber col/ the columns @columns-and-tags / column ; rmdir closes it when empty @columns-and-tags tag its tag @@ -1015,6 +1018,51 @@ at 200, ending in `…`. Control characters become spaces. synthetic. Linux v9fs's truncation `mtime` hint is accepted and dropped. - #file("/src/") with `-Dembed-sources=true`. += The plumber + +Plan 9's plumber(4), its language plumb(6)'s, in the session: rules +match a message and say where it goes. A #word("Look") does not ask it +yet (the #word("Plumb") rules do, #doc("reference", section: "from-acme")). + +- #file("/plumb/rules") reads the rules in force: rule sets of + `objectverbarg` lines, each set ended by a blank line, a + variable's `name=value` where it was set, an `include`'s rules in its + place. A session starts with `include basic`, pardes's own + (`src/plumbing`): a URL to the `web` port, an existing directory or file + (at the place written after it) to `edit`. A write adds rule sets, each + read as its blank line comes, the rest at the close; `>` replaces them + all. One open writes at a time (`file in use`). Kept in a dump. +- A rule set that does not read is refused at the write it is whole in, + `plumb/rules:: ` in rules.c's words (`unknown verb isnt`, + `ruleset must have patterns and actions`), and the rules stay as they + were. `$1`-`$9` are refused: pardes's regular expressions + (#doc("reference", section: "regexp")) have no submatches; write `$0` + and several `matches`, as Pike's two patterns do. `include basic` is + `src/plumbing`; another name is the configuration directory's file, an + absolute one where it says. +- #file("/plumb/send") takes a message, plumb(6)'s six lines (`src`, + `dst`, `wdir`, `type`, `attr`, the data's length) and then the data, + in one write or several. The write is answered once it has gone where + the first rule set whose patterns hold says, or refused in Plan 9's + words: `bad plumb message format`, `couldn't find destination for + message` (no rule set takes it and it names no port), `no start action + for plumb message`, `no port for "client" rule`. +- The verbs are plumb(6)'s: `is`, `matches` (the whole text; with + `click=N` in `attr`, the run around rune N, and the data cut to it), + `isfile` and `isdir` (a name found as #word("Look") finds one: past the + place written after it, in `wdir`, then #word("Incl")'s directories; + `$file` and `$dir` are where), `set`, `add` and `delete` (`delete` of + an attribute not there fails, as plumber's code does), and the actions + `plumb to `, `plumb start ` and `plumb client `. +- The ports pardes reads itself: `edit` (the data opened as a + #word("Look") opens it, at `addr=` when given), `web` (the host's + browser, a URL of at most 256 bytes) and each loaded kind by its name + (`image`, `pdf`). A message to another port runs its rule set's + `start` or `client`; to a port no rule names it goes nowhere. +- `plumb start` runs its words as #word("Exec") runs a line: a builtin in + place at the pane with the keyboard, anything else a command pane in + the message's `wdir`, each word one argument to the shell. + = Addons An addon is a shared library that brings one kind of pane: a picture, a diff --git a/src/CHANGELOG.md b/src/CHANGELOG.md index da489b82..d4d237f0 100644 --- a/src/CHANGELOG.md +++ b/src/CHANGELOG.md @@ -2,6 +2,17 @@ ## Unreleased +- The plumber, Plan 9's, is in the session: `plumb/rules` holds its + rules in plumb(6)'s language (rule sets of `object verb arg` lines, + variables, `include`, `matches` over the whole text or around a click, + `isfile` and `isdir` finding a name as a look does), and `plumb/send` + takes a message and sends it where they say, to a port pardes reads + (`edit`, `web`, a loaded kind) or to a word or command started, with + Plan 9's words when it cannot. A session starts with `include basic`, + pardes's rules (`src/plumbing`). Kept in a dump. `$1`-`$9` are refused, + the regular expressions having no submatches. A look does not ask it + yet. + - 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/Core.zig b/src/Core.zig index c5187616..9a6e80d4 100644 --- a/src/Core.zig +++ b/src/Core.zig @@ -39,6 +39,7 @@ const Rect = pardes.Rect; const Registers = pardes.Registers; const RowMetrics = pardes.RowMetrics; const Store = @import("Store.zig"); +const Plumb = @import("Plumb.zig"); const Db = pardes.Db; const Stream = pardes.Stream; const Surface = pardes.Surface; @@ -211,6 +212,9 @@ incl: std.ArrayList([]u8) = .empty, /// Plumb's rules, the user's, tried in order before the built-in ones /// (look.resolve), the first to match taking the look. Kept in a dump. plumb: std.ArrayList([]u8) = .empty, +/// The plumber's rules (Plumb.zig): plumb/rules and plumb/send's, the +/// defaults (`include basic`) until something writes others. Kept in a dump. +plumber: Plumb = .{}, /// Zerox's groups of panes on one buffer (File.syncTwins), and the id /// the next takes. twin_groups: std.ArrayList(pardes.panes.File.TwinGroup) = .empty, @@ -227,6 +231,9 @@ next_serial: u32 = 0, /// The column whose tag the running command came from, while it runs: /// the column acme's commands take from their Text's col. exec_column: ?usize = null, +/// The directory a `plumb start`'s command runs in, while it runs +/// (Plumb.run): the message's wdir, which no pane need have. +exec_dir: ?[]const u8 = null, /// Panes made this step that found no room in their column /// (layout.placeNew): closed at the step's end, once whatever made them /// is done with them. @@ -759,6 +766,7 @@ pub fn deinit(p: *Pardes) void { p.incl.deinit(p.gpa); for (p.plumb.items) |rule| p.gpa.free(rule); p.plumb.deinit(p.gpa); + p.plumber.deinit(p.gpa); for (p.twin_groups.items) |group| p.gpa.free(group.path); p.twin_groups.deinit(p.gpa); p.fs.batch.bytes.deinit(p.gpa); @@ -1703,6 +1711,7 @@ fn processDir(buf: *[limits.host_path_cap]u8) ?[]const u8 { /// The directory a word run from pane `id`'s text or tag runs in, or, /// from a header, the session's. pub fn execDir(p: *Pardes, id: usize) []const u8 { + if (p.exec_dir) |dir| return dir; if (p.exec_header) return p.sessionDir(); return paneDir(p.panes[id] orelse return p.sessionDir()); } diff --git a/src/Plumb.zig b/src/Plumb.zig new file mode 100644 index 00000000..57a19b14 --- /dev/null +++ b/src/Plumb.zig @@ -0,0 +1,1241 @@ +//! The plumber (Plan 9's plumber(4), windows/plumb/): the rules, and a +//! message matched against them and sent where they say. The language is +//! plumb(6)'s as rules.c and match.c read it, and its refusals are their +//! words; docs/next-plumber.md is the design. The rules are kept as their +//! text, a step's state as any other (digested, dumped, replicated), and +//! parsed again for each message: a send reads no file, and asks the disk +//! only at `isfile` and `isdir`, through the taped resolve sites Look uses. +const Plumb = @This(); +const std = @import("std"); +const pardes = @import("pardes.zig"); +const fs = @import("fs.zig"); +const look = @import("look.zig"); +const exec = @import("exec.zig"); +const layout = @import("layout.zig"); +const Kind = @import("Kind.zig"); +const Regex = @import("regexp.zig").Regex; +const Pardes = pardes.Pardes; + +/// The rules in force once any were written, as plumb/rules reads them: +/// what `print` makes of them, an include's text in its place, in the +/// order they were written. +text: std.ArrayList(u8) = .empty, +/// Whether rules were written (or cleared): until then the rules in force +/// are `include basic`'s, so a session starts with the defaults, and so +/// does a dump made before the plumber. +written: bool = false, + +/// The default rules, which `include basic` names, as Plan 9's names +/// /lib/plumb/basic. +pub const basic = @embedFile("plumbing"); + +/// The most rule text kept (Plan 9's whole basic is about 4 KiB), variables +/// and ports, as Plan 9's NDIR less its fixed files; deeper includes, as +/// rules.c's pushinput. +pub const max_text = 64 * 1024; +const max_vars = 32; +const max_ports = 32; +const max_depth = 10; + +/// fsys.c's and match.c's words for a message that went nowhere. +pub const e_bad_msg = "bad plumb message format"; +pub const e_no_port = "couldn't find destination for message"; +pub const e_no_start = "no start action for plumb message"; +pub const e_client = "no port for \"client\" rule"; +pub const e_empty = "empty argument list"; + +pub fn deinit(pl: *Plumb, gpa: std.mem.Allocator) void { + pl.text.deinit(gpa); +} + +// ---- the message ---- + +/// A plumb message (plumb.h, plumb(6)): six lines of header, then `data`. +pub const Msg = struct { + src: []const u8 = "", + dst: []const u8 = "", + wdir: []const u8 = "", + type: []const u8 = "", + /// `name=value` pairs, blank-separated, as they are packed: a value + /// holding a blank, a quote, `=` or a tab quoted rc's way. + attr: []const u8 = "", + data: []const u8 = "", + + /// plumbpack: the header lines, the data's length, the data. + pub fn pack(m: Msg, w: *std.Io.Writer) std.Io.Writer.Error!void { + try w.print("{s}\n{s}\n{s}\n{s}\n{s}\n{d}\n{s}", .{ m.src, m.dst, m.wdir, m.type, m.attr, m.data.len, m.data }); + } +}; + +/// plumbunpackpartial: a whole message, `more` bytes of its data still to +/// come, or one malformed (a header line short, a count the data passes). +pub const Unpacked = union(enum) { msg: Msg, more: usize, bad }; + +pub fn unpack(bytes: []const u8) Unpacked { + var lines: [6][]const u8 = undefined; + var at: usize = 0; + for (&lines) |*line| { + const nl = std.mem.indexOfScalarPos(u8, bytes, at, '\n') orelse return .bad; + line.* = bytes[at..nl]; + at = nl + 1; + } + // atoi's: digits after blanks, else 0. + const count = std.mem.trimStart(u8, lines[5], " \t"); + var n: usize = 0; + for (count) |c| { + if (c < '0' or c > '9') break; + n = std.math.mul(usize, n, 10) catch return .bad; + n = std.math.add(usize, n, c - '0') catch return .bad; + } + const rest = bytes.len - at; + if (n > rest) return .{ .more = n - rest }; + if (n < rest) return .bad; + return .{ .msg = .{ .src = lines[0], .dst = lines[1], .wdir = lines[2], .type = lines[3], .attr = lines[4], .data = bytes[at..] } }; +} + +/// One `name=value` of packed attributes, its value unquoted. +const Attr = struct { name: []const u8, value: []const u8 }; + +/// The attribute at `at.*` in `attr`, read as plumbunpackattr reads it, +/// its value unquoted into `buf`; null at their end, or at one with no +/// `=`, where Plan 9 stops. +fn nextAttr(attr: []const u8, at: *usize, buf: *[4096]u8) ?Attr { + var i = at.*; + while (i < attr.len and (attr[i] == ' ' or attr[i] == '\t')) i += 1; + if (i >= attr.len or attr[i] == '\n') return null; + const start = i; + while (i < attr.len and attr[i] != '=' and attr[i] != ' ' and attr[i] != '\t' and attr[i] != '\n') i += 1; + if (i >= attr.len or attr[i] != '=') return null; + const name = attr[start..i]; + i += 1; + var n: usize = 0; + var quoting = false; + while (i < attr.len and attr[i] != '\n' and n < buf.len) { + const c = attr[i]; + i += 1; + if (c == '\'') { + if (!quoting) { + quoting = true; + continue; + } + if (i < attr.len and attr[i] == '\'') { + i += 1; + } else { + quoting = false; + continue; + } + } else if (!quoting and (c == ' ' or c == '\t')) break; + buf[n] = c; + n += 1; + } + at.* = i; + return .{ .name = name, .value = buf[0..n] }; +} + +/// plumblookup: the first attribute named `name`'s value. +fn attrValue(attr: []const u8, name: []const u8, buf: *[4096]u8) ?[]const u8 { + var at: usize = 0; + while (nextAttr(attr, &at, buf)) |a| if (std.mem.eql(u8, a.name, name)) return a.value; + return null; +} + +/// `attr` packed again (plumbpackattr): the first attribute named `drop` +/// left out (plumbdelattr), those of `add` after it (plumbaddattr). +fn repack(arena: std.mem.Allocator, attr: []const u8, drop: ?[]const u8, add: []const u8) error{OutOfMemory}![]const u8 { + var out: std.Io.Writer.Allocating = .init(arena); + var dropped = drop == null; + var buf: [4096]u8 = undefined; + for ([2][]const u8{ attr, add }) |from| { + var at: usize = 0; + while (nextAttr(from, &at, &buf)) |a| { + if (!dropped and std.mem.eql(u8, a.name, drop.?)) { + dropped = true; + continue; + } + const w = &out.writer; + if (out.written().len > 0) w.writeByte(' ') catch return error.OutOfMemory; + w.print("{s}=", .{a.name}) catch return error.OutOfMemory; + // mesg.c's quote: a value with a blank, a quote, `=` or a tab. + if (std.mem.indexOfAny(u8, a.value, " '=\t") == null) { + w.writeAll(a.value) catch return error.OutOfMemory; + continue; + } + w.writeByte('\'') catch return error.OutOfMemory; + for (a.value) |c| { + if (c == '\'') w.writeByte('\'') catch return error.OutOfMemory; + w.writeByte(c) catch return error.OutOfMemory; + } + w.writeByte('\'') catch return error.OutOfMemory; + } + } + return out.written(); +} + +// ---- the rules ---- + +/// rules.c's objects and verbs, in its order (`kind` is an old `type`). +const Obj = enum { arg, attr, data, dst, plumb, src, type, wdir }; +const Verb = enum { add, client, delete, is, isdir, isfile, matches, set, start, to }; + +/// A line `object verb arg`: `qarg` is `arg` expanded with the variables +/// alone, its first word, as rules.c's parserule keeps it. +const Rule = struct { obj: Obj, verb: Verb, arg: []const u8, qarg: []const u8 }; +const Set = struct { pats: []const Rule, acts: []const Rule, port: ?[]const u8 }; +const Var = struct { name: []const u8, value: []const u8, qvalue: []const u8 }; + +/// The rules as read, each item where it was written: printed back in +/// that order, a variable given again later means what it meant to the +/// rules between (Plan 9's printrules puts every variable first). +const Rules = struct { + items: std.ArrayList(union(enum) { variable: Var, ports: []const Rule, set: Set }) = .empty, + vars: std.ArrayList(Var) = .empty, + /// Every port a rule set or a declaration names, once, in order. + ports: std.ArrayList([]const u8) = .empty, + + fn print(r: *const Rules, w: *std.Io.Writer) std.Io.Writer.Error!void { + for (r.items.items) |item| switch (item) { + .variable => |v| try w.print("{s}={s}\n\n", .{ v.name, v.value }), + .ports => |acts| { + for (acts) |a| try printRule(w, a); + try w.writeByte('\n'); + }, + .set => |set| { + for (set.pats) |a| try printRule(w, a); + for (set.acts) |a| try printRule(w, a); + try w.writeByte('\n'); + }, + }; + } + + fn printRule(w: *std.Io.Writer, r: Rule) std.Io.Writer.Error!void { + try w.print("{s}\t{s}\t{s}\n", .{ @tagName(r.obj), @tagName(r.verb), r.arg }); + } + + fn named(r: *const Rules, port: []const u8) bool { + for (r.ports.items) |n| if (std.mem.eql(u8, n, port)) return true; + return false; + } +}; + +/// What a message is matched with, beside the rules: the message, and what +/// the rule set's patterns found so far (match.c's Exec). +const Exec = struct { + m: *Msg, + /// The last `data matches`'s match, `$0`. + match0: []const u8 = "", + /// The span a click match took, which every other `data matches` of + /// the set must take too. + span: ?[2]usize = null, + clearclick: bool = false, + setdata: bool = false, + /// What `isfile` and `isdir` found: `$file`, `$dir`. + file: ?[]const u8 = null, + dir: ?[]const u8 = null, +}; + +/// rules.c's expand: the first word of `s` (a blank outside quotes ends +/// it), quotes rc's (`'...'`, `''` a quote), `$name` a variable's value, +/// with a message the message's (`$data`, `$0`, `$file`, ...); a `$` that +/// names nothing stays. Past `out` (Plan 9's 4 KiB ebuf), `TooLong`. +/// Answers the word and how much of `s` it took. +fn expand(r: *const Rules, e: ?*const Exec, s: []const u8, out: *[4096]u8) error{TooLong}!struct { []const u8, usize } { + var w = std.Io.Writer.fixed(out); + var i: usize = 0; + var quoting = false; + while (i < s.len and (quoting or (s[i] != ' ' and s[i] != '\t'))) { + if (s[i] == '\'') { + i += 1; + if (!quoting) { + quoting = true; + } else if (i < s.len and s[i] == '\'') { + w.writeByte('\'') catch return error.TooLong; + i += 1; + } else quoting = false; + continue; + } + if (quoting or s[i] != '$') { + w.writeByte(s[i]) catch return error.TooLong; + i += 1; + continue; + } + i += 1; + const took = dollar(r, e, s[i..], &w) catch return error.TooLong; + if (took) |n| i += n else w.writeByte('$') catch return error.TooLong; + } + return .{ w.buffered(), i }; +} + +/// rules.c's dollar: the value `$` then `s` names, written to `w`; how +/// much of `s` its name took, or null when it names nothing. +fn dollar(r: *const Rules, e: ?*const Exec, s: []const u8, w: *std.Io.Writer) std.Io.Writer.Error!?usize { + if (e) |x| if (s.len > 0 and std.ascii.isDigit(s[0])) { + // `$1`-`$9` were refused at parse (no submatches): `$0` alone. + if (s[0] == '0') try w.writeAll(x.match0); + return 1; + }; + var n: usize = 0; + while (n < s.len and std.ascii.isAlphanumeric(s[n])) n += 1; + const name = s[0..n]; + if (e) |x| { + const m = x.m; + const field: ?[]const u8 = if (std.mem.eql(u8, name, "src")) m.src else if (std.mem.eql(u8, name, "dst")) m.dst else if (std.mem.eql(u8, name, "attr")) m.attr else if (std.mem.eql(u8, name, "data")) m.data else if (std.mem.eql(u8, name, "type")) m.type else if (std.mem.eql(u8, name, "wdir")) m.wdir else null; + if (field) |f| { + try w.writeAll(f); + return n; + } + // rules.c's filename: what isfile or isdir found, else the data + // made absolute in wdir. + const found = if (std.mem.eql(u8, name, "file")) x.file else if (std.mem.eql(u8, name, "dir")) x.dir else null; + if (found != null or std.mem.eql(u8, name, "file") or std.mem.eql(u8, name, "dir")) { + if (found) |f| { + try w.writeAll(f); + } else if ((m.data.len > 0 and m.data[0] == '/') or m.wdir.len == 0) { + try w.writeAll(m.data); + } else try w.print("{s}/{s}", .{ m.wdir, m.data }); + return n; + } + } + for (r.vars.items) |v| if (std.mem.eql(u8, v.name, name)) { + try w.writeAll(v.qvalue); + return n; + }; + return null; +} + +/// Reads rule text into `rules` (rules.c's readrules): line by line, a +/// blank line (or a comment, or a variable) ending a rule set, an include +/// read in its place. A refusal is `why`: `:: `. +const Parser = struct { + arena: std.mem.Allocator, + /// Where an include is read from: none, only `basic`. + p: ?*Pardes, + /// Rules written, not the ones in force read again: their patterns + /// compiled and their bounds counted. + check: bool, + rules: Rules = .{}, + pats: std.ArrayList(Rule) = .empty, + acts: std.ArrayList(Rule) = .empty, + port: ?[]const u8 = null, + commands: usize = 0, + file: []const u8 = "", + line: usize = 0, + depth: usize = 0, + why: []const u8 = "", + + const Error = error{ Parse, OutOfMemory }; + + fn fail(ps: *Parser, comptime fmt: []const u8, args: anytype) Error { + ps.why = try std.fmt.allocPrint(ps.arena, "{s}:{d}: " ++ fmt, .{ ps.file, ps.line } ++ args); + return error.Parse; + } + + fn feed(ps: *Parser, name: []const u8, text: []const u8) Error!void { + ps.file = name; + ps.line = 0; + const whole = if (std.mem.endsWith(u8, text, "\n")) text[0 .. text.len - 1] else text; + var lines = std.mem.splitScalar(u8, whole, '\n'); + while (lines.next()) |line| { + ps.line += 1; + try ps.take(line); + } + } + + /// The text read, ended as its end ends a rule set. + fn finish(ps: *Parser) Error!void { + try ps.endSet(); + } + + /// rules.c's readrule, for one line. + fn take(ps: *Parser, raw: []const u8) Error!void { + const l = std.mem.trimStart(u8, raw, " \t"); + if (l.len == 0 or l[0] == '#') return ps.endSet(); + if (std.mem.startsWith(u8, l, "include")) return ps.include(l); + if (try ps.assignment(l)) return; + const obj_end = std.mem.indexOfAny(u8, l, " \t") orelse return ps.fail("malformed rule", .{}); + const obj_word = l[0..obj_end]; + const obj = std.meta.stringToEnum(Obj, obj_word) orelse + if (std.mem.eql(u8, obj_word, "kind")) .type else return ps.fail("unknown object {s}", .{obj_word}); + const rest = std.mem.trimStart(u8, l[obj_end..], " \t"); + const verb_end = std.mem.indexOfAny(u8, rest, " \t") orelse return ps.fail("malformed rule", .{}); + const verb = std.meta.stringToEnum(Verb, rest[0..verb_end]) orelse return ps.fail("unknown verb {s}", .{rest[0..verb_end]}); + const arg = std.mem.trimStart(u8, rest[verb_end..], " \t"); + if (arg.len == 0) return ps.fail("malformed rule", .{}); + // parserule. + const action = verb == .client or verb == .start or verb == .to; + if ((obj == .plumb) != action or (obj != .attr and (verb == .add or verb == .delete))) + return ps.fail("{s} not valid verb for object {s}", .{ @tagName(verb), @tagName(obj) }); + // pardes's regular expressions have no capture groups (regexp.zig, + // mvzr), and the user chose never to have an engine of pardes's + // own: a submatch is refused, never silently empty. + var quoting = false; + for (arg, 0..) |c, i| { + if (c == '\'') quoting = !quoting; + if (!quoting and c == '$' and i + 1 < arg.len and arg[i + 1] >= '1' and arg[i + 1] <= '9') + return ps.fail("${c}: no submatches (the regular expressions have no capture groups): use $0 and several matches", .{arg[i + 1]}); + } + const r: Rule = .{ .obj = obj, .verb = verb, .arg = arg, .qarg = try ps.word(arg) }; + if (verb == .matches and ps.check) { + var pat: [4096 + 4]u8 = undefined; + _ = Regex.compile(anchored(r.qarg, &pat)) catch |err| return ps.fail("{s}", .{Regex.message(err)}); + } + if (obj != .plumb) return ps.pats.append(ps.arena, r); + try ps.acts.append(ps.arena, r); + if (verb != .to) { + ps.commands += 1; + return; + } + // readruleset's: a declaration names many, a rule set one. + if (ps.pats.items.len > 0 and ps.port != null) return ps.fail("too many ports", .{}); + for ([_][]const u8{ ".", "..", "send", "rules" }) |bad| if (std.mem.eql(u8, r.qarg, bad)) + return ps.fail("illegal port name {s}", .{r.qarg}); + ps.port = r.qarg; + } + + /// readruleset's end: a rule set kept, ports declared, or a refusal. + fn endSet(ps: *Parser) Error!void { + const pats = ps.pats.items; + const acts = ps.acts.items; + const port = ps.port; + const commands = ps.commands; + ps.pats = .empty; + ps.acts = .empty; + ps.port = null; + ps.commands = 0; + if (commands > 1) return ps.fail("ruleset has more than one client or start action", .{}); + if (pats.len == 0 and acts.len == 0) return; + if (pats.len > 0 and acts.len > 0) { + try ps.rules.items.append(ps.arena, .{ .set = .{ .pats = pats, .acts = acts, .port = port } }); + } else { + if (acts.len == 0 or port == null) return ps.fail("ruleset must have patterns and actions", .{}); + for (acts) |a| if (a.verb != .to) return ps.fail("ruleset must have actions", .{}); + try ps.rules.items.append(ps.arena, .{ .ports = acts }); + } + for (acts) |a| if (a.verb == .to and !ps.rules.named(a.qarg)) { + if (ps.check and ps.rules.ports.items.len >= max_ports) return ps.fail("too many ports; max {d}", .{max_ports}); + try ps.rules.ports.append(ps.arena, a.qarg); + }; + } + + /// `s`'s first word expanded with the variables: a slice of `s` when + /// that changes nothing (no quote, no `$`), as in most rules. What a + /// parse keeps slices the text it read, which outlives it (the rules in + /// force, a write's, an include read into the arena, src/plumbing). + fn word(ps: *Parser, s: []const u8) Error![]const u8 { + var buf: [4096]u8 = undefined; + const w, const took = expand(&ps.rules, null, s, &buf) catch return ps.fail("string-too-long", .{}); + return if (std.mem.eql(u8, w, s[0..took])) s[0..took] else ps.arena.dupe(u8, w); + } + + /// rules.c's assignment: `name=value`, its value expanded once, now; + /// it ends a rule set as a blank line does. + fn assignment(ps: *Parser, l: []const u8) Error!bool { + if (!std.ascii.isAlphabetic(l[0])) return false; + var i: usize = 0; + while (i < l.len and std.ascii.isAlphanumeric(l[i])) i += 1; + const name = l[0..i]; + while (i < l.len and (l[i] == ' ' or l[i] == '\t')) i += 1; + if (i >= l.len or l[i] != '=') return false; + try ps.endSet(); + const value = std.mem.trimStart(u8, l[i + 1 ..], " \t"); + const v: Var = .{ .name = name, .value = value, .qvalue = try ps.word(value) }; + try ps.rules.items.append(ps.arena, .{ .variable = v }); + for (ps.rules.vars.items) |*old| if (std.mem.eql(u8, old.name, name)) { + old.* = v; + return true; + }; + if (ps.check and ps.rules.vars.items.len >= max_vars) return ps.fail("too many variables; max {d}", .{max_vars}); + try ps.rules.vars.append(ps.arena, v); + return true; + } + + /// rules.c's include: `include basic` is src/plumbing; another name + /// the configuration directory's file, an absolute one where it says. + fn include(ps: *Parser, l: []const u8) Error!void { + var words = std.mem.tokenizeAny(u8, l, " \t"); + const first = words.next().?; + const name = words.next() orelse ""; + const third = words.next(); + if (!std.mem.eql(u8, first, "include") or name.len == 0 or name[0] == '#' or (third != null and third.?[0] != '#')) + return ps.fail("malformed include statement", .{}); + if (ps.depth >= max_depth) return ps.fail("include stack too deep; max {d}", .{max_depth}); + const text = if (std.mem.eql(u8, name, "basic")) basic else text: { + var buf: [4096]u8 = undefined; + const p = ps.p orelse return ps.fail("can't open {s} for inclusion", .{name}); + const path = if (name[0] == '/') name else std.fmt.bufPrint(&buf, "{s}/{s}", .{ p.configDir() orelse "", name }) catch name; + break :text fs.readFile(ps.arena, path) catch return ps.fail("can't open {s} for inclusion", .{path}); + }; + const file = ps.file; + const line = ps.line; + ps.depth += 1; + try ps.feed(name, text); + ps.depth -= 1; + ps.file = file; + ps.line = line; + } +}; + +/// `pat` matching only the whole of what it is run over: `^(pat)$` (its +/// own anchors dropped, mvzr taking `^` only first), in `out`. +fn anchored(pat: []const u8, out: *[4096 + 4]u8) []const u8 { + var core = pat; + if (core.len > 0 and core[0] == '^') core = core[1..]; + if (core.len > 1 and core[core.len - 1] == '$' and core[core.len - 2] != '\\') core = core[0 .. core.len - 1]; + return std.fmt.bufPrint(out, "^({s})$", .{core}) catch pat; +} + +/// The rules in force as text to read again. +fn source(p: *Pardes) []const u8 { + return if (p.plumber.written) p.plumber.text.items else "include basic\n"; +} + +/// The rules in force read, for a send. +fn rulesOf(p: *Pardes, arena: std.mem.Allocator) Parser.Error!Rules { + var ps: Parser = .{ .arena = arena, .p = p, .check = false }; + try ps.feed("plumb/rules", source(p)); + try ps.finish(); + return ps.rules; +} + +/// The rules in force as plumb/rules reads them, the defaults printed +/// (in the step's scratch) while none were written. +pub fn inForce(p: *Pardes) []const u8 { + if (p.plumber.written) return p.plumber.text.items; + const arena = p.scratch.allocator(); + const rules = rulesOf(p, arena) catch return ""; + var out: std.Io.Writer.Allocating = .init(arena); + rules.print(&out.writer) catch return ""; + return out.written(); +} + +/// No rules at all: a `>` to plumb/rules, before what it writes. +pub fn clear(p: *Pardes) void { + p.plumber.text.clearRetainingCapacity(); + p.plumber.written = true; +} + +/// `more` read after the rules in force (`keep`) or in their place, and +/// what that makes kept as the rules: plumb/rules' write and its close's +/// rest. Null when taken, else why not, in the step's scratch, the rules +/// as they were. +pub fn apply(p: *Pardes, keep: bool, more: []const u8) ?[]const u8 { + const arena = p.scratch.allocator(); + var ps: Parser = .{ .arena = arena, .p = p, .check = true }; + const said = said: { + if (keep) { + ps.feed("plumb/rules", source(p)) catch break :said ps.why; + ps.finish() catch break :said ps.why; + } + ps.feed("plumb/rules", more) catch break :said ps.why; + ps.finish() catch break :said ps.why; + var out: std.Io.Writer.Allocating = .init(arena); + ps.rules.print(&out.writer) catch break :said "out of memory"; + if (out.written().len > max_text) break :said std.fmt.comptimePrint("rules too long; max {d} KiB", .{max_text / 1024}); + p.plumber.text.clearRetainingCapacity(); + p.plumber.text.appendSlice(p.gpa, out.written()) catch break :said "out of memory"; + p.plumber.written = true; + return null; + }; + return if (said.len > 0) said else "out of memory"; +} + +// ---- matching ---- + +/// One message's match (fsys.c's write of `send` through dispose): the +/// rules, and what the disk said of a name, asked once however many rules +/// ask it. +const Send = struct { + p: *Pardes, + /// The pane a look sent from, whose jump list's directories a name is + /// looked for in too; none from plumb/send. + from: ?usize, + arena: std.mem.Allocator, + rules: Rules, + memo_name: ?[]const u8 = null, + memo_wdir: []const u8 = "", + memo: ?fs.Resolved = null, + memo_buf: [4096]u8 = undefined, + + /// Where a name is, as Look finds it: the place written after it + /// (`:12`, `:12:5`) no part of it, then the message's directory, the + /// jump list's panes' (from a look), then Incl's (look.zig's + /// resolveLookTarget). Each stat is a taped resolve site; a name is + /// asked once a send. + fn resolve(s: *Send, wdir: []const u8, raw: []const u8) ?fs.Resolved { + const name = look.parsePathLine(std.mem.trim(u8, raw, " \t\r\n")).path; + if (s.memo_name) |n| if (std.mem.eql(u8, n, name) and std.mem.eql(u8, s.memo_wdir, wdir)) return s.memo; + s.memo_name = s.arena.dupe(u8, name) catch return null; + s.memo_wdir = s.arena.dupe(u8, wdir) catch return null; + s.memo = s.search(wdir, name); + return s.memo; + } + + fn search(s: *Send, wdir: []const u8, name: []const u8) ?fs.Resolved { + if (name.len == 0) return null; + if (fs.resolve(s.p, name, wdir, &s.memo_buf)) |found| return found; + if (name[0] == '/' or fs.dotRelative(name)) return null; + if (s.from) |id| { + const v = s.p.view(); + var seen: [pardes.MAX_PANES][]const u8 = undefined; + var nseen: usize = 0; + var n: usize = 1; + cand: while (n <= v.jumps.n) : (n += 1) { + const k = v.jumps.list[v.jumps.n - n].pane; + if (k == id) continue; + const dir = Pardes.paneDir(s.p.panes[k] orelse continue); + if (std.mem.eql(u8, dir, wdir)) continue; + for (seen[0..nseen]) |d| if (std.mem.eql(u8, d, dir)) continue :cand; + seen[nseen] = dir; + nseen += 1; + if (fs.resolve(s.p, name, dir, &s.memo_buf)) |found| return found; + } + } + for (s.p.incl.items) |dir| if (fs.resolve(s.p, name, dir, &s.memo_buf)) |found| return found; + return null; + } + + /// match.c's matchruleset: the message tried against `set`, rewritten + /// in place by its patterns (a `set` stays though a later one fails). + fn matchSet(s: *Send, set: Set, e: *Exec) error{OutOfMemory}!bool { + const m = e.m; + if (m.dst.len > 0 and set.port != null and !std.mem.eql(u8, m.dst, set.port.?)) return false; + for (set.pats) |r| if (!try s.pattern(e, r)) return false; + if (set.port) |port| if (m.dst.len == 0) { + m.dst = port; + }; + // match.c's rewrite: a click match's span is the data now. + if (e.clearclick) { + m.attr = try repack(s.arena, m.attr, "click", ""); + if (e.setdata) m.data = e.match0; + } + return true; + } + + /// match.c's matchpat. + fn pattern(s: *Send, e: *Exec, r: Rule) error{OutOfMemory}!bool { + const m = e.m; + const field: ?*[]const u8 = switch (r.obj) { + .data => &m.data, + .dst => &m.dst, + .type => &m.type, + .wdir => &m.wdir, + .src => &m.src, + .arg, .attr, .plumb => null, + }; + var buf: [4096]u8 = undefined; + switch (r.verb) { + .is => return if (field) |f| std.mem.eql(u8, f.*, r.qarg) else false, + .set => { + const f = field orelse return true; + const value = (expand(&s.rules, e, r.arg, &buf) catch return false)[0]; + f.* = try s.arena.dupe(u8, value); + if (r.obj == .data) { + e.span = null; + e.setdata = false; + } + return true; + }, + .add, .delete => { + if (r.obj != .attr) return false; + const value = (expand(&s.rules, e, r.arg, &buf) catch return false)[0]; + if (r.verb == .add) { + m.attr = try repack(s.arena, m.attr, null, value); + return true; + } + // The code's, not the man page's: an absent one fails. + var vbuf: [4096]u8 = undefined; + if (attrValue(m.attr, value, &vbuf) == null) return false; + m.attr = try repack(s.arena, m.attr, value, ""); + return true; + }, + .isfile, .isdir => { + const name = switch (r.obj) { + .arg => (expand(&s.rules, e, r.arg, &buf) catch return false)[0], + .data => m.data, + .wdir => m.wdir, + else => return false, + }; + const found = s.resolve(m.wdir, name) orelse return false; + if (found.dir != (r.verb == .isdir)) return false; + const path = try s.arena.dupe(u8, found.path); + if (r.verb == .isdir) e.dir = path else e.file = path; + return true; + }, + .matches => { + const text = (field orelse return false).*; + var pat: [4096 + 4]u8 = undefined; + var click_buf: [4096]u8 = undefined; + const click = if (r.obj == .data) attrValue(m.attr, "click", &click_buf) else null; + if (click == null) { + // The whole of it, as match.c asks of regexec's answer. + var rx = Regex.compile(anchored(r.qarg, &pat)) catch return false; + const hit = (rx.find(text, 0, 0, text.len) catch return false) orelse return false; + if (hit.start != 0 or hit.end != text.len) return false; + e.match0 = text; + return true; + } + // clickmatch: the first match from each start up to the + // click that holds it, the click counted in runes. + const runes = std.fmt.parseInt(usize, std.mem.trim(u8, click.?, " \t"), 10) catch 0; + var at: usize = 0; + var n: usize = 0; + while (n < runes and at < text.len) : (n += 1) at += std.unicode.utf8ByteSequenceLength(text[at]) catch 1; + at = @min(at, text.len); + var rx = Regex.compile(r.qarg) catch return false; + var from: usize = 0; + const hit = while (from <= at) { + const h = (rx.find(text, from, at, text.len) catch return false) orelse return false; + if (h.start <= at and at <= h.end) break h; + // Every start before the next match finds this one. + from = h.start + 1; + while (from < text.len and text[from] & 0xC0 == 0x80) from += 1; + } else return false; + if (e.span) |sp| if (sp[0] != hit.start or sp[1] != hit.end) return false; + e.span = .{ hit.start, hit.end }; + e.clearclick = true; + e.setdata = true; + e.match0 = text[hit.start..hit.end]; + return true; + }, + .client, .start, .to => return false, + } + } +}; + +/// The ports pardes reads itself, as acme reads `edit`; and every loaded +/// kind by its name. +const Port = enum { + /// A file or directory opened as Look opens one, at the place written + /// after its name or given as `addr=`. + edit, + /// A URL given to the host's browser (xdg-open, open on macOS). + web, +}; + +/// A message matched against the rules and sent where they say (fsys.c's +/// write of `send`, then dispose), from pane `from` (a look's) or from +/// plumb/send (null: the pane with the keyboard runs what it starts). +/// Null when it went somewhere, else why not, in Plan 9's words, in the +/// step's scratch. +pub fn send(p: *Pardes, from: ?usize, msg: Msg) ?[]const u8 { + const arena = p.scratch.allocator(); + var s: Send = .{ .p = p, .from = from, .arena = arena, .rules = rulesOf(p, arena) catch return "plumb/rules: the rules in force do not read" }; + var m = msg; + var e: Exec = .{ .m = &m }; + const set: ?Set = for (s.rules.items.items) |item| { + const candidate = switch (item) { + .set => |x| x, + else => continue, + }; + e = .{ .m = &m }; + if (s.matchSet(candidate, &e) catch return "out of memory") break candidate; + } else null; + const id = from orelse p.view().active; + // dispose. + if (m.dst.len == 0) return startup(&s, id, set orelse return e_no_port, &e); + if (std.meta.stringToEnum(Port, m.dst)) |port| { + deliver(&s, id, port, &m); + return null; + } + if (p.kinds.byName(m.dst)) |k| { + openInKind(&s, id, k, &m); + return null; + } + // A port nobody reads: what the rule set starts, if it is one a rule + // names; one no rule names is no port, and the message goes nowhere, + // as fsys.c's dispose finds no Dirtab for it. + if (!s.rules.named(m.dst)) return null; + return startup(&s, id, set orelse return e_no_start, &e); +} + +/// match.c's startup: the rule set's `start` or `client`, its words +/// expanded, run. +fn startup(s: *Send, id: usize, set: Set, e: *const Exec) ?[]const u8 { + const act = for (set.acts) |a| { + if (a.verb == .start) break a; + if (a.verb == .client) { + if (e.m.dst.len == 0) return e_client; + break a; + } + } else return e_no_start; + // buildargv: one expansion a word. + var argv: std.ArrayList([]const u8) = .empty; + var rest = act.arg; + while (true) { + rest = std.mem.trimStart(u8, rest, " \t"); + if (rest.len == 0) break; + var buf: [4096]u8 = undefined; + const word, const took = expand(&s.rules, e, rest, &buf) catch return "string-too-long"; + argv.append(s.arena, s.arena.dupe(u8, word) catch return "out of memory") catch return "out of memory"; + rest = rest[took..]; + } + if (argv.items.len == 0) return e_empty; + run(s.p, id, e.m.wdir, argv.items); + return null; +} + +/// What a `plumb start` (and, until ports are read, a `plumb client`) runs: +/// the one place that decides it (question 4 of docs/next-plumber.md). +/// Its words as pardes's exec runs a line from the message's pane: a +/// builtin or a kind's word in place, any other line a command pane in +/// `wdir`, each word one argument to $SHELL -c however it is spelled. +/// Plan 9's runs detached, with no window. +fn run(p: *Pardes, id: usize, wdir: []const u8, argv: []const []const u8) void { + const arena = p.scratch.allocator(); + const line = std.mem.join(arena, " ", argv) catch return p.reportError(id, "plumb", error.OutOfMemory); + if (p.executeBuiltinLine(id, line)) return; + var quoted: std.Io.Writer.Allocating = .init(arena); + for (argv, 0..) |a, i| { + if (i > 0) quoted.writer.writeByte(' ') catch return; + quoted.writer.writeByte('\'') catch return; + for (a) |c| { + if (c == '\'') { + quoted.writer.writeAll("'\\''") catch return; + } else quoted.writer.writeByte(c) catch return; + } + quoted.writer.writeByte('\'') catch return; + } + p.exec_dir = if (wdir.len > 0) wdir else null; + defer p.exec_dir = null; + _ = exec.runCommand(p, id, quoted.written()); +} + +/// What pardes does with a message to a port it reads. Like a message +/// queued to a reader in Plan 9, the send is done: what goes wrong after +/// is said as a look's failure is. +fn deliver(s: *Send, id: usize, port: Port, m: *const Msg) void { + const p = s.p; + switch (port) { + .web => { + if (m.data.len > 256) return p.reportFailure(id, "plumb: web: a URL is at most 256 bytes"); + p.emit(.{ .open_link = .from(m.data) }); + }, + .edit => { + // acme's plumblook: the data a name in wdir, at its addr. + var buf: [4096]u8 = undefined; + const addr = attrValue(m.attr, "addr", &buf) orelse ""; + const relative = m.data.len > 0 and m.data[0] != '/' and m.data[0] != '~' and m.wdir.len > 0; + const text = std.fmt.allocPrint(s.arena, "{s}{s}{s}{s}{s}", .{ + if (relative) m.wdir else "", if (relative) "/" else "", m.data, + if (addr.len > 0) ":" else "", addr, + }) catch return p.reportError(id, "plumb", error.OutOfMemory); + look.lookAt(p, id, text); + }, + } +} + +/// A message to a loaded kind's port: its data, a file, opened in that kind +/// (or its pane given the keyboard, when one shows it). +fn openInKind(s: *Send, id: usize, k: u8, m: *const Msg) void { + const p = s.p; + const found = s.resolve(m.wdir, m.data) orelse return p.reportFailure(id, "plumb: no such file"); + if (found.dir) return p.reportFailure(id, "plumb: a directory is no kind's"); + const path = s.arena.dupe(u8, found.path) catch return; + for (p.panes, 0..) |slot, i| if (slot) |pn| if (pn.addon) |a| if (std.mem.eql(u8, a.path, path)) { + p.view().active = i; + return; + }; + const free = p.freeSlot() orelse return p.reportError(id, "plumb", error.NoPaneSlots); + const made = Kind.openFile(p, free, k, path) catch |err| return p.reportError(id, path, err); + if (made.addon.?.refused.len > 0) { + made.vweight = 0; + p.unplaced.set(free); + return p.reportFailure(id, s.arena.dupe(u8, made.addon.?.refused.slice()) catch "plumb: refused"); + } + layout.placeNew(p, id, id, free, .doc); +} + +/// Where rule text written in pieces is whole: through its last blank line +/// (rules.c's morerules), 0 when none is. +pub fn wholeSets(text: []const u8) usize { + return if (std.mem.lastIndexOf(u8, text, "\n\n")) |at| at + 2 else 0; +} + +// ---- tests ---- + +const testing = std.testing; + +/// The rules `text` read as written ones are, printed; or the refusal. +fn reread(arena: std.mem.Allocator, text: []const u8) ![]const u8 { + var ps: Parser = .{ .arena = arena, .p = null, .check = true }; + ps.feed("t", text) catch return ps.why; + ps.finish() catch return ps.why; + var out: std.Io.Writer.Allocating = .init(arena); + try ps.rules.print(&out.writer); + return out.written(); +} + +test "plumb: a message packs as plumb(6)'s six lines and its data, and unpacks whole, short of its data, or malformed" { + var buf: [256]u8 = undefined; + var w = std.Io.Writer.fixed(&buf); + const m: Msg = .{ .src = "pardes", .wdir = "/tmp", .type = "text", .attr = "click=3 addr=12", .data = "a b\nc" }; + try m.pack(&w); + try testing.expectEqualStrings("pardes\n\n/tmp\ntext\nclick=3 addr=12\n5\na b\nc", w.buffered()); + const back = unpack(w.buffered()).msg; + inline for (.{ "src", "dst", "wdir", "type", "attr", "data" }) |f| try testing.expectEqualStrings(@field(m, f), @field(back, f)); + try testing.expectEqual(@as(usize, 2), unpack(w.buffered()[0 .. w.buffered().len - 2]).more); + // A header line short is no message at all, as is data past its count. + try testing.expect(unpack("pardes\n\n/tmp\ntext\n") == .bad); + try testing.expect(unpack("a\nb\nc\nd\ne\n1\nxy") == .bad); + try testing.expect(unpack("a\nb\nc\nd\ne\nzz\n") == .msg); +} + +test "plumb: attributes read rc's quotes, a value that needs them is quoted again, delete takes the first, add appends" { + var arena: std.heap.ArenaAllocator = .init(testing.allocator); + defer arena.deinit(); + const a = arena.allocator(); + var buf: [4096]u8 = undefined; + const attr = "action=showdata filename='/a b/it''s' click=4"; + try testing.expectEqualStrings("/a b/it's", attrValue(attr, "filename", &buf).?); + try testing.expectEqualStrings("4", attrValue(attr, "click", &buf).?); + try testing.expect(attrValue(attr, "addr", &buf) == null); + try testing.expectEqualStrings("action=showdata filename='/a b/it''s'", try repack(a, attr, "click", "")); + try testing.expectEqualStrings("action=showdata filename='/a b/it''s' click=4 addr='x=1'", try repack(a, attr, null, "addr='x=1'")); + // One with no `=` ends them, as plumbunpackattr stops there. + try testing.expect(attrValue("a=1 bogus b=2", "b", &buf) == null); +} + +test "plumb: every parse error in rules.c's words, with its line" { + var arena: std.heap.ArenaAllocator = .init(testing.allocator); + defer arena.deinit(); + const a = arena.allocator(); + for ([_][2][]const u8{ + .{ "type is text\nbogus\n", "t:2: malformed rule" }, + .{ "type is\n", "t:1: malformed rule" }, + .{ "type \n", "t:1: malformed rule" }, + .{ "colour is red\n", "t:1: unknown object colour" }, + .{ "type equals text\n", "t:1: unknown verb equals" }, + .{ "data to edit\n", "t:1: to not valid verb for object data" }, + .{ "type start x\n", "t:1: start not valid verb for object type" }, + .{ "data add x=1\n", "t:1: add not valid verb for object data" }, + .{ "plumb is edit\n", "t:1: is not valid verb for object plumb" }, + .{ "type is text\nplumb to a\nplumb to b\n", "t:3: too many ports" }, + .{ "type is text\nplumb to send\n", "t:2: illegal port name send" }, + .{ "plumb to ..\n", "t:1: illegal port name .." }, + .{ "plumb to rules\n", "t:1: illegal port name rules" }, + .{ "type is text\nplumb start a\nplumb client b\n", "t:3: ruleset has more than one client or start action" }, + .{ "type is text\n\n", "t:2: ruleset must have patterns and actions" }, + .{ "plumb start x\n", "t:1: ruleset must have patterns and actions" }, + .{ "plumb to a\nplumb start x\n\n", "t:3: ruleset must have actions" }, + .{ "include\n", "t:1: malformed include statement" }, + .{ "include a b\n", "t:1: malformed include statement" }, + .{ "includes x\n", "t:1: malformed include statement" }, + .{ "include nowhere\n", "t:1: can't open nowhere for inclusion" }, + .{ "data matches '[a-'\nplumb to edit\n", "t:1: bad regular expression" }, + .{ "data matches '([a-z]+)\\.c'\narg isfile $1\nplumb to edit\n", "t:2: $1: no submatches (the regular expressions have no capture groups): use $0 and several matches" }, + }) |c| try testing.expectEqualStrings(c[1], try reread(a, c[0])); + // Inside quotes a `$1` is the text `$1`. + try testing.expectEqualStrings("data\tis\t'$1'\nplumb\tto\tedit\n\n", try reread(a, "data is '$1'\nplumb to edit\n")); + // The most variables, and ports, are bounded. + var many: std.Io.Writer.Allocating = .init(a); + for (0..max_vars + 1) |i| try many.writer.print("v{d}=x\n", .{i}); + try testing.expectEqualStrings("t:33: too many variables; max 32", try reread(a, many.written())); + many.clearRetainingCapacity(); + for (0..max_ports + 1) |i| try many.writer.print("plumb to p{d}\n", .{i}); + try testing.expectEqualStrings("t:33: too many ports; max 32", try reread(a, many.written())); +} + +test "plumb: rules print as rule sets of tab-separated lines, variables where they were set, and read back the same" { + var arena: std.heap.ArenaAllocator = .init(testing.allocator); + defer arena.deinit(); + const a = arena.allocator(); + const text = + \\# a comment ends nothing it is not in + \\x = '[a-z]+' + \\plumb to seemail + \\plumb to showmail + \\ + \\kind is text + \\data matches $x + \\plumb to edit + \\x=other + \\type is text + \\data set $x + \\plumb start Msg $data + ; + const printed = try reread(a, text); + try testing.expectEqualStrings("x='[a-z]+'\n\nplumb\tto\tseemail\nplumb\tto\tshowmail\n\ntype\tis\ttext\ndata\tmatches\t$x\nplumb\tto\tedit\n\nx=other\n\ntype\tis\ttext\ndata\tset\t$x\nplumb\tstart\tMsg $data\n\n", printed); + try testing.expectEqualStrings(printed, try reread(a, printed)); + // The default rules read, and print as they read. + const defaults = try reread(a, "include basic\n"); + try testing.expect(std.mem.indexOf(u8, defaults, "data\tmatches\t'https?://.*'\nplumb\tto\tweb\n") != null); + try testing.expectEqualStrings(defaults, try reread(a, defaults)); +} + +test "plumb: rc's quoting, variables and the message's in an expansion, the first word alone" { + var arena: std.heap.ArenaAllocator = .init(testing.allocator); + defer arena.deinit(); + var ps: Parser = .{ .arena = arena.allocator(), .p = null, .check = true }; + try ps.feed("t", "v='a b'\nw=x$v'y'\n"); + var m: Msg = .{ .src = "pardes", .wdir = "/w", .data = "f.c" }; + var e: Exec = .{ .m = &m, .match0 = "zero" }; + var buf: [4096]u8 = undefined; + for ([_][2][]const u8{ + .{ "'it''s' rest", "it's" }, + .{ "pre$v.post", "prea b.post" }, + .{ "$w", "xa by" }, + .{ "'$v'", "$v" }, + .{ "$nothere$", "$nothere$" }, + .{ "$src:$wdir:$data:$0:$file", "pardes:/w:f.c:zero:/w/f.c" }, + }) |c| try testing.expectEqualStrings(c[1], (try expand(&ps.rules, &e, c[0], &buf))[0]); + e.file = "/real/f.c"; + try testing.expectEqualStrings("/real/f.c", (try expand(&ps.rules, &e, "$file", &buf))[0]); + // Past 4 KiB: too long, never cut. + const long = try arena.allocator().alloc(u8, 5000); + @memset(long, 'a'); + m.data = long; + try testing.expectError(error.TooLong, expand(&ps.rules, &e, "$data", &buf)); +} + +/// A send against `text`'s rules on a session of its own: the message +/// after its match, the rule set that took it (its index among the sets, +/// null for none) and what dispose said. +const Tried = struct { m: Msg, set: ?usize }; + +fn tryRules(p: *Pardes, text: []const u8, msg: Msg) !Tried { + try testing.expect(apply(p, false, text) == null); + const arena = p.scratch.allocator(); + var s: Send = .{ .p = p, .from = null, .arena = arena, .rules = try rulesOf(p, arena) }; + var m = msg; + var e: Exec = .{ .m = &m }; + var n: usize = 0; + for (s.rules.items.items) |item| { + const set = switch (item) { + .set => |x| x, + else => continue, + }; + e = .{ .m = &m }; + if (try s.matchSet(set, &e)) return .{ .m = m, .set = n }; + n += 1; + } + return .{ .m = m, .set = null }; +} + +test "plumb: matches takes the whole text, or with a click the run around it: Pike's horse.gift is no gif" { + const p = try Pardes.init(testing.allocator, .{ .cols = 80, .rows = 24 }); + defer p.deinit(); + const rules = + \\type is text + \\data matches '[a-zA-Z0-9_\-./]+' + \\data matches '([a-zA-Z0-9_\-./]+)\.(gif|jpe?g)' + \\plumb to image + \\ + ; + try testing.expectEqual(@as(?usize, 0), (try tryRules(p, rules, .{ .type = "text", .data = "horse.gif" })).set); + try testing.expect((try tryRules(p, rules, .{ .type = "text", .data = "horse.gift" })).set == null); + try testing.expect((try tryRules(p, rules, .{ .type = "text", .data = "see horse.gif" })).set == null); + // A click inside the name: the run of file characters around it, the + // data cut to it and the click gone. + const hit = try tryRules(p, rules, .{ .type = "text", .attr = "click=7", .data = "see horse.gif now" }); + try testing.expectEqual(@as(?usize, 0), hit.set); + try testing.expectEqualStrings("horse.gif", hit.m.data); + try testing.expectEqualStrings("", hit.m.attr); + try testing.expectEqualStrings("image", hit.m.dst); + try testing.expect((try tryRules(p, rules, .{ .type = "text", .attr = "click=7", .data = "see horse.gift now" })).set == null); + // The click counts runes: two bytes of é before it. + try testing.expectEqualStrings("horse.gif", (try tryRules(p, rules, .{ .type = "text", .attr = "click=3", .data = "é horse.gif" })).m.data); + // Each object a rule matches whole. + const src = "src\tmatches\t'par.*'\ntype\tmatches\t'te(x|y)t'\nplumb\tto\tedit\n"; + try testing.expectEqual(@as(?usize, 0), (try tryRules(p, src, .{ .src = "pardes", .type = "text" })).set); + try testing.expect((try tryRules(p, src, .{ .src = "pardes", .type = "texts" })).set == null); + // The default rules' URL: http and https, whole. + try testing.expectEqual(@as(?usize, 0), (try tryRules(p, basic, .{ .type = "text", .data = "https://ziglang.org/x?y" })).set); + try testing.expect((try tryRules(p, basic, .{ .type = "text", .data = "see https://ziglang.org" })).set == null); +} + +test "plumb: a set rewrites the message for good, attr delete of one absent fails, a message to a port tries only rule sets to it" { + const p = try Pardes.init(testing.allocator, .{ .cols = 80, .rows = 24 }); + defer p.deinit(); + const rules = + \\data set changed + \\type is never + \\plumb to a + \\ + \\attr delete action + \\attr add 'action=showdiff filename=x' + \\plumb to b + \\ + \\data is changed + \\plumb to c + \\ + ; + // The first set fails after its `set`: the data stays changed; the + // second fails at its delete; the third sees the changed data. + const t = try tryRules(p, rules, .{ .type = "text", .data = "orig" }); + try testing.expectEqual(@as(?usize, 2), t.set); + try testing.expectEqualStrings("changed", t.m.data); + try testing.expectEqualStrings("c", t.m.dst); + const d = try tryRules(p, rules, .{ .type = "text", .attr = "action=showdata", .data = "x" }); + try testing.expectEqual(@as(?usize, 1), d.set); + try testing.expectEqualStrings("action=showdiff filename=x", d.m.attr); + // dst names a port: rule sets to another are passed over. + const to_a = try tryRules(p, "data\tis\tx\nplumb\tto\ta\n\ndata\tis\tx\nplumb\tto\tb\n\n", .{ .dst = "b", .data = "x" }); + try testing.expectEqual(@as(?usize, 1), to_a.set); +} + +test "plumb: isfile and isdir find a name as Look does, past its place, in the message's directory then Incl's; $file is where" { + if (!fs.platform_has_fs) return; + var tmp = testing.tmpDir(.{}); + defer tmp.cleanup(); + try tmp.dir.writeFile(testing.io, .{ .sub_path = "it.zig", .data = "x\n" }); + try tmp.dir.createDir(testing.io, "sub", .default_dir); + var dir_buf: [4096]u8 = undefined; + const root = dir_buf[0..try tmp.dir.realPath(testing.io, &dir_buf)]; + const p = try Pardes.init(testing.allocator, .{ .cols = 80, .rows = 24 }); + defer p.deinit(); + const rules = "arg\tisfile\t$data\ndata\tset\t$file\nplumb\tto\tedit\n\narg\tisdir\t$data\ndata\tset\t$dir\nplumb\tto\tedit\n\n"; + const file = try tryRules(p, rules, .{ .wdir = root, .data = "it.zig:3:2" }); + try testing.expectEqual(@as(?usize, 0), file.set); + try testing.expect(std.mem.endsWith(u8, file.m.data, "/it.zig")); + const dir = try tryRules(p, rules, .{ .wdir = root, .data = "sub" }); + try testing.expectEqual(@as(?usize, 1), dir.set); + try testing.expect(std.mem.endsWith(u8, dir.m.data, "/sub")); + try testing.expect((try tryRules(p, rules, .{ .wdir = root, .data = "nothere.zig" })).set == null); + // Not in wdir: Incl's directories, as acme's includename. + try p.incl.append(p.gpa, try p.gpa.dupe(u8, root)); + try testing.expectEqual(@as(?usize, 0), (try tryRules(p, rules, .{ .wdir = "/", .data = "it.zig" })).set); + try testing.expect((try tryRules(p, rules, .{ .wdir = "/", .data = "./it.zig" })).set == null); +} + +test "plumb: dispose: no rule and no dst, a start, the web port, a port no rule names" { + const p = try Pardes.init(testing.allocator, .{ .cols = 80, .rows = 24 }); + defer p.deinit(); + _ = try p.setTestFile("x\n"); + try testing.expect(apply(p, false, "include basic\n\ntype\tis\tmsg\nplumb\tstart\tMsg $data\n\ntype\tis\tnone\nplumb\tto\tnobody\n\ntype\tis\tclient\nplumb\tclient\tMsg x\n\n") == null); + try testing.expectEqualStrings(e_no_port, send(p, null, .{ .type = "text", .data = "no such thing" }).?); + // A start of a builtin runs it in place. + try testing.expect(send(p, null, .{ .type = "msg", .data = "hello" }) == null); + const pane = p.panes[p.view().active].?; + try testing.expectEqualStrings("hello", pane.msg[0..pane.msg_len]); + try testing.expectEqualStrings(e_client, send(p, null, .{ .type = "client" }).?); + try testing.expectEqualStrings(e_no_start, send(p, null, .{ .type = "none" }).?); + try testing.expectEqualStrings(e_no_start, send(p, null, .{ .dst = "nobody", .type = "x" }).?); + // A port no rule names goes nowhere, said nothing (fsys.c's dispose). + try testing.expect(send(p, null, .{ .dst = "elsewhere", .data = "x" }) == null); + // A URL to the web port: the host's opener. + while (p.nextEffect()) |_| {} + try testing.expect(send(p, null, .{ .type = "text", .data = "https://ziglang.org" }) == null); + var opened = false; + while (p.nextEffect()) |e| switch (e) { + .open_link => |u| { + try testing.expectEqualStrings("https://ziglang.org", u.slice()); + opened = true; + }, + else => {}, + }; + try testing.expect(opened); +} + +test "plumb: rules written replace or add, a refusal keeps them as they were, and a dump keeps them" { + const p = try Pardes.init(testing.allocator, .{ .cols = 80, .rows = 24 }); + defer p.deinit(); + // Every session starts with the defaults. + try testing.expect(std.mem.indexOf(u8, inForce(p), "plumb\tto\tweb") != null); + try testing.expect(!p.plumber.written); + try testing.expect(apply(p, false, "type is a\nplumb to edit\n") == null); + try testing.expect(apply(p, true, "type is b\nplumb to edit\n") == null); + try testing.expectEqualStrings("type\tis\ta\nplumb\tto\tedit\n\ntype\tis\tb\nplumb\tto\tedit\n\n", p.plumber.text.items); + try testing.expectEqualStrings("plumb/rules:1: unknown verb isnt", apply(p, true, "type isnt c\n").?); + try testing.expectEqualStrings("type\tis\ta\nplumb\tto\tedit\n\ntype\tis\tb\nplumb\tto\tedit\n\n", p.plumber.text.items); + try pardes.dump.dumpState(p); + const restored = try pardes.dump.restore(p, p.dump_out.?, "/tmp/pardes.dump.zon"); + defer restored.deinit(); + try testing.expectEqualStrings(p.plumber.text.items, restored.plumber.text.items); + try testing.expect(restored.plumber.written); +} + +test "plumb: plan9port's basic parses, its ¡-￿ classes UTF-8's bytes and its submatch rule sets left out, and its rules match" { + var arena: std.heap.ArenaAllocator = .init(testing.allocator); + defer arena.deinit(); + // plan9port's plumb/basic and fileaddr; `¡-￿` is `\x80-\xf4`, the bytes + // of UTF-8's multi-byte runes (a run of them is whole runes: UTF-8 is + // self-synchronising), and the rule sets that need `$1`-`$5` are gone. + const p9p = + \\addrelem='((#?[0-9]+)|(/[A-Za-z0-9_\^]+/?)|[.$])' + \\addr=:($addrelem([,;+\-]$addrelem)*) + \\ + \\plumb to seemail + \\plumb to showmail + \\ + \\type is text + \\data matches '(https?|ftp|file|gopher|mailto|news|nntp|telnet|wais|prospero)://[a-zA-Z0-9_@\-]+([.:][a-zA-Z0-9_@\-]+)*/?[a-zA-Z0-9_?,%#~&/\-+=]+([:.][a-zA-Z0-9_?,%#~&/\-+=]+)*' + \\plumb to web + \\plumb start web $0 + \\ + \\type is text + \\data matches '[a-zA-Z\x80-\xf40-9_\-./]+' + \\data matches '([a-zA-Z\x80-\xf40-9_\-./]+)\.(doc|rtf)' + \\arg isfile $0 + \\plumb to msword + \\plumb start wdoc2txt $file + \\ + \\type is text + \\dst is msword + \\plumb to msword + \\plumb start wdoc2txt $file + \\ + \\type is text + \\data matches '[a-zA-Z\x80-\xf40-9_\-./@]+' + \\data matches '([a-zA-Z\x80-\xf40-9_\-./@]+)\.(jpe?g|JPE?G|gif|GIF|tiff?|TIFF?|ppm|bit|png|PNG)' + \\arg isfile $0 + \\plumb to image + \\plumb start 9 page $file + \\ + \\type is text + \\data matches '[a-zA-Z\x80-\xf40-9_\-./@]+' + \\data matches '([a-zA-Z\x80-\xf40-9_\-./@]+)\.(ps|PS|eps|EPS|pdf|PDF|dvi|DVI)' + \\arg isfile $0 + \\plumb to postscript + \\plumb start 9 page $file + \\ + \\data matches '[a-zA-Z\x80-\xf40-9_\-./@]+' + \\data matches '([a-zA-Z\x80-\xf40-9_\-./@]+)\.([Ss][XxTt][CcDdIiGgMmWw]|[Dd][Oo][Cc]|[Xx][Ll][Ss]|[Pp][Pp][Tt])' + \\arg isfile $0 + \\plumb to openoffice + \\plumb start openoffice $file + \\ + \\type is text + \\data matches '[a-zA-Z\x80-\xf40-9_\-./]+' + \\data matches '/mail/fs/[a-zA-Z\x80-\xf40-9/]+/[0-9]+' + \\plumb to showmail + \\plumb start window -r 4 120 750 600 upas/nedmail -s $0 + \\ + \\type is text + \\data matches '[a-zA-Z0-9_+.\-]+@[a-zA-Z0-9_+.\-]*' + \\plumb to sendmail + \\plumb start wmail $0 + \\ + \\dst is image + \\arg isfile $data + \\plumb to image + \\plumb start 9 page $data + \\ + \\dst is postscript + \\arg isfile $data + \\plumb start 9 page $data + \\ + ; + const printed = try reread(arena.allocator(), p9p); + try testing.expect(std.mem.startsWith(u8, printed, "addrelem='((#?[0-9]+)|(/[A-Za-z0-9_\\^]+/?)|[.$])'\n\naddr=:($addrelem([,;+\\-]$addrelem)*)\n\nplumb\tto\tseemail\n")); + try testing.expectEqualStrings(printed, try reread(arena.allocator(), printed)); + const p = try Pardes.init(testing.allocator, .{ .cols = 80, .rows = 24 }); + defer p.deinit(); + // Clicked in a line: the URL's run, the mail address's, and the + // faces' path, whole runes of a name that is not ASCII. + const url = try tryRules(p, p9p, .{ .type = "text", .attr = "click=10", .data = "see https://9fans.github.io/plan9port/ now" }); + try testing.expectEqual(@as(?usize, 0), url.set); + try testing.expectEqualStrings("https://9fans.github.io/plan9port/", url.m.data); + try testing.expectEqualStrings("web", url.m.dst); + const mail = try tryRules(p, p9p, .{ .type = "text", .attr = "click=12", .data = "write to gs@example.org." }); + try testing.expectEqualStrings("sendmail", mail.m.dst); + try testing.expectEqualStrings("gs@example.org.", mail.m.data); + const face = try tryRules(p, p9p, .{ .type = "text", .attr = "click=3", .data = "x /mail/fs/café/12 y" }); + try testing.expectEqualStrings("showmail", face.m.dst); + try testing.expectEqualStrings("/mail/fs/café/12", face.m.data); + // An image named in UTF-8, and Pike's horse.gift, by the image set's + // two patterns alone. + const pics = "data matches '[a-zA-Z\\x80-\\xf40-9_\\-./@]+'\ndata matches '([a-zA-Z\\x80-\\xf40-9_\\-./@]+)\\.(jpe?g|gif|png)'\nplumb to image\n"; + try testing.expectEqualStrings("Ångström.png", (try tryRules(p, pics, .{ .attr = "click=2", .data = "Ångström.png" })).m.data); + try testing.expect((try tryRules(p, pics, .{ .attr = "click=2", .data = "horse.gift" })).set == null); + // The rune range as written is refused, in regexp.zig's words. + try testing.expectEqualStrings("t:1: bad regular expression: a range of runes wider than 256 in [...] is not supported", try reread(arena.allocator(), "data matches '[a-zA-Z¡-￿0-9_\\-./]+'\nplumb to edit\n")); +} diff --git a/src/config.zig b/src/config.zig index 3a846206..8a1528a8 100644 --- a/src/config.zig +++ b/src/config.zig @@ -1818,6 +1818,7 @@ test "reference.typ's #fstree is the tree the session serves, file for file" { for (std.enums.values(tree.TopFile)) |f| switch (f) { .root => {}, .new => try served.put(gpa, "pane/new", {}), + .rules, .send => try served.put(gpa, try std.fmt.allocPrint(gpa, "plumb/{s}", .{f.fileName()}), {}), else => try served.put(gpa, if (f.dir()) try std.fmt.allocPrint(gpa, "{s}/", .{f.fileName()}) else f.fileName(), {}), }; try served.put(gpa, "os/", {}); diff --git a/src/exec.zig b/src/exec.zig index df578d08..43ea4617 100644 --- a/src/exec.zig +++ b/src/exec.zig @@ -726,7 +726,7 @@ pub fn executeFrom(p: *Pardes, id: usize, txt: []const u8, from_body: bool) ?usi /// is done, else a new one, placed as layout.placeNew places a command pane. /// A pane reused keeps what it showed: the new command runs below a line /// naming it, as acme appends to +Errors and never clears it (util.c:213). -fn runCommand(p: *Pardes, from: usize, line: []const u8) ?usize { +pub fn runCommand(p: *Pardes, from: usize, line: []const u8) ?usize { if (line.len > command_max) { p.reportFailure(from, "exec: a command line is at most 1024 bytes"); return null; @@ -749,7 +749,7 @@ fn runCommand(p: *Pardes, from: usize, line: []const u8) ?usize { // Nor one leased: an open that was answered its serial and is still // open reads that pane's output, which another client's command must // not replace; a new pane runs it instead. - const reuse: ?usize = if (!p.exec_header and p.exec_column == null and src != null and src.?.command != null and src.?.command_done and !src.?.command_pty and !leased(p, src.?.serial)) from else for (p.panes, 0..) |slot, i| { + const reuse: ?usize = if (!p.exec_header and p.exec_column == null and p.exec_dir == null and src != null and src.?.command != null and src.?.command_done and !src.?.command_pty and !leased(p, src.?.serial)) from else for (p.panes, 0..) |slot, i| { const other = slot orelse continue; if (p.exec_column) |c| if (if (layout.findPane(p, i)) |f| f.col != c else true) continue; if (other.command != null and other.command_done and !other.command_pty and std.mem.eql(u8, other.cwdSlice(), dir) and !leased(p, other.serial)) break i; diff --git a/src/fs-help.txt b/src/fs-help.txt index bc699418..1155ae1f 100644 --- a/src/fs-help.txt +++ b/src/fs-help.txt @@ -19,11 +19,11 @@ recent files opened lately, closed ones too: open|closed dumps the dumps the state file keeps, the newest first: