diff options
| author | Can Celik <ogulcancelik@gmail.com> | 2026-04-04 19:22:04 +0300 |
|---|---|---|
| committer | Can Celik <ogulcancelik@gmail.com> | 2026-04-05 01:23:06 +0300 |
| commit | 41dd733ca7123c9ac4bfc6c781697a660e95b052 (patch) | |
| tree | 3fc91815ca139ef2e0b281bba0abda4ef15175f4 /vendor/libghostty-vt/src/termio/backend.zig | |
| parent | 55c138263e190a1e79d4b997bfb9397306c0ec1f (diff) | |
feat: finish ghostty pane backend integration
Diffstat (limited to 'vendor/libghostty-vt/src/termio/backend.zig')
| -rw-r--r-- | vendor/libghostty-vt/src/termio/backend.zig | 129 |
1 files changed, 129 insertions, 0 deletions
diff --git a/vendor/libghostty-vt/src/termio/backend.zig b/vendor/libghostty-vt/src/termio/backend.zig new file mode 100644 index 00000000..c29009ac --- /dev/null +++ b/vendor/libghostty-vt/src/termio/backend.zig @@ -0,0 +1,129 @@ +const std = @import("std"); +const Allocator = std.mem.Allocator; +const posix = std.posix; +const renderer = @import("../renderer.zig"); +const terminal = @import("../terminal/main.zig"); +const termio = @import("../termio.zig"); +const ProcessInfo = @import("../pty.zig").ProcessInfo; + +// The preallocation size for the write request pool. This should be big +// enough to satisfy most write requests. It must be a power of 2. +const WRITE_REQ_PREALLOC = std.math.pow(usize, 2, 5); + +/// The kinds of backends. +pub const Kind = enum { exec }; + +/// Configuration for the various backend types. +pub const Config = union(Kind) { + /// Exec uses posix exec to run a command with a pty. + exec: termio.Exec.Config, +}; + +/// Backend implementations. A backend is responsible for owning the pty +/// behavior and providing read/write capabilities. +pub const Backend = union(Kind) { + exec: termio.Exec, + + pub fn deinit(self: *Backend) void { + switch (self.*) { + .exec => |*exec| exec.deinit(), + } + } + + pub fn initTerminal(self: *Backend, t: *terminal.Terminal) void { + switch (self.*) { + .exec => |*exec| exec.initTerminal(t), + } + } + + pub fn threadEnter( + self: *Backend, + alloc: Allocator, + io: *termio.Termio, + td: *termio.Termio.ThreadData, + ) !void { + switch (self.*) { + .exec => |*exec| try exec.threadEnter(alloc, io, td), + } + } + + pub fn threadExit(self: *Backend, td: *termio.Termio.ThreadData) void { + switch (self.*) { + .exec => |*exec| exec.threadExit(td), + } + } + + pub fn focusGained( + self: *Backend, + td: *termio.Termio.ThreadData, + focused: bool, + ) !void { + switch (self.*) { + .exec => |*exec| try exec.focusGained(td, focused), + } + } + + pub fn resize( + self: *Backend, + grid_size: renderer.GridSize, + screen_size: renderer.ScreenSize, + ) !void { + switch (self.*) { + .exec => |*exec| try exec.resize(grid_size, screen_size), + } + } + + pub fn queueWrite( + self: *Backend, + alloc: Allocator, + td: *termio.Termio.ThreadData, + data: []const u8, + linefeed: bool, + ) !void { + switch (self.*) { + .exec => |*exec| try exec.queueWrite(alloc, td, data, linefeed), + } + } + + pub fn childExitedAbnormally( + self: *Backend, + gpa: Allocator, + t: *terminal.Terminal, + exit_code: u32, + runtime_ms: u64, + ) !void { + switch (self.*) { + .exec => |*exec| try exec.childExitedAbnormally( + gpa, + t, + exit_code, + runtime_ms, + ), + } + } + + /// Get information about the process(es) attached to the backend. Returns + /// `null` if there was an error getting the information or the information + /// is not available on a particular platform. + pub fn getProcessInfo(self: *Backend, comptime info: ProcessInfo) ?ProcessInfo.Type(info) { + return switch (self.*) { + .exec => |*exec| exec.getProcessInfo(info), + }; + } +}; + +/// Termio thread data. See termio.ThreadData for docs. +pub const ThreadData = union(Kind) { + exec: termio.Exec.ThreadData, + + pub fn deinit(self: *ThreadData, alloc: Allocator) void { + switch (self.*) { + .exec => |*exec| exec.deinit(alloc), + } + } + + pub fn changeConfig(self: *ThreadData, config: *termio.DerivedConfig) void { + _ = self; + _ = config; + } +}; |
