diff --git a/src/Grid.zig b/src/Grid.zig index e60f6bcc7..519ba7460 100644 --- a/src/Grid.zig +++ b/src/Grid.zig @@ -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 { diff --git a/src/Window.zig b/src/Window.zig index 4a6e733f7..4947982a7 100644 --- a/src/Window.zig +++ b/src/Window.zig @@ -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), diff --git a/src/terminal/Terminal.zig b/src/terminal/Terminal.zig index 3ed3ae695..608d4cb58 100644 --- a/src/terminal/Terminal.zig +++ b/src/terminal/Terminal.zig @@ -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. ///