pub struct Editor<H: Helper> { /* private fields */ }
Expand description
Line editor
Implementations§
source§impl<H: Helper> Editor<H>
impl<H: Helper> Editor<H>
sourcepub fn with_config(config: Config) -> Result<Self>
pub fn with_config(config: Config) -> Result<Self>
Create an editor with a specific configuration.
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,
) -> bool
pub fn add_history_entry<S: AsRef<str> + Into<String>>( &mut self, line: S, ) -> bool
Add a new entry in the history.
sourcepub fn clear_history(&mut self)
pub fn clear_history(&mut self)
Clear history.
sourcepub fn history_mut(&mut self) -> &mut History
pub fn history_mut(&mut self) -> &mut History
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::Editor::<()>::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 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
Trait Implementations§
source§impl<H: Helper> Configurer for Editor<H>
impl<H: Helper> Configurer for Editor<H>
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)
fn set_max_history_size(&mut self, max_size: usize)
source§fn set_history_ignore_dups(&mut self, yes: bool)
fn set_history_ignore_dups(&mut self, yes: bool)
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
.