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
impl LineReader
Sourcepub fn new(max_history: usize) -> Self
pub fn new(max_history: usize) -> Self
Create a new LineReader with the given maximum history size.
Sourcepub fn read_line(
&mut self,
prompt: &str,
cancel_token: Option<CancellationToken>,
) -> Result<Option<String>>
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).
Sourcepub fn read_line_with_stdin(
&mut self,
prompt: &str,
cancel_token: Option<CancellationToken>,
reader: Box<dyn Read>,
) -> Result<Option<String>>
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.
Sourcepub fn run_loop<P, H>(
&mut self,
prompt_fn: P,
handler: &H,
cancel_token: CancellationToken,
) -> Result<()>
pub fn run_loop<P, H>( &mut self, prompt_fn: P, handler: &H, cancel_token: CancellationToken, ) -> Result<()>
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
Sourcepub fn run_loop_with_stdin<P, H>(
&mut self,
prompt_fn: P,
handler: &H,
cancel_token: CancellationToken,
reader: Box<dyn Read>,
) -> Result<()>
pub fn run_loop_with_stdin<P, H>( &mut self, prompt_fn: P, handler: &H, cancel_token: CancellationToken, reader: Box<dyn Read>, ) -> Result<()>
Run an interactive REPL loop using a provided reader.
Auto Trait Implementations§
impl Freeze for LineReader
impl RefUnwindSafe for LineReader
impl Send for LineReader
impl Sync for LineReader
impl Unpin for LineReader
impl UnsafeUnpin for LineReader
impl UnwindSafe for LineReader
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more