summaryrefslogtreecommitdiff
path: root/runtime
diff options
context:
space:
mode:
Diffstat (limited to 'runtime')
-rw-r--r--runtime/upgrade.zig15
1 files changed, 11 insertions, 4 deletions
diff --git a/runtime/upgrade.zig b/runtime/upgrade.zig
index 510c50ea..b385556c 100644
--- a/runtime/upgrade.zig
+++ b/runtime/upgrade.zig
@@ -134,6 +134,10 @@ pub const Record = struct {
old: c_int = -1,
/// A window was open (the GUI).
window: bool = false,
+ /// Its size in points at the Upgrade, `WxH` (SDL_GetWindowSize then: the
+ /// user's since its start), the new window's `--geometry` (gui.zig).
+ /// None, an older build's record: the default.
+ size: ?[]const u8 = null,
ptys: [pardes.MAX_PANES]Pty = undefined,
nptys: usize = 0,
ttys: [pardes.views.max]Tty = undefined,
@@ -187,6 +191,7 @@ pub const Record = struct {
/// One `word value` a line, the dump's path last (its line is all of it).
pub fn encode(rec: *const Record, w: *std.Io.Writer) !void {
try w.print("link {d}\nstub {d}\nold {d}\nwindow {d}\n", .{ rec.link, rec.stub, rec.old, @intFromBool(rec.window) });
+ if (rec.size) |wh| try w.print("size {s}\n", .{wh});
for (rec.ptys[0..rec.nptys]) |p| try w.print("pty {d} {d} {d}\n", .{ p.pane, p.pid, p.fd });
for (rec.ttys[0..rec.nttys]) |t| try w.print("tty {d} {d} {d} {d} {x}\n", .{ t.view, t.fd, t.stub, @intFromBool(t.primary), std.mem.asBytes(&t.termios) });
if (rec.refused.len > 0) try w.print("refused {s}\n", .{rec.refused});
@@ -206,11 +211,12 @@ pub const Record = struct {
const rest = line[sp + 1 ..];
var it = std.mem.tokenizeScalar(u8, rest, ' ');
// A word of a later build's record is passed over.
- switch (std.meta.stringToEnum(enum { link, stub, old, window, pty, tty, refused, label, state, exe, dump }, word) orelse continue) {
+ switch (std.meta.stringToEnum(enum { link, stub, old, window, size, pty, tty, refused, label, state, exe, dump }, word) orelse continue) {
.link => rec.link = try std.fmt.parseInt(c_int, rest, 10),
.stub => rec.stub = try std.fmt.parseInt(c_int, rest, 10),
.old => rec.old = try std.fmt.parseInt(c_int, rest, 10),
.window => rec.window = std.mem.eql(u8, rest, "1"),
+ .size => rec.size = rest,
.pty => {
if (rec.nptys == rec.ptys.len) return error.BadRecord;
const pane = try std.fmt.parseInt(u8, it.next() orelse return error.BadRecord, 10);
@@ -474,7 +480,7 @@ pub fn load(gpa: std.mem.Allocator, core_gpa: std.mem.Allocator, opts: pardes.Op
}
test "an upgrade's record reads back as it was written, and refuses one cut short" {
- var rec: Record = .{ .link = 5, .stub = 7, .old = 9, .window = true, .exe = "/a b/pardes", .dump = "/home/u/.local/share/pardes/pardes.xitdb", .label = "upgrade-1", .state = .kept };
+ var rec: Record = .{ .link = 5, .stub = 7, .old = 9, .window = true, .size = "1402x1488", .exe = "/a b/pardes", .dump = "/home/u/.local/share/pardes/pardes.xitdb", .label = "upgrade-1", .state = .kept };
rec.addPty(3, 1234, 11);
rec.addPty(0, 99, 12);
var tio: posix.termios = std.mem.zeroes(posix.termios);
@@ -487,6 +493,7 @@ test "an upgrade's record reads back as it was written, and refuses one cut shor
try std.testing.expectEqual(@as(c_int, 5), back.link);
try std.testing.expectEqual(@as(c_int, 9), back.old);
try std.testing.expect(back.window);
+ try std.testing.expectEqualStrings("1402x1488", back.size.?);
try std.testing.expectEqual(@as(usize, 2), back.nptys);
try std.testing.expectEqual(Pty{ .pane = 3, .pid = 1234, .fd = 11 }, back.ptys[0]);
try std.testing.expectEqual(@as(usize, 1), back.nttys);
@@ -496,11 +503,11 @@ test "an upgrade's record reads back as it was written, and refuses one cut shor
try std.testing.expectEqualStrings("/home/u/.local/share/pardes/pardes.xitdb", back.dump);
try std.testing.expectEqualStrings("upgrade-1", back.label);
try std.testing.expectEqual(daemon.State.kept, back.state.?);
- // An older build's: its dump a file, no label, no state.
+ // An older build's: its dump a file, no label, no state, no size.
const older = try Record.decode("link 5\nexe /a\ndump /run/u/pardes-upgrade-1.dump\n");
try std.testing.expectEqualStrings("/run/u/pardes-upgrade-1.dump", older.dump);
try std.testing.expectEqualStrings("", older.label);
- try std.testing.expect(older.state == null);
+ try std.testing.expect(older.state == null and older.size == null);
try std.testing.expectError(error.BadRecord, Record.decode("link 5\n"));
try std.testing.expectError(error.BadRecord, Record.decode("tty 0 1 2 1 abc\ndump x\n"));
}