style

package
v0.26.0 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: MIT Imports: 15 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package style is the one place terminal appearance is decided: colors, glyphs and the small layout helpers every human-facing surface shares, so the review interface and the one-shot commands look like one program.

docs/tui-design.md is the contract for how the review window draws a finding and its header. A change here that departs from it changes that document in the same commit.

Index

Constants

View Source
const (
	PaneRows = 2
	PaneCols = 4
)

PaneRows and PaneCols are what one pane costs: two border rows, and two border columns plus one padding column inside each side.

View Source
const ContentWidth = 110

ContentWidth caps prose, list rows and one-shot output; headers and rules still span the terminal.

View Source
const IconsEnv = "LOUPE_ICONS"

IconsEnv is the variable that overrides the tier; ValidateEnv refuses a value that is not one of Tiers.

View Source
const PillWidth = 12

PillWidth is the list's severity column: the longest label with its padding or brackets, after the blocking mark.

Variables

View Source
var Tiers = []string{"ascii", "unicode", "nerd"}

Tiers are the values IconsEnv accepts.

Functions

func Content

func Content(width int) int

Content is the width prose and rows wrap at: the terminal, capped where a line stops being readable.

func Head(text string, width int) string

Head is the first width cells of text with its styling intact and nothing added, for a caller that will put its own content where the rest was. TruncRight is the one that marks what it dropped.

func Highlight

func Highlight(path string, lines []string) ([][]CodeToken, error)

Highlight splits lines of code from path into tokens. A path whose language is unknown returns nil, which means plain code. A tokenizer failure returns the error, and the caller keeps the plain lines and says so.

func LinkableURL

func LinkableURL(url string) bool

LinkableURL is an https URL with no space, control or format character: one that cannot end an escape early, point somewhere it does not show, or reach a handler as a flag or a local file.

func Pad

func Pad(text string, width int) string

Pad right-pads text to width, measuring by cells so escapes do not count.

func PaneInner

func PaneInner(width, height int) (int, int)

PaneInner is the content rectangle of a pane whose outer rectangle is width by height.

func Relative

func Relative(t, now time.Time) string

Relative renders an instant as a coarse age for lists; the exact time stays in --json.

func ValidateEnv

func ValidateEnv(getenv func(string) string) error

ValidateEnv is the refusal for an environment loupe cannot honor.

func Width

func Width(text string) int

Width is the printed width of text, ignoring escape sequences.

Types

type CodeKind

type CodeKind int

CodeKind is what a diff line does to the file.

const (
	CodeContext CodeKind = iota
	CodeAdded
	CodeDeleted
)

type CodeRow

type CodeRow struct {
	Num    int
	Kind   CodeKind
	Cited  bool
	Text   string
	Tokens []CodeToken
}

CodeRow is one line of a hunk or file diff as the TUI parsed it. Text is the sanitized line; Tokens, when set, are the same text split by role.

type CodeToken

type CodeToken struct {
	Role TokenRole
	Text string
}

CodeToken is one run of source in one role.

type GlyphSet

type GlyphSet struct {
	Tier Tier

	Accepted  string
	Pending   string
	Excluded  string
	Withdrawn string
	Blocking  string
	Note      string
	// Question marks an apply run's finding that proposes no change and only asks.
	Question string
	Update   string
	Reply    string
	Cursor   string
	Ellipsis string
	HRule    string
	Quote    string
	// Sep joins the parts of a header.
	Sep string
	// Up, Down, Left and Right name the arrow keys in footers and help; the ASCII tier spells them out.
	Up, Down, Left, Right string

	File      string
	General   string
	PR        string
	Fix       string
	Error     string
	Published string
	Canceled  string
	Help      string
	// contains filtered or unexported fields
}

GlyphSet is the character set for states and structure. Fields that are empty in a tier have no icon there: the word beside them carries the state alone.

func Glyphs

func Glyphs(getenv func(string) string) GlyphSet

Glyphs picks the tier: a non-UTF-8 locale forces ASCII, then LOUPE_ICONS decides, then Unicode. The locale follows POSIX precedence: the first non-empty of LC_ALL, LC_CTYPE and LANG. An unknown LOUPE_ICONS value is ignored here and refused by ValidateEnv, so a command still starts far enough to explain it.

func (GlyphSet) Label

func (g GlyphSet) Label(label string) string

Label is the icon for a finding label in the one-shot commands; kinds without their own icon share the comment glyph.

type Hint

type Hint struct {
	Key, Verb string
	Role      Role
	// Unavailable is why the action cannot run now. KeyGroups draws such a hint dim, and under NO_COLOR, where dim is
	// invisible, spells the reason out in parentheses.
	Unavailable string
}

