diff options
| author | Can Celik <ogulcancelik@gmail.com> | 2026-09-10 21:51:57 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-09-10 21:51:57 +0300 |
| commit | 425c86179791cd32e2d4ce0ae7f269940b4b0663 (patch) | |
| tree | e52c4383a6d69216cbe2a32638bf90841d7e2189 /vendor/libghostty-vt/src/cli/new_window.zig | |
| parent | 90e947a6e26e02f10ec7f1694c4eb5b78a86406b (diff) | |
chore: upgrade libghostty and preserve terminal behavior (#3906)
Diffstat (limited to 'vendor/libghostty-vt/src/cli/new_window.zig')
| -rw-r--r-- | vendor/libghostty-vt/src/cli/new_window.zig | 68 |
1 files changed, 50 insertions, 18 deletions
diff --git a/vendor/libghostty-vt/src/cli/new_window.zig b/vendor/libghostty-vt/src/cli/new_window.zig index a89c4ffa..29115a2e 100644 --- a/vendor/libghostty-vt/src/cli/new_window.zig +++ b/vendor/libghostty-vt/src/cli/new_window.zig @@ -5,10 +5,13 @@ const Action = @import("../cli.zig").ghostty.Action; const apprt = @import("../apprt.zig"); const args = @import("args.zig"); const diagnostics = @import("diagnostics.zig"); -const lib = @import("../lib/main.zig"); const homedir = @import("../os/homedir.zig"); +const global = @import("../global.zig"); pub const Options = struct { + /// We store an I/O implementation to make maintenance easier. + _io: std.Io, + /// This is set by the CLI parser for deinit. _arena: ?ArenaAllocator = null, @@ -26,8 +29,18 @@ pub const Options = struct { /// there is a "normal" config setting on the cli. _diagnostics: diagnostics.DiagnosticList = .{}, + pub const ParseManuallyHookError = error{InvalidValue} || + homedir.ExpandError || + std.Io.Dir.RealPathFileAllocError || + Allocator.Error; + /// Manual parse hook, collect all of the arguments after `+new-window`. - pub fn parseManuallyHook(self: *Options, alloc: Allocator, arg: []const u8, iter: anytype) (error{InvalidValue} || homedir.ExpandError || std.fs.Dir.RealPathAllocError || Allocator.Error)!bool { + pub fn parseManuallyHook( + self: *Options, + alloc: Allocator, + arg: []const u8, + iter: anytype, + ) ParseManuallyHookError!bool { var e_seen: bool = std.mem.eql(u8, arg, "-e"); // Include the argument that triggered the manual parse hook. @@ -50,21 +63,30 @@ pub const Options = struct { return false; } - fn checkArg(self: *Options, alloc: Allocator, arg: []const u8) (error{InvalidValue} || homedir.ExpandError || std.fs.Dir.RealPathAllocError || Allocator.Error)!?[:0]const u8 { - if (lib.cutPrefix(u8, arg, "--class=")) |rest| { + const CheckArgError = error{InvalidValue} || + homedir.ExpandError || + std.Io.Dir.RealPathFileAllocError || + Allocator.Error; + + fn checkArg(self: *Options, alloc: Allocator, arg: []const u8) CheckArgError!?[:0]const u8 { + if (std.mem.cutPrefix(u8, arg, "--class=")) |rest| { self.class = try alloc.dupeZ(u8, std.mem.trim(u8, rest, &std.ascii.whitespace)); return null; } - if (lib.cutPrefix(u8, arg, "--working-directory=")) |rest| { + if (std.mem.cutPrefix(u8, arg, "--working-directory=")) |rest| { const stripped = std.mem.trim(u8, rest, &std.ascii.whitespace); if (std.mem.eql(u8, stripped, "home")) return try alloc.dupeZ(u8, arg); if (std.mem.eql(u8, stripped, "inherit")) return try alloc.dupeZ(u8, arg); - const cwd: std.fs.Dir = std.fs.cwd(); + const cwd: std.Io.Dir = .cwd(); var expandhome_buf: [std.fs.max_path_bytes]u8 = undefined; - const expanded = try homedir.expandHome(stripped, &expandhome_buf); + const expanded = expanded: { + var environ_map = try global.environMap(); + defer environ_map.deinit(); + break :expanded try homedir.expandHome(global.io(), &environ_map, stripped, &expandhome_buf); + }; var realpath_buf: [std.fs.max_path_bytes]u8 = undefined; - const realpath = try cwd.realpath(expanded, &realpath_buf); + const realpath = realpath_buf[0..try cwd.realPathFile(self._io, expanded, &realpath_buf)]; self._working_directory_seen = true; return try std.fmt.allocPrintSentinel(alloc, "--working-directory={s}", .{realpath}, 0); } @@ -97,10 +119,11 @@ pub const Options = struct { /// `--class` flag) will be sent to the remote Ghostty instance and will be /// parsed as command line flags. These flags will override certain settings /// when creating the first surface in the new window. Currently, only -/// `--working-directory`, `--command`, and `--title` are supported. `-e` will -/// also work as an alias for `--command`, except that if `-e` is found on the -/// command line all following arguments will become part of the command and no -/// more arguments will be parsed for configuration settings. +/// `--working-directory`, `--command`, `--shell-integration=<mode>`, and +/// `--title` are supported. `-e` will also work as an alias for `--command`, except that if +/// `-e` is found on the command line all following arguments will become part +/// of the command and no more arguments will be parsed for configuration +/// settings. /// /// If `--working-directory` is found on the command line and is a relative /// path (i.e. doesn't start with `/`) it will be resolved to an absolute path @@ -136,6 +159,10 @@ pub const Options = struct { /// /// * `--command`: The command to be executed in the first surface of the new window. /// +/// * `--shell-integration=<mode>`: Whether to enable shell integration and +/// which shell to use. See the main configuration documentation for +/// supported values. +/// /// * `--working-directory=<directory>`: The working directory to pass to Ghostty. /// /// * `--title`: A title that will override the title of the first surface in @@ -147,11 +174,11 @@ pub const Options = struct { /// /// Available since: 1.2.0 pub fn run(alloc: Allocator) !u8 { - var iter = try args.argsIterator(alloc); + var iter = try args.argsIterator(alloc, global.args()); defer iter.deinit(); var buffer: [1024]u8 = undefined; - var stderr_writer = std.fs.File.stderr().writer(&buffer); + var stderr_writer = std.Io.File.stderr().writer(global.io(), &buffer); const stderr = &stderr_writer.interface; const result = runArgs(alloc, &iter, stderr); @@ -164,7 +191,7 @@ fn runArgs( argsIter: anytype, stderr: *std.Io.Writer, ) !u8 { - var opts: Options = .{}; + var opts: Options = .{ ._io = global.io() }; defer opts.deinit(); args.parse(Options, alloc_gpa, &opts, argsIter) catch |err| switch (err) { @@ -195,11 +222,16 @@ fn runArgs( if (!opts._working_directory_seen) { const alloc = opts._arena.?.allocator(); - const cwd: std.fs.Dir = std.fs.cwd(); + const cwd: std.Io.Dir = .cwd(); var buf: [std.fs.max_path_bytes]u8 = undefined; - const wd = try cwd.realpath(".", &buf); + const wd = buf[0..try cwd.realPathFile(global.io(), ".", &buf)]; // This should be inserted at the beginning of the list, just in case `-e` was used. - try opts._arguments.insert(alloc, 0, try std.fmt.allocPrintSentinel(alloc, "--working-directory={s}", .{wd}, 0)); + try opts._arguments.insert(alloc, 0, try std.fmt.allocPrintSentinel( + alloc, + "--working-directory={s}", + .{wd}, + 0, + )); } var arena = ArenaAllocator.init(alloc_gpa); |
