Skip to main content

Prompt

Struct Prompt 

Source
pub struct Prompt {
    pub message: String,
    pub input: String,
    pub cursor_pos: usize,
    pub prompt_type: PromptType,
    pub suggestions: Vec<Suggestion>,
    pub original_suggestions: Option<Vec<Suggestion>>,
    pub selected_suggestion: Option<usize>,
    pub selection_anchor: Option<usize>,
    pub suggestions_set_for_input: Option<String>,
    pub sync_input_on_navigate: bool,
}
Expand description

Prompt state for the minibuffer

Fields§

§message: String

The prompt message (e.g., “Find file: “)

§input: String

User’s current input

§cursor_pos: usize

Cursor position in the input

§prompt_type: PromptType

What to do when user confirms

§suggestions: Vec<Suggestion>

Autocomplete suggestions (filtered)

§original_suggestions: Option<Vec<Suggestion>>

Original unfiltered suggestions (for prompts that filter client-side like SwitchToTab)

§selected_suggestion: Option<usize>

Currently selected suggestion index

§selection_anchor: Option<usize>

Selection anchor position (for Shift+Arrow selection) When Some(pos), there’s a selection from anchor to cursor_pos

§suggestions_set_for_input: Option<String>

Tracks the input value when suggestions were last set by a plugin. Used to skip Rust-side filtering when plugin has already filtered for this input.

§sync_input_on_navigate: bool

When true, navigating suggestions updates the input text (selected) to match. Used by plugin prompts that want picker-like behavior (e.g. compose width).

Implementations§

Source§

impl Prompt

Source

pub fn new(message: String, prompt_type: PromptType) -> Self

Create a new prompt

Source

pub fn with_suggestions( message: String, prompt_type: PromptType, suggestions: Vec<Suggestion>, ) -> Self

Create a new prompt with suggestions

The suggestions are stored both as the current filtered list and as the original unfiltered list (for prompts that filter client-side like SwitchToTab).

Source

pub fn with_initial_text( message: String, prompt_type: PromptType, initial_text: String, ) -> Self

Create a new prompt with initial text (selected so typing replaces it)

Source

pub fn cursor_left(&mut self)

Move cursor left (to previous grapheme cluster boundary)

Uses grapheme cluster boundaries for proper handling of combining characters like Thai diacritics, emoji with modifiers, etc.

Source

pub fn cursor_right(&mut self)

Move cursor right (to next grapheme cluster boundary)

Uses grapheme cluster boundaries for proper handling of combining characters like Thai diacritics, emoji with modifiers, etc.

Source

pub fn insert_char(&mut self, ch: char)

Insert a character at the cursor position

Source

pub fn backspace(&mut self)

Delete one code point before cursor (backspace)

Deletes one Unicode code point at a time, allowing layer-by-layer deletion of combining characters. For Thai text, this means you can delete just the tone mark without removing the base consonant.

Source

pub fn delete(&mut self)

Delete grapheme cluster at cursor (delete key)

Deletes the entire grapheme cluster, handling combining characters properly.

Source

pub fn move_to_start(&mut self)

Move to start of input

Source

pub fn move_to_end(&mut self)

Move to end of input

Source

pub fn set_input(&mut self, text: String)

Set the input text and cursor position

Used for history navigation - replaces the entire input with a new value and moves cursor to the end.

§Example
let mut prompt = Prompt::new("Search: ".to_string(), PromptType::Search);
prompt.input = "current".to_string();
prompt.cursor_pos = 7;

prompt.set_input("from history".to_string());
assert_eq!(prompt.input, "from history");
assert_eq!(prompt.cursor_pos, 12); // At end
Source

pub fn select_next_suggestion(&mut self)

Select next suggestion

Source

pub fn select_prev_suggestion(&mut self)

Select previous suggestion

Source

pub fn selected_value(&self) -> Option<String>

Get the currently selected suggestion value

Source

pub fn get_final_input(&self) -> String

Get the final input (use selected suggestion if available, otherwise raw input)

Source

pub fn filter_suggestions(&mut self, match_description: bool)

Apply fuzzy filtering to suggestions based on current input

If match_description is true, also matches against suggestion descriptions. Updates suggestions with filtered and sorted results.

Source

pub fn delete_word_forward(&mut self)

Delete from cursor to end of word (Ctrl+Delete).

Deletes from the current cursor position to the end of the current word. If the cursor is at a non-word character, skips to the next word and deletes to its end.

§Example
let mut prompt = Prompt::new("Find: ".to_string(), PromptType::OpenFile);
prompt.input = "hello world".to_string();
prompt.cursor_pos = 0; // At start of "hello"
prompt.delete_word_forward();
assert_eq!(prompt.input, " world");
assert_eq!(prompt.cursor_pos, 0);
Source

pub fn delete_word_backward(&mut self)

