summaryrefslogtreecommitdiff
path: root/src/panes.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-17 00:06:42 -0300
committerGabriel Schneider <[email protected]>2026-11-17 12:15:01 -0300
commitc742d19d4bacbd9a91627c4859ca8cb0d11bdba7 (patch)
tree810036d05946b51dfadef508ee75f677303ba7c8 /src/panes.zig
parente4fbb97a506ca2a4b469b6e2e13ecba6e516272c (diff)
downloadpardes-c742d19d4bacbd9a91627c4859ca8cb0d11bdba7.tar.gz
pardes-c742d19d4bacbd9a91627c4859ca8cb0d11bdba7.zip
Term: the terminal as the core calls it, src/Term.zig, its lifecycle first (docs/next-terminal.md, Phase 0): Term.open makes an emulator and Term.close frees it, Term.due says when its next kitty frame is due, Term.revive resets a restored terminal's modes under its banner, Term.start and Term.stop run the PNG resize workers; the pane half of each is the core's: panes.createDoc and panes.createTerminal make the pane (the speculation guard there), emulatorGpa and emulator_gpa are the core's choice of allocator, teardownPane closes the emulator, dump.zig's revivePane resets what the old shell was and ensureKind opens an emulator straight into the pane; tape.authorityOnly is the one guard Kind.zig and the terminal both had a copy of; nothing else changes
Diffstat (limited to 'src/panes.zig')
-rw-r--r--src/panes.zig56
1 files changed, 49 insertions, 7 deletions
diff --git a/src/panes.zig b/src/panes.zig
index b03cd7cd..e1eb7e0e 100644
--- a/src/panes.zig
+++ b/src/panes.zig
@@ -109,7 +109,7 @@ pub const Pane = struct {
pub const Cwd = union(enum) { none, inherited: *Pane, owned: []u8 };
pub const Focus = enum { body, tag };
pub const SessionView = struct { wrap: bool = true, layered: bool = true, body_h: u32 = 0, tagline_h: u32 = 0, rect_h: u16 = 0 };
- terminal: ?*terminal.State = null,
+ terminal: ?*Term.State = null,
gpa: std.mem.Allocator,
serial: u32 = 0,
/// What the control filesystem keeps of this pane -- addr and limit, the
@@ -732,6 +732,43 @@ pub const mini = @import("mini.zig");
pub const terminal = @import("term/terminal.zig");
+pub const Term = @import("Term.zig");
+
+/// A pane with nothing in it yet, `cols` by `rows`: what a file, a
+/// directory, a kind's pane or a terminal is made from.
+pub fn createDoc(gpa: std.mem.Allocator, cols: u16, rows: u16) !*Pane {
+ const pane = try gpa.create(Pane);
+ pane.* = .{
+ .gpa = gpa,
+ .cols = cols,
+ .rows = rows,
+ };
+ return pane;
+}
+
+/// A terminal pane: a pane and its emulator. Slot ownership, serial
+/// assignment and spawn effects remain core lifecycle invariants.
+pub fn createTerminal(gpa: std.mem.Allocator, cols: u16, rows: u16) !*Pane {
+ if (tape.authorityOnly("open a terminal")) return error.OutOfMemory;
+ const pane = try createDoc(gpa, cols, rows);
+ errdefer gpa.destroy(pane);
+ pane.terminal = try Term.open(emulatorGpa(gpa), cols, rows);
+ pane.tty_filter = true;
+ return pane;
+}
+
+/// A screen-state replica's emulators' allocator (`Term.State.gpa`): the C
+/// heap, outside its rollback epoch: written by deltas while a copy is
+/// held, no part of it is ever a copy's to save or put back.
+pub const emulator_gpa = std.heap.c_allocator;
+
+/// What a terminal's emulator is made with, by `createTerminal` or a pane's
+/// load (dump.loadPane, a closed terminal brought back): `gpa`, but on a
+/// screen-state replica `emulator_gpa`.
+pub fn emulatorGpa(gpa: std.mem.Allocator) std.mem.Allocator {
+ return if (tape.screenReplica()) emulator_gpa else gpa;
+}
+
// ---- the session's pane slots: making, finding, closing and freeing panes, and their prompts ----
const tutor_text = @embedFile("tutor.txt");
@@ -813,7 +850,12 @@ pub fn teardownPane(p: *Pardes, pane: *Pane) void {
p.gpa.destroy(q);
pane.query = null;
}
- panes.terminal.deinitEmulator(pane, p.gpa);
+ // A pane with none (a file's, a picker's, a preview's) closes in a
+ // speculation as anywhere.
+ if (pane.terminal) |state| if (!tape.authorityOnly("close a terminal")) {
+ Term.close(state, p.gpa);
+ pane.terminal = null;
+ };
pane.clearCwd();
pane.fs.deinit(p.gpa);
p.gpa.destroy(pane);
@@ -846,7 +888,7 @@ pub fn installPane(p: *Pardes, id: usize, pane: *Pane) void {
pub fn newShell(p: *Pardes, id: usize, cwd: []const u8) !*Pane {
std.debug.assert(p.panes[id] == null);
if (cwd.len > limits.host_path_cap) return error.PathTooLong;
- const pane = try panes.terminal.create(p.gpa, p.view().screen_w, p.view().screen_h);
+ const pane = try panes.createTerminal(p.gpa, p.view().screen_w, p.view().screen_h);
// Named by the directory it is started in from the first, so the
// shell saying it is there is no rename (`new N /` then `rename`);
// out of memory for it, the shell names it when it says.
@@ -877,7 +919,7 @@ pub fn newCommand(p: *Pardes, id: usize, cwd: []const u8, line: []const u8) !*Pa
if (cwd.len > limits.host_path_cap) return error.PathTooLong;
const owned = try p.gpa.dupe(u8, line);
errdefer p.gpa.free(owned);
- const pane = try panes.terminal.create(p.gpa, p.view().screen_w, p.view().screen_h);
+ const pane = try panes.createTerminal(p.gpa, p.view().screen_w, p.view().screen_h);
pane.command = owned;
pane.command_pty = true;
pane.body.mode = .tty;
@@ -891,7 +933,7 @@ pub fn newCommand(p: *Pardes, id: usize, cwd: []const u8, line: []const u8) !*Pa
pub fn newDocPane(p: *Pardes, id: usize) !*Pane {
std.debug.assert(p.panes[id] == null);
- const pane = try panes.terminal.createDoc(p.gpa, p.view().screen_w, p.view().screen_h);
+ const pane = try panes.createDoc(p.gpa, p.view().screen_w, p.view().screen_h);
p.installPane(id, pane);
return pane;
}
@@ -942,7 +984,7 @@ pub fn paneBySerial(p: *Pardes, serial: u32) ?usize {
/// The pane a session word runs with in an empty window.
pub fn standIn(p: *Pardes) ?*Pane {
- if (p.stand_in == null) p.stand_in = panes.terminal.createDoc(p.gpa, p.view().screen_w, p.view().screen_h) catch null;
+ if (p.stand_in == null) p.stand_in = panes.createDoc(p.gpa, p.view().screen_w, p.view().screen_h) catch null;
return p.stand_in;
}
@@ -973,7 +1015,7 @@ pub fn setTestFile(p: *Pardes, content: []const u8) !*Pane {
errdefer p.gpa.free(path);
const history = try panes.File.History.create(p.gpa);
errdefer p.gpa.destroy(history);
- const pane = try panes.terminal.createDoc(p.gpa, v.screen_w, v.screen_h);
+ const pane = try panes.createDoc(p.gpa, v.screen_w, v.screen_h);
errdefer p.gpa.destroy(pane);
try deinitPane(p, p.panes[0].?);
p.panes[0] = null;