Documentation
¶
Index ¶
- func DetectWidth() int
- func EmojiShortName(emoji string) (string, bool)
- func Escape(text string) string
- func Plain(markup string) string
- func Render(markup string, color bool) string
- func TerminalProfile() colorprofile.Profile
- func WrapStyled(text string, width int) []string
- type BarColumn
- type Column
- type Console
- func (c *Console) Input(prompt string) (string, error)
- func (c *Console) NewProgress(refresh time.Duration, columns ...ProgressColumn) *Progress
- func (c *Console) Print(markup ...string)
- func (c *Console) PrintNoHighlight(markup ...string)
- func (c *Console) PrintPanel(p Panel)
- func (c *Console) PrintRenderableWith(r Renderable, o PrintOptions)
- func (c *Console) PrintSoft(markup string)
- func (c *Console) PrintTable(t *Table)
- func (c *Console) Status(markup string) *Status
- type DescriptionColumn
- type Markdown
- type Panel
- type PrintOptions
- type Progress
- type ProgressColumn
- type Renderable
- type SpinnerColumn
- type Status
- type Style
- type Table
- type Task
- type TaskColumn
- type TaskProgressColumn
- type Text
- type TextColumn
- type TimeElapsedColumn
- type TimeRemainingColumn
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DetectWidth ¶
func DetectWidth() int
Width in cells output wraps at: COLUMNS, else the terminal on stdout, the terminals a live display captured, stderr or stdin, else 80
func EmojiShortName ¶
Shortest GitHub style name of an emoji, the name chat platforms take for reactions, a skin toned emoji falling back to the name of its plain form
func Escape ¶
Markup that prints the given text as written wherever it is placed in other markup, no part of it read as a tag: tag shaped parts escaped, a backslash before a bracket doubled, trailing backslashes doubled and closed off by an empty tag pair
func Plain ¶
Text of console markup with its tags resolved, their styles and any escape sequences dropped
func Render ¶
Text of console markup, styled with escape sequences for the terminal's color profile when color is set, plain otherwise
func TerminalProfile ¶
func TerminalProfile() colorprofile.Profile
Color profile of the terminal the program runs in, for output the program has chosen to style: what the terminal shows, at least the sixteen standard colors, attributes without colors under a non empty NO_COLOR
func WrapStyled ¶
Lines of ANSI styled text wrapped at width cells, long words folded, each line closing and reopening the styles it draws in
Types ¶
type BarColumn ¶
type BarColumn struct{ Width int }
Bar of Width cells, forty when zero, filling as steps are done and pulsing while the total is unknown
type Column ¶
type Column struct {
// Header text, printed as written in bold
Header string
// Style definition every cell of the column draws in
Style string
// Cells of content the column always takes, zero to fit the content
Width int
// Most cells of content the column takes, zero for no limit
MaxWidth int
// Side cells align to: left when empty, center or right
Justify string
// What a word wider than the column does: ellipsis when empty cuts it with an ellipsis, fold breaks it across lines, crop cuts it
Overflow string
}
One column of a table: its header, the style its cells draw in and how they fit the column
type Console ¶
type Console struct {
// Destination of everything printed, nothing is written when nil
Out io.Writer
// Whether output is styled with escape sequences
Color bool
// Colors styled output uses, the terminal's own when left unknown or none
Profile colorprofile.Profile
// Cells lines wrap at, DetectWidth when zero
Width int
// Whether Out is an interactive terminal, the only kind status spinners and progress displays animate on
Terminal bool
// Every print dropped
Quiet bool
// Automatic coloring of numbers, quoted strings, paths, addresses and similar literals in printed markup turned off
NoHighlight bool
// Hyperlinks written as their address in parentheses after the linked text instead of as terminal links
NoLinks bool
// Receives the plain text of every print in place of writing it: printed markup unwrapped, tables, panels and renderables as their lines at the width
Capture func(text string)
// contains filtered or unexported fields
}
Printer of console markup, tables, panels and other renderables to a writer, wrapped at a width and styled with escape sequences when color is on
func NewConsole ¶
Console over a writer, styled in the terminal's colors (or forced ones under FORCE_COLOR or CLICOLOR_FORCE) and animated only when the writer is a terminal that is not dumb
func (*Console) Input ¶
Line typed on standard input after the markup prompt, without its line end; io.EOF when input ends before any character
func (*Console) NewProgress ¶
func (c *Console) NewProgress(refresh time.Duration, columns ...ProgressColumn) *Progress
Progress display over the console redrawn every refresh, a tenth of a second when not positive
func (*Console) Print ¶
Prints console markup ([bold red]text[/] styles a run, [link=https://x.io]site[/] links one, \[ is a literal bracket) joined by spaces, wrapped at the width, its literals colored unless NoHighlight is set, a blank line when called without markup
func (*Console) PrintNoHighlight ¶
Prints markup joined by spaces, wrapped at the width, with no coloring of its literals
func (*Console) PrintPanel ¶
Prints a panel at the width, or fitted to its content when it asks
func (*Console) PrintRenderableWith ¶
func (c *Console) PrintRenderableWith(r Renderable, o PrintOptions)
Prints a renderable at the width with the options applied, a style that does not parse laying nothing under it
func (*Console) PrintSoft ¶
Prints markup on lines left unwrapped for the terminal to wrap, so long commands and paths stay whole for copying
func (*Console) PrintTable ¶
Prints a table fitted to the width
type Markdown ¶
type Markdown string
Document in markdown drawn for a terminal: centered and styled headings, emphasis, inline and syntax highlighted code, quotes, lists, tables, links and images
type Panel ¶
type Panel struct {
// Markup inside the box when Content is nil
Body string
// Markup set in the top border
Title string
// Markup set in the bottom border
Subtitle string
// Style definition of the border
BorderStyle string
// Box sized to its content instead of the whole width
Fit bool
// Renderable drawn inside the box in place of Body
Content Renderable
// Border drawn: rounded corners when empty, horizontals for rules above and below only
Box string
// Side the title and subtitle sit on: centered when empty, left or right
TitleAlign string
// Style definition laid under the border, the padding and what the box holds
Style string
// Lines of padding above and below and cells of padding on each side inside the border, none and one when nil
Padding *[2]int
// Most cells the box takes, the print width when zero
Width int
}
Box drawn around markup or a renderable, a title set in its top border and a subtitle in its bottom one, as wide as it prints unless fitted
type PrintOptions ¶
type PrintOptions struct {
// Style definition laid under everything printed
Style string
// Lines left unwrapped and uncut so the terminal wraps them
SoftWrap bool
}
Settings of one renderable print beyond the console's own
type Progress ¶
type Progress struct {
// contains filtered or unexported fields
}
Live display of task rows redrawn in place on a terminal, the final rows printed once on any other writer
func (*Progress) AddTask ¶
Adds a running task of total steps, below zero for an unknown total, and returns its id
func (*Progress) RemoveTask ¶
Removes a task row, an unknown id doing nothing
func (*Progress) Start ¶
func (p *Progress) Start()
Starts the display: redrawn in place on a terminal, every console print to that terminal and, on Unix, whatever reaches the standard output and error descriptors shown above it whole lines at a time; nothing drawn on any other writer until Stop
type ProgressColumn ¶
type ProgressColumn interface {
// contains filtered or unexported methods
}
One cell of each task row of a progress display
type Renderable ¶
type Renderable interface {
// contains filtered or unexported methods
}
Something a console prints as lines laid out at its width: Text, Markdown, a Table or a Panel
type Status ¶
type Status struct {
// contains filtered or unexported fields
}
Spinner beside a markup message on a terminal while work runs, erased when stopped, drawing nothing on other writers
type Style ¶
type Style struct {
// contains filtered or unexported fields
}
Text style of console markup: foreground and background colors, attributes switched on or explicitly off, a hyperlink
func ParseStyle ¶
Style a definition such as "bold red on white", "not italic", "#ff8800", "color(208)", "rgb(10,20,30)" or "link https://example.com" describes
type Table ¶
type Table struct {
// Markup centered above the table
Title string
Columns []Column
// Header row left out
HideHeader bool
// Borders and rules left out, cells set apart by their padding alone
NoBox bool
// Cells of padding on each side of every cell, one when zero
PadX int
// contains filtered or unexported fields
}
Grid of markup cells under bold headers in a box with a heavy head, an italic title centered above it, fitted to the width it prints in
type Task ¶
type Task struct {
ID int
Description string
// Steps done so far
Completed int
// Steps in all, below zero while unknown
Total int
// Time since the task was added, frozen once it finished
Elapsed time.Duration
// Whether the steps done reached the total
Finished bool
}
What a progress column knows about one task when it draws
type TaskProgressColumn ¶
type TaskProgressColumn struct{}
Right aligned percentage done, empty while the total is unknown
type Text ¶
type Text string
ANSI styled or plain text, its colors, attributes and hyperlinks kept, printed as it is and wrapped at the width
type TimeElapsedColumn ¶
type TimeElapsedColumn struct{}
Time since the task was added, frozen at its finish
type TimeRemainingColumn ¶
type TimeRemainingColumn struct{}
Estimated time left, dashes while the speed is unknown, empty while the total is