summaryrefslogtreecommitdiff
path: root/term.zig
diff options
context:
space:
mode:
Diffstat (limited to 'term.zig')
-rw-r--r--term.zig11
1 files changed, 10 insertions, 1 deletions
diff --git a/term.zig b/term.zig
index cb451b7c..7201c7c7 100644
--- a/term.zig
+++ b/term.zig
@@ -84,6 +84,8 @@ pub const EditSnap = struct {
cur_off: u16,
};
+pub const CwdOscState = enum { normal, esc, osc, osc7, collect, st_esc };
+
/// 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.
@@ -94,10 +96,15 @@ pub const EditSnap = struct {
pub const Term = @This();
pty: std.Io.File,
-pid: std.posix.pid_t, // the shell child; used to read /proc/<pid>/cwd for the tag
+pid: std.posix.pid_t, // shell child; Linux uses /proc/<pid>/cwd for live cwd tags
term: ghostty_vt.Terminal,
stream: ghostty_vt.TerminalStream,
reader: std.Io.Future(anyerror!void),
+/// Last known shell cwd for platforms without Linux procfs. macOS updates this
+/// from OSC 7 emitted by our shell rc; BSDs use the spawn cwd as a fallback.
+cwd: ?[]u8 = null,
+cwd_osc_state: CwdOscState = .normal,
+cwd_osc: std.ArrayList(u8) = .empty,
/// 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
@@ -196,6 +203,8 @@ pub fn deinit(self: *Term, io: std.Io, gpa: std.mem.Allocator) void {
self.pty.close(io);
}
self.tty_stream.deinit(gpa);
+ if (self.cwd) |cwd| gpa.free(cwd);
+ self.cwd_osc.deinit(gpa);
self.ed_undo.deinit(gpa);
self.ed_redo.deinit(gpa);
self.tag_tail.deinit(gpa);