Repository navigation
termio: add zmx backend for persistent terminal sessions #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 2 commits
72dc627
4eb974f
8b34709
9b5d9d0
e0ebec4
f7405f8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -478,6 +478,18 @@ pub const Surface = struct { | |||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| /// Userdata passed to io_write_cb. | ||||||||||||||||||||||||||||||||||||||||||||||||
| io_write_userdata: ?*anyopaque = null, | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| /// zmx session name. When non-null, the surface connects to a zmx | ||||||||||||||||||||||||||||||||||||||||||||||||
| /// daemon session instead of spawning a new shell process. | ||||||||||||||||||||||||||||||||||||||||||||||||
| zmx_session: ?[*:0]const u8 = null, | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| /// Whether to create the zmx session if it doesn't exist. | ||||||||||||||||||||||||||||||||||||||||||||||||
| zmx_create: bool = true, | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| /// Whether this surface should use zmx mode. When true and | ||||||||||||||||||||||||||||||||||||||||||||||||
| /// zmx_session is null, a session name is auto-generated. | ||||||||||||||||||||||||||||||||||||||||||||||||
| /// This is how zmx mode propagates across splits/tabs. | ||||||||||||||||||||||||||||||||||||||||||||||||
| zmx_mode: bool = false, | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+482
to
+492
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Clarify the empty-string contract in
📝 Suggested doc update- /// zmx session name. When non-null, the surface connects to a zmx
- /// daemon session instead of spawning a new shell process.
+ /// zmx session name. A non-empty value attaches to that zmx daemon
+ /// session instead of spawning a new shell process. An explicit empty
+ /// string clears any inherited session.
- /// Whether this surface should use zmx mode. When true and
- /// zmx_session is null, a session name is auto-generated.
+ /// Whether this surface should use zmx mode. When true and
+ /// zmx_session is null or empty, a session name is auto-generated.📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| pub fn init(self: *Surface, app: *App, opts: Options) !void { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -586,6 +598,22 @@ pub const Surface = struct { | |||||||||||||||||||||||||||||||||||||||||||||||
| config.@"wait-after-command" = true; | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| // zmx mode: explicit session name takes priority, then zmx_mode flag | ||||||||||||||||||||||||||||||||||||||||||||||||
| if (opts.zmx_session) |c_session| { | ||||||||||||||||||||||||||||||||||||||||||||||||
| const session = std.mem.sliceTo(c_session, 0); | ||||||||||||||||||||||||||||||||||||||||||||||||
| if (session.len > 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||
| config.@"zmx-session" = session; | ||||||||||||||||||||||||||||||||||||||||||||||||
| config.@"zmx-create" = opts.zmx_create; | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
| } else if (opts.zmx_mode) { | ||||||||||||||||||||||||||||||||||||||||||||||||
| // Inherited zmx mode — auto-generate a unique session name | ||||||||||||||||||||||||||||||||||||||||||||||||
| const zmx_alloc = config.arenaAlloc(); | ||||||||||||||||||||||||||||||||||||||||||||||||
| const uuid = std.crypto.random.int(u128); | ||||||||||||||||||||||||||||||||||||||||||||||||
| const session = try std.fmt.allocPrint(zmx_alloc, "cmux-{x}", .{uuid}); | ||||||||||||||||||||||||||||||||||||||||||||||||
| config.@"zmx-session" = session; | ||||||||||||||||||||||||||||||||||||||||||||||||
| config.@"zmx-create" = true; | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| // Initialize our surface right away. We're given a view that is | ||||||||||||||||||||||||||||||||||||||||||||||||
| // ready to use. | ||||||||||||||||||||||||||||||||||||||||||||||||
| try self.core_surface.init( | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -969,13 +997,19 @@ pub const Surface = struct { | |||||||||||||||||||||||||||||||||||||||||||||||
| break :wd self.app.core_app.alloc.dupeZ(u8, cwd) catch null; | ||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| // Inherit zmx mode: if this surface uses zmx, new surfaces should too. | ||||||||||||||||||||||||||||||||||||||||||||||||
| // Each new surface gets its own fresh zmx session (name auto-generated | ||||||||||||||||||||||||||||||||||||||||||||||||
| // in Surface.init when zmx_mode=true and zmx_session=null). | ||||||||||||||||||||||||||||||||||||||||||||||||
| const zmx_mode: bool = self.core_surface.io.backend == .zmx; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| return .{ | ||||||||||||||||||||||||||||||||||||||||||||||||
| .font_size = font_size, | ||||||||||||||||||||||||||||||||||||||||||||||||
| .working_directory = working_directory, | ||||||||||||||||||||||||||||||||||||||||||||||||
| .context = context, | ||||||||||||||||||||||||||||||||||||||||||||||||
| .io_mode = self.io_mode, | ||||||||||||||||||||||||||||||||||||||||||||||||
| .io_write_cb = self.io_write_cb, | ||||||||||||||||||||||||||||||||||||||||||||||||
| .io_write_userdata = self.io_write_userdata, | ||||||||||||||||||||||||||||||||||||||||||||||||
| .zmx_mode = zmx_mode, | ||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -1534,6 +1534,16 @@ class: ?[:0]const u8 = null, | |||||||||||||||||||||||||||
| /// * `inherit` - The working directory of the launching process. | ||||||||||||||||||||||||||||
| @"working-directory": ?[]const u8 = null, | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| /// Connect to a zmx daemon session instead of spawning a new shell process. | ||||||||||||||||||||||||||||
| /// When set, the surface connects to the named zmx session over a Unix | ||||||||||||||||||||||||||||
| /// domain socket. The zmx daemon owns the PTY and persists independently | ||||||||||||||||||||||||||||
| /// of the surface, enabling session persistence across restarts. | ||||||||||||||||||||||||||||
| @"zmx-session": ?[]const u8 = null, | ||||||||||||||||||||||||||||
|
Comment on lines
+1537
to
+1541
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Document the
Suggested wording-/// Connect to a zmx daemon session instead of spawning a new shell process.
-/// When set, the surface connects to the named zmx session over a Unix
+/// Prefer connecting to a zmx daemon session instead of spawning a new shell
+/// process.
+/// When set, the surface connects to the named zmx session over a Unix
/// domain socket. The zmx daemon owns the PTY and persists independently
/// of the surface, enabling session persistence across restarts.
+/// If zmx is unavailable, Ghostty falls back to the exec backend and logs
+/// a warning.
@"zmx-session": ?[]const u8 = null,📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| /// Whether to create the zmx session if it doesn't already exist. | ||||||||||||||||||||||||||||
| /// Only applies when `zmx-session` is set. Default: true. | ||||||||||||||||||||||||||||
| @"zmx-create": bool = true, | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| /// Key bindings. The format is `trigger=action`. Duplicate triggers will | ||||||||||||||||||||||||||||
| /// overwrite previously set values. The list of actions is available in | ||||||||||||||||||||||||||||
| /// the documentation or using the `ghostty +list-actions` command. | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.