Delete from start of word to cursor (Ctrl+Backspace).

Deletes from the start of the current word to the cursor position. If the cursor is after a non-word character, deletes the previous word.

§Example
let mut prompt = Prompt::new("Find: ".to_string(), PromptType::OpenFile);
prompt.input = "hello world".to_string();
prompt.cursor_pos = 5; // After "hello"
prompt.delete_word_backward();
assert_eq!(prompt.input, " world");
assert_eq!(prompt.cursor_pos, 0);
Source

pub fn delete_to_end(&mut self)

Delete from cursor to end of line (Ctrl+K).

Deletes all text from the cursor position to the end of the input.

§Example
let mut prompt = Prompt::new("Find: ".to_string(), PromptType::OpenFile);
prompt.input = "hello world".to_string();
prompt.cursor_pos = 5; // After "hello"
prompt.delete_to_end();
assert_eq!(prompt.input, "hello");
assert_eq!(prompt.cursor_pos, 5);
Source

pub fn get_text(&self) -> String

Get the current input text (for copy operation).

Returns a copy of the entire input. In future, this could be extended to support selection ranges for copying only selected text.

§Example
let mut prompt = Prompt::new("Search: ".to_string(), PromptType::Search);
prompt.input = "test query".to_string();
assert_eq!(prompt.get_text(), "test query");
Source

pub fn clear(&mut self)

Clear the input (used for cut operation).

Removes all text from the input and resets cursor to start.

§Example
let mut prompt = Prompt::new("Find: ".to_string(), PromptType::OpenFile);
prompt.input = "some text".to_string();
prompt.cursor_pos = 9;
prompt.clear();
assert_eq!(prompt.input, "");
assert_eq!(prompt.cursor_pos, 0);
Source

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

Insert text at cursor position (used for paste operation).

Inserts the given text at the current cursor position and moves the cursor to the end of the inserted text.

§Example
let mut prompt = Prompt::new("Command: ".to_string(), PromptType::Command);
prompt.input = "save".to_string();
prompt.cursor_pos = 4;
prompt.insert_str(" file");
assert_eq!(prompt.input, "save file");
assert_eq!(prompt.cursor_pos, 9);
Source

pub fn has_selection(&self) -> bool

Check if there’s an active selection

Source

pub fn selection_range(&self) -> Option<(usize, usize)>

Get the selection range (start, end) where start <= end

Source

pub fn selected_text(&self) -> Option<String>

Get the selected text

Source

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

Delete the current selection and return the deleted text

Source

pub fn clear_selection(&mut self)

Clear selection without deleting text

Source

pub fn move_left_selecting(&mut self)

Move cursor left with selection (by grapheme cluster)

Source

pub fn move_right_selecting(&mut self)

Move cursor right with selection (by grapheme cluster)

Source

pub fn move_home_selecting(&mut self)

Move to start of input with selection

Source

pub fn move_end_selecting(&mut self)

Move to end of input with selection

Source

pub fn move_word_left_selecting(&mut self)

Move to start of previous word with selection Mimics Buffer’s find_word_start_left behavior

Source

pub fn move_word_right_selecting(&mut self)

Move to end of next word with selection For selection, we want to select whole words, so move to word END, not word START

Source

pub fn move_word_left(&mut self)

Move to start of previous word (without selection) Mimics Buffer’s find_word_start_left behavior

Source

pub fn move_word_right(&mut self)

Move to start of next word (without selection) Mimics Buffer’s find_word_start_right behavior

Trait Implementations§

Source§

impl Clone for Prompt

Source§

fn clone(&self) -> Prompt

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Prompt

Source§

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

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

impl InputHandler for Prompt

Source§

fn handle_key_event( &mut self, event: &KeyEvent, ctx: &mut InputContext, ) -> InputResult

Handle a key event. Returns whether the event was consumed.
Source§

fn is_modal(&self) -> bool

Whether this handler is modal (consumes all unhandled input).
Source§

fn focused_child(&self) -> Option<&dyn InputHandler>

Get the currently focused child handler, if any.
Source§

fn focused_child_mut(&mut self) -> Option<&mut dyn InputHandler>

Get the currently focused child handler mutably, if any.
Source§

fn dispatch_input( &mut self, event: &KeyEvent, ctx: &mut InputContext, ) -> InputResult

Dispatch input through this handler and its children. This is the main entry point - it handles the bubble-up logic.

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> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<'a, T> FromIn<'a, T> for T

Source§

