summaryrefslogtreecommitdiff
path: root/src/dump.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/dump.zig')
-rw-r--r--src/dump.zig44
1 files changed, 27 insertions, 17 deletions
diff --git a/src/dump.zig b/src/dump.zig
index a880c7e1..31765836 100644
--- a/src/dump.zig
+++ b/src/dump.zig
@@ -74,7 +74,7 @@ pub var terminal_gpa: ?std.mem.Allocator = null;
//
// A dump is everything the session is but what is the host's, the frame's
// or worked out again: its panes with their text and undo, terminals with
-// their screens, history and kitty images (ghostty's snapshot), registers,
+// their screens, history and kitty images (the emulator's snapshot), registers,
// places, tags, layout and settings. It crosses builds: its fields are
// matched by name. It is an image (Db.zig): a database in memory the walk
// writes by name (walk.Put), which the state file keeps under a label,
@@ -490,10 +490,8 @@ fn loadImage(gpa: std.mem.Allocator, opts: Options, bytes: []const u8, notes: ?*
/// build's dump could not give): a terminal, a new emulator for its shell.
fn ensureKind(p: *Pardes, pane: *pardes.panes.Pane) !void {
if (pane.terminal != null or pane.file != null or pane.addon != null or pane.pdf != null) return;
- const fresh = try pardes.panes.terminal.create(p.gpa, @max(1, pane.cols), @max(1, pane.rows));
- pane.terminal = fresh.terminal;
- fresh.terminal = null;
- p.gpa.destroy(fresh);
+ if (pardes.tape.authorityOnly("open a terminal")) return error.OutOfMemory;
+ pane.terminal = try pardes.Term.open(pardes.panes.emulatorGpa(p.gpa), @max(1, pane.cols), @max(1, pane.rows));
}
/// The panes a column lists that are not there (another build's dump left
@@ -660,7 +658,18 @@ fn revivePane(p: *Pardes, id: usize, pane: *pardes.panes.Pane, was_on_disk: bool
}
if (comptime isolated) return;
if (pane.cwdSlice().len > effect_path_cap) return;
- pardes.panes.terminal.reviveShell(pane);
+ // Its shell not there, made ready for a new one: what the old
+ // shell was, ran and said is gone with it (the REPL it ran, the
+ // Term+ word naming it), and the pane waits for the new one like
+ // any new terminal (a line queued for the old one goes to it).
+ pardes.Term.revive(pane.terminal.?);
+ pane.shell_spoke = false;
+ pane.had_shell = false;
+ pane.shell_failed = false;
+ pane.shell_tail_len = 0;
+ pane.repl = null;
+ pane.sent_command = null;
+ pane.pending_command.wait = .spawn;
p.emitSpawn(id, pane.serial, pane.cwdSlice());
return;
}
@@ -719,7 +728,7 @@ pub fn savePane(gpa: std.mem.Allocator, pane: *pardes.panes.Pane, slim: bool) ![
pub fn loadPane(p: *Pardes, id: usize, bytes: []const u8) !*pardes.panes.Pane {
var l = try walk.Load(&.{pardes.panes.Pane}).init(p.gpa, bytes);
defer l.deinit();
- l.allocs = .{ .image = p.image_gpa, .terminal = pardes.panes.terminal.emulatorGpa(p.gpa) };
+ l.allocs = .{ .image = p.image_gpa, .terminal = pardes.panes.emulatorGpa(p.gpa) };
const pane = try p.gpa.create(pardes.panes.Pane);
errdefer {
l.rollback();
@@ -989,19 +998,19 @@ test "a pane restored with unsaved text is asked about by Exit, Restore, Del and
test "a loaded terminal's history stays above its banner, the cursor where it was" {
if (comptime isolated) return error.SkipZigTest;
const gpa = std.testing.allocator;
- const term = pardes.panes.terminal;
const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 40, .rows = 12 });
defer p.deinit();
while (p.nextEffect()) |_| {}
- term.feedOutput(p, p.panes[0].?, "one\r\ntwo\r\n$ ");
- const before = term.gridCursor(p.panes[0].?);
+ p.panes[0].?.feedOutput(p, "one\r\ntwo\r\n$ ");
+ const before = pardes.Term.grid(p.panes[0].?.terminal);
try dumpState(p);
const loaded = try load(gpa, .{ .tty_only = true, .cols = 40, .rows = 12 }, p.dump_out.?, null);
defer loaded.deinit();
- try std.testing.expectEqual(before, term.gridCursor(loaded.panes[0].?));
+ const after = pardes.Term.grid(loaded.panes[0].?.terminal);
+ try std.testing.expectEqual([2]u16{ before.cursor_x, before.cursor_y }, [2]u16{ after.cursor_x, after.cursor_y });
const q = try initFromDump(gpa, .{ .tty_only = true, .cols = 40, .rows = 12 }, p.dump_out.?);
defer q.deinit();
- const text = try term.screenTextAlloc(q.panes[0].?, gpa);
+ const text = try pardes.Term.scrollback(q.panes[0].?.terminal, gpa);
defer gpa.free(text);
try std.testing.expect(std.mem.indexOf(u8, text, "one\ntwo\n") != null);
try std.testing.expect(std.mem.indexOf(u8, text, "two").? < std.mem.indexOf(u8, text, "restored history").?);
@@ -1010,11 +1019,10 @@ test "a loaded terminal's history stays above its banner, the cursor where it wa
test "an upgraded session's dump keeps its views and its running terminal as they were, and settings the startup config would change" {
if (comptime isolated) return error.SkipZigTest;
const gpa = std.testing.allocator;
- const term = pardes.panes.terminal;
const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 40, .rows = 12, .startup_config = "Verbose off\n" });
defer p.deinit();
while (p.nextEffect()) |_| {}
- term.feedOutput(p, p.panes[0].?, "one\r\n\x1b[?1049h$ vim");
+ p.panes[0].?.feedOutput(p, "one\r\n\x1b[?1049h$ vim");
try std.testing.expect(p.executeBuiltinLine(p.view().active, "Verbose on"));
_ = p.openView().?;
const bytes = try dumpBytes(p);
@@ -1026,14 +1034,16 @@ test "an upgraded session's dump keeps its views and its running terminal as the
try std.testing.expectEqual(@as(usize, 2), views.count(q));
try std.testing.expect(q.settings.verbose);
// The program's own screen, no banner, and no shell asked for.
- try std.testing.expectEqual(term.gridCursor(p.panes[0].?), term.gridCursor(q.panes[0].?));
- try std.testing.expect(q.panes[0].?.terminal.?.vt.screens.active_key == .alternate);
+ const was = pardes.Term.grid(p.panes[0].?.terminal);
+ const is = pardes.Term.grid(q.panes[0].?.terminal);
+ try std.testing.expectEqual([2]u16{ was.cursor_x, was.cursor_y }, [2]u16{ is.cursor_x, is.cursor_y });
+ try std.testing.expect(pardes.Term.modes(q.panes[0].?.terminal).alternate);
while (q.nextEffect()) |e| try std.testing.expect(e != .spawn);
// Not kept, the same terminal is a new shell's under its history.
kept[0] = false;
const r = try resumeFromDump(gpa, .{ .tty_only = true, .cols = 40, .rows = 12 }, bytes, &kept);
defer r.deinit();
- try std.testing.expect(r.panes[0].?.terminal.?.vt.screens.active_key == .primary);
+ try std.testing.expect(!pardes.Term.modes(r.panes[0].?.terminal).alternate);
}
test "a loaded session asks its host for its font again: a new process has only its built-in face" {