From 31ac3ec7ba26eb62d7841471b598bac10e63a2c7 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 1 Mar 2023 17:24:24 -0800 Subject: [PATCH] screen: when expanding cols, broadcast empty styled cells --- src/terminal/Screen.zig | 66 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 65 insertions(+), 1 deletion(-) diff --git a/src/terminal/Screen.zig b/src/terminal/Screen.zig index 7165749f3..757f84fd0 100644 --- a/src/terminal/Screen.zig +++ b/src/terminal/Screen.zig @@ -1894,8 +1894,19 @@ pub fn resize(self: *Screen, rows: usize, cols: usize) !void { new_cursor = .{ .y = self.rowsWritten() - 1, .x = cursor_pos.x }; } - // If no reflow, just keep going + // If no reflow, just keep going. if (!old_row.header().flags.wrap) { + // If we have no reflow, we attempt to extend any stylized + // cells at the end of the line if there is one. + const len = old_row.lenCells(); + const end = new_row.getCell(len - 1); + if ((end.char == 0 or end.char == ' ') and !end.empty()) { + for (len..self.cols) |x| { + const cell = new_row.getCellPtr(x); + cell.* = end; + } + } + y += 1; continue; } @@ -4050,6 +4061,59 @@ test "Screen: resize more cols no reflow" { } } +test "Screen: resize more cols trailing background colors" { + const testing = std.testing; + const alloc = testing.allocator; + + var s = try init(alloc, 3, 5, 0); + defer s.deinit(); + const str = "1AB"; + try s.testWriteString(str); + const cursor = s.cursor; + + // Color our cells red + const pen: Cell = .{ .bg = .{ .r = 0xFF }, .attrs = .{ .has_bg = true } }; + for (s.cursor.x..s.cols) |x| { + const row = s.getRow(.{ .active = s.cursor.y }); + const cell = row.getCellPtr(x); + cell.* = pen; + } + for ((s.cursor.y + 1)..s.rows) |y| { + const row = s.getRow(.{ .active = y }); + row.fill(pen); + } + + try s.resize(3, 10); + + // Cursor should not move + try testing.expectEqual(cursor, s.cursor); + + { + var contents = try s.testString(alloc, .viewport); + defer alloc.free(contents); + try testing.expectEqualStrings(str, contents); + } + { + var contents = try s.testString(alloc, .screen); + defer alloc.free(contents); + try testing.expectEqualStrings(str, contents); + } + + // Verify all our trailing cells have the color + for (s.cursor.x..s.cols) |x| { + const row = s.getRow(.{ .active = s.cursor.y }); + const cell = row.getCellPtr(x); + try testing.expectEqual(pen, cell.*); + } + for ((s.cursor.y + 1)..s.rows) |y| { + const row = s.getRow(.{ .active = y }); + for (0..s.cols) |x| { + const cell = row.getCellPtr(x); + try testing.expectEqual(pen, cell.*); + } + } +} + test "Screen: resize more cols grapheme map" { const testing = std.testing; const alloc = testing.allocator;