Skip to main content

Editor

Struct Editor 

Source
pub struct Editor<'a> {
    head: VecDeque<char>,
    tail: VecDeque<char>,
    pub color: &'a str,
    pub begin: &'a str,
    pub again: &'a str,
}
Expand description

A multi-line editor which operates on an un-cleared ANSI terminal.

Fields§

§head: VecDeque<char>§tail: VecDeque<char>§color: &'a str§begin: &'a str§again: &'a str

Implementations§

Source§

impl<'a> Editor<'a>

Source

pub fn new(color: &'a str, begin: &'a str, again: &'a str) -> Self

Constructs a new Editor with the provided prompt color, begin prompt, and again prompt.

Source

pub fn iter(&self) -> impl Iterator<Item = &char>

Returns an iterator over characters in the editor.

Source

fn putchar<W: Write>(&self, c: char, w: &mut W) -> ReplResult<()>

Source

pub fn redraw_head<W: Write>(&self, w: &mut W) -> ReplResult<()>

Source

pub fn redraw_tail<W: Write>(&self, w: &mut W) -> ReplResult<()>

Source

pub fn print_head<W: Write>(&self, w: &mut W) -> ReplResult<()>

Prints the characters before the cursor on the current line.

Source

pub fn print_tail<W: Write>(&self, w: &mut W) -> ReplResult<()>

Prints the characters after the cursor on the current line.

Source

pub fn print_err<W: Write>( &self, err: impl Display, w: &mut W, ) -> ReplResult<()>

Source

pub fn push<W: Write>(&mut self, c: char, w: &mut W) -> ReplResult<()>

Writes a character at the cursor, shifting the text around as necessary.

Source

pub fn pop<W: Write>(&mut self, w: &mut W) -> ReplResult<Option<char>>

Erases a character at the cursor, shifting the text around as necessary.

Source

pub fn delete<W: Write>(&mut self, w: &mut W) -> ReplResult<Option<char>>

Pops the character after the cursor, redrawing if necessary

Source

pub fn extend<T: IntoIterator<Item = char>, W: Write>( &mut self, iter: T, w: &mut W, ) -> ReplResult<()>

Writes characters into the editor at the location of the cursor.

Source

pub fn restore<W: Write>(&mut self, s: &str, w: &mut W) -> ReplResult<()>

Sets the editor to the contents of a string, placing the cursor at the end.

Source

pub fn clear(&mut self)

Clears the editor, removing all characters.

Source

pub fn erase_word<W: Write>(&mut self, w: &mut W) -> ReplResult<()>

Erases a word from the buffer, where a word is any non-whitespace characters preceded by a single whitespace character

Source

pub fn len(&self) -> usize

Returns the number of characters in the buffer

Source

pub fn at_start(&self) -> bool

Returns true if the cursor is at the start of the buffer

Source

pub fn at_end(&self) -> bool

Returns true if the cursor is at the end of the buffer

Source

pub fn at_line_start(&self) -> bool

Returns true if the cursor is at the start of a line

Source

pub fn at_line_end(&self) -> bool

Returns true if the cursor is at the end of a line

Source

pub fn at_word_start(&self) -> bool

Returns true if the character before the cursor is whitespace

Source

pub fn at_word_end(&self) -> bool

Returns true if the character after the cursor is whitespace

Source

pub fn is_empty(&self) -> bool

Returns true if the buffer is empty.

Source

pub fn ends_with(&self, iter: impl DoubleEndedIterator<Item = char>) -> bool

Returns true if the buffer ends with a given pattern

Source

pub fn cursor_back<W: Write>(&mut self, w: &mut W) -> ReplResult<()>

Moves the cursor back steps steps

Source

pub fn cursor_forward<W: Write>(&mut self, w: &mut W) -> ReplResult<()>

Moves the cursor forward steps steps

Source

pub fn cursor_up<W: Write>(&mut self, w: &mut W) -> ReplResult<()>

Moves the cursor up to the previous line, attempting to preserve relative offset

Source

pub fn cursor_down<W: Write>(&mut self, w: &mut W) -> ReplResult<()>

Moves the cursor down to the next line, attempting to preserve relative offset

Source

pub fn cursor_line_start<W: Write>(&mut self, w: &mut W) -> ReplResult<()>

Moves the cursor to the beginning of the current line

Source

pub fn cursor_line_end<W: Write>(&mut self, w: &mut W) -> ReplResult<()>

Moves the cursor to the end of the current line

Source

pub fn cursor_word_back<W: Write>(&mut self, w: &mut W) -> ReplResult<()>

Moves the cursor to the previous whitespace boundary

Source

pub fn cursor_word_forward<W: Write>(&mut self, w: &mut W) -> ReplResult<()>

Moves the cursor to the next whitespace boundary

Source

pub fn cursor_start<W: Write>(&mut self, w: &mut W) -> ReplResult<()>

Moves the cursor to the start of the buffer

Source

pub fn cursor_end<W: Write>(&mut self, w: &mut W) -> ReplResult<()>

Moves the cursor to the end of the buffer

Trait Implementations§

Source§

impl<'a> Clone for Editor<'a>

Source§

fn clone(&self) -> Editor<'a>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for Editor<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for Editor<'_>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'e> IntoIterator for &'e Editor<'_>

Source§

type Item = &'e char

The type of the elements being iterated over.
Source§

type IntoIter = Chain<Iter<'e, char>, Iter<'e, char>>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.