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 strImplementations§
Source§impl<'a> Editor<'a>
impl<'a> Editor<'a>
Sourcepub fn new(color: &'a str, begin: &'a str, again: &'a str) -> Self
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.
Sourcepub fn iter(&self) -> impl Iterator<Item = &char>
pub fn iter(&self) -> impl Iterator<Item = &char>
Returns an iterator over characters in the editor.
fn putchar<W: Write>(&self, c: char, w: &mut W) -> ReplResult<()>
pub fn redraw_head<W: Write>(&self, w: &mut W) -> ReplResult<()>
pub fn redraw_tail<W: Write>(&self, w: &mut W) -> ReplResult<()>
Sourcepub fn print_head<W: Write>(&self, w: &mut W) -> ReplResult<()>
pub fn print_head<W: Write>(&self, w: &mut W) -> ReplResult<()>
Prints the characters before the cursor on the current line.
Sourcepub fn print_tail<W: Write>(&self, w: &mut W) -> ReplResult<()>
pub fn print_tail<W: Write>(&self, w: &mut W) -> ReplResult<()>
Prints the characters after the cursor on the current line.
pub fn print_err<W: Write>( &self, err: impl Display, w: &mut W, ) -> ReplResult<()>
Sourcepub fn push<W: Write>(&mut self, c: char, w: &mut W) -> ReplResult<()>
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.
Sourcepub fn pop<W: Write>(&mut self, w: &mut W) -> ReplResult<Option<char>>
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.
Sourcepub fn delete<W: Write>(&mut self, w: &mut W) -> ReplResult<Option<char>>
pub fn delete<W: Write>(&mut self, w: &mut W) -> ReplResult<Option<char>>
Pops the character after the cursor, redrawing if necessary
Sourcepub fn extend<T: IntoIterator<Item = char>, W: Write>(
&mut self,
iter: T,
w: &mut W,
) -> ReplResult<()>
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.
Sourcepub fn restore<W: Write>(&mut self, s: &str, w: &mut W) -> ReplResult<()>
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.
Sourcepub fn erase_word<W: Write>(&mut self, w: &mut W) -> ReplResult<()>
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
Sourcepub fn at_line_start(&self) -> bool
pub fn at_line_start(&self) -> bool
Returns true if the cursor is at the start of a line
Sourcepub fn at_line_end(&self) -> bool
pub fn at_line_end(&self) -> bool
Returns true if the cursor is at the end of a line
Sourcepub fn at_word_start(&self) -> bool
pub fn at_word_start(&self) -> bool
Returns true if the character before the cursor is whitespace
Sourcepub fn at_word_end(&self) -> bool
pub fn at_word_end(&self) -> bool
Returns true if the character after the cursor is whitespace
Sourcepub fn ends_with(&self, iter: impl DoubleEndedIterator<Item = char>) -> bool
pub fn ends_with(&self, iter: impl DoubleEndedIterator<Item = char>) -> bool
Returns true if the buffer ends with a given pattern
Sourcepub fn cursor_back<W: Write>(&mut self, w: &mut W) -> ReplResult<()>
pub fn cursor_back<W: Write>(&mut self, w: &mut W) -> ReplResult<()>
Moves the cursor back steps steps
Sourcepub fn cursor_forward<W: Write>(&mut self, w: &mut W) -> ReplResult<()>
pub fn cursor_forward<W: Write>(&mut self, w: &mut W) -> ReplResult<()>
Moves the cursor forward steps steps
Sourcepub fn cursor_up<W: Write>(&mut self, w: &mut W) -> ReplResult<()>
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
Sourcepub fn cursor_down<W: Write>(&mut self, w: &mut W) -> ReplResult<()>
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
Sourcepub fn cursor_line_start<W: Write>(&mut self, w: &mut W) -> ReplResult<()>
pub fn cursor_line_start<W: Write>(&mut self, w: &mut W) -> ReplResult<()>
Moves the cursor to the beginning of the current line
Sourcepub fn cursor_line_end<W: Write>(&mut self, w: &mut W) -> ReplResult<()>
pub fn cursor_line_end<W: Write>(&mut self, w: &mut W) -> ReplResult<()>
Moves the cursor to the end of the current line
Sourcepub fn cursor_word_back<W: Write>(&mut self, w: &mut W) -> ReplResult<()>
pub fn cursor_word_back<W: Write>(&mut self, w: &mut W) -> ReplResult<()>
Moves the cursor to the previous whitespace boundary
Sourcepub fn cursor_word_forward<W: Write>(&mut self, w: &mut W) -> ReplResult<()>
pub fn cursor_word_forward<W: Write>(&mut self, w: &mut W) -> ReplResult<()>
Moves the cursor to the next whitespace boundary
Sourcepub fn cursor_start<W: Write>(&mut self, w: &mut W) -> ReplResult<()>
pub fn cursor_start<W: Write>(&mut self, w: &mut W) -> ReplResult<()>
Moves the cursor to the start of the buffer
Sourcepub fn cursor_end<W: Write>(&mut self, w: &mut W) -> ReplResult<()>
pub fn cursor_end<W: Write>(&mut self, w: &mut W) -> ReplResult<()>
Moves the cursor to the end of the buffer