ui

package
v0.4.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 21, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package ui provides terminal UI components.

Index

Constants

View Source
 _____                _
/ _  / __ _ _ __  ___| |_ ___  _ __ ___
\// / / _` + "`" + ` | '_ \/ __| __/ _ \| '__/ _ \
 / //\ (_| | |_) \__ \ || (_) | | |  __/
/____/\__,_| .__/|___/\__\___/|_|  \___|
           |_|
    ═══════════════════════════════
           P U B L I S H E R
`

Logo is the ASCII art logo for Zapstore Publisher.

Variables

View Source
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
)
View Source
var DefaultFrames = []string{"⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"}

DefaultFrames are the default spinner animation frames.

View Source
var ErrInterrupted = errors.New("interrupted")

ErrInterrupted is returned when an operation is interrupted by Ctrl+C.

View Source
var SimpleFrames = []string{"|", "/", "-", "\\"}

SimpleFrames are simple ASCII spinner frames.

View Source
var Version = "dev"

Version holds the application version, set at startup.

Functions

func Bold

func Bold(s string) string

Bold formats text as bold.

func Code

func Code(s string) string

Code formats text as inline code.

func ColorizeJSON

func ColorizeJSON(jsonStr string) string

ColorizeJSON adds syntax highlighting to JSON string.

func Confirm

func Confirm(message string, defaultYes bool) (bool, error)

Confirm asks for yes/no confirmation.

func ConfirmWithPort

func ConfirmWithPort(message string, defaultPort int) (bool, int, error)

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

func ConfirmWithPortYesOnly(message string, defaultPort int) (int, error)

ConfirmWithPortYesOnly presents a Y/port prompt (no skip option). Returns: port (int), error

func ContextError

func ContextError(ctx context.Context, err error) error

ContextError returns ErrInterrupted if the context is cancelled, otherwise returns the original error.

func Dim

func Dim(s string) string

Dim formats text as dimmed.

func Error

func Error(s string) string

Error formats text as error message.

func GetContext

func GetContext() context.Context

GetContext returns the global context.

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 Info

func Info(s string) string

Info formats text as info message.

func IsInterrupted

func IsInterrupted() bool

IsInterrupted checks if the global context has been cancelled.

func PrintCompletionSummary

func PrintCompletionSummary(success bool, message string)

PrintCompletionSummary prints a final summary when all steps are done.

func PrintError

func PrintError(message string)

PrintError prints an error message.

func PrintHeader

func PrintHeader(message string)

PrintHeader prints a section header (legacy - use StepTracker for numbered steps).

func PrintInfo

func PrintInfo(message string)

PrintInfo prints an info message.

func PrintKeyValue

func PrintKeyValue(key, value string)

PrintKeyValue prints a key-value pair.

func PrintSectionHeader

func PrintSectionHeader(name string)

PrintSectionHeader prints a minor section header within a step.

func PrintStepSummary

func PrintStepSummary(items map[string]string)

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 PrintSuccess

func PrintSuccess(message string)

PrintSuccess prints a success message.

func PrintWarning

func PrintWarning(message string)

PrintWarning prints a warning message.

func Prompt

func Prompt(message string) (string, error)

Prompt asks for user input with a prompt message. Returns ErrInterrupted if Ctrl+C is pressed.

func PromptDefault

func PromptDefault(message, defaultValue string) (string, error)

PromptDefault asks for user input with a default value.

func PromptInt

func PromptInt(message string, defaultValue int) (int, error)

PromptInt asks for an integer input with a default value.

func PromptPassword

func PromptPassword(message string) (string, error)

PromptPassword asks for password input with hidden characters. Returns ErrInterrupted if Ctrl+C is pressed.

func PromptSecret

func PromptSecret(message string) (string, error)

PromptSecret asks for secret input (like passwords or keys) with hidden characters. The input is not echoed to the terminal for security.

func RenderLogo() string

RenderLogo returns the styled logo with version underneath.

func SanitizeErrorMessage

func SanitizeErrorMessage(err error) string

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

func Select(title string, options []string, recommended int) (int, error)

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

func SelectMultiple(message string, options []string) ([]int, error)

SelectMultiple presents a list of options for multiple selection with arrow keys. Space toggles selection, Enter confirms.

func SelectMultiplePreselected

func SelectMultiplePreselected(title string, options []string, preselected []int) ([]int, error)

SelectMultiplePreselected presents a list of options with some pre-selected. preselected is a list of indices to pre-select.

func SelectMultipleWithArrows

func SelectMultipleWithArrows(title string, options []string) ([]int, error)

SelectMultipleWithArrows presents a list of options for multiple selection with arrow keys. Space toggles selection, Enter confirms.

func SelectMultipleWithDefaults

func SelectMultipleWithDefaults(message string, options []string, preselected []int) ([]int, error)

SelectMultipleWithDefaults presents a list of options with some pre-selected. preselected is a list of indices to pre-select.

func SelectOption

func SelectOption(message string, options []string, recommended int) (int, error)

SelectOption presents a list of options with arrow-key navigation. Returns the selected index (0-based).

func SetContext

func SetContext(ctx context.Context)

SetContext sets the global context used by all UI prompts. Call this at startup with the signal handler's context.

func SetNoColor

func SetNoColor(noColor bool)

SetNoColor enables or disables colored output.

func SetVersion

func SetVersion(v string)

SetVersion sets the application version for logo rendering.

func Success

func Success(s string) string

Success formats text as success message.

func Title

func Title(s string) string

Title formats text as a title.

func Warning

func Warning(s string) string

Warning formats text as warning message.

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 KeyValue

type KeyValue struct {
	Key   string
	Value string
}

KeyValue represents a key-value pair for ordered summary output.

type Progress

type Progress struct {
	// contains filtered or unexported fields
}

Progress displays a progress indicator with animated bar.

func NewProgress

func NewProgress(message string, total int64) *Progress

NewProgress creates a new progress indicator with animated bar.

func (*Progress) Done

func (p *Progress) Done()

Done marks the progress as complete.

func (*Progress) Update

func (p *Progress) Update(current int64)

Update updates the progress.

type Spinner

type Spinner struct {
	// contains filtered or unexported fields
}

Spinner displays a spinning animation during long operations.

func NewSpinner

func NewSpinner(message string) *Spinner

NewSpinner creates a new spinner with a message.

func (*Spinner) Start

func (s *Spinner) Start()

Start begins the spinner animation.

func (*Spinner) Stop

func (s *Spinner) Stop()

Stop stops the spinner animation.

func (*Spinner) StopWithError

func (s *Spinner) StopWithError(message string)

StopWithError stops the spinner with an error message.

func (*Spinner) StopWithMessage

func (s *Spinner) StopWithMessage(message string)

StopWithMessage stops the spinner and prints a final message.

func (*Spinner) StopWithSuccess

func (s *Spinner) StopWithSuccess(message string)

StopWithSuccess stops the spinner with a success message.

func (*Spinner) StopWithWarning

func (s *Spinner) StopWithWarning(message string)

StopWithWarning stops the spinner with a warning message.

func (*Spinner) UpdateMessage

func (s *Spinner) UpdateMessage(message string)

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL