howmuchleft v0.14.1 /internal/render
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

Go go
const FullBlock = '█'

FullBlock is U+2588, used for fully filled cells.

#Reset

Go go
const Reset   = "\x1b[0m"

ANSI escape constants matching the Node.js colors object.

#Bold

Go go
const Bold    = "\x1b[1m"

#Dim

Go go
const Dim     = "\x1b[2m"

#Green

Go go
const Green   = "\x1b[32m"

#Yellow

Go go
const Yellow  = "\x1b[33m"

#Orange

Go go
const Orange  = "\x1b[38;5;208m"

#Red

Go go
const Red     = "\x1b[31m"

#Cyan

Go go
const Cyan    = "\x1b[36m"

#Magenta

Go go
const Magenta = "\x1b[35m"

#White

Go go
const White   = "\x1b[37m"

#Gray

Go go
const Gray    = "\x1b[90m"

#HorizontalChars

Go go
var HorizontalChars = []rune{'▏', '▎', '▍', '▌', '▋', '▊', '▉'}

Fractional block characters for sub-cell precision. Horizontal: left fractional blocks (U+258F to U+2589), fill left-to-right.

#VerticalChars

Go go
var VerticalChars = []rune{'▁', '▂', '▃', '▄', '▅', '▆', '▇'}

Vertical: lower fractional blocks (U+2581 to U+2587), fill bottom-to-top.

#PartialBlocksBlocklist

Go go
var PartialBlocksBlocklist = []string{"Apple_Terminal", "linux"}

PartialBlocksBlocklist contains terminal identifiers that don't render fractional block characters correctly.

#BuiltinColors

