Skip to main content

TerminalPlatform

Struct TerminalPlatform 

Source
pub struct TerminalPlatform { /* private fields */ }
Expand description

Cross-platform Terminal TUI and Static/Pipe CLI host implementing PlatformBackend and PlatformHostAdapter.

Implementations§

Source§

impl TerminalPlatform

Mode builders, PTY input injection, resize sync, and CLI stdout/stderr helpers for TerminalPlatform.

Source

pub fn with_mode(mode: TerminalHostMode) -> Self

Creates a TerminalPlatform configured for mode using a live host TTY probe.

§Arguments
  • TerminalHostMode - Desired host operating mode (Auto, InteractiveTui, or StaticCli).
§Returns
  • Self - Initialized terminal platform backend.
Source

pub fn interactive(cols: u16, rows: u16) -> Self

Creates a TerminalPlatform explicitly in interactive PTY TUI mode with custom (cols, rows).

§Arguments
  • u16 - Terminal width in character columns.
  • u16 - Terminal height in character rows.
§Returns
  • Self - Interactive TUI platform backend.
Source

pub fn static_cli(stdout_is_tty: bool, no_color: bool) -> Self

Creates a TerminalPlatform explicitly in non-interactive static/pipe CLI mode.

§Arguments
  • bool - Whether standard output is attached to a TTY (false when piped).
  • bool - Whether NO_COLOR override is active.
§Returns
  • Self - Static/pipe CLI platform backend.
Source

pub fn from_probe(mode: TerminalHostMode, probe: TerminalTtyProbe) -> Self

Constructs a TerminalPlatform deterministically from a precomputed TerminalTtyProbe.

§Arguments
  • TerminalHostMode - Requested mode.
  • TerminalTtyProbe - Precomputed TTY and color capability probe.
§Returns
  • Self - Configured terminal backend.
Source

pub fn enter_live_tui_session(&mut self)

Enters live interactive PTY raw mode and attaches the RAII restoration guard to this backend.

§Arguments
  • &Self - Mutable terminal platform backend.
Source

pub fn enter_captured_tui_session(&mut self, sink: Rc<RefCell<String>>)

Attaches a deterministic captured RAII guard for testing raw-mode entry and restore without touching real TTY handles.

§Arguments
  • &Self - Mutable terminal platform backend.
  • Rc<RefCell<String>> - Sink capturing enter/exit ANSI sequences.
Source

pub fn leave_tui_session(&mut self)

Explicitly restores and releases the active RAII terminal raw-mode guard, if entered.

§Arguments
  • &Self - Mutable terminal platform backend.
Source

pub fn primary_window_id(&self) -> Option<WindowId>

Returns the primary terminal WindowId if one has been created.

§Arguments
  • &Self - Terminal platform reference.
§Returns
  • Option<WindowId> - Primary window handle.
Source

pub fn push_raw_input(&mut self, bytes: &[u8]) -> usize

Feeds raw VT/xterm input bytes into the parser and enqueues all decoded WindowEvents.

§Arguments
  • &Self - Mutable terminal platform.
  • &[u8] - Raw bytes read from PTY or injected by a test harness.
§Returns
  • usize - Number of WindowEvents enqueued.
Source

pub fn handle_terminal_resize(&mut self, cols: u16, rows: u16)

Updates terminal (cols, rows) and emits matching WindowEvent::Resized and SystemEvent::Resize events.

§Arguments
  • &Self - Mutable terminal platform.
  • u16 - New terminal column count.
  • u16 - New terminal row count.
Source

pub fn write_stdout(&mut self, text: &str) -> Result<(), PlatformError>

Writes clean result text to the stdout channel, stripping or suppressing ANSI automatically when piped.

§Arguments
  • &Self - Mutable terminal platform.
  • &str - UTF-8 output payload.
§Returns
  • Result<(), PlatformError> - Write status (Err if pipe is broken).
Source

pub fn write_stderr(&mut self, text: &str) -> Result<(), PlatformError>

Writes diagnostic or error text strictly to the stderr channel so stdout pipelines remain unpolluted.

§Arguments
  • &Self - Mutable terminal platform.
  • &str - UTF-8 diagnostic payload.
§Returns
  • Result<(), PlatformError> - Write status.
Source

pub fn present_terminal_output( &mut self, id: WindowId, output: &str, ) -> Result<(), PlatformError>

Records a terminal frame string (TerminalRenderer output) against id and writes it to stdout.

§Arguments
  • &Self - Mutable terminal platform.
  • WindowId - Target window handle.
  • &str - Rendered ANSI cell-diff or static plain-text output.
§Returns
  • Result<(), PlatformError> - Presentation status.
Source

pub fn stdout_text(&self) -> String

Returns captured standard output decoded as UTF-8.

§Arguments
  • &Self - Terminal platform reference.
