From 3c98c6375a8c253645f6d54b77b03114446da682 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 20 Nov 2023 19:55:06 -0800 Subject: [PATCH] terminal: handle width==3 glyphs by just pretending they're width 2 --- src/terminal/Terminal.zig | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/terminal/Terminal.zig b/src/terminal/Terminal.zig index 22a57a546..ff39370f9 100644 --- a/src/terminal/Terminal.zig +++ b/src/terminal/Terminal.zig @@ -770,7 +770,14 @@ pub fn print(self: *Terminal, c: u21) !void { // Determine the width of this character so we can handle // non-single-width characters properly. - const width: usize = @intCast(@max(0, ziglyph.display_width.codePointWidth(c, .half))); + const width: usize = @intCast(@min( + @max(0, ziglyph.display_width.codePointWidth(c, .half)), + 2, + )); + + // Note: it is possible to have a width of "3" and a width of "-1" + // from ziglyph. We should look into those cases and handle them + // appropriately. assert(width <= 2); // log.debug("c={x} width={}", .{ c, width });