Skip to main content

Crate huh

Crate huh 

Source
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.
ConfirmKeyMap
Keybindings for confirm fields.
FieldPosition
Positional information about a field within a form.
FieldStyles
Styles for input fields.
FilePicker
A file picker field for selecting files and directories.
FilePickerKeyMap
Keybindings for file picker fields.
Form
A form containing multiple groups of fields.
FormStyles
Styles for the form container.
Group
A group of fields displayed together.
GroupStyles
Styles for groups.
Input
A text input field.
InputKeyMap
Keybindings for input fields.
KeyMap
Keybindings for form navigation.
LayoutColumns
Columns layout - distributes groups across columns.
LayoutDefault
Default layout - shows one group at a time.
LayoutGrid
Grid layout - arranges groups in a fixed grid pattern.
LayoutStack
Stack layout - shows all groups stacked vertically.
MultiSelect
A multi-select field for choosing multiple options from a list.
MultiSelectKeyMap
Keybindings for multi-select fields.
NextFieldMsg
Message to move to the next field.
NextGroupMsg
Message to move to the next group.
Note
A non-interactive note/text display field.
NoteKeyMap
Keybindings for note fields.
PrevFieldMsg
Message to move to the previous field.
PrevGroupMsg
Message to move to the previous group.
Select
A select field for choosing one option from a list.
SelectKeyMap
Keybindings for select fields.
SelectOption
An option for select fields.
Text
A multi-line text area field.
TextInputStyles
Styles for text inputs.
TextKeyMap
Keybindings for text area fields.
Theme
Collection of styles for form components.
UpdateFieldMsg
Message to update dynamic field content.

Enums§

EchoMode
Echo mode for input fields.
FormError
Errors that can occur during form execution.
FormState
The current state of the form.

Traits§

Field
A form field.
Layout
Layout determines how groups are arranged within a form.

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.

Type Aliases§

Result
A specialized Result type for huh form operations.