### Create a User Setup Wizard Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/quick-start.md A complete example demonstrating form initialization, input validation, and group management. ```go package main import ( "errors" "fmt" "log" "strings" "charm.land/huh/v2" ) func main() { var ( username string email string password string subscribe bool ) form := huh.NewForm( huh.NewGroup( huh.NewNote(). Title("Setup Wizard"). Description("Create your account"). Next(true), ), huh.NewGroup( huh.NewInput(). Title("Username"). Validate(huh.ValidateLength(3, 20)). Value(&username), huh.NewInput(). Title("Email"). Placeholder("user@example.com"). Validate(func(s string) error { if !strings.Contains(s, "@") { return errors.New("invalid email") } return nil }). Value(&email), huh.NewInput(). Title("Password"). Password(true). Validate(huh.ValidateMinLength(8)). Value(&password), ), huh.NewGroup( huh.NewConfirm(). Title("Subscribe to updates?"). Value(&subscribe), ), ) if err := form.Run(); err != nil { log.Fatal(err) } fmt.Printf("User created: %s (%s)\n", username, email) if subscribe { fmt.Println("Subscribed to updates") } } ``` -------------------------------- ### Confirm Field Usage Example Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/api-reference/confirm.md Example demonstrating how to configure and run a confirm field. ```go var deleteFile bool huh.NewConfirm(). Title("Are you sure?"). Affirmative("Delete"). Negative("Cancel"). Value(&deleteFile). Run() ``` -------------------------------- ### Configure CurrentDirectory Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/api-reference/filepicker.md Sets the starting directory for the file picker. ```go func (f *FilePicker) CurrentDirectory(directory string) *FilePicker ``` ```go picker.CurrentDirectory("/home/user/Downloads") ``` -------------------------------- ### Run FilePicker Example Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/api-reference/filepicker.md Basic implementation showing how to initialize, configure, and execute a file picker. ```go var selectedFile string huh.NewFilePicker(). Title("Choose a file"). Value(&selectedFile). Run() ``` -------------------------------- ### Basic Spinner Execution Example Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/api-reference/spinner.md Demonstrates running a spinner with a title and an action that returns an error. ```go if err := spinner.New(). Title("Downloading..."). ActionWithErr(func(ctx context.Context) error { return download(ctx) }). Run(); err != nil { log.Fatal(err) } ``` -------------------------------- ### Initialize Typed Select Fields Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/INDEX.md Examples of initializing select fields with different underlying types. ```go huh.NewSelect[string]() // Strings huh.NewSelect[int]() // Integers huh.NewSelect[UserRole]() // Custom enum-like types ``` -------------------------------- ### Example usage of Note field Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/api-reference/note.md Demonstrates chaining configuration methods to set up a note with a title, description, and navigation. ```go huh.NewNote(). Title("Welcome"). Description("This is an informational note."). Next(true). NextLabel("Continue") ``` -------------------------------- ### Configure MultiSelect Field Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/api-reference/multiselect.md Example showing the initialization and configuration of a multi-select field with options and a selection limit. ```go var toppings []string huh.NewMultiSelect[string](). Title("Choose toppings"). Options( huh.NewOption("Lettuce", "lettuce").Selected(true), huh.NewOption("Cheese", "cheese"), ). Limit(4). Value(&toppings). Run() ``` -------------------------------- ### Run an Input field Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/api-reference/input.md Example of configuring and executing an input field to collect a user's name. ```go var name string huh.NewInput(). Title("What's your name?"). Value(&name). Run() ``` -------------------------------- ### Implement Multi-Step Wizard Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/advanced-topics.md Create complex forms with multiple groups and conditional visibility logic to guide users through a sequence of steps. ```go type WizardStep int const ( StepWelcome WizardStep = iota StepUserInfo StepProductChoice StepPayment StepConfirmation ) func runWizard() error { var ( name string product string method string ) // Each step can show different fields based on previous choices form := huh.NewForm( // Welcome step huh.NewGroup( huh.NewNote(). Title("Welcome"). Description("This wizard will guide you through setup."). Next(true), ), // User info step huh.NewGroup( huh.NewInput().Title("Name").Value(&name), ), // Product selection step huh.NewGroup( huh.NewSelect[string](). Title("Product"). Options(huh.NewOptions("Basic", "Pro", "Enterprise")...). Value(&product), ), // Payment step (only for Pro/Enterprise) huh.NewGroup( huh.NewSelect[string](). Title("Payment Method"). Options(huh.NewOptions("Credit Card", "Bank Transfer")...). Value(&method), ).WithHideFunc(func() bool { return product == "Basic" }), // Confirmation step huh.NewGroup( huh.NewNote(). Title("Review"). Description(func() string { return fmt.Sprintf("Name: %s\nProduct: %s\nMethod: %s", name, product, method) }()). Next(true), ), ) return form.Run() } ``` -------------------------------- ### Implement FilePicker Field Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/quick-start.md Enables file or directory selection starting from a specified path. ```go var filepath string huh.NewFilePicker(). Title("Choose a file"). CurrentDirectory("/home/user"). Value(&filepath) ``` -------------------------------- ### Select Field Usage Example Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/api-reference/select.md Basic implementation of a select field with static options and value binding. ```go var country string huh.NewSelect[string](). Title("Choose a country"). Options( huh.NewOption("United States", "US"), huh.NewOption("Canada", "CA"), ). Value(&country). Run() ``` -------------------------------- ### Example usage of Text field Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/api-reference/text.md Demonstrates creating a text field, setting a title, character limit, and binding to a variable. ```go var bio string huh.NewText(). Title("Tell us about yourself"). CharLimit(500). Value(&bio). Run() ``` -------------------------------- ### Common Validation Patterns Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/errors.md Examples of length, custom, multi-select, and confirmation validation logic. ```go // Length validation huh.NewInput().Validate(huh.ValidateLength(3, 50)) // Custom validation huh.NewInput().Validate(func(s string) error { if !isValidEmail(s) { return errors.New("invalid email format") } return nil }) // MultiSelect validation huh.NewMultiSelect[string]().Validate(func(items []string) error { if len(items) == 0 { return errors.New("at least one selection required") } return nil }) // Confirm validation huh.NewConfirm().Validate(func(b bool) error { if !b { return errors.New("you must agree to continue") } return nil }) ``` -------------------------------- ### Set picking mode Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/api-reference/filepicker.md Configures whether the file picker starts in picking mode. ```go func (f *FilePicker) Picking(v bool) *FilePicker ``` -------------------------------- ### Get Selected Value Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/api-reference/filepicker.md Returns the currently selected file path. ```go func (f *FilePicker) GetValue() any ``` -------------------------------- ### Apply Validation Helpers to Inputs in Go Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/errors.md Examples of applying various validation helpers to input and selection fields. ```go // Username: 3-20 characters huh.NewInput(). Title("Username"). Validate(huh.ValidateLength(3, 20)). Value(&username) // Password: minimum 8 characters huh.NewInput(). Title("Password"). Password(true). Validate(huh.ValidateMinLength(8)). Value(&password) // Status: must be one of specific values huh.NewInput(). Title("Status"). Validate(huh.ValidateOneOf("active", "inactive", "pending")). Value(&status) // At least one selection required huh.NewMultiSelect[string](). Title("Features"). Options(huh.NewOptions("A", "B", "C")...). Validate(func(items []string) error { if len(items) == 0 { return errors.New("select at least one feature") } return nil }). Value(&selected) ``` -------------------------------- ### Import Huh Library and Define Variables Source: https://github.com/charmbracelet/huh/blob/main/README.md Import the huh library and declare variables to store form answers. This is the initial setup for creating a form. ```go package main import "charm.land/huh/v2" var ( burger string toppings []string sauceLevel int name string instructions string discount bool ) ``` -------------------------------- ### Apply Validation to Input Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/configuration.md Example of applying a length validator to an input field. ```go huh.NewInput(). Title("Username"). Validate(huh.ValidateLength(3, 20)) ``` -------------------------------- ### Configure a FilePicker field in Go Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/configuration.md Initializes a file picker starting in a specific directory with hidden files enabled. ```go huh.NewFilePicker(). Title("Config file"). CurrentDirectory("/etc"). ShowHidden(true). Value(&configPath) ``` -------------------------------- ### Handle Form Execution Errors Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/api-reference/form.md Example of checking for user cancellation during form execution. ```go if err := form.Run(); err != nil { if errors.Is(err, huh.ErrUserAborted) { fmt.Println("User cancelled") } } ``` -------------------------------- ### Picking(v bool) *FilePicker Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/api-reference/filepicker.md Sets whether the file picker should start in picking mode. ```APIDOC ## Picking(v bool) *FilePicker ### Description Sets whether the file picker should start in picking mode. ### Parameters - **v** (bool) - Required - Start in picking mode (Default: false) ### Returns - *FilePicker - The field receiver for method chaining ``` -------------------------------- ### Initialize and Run a Form Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/api-reference/form.md Demonstrates creating a form with a group and input field, then executing it. ```go form := huh.NewForm( huh.NewGroup( huh.NewInput().Title("Name").Value(&name), ), ) err := form.Run() ``` -------------------------------- ### Filtering Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/api-reference/select.md Sets whether the select field starts in filtering mode. ```APIDOC ## func (s *Select[T]) Filtering(filtering bool) *Select[T] ### Description Sets whether the select field starts in filtering mode. ### Parameters - **filtering** (bool) - Required - Enable/disable filtering ### Returns - ***Select[T]** - The field receiver for method chaining ``` -------------------------------- ### Get Field Key Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/api-reference/select.md Retrieves the unique identifier for the select field. ```go func (s *Select[T]) GetKey() string ``` -------------------------------- ### Get MultiSelect field key Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/api-reference/multiselect.md Retrieves the unique string identifier for the field. ```go func (m *MultiSelect[T]) GetKey() string ``` -------------------------------- ### Get Field Key Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/api-reference/filepicker.md Returns the unique identifier for the file picker field. ```go func (f *FilePicker) GetKey() string ``` -------------------------------- ### Update Go Dependencies for Huh v2 Source: https://github.com/charmbracelet/huh/blob/main/UPGRADE_GUIDE_V2.md Use 'go get' to update your go.mod file with the latest versions of Huh and related Charm libraries. ```bash go get charm.land/huh/v2@latest go get charm.land/bubbletea/v2@latest go get charm.land/lipgloss/v2@latest go get charm.land/bubbles/v2@latest ``` -------------------------------- ### Get Selected Value Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/api-reference/select.md Retrieves the currently selected value of type T. ```go func (s *Select[T]) GetValue() any ``` -------------------------------- ### Get Validation Error Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/api-reference/select.md Retrieves the last validation error encountered by the field. ```go func (s *Select[T]) Error() error ``` -------------------------------- ### Initialize a new Note field Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/api-reference/note.md Constructor for creating a new Note instance. ```go func NewNote() *Note ``` -------------------------------- ### Configure a Select field in Go Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/configuration.md Shows how to create a select field with static options, a defined height, and value binding. ```go huh.NewSelect[string](). Title("Country"). Options( huh.NewOption("USA", "us"), huh.NewOption("Canada", "ca"), ). Height(5). Value(&country) ``` -------------------------------- ### Initialize a new Text field Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/api-reference/text.md Creates a new text field instance. ```go func NewText() *Text ``` -------------------------------- ### Get Focused Field Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/api-reference/form.md Retrieves the currently focused field, or nil if no field is focused. ```go func (f *Form) GetFocusedField() Field ``` -------------------------------- ### Get field key Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/api-reference/confirm.md Retrieves the unique identifier string associated with the confirm field. ```go func (c *Confirm) GetKey() string ``` -------------------------------- ### Create a Basic Form Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/README.md Constructs a multi-field form using groups and executes it. ```go form := huh.NewForm( huh.NewGroup( huh.NewInput().Title("Name").Value(&name), ), ) form.Run() ``` -------------------------------- ### Create a new Spinner Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/api-reference/spinner.md Initializes a new spinner instance with default settings. ```go func New() *Spinner ``` -------------------------------- ### Get Note value Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/api-reference/note.md Retrieves the value associated with the note field, which is always nil. ```go func (n *Note) GetValue() any ``` -------------------------------- ### Configure ShowSize Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/api-reference/filepicker.md Toggles the display of file sizes. ```go func (f *FilePicker) ShowSize(v bool) *FilePicker ``` -------------------------------- ### Initialize FilePicker Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/api-reference/filepicker.md Constructor for creating a new FilePicker instance. ```go func NewFilePicker() *FilePicker ``` -------------------------------- ### Configure an Input field in Go Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/configuration.md Demonstrates setting a title, placeholder, character limit, value binding, and custom validation for an input field. ```go huh.NewInput(). Title("Email"). Placeholder("name@example.com"). CharLimit(255). Value(&email). Validate(func(s string) error { if !strings.Contains(s, "@") { return errors.New("invalid email") } return nil }) ``` -------------------------------- ### Create a new Input field Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/api-reference/input.md Initializes a new input field instance. ```go func NewInput() *Input ``` -------------------------------- ### Get MultiSelect selected values Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/api-reference/multiselect.md Returns the currently selected values as a slice of type T. ```go func (m *MultiSelect[T]) GetValue() any ``` -------------------------------- ### Run file picker Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/api-reference/filepicker.md Executes the file picker as a standalone form. ```go func (f *FilePicker) Run() error ``` ```go var configFile string if err := huh.NewFilePicker(). Title("Select config file"). CurrentDirectory("/etc"). Value(&configFile). Run(); err != nil { log.Fatal(err) } ``` -------------------------------- ### Get FilePicker Error Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/api-reference/filepicker.md Retrieves the last validation error, returning nil if the field is valid. ```go func (f *FilePicker) Error() error ``` -------------------------------- ### Implement Note Field Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/quick-start.md Displays informational text to the user with a navigation button. ```go huh.NewNote(). Title("Welcome"). Description("This form will collect your preferences."). Next(true). NextLabel("Continue") ``` -------------------------------- ### Get Note key identifier Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/api-reference/note.md Retrieves the key identifier for the note field, which is typically empty. ```go func (n *Note) GetKey() string ``` -------------------------------- ### Define complex conditional logic Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/advanced-topics.md Example of a multi-condition hide function for granular control over field visibility. ```go .WithHideFunc(func() bool { // Show only if department is Engineering AND title contains Manager return department != "Engineering" || !strings.Contains(jobTitle, "Manager") }) ``` -------------------------------- ### Configure Value Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/api-reference/filepicker.md Binds a pointer to a string variable to store the selected path. ```go func (f *FilePicker) Value(value *string) *FilePicker ``` -------------------------------- ### Run a Spinner with an action Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/api-reference/spinner.md Executes a task while displaying a loading spinner. ```go err := spinner.New(). Title("Loading..."). Action(func() { time.Sleep(2 * time.Second) }). Run() ``` -------------------------------- ### Create a simple single-field prompt Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/INDEX.md Use this pattern for basic user input collection. ```go var name string huh.NewInput().Title("Name").Value(&name).Run() ``` -------------------------------- ### func (f *Form) Get(key string) any Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/api-reference/form.md Returns a result value by key from the form results. ```APIDOC ## func (f *Form) Get(key string) any ### Description Returns a result value by key from the form results. ### Parameters - **key** (string) - Required - The field key to retrieve ### Returns - **any** - The field value, or nil if not found ``` -------------------------------- ### Configure form layout and help display Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/configuration.md Adjusts the visual arrangement of groups and toggles the visibility of keybinding help. ```go form.WithLayout(huh.LayoutColumns(2)) form.WithShowHelp(false) ``` -------------------------------- ### Initialize Select Field Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/api-reference/select.md Constructor for creating a new select field instance. ```go func NewSelect[T comparable]() *Select[T] ``` -------------------------------- ### Configure Form I/O Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/api-reference/form.md Sets the input reader or output writer for the form. ```go func (f *Form) WithOutput(w io.Writer) *Form ``` ```go func (f *Form) WithInput(r io.Reader) *Form ``` -------------------------------- ### WithTheme Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/api-reference/filepicker.md Sets the theme for the file picker field. ```APIDOC ## func (f *FilePicker) WithTheme(theme Theme) *FilePicker ### Description Sets the theme for the file picker field. ### Parameters - **theme** (Theme) - Required - Theme implementation ### Returns - ***FilePicker** - The field receiver for method chaining ``` -------------------------------- ### Get field value Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/api-reference/confirm.md Returns the current boolean state of the confirm field, where true represents affirmative and false represents negative. ```go func (c *Confirm) GetValue() any ``` -------------------------------- ### Configure Note Field Options Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/configuration.md Sets the title, description, and next button behavior for a note field. ```go huh.NewNote(). Title("Welcome"). Description("This is a welcome message."). Next(true). NextLabel("Start") ``` -------------------------------- ### Set Select Theme Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/api-reference/select.md Configures the visual theme for the select field. ```go func (s *Select[T]) WithTheme(theme Theme) *Select[T] ``` -------------------------------- ### Get Field Width with Width() Method Source: https://github.com/charmbracelet/huh/blob/main/UPGRADE_GUIDE_V2.md Select and MultiSelect fields now provide a Width() method to retrieve the field's current width. ```go width := multiSelect.Width() ``` -------------------------------- ### Option[T] methods Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/types.md Methods for configuring and stringifying options. ```go func (o Option[T]) Selected(selected bool) Option[T] func (o Option[T]) String() string ``` -------------------------------- ### Create a text field Source: https://github.com/charmbracelet/huh/blob/main/README.md Prompt the user for multiple lines of text. ```go huh.NewText(). Title("Tell me a story."). Validate(checkForPlagiarism). Value(&story) ``` -------------------------------- ### Initialize Confirm Field Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/api-reference/confirm.md Constructor for creating a new confirm field instance. ```go func NewConfirm() *Confirm ``` -------------------------------- ### New() Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/api-reference/spinner.md Creates a new spinner instance with default settings. ```APIDOC ## func New() ### Description Creates a new spinner instance with default settings. ### Returns *Spinner - A new spinner instance. ``` -------------------------------- ### Configure Title Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/api-reference/filepicker.md Sets the display title for the file picker. ```go func (f *FilePicker) Title(title string) *FilePicker ``` -------------------------------- ### Configure a Text field in Go Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/configuration.md Sets up a text field with a character limit and a specific external editor command. ```go huh.NewText(). Title("Biography"). CharLimit(1000). Editor("vim"). Value(&bio) ``` -------------------------------- ### Set Input Suggestions Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/api-reference/input.md Sets static suggestions displayed while typing. ```go func (i *Input) Suggestions(suggestions []string) *Input ``` -------------------------------- ### Configure Description Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/api-reference/filepicker.md Sets the descriptive text shown below the title. ```go func (f *FilePicker) Description(description string) *FilePicker ``` -------------------------------- ### Run the Form Source: https://github.com/charmbracelet/huh/blob/main/README.md Execute the form and handle any potential errors during its run. ```go err := form.Run() if err != nil { log.Fatal(err) } ``` -------------------------------- ### Configure Note description Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/api-reference/note.md Methods for setting static or dynamic descriptive content, supporting markdown. ```go func (n *Note) Description(description string) *Note ``` ```go note.Description("This form will ask for your **personal information**.\n\nPlease ensure accuracy.") ``` ```go func (n *Note) DescriptionFunc(f func() string, bindings any) *Note ``` -------------------------------- ### Configure dynamic Text field placeholder Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/api-reference/text.md Sets a dynamic placeholder that recomputes when bindings change. ```go func (t *Text) PlaceholderFunc(f func() string, bindings any) *Text ``` -------------------------------- ### Configure Form KeyMap Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/api-reference/form.md Sets custom keybindings for navigation and field interactions. ```go func (f *Form) WithKeyMap(keymap *KeyMap) *Form ``` -------------------------------- ### Configure Note navigation Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/api-reference/note.md Methods for controlling the visibility and label of the next button. ```go func (n *Note) Next(v bool) *Note ``` ```go func (n *Note) NextLabel(label string) *Note ``` -------------------------------- ### Configure Note title Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/api-reference/note.md Methods for setting static or dynamic titles. ```go func (n *Note) Title(title string) *Note ``` ```go func (n *Note) TitleFunc(f func() string, bindings any) *Note ``` -------------------------------- ### Complete Spinner Usage Pattern Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/api-reference/spinner.md Shows a full implementation including context timeout, custom spinner type, and error handling. ```go import ( "context" "time" "charm.land/huh/v2/spinner" ) func main() { ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) defer cancel() err := spinner.New(). Title("Processing..."). Type(spinner.Line). ActionWithErr(func(ctx context.Context) error { // Your long-running task here return processData(ctx) }). Context(ctx). Run() if err != nil { log.Fatal(err) } } ``` -------------------------------- ### Create a multi-step form Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/INDEX.md Group multiple fields together to create a sequential form flow. ```go huh.NewForm( huh.NewGroup(field1, field2), huh.NewGroup(field3, field4), ).Run() ``` -------------------------------- ### Form Constructor Signature Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/api-reference/form.md The constructor for initializing a new form instance. ```go func NewForm(groups ...*Group) *Form ``` -------------------------------- ### Configure form layout for many groups Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/advanced-topics.md Use LayoutDefault to display form groups one at a time, reducing visual clutter. ```go form.WithLayout(huh.LayoutDefault) // Show one at a time ``` -------------------------------- ### Configure Input Styling and Layout Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/api-reference/input.md Methods for customizing the theme, keybindings, and dimensions of the input field. These methods return the receiver for chaining. ```go func (i *Input) WithTheme(theme Theme) *Input ``` ```go func (i *Input) WithKeyMap(keymap *KeyMap) *Input ``` ```go func (i *Input) WithWidth(width int) *Input ``` ```go func (i *Input) WithHeight(height int) *Input ``` -------------------------------- ### Configure form I/O Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/configuration.md Specifies custom input readers and output writers for the form. ```go form.WithInput(os.Stdin) form.WithOutput(os.Stderr) ``` -------------------------------- ### WithTheme Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/api-reference/select.md Sets the theme for the select field. ```APIDOC ## func (s *Select[T]) WithTheme(theme Theme) *Select[T] ### Description Sets the theme for the select field. ### Parameters - **theme** (Theme) - Required - Theme implementation ### Returns - ***Select[T]** - The field receiver for method chaining ``` -------------------------------- ### Implement Text Field Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/quick-start.md Creates a multi-line text input with a character limit. ```go var bio string huh.NewText(). Title("Biography"). CharLimit(500). Value(&bio) ``` -------------------------------- ### Run file picker in accessible mode Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/api-reference/filepicker.md Executes the file picker with support for screen readers using provided reader and writer. ```go func (f *FilePicker) RunAccessible(w io.Writer, r io.Reader) error ``` -------------------------------- ### Update Import Paths from Huh v1 to v2 Source: https://github.com/charmbracelet/huh/blob/main/UPGRADE_GUIDE_V2.md Change your import paths to use the 'charm.land' vanity domain with the '/v2' suffix for Huh and related libraries. ```go // Before import ( "github.com/charmbracelet/huh" "github.com/charmbracelet/huh/spinner" tea "github.com/charmbracelet/bubbletea" "github.com/charmbracelet/lipgloss" "github.com/charmbracelet/bubbles/key" ) // After import ( "charm.land/huh/v2" "charm.land/huh/v2/spinner" tea "charm.land/bubbletea/v2" "charm.land/lipgloss/v2" "charm.land/bubbles/v2/key" ) ``` -------------------------------- ### Set Input Prompt Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/api-reference/input.md Defines the string displayed at the input cursor. ```go func (i *Input) Prompt(prompt string) *Input ``` -------------------------------- ### Configure directory selection Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/api-reference/filepicker.md Sets whether directories can be selected in the file picker. ```go func (f *FilePicker) DirAllowed(v bool) *FilePicker ``` -------------------------------- ### Retrieve Group Help Model Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/api-reference/group.md Returns the help model associated with the group for rendering keybindings. ```go func (g *Group) Help() help.Model ``` -------------------------------- ### Configure ShowHidden Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/api-reference/filepicker.md Toggles the visibility of hidden files. ```go func (f *FilePicker) ShowHidden(v bool) *FilePicker ``` -------------------------------- ### Implement Confirm Field Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/quick-start.md Creates a boolean yes/no confirmation prompt. ```go var confirmed bool huh.NewConfirm(). Title("Are you sure?"). Affirmative("Yes"). Negative("No"). Value(&confirmed) ``` -------------------------------- ### Create an input field Source: https://github.com/charmbracelet/huh/blob/main/README.md Prompt the user for a single line of text with optional validation. ```go huh.NewInput(). Title("What’s for lunch?"). Prompt("?"). Validate(isFood). Value(&lunch) ``` -------------------------------- ### Create a select field Source: https://github.com/charmbracelet/huh/blob/main/README.md Prompt the user to select a single option from a list. ```go huh.NewSelect[string](). Title("Pick a country."). Options( huh.NewOption("United States", "US"), huh.NewOption("Germany", "DE"), huh.NewOption("Brazil", "BR"), huh.NewOption("Canada", "CA"), ). Value(&country) ``` -------------------------------- ### Fetch dynamic options from API Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/advanced-topics.md Uses OptionsFunc to populate select options dynamically. Passing nil as the second argument forces a refresh on every update. ```go var selectedUser string huh.NewSelect[string](). Title("Choose User"). OptionsFunc(func() []huh.Option[string] { // Fetch from API users, err := fetchUsers() if err != nil { return []huh.Option[string]{} // Empty on error } options := make([]huh.Option[string], len(users)) for i, u := range users { options[i] = huh.NewOption(u.Name, u.ID) } return options }, nil). // nil binding = refresh on every update Value(&selectedUser) ``` -------------------------------- ### WithTheme Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/api-reference/text.md Sets the theme for the text field. ```APIDOC ## func (t *Text) WithTheme(theme Theme) *Text ### Description Sets the theme for the text field. ### Parameters - **theme** (Theme) - Required - Theme implementation ### Returns - ***Text** - The field receiver for method chaining ``` -------------------------------- ### Configure ShowPermissions Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/api-reference/filepicker.md Toggles the display of file permissions. ```go func (f *FilePicker) ShowPermissions(v bool) *FilePicker ``` -------------------------------- ### WithKeyMap Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/api-reference/filepicker.md Sets custom keybindings for the file picker field. ```APIDOC ## func (f *FilePicker) WithKeyMap(keymap *KeyMap) *FilePicker ### Description Sets custom keybindings for the file picker field. ### Parameters - **keymap** (*KeyMap) - Required - Keymap with field bindings ### Returns - ***FilePicker** - The field receiver for method chaining ``` -------------------------------- ### Bubble Tea v2 Integration in Huh Field Methods Source: https://github.com/charmbracelet/huh/blob/main/UPGRADE_GUIDE_V2.md Field methods like Blur(), Focus(), and Init() now return 'charm.land/bubbletea/v2.Cmd' instead of 'tea.Cmd'. ```go // Field Methods: // Blur() tea.Cmd (now returns charm.land/bubbletea/v2.Cmd) // Focus() tea.Cmd (now returns charm.land/bubbletea/v2.Cmd) // Init() tea.Cmd (now returns charm.land/bubbletea/v2.Cmd) // Update(tea.Msg) (tea.Model, tea.Cmd) (now uses v2 types) ``` -------------------------------- ### WithShowHelp Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/api-reference/form.md Sets whether help text should be displayed in all groups and fields. ```APIDOC ## func (f *Form) WithShowHelp(v bool) *Form ### Description Sets whether help text should be displayed in all groups and fields. ### Parameters - **v** (bool) - Required - Show/hide help (Default: true) ### Returns - *Form - The form receiver for method chaining ``` -------------------------------- ### Implement Select Field Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/quick-start.md Provides a single-choice selection menu from a list of options. ```go var country string huh.NewSelect[string](). Title("Country"). Options( huh.NewOption("USA", "us"), huh.NewOption("Canada", "ca"), huh.NewOption("Mexico", "mx"), ). Value(&country) ``` -------------------------------- ### Use Correct Theme Signature with `isDark` Parameter Source: https://github.com/charmbracelet/huh/blob/main/UPGRADE_GUIDE_V2.md All built-in themes now require a boolean parameter to indicate if the theme is dark. Pass `true` or `false` accordingly. ```go // ✅ Correct form.WithTheme(huh.ThemeCharm(true)) // ❌ Wrong form.WithTheme(huh.ThemeCharm()) ``` -------------------------------- ### Bubble Tea v2 Integration in Huh Form Methods Source: https://github.com/charmbracelet/huh/blob/main/UPGRADE_GUIDE_V2.md Form methods like Init(), Update(), and WithProgramOptions() have been updated to use Bubble Tea v2 types. ```go // Form Methods: // Init() tea.Cmd (now returns charm.land/bubbletea/v2.Cmd) // Update(tea.Msg) (tea.Model, tea.Cmd) (now uses v2 types) // WithProgramOptions(...tea.ProgramOption) (now uses v2 types) ``` -------------------------------- ### Show a loading indicator Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/INDEX.md Display a spinner while performing background tasks. ```go spinner.New(). Title("Processing..."). ActionWithErr(func(ctx context.Context) error { return doWork(ctx) }). Run() ``` -------------------------------- ### Update Lip Gloss Style Import Path Source: https://github.com/charmbracelet/huh/blob/main/UPGRADE_GUIDE_V2.md Update the import path for Lip Gloss styles from v1 to v2. The API remains largely the same. ```go import "github.com/charmbracelet/lipgloss" style := lipgloss.NewStyle(). Foreground(lipgloss.Color("205")) ``` ```go import "charm.land/lipgloss/v2" style := lipgloss.NewStyle(). Foreground(lipgloss.Color("205")) ``` -------------------------------- ### Configure Select Field Options Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/api-reference/select.md Method to define static options for the selection list. ```go func (s *Select[T]) Options(options ...Option[T]) *Select[T] ``` ```go select.Options( huh.NewOption("Option A", valueA), huh.NewOption("Option B", valueB), ) ``` -------------------------------- ### Handle Form Timeout Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/quick-start.md Configure a timeout duration and check for huh.ErrTimeout to handle expired sessions. ```go form.WithTimeout(30 * time.Second) err := form.Run() if errors.Is(err, huh.ErrTimeout) { fmt.Println("Form timed out after 30 seconds") os.Exit(1) } ``` -------------------------------- ### Resolve ErrTimeoutUnsupported Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/errors.md Alternative configurations to avoid timeout errors in accessible mode. ```go // Option 1: Use timeout without accessible mode form.WithTimeout(30 * time.Second).Run() // Option 2: Use accessible mode without timeout form.WithAccessible(true).Run() // Option 3: Check mode before setting timeout if !accessible { form.WithTimeout(30 * time.Second) } ``` -------------------------------- ### Implement Dynamic Field Configuration Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/configuration.md Uses *Func methods to automatically recompute field titles and options based on bound variable changes. ```go var country string stateSelect := huh.NewSelect[string](). TitleFunc(func() string { return fmt.Sprintf("States in %s", country) }, &country). OptionsFunc(func() []huh.Option[string] { // Fetch states for selected country states := getStates(country) return huh.NewOptions(states...) }, &country) ``` -------------------------------- ### Set Note Theme Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/api-reference/note.md Configures the visual theme for the note field. ```go func (n *Note) WithTheme(theme Theme) *Note ``` -------------------------------- ### Run() error Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/api-reference/filepicker.md Runs the file picker as a standalone form. ```APIDOC ## Run() error ### Description Runs the file picker as a standalone form without needing a Form instance. ### Returns - error - Validation error, user abort, or nil on success ``` -------------------------------- ### Run Spinner with Context Source: https://github.com/charmbracelet/huh/blob/main/README.md Create and run a spinner with a specific type, title, and a context. This is useful for controlling the spinner's lifecycle or providing additional information. ```go go makeBurger() err := spinner.New(). Type(spinner.Line). Title("Making your burger..."). Context(ctx). Run() fmt.Println("Order up!") ``` -------------------------------- ### Configure Text field placeholder Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/api-reference/text.md Sets static placeholder text shown when field is empty. ```go func (t *Text) Placeholder(placeholder string) *Text ``` -------------------------------- ### Run a single field with shorthand Source: https://github.com/charmbracelet/huh/blob/main/README.md Use the Run method on a field for a blocking, single-field prompt. ```go var name string huh.NewInput(). Title("What’s your name?"). Value(&name). Run() // this is blocking... fmt.Printf("Hey, %s!\n", name) ``` -------------------------------- ### func (c *Confirm) WithTheme(theme Theme) *Confirm Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/api-reference/confirm.md Sets the theme for the confirm field. ```APIDOC ## func (c *Confirm) WithTheme(theme Theme) *Confirm ### Description Sets the theme for the confirm field. ### Parameters - **theme** (Theme) - Required - Theme implementation ### Returns - ***Confirm** - The field receiver for method chaining ``` -------------------------------- ### Optimize form performance with lazy loading Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/advanced-topics.md Use OptionsFunc to defer the generation of options until they are required by the form. ```go .OptionsFunc(func() []Option[T] { // Only called when needed }, binding) ``` -------------------------------- ### Handle Form Timeouts Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/advanced-topics.md Use context with a timeout to limit form execution time and check for huh.ErrTimeout to handle user inactivity. ```go ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute) defer cancel() form.WithTimeout(5 * time.Minute) err := form.RunWithContext(ctx) if errors.Is(err, huh.ErrTimeout) { fmt.Println("Form timeout: user took too long") } ``` -------------------------------- ### Run Accessible Mode Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/api-reference/select.md Executes the select field with screen reader support using provided input and output streams. ```go func (s *Select[T]) RunAccessible(w io.Writer, r io.Reader) error ``` -------------------------------- ### Initialize MultiSelect Field Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/api-reference/multiselect.md Constructor for creating a new multi-select field instance. ```go func NewMultiSelect[T comparable]() *MultiSelect[T] ``` -------------------------------- ### WithTheme(theme Theme) Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/api-reference/spinner.md Sets the theme for spinner styling. ```APIDOC ## func (s *Spinner) WithTheme(theme Theme) ### Description Sets the theme for spinner styling. ### Parameters - **theme** (Theme) - Required - Theme implementation ### Returns *Spinner - The spinner receiver for method chaining. ``` -------------------------------- ### Import Huh Package Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/README.md Standard import statement for using the Huh library in Go projects. ```go import "charm.land/huh/v2" ``` -------------------------------- ### Configure Confirm Theme Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/api-reference/confirm.md Sets the theme for the confirm field, returning the receiver for method chaining. ```go func (c *Confirm) WithTheme(theme Theme) *Confirm ``` -------------------------------- ### Define Huh Documentation Structure Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/README.md Standard template for component documentation pages. ```markdown # Title Brief description of the component/topic ## Constructor/Overview Full signature and usage ## Configuration Methods Organized by category with parameter tables ## Execution How to run the component ## Advanced Topics Optional advanced patterns ## Source Reference File locations in repository ``` -------------------------------- ### Execute a Single Field Prompt Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/README.md Runs a standalone input prompt without requiring a full form structure. ```go huh.NewInput().Title("Name").Value(&name).Run() ``` -------------------------------- ### Configuration Methods Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/api-reference/filepicker.md Methods for configuring the FilePicker field behavior and appearance. ```APIDOC ## Configuration Methods ### Title(title string) Sets the title displayed above the file picker. ### Description(description string) Sets descriptive text shown below the title. ### Value(value *string) Sets a pointer to the string variable where the selected path is stored. ### Accessor(accessor Accessor[string]) Sets a custom accessor for reading/writing the field value. ### Key(key string) Sets the key used to retrieve the field value from form results. ### CurrentDirectory(directory string) Sets the initial directory to browse. ### Cursor(cursor string) Sets the cursor character for directory selection. ### ShowHidden(v bool) Sets whether hidden files (starting with .) should be displayed. ### ShowSize(v bool) Sets whether file sizes should be displayed. ### ShowPermissions(v bool) Sets whether file permissions should be displayed. ### FileAllowed(v bool) Sets whether files can be selected (vs directories only). ``` -------------------------------- ### func (i *Input) WithTheme(theme Theme) *Input Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/api-reference/input.md Sets the theme for the input field. ```APIDOC ## func (i *Input) WithTheme(theme Theme) *Input ### Description Sets the theme for the input field. ### Parameters - **theme** (Theme) - Required - Theme implementation ### Returns - ***Input** - The field receiver for method chaining ``` -------------------------------- ### Create a new Group Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/api-reference/group.md Initializes a group with a variable number of fields to be used within a form. ```go func NewGroup(fields ...Field) *Group ``` ```go group := huh.NewGroup( huh.NewInput().Title("Name").Value(&name), huh.NewConfirm().Title("Continue?").Value(&confirmed), ) form := huh.NewForm(group) ``` -------------------------------- ### Run Spinner with Action Source: https://github.com/charmbracelet/huh/blob/main/README.md Create and run a spinner with a title and an action function to indicate background activity. The spinner will run until the action is complete. ```go err := spinner.New(). Title("Making your burger..."). Action(makeBurger). Run() fmt.Println("Order up!") ``` -------------------------------- ### Enable accessible mode Source: https://github.com/charmbracelet/huh/blob/main/README.md Configure the form to use standard prompts instead of TUI for better screen reader support. ```go accessibleMode := os.Getenv("ACCESSIBLE") != "" form.WithAccessible(accessibleMode) ``` -------------------------------- ### NewForm Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/api-reference/form.md Creates a new form instance with the specified groups, default themes, and keybindings. ```APIDOC ## NewForm ### Description Creates a new form with the given groups and default themes and keybindings. ### Signature `func NewForm(groups ...*Group) *Form` ### Parameters - **groups** (...*Group) - Optional - Variable number of group pointers to include in the form ### Returns - ***Form** - A new form instance ready for configuration ### Example ```go form := huh.NewForm( huh.NewGroup( huh.NewInput().Title("Name").Value(&name), ), ) err := form.Run() ``` ``` -------------------------------- ### Run Form with Context Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/api-reference/form.md Executes the form with a provided context to support cancellation. ```go func (f *Form) RunWithContext(ctx context.Context) error ``` -------------------------------- ### Apply Predefined Themes Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/quick-start.md Set the visual style of the form using built-in theme constants. ```go form.WithTheme(huh.ThemeCharm) // Default form.WithTheme(huh.ThemeDracula) // Dracula colors form.WithTheme(huh.ThemeCatppuccin) // Catppuccin colors form.WithTheme(huh.ThemeBase) // Minimal styling ``` -------------------------------- ### Set FilePicker Theme Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/api-reference/filepicker.md Configures the visual theme for the file picker field. ```go func (f *FilePicker) WithTheme(theme Theme) *FilePicker ``` -------------------------------- ### WithHeight Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/api-reference/select.md Sets the display height (viewport height for options). ```APIDOC ## func (s *Select[T]) WithHeight(height int) *Select[T] ### Description Sets the display height (viewport height for options). ### Parameters - **height** (int) - Required - Height in characters ### Returns - ***Select[T]** - The field receiver for method chaining ``` -------------------------------- ### Configure Select Field Description Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/api-reference/select.md Method to set static descriptive text below the title. ```go func (s *Select[T]) Description(description string) *Select[T] ``` -------------------------------- ### Toggle Help Display Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/api-reference/group.md Controls whether help keybindings are visible for fields in the group. ```go func (g *Group) WithShowHelp(show bool) *Group ``` -------------------------------- ### Run Note Field Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/api-reference/note.md Executes the note field as a standalone form. ```go func (n *Note) Run() error ``` ```go if err := huh.NewNote(). Title("Disclaimer"). Description("You must agree to continue."). Next(true). Run(); err != nil { log.Fatal(err) } ``` -------------------------------- ### WithKeyMap Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/api-reference/form.md Sets custom keybindings for form navigation and field interactions. ```APIDOC ## func (f *Form) WithKeyMap(keymap *KeyMap) *Form ### Description Sets custom keybindings for form navigation and field interactions. ### Parameters - **keymap** (*KeyMap) - Required - A KeyMap with custom bindings (Default: Default keybindings) ### Returns - *Form - The form receiver for method chaining ``` -------------------------------- ### func (n *Note) WithTheme(theme Theme) *Note Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/api-reference/note.md Sets the theme for the note field. ```APIDOC ### func (n *Note) WithTheme(theme Theme) *Note ### Description Sets the theme for the note field. ### Parameters - **theme** (Theme) - Required - Theme implementation ### Returns - ***Note** - The field receiver for method chaining ``` -------------------------------- ### Configure external editor command Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/api-reference/text.md Sets the command and optional arguments for an external editor triggered by the editor key. ```go text.Editor("vim") // or text.Editor("nano", "-w") ``` -------------------------------- ### Execute standalone fields in Go Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/advanced-topics.md Run individual input and confirmation fields without wrapping them in a full form structure. ```go var name string if err := huh.NewInput(). Title("Name"). Value(&name). Run(); err != nil { return err } var confirmed bool if err := huh.NewConfirm(). Title("Continue?"). Value(&confirmed). Run(); err != nil { return err } if !confirmed { return errors.New("user cancelled") } ``` -------------------------------- ### Configure dynamic Text field description Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/api-reference/text.md Sets a dynamic description that recomputes when bindings change. ```go func (t *Text) DescriptionFunc(f func() string, bindings any) *Text ``` -------------------------------- ### Construct Option[T] instances Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/types.md Helper functions for creating new options or slices of options. ```go func NewOption[T comparable](key string, value T) Option[T] func NewOptions[T comparable](values ...T) []Option[T] ``` -------------------------------- ### Prompt Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/api-reference/input.md Sets the prompt string displayed at the input cursor. ```APIDOC ## func (i *Input) Prompt(prompt string) *Input ### Description Sets the prompt string displayed at the input cursor. ### Parameters - **prompt** (string) - Required - Prompt string (e.g., "> ") ### Returns - ***Input** - The field receiver for method chaining ``` -------------------------------- ### Create a multi-select field Source: https://github.com/charmbracelet/huh/blob/main/README.md Prompt the user to select multiple options from a list with an optional limit. ```go huh.NewMultiSelect[string](). Options( huh.NewOption("Lettuce", "Lettuce").Selected(true), huh.NewOption("Tomatoes", "Tomatoes").Selected(true), huh.NewOption("Charm Sauce", "Charm Sauce"), huh.NewOption("Jalapeños", "Jalapeños"), huh.NewOption("Cheese", "Cheese"), huh.NewOption("Vegan Cheese", "Vegan Cheese"), huh.NewOption("Nutella", "Nutella"), ). Title("Toppings"). Limit(4). Value(&toppings) ``` -------------------------------- ### huh.NewFilePicker() Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/configuration.md Creates a new file picker field for selecting files or directories. ```APIDOC ## huh.NewFilePicker() ### Description Creates a new file picker field. Allows users to navigate the file system and select files or directories. ### Example ```go huh.NewFilePicker(). Title("Config file"). CurrentDirectory("/etc"). ShowHidden(true). Value(&configPath) ``` ``` -------------------------------- ### Bubble Tea Integration with Huh Form Source: https://github.com/charmbracelet/huh/blob/main/README.md Demonstrates embedding a Huh form within a Bubble Tea application. The Huh form acts as a tea.Model, allowing seamless integration and state management. Use this when your application requires complex form input within a Bubble Tea environment. ```go type Model struct { form *huh.Form // huh.Form is just a tea.Model } func NewModel() Model { return Model{ form: huh.NewForm( huh.NewGroup( huh.NewSelect[string](). Key("class"). Options(huh.NewOptions("Warrior", "Mage", "Rogue")...). Title("Choose your class"), huh.NewSelect[int](). Key("level"). Options(huh.NewOptions(1, 20, 9999)...). Title("Choose your level"), ), ) } } func (m Model) Init() tea.Cmd { return m.form.Init() } func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { // ... form, cmd := m.form.Update(msg) if f, ok := form.(*huh.Form); ok { m.form = f } return m, cmd } func (m Model) View() string { if m.form.State == huh.StateCompleted { class := m.form.GetString("class") level := m.form.GetInt("level") return fmt.Sprintf("You selected: %s, Lvl. %d", class, level) } return m.form.View() } ``` -------------------------------- ### Configure MultiSelect Theme Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/api-reference/multiselect.md Sets the theme for the multi-select field. ```go func (m *MultiSelect[T]) WithTheme(theme Theme) *MultiSelect[T] ``` -------------------------------- ### Configure Form Layout Source: https://github.com/charmbracelet/huh/blob/main/_autodocs/api-reference/form.md Sets the layout strategy for displaying groups within the form. ```go func (f *Form) WithLayout(layout Layout) *Form ``` ```go form.WithLayout(huh.LayoutColumns(2)) ```