summaryrefslogtreecommitdiff
path: root/term.zig
diff options
context:
space:
mode:
Diffstat (limited to 'term.zig')
-rw-r--r--term.zig22
1 files changed, 20 insertions, 2 deletions
diff --git a/term.zig b/term.zig
index 307b116f..b0b424ee 100644
--- a/term.zig
+++ b/term.zig
@@ -14,6 +14,13 @@ pub const Sel = struct {
pub const EDIT_CAP = 128; // max chars in one insertion run
pub const MAX_EDITS = 16; // max concurrent insertion runs per window
+/// A file pane's backing state (see the `file` field below).
+pub const File = struct {
+ path: []const u8, // gpa-owned absolute path
+ content: []u8, // gpa-owned file bytes
+ scroll: usize = 0, // top visible file line
+};
+
/// A run of inserted ("char mode") text. `col` is the ORIGINAL tty column it is
/// spliced in *before* — the run shifts the underlying row right, it doesn't
/// overwrite. `row`/`col` are pane-local (row carries the BOX_H tag offset).
@@ -39,6 +46,12 @@ term: ghostty_vt.Terminal,
stream: ghostty_vt.TerminalStream,
reader: std.Io.Future(anyerror!void),
+/// When set, this pane is a (read/editable) text FILE view, not a terminal: its
+/// body comes from `content` instead of the emulator, and all the tty-specific
+/// handling (pty io, modes, prompt hiding) is skipped. Everything else — layout,
+/// selection, char-mode editing — is shared. pty.handle is -1, reader is a no-op.
+file: ?File = null,
+
/// current emulator grid size; we only push a resize when it actually changes.
cols: u16,
rows: u16,
@@ -67,8 +80,13 @@ nedits: usize = 0,
edits: [MAX_EDITS]Edit = @splat(.{}),
pub fn deinit(self: *Term, io: std.Io, gpa: std.mem.Allocator) void {
- _ = self.reader.cancel(io) catch {};
+ if (self.file) |f| {
+ gpa.free(f.path);
+ gpa.free(f.content);
+ } else {
+ _ = self.reader.cancel(io) catch {};
+ self.pty.close(io);
+ }
self.stream.deinit();
self.term.deinit(gpa);
- self.pty.close(io);
}