attach a terminal to the window, start hinting at renderer hookup

This commit is contained in:
Mitchell Hashimoto
2022-04-18 14:12:35 -07:00
parent 753a946fd5
commit 2e46612bc7
3 changed files with 32 additions and 0 deletions

View File

@ -7,6 +7,7 @@ const testing = std.testing;
const Allocator = std.mem.Allocator; const Allocator = std.mem.Allocator;
const Atlas = @import("Atlas.zig"); const Atlas = @import("Atlas.zig");
const FontAtlas = @import("FontAtlas.zig"); const FontAtlas = @import("FontAtlas.zig");
const Terminal = @import("terminal/Terminal.zig");
const gl = @import("opengl.zig"); const gl = @import("opengl.zig");
const gb = @import("gb_math.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 /// Set the screen size for rendering. This will update the projection
/// used for the shader so that the scaling of the grid is correct. /// used for the shader so that the scaling of the grid is correct.
pub fn setScreenSize(self: *Grid, dim: ScreenSize) !void { pub fn setScreenSize(self: *Grid, dim: ScreenSize) !void {

View File

@ -12,6 +12,7 @@ const Grid = @import("Grid.zig");
const glfw = @import("glfw"); const glfw = @import("glfw");
const gl = @import("opengl.zig"); const gl = @import("opengl.zig");
const Pty = @import("Pty.zig"); const Pty = @import("Pty.zig");
const Terminal = @import("terminal/Terminal.zig");
const log = std.log.scoped(.window); const log = std.log.scoped(.window);
@ -24,6 +25,12 @@ grid: Grid,
/// The underlying pty for this window. /// The underlying pty for this window.
pty: Pty, 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 /// Create a new window. This allocates and returns a pointer because we
/// need a stable pointer for user data callbacks. Therefore, a stack-only /// need a stable pointer for user data callbacks. Therefore, a stack-only
/// initialization is not currently possible. /// initialization is not currently possible.
@ -79,10 +86,16 @@ pub fn create(alloc: Allocator) !*Window {
}); });
errdefer pty.deinit(); 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.* = .{ self.* = .{
.window = window, .window = window,
.grid = grid, .grid = grid,
.pty = pty, .pty = pty,
.terminal = term,
}; };
// Setup our callbacks and user data // Setup our callbacks and user data
@ -93,6 +106,7 @@ pub fn create(alloc: Allocator) !*Window {
} }
pub fn destroy(self: *Window, alloc: Allocator) void { pub fn destroy(self: *Window, alloc: Allocator) void {
self.terminal.deinit(alloc);
self.pty.deinit(); self.pty.deinit();
self.grid.deinit(); self.grid.deinit();
self.window.destroy(); self.window.destroy();
@ -130,6 +144,9 @@ fn sizeCallback(window: glfw.Window, width: i32, height: i32) void {
// TODO: temp // TODO: temp
win.grid.demoCells() catch unreachable; 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 // Update the size of our pty
win.pty.setSize(.{ win.pty.setSize(.{
.ws_row = @intCast(u16, win.grid.size.rows), .ws_row = @intCast(u16, win.grid.size.rows),

View File

@ -57,6 +57,13 @@ pub fn deinit(self: *Terminal, alloc: Allocator) void {
self.* = undefined; 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 /// Return the current string value of the terminal. Newlines are
/// encoded as "\n". This omits any formatting such as fg/bg. /// encoded as "\n". This omits any formatting such as fg/bg.
/// ///