mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-14 15:56:13 +03:00
terminal: implement resizing in a basic way
This commit is contained in:
@ -282,7 +282,8 @@ fn sizeCallback(window: glfw.Window, width: i32, height: i32) void {
|
|||||||
}) catch |err| log.err("error updating grid screen size err={}", .{err});
|
}) catch |err| log.err("error updating grid screen size err={}", .{err});
|
||||||
|
|
||||||
// Update the size of our terminal state
|
// Update the size of our terminal state
|
||||||
win.terminal.resize(win.grid.size.columns, win.grid.size.rows);
|
win.terminal.resize(win.alloc, win.grid.size.columns, win.grid.size.rows) catch |err|
|
||||||
|
log.err("error updating terminal size: {}", .{err});
|
||||||
|
|
||||||
// Update the size of our pty
|
// Update the size of our pty
|
||||||
win.pty.setSize(.{
|
win.pty.setSize(.{
|
||||||
|
@ -100,6 +100,7 @@ pub fn get(self: Tabstops, col: usize) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Resize this to support up to cols columns.
|
/// Resize this to support up to cols columns.
|
||||||
|
// TODO: needs interval to set new tabstops
|
||||||
pub fn resize(self: *Tabstops, alloc: Allocator, cols: usize) !void {
|
pub fn resize(self: *Tabstops, alloc: Allocator, cols: usize) !void {
|
||||||
// Set our new value
|
// Set our new value
|
||||||
self.cols = cols;
|
self.cols = cols;
|
||||||
|
@ -103,10 +103,39 @@ pub fn deinit(self: *Terminal, alloc: Allocator) void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Resize the underlying terminal.
|
/// Resize the underlying terminal.
|
||||||
pub fn resize(self: *Terminal, cols: usize, rows: usize) void {
|
pub fn resize(self: *Terminal, alloc: Allocator, cols: usize, rows: usize) !void {
|
||||||
// TODO: actually doing anything for this
|
// TODO: test, wrapping, etc.
|
||||||
|
|
||||||
|
// Resize our tabstops
|
||||||
|
// TODO: use resize, but it doesn't set new tabstops
|
||||||
|
if (self.cols != cols) {
|
||||||
|
self.tabstops.deinit(alloc);
|
||||||
|
self.tabstops = try Tabstops.init(alloc, cols, 8);
|
||||||
|
}
|
||||||
|
|
||||||
|
// If we're making the screen smaller, dealloc the unused items.
|
||||||
|
// TODO: we probably want to wrap in the future.
|
||||||
|
if (rows < self.rows and self.screen.items.len > rows) {
|
||||||
|
for (self.screen.items[rows..self.screen.items.len]) |*line|
|
||||||
|
line.deinit(alloc);
|
||||||
|
self.screen.shrinkRetainingCapacity(rows);
|
||||||
|
}
|
||||||
|
if (cols < self.cols) {
|
||||||
|
for (self.screen.items) |*line| {
|
||||||
|
if (line.items.len < cols) continue;
|
||||||
|
line.shrinkRetainingCapacity(cols);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set our size
|
||||||
self.cols = cols;
|
self.cols = cols;
|
||||||
self.rows = rows;
|
self.rows = rows;
|
||||||
|
|
||||||
|
// Reset the scrolling region
|
||||||
|
self.scrolling_region = .{
|
||||||
|
.top = 0,
|
||||||
|
.bottom = rows - 1,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return the current string value of the terminal. Newlines are
|
/// Return the current string value of the terminal. Newlines are
|
||||||
|
Reference in New Issue
Block a user