mirror of
https://github.com/psviderski/uncloud.git
synced 2026-08-26 19:13:34 +00:00
54 lines
1.2 KiB
Go
54 lines
1.2 KiB
Go
package tui
|
|
|
|
import (
|
|
"os"
|
|
|
|
"charm.land/huh/v2"
|
|
"charm.land/lipgloss/v2"
|
|
"golang.org/x/term"
|
|
)
|
|
|
|
// Confirm shows a confirmation prompt with a yellow-styled title.
|
|
// If title is empty, it defaults to "Do you want to continue?".
|
|
func Confirm(title string) (bool, error) {
|
|
if title == "" {
|
|
title = "Do you want to continue?"
|
|
}
|
|
|
|
var confirmed bool
|
|
form := huh.NewForm(
|
|
huh.NewGroup(
|
|
huh.NewConfirm().
|
|
Title(title).
|
|
Affirmative("Yes!").
|
|
Negative("No").
|
|
Value(&confirmed),
|
|
),
|
|
).WithTheme(ThemeConfirm()).
|
|
WithAccessible(true)
|
|
if err := form.Run(); err != nil {
|
|
return false, err
|
|
}
|
|
|
|
return confirmed, nil
|
|
}
|
|
|
|
// ThemeConfirm returns a huh theme with a bold yellow title style for the confirmation prompt.
|
|
func ThemeConfirm() huh.Theme {
|
|
return huh.ThemeFunc(func(isDark bool) *huh.Styles {
|
|
t := huh.ThemeBase(isDark)
|
|
t.Focused.Title = t.Focused.Title.Foreground(lipgloss.Yellow).Bold(true)
|
|
return t
|
|
})
|
|
}
|
|
|
|
// IsStdinTerminal checks if the standard input is a terminal (TTY).
|
|
func IsStdinTerminal() bool {
|
|
return term.IsTerminal(int(os.Stdin.Fd()))
|
|
}
|
|
|
|
// IsStdoutTerminal checks if the standard output is a terminal (TTY).
|
|
func IsStdoutTerminal() bool {
|
|
return term.IsTerminal(int(os.Stdout.Fd()))
|
|
}
|