terminal/new: add scrollViewport

This commit is contained in:
Mitchell Hashimoto
2024-03-04 14:39:36 -08:00
parent 1f135f9d9e
commit ff4a0fce7f
2 changed files with 22 additions and 0 deletions

View File

@ -25,6 +25,7 @@ pub const CSI = Parser.Action.CSI;
pub const DCS = Parser.Action.DCS;
pub const MouseShape = @import("mouse_shape.zig").MouseShape;
pub const Terminal = @import("Terminal.zig");
//pub const Terminal = new.Terminal;
pub const Parser = @import("Parser.zig");
pub const Selection = @import("Selection.zig");
pub const Screen = @import("Screen.zig");

View File

@ -1195,6 +1195,27 @@ pub fn scrollUp(self: *Terminal, count: usize) void {
self.deleteLines(count);
}
/// Options for scrolling the viewport of the terminal grid.
pub const ScrollViewport = union(enum) {
/// Scroll to the top of the scrollback
top: void,
/// Scroll to the bottom, i.e. the top of the active area
bottom: void,
/// Scroll by some delta amount, up is negative.
delta: isize,
};
/// Scroll the viewport of the terminal grid.
pub fn scrollViewport(self: *Terminal, behavior: ScrollViewport) !void {
self.screen.scroll(switch (behavior) {
.top => .{ .top = {} },
.bottom => .{ .active = {} },
.delta => |delta| .{ .delta_row = delta },
});
}
/// Insert amount lines at the current cursor row. The contents of the line
/// at the current cursor row and below (to the bottom-most line in the
/// scrolling region) are shifted down by amount lines. The contents of the