xterm

package
v0.13.2 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2021 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Alignment

type Alignment int

Alignment is a text alignment. A text can be:

  • aligned to left: "foo123 "
  • aligned to center: " foo123 "
  • aligned to right: " foo123"

By default, text is aligned to the left.

const (
	AlignLeft Alignment = iota
	AlignCenter
	AlignRight
)

func (Alignment) Format

func (a Alignment) Format(text string, length int) string

Format aligns the given text and returns a string that is exactly length runes long.

If text is exactly length runes long then Format returns text unmodified.

If text consists of fewer then length runes then Format pads text to the given length with whitespaces depending on the alignment:

  • AlignLeft: whitespaces are added at the end
  • AlignRight: whitespaces are added at the beginning
  • AlignCenter: whitespaces are added at the end and the beginning. If length is odd an additional whitespaces is added at the end.

If text consists of more then length runes then Format truncates text to length runes. If text consits of at least 2 runes it replaces length-1 rune with '…' to visually indicate that the text has been truncated. If text ends with one or more whitespaces then Format replaces the length-2 rune with '…' and preserves one whitespace at the end.

type Cell

type Cell struct {
	Text  string
	Color *color.Color
}

Cell represents a single table cell.

func NewCell

func NewCell(text string) *Cell

NewCell returns a new tabel cell with the given text and no color.

type HCell

type HCell struct {
	Cell
	Width     float64   // The width of the column in percent.
	Alignment Alignment // The text alignment of the column.
}

HCell represents a single header cell of a table. A table with n columns has n header cells. A HCell defines certain properties for all cells of the same column - like the column width.

type Table

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

Table represents a table UI that consists of n columns and a sliding window of rows.

Each column has a header cell that defines the column width and other properties.

New rows can be added to the table but it remembers only a sliding window of rows. Once the capacity of the table is reached the window is moved forward whenever a new row is added such that olds rows get dropped.

In any case, the table only prints the latest m rows that fit on the STDOUT terminal window. So, a table keeps a sliding window of the latest n rows and prints a view of the latest m rows, that fits on the screen, to STDOUT.

func NewTable

func NewTable(headers ...string) *Table

NewTable creates a new table with len(headers) columns. Each column has its on header title and in bold text and aligned to the left. All columns have the same width of 1/len(headers).

func (*Table) AddRow

func (t *Table) AddRow(cells ...*Cell)

AddRow adds a new row to the table. If the capacity of the table is reached older rows get dropped.

func (*Table) Draw

func (t *Table) Draw()

Draw first cleans the screen and then prints a view of the table to STDOUT. The view is adjusted to the terminal width and height.

func (*Table) Header

func (t *Table) Header() []*HCell

Header returns the header cell of each column.

Jump to

Keyboard shortcuts

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