termio: change all sizes to the new size type

This commit is contained in:
Mitchell Hashimoto
2024-11-14 13:31:01 -08:00
parent dcb1ce8377
commit 90c59f2462
4 changed files with 40 additions and 52 deletions

View File

@ -513,10 +513,7 @@ pub fn init(
errdefer io_mailbox.deinit(alloc);
try termio.Termio.init(&self.io, alloc, .{
.grid_size = size.grid(),
.cell_size = size.cell,
.screen_size = size.screen,
.padding = padding,
.size = size,
.full_config = config,
.config = try termio.Termio.DerivedConfig.init(alloc, config),
.backend = .{ .exec = io_exec },

View File

@ -8,17 +8,8 @@ const Command = @import("../Command.zig");
const Config = @import("../config.zig").Config;
const termio = @import("../termio.zig");
/// The size of the terminal grid.
grid_size: renderer.GridSize,
/// The size of a single cell, in pixels.
cell_size: renderer.CellSize,
/// The size of the viewport in pixels.
screen_size: renderer.ScreenSize,
/// The padding of the viewport.
padding: renderer.Padding,
/// All size metrics for the terminal.
size: renderer.Size,
/// The full app configuration. This is only available during initialization.
/// The memory it points to is NOT stable after the init call so any values

View File

@ -56,11 +56,8 @@ renderer_mailbox: *renderer.Thread.Mailbox,
/// The mailbox for communicating with the surface.
surface_mailbox: apprt.surface.Mailbox,
/// The cached grid size whenever a resize is called.
grid_size: renderer.GridSize,
/// The size of a single cell. Used for size reports.
cell_size: renderer.CellSize,
/// The cached size info
size: renderer.Size,
/// The mailbox implementation to use.
mailbox: termio.Mailbox,
@ -131,10 +128,13 @@ pub const DerivedConfig = struct {
/// to run a child process.
pub fn init(self: *Termio, alloc: Allocator, opts: termio.Options) !void {
// Create our terminal
var term = try terminal.Terminal.init(alloc, .{
.cols = opts.grid_size.columns,
.rows = opts.grid_size.rows,
var term = try terminal.Terminal.init(alloc, opts: {
const grid_size = opts.size.grid();
break :opts .{
.cols = grid_size.columns,
.rows = grid_size.rows,
.max_scrollback = opts.full_config.@"scrollback-limit",
};
});
errdefer term.deinit(alloc);
term.default_palette = opts.config.palette;
@ -169,8 +169,8 @@ pub fn init(self: *Termio, alloc: Allocator, opts: termio.Options) !void {
term.screen.cursor.cursor_style = opts.config.cursor_style;
// Setup our terminal size in pixels for certain requests.
term.width_px = opts.grid_size.columns * opts.cell_size.width;
term.height_px = opts.grid_size.rows * opts.cell_size.height;
term.width_px = term.cols * opts.size.cell.width;
term.height_px = term.rows * opts.size.cell.height;
// Setup our backend.
var backend = opts.backend;
@ -191,7 +191,7 @@ pub fn init(self: *Termio, alloc: Allocator, opts: termio.Options) !void {
.renderer_state = opts.renderer_state,
.renderer_wakeup = opts.renderer_wakeup,
.renderer_mailbox = opts.renderer_mailbox,
.grid_size = &self.grid_size,
.size = &self.size,
.terminal = &self.terminal,
.osc_color_report_format = opts.config.osc_color_report_format,
.enquiry_response = opts.config.enquiry_response,
@ -214,8 +214,7 @@ pub fn init(self: *Termio, alloc: Allocator, opts: termio.Options) !void {
.renderer_wakeup = opts.renderer_wakeup,
.renderer_mailbox = opts.renderer_mailbox,
.surface_mailbox = opts.surface_mailbox,
.grid_size = opts.grid_size,
.cell_size = opts.cell_size,
.size = opts.size,
.backend = opts.backend,
.mailbox = opts.mailbox,
.terminal_stream = .{
@ -356,10 +355,6 @@ pub fn resize(
// Update the size of our pty.
try self.backend.resize(grid_size, size.terminal());
// Update our cached grid size
self.grid_size = size.grid();
self.cell_size = size.cell;
// Enter the critical area that we want to keep small
{
self.renderer_state.mutex.lock();
@ -373,8 +368,8 @@ pub fn resize(
);
// Update our pixel sizes
self.terminal.width_px = grid_size.columns * self.cell_size.width;
self.terminal.height_px = grid_size.rows * self.cell_size.height;
self.terminal.width_px = grid_size.columns * self.size.cell.width;
self.terminal.height_px = grid_size.rows * self.size.cell.height;
// Disable synchronized output mode so that we show changes
// immediately for a resize. This is allowed by the spec.
@ -404,6 +399,8 @@ pub fn sizeReport(self: *Termio, td: *ThreadData, style: termio.Message.SizeRepo
}
fn sizeReportLocked(self: *Termio, td: *ThreadData, style: termio.Message.SizeReport) !void {
const grid_size = self.size.grid();
// 1024 bytes should be enough for size report since report
// in columns and pixels.
var buf: [1024]u8 = undefined;
@ -412,34 +409,34 @@ fn sizeReportLocked(self: *Termio, td: *ThreadData, style: termio.Message.SizeRe
&buf,
"\x1B[48;{};{};{};{}t",
.{
self.grid_size.rows,
self.grid_size.columns,
self.grid_size.rows * self.cell_size.height,
self.grid_size.columns * self.cell_size.width,
grid_size.rows,
grid_size.columns,
grid_size.rows * self.size.cell.height,
grid_size.columns * self.size.cell.width,
},
),
.csi_14_t => try std.fmt.bufPrint(
&buf,
"\x1b[4;{};{}t",
.{
self.grid_size.rows * self.cell_size.height,
self.grid_size.columns * self.cell_size.width,
grid_size.rows * self.size.cell.height,
grid_size.columns * self.size.cell.width,
},
),
.csi_16_t => try std.fmt.bufPrint(
&buf,
"\x1b[6;{};{}t",
.{
self.cell_size.height,
self.cell_size.width,
self.size.cell.height,
self.size.cell.width,
},
),
.csi_18_t => try std.fmt.bufPrint(
&buf,
"\x1b[8;{};{}t",
.{
self.grid_size.rows,
self.grid_size.columns,
grid_size.rows,
grid_size.columns,
},
),
};

View File

@ -26,7 +26,7 @@ const disable_kitty_keyboard_protocol = apprt.runtime == apprt.glfw;
/// unless all of the member fields are copied.
pub const StreamHandler = struct {
alloc: Allocator,
grid_size: *renderer.GridSize,
size: *renderer.Size,
terminal: *terminal.Terminal,
/// Mailbox for data to the termio thread.
@ -611,12 +611,15 @@ pub const StreamHandler = struct {
},
// Force resize back to the window size
.enable_mode_3 => self.terminal.resize(
.enable_mode_3 => {
const grid_size = self.size.grid();
self.terminal.resize(
self.alloc,
self.grid_size.columns,
self.grid_size.rows,
grid_size.columns,
grid_size.rows,
) catch |err| {
log.err("error updating terminal size: {}", .{err});
};
},
.@"132_column" => try self.terminal.deccolm(