Skip to main content

PromptBuffer

Struct PromptBuffer 

Source
pub struct PromptBuffer { /* private fields */ }

Implementations§

Source§

impl PromptBuffer

Source

pub fn new() -> Self

Source

pub fn is_empty(&self) -> bool

Source

pub fn as_string(&self) -> String

Joined string with embedded \n between rows. Allocates.

Source

pub fn height(&self) -> usize

Number of rows in the current buffer. Always ≥ 1.

Source

pub const fn cursor_row(&self) -> usize

Current cursor row (0-based).

Source

pub const fn cursor(&self) -> usize

Current cursor column on the active row.

Source

pub fn cursor_column(&self) -> u16

Same as [cursor] but as a u16 for ratatui’s column API.

Source

pub fn line(&self, row: usize) -> Option<&[char]>

Read a row’s contents — used by the widget for rendering.

Source

pub const fn history(&self) -> &PromptHistory

Borrowed access to the history ring (read-only).

Source

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

Insert a literal character at the cursor. Discards the history-recall flag — once you start typing on a recalled entry it’s part of your draft.

Source

pub fn insert_newline(&mut self)

Shift+Enter — break the current line at the cursor and move down. Capped at MAX_LINES; further newlines are silently dropped so a stuck Repeat key cannot grow the prompt indefinitely.

Source

pub fn backspace(&mut self)

Backspace — delete the char to the left of the cursor; if at column 0 of a non-first row, merge with the previous row instead.

Source

pub fn delete(&mut self)

Delete — char at the cursor, or if at end of line, splice the next line up.

Source

pub fn move_left(&mut self)

Source

pub fn move_right(&mut self)

Source

pub fn move_home(&mut self)

Source

pub fn move_end(&mut self)

Source

pub fn move_up(&mut self)

Up arrow — intra-buffer movement. The caller (input.rs) is responsible for routing Up to history recall when the cursor is at the first row; this method only moves up inside a multi-line buffer.

Source

pub fn move_down(&mut self)

Source

pub const fn cursor_on_first_row(&self) -> bool

True when the cursor is on the visual top row of the buffer. Input router uses this to decide whether Up should recall history or move within the buffer.

Source

pub fn cursor_on_last_row(&self) -> bool

True when the cursor is on the visual last row.

Source

pub fn recall_prev(&mut self)

Recall the previous (older) history entry. Stashes the live draft on first use so a subsequent recall_next past the newest can restore it.

Source

pub fn recall_next(&mut self)

Recall the next (newer) history entry, or restore the saved draft when stepping past the newest entry.

Source

pub fn take(&mut self) -> Option<String>

Submit the buffer. Returns None for an all-whitespace buffer so the caller can short-circuit. Also pushes the joined text onto history and resets the recall cursor.

Source

pub fn clear(&mut self)

Discard the buffer and reset the cursor, but keep history intact. Used by Esc.

Source

pub fn replace_all(&mut self, s: &str)

Replace the whole buffer with a literal value (used by the slash-command picker on Tab-complete). Cursor lands at end-of-buffer.

Trait Implementations§

Source§

impl Debug for PromptBuffer

Source§

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

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

impl Default for PromptBuffer

Source§

fn default() -> Self

Returns the “default value” for a type. 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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more