[−][src]Struct rucline::Buffer
A String
that also keeps track of its cursor position.
When presenting the context of the line reader to an action
or a completion
, the Buffer
is used as a read-only view into the line reader's buffer state.
Basic example:
use rucline::actions::Direction::Backward; use rucline::actions::Range::Word; use rucline::actions::Scope::WholeWord; use rucline::Buffer; let mut buffer: Buffer = "my new buffer".into(); assert_eq!(buffer.as_str(), "my new buffer"); assert_eq!(buffer.cursor(), "my new buffer".len()); buffer.move_cursor(Word, Backward); assert_eq!(buffer.as_str(), "my new buffer"); assert_eq!(buffer.cursor(), "my new ".len()); buffer.delete(WholeWord); assert_eq!(buffer.as_str(), "my new "); assert_eq!(buffer.cursor(), "my new ".len());
Implementations
impl Buffer
[src]
#[must_use]pub fn new() -> Self
[src]
Creates an empty buffer.
pub fn new_with_cursor<S: AsRef<str>>(
string: S,
cursor: usize
) -> Result<Self, InvalidIndex>
[src]
string: S,
cursor: usize
) -> Result<Self, InvalidIndex>
Creates a new Buffer
from string
with a given cursor position.
This is a short-hand for:
let mut buffer = Buffer::from(string); buffer.set_cursor(cursor);
Errors
- If the curosr position does not fall into a character boundary.
#[must_use]pub fn as_str(&self) -> &str
[src]
Returns the current buffer string.
#[must_use]pub fn cursor(&self) -> usize
[src]
Returns the current position of the cursor.
pub fn set_cursor(&mut self, cursor: usize) -> Result<(), InvalidIndex>
[src]
Sets the cursor position in the buffer
.
Errors
- If the curosr position does not fall into a character boundary.
pub fn go_to_end(&mut self)
[src]
Puts the cursor at the end of the buffer.
This is short-hand for move_cursor(Range::Line, Direction::Forward)
pub fn clear(&mut self)
[src]
Clears the buffer and sets the cursor back to zero.
pub fn write(&mut self, c: char)
[src]
Inserts a single character to the buffer at the cursor position and increments the cursor by one.
Arguments
c
- The character to insert.
pub fn write_str(&mut self, string: &str)
[src]
Inserts a string to the buffer at the cursor position and increments
the cursor by the length of string
.
Arguments
string
- The string to insert.
pub fn write_range(&mut self, string: &str, range: Range)
[src]
Inserts a range
of a string to the buffer at the cursor position and increments
the cursor by the length of the range.
Arguments
string
- The string to insert.range
- The range fromstring
to insert.
pub fn delete(&mut self, scope: Scope)
[src]
Deletes the given scope
from this buffer and updates the cursor accordingly.
Arguments
scope
- The scope of the deletion.
pub fn move_cursor(&mut self, range: Range, direction: Direction)
[src]
Trait Implementations
impl Clone for Buffer
[src]
impl Debug for Buffer
[src]
impl Default for Buffer
[src]
impl Deref for Buffer
[src]
impl Display for Buffer
[src]
impl Eq for Buffer
[src]
impl<S> From<S> for Buffer where
S: AsRef<str>,
[src]
S: AsRef<str>,
impl PartialEq<Buffer> for Buffer
[src]
impl StructuralEq for Buffer
[src]
impl StructuralPartialEq for Buffer
[src]
Auto Trait Implementations
impl RefUnwindSafe for Buffer
impl Send for Buffer
impl Sync for Buffer
impl Unpin for Buffer
impl UnwindSafe for Buffer
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,