ui

package
v1.18.0 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

Variables

This section is empty.

Functions

func Env

func Env(desc, envVar string) string

Env wraps a description with a dimmed env-var hint.

func PromptPassword added in v1.4.1

func PromptPassword(prompt string) (string, error)

PromptPassword prompts the user for a password on the terminal without echoing.

func PromptPasswordConfirm added in v1.9.0

func PromptPasswordConfirm(msg string) (string, error)

PromptPasswordConfirm prompts for a password and then a confirmation. Returns an error if they don't match or are empty.

func Style added in v1.17.0

func Style(color, text string) string

Style wraps text in the given color, resetting after it.

Types

type ConsoleReporter

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

ConsoleReporter implements Reporter using go-pretty for console output.

func NewConsoleReporter

func NewConsoleReporter() *ConsoleReporter

func (*ConsoleReporter) SetDetail added in v1.18.0

func (c *ConsoleReporter) SetDetail(d Detail)

SetDetail chooses how much this reporter shows.

This is the single place verbosity is decided. Operations report what they are doing at a level; this decides which levels reach the user. Before it existed, each of the nine operations carried its own verbose option and gated its own log calls, so the same choice had nine names and nine implementations.

func (*ConsoleReporter) SetLogWriter

func (c *ConsoleReporter) SetLogWriter(w *SafeLogWriter)

SetLogWriter registers a SafeLogWriter that will be kept in sync with the active progress writer so external log lines (e.g. store debug output) render cleanly above the progress bar.

func (*ConsoleReporter) StartPhase

func (c *ConsoleReporter) StartPhase(name string, total int64, isBytes bool) Phase

type Detail added in v1.18.0

type Detail int

Detail is how much an operation should say about what it is doing.

It exists because verbosity is a presentation choice, and the code that makes presentation choices is the reporter — not the engine producing the events. Every operation used to carry its own verbose flag and gate its own log calls, which meant six option constructors for one idea and six places to change it.

const (
	// DetailNormal reports milestones: phases, counts, warnings.
	DetailNormal Detail = iota
	// DetailVerbose additionally reports per-item progress — every object
	// verified, every file restored. On a large repository this is a line per
	// object, which is why it is off by default and why Logf defers formatting.
	DetailVerbose
)

type NoOpReporter

type NoOpReporter struct{}

NoOpReporter implements Reporter doing nothing (for tests or silent mode).

func NewNoOpReporter

func NewNoOpReporter() *NoOpReporter

func (*NoOpReporter) StartPhase

func (n *NoOpReporter) StartPhase(name string, total int64, isBytes bool) Phase

type Phase

type Phase interface {
	Increment(n int64)
	// Log records a message the caller has already decided to emit.
	Log(msg string)
	// Logf records a message at a detail level, formatting the arguments only
	// if the reporter wants that level.
	//
	// The deferral is the point, not an optimization detail: per-item logging
	// runs once per object checked or file restored, so formatting a string the
	// reporter will discard is work proportional to repository size.
	Logf(level Detail, format string, args ...any)
	Done()
	Error()
}

Phase represents an active progress tracking phase.

type Reporter

type Reporter interface {
	// StartPhase starts a new progress tracking phase.
	// name: Description of the phase.
	// total: Total items/bytes to process. 0 for indeterminate.
	// isBytes: If true, units are bytes, otherwise count.
	StartPhase(name string, total int64, isBytes bool) Phase
}

Reporter defines the interface for progress reporting.

type SafeLogWriter

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

SafeLogWriter is an io.Writer that coexists with go-pretty progress bars. When a progress writer is active, lines are routed through pw.Log() so they render above the bar. Otherwise lines go straight to stderr.

func (*SafeLogWriter) ClearActive

func (w *SafeLogWriter) ClearActive()

ClearActive unregisters the progress writer.

func (*SafeLogWriter) SetActive

func (w *SafeLogWriter) SetActive(pw progress.Writer)

SetActive registers the progress writer that is currently rendering.

func (*SafeLogWriter) Write

func (w *SafeLogWriter) Write(p []byte) (n int, err error)

type TermWriter

type TermWriter struct{ W io.Writer }

TermWriter provides helpers for styled terminal output.

func NewTermWriter

func NewTermWriter(w io.Writer) TermWriter

NewTermWriter returns a TermWriter targeting the given writer.

func (TermWriter) Blank

func (t TermWriter) Blank()

func (TermWriter) Command

func (t TermWriter) Command(name, args string)

func (TermWriter) Commands

func (t TermWriter) Commands(cmds [][2]string)

func (TermWriter) Examples

func (t TermWriter) Examples(cmds ...string)

func (TermWriter) Flags

func (t TermWriter) Flags(flags [][2]string)

func (TermWriter) Heading

func (t TermWriter) Heading(title string)

func (TermWriter) HeadingSub

func (t TermWriter) HeadingSub(title, subtitle string)

func (TermWriter) Note

func (t TermWriter) Note(lines ...string)

Jump to

Keyboard shortcuts

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