terminal/new: more resize more cols tests

This commit is contained in:
Mitchell Hashimoto
2024-03-02 21:56:36 -08:00
parent 839fae55f4
commit 7b70dd1338
3 changed files with 58 additions and 3 deletions

View File

@ -6513,6 +6513,12 @@ test "Screen: resize more cols perfect split" {
const str = "1ABCD2EFGH3IJKL"; const str = "1ABCD2EFGH3IJKL";
try s.testWriteString(str); try s.testWriteString(str);
try s.resize(3, 10); try s.resize(3, 10);
{
const contents = try s.testString(alloc, .screen);
defer alloc.free(contents);
try testing.expectEqualStrings("1ABCD2EFGH\n3IJKL", contents);
}
} }
// X // X
@ -6669,6 +6675,7 @@ test "Screen: resize more cols grapheme map" {
} }
} }
// X
test "Screen: resize more cols with reflow that fits full width" { test "Screen: resize more cols with reflow that fits full width" {
const testing = std.testing; const testing = std.testing;
const alloc = testing.allocator; const alloc = testing.allocator;

View File

@ -564,13 +564,14 @@ fn reflowPage(
} }
} }
src_cursor.cursorAbsolute(src_cursor.x, @intCast(src_y)); src_cursor.cursorAbsolute(0, @intCast(src_y));
for (src_cursor.x..src_cursor.page.size.cols) |src_x| { for (src_cursor.x..src_cursor.page.size.cols) |src_x| {
assert(src_cursor.x == src_x); assert(src_cursor.x == src_x);
if (dst_cursor.pending_wrap) { if (dst_cursor.pending_wrap) {
@panic("TODO"); dst_cursor.page_row.wrap = true;
dst_cursor.cursorScroll();
dst_cursor.page_row.wrap_continuation = true;
} }
switch (src_cursor.page_cell.content_tag) { switch (src_cursor.page_cell.content_tag) {

View File

@ -2224,6 +2224,12 @@ test "Screen: resize more cols perfect split" {
const str = "1ABCD2EFGH3IJKL"; const str = "1ABCD2EFGH3IJKL";
try s.testWriteString(str); try s.testWriteString(str);
try s.resize(10, 3); try s.resize(10, 3);
{
const contents = try s.dumpStringAlloc(alloc, .{ .screen = .{} });
defer alloc.free(contents);
try testing.expectEqualStrings("1ABCD2EFGH\n3IJKL", contents);
}
} }
// https://github.com/mitchellh/ghostty/issues/1159 // https://github.com/mitchellh/ghostty/issues/1159
@ -2258,3 +2264,44 @@ test "Screen: resize (no reflow) more cols with scrollback scrolled up" {
try testing.expectEqual(@as(size.CellCountInt, 1), s.cursor.x); try testing.expectEqual(@as(size.CellCountInt, 1), s.cursor.x);
try testing.expectEqual(@as(size.CellCountInt, 2), s.cursor.y); try testing.expectEqual(@as(size.CellCountInt, 2), s.cursor.y);
} }
test "Screen: resize more cols with reflow that fits full width" {
const testing = std.testing;
const alloc = testing.allocator;
var s = try init(alloc, 5, 3, 0);
defer s.deinit();
const str = "1ABCD2EFGH\n3IJKL";
try s.testWriteString(str);
// Verify we soft wrapped
{
const contents = try s.dumpStringAlloc(alloc, .{ .viewport = .{} });
defer alloc.free(contents);
const expected = "1ABCD\n2EFGH\n3IJKL";
try testing.expectEqualStrings(expected, contents);
}
// Let's put our cursor on row 2, where the soft wrap is
s.cursorAbsolute(0, 1);
{
const list_cell = s.pages.getCell(.{ .active = .{
.x = s.cursor.x,
.y = s.cursor.y,
} }).?;
try testing.expectEqual(@as(u21, '2'), list_cell.cell.content.codepoint);
}
// Resize and verify we undid the soft wrap because we have space now
try s.resize(10, 3);
{
const contents = try s.dumpStringAlloc(alloc, .{ .viewport = .{} });
defer alloc.free(contents);
try testing.expectEqualStrings(str, contents);
}
// Our cursor should've moved
// TODO
// try testing.expectEqual(@as(usize, 5), s.cursor.x);
// try testing.expectEqual(@as(usize, 0), s.cursor.y);
}