Skip to main content

BackendEventSource

Trait BackendEventSource 

Source
pub trait BackendEventSource {
    type Error: Debug + Display;

    // Required methods
    fn size(&self) -> Result<(u16, u16), Self::Error>;
    fn set_features(
        &mut self,
        features: BackendFeatures,
    ) -> Result<(), Self::Error>;
    fn poll_event(&mut self, timeout: Duration) -> Result<bool, Self::Error>;
    fn read_event(&mut self) -> Result<Option<Event>, Self::Error>;

    // Provided methods
    fn supports_suspend(&self) -> bool { ... }
    fn suspend(&mut self) -> Result<bool, Self::Error> { ... }
    fn resume(&mut self) -> Result<(), Self::Error> { ... }
}
Expand description

Event source abstraction: terminal size queries, feature toggles, and event I/O.

This is the input half of the backend boundary. The runtime polls this for canonical Event values without knowing whether they come from crossterm, raw Unix reads, or DOM events.

Required Associated Types§

Source

type Error: Debug + Display

Platform-specific error type.

Required Methods§

Source

fn size(&self) -> Result<(u16, u16), Self::Error>

Query current terminal dimensions (columns, rows).

Source

fn set_features(&mut self, features: BackendFeatures) -> Result<(), Self::Error>

Enable or disable terminal features (mouse, paste, focus, kitty keyboard).

Backends must track current state and only emit escape sequences for changes.

Source

fn poll_event(&mut self, timeout: Duration) -> Result<bool, Self::Error>

Poll for an available event, returning true if one is ready.

Must not block longer than timeout. Returns Ok(false) on timeout.

Source

fn read_event(&mut self) -> Result<Option<Event>, Self::Error>

Read the next available event, or None if none is ready.

Call after poll_event returns true, or speculatively.

A prior poll_event readiness result is a hint, not a guarantee: implementations may return Ok(None) even immediately after a true poll (e.g. the pending input was discarded by the parser, or, on Windows, console readiness was spurious — see frankentui#95). Implementations must not park indefinitely when no event is actually pending; callers must treat Ok(None) as “nothing decodable right now” and return to their poll loop.

Provided Methods§

Source

fn supports_suspend(&self) -> bool

Whether suspend can hand the terminal back for a job-control stop. The runtime claims SIGTSTP/SIGTTIN/SIGTTOU only for a source that says so; others keep the signals’ default action.

Source

fn suspend(&mut self) -> Result<bool, Self::Error>

Hand the terminal back to the shell ahead of a job-control stop: disable input modes, leave the alternate screen and restore the original terminal modes, keeping what is needed to undo it.

Returns Ok(false) when this source owns no terminal session to release; the runtime then does not stop the process.

Source

fn resume(&mut self) -> Result<(), Self::Error>

Undo suspend after the process is continued. A no-op when nothing is suspended.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§