columns

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: MIT Imports: 3 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 columns ranks and styles the columns tui-builder writes for you. The evidence differs by caller (a JSON sample for `add exec`, a schema for the OpenAPI generator), so callers classify each column; this package holds the vocabularies, the ranking and the style.

Index

Constants

View Source
const DefaultMax = 8

DefaultMax is how many columns are kept; the rest are written commented out.

Variables

This section is empty.

Functions

func IdentityNames

func IdentityNames() []string

IdentityNames are the field names an identity is looked for under, in order, after any caller-specific choice.

func IsBookkeepingName

func IsBookkeepingName(name string) bool

IsBookkeepingName is a timestamp the store keeps rather than one about the thing: created_at, updatedAt, last_modified.

func IsCheckName

func IsCheckName(name string) bool

IsCheckName reads a boolean's name as a check worth colouring: ready, healthy, ok, enabled…

func IsCoordinateName

func IsCoordinateName(name string) bool

IsCoordinateName is a latitude or longitude.

func IsFailureCount

func IsFailureCount(name string) bool

IsFailureCount reads a number's name as a count of failures: restarts, errors, failures…

func IsIDName

func IsIDName(name string) bool

IsIDName is an id: id, owner_id, ownerId.

func IsLinkName

func IsLinkName(name string) bool

IsLinkName is a URL or link to something: image_url, href, self_link.

func IsLongName

func IsLongName(name string) bool

IsLongName reads a field name as long text: description, message…

func IsStatusName

func IsStatusName(name string) bool

IsStatusName reads a field name as a status: status, state, phase…

func IsTimeName

func IsTimeName(name string) bool

IsTimeName reads a field name as a timestamp: created_at, updatedAt, creationTimestamp, ts…

func SortByRank

func SortByRank(cols []Column)

SortByRank orders cols by rank, minor columns after short text, keeping the given order within each.

Types

type Column

type Column struct {
	Path  string
	Title string
	Rank  Rank
	// Bool is a boolean column (true/false values).
	Bool bool
	// Values are the distinct values seen (a sample) or declared (an
	// enum), for status colours.
	Values []string
	// Sort is the comparator: "", "number" or "si".
	Sort string
	// Minor is a column worth less than any other short one, whatever
	// its rank: a bookkeeping timestamp, a coordinate, an id or link, a
	// nested object's other fields. It sorts after short text, before
	// long text, and keeps its rank for its style.
	Minor bool
}

Column is one column as the caller found it.

func Pick

func Pick(cols []Column, max int) (kept, rest []Column)

Pick orders cols with SortByRank and keeps the first max, with one slot guaranteed to the top long-text column: it takes the last slot, displacing the last short or minor one (or, with none, the last kept). It returns the kept columns and the rest.

type Rank

type Rank int

Rank is how important a column is; lower comes first.

const (
	Identity Rank = iota // what a row is: its name, title or id
	Status               // a small set of states, or a boolean
	Time                 // timestamps
	Number               // counts, sizes, amounts
	Short                // other short text
	Long                 // long text: descriptions, messages
	Empty                // empty in every row seen
)

type Rule

type Rule struct {
	When  string
	Color string
}

Rule is one colour rule: when the cell matches When, it's drawn in Color.

func StatusRules

func StatusRules(values []string) []Rule

StatusRules writes colour rules for the vocabulary words among values, in the order seen, then the bad and warning catch-alls. No rule for a value outside the vocabulary, and none at all when no value is in it: unknown values render plain.

type Style

type Style struct {
	Bold     bool
	Flex     int
	MaxWidth int
	Align    string // "" or "right"
	Rules    []Rule
}

Style is how a kept column is drawn.

func Styles

func Styles(kept []Column) []Style

Styles styles the kept columns: bold on the first identity column; status colours from the vocabulary, for values seen; booleans coloured only when named as a check; failure counts warn above zero; numbers and timestamps right- aligned; flex on the long-text column, else on the identity; a max_width of 20 on status columns.

Jump to

Keyboard shortcuts

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