diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-10 09:22:10 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-10 09:29:11 -0300 |
| commit | e617ee11b6fafd48278ef0e371fa1981f8559413 (patch) | |
| tree | 106b973366d1905e38b009b8b5b1d3005b8eb4ba | |
| parent | 3eb166e287ec5afbd54b03a86711610e1b5269b6 (diff) | |
| download | pardes-e617ee11b6fafd48278ef0e371fa1981f8559413.tar.gz pardes-e617ee11b6fafd48278ef0e371fa1981f8559413.zip | |
history: a +History row reads `Restore <label>` before its date, size and panes, and a click on that Restore (an exec, or a look) is a Restore of that row's dump, exec.operandAt expanding the word to the label beside it as the row reads, where a bare Restore would have been this session's last dump; a look of the whole row reads past the word; the behaviour test clicks a row's Restore and looks at a row
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
| -rw-r--r-- | docs/typ/reference.typ | 7 | ||||
| -rw-r--r-- | src/Output.zig | 13 | ||||
| -rw-r--r-- | src/builtins.zig | 6 | ||||
| -rw-r--r-- | src/exec.zig | 8 | ||||
| -rw-r--r-- | src/look.zig | 11 | ||||
| -rw-r--r-- | test/behaviour/root_ctl.zig | 20 |
6 files changed, 45 insertions, 20 deletions
diff --git a/docs/typ/reference.typ b/docs/typ/reference.typ index 9afe002c..04a207e0 100644 --- a/docs/typ/reference.typ +++ b/docs/typ/reference.typ @@ -402,9 +402,10 @@ Writes take settings and session builtins (`scope = .session` in file's, read again), an undo history or a terminal's screen (a new shell starts in the directory); a session of shells alone leaves none. #word("History") (`SPC f h`) lists the state file's dumps in a `+History` - pane, the newest first, a row each: its label, date, size, pane count and - what its panes showed, a word each; a look at a row is a - #word("Restore") of its label. `Dump export <path>` writes the dump to a file of its own + pane, the newest first, a row each: `Restore <label>`, its date, size, + pane count and what its panes showed, a word each; a click on a row's + #word("Restore") (its exec, or a look at the row) is a #word("Restore") of + that dump. `Dump export <path>` writes the dump to a file of its own instead (`~` the home directory; the tag's word then names the path), which `-l <path>` and #word("Restore") `<path>` read: the way to carry a session to another machine. diff --git a/src/Output.zig b/src/Output.zig index c76e31b1..1bf1b453 100644 --- a/src/Output.zig +++ b/src/Output.zig @@ -571,13 +571,18 @@ pub fn openJumps(p: *Pardes, id: usize) !void { } /// The state file's dumps as rows (Db.listDumps: label, date, size, pane -/// count, the panes' names), the newest first; a look at a row is a -/// Restore of its label (look.zig). Asked of the authority: the state file -/// is its host's. +/// count, the panes' names), the newest first, each behind the `Restore` +/// that brings it back: an exec of a row's Restore takes the label beside +/// it (exec.operandAt), and a look at the row is the same (look.zig). +/// Asked of the authority: the state file is its host's. pub fn openHistory(p: *Pardes, id: usize) !void { const text = pardes.tape.authority(dumpsText, .{p}) orelse return error.NoStateFile; if (text.len == 0) return error.NoDumps; - try refillOrOpen(p, id, .{ .cmd = .History }, try p.gpa.dupe(u8, text)); + var out: std.Io.Writer.Allocating = .init(p.gpa); + errdefer out.deinit(); + var rows = std.mem.splitScalar(u8, std.mem.trimEnd(u8, text, "\n"), '\n'); + while (rows.next()) |row| try out.writer.print("Restore {s}\n", .{row}); + try refillOrOpen(p, id, .{ .cmd = .History }, try out.toOwnedSlice()); } /// Db.listDumps's text, the step's (scratch); null for no state file. diff --git a/src/builtins.zig b/src/builtins.zig index b715bae1..6214861d 100644 --- a/src/builtins.zig +++ b/src/builtins.zig @@ -1701,9 +1701,9 @@ pub const Recent = struct { }; /// List the state file's dumps, those Dump made and those every session's -/// end left (dump.dumpExit), the newest first: a row each, its label, -/// date, size, pane count and the panes' names; a look at a row is a -/// Restore of its label. +/// end left (dump.dumpExit), the newest first: a row each, `Restore +/// <label>`, date, size, pane count and the panes' names; a click on a +/// row's Restore (an exec, or a look at the row) is a Restore of its label. pub const History = struct { pub const scope: Scope = .session; pub const output: OutputTraits = .{ .name = config.history_buffer }; diff --git a/src/exec.zig b/src/exec.zig index 96902889..06752ffd 100644 --- a/src/exec.zig +++ b/src/exec.zig @@ -215,7 +215,13 @@ pub fn operandAt(p: *Pardes, pane: *Pane, clicked: Pane.Sel, borrow: bool, for_l const source_col: usize = @intCast(@max(0, col)); if (source_col < word_from or word_from > line.len) return result; const word = look.expandedWord(line[word_from..], source_col - word_from) orelse return result; - const b: look.ExpandedWord = .{ .lo = word.lo + word_from, .hi = word.hi + word_from }; + var b: look.ExpandedWord = .{ .lo = word.lo + word_from, .hi = word.hi + word_from }; + // A +History row's `Restore` is that row's: a click on it (an exec, + // or a look) takes the label beside it, as the row reads. + if (look.isHistoryList(pane) and std.mem.eql(u8, line[b.lo..b.hi], "Restore")) { + const rest = std.mem.trimStart(u8, line[b.hi..], " "); + if (std.mem.startsWith(u8, rest, "pardes-")) b.hi = (line.len - rest.len) + (std.mem.indexOfAny(u8, rest, " \t") orelse rest.len); + } const lo = std.math.cast(i32, b.lo) orelse return result; const hi = std.math.cast(i32, b.hi) orelse return result; result.text = line[b.lo..b.hi]; diff --git a/src/look.zig b/src/look.zig index 6ecebd41..95506d9c 100644 --- a/src/look.zig +++ b/src/look.zig @@ -1360,7 +1360,7 @@ fn isRecentList(pane: *const Pane) bool { } /// Whether `pane` is the History list, whose rows name dumps. -fn isHistoryList(pane: *const Pane) bool { +pub fn isHistoryList(pane: *const Pane) bool { const f = pane.file orelse return false; const o = f.output orelse return false; return std.meta.eql(o.from, panes.Output.Origin{ .cmd = .History }); @@ -1500,11 +1500,12 @@ pub fn lookAt(p: *Pardes, id: usize, operand_raw: []const u8) void { var home_buf: [4096]u8 = undefined; const stripped = std.mem.trim(u8, operand_raw, " \t\r\n"); const operand = if (stripped.len > 0 and stripped[0] == '~') filesystem.expandHome(stripped, &home_buf) else std.mem.trimEnd(u8, operand_raw, "\r\n"); - // A +History row names a dump of the state file's (its label, first): - // a look at it is a Restore of that dump; its other words are looked - // as any (a path in it opens). + // A +History row names a dump of the state file's (`Restore <label>`, + // then its date, size and panes): a look at it is a Restore of that + // dump; its other words are looked as any (a path in it opens). if (isHistoryList(pane)) { - const row = std.mem.trim(u8, operand, " \t\r\n"); + var row = std.mem.trim(u8, operand, " \t\r\n"); + if (std.mem.startsWith(u8, row, "Restore ")) row = std.mem.trimStart(u8, row["Restore ".len..], " "); const label = row[0 .. std.mem.indexOfAny(u8, row, " \t") orelse row.len]; if (std.mem.startsWith(u8, label, "pardes-")) return exec.runBuiltin(p, .Restore, id, "Restore", label); } diff --git a/test/behaviour/root_ctl.zig b/test/behaviour/root_ctl.zig index 1fa67206..a3379685 100644 --- a/test/behaviour/root_ctl.zig +++ b/test/behaviour/root_ctl.zig @@ -264,7 +264,7 @@ test "root-ctl: a Dump killed in the middle leaves the one before it whole, and try std.testing.expectEqual(@as(usize, 2), (try labels(&s)).len); } -test "root-ctl: a session's end leaves a slim dump the next session's History lists with the panes' names, a look at its row restores the file pane, and a session of shells alone leaves none" { +test "root-ctl: a session's end leaves a slim dump the next session's History lists as `Restore <label>` with the panes' names, a middle click on the Restore or a look at the row restores the file pane, and a session of shells alone leaves none" { var tmp = std.testing.tmpDir(.{}); defer tmp.cleanup(); var dir_buf: [std.fs.max_path_bytes]u8 = undefined; @@ -294,10 +294,22 @@ test "root-ctl: a session's end leaves a slim dump the next session's History li try s.write("/exec", "History\n"); const hist = std.mem.trimEnd(u8, try s.read("/exec"), "\n"); const body = try s.read(s.at("/pane/{s}/body", .{hist})); - try std.testing.expect(std.mem.startsWith(u8, body, listed[0])); + try std.testing.expect(std.mem.startsWith(u8, body, s.at("Restore {s} ", .{listed[0]}))); try std.testing.expect(has(body, "a.txt")); - // A look at the row: the dump restored, the file pane back with its text. - try s.write(s.at("/pane/{s}/look", .{hist}), body[0..std.mem.indexOfScalar(u8, body, '\n').?]); + // A middle click on the row's Restore: that row's dump restored, the + // file pane back with its text; a bare Restore would have been this + // session's last dump, of which there is none. + try s.click(s.at("Restore {s}", .{listed[0]}), 2, 2); try std.testing.expect(has(try s.read("/log"), s.at("restore {s}\n", .{listed[0]}))); try s.expect(s.at("/pane/{d}/body", .{try s.lookFile(s.at("{s}/a.txt", .{dir}))}), "kept on disk\n"); + // A look at the whole row is the same Restore. + try s.write("/exec", "History\n"); + const again = std.mem.trimEnd(u8, try s.read("/exec"), "\n"); + const row = try s.read(s.at("/pane/{s}/body", .{again})); + try s.write(s.at("/pane/{s}/look", .{again}), row[0..std.mem.indexOfScalar(u8, row, '\n').?]); + // The Restore replaced every pane, the +History among them, and the + // log starts over at a restore. + try std.testing.expect(has(try s.read("/log"), s.at("restore {s}\n", .{listed[0]}))); + try std.testing.expect(!has(try s.read("/index"), "+History")); + try s.expect(s.at("/pane/{d}/body", .{try s.lookFile(s.at("{s}/a.txt", .{dir}))}), "kept on disk\n"); } |
