Expand description
§Huh
A library for building interactive forms and prompts in the terminal.
Huh provides a declarative way to create:
- Text inputs and text areas
- Select menus and multi-select
- Confirmations and notes
- Grouped form fields
- Accessible, keyboard-navigable interfaces
§Role in charmed_rust
Huh is the form and prompt layer built on bubbletea and bubbles:
- bubbletea provides the runtime and update loop.
- bubbles supplies reusable widgets (text input, list, etc.).
- lipgloss handles consistent styling and themes.
- demo_showcase uses huh to demonstrate multi-step workflows.
§Example
ⓘ
use huh::{Form, Group, Input, Select, SelectOption, Confirm};
use bubbletea::Program;
let form = Form::new(vec![
Group::new(vec![
Box::new(Input::new()
.key("name")
.title("What's your name?")),
Box::new(Select::new()
.key("color")
.title("Favorite color?")
.options(vec![
SelectOption::new("Red", "red"),
SelectOption::new("Green", "green"),
SelectOption::new("Blue", "blue"),
])),
]),
Group::new(vec![
Box::new(Confirm::new()
.key("confirm")
.title("Are you sure?")),
]),
]);
let form = Program::new(form).run()?;
let name = form.get_string("name").unwrap();
let color = form.get_string("color").unwrap();
let confirm = form.get_bool("confirm").unwrap();
println!("Name: {}, Color: {}, Confirmed: {}", name, color, confirm);Structs§
- Confirm
- A confirmation field with Yes/No options.
- Confirm
KeyMap - Keybindings for confirm fields.
- Field
Position - Positional information about a field within a form.
- Field
Styles - Styles for input fields.
- File
Picker - A file picker field for selecting files and directories.
- File
Picker KeyMap - Keybindings for file picker fields.
- Form
- A form containing multiple groups of fields.
- Form
Styles - Styles for the form container.
- Group
- A group of fields displayed together.
- Group
Styles - Styles for groups.
- Input
- A text input field.
- Input
KeyMap - Keybindings for input fields.
- KeyMap
- Keybindings for form navigation.
- Layout
Columns - Columns layout - distributes groups across columns.
- Layout
Default - Default layout - shows one group at a time.
- Layout
Grid - Grid layout - arranges groups in a fixed grid pattern.
- Layout
Stack - Stack layout - shows all groups stacked vertically.
- Multi
Select - A multi-select field for choosing multiple options from a list.
- Multi
Select KeyMap - Keybindings for multi-select fields.
- Next
Field Msg - Message to move to the next field.
- Next
Group Msg - Message to move to the next group.
- Note
- A non-interactive note/text display field.
- Note
KeyMap - Keybindings for note fields.
- Prev
Field Msg - Message to move to the previous field.
- Prev
Group Msg - Message to move to the previous group.
- Select
- A select field for choosing one option from a list.
- Select
KeyMap - Keybindings for select fields.
- Select
Option - An option for select fields.
- Text
- A multi-line text area field.
- Text
Input Styles - Styles for text inputs.
- Text
KeyMap - Keybindings for text area fields.
- Theme
- Collection of styles for form components.
- Update
Field Msg - Message to update dynamic field content.
Enums§
- Echo
Mode - Echo mode for input fields.
- Form
Error - Errors that can occur during form execution.
- Form
State - The current state of the form.
Traits§
Functions§
- new_
options - Creates options from string values.
- theme_
base - Returns the base theme.
- theme_
base16 - Returns the Base16 theme.
- theme_
catppuccin - Returns the Catppuccin theme.
- theme_
charm - Returns the Charm theme (default).
- theme_
dracula - Returns the Dracula theme.
- validate_
email - Creates a validator for email format. Uses a simple regex pattern to validate email addresses.
- validate_
min_ length_ 8 - Creates a min length validator for password fields. Note: Due to Rust’s function pointer limitations, this returns a closure that can be converted to a function pointer.
- validate_
required - Creates a validator that checks if the input is not empty.
- validate_
required_ name - Creates a required validator for the “name” field.