pub struct Editor<H: Helper> { /* private fields */ }
Expand description
Line editor
Implementations
sourceimpl<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>
Available on crate feature custom-bindings
only.
pub fn bind_sequence<E: Into<Event>, R: Into<EventHandler>>(
&mut self,
key_seq: E,
handler: R
) -> Option<EventHandler>
custom-bindings
only.Bind a sequence to a command.
sourcepub fn unbind_sequence<E: Into<Event>>(
&mut self,
key_seq: E
) -> Option<EventHandler>
Available on crate feature custom-bindings
only.
pub fn unbind_sequence<E: Into<Event>>(
&mut self,
key_seq: E
) -> Option<EventHandler>
custom-bindings
only.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
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<<Console as Term>::ExternalPrinter>
pub fn create_external_printer(
&mut self
) -> Result<<Console as Term>::ExternalPrinter>
Create an external printer
Trait Implementations
sourceimpl<H: Helper> Configurer for Editor<H>
impl<H: Helper> Configurer for Editor<H>
sourcefn config_mut(&mut self) -> &mut Config
fn config_mut(&mut self) -> &mut Config
Config
accessor.
sourcefn set_max_history_size(&mut self, max_size: usize)
fn set_max_history_size(&mut self, max_size: usize)
Set the maximum length for the history.
sourcefn set_history_ignore_dups(&mut self, yes: bool)
fn set_history_ignore_dups(&mut self, yes: bool)
Tell if lines which match the previous history entry are saved or not in the history list. Read more
sourcefn set_history_ignore_space(&mut self, yes: bool)
fn set_history_ignore_space(&mut self, yes: bool)
Tell if lines which begin with a space character are saved or not in the history list. Read more
sourcefn set_color_mode(&mut self, color_mode: ColorMode)
fn set_color_mode(&mut self, color_mode: ColorMode)
Forces colorization on or off. Read more
sourcefn set_completion_type(&mut self, completion_type: CompletionType)
fn set_completion_type(&mut self, completion_type: CompletionType)
Set completion_type
.
sourcefn set_completion_prompt_limit(&mut self, completion_prompt_limit: usize)
fn set_completion_prompt_limit(&mut self, completion_prompt_limit: usize)
The number of possible completions that determines when the user is asked whether the list of possibilities should be displayed. Read more
sourcefn set_keyseq_timeout(&mut self, keyseq_timeout_ms: i32)
fn set_keyseq_timeout(&mut self, keyseq_timeout_ms: i32)
Timeout for ambiguous key sequences in milliseconds.
sourcefn set_edit_mode(&mut self, edit_mode: EditMode)
fn set_edit_mode(&mut self, edit_mode: EditMode)
Choose between Emacs or Vi mode.
sourcefn set_auto_add_history(&mut self, yes: bool)
fn set_auto_add_history(&mut self, yes: bool)
Tell if lines are automatically added to the history. Read more
sourcefn set_bell_style(&mut self, bell_style: BellStyle)
fn set_bell_style(&mut self, bell_style: BellStyle)
Set bell style: beep, flash or nothing.
sourcefn set_behavior(&mut self, behavior: Behavior)
fn set_behavior(&mut self, behavior: Behavior)
Whether to use stdio or not Read more
sourcefn set_tab_stop(&mut self, tab_stop: usize)
fn set_tab_stop(&mut self, tab_stop: usize)
Horizontal space taken by a tab. Read more
sourcefn set_check_cursor_position(&mut self, yes: bool)
fn set_check_cursor_position(&mut self, yes: bool)
Check if cursor position is at leftmost before displaying prompt. Read more
sourcefn set_indent_size(&mut self, size: usize)
fn set_indent_size(&mut self, size: usize)
Indentation size for indent/dedent commands Read more
sourcefn enable_bracketed_paste(&mut self, enabled: bool)
fn enable_bracketed_paste(&mut self, enabled: bool)
Enable or disable bracketed paste on unix platform Read more
Auto Trait Implementations
impl<H> !RefUnwindSafe for Editor<H>
impl<H> Send for Editor<H> where
H: Send,
impl<H> Sync for Editor<H> where
H: Sync,
impl<H> Unpin for Editor<H> where
H: Unpin,
impl<H> !UnwindSafe for Editor<H>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more