mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-14 07:46:12 +03:00
attach a terminal to the window, start hinting at renderer hookup
This commit is contained in:
@ -7,6 +7,7 @@ const testing = std.testing;
|
||||
const Allocator = std.mem.Allocator;
|
||||
const Atlas = @import("Atlas.zig");
|
||||
const FontAtlas = @import("FontAtlas.zig");
|
||||
const Terminal = @import("terminal/Terminal.zig");
|
||||
const gl = @import("opengl.zig");
|
||||
const gb = @import("gb_math.zig");
|
||||
|
||||
@ -164,6 +165,13 @@ pub fn demoCells(self: *Grid) !void {
|
||||
}
|
||||
}
|
||||
|
||||
/// updateCells updates our GPU cells from the current terminal view.
|
||||
/// The updated cells will take effect on the next render.
|
||||
pub fn updateCells(self: *Grid, term: Terminal) !void {
|
||||
_ = self;
|
||||
_ = term;
|
||||
}
|
||||
|
||||
/// Set the screen size for rendering. This will update the projection
|
||||
/// used for the shader so that the scaling of the grid is correct.
|
||||
pub fn setScreenSize(self: *Grid, dim: ScreenSize) !void {
|
||||
|
@ -12,6 +12,7 @@ const Grid = @import("Grid.zig");
|
||||
const glfw = @import("glfw");
|
||||
const gl = @import("opengl.zig");
|
||||
const Pty = @import("Pty.zig");
|
||||
const Terminal = @import("terminal/Terminal.zig");
|
||||
|
||||
const log = std.log.scoped(.window);
|
||||
|
||||
@ -24,6 +25,12 @@ grid: Grid,
|
||||
/// The underlying pty for this window.
|
||||
pty: Pty,
|
||||
|
||||
/// The terminal emulator internal state. This is the abstract "terminal"
|
||||
/// that manages input, grid updating, etc. and is renderer-agnostic. It
|
||||
/// just stores internal state about a grid. This is connected back to
|
||||
/// a renderer.
|
||||
terminal: Terminal,
|
||||
|
||||
/// Create a new window. This allocates and returns a pointer because we
|
||||
/// need a stable pointer for user data callbacks. Therefore, a stack-only
|
||||
/// initialization is not currently possible.
|
||||
@ -79,10 +86,16 @@ pub fn create(alloc: Allocator) !*Window {
|
||||
});
|
||||
errdefer pty.deinit();
|
||||
|
||||
// Create our terminal
|
||||
var term = Terminal.init(grid.size.columns, grid.size.rows);
|
||||
errdefer term.deinit(alloc);
|
||||
try term.append(alloc, "hello!");
|
||||
|
||||
self.* = .{
|
||||
.window = window,
|
||||
.grid = grid,
|
||||
.pty = pty,
|
||||
.terminal = term,
|
||||
};
|
||||
|
||||
// Setup our callbacks and user data
|
||||
@ -93,6 +106,7 @@ pub fn create(alloc: Allocator) !*Window {
|
||||
}
|
||||
|
||||
pub fn destroy(self: *Window, alloc: Allocator) void {
|
||||
self.terminal.deinit(alloc);
|
||||
self.pty.deinit();
|
||||
self.grid.deinit();
|
||||
self.window.destroy();
|
||||
@ -130,6 +144,9 @@ fn sizeCallback(window: glfw.Window, width: i32, height: i32) void {
|
||||
// TODO: temp
|
||||
win.grid.demoCells() catch unreachable;
|
||||
|
||||
// Update the size of our terminal state
|
||||
win.terminal.resize(win.grid.size.columns, win.grid.size.rows);
|
||||
|
||||
// Update the size of our pty
|
||||
win.pty.setSize(.{
|
||||
.ws_row = @intCast(u16, win.grid.size.rows),
|
||||
|
@ -57,6 +57,13 @@ pub fn deinit(self: *Terminal, alloc: Allocator) void {
|
||||
self.* = undefined;
|
||||
}
|
||||
|
||||
/// Resize the underlying terminal.
|
||||
pub fn resize(self: *Terminal, cols: usize, rows: usize) void {
|
||||
// TODO: actually doing anything for this
|
||||
self.cols = cols;
|
||||
self.rows = rows;
|
||||
}
|
||||
|
||||
/// Return the current string value of the terminal. Newlines are
|
||||
/// encoded as "\n". This omits any formatting such as fg/bg.
|
||||
///
|
||||
|
Reference in New Issue
Block a user