termio: remove more state

This commit is contained in:
Mitchell Hashimoto
2024-07-15 10:02:02 -07:00
parent 3625e1e58e
commit dc6dc1d3d2
2 changed files with 42 additions and 50 deletions

View File

@ -426,51 +426,50 @@ pub fn init(
};
// Start our IO implementation
var io_exec = try termio.Exec.init(alloc, .{
.command = config.command,
.shell_integration = config.@"shell-integration",
.shell_integration_features = config.@"shell-integration-features",
.working_directory = config.@"working-directory",
.resources_dir = main.state.resources_dir,
.term = config.term,
// This separate block ({}) is important because our errdefers must
// be scoped here to be valid.
{
// Initialize our IO backend
var io_exec = try termio.Exec.init(alloc, .{
.command = config.command,
.shell_integration = config.@"shell-integration",
.shell_integration_features = config.@"shell-integration-features",
.working_directory = config.@"working-directory",
.resources_dir = main.state.resources_dir,
.term = config.term,
// Get the cgroup if we're on linux and have the decl. I'd love
// to change this from a decl to a surface options struct because
// then we can do memory management better (don't need to retain
// the string around).
.linux_cgroup = if (comptime builtin.os.tag == .linux and
@hasDecl(apprt.runtime.Surface, "cgroup"))
rt_surface.cgroup()
else
Command.linux_cgroup_default,
});
errdefer io_exec.deinit();
var io_writer = try termio.Writer.initMailbox(alloc);
errdefer io_writer.deinit(alloc);
try termio.Termio.init(&self.io, alloc, .{
.grid_size = grid_size,
.screen_size = screen_size,
.padding = padding,
.full_config = config,
.config = try termio.Termio.DerivedConfig.init(alloc, config),
.reader = .{ .exec = io_exec },
.writer = io_writer,
.resources_dir = main.state.resources_dir,
.renderer_state = &self.renderer_state,
.renderer_wakeup = render_thread.wakeup,
.renderer_mailbox = render_thread.mailbox,
.surface_mailbox = .{ .surface = self, .app = app_mailbox },
// Get the cgroup if we're on linux and have the decl. I'd love
// to change this from a decl to a surface options struct because
// then we can do memory management better (don't need to retain
// the string around).
.linux_cgroup = if (comptime builtin.os.tag == .linux and
@hasDecl(apprt.runtime.Surface, "cgroup"))
rt_surface.cgroup()
else
Command.linux_cgroup_default,
});
errdefer io_exec.deinit();
// Get the cgroup if we're on linux and have the decl. I'd love
// to change this from a decl to a surface options struct because
// then we can do memory management better (don't need to retain
// the string around).
.linux_cgroup = if (comptime builtin.os.tag == .linux and
@hasDecl(apprt.runtime.Surface, "cgroup"))
rt_surface.cgroup()
else
Command.linux_cgroup_default,
});
// Initialize our IO writer
var io_writer = try termio.Writer.initMailbox(alloc);
errdefer io_writer.deinit(alloc);
try termio.Termio.init(&self.io, alloc, .{
.grid_size = grid_size,
.screen_size = screen_size,
.padding = padding,
.full_config = config,
.config = try termio.Termio.DerivedConfig.init(alloc, config),
.reader = .{ .exec = io_exec },
.writer = io_writer,
.renderer_state = &self.renderer_state,
.renderer_wakeup = render_thread.wakeup,
.renderer_mailbox = render_thread.mailbox,
.surface_mailbox = .{ .surface = self, .app = app_mailbox },
});
}
// Outside the block, IO has now taken ownership of our temporary state
// so we can just defer this and not the subcomponents.
errdefer self.io.deinit();
// Report initial cell size on surface creation

View File

@ -32,9 +32,6 @@ reader: termio.Reader,
/// If you're using termio.Thread this MUST be "mailbox".
writer: termio.Writer,
/// The application resources directory.
resources_dir: ?[]const u8,
/// The render state. The IO implementation can modify anything here. The
/// surface thread will setup the initial "terminal" pointer but the IO impl
/// is free to change that if that is useful (i.e. doing some sort of dual
@ -50,7 +47,3 @@ renderer_mailbox: *renderer.Thread.Mailbox,
/// The mailbox for sending the surface messages.
surface_mailbox: apprt.surface.Mailbox,
/// The cgroup to apply to the started termio process, if able by
/// the termio implementation. This only applies to Linux.
linux_cgroup: Command.LinuxCgroup = Command.linux_cgroup_default,