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.

prompt should not be styled (in case the terminal doesn't support ANSI) directly: use Highlighter::highlight_prompt instead.

It uses terminal-style interaction if stdin is connected to a terminal. Otherwise (e.g., if stdin is a pipe or the terminal is not supported), it uses file-style interaction.

Errors

Will return Err if an IO error occurs

fn 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 Err if an IO error occurs

fn load_history<P: AsRef<Path> + ?Sized>(&mut self, path: &P) -> Result<()>

Load the history from the specified file.

Errors

Will return Err if an IO error occurs

fn save_history<P: AsRef<Path> + ?Sized>(&mut self, path: &P) -> Result<()>

Save the history in the specified file.

Errors

Will return Err if an IO error occurs

fn append_history<P: AsRef<Path> + ?Sized>(&mut self, path: &P) -> Result<()>

Append new entries in the specified file.

Errors

Will return Err if an IO error occurs

fn add_history_entry<S: AsRef<str> + Into<String>>(&mut self, line: S) -> Result<bool>

Add a new entry in the history.

Errors

Will return Err if entry cannot be persisted

fn clear_history(&mut self) -> Result<()>

Clear history.

Errors

Will return Err if an IO error occurs

fn history_mut(&mut self) -> &mut I

Return a mutable reference to the history object.

fn history(&self) -> &I

Return 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>> + 'a

Returns 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 Err if an IO error occurs

fn 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 Err if an IO error occurs

Trait Implementations

impl<H: Helper, I: History> Configurer for Editor<H, I>

fn config_mut(&mut self) -> &mut Config
fn 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

Auto Trait Implementations

impl<H, I> !RefUnwindSafe for Editor<H, I>

impl<H, I> !UnwindSafe for Editor<H, I>

impl<H, I> Freeze for Editor<H, I> where I: Freeze, Option<H>: Freeze,

impl<H, I> Send for Editor<H, I> where I: Send, Option<H>: Send,

impl<H, I> Sync for Editor<H, I> where I: Sync, Option<H>: Sync,

impl<H, I> Unpin for Editor<H, I> where I: Unpin, Option<H>: Unpin,

impl<H, I> UnsafeUnpin for Editor<H, I> where I: UnsafeUnpin, Option<H>: UnsafeUnpin,

Blanket Implementations

impl<T> Any for Editor<H, I> where T: 'static + ?Sized,

impl<T> Borrow<T> for Editor<H, I> where T: ?Sized,

impl<T> BorrowMut<T> for Editor<H, I> where T: ?Sized,

impl<T> From<T> for Editor<H, I>

impl<T, U> Into<U> for Editor<H, I> where U: From<T>,

impl<T, U> TryFrom<U> for Editor<H, I> where U: Into<T>,

impl<T, U> TryInto<U> for Editor<H, I> where U: TryFrom<T>,