terminal/new: port lots of no reflow screen resizes

This commit is contained in:
Mitchell Hashimoto
2024-03-01 13:30:05 -08:00
parent 9269d70f03
commit 2e21f2179d
3 changed files with 147 additions and 0 deletions

View File

@ -6116,6 +6116,7 @@ test "Screen: resize (no reflow) less rows trims blank lines" {
}
}
// X
test "Screen: resize (no reflow) more rows trims blank lines" {
const testing = std.testing;
const alloc = testing.allocator;
@ -6151,6 +6152,7 @@ test "Screen: resize (no reflow) more rows trims blank lines" {
}
}
// X
test "Screen: resize (no reflow) more cols" {
const testing = std.testing;
const alloc = testing.allocator;
@ -6168,6 +6170,7 @@ test "Screen: resize (no reflow) more cols" {
}
}
// X
test "Screen: resize (no reflow) less cols" {
const testing = std.testing;
const alloc = testing.allocator;
@ -6186,6 +6189,7 @@ test "Screen: resize (no reflow) less cols" {
}
}
// X
test "Screen: resize (no reflow) more rows with scrollback cursor end" {
const testing = std.testing;
const alloc = testing.allocator;
@ -6203,6 +6207,7 @@ test "Screen: resize (no reflow) more rows with scrollback cursor end" {
}
}
// X
test "Screen: resize (no reflow) less rows with scrollback" {
const testing = std.testing;
const alloc = testing.allocator;

View File

@ -1984,6 +1984,46 @@ test "PageList resize (no reflow) less rows trims blank lines" {
}
}
test "PageList resize (no reflow) more rows extends blank lines" {
const testing = std.testing;
const alloc = testing.allocator;
var s = try init(alloc, 10, 3, 0);
defer s.deinit();
try testing.expect(s.pages.first == s.pages.last);
const page = &s.pages.first.?.data;
// Write codepoint into first line
{
const rac = page.getRowAndCell(0, 0);
rac.cell.* = .{
.content_tag = .codepoint,
.content = .{ .codepoint = 'A' },
};
}
// Fill remaining lines with a background color
for (1..s.rows) |y| {
const rac = page.getRowAndCell(0, y);
rac.cell.* = .{
.content_tag = .bg_color_rgb,
.content = .{ .color_rgb = .{ .r = 0xFF, .g = 0, .b = 0 } },
};
}
// Resize
try s.resize(.{ .rows = 7, .reflow = false });
try testing.expectEqual(@as(usize, 7), s.rows);
try testing.expectEqual(@as(usize, 7), s.totalRows());
{
const pt = s.getCell(.{ .active = .{} }).?.screenPoint();
try testing.expectEqual(point.Point{ .screen = .{
.x = 0,
.y = 0,
} }, pt);
}
}
test "PageList resize (no reflow) less cols" {
const testing = std.testing;
const alloc = testing.allocator;

View File

@ -1869,3 +1869,105 @@ test "Screen: resize (no reflow) less rows trims blank lines" {
try testing.expectEqualStrings("1ABCD", contents);
}
}
test "Screen: resize (no reflow) more rows trims blank lines" {
const testing = std.testing;
const alloc = testing.allocator;
var s = try init(alloc, 10, 3, 0);
defer s.deinit();
const str = "1ABCD";
try s.testWriteString(str);
// Write only a background color into the remaining rows
for (1..s.pages.rows) |y| {
const list_cell = s.pages.getCell(.{ .active = .{ .x = 0, .y = y } }).?;
list_cell.cell.* = .{
.content_tag = .bg_color_rgb,
.content = .{ .color_rgb = .{ .r = 0xFF, .g = 0, .b = 0 } },
};
}
const cursor = s.cursor;
try s.resizeWithoutReflow(10, 7);
// Cursor should not move
try testing.expectEqual(cursor.x, s.cursor.x);
try testing.expectEqual(cursor.y, s.cursor.y);
{
const contents = try s.dumpStringAlloc(alloc, .{ .viewport = .{} });
defer alloc.free(contents);
try testing.expectEqualStrings("1ABCD", contents);
}
}
test "Screen: resize (no reflow) more cols" {
const testing = std.testing;
const alloc = testing.allocator;
var s = try init(alloc, 10, 3, 0);
defer s.deinit();
const str = "1ABCD\n2EFGH\n3IJKL";
try s.testWriteString(str);
try s.resizeWithoutReflow(20, 3);
{
const contents = try s.dumpStringAlloc(alloc, .{ .viewport = .{} });
defer alloc.free(contents);
try testing.expectEqualStrings(str, contents);
}
}
test "Screen: resize (no reflow) less cols" {
const testing = std.testing;
const alloc = testing.allocator;
var s = try init(alloc, 10, 3, 0);
defer s.deinit();
const str = "1ABCD\n2EFGH\n3IJKL";
try s.testWriteString(str);
try s.resizeWithoutReflow(4, 3);
{
const contents = try s.dumpStringAlloc(alloc, .{ .viewport = .{} });
defer alloc.free(contents);
const expected = "1ABC\n2EFG\n3IJK";
try testing.expectEqualStrings(expected, contents);
}
}
test "Screen: resize (no reflow) more rows with scrollback cursor end" {
const testing = std.testing;
const alloc = testing.allocator;
var s = try init(alloc, 7, 3, 2);
defer s.deinit();
const str = "1ABCD\n2EFGH\n3IJKL\n4ABCD\n5EFGH";
try s.testWriteString(str);
try s.resizeWithoutReflow(7, 10);
{
const contents = try s.dumpStringAlloc(alloc, .{ .viewport = .{} });
defer alloc.free(contents);
try testing.expectEqualStrings(str, contents);
}
}
test "Screen: resize (no reflow) less rows with scrollback" {
const testing = std.testing;
const alloc = testing.allocator;
var s = try init(alloc, 7, 3, 2);
defer s.deinit();
const str = "1ABCD\n2EFGH\n3IJKL\n4ABCD\n5EFGH";
try s.testWriteString(str);
try s.resizeWithoutReflow(7, 2);
{
const contents = try s.dumpStringAlloc(alloc, .{ .viewport = .{} });
defer alloc.free(contents);
const expected = "4ABCD\n5EFGH";
try testing.expectEqualStrings(expected, contents);
}
}