From 880252fd1d432659ead8c51e7bdf202c3a9e1c62 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 13 Oct 2023 14:45:40 -0700 Subject: [PATCH] terminal: printing over wide spacer tail should clear wide char --- src/terminal/Terminal.zig | 44 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/src/terminal/Terminal.zig b/src/terminal/Terminal.zig index 8a0e0c7f2..d27e5c54f 100644 --- a/src/terminal/Terminal.zig +++ b/src/terminal/Terminal.zig @@ -821,9 +821,10 @@ fn printCell(self: *Terminal, unmapped_c: u21) *Screen.Cell { const x = self.screen.cursor.x - 1; const wide_cell = row.getCellPtr(x); + wide_cell.char = 0; wide_cell.attrs.wide = false; - if (self.screen.cursor.x <= 1) { + if (self.screen.cursor.y > 0 and self.screen.cursor.x <= 1) { self.clearWideSpacerHead(); } } @@ -2013,6 +2014,47 @@ test "Terminal: print over wide char at 0,0" { try testing.expectEqual(@as(usize, 0), t.screen.cursor.y); try testing.expectEqual(@as(usize, 1), t.screen.cursor.x); + + const row = t.screen.getRow(.{ .screen = 0 }); + { + const cell = row.getCell(0); + try testing.expectEqual(@as(u32, 'A'), cell.char); + try testing.expect(!cell.attrs.wide); + try testing.expectEqual(@as(usize, 1), row.codepointLen(0)); + } + { + const cell = row.getCell(1); + try testing.expect(!cell.attrs.wide_spacer_tail); + } +} + +test "Terminal: print over wide spacer tail" { + var t = try init(testing.allocator, 5, 5); + defer t.deinit(testing.allocator); + + try t.print('橋'); + t.setCursorPos(1, 2); + try t.print('X'); + + { + var str = try t.plainString(testing.allocator); + defer testing.allocator.free(str); + try testing.expectEqualStrings(" X", str); + } + + const row = t.screen.getRow(.{ .screen = 0 }); + { + const cell = row.getCell(0); + try testing.expectEqual(@as(u32, 0), cell.char); + try testing.expect(!cell.attrs.wide); + try testing.expectEqual(@as(usize, 1), row.codepointLen(0)); + } + { + const cell = row.getCell(1); + try testing.expectEqual(@as(u32, 'X'), cell.char); + try testing.expect(!cell.attrs.wide_spacer_tail); + try testing.expectEqual(@as(usize, 1), row.codepointLen(1)); + } } test "Terminal: print multicodepoint grapheme, disabled mode 2027" {