Struct reedline::LineBuffer

source ·
pub struct LineBuffer { /* private fields */ }
Expand description

In memory representation of the entered line(s) including a cursor position to facilitate cursor based editing.

Implementations§

source§

impl LineBuffer

source

pub fn new() -> LineBuffer

Create a line buffer instance

source

pub fn is_empty(&self) -> bool

Check to see if the line buffer is empty

source

pub fn is_valid(&self) -> bool

Check if the line buffer is valid utf-8 and the cursor sits on a valid grapheme boundary

source

pub fn insertion_point(&self) -> usize

Gets the current edit position

source

pub fn set_insertion_point(&mut self, offset: usize)

Sets the current edit position

§Unicode safety:

Not checked, improper use may cause panics in following operations

source

pub fn get_buffer(&self) -> &str

Output the current line in the multiline buffer

source

pub fn set_buffer(&mut self, buffer: String)

Set to a single line of buffer and reset the InsertionPoint cursor to the end

source

pub fn line(&self) -> usize

Calculates the current the user is on

Zero-based index

source

pub fn num_lines(&self) -> usize

Counts the number of lines in the buffer

source

pub fn ends_with(&self, c: char) -> bool

Checks to see if the buffer ends with a given character

source

pub fn move_to_start(&mut self)

Reset the insertion point to the start of the buffer

source

pub fn move_to_line_start(&mut self)

Move the cursor before the first character of the line

source

pub fn move_to_line_end(&mut self)

Move cursor position to the end of the line

Insertion will append to the line. Cursor on top of the potential \n or \r of \r\n

source

pub fn move_to_end(&mut self)

Set the insertion point behind the last character.

source

pub fn len(&self) -> usize

Get the length of the buffer

source

pub fn find_current_line_end(&self) -> usize

Returns where the current line terminates

Either:

  • end of buffer (len())
  • \n or \r\n (on the first byte)
source

pub fn grapheme_right_index(&self) -> usize

Cursor position behind the next unicode grapheme to the right

source

pub fn grapheme_left_index(&self) -> usize

Cursor position in front of the next unicode grapheme to the left

source

pub fn word_right_index(&self) -> usize

Cursor position behind the next word to the right

source

pub fn big_word_right_index(&self) -> usize

Cursor position behind the next WORD to the right

source

pub fn word_right_end_index(&self) -> usize

Cursor position at end of the next word to the right

source

pub fn big_word_right_end_index(&self) -> usize

Cursor position at end of the next WORD to the right

source

pub fn word_right_start_index(&self) -> usize

Cursor position in front of the next word to the right

source

pub fn big_word_right_start_index(&self) -> usize

Cursor position in front of the next WORD to the right

source

pub fn word_left_index(&self) -> usize

Cursor position in front of the next word to the left

source

pub fn big_word_left_index(&self) -> usize

Cursor position in front of the next WORD to the left

source

pub fn next_whitespace(&self) -> usize

Cursor position on the next whitespace

source

pub fn move_right(&mut self)

Move cursor position behind the next unicode grapheme to the right

source

pub fn move_left(&mut self)

Move cursor position in front of the next unicode grapheme to the left

source

pub fn move_word_left(&mut self)

Move cursor position in front of the next word to the left

source

pub fn move_big_word_left(&mut self)

Move cursor position in front of the next WORD to the left

source

pub fn move_word_right(&mut self)

Move cursor position behind the next word to the right

source

pub fn move_word_right_start(&mut self)

Move cursor position to the start of the next word

source

pub fn move_big_word_right_start(&mut self)

Move cursor position to the start of the next WORD

source

pub fn move_word_right_end(&mut self)

Move cursor position to the end of the next word

source

pub fn move_big_word_right_end(&mut self)

Move cursor position to the end of the next WORD

source

pub fn insert_char(&mut self, c: char)

Insert a single character at the insertion point and move right

source

pub fn insert_str(&mut self, string: &str)

Insert &str at the cursor position in the current line.

Sets cursor to end of inserted string

§Unicode safety:

Does not validate the incoming string or the current cursor position

source

pub fn insert_newline(&mut self)

Inserts the system specific new line character

  • On Unix systems LF ("\n")
  • On Windows CRLF ("\r\n")
source

pub fn clear(&mut self)

Empty buffer and reset cursor

source

pub fn clear_to_end(&mut self)

Clear everything beginning at the cursor to the right/end. Keeps the cursor at the end.

