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
- Variables
- func Content(width int) int
- func Head(text string, width int) string
- func Highlight(path string, lines []string) ([][]CodeToken, error)
- func LinkableURL(url string) bool
- func Pad(text string, width int) string
- func PaneInner(width, height int) (int, int)
- func Relative(t, now time.Time) string
- func ValidateEnv(getenv func(string) string) error
- func Width(text string) int
- type CodeKind
- type CodeRow
- type CodeToken
- type GlyphSet
- type Hint
- type KeyGroup
- type Kind
- type LocalPlace
- type Pane
- type PaneTitles
- type ProgressState
- type ReviewHeading
- type ReviewLayout
- type Role
- type Scroll
- type Span
- type Style
- func (s Style) ApplyBadge(text string) string
- func (s Style) BlockingMark() lipgloss.Style
- func (s Style) Brand() string
- func (s Style) Bullet() string
- func (s Style) Checkbox(on bool) string
- func (s Style) Chip(text string, t Tone) string
- func (s Style) CodeLine(r CodeRow, numWidth, width int) string
- func (s Style) ColumnHead() lipgloss.Style
- func (s Style) Composite(base string, pane []string, width, top, height int) string
- func (s Style) ConfidenceScale(word string) string
- func (s Style) Counts(accepted, pending, excluded, withdrawn, openNotes, width int) []string
- func (s Style) Disposition(disposition string) (glyph, word string, k Kind)
- func (s Style) Emphasis(st lipgloss.Style) lipgloss.Style
- func (s Style) Field(name string, nameWidth int, items []string, sep string, width int) []string
- func (s Style) Heading(text string) string
- func (s Style) HintTitle(text string) string
- func (s Style) InputTitle(text string) string
- func (s Style) KeyGroups(groups []KeyGroup, width int) []string
- func (s Style) Link(url, text string) string
- func (s Style) LocationTitle(location string, width int, bright bool) string
- func (s Style) Muted(screen string) string
- func (s Style) NewStyle() lipgloss.Style
- func (s Style) NoteMark(replied bool) lipgloss.Style
- func (s Style) NoticeRoom(p Pane) int
- func (s Style) Of(k Kind) lipgloss.Style
- func (s Style) OnSurface(sf Surface, rendered string) string
- func (s Style) Overlay() lipgloss.Style
- func (s Style) Pane(p Pane) []string
- func (s Style) PickerCursor() string
- func (s Style) Progress(order []ProgressState, current int) string
- func (s Style) Readiness(ready bool, pending, openNotes int) string
- func (s Style) Render(text string) string
- func (s Style) ReviewDisposition(disposition string) (glyph string, mark, row lipgloss.Style)
- func (s Style) ReviewFrame(header string, body, footer []string, width, height int) string
- func (s Style) ReviewHeader(h ReviewHeading, width int) string
- func (s Style) Rule(width int, title, right string) string
- func (s Style) Secondary() lipgloss.Style
- func (s Style) Section(t Tone, heading, chip string, body []string) []string
- func (s Style) Selection() string
- func (s *Style) SetColorProfile(profile colorprofile.Profile)
- func (s *Style) SetDarkBackground(dark bool)
- func (s Style) SeverityCell(word string, blocking bool, width int) string
- func (s Style) SeverityPill(word string, width int) string
- func (s Style) Speaker(name string, you bool) string
- func (s Style) SurfaceSpan(sf Surface, width int, spans ...Span) string
- func (s Style) Tabs(names []string, active int) string
- func (s Style) Tag(text string, blocking bool) string
- func (s Style) Text() lipgloss.Style
- func (s Style) TitleTab(text string, t Tone) string
- func (s Style) TitleTag(text string) string
- func (s Style) ToneStyle(t Tone) lipgloss.Style
- func (s Style) TruncLeft(text string, width int) string
- func (s Style) TruncRight(text string, width int) string
- func (s *Style) UseReviewTheme()
- func (s Style) Verified(word string) string
- func (s Style) WarnTitle(text string, strong bool) string
- func (s Style) Wrap(text string, width int, indent string) string
- type Surface
- type Tier
- type TokenRole
- type Tone
Constants ¶
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.
const ContentWidth = 110
ContentWidth caps prose, list rows and one-shot output; headers and rules still span the terminal.
const IconsEnv = "LOUPE_ICONS"
IconsEnv is the variable that overrides the tier; ValidateEnv refuses a value that is not one of Tiers.
const PillWidth = 12
PillWidth is the list's severity column: the longest label with its padding or brackets, after the blocking mark.
Variables ¶
var Tiers = []string{"ascii", "unicode", "nerd"}
Tiers are the values IconsEnv accepts.
Functions ¶
func Content ¶
Content is the width prose and rows wrap at: the terminal, capped where a line stops being readable.
func Head ¶
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 ¶
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 ¶
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 PaneInner ¶
PaneInner is the content rectangle of a pane whose outer rectangle is width by height.
func Relative ¶
Relative renders an instant as a coarse age for lists; the exact time stays in --json.
func ValidateEnv ¶
ValidateEnv is the refusal for an environment loupe cannot honor.
Types ¶
type CodeRow ¶
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 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 ¶
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.
type Hint ¶
type Hint struct {
Key, Verb string
Role Role
// 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.
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
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 ¶
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 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 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 (Style) ApplyBadge ¶
ApplyBadge is a local run's mode badge: a tab in the apply color, or the text in brackets without color.
func (Style) BlockingMark ¶
Marker roles for the finding title: blocking in red, an open note in yellow once it has a reply and dim before.
func (Style) Checkbox ¶
Checkbox is a toggle's state in brackets, which reads the same with or without color.
func (Style) Chip ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
Disposition is the glyph, word and kind for a finding's state.
func (Style) Field ¶
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) HintTitle ¶
HintTitle is a pane title that tells the human what a key does or where they are, in plain text.
func (Style) InputTitle ¶
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 ¶
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 (Style) Link ¶
Link makes text a terminal hyperlink to url where escapes are drawn. A URL that LinkableURL refuses stays text.
func (Style) LocationTitle ¶
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 ¶
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) NoticeRoom ¶
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) OnSurface ¶
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) PickerCursor ¶
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 ¶
Readiness is the concise publication state: ready to publish, or what remains.
func (Style) ReviewDisposition ¶
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 ¶
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, 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 title gives way first, then the bar, then the round, and then the reference shortens in its middle. The tag and the count never give way.
func (Style) Rule ¶
Rule is a horizontal rule, optionally titled at its left edge and labeled at its right.
func (Style) Section ¶
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 ¶
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 ¶
SetDarkBackground applies one background result to every palette color.
func (Style) SeverityCell ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
Text is the theme's ordinary foreground; Secondary and Overlay are the two receding steps under it.
func (Style) TitleTab ¶
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 ¶
TitleTag is a word a pane title adds after its subject to name the view, bold in the accent.
func (Style) ToneStyle ¶
ToneStyle is the foreground a tone draws in, and nothing where color is off.
func (Style) TruncLeft ¶
TruncLeft keeps the tail, for paths whose filename matters more than their directory.
func (Style) TruncRight ¶
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) WarnTitle ¶
WarnTitle is a pane title part that warns about what a step will do, in the warn color, bold when strong.
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 )