terminal/new: screen resize stubs (don't work)

This commit is contained in:
Mitchell Hashimoto
2024-02-29 11:08:23 -08:00
parent e5cb77fe62
commit 43ad442ffe
2 changed files with 76 additions and 0 deletions

View File

@ -6035,6 +6035,7 @@ test "Screen: dirty with graphemes" {
} }
} }
// X
test "Screen: resize (no reflow) more rows" { test "Screen: resize (no reflow) more rows" {
const testing = std.testing; const testing = std.testing;
const alloc = testing.allocator; const alloc = testing.allocator;
@ -6061,6 +6062,7 @@ test "Screen: resize (no reflow) more rows" {
while (iter.next()) |row| try testing.expect(row.isDirty()); while (iter.next()) |row| try testing.expect(row.isDirty());
} }
// X
test "Screen: resize (no reflow) less rows" { test "Screen: resize (no reflow) less rows" {
const testing = std.testing; const testing = std.testing;
const alloc = testing.allocator; const alloc = testing.allocator;

View File

@ -564,6 +564,45 @@ fn blankCell(self: *const Screen) Cell {
return self.cursor.style.bgCell() orelse .{}; return self.cursor.style.bgCell() orelse .{};
} }
/// Resize the screen. The rows or cols can be bigger or smaller.
///
/// This will reflow soft-wrapped text. If the screen size is getting
/// smaller and the maximum scrollback size is exceeded, data will be
/// lost from the top of the scrollback.
pub fn resize(
self: *Screen,
cols: size.CellCountInt,
rows: size.CellCountInt,
) !void {
if (self.pages.cols == cols) {
// No resize necessary
if (self.pages.rows == rows) return;
// No matter what we mark our image state as dirty
self.kitty_images.dirty = true;
// If we have the same number of columns, text can't possibly
// reflow in any way, so we do the quicker thing and do a resize
// without reflow checks.
try self.resizeWithoutReflow(rows, cols);
return;
}
@panic("TODO");
}
/// Resize the screen without any reflow. In this mode, columns/rows will
/// be truncated as they are shrunk. If they are grown, the new space is filled
/// with zeros.
pub fn resizeWithoutReflow(
self: *Screen,
rows: size.CellCountInt,
cols: size.CellCountInt,
) !void {
// If we're resizing to the same size, do nothing.
if (self.pages.cols == cols and self.pages.rows == rows) return;
}
/// Set a style attribute for the current cursor. /// Set a style attribute for the current cursor.
/// ///
/// This can cause a page split if the current page cannot fit this style. /// This can cause a page split if the current page cannot fit this style.
@ -1764,3 +1803,38 @@ test "Screen: clear above cursor with history" {
try testing.expectEqual(@as(usize, 5), s.cursor.x); try testing.expectEqual(@as(usize, 5), s.cursor.x);
try testing.expectEqual(@as(usize, 2), s.cursor.y); try testing.expectEqual(@as(usize, 2), s.cursor.y);
} }
test "Screen: resize (no reflow) more rows" {
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);
// Resize
try s.resizeWithoutReflow(10, 10);
{
const contents = try s.dumpStringAlloc(alloc, .{ .viewport = .{} });
defer alloc.free(contents);
try testing.expectEqualStrings(str, contents);
}
}
// test "Screen: resize (no reflow) less rows" {
// 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(10, 2);
//
// {
// const contents = try s.dumpStringAlloc(alloc, .{ .viewport = .{} });
// defer alloc.free(contents);
// try testing.expectEqualStrings("2EFGH\n3IJKL", contents);
// }
// }