border

package
v1.16.0 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2026 License: MIT Imports: 5 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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

View Source
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

func DetectTruecolor(env Env) bool

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.

func Chars

func Chars(c Corners) Charset

Chars returns the charset for the requested corner style.

type Corners

type Corners int

Corners selects a charset.

const (
	CornersRound Corners = iota
	CornersSquare
)

type Env

type Env func(string) string

Env looks up an environment variable; nil means "no environment".

type Gradient

type Gradient struct {
	Stops []RGB
	Angle float64
}

Gradient is a parsed border_gradient spec.

func ParseGradient

func ParseGradient(spec string) *Gradient

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.

func (*Painter) Cell

func (p *Painter) Cell(x, y int, glyph string) string

Cell renders a single colored glyph, self-closing.

func (*Painter) Run

func (p *Painter) Run(y, x0 int, glyphs []string) string

Run renders consecutive cells on row y starting at column x0, coalescing equal adjacent colors into one SGR. It closes with a single reset iff any color was emitted.

func (*Painter) SGRAt

func (p *Painter) SGRAt(x, y int) string

SGRAt is the opening sequence for the cell at (x, y): a truecolor foreground in gradient mode, else the solid fallback (possibly "").

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.

type RGB

type RGB [3]int

RGB is one gradient stop.

Jump to

Keyboard shortcuts

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