§Returns
  • String - Captured stdout text.
Source

pub fn stderr_text(&self) -> String

Returns captured standard error diagnostics decoded as UTF-8.

§Arguments
  • &Self - Terminal platform reference.
§Returns
  • String - Captured stderr text.
Source

pub fn request_exit_with_code(&mut self, code: i32)

Marks the session as exiting with code and enqueues SystemEvent::Terminate.

§Arguments
  • &Self - Mutable terminal platform.
  • i32 - Process exit code to propagate.
Source

pub fn render_mode(&self) -> TerminalRenderMode

Resolves the active TerminalRenderMode matching this host’s resolved mode and TTY probe.

§Arguments
  • &Self - Terminal platform reference.
§Returns
  • TerminalRenderMode - InteractiveTui for live PTY sessions, StaticPlainText for piped/static CLI.
Source§

impl TerminalPlatform

Source

pub fn get_requested_mode(&self) -> TerminalHostMode

Source

pub fn get_mut_requested_mode(&mut self) -> &mut TerminalHostMode

Source

pub fn set_requested_mode(&mut self, val: TerminalHostMode) -> &mut Self

Source

pub fn get_resolved_mode(&self) -> TerminalHostMode

Source

pub fn get_mut_resolved_mode(&mut self) -> &mut TerminalHostMode

Source

pub fn set_resolved_mode(&mut self, val: TerminalHostMode) -> &mut Self

Source

pub fn get_probe(&self) -> TerminalTtyProbe

Source

pub fn get_mut_probe(&mut self) -> &mut TerminalTtyProbe

Source

pub fn set_probe(&mut self, val: TerminalTtyProbe) -> &mut Self

Source

pub fn get_metrics(&self) -> TerminalCellMetrics

Source

pub fn get_mut_metrics(&mut self) -> &mut TerminalCellMetrics

Source

pub fn set_metrics(&mut self, val: TerminalCellMetrics) -> &mut Self

Source

pub fn get_mut_primary_window(&mut self) -> &mut Option<WindowId>

Source

pub fn set_primary_window(&mut self, val: Option<WindowId>) -> &mut Self

Source

pub fn get_windows(&self) -> &HashMap<WindowId, TerminalWindowRecord>

Source

pub fn get_mut_windows( &mut self, ) -> &mut HashMap<WindowId, TerminalWindowRecord>

Source

pub fn set_windows( &mut self, val: HashMap<WindowId, TerminalWindowRecord>, ) -> &mut Self

Source

pub fn get_pending_events(&self) -> &Vec<WindowEvent>

Source

pub fn get_mut_pending_events(&mut self) -> &mut Vec<WindowEvent>

Source

pub fn set_pending_events(&mut self, val: Vec<WindowEvent>) -> &mut Self

Source

pub fn get_parser(&self) -> &TerminalInputParser

Source

pub fn get_mut_parser(&mut self) -> &mut TerminalInputParser

Source

pub fn set_parser(&mut self, val: TerminalInputParser) -> &mut Self

Source

pub fn get_mut_raw_guard(&mut self) -> &mut Option<TerminalRawGuard>

Source

pub fn set_raw_guard(&mut self, val: Option<TerminalRawGuard>) -> &mut Self

Source

pub fn get_stdout_log(&self) -> &Vec<u8> ⓘ

Source

pub fn get_mut_stdout_log(&mut self) -> &mut Vec<u8> ⓘ

Source

pub fn set_stdout_log(&mut self, val: Vec<u8>) -> &mut Self

Source

pub fn get_stderr_log(&self) -> &Vec<u8> ⓘ

Source

pub fn get_mut_stderr_log(&mut self) -> &mut Vec<u8> ⓘ

Source

pub fn set_stderr_log(&mut self, val: Vec<u8>) -> &mut Self

Source

pub fn get_emit_os_streams(&self) -> bool

Source

pub fn get_mut_emit_os_streams(&mut self) -> &mut bool

Source

pub fn set_emit_os_streams(&mut self, val: bool) -> &mut Self

Source

pub fn get_exit_code(&self) -> i32

Source

pub fn get_mut_exit_code(&mut self) -> &mut i32

Source

pub fn set_exit_code(&mut self, val: i32) -> &mut Self

Source

pub fn get_broken_pipe(&self) -> bool

Source

pub fn get_mut_broken_pipe(&mut self) -> &mut bool

Source

pub fn set_broken_pipe(&mut self, val: bool) -> &mut Self

Source

pub fn get_mut_clipboard(&mut self) -> &mut Option<String>

Source

pub fn set_clipboard(&mut self, val: Option<String>) -> &mut Self

Source

pub fn get_storage(&self) -> &HashMap<String, String>

Source

pub fn get_mut_storage(&mut self) -> &mut HashMap<String, String>

Source

pub fn set_storage(&mut self, val: HashMap<String, String>) -> &mut Self

