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<H: History> LineEditor<H>
impl<H: History> LineEditor<H>
pub fn with_history(history: H) -> Self
pub const fn with_history_and_len(history: H, len: usize) -> Self
pub fn buffer(&self) -> &str
pub fn cursor_pos(&self) -> usize
Sourcepub fn start_new_line(&mut self)
pub fn start_new_line(&mut self)
Prepares the internal state for a new line of input.
pub fn input_char(&mut self, code: u32) -> Option<String>
pub fn input_char_with_handler<K: KeyEventHandler>( &mut self, code: u32, handler: &mut K, ) -> Option<String>
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, L>(
&mut self,
prompt_fn: P,
handler: &L,
cancel_token: CancellationToken,
) -> Result<()>
pub fn run_loop<P, L>( &mut self, prompt_fn: P, handler: &L, 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, L>(
&mut self,
prompt_fn: P,
handler: &L,
cancel_token: CancellationToken,
reader: Box<dyn Read>,
) -> Result<()>
pub fn run_loop_with_stdin<P, L>( &mut self, prompt_fn: P, handler: &L, cancel_token: CancellationToken, reader: Box<dyn Read>, ) -> Result<()>
Run an interactive REPL loop using a provided reader.
Sourcepub 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>>
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> 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