summaryrefslogtreecommitdiff
path: root/term.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-06-29 17:25:43 -0300
committerGabriel Schneider <[email protected]>2026-06-29 19:14:37 -0300
commitfd095f7fa6e26fba3aa797d2b57740e776d3bb04 (patch)
tree17fa8c2a2e4bc26a691ae4912b8b8dd7e74f76fa /term.zig
parenta0ef7e5037505b211bab83fa18854204c5d66ba2 (diff)
downloadpardes-fd095f7fa6e26fba3aa797d2b57740e776d3bb04.tar.gz
pardes-fd095f7fa6e26fba3aa797d2b57740e776d3bb04.zip
vibes layout and multiple terminals
Diffstat (limited to 'term.zig')
-rw-r--r--term.zig43
1 files changed, 43 insertions, 0 deletions
diff --git a/term.zig b/term.zig
new file mode 100644
index 00000000..a69e8c4d
--- /dev/null
+++ b/term.zig
@@ -0,0 +1,43 @@
+const std = @import("std");
+const ghostty_vt = @import("ghostty-vt");
+
+/// One text selection (block-shaped), in pane-local coords; the row carries the
+/// scrollback offset. .none == nothing selected.
+pub const Sel = struct {
+ state: enum { none, dragging, done } = .none,
+ c0: i32 = 0,
+ c1: i32 = 0,
+ r0: i32 = 0,
+ r1: i32 = 0,
+};
+
+/// Persistent per-terminal state: the pty handle, the ghostty emulator and its
+/// (stateful) VT parser, the background reader task, plus its layout weight and
+/// text selection.
+///
+/// Heap-allocate these and never move them: `stream`'s handler holds a pointer
+/// back into `term`, so the address must stay stable for parser state split
+/// across pty reads to keep working.
+pub const Term = @This();
+
+pty: std.Io.File,
+term: ghostty_vt.Terminal,
+stream: ghostty_vt.TerminalStream,
+reader: std.Io.Future(anyerror!void),
+
+/// current emulator grid size; we only push a resize when it actually changes.
+cols: u16,
+rows: u16,
+
+/// vertical weight within the column (siblings split the column height by this).
+vweight: f32 = 1,
+
+/// One independent selection per mouse button: 0=left, 1=middle, 2=right.
+sel: [3]Sel = .{ .{}, .{}, .{} },
+
+pub fn deinit(self: *Term, io: std.Io, gpa: std.mem.Allocator) void {
+ _ = self.reader.cancel(io) catch {};
+ self.stream.deinit();
+ self.term.deinit(gpa);
+ self.pty.close(io);
+}