CTRL+C sets value to currently selected option in Select #693
Unanswered
chrishessler
asked this question in
Q&A
Replies: 1 comment 3 replies
-
|
You can do something like this: err := huh.NewForm(
huh.NewGroup(
huh.NewSelect[int]().
Title("Make a choice").
Options(
huh.NewOption("A", 1),
huh.NewOption("B", 2),
huh.NewOption("C", 3),
huh.NewOption("D", 4),
).
Value(&choiceId),
),
).WithTheme(huh.ThemeBase16()).Run()
if err != nil {
// Catch Ctrl-C here, return or whatever so that it doesn't fall through
}
// Code that you only want to run if Ctrl-C didn't happen |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment

Uh oh!
There was an error while loading. Please reload this page.
-
When presenting the user with a Select form, I would expect, for example a
var choiceId intto be 0. Instead it sets the value to the currently selected/hovered option.My program continues execution after pressing CTRL+C with said value resulting in (imo) unexpected behaviour because of this.
Is this a bug? If not, how should I correctly end execution when CTRL+C is pressed?
Beta Was this translation helpful? Give feedback.
All reactions