Skip to main content

LineEditor

Trait LineEditor 

Source
pub trait LineEditor {
    // Required methods
    fn handle_key(&mut self, key: Key, text: &str) -> EditResult;
    fn cursor(&self) -> usize;
    fn status(&self) -> &str;
    fn selection(&self) -> Option<Range<usize>>;
    fn reset(&mut self);
    fn set_cursor(&mut self, pos: usize, text: &str);
}
Expand description

The contract between a line editor and its host application.

Implementations handle key interpretation and cursor management, while the host owns the text buffer and handles rendering.

Required Methods§

Source

fn handle_key(&mut self, key: Key, text: &str) -> EditResult

Process a key event, returning edits to apply and any action requested.

The text parameter is the current content - the editor uses it to calculate motions but never modifies it directly.

Source

fn cursor(&self) -> usize

Current cursor position as a byte offset into the text.

Source

fn status(&self) -> &str

Status text for display (e.g., “NORMAL”, “INSERT”, “– VISUAL –”).

Source

fn selection(&self) -> Option<Range<usize>>

Selection range for highlighting, if in visual mode.

Source

fn reset(&mut self)

Reset editor state (call after submitting/clearing input).

Source

fn set_cursor(&mut self, pos: usize, text: &str)

Set cursor position, clamped to valid bounds within text.

Implementors§