diff options
Diffstat (limited to 'src/tui_terminal.zig')
| -rw-r--r-- | src/tui_terminal.zig | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/tui_terminal.zig b/src/tui_terminal.zig index 0f8b3d9..0b00bb4 100644 --- a/src/tui_terminal.zig +++ b/src/tui_terminal.zig @@ -252,6 +252,31 @@ pub const Terminal = struct { if (active_restore == &self.restore) active_restore = null; } + /// Temporarily return the tty to its ORIGINAL (cooked) termios so a child + /// process (e.g. `$EDITOR`) can drive the terminal normally, and show the + /// cursor. Pairs with `resumeRawMode`. Unlike `deinit`, this does NOT clear + /// the global restore record or mark the restore done — the signal/panic + /// restore path stays armed with the original termios (restoring to cooked + /// is exactly what we'd want on a crash mid-editor), and we re-enter raw + /// mode afterward. + /// + /// No-op if not currently in raw mode. + pub fn suspendRawMode(self: *Terminal) void { + if (!self.raw_mode) return; + posix.tcsetattr(self.fd, .FLUSH, self.restore.original) catch {}; + self.raw_mode = false; + self.writeAll(seq.show_cursor); + } + + /// Re-enter raw mode after `suspendRawMode` and hide the cursor again. The + /// global restore record and signal handlers are already installed (they + /// were never torn down), so this just reapplies the raw termios. + pub fn resumeRawMode(self: *Terminal) Error!void { + if (self.raw_mode) return; + try self.enableRawMode(); + self.writeAll(seq.hide_cursor); + } + // -- output helpers ----------------------------------------------------- /// Raw write of `bytes` to the tty. Returns the count written (short |
