mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-14 15:56:13 +03:00
terminal: scrolling
This commit is contained in:
@ -30,4 +30,5 @@ test {
|
||||
// Libraries
|
||||
_ = @import("segmented_pool.zig");
|
||||
_ = @import("libuv/main.zig");
|
||||
_ = @import("terminal/main.zig");
|
||||
}
|
||||
|
@ -140,7 +140,7 @@ fn execute(self: *Terminal, alloc: Allocator, c: u8) !void {
|
||||
.BEL => self.bell(),
|
||||
.BS => self.backspace(),
|
||||
.HT => try self.horizontal_tab(alloc),
|
||||
.LF => self.linefeed(),
|
||||
.LF => self.linefeed(alloc),
|
||||
.CR => self.carriage_return(),
|
||||
}
|
||||
}
|
||||
@ -176,11 +176,36 @@ pub fn carriage_return(self: *Terminal) void {
|
||||
}
|
||||
|
||||
/// Linefeed moves the cursor to the next line.
|
||||
pub fn linefeed(self: *Terminal) void {
|
||||
// TODO: end of screen
|
||||
pub fn linefeed(self: *Terminal, alloc: Allocator) void {
|
||||
// If we're at the end of the screen, scroll up. This is surprisingly
|
||||
// common because most terminals live with a full screen so we do this
|
||||
// check first.
|
||||
if (self.cursor.y == self.rows - 1) {
|
||||
self.scroll_up(alloc);
|
||||
return;
|
||||
}
|
||||
|
||||
// Increase cursor by 1
|
||||
self.cursor.y += 1;
|
||||
}
|
||||
|
||||
/// Scroll the text up by one row.
|
||||
pub fn scroll_up(self: *Terminal, alloc: Allocator) void {
|
||||
// TODO: this is horribly expensive. we need to optimize the screen repr
|
||||
|
||||
// If we have no items, scrolling does nothing.
|
||||
if (self.screen.items.len == 0) return;
|
||||
|
||||
// Clear the first line
|
||||
self.screen.items[0].deinit(alloc);
|
||||
|
||||
var i: usize = 0;
|
||||
while (i < self.screen.items.len - 1) : (i += 1) {
|
||||
self.screen.items[i] = self.screen.items[i + 1];
|
||||
}
|
||||
self.screen.items.len -= 1;
|
||||
}
|
||||
|
||||
fn getOrPutCell(self: *Terminal, alloc: Allocator, x: usize, y: usize) !*Cell {
|
||||
// If we don't have enough lines to get to y, then add it.
|
||||
if (self.screen.items.len < y + 1) {
|
||||
|
11
src/terminal/main.zig
Normal file
11
src/terminal/main.zig
Normal file
@ -0,0 +1,11 @@
|
||||
pub const Terminal = @import("Terminal.zig");
|
||||
|
||||
// Not exported because they're just used for tests.
|
||||
|
||||
test {
|
||||
_ = Terminal;
|
||||
|
||||
_ = @import("parse_table.zig");
|
||||
_ = @import("Parser.zig");
|
||||
_ = @import("Tabstops.zig");
|
||||
}
|
Reference in New Issue
Block a user