style

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2026 License: GPL-3.0 Imports: 8 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
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.

View Source
var (
	Success = Green
	Failure = Red.Bold(true)
	Warning = Yellow
	Info    = Cyan
)

Messages: a line that reports how something went. These use the plain (non-bright) colors.

View Source
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.

View Source
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.

View Source
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

View Source
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

View Source
var (
	Card = lipgloss.NewStyle().
			Border(lipgloss.RoundedBorder()).
			Padding(0, 1)
			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 Age

func Age(t time.Time) string

Age renders how long ago t was, such as "3 hours ago".

func AgeAt

func AgeAt(now, t time.Time) string

AgeAt is Age relative to now rather than the current time.

func Bytes

func Bytes(n int64) string

Bytes renders a byte count as a human-readable size, such as "1.5 KB". Sizes are in powers of 1024.

func Duration

func Duration(d time.Duration) string

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 Fprint

func Fprint(w io.Writer, a ...any) (int, error)

Fprint prints to w, like fmt.Fprint.

func Fprintf

func Fprintf(w io.Writer, format string, a ...any) (int, error)

Fprintf prints formatted text to w, like fmt.Fprintf.

func Fprintln

func Fprintln(w io.Writer, a ...any) (int, error)

Fprintln prints to w followed by a newline, like fmt.Fprintln.

func InactiveDot

func InactiveDot() string

func Print

func Print(a ...any) (int, error)

Print prints to standard output, like fmt.Print.

func Printf

func Printf(format string, a ...any) (int, error)

Printf prints formatted text to standard output, like fmt.Printf.

func Println

func Println(a ...any) (int, error)

Println prints to standard output followed by a newline, like fmt.Println.

func ShortSha

func ShortSha(sha string) string

ShortSha shortens a hash for display: the first 16 characters followed by "...". A hash that is already that short is returned as it is.

func Table

func Table(headers []string, rows [][]string) string

Table renders rows under a header as a table. Cells are rendered as they are given, so pad them (for example with spaces on either side) if you want them to have some room.

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.

func (KV) Line

func (kv KV) Line(label, value string) string

Line returns the line for a label and value, including the newline.

func (KV) Print

func (kv KV) Print(label, value string)

Print prints the line for a label and value.

func (KV) Write

func (kv KV) Write(b *strings.Builder, label, value string)

Write adds the line for a label and value to b.

Jump to

Keyboard shortcuts

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