sl_liner

Struct Buffer

Source
pub struct Buffer { /* private fields */ }
Expand description

A buffer for text in the line editor.

It keeps track of each action performed on it for use with undo/redo.

Implementations§

Source§

impl Buffer

Source

pub fn new() -> Self

Source

pub fn clear_actions(&mut self)

Source

pub fn start_undo_group(&mut self)

Source

pub fn end_undo_group(&mut self)

Source

pub fn undo(&mut self) -> Option<usize>

Source

pub fn redo(&mut self) -> Option<usize>

Source

pub fn revert(&mut self) -> bool

Source

pub fn is_last_arg_newline(&self) -> bool

Source

pub fn last_arg(&self) -> Option<&str>

Source

pub fn num_lines(&self) -> usize

Source

pub fn num_graphemes(&self) -> usize

Source

pub fn lines(&self) -> impl Iterator<Item = &str> + '_

Source

pub fn num_bytes(&self) -> usize

Source

pub fn grapheme_before(&self, cursor: usize) -> Option<&str>

Source

pub fn grapheme_after(&self, cursor: usize) -> Option<&str>

Source

pub fn remove_unrecorded(&mut self, start: usize, end: usize)

Returns the graphemes removed. Does not register as an action in the undo/redo buffer or in the buffer’s register.

Source

pub fn remove(&mut self, start: usize, end: usize) -> usize

Returns the number of graphemes removed.

Source

pub fn insert_register_around_idx( &mut self, idx: usize, count: usize, right: bool, ) -> usize

Insert contents of register to the right or to the left of the provided start index in the current buffer and return length of text inserted.

Source

pub fn insert_str(&mut self, start: usize, text: &str) -> usize

Source

pub fn insert<'a, I>(&mut self, start: usize, text: I) -> usize
where I: Iterator<Item = &'a char>,

Source

pub fn insert_action(&mut self, act: Action)

Source

pub fn append_buffer(&mut self, other: &Buffer) -> usize

Source

pub fn copy_buffer(&mut self, other: &Buffer) -> usize

Source

pub fn range_graphemes_all(&self) -> GraphemeIter<'_>

Source

pub fn range_graphemes_until(&self, until: usize) -> GraphemeIter<'_>

Source

pub fn range_graphemes_from(&self, start: usize) -> GraphemeIter<'_>

Source

pub fn range(&self, start: usize, end: usize) -> &str

Source

pub fn range_graphemes(&self, start: usize, end: usize) -> GraphemeIter<'_>

Source

pub fn line_width_until(&self, until: usize) -> impl Iterator<Item = usize> + '_

Source

pub fn line_widths(&self) -> impl Iterator<Item = usize> + '_

Source

pub fn truncate(&mut self, num: usize)

Source

pub fn print<W>(&self, out: &mut W) -> Result<()>
where W: Write,

Source

pub fn print_rest<W>(&self, out: &mut W, after: usize) -> Result<usize>
where W: Write,

Takes other buffer, measures its length and prints this buffer from the point where the other stopped. Used to implement autosuggestions.

Source

pub fn yank(&mut self, start: usize, end: usize)

Source

pub fn push(&mut self, ch: char)

Push ch onto the end of the buffer.

Source

pub fn starts_with(&self, other: &Buffer) -> bool

Check if the other buffer starts with the same content as this one. Used to implement autosuggestions.

Source

pub fn contains(&self, other: &Buffer) -> bool

Check if the buffer contains pattern. Used to implement history search.

Source

pub fn is_empty(&self) -> bool

Return true if the buffer is empty.

Source

pub fn first(&self) -> Option<&str>

Returns the first grapheme of the buffer or None if empty.

Source

pub fn last(&self) -> Option<&str>

Returns the last grapheme of the buffer or None if empty.

Trait Implementations§

Source§

impl Clone for Buffer

Source§

fn clone(&self) -> Buffer

Returns a copy 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 Debug for Buffer

Source§

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

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

impl Default for Buffer

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Display for Buffer

Source§

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

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

impl<'a> From<&'a str> for Buffer

Source§

fn from(s: &'a str) -> Self

Converts to this type from the input type.
Source§

impl From<Buffer> for String

Source§

fn from(buf: Buffer) -> Self

Converts to this type from the input type.
Source§

impl From<String> for Buffer

Source§

fn from(s: String) -> Self

Converts to this type from the input type.
Source§

impl FromIterator<char> for Buffer

Source§

fn from_iter<T: IntoIterator<Item = char>>(t: T) -> Self

Creates a value from an iterator. Read more
Source§

impl PartialEq for Buffer

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for Buffer

Auto Trait Implementations§

§

impl Freeze for Buffer

§

impl RefUnwindSafe for Buffer

§

impl Send for Buffer

§

impl Sync for Buffer

§

impl Unpin for Buffer

§

impl UnwindSafe for Buffer

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, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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§

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