Hint is one entry on a footer.

type KeyGroup

type KeyGroup []Hint

KeyGroup is one semantic group of the footer: decide, move, or app.

type Kind

type Kind int

Kind is a semantic role; the palette maps it to a color so callers never name colors.

const (
	Plain Kind = iota
	Good
	Warn
	Bad
	Note
	Accent
	Dim
	// Caution sits between Warn and Bad. Warn and Note share one yellow, so a ramp that needs four steps between
	// good and bad has only three without it.
	Caution
)

func Severity

func Severity(word string) Kind

Severity is the role a severity word paints in. A value captured before the enum stays dim, because nothing here can say where it ranks.

type LocalPlace

type LocalPlace struct {
	Repo, Branch, Capture string
}

LocalPlace is the repository, branch and capture summary a local header names. Branch is empty on a detached head.

type Pane

type Pane struct {
	Width, Height int
	Titles        PaneTitles
	Lines         []string
	Scroll        Scroll
	Tone          Tone
	// Focus marks the pane taking the keys; its plain title becomes a solid tab in its tone.
	Focus bool
}

Pane is one titled rectangle. Lines are the content rows; fewer are padded, more are cut.

type PaneTitles

type PaneTitles struct {
	TopLeft, TopRight, BottomLeft, BottomRight string
	// TopNotice sits at the right of the top border, before TopRight, and is drawn whole or not at all; NoticeRoom
	// says whether it fits.
	TopNotice string
	// TopNoticeTab says TopNotice is a tab, padded inside its own block, so the row adds no spaces of its own and the
	// text stays in the cells it has without the block.
	TopNoticeTab bool
}

PaneTitles are the places a pane's border carries text. TopLeft is the pane's name; the others are inserted as given, so a caller styles a notice or a count with the roles here.

type ProgressState

type ProgressState int

ProgressState is one counted finding's place in the progress bar, in the order grouped cells take and the precedence a finding's state follows: accepted, excluded, pending with an open note, pending blocking, pending.

const (
	ProgressAccepted ProgressState = iota
	ProgressExcluded
	ProgressNote
	ProgressBlocking
	ProgressPending
)

func ProgressCells

func ProgressCells(order []ProgressState) []ProgressState

ProgressCells is the bar's cells. Up to 30 findings it is the findings themselves in list order. Above that every nonempty state gets one cell, then the remaining cells go by each state's share rounded down, then to the largest remainders in state order. The cells approximate; the exact count is always printed beside them.

type ReviewHeading

type ReviewHeading struct {
	Ref, URL string
	// Author is the pull request author's login, already sanitized for display; empty for none.
	Author   string
	Round    int
	Title    string
	Progress []ProgressState
	// Current is the counted finding the bar marks, counting from 1, or 0 for none.
	Current        int
	Decided, Total int
	// NoCount leaves out the progress and the count, for the standalone confirmation, which has no draft.
	NoCount bool
	// Reserve is the columns at the right end left empty for a host that draws over them. The band still runs under
	// them, so the host's controls sit on it rather than in a gap.
	Reserve int
	// Tag is the pull request's live state when it needs the human's eye, such as "PR merged"; empty for none
	// (specs/050-pr-state-awareness).
	Tag string
	// Badges are a local run's mode badge, longest form first. The header draws the longest its width tier allows
	// and that fits, and gives it up only after the title, the bar and the round.
	Badges []string
	// Local is where a local run's work lives. It replaces the ref, which a local header does not show.
	Local *LocalPlace
}

ReviewHeading is what the one-row header shows. Ref and Title are already sanitized for display; URL is the pull request, linked only when Link accepts it.

type ReviewLayout

type ReviewLayout struct{ Width, Height, Footer int }

ReviewLayout is the shell's rectangles: one header row, the body, and the measured footer. There is no notice row; a notice belongs to the pane it is about.

func (ReviewLayout) Body

func (l ReviewLayout) Body() int

Body is the rows between the header, with its gap, and the footer.

func (ReviewLayout) Gap

func (l ReviewLayout) Gap() int

Gap is the blank rows between the header and the body.

type Role

type Role int

Role is what a footer hint is for, which decides when it gives way.

const (
	// RoleRequired never gives way.
	RoleRequired Role = iota
	// RoleNav is navigation prose, the first to go.
	RoleNav
	// RoleDecision is a decision key; at the last step decisions collapse to their keys.
	RoleDecision
	// RoleFile goes after navigation.
	RoleFile
	// RoleHelp never gives way.
	RoleHelp
)

type Scroll

