From 46bbab5d10f0919982f0f2679f924dffc385f9a2 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 24 Aug 2022 13:48:22 -0700 Subject: [PATCH] ignore zero-width characters for now --- src/terminal/Screen.zig | 13 +++++++++++-- src/terminal/Terminal.zig | 6 +++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/terminal/Screen.zig b/src/terminal/Screen.zig index fa3890f5f..8feb335d3 100644 --- a/src/terminal/Screen.zig +++ b/src/terminal/Screen.zig @@ -63,8 +63,7 @@ pub const Cell = struct { bg: ?color.RGB = null, /// On/off attributes that can be set - /// TODO: pack it - attrs: struct { + attrs: packed struct { bold: u1 = 0, underline: u1 = 0, inverse: u1 = 0, @@ -82,12 +81,22 @@ pub const Cell = struct { /// wide character (tail) or following (head). wide_spacer_tail: u1 = 0, wide_spacer_head: u1 = 0, + + _padding: u1 = 0, } = .{}, /// True if the cell should be skipped for drawing pub fn empty(self: Cell) bool { return self.char == 0; } + + test { + // We use this test to ensure we always get the right size of the attrs + const cell: Cell = .{ .char = 0 }; + try std.testing.expectEqual(1, @sizeOf(@TypeOf(cell.attrs))); + + log.warn("CELL={}", .{@sizeOf(Cell)}); + } }; pub const RowIterator = struct { diff --git a/src/terminal/Terminal.zig b/src/terminal/Terminal.zig index 6e25a9f81..ee2629ea0 100644 --- a/src/terminal/Terminal.zig +++ b/src/terminal/Terminal.zig @@ -346,7 +346,11 @@ 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 = utf8proc.charwidth(c); - assert(width == 1 or width == 2); + assert(width <= 2); + + // For now, we ignore zero-width characters. When we support ligatures, + // this will have to change. + if (width == 0) return; // If we're soft-wrapping, then handle that first. if (self.screen.cursor.pending_wrap and self.modes.autowrap == 1)