Skip to main content

Host

Trait Host 

Source
pub trait Host: Send {
    type Intent;

    // Required methods
    fn write_clipboard(&mut self, text: String);
    fn read_clipboard(&mut self) -> Option<String>;
    fn now(&self) -> Duration;
    fn prompt_search(&mut self) -> Option<String>;
    fn emit_cursor_shape(&mut self, shape: CursorShape);
    fn viewport(&self) -> &Viewport;
    fn viewport_mut(&mut self) -> &mut Viewport;
    fn emit_intent(&mut self, intent: Self::Intent);

    // Provided methods
    fn should_cancel(&self) -> bool { ... }
    fn display_line_for(&self, pos: Pos) -> u32 { ... }
    fn pos_for_display(&self, line: u32, col: u32) -> Pos { ... }
    fn syntax_highlights(&self, range: Range<Pos>) -> Vec<Highlight> { ... }
}
Expand description

Host adapter consumed by the engine. Lives behind the planned Editor<B: Buffer, H: Host> generic; today it’s the contract that buffr-modal::BuffrHost and the (future) sqeel-tui Host impl align against.

Methods with default impls return safe no-ops so hosts that don’t need a feature (cancellation, wrap-aware motion, syntax highlights) can ignore them.

Required Associated Types§

Source

type Intent

Custom intent type. Hosts that don’t fan out actions back to themselves can use the unit type via the default impl approach (set associated type explicitly).

Required Methods§

Source

fn write_clipboard(&mut self, text: String)

Fire-and-forget clipboard write. Engine never blocks; the host queues internally and flushes on its own task (OSC52, wl-copy, pbcopy, …).

Source

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

Returns the last-known cached clipboard value. May be stale — matches the OSC52/wl-paste model neovim and helix both ship.

Source

fn now(&self) -> Duration

Monotonic time. Multi-key timeout (timeoutlen) resolution reads this; engine never reads Instant::now() directly so macro replay stays deterministic.

Synchronously prompt the user for a search pattern. Returning None aborts the search.

Source

fn emit_cursor_shape(&mut self, shape: CursorShape)

Engine emits this on every mode transition. Hosts repaint the cursor in the requested shape.

Source

fn viewport(&self) -> &Viewport

Borrow the host’s viewport. The host writes width/height/ text_width/wrap per render frame; the engine reads/writes top_row / top_col to scroll. 0.0.34 (Patch C-δ.1) moved this off hjkl_buffer::Buffer onto Host.

Source

fn viewport_mut(&mut self) -> &mut Viewport

Mutable viewport access. Engine motion + scroll code routes here when scrolloff math advances top_row.

Source

fn emit_intent(&mut self, intent: Self::Intent)

Host-defined event the engine raises (LSP request, fold op, buffer switch, …).

Provided Methods§

Source

fn should_cancel(&self) -> bool

Cooperative cancellation. Engine polls during long search / regex / multi-cursor edit loops. Default returns false.

Source

fn display_line_for(&self, pos: Pos) -> u32

Map a logical position to its display line for gj/gk. Hosts without wrapping may use the default identity impl.

Source

fn pos_for_display(&self, line: u32, col: u32) -> Pos

Inverse of [display_line_for]. Default identity.

Source

fn syntax_highlights(&self, range: Range<Pos>) -> Vec<Highlight>

Host-supplied syntax highlights for range. Empty by default; hosts wire tree-sitter or LSP semantic tokens here.

Implementors§