From 779186adc0d8b79cc60ca580950d95634c79f76e Mon Sep 17 00:00:00 2001 From: Tim Culverhouse Date: Tue, 26 Sep 2023 05:02:14 -0500 Subject: [PATCH 1/2] config: add term config option Add a configuration key for the TERM environment variable. Default this to "ghostty". Most TEs are using their name as the default TERM value. Most modern termulators aren't even providing "xterm-" as an alias anymore, after some drama between kitty / ncurses. Notably, this also has issues for tcell-based applications (I've submitted a PR to tcell to fix) because it fails if the TERM value doesn't match the _primary_ name of the terminal in the terminfo file. Providing a config option allows users to modify-with-persistence if they have issues, but Ghostty should be known as Ghostty by default! --- src/config/Config.zig | 8 ++++++++ src/termio/Exec.zig | 4 +++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/config/Config.zig b/src/config/Config.zig index 16b465168..2891e24e9 100644 --- a/src/config/Config.zig +++ b/src/config/Config.zig @@ -411,6 +411,9 @@ keybind: Keybinds = .{}, /// Debug builds of Ghostty have a separate single-instance ID. @"gtk-single-instance": bool = true, +/// This will be used to set the TERM environment variable +term: []const u8 = "ghostty", + /// This is set by the CLI parser for deinit. _arena: ?ArenaAllocator = null, @@ -899,6 +902,11 @@ pub fn finalize(self: *Config) !void { } } + // Prevent setting TERM to an empty string + if (self.term.len == 0) { + self.term = "ghostty"; + } + // The default for the working directory depends on the system. const wd = self.@"working-directory" orelse switch (builtin.os.tag) { .macos => if (c.getppid() == 1) "home" else "inherit", diff --git a/src/termio/Exec.zig b/src/termio/Exec.zig index 974c1de1b..654dfae0b 100644 --- a/src/termio/Exec.zig +++ b/src/termio/Exec.zig @@ -91,6 +91,7 @@ pub const DerivedConfig = struct { foreground: configpkg.Config.Color, background: configpkg.Config.Color, osc_color_report_format: configpkg.Config.OSCColorReportFormat, + term: []const u8, pub fn init( alloc_gpa: Allocator, @@ -106,6 +107,7 @@ pub const DerivedConfig = struct { .foreground = config.foreground, .background = config.background, .osc_color_report_format = config.@"osc-color-report-format", + .term = config.term, }; } @@ -663,7 +665,7 @@ const Subprocess = struct { if (opts.resources_dir) |base| { var buf: [std.fs.MAX_PATH_BYTES]u8 = undefined; const dir = try std.fmt.bufPrint(&buf, "{s}/terminfo", .{base}); - try env.put("TERM", "xterm-ghostty"); + try env.put("TERM", opts.config.term); try env.put("COLORTERM", "truecolor"); try env.put("TERMINFO", dir); } else { From c77f0dc6fcf3b5f8bddd790ca2c623bc6f91f2cb Mon Sep 17 00:00:00 2001 From: Tim Culverhouse Date: Tue, 26 Sep 2023 06:42:42 -0500 Subject: [PATCH 2/2] terminfo: add cursor styles to terminfo Add Ss and Se definitions --- src/terminfo/ghostty.zig | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/terminfo/ghostty.zig b/src/terminfo/ghostty.zig index 42dd2fea7..5c78a6eb1 100644 --- a/src/terminfo/ghostty.zig +++ b/src/terminfo/ghostty.zig @@ -98,6 +98,12 @@ pub const ghostty: Source = .{ // Colored underlines .{ .name = "Setulc", .value = .{ .string = "\\E[58:2::%p1%{65536}%/%d:%p1%{256}%/%{255}%&%d:%p1%{255}%&%d%;m" } }, + // Cursor styles + .{ .name = "Ss", .value = .{ .string = "\\E[%p1%d q" } }, + + // Cursor style reset + .{ .name = "Se", .value = .{ .string = "\\E[2 q" } }, + // These are all capabilities that should be pretty straightforward // and map to input sequences. .{ .name = "bel", .value = .{ .string = "^G" } },