pub struct Editor<H: Helper, I: History> { /* private fields */ }
Expand description
Line editor
Implementations§
source§impl<H: Helper> Editor<H, DefaultHistory>
impl<H: Helper> Editor<H, DefaultHistory>
source§impl<H: Helper, I: History> Editor<H, I>
impl<H: Helper, I: History> Editor<H, I>
sourcepub fn with_history(config: Config, history: I) -> Result<Self>
pub fn with_history(config: Config, history: I) -> Result<Self>
Create an editor with a custom history impl.
sourcepub fn readline(&mut self, prompt: &str) -> Result<String>
pub fn readline(&mut self, prompt: &str) -> Result<String>
This method will read a line from STDIN and will display a prompt
.
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.
sourcepub fn readline_with_initial(
&mut self,
prompt: &str,
initial: (&str, &str),
) -> Result<String>
pub fn readline_with_initial( &mut self, prompt: &str, initial: (&str, &str), ) -> Result<String>
This function behaves in the exact same manner as 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.
sourcepub fn load_history<P: AsRef<Path> + ?Sized>(&mut self, path: &P) -> Result<()>
pub fn load_history<P: AsRef<Path> + ?Sized>(&mut self, path: &P) -> Result<()>
Load the history from the specified file.
sourcepub fn save_history<P: AsRef<Path> + ?Sized>(&mut self, path: &P) -> Result<()>
pub fn save_history<P: AsRef<Path> + ?Sized>(&mut self, path: &P) -> Result<()>
Save the history in the specified file.
sourcepub fn append_history<P: AsRef<Path> + ?Sized>(
&mut self,
path: &P,
) -> Result<()>
pub fn append_history<P: AsRef<Path> + ?Sized>( &mut self, path: &P, ) -> Result<()>
Append new entries in the specified file.
sourcepub fn add_history_entry<S: AsRef<str> + Into<String>>(
&mut self,
line: S,
) -> Result<bool>
pub fn add_history_entry<S: AsRef<str> + Into<String>>( &mut self, line: S, ) -> Result<bool>
Add a new entry in the history.
sourcepub fn clear_history(&mut self) -> Result<()>
pub fn clear_history(&mut self) -> Result<()>
Clear history.
sourcepub fn history_mut(&mut self) -> &mut I
pub fn history_mut(&mut self) -> &mut I
Return a mutable reference to the history object.
sourcepub fn set_helper(&mut self, helper: Option<H>)
pub 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.
sourcepub fn helper_mut(&mut self) -> Option<&mut H>
pub fn helper_mut(&mut self) -> Option<&mut H>
Return a mutable reference to the helper.
sourcepub fn bind_sequence<E: Into<Event>, R: Into<EventHandler>>(
&mut self,
key_seq: E,
handler: R,
) -> Option<EventHandler>
pub fn bind_sequence<E: Into<Event>, R: Into<EventHandler>>( &mut self, key_seq: E, handler: R, ) -> Option<EventHandler>
Bind a sequence to a command.
sourcepub fn unbind_sequence<E: Into<Event>>(
&mut self,
key_seq: E,
) -> Option<EventHandler>
pub fn unbind_sequence<E: Into<Event>>( &mut self, key_seq: E, ) -> Option<EventHandler>
Remove a binding for the given sequence.
sourcepub fn iter<'a>(
&'a mut self,
prompt: &'a str,
) -> impl Iterator<Item = Result<String>> + 'a
pub 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;
}
}
}
sourcepub fn dimensions(&mut self) -> Option<(usize, usize)>
pub fn dimensions(&mut self) -> Option<(usize, usize)>
If output stream is a tty, this function returns its width and height as a number of characters.
sourcepub fn clear_screen(&mut self) -> Result<()>
pub fn clear_screen(&mut self) -> Result<()>
Clear the screen.
sourcepub fn create_external_printer(
&mut self,
) -> Result<<PosixTerminal as Term>::ExternalPrinter>
pub fn create_external_printer( &mut self, ) -> Result<<PosixTerminal as Term>::ExternalPrinter>
Create an external printer
sourcepub fn set_cursor_visibility(
&mut self,
visible: bool,
) -> Result<Option<<PosixTerminal as Term>::CursorGuard>>
pub fn set_cursor_visibility( &mut self, visible: bool, ) -> Result<Option<<PosixTerminal as Term>::CursorGuard>>
Change cursor visibility
Trait Implementations§
source§impl<H: Helper, I: History> Configurer for Editor<H, I>
impl<H: Helper, I: History> Configurer for Editor<H, I>
source§fn config_mut(&mut self) -> &mut Config
fn config_mut(&mut self) -> &mut Config
Config
accessor.source§fn set_max_history_size(&mut self, max_size: usize) -> Result<()>
fn set_max_history_size(&mut self, max_size: usize) -> Result<()>
source§fn set_history_ignore_dups(&mut self, yes: bool) -> Result<()>
fn set_history_ignore_dups(&mut self, yes: bool) -> Result<()>
source§fn set_history_ignore_space(&mut self, yes: bool)
fn set_history_ignore_space(&mut self, yes: bool)
source§fn set_color_mode(&mut self, color_mode: ColorMode)
fn set_color_mode(&mut self, color_mode: ColorMode)
source§fn set_completion_type(&mut self, completion_type: CompletionType)
fn set_completion_type(&mut self, completion_type: CompletionType)
completion_type
.