diff --git a/src/Surface.zig b/src/Surface.zig index 95bc4d765..94bb058b3 100644 --- a/src/Surface.zig +++ b/src/Surface.zig @@ -101,7 +101,7 @@ color_scheme: apprt.ColorScheme = .light, last_binding_trigger: u64 = 0, /// The terminal IO handler. -io: termio.Impl, +io: termio.Termio, io_thread: termio.Thread, io_thr: std.Thread, @@ -397,12 +397,12 @@ pub fn init( errdefer render_thread.deinit(); // Start our IO implementation - var io = try termio.Impl.init(alloc, .{ + var io = try termio.Termio.init(alloc, .{ .grid_size = grid_size, .screen_size = screen_size, .padding = padding, .full_config = config, - .config = try termio.Impl.DerivedConfig.init(alloc, config), + .config = try termio.Termio.DerivedConfig.init(alloc, config), .resources_dir = main.state.resources_dir, .renderer_state = &self.renderer_state, .renderer_wakeup = render_thread.wakeup, @@ -809,9 +809,9 @@ fn changeConfig(self: *Surface, config: *const configpkg.Config) !void { // our messages aren't huge. var renderer_message = try renderer.Message.initChangeConfig(self.alloc, config); errdefer renderer_message.deinit(); - var termio_config_ptr = try self.alloc.create(termio.Impl.DerivedConfig); + var termio_config_ptr = try self.alloc.create(termio.Termio.DerivedConfig); errdefer self.alloc.destroy(termio_config_ptr); - termio_config_ptr.* = try termio.Impl.DerivedConfig.init(self.alloc, config); + termio_config_ptr.* = try termio.Termio.DerivedConfig.init(self.alloc, config); errdefer termio_config_ptr.deinit(); _ = self.renderer_thread.mailbox.push(renderer_message, .{ .forever = {} }); diff --git a/src/termio.zig b/src/termio.zig index 45382cda1..e0b3efb28 100644 --- a/src/termio.zig +++ b/src/termio.zig @@ -5,15 +5,10 @@ pub usingnamespace @import("termio/message.zig"); pub const Exec = @import("termio/Exec.zig"); pub const Options = @import("termio/Options.zig"); +pub const Termio = @import("termio/Termio.zig"); pub const Thread = @import("termio/Thread.zig"); pub const Mailbox = Thread.Mailbox; -/// The implementation to use for the IO. This is just "exec" for now but -/// this is somewhat pluggable so that in the future we can introduce other -/// options for other platforms (i.e. wasm) or even potentially a vtable -/// implementation for runtime polymorphism. -pub const Impl = Exec; - test { @import("std").testing.refAllDecls(@This()); diff --git a/src/termio/Options.zig b/src/termio/Options.zig index b4edb473a..ac12c31eb 100644 --- a/src/termio/Options.zig +++ b/src/termio/Options.zig @@ -23,7 +23,7 @@ padding: renderer.Padding, full_config: *const Config, /// The derived configuration for this termio implementation. -config: termio.Impl.DerivedConfig, +config: termio.Termio.DerivedConfig, /// The application resources directory. resources_dir: ?[]const u8, diff --git a/src/termio/Thread.zig b/src/termio/Thread.zig index 45b9fd1ae..aceeaa636 100644 --- a/src/termio/Thread.zig +++ b/src/termio/Thread.zig @@ -58,8 +58,8 @@ sync_reset: xev.Timer, sync_reset_c: xev.Completion = .{}, sync_reset_cancel_c: xev.Completion = .{}, -/// The underlying IO implementation. -impl: *termio.Impl, +/// The main termio state. +termio: *termio.Termio, /// The mailbox that can be used to send this thread messages. Note /// this is a blocking queue so if it is full you will get errors (or block). @@ -83,7 +83,7 @@ flags: packed struct { /// is up to the caller to start the thread with the threadMain entrypoint. pub fn init( alloc: Allocator, - impl: *termio.Impl, + t: *termio.Termio, ) !Thread { // Create our event loop. var loop = try xev.Loop.init(.{}); @@ -116,7 +116,7 @@ pub fn init( .stop = stop_h, .coalesce = coalesce_h, .sync_reset = sync_reset_h, - .impl = impl, + .termio = t, .mailbox = mailbox, }; } @@ -150,9 +150,9 @@ pub fn threadMain(self: *Thread) void { // the error to the surface thread and let the apprt deal with it // in some way but this works for now. Without this, the user would // just see a blank terminal window. - self.impl.renderer_state.mutex.lock(); - defer self.impl.renderer_state.mutex.unlock(); - const t = self.impl.renderer_state.terminal; + self.termio.renderer_state.mutex.lock(); + defer self.termio.renderer_state.mutex.unlock(); + const t = self.termio.renderer_state.terminal; // Hide the cursor t.modes.set(.cursor_visible, false); @@ -226,9 +226,9 @@ fn threadMain_(self: *Thread) !void { // Run our thread start/end callbacks. This allows the implementation // to hook into the event loop as needed. - var data = try self.impl.threadEnter(self); + var data = try self.termio.threadEnter(self); defer data.deinit(); - defer self.impl.threadExit(data); + defer self.termio.threadExit(data); // Run log.debug("starting IO thread", .{}); @@ -256,21 +256,21 @@ fn drainMailbox(self: *Thread) !void { switch (message) { .change_config => |config| { defer config.alloc.destroy(config.ptr); - try self.impl.changeConfig(config.ptr); + try self.termio.changeConfig(config.ptr); }, .inspector => |v| self.flags.has_inspector = v, .resize => |v| self.handleResize(v), - .clear_screen => |v| try self.impl.clearScreen(v.history), - .scroll_viewport => |v| try self.impl.scrollViewport(v), - .jump_to_prompt => |v| try self.impl.jumpToPrompt(v), + .clear_screen => |v| try self.termio.clearScreen(v.history), + .scroll_viewport => |v| try self.termio.scrollViewport(v), + .jump_to_prompt => |v| try self.termio.jumpToPrompt(v), .start_synchronized_output => self.startSynchronizedOutput(), .linefeed_mode => |v| self.flags.linefeed_mode = v, - .child_exited_abnormally => |v| try self.impl.childExitedAbnormally(v.exit_code, v.runtime_ms), - .write_small => |v| try self.impl.queueWrite(v.data[0..v.len], self.flags.linefeed_mode), - .write_stable => |v| try self.impl.queueWrite(v, self.flags.linefeed_mode), + .child_exited_abnormally => |v| try self.termio.childExitedAbnormally(v.exit_code, v.runtime_ms), + .write_small => |v| try self.termio.queueWrite(v.data[0..v.len], self.flags.linefeed_mode), + .write_stable => |v| try self.termio.queueWrite(v, self.flags.linefeed_mode), .write_alloc => |v| { defer v.alloc.free(v.data); - try self.impl.queueWrite(v.data, self.flags.linefeed_mode); + try self.termio.queueWrite(v.data, self.flags.linefeed_mode); }, } } @@ -278,7 +278,7 @@ fn drainMailbox(self: *Thread) !void { // Trigger a redraw after we've drained so we don't waste cyces // messaging a redraw. if (redraw) { - try self.impl.renderer_wakeup.notify(); + try self.termio.renderer_wakeup.notify(); } } @@ -328,7 +328,7 @@ fn syncResetCallback( }; const self = self_ orelse return .disarm; - self.impl.resetSynchronizedOutput(); + self.termio.resetSynchronizedOutput(); return .disarm; } @@ -350,7 +350,7 @@ fn coalesceCallback( if (self.coalesce_data.resize) |v| { self.coalesce_data.resize = null; - self.impl.resize(v.grid_size, v.screen_size, v.padding) catch |err| { + self.termio.resize(v.grid_size, v.screen_size, v.padding) catch |err| { log.warn("error during resize err={}", .{err}); }; } diff --git a/src/termio/message.zig b/src/termio/message.zig index c91f3b5d6..31b203f05 100644 --- a/src/termio/message.zig +++ b/src/termio/message.zig @@ -33,7 +33,7 @@ pub const Message = union(enum) { /// is allocated via the allocator and is expected to be freed when done. change_config: struct { alloc: Allocator, - ptr: *termio.Impl.DerivedConfig, + ptr: *termio.Termio.DerivedConfig, }, /// Activate or deactivate the inspector.