pub struct LineEditor { /* private fields */ }Expand description
Main line editor interface with full editing and history support.
Provides a high-level API for reading edited lines from any Terminal
implementation. Handles all keyboard input, cursor movement, text editing,
and history navigation.
§Examples
use editline::{LineEditor, terminals::StdioTerminal};
let mut editor = LineEditor::new(1024, 50);
let mut terminal = StdioTerminal::new();
match editor.read_line(&mut terminal) {
Ok(line) => println!("Got: {}", line),
Err(e) => eprintln!("Error: {}", e),
}§Key Bindings
- Arrow keys: Move cursor left/right, navigate history up/down
- Home/End: Jump to start/end of line
- Backspace/Delete: Delete characters
- Ctrl+Left/Right: Move by word
- Alt+Backspace: Delete word left
- Ctrl+Delete: Delete word right
- Enter: Submit line
Implementations§
Source§impl LineEditor
impl LineEditor
Sourcepub fn new(buffer_capacity: usize, history_capacity: usize) -> Self
pub fn new(buffer_capacity: usize, history_capacity: usize) -> Self
Creates a new line editor with the specified capacities.
§Arguments
buffer_capacity- Initial capacity for the line buffer in byteshistory_capacity- Maximum number of history entries to store
§Examples
use editline::LineEditor;
// 1024 byte buffer, 50 history entries
let editor = LineEditor::new(1024, 50);Sourcepub fn read_line<T: Terminal>(&mut self, terminal: &mut T) -> Result<String>
pub fn read_line<T: Terminal>(&mut self, terminal: &mut T) -> Result<String>
Reads a line from the terminal with full editing support.
Enters raw mode, processes key events until Enter is pressed, then returns the edited line with leading and trailing whitespace removed. The trimmed line is automatically added to history if non-empty.
§Arguments
terminal- Any type implementing theTerminaltrait
§Returns
Ok(String) with the trimmed entered line, or Err if an I/O error occurs.
§Examples
use editline::{LineEditor, terminals::StdioTerminal};
let mut editor = LineEditor::new(1024, 50);
let mut terminal = StdioTerminal::new();
print!("> ");
std::io::Write::flush(&mut std::io::stdout()).unwrap();
let line = editor.read_line(&mut terminal)?;
println!("You entered: {}", line);Auto Trait Implementations§
impl Freeze for LineEditor
impl RefUnwindSafe for LineEditor
impl Send for LineEditor
impl Sync for LineEditor
impl Unpin for LineEditor
impl UnwindSafe for LineEditor
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