pub struct Editor<'a, W: Write> {
pub no_eol: bool,
/* private fields */
}
Expand description
The core line editor. Displays and provides editing for history and the new buffer.
Fields§
§no_eol: bool
Implementations§
Source§impl<'a, W: Write> Editor<'a, W>
impl<'a, W: Write> Editor<'a, W>
pub fn new( out: W, prompt: Prompt, f: Option<ColorClosure>, context: &'a mut Context, ) -> Result<Self>
pub fn new_with_init_buffer<B: Into<Buffer>>( out: W, prompt: Prompt, f: Option<ColorClosure>, context: &'a mut Context, buffer: B, ) -> Result<Self>
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 set_prompt(&mut self, prompt: Prompt)
pub fn context(&mut self) -> &mut Context
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) -> Result<bool>
pub fn undo(&mut self) -> Result<bool>
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) -> Result<bool>
pub fn revert(&mut self) -> Result<bool>
pub fn skip_completions_hint(&mut self)
pub fn complete<T: Completer>(&mut self, handler: &mut T) -> 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).
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 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 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 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 cursor_is_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
Sourcepub fn display(&mut self) -> Result<()>
pub fn display(&mut self) -> Result<()>
Deletes the displayed prompt and buffer, replacing them with the current prompt and buffer
Sourcepub fn set_vi_mode(&mut self, mode: ViPromptMode)
pub fn set_vi_mode(&mut self, mode: ViPromptMode)
Modifies the prompt to reflect the Vi mode.
This operation will be ignored if a static prompt is used, as mode changes will have no side effect.
Trait Implementations§
Auto Trait Implementations§
impl<'a, W> Freeze for Editor<'a, W>where
W: Freeze,
impl<'a, W> !RefUnwindSafe for Editor<'a, W>
impl<'a, W> !Send for Editor<'a, W>
impl<'a, W> !Sync for Editor<'a, W>
impl<'a, W> Unpin for Editor<'a, W>where
W: Unpin,
impl<'a, W> !UnwindSafe for Editor<'a, W>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more