type Scroll struct{ Offset, Visible, Total, Top int }

Scroll is where a pane's content sits in a longer document. A Total no greater than Visible draws no thumb. Top is the pane rows above the document, pinned while it scrolls, which the thumb leaves alone.

type Span

type Span struct {
	Text  string
	Style lipgloss.Style
}

Span is one piece of a painted row: text in a foreground-only style.

type Style

type Style struct {
	Dark   bool
	Glyphs GlyphSet
	Color  bool

	Bold, Dim, Accent, Good, Warn, Bad, Note, Head, Cursor lipgloss.Style
	Caution                                                lipgloss.Style
	Selected                                               lipgloss.Style
	// contains filtered or unexported fields
}

Style renders text for one output. Color is false under NO_COLOR or when the output is not a terminal; then no escape sequence is emitted at all and the glyphs and words carry every state.

func New

func New(out io.Writer, getenv func(string) string) Style

New builds styles for one output and its environment.

func (Style) ApplyBadge

func (s Style) ApplyBadge(text string) string

ApplyBadge is a local run's mode badge: a tab in the apply color, or the text in brackets without color.

func (Style) BlockingMark

func (s Style) BlockingMark() lipgloss.Style

Marker roles for the finding title: blocking in red, an open note in yellow once it has a reply and dim before.

func (Style) Brand

func (s Style) Brand() string

Brand is the program name as it appears at the head of every screen.

func (Style) Bullet

func (s Style) Bullet() string

Bullet marks an item of the expanded summary.

func (Style) Checkbox

func (s Style) Checkbox(on bool) string

Checkbox is a toggle's state in brackets, which reads the same with or without color.

func (Style) Chip

func (s Style) Chip(text string, t Tone) string

Chip is a short status word in its tone's color on a tint of it, set apart the way a label or severity pill is. Without color it is the word alone.

func (Style) CodeLine

func (s Style) CodeLine(r CodeRow, numWidth, width int) string

CodeLine draws one diff line: the citation bar, the line number right-aligned in numWidth cells, the diff sign in green or red and the code, on the winning background and padded to width. A cited line's neutral band wins over the add and delete tints, so the sign is what still tells an added cited line from a removed one. Under NO_COLOR the citation is a > and nothing is padded.

func (Style) ColumnHead

func (s Style) ColumnHead() lipgloss.Style

ColumnHead is a list's column headings: bold secondary, so they read apart from the overlay text that decided rows and path prefixes recede to.

func (Style) Composite

func (s Style) Composite(base string, pane []string, width, top, height int) string

Composite lays pane over base with lipgloss layers, centered across width and down the rows from top to height. The pane is opaque: the base shows only around it.

func (Style) ConfidenceScale

func (s Style) ConfidenceScale(word string) string

ConfidenceScale is three cells for a stated confidence and nothing for a missing or unknown one, which must not read as a rating.

func (Style) Counts

func (s Style) Counts(accepted, pending, excluded, withdrawn, openNotes, width int) []string

Counts is the readiness tally as glyph pairs, one line when it fits width; zero excluded and withdrawn fade so the live numbers stand out. Narrower, the zero counts go and the gaps tighten, and then the tally splits over two lines.

func (Style) Disposition

func (s Style) Disposition(disposition string) (glyph, word string, k Kind)

Disposition is the glyph, word and kind for a finding's state.

func (Style) Emphasis

func (s Style) Emphasis(st lipgloss.Style) lipgloss.Style

Emphasis applies bold only when the output supports styling.

func (Style) Field

func (s Style) Field(name string, nameWidth int, items []string, sep string, width int) []string

Field is one line of a vertical list: a dim name in a column nameWidth cells wide after a two-cell indent, then the items joined by sep. It breaks only between items where it can, each further line hangs under the first item, and an item wider than the value column word-wraps.

func (Style) Heading

func (s Style) Heading(text string) string

Heading is a section title in sentence case.

func (Style) HintTitle

func (s Style) HintTitle(text string) string

HintTitle is a pane title that tells the human what a key does or where they are, in plain text.

func (Style) InputTitle

func (s Style) InputTitle(text string) string

InputTitle is a pane title that names the input taking the keys, in the note color, so focus reads without the border.

func (Style) KeyGroups

func (s Style) KeyGroups(groups []KeyGroup, width int) []string

KeyGroups lays out the footer: each key in the accent and its verb in secondary, the groups in order with a dim bar between them, empty groups left out. The verb steps back so the key leads, but only to secondary: the overlay gray is an unavailable hint's, and a live verb in it would read as disabled. It wraps between whole groups where that costs no extra row, and otherwise between hints; a bar that would end or start a row is dropped, since the row break separates the groups there.

