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.
func (Alignment) Format ¶
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 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 ¶
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 ¶
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.