fn from_in(t: T, _: &'a Allocator) -> T

Converts to this type from the input type within the given allocator.
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<'a, T, U> IntoIn<'a, U> for T
where U: FromIn<'a, T>,

Source§

fn into_in(self, allocator: &'a Allocator) -> U

Converts this type into the (usually inferred) input type within the given allocator.
Source§

impl<D> OwoColorize for D

Source§

fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>
where C: Color,

Set the foreground color generically Read more
Source§

fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>
where C: Color,

Set the background color generically. Read more
Source§

fn black(&self) -> FgColorDisplay<'_, Black, Self>

Change the foreground color to black
Source§

fn on_black(&self) -> BgColorDisplay<'_, Black, Self>

Change the background color to black
Source§

fn red(&self) -> FgColorDisplay<'_, Red, Self>

Change the foreground color to red
Source§

fn on_red(&self) -> BgColorDisplay<'_, Red, Self>

Change the background color to red
Source§

fn green(&self) -> FgColorDisplay<'_, Green, Self>

Change the foreground color to green
Source§

fn on_green(&self) -> BgColorDisplay<'_, Green, Self>

Change the background color to green
Source§

fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>

Change the foreground color to yellow
Source§

fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>

Change the background color to yellow
Source§

fn blue(&self) -> FgColorDisplay<'_, Blue, Self>

Change the foreground color to blue
Source§

fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>

Change the background color to blue
Source§

fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>

Change the foreground color to magenta
Source§

fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>

Change the background color to magenta
Source§

fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>

Change the foreground color to purple
Source§

fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>

Change the background color to purple
Source§

fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>

Change the foreground color to cyan
Source§

fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>

Change the background color to cyan
Source§

fn white(&self) -> FgColorDisplay<'_, White, Self>

Change the foreground color to white
Source§

fn on_white(&self) -> BgColorDisplay<'_, White, Self>

Change the background color to white
Source§

fn default_color(&self) -> FgColorDisplay<'_, Default, Self>

Change the foreground color to the terminal default
Source§

fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>

Change the background color to the terminal default
Source§

fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>

Change the foreground color to bright black
Source§

fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>

Change the background color to bright black
Source§

fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>

Change the foreground color to bright red
Source§

fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>

Change the background color to bright red
Source§

fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>

Change the foreground color to bright green
Source§

fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>

Change the background color to bright green
Source§

fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>

Change the foreground color to bright yellow
Source§

fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>

Change the background color to bright yellow
Source§

fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>

Change the foreground color to bright blue
Source§

fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>

Change the background color to bright blue
Source§

fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>

Change the foreground color to bright magenta
Source§

fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>

Change the background color to bright magenta
Source§

fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>

Change the foreground color to bright purple
Source§

fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>

Change the background color to bright purple
Source§

fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>

Change the foreground color to bright cyan
Source§

fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>

Change the background color to bright cyan
Source§

fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>

Change the foreground color to bright white
Source§

fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>

Change the background color to bright white
Source§

fn bold(&self) -> BoldDisplay<'_, Self>

Make the text bold
Source§

fn dimmed(&self) -> DimDisplay<'_, Self>

Make the text dim
Source§

fn italic(&self) -> ItalicDisplay<'_, Self>

Make the text italicized
Source§

fn underline(&self) -> UnderlineDisplay<'_, Self>

Make the text underlined
Make the text blink
Make the text blink (but fast!)
Source§

fn reversed(&self) -> ReversedDisplay<'_, Self>

Swap the foreground and background colors
Source§

fn hidden(&self) -> HiddenDisplay<'_, Self>

Hide the text
Source§

fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>

Cross out the text
Source§

fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>
where Color: DynColor,

Set the foreground color at runtime. Only use if you do not know which color will be used at compile-time. If the color is constant, use either OwoColorize::fg or a color-specific method, such as OwoColorize::green, Read more
Source§

fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>
where Color: DynColor,

Set the background color at runtime. Only use if you do not know what color to use at compile-time. If the color is constant, use either OwoColorize::bg or a color-specific method, such as OwoColorize::on_yellow, Read more
Source§

fn fg_rgb<const R: u8, const G: u8, const B: u8>( &self, ) -> FgColorDisplay<'_, CustomColor<R, G, B>, Self>

Set the foreground color to a specific RGB value.
Source§

fn bg_rgb<const R: u8, const G: u8, const B: u8>( &self, ) -> BgColorDisplay<'_, CustomColor<R, G, B>, Self>

Set the background color to a specific RGB value.
Source§

fn truecolor(&self, r: u8, g: u8, b: u8) -> FgDynColorDisplay<'_, Rgb, Self>

Sets the foreground color to an RGB value.
Source§

fn on_truecolor(&self, r: u8, g: u8, b: u8) -> BgDynColorDisplay<'_, Rgb, Self>

Sets the background color to an RGB value.
Source§

fn style(&self, style: Style) -> Styled<&Self>

Apply a runtime-determined style
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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> TryClone for T
where T: Clone,

Source§

fn try_clone(&self) -> Result<T, Error>

Clones self, possibly returning an error.
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<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
Source§

impl<T> ParallelSend for T