LineBuffer

Struct LineBuffer 

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

Text buffer with cursor tracking for line editing operations.

Manages the actual text being edited and the cursor position within it. Supports UTF-8 text and provides methods for character/word manipulation.

This struct is typically not used directly - instead use LineEditor which provides the high-level editing interface.

Implementations§

Source§

impl LineBuffer

Source

pub fn new(capacity: usize) -> Self

Creates a new line buffer with the specified capacity.

§Arguments
  • capacity - Initial capacity for the internal buffer in bytes
§Examples
use editline::LineBuffer;

let buffer = LineBuffer::new(1024);
assert!(buffer.is_empty());
Source

pub fn clear(&mut self)

Clears the buffer and resets the cursor to the start.

Source

pub fn len(&self) -> usize

Returns the length of the buffer in bytes.

Note: For UTF-8 text, this is the byte count, not the character count.

Source

pub fn is_empty(&self) -> bool

Returns true if the buffer is empty.

Source

pub fn cursor_pos(&self) -> usize

Returns the current cursor position in bytes from the start.

Source

pub fn as_str(&self) -> Result<&str>

Returns the buffer contents as a UTF-8 string slice.

§Errors

Returns Err if the buffer contains invalid UTF-8.

Source

pub fn as_bytes(&self) -> &[u8]

Returns the buffer contents as a byte slice.

Source

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

Inserts a character at the cursor position, moving the cursor forward.

Supports UTF-8 characters. The cursor advances by the byte length of the character.

Source

pub fn delete_before_cursor(&mut self) -> bool

Deletes the character before the cursor (backspace operation).

Returns true if a character was deleted, false if the cursor is at the start.

Source

pub fn delete_at_cursor(&mut self) -> bool

Deletes the character at the cursor (delete key operation).

Returns true if a character was deleted, false if the cursor is at the end.

Source

pub fn move_cursor_left(&mut self) -> bool

Moves the cursor one position to the left.

Returns true if the cursor moved, false if already at the start.

Source

pub fn move_cursor_right(&mut self) -> bool

Moves the cursor one position to the right.

Returns true if the cursor moved, false if already at the end.

Source

pub fn move_cursor_to_start(&mut self) -> usize

Moves the cursor to the start of the line.

Returns the number of positions the cursor moved.

Source

pub fn move_cursor_to_end(&mut self) -> usize

Moves the cursor to the end of the line.

Returns the number of positions the cursor moved.

Source

pub fn move_cursor_word_left(&mut self) -> usize

Moves the cursor to the start of the previous word.

Words are defined as sequences of alphanumeric characters and underscores. Returns the number of positions the cursor moved.

Source

pub fn move_cursor_word_right(&mut self) -> usize

Moves the cursor to the start of the next word.

Words are defined as sequences of alphanumeric characters and underscores. Returns the number of positions the cursor moved.

Source

pub fn delete_word_left(&mut self) -> usize

Deletes the word to the left of the cursor (Alt+Backspace operation).

Returns the number of bytes deleted.

Source

pub fn delete_word_right(&mut self) -> usize

Deletes the word to the right of the cursor (Ctrl+Delete operation).

Returns the number of bytes deleted.

Source

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

Loads text into the buffer, replacing existing content.

The cursor is positioned at the end of the loaded text. Used internally for history navigation.

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