diff --git a/src/config/Config.zig b/src/config/Config.zig index 4012c5cf8..a4604d465 100644 --- a/src/config/Config.zig +++ b/src/config/Config.zig @@ -208,7 +208,7 @@ const c = @cImport({ /// reset, this configuration will be used again. /// /// This configuration can be changed at runtime but will not affect existing -/// printed cells. Only new cells will use the new configuration. +/// terminals. Only new terminals will use the new configuration. @"grapheme-width-method": GraphemeWidthMethod = .unicode, /// A named theme to use. The available themes are currently hardcoded to the diff --git a/src/terminal/Terminal.zig b/src/terminal/Terminal.zig index bd30a9f1e..66643fbd9 100644 --- a/src/terminal/Terminal.zig +++ b/src/terminal/Terminal.zig @@ -119,9 +119,6 @@ flags: packed struct { /// then we want to capture the shift key for the mouse protocol /// if the configuration allows it. mouse_shift_capture: enum { null, false, true } = .null, - - /// If true, we perform grapheme clustering even if mode 2027 is disabled. - default_grapheme_cluster: bool = false, } = .{}, /// The event types that can be reported for mouse-related activities. @@ -746,10 +743,7 @@ pub fn print(self: *Terminal, c: u21) !void { // This is MUCH slower than the normal path so the conditional below is // purposely ordered in least-likely to most-likely so we can drop out // as quickly as possible. - if (c > 255 and - (self.modes.get(.grapheme_cluster) or self.flags.default_grapheme_cluster) and - self.screen.cursor.x > 0) - grapheme: { + if (c > 255 and self.modes.get(.grapheme_cluster) and self.screen.cursor.x > 0) grapheme: { const row = self.screen.getRow(.{ .active = self.screen.cursor.y }); // We need the previous cell to determine if we're at a grapheme @@ -891,9 +885,7 @@ pub fn print(self: *Terminal, c: u21) !void { // If we have grapheme clustering enabled, we don't blindly attach // any zero width character to our cells and we instead just ignore // it. - if (self.modes.get(.grapheme_cluster) or - self.flags.default_grapheme_cluster) - return; + if (self.modes.get(.grapheme_cluster)) return; // If we're at cell zero, then this is malformed data and we don't // print anything or even store this. Zero-width characters are ALWAYS diff --git a/src/termio/Exec.zig b/src/termio/Exec.zig index 1580309b1..e98365fd8 100644 --- a/src/termio/Exec.zig +++ b/src/termio/Exec.zig @@ -135,7 +135,13 @@ pub fn init(alloc: Allocator, opts: termio.Options) !Exec { errdefer term.deinit(alloc); term.default_palette = opts.config.palette; term.color_palette.colors = opts.config.palette; - term.flags.default_grapheme_cluster = opts.config.grapheme_width_method == .unicode; + + // Setup our initial grapheme cluster support if enabled. We use a + // switch to ensure we get a compiler error if more cases are added. + switch (opts.config.grapheme_width_method) { + .unicode => term.modes.set(.grapheme_cluster, true), + .wcswidth => {}, + } // Set the image size limits try term.screen.kitty_images.setLimit(alloc, opts.config.image_storage_limit); @@ -373,8 +379,6 @@ pub fn changeConfig(self: *Exec, config: *DerivedConfig) !void { // - command, working-directory: we never restart the underlying // process so we don't care or need to know about these. - self.terminal.flags.default_grapheme_cluster = config.grapheme_width_method == .unicode; - // Update the default palette. Note this will only apply to new colors drawn // since we decode all palette colors to RGB on usage. self.terminal.default_palette = config.palette;