Skip to main content

PromptState

Struct PromptState 

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

Headless single-line input + item list + history.

Owned by the host (the GPUI Editor, or a test harness) and shared with hooks via HookContext::prompt, so any hook can open a bottom bar or command palette with zero frontend code: ctx.prompt.open(...), read ctx.prompt.input() on submit, push a crate::HookEffect for app-level work (save/quit). Frontends only render + forward keys.

Implementations§

Source§

impl PromptState

Source

pub fn new() -> Self

Creates a closed prompt.

Source

pub fn is_open(&self) -> bool

Whether a prompt is currently open.

Source

pub fn spec(&self) -> Option<&PromptSpec>

Returns the active spec, if open.

Source

pub fn input(&self) -> &str

Current input text.

Source

pub fn cursor(&self) -> usize

Byte index of the input cursor (always a char boundary).

Source

pub fn items(&self) -> &[PromptItem]

Current item rows.

Source

pub fn selected_index(&self) -> usize

Selected item index.

Source

pub fn selected_item(&self) -> Option<&PromptItem>

Selected item, if the list is non-empty.

Source

pub fn message(&self) -> Option<&str>

Validation / error message to show under the box.

Source

pub fn history(&self) -> &[String]

Submitted-input history, oldest first.

Source

pub fn open(&mut self, spec: PromptSpec, initial: &str)

Opens a prompt, replacing any active one.

Source

pub fn close(&mut self)

Closes the prompt, clearing input, items, and message (history kept).

Source

pub fn set_message(&mut self, message: &str)

Sets the validation / error message.

Source

pub fn clear_message(&mut self)

Clears the validation / error message.

Source

pub fn set_items(&mut self, items: Vec<PromptItem>)

Replaces the item list, clamping the selection into range.

Source

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

Inserts text at the input cursor.

Source

pub fn backspace(&mut self)

Deletes the char before the input cursor (UTF-8 safe).

Source

pub fn delete_after_cursor(&mut self)

Deletes the char after the input cursor (UTF-8 safe).

Source

pub fn delete_word_before(&mut self)

Deletes back to the previous blank-separated word start (Ctrl+W, Ctrl+Backspace).

Source

pub fn delete_word_after(&mut self)

Deletes from the cursor forward across the next word (Ctrl+Delete).

Source

pub fn clear_to_start(&mut self)

Clears everything before the cursor (Ctrl+U).

Source

pub fn clear_to_end(&mut self)

Clears everything after the cursor (Ctrl+K).

Source

pub fn move_word_left(&mut self)

Moves the input cursor to the start of the previous word (Ctrl+Left).

Source

pub fn move_word_right(&mut self)

Moves the input cursor to the end of the current or next word (Ctrl+Right).

Source

pub fn move_left(&mut self)

Moves the input cursor one char left.

Source

pub fn move_right(&mut self)

Moves the input cursor one char right.

Source

pub fn move_home(&mut self)

Moves the input cursor to the start.

Source

pub fn move_end(&mut self)

Moves the input cursor to the end.

Source

pub fn history_prev(&mut self)

Steps back through submitted-input history.

Source

pub fn history_next(&mut self)

Steps forward through history, restoring the draft at the end.

Source

pub fn select_next(&mut self)

Moves the item selection forward, wrapping.

Source

pub fn select_prev(&mut self)

Moves the item selection backward, wrapping.

Source

pub fn complete_selected(&mut self)

Copies the selected item’s label into the input (Tab).

Source

pub fn submit(&mut self) -> String

Records the input in history and returns it. Leaves the prompt open so the caller can inspect items/message before closing.

Source

pub fn handle_key(&mut self, event: &KeyEvent) -> PromptAction

Routes one keystroke when the prompt is open. Returns PromptAction::Ignored when closed (or for keys the prompt does not own, e.g. Tab with an empty item list) so callers can fall through to buffer handling.

Trait Implementations§

Source§

impl Clone for PromptState

Source§

fn clone(&self) -> PromptState

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PromptState

Source§

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

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

impl Default for PromptState

Source§

fn default() -> PromptState

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> 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> 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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.