termio/exec: initial subprocess screen size should be sub padding

This commit is contained in:
Mitchell Hashimoto
2023-08-24 08:45:32 -07:00
parent c962bd0abf
commit f2f2b1eaf1
4 changed files with 16 additions and 7 deletions

View File

@ -401,6 +401,7 @@ pub fn init(
var io = try termio.Impl.init(alloc, .{
.grid_size = grid_size,
.screen_size = screen_size,
.padding = padding,
.full_config = config,
.config = try termio.Impl.DerivedConfig.init(alloc, config),
.resources_dir = app.resources_dir,

View File

@ -222,14 +222,14 @@ fn display(
// We can do better by doing this with pure internal screen state
// but this handles scroll regions.
const height = rect.bottom_right.y - rect.top_left.y + 1;
const height = rect.bottom_right.y - rect.top_left.y;
for (0..height) |_| terminal.index() catch |err| {
log.warn("failed to move cursor: {}", .{err});
break;
};
terminal.setCursorPos(
terminal.screen.cursor.y + 1,
terminal.screen.cursor.y,
rect.bottom_right.x + 1,
);
},

View File

@ -105,8 +105,6 @@ pub fn init(alloc: Allocator, opts: termio.Options) !Exec {
);
errdefer term.deinit(alloc);
term.color_palette = opts.config.palette;
term.width_px = opts.screen_size.width;
term.height_px = opts.screen_size.height;
// Set the image size limits
try term.screen.kitty_images.setLimit(alloc, opts.config.image_storage_limit);
@ -115,6 +113,10 @@ pub fn init(alloc: Allocator, opts: termio.Options) !Exec {
var subprocess = try Subprocess.init(alloc, opts);
errdefer subprocess.deinit();
// Initial width/height based on subprocess
term.width_px = subprocess.screen_size.width;
term.height_px = subprocess.screen_size.height;
return Exec{
.alloc = alloc,
.terminal = term,
@ -289,8 +291,8 @@ pub fn resize(
);
// Update our pixel sizes
self.terminal.width_px = screen_size.width;
self.terminal.height_px = screen_size.height;
self.terminal.width_px = padded_size.width;
self.terminal.height_px = padded_size.height;
}
}
@ -682,6 +684,9 @@ const Subprocess = struct {
log.warn("shell could not be detected, no automatic shell integration will be injected", .{});
}
// Our screen size should be our padded size
const padded_size = opts.screen_size.subPadding(opts.padding);
return .{
.arena = arena,
.env = env,
@ -689,7 +694,7 @@ const Subprocess = struct {
.path = final_path,
.args = args,
.grid_size = opts.grid_size,
.screen_size = opts.screen_size,
.screen_size = padded_size,
};
}

View File

@ -12,6 +12,9 @@ grid_size: renderer.GridSize,
/// The size of the viewport in pixels.
screen_size: renderer.ScreenSize,
/// The padding of the viewport.
padding: renderer.Padding,
/// 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
/// in here must be copied.