Source

pub fn get_route_stack(&self) -> &Vec<String>

Source

pub fn get_mut_route_stack(&mut self) -> &mut Vec<String>

Source

pub fn set_route_stack(&mut self, val: Vec<String>) -> &mut Self

Source

pub fn get_theme(&self) -> ThemeMode

Source

pub fn get_mut_theme(&mut self) -> &mut ThemeMode

Source

pub fn set_theme(&mut self, val: ThemeMode) -> &mut Self

Source

pub fn get_pump_paused(&self) -> bool

Source

pub fn get_mut_pump_paused(&mut self) -> &mut bool

Source

pub fn set_pump_paused(&mut self, val: bool) -> &mut Self

Trait Implementations§

Source§

impl Debug for TerminalPlatform

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the struct fields as a debug struct, skipping excluded fields.

§Arguments
  • &mut ::std::fmt::Formatter<'_> - The formatter to write the representation into.
§Returns
  • ::std::fmt::Result - Success or failure of the formatting operation.
Source§

impl Default for TerminalPlatform

Default TerminalPlatform auto-probing the host process TTY state.

Source§

fn default() -> Self

Creates a TerminalPlatform in TerminalHostMode::Auto.

§Returns
  • Self - Auto-configured terminal host backend.
Source§

impl PlatformBackend for TerminalPlatform

PlatformBackend implementation for TerminalPlatform.

Source§

fn kind(&self) -> PlatformKind

Returns PlatformKind::Terminal in interactive TUI mode or PlatformKind::TerminalCli in static/pipe CLI mode.

§Arguments
  • &Self - Terminal platform reference.
§Returns
  • PlatformKind - Concrete terminal platform kind.
Source§

fn capabilities(&self) -> PlatformCapabilities

Returns normalized capabilities for this terminal mode.

§Arguments
  • &Self - Terminal platform reference.
§Returns
  • PlatformCapabilities - Terminal capabilities.
Source§

fn create_window( &mut self, config: &WindowConfig, ) -> Result<WindowState, PlatformError>

Allocates a terminal viewport window mapped to the current (cols, rows) cell metrics.

§Arguments
  • &Self - Mutable terminal platform.
  • &WindowConfig - Declarative window configuration.
§Returns
  • Result<WindowState, PlatformError> - Created terminal window state.
Source§

fn window_state(&self, id: WindowId) -> Option<WindowState>

Queries live WindowState for id.

§Arguments
  • &Self - Terminal platform reference.
  • WindowId - Window identifier.
§Returns
  • Option<WindowState> - Window state if alive.
Source§

fn raw_window_handle(&self, _id: WindowId) -> RawWindowHandle

Returns RawWindowHandle::TerminalPty describing the attached PTY/console fd.

§Arguments
  • &Self - Terminal platform reference.
  • WindowId - Window identifier.
§Returns
  • RawWindowHandle - Terminal PTY raw handle.
Source§

fn poll_events(&mut self) -> Vec<WindowEvent>

Polls pending SIGWINCH resizes, non-blocking live PTY bytes (when active), and drains queued WindowEvents.

§Arguments
  • &Self - Mutable terminal platform.
§Returns
  • Vec<WindowEvent> - Ordered pending events.
Source§

fn set_frame_pump_paused(&mut self, paused: bool)

Updates frame pump pause state for suspend/background freeze.

§Arguments
  • &Self - Mutable terminal platform.
  • bool - true to pause frame pumping.
Source§

fn is_frame_pump_paused(&self) -> bool

Returns whether the terminal frame pump is paused.

§Arguments
  • &Self - Terminal platform reference.
§Returns
  • bool - Pause status.
Source§

fn present_framebuffer( &mut self, id: WindowId, framebuffer: &Framebuffer, ) -> Result<(), PlatformError>

Stores a fallback RGBA8 framebuffer snapshot without emitting raw pixel bytes to the terminal stream.

§Arguments
  • &Self - Mutable terminal platform.
  • WindowId - Target window handle.
  • &Framebuffer - Rendered RGBA8 framebuffer.
§Returns
  • Result<(), PlatformError> - Presentation status.
Source§

fn read_clipboard(&self) -> Option<String>

Reads the terminal clipboard cache.

§Arguments
  • &Self - Terminal platform reference.
§Returns
  • Option<String> - Cached clipboard string.
Source§

fn write_clipboard(&mut self, text: &str) -> Result<(), PlatformError>

Stores text into the terminal clipboard buffer.

§Arguments
  • &Self - Mutable terminal platform.
  • &str - Clipboard text.
§Returns
  • Result<(), PlatformError> - Always succeeds.
Source§

fn system_theme(&self) -> ThemeMode

Returns the terminal theme hint.

§Arguments
  • &Self - Terminal platform reference.