func (s Style) Link(url, text string) string

Link makes text a terminal hyperlink to url where escapes are drawn. A URL that LinkableURL refuses stays text.

func (Style) LocationTitle

func (s Style) LocationTitle(location string, width int, bright bool) string

LocationTitle is a path:line location cut from the left to width, the directory dim and the filename bright, so the part that names the file survives and stands out.

func (Style) Muted

func (s Style) Muted(screen string) string

Muted redraws a screen as the dimmed layer under an overlay: its text kept, its colors replaced by one muted role. Under NO_COLOR nothing dims, and the overlay's border alone sets it apart.

func (Style) NewStyle

func (s Style) NewStyle() lipgloss.Style

NewStyle creates an unadorned layout style.

func (Style) NoteMark

func (s Style) NoteMark(replied bool) lipgloss.Style

func (Style) NoticeRoom

func (s Style) NoticeRoom(p Pane) int

NoticeRoom is the widest notice text p's top border holds whole between its titles, beside the space on each side of it and the rule cell after it.

func (Style) Of

func (s Style) Of(k Kind) lipgloss.Style

Of returns the foreground style for a kind.

func (Style) OnSurface

func (s Style) OnSurface(sf Surface, rendered string) string

OnSurface puts a surface behind an already-rendered string, putting it back after every reset inside, so pieces with no background of their own sit on the band and a pill keeps its own fill.

func (Style) Overlay

func (s Style) Overlay() lipgloss.Style

func (Style) Pane

func (s Style) Pane(p Pane) []string

Pane draws p as exactly Height rows of exactly Width cells.

func (Style) PickerCursor

func (s Style) PickerCursor() string

PickerCursor is the marker of the chosen publish option: the tier's cursor, or > where color cannot show it.

func (Style) Progress

func (s Style) Progress(order []ProgressState, current int) string

Progress draws the bar: one joined ▮ per cell in its state's color, or the state characters where color or the glyph is not available. ● is reserved for blocking and never appears here. current is the counted finding to mark, counting from 1, or 0 for none; its cell sits on the accent while each cell is one finding.

func (Style) Readiness

func (s Style) Readiness(ready bool, pending, openNotes int) string

Readiness is the concise publication state: ready to publish, or what remains.

func (Style) Render

func (s Style) Render(text string) string

Render adapts component output to the same profile as the palette.

func (Style) ReviewDisposition

func (s Style) ReviewDisposition(disposition string) (glyph string, mark, row lipgloss.Style)

ReviewDisposition is the list's state glyph for a disposition and the style a row's text recedes to: accepted rows step back to secondary text, excluded and withdrawn rows to overlay text, and pending rows stay full.

func (Style) ReviewFrame

func (s Style) ReviewFrame(header string, body, footer []string, width, height int) string

ReviewFrame stacks the header, the body cut or padded to its rows, and the footer into exactly height rows.

func (Style) ReviewHeader

func (s Style) ReviewHeader(h ReviewHeading, width int) string

ReviewHeader is the one-row header: the badge, the linked pull request, its author, the round and its title at the left, and the state tag, the progress and the bold exact count at the right, on the surface band. The round gives way first, then the author, both before the title would keep fewer than headerTitleRoom cells, then the title, then the bar, and then the reference shortens in its middle. The tag and the count never give way.

func (Style) Rule

func (s Style) Rule(width int, title, right string) string

Rule is a horizontal rule, optionally titled at its left edge and labeled at its right.

func (Style) Secondary

func (s Style) Secondary() lipgloss.Style

func (Style) Section

func (s Style) Section(t Tone, heading, chip string, body []string) []string

Section is one block of a finding: a bold heading in its tone, then its chip, if any, then each body line behind a bar in the same tone. A blank body line keeps the bar, so the section reads as one block. Without color the chip is a bare word, so a separator stands between it and the heading. docs/tui-design.md owns these rules.

func (Style) Selection

func (s Style) Selection() string

Selection is the marker of the selected row: a bar in the accent, or > where color cannot show the band.

func (*Style) SetColorProfile

func (s *Style) SetColorProfile(profile colorprofile.Profile)

SetColorProfile rebuilds the palette for an output capability, including injected test outputs.

func (*Style) SetDarkBackground

func (s *Style) SetDarkBackground(dark bool)

SetDarkBackground applies one background result to every palette color.

func (Style) SeverityCell

func (s Style) SeverityCell(word string, blocking bool, width int) string

SeverityCell is the list's severity column: the pill, with the blocking mark after the label on the pill's fill, so every label starts in the same column, padded to width. A blocking finding with no rating shows the mark alone, where the pill would start.

