mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-16 00:36:07 +03:00
terminal/new: scrolling viewport
This commit is contained in:
@ -2747,6 +2747,7 @@ test "Terminal: disabled wraparound with wide grapheme and half space" {
|
||||
}
|
||||
}
|
||||
|
||||
// X
|
||||
test "Terminal: print writes to bottom if scrolled" {
|
||||
var t = try init(testing.allocator, 5, 2);
|
||||
defer t.deinit(testing.allocator);
|
||||
|
@ -214,6 +214,25 @@ pub fn cursorDownScroll(self: *Screen) !void {
|
||||
self.cursor.page_cell = page_rac.cell;
|
||||
}
|
||||
|
||||
/// Options for scrolling the viewport of the terminal grid. The reason
|
||||
/// we have this in addition to PageList.Scroll is because we have additional
|
||||
/// scroll behaviors that are not part of the PageList.Scroll enum.
|
||||
pub const Scroll = union(enum) {
|
||||
/// For all of these, see PageList.Scroll.
|
||||
active,
|
||||
top,
|
||||
delta_row: isize,
|
||||
};
|
||||
|
||||
/// Scroll the viewport of the terminal grid.
|
||||
pub fn scroll(self: *Screen, behavior: Scroll) void {
|
||||
switch (behavior) {
|
||||
.active => self.pages.scroll(.{ .active = {} }),
|
||||
.top => self.pages.scroll(.{ .top = {} }),
|
||||
.delta_row => |v| self.pages.scroll(.{ .delta_row = v }),
|
||||
}
|
||||
}
|
||||
|
||||
/// Dump the screen to a string. The writer given should be buffered;
|
||||
/// this function does not attempt to efficiently write and generally writes
|
||||
/// one byte at a time.
|
||||
|
@ -1394,6 +1394,43 @@ test "Terminal: overwrite grapheme should clear grapheme data" {
|
||||
}
|
||||
}
|
||||
|
||||
test "Terminal: print writes to bottom if scrolled" {
|
||||
var t = try init(testing.allocator, 5, 2);
|
||||
defer t.deinit(testing.allocator);
|
||||
|
||||
// Basic grid writing
|
||||
for ("hello") |c| try t.print(c);
|
||||
t.setCursorPos(0, 0);
|
||||
|
||||
// Make newlines so we create scrollback
|
||||
// 3 pushes hello off the screen
|
||||
try t.index();
|
||||
try t.index();
|
||||
try t.index();
|
||||
{
|
||||
const str = try t.plainString(testing.allocator);
|
||||
defer testing.allocator.free(str);
|
||||
try testing.expectEqualStrings("", str);
|
||||
}
|
||||
|
||||
// Scroll to the top
|
||||
t.screen.scroll(.{ .top = {} });
|
||||
{
|
||||
const str = try t.plainString(testing.allocator);
|
||||
defer testing.allocator.free(str);
|
||||
try testing.expectEqualStrings("hello", str);
|
||||
}
|
||||
|
||||
// Type
|
||||
try t.print('A');
|
||||
t.screen.scroll(.{ .active = {} });
|
||||
{
|
||||
const str = try t.plainString(testing.allocator);
|
||||
defer testing.allocator.free(str);
|
||||
try testing.expectEqualStrings("\nA", str);
|
||||
}
|
||||
}
|
||||
|
||||
test "Terminal: soft wrap" {
|
||||
var t = try init(testing.allocator, 3, 80);
|
||||
defer t.deinit(testing.allocator);
|
||||
|
Reference in New Issue
Block a user