Documentation
¶
Overview ¶
Package border is the single owner of box-drawing chrome: rounded corners plus an angled truecolor gradient swept across a container's border cells. Frames, modals, and palettes all route their boxes through here so every container gets the same look, and so the box-drawing glyphs live in exactly one place.
A Gradient is a stop list plus an angle in degrees. For each border cell the cell is projected onto the angle's direction vector (with a vertical aspect correction, since terminal cells are ~2x taller than wide), the projection is normalized across the box's four corners to t in [0,1], and the stops are interpolated at t. When no gradient is active (no truecolor, a NO_COLOR/mono theme, or none configured) the border falls back to a single solid SGR — same call sites, no branching at the caller.
Go port of Ruby's lib/tui/border.rb. Truecolor availability is a Painter option rather than Ruby's module-level flag.
Index ¶
Constants ¶
const ( // DefaultSteps is the number of distinct colors quantized along the ring. // Quantizing both caps the number of SGR sequences emitted and lets // adjacent equal-color cells coalesce into one run, so a ~200-cell // perimeter costs a couple dozen escapes, not 200. DefaultSteps = 24 // DefaultAspect scales y so a configured angle reads on screen as that // angle rather than vertically skewed. DefaultAspect = 2.0 )
Variables ¶
var ( Round = Charset{TL: "╭", TR: "╮", BL: "╰", BR: "╯", H: "─", V: "│", ML: "├", MR: "┤"} Square = Charset{TL: "┌", TR: "┐", BL: "└", BR: "┘", H: "─", V: "│", ML: "├", MR: "┤"} )
Round has rounded outer corners; Square keeps them square. The divider tees (ML/MR) are shared by both, since the header/footer rules keep their square junctions.
Functions ¶
func Box ¶
func Box(opts BoxOptions) []string
Box renders a complete box. Returned rows are each InnerWidth + 2 cells wide.
func DetectTruecolor ¶
DetectTruecolor is the Ruby truecolor probe: a non-empty NO_COLOR disables color entirely, COLORTERM naming truecolor/24bit enables it, and otherwise any TERM that is neither empty nor "dumb" is assumed capable.
Types ¶
type BoxOptions ¶
type BoxOptions struct {
// InnerLines are each exactly InnerWidth visible cells (any inner margin is
// the caller's); the vertical edges are added here.
InnerLines []string
InnerWidth int
Gradient *Gradient
Solid string
Truecolor bool
// Title is already styled by the caller and sits after TitleLead leading
// dashes; the border glyphs around it are painted while the title text
// passes through untouched. An empty title draws a plain top rule.
Title string
TitleLead int
Corners Corners
Steps int
Aspect float64
}
BoxOptions describes one complete box.
type Charset ¶
type Charset struct {
TL, TR, BL, BR, H, V, ML, MR string
}
Charset is one box-drawing glyph set.
type Gradient ¶
Gradient is a parsed border_gradient spec.
func ParseGradient ¶
ParseGradient parses a border_gradient spec: two or more hex stops then an "@<angle>", e.g. "#7aa2f7 #bb9af7 @60". It returns nil if the spec is malformed, so a bad config value degrades to the solid border rather than failing.
type Painter ¶
type Painter struct {
// contains filtered or unexported fields
}
Painter precomputes the per-cell colorizer for one box size. Cell and Run return glyphs wrapped in the appropriate SGR; the caller maps only border glyphs through it, leaving interior content untouched.
func NewPainter ¶
func NewPainter(opts PainterOptions) *Painter
NewPainter builds a Painter for a box of Width x Height cells.
type PainterOptions ¶
type PainterOptions struct {
Width, Height int
Gradient *Gradient
// Solid is an SGR opener (e.g. "\e[90m") or "" used when the gradient is
// inactive.
Solid string
// Truecolor gates the gradient. Absent truecolor, gradients drop to Solid.
Truecolor bool
Steps int
Aspect float64
}
PainterOptions configures one box-sized colorizer.