pub struct Editor<'a> { /* private fields */ }
Expand description
The core line editor. Displays and provides editing for history and the new buffer.
Implementations§
Source§impl<'a> Editor<'a>
impl<'a> Editor<'a>
pub fn new( out: &'a mut dyn Write, prompt: Prompt, f: Option<ColorClosure>, history: &'a mut History, buf: &'a mut String, editor_rules: &'a dyn EditorRules, ) -> Result<Self>
pub fn new_with_init_buffer<B: Into<Buffer>>( out: &'a mut dyn Write, prompt: Prompt, f: Option<ColorClosure>, history: &'a mut History, buf: &'a mut String, buffer: B, editor_rules: &'a dyn EditorRules, ) -> Result<Self>
pub fn set_closure(&mut self, closure: ColorClosure) -> &mut Self
pub fn use_closure(&mut self, use_closure: bool)
Sourcepub fn current_history_location(&self) -> Option<usize>
pub fn current_history_location(&self) -> Option<usize>
None if we’re on the new buffer, else the index of history
pub fn get_words_and_cursor_position( &self, ) -> (Vec<(usize, usize)>, CursorPosition)
pub fn history(&mut self) -> &mut History
pub fn cursor(&self) -> usize
pub fn handle_newline(&mut self) -> Result<bool>
Sourcepub fn search(&mut self, forward: bool) -> Result<()>
pub fn search(&mut self, forward: bool) -> Result<()>
Begin or continue a search through history. If forward is true then start at top (or current_history_loc if set). If started with forward true then incremental search goes forward (top to bottom) other wise reverse (bottom to top). It is valid to continue a search with forward changed (i.e. reverse search direction for one result).
pub fn flush(&mut self) -> Result<()>
Sourcepub fn undo(&mut self) -> Option<usize>
pub fn undo(&mut self) -> Option<usize>
Attempts to undo an action on the current buffer.
Returns Ok(true)
if an action was undone.
Returns Ok(false)
if there was no action to undo.
pub fn redo(&mut self) -> Option<usize>
Sourcepub fn paste(&mut self, right: bool, count: usize) -> Result<()>
pub fn paste(&mut self, right: bool, count: usize) -> Result<()>
Inserts characters from internal register to the right or the left of the cursor, moving the cursor to the last character inserted.
pub fn revert(&mut self) -> Result<bool>
pub fn skip_completions_hint(&mut self)
pub fn complete(&mut self, handler: &mut dyn Completer) -> Result<()>
Sourcepub fn delete_word_before_cursor(
&mut self,
ignore_space_before_cursor: bool,
) -> Result<()>
pub fn delete_word_before_cursor( &mut self, ignore_space_before_cursor: bool, ) -> Result<()>
Deletes the word preceding the cursor.
If ignore_space_before_cursor
is true and there is space directly before the cursor,
this method ignores that space until it finds a word.
If ignore_space_before_cursor
is false and there is space directly before the cursor,
nothing is deleted.
Sourcepub fn clear(&mut self) -> Result<()>
pub fn clear(&mut self) -> Result<()>
Clears the screen then prints the prompt and current buffer.
Sourcepub fn move_down(&mut self) -> Result<()>
pub fn move_down(&mut self) -> Result<()>
Move down (forwards) in history, or to the new buffer if we reach the end of history.
Sourcepub fn move_to_start_of_history(&mut self) -> Result<()>
pub fn move_to_start_of_history(&mut self) -> Result<()>
Moves to the start of history (ie. the earliest history entry).
Sourcepub fn move_to_end_of_history(&mut self) -> Result<()>
pub fn move_to_end_of_history(&mut self) -> Result<()>
Moves to the end of history (ie. the new buffer).
pub fn flip_case(&mut self) -> Result<()>
Sourcepub fn insert_str_after_cursor(&mut self, s: &str) -> Result<()>
pub fn insert_str_after_cursor(&mut self, s: &str) -> Result<()>
Inserts a string directly after the cursor, moving the cursor to the right.
Note: it is more efficient to call insert_chars_after_cursor()
directly.
Sourcepub fn insert_after_cursor(&mut self, c: char) -> Result<()>
pub fn insert_after_cursor(&mut self, c: char) -> Result<()>
Inserts a character directly after the cursor, moving the cursor to the right.
Sourcepub fn insert_chars_after_cursor(&mut self, cs: &[char]) -> Result<()>
pub fn insert_chars_after_cursor(&mut self, cs: &[char]) -> Result<()>
Inserts characters directly after the cursor, moving the cursor to the right.
Sourcepub fn delete_before_cursor(&mut self) -> Result<()>
pub fn delete_before_cursor(&mut self) -> Result<()>
Deletes the character directly before the cursor, moving the cursor to the left. If the cursor is at the start of the line, nothing happens.
Sourcepub fn delete_after_cursor(&mut self) -> Result<()>
pub fn delete_after_cursor(&mut self) -> Result<()>
Deletes the character directly after the cursor. The cursor does not move. If the cursor is at the end of the line, nothing happens.
Sourcepub fn delete_all_before_cursor(&mut self) -> Result<()>
pub fn delete_all_before_cursor(&mut self) -> Result<()>
Deletes every character preceding the cursor until the beginning of the line.
Sourcepub fn yank_all_after_cursor(&mut self) -> Result<()>
pub fn yank_all_after_cursor(&mut self) -> Result<()>
Yanks every character after the cursor until the end of the line.
Sourcepub fn delete_all_after_cursor(&mut self) -> Result<()>
pub fn delete_all_after_cursor(&mut self) -> Result<()>
Deletes every character after the cursor until the end of the line.
Sourcepub fn yank_until(&mut self, position: usize) -> Result<()>
pub fn yank_until(&mut self, position: usize) -> Result<()>
Yanks every character from the cursor until the given position.
Sourcepub fn delete_until_silent(&mut self, position: usize) -> Result<()>
pub fn delete_until_silent(&mut self, position: usize) -> Result<()>
Deletes every character from the cursor until the given position. Does not register as an action in the undo/redo buffer or in the buffer’s register.
Sourcepub fn delete_until(&mut self, position: usize) -> Result<()>
pub fn delete_until(&mut self, position: usize) -> Result<()>
Deletes every character from the cursor until the given position.
Sourcepub fn yank_until_inclusive(&mut self, position: usize) -> Result<()>
pub fn yank_until_inclusive(&mut self, position: usize) -> Result<()>
Yanks every character from the cursor until the given position, inclusive.
Sourcepub fn delete_until_inclusive(&mut self, position: usize) -> Result<()>
pub fn delete_until_inclusive(&mut self, position: usize) -> Result<()>
Deletes every character from the cursor until the given position, inclusive.
Sourcepub fn move_cursor_left(&mut self, count: usize) -> Result<()>
pub fn move_cursor_left(&mut self, count: usize) -> Result<()>
Moves the cursor to the left by count
characters.
The cursor will not go past the start of the buffer.
Sourcepub fn move_cursor_right(&mut self, count: usize) -> Result<()>
pub fn move_cursor_right(&mut self, count: usize) -> Result<()>
Moves the cursor to the right by count
characters.
The cursor will not go past the end of the buffer.
Sourcepub fn move_cursor_to(&mut self, pos: usize) -> Result<()>
pub fn move_cursor_to(&mut self, pos: usize) -> Result<()>
Moves the cursor to pos
. If pos
is past the end of the buffer, it will be clamped.
Sourcepub fn move_cursor_to_start_of_line(&mut self) -> Result<()>
pub fn move_cursor_to_start_of_line(&mut self) -> Result<()>
Moves the cursor to the start of the line.
Sourcepub fn move_cursor_to_end_of_line(&mut self) -> Result<()>
pub fn move_cursor_to_end_of_line(&mut self) -> Result<()>
Moves the cursor to the end of the line.
pub fn curr_char(&self) -> Option<&str>
pub fn is_cursor_at_beginning_of_word_or_line(&self) -> bool
pub fn is_cursor_at_end_of_line(&self) -> bool
Sourcepub fn current_buffer(&self) -> &Buffer
pub fn current_buffer(&self) -> &Buffer
Returns a reference to the current buffer being edited. This may be the new buffer or a buffer from history.
Sourcepub fn current_buffer_mut(&mut self) -> &mut Buffer
pub fn current_buffer_mut(&mut self) -> &mut Buffer
Returns a mutable reference to the current buffer being edited. This may be the new buffer or a buffer from history.
Sourcepub fn accept_autosuggestion(&mut self) -> Result<()>
pub fn accept_autosuggestion(&mut self) -> Result<()>
Accept autosuggestion and copy its content into current buffer
pub fn is_currently_showing_autosuggestion(&self) -> bool
pub fn set_no_eol(&mut self, no_eol: bool)
Sourcepub fn display_term(&mut self) -> Result<()>
pub fn display_term(&mut self) -> Result<()>
Deletes the displayed prompt and buffer, replacing them with the current prompt and buffer
Sourcepub fn set_prompt_prefix<P: Into<String>>(&mut self, prefix: P)
pub fn set_prompt_prefix<P: Into<String>>(&mut self, prefix: P)
Modifies the prompt prefix. Useful to reflect a keybinding mode (vi insert/normal for instance).
Sourcepub fn clear_prompt_prefix(&mut self)
pub fn clear_prompt_prefix(&mut self)
Clears the prompt prefix. Useful to reflect a keybinding mode (vi insert/normal for instance).
Sourcepub fn set_prompt_suffix<S: Into<String>>(&mut self, suffix: S)
pub fn set_prompt_suffix<S: Into<String>>(&mut self, suffix: S)
Modifies the prompt suffix. Useful to reflect a keybinding mode (vi insert/normal for instance).
Sourcepub fn clear_prompt_suffix(&mut self)
pub fn clear_prompt_suffix(&mut self)
Clears the prompt prefix. Useful to reflect a keybinding mode (vi insert/normal for instance).