### Run Text Example Source: https://docs.rs/promkit/latest/promkit/index.html Execute the Text prompt example using the provided command. ```bash cargo run --bin text ``` -------------------------------- ### Run Form Example Source: https://docs.rs/promkit/latest/promkit/index.html Execute the Form prompt example using the provided command. ```bash cargo run --bin form ``` -------------------------------- ### Run QuerySelector Example Source: https://docs.rs/promkit/latest/promkit/index.html Execute the QuerySelector prompt example using the provided command. ```bash cargo run --bin query_selector ``` -------------------------------- ### Run Tree Example Source: https://docs.rs/promkit/latest/promkit/index.html Execute the Tree prompt example using the provided command. ```bash cargo run --bin tree ``` -------------------------------- ### Run Password Example Source: https://docs.rs/promkit/latest/promkit/index.html Execute the Password prompt example using the provided command. ```bash cargo run --bin password ``` -------------------------------- ### Run Listbox Example Source: https://docs.rs/promkit/latest/promkit/index.html Execute the Listbox prompt example using the provided command. ```bash cargo run --bin listbox ``` -------------------------------- ### Run Checkbox Example Source: https://docs.rs/promkit/latest/promkit/index.html Execute the Checkbox prompt example using the provided command. ```bash cargo run --bin checkbox ``` -------------------------------- ### Run Readline Example Source: https://docs.rs/promkit/latest/promkit/index.html Execute the Readline prompt example using the provided command. ```bash cargo run --bin readline ``` -------------------------------- ### Run Confirm Example Source: https://docs.rs/promkit/latest/promkit/index.html Execute the Confirm prompt example using the provided command. ```bash cargo run --bin confirm ``` -------------------------------- ### Run JSON Example Source: https://docs.rs/promkit/latest/promkit/index.html Execute the JSON prompt example, providing a path to a JSON file as an argument. ```bash cargo run --bin json ${PATH_TO_JSON_FILE} ``` -------------------------------- ### Prompt for Checkbox - initialize Source: https://docs.rs/promkit/latest/promkit/preset/checkbox/struct.Checkbox.html Initializes the handler, preparing it for use. This method is called before the prompt starts running. ```APIDOC ## impl Prompt for Checkbox ### fn initialize<'life0, 'async_trait>( &'life0 mut self, ) -> Pin> + Send + 'async_trait>> Initializes the handler, preparing it for use. This method is called before the prompt starts running. ``` -------------------------------- ### Prompt Run Method Implementation Source: https://docs.rs/promkit/latest/src/promkit/lib.rs.html Handles the main loop for running a prompt, including terminal setup, event handling, and cleanup. It ensures raw mode is enabled and the cursor is hidden during execution, and restored afterward. ```rust async fn run(&mut self) -> anyhow::Result { defer! { execute!( io::stdout(), cursor::Show, event::DisableMouseCapture, ) .ok(); disable_raw_mode().ok(); }; enable_raw_mode()?; execute!(io::stdout(), cursor::Hide)?; self.initialize().await?; while let Some(event) = EVENT_STREAM.lock().await.next().await { match event { Ok(event) => { if event.is_resize() { continue; } if self.evaluate(&event).await? == Signal::Quit { break; } } Err(_) => break, } } Ok(self.finalize()?) } ``` -------------------------------- ### Prefix Search Implementation Source: https://docs.rs/promkit/latest/src/promkit/suggest.rs.html Provides a method to search for all suggestions that start with a given query prefix. Returns a vector of matching strings. ```rust impl Suggest { pub fn prefix_search>(&self, query: T) -> Option> { self.0 .get_raw_descendant(query.as_ref()) .map(|subtrie| subtrie.iter().map(|item| item.0.clone()).collect()) } } ``` -------------------------------- ### Form::initialize Method Source: https://docs.rs/promkit/latest/promkit/preset/form/struct.Form.html Initializes the Form handler, preparing it for use before the prompt starts running. This is part of the Prompt trait implementation. ```rust fn initialize<'life0, 'async_trait>( &'life0 mut self, ) -> Pin> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, ``` -------------------------------- ### Prompt Trait - Initialize Method Source: https://docs.rs/promkit/latest/promkit/trait.Prompt.html Initializes the prompt handler, preparing it for use before the prompt starts running. Returns a Result indicating success or failure. ```rust fn initialize<'life0, 'async_trait>( &'life0 mut self, ) -> Pin> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; ``` -------------------------------- ### prefix_search Source: https://docs.rs/promkit/latest/src/promkit/suggest.rs.html Searches the Suggest trie for all entries that start with the given query prefix. ```APIDOC impl Suggest { /// Searches the Suggest trie for all entries that start with the given query prefix. /// /// # Arguments /// /// * `query` - The prefix string to search for. /// /// # Returns /// /// An `Option` containing a `Vec` of matching suggestions if found, otherwise `None`. pub fn prefix_search>(&self, query: T) -> Option> { self.0 .get_raw_descendant(query.as_ref()) .map(|subtrie| subtrie.iter().map(|item| item.0.clone()).collect()) } } ``` -------------------------------- ### Readline Initialization and Configuration Source: https://docs.rs/promkit/latest/promkit/preset/readline/struct.Readline.html Demonstrates how to create and configure a Readline prompt with various options. ```APIDOC ## Readline Configuration Methods This section details the methods available for configuring the `Readline` struct before running the prompt. ### `title(self, text: T) -> Self` Sets the title text displayed above the input field. ### `title_style(self, style: ContentStyle) -> Self` Sets the style for the title text. ### `enable_suggest(self, suggest: Suggest) -> Self` Enables suggestion functionality with the provided `Suggest` instance. ### `enable_history(self) -> Self` Enables history functionality allowing navigation through previous inputs. ### `prefix(self, prefix: T) -> Self` Sets the prefix string displayed before the input text. ### `mask(self, mask: char) -> Self` Sets the character used for masking input text, typically used for password fields. ### `prefix_style(self, style: ContentStyle) -> Self` Sets the style for the prefix string. ### `active_char_style(self, style: ContentStyle) -> Self` Sets the style for the currently active character in the input field. ### `inactive_char_style(self, style: ContentStyle) -> Self` Sets the style for characters that are not currently active in the input field. ### `edit_mode(self, mode: Mode) -> Self` Sets the edit mode for the text editor, either insert or overwrite. ### `word_break_chars(self, characters: HashSet) -> Self` Sets the characters to be for word break. ### `text_editor_lines(self, lines: usize) -> Self` Sets the number of lines available for rendering the text editor. ### `evaluator(self, evaluator: Evaluator) -> Self` Sets the function to evaluate the input, allowing for custom evaluation logic. ### `validator(self, validator: Validator, error_message_generator: ErrorMessageGenerator) -> Self` Configures a validator for the input with a function to validate the input and another to configure the error message. ``` -------------------------------- ### Form::type_id Method Source: https://docs.rs/promkit/latest/promkit/preset/form/struct.Form.html Gets the `TypeId` of the Form. This is a standard method from the `Any` trait. ```rust fn type_id(&self) -> TypeId ``` -------------------------------- ### render Source: https://docs.rs/promkit/latest/src/promkit/preset/tree.rs.html Renders the prompt with the specified width and height. ```APIDOC ## render ### Description Render the prompt with the specified width and height. ### Method `render(width: u16, height: u16) -> anyhow::Result<()>` ### Parameters #### Path Parameters - **width** (u16) - Required - The width for rendering. - **height** (u16) - Required - The height for rendering. ### Response #### Success Response (200) - **Ok(())** - Indicates successful rendering. #### Error Response - **Err(anyhow::Error)** - If the renderer is not initialized. ``` -------------------------------- ### Type ID Source: https://docs.rs/promkit/latest/promkit/preset/readline/struct.Readline.html Provides a way to get the unique `TypeId` of a type, useful for runtime type identification. ```APIDOC ## `fn type_id(&self) -> TypeId` ### Description Gets the `TypeId` of `self`. ### Method `type_id` ### Parameters None ### Returns - `TypeId`: The unique identifier for the type of `self`. ``` -------------------------------- ### Json::new Source: https://docs.rs/promkit/latest/promkit/preset/json/struct.Json.html Creates a new instance of the Json preset, initializing it with the provided JSON stream. ```APIDOC ### impl Json #### pub fn new(stream: JsonStream) -> Self Creates a new JSON preset with the provided JSON stream. ``` -------------------------------- ### Password Configuration Source: https://docs.rs/promkit/latest/promkit/preset/password/struct.Password.html Demonstrates how to configure and use the Password struct for capturing input. ```APIDOC ## Password Configuration This section details the methods available for configuring the `Password` struct before running the prompt. ### Methods - `title(text: T) -> Self`: Sets the title text displayed above the password input field. - `title_style(style: ContentStyle) -> Self`: Sets the style for the title text. - `mask(mask: char) -> Self`: Sets the character used for masking the password input. - `active_char_style(style: ContentStyle) -> Self`: Sets the style for the currently active character. - `inactive_char_style(style: ContentStyle) -> Self`: Sets the style for inactive characters. - `text_editor_lines(lines: usize) -> Self`: Sets the number of lines for rendering the input field. - `validator(validator: Validator, error_message_generator: ErrorMessageGenerator) -> Self`: Configures a validator for the password input. ### Running the Prompt - `run(&mut self) -> Result`: Executes the password prompt and returns the entered password as a `String` upon success. ``` -------------------------------- ### Form::run Method Source: https://docs.rs/promkit/latest/promkit/preset/form/struct.Form.html Runs the Form prompt, handling all events and producing a final result. This is the main entry point for executing the form. ```rust fn run<'life0, 'async_trait>( &'life0 mut self, ) -> Pin> + Send + 'async_trait>> where Self: Send + 'async_trait, 'life0: 'async_trait, ``` -------------------------------- ### Create New Text Instance Source: https://docs.rs/promkit/latest/promkit/preset/text/struct.Text.html Creates a new Text instance with the provided static text. Use this to initialize a text component. ```rust pub fn new>(text: T) -> Self ``` -------------------------------- ### Form::new Constructor Source: https://docs.rs/promkit/latest/promkit/preset/form/struct.Form.html Creates a new Form instance with the provided initial states. Use this to initialize the form with your desired input fields. ```rust pub fn new>(states: I) -> Self> ``` -------------------------------- ### Form::init Method Source: https://docs.rs/promkit/latest/promkit/preset/form/struct.Form.html Initializes a Form with a given initializer. This is part of the `Pointable` trait. ```rust unsafe fn init(init: ::Init) -> usize ``` -------------------------------- ### Initialize Text Preset Source: https://docs.rs/promkit/latest/src/promkit/preset/text.rs.html Initializes the text preset by creating a shared renderer with the specified text content and terminal size. This should be called before rendering. ```rust async fn initialize(&mut self) -> anyhow::Result<()> { let size = crossterm::terminal::size()?; self.renderer = Some(SharedRenderer::new( Renderer::try_new_with_graphemes( [(Index::Text, self.text.create_graphemes(size.0, size.1))], true, ) .await?, )); Ok(()) } ``` -------------------------------- ### Prompt Rendering Source: https://docs.rs/promkit/latest/src/promkit/preset/readline.rs.html Renders the prompt with the specified width and height. ```APIDOC ## render ### Description Render the prompt with the specified width and height. ### Signature `async fn render(&mut self, width: u16, height: u16) -> anyhow::Result<()>` ### Parameters * `width` (u16) - The width to render the prompt. * `height` (u16) - The height to render the prompt. ### Returns `anyhow::Result<()>` - A result indicating success or failure during rendering. ``` -------------------------------- ### Create New Listbox Instance Source: https://docs.rs/promkit/latest/src/promkit/preset/listbox.rs.html Constructs a new `Listbox` with a provided list of items. Initializes default styles and configurations for the title and listbox components. ```rust pub fn new>(items: I) -> Self { Self { renderer: None, evaluator: |event, ctx| Box::pin(evaluate::default(event, ctx)), title: text::State { config: text::config::Config { style: Some(ContentStyle { attributes: Attributes::from(Attribute::Bold), ..Default::default() }), ..Default::default() }, ..Default::default() }, listbox: listbox::State { listbox: listbox::Listbox::from(items), config: Config { cursor: String::from("❯ "), active_item_style: Some(ContentStyle { foreground_color: Some(Color::DarkCyan), ..Default::default() }), inactive_item_style: Some(ContentStyle::default()), lines: Default::default(), }, }, } } ``` -------------------------------- ### Confirm::new Source: https://docs.rs/promkit/latest/promkit/preset/confirm/struct.Confirm.html Creates a new Confirm prompt with a specified prefix. This function is used to initialize the confirmation prompt. ```APIDOC ## pub fn new>(prefix: T) -> Self Creates a new `Confirm` prompt with a specified prefix. ``` -------------------------------- ### Render JSON Prompt Source: https://docs.rs/promkit/latest/src/promkit/preset/json.rs.html Asynchronously renders the prompt with the specified width and height, displaying the configured JSON data. ```APIDOC ## render ### Description Render the prompt with the specified width and height. ### Method `async fn render(&mut self, width: u16, height: u16) -> anyhow::Result<()>` ### Parameters - **width** (u16) - The width of the rendering area. - **height** (u16) - The height of the rendering area. ### Response #### Success Response (Ok(())) Indicates successful rendering. #### Error Response (Err(anyhow::Error)) Returns an error if the renderer is not initialized or another rendering issue occurs. ``` -------------------------------- ### Render Prompt with Dimensions Source: https://docs.rs/promkit/latest/src/promkit/preset/form.rs.html Renders the prompt content with the specified width and height. It updates the renderer with graphemes derived from the text editor states and then displays them. Returns an error if the renderer is not initialized. ```rust async fn render(&mut self, width: u16, height: u16) -> anyhow::Result<()> { match self.renderer.as_ref() { Some(renderer) => { renderer .update( self.readlines .contents() .iter() .enumerate() .map(|(i, state)| (i, state.create_graphemes(width, height))) ) .render() .await } None => Err(anyhow::anyhow!("Renderer not initialized")), } } ``` -------------------------------- ### Create New Text Preset Source: https://docs.rs/promkit/latest/src/promkit/preset/text.rs.html Constructs a new `Text` instance with default settings. Accepts any type that can be converted into a string slice for the text content. ```rust pub fn new>(text: T) -> Self { Self { renderer: None, evaluator: |event, ctx| Box::pin(evaluate::default(event, ctx)), text: text::State { text: text::Text::from(text), config: Config::default(), }, } } ``` -------------------------------- ### Prompt::run Implementation Source: https://docs.rs/promkit/latest/promkit/preset/query_selector/struct.QuerySelector.html Runs the QuerySelector prompt, handling all events and interactions until completion, and then returns the final result. This is the primary method for executing the prompt. ```rust fn run<'life0, 'async_trait>( &'life0 mut self, ) -> Pin> + Send + 'async_trait>> where Self: Send + 'async_trait, 'life0: 'async_trait, ``` -------------------------------- ### Form::new Source: https://docs.rs/promkit/latest/promkit/preset/form/struct.Form.html Constructor for the Form struct, initializing it with a collection of states. ```APIDOC ## impl Form ### pub fn new>(states: I) -> Self Creates a new Form instance with the provided initial states. ``` -------------------------------- ### Run Confirm Prompt Source: https://docs.rs/promkit/latest/promkit/preset/confirm/struct.Confirm.html Executes the confirmation prompt and returns the user's response. This method sets the title text displayed above the prompt. ```rust pub async fn run(&mut self) -> Result ``` -------------------------------- ### Render Prompt with Listbox Source: https://docs.rs/promkit/latest/src/promkit/preset/listbox.rs.html Renders the prompt, including the title and listbox components, with the specified width and height. Ensures the renderer is initialized before attempting to update and render. ```rust async fn render(&mut self, width: u16, height: u16) -> anyhow::Result<()> { match self.renderer.as_ref() { Some(renderer) => { renderer .update([ (Index::Title, self.title.create_graphemes(width, height)), (Index::Listbox, self.listbox.create_graphemes(width, height)), ]) .render() .await } None => Err(anyhow::anyhow!("Renderer not initialized")), } } ``` -------------------------------- ### Password Input Configuration Methods Source: https://docs.rs/promkit/latest/src/promkit/preset/password.rs.html Provides methods to configure the appearance and behavior of the password input prompt, such as setting titles, styles, masking characters, and text editor lines. These methods allow for customization of the user experience. ```rust impl Password { /// Sets the title text displayed above the password input field. pub fn title>(mut self, text: T) -> Self { self = Password(self.0.title(text)); self } /// Sets the style for the title text. pub fn title_style(mut self, style: ContentStyle) -> Self { self = Password(self.0.title_style(style)); self } /// Sets the character used for masking the password input. pub fn mask(mut self, mask: char) -> Self { self = Password(self.0.mask(mask)); self } /// Sets the style for the currently active character in the password input field. pub fn active_char_style(mut self, style: ContentStyle) -> Self { self = Password(self.0.active_char_style(style)); self } /// Sets the style for characters that are not currently active in the password input field. pub fn inactive_char_style(mut self, style: ContentStyle) -> Self { self = Password(self.0.inactive_char_style(style)); self } /// Sets the number of lines available for rendering the password input field. pub fn text_editor_lines(mut self, lines: usize) -> Self { self = Password(self.0.text_editor_lines(lines)); self } ``` -------------------------------- ### Listbox::new Source: https://docs.rs/promkit/latest/promkit/preset/listbox/struct.Listbox.html Constructs a new Listbox instance with a list of items to be displayed as selectable options. ```APIDOC ## pub fn new>(items: I) -> Self ### Description Constructs a new `Listbox` instance with a list of items to be displayed as selectable options. ### Arguments * `items` - An iterator over items that implement the `Display` trait, to be used as options. ``` -------------------------------- ### Form Initialization and Rendering Source: https://docs.rs/promkit/latest/src/promkit/preset/form.rs.html Initializes the Form's renderer and updates styles based on the current cursor position. This is typically called during the prompt's initialization and evaluation phases. ```rust async fn initialize(&mut self) -> anyhow::Result<()> { // Update styles based on the current position. self.overwrite_styles(); let size = crossterm::terminal::size()?; self.renderer = Some(SharedRenderer::new( Renderer::try_new_with_graphemes( self.readlines .contents() .iter() .enumerate() .map(|(i, state)| (i, state.create_graphemes(size.0, size.1))), true, ) .await?, )); Ok(()) } ``` ```rust async fn evaluate(&mut self, event: &Event) -> anyhow::Result { let ret = (self.evaluator)(event, self).await; // Update the styles based on the current position. self.overwrite_styles(); let size = crossterm::terminal::size()?; self.render(size.0, size.1).await?; ret } ``` -------------------------------- ### default Source: https://docs.rs/promkit/latest/promkit/preset/text/evaluate/fn.default.html This function sets up default key bindings for text input, allowing users to interact with text fields using standard keyboard shortcuts. It is available only when the `text` feature is enabled. ```APIDOC ## default promkit::preset::text::evaluate # Function default Copy item path Source Search Settings Help ## Summary ```rust pub async fn default(event: &Event, ctx: &mut Text) -> Result ``` Available on **crate feature`text`** only. ### Description Default key bindings for the text. ### Key Bindings Key| Action ---|--- `Enter`| Exit the text `Ctrl + C`| Interrupt the current operation `↑`| Move the selection up `↓`| Move the selection down ``` -------------------------------- ### TryFrom and TryInto Implementations Source: https://docs.rs/promkit/latest/promkit/preset/json/struct.Json.html Details the implementations for TryFrom and TryInto traits, enabling fallible type conversions. ```APIDOC ## impl TryFrom for T ### Description Provides fallible conversion from type U into type T. #### type Error = Infallible ### Description The type returned in the event of a conversion error. #### fn try_from(value: U) -> Result>::Error> ### Description Performs the conversion from U to T. ### Method fn ``` ```APIDOC ## impl TryInto for T ### Description Provides fallible conversion from type T into type U. #### type Error = >::Error ### Description The type returned in the event of a conversion error. #### fn try_into(self) -> Result>::Error> ### Description Performs the conversion from T to U. ### Method fn ``` -------------------------------- ### Enable Suggestion Functionality Source: https://docs.rs/promkit/latest/promkit/preset/readline/struct.Readline.html Enables suggestion functionality for the Readline prompt using a provided `Suggest` instance. ```rust pub fn enable_suggest(self, suggest: Suggest) -> Self ``` -------------------------------- ### Create a New Tree Instance Source: https://docs.rs/promkit/latest/promkit/preset/tree/struct.Tree.html Initializes a new Tree component with a specified root node. ```rust pub fn new(root: Node) -> Self> ``` -------------------------------- ### Prompt Trait - Run Method Source: https://docs.rs/promkit/latest/promkit/trait.Prompt.html Provides a default implementation for running the prompt. It handles terminal initialization, event looping, and result production until a quit signal is received. ```rust fn run<'life0, 'async_trait>( &'life0 mut self, ) -> Pin> + Send + 'async_trait>> where Self: Send + 'async_trait, 'life0: 'async_trait { // ... implementation details ... } ``` -------------------------------- ### Confirm::run Source: https://docs.rs/promkit/latest/promkit/preset/confirm/struct.Confirm.html Executes the confirmation prompt and returns the user's response. This asynchronous method displays the prompt and waits for user input. ```APIDOC ## pub async fn run(&mut self) -> Result Sets the title text displayed above the confirmation prompt. ``` -------------------------------- ### Create New Confirm Prompt Source: https://docs.rs/promkit/latest/promkit/preset/confirm/struct.Confirm.html Creates a new Confirm prompt instance with a specified prefix. This function is part of the Confirm struct's implementation. ```rust pub fn new>(prefix: T) -> Self ``` -------------------------------- ### Render Prompt with JSON Data Source: https://docs.rs/promkit/latest/src/promkit/preset/json.rs.html Renders the prompt interface with the configured JSON data, applying specified width and height constraints. This method is asynchronous and returns a result. ```rust async fn render(&mut self, width: u16, height: u16) -> anyhow::Result<()> { match self.renderer.as_ref() { Some(renderer) => { renderer .update([ (Index::Title, self.title.create_graphemes(width, height)), (Index::Json, self.json.create_graphemes(width, height)), ]) .render() .await } None => Err(anyhow::anyhow!("Renderer not initialized")), } } ``` -------------------------------- ### Rust Confirm Prompt Implementation Source: https://docs.rs/promkit/latest/src/promkit/preset/confirm.rs.html Defines a `Confirm` struct that wraps `Readline` to create a yes/no confirmation prompt. It includes a constructor `new` to set the prefix and validation, and a `run` method to execute the prompt. ```rust use crate::Prompt; use crate::preset::readline::Readline; /// A wrapper around `Readline` for creating simple yes/no confirmation prompts. pub struct Confirm(Readline); impl Confirm { /// Creates a new `Confirm` prompt with a specified prefix. pub fn new>(prefix: T) -> Self { Self( Readline::default() .prefix(format!("{} (y/n) ", prefix.as_ref())) .validator( |text| -> bool { ["yes", "no", "y", "n", "Y", "N"].contains(&text) }, |_| String::from("Please type 'y' or 'n' as an answer"), ), ) } /// Sets the title text displayed above the confirmation prompt. pub async fn run(&mut self) -> anyhow::Result { self.0.run().await } } ``` -------------------------------- ### Readline Configuration Methods Source: https://docs.rs/promkit/latest/src/promkit/preset/readline.rs.html These methods allow for the configuration of the Readline input interface, including setting titles, styles, and enabling features like suggestions and history. ```APIDOC ## Readline Methods ### `title` Sets the title text displayed above the input field. - **Parameters** - `text` (T: AsRef) - The text to be displayed as the title. ### `title_style` Sets the style for the title text. - **Parameters** - `style` (ContentStyle) - The styling to apply to the title. ### `enable_suggest` Enables suggestion functionality with the provided `Suggest` instance. - **Parameters** - `suggest` (Suggest) - The Suggest instance to use for suggestions. ### `enable_history` Enables history functionality allowing navigation through previous inputs. ### `prefix` Sets the prefix string displayed before the input text. - **Parameters** - `prefix` (T: AsRef) - The prefix string. ### `mask` Sets the character used for masking input text, typically used for password fields. - **Parameters** - `mask` (char) - The character to use for masking. ### `prefix_style` Sets the style for the prefix string. - **Parameters** - `style` (ContentStyle) - The styling to apply to the prefix. ### `active_char_style` Sets the style for the currently active character in the input field. - **Parameters** - `style` (ContentStyle) - The styling for the active character. ### `inactive_char_style` Sets the style for characters that are not currently active in the input field. - **Parameters** - `style` (ContentStyle) - The styling for inactive characters. ### `edit_mode` Sets the edit mode for the text editor, either insert or overwrite. - **Parameters** - `mode` (text_editor::Mode) - The edit mode. ### `word_break_chars` Sets the characters to be used for word breaking. - **Parameters** - `characters` (HashSet) - A set of characters that define word breaks. ### `text_editor_lines` Sets the number of lines available for rendering the text editor. - **Parameters** - `lines` (usize) - The number of lines for the text editor. ### `evaluator` Sets the function to evaluate the input, allowing for custom evaluation logic. - **Parameters** - `evaluator` (Evaluator) - The custom evaluator function. ``` -------------------------------- ### Checkbox Initialization Source: https://docs.rs/promkit/latest/src/promkit/preset/checkbox.rs.html Provides methods to create a new Checkbox instance with different configurations. ```APIDOC ## Checkbox::new(items: I) ### Description Creates a new `Checkbox` instance with the provided items. ### Parameters - `items` (I: IntoIterator): An iterator of displayable items to be included in the checkbox list. ### Returns A new `Checkbox` instance. ``` ```APIDOC ## Checkbox::new_with_checked(items: I) ### Description Creates a new `Checkbox` instance with the provided items and their initial checked states. ### Parameters - `items` (I: IntoIterator): An iterator of tuples, where each tuple contains a displayable item and its initial boolean checked state. ### Returns A new `Checkbox` instance. ``` -------------------------------- ### Initialize Listbox Renderer Source: https://docs.rs/promkit/latest/src/promkit/preset/listbox.rs.html Initializes the shared renderer for the listbox, setting up graphemes for title and listbox components based on terminal size. ```rust async fn initialize(&mut self) -> anyhow::Result<()> { let size = crossterm::terminal::size()?; self.renderer = Some(SharedRenderer::new( Renderer::try_new_with_graphemes( [ (Index::Title, self.title.create_graphemes(size.0, size.1)), ( Index::Listbox, self.listbox.create_graphemes(size.0, size.1), ), ], true, ) .await?, )); Ok(()) } ``` -------------------------------- ### Render Prompt with Promkit Source: https://docs.rs/promkit/latest/src/promkit/preset/readline.rs.html Renders the prompt interface with specified width and height. It updates the display of title, readline input, suggestions, and error messages. ```rust /// Render the prompt with the specified width and height. async fn render(&mut self, width: u16, height: u16) -> anyhow::Result<()> { match self.renderer.as_ref() { Some(renderer) => { renderer .update([ (Index::Title, self.title.create_graphemes(width, height)), ( Index::Readline, self.readline.create_graphemes(width, height), ), ( Index::Suggestion, self.suggestions.create_graphemes(width, height), ), ( Index::ErrorMessage, self.error_message.create_graphemes(width, height), ), ]) .render() .await } None => Err(anyhow::anyhow!("Renderer not initialized")), } } ``` -------------------------------- ### Render Prompt with Tree Source: https://docs.rs/promkit/latest/src/promkit/preset/tree.rs.html Renders the prompt interface, including the title and tree structure, within the specified width and height. Ensures the renderer is initialized before calling. ```rust async fn render(&mut self, width: u16, height: u16) -> anyhow::Result<()> { match self.renderer.as_ref() { Some(renderer) => { renderer .update([ (Index::Title, self.title.create_graphemes(width, height)), (Index::Tree, self.tree.create_graphemes(width, height)), ]) .render() .await } None => Err(anyhow::anyhow!("Renderer not initialized")), } } ``` -------------------------------- ### Initialize Promkit JSON Preset Source: https://docs.rs/promkit/latest/src/promkit/preset/json.rs.html Initializes the JSON preset by setting up the renderer with the title and JSON stream components. This is typically called once when the preset is first used. ```rust async fn initialize(&mut self) -> anyhow::Result<()> { let size = crossterm::terminal::size()?; self.renderer = Some(SharedRenderer::new( Renderer::try_new_with_graphemes( [ (Index::Title, self.title.create_graphemes(size.0, size.1)), (Index::Json, self.json.create_graphemes(size.0, size.1)), ], true, ) .await?, )); Ok(()) } ``` -------------------------------- ### Render Prompt Source: https://docs.rs/promkit/latest/src/promkit/preset/form.rs.html Renders the prompt with the specified width and height. This method updates the renderer with the current state of the lines and then performs the rendering operation. ```APIDOC ## render ### Description Render the prompt with the specified width and height. ### Signature `async fn render(&mut self, width: u16, height: u16) -> anyhow::Result<()>` ### Parameters * `width` (u16) - The width to render the prompt. * `height` (u16) - The height to render the prompt. ### Returns * `anyhow::Result<()>` - Returns Ok(()) on success, or an error if the renderer is not initialized. ``` -------------------------------- ### Prompt for Checkbox - run Source: https://docs.rs/promkit/latest/promkit/preset/checkbox/struct.Checkbox.html Runs the prompt, handling events and producing a result. ```APIDOC ## impl Prompt for Checkbox ### fn run<'life0, 'async_trait>( &'life0 mut self, ) -> Pin> + Send + 'async_trait>> Runs the prompt, handling events and producing a result. ``` -------------------------------- ### Prompt for Json Source: https://docs.rs/promkit/latest/promkit/preset/json/struct.Json.html Implementation of the Prompt trait for the Json struct, defining methods for initialization, event evaluation, finalization, and running the prompt. ```APIDOC ### impl Prompt for Json #### type Return = () The type of the result produced by the renderer. #### fn initialize<'life0, 'async_trait>( &'life0 mut self, ) -> Pin> + Send + 'async_trait>> Initializes the handler, preparing it for use. This method is called before the prompt starts running. #### fn evaluate<'life0, 'life1, 'async_trait>( &'life0 mut self, event: &'life1 Event, ) -> Pin> + Send + 'async_trait>> Evaluates an event and determines the next action for the prompt. #### fn finalize(&mut self) -> Result Finalizes the prompt and produces a result. #### fn run<'life0, 'async_trait>( &'life0 mut self, ) -> Pin> + Send + 'async_trait>> Runs the prompt, handling events and producing a result. ``` -------------------------------- ### Configure Listbox Display Lines Source: https://docs.rs/promkit/latest/src/promkit/preset/listbox.rs.html Sets the number of lines to be used for displaying the selectable list within the listbox. ```rust pub fn listbox_lines(mut self, lines: usize) -> Self { self.listbox.config.lines = Some(lines); self } ``` -------------------------------- ### QuerySelector Initialization with Graphemes Source: https://docs.rs/promkit/latest/src/promkit/preset/query_selector.rs.html Initializes the renderer for the QuerySelector, creating graphemes for title, readline, and list components. This is part of the `initialize` method for the `Prompt` trait. ```rust let size = crossterm::terminal::size()?; self.renderer = Some(SharedRenderer::new( Renderer::try_new_with_graphemes( [ (Index::Title, self.title.create_graphemes(size.0, size.1)), ( Index::Readline, self.readline.create_graphemes(size.0, size.1), ), (Index::List, self.list.create_graphemes(size.0, size.1)), ], true, ) .await?, )); Ok(()) ``` -------------------------------- ### Tree::new Source: https://docs.rs/promkit/latest/promkit/preset/tree/struct.Tree.html Creates a new `Tree` instance with the specified root node. ```APIDOC ## Tree::new ### Description Creates a new `Tree` instance with the specified root node. ### Signature ```rust pub fn new(root: Node) -> Self ``` ``` -------------------------------- ### Default Key Bindings Source: https://docs.rs/promkit/latest/promkit/preset/readline/evaluate/fn.readline.html A table outlining the default key bindings and their corresponding actions within the readline editor. ```APIDOC ## Default Key Bindings Key| Action ---|--- `Enter`| Exit the editor if input is valid, otherwise show error message `Ctrl + C`| Interrupt the current operation `←`| Move the cursor one character to the left `→`| Move the cursor one character to the right `Ctrl + A`| Move the cursor to the start of the line `Ctrl + E`| Move the cursor to the end of the line `↑`| Recall the previous entry from history `↓`| Recall the next entry from history `Backspace`| Delete the character before the cursor `Ctrl + U`| Delete all characters in the current line `Tab`| Autocomplete the current input based on available suggestions `Alt + B`| Move the cursor to the previous nearest character within set (default: whitespace) `Alt + F`| Move the cursor to the next nearest character within set (default: whitespace) `Ctrl + W`| Erase to the previous nearest character within set (default: whitespace) `Alt + D`| Erase to the next nearest character within set (default: whitespace) ``` -------------------------------- ### Set Readline Prefix Source: https://docs.rs/promkit/latest/src/promkit/preset/readline.rs.html Sets the prefix string displayed before the input text. This is often used to indicate the prompt, e.g., '> '. ```rust pub fn prefix>(mut self, prefix: T) -> Self { self.readline.config.prefix = prefix.as_ref().to_string(); self } ``` -------------------------------- ### Enable History Functionality Source: https://docs.rs/promkit/latest/promkit/preset/readline/struct.Readline.html Enables history functionality for the Readline prompt, allowing navigation through previous inputs. ```rust pub fn enable_history(self) -> Self ``` -------------------------------- ### Type Conversion Implementations Source: https://docs.rs/promkit/latest/promkit/preset/listbox/struct.Listbox.html Details the `TryFrom` and `TryInto` trait implementations for type conversions. ```APIDOC ### impl TryFrom for T #### type Error = Infallible ### Description The type returned in the event of a conversion error. #### fn try_from(value: U) -> Result>::Error> ### Description Performs the conversion from type U to type T. ### Method try_from ### Parameters #### Path Parameters - **value** (U) - Required - The value to convert. ### Response #### Success Response (Result>::Error>) - **Result>::Error>** - The result of the conversion, either the converted value or an error. ### impl TryInto for T #### type Error = >::Error ### Description The type returned in the event of a conversion error. #### fn try_into(self) -> Result>::Error> ### Description Performs the conversion from type T to type U. ### Method try_into ### Parameters #### Path Parameters - **self** (T) - Required - The value to convert. ### Response #### Success Response (Result>::Error>) - **Result>::Error>** - The result of the conversion, either the converted value or an error. ``` -------------------------------- ### Query Selector Configuration Source: https://docs.rs/promkit/latest/src/promkit/preset/query_selector.rs.html This section details the methods available to configure the Query Selector component, including setting titles, styles, prefixes, and listbox behaviors. ```APIDOC ## Query Selector Configuration Methods This document outlines the various methods available to customize the appearance and behavior of the Query Selector. ### Methods - `title>(mut self, text: T) -> Self` Sets the title text displayed above the query selection. - `title_style(mut self, style: ContentStyle) -> Self` Sets the style for the title text. - `prefix>(mut self, prefix: T) -> Self` Sets the prefix string displayed before the input text in the text editor component. - `prefix_style(mut self, style: ContentStyle) -> Self` Sets the style for the prefix string in the text editor component. - `active_char_style(mut self, style: ContentStyle) -> Self` Sets the style for the active character (the character at the cursor position) in the text editor component. - `inactive_char_style(mut self, style: ContentStyle) -> Self` Sets the style for inactive characters (characters not at the cursor position) in the text editor component. - `edit_mode(mut self, mode: Mode) -> Self` Sets the editing mode for the text editor component. - `text_editor_lines(mut self, lines: usize) -> Self` Sets the number of lines available for the text editor component. - `cursor>(mut self, cursor: T) -> Self` Sets the cursor symbol used in the list box component. - `active_item_style(mut self, style: ContentStyle) -> Self` Sets the style for active (currently selected) items in the list box component. - `inactive_item_style(mut self, style: ContentStyle) -> Self` Sets the style for inactive (not currently selected) items in the list box component. - `listbox_lines(mut self, lines: usize) -> Self` Sets the number of lines available for the list box component. - `evaluator(mut self, evaluator: Evaluator) -> Self` Sets the evaluator function for the text prompt. - `render(mut self, width: usize, height: usize) -> Self` Render the prompt with the specified width and height. ``` -------------------------------- ### QuerySelector Prompt Implementation Source: https://docs.rs/promkit/latest/promkit/preset/query_selector/struct.QuerySelector.html Implementation of the Prompt trait for QuerySelector. ```APIDOC ## QuerySelector Prompt Implementation ### `Return` Type The type of the result produced by the renderer. ### `initialize` Initializes the handler, preparing it for use. This method is called before the prompt starts running. ### `evaluate` Evaluates an event and determines the next action for the prompt. ### `finalize` Finalizes the prompt and produces a result. ### `run` Runs the prompt, handling events and producing a result. ``` -------------------------------- ### Tree Type Conversions (TryFrom) Source: https://docs.rs/promkit/latest/promkit/preset/tree/struct.Tree.html Implements `TryFrom` for the Tree structure, allowing fallible conversions from one type to another. ```APIDOC ## impl TryFrom for T ### Description Provides a fallible conversion from type `U` into type `T`. ### Associated Types - `type Error = Infallible`: The type returned in the event of a conversion error. In this case, `Infallible` indicates that conversion errors are not expected. ### Methods - `fn try_from(value: U) -> Result>::Error>`: Performs the conversion from `value` of type `U` to type `T`. ``` -------------------------------- ### Clone To Uninit Method (Nightly) Source: https://docs.rs/promkit/latest/promkit/suggest/struct.Suggest.html An experimental nightly-only API for performing copy-assignment from self to an uninitialized destination. ```rust unsafe fn clone_to_uninit(&self, dest: *mut u8) ``` -------------------------------- ### Add promkit to Cargo.toml Source: https://docs.rs/promkit/latest/promkit/index.html Include the promkit crate in your project's dependencies by adding this to your Cargo.toml file. ```toml [dependencies] promkit = "0.12.1" ``` -------------------------------- ### Suggest Unit Test Source: https://docs.rs/promkit/latest/src/promkit/suggest.rs.html Tests the `prefix_search` functionality of the `Suggest` struct by inserting several words into a trie and verifying that a prefix search returns the expected subset of words. ```rust #[cfg(test)] mod tests { use super::*; mod suggest { use super::*; #[test] fn test() { let mut trie = Trie::new(); trie.insert("apple".to_string(), 1); trie.insert("applet".to_string(), 1); trie.insert("application".to_string(), 1); trie.insert("banana".to_string(), 1); let suggest = Suggest(trie); let ret = suggest.prefix_search("app").unwrap(); let expected: Vec = vec!["apple", "applet", "application"] .into_iter() .map(String::from) .collect(); assert_eq!(ret, expected); } } } ``` -------------------------------- ### Readline Prompt Behavior Source: https://docs.rs/promkit/latest/promkit/preset/readline/struct.Readline.html Details on how the Readline prompt behaves during execution, including initialization, event evaluation, and finalization. ```APIDOC ## Readline Prompt Trait Implementations This section covers the implementations of the `Prompt` trait for the `Readline` struct, defining its runtime behavior. ### `impl Prompt for Readline` #### `type Return = String` The type of the result produced by the prompt. #### `fn initialize<'life0, 'async_trait>(&'life0 mut self) -> Pin> + Send + 'async_trait>>` Initializes the prompt, preparing it for execution. This is called before the prompt starts running. #### `fn evaluate<'life0, 'life1, 'async_trait>(&'life0 mut self, event: &'life1 Event) -> Pin> + Send + 'async_trait>>` Evaluates an incoming event and determines the next action for the prompt. #### `fn finalize(&mut self) -> Result` Finalizes the prompt execution and returns the collected result. #### `fn run<'life0, 'async_trait>(&'life0 mut self) -> Pin> + Send + 'async_trait>>` Executes the prompt, handling all events and interactions until completion, and returns the final result. ``` -------------------------------- ### Create New Json Preset Source: https://docs.rs/promkit/latest/promkit/preset/json/struct.Json.html Creates a new Json preset instance with the provided JSON stream. ```rust pub fn new(stream: JsonStream) -> Self> ``` -------------------------------- ### Running the Password Prompt Source: https://docs.rs/promkit/latest/src/promkit/preset/password.rs.html Executes the password prompt, allowing the user to enter their password securely. The input is masked, and upon completion, the entered password string is returned. This method handles the asynchronous execution of the prompt. ```rust /// Runs the password prompt, allowing the user to input a password. pub async fn run(&mut self) -> anyhow::Result { self.0.run().await } } ``` -------------------------------- ### FromIterator Implementation for Suggest Source: https://docs.rs/promkit/latest/src/promkit/suggest.rs.html Enables creating a `Suggest` instance from any iterator of displayable items. Each item is converted to a string and inserted into the trie. ```rust impl FromIterator for Suggest { /// Constructs a `Suggest` instance from an iterator of displayable items. /// Each item is inserted into the trie with a default value to facilitate /// quick prefix-based searches. /// /// # Arguments /// /// * `iter` - An iterator over items that implement the `Display` trait. fn from_iter>(iter: I) -> Self { Suggest(Trie::from_iter( iter.into_iter().map(|e| (format!("{}", e), 1)), )) } } ``` -------------------------------- ### Clone From Implementation for Suggest Source: https://docs.rs/promkit/latest/promkit/suggest/struct.Suggest.html Enables performing copy-assignment from a source Suggest instance to a mutable instance. ```rust fn clone_from(&mut self, source: &Self) ``` -------------------------------- ### From and Into Source: https://docs.rs/promkit/latest/promkit/preset/readline/struct.Readline.html Facilitates conversions between types. `From` allows creating a type from another type `T`, while `Into` allows converting the current type into another type `U` if `U` implements `From`. ```APIDOC ## `fn from(t: T) -> T` ### Description Returns the argument unchanged. ### Method `from` ### Parameters - `t` (T): The value to convert from. ### Returns - `T`: The unchanged input value. ``` ```APIDOC ## `fn into(self) -> U` ### Description Calls `U::from(self)`. This conversion is determined by the `From for U` implementation. ### Method `into` ### Parameters - `self`: The value to convert. ### Returns - `U`: The converted value. ```