On this page
Renders gradient-colored horizontal and vertical progress bars, ANSI color output, model name shortening, and multi-line statusline composition.
#internal/render
#internal/render
#FullBlock
const FullBlock = '█'FullBlock is U+2588, used for fully filled cells.
#Reset
const Reset = "\x1b[0m"ANSI escape constants matching the Node.js colors object.
#Bold
const Bold = "\x1b[1m"#Dim
const Dim = "\x1b[2m"#Green
const Green = "\x1b[32m"#Yellow
const Yellow = "\x1b[33m"#Orange
const Orange = "\x1b[38;5;208m"#Red
const Red = "\x1b[31m"#Cyan
const Cyan = "\x1b[36m"#Magenta
const Magenta = "\x1b[35m"#White
const White = "\x1b[37m"#Gray
const Gray = "\x1b[90m"#HorizontalChars
var HorizontalChars = []rune{'▏', '▎', '▍', '▌', '▋', '▊', '▉'}Fractional block characters for sub-cell precision. Horizontal: left fractional blocks (U+258F to U+2589), fill left-to-right.
#VerticalChars
var VerticalChars = []rune{'▁', '▂', '▃', '▄', '▅', '▆', '▇'}Vertical: lower fractional blocks (U+2581 to U+2587), fill bottom-to-top.
#PartialBlocksBlocklist
var PartialBlocksBlocklist = []string{"Apple_Terminal", "linux"}PartialBlocksBlocklist contains terminal identifiers that don't render fractional block characters correctly.
#BuiltinColors
var BuiltinColors = []ColorEntry{BuiltinColors contains the 4 default color entries covering dark/light x truecolor/256-color combinations.
#BarConfig
type BarConfig structBarConfig packages the rendering configuration needed by bar functions.
#GradientResult
type GradientResult structGradientResult holds the foreground and background ANSI escape sequences for a given position in the gradient.
#BgValue
type BgValue structBgValue represents a background color: either RGB or a 256-color palette index.
#UsageData
type UsageData structUsageData holds percentage and reset time for a usage window.
#ExtraUsageData
type ExtraUsageData structExtraUsageData holds extra usage information.
#GitInfo
type GitInfo structGitInfo holds git repository state.
#LineChangeInfo
type LineChangeInfo structLineChangeInfo holds line addition/removal counts.
#BarColumn
type BarColumn structBarColumn describes a single progress bar column for RenderLines.
#TimeBarInfo
type TimeBarInfo structTimeBarInfo holds the time and usage percentages for a time-progress bar.
#RenderData
type RenderData structRenderData contains all data needed to render the 3-line statusline output.
#GradientStop
type GradientStop structGradientStop represents a single gradient stop: either an RGB triplet (for truecolor) or a 256-color palette index.
#ColorEntry
type ColorEntry structColorEntry represents a color configuration with optional conditions. nil pointers for DarkMode/TrueColor act as wildcards (match any).
#ShouldUsePartialBlocks
func ShouldUsePartialBlocks(configOverride string) boolShouldUsePartialBlocks determines whether fractional block characters should be used. configOverride: "true" forces on, "false" forces off, anything else uses auto-detection against the blocklist.
#GetGradientStop
func GetGradientStop(percent float64, config *BarConfig) GradientResultGetGradientStop returns fg and bg ANSI escapes for a given percentage (0-100) within the configured gradient.
#GetUrgencyColor
func GetUrgencyColor(urgency float64, isDark bool, truecolor bool) stringGetUrgencyColor computes an ANSI foreground escape for the time bar based on urgency ratio (0-1). Uses a 3-stop gradient: gray -> yellow -> red. Adapts to dark/light mode and truecolor/256-color.
#HorizontalBar
func HorizontalBar(percent float64, config *BarConfig, emptyBgOverride string) stringHorizontalBar renders a horizontal progress bar with sub-cell precision. Filled cells use the gradient bg as background + space. The fractional cell uses a left block character with gradient fg on empty bg. Empty cells use empty bg + space. If emptyBgOverride is non-empty, it overrides config.EmptyBg.
#VerticalBarCell
func VerticalBarCell(percent float64, rowIdx int, totalRows int, emptyBgOverride string, config *BarConfig) stringVerticalBarCell renders one cell of a vertical bar. Each bar spans totalRows rows (top=0, bottom=totalRows-1), 8 fill states per row. Fills bottom-to-top: bottom row fills first. If emptyBgOverride is non-empty, it overrides config.EmptyBg.
#TimeBarCell
func TimeBarCell(timePercent float64, usagePercent float64, rowIdx int, totalRows int, config *BarConfig) stringTimeBarCell renders one cell of a vertical time-elapsed bar with urgency coloring. Same fill logic as VerticalBarCell but the color is derived from urgency (how far usage outpaces elapsed time) rather than the standard gradient.
#IsTruecolorSupported
func IsTruecolorSupported() boolIsTruecolorSupported checks COLORTERM env var for "truecolor" or "24bit". Result is cached per-process.
#ResetTruecolorCache
func ResetTruecolorCache()ResetTruecolorCache allows tests to reset the cached value.
#ResetDarkModeCache
func ResetDarkModeCache()ResetDarkModeCache allows tests to reset the cached value.
#IsDarkMode
func IsDarkMode() boolIsDarkMode detects OS dark/light mode. Check order: HOWMUCHLEFT_DARK env override, then OS-specific detection. Result is cached per-process.
#RgbTo256
func RgbTo256(r, g, b uint8) intRgbTo256 converts RGB to nearest 256-color 6x6x6 cube index (16-231).
#InterpolateRgb
func InterpolateRgb(stops [][3]uint8, t float64) [3]uint8InterpolateRgb does linear interpolation between gradient stops at position t (0-1).
#FormatFg
func FormatFg(r, g, b uint8, truecolor bool) stringFormatFg formats RGB as an ANSI foreground escape sequence.
#FormatBg
func FormatBg(r, g, b uint8, truecolor bool) stringFormatBg formats RGB as an ANSI background escape sequence.
#NewBgRgb
func NewBgRgb(r, g, b uint8) BgValueNewBgRgb creates an RGB background value.
#NewBgIndex
func NewBgIndex(idx int) BgValueNewBgIndex creates a 256-color palette index background value.
#FormatBgFromValue
func FormatBgFromValue(bg BgValue, truecolor bool) stringFormatBgFromValue formats a BgValue as an ANSI background escape sequence.
#ShortenModelName
func ShortenModelName(model string) stringShortenModelName abbreviates a Claude model name to a compact form. e.g. "claude-sonnet-4-5-20250514" -> "S4.5" Unknown models pass through unchanged.
#FormatPercent
func FormatPercent(percent *float64, stale bool) stringFormatPercent formats a usage percentage with ANSI colors. nil -> gray "?%", stale -> dim "~{rounded}%", normal -> cyan "{rounded}%".
#FormatExtraPercent
func FormatExtraPercent(percent float64, stale bool, isDark bool, truecolor bool) stringFormatExtraPercent formats extra usage percentage with a warm amber background.
#FormatTimeRemaining
func FormatTimeRemaining(ms int64) stringFormatTimeRemaining formats a duration in milliseconds as a human-readable string. Negative -> empty string, <60s -> "Ns", <1h -> "Nm", <1d -> "NhNm", else "NdNh".
#FormatAge
func FormatAge(ms int64) stringFormatAge formats a duration in milliseconds as a short age string. <60s -> "Ns", <1h -> "Nm", else "Nh".
#ShortenPath
func ShortenPath(p string, maxLen int, depth int) stringShortenPath shortens a filesystem path for display. Replaces home directory prefix with ~, then truncates to maxLen keeping the last depth segments (prepended with .../).
#BuildLineText
func BuildLineText(elements map[string]func() string, order []string) stringBuildLineText calls each function from the element map in order, filters out empty strings, and joins with a single space.
#WarmBgColors
func WarmBgColors(isDark, truecolor bool) (textBg, barBg string)WarmBgColors returns the ANSI background escape sequences for extra-usage warm amber coloring. textBg is used for percentage labels, barBg is used for bar cell backgrounds. Both adapt to dark/light mode and truecolor/256-color.
#ComputeTimeBarBg
func ComputeTimeBarBg(bg BgValue, isDark bool, truecolor bool, blend float64) stringComputeTimeBarBg blends the bar background toward the terminal default. Dark terminals default to black (0,0,0), light to white (255,255,255). blend: 0 = same as bar bg, 1 = fully terminal default.
#ComputeTimePercent
func ComputeTimePercent(resetInMs, windowDurationMs int64) float64ComputeTimePercent computes the elapsed time percentage for a usage window. resetInMs is milliseconds until the window resets, windowDurationMs is the total window duration. Returns a value clamped to [0, 100].
#RenderLines
func RenderLines(data *RenderData, barCfg *BarConfig, lineElements *config.LinesConfig, columns []BarColumn) stringRenderLines composes the 3-line statusline output from RenderData. If lineElements is nil, returns "\n\n" (3 empty lines). columns describes the bar columns to render. Pass nil for the default 3-column layout (context, 5hr, weekly/extra).
#ConfigColorToRenderColor
func ConfigColorToRenderColor(ce config.ColorEntry) *ColorEntryConfigColorToRenderColor converts a config.ColorEntry to a render.ColorEntry. Returns nil if the entry has no valid gradient.
#ParseGradientStops
func ParseGradientStops(g interface{}) []GradientStopParseGradientStops converts the generic gradient interface to typed stops.
#ParseBgValue
func ParseBgValue(bg interface{}) BgValueParseBgValue converts the generic bg interface to a BgValue.
#BuildBarConfig
func BuildBarConfig(cfg *config.Config) *BarConfigBuildBarConfig creates a BarConfig from the user's config. It resolves color mode, selects user or builtin gradients, computes time bar background, and sets orientation. This is the single authoritative source for bar configuration used by the statusline, demo, dashboard, and colors commands.
#NewRgbStop
func NewRgbStop(r, g, b uint8) GradientStopNewRgbStop creates an RGB gradient stop.
#NewIndexStop
func NewIndexStop(idx int) GradientStopNewIndexStop creates a 256-color palette index gradient stop.
#IsRgbStop
func IsRgbStop(stop GradientStop) boolIsRgbStop validates whether a GradientStop is an RGB stop with values 0-255. Since uint8 is inherently 0-255, this just checks the IsRgb flag.
#FindColorMatch
func FindColorMatch(entries []ColorEntry, isDark bool, isTruecolor bool) *ColorEntryFindColorMatch returns the first entry whose conditions match the given dark mode and truecolor state. nil condition pointers are wildcards.
#HashToHue
func HashToHue(s string) intHashToHue converts a string to a hue value 0-359 using djb2 hash.
#HueToAnsi
func HueToAnsi(hue int, isDark bool) stringHueToAnsi converts a hue (0-359) to an ANSI foreground escape sequence. Uses HSL->RGB with saturation 0.7 and lightness adapted to terminal background.
#TestColors
func TestColors(barCfg *BarConfig) stringTestColors returns a multi-line string previewing the gradient colors. Shows sample bars at 7 percentages, vertical bar columns, and a gradient strip.