Skip to main content

Transport

Trait Transport 

Source
pub trait Transport {
    type Backend: Backend;

    // Required methods
    fn terminal_mut(&mut self) -> &mut Terminal<Self::Backend>;
    fn poll(&mut self, timeout: Duration) -> Result<Option<RawEvent>>;

    // Provided methods
    fn finish(self) -> Result<()>
       where Self: Sized { ... }
    fn write_passthrough(&mut self, _bytes: &[u8]) -> Result<()> { ... }
    fn client_term(&self) -> Option<&str> { ... }
}
Expand description

Bridge between the event loop and whatever terminal it talks to.

Lifecycle: a Transport is constructed in whatever mode it needs (raw mode, alternate screen, SSH channel attached), then passed by mutable reference to crate::runtime::run_loop. When the loop exits, the owning code calls Transport::finish to tear down.

The transport owns the Terminal rather than just a raw backend because ratatui’s Terminal<B> requires B: Backend, which does not hold for &mut B. Having the transport expose terminal_mut() keeps the runtime generic without hitting that trait-bound wall.

Required Associated Types§

Source

type Backend: Backend

Required Methods§

Source

fn terminal_mut(&mut self) -> &mut Terminal<Self::Backend>

Mutable access to the owned ratatui Terminal so the runtime can drive draw.

Source

fn poll(&mut self, timeout: Duration) -> Result<Option<RawEvent>>

Block up to timeout waiting for an input event. Returns Ok(None) on timeout, Ok(Some(event)) on activity.

§Errors

Returns Err on disconnect (local stdin closed, SSH channel closed) or any unrecoverable read failure.

Provided Methods§

Source

fn finish(self) -> Result<()>
where Self: Sized,

Restore the terminal to its pre-TUI state. The default impl is a no-op so test transports do not have to implement it.

§Errors

Returns Err if teardown fails, e.g. writing the “leave alternate screen” escape to a closed stdout.

Source

fn write_passthrough(&mut self, _bytes: &[u8]) -> Result<()>

Forward a raw byte sequence to the same stream the backend writes to, bypassing ratatui’s cell grid. Used for terminal escape sequences that ratatui can’t model directly — kitty graphics APC bytes, future sixel, etc. The default impl silently drops the bytes so transports that don’t speak that dialect (or test doubles) don’t need an override.

§Errors

Returns Err only if the underlying stream write fails.

Source

fn client_term(&self) -> Option<&str>

Terminal type the client claims to be, in OpenSSH-style xterm-256color form. The local transport reads $TERM; the SSH transport returns whatever the peer sent in pty-req. Returns None when the transport cannot tell.

Capability detection (kitty graphics, true-colour, etc.) should consult this rather than the daemon’s own environment, which is whatever the host running the daemon happened to have.

Implementors§

Source§

impl Transport for LocalTransport

Source§

type Backend = CrosstermBackend<Stdout>