Struct Prompter

Source
pub struct Prompter<'a, 'b: 'a, Term: 'b + Terminal> { /* private fields */ }
Expand description

Provides access to the current state of input while a read_line call is in progress.

Holds read and write locks on terminal operations. See Interface for more information about concurrent operations.

Instances of this type cannot be constructed by public methods. Instead, an instance is created internally during a call to read_line.

Implementations§

Source§

impl<'a, 'b: 'a, Term: 'b + Terminal> Prompter<'a, 'b, Term>

Source

pub fn writer_append<'c>(&'c mut self) -> Result<Writer<'c, 'b, Term>>

Returns a Writer instance using the currently held write lock.

This method will move the cursor to a new line after the prompt, allowing output to be written without corrupting the prompt text. The prompt will be redrawn when the Writer instance is dropped.

To instead erase the prompt and write text, use writer_erase.

Source

pub fn writer_erase<'c>(&'c mut self) -> Result<Writer<'c, 'b, Term>>

Returns a Writer instance using the currently held write lock.

This method will erase the prompt, allowing output to be written without corrupting the prompt text. The prompt will be redrawn when the Writer instance is dropped.

To instead write text after the prompt, use writer_append.

Source

pub fn buffer(&self) -> &str

Returns the current buffer.

Source

pub fn backup_buffer(&self) -> &str

Returns the “backup” buffer.

When the user is currently editing a history entry, the backup buffer contains the original user input.

Source

pub fn last_command_category(&self) -> Category

Returns the command Category of the most recently executed command.

Some commands may use this to influence behavior of repeated commands.

Source

pub fn word_break_chars(&self) -> &str

Returns the set of characters that indicate a word break.

Source

pub fn set_buffer(&mut self, buf: &str) -> Result<()>

Sets the buffer to the given value.

The cursor is moved to the end of the buffer.

Source

pub fn cursor(&self) -> usize

Returns the current position of the cursor.

Source

pub fn set_cursor(&mut self, pos: usize) -> Result<()>

Sets the cursor to the given position within the buffer.

§Panics

If the given position is out of bounds or is not aligned to char boundaries.

Source

pub fn set_prompt(&mut self, prompt: &str) -> Result<()>

Sets the prompt that will be displayed when read_line is called.

§Notes

If prompt contains any terminal escape sequences (e.g. color codes), such escape sequences should be immediately preceded by the character '\x01' and immediately followed by the character '\x02'.

Source

pub fn screen_size(&self) -> Size

Returns the size of the terminal at the last draw operation.

Source

pub fn explicit_arg(&self) -> bool

Returns whether a numerical argument was explicitly supplied by the user.

Source

pub fn sequence(&self) -> &str

Returns the current input sequence.

Source

pub fn bindings(&self) -> BindingIter<'_>

Returns an iterator over bound sequences

Source

pub fn variables(&self) -> VariableIter<'_>

Returns an iterator over variable values.

Source

pub fn history(&self) -> HistoryIter<'_>

Returns an iterator over history entries

Source

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

Returns the index into history currently being edited.

If the user is not editing a line of history, None is returned.

Source

pub fn history_len(&self) -> usize

Returns the current number of history entries.

Source

pub fn select_history_entry(&mut self, new: Option<usize>) -> Result<()>

Selects the history entry currently being edited by the user.

Setting the entry to None will result in editing the input buffer.

§Panics

If the index is out of bounds.

Source

pub fn completions(&self) -> Option<&[Completion]>

Returns the current set of completions.

Unless the most recent command executed was one operating on completion sets, the result is None.

Source

pub fn set_completions(&mut self, completions: Option<Vec<Completion>>)

Sets the current set of completions.

This completion set is accessed by commands such as complete and possible-completions.

This set will only remain active until the end of the next non-completion command’s execution. Therefore, any Function that uses this method must be of the Complete category.

Source

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

Accepts the current input buffer as user input.

This method may be called by a Function implementation, immediately before ending execution, in order to simulate the accept-line command; e.g. to implement a command that extends the default behavior of the accept-line action.

Behavior of this method is undefined if called outside of a Function implementation.

Moves the cursor to the given position, waits for 500 milliseconds (or until next user input), then restores the original cursor position.

§Panics

If the given position is out of bounds or is not aligned to char boundaries.

Source

pub fn delete_range<R: RangeArgument<usize>>(&mut self, range: R) -> Result<()>

Deletes a range of text from the input buffer.

§Panics

If the given range is out of bounds or is not aligned to char boundaries.

Source

pub fn kill_range<R: RangeArgument<usize>>(&mut self, range: R) -> Result<()>

Deletes a range from the buffer and adds the removed text to the kill ring.

§Panics

If the given range is out of bounds or is not aligned to char boundaries.

Source

pub fn transpose_range( &mut self, src: Range<usize>, dest: Range<usize>, ) -> Result<()>

Transposes two regions of the buffer, src and dest. The cursor is placed at the end of the new location of src.

§Panics

If src and dest overlap, are out of bounds, or are not aligned to char boundaries.

Source

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

Insert text from the front of the kill ring at the current cursor position. The cursor is placed at the end of the new text.

Source

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

Rotates the kill ring and replaces yanked text with the new front.

If the previous operation was not yank, this has no effect.

Source

pub fn insert(&mut self, n: usize, ch: char) -> Result<()>

Insert a given character at the current cursor position n times.

The cursor position remains the same.

Source

pub fn insert_str(&mut self, s: &str) -> Result<()>

Insert a string at the current cursor position.

The cursor is placed at the end of the new string.

Source

pub fn replace_str_backward<R: RangeArgument<usize>>( &mut self, range: R, s: &str, ) -> Result<()>

Replaces a range in the buffer and redraws.

The cursor is placed at the start of the range.

Source

pub fn replace_str_forward<R: RangeArgument<usize>>( &mut self, range: R, s: &str, ) -> Result<()>

Replaces a range in the buffer and redraws.

The cursor is placed at the end of the new string.

Auto Trait Implementations§

§

impl<'a, 'b, Term> Freeze for Prompter<'a, 'b, Term>

§

impl<'a, 'b, Term> !RefUnwindSafe for Prompter<'a, 'b, Term>

§

impl<'a, 'b, Term> !Send for Prompter<'a, 'b, Term>

§

impl<'a, 'b, Term> !Sync for Prompter<'a, 'b, Term>

§

impl<'a, 'b, Term> Unpin for Prompter<'a, 'b, Term>

§

impl<'a, 'b, Term> !UnwindSafe for Prompter<'a, 'b, Term>

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.