summaryrefslogtreecommitdiff
path: root/src/Store.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/Store.zig')
-rw-r--r--src/Store.zig46
1 files changed, 37 insertions, 9 deletions
diff --git a/src/Store.zig b/src/Store.zig
index 36215234..9c726705 100644
--- a/src/Store.zig
+++ b/src/Store.zig
@@ -468,6 +468,21 @@ fn unlist(s: *Store, gpa: std.mem.Allocator, serial: u32) void {
};
}
+/// A closed pane as Panes lists it: its serial and what its row shows.
+pub const Named = struct { serial: u32, name: []const u8 };
+
+/// This session's closed panes, the latest first (scratch; the names the
+/// store's): what a step lists of them (`tape.authority`).
+pub fn closedNames(p: *Pardes) []const Named {
+ const items = p.store.closed.items;
+ const out = p.scratch.allocator().alloc(Named, items.len) catch return &.{};
+ for (out, 0..) |*o, i| {
+ const c = items[items.len - 1 - i];
+ o.* = .{ .serial = c.serial, .name = c.name };
+ }
+ return out;
+}
+
/// The closed pane with this serial, if this session has it.
pub fn closedBySerial(s: *const Store, serial: u32) ?*Closed {
for (s.closed.items) |*c| if (c.serial == serial) return c;
@@ -785,12 +800,10 @@ fn compact(s: *Store, p: *Pardes, file: File, st: File.Stat, path: []const u8) v
/// from `from`. False when it is not this session's, or its record is gone
/// or bad; the keyboard on it otherwise.
pub fn reopen(s: *Store, p: *Pardes, serial: u32, from: usize) bool {
- s.refresh(p);
const gpa = p.recentGpa();
- const place = (s.closedBySerial(serial) orelse return false).*;
- const body = s.bodyOf(p, place) orelse return false;
- // Read from the file: this call's to free (`unlist` frees one held).
- defer if (place.body.len == 0) gpa.free(body);
+ // The store's: a replica has the authority's (`tape.authority`).
+ const place = pardes.tape.authority(record, .{ s, p, serial }) orelse return false;
+ const body = place.body;
const m = parseMeta(body) orelse return false;
const free = p.freeSlot() orelse {
p.reportError(from, "Panes", error.NoPaneSlots);
@@ -826,6 +839,21 @@ pub fn reopen(s: *Store, p: *Pardes, serial: u32, from: usize) bool {
return true;
}
+/// Where a closed pane goes back, and its record's body (scratch).
+pub const Record = struct { gainer: u32, below: bool, owner: u32, rows: u16, body: []const u8 };
+
+/// Closed pane `serial`'s record, the store read on first; null when it is
+/// not this session's, or its record is gone or bad.
+fn record(s: *Store, p: *Pardes, serial: u32) ?Record {
+ s.refresh(p);
+ const c = (s.closedBySerial(serial) orelse return null).*;
+ const body = s.bodyOf(p, c) orelse return null;
+ // Read from the file: this call's to free (`unlist` frees one held).
+ defer if (c.body.len == 0) p.recentGpa().free(body);
+ const copy = p.scratch.allocator().dupe(u8, body) catch return null;
+ return .{ .gainer = c.gainer, .below = c.below, .owner = c.owner, .rows = c.rows, .body = copy };
+}
+
/// A closed pane's record body: held here, or read from the file and
/// checked against its CRC (gpa; the caller frees it when it is not
/// `c.body`).
@@ -855,8 +883,9 @@ fn bodyOf(s: *Store, p: *Pardes, c: Closed) ?[]u8 {
return body;
}
-/// `@p<serial>` naming a pane this session closed: its serial.
-pub fn closedAddress(s: *const Store, word: []const u8) ?u32 {
+/// `@p<serial>` alone, the pane and no place in it: its serial, for a pane
+/// this session closed to come back by (`reopen` says whether it did).
+pub fn closedAddress(word: []const u8) ?u32 {
const addr = @import("config.zig").pane_addr;
if (!std.mem.startsWith(u8, word, addr)) return null;
const digits = word[addr.len..];
@@ -865,8 +894,7 @@ pub fn closedAddress(s: *const Store, word: []const u8) ?u32 {
} else digits.len;
// `@p7` alone, or `@p7:` with nothing after it: the pane, no place in it.
if (end == 0 or (end < digits.len and !(digits[end] == ':' and end + 1 == digits.len))) return null;
- const serial = std.fmt.parseInt(u32, digits[0..end], 10) catch return null;
- return if (s.closedBySerial(serial) != null) serial else null;
+ return std.fmt.parseInt(u32, digits[0..end], 10) catch null;
}
// ---- tests ----