render

package
v1.11.0 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package render provides terminal output helpers: optional ANSI color, simple aligned tables, and an ASCII commit-graph used to visualize rebases. Color is disabled when color-mode:none is passed or when output is not a terminal.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Plain

func Plain(format string, a ...any) string

Plain is a convenience for fmt.Sprintf used by callers.

Types

type Colors

type Colors struct {
	// contains filtered or unexported fields
}

Colors holds whether ANSI styling is enabled.

func NewColors

func NewColors(colorMode string, isTTY bool) Colors

NewColors decides whether to colorize. Precedence: an explicit colorMode wins ("none" forces plain, "always" forces color); otherwise a non-empty NO_COLOR environment variable disables color (https://no-color.org); otherwise color follows isTTY.

func (Colors) Bold

func (c Colors) Bold(s string) string

func (Colors) Cyan

func (c Colors) Cyan(s string) string

func (Colors) Dim

func (c Colors) Dim(s string) string

func (Colors) Enabled

func (c Colors) Enabled() bool

Enabled reports whether ANSI styling is on.

func (Colors) Green

func (c Colors) Green(s string) string

func (Colors) Magenta

func (c Colors) Magenta(s string) string

func (Colors) Red

func (c Colors) Red(s string) string

func (Colors) Yellow

func (c Colors) Yellow(s string) string

type Commit

type Commit struct {
	Short   string // abbreviated sha
	Subject string // first line of the commit message
}

Commit is one node in a rebase visualization.

type RebasePlan

type RebasePlan struct {
	Feature   string // feature branch name (for labels)
	Trunk     string // trunk branch name (for labels)
	Fork      Commit
	TrunkLine []Commit
	FeatLine  []Commit
}

RebasePlan describes the move a rebase performs: the feature commits currently hanging off Fork are replayed on top of the trunk commits that landed since.

Trunk   = commits on trunk after Fork, up to trunk head (newest first)
Feature = the feature's own commits after Fork (newest first)
Fork    = the common ancestor the feature forked from

func (RebasePlan) Render

func (p RebasePlan) Render(c Colors) string

Render draws a before/after ASCII graph of the rebase. The "before" picture shows the feature diverged from trunk; the "after" picture shows it replayed on top of trunk head. Colors are applied when enabled.

type Stepper added in v1.8.0

type Stepper struct {
	W      io.Writer
	TTY    bool
	Colors Colors
}

Stepper telegraphs the procedure tbd is about to run and, on a terminal, animates a spinner for its duration. Progress is meant for stderr so stdout stays clean for piping.

func (Stepper) Run added in v1.8.0

func (s Stepper) Run(label string, fn func() error) error

Run announces label, runs fn, and returns fn's error. On a TTY it shows an animated spinner ONLY if fn runs longer than spinDelay, erasing it when done (the command prints its own result). Off a TTY it prints the label once, so the procedure is still telegraphed in logs and CI.

type Table

type Table struct {
	// contains filtered or unexported fields
}

Table renders rows of cells into a left-aligned, space-padded table.

func NewTable

func NewTable(header ...string) *Table

NewTable creates a table with the given header.

func (*Table) Add

func (t *Table) Add(cells ...string)

Add appends a row.

func (*Table) String

func (t *Table) String() string

String renders the table. Width is computed from visible (un-styled) length, so cells may carry ANSI color and still align.

Jump to

Keyboard shortcuts

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