pub trait Buffer {
Show 19 methods
fn len(&self) -> usize;
fn get_tag(&self, tag: char) -> Result<usize, &'static str>;
fn get_matching(
&self,
pattern: &str,
curr_line: usize,
backwards: bool
) -> Result<usize, &'static str>;
fn mark_matching(
&mut self,
pattern: &str,
selection: (usize, usize),
inverse: bool
) -> Result<(), &'static str>;
fn get_marked(&mut self) -> Result<Option<usize>, &'static str>;
fn tag_line(&mut self, index: usize, tag: char) -> Result<(), &'static str>;
fn insert<'a>(
&mut self,
data: &mut dyn Iterator<Item = &'a str>,
index: usize
) -> Result<(), &'static str>;
fn cut(&mut self, selection: (usize, usize)) -> Result<(), &'static str>;
fn change<'a>(
&mut self,
data: &mut dyn Iterator<Item = &'a str>,
selection: (usize, usize)
) -> Result<(), &'static str>;
fn mov(
&mut self,
selection: (usize, usize),
index: usize
) -> Result<(), &'static str>;
fn mov_copy(
&mut self,
selection: (usize, usize),
index: usize
) -> Result<(), &'static str>;
fn join(&mut self, selection: (usize, usize)) -> Result<(), &'static str>;
fn copy(&mut self, selection: (usize, usize)) -> Result<(), &'static str>;
fn paste(&mut self, index: usize) -> Result<usize, &'static str>;
fn search_replace(
&mut self,
pattern: (&str, &str),
selection: (usize, usize),
global: bool
) -> Result<usize, &'static str>;
fn read_from(
&mut self,
path: &str,
index: Option<usize>,
must_exist: bool
) -> Result<usize, &'static str>;
fn write_to(
&mut self,
selection: Option<(usize, usize)>,
path: &str,
append: bool
) -> Result<(), &'static str>;
fn saved(&self) -> bool;
fn get_selection<'a>(
&'a self,
selection: (usize, usize)
) -> Result<Box<dyn Iterator<Item = &'a str> + 'a>, &'static str>;
}Expand description
Trait that defines a buffer supporting ’ed’s base commands
BEWARE!!! 1-indexed! This means line 0 doesn’t exist, error if given (use verify_selection/verify_line below) BUT, index 0 is valid (therefore use verify_index instead) Subtract 1 to get 0 indexed. It is recommended to use .saturating_sub(1)
Required Methods
Get line tagged with given letter. Not found is error
Return the nearest previous/following index in the selection that contains the regex pattern
Set the matched flag on all lines matching given pattern
Get a line with the matched flag set, clearing that line’s flag
Mark a line with a letter, mark with ‘\0’ to clear
Takes a iterator over lines in strings and inserts after given index
Cut the selection from the buffer, into the clipboard
Replace selection with input
Move selection to immediately after index
Insert a copy of the selection immediately after index
Join all lines in selection into one line
Copy selected lines into clipboard
Paste the clipboard contents after given index Leave clipboard unchanged
Perform regex search and replace on the selection changing pattern.0 to pattern.1 Should interpret escape sequences in both patterns. At minimum \n and \. If pattern is empty, should re-use stored pattern from previous s command Returns new end of selection, since it may delete or add lines Beware that it may delete the whole selection just as ‘c’
Read to the buffer from given path If index is None replaces current buffer with read lines Else inserts read lines after given index Return number of lines read
Write the buffer to given path