terminal stuff

This commit is contained in:
Mitchell Hashimoto
2022-04-17 09:40:09 -07:00
parent d1173626ad
commit dc788ce5b2
2 changed files with 45 additions and 0 deletions

View File

@ -25,4 +25,5 @@ test {
_ = @import("Pty.zig"); _ = @import("Pty.zig");
_ = @import("Command.zig"); _ = @import("Command.zig");
_ = @import("TempDir.zig"); _ = @import("TempDir.zig");
_ = @import("terminal/Terminal.zig");
} }

44
src/terminal/Terminal.zig Normal file
View File

@ -0,0 +1,44 @@
//! The primary terminal emulation structure. This represents a single
//! "terminal" containing a grid of characters and exposes various operations
//! on that grid. This also maintains the scrollback buffer.
const Terminal = @This();
const std = @import("std");
/// Screen is the current screen state.
screen: Screen,
/// Cursor position.
cursor: Cursor,
/// The size of the terminal.
rows: usize,
cols: usize,
/// Screen represents a presentable terminal screen made up of lines and cells.
const Screen = std.ArrayListUnmanaged(Line);
const Line = std.ArrayListUnmanaged(Cell);
/// Cell is a single cell within the terminal.
const Cell = struct {
/// Each cell contains exactly one character.
char: u32,
// TODO(mitchellh): this is where we'll track fg/bg and other attrs.
};
/// Cursor represents the cursor state.
const Cursor = struct {
x: usize,
y: usize,
};
/// Initialize a new terminal.
pub fn init(cols: usize, rows: usize) Terminal {
return .{
.cols = cols,
.rows = rows,
.screen = .{},
.cursor = .{ .x = 0, .y = 0 },
};
}