mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-06-02 18:08:11 +00:00
apprt: support a pwd change action
This commit is contained in:
@@ -856,6 +856,20 @@ pub fn handleMessage(self: *Surface, msg: Message) !void {
|
||||
},
|
||||
},
|
||||
|
||||
.pwd_change => |w| {
|
||||
defer w.deinit();
|
||||
|
||||
// We always allocate for this because we need to null-terminate.
|
||||
const str = try self.alloc.dupeZ(u8, w.slice());
|
||||
defer self.alloc.free(str);
|
||||
|
||||
try self.rt_app.performAction(
|
||||
.{ .surface = self },
|
||||
.pwd,
|
||||
.{ .pwd = str },
|
||||
);
|
||||
},
|
||||
|
||||
.close => self.close(),
|
||||
|
||||
// Close without confirmation.
|
||||
|
||||
@@ -151,6 +151,9 @@ pub const Action = union(Key) {
|
||||
/// Set the title of the target.
|
||||
set_title: SetTitle,
|
||||
|
||||
/// The current working directory has changed for the target terminal.
|
||||
pwd: Pwd,
|
||||
|
||||
/// Set the mouse cursor shape.
|
||||
mouse_shape: terminal.MouseShape,
|
||||
|
||||
@@ -215,6 +218,7 @@ pub const Action = union(Key) {
|
||||
render_inspector,
|
||||
desktop_notification,
|
||||
set_title,
|
||||
pwd,
|
||||
mouse_shape,
|
||||
mouse_visibility,
|
||||
mouse_over_link,
|
||||
@@ -417,6 +421,21 @@ pub const SetTitle = struct {
|
||||
}
|
||||
};
|
||||
|
||||
pub const Pwd = struct {
|
||||
pwd: [:0]const u8,
|
||||
|
||||
// Sync with: ghostty_action_set_pwd_s
|
||||
pub const C = extern struct {
|
||||
pwd: [*:0]const u8,
|
||||
};
|
||||
|
||||
pub fn cval(self: Pwd) C {
|
||||
return .{
|
||||
.pwd = self.pwd.ptr,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
/// The desktop notification to show.
|
||||
pub const DesktopNotification = struct {
|
||||
title: [:0]const u8,
|
||||
|
||||
@@ -224,6 +224,7 @@ pub const App = struct {
|
||||
.cell_size,
|
||||
.renderer_health,
|
||||
.color_change,
|
||||
.pwd,
|
||||
=> log.info("unimplemented action={}", .{action}),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -486,6 +486,7 @@ pub fn performAction(
|
||||
.render_inspector,
|
||||
.renderer_health,
|
||||
.color_change,
|
||||
.pwd,
|
||||
=> log.warn("unimplemented action={}", .{action}),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,6 +76,9 @@ pub const Message = union(enum) {
|
||||
color: terminal.color.RGB,
|
||||
},
|
||||
|
||||
/// The terminal has reported a change in the working directory.
|
||||
pwd_change: WriteReq,
|
||||
|
||||
pub const ReportTitleStyle = enum {
|
||||
csi_21_t,
|
||||
|
||||
|
||||
@@ -1123,6 +1123,14 @@ pub const StreamHandler = struct {
|
||||
log.debug("terminal pwd: {s}", .{path});
|
||||
try self.terminal.setPwd(path);
|
||||
|
||||
// Report it to the surface. If creating our write request fails
|
||||
// then we just ignore it.
|
||||
if (apprt.surface.Message.WriteReq.init(self.alloc, path)) |req| {
|
||||
self.surfaceMessageWriter(.{ .pwd_change = req });
|
||||
} else |err| {
|
||||
log.warn("error notifying surface of pwd change err={}", .{err});
|
||||
}
|
||||
|
||||
// If we haven't seen a title, use our pwd as the title.
|
||||
if (!self.seen_title) {
|
||||
try self.changeWindowTitle(path);
|
||||
|
||||
Reference in New Issue
Block a user