mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-17 17:26:09 +03:00
terminal/new: more reflow less cols tests
This commit is contained in:
@ -7257,6 +7257,7 @@ test "Screen: resize less cols with reflow but row space" {
|
|||||||
try testing.expectEqual(@as(usize, 1), s.cursor.y);
|
try testing.expectEqual(@as(usize, 1), s.cursor.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// X
|
||||||
test "Screen: resize less cols with reflow with trimmed rows" {
|
test "Screen: resize less cols with reflow with trimmed rows" {
|
||||||
const testing = std.testing;
|
const testing = std.testing;
|
||||||
const alloc = testing.allocator;
|
const alloc = testing.allocator;
|
||||||
@ -7281,6 +7282,7 @@ test "Screen: resize less cols with reflow with trimmed rows" {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// X
|
||||||
test "Screen: resize less cols with reflow with trimmed rows and scrollback" {
|
test "Screen: resize less cols with reflow with trimmed rows and scrollback" {
|
||||||
const testing = std.testing;
|
const testing = std.testing;
|
||||||
const alloc = testing.allocator;
|
const alloc = testing.allocator;
|
||||||
@ -7305,6 +7307,7 @@ test "Screen: resize less cols with reflow with trimmed rows and scrollback" {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// X
|
||||||
test "Screen: resize less cols with reflow previously wrapped" {
|
test "Screen: resize less cols with reflow previously wrapped" {
|
||||||
const testing = std.testing;
|
const testing = std.testing;
|
||||||
const alloc = testing.allocator;
|
const alloc = testing.allocator;
|
||||||
|
@ -604,6 +604,7 @@ pub fn resize(
|
|||||||
.y = self.cursor.y,
|
.y = self.cursor.y,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const old_cols = self.pages.cols;
|
||||||
try self.pages.resize(.{
|
try self.pages.resize(.{
|
||||||
.rows = rows,
|
.rows = rows,
|
||||||
.cols = cols,
|
.cols = cols,
|
||||||
@ -611,6 +612,13 @@ pub fn resize(
|
|||||||
.cursor = &cursor,
|
.cursor = &cursor,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// If we have no scrollback and we shrunk our rows, we must explicitly
|
||||||
|
// erase our history. This is beacuse PageList always keeps at least
|
||||||
|
// a page size of history.
|
||||||
|
if (self.no_scrollback and cols < old_cols) {
|
||||||
|
self.pages.eraseRows(.{ .history = .{} }, null);
|
||||||
|
}
|
||||||
|
|
||||||
if (cursor.x != self.cursor.x or cursor.y != self.cursor.y) {
|
if (cursor.x != self.cursor.x or cursor.y != self.cursor.y) {
|
||||||
self.cursor.x = cursor.x;
|
self.cursor.x = cursor.x;
|
||||||
self.cursor.y = cursor.y;
|
self.cursor.y = cursor.y;
|
||||||
@ -2790,3 +2798,84 @@ test "Screen: resize less cols with reflow but row space" {
|
|||||||
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, 1), s.cursor.y);
|
try testing.expectEqual(@as(size.CellCountInt, 1), s.cursor.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test "Screen: resize less cols with reflow with trimmed rows" {
|
||||||
|
const testing = std.testing;
|
||||||
|
const alloc = testing.allocator;
|
||||||
|
|
||||||
|
var s = try init(alloc, 5, 3, 0);
|
||||||
|
defer s.deinit();
|
||||||
|
const str = "3IJKL\n4ABCD\n5EFGH";
|
||||||
|
try s.testWriteString(str);
|
||||||
|
try s.resize(3, 3);
|
||||||
|
|
||||||
|
{
|
||||||
|
const contents = try s.dumpStringAlloc(alloc, .{ .viewport = .{} });
|
||||||
|
defer alloc.free(contents);
|
||||||
|
const expected = "CD\n5EF\nGH";
|
||||||
|
try testing.expectEqualStrings(expected, contents);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
const contents = try s.dumpStringAlloc(alloc, .{ .screen = .{} });
|
||||||
|
defer alloc.free(contents);
|
||||||
|
const expected = "CD\n5EF\nGH";
|
||||||
|
try testing.expectEqualStrings(expected, contents);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
test "Screen: resize less cols with reflow with trimmed rows and scrollback" {
|
||||||
|
const testing = std.testing;
|
||||||
|
const alloc = testing.allocator;
|
||||||
|
|
||||||
|
var s = try init(alloc, 5, 3, 1);
|
||||||
|
defer s.deinit();
|
||||||
|
const str = "3IJKL\n4ABCD\n5EFGH";
|
||||||
|
try s.testWriteString(str);
|
||||||
|
try s.resize(3, 3);
|
||||||
|
|
||||||
|
{
|
||||||
|
const contents = try s.dumpStringAlloc(alloc, .{ .viewport = .{} });
|
||||||
|
defer alloc.free(contents);
|
||||||
|
const expected = "CD\n5EF\nGH";
|
||||||
|
try testing.expectEqualStrings(expected, contents);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
const contents = try s.dumpStringAlloc(alloc, .{ .screen = .{} });
|
||||||
|
defer alloc.free(contents);
|
||||||
|
const expected = "3IJ\nKL\n4AB\nCD\n5EF\nGH";
|
||||||
|
try testing.expectEqualStrings(expected, contents);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
test "Screen: resize less cols with reflow previously wrapped" {
|
||||||
|
const testing = std.testing;
|
||||||
|
const alloc = testing.allocator;
|
||||||
|
|
||||||
|
var s = try init(alloc, 5, 3, 0);
|
||||||
|
defer s.deinit();
|
||||||
|
const str = "3IJKL4ABCD5EFGH";
|
||||||
|
try s.testWriteString(str);
|
||||||
|
|
||||||
|
// Check
|
||||||
|
{
|
||||||
|
const contents = try s.dumpStringAlloc(alloc, .{ .screen = .{} });
|
||||||
|
defer alloc.free(contents);
|
||||||
|
const expected = "3IJKL\n4ABCD\n5EFGH";
|
||||||
|
try testing.expectEqualStrings(expected, contents);
|
||||||
|
}
|
||||||
|
|
||||||
|
try s.resize(3, 3);
|
||||||
|
|
||||||
|
// {
|
||||||
|
// const contents = try s.testString(alloc, .viewport);
|
||||||
|
// defer alloc.free(contents);
|
||||||
|
// const expected = "CD\n5EF\nGH";
|
||||||
|
// try testing.expectEqualStrings(expected, contents);
|
||||||
|
// }
|
||||||
|
{
|
||||||
|
const contents = try s.dumpStringAlloc(alloc, .{ .screen = .{} });
|
||||||
|
defer alloc.free(contents);
|
||||||
|
const expected = "ABC\nD5E\nFGH";
|
||||||
|
try testing.expectEqualStrings(expected, contents);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user