source

pub fn clear_to_line_end(&mut self)

Clear beginning at the cursor up to the end of the line. Newline character at the end remains.

source

pub fn clear_to_insertion_point(&mut self)

Clear from the start of the buffer to the cursor. Keeps the cursor at the beginning of the line/buffer.

source

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

Clear all contents between start and end and change insertion point if necessary.

If the cursor is located between start and end it is adjusted to start. If the cursor is located after end it is adjusted to stay at its current char boundary.

source

pub fn replace_range<R>(&mut self, range: R, replace_with: &str)
where R: RangeBounds<usize>,

Substitute text covered by range in the current line

Safety: Does not change the insertion point/offset and is thus not unicode safe!

source

pub fn on_whitespace(&self) -> bool

Checks to see if the current edit position is pointing to whitespace

source

pub fn grapheme_right(&self) -> &str

Get the grapheme immediately to the right of the cursor, if any

source

pub fn grapheme_left(&self) -> &str

Get the grapheme immediately to the left of the cursor, if any

source

pub fn current_word_range(&self) -> Range<usize>

Gets the range of the word the current edit position is pointing to

source

pub fn current_line_range(&self) -> Range<usize>

Range over the current line

Starts on the first non-newline character and is an exclusive range extending beyond the potential carriage return and line feed characters terminating the line

source

pub fn uppercase_word(&mut self)

Uppercases the current word

source

pub fn lowercase_word(&mut self)

Lowercases the current word

source

pub fn switchcase_char(&mut self)

Switches the ASCII case of the current char

source

pub fn capitalize_char(&mut self)

Capitalize the character at insertion point (or the first character following the whitespace at the insertion point) and move the insertion point right one grapheme.

source

pub fn delete_left_grapheme(&mut self)

Deletes on grapheme to the left

source

pub fn delete_right_grapheme(&mut self)

Deletes one grapheme to the right

source

pub fn delete_word_left(&mut self)

Deletes one word to the left

source

pub fn delete_word_right(&mut self)

Deletes one word to the right

source

pub fn swap_words(&mut self)

Swaps current word with word on right

source

pub fn swap_graphemes(&mut self)

Swaps current grapheme with grapheme on right

source

pub fn move_line_up(&mut self)

Moves one line up

source

pub fn move_line_down(&mut self)

Moves one line down

source

pub fn is_cursor_at_first_line(&self) -> bool

Checks to see if the cursor is on the first line of the buffer

source

pub fn is_cursor_at_last_line(&self) -> bool

Checks to see if the cursor is on the last line of the buffer

source

pub fn find_char_right(&self, c: char, current_line: bool) -> Option<usize>

Finds index for the first occurrence of a char to the right of offset

source

pub fn find_char_left(&self, c: char, current_line: bool) -> Option<usize>

Finds index for the first occurrence of a char to the left of offset

source

pub fn move_right_until(&mut self, c: char, current_line: bool) -> usize

Moves the insertion point until the next char to the right

source

pub fn move_right_before(&mut self, c: char, current_line: bool) -> usize

Moves the insertion point before the next char to the right

source

pub fn move_left_until(&mut self, c: char, current_line: bool) -> usize

Moves the insertion point until the next char to the left of offset

source

pub fn move_left_before(&mut self, c: char, current_line: bool) -> usize

Moves the insertion point before the next char to the left of offset

source

pub fn delete_right_until_char(&mut self, c: char, current_line: bool)

Deletes until first character to the right of offset

source

pub fn delete_right_before_char(&mut self, c: char, current_line: bool)

Deletes before first character to the right of offset

source

pub fn delete_left_until_char(&mut self, c: char, current_line: bool)

Deletes until first character to the left of offset

source

pub fn delete_left_before_char(&mut self, c: char, current_line: bool)

Deletes before first character to the left of offset

Trait Implementations§

source§

impl Clone for LineBuffer

source§

fn clone(&self) -> LineBuffer

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 LineBuffer

source§

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

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

impl Default for LineBuffer

source§

fn default() -> LineBuffer

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

impl From<&str> for LineBuffer

source§

fn from(input: &str) -> Self

Converts to this type from the input type.
source§

impl PartialEq for LineBuffer

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Eq for LineBuffer

source§

impl StructuralPartialEq for LineBuffer

Auto Trait Implementations§

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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. 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> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> ToOwned for T
where T: Clone,

§

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, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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.