Commit 883b02d
David van Munster
·
2026-08-13 10:13:16 -0400 EDT
parent a959c5a
fix: write/reset osc 10/11/12 on attach/detach
2 files changed,
+26,
-2
+3,
-2
| ... | ... | @@ -1312,12 +1312,14 @@ fn attach(gpa: std.mem.Allocator, io: std.Io, daemon: *Daemon) !void { | |
| 1312 | 1312 | var orig_termios: cross.c.termios = undefined; | |
| 1313 | 1313 | const stdin_is_tty = cross.c.tcgetattr(lib_posix.STDIN_FILENO, &orig_termios) == 0; | |
| 1314 | 1314 | ||
| 1315 | + | // RIS, OSC 10/11/12 | |
| 1316 | + | const restore_seq = "\x1bc\x1b]110\x1b\\\x1b]111\x1b\\\x1b]112\x1b\\"; | |
| 1317 | + | ||
| 1315 | 1318 | defer { | |
| 1316 | 1319 | if (stdin_is_tty) { | |
| 1317 | 1320 | _ = cross.c.tcsetattr(lib_posix.STDIN_FILENO, cross.c.TCSAFLUSH, &orig_termios); | |
| 1318 | 1321 | } | |
| 1319 | 1322 | // Reset terminal modes on detach | |
| 1320 | - | const restore_seq = "\x1bc"; | |
| 1321 | 1323 | _ = lib_posix.write(lib_posix.STDOUT_FILENO, restore_seq) catch {}; | |
| 1322 | 1324 | } | |
| 1323 | 1325 |
| ... | ... | @@ -1350,7 +1352,6 @@ fn attach(gpa: std.mem.Allocator, io: std.Io, daemon: *Daemon) !void { | |
| 1350 | 1352 | .switch_session => { | |
| 1351 | 1353 | if (looper.session_name) |session_name| { | |
| 1352 | 1354 | // Reset terminal modes when switching sessions | |
| 1353 | - | const restore_seq = "\x1bc"; | |
| 1354 | 1355 | _ = lib_posix.write(lib_posix.STDOUT_FILENO, restore_seq) catch {}; | |
| 1355 | 1356 | ||
| 1356 | 1357 | const target_path = socket.getSocketPath( |
+23,
-0
| ... | ... | @@ -746,6 +746,26 @@ fn writePwd(writer: *std.Io.Writer, term: *const ghostty_vt.Terminal) void { | |
| 746 | 746 | }; | |
| 747 | 747 | } | |
| 748 | 748 | ||
| 749 | + | fn writeDynamicColor( | |
| 750 | + | writer: *std.Io.Writer, | |
| 751 | + | kind: ghostty_vt.color.Dynamic, | |
| 752 | + | dynamic: ghostty_vt.color.DynamicRGB, | |
| 753 | + | ) void { | |
| 754 | + | const c = dynamic.override orelse return; | |
| 755 | + | writer.print("\x1b]{d};rgb:{x:0>2}/{x:0>2}/{x:0>2}\x1b\\", .{ | |
| 756 | + | @intFromEnum(kind), c.r, c.g, c.b, | |
| 757 | + | }) catch |err| { | |
| 758 | + | std.log.warn("failed to format dynamic color err={s}", .{@errorName(err)}); | |
| 759 | + | }; | |
| 760 | + | } | |
| 761 | + | ||
| 762 | + | fn writeColorOverrides(writer: *std.Io.Writer, term: *const ghostty_vt.Terminal) void { | |
| 763 | + | const colors = &term.colors; | |
| 764 | + | writeDynamicColor(writer, .foreground, colors.foreground); | |
| 765 | + | writeDynamicColor(writer, .background, colors.background); | |
| 766 | + | writeDynamicColor(writer, .cursor, colors.cursor); | |
| 767 | + | } | |
| 768 | + | ||
| 749 | 769 | pub fn serializeTerminalState(alloc: std.mem.Allocator, term: *ghostty_vt.Terminal) ?[]const u8 { | |
| 750 | 770 | var builder: std.Io.Writer.Allocating = .init(alloc); | |
| 751 | 771 | defer builder.deinit(); |
| ... | ... | @@ -760,6 +780,9 @@ pub fn serializeTerminalState(alloc: std.mem.Allocator, term: *ghostty_vt.Termin | |
| 760 | 780 | term.modes.set(.synchronized_output, false); | |
| 761 | 781 | } | |
| 762 | 782 | ||
| 783 | + | // If state contains color override, restore it. | |
| 784 | + | writeColorOverrides(&builder.writer, term); | |
| 785 | + | ||
| 763 | 786 | const pages = &term.screens.active.pages; | |
| 764 | 787 | const screen_top = pages.getTopLeft(.screen); | |
| 765 | 788 | const active_top = pages.getTopLeft(.active); |