{"name":"huh: Build Interactive Terminal Forms and Prompts in Go","description":"`huh` is a simple yet powerful Go library from Charmbracelet designed for creating interactive forms and prompts directly within the terminal. It offers a wide range of field types, including text inputs, multi-selects, and confirmations, all easily configurable. The library also boasts features like accessibility support, customizable themes, and seamless integration with Bubble Tea applications, making it an excellent choice for enhancing command-line interfaces.","github":"https://github.com/charmbracelet/huh","url":"https://osrepos.com/repo/charmbracelet-huh","source":"osrepos.com","sourceDescription":"This repository profile is provided by osrepos.com, an open source repository discovery platform.","repositoryProfile":"https://osrepos.com/repo/charmbracelet-huh","generatedFor":"open source discovery and AI-assisted research","markdown":"https://osrepos.com/repo/charmbracelet-huh.md","json":"https://osrepos.com/repo/charmbracelet-huh.json","topics":["Go","CLI","Terminal UI","Forms","Prompts","Interactive","Charmbracelet"],"keywords":["Go","CLI","Terminal UI","Forms","Prompts","Interactive","Charmbracelet"],"stars":null,"summary":"`huh` is a simple yet powerful Go library from Charmbracelet designed for creating interactive forms and prompts directly within the terminal. It offers a wide range of field types, including text inputs, multi-selects, and confirmations, all easily configurable. The library also boasts features like accessibility support, customizable themes, and seamless integration with Bubble Tea applications, making it an excellent choice for enhancing command-line interfaces.","content":"## Introduction\n\n`huh` is a robust and user-friendly Go library developed by Charmbracelet, specifically engineered for building interactive forms and prompts within the terminal. It empowers developers to create engaging command-line interfaces with a variety of input fields, making CLI applications more dynamic and user-friendly. Whether you need to gather simple text input, allow users to select from a list, or confirm actions, `huh` provides an elegant solution.\n\nKey features of `huh` include:\n*   A comprehensive set of field types: `Input`, `Text`, `Select`, `MultiSelect`, and `Confirm`.\n*   Support for multi-page forms using groups.\n*   Built-in validation for fields.\n*   An accessible mode for screen readers.\n*   Customizable themes to match your application's aesthetic.\n*   Seamless integration with Charmbracelet's `Bubble Tea` framework.\n*   Dynamic forms that adapt based on user input.\n\n## Installation\n\nGetting started with `huh` is straightforward. You can add it to your Go project using the standard `go get` command:\n\nbash\ngo get github.com/charmbracelet/huh\n\n\n## Examples\n\n`huh` makes it easy to create both simple prompts and complex multi-page forms. Here's a quick example demonstrating a single input field:\n\ngo\npackage main\n\nimport (\n\t\"fmt\"\n\t\"log\"\n\n\t\"github.com/charmbracelet/huh\"\n)\n\nfunc main() {\n\tvar name string\n\n\terr := huh.NewInput().\n\t\tTitle(\"What’s your name?\").\n\t\tValue(&name).\n\t\tRun() // this is blocking...\n\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\tfmt.Printf(\"Hey, %s!\\n\", name)\n}\n\n\nFor more elaborate scenarios, `huh` allows you to construct multi-group forms with various field types. Below is an excerpt from a burger ordering form, showcasing `Select`, `MultiSelect`, `Input`, `Text`, and `Confirm` fields:\n\ngo\npackage main\n\nimport (\n\t\"errors\"\n\t\"fmt\"\n\t\"log\"\n\n\t\"github.com/charmbracelet/huh\"\n)\n\nvar (\n\tburger       string\n\ttoppings     []string\n\tsauceLevel   int\n\tname         string\n\tinstructions string\n\tdiscount     bool\n)\n\nfunc main() {\n\tform := huh.NewForm(\n\t\thuh.NewGroup(\n\t\t\thuh.NewSelect[string]().\n\t\t\t\tTitle(\"Choose your burger\").\n\t\t\t\tOptions(\n\t\t\t\t\thuh.NewOption(\"Charmburger Classic\", \"classic\"),\n\t\t\t\t\thuh.NewOption(\"Chickwich\", \"chickwich\"),\n\t\t\t\t\thuh.NewOption(\"Fishburger\", \"fishburger\"),\n\t\t\t\t\thuh.NewOption(\"Charmpossible™ Burger\", \"charmpossible\"),\n\t\t\t\t).\n\t\t\t\tValue(&burger),\n\n\t\t\thuh.NewMultiSelect[string]().\n\t\t\t\tTitle(\"Toppings\").\n\t\t\t\tOptions(\n\t\t\t\t\thuh.NewOption(\"Lettuce\", \"lettuce\").Selected(true),\n\t\t\t\t\thuh.NewOption(\"Tomatoes\", \"tomatoes\").Selected(true),\n\t\t\t\t\thuh.NewOption(\"Jalapeños\", \"jalapeños\"),\n\t\t\t\t\thuh.NewOption(\"Cheese\", \"cheese\"),\n\t\t\t\t\thuh.NewOption(\"Vegan Cheese\", \"vegan cheese\"),\t\t\t\t\t\n\t\t\t\t\thuh.NewOption(\"Nutella\", \"nutella\"),\n\t\t\t\t).\n\t\t\t\tLimit(4).\n\t\t\t\tValue(&toppings),\n\n\t\t\thuh.NewSelect[int]().\n\t\t\t\tTitle(\"How much Charm Sauce do you want?\").\n\t\t\t\tOptions(\n\t\t\t\t\thuh.NewOption(\"None\", 0),\n\t\t\t\t\thuh.NewOption(\"A little\", 1),\n\t\t\t\t\thuh.NewOption(\"A lot\", 2),\n\t\t\t\t).\n\t\t\t\tValue(&sauceLevel),\n\t\t),\n\n\t\thuh.NewGroup(\n\t\t\thuh.NewInput().\n\t\t\t\tTitle(\"What’s your name?\").\n\t\t\t\tValue(&name).\n\t\t\t\tValidate(func(str string) error {\n\t\t\t\t\tif str == \"Frank\" {\n\t\t\t\t\t\treturn errors.New(\"Sorry, we don’t serve customers named Frank.\")\n\t\t\t\t\t}\n\t\t\t\t\treturn nil\n\t\t\t\t}),\n\n\t\t\thuh.NewText().\n\t\t\t\tTitle(\"Special Instructions\").\n\t\t\t\tCharLimit(400).\n\t\t\t\tValue(&instructions),\n\n\t\t\thuh.NewConfirm().\n\t\t\t\tTitle(\"Would you like 15% off?\").\n\t\t\t\tValue(&discount),\n\t\t),\n\t)\n\n\terr := form.Run()\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\tif !discount {\n\t\tfmt.Println(\"What? You didn’t take the discount?!\")\n\t}\n}\n\n\n`huh` also supports dynamic forms, where fields can change based on previous inputs, and an accessible mode for improved usability with screen readers.\n\n## Why Use `huh`?\n\n`huh` stands out for several reasons, making it an excellent choice for developers looking to enhance their CLI applications:\n\n*   **Simplicity and Power**: It offers a clean and intuitive API that allows for the rapid development of complex interactive forms.\n*   **Rich User Experience**: By bringing interactive forms to the terminal, `huh` elevates the user experience of command-line tools beyond simple text prompts.\n*   **Flexibility**: With a variety of field types, validation capabilities, and dynamic form features, `huh` can adapt to almost any input requirement.\n*   **Accessibility**: The dedicated accessible mode ensures that your CLI applications are usable by a wider audience, including those who rely on screen readers.\n*   **Customization**: Theming options allow you to tailor the look and feel of your forms to perfectly match your brand or application's style.\n*   **Bubble Tea Integration**: For those building more extensive Terminal User Interface (TUI) applications with `Bubble Tea`, `huh` integrates seamlessly, acting as a `tea.Model` for advanced control.\n\n## Links\n\n*   **GitHub Repository**: [https://github.com/charmbracelet/huh](https://github.com/charmbracelet/huh){:target=\"_blank\"}\n*   **Go Documentation**: [https://pkg.go.dev/github.com/charmbracelet/huh?tab=doc](https://pkg.go.dev/github.com/charmbracelet/huh?tab=doc){:target=\"_blank\"}\n*   **Charmbracelet**: [https://charm.sh](https://charm.sh){:target=\"_blank\"}","metrics":{"detailViews":2,"githubClicks":3},"dates":{"published":null,"modified":"2026-03-06T09:21:18.000Z"}}