pub struct PromptInput { /* private fields */ }Expand description
A cursor-aware text buffer used for the prompt input line.
The cursor is stored as a grapheme cluster index so that combining marks,
emoji sequences, and other multi-codepoint clusters are treated as a single
unit. It is always in the range 0..=grapheme_count.
Implementations§
Source§impl PromptInput
impl PromptInput
Sourcepub fn len_graphemes(&self) -> usize
pub fn len_graphemes(&self) -> usize
Number of grapheme clusters in the buffer.
Sourcepub fn cursor_left(&mut self)
pub fn cursor_left(&mut self)
Move the cursor left by one grapheme cluster (clamped at 0).
Sourcepub fn cursor_right(&mut self)
pub fn cursor_right(&mut self)
Move the cursor right by one grapheme cluster (clamped at end).
Sourcepub fn cursor_to_start(&mut self)
pub fn cursor_to_start(&mut self)
Move the cursor to the start of the line (grapheme index 0).
Sourcepub fn cursor_to_end(&mut self)
pub fn cursor_to_end(&mut self)
Move the cursor to the end of the text.
Sourcepub fn cursor_up(&mut self) -> bool
pub fn cursor_up(&mut self) -> bool
Move the cursor to the previous logical line, preserving the column as
closely as possible. Returns true when the cursor moved.
Sourcepub fn cursor_down(&mut self) -> bool
pub fn cursor_down(&mut self) -> bool
Move the cursor to the next logical line, preserving the column as
closely as possible. Returns true when the cursor moved.
Sourcepub fn cursor_word_left(&mut self)
pub fn cursor_word_left(&mut self)
Move the cursor left to the start of the previous Unicode word.
Uses unicode-segmentation word boundaries so that punctuation,
numbers, and other non-whitespace runs are treated as word units.
Sourcepub fn cursor_word_right(&mut self)
pub fn cursor_word_right(&mut self)
Move the cursor right to the start of the next Unicode word.
Uses unicode-segmentation word boundaries so that punctuation,
numbers, and other non-whitespace runs are treated as word units.
Sourcepub fn insert_char(&mut self, ch: char)
pub fn insert_char(&mut self, ch: char)
Insert a character at the cursor, then advance the cursor past it.
Sourcepub fn insert_str(&mut self, s: &str)
pub fn insert_str(&mut self, s: &str)
Insert a string at the cursor, advancing the cursor to the end of the inserted text.
Sourcepub fn replace_range(&mut self, start: usize, end: usize, replacement: &str)
pub fn replace_range(&mut self, start: usize, end: usize, replacement: &str)
Replace a grapheme-cluster range and place the cursor after the inserted text.
Sourcepub fn backspace(&mut self) -> bool
pub fn backspace(&mut self) -> bool
Delete the grapheme cluster to the left of the cursor (backspace).
Returns true if a grapheme was deleted.
Sourcepub fn delete_forward(&mut self) -> bool
pub fn delete_forward(&mut self) -> bool
Delete the grapheme cluster to the right of the cursor (forward delete).
Returns true if a grapheme was deleted.
Sourcepub fn kill_to_end_of_line(&mut self) -> String
pub fn kill_to_end_of_line(&mut self) -> String
Kill from the cursor to the end of the line. Returns the killed text.
Sourcepub fn kill_to_start_of_line(&mut self) -> String
pub fn kill_to_start_of_line(&mut self) -> String
Kill from the start of the line to the cursor. Returns the killed text.
Sourcepub fn kill_word_left(&mut self) -> String
pub fn kill_word_left(&mut self) -> String
Kill the word before the cursor (unix-word-rubout style). Uses Unicode word boundaries. Returns the killed text.
Sourcepub fn kill_word_right(&mut self) -> String
pub fn kill_word_right(&mut self) -> String
Kill the word after the cursor. Uses Unicode word boundaries. Returns the killed text.
Sourcepub fn transpose_chars(&mut self) -> bool
pub fn transpose_chars(&mut self) -> bool
Transpose the grapheme clusters at the cursor and just before it.
Returns true if a transposition happened.
At the start of the line, swaps the first two graphemes and moves the cursor past both. In the middle, swaps the grapheme before and at the cursor, then advances. At the end, swaps the last two graphemes.
Sourcepub fn yank(&mut self, text: &str)
pub fn yank(&mut self, text: &str)
Yank (paste) text at the cursor, advancing the cursor past it.
Sourcepub fn text_before_cursor(&self) -> &str
pub fn text_before_cursor(&self) -> &str
The text before the cursor.
Trait Implementations§
Source§impl Clone for PromptInput
impl Clone for PromptInput
Source§fn clone(&self) -> PromptInput
fn clone(&self) -> PromptInput
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for PromptInput
impl Debug for PromptInput
Source§impl Default for PromptInput
impl Default for PromptInput
Source§fn default() -> PromptInput
fn default() -> PromptInput
impl Eq for PromptInput
Source§impl From<&str> for PromptInput
impl From<&str> for PromptInput
Source§impl From<String> for PromptInput
impl From<String> for PromptInput
Source§impl FromStr for PromptInput
impl FromStr for PromptInput
Source§impl PartialEq for PromptInput
impl PartialEq for PromptInput
impl StructuralPartialEq for PromptInput
Auto Trait Implementations§
impl Freeze for PromptInput
impl RefUnwindSafe for PromptInput
impl Send for PromptInput
impl Sync for PromptInput
impl Unpin for PromptInput
impl UnsafeUnpin for PromptInput
impl UnwindSafe for PromptInput
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more