From 3f9e3c39a40077ebd38d69336c46d37f67cb847f Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sun, 28 Apr 2024 10:26:41 -0700 Subject: [PATCH] terminal: track dirty state of palette and reverse colors --- src/terminal/Terminal.zig | 17 +++++++++++++++++ src/termio/Exec.zig | 9 ++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/terminal/Terminal.zig b/src/terminal/Terminal.zig index b83b9ff99..031a399fa 100644 --- a/src/terminal/Terminal.zig +++ b/src/terminal/Terminal.zig @@ -114,8 +114,25 @@ flags: packed struct { /// then we want to capture the shift key for the mouse protocol /// if the configuration allows it. mouse_shift_capture: enum(u2) { null, false, true } = .null, + + /// Dirty flags for the renderer. + dirty: Dirty = .{}, } = .{}, +/// This is a set of dirty flags the renderer can use to determine +/// what parts of the screen need to be redrawn. It is up to the renderer +/// to clear these flags. +/// +/// This only contains dirty flags for terminal state, not for the screen +/// state. The screen state has its own dirty flags. +pub const Dirty = packed struct { + /// Set when the color palette is modified in any way. + palette: bool = false, + + /// Set when the reverse colors mode is modified. + reverse_colors: bool = false, +}; + /// The event types that can be reported for mouse-related activities. /// These are all mutually exclusive (hence in a single enum). pub const MouseEvents = enum(u3) { diff --git a/src/termio/Exec.zig b/src/termio/Exec.zig index 1a044c25b..9d106f79d 100644 --- a/src/termio/Exec.zig +++ b/src/termio/Exec.zig @@ -397,6 +397,7 @@ pub fn changeConfig(self: *Exec, config: *DerivedConfig) !void { for (0..config.palette.len) |i| { if (!self.terminal.color_palette.mask.isSet(i)) { self.terminal.color_palette.colors[i] = config.palette[i]; + self.terminal.flags.dirty.palette = true; } } @@ -2166,7 +2167,10 @@ const StreamHandler = struct { .autorepeat => {}, // Schedule a render since we changed colors - .reverse_colors => try self.queueRender(), + .reverse_colors => { + self.terminal.flags.dirty.reverse_colors = true; + try self.queueRender(); + }, // Origin resets cursor pos. This is called whether or not // we're enabling or disabling origin mode and whether or @@ -2792,6 +2796,7 @@ const StreamHandler = struct { switch (kind) { .palette => |i| { + self.terminal.flags.dirty.palette = true; self.terminal.color_palette.colors[i] = color; self.terminal.color_palette.mask.set(i); }, @@ -2829,6 +2834,7 @@ const StreamHandler = struct { // reset those indices to the default palette var it = mask.iterator(.{}); while (it.next()) |i| { + self.terminal.flags.dirty.palette = true; self.terminal.color_palette.colors[i] = self.terminal.default_palette[i]; mask.unset(i); } @@ -2838,6 +2844,7 @@ const StreamHandler = struct { // Skip invalid parameters const i = std.fmt.parseUnsigned(u8, param, 10) catch continue; if (mask.isSet(i)) { + self.terminal.flags.dirty.palette = true; self.terminal.color_palette.colors[i] = self.terminal.default_palette[i]; mask.unset(i); }