Documentation
¶
Overview ¶
Package ui holds every terminal UI component: lipgloss styles, the reusable stack tree renderer and the bubbletea checkout picker. It is the only package allowed to import Charm libraries.
Index ¶
- Variables
- func Busy(w io.Writer, enabled bool) func()
- func FuzzyMatch(s, q string) (bool, []int)
- func Hyperlink(enabled bool, url, text string) string
- func RelativeTime(t, now time.Time) string
- func RenderLog(v *app.View, o LogOptions) string
- func RenderRow(tr TreeRow, o RenderOptions) string
- func RenderTree(rows []TreeRow, o RenderOptions) string
- func WithSpinner(ctx context.Context, in io.Reader, out io.Writer, message string, ...) error
- type LogOptions
- type Picker
- type PickerOptions
- type PickerResult
- type Prompter
- type RenderOptions
- type Reporter
- func (r *Reporter) Branch(name string) string
- func (r *Reporter) Error(err error)
- func (r *Reporter) Info(format string, args ...any)
- func (r *Reporter) Link(url string) string
- func (r *Reporter) Links() bool
- func (r *Reporter) Print(block string)
- func (r *Reporter) Quiet() bool
- func (r *Reporter) Ref(number int, url string) string
- func (r *Reporter) SHA(sha string) string
- func (r *Reporter) Step(ctx context.Context, phase app.Phase, message string, ...) error
- func (r *Reporter) Stream() io.Writer
- func (r *Reporter) Styles() Styles
- func (r *Reporter) Success(format string, args ...any)
- func (r *Reporter) Warn(format string, args ...any)
- type ReporterOptions
- type Styles
- type TreeRow
Constants ¶
This section is empty.
Variables ¶
var ErrCancelled = fmt.Errorf("cancelled")
ErrCancelled is returned when the user dismisses a prompt.
Functions ¶
func Busy ¶
Busy marks the terminal as busy with an indeterminate progress indicator (a pulsing tab or taskbar entry, depending on the terminal) and returns a function that clears it. With enabled false (not a terminal) it does nothing. Terminals without OSC 9;4 support ignore the sequence.
func FuzzyMatch ¶
FuzzyMatch reports whether q is a case-insensitive subsequence of s and returns the matched rune indices.
func Hyperlink ¶
Hyperlink wraps text in an OSC 8 hyperlink to url when enabled, so terminals such as Ghostty, iTerm2 and WezTerm make it clickable. With enabled false (not a terminal) or an empty url it returns text unchanged.
func RelativeTime ¶
RelativeTime renders t relative to now ("3h ago").
func RenderLog ¶
func RenderLog(v *app.View, o LogOptions) string
RenderLog renders every stack the way `gt log` does: trunk at the bottom, each stack a column rising from it, newest branch at the top, with the pull request and age under each branch name.
● feat-b │ #13 draft · 2d ago │ ○ feat-a │ #12 open · 3h ago │ │ ○ hotfix │ │ no PR · 1w ago ├─┘ ■ main
Untracked branches are not shown. It returns "" when there are no stacks.
func RenderRow ¶
func RenderRow(tr TreeRow, o RenderOptions) string
RenderRow renders one tree row: prefix, name, PR, restack marker, age and worktree.
func RenderTree ¶
func RenderTree(rows []TreeRow, o RenderOptions) string
RenderTree renders every row, one per line, without selection.
Types ¶
type LogOptions ¶
type LogOptions struct {
Styles Styles
Now time.Time
// Links makes PR references OSC 8 hyperlinks.
Links bool
}
LogOptions controls RenderLog.
type Picker ¶
type Picker struct {
// contains filtered or unexported fields
}
Picker is the bubbletea model. It is exported for tests.
func NewPicker ¶
func NewPicker(ctx context.Context, o PickerOptions) *Picker
NewPicker builds the model.
func (*Picker) Result ¶
func (p *Picker) Result() PickerResult
Result returns the choice once the program has finished.
type PickerOptions ¶
type PickerOptions struct {
Rows []app.Row
// Refresh, when set, is run in the background; its result updates the
// PR decorations while the picker is open.
Refresh func(ctx context.Context) ([]forge.PullRequest, error)
// Styles defaults to DefaultStyles when nil.
Styles *Styles
Now time.Time
// Height limits the number of visible rows (0: derive from the terminal).
Height int
}
PickerOptions configures the checkout picker.
type PickerResult ¶
PickerResult is the user's choice.
type Prompter ¶
Prompter asks yes/no and pick-one questions on the terminal. It satisfies app.Prompter.
type RenderOptions ¶
type RenderOptions struct {
Styles Styles
Now time.Time
// Selected highlights the row (picker cursor).
Selected bool
}
RenderOptions controls RenderRow.
type Reporter ¶
type Reporter struct {
// contains filtered or unexported fields
}
Reporter prints every human facing line the CLI produces, so all commands share one look (see docs/style.md). On a terminal it uses marks, colour, emoji headlines and spinners; piped it falls back to plain ASCII prefixes (ok:, note:, error:) with the same words.
func NewReporter ¶
NewReporter builds a Reporter over the given streams. Terminal writers are wrapped so colour is downsampled to what the terminal supports and dropped under NO_COLOR; hyperlinks and the busy state pass through.
func (*Reporter) Error ¶
Error prints an error on stderr: the message, any detail (faint) and the next steps. It renders stack.Error specially and anything else as one line.
func (*Reporter) Step ¶
func (r *Reporter) Step(ctx context.Context, phase app.Phase, message string, fn func(ctx context.Context) error) error
Step runs fn under a headline for the phase: an emoji, the message and a spinner on a terminal (the line is replaced by whatever is printed next when fn returns), or the message printed once when piped. The terminal's busy state is set for the duration. Output written to Stream while the step runs is shown above the spinner.
func (*Reporter) Stream ¶
Stream returns a writer for a subprocess's live output. Each line is shown in the "│" gutter on stderr (plain indent when piped), above the spinner while a Step is running.
func (*Reporter) Styles ¶
Styles returns the palette for stdout: the default styles on a terminal, the zero value (no escape codes) when piped.
type ReporterOptions ¶
type ReporterOptions struct {
// OutTTY / ErrTTY: stdout / stderr are terminals (marks and colour).
OutTTY, ErrTTY bool
// Spinners enables animated headlines; needs a terminal on stdin and
// stderr. Without it Step prints the headline once as a plain line.
Spinners bool
// Quiet drops everything but errors.
Quiet bool
}
ReporterOptions describe the streams the Reporter writes to.
type Styles ¶
type Styles struct {
Trunk lipgloss.Style
Branch lipgloss.Style
Current lipgloss.Style
Untracked lipgloss.Style
Prefix lipgloss.Style
Selected lipgloss.Style
Match lipgloss.Style
PROpen lipgloss.Style
PRDraft lipgloss.Style
PRMerged lipgloss.Style
PRClosed lipgloss.Style
Restack lipgloss.Style
Muted lipgloss.Style
Help lipgloss.Style
Title lipgloss.Style
// Reporter marks.
Success lipgloss.Style
Warning lipgloss.Style
Error lipgloss.Style
}
Styles groups the lipgloss styles used by the tree and picker.
func DefaultStyles ¶
func DefaultStyles() Styles
DefaultStyles returns the standard palette (ANSI colours so NO_COLOR and 16-colour terminals degrade gracefully).
type TreeRow ¶
type TreeRow struct {
Row app.Row
// Prefix holds the tree glyphs ("├─ ", "│ └─ ").
Prefix string
// Matched positions in Row.Name when a filter is active.
Matched []int
// IsMatch is true when the row itself matched the filter (as opposed to
// being kept as an ancestor of a match).
IsMatch bool
}
TreeRow is a display row: the app row plus its tree prefix and, after filtering, the matched rune positions.
func BuildTree ¶
BuildTree computes tree prefixes for rows in display order. Stacks are linear, so only the branches directly above a trunk can have siblings.
func FilterTree ¶
FilterTree keeps rows matching query plus their ancestors, so the tree context survives filtering. An empty query returns every row.