Struct TextBuffer

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

A text buffer where characters are manipulated visually with consideration on the unicode width of characters. Characters can span more than 1 cell, therefore visually manipulating text in a 2-dimensional way should consider using the unicode width.

Implementations§

Source§

impl TextBuffer

Source

pub fn new_from_str(content: &str) -> Self

Source

pub fn from_ch(chars: &[&[Ch]]) -> Self

Source

pub fn is_empty(&self) -> bool

Source

pub fn chars(&self) -> &[Vec<Ch>]

Source

pub fn total_chars(&self) -> usize

return the total number of characters excluding new lines

Source

pub fn split_line_at_point(&self, loc: Point2<usize>) -> (String, String)

Source

pub fn split_line_at_2_points( &self, loc: Point2<usize>, loc2: Point2<usize>, ) -> (String, String, String)

Source

pub fn cut_text_in_linear_mode( &mut self, start: Point2<usize>, end: Point2<usize>, ) -> String

Remove the text within the start and end position then return the deleted text

Source

pub fn get_text_in_linear_mode( &self, start: Point2<usize>, end: Point2<usize>, ) -> String

get the text in between start and end if selected in linear mode

Source

pub fn get_text_in_block_mode( &self, start: Point2<usize>, end: Point2<usize>, ) -> String

get the text in between start and end if selected in block mode

Source

pub fn cut_text_in_block_mode( &mut self, start: Point2<usize>, end: Point2<usize>, ) -> String

Source

pub fn paste_text_in_block_mode(&mut self, text_block: String)

paste the text block in the cursor location

Source§

impl TextBuffer

text manipulation This are purely manipulating text into the text buffer. The cursor shouldn’t be move here, since it is done by the commands functions

Source

pub fn total_lines(&self) -> usize

the total number of lines of this text canvas

Source

pub fn numberline_wide(&self) -> usize

return the number of characters to represent the line number of the last line of this text buffer

Source

pub fn lines(&self) -> Vec<String>

Source

pub fn first_non_blank_line(&self) -> Option<usize>

return the first non blank line

Source

pub fn last_non_blank_line(&self) -> Option<usize>

return the last non blank line

Source

pub fn line_width(&self, n: usize) -> usize

the width of the line at line n

Source

pub fn max_column_width(&self) -> usize

get the length of the widest line

Source

pub fn max_position(&self) -> Point2<usize>

return rectangular position starting from 0,0 to contain all the text

Source

pub fn last_char_position(&self) -> Point2<usize>

Source

pub fn break_line(&mut self, loc: Point2<usize>)

break at line y and put the characters after x on the next line

Source

pub fn join_line(&mut self, loc: Point2<usize>)

Source

pub fn ensure_line_exist(&mut self, y: usize)

ensure line at index y exist

Source

pub fn ensure_before_line_exist(&mut self, y: usize)

Source

pub fn ensure_cell_exist(&mut self, loc: Point2<usize>)

ensure line in index y exist and the cell at index x

Source

pub fn ensure_before_cell_exist(&mut self, loc: Point2<usize>)

Source

pub fn insert_char(&mut self, loc: Point2<usize>, ch: char)

insert a character at this x and y and move cells after it to the right

Source

pub fn insert_text(&mut self, loc: Point2<usize>, text: &str)

Source

pub fn replace_char(&mut self, loc: Point2<usize>, ch: char) -> Option<char>

replace the character at this location

Source

pub fn get_char(&self, loc: Point2<usize>) -> Option<char>

get the character at this cursor position

Source

pub fn delete_char(&mut self, loc: Point2<usize>) -> Option<char>

delete character at this position

Source

pub fn get_position(&self) -> Point2<usize>

return the position of the cursor

Source§

impl TextBuffer

Command implementation here

functions that are preceeded with command also moves the cursor and highlight the texts

Note: methods that are preceeded with command such as command_insert_char are high level methods which has consequences in the text buffer such as moving the cursor. While there corresponding more primitive counter parts such as insert_char are low level commands, which doesn’t move the cursor location

Source

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

Source

pub fn command_replace_char(&mut self, ch: char) -> Option<char>

Source

pub fn command_insert_text(&mut self, text: &str)

Source

pub fn move_left(&mut self)

Source

pub fn move_left_start(&mut self)

Source

pub fn move_right(&mut self)

Source

pub fn move_right_clamped(&mut self)

Source

pub fn move_right_end(&mut self)

Source

pub fn move_x(&mut self, x: usize)

Source

pub fn move_y(&mut self, y: usize)

Source

pub fn move_up(&mut self)

Source

pub fn move_down(&mut self)

Source

pub fn move_up_clamped(&mut self)

Source

pub fn clamp_position(&self, loc: Point2<usize>) -> Point2<usize>

Source

pub fn move_down_clamped(&mut self)

Source

pub fn set_position(&mut self, pos: Point2<usize>)

Source

pub fn set_position_clamped(&mut self, pos: Point2<usize>)

set the position to the max_column of the line if it is out of bounds

Source

pub fn command_break_line(&mut self, loc: Point2<usize>)

Source

pub fn command_join_line(&mut self, loc: Point2<usize>)

Source

pub fn command_delete_back(&mut self) -> Option<char>

Source

pub fn command_delete_forward(&mut self) -> Option<char>

Source

pub fn move_to(&mut self, pos: Point2<usize>)

move the cursor to position

Source

pub fn clear(&mut self)

clear the contents of this text buffer

Trait Implementations§

Source§

impl Clone for TextBuffer

Source§

fn clone(&self) -> TextBuffer

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 Default for TextBuffer

Source§

fn default() -> Self

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

impl ToString for TextBuffer

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more

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<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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
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, 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.