ui

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package ui provides shared terminal rendering utilities — tables with CJK-correct alignment, styled panels, and progress bars.

We implement our own table renderer instead of using lipgloss/table because lipgloss/table v1.1.0 has a CJK width bug that truncates double-width characters. Our renderer uses lipgloss.Width() (which delegates to go-runewidth) for all column width calculations.

Index

Constants

This section is empty.

Variables

View Source
var (
	ColorPrimary = lipgloss.Color("39")
	ColorAccent  = lipgloss.Color("41")
	ColorWarn    = lipgloss.Color("220")
	ColorError   = lipgloss.Color("203")
	ColorDim     = lipgloss.Color("240")
	ColorHeader  = lipgloss.Color("99")
	ColorValue   = lipgloss.Color("252")
	ColorLabel   = lipgloss.Color("245")
	ColorFree    = lipgloss.Color("42")
	ColorCost    = lipgloss.Color("220")
	ColorBorder  = lipgloss.Color("238")

	StyleHeader = lipgloss.NewStyle().Bold(true).Foreground(ColorHeader)
	StyleValue  = lipgloss.NewStyle().Foreground(ColorValue)
	StyleLabel  = lipgloss.NewStyle().Foreground(ColorLabel)
	StyleDim    = lipgloss.NewStyle().Foreground(ColorDim)
	StyleFree   = lipgloss.NewStyle().Foreground(ColorFree)
	StyleCost   = lipgloss.NewStyle().Foreground(ColorCost)
	StyleWarn   = lipgloss.NewStyle().Foreground(ColorWarn)
	StyleError  = lipgloss.NewStyle().Foreground(ColorError)
	StyleAccent = lipgloss.NewStyle().Foreground(ColorAccent)
)

Color palette (dark theme).

Functions

func Panel

func Panel(title, content string, width int) string

Panel renders a titled bordered panel with the given content. Borders are colored manually because lipgloss strips ANSI from pure-symbol strings when output is not a TTY.

func PctColor

func PctColor(pct float64) lipgloss.Style

PctColor returns a lipgloss style based on percentage threshold.

func ProgressBar

func ProgressBar(pct, width float64) string

ProgressBar renders a unicode progress bar with correct width.

func Sparkline

func Sparkline(pts []float64, width int) string

Sparkline renders a unicode sparkline from float values.

func Truncate

func Truncate(s string, maxDisplayWidth int) string

Truncate truncates s to maxDisplayWidth using runewidth for CJK correctness.

Types

type TableBuilder

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

TableBuilder builds a styled table with rounded borders and CJK-correct column width calculation. Automatically fits to terminal width by truncating the widest text columns first — only when the terminal is too narrow. No truncation happens when there is enough space.

func NewTable

func NewTable(headers ...string) *TableBuilder

NewTable creates a new TableBuilder with the given headers.

func (*TableBuilder) Print

func (t *TableBuilder) Print()

Print renders and prints the table to stdout.

func (*TableBuilder) RightAlign

func (t *TableBuilder) RightAlign(cols ...int) *TableBuilder

RightAlign sets columns (0-indexed) to right-aligned.

func (*TableBuilder) Row

func (t *TableBuilder) Row(values ...string) *TableBuilder

Row adds a data row.

func (*TableBuilder) String

func (t *TableBuilder) String() string

String renders the table as a string with rounded borders. If the table exceeds terminal width, text columns are truncated to fit.

func (*TableBuilder) TotalRow added in v0.2.0

func (t *TableBuilder) TotalRow(values ...string) *TableBuilder

TotalRow adds a totals row that is rendered with a separator line above it. Use this for the summary/aggregate row at the bottom of a table.

Jump to

Keyboard shortcuts

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