Struct Editor
#[must_use]
pub struct Editor<H: Helper, I: History> { /* private fields */ }
Line editor
Implementations
impl<H: Helper + Default> Editor<H, DefaultHistory>
fn default() -> Result<Self>Create an editor with the default configuration and helper
fn with_default(config: Config) -> Result<Self>Create an editor with a specific configuration and default helper
impl<H: Helper> Editor<H, DefaultHistory>
fn new() -> Result<Self>Create an editor with the default configuration but no helper
fn with_config(config: Config) -> Result<Self>Create an editor with a specific configuration but no helper.
fn with_helper(h: H) -> Result<Self>Create an editor with a specific helper.
impl<H: Helper, I: History> Editor<H, I>
fn with_history(config: Config, history: I) -> Result<Self>Create an editor with a custom history impl.
fn readline<P: Prompt + ?Sized>(&mut self, prompt: &P) -> Result<String>This method will read a line from STDIN and will display a
prompt.promptshould not be styled (in case the terminal doesn't support ANSI) directly: useHighlighter::highlight_promptinstead.It uses terminal-style interaction if
stdinis connected to a terminal. Otherwise (e.g., ifstdinis a pipe or the terminal is not supported), it uses file-style interaction.Errors
Will return
Errif an IO error occursfn readline_with_initial<P: Prompt + ?Sized>(&mut self, prompt: &P, initial: (&str, &str)) -> Result<String>This function behaves in the exact same manner as
Editor::readline, except that it pre-populates the input area.The text that resides in the input area is given as a 2-tuple. The string on the left of the tuple is what will appear to the left of the cursor and the string on the right is what will appear to the right of the cursor.
Errors
Will return
Errif an IO error occursfn load_history<P: AsRef<Path> + ?Sized>(&mut self, path: &P) -> Result<()>Load the history from the specified file.
Errors
Will return
Errif an IO error occursfn save_history<P: AsRef<Path> + ?Sized>(&mut self, path: &P) -> Result<()>Save the history in the specified file.
Errors
Will return
Errif an IO error occursfn append_history<P: AsRef<Path> + ?Sized>(&mut self, path: &P) -> Result<()>Append new entries in the specified file.
Errors
Will return
Errif an IO error occursfn add_history_entry<S: AsRef<str> + Into<String>>(&mut self, line: S) -> Result<bool>Add a new entry in the history.
Errors
Will return
Errif entry cannot be persistedfn clear_history(&mut self) -> Result<()>Clear history.
Errors
Will return
Errif an IO error occursfn history_mut(&mut self) -> &mut IReturn a mutable reference to the history object.
fn history(&self) -> &IReturn an immutable reference to the history object.
fn set_helper(&mut self, helper: Option<H>)Register a callback function to be called for tab-completion or to show hints to the user at the right of the prompt.
fn helper_mut(&mut self) -> Option<&mut H>Return a mutable reference to the helper.
fn helper(&self) -> Option<&H>Return an immutable reference to the helper.
fn bind_sequence<E: Into<Event>, R: Into<EventHandler>>(&mut self, key_seq: E, handler: R) -> Option<EventHandler>Bind a sequence to a command.
fn unbind_sequence<E: Into<Event>>(&mut self, key_seq: E) -> Option<EventHandler>Remove a binding for the given sequence.
fn iter<'a>(&'a mut self, prompt: &'a str) -> impl Iterator<Item = Result<String>> + 'aReturns an iterator over edited lines. Iterator ends at EOF.
let mut rl = rustyline::DefaultEditor::new()?; for readline in rl.iter("> ") { match readline { Ok(line) => { println!("Line: {}", line); } Err(err) => { println!("Error: {:?}", err); break; } } } # Ok::<(), rustyline::error::ReadlineError>(())fn dimensions(&mut self) -> Option<(u16, u16)>If output stream is a tty, this function returns its width and height as a number of characters.
fn clear_screen(&mut self) -> Result<()>Clear the screen.
Errors
Will return
Errif an IO error occursfn create_external_printer(&mut self) -> Result<<PosixTerminal as Term>::ExternalPrinter>Create an external printer
fn set_cursor_visibility(&mut self, visible: bool) -> Result<Option<<PosixTerminal as Term>::CursorGuard>>Change cursor visibility
Errors
Will return
Errif an IO error occurs
Trait Implementations
impl<H: Helper, I: History> Configurer for Editor<H, I>
fn config_mut(&mut self) -> &mut Configfn set_max_history_size(&mut self, max_size: usize) -> Result<()>fn set_history_ignore_dups(&mut self, yes: bool) -> Result<()>fn set_history_ignore_space(&mut self, yes: bool)
impl<H: Helper, I: History> Debug for Editor<H, I>
fn fmt(&self, f: &mut Formatter<'_>) -> Result