summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Output.zig13
-rw-r--r--src/builtins.zig6
-rw-r--r--src/exec.zig8
-rw-r--r--src/look.zig11
4 files changed, 25 insertions, 13 deletions
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);
}