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
impl PromptState
Sourcepub fn spec(&self) -> Option<&PromptSpec>
pub fn spec(&self) -> Option<&PromptSpec>
Returns the active spec, if open.
Sourcepub fn items(&self) -> &[PromptItem]
pub fn items(&self) -> &[PromptItem]
Current item rows.
Sourcepub fn selected_index(&self) -> usize
pub fn selected_index(&self) -> usize
Selected item index.
Sourcepub fn selected_item(&self) -> Option<&PromptItem>
pub fn selected_item(&self) -> Option<&PromptItem>
Selected item, if the list is non-empty.
Sourcepub fn open(&mut self, spec: PromptSpec, initial: &str)
pub fn open(&mut self, spec: PromptSpec, initial: &str)
Opens a prompt, replacing any active one.
Sourcepub fn set_message(&mut self, message: &str)
pub fn set_message(&mut self, message: &str)
Sets the validation / error message.
Sourcepub fn clear_message(&mut self)
pub fn clear_message(&mut self)
Clears the validation / error message.
Sourcepub fn set_items(&mut self, items: Vec<PromptItem>)
pub fn set_items(&mut self, items: Vec<PromptItem>)
Replaces the item list, clamping the selection into range.
Sourcepub fn delete_after_cursor(&mut self)
pub fn delete_after_cursor(&mut self)
Deletes the char after the input cursor (UTF-8 safe).
Sourcepub fn delete_word_before(&mut self)
pub fn delete_word_before(&mut self)
Deletes back to the previous blank-separated word start (Ctrl+W, Ctrl+Backspace).
Sourcepub fn delete_word_after(&mut self)
pub fn delete_word_after(&mut self)
Deletes from the cursor forward across the next word (Ctrl+Delete).
Sourcepub fn clear_to_start(&mut self)
pub fn clear_to_start(&mut self)
Clears everything before the cursor (Ctrl+U).
Sourcepub fn clear_to_end(&mut self)
pub fn clear_to_end(&mut self)
Clears everything after the cursor (Ctrl+K).
Sourcepub fn move_word_left(&mut self)
pub fn move_word_left(&mut self)
Moves the input cursor to the start of the previous word (Ctrl+Left).
Sourcepub fn move_word_right(&mut self)
pub fn move_word_right(&mut self)
Moves the input cursor to the end of the current or next word (Ctrl+Right).
Sourcepub fn move_right(&mut self)
pub fn move_right(&mut self)
Moves the input cursor one char right.
Sourcepub fn history_prev(&mut self)
pub fn history_prev(&mut self)
Steps back through submitted-input history.
Sourcepub fn history_next(&mut self)
pub fn history_next(&mut self)
Steps forward through history, restoring the draft at the end.
Sourcepub fn select_next(&mut self)
pub fn select_next(&mut self)
Moves the item selection forward, wrapping.
Sourcepub fn select_prev(&mut self)
pub fn select_prev(&mut self)
Moves the item selection backward, wrapping.
Sourcepub fn complete_selected(&mut self)
pub fn complete_selected(&mut self)
Copies the selected item’s label into the input (Tab).
Sourcepub fn submit(&mut self) -> String
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.
Sourcepub fn handle_key(&mut self, event: &KeyEvent) -> PromptAction
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
impl Clone for PromptState
Source§fn clone(&self) -> PromptState
fn clone(&self) -> PromptState
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more