mirror of
https://github.com/charmbracelet/gum
synced 2026-03-15 06:05:45 +01:00
* fix(confirm,choose,file,input): timeout handling - some fields were not actually using the `--timeout` value - some fields had different behavior when a timeout did occur. On this matter, it seems to me the best way forward is to specifically say it timed out, and after how long - added exit status 124 (copied from `timeout` from coreutils) (fixes #684) Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com> * Update main.go Co-authored-by: Ayman Bagabas <ayman.bagabas@gmail.com> * Update internal/exit/exit.go Co-authored-by: ccoVeille <3875889+ccoVeille@users.noreply.github.com> * fix: improve Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com> * fix: stderr --------- Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com> Co-authored-by: Ayman Bagabas <ayman.bagabas@gmail.com> Co-authored-by: ccoVeille <3875889+ccoVeille@users.noreply.github.com>
42 lines
844 B
Go
42 lines
844 B
Go
package confirm
|
|
|
|
import (
|
|
"os"
|
|
|
|
"github.com/charmbracelet/gum/internal/exit"
|
|
"github.com/charmbracelet/huh"
|
|
)
|
|
|
|
// Run provides a shell script interface for prompting a user to confirm an
|
|
// action with an affirmative or negative answer.
|
|
func (o Options) Run() error {
|
|
theme := huh.ThemeCharm()
|
|
theme.Focused.Title = o.PromptStyle.ToLipgloss()
|
|
theme.Focused.FocusedButton = o.SelectedStyle.ToLipgloss()
|
|
theme.Focused.BlurredButton = o.UnselectedStyle.ToLipgloss()
|
|
|
|
choice := o.Default
|
|
|
|
err := huh.NewForm(
|
|
huh.NewGroup(
|
|
huh.NewConfirm().
|
|
Affirmative(o.Affirmative).
|
|
Negative(o.Negative).
|
|
Title(o.Prompt).
|
|
Value(&choice),
|
|
),
|
|
).
|
|
WithTimeout(o.Timeout).
|
|
WithTheme(theme).
|
|
WithShowHelp(o.ShowHelp).
|
|
Run()
|
|
if err != nil {
|
|
return exit.Handle(err, o.Timeout)
|
|
}
|
|
|
|
if !choice {
|
|
os.Exit(1)
|
|
}
|
|
|
|
return nil
|
|
}
|