mirror of
https://github.com/psviderski/uncloud.git
synced 2026-08-27 11:33:33 +00:00
refactor: tui package for CLI styles and prompts, restyle confirmation
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
package tui
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
func PrintWarning(msg string) {
|
||||
styledMsg := BoldYellow.Render(fmt.Sprintf("WARNING: %s", msg))
|
||||
fmt.Fprintln(os.Stderr, styledMsg)
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
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()))
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package tui
|
||||
|
||||
import "charm.land/lipgloss/v2"
|
||||
|
||||
var (
|
||||
Faint = lipgloss.NewStyle().Faint(true)
|
||||
Red = lipgloss.NewStyle().Foreground(lipgloss.Red)
|
||||
Green = lipgloss.NewStyle().Foreground(lipgloss.Green)
|
||||
Yellow = lipgloss.NewStyle().Foreground(lipgloss.Yellow)
|
||||
|
||||
Bold = lipgloss.NewStyle().Bold(true)
|
||||
BoldRed = lipgloss.NewStyle().Bold(true).Foreground(lipgloss.Red)
|
||||
BoldGreen = lipgloss.NewStyle().Bold(true).Foreground(lipgloss.Green)
|
||||
BoldYellow = lipgloss.NewStyle().Bold(true).Foreground(lipgloss.Yellow)
|
||||
|
||||
NameStyle = lipgloss.NewStyle().Bold(true).Foreground(lipgloss.Color("152"))
|
||||
)
|
||||
Reference in New Issue
Block a user