diff --git a/src/cell.zig b/src/cell.zig index 08260c1..9670382 100644 --- a/src/cell.zig +++ b/src/cell.zig @@ -6,6 +6,10 @@ pub const Cell = struct { pub const Character = struct { grapheme: []const u8 = " ", + /// width should only be provided when the application is sure the terminal + /// will meeasure the same width. This can be ensure by using the gwidth method + /// included in libvaxis. If width is 0, libvaxis will measure the glyph at + /// render time width: usize = 1, }; diff --git a/src/vaxis.zig b/src/vaxis.zig index b1a2b09..94d8128 100644 --- a/src/vaxis.zig +++ b/src/vaxis.zig @@ -294,8 +294,12 @@ pub fn Vaxis(comptime T: type) type { const cell = self.screen.buf[i]; defer { // advance by the width of this char mod 1 - const method: gwidth.Method = if (self.caps.unicode) .unicode else .wcwidth; - const w = gwidth.gwidth(cell.char.grapheme, method) catch 1; + const w = blk: { + if (cell.char.width != 0) break :blk cell.char.width; + + const method: gwidth.Method = if (self.caps.unicode) .unicode else .wcwidth; + break :blk gwidth.gwidth(cell.char.grapheme, method) catch 1; + }; var j = i + 1; while (j < i + w) : (j += 1) { self.screen_last.buf[j].skipped = true;