sl_liner

Struct Editor

Source
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>

Source

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>

Source

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>

Source

pub fn set_closure(&mut self, closure: ColorClosure) -> &mut Self

Source

pub fn use_closure(&mut self, use_closure: bool)

Source

pub fn current_history_location(&self) -> Option<usize>

None if we’re on the new buffer, else the index of history

Source

pub fn get_words_and_cursor_position( &self, ) -> (Vec<(usize, usize)>, CursorPosition)

Source

pub fn history(&mut self) -> &mut History

Source

pub fn cursor(&self) -> usize

Source

pub fn handle_newline(&mut self) -> Result<bool>

Source

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).

Source

pub fn flush(&mut self) -> Result<()>

Source

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.

Source

pub fn redo(&mut self) -> Option<usize>

Source

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.

Source

pub fn revert(&mut self) -> Result<bool>

Source

pub fn skip_completions_hint(&mut self)

Source

pub fn complete(&mut self, handler: &mut dyn Completer) -> Result<()>

Source

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.

Source

pub fn clear(&mut self) -> Result<()>

Clears the screen then prints the prompt and current buffer.

Source

pub fn move_up(&mut self) -> Result<()>

Move up (backwards) in history.

Source

pub fn move_down(&mut self) -> Result<()>

Move down (forwards) in history, or to the new buffer if we reach the end of history.

Source

pub fn move_to_start_of_history(&mut self) -> Result<()>

Moves to the start of history (ie. the earliest history entry).

Source

pub fn move_to_end_of_history(&mut self) -> Result<()>

Moves to the end of history (ie. the new buffer).

Source

pub fn flip_case(&mut self) -> Result<()>

Source

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.

Source

pub fn insert_after_cursor(&mut self, c: char) -> Result<()>

Inserts a character directly after the cursor, moving the cursor to the right.

Source

pub fn insert_chars_after_cursor(&mut self, cs: &[char]) -> Result<()>

Inserts characters directly after the cursor, moving the cursor to the right.

Source

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.

Source

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.

Source

pub fn delete_all_before_cursor(&mut self) -> Result<()>

Deletes every character preceding the cursor until the beginning of the line.

Source

pub fn yank_all_after_cursor(&mut self) -> Result<()>

Yanks every character after the cursor until the end of the line.

Source

pub fn delete_all_after_cursor(&mut self) -> Result<()>

Deletes every character after the cursor until the end of the line.

Source

pub fn yank_until(&mut self, position: usize) -> Result<()>

Yanks every character from the cursor until the given position.

Source

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.

Source

pub fn delete_until(&mut self, position: usize) -> Result<()>

Deletes every character from the cursor until the given position.

Source

pub fn yank_until_inclusive(&mut self, position: usize) -> Result<()>

Yanks every character from the cursor until the given position, inclusive.

Source

pub fn delete_until_inclusive(&mut self, position: usize) -> Result<()>

Deletes every character from the cursor until the given position, inclusive.

Source

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.

Source

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.

Source

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.

Source

pub fn move_cursor_to_start_of_line(&mut self) -> Result<()>

Moves the cursor to the start of the line.

Source

pub fn move_cursor_to_end_of_line(&mut self) -> Result<()>

Moves the cursor to the end of the line.

Source

pub fn curr_char(&self) -> Option<&str>

Source

pub fn is_cursor_at_beginning_of_word_or_line(&self) -> bool

Source

pub fn is_cursor_at_end_of_line(&self) -> bool

Source

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.

Source

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.

Source

pub fn accept_autosuggestion(&mut self) -> Result<()>

Accept autosuggestion and copy its content into current buffer

Source

pub fn is_currently_showing_autosuggestion(&self) -> bool

Source

pub fn set_no_eol(&mut self, no_eol: bool)

Source

pub fn display_term(&mut self) -> Result<()>

Deletes the displayed prompt and buffer, replacing them with the current prompt and buffer

Source

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).

Source

pub fn clear_prompt_prefix(&mut self)

Clears the prompt prefix. Useful to reflect a keybinding mode (vi insert/normal for instance).

Source

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).

Source

pub fn clear_prompt_suffix(&mut self)

Clears the prompt prefix. Useful to reflect a keybinding mode (vi insert/normal for instance).

Trait Implementations§

Source§

impl<'a> From<Editor<'a>> for String

Source§

fn from(ed: Editor<'a>) -> String

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<'a> Freeze for Editor<'a>

§

impl<'a> !RefUnwindSafe for Editor<'a>

§

impl<'a> !Send for Editor<'a>

§

impl<'a> !Sync for Editor<'a>

§

impl<'a> Unpin for Editor<'a>

§

impl<'a> !UnwindSafe for Editor<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.