printedtable

package
v0.78.0 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2026 License: MIT Imports: 6 Imported by: ? 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 printedtable prints rows as a table for a command that prints and exits, as a rich table prints for a Python one. It lays the table out through lipgloss's table, which measures a cell by the width it prints at, so a colored cell lines up where text/tabwriter would count its escapes as width. Each cell prints in the gotermstyle code it carries, through a palette the caller resolves once, so a palette that is off prints no escape at all. Each cell's text and each title loses its terminal controls before it is measured, so a stored value cannot drive the terminal the table prints to.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cell

type Cell struct {
	Text string
	Code string
}

Cell is a cell's text and the gotermstyle code it prints in, such as gotermstyle.CodeRed. An empty Code prints the text in the terminal's own foreground.

func C

func C(text, code string) Cell

C is a cell of text in code.

type Column

type Column struct {
	// Title heads the column in bold. A table whose columns all have none prints no title line.
	Title string
	// Right sets the column's cells and title against its right edge, as a count reads.
	Right bool
	// Whole keeps the column's cells whole where the table is cut to its Width, because a cut
	// handle is a command that fails when typed. The other columns give up the room, and where
	// they cannot, the table prints wider than Width.
	Whole bool
}

Column is one column's title and how its cells sit.

type Table

type Table struct {
	Columns []Column
	Rows    [][]Cell
	// Width is how many columns wide the table may print. A wider table cuts its widest cells to
	// fit, each ending in "…". Zero prints every cell whole, as piped output is read whole.
	Width int
	// Gap is the blank columns between two neighbors. Zero takes two.
	Gap int
}

Table is one printed table's columns and rows, and the room it prints in. A row holding more cells than Columns names adds columns with no title.

func (Table) Lines

func (t Table) Lines(p gotermstyle.Palette) []string

Lines is the table's lines, one per row under the title line, each with no trailing space. p paints each cell in its code and each title in bold.

func (Table) Print

func (t Table) Print(w io.Writer, p gotermstyle.Palette) error

Print writes the table's lines to w, each ending in a newline.

Jump to

Keyboard shortcuts

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