Documentation
¶
Overview ¶
Package ui provides terminal UI components.
Index ¶
- Constants
- Variables
- func Bold(s string) string
- func Code(s string) string
- func ColorizeJSON(jsonStr string) string
- func Confirm(message string, defaultYes bool) (bool, error)
- func ConfirmWithPort(message string, defaultPort int) (bool, int, error)
- func ConfirmWithPortYesOnly(message string, defaultPort int) (int, error)
- func ContextError(ctx context.Context, err error) error
- func Dim(s string) string
- func Error(s string) string
- func GetContext() context.Context
- func HasDisplay() bool
- func Info(s string) string
- func IsInterrupted() bool
- func PrintCompletionSummary(success bool, message string)
- func PrintError(message string)
- func PrintHeader(message string)
- func PrintInfo(message string)
- func PrintKeyValue(key, value string)
- func PrintSectionHeader(name string)
- func PrintStepSummary(items map[string]string)
- func PrintStepSummaryOrdered(items []KeyValue)
- func PrintSuccess(message string)
- func PrintWarning(message string)
- func Prompt(message string) (string, error)
- func PromptDefault(message, defaultValue string) (string, error)
- func PromptInt(message string, defaultValue int) (int, error)
- func PromptPassword(message string) (string, error)
- func PromptSecret(message string) (string, error)
- func RenderLogo() string
- func SanitizeErrorMessage(err error) string
- func Select(title string, options []string, recommended int) (int, error)
- func SelectMultiple(message string, options []string) ([]int, error)
- func SelectMultiplePreselected(title string, options []string, preselected []int) ([]int, error)
- func SelectMultipleWithArrows(title string, options []string) ([]int, error)
- func SelectMultipleWithDefaults(message string, options []string, preselected []int) ([]int, error)
- func SelectOption(message string, options []string, recommended int) (int, error)
- func SetContext(ctx context.Context)
- func SetNoColor(noColor bool)
- func SetVersion(v string)
- func Success(s string) string
- func Title(s string) string
- func Warning(s string) string
- type DownloadTracker
- type KeyValue
- type Progress
- type Spinner
- type StepTracker
Constants ¶
const Logo = `
_____ _
/ _ / __ _ _ __ ___| |_ ___ _ __ ___
\// / / _` + "`" + ` | '_ \/ __| __/ _ \| '__/ _ \
/ //\ (_| | |_) \__ \ || (_) | | | __/
/____/\__,_| .__/|___/\__\___/|_| \___|
|_|
═══════════════════════════════
P U B L I S H E R
`
Logo is the ASCII art logo for Zapstore Publisher.
Variables ¶
var ( // NoColor disables colored output when true. NoColor = false // Styles TitleStyle lipgloss.Style SuccessStyle lipgloss.Style ErrorStyle lipgloss.Style WarningStyle lipgloss.Style InfoStyle lipgloss.Style DimStyle lipgloss.Style BoldStyle lipgloss.Style CodeStyle lipgloss.Style LogoStyle lipgloss.Style )
var DefaultFrames = []string{"⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"}
DefaultFrames are the default spinner animation frames.
var ErrInterrupted = errors.New("interrupted")
ErrInterrupted is returned when an operation is interrupted by Ctrl+C.
var SimpleFrames = []string{"|", "/", "-", "\\"}
SimpleFrames are simple ASCII spinner frames.
var Version = "dev"
Version holds the application version, set at startup.
Functions ¶
func ColorizeJSON ¶
ColorizeJSON adds syntax highlighting to JSON string.
func ConfirmWithPort ¶
ConfirmWithPort presents a Y/n/port prompt with arrow key navigation. Returns: confirmed (bool), port (int), error If user selects yes, returns (true, defaultPort, nil) If user selects no, returns (false, 0, nil) If user enters custom port, returns (true, customPort, nil)
func ConfirmWithPortYesOnly ¶
ConfirmWithPortYesOnly presents a Y/port prompt (no skip option). Returns: port (int), error
func ContextError ¶
ContextError returns ErrInterrupted if the context is cancelled, otherwise returns the original error.
func HasDisplay ¶
func HasDisplay() bool
HasDisplay returns true if a graphical display is available. On Linux, this checks for DISPLAY or WAYLAND_DISPLAY environment variables. On macOS and Windows, it generally assumes a display is available.
func IsInterrupted ¶
func IsInterrupted() bool
IsInterrupted checks if the global context has been cancelled.
func PrintCompletionSummary ¶
PrintCompletionSummary prints a final summary when all steps are done.
func PrintHeader ¶
func PrintHeader(message string)
PrintHeader prints a section header (legacy - use StepTracker for numbered steps).
func PrintSectionHeader ¶
func PrintSectionHeader(name string)
PrintSectionHeader prints a minor section header within a step.
func PrintStepSummary ¶
PrintStepSummary prints a summary section with key-value pairs.
func PrintStepSummaryOrdered ¶
func PrintStepSummaryOrdered(items []KeyValue)
PrintStepSummaryOrdered prints a summary section with key-value pairs in order.
func Prompt ¶
Prompt asks for user input with a prompt message. Returns ErrInterrupted if Ctrl+C is pressed.
func PromptDefault ¶
PromptDefault asks for user input with a default value.
func PromptPassword ¶
PromptPassword asks for password input with hidden characters. Returns ErrInterrupted if Ctrl+C is pressed.
func PromptSecret ¶
PromptSecret asks for secret input (like passwords or keys) with hidden characters. The input is not echoed to the terminal for security.
func RenderLogo ¶
func RenderLogo() string
RenderLogo returns the styled logo with version underneath.
func SanitizeErrorMessage ¶
SanitizeErrorMessage redacts potentially sensitive path information from error messages. Replaces the user's home directory with ~ to avoid leaking usernames or system structure.
func Select ¶
Select presents a list of options for arrow-key selection. Returns the selected index and nil error on success, or -1 and ErrInterrupted if aborted.
func SelectMultiple ¶
SelectMultiple presents a list of options for multiple selection with arrow keys. Space toggles selection, Enter confirms.
func SelectMultiplePreselected ¶
SelectMultiplePreselected presents a list of options with some pre-selected. preselected is a list of indices to pre-select.
func SelectMultipleWithArrows ¶
SelectMultipleWithArrows presents a list of options for multiple selection with arrow keys. Space toggles selection, Enter confirms.
func SelectMultipleWithDefaults ¶
SelectMultipleWithDefaults presents a list of options with some pre-selected. preselected is a list of indices to pre-select.
func SelectOption ¶
SelectOption presents a list of options with arrow-key navigation. Returns the selected index (0-based).
func SetContext ¶
SetContext sets the global context used by all UI prompts. Call this at startup with the signal handler's context.
func SetVersion ¶
func SetVersion(v string)
SetVersion sets the application version for logo rendering.
Types ¶
type DownloadTracker ¶
type DownloadTracker struct {
// contains filtered or unexported fields
}
DownloadTracker tracks download progress, handling both known and unknown sizes. It provides a callback function for use with download operations.
func NewDownloadTracker ¶
func NewDownloadTracker(message string, initialTotal int64) *DownloadTracker
NewDownloadTracker creates a new download tracker. Pass 0 for initialTotal if the size is unknown.
func (*DownloadTracker) Callback ¶
func (dt *DownloadTracker) Callback() func(downloaded, total int64)
Callback returns a function suitable for passing to download operations.
func (*DownloadTracker) Done ¶
func (dt *DownloadTracker) Done()
Done marks the download as complete.
func (*DownloadTracker) DoneWithMessage ¶
func (dt *DownloadTracker) DoneWithMessage(message string)
DoneWithMessage marks the download as complete with a custom message.
func (*DownloadTracker) Update ¶
func (dt *DownloadTracker) Update(downloaded, total int64)
Update updates the download progress.
type Progress ¶
type Progress struct {
// contains filtered or unexported fields
}
Progress displays a progress indicator with animated bar.
func NewProgress ¶
NewProgress creates a new progress indicator with animated bar.
type Spinner ¶
type Spinner struct {
// contains filtered or unexported fields
}
Spinner displays a spinning animation during long operations.
func NewSpinner ¶
NewSpinner creates a new spinner with a message.
func (*Spinner) StopWithError ¶
StopWithError stops the spinner with an error message.
func (*Spinner) StopWithMessage ¶
StopWithMessage stops the spinner and prints a final message.
func (*Spinner) StopWithSuccess ¶
StopWithSuccess stops the spinner with a success message.
func (*Spinner) StopWithWarning ¶
StopWithWarning stops the spinner with a warning message.
func (*Spinner) UpdateMessage ¶
UpdateMessage updates the spinner message.
type StepTracker ¶
type StepTracker struct {
// contains filtered or unexported fields
}
StepTracker tracks progress through numbered steps in the CLI flow.
func NewStepTracker ¶
func NewStepTracker(total int) *StepTracker
NewStepTracker creates a new step tracker with the given total number of steps.
func (*StepTracker) Current ¶
func (s *StepTracker) Current() int
Current returns the current step number.
func (*StepTracker) PrintSubStep ¶
func (s *StepTracker) PrintSubStep(message string)
PrintSubStep prints a sub-step item under the current step.
func (*StepTracker) SetTotal ¶
func (s *StepTracker) SetTotal(total int)
SetTotal updates the total number of steps (useful when steps are conditional).
func (*StepTracker) Skip ¶
func (s *StepTracker) Skip()
Skip skips the current step number without printing anything. Use this when a step is conditionally skipped.
func (*StepTracker) StartStep ¶
func (s *StepTracker) StartStep(name string)
StartStep begins a new step with the given name. It prints a visual header for the step.
func (*StepTracker) Total ¶
func (s *StepTracker) Total() int
Total returns the total number of steps.