Build terminal forms and prompts π€·π»ββοΈ
MIT License
Bot releases are hidden (Show)
This is a big release with a tonne of new features.
To upgrade to huh
v0.3.0:
go get -u github.com/charmbracelet/huh@latest
For details read on!
If a form is in a small terminal it will automatically resize to fit the available space and the active group will scroll to stay in view. Form heights can also be set manually with the new WithHeight
method.
Select and Multi select fields can now be restricted to a certain height, allowing their options to be scrollable. This means you can now pack in tonnes of options.
To make a Select
or MultiSelect
scrollable simply set the height on the field or form through the Height
method.
s := huh.NewSelect()
.Title("Whatβs for dinner?")
.Options(/* ... */)
.Height(height)
Now Input
s can offer suggestions making it easier for users to fill out inputs. These suggestions can be accepted autocomplete-style with a configurable key binding (which defaults to ctrl+e).
Simply provide a []string
to Suggestions
to enable this feature.
huh.NewInput().
Title("What's for lunch?").
Prompt("? ").
Suggestions([]string{
"Artichoke",
// ...
"Cashew Apple",
"Cashews",
"Cat Food",
"Coconut Milk",
"Cucumber",
"Curry Paste",
"Currywurst",
// ...
})
Forms will automatically adjust their help text to indicate to the user whether the form will continue or submit on actions. This works with hidden groups. In the below example, the user will be asked to list their allergies if they select "Yes" otherwise, the form will submit.
Huh now produces way smaller binaries! Thanks to #94 Huh now has a 7x smaller compiled footprint.
Before, using [email protected]
:
33M ./burger
After, using [email protected]
:
4.5M ./burger
Special thanks to the intrepid @vitor-mariano, one of the earliest huh
contributors, who came in hot with features, fixes, improvements and good vibes. Thank you, Vitor!
Full Changelog: https://github.com/charmbracelet/huh/compare/v0.2.3...v0.3.0
Thoughts? Questions? We love hearing from you. Feel free to reach out on Twitter, The Fediverse, or on Discord.
Published by maaslalani 10 months ago
Huh? v0.2.3
fixes some bugs for more consistent behaviour across inputs π
Text
inputs now update values on each keystroke rather than on Blur
for consistency.Select
and MultiSelect
read their default values from the initial values set by the Value
variable if provided.A special thanks to @vitor-mariano for all his contributions to this release π€
You can now have preselected options by declaring them in the Value
variable:
var toppings = []string{"Lettuce", "Tomatoes"}
var options = huh.NewOptions("Lettuce", "Tomatoes", "Charm Sauce", "Cheese", "Vegan Cheese")
huh.NewMultiSelect[string]().Title("Toppings").Options(options...).Value(&toppings).Run()
In the above example, Lettuce
and Tomatoes
will be preselected by default.
Text
value updates by @vitor-mariano in https://github.com/charmbracelet/huh/pull/64
Select
and MultiSelect
inputs with default values by @vitor-mariano in https://github.com/charmbracelet/huh/pull/62
Full Changelog: https://github.com/charmbracelet/huh/compare/v0.2.2...v0.2.3
Thoughts? Questions? We love hearing from you. Feel free to reach out on Twitter, The Fediverse, or on Discord.
Published by maaslalani 10 months ago
Huh?
v0.2.2 improves wrapping of the Input
and Text
fields.
It applies width set on the form to the inputs to perform wrapping based on the specified or terminal width.
Full Changelog: https://github.com/charmbracelet/huh/compare/v0.2.1...v0.2.2
Thoughts? Questions? We love hearing from you. Feel free to reach out on Twitter, The Fediverse, or Discord.
Published by maaslalani 10 months ago
huh?
forms can now use Catppuccin themes. (Thanks to the wonderful @sgoudham β¨)
Simply add the following to your huh.Form
s:
.WithTheme(huh.ThemeCatppuccin())
Thoughts? Questions? We love hearing from you. Feel free to reach out on Twitter, The Fediverse, or Discord.
Published by maaslalani 10 months ago
Help
Styles now apply on a Theme
rather than embedded in FieldStyles
. (Thanks to the wonderful @jolheiser β¨)
// Old...
theme.Focused.Help.ShortKey = lipgloss.NewStyle() //...
// Updated!
theme.Help.ShortKey = lipgloss.NewStyle() //...
Thoughts? Questions? We love hearing from you. Feel free to reach out on Twitter, The Fediverse, or Discord.
Published by maaslalani 10 months ago
A simple, powerful library for building interactive forms and prompts in the terminal.
huh?
is easy to use in a standalone fashion, can be integrated into a Bubble Tea application, and contains a first-class accessible mode mode for screen readers.
Thoughts? Questions? We love hearing from you. Feel free to reach out on Twitter, The Fediverse, or Discord.