ui

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2026 License: MPL-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package ui is the presentation layer of the fxvcs CLI: headers, footers, aligned tables, item rows with a state word (and an optional symbol on a terminal), hints, byte formatting, and plural helpers. It holds no business logic and knows nothing about repositories; commands hand it already computed facts.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bytes

func Bytes(n int64) string

Bytes formats a byte count in human units (B, KiB, MiB, GiB, ...).

func Count

func Count(n int, noun string) string

Count returns "<n> <noun>" with a regular English plural (adds "s").

func Detect

func Detect(mode string, w io.Writer, isTerminal func(io.Writer) bool) bool

Detect decides whether decoration is on: mode is "always", "never", or "auto" (the default: on when w is a terminal and NO_COLOR is unset).

func IsTerminal

func IsTerminal(w io.Writer) bool

IsTerminal reports whether w is a character device (an interactive terminal) without any platform-specific system call.

func Plural

func Plural(n int, one, many string) string

Plural returns "<n> <one>" or "<n> <many>".

func ShortID

func ShortID(digest string) string

ShortID abbreviates a content digest for verbose output.

func SignedBytes

func SignedBytes(n int64) string

SignedBytes formats a size difference with its direction: "+2.4 MiB", "-1.1 MiB", or "same size" for a change that kept the byte count. It is what a managed asset has instead of a line count, because a diff of two placeholders says one line changed however many megabytes moved.

func Size

func Size(w io.Writer) (width, height int, ok bool)

Size reports the terminal dimensions of w. ok is false when w is not a terminal, which is the caller's cue to use a fixed layout rather than guessing at a width.

Types

type Item

type Item struct {
	State State
	Label string
	Path  string
	Size  string
	Note  string
}

Item is one row of a command body: a state, its label word, the repository-relative path, an already formatted size (or ""), and a note.

type Options

type Options struct {
	// Color enables ANSI colours and the state symbols. Callers decide from
	// the terminal, NO_COLOR, and --color; see Detect.
	Color bool
	// Quiet suppresses everything except errors; renderers check Quiet
	// before printing.
	Quiet bool
	// Verbose lets renderers add digests, codes, and internal paths.
	Verbose bool
}

Options controls decoration and verbosity.

type Printer

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

Printer writes formatted output to one writer.

func New

func New(w io.Writer, opts Options) *Printer

New creates a Printer for w.

func (*Printer) Blank

func (p *Printer) Blank()

Blank prints an empty line.

func (*Printer) Color

func (p *Printer) Color() bool

Color reports whether decoration is on.

func (*Printer) Footer

func (p *Printer) Footer(text string)

Footer prints the closing summary preceded by a blank line.

func (*Printer) Header

func (p *Printer) Header(command, summary string)

Header prints the first line of a command's output: "fxvcs <command> — <summary>".

func (*Printer) Hint

func (p *Printer) Hint(command string)

Hint prints an indented "hint:" line with an exact next command.

func (*Printer) Items

func (p *Printer) Items(items []Item)

Items prints item rows as an aligned, two-space indented table: [symbol] label path size note.

func (*Printer) Line

func (p *Printer) Line(format string, args ...any)

Line prints one plain line.

func (*Printer) List

func (p *Printer) List(entries []string)

List prints one indented line per entry.

func (*Printer) Quiet

func (p *Printer) Quiet() bool

Quiet reports --quiet.

func (*Printer) Table

func (p *Printer) Table(rows [][]string)

Table prints rows as aligned columns, two-space indented; the first row may be a header (callers pass it like any other row).

func (*Printer) Verbose

func (p *Printer) Verbose() bool

Verbose reports --verbose.

func (*Printer) Verbosef

func (p *Printer) Verbosef(format string, args ...any)

Verbosef prints only under --verbose.

func (*Printer) Writer

func (p *Printer) Writer() io.Writer

Writer returns the underlying writer.

type State

type State int

State classifies an item row. The word printed next to it is always present; the symbol and colour are decoration on a terminal only.

const (
	OK      State = iota // ✓ done, loaded, present
	Pending              // ○ placeholder, not yet done
	Warn                 // ! needs attention, changed locally
	Fail                 // ✗ failed
	Skip                 // – skipped, refused
	Plain                // no symbol
)

Row states.

Directories

Path Synopsis
Package live is the interactive progress view: a bounded, in-place display of an operation that touches many files.
Package live is the interactive progress view: a bounded, in-place display of an operation that touches many files.

Jump to

Keyboard shortcuts

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