Skip to main content

LineEditor

Struct LineEditor 

Source
pub struct LineEditor<H: History = InMemoryHistory> { /* private fields */ }
Expand description

A minimal line editor with command history.

Supports:

  • Up/Down arrow keys to navigate command history
  • Left/Right arrow keys to move the cursor within the line
  • Home/End to jump to the beginning/end of the line
  • Delete to remove the character under the cursor
  • Backspace to remove the character before the cursor
  • Ctrl-U to clear the line, Ctrl-K to kill to end of line
  • Ctrl-W to delete the previous word
  • Ctrl-A / Ctrl-E for Home / End

Implementations§

Source§

impl LineEditor<InMemoryHistory>

Source

pub const fn new(max_history: usize) -> Self

Create a new LineEditor with the given maximum history size.

Source§

impl<H: History> LineEditor<H>

Source

pub fn with_history(history: H) -> Self

Source

pub const fn with_history_and_len(history: H, len: usize) -> Self

Source

pub fn buffer(&self) -> &str

Source

pub fn cursor_pos(&self) -> usize

Source

pub fn start_new_line(&mut self)

Prepares the internal state for a new line of input.

Source

pub fn input_char(&mut self, code: u32) -> Option<String>

Source

pub fn input_char_with_handler<K: KeyEventHandler>( &mut self, code: u32, handler: &mut K, ) -> Option<String>

Source

pub fn read_line( &mut self, prompt: &str, cancel_token: Option<CancellationToken>, ) -> Result<Option<String>>

Read a line interactively with arrow-key history navigation.

Returns Ok(Some(line)) on success, Ok(None) on EOF (Ctrl-D).

Source

pub fn read_line_with_stdin( &mut self, prompt: &str, cancel_token: Option<CancellationToken>, reader: Box<dyn Read>, ) -> Result<Option<String>>

Read a line interactively using a provided reader.

Source

pub fn run_loop<P, L>( &mut self, prompt_fn: P, handler: &L, cancel_token: CancellationToken, ) -> Result<()>
where P: Fn() -> String, L: LineHandler,

Run an interactive REPL loop, delegating each line to handler.

The loop ends when:

  • The handler returns Ok(LoopAction::Break)
  • EOF is reached (Ctrl-D)
  • An I/O error occurs
Source

pub fn run_loop_with_stdin<P, L>( &mut self, prompt_fn: P, handler: &L, cancel_token: CancellationToken, reader: Box<dyn Read>, ) -> Result<()>
where P: Fn() -> String, L: LineHandler,

Run an interactive REPL loop using a provided reader.

Source

pub fn read_line_from<R: Read, W: Write>( &mut self, reader: &mut R, writer: &mut W, prompt: &str, cancel_token: Option<CancellationToken>, ) -> Result<Option<String>>

Core line-editing logic, reading bytes from reader and writing to writer. Separated from read_line so it can be tested with synthetic input.

Auto Trait Implementations§

§

impl<H> Freeze for LineEditor<H>
where H: Freeze,

§

impl<H> RefUnwindSafe for LineEditor<H>
where H: RefUnwindSafe,

§

impl<H> Send for LineEditor<H>
where H: Send,

§

impl<H> Sync for LineEditor<H>
where H: Sync,

§

impl<H> Unpin for LineEditor<H>
where H: Unpin,

§

impl<H> UnsafeUnpin for LineEditor<H>
where H: UnsafeUnpin,

§

impl<H> UnwindSafe for LineEditor<H>
where H: UnwindSafe,

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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.