Go go
var BuiltinColors = []ColorEntry{

BuiltinColors contains the 4 default color entries covering dark/light x truecolor/256-color combinations.

#BarConfig

Go go
type BarConfig struct

BarConfig packages the rendering configuration needed by bar functions.

#GradientResult

Go go
type GradientResult struct

GradientResult holds the foreground and background ANSI escape sequences for a given position in the gradient.

#BgValue

Go go
type BgValue struct

BgValue represents a background color: either RGB or a 256-color palette index.

#UsageData

Go go
type UsageData struct

UsageData holds percentage and reset time for a usage window.

#ExtraUsageData

Go go
type ExtraUsageData struct

ExtraUsageData holds extra usage information.

#GitInfo

Go go
type GitInfo struct

GitInfo holds git repository state.

#LineChangeInfo

Go go
type LineChangeInfo struct

LineChangeInfo holds line addition/removal counts.

#BarColumn

Go go
type BarColumn struct

BarColumn describes a single progress bar column for RenderLines.

#TimeBarInfo

Go go
type TimeBarInfo struct

TimeBarInfo holds the time and usage percentages for a time-progress bar.

#RenderData

Go go
type RenderData struct

RenderData contains all data needed to render the 3-line statusline output.

#GradientStop

Go go
type GradientStop struct

GradientStop represents a single gradient stop: either an RGB triplet (for truecolor) or a 256-color palette index.

#ColorEntry

Go go
type ColorEntry struct

ColorEntry represents a color configuration with optional conditions. nil pointers for DarkMode/TrueColor act as wildcards (match any).

#ShouldUsePartialBlocks

Go go
func ShouldUsePartialBlocks(configOverride string) bool

ShouldUsePartialBlocks determines whether fractional block characters should be used. configOverride: "true" forces on, "false" forces off, anything else uses auto-detection against the blocklist.

#GetGradientStop

Go go
func GetGradientStop(percent float64, config *BarConfig) GradientResult

GetGradientStop returns fg and bg ANSI escapes for a given percentage (0-100) within the configured gradient.

#GetUrgencyColor

Go go
func GetUrgencyColor(urgency float64, isDark bool, truecolor bool) string

GetUrgencyColor 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

Go go
func HorizontalBar(percent float64, config *BarConfig, emptyBgOverride string) string

HorizontalBar 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

Go go
func VerticalBarCell(percent float64, rowIdx int, totalRows int, emptyBgOverride string, config *BarConfig) string

VerticalBarCell 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

Go go
func TimeBarCell(timePercent float64, usagePercent float64, rowIdx int, totalRows int, config *BarConfig) string

TimeBarCell 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

Go go
func IsTruecolorSupported() bool

IsTruecolorSupported checks COLORTERM env var for "truecolor" or "24bit". Result is cached per-process.

#ResetTruecolorCache

Go go
func ResetTruecolorCache()

ResetTruecolorCache allows tests to reset the cached value.

#ResetDarkModeCache

Go go
func ResetDarkModeCache()

ResetDarkModeCache allows tests to reset the cached value.

#IsDarkMode

Go go
func IsDarkMode() bool

IsDarkMode detects OS dark/light mode. Check order: HOWMUCHLEFT_DARK env override, then OS-specific detection. Result is cached per-process.

#RgbTo256

Go go
func RgbTo256(r, g, b uint8) int

RgbTo256 converts RGB to nearest 256-color 6x6x6 cube index (16-231).

#InterpolateRgb

Go go
func InterpolateRgb(stops [][3]uint8, t float64) [3]uint8

InterpolateRgb does linear interpolation between gradient stops at position t (0-1).

#FormatFg

Go go
func FormatFg(r, g, b uint8, truecolor bool) string

FormatFg formats RGB as an ANSI foreground escape sequence.

#FormatBg

Go go
func FormatBg(r, g, b uint8, truecolor bool) string

FormatBg formats RGB as an ANSI background escape sequence.

#NewBgRgb

Go go
func NewBgRgb(r, g, b uint8) BgValue

NewBgRgb creates an RGB background value.

#NewBgIndex

Go go
func NewBgIndex(idx int) BgValue

NewBgIndex creates a 256-color palette index background value.

#FormatBgFromValue

Go go
func FormatBgFromValue(bg BgValue, truecolor bool) string

FormatBgFromValue formats a BgValue as an ANSI background escape sequence.

#ShortenModelName

Go go
func ShortenModelName(model string) string

ShortenModelName abbreviates a Claude model name to a compact form. e.g. "claude-sonnet-4-5-20250514" -> "S4.5" Unknown models pass through unchanged.

#FormatPercent

Go go
func FormatPercent(percent *float64, stale bool) string

FormatPercent formats a usage percentage with ANSI colors. nil -> gray "?%", stale -> dim "~{rounded}%", normal -> cyan "{rounded}%".

#FormatExtraPercent

Go go
func FormatExtraPercent(percent float64, stale bool, isDark bool, truecolor bool) string

FormatExtraPercent formats extra usage percentage with a warm amber background.

#FormatTimeRemaining

Go go
func FormatTimeRemaining(ms int64) string

FormatTimeRemaining formats a duration in milliseconds as a human-readable string. Negative -> empty string, <60s -> "Ns", <1h -> "Nm", <1d -> "NhNm", else "NdNh".

#FormatAge

Go go
func FormatAge(ms int64) string

FormatAge formats a duration in milliseconds as a short age string. <60s -> "Ns", <1h -> "Nm", else "Nh".

#ShortenPath

Go go
func ShortenPath(p string, maxLen int, depth int) string

ShortenPath shortens a filesystem path for display. Replaces home directory prefix with ~, then truncates to maxLen keeping the last depth segments (prepended with .../).

#BuildLineText

Go go
func BuildLineText(elements map[string]func() string, order []string) string

BuildLineText calls each function from the element map in order, filters out empty strings, and joins with a single space.

#WarmBgColors

Go go
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

Go go
func ComputeTimeBarBg(bg BgValue, isDark bool, truecolor bool, blend float64) string

ComputeTimeBarBg 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

Go go
func ComputeTimePercent(resetInMs, windowDurationMs int64) float64

ComputeTimePercent 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

Go go
func RenderLines(data *RenderData, barCfg *BarConfig, lineElements *config.LinesConfig, columns []BarColumn) string

RenderLines 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

Go go
func ConfigColorToRenderColor(ce config.ColorEntry) *ColorEntry

ConfigColorToRenderColor converts a config.ColorEntry to a render.ColorEntry. Returns nil if the entry has no valid gradient.

#ParseGradientStops

Go go
func ParseGradientStops(g interface{}) []GradientStop

ParseGradientStops converts the generic gradient interface to typed stops.

#ParseBgValue

Go go
func ParseBgValue(bg interface{}) BgValue

ParseBgValue converts the generic bg interface to a BgValue.

#BuildBarConfig

Go go
func BuildBarConfig(cfg *config.Config) *BarConfig

BuildBarConfig 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

Go go
func NewRgbStop(r, g, b uint8) GradientStop

NewRgbStop creates an RGB gradient stop.

#NewIndexStop

Go go
func NewIndexStop(idx int) GradientStop

NewIndexStop creates a 256-color palette index gradient stop.

#IsRgbStop

Go go
func IsRgbStop(stop GradientStop) bool

IsRgbStop 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

Go go
func FindColorMatch(entries []ColorEntry, isDark bool, isTruecolor bool) *ColorEntry

FindColorMatch returns the first entry whose conditions match the given dark mode and truecolor state. nil condition pointers are wildcards.

#HashToHue

Go go
func HashToHue(s string) int

HashToHue converts a string to a hue value 0-359 using djb2 hash.

#HueToAnsi

Go go
func HueToAnsi(hue int, isDark bool) string

HueToAnsi 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

Go go
func TestColors(barCfg *BarConfig) string

TestColors returns a multi-line string previewing the gradient colors. Shows sample bars at 7 percentages, vertical bar columns, and a gradient strip.

Search