Skip to content

Conversation

@renovate
Copy link
Contributor

@renovate renovate bot commented Jul 12, 2024

Mend Renovate

This PR contains the following updates:

Package Change Age Adoption Passing Confidence
github.com/charmbracelet/huh v0.4.2 -> v0.5.1 age adoption passing confidence

Release Notes

charmbracelet/huh (github.com/charmbracelet/huh)

v0.5.1

Compare Source

v0.5.0

Compare Source

Dynamic Forms 🪄

Country / State form with dynamic inputs running.

huh? forms can now react to changes in other parts of the form. Replace properties such as Options, Title, Description with their dynamic counterparts: OptionsFunc, TitleFunc, and DescriptionFunc to recompute properties values on changes when watched variables change.

Let’s build a simple state / province picker.

var country string
var state string

The country select will be static, we’ll use this value to recompute the
options and title for the next input.

huh.NewSelect[string]().
    Options(huh.NewOptions("United States", "Canada", "Mexico")...).
    Value(&country).
    Title("Country").

Define your Select with TitleFunc and OptionsFunc and bind them to the
&country value from the previous field. Whenever the user chooses a different
country, the TitleFunc and OptionsFunc will be recomputed.

[!IMPORTANT]
We have to pass &country as the binding to recompute the function only when
country changes, otherwise we will hit the API too often.

huh.NewSelect[string]().
    Value(&state).
    Height(8).
    TitleFunc(func() string {
        switch country {
        case "United States":
            return "State"
        case "Canada":
            return "Province"
        default:
            return "Territory"
        }
    }, &country).
    OptionsFunc(func() []huh.Option[string] {
        opts := fetchStatesForCountry(country)
        return huh.NewOptions(opts...)
    }, &country),

Lastly, run the form with these inputs.

err := form.Run()
if err != nil {
    log.Fatal(err)
}
Other Changes

What's Changed

New Contributors

Full Changelog: charmbracelet/huh@v0.4.2...v0.5.0


The Charm logo

Thoughts? Questions? We love hearing from you. Feel free to reach out on Twitter, The Fediverse, or Slack.


Configuration

📅 Schedule: Branch creation - "before 4pm on friday" in timezone Europe/London, Automerge - At any time (no schedule defined).

🚦 Automerge: Enabled.

Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 Ignore: Close this PR and you won't be reminded about this update again.


  • If you want to rebase/retry this PR, check this box

This PR has been generated by Mend Renovate. View repository job log here.

@renovate
Copy link
Contributor Author

renovate bot commented Jul 12, 2024

ℹ Artifact update notice

File name: go.mod

In order to perform the update(s) described in the table above, Renovate ran the go get command, which resulted in the following additional change(s):

  • 2 additional dependencies were updated

Details:

Package Change
github.com/charmbracelet/x/exp/strings v0.0.0-20240524151031-ff83003bf67a -> v0.0.0-20240617190524-788ec55faed1
github.com/charmbracelet/x/input v0.1.1 -> v0.1.2

@renovate renovate bot enabled auto-merge (squash) July 12, 2024 01:51
@renovate renovate bot merged commit 2f4e897 into main Jul 12, 2024
@renovate renovate bot deleted the renovate/github.com-charmbracelet-huh-0.x branch July 12, 2024 01:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant