Skip to main content

LineReader

Struct LineReader 

Source
pub struct LineReader { /* 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 LineReader

Source

pub fn new(max_history: usize) -> Self

Create a new LineReader with the given maximum history size.

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, H>( &mut self, prompt_fn: P, handler: &H, cancel_token: CancellationToken, ) -> Result<()>
where P: Fn() -> String, H: 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, H>( &mut self, prompt_fn: P, handler: &H, cancel_token: CancellationToken, reader: Box<dyn Read>, ) -> Result<()>
where P: Fn() -> String, H: LineHandler,

Run an interactive REPL loop using a provided reader.

Auto Trait Implementations§

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.