Documentation
¶
Overview ¶
Package style holds how modctl looks in a terminal, so that no command formats its own output:
- the styles, in two layers: the palette (palette.go) of named ANSI colors, and the roles (roles.go), styles named for what they are used for and defined in terms of the palette;
- aligned label/value lines (kv.go) and tables (table.go);
- formatting of sizes, times and hashes (format.go).
Commands should use a role. If a function has no role yet, add one rather than reaching for a palette color, so that restyling a function is a one-line change here instead of a search through the commands.
Index ¶
- Variables
- func ActiveDot() string
- func Age(t time.Time) string
- func AgeAt(now, t time.Time) string
- func Bytes(n int64) string
- func Duration(d time.Duration) string
- func Fprint(w io.Writer, a ...any) (int, error)
- func Fprintf(w io.Writer, format string, a ...any) (int, error)
- func Fprintln(w io.Writer, a ...any) (int, error)
- func InactiveDot() string
- func Print(a ...any) (int, error)
- func Printf(format string, a ...any) (int, error)
- func Println(a ...any) (int, error)
- func ShortSha(sha string) string
- func Table(headers []string, rows [][]string) string
- type KV
Constants ¶
This section is empty.
Variables ¶
var ( Green = fg("2") BrightGreen = fg("10") Red = fg("1") BrightRed = fg("9") Yellow = fg("3") BrightYellow = fg("11") Cyan = fg("6") BrightCyan = fg("14") BrightBlue = fg("12") White = fg("7") // light gray Gray = fg("8") // "bright black" )
The palette. These are the 16 ANSI colors that modctl uses (the terminal's theme decides what they actually look like), plus the two grays.
Messages: a line that reports how something went. These use the plain (non-bright) colors.
var ( Added = BrightGreen Removed = BrightRed Changed = BrightYellow Restored = BrightCyan Unchanged = Gray Hunk = Cyan // diff hunk headers )
Changes: markers and lines in plans, diffs and previews. These use the bright colors.
var ( Active = BrightGreen Inactive = Gray Good = BrightGreen Bad = BrightRed Pending = BrightYellow )
State: the state of an item in a list or on a status screen. These use the bright colors, like the change markers.
var ( Bold = lipgloss.NewStyle().Bold(true) Title = Bold Subtle = lipgloss.NewStyle().Foreground(subtleColor(lipgloss.Writer.Profile)) // secondary text Dim = Gray // de-emphasized text Label = White // field labels; use Label.Width(n) in aligned lists Header = Bold.Foreground(lipgloss.Color("63")) Section = Bold.MarginTop(1) )
Text
var ( ActiveTag = BrightGreen.Bold(true) // "(active)" PrimaryTag = Cyan // "(primary)" UpdateAvailable = BrightYellow.Bold(true) DryRun = BrightBlue ContextBadge = lipgloss.NewStyle(). Foreground(lipgloss.Color("0")). Background(lipgloss.Color("10")). Padding(0, 1). Bold(true) )
Tags and badges
var ( Card = lipgloss.NewStyle(). Border(lipgloss.RoundedBorder()). Padding(0, 1) Banner = lipgloss.NewStyle(). Foreground(lipgloss.Color("11")). Border(lipgloss.NormalBorder()). BorderForeground(lipgloss.Color("11")). Padding(0, 1) )
Containers
Functions ¶
func ActiveDot ¶
func ActiveDot() string
ActiveDot and InactiveDot are the dots that mark an active or inactive item. They are functions so that they render when called, not when the program starts.
func Bytes ¶
Bytes renders a byte count as a human-readable size, such as "1.5 KB". Sizes are in powers of 1024.
func Duration ¶
Duration renders a length of time compactly, such as "1h 5m" or "30s", for things that happen in the future (a quota reset, say). Zero or negative durations render as "now".
func InactiveDot ¶
func InactiveDot() string
Types ¶
type KV ¶
type KV struct {
Indent int
Width int
// Dim renders the whole line dimmed, for items that are inactive.
Dim bool
}
KV lays out label/value lines so that the values line up:
ID: 3 Store: steam
Each line is Indent spaces, the label padded to Width, a space and then the value. Use one KV per group of lines and write all of them through it, so that they stay aligned. Width must be at least the length of the longest label: lipgloss wraps a label that is wider.