§Returns
  • ThemeMode - Active terminal theme mode.
Source§

fn wait_for_events(&mut self) -> Vec<WindowEvent>

Blocks with zero CPU usage until at least one OS or lifecycle event arrives, then drains all pending events. Read more
Source§

fn present_framebuffer_region( &mut self, id: WindowId, framebuffer: &Framebuffer, _damage: DamageRegion, ) -> Result<(), PlatformError>

Presents a damaged sub-region of a CPU-rendered RGBA8 Framebuffer when supported by the backend. Read more
Source§

fn display_refresh_rate_hz(&self) -> f32

Queries the active display’s native hardware refresh rate in Hertz (60.0 fallback). Read more
Source§

impl PlatformHostAdapter for TerminalPlatform

PlatformHostAdapter implementation for TerminalPlatform.

Source§

fn device_form_factor(&self) -> DeviceFormFactor

Returns DeviceFormFactor::Terminal.

§Arguments
  • &Self - Terminal platform reference.
§Returns
  • DeviceFormFactor - DeviceFormFactor::Terminal.
Source§

fn host_vendor_name(&self) -> &'static str

Returns "terminal-tui" for interactive PTY sessions or "terminal-cli" for static/pipe CLI sessions.

§Arguments
  • &Self - Terminal platform reference.
§Returns
  • &'static str - Canonical host vendor identifier.
Source§

impl PlatformLifecycleBridge for TerminalPlatform

PlatformLifecycleBridge implementation for TerminalPlatform.

Source§

fn freeze_surface(&mut self) -> Vec<WindowEvent>

Pauses terminal frame pumping and emits Disappear + Background.

§Arguments
  • &Self - Mutable terminal platform.
§Returns
  • Vec<WindowEvent> - Normalized freeze lifecycle events.
Source§

fn resume_surface(&mut self) -> Vec<WindowEvent>

Resumes terminal frame pumping and emits Appear + Foreground.

§Arguments
  • &Self - Mutable terminal platform.
§Returns
  • Vec<WindowEvent> - Normalized resume lifecycle events.
Source§

fn destroy_surface(&mut self) -> Vec<WindowEvent>

Restores raw terminal state cleanly and emits Terminate.

§Arguments
  • &Self - Mutable terminal platform.
§Returns
  • Vec<WindowEvent> - Normalized destroy lifecycle events.
Source§

impl PlatformNavigation for TerminalPlatform

PlatformNavigation implementation for TerminalPlatform.

Source§

fn navigate_to(&mut self, route: &str) -> Result<(), PlatformError>

Pushes route onto the terminal session navigation stack.

§Arguments
  • &Self - Mutable terminal platform.
  • &str - Logical route path.
§Returns
  • Result<(), PlatformError> - Navigation status.
Source§

fn navigate_back(&mut self, delta: u32) -> Result<(), PlatformError>

Pops delta entries from the terminal navigation stack, keeping the root route.

§Arguments
  • &Self - Mutable terminal platform.
  • u32 - Number of routes to pop.
§Returns
  • Result<(), PlatformError> - Navigation status.
Source§

fn current_route(&self) -> &str

Returns the currently active terminal route path.

§Arguments
  • &Self - Terminal platform reference.
§Returns
  • &str - Current route path.
Source§

impl PlatformStorage for TerminalPlatform

PlatformStorage implementation for TerminalPlatform.

Source§

fn storage_get(&self, key: &str) -> Option<String>

Reads a key from in-memory terminal session storage.

§Arguments
  • &Self - Terminal platform reference.
  • &str - Storage key.
§Returns
  • Option<String> - Stored value, if present.
Source§

fn storage_set(&mut self, key: &str, value: &str) -> Result<(), PlatformError>

Writes a key-value pair into terminal session storage.

§Arguments
  • &Self - Mutable terminal platform.
  • &str - Storage key.
  • &str - Value to store.
§Returns
  • Result<(), PlatformError> - Storage status.
Source§

fn storage_remove(&mut self, key: &str) -> Result<(), PlatformError>

Removes key from terminal session storage.

§Arguments
  • &Self - Mutable terminal platform.
  • &str - Storage key.
§Returns
  • Result<(), PlatformError> - Storage status.
Source§

fn storage_clear(&mut self) -> Result<(), PlatformError>

Clears all keys from terminal session storage.

§Arguments
  • &Self - Mutable terminal platform.
§Returns
  • Result<(), PlatformError> - Storage status.
Source§

impl WindowController for TerminalPlatform

WindowController implementation for TerminalPlatform.

Source§

fn apply_command(&mut self, command: WindowCommand) -> Result<(), PlatformError>

Applies a WindowCommand against the terminal window record.

§Arguments
  • &Self - Mutable terminal platform.
  • WindowCommand - Command to apply.
§Returns
  • Result<(), PlatformError> - Execution status.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.