terminal: support mode 2031

This commit is contained in:
Mitchell Hashimoto
2024-02-02 13:08:10 -08:00
parent 258d51395c
commit 6fe8376073
2 changed files with 25 additions and 9 deletions

View File

@ -838,18 +838,21 @@ pub fn handleMessage(self: *Surface, msg: Message) !void {
.renderer_health => |health| self.updateRendererHealth(health),
.report_color_scheme => {
const output = switch (self.color_scheme) {
.light => "\x1B[?997;2n",
.dark => "\x1B[?997;1n",
};
_ = self.io_thread.mailbox.push(.{ .write_stable = output }, .{ .forever = {} });
try self.io_thread.wakeup.notify();
},
.report_color_scheme => try self.reportColorScheme(),
}
}
/// Sends a DSR response for the current color scheme to the pty.
fn reportColorScheme(self: *const Surface) !void {
const output = switch (self.color_scheme) {
.light => "\x1B[?997;2n",
.dark => "\x1B[?997;1n",
};
_ = self.io_thread.mailbox.push(.{ .write_stable = output }, .{ .forever = {} });
try self.io_thread.wakeup.notify();
}
/// Call this when modifiers change. This is safe to call even if modifiers
/// match the previous state.
///
@ -2804,7 +2807,19 @@ fn dragLeftClickBefore(
/// Call to notify Ghostty that the color scheme for the terminal has
/// changed.
pub fn colorSchemeCallback(self: *Surface, scheme: apprt.ColorScheme) !void {
// If our scheme didn't change, then we don't do anything.
if (self.color_scheme == scheme) return;
// Set our new scheme
self.color_scheme = scheme;
// If mode 2031 is on, then we report the change live.
const report = report: {
self.renderer_state.mutex.lock();
defer self.renderer_state.mutex.unlock();
break :report self.renderer_state.terminal.modes.get(.report_color_scheme);
};
if (report) try self.reportColorScheme();
}
fn posToViewport(self: Surface, xpos: f64, ypos: f64) terminal.point.Viewport {

View File

@ -215,6 +215,7 @@ const entries: []const ModeEntry = &.{
.{ .name = "bracketed_paste", .value = 2004 },
.{ .name = "synchronized_output", .value = 2026 },
.{ .name = "grapheme_cluster", .value = 2027 },
.{ .name = "report_color_scheme", .value = 2031 },
};
test {