screen: when expanding cols, broadcast empty styled cells

This commit is contained in:
Mitchell Hashimoto
2023-03-01 17:24:24 -08:00
parent 89138cf7e3
commit 31ac3ec7ba

View File

@ -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;