Struct liner::Editor

source ·
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>

source

pub fn new( out: W, prompt: Prompt, f: Option<ColorClosure>, context: &'a mut Context ) -> Result<Self>

source

pub fn new_with_init_buffer<B: Into<Buffer>>( out: W, prompt: Prompt, f: Option<ColorClosure>, context: &'a mut Context, buffer: B ) -> Result<Self>

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 set_prompt(&mut self, prompt: Prompt)

source

pub fn context(&mut self) -> &mut Context

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

source

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

source

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

source

pub fn skip_completions_hint(&mut self)

source

pub fn complete<T: Completer>(&mut self, handler: &mut T) -> 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 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 delete_all_after_cursor(&mut self) -> Result<()>

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

source

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

Deletes every character from the cursor until the given position.

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 cursor_is_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 display(&mut self) -> Result<()>

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

source

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§

source§

impl<'a, W: Write> From<Editor<'a, W>> for String

source§

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

Converts to this type from the input type.

Auto Trait Implementations§

§

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

§

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

§

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.