func (Style) SeverityPill

func (s Style) SeverityPill(word string, width int) string

SeverityPill is the severity as an uppercase pill in the hue its published SVG uses, padded to width; zero width is the compact pill. An empty word is blank, never a stand-in rating. A word outside the scale keeps the gray.

func (Style) Speaker

func (s Style) Speaker(name string, you bool) string

Speaker is a thread author's name as a bold chip: you in the accent on its tint, anyone else in text on the raised surface, so the agent reads as a peer rather than as receded text. Without color it is the bold name alone.

func (Style) SurfaceSpan

func (s Style) SurfaceSpan(sf Surface, width int, spans ...Span) string

SurfaceSpan paints spans onto one surface and pads them to width, every piece carrying the background so that no reset inside the row cuts the band. A width of zero pads nothing.

func (Style) Tabs

func (s Style) Tabs(names []string, active int) string

Tabs is the publish steps as a sequence: done steps checked in good, the current one on a solid accent block, later ones dim, joined by arrows. Only the current step is a block, so it is the one thing that stands out; without color it is bracketed.

func (Style) Tag

func (s Style) Tag(text string, blocking bool) string

Tag is a finding attribute in the detail's metadata line: tinted text, or bracketed under NO_COLOR so its extent still shows.

func (Style) Text

func (s Style) Text() lipgloss.Style

Text is the theme's ordinary foreground; Secondary and Overlay are the two receding steps under it.

func (Style) TitleTab

func (s Style) TitleTab(text string, t Tone) string

TitleTab is a focused pane's title: the text in bold on a solid block of its tone, like the badge. Without color it is the text alone.

func (Style) TitleTag

func (s Style) TitleTag(text string) string

TitleTag is a word a pane title adds after its subject to name the view, bold in the accent.

func (Style) ToneStyle

func (s Style) ToneStyle(t Tone) lipgloss.Style

ToneStyle is the foreground a tone draws in, and nothing where color is off.

func (Style) TruncLeft

func (s Style) TruncLeft(text string, width int) string

TruncLeft keeps the tail, for paths whose filename matters more than their directory.

func (Style) TruncRight

func (s Style) TruncRight(text string, width int) string

TruncRight keeps the head of a line that is too wide, ending it with the ellipsis glyph.

func (*Style) UseReviewTheme

func (s *Style) UseReviewTheme()

UseReviewTheme switches this Style to the interactive review theme: the lavender accent and the review palette. The global accent stays for every command that does not call it.

func (Style) Verified

func (s Style) Verified(word string) string

Verified is the verification word, a check before a reproduced finding.

func (Style) WarnTitle

func (s Style) WarnTitle(text string, strong bool) string

WarnTitle is a pane title part that warns about what a step will do, in the warn color, bold when strong.

func (Style) Wrap

func (s Style) Wrap(text string, width int, indent string) string

Wrap word-wraps prose to width and prefixes every line with indent. Existing newlines are kept. Hyphens are hidden from the wrapper, which would otherwise split paths and identifiers such as gadfly-review-local at every dash.

type Surface

type Surface int

Surface is the band a row is painted on.

const (
	SurfaceNone Surface = iota
	// SurfaceSelected is the selected finding row.
	SurfaceSelected
	// SurfaceHeader is the one-row header.
	SurfaceHeader
	SurfaceAdded
	SurfaceDeleted
	// SurfaceCited is a line a finding cites; it wins over the added and deleted tints.
	SurfaceCited
)

type Tier

type Tier int

Tier is which character repertoire the terminal is trusted to draw.

const (
	// ASCII is forced by a non-UTF-8 locale and chosen by LOUPE_ICONS=ascii.
	ASCII Tier = iota
	// Unicode is the box-drawing and dingbat set any UTF-8 terminal font carries; it is the default under UTF-8.
	Unicode
	// Nerd adds the private-use icons a Nerd Font patches in, chosen only by LOUPE_ICONS=nerd.
	Nerd
)

type TokenRole

type TokenRole int

TokenRole is the muted foreground a syntax token takes. Chroma supplies the boundaries; these roles, not a Chroma theme, decide the color, so most code stays neutral text.

const (
	TokenNeutral TokenRole = iota
	TokenKeyword
	TokenString
	TokenNumber
	TokenComment
)

type Tone

type Tone int

Tone is the color a pane's border takes. The accent is the default; a finding's or a note's status may set another.

const (
	ToneAccent Tone = iota
	ToneGood
	ToneNote
	ToneMuted
)

Jump to

Keyboard shortcuts

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