### Install go-pretty
Source: https://pkg.go.dev/github.com/jedib0t/go-pretty/v6
Use 'go get' to install the latest version of the go-pretty library.
```bash
go get github.com/jedib0t/go-pretty/v6
```
--------------------------------
### Tracker Start Method
Source: https://pkg.go.dev/github.com/jedib0t/go-pretty/v6%40v6.8.1/progress
Start begins the tracking process for cases where DeferStart is set to false. Added in v6.4.7.
```go
func (t *Tracker) Start()
```
--------------------------------
### Table Rendering Example
Source: https://pkg.go.dev/github.com/jedib0t/go-pretty/v6/table
Demonstrates how to render a table in a human-readable pretty format. This example shows a basic table with headers and data rows.
```go
┌─────┬────────────┬───────────┬────────┬─────────────────────────────┐
│ # │ FIRST NAME │ LAST NAME │ SALARY │ │
├─────┼────────────┼───────────┼────────┼─────────────────────────────┤
│ 1 │ Arya │ Stark │ 3000 │ │
│ 20 │ Jon │ Snow │ 2000 │ You know nothing, Jon Snow! │
```
--------------------------------
### Default and Example Color Styles
Source: https://pkg.go.dev/github.com/jedib0t/go-pretty/v6%40v6.8.1/progress
Defines default color settings and an example of custom color configurations for progress trackers.
```go
var (
// StyleColorsDefault defines sane color choices - None.
StyleColorsDefault = StyleColors{}
// StyleColorsExample defines a few choice color options. Use this is just
// as an example to customize the Tracker/text colors.
StyleColorsExample = StyleColors{
Message: text.Colors{text.FgWhite},
Error: text.Colors{text.FgRed},
Percent: text.Colors{text.FgHiRed},
Pinned: text.Colors{text.BgHiBlack, text.FgWhite, text.Bold},
Stats: text.Colors{text.FgHiBlack},
Time: text.Colors{text.FgGreen},
Tracker: text.Colors{text.FgYellow},
Value: text.Colors{text.FgCyan},
Speed: text.Colors{text.FgMagenta},
}
)
```
--------------------------------
### Table Rendering Examples
Source: https://pkg.go.dev/github.com/jedib0t/go-pretty/v6%40v6.8.1/table
Demonstrates how to render tables with and without styling using the go-pretty library.
```APIDOC
## Table Rendering Examples
### Simple Table Output
This example shows a basic table without any customizations.
```
+-----+------------+-----------+--------+-----------------------------+
| # | FIRST NAME | LAST NAME | SALARY | |
+-----+------------+-----------+--------+-----------------------------+
| 1 | Arya | Stark | 3000 | |
| 20 | Jon | Snow | 2000 | You know nothing, Jon Snow! |
| 300 | Tyrion | Lannister | 5000 | |
+-----+------------+-----------+--------+-----------------------------+
| | | TOTAL | 10000 | |
+-----+------------+-----------+--------+-----------------------------+
```
### Styled Table Output
This example demonstrates a table with various customizations and styling applied.
```
┌──────────────────────────────────────────────────────────────────────┐
│ first name last name salary │
├──────────────────────────────────────────────────────────────────────┤
│ 1 arya stark 3000 a girl has no name. │
│ 2 sansa stark 4000 │
│ 3 jon snow 2000 you know nothing, jon snow! │
│ 4 jaime lannister 5000 │
│ 5 tyrion lannister 5000 a lannister always pays his debts. │
├──────────────────────────────────────────────────────────────────────┤
│ total 10000 │
└──────────────────────────────────────────────────────────────────────┘
```
```
--------------------------------
### RenderHTML Example
Source: https://pkg.go.dev/github.com/jedib0t/go-pretty/v6%40v6.8.1/list
An example of how the list is rendered in HTML format, showcasing nested unordered lists with specific CSS classes for styling.
```html
- Game Of Thrones
- The Dark Tower
```
--------------------------------
### Tracker.Start
Source: https://pkg.go.dev/github.com/jedib0t/go-pretty/v6/progress
Marks the tracker as started.
```APIDOC
## func (t *Tracker) Start()
### Description
Marks the tracker as started.
```
--------------------------------
### Simple List Example
Source: https://pkg.go.dev/github.com/jedib0t/go-pretty/v6%40v6.8.1/cmd/demo-list
Renders a basic, single-level bulleted list. Suitable for straightforward itemizations.
```go
A Simple List:
--------------
* Game Of Thrones
* The Dark Tower
```
--------------------------------
### Run 256-Color Palette Demo
Source: https://pkg.go.dev/github.com/jedib0t/go-pretty/v6/cmd/demo-colors
Execute the demo to see the 256-color ANSI palette in action. Ensure you have the go-pretty package installed.
```bash
go run ./cmd/demo-colors
```
--------------------------------
### Simple List Output Example
Source: https://pkg.go.dev/github.com/jedib0t/go-pretty/v6/list
Demonstrates the default rendering of a hierarchical list structure. This output is generated by the go-pretty library.
```text
Output:
Simple List:
├ George. R. R. Martin
│ └─ A Song Of Ice And Fire
│ ├─ Arya Stark
│ ├─ Bran Stark
│ ├─ Rickon Stark
│ ├─ Robb Stark
│ ├─ Sansa Stark
│ └─ Jon Snow
└─ Stephen King
├─ The Dark Tower
│ ├─ Jake Chambers
│ ├─ Randal Flagg
│ └─ Roland Deschain
└─ The Shawshank Redemption
├─ Andy Dufresne
├─ Byron Hadley
├─ Ellis Boyd Redding
└─ Samuel Norton
```
--------------------------------
### Format Apply Method Example
Source: https://pkg.go.dev/github.com/jedib0t/go-pretty/v6%40v6.8.1/text
Demonstrates the Apply method of the Format type, showing text transformations with and without ANSI escape sequences.
```text
Output:
FormatDefault: "jon Snow"
FormatLower : "jon snow"
FormatTitle : "Jon Snow"
FormatUpper : "JON SNOW"
FormatDefault (w/EscSeq): "\x1b[1mjon Snow\x1b[0m"
FormatLower (w/EscSeq): "\x1b[1mjon snow\x1b[0m"
FormatTitle (w/EscSeq): "\x1b[1mJon Snow\x1b[0m"
FormatUpper (w/EscSeq): "\x1b[1mJON SNOW\x1b[0m"
```
--------------------------------
### VAlign Apply Method Example
Source: https://pkg.go.dev/github.com/jedib0t/go-pretty/v6%40v6.8.1/text
Demonstrates the Apply method of VAlign, showing how lines are vertically aligned to fit a maximum number of lines.
```text
Output:
VAlignDefault: []string{"Game", "Of", "Thrones", "", ""}
VAlignTop : []string{"Game", "Of", "Thrones", "", ""}
VAlignMiddle : []string{"", "Game", "Of", "Thrones", ""}
VAlignBottom : []string{"", "", "Game", "Of", "Thrones"}
```
--------------------------------
### Auto Index Column ID Examples
Source: https://pkg.go.dev/github.com/jedib0t/go-pretty/v6/table
Examples demonstrating the output of AutoIndexColumnID for various column indices, mimicking Excel's column naming convention.
```text
Output:
AutoIndexColumnID( 0): "A"
AutoIndexColumnID( 1): "B"
AutoIndexColumnID( 2): "C"
AutoIndexColumnID( 25): "Z"
AutoIndexColumnID( 26): "AA"
AutoIndexColumnID( 702): "AAA"
AutoIndexColumnID(18278): "AAAA"
```
--------------------------------
### SortBy Enum Example
Source: https://pkg.go.dev/github.com/jedib0t/go-pretty/v6%40v6.8.1/progress
Illustrates the SortBy enumeration used for sorting progress trackers.
```go
// SortByValueDsc sorts by the Value in descending order.
SortByValueDsc
```
--------------------------------
### Run Table Colors Demo
Source: https://pkg.go.dev/github.com/jedib0t/go-pretty/v6
Execute the table demo command to see colored table outputs. This requires the go-pretty CLI tools to be installed.
```bash
go run github.com/jedib0t/go-pretty/v6/cmd/demo-table@latest colors
```
--------------------------------
### NewWriter Function
Source: https://pkg.go.dev/github.com/jedib0t/go-pretty/v6%40v6.8.1/list
Initializes and returns a new `Writer` instance. This is the primary function to call to start creating and rendering lists.
```go
func NewWriter() Writer
```
--------------------------------
### Example List Rendering Output
Source: https://pkg.go.dev/github.com/jedib0t/go-pretty/v6%40v6.8.1/list
Demonstrates the visual output of a hierarchical list rendered with the go-pretty library, showcasing nested items and different branches.
```text
Output:
Simple List:
├ George. R. R. Martin
│ └─ A Song Of Ice And Fire
│ ├ Arya Stark
│ ├ Bran Stark
│ ├ Rickon Stark
│ ├ Robb Stark
│ ├ Sansa Stark
│ └ Jon Snow
└─ Stephen King
├─ The Dark Tower
│ ├ Jake Chambers
│ ├ Randal Flagg
│ └ Roland Deschain
└─ The Shawshank Redemption
├ Andy Dufresne
├ Byron Hadley
├ Ellis Boyd Redding
└ Samuel Norton
```
--------------------------------
### WrapSoft Function Example
Source: https://pkg.go.dev/github.com/jedib0t/go-pretty/v6/text
Demonstrates how WrapSoft handles string wrapping with ANSI escape sequences, preserving formatting while moving words to new lines.
```go
func WrapSoft(str string, wrapLen int) string
```
--------------------------------
### Sample Table Rendering
Source: https://pkg.go.dev/github.com/jedib0t/go-pretty/v6/table
Demonstrates the visual output of a rendered table with headers, rows, and a footer. This example shows a basic table structure and content.
```text
+---------------------------------------------------------------------+
| Game of Thrones +
+-----+------------+-----------+--------+-----------------------------+
| # | FIRST NAME | LAST NAME | SALARY | |
+-----+------------+-----------+--------+-----------------------------+
| 1 | Arya | Stark | 3000 | |
| 20 | Jon | Snow | 2000 | You know nothing, Jon Snow! |
| 300 | Tyrion | Lannister | 5000 | |
+-----+------------+-----------+--------+-----------------------------+
| | | TOTAL | 10000 | |
+-----+------------+-----------+--------+-----------------------------+
```
--------------------------------
### Tracker.IsStarted
Source: https://pkg.go.dev/github.com/jedib0t/go-pretty/v6/progress
Checks if the tracker has been started.
```APIDOC
## func (t *Tracker) IsStarted() bool
### Description
Checks if the tracker has been started.
### Returns
* (bool) - True if the tracker has started, false otherwise.
```
--------------------------------
### Pretty-print ASCII Table
Source: https://pkg.go.dev/github.com/jedib0t/go-pretty/v6
Example of a formatted ASCII table generated by go-pretty. This demonstrates the visual output of the table package.
```text
+-----+------------+-----------+--------+-----------------------------+
| # | FIRST NAME | LAST NAME | SALARY | |
+-----+------------+-----------+--------+-----------------------------+
| 1 | Arya | Stark | 3000 | |
| 20 | Jon | Snow | 2000 | You know nothing, Jon Snow! |
| 300 | Tyrion | Lannister | 5000 | |
+-----+------------+-----------+--------+-----------------------------+
| | | TOTAL | 10000 | |
+-----+------------+-----------+--------+-----------------------------+
```
--------------------------------
### Align.Apply Method Example
Source: https://pkg.go.dev/github.com/jedib0t/go-pretty/v6/text
Illustrates the Apply method of the Align type, demonstrating how different alignment settings affect text within a specified maximum length.
```go
func (a Align) Apply(text string, maxLength int) string
// Example:
// * AlignDefault.Apply("Jon Snow", 12) returns "Jon Snow "
// * AlignLeft.Apply("Jon Snow", 12) returns "Jon Snow "
// * AlignCenter.Apply("Jon Snow", 12) returns " Jon Snow "
// * AlignJustify.Apply("Jon Snow", 12) returns "Jon Snow"
// * AlignRight.Apply("Jon Snow", 12) returns " Jon Snow"
// * AlignAuto.Apply("Jon Snow", 12) returns "Jon Snow "
// * AlignAuto.Apply(" -5.43", 12) returns " -5.43"
```
--------------------------------
### WrapText Function Example
Source: https://pkg.go.dev/github.com/jedib0t/go-pretty/v6/text
Shows WrapText's behavior, which is similar to WrapHard but also respects existing line breaks in the input string.
```go
func WrapText(str string, wrapLen int) string
```
--------------------------------
### Pretty-print Hierarchical List
Source: https://pkg.go.dev/github.com/jedib0t/go-pretty/v6
Example of a formatted hierarchical list generated by go-pretty. This demonstrates indentation and structure for nested items.
```text
╭─ Game Of Thrones
│ ├─ Winter
│ ├─ Is
│ ╰─ Coming
│ ├─ This
│ ├─ Is
│ ╰─ Known
╰─ The Dark Tower
╰─ The Gunslinger
```
--------------------------------
### Align.MarkdownProperty Method Example
Source: https://pkg.go.dev/github.com/jedib0t/go-pretty/v6/text
Demonstrates the MarkdownProperty method of the Align type, returning the equivalent Markdown horizontal-align separator, with an option to specify minimum length.
```go
func (a Align) MarkdownProperty(minLength ...int) string
```
--------------------------------
### Default Style Visibility Options
Source: https://pkg.go.dev/github.com/jedib0t/go-pretty/v6%40v6.8.1/progress
Use StyleVisibilityDefault as a starting point for customizing tracker rendering options.
```go
var StyleVisibilityDefault = StyleVisibility{
ETA: false,
ETAOverall: true,
Percentage: true,
Pinned: true,
Speed: false,
SpeedOverall: false,
Time: true,
Tracker: true,
TrackerOverall: false,
Value: true,
}
```
--------------------------------
### Align.HTMLProperty Method Example
Source: https://pkg.go.dev/github.com/jedib0t/go-pretty/v6/text
Shows the HTMLProperty method of the Align type, which returns the corresponding HTML horizontal-align tag property.
```go
func (a Align) HTMLProperty() string
```
--------------------------------
### Example Usage of AutoIndexColumnID
Source: https://pkg.go.dev/github.com/jedib0t/go-pretty/v6%40v6.8.1/table
Demonstrates the output of AutoIndexColumnID for various integer inputs, illustrating the Excel-like column naming.
```text
Output:
AutoIndexColumnID( 0): "A"
AutoIndexColumnID( 1): "B"
AutoIndexColumnID( 2): "C"
AutoIndexColumnID( 25): "Z"
AutoIndexColumnID( 26): "AA"
AutoIndexColumnID( 702): "AAA"
AutoIndexColumnID(18278): "AAAA"
```
--------------------------------
### Apply Text Formatting
Source: https://pkg.go.dev/github.com/jedib0t/go-pretty/v6/text
Converts the text to the specified format (default, lower, title, upper), preserving escape sequences. Includes examples with and without escape sequences.
```go
func (tc Format) Apply(text string) string
```
```text
Output:
FormatDefault: "jon Snow"
FormatLower : "jon snow"
FormatTitle : "Jon Snow"
FormatUpper : "JON SNOW"
FormatDefault (w/EscSeq): "\x1b[1mjon Snow\x1b[0m"
FormatLower (w/EscSeq): "\x1b[1mjon snow\x1b[0m"
FormatTitle (w/EscSeq): "\x1b[1mJon Snow\x1b[0m"
FormatUpper (w/EscSeq): "\x1b[1mJON SNOW\x1b[0m"
```
--------------------------------
### Multi-level List Example
Source: https://pkg.go.dev/github.com/jedib0t/go-pretty/v6%40v6.8.1/cmd/demo-list
Displays a nested list structure, ideal for representing hierarchical data. Indentation clearly defines parent-child relationships.
```go
A Multi-level List:
-------------------
* Game Of Thrones
* Winter
* Is
* Coming
* This
* Is
* Known
* The Dark Tower
* The Gunslinger
```
--------------------------------
### Tracker Initialization and Usage
Source: https://pkg.go.dev/github.com/jedib0t/go-pretty/v6/progress
Instantiate a Tracker with a message, total, and units, then feed it to the Progress Writer. Use Increment to update progress.
```go
Tracker helps track the progress of a single task. The way to use it is to instantiate a Tracker with a valid Message, a valid (expected) Total, and Units values. This should then be fed to the Progress Writer with the Writer.AppendTracker() method. When the task that is being done has progress, increment the value using the Tracker.Increment(value) method.
```
--------------------------------
### LengthDone
Source: https://pkg.go.dev/github.com/jedib0t/go-pretty/v6/progress
Gets the number of trackers that have completed.
```APIDOC
## LengthDone
### Description
LengthDone returns the number of Trackers that are done tracking.
### Method
func (p *Progress) LengthDone() int
```
--------------------------------
### Tracker IsStarted Method
Source: https://pkg.go.dev/github.com/jedib0t/go-pretty/v6%40v6.8.1/progress
IsStarted returns true if the tracker has begun tracking. It returns false if DeferStart is used and Start, Increment, IncrementWithError, or SetValue have not yet been called. Added in v6.4.7.
```go
func (t *Tracker) IsStarted() bool
```
--------------------------------
### LengthInQueue
Source: https://pkg.go.dev/github.com/jedib0t/go-pretty/v6/progress
Gets the number of trackers waiting to be processed.
```APIDOC
## LengthInQueue
### Description
LengthInQueue returns the number of Trackers in queue to be actively tracked (not tracking yet).
### Method
func (p *Progress) LengthInQueue() int
```
--------------------------------
### LengthActive
Source: https://pkg.go.dev/github.com/jedib0t/go-pretty/v6/progress
Gets the number of currently active trackers.
```APIDOC
## LengthActive
### Description
LengthActive returns the number of Trackers actively tracked (not done yet).
### Method
func (p *Progress) LengthActive() int
```
--------------------------------
### Length
Source: https://pkg.go.dev/github.com/jedib0t/go-pretty/v6/progress
Gets the total number of trackers being managed.
```APIDOC
## Length
### Description
Length returns the number of Trackers tracked overall.
### Method
func (p *Progress) Length() int
```
--------------------------------
### EscSeqParser.IsOpen
Source: https://pkg.go.dev/github.com/jedib0t/go-pretty/v6%40v6.8.1/text
Checks if an escape sequence has been started but not yet completed.
```APIDOC
## EscSeqParser.IsOpen
### Description
Checks if an escape sequence has been started but not yet completed.
### Method Signature
func (s *EscSeqParser) IsOpen() bool
### Parameters
#### Path Parameters
- **s** (*EscSeqParser) - The escape sequence parser.
```
--------------------------------
### Get Number of Trackers in Queue
Source: https://pkg.go.dev/github.com/jedib0t/go-pretty/v6%40v6.8.1/progress
LengthInQueue returns the count of trackers that are waiting to be processed.
```go
func (p *Progress) LengthInQueue() int
```
--------------------------------
### Import go-pretty Packages
Source: https://pkg.go.dev/github.com/jedib0t/go-pretty/v6
Import the necessary packages from go-pretty for table, list, progress, and text utilities.
```go
import (
"github.com/jedib0t/go-pretty/v6/table"
"github.com/jedib0t/go-pretty/v6/list"
"github.com/jedib0t/go-pretty/v6/progress"
"github.com/jedib0t/go-pretty/v6/text"
)
```
--------------------------------
### Get Number of Completed Trackers
Source: https://pkg.go.dev/github.com/jedib0t/go-pretty/v6%40v6.8.1/progress
LengthDone returns the count of trackers that have successfully completed their tasks.
```go
func (p *Progress) LengthDone() int
```
--------------------------------
### Table with Header, Rows, and Footer
Source: https://pkg.go.dev/github.com/jedib0t/go-pretty/v6%40v6.8.1/cmd/demo-table
Constructs a table including a header, data rows, and a footer row. Useful for summaries or totals.
```go
package main
import (
"fmt"
"github.com/jedib0t/go-pretty/v6/table"
)
func main() {
t t := table.NewWriter()
t t.AppendHeader(&table.Row{"#", "FIRST NAME", "LAST NAME", "SALARY"})
t t.AppendRows([]interface{}{
table.Row{1, "Arya", "Stark", 3000},
table.Row{20, "Jon", "Snow", 2000},
table.Row{300, "Tyrion", "Lannister", 5000},
})
t t.AppendFooter(&table.Row{"", "", "TOTAL", 10000})
fmt.Println(t.Render())
```
--------------------------------
### Indeterminate Indicator Structure
Source: https://pkg.go.dev/github.com/jedib0t/go-pretty/v6%40v6.8.1/progress
Defines the structure for an indicator used in indeterminate progress displays. Example: {0, <=>}.
```go
type IndeterminateIndicator struct {
Position int
Text string
}
```
--------------------------------
### Get Current Escape Sequence
Source: https://pkg.go.dev/github.com/jedib0t/go-pretty/v6/text
Returns the currently parsed escape sequence string. Added in v6.7.3.
```go
func (s *EscSeqParser) Sequence() string
```
--------------------------------
### Sample List Output
Source: https://pkg.go.dev/github.com/jedib0t/go-pretty/v6%40v6.8.1/list
Demonstrates the hierarchical structure and visual output of a pretty-printed list.
```text
■ Game Of Thrones
■ Winter
■ Is
■ Coming
■ This
■ Is
■ Known
■ The Dark Tower
■ The Gunslinger
```
--------------------------------
### Get Active Codes from EscSeqParser
Source: https://pkg.go.dev/github.com/jedib0t/go-pretty/v6/text
Retrieves the active formatting codes tracked by the EscSeqParser. Added in v6.7.3.
```go
func (s *EscSeqParser) Codes() []int
```
--------------------------------
### Bright Color Options
Source: https://pkg.go.dev/github.com/jedib0t/go-pretty/v6/table
Sets up color options for rendering dark text on a bright background.
```go
// ColorOptionsBright renders dark text on bright background.
ColorOptionsBright = ColorOptionsBlackOnCyanWhite
```
--------------------------------
### Get Number of Active Trackers
Source: https://pkg.go.dev/github.com/jedib0t/go-pretty/v6%40v6.8.1/progress
LengthActive returns the count of trackers that are currently being processed and have not yet finished.
```go
func (p *Progress) LengthActive() int
```
--------------------------------
### Get Total Number of Trackers
Source: https://pkg.go.dev/github.com/jedib0t/go-pretty/v6%40v6.8.1/progress
Length returns the total count of all trackers that have been managed by the Progress instance.
```go
func (p *Progress) Length() int
```
--------------------------------
### Check if EscSeqParser Sequence is Open
Source: https://pkg.go.dev/github.com/jedib0t/go-pretty/v6/text
Indicates whether an escape sequence has been started but not yet completed. Added in v6.7.3.
```go
func (s *EscSeqParser) IsOpen() bool
```
--------------------------------
### Reset Table Rows
Source: https://pkg.go.dev/github.com/jedib0t/go-pretty/v6/table
Clears all previously appended data rows from the table. Use this to start over with a fresh set of rows.
```go
func (t *Table) ResetRows()
```
--------------------------------
### Format Constants
Source: https://pkg.go.dev/github.com/jedib0t/go-pretty/v6%40v6.8.1/text
Enumerates different text formatting options including default, lower case, title case, and upper case.
```go
const (
FormatDefault Format = iota // default_Case
FormatLower // lower
FormatTitle // Title
FormatUpper // UPPER
)
```
--------------------------------
### Render Method
Source: https://pkg.go.dev/github.com/jedib0t/go-pretty/v6%40v6.8.1/list
Renders the list into a human-readable, "pretty" text format. This method is suitable for console output or plain text displays.
```go
func (l *List) Render() string
```
--------------------------------
### Render Multi-level List
Source: https://pkg.go.dev/github.com/jedib0t/go-pretty/v6/cmd/demo-list
Shows how to create nested lists with indentation. Supports hierarchical data structures.
```go
A Multi-level List:
-------------------
* Game Of Thrones
* Winter
* Is
* Coming
* This
* Is
* Known
* The Dark Tower
* The Gunslinger
```
--------------------------------
### Dark Color Options
Source: https://pkg.go.dev/github.com/jedib0t/go-pretty/v6/table
Sets up color options for rendering bright text on a dark background.
```go
// ColorOptionsDark renders bright text on dark background.
ColorOptionsDark = ColorOptionsCyanWhiteOnBlack
```
--------------------------------
### Unit Formatting Options
Source: https://pkg.go.dev/github.com/jedib0t/go-pretty/v6%40v6.8.1/progress
Provides predefined unit formats for displaying values, including default, bytes, and currency.
```go
var (
// UnitsDefault doesn't define any units. The value will be treated as any
// other number.
UnitsDefault = Units{
Notation: "",
NotationPosition: UnitsNotationPositionBefore,
Formatter: FormatNumber,
}
// UnitsBytes defines the value as a storage unit. Values will be converted
// and printed in one of these forms: B, KB, MB, GB, TB, PB
UnitsBytes = Units{
Notation: "",
NotationPosition: UnitsNotationPositionBefore,
Formatter: FormatBytes,
}
// UnitsCurrencyDollar defines the value as a Dollar amount. Values will be
// converted and printed in one of these forms: $x.yz, $x.yzK, $x.yzM,
// $x.yzB, $x.yzT
UnitsCurrencyDollar = Units{
Notation: "$",
NotationPosition: UnitsNotationPositionBefore,
Formatter: FormatNumber,
}
// UnitsCurrencyEuro defines the value as a Euro amount. Values will be
// converted and printed in one of these forms: ₠x.yz, ₠x.yzK, ₠x.yzM,
// ₠x.yzB, ₠x.yzT
UnitsCurrencyEuro = Units{
Notation: "₠",
NotationPosition: UnitsNotationPositionBefore,
Formatter: FormatNumber,
}
)
```
--------------------------------
### Get HTML Property for Color
Source: https://pkg.go.dev/github.com/jedib0t/go-pretty/v6/text
HTMLProperty returns the "class" attribute for the color, suitable for HTML output.
```go
func (c Color) HTMLProperty() string
```
--------------------------------
### Default Table Options
Source: https://pkg.go.dev/github.com/jedib0t/go-pretty/v6/table
Provides default configurations for table rendering. OptionsDefault sets up a table with borders and separators, while OptionsNoBorders and OptionsNoBordersAndSeparators disable these elements.
```go
var (
// OptionsDefault defines sensible global options.
OptionsDefault = Options{
DoNotColorBordersAndSeparators: false,
DrawBorder: true,
SeparateColumns: true,
SeparateFooter: true,
SeparateHeader: true,
SeparateRows: false,
}
// OptionsNoBorders sets up a table without any borders.
OptionsNoBorders = Options{
DoNotColorBordersAndSeparators: false,
DrawBorder: false,
SeparateColumns: true,
SeparateFooter: true,
SeparateHeader: true,
SeparateRows: false,
}
// OptionsNoBordersAndSeparators sets up a table without any borders or
// separators.
OptionsNoBordersAndSeparators = Options{
DoNotColorBordersAndSeparators: false,
DrawBorder: false,
SeparateColumns: false,
SeparateFooter: false,
SeparateHeader: false,
SeparateRows: false,
}
)
```
--------------------------------
### Get ANSI Escape Sequence for Color
Source: https://pkg.go.dev/github.com/jedib0t/go-pretty/v6/text
EscapeSeq returns the ANSI escape sequence for the color. This is used for terminal colorization.
```go
func (c Color) EscapeSeq() string
```
--------------------------------
### Format.Apply
Source: https://pkg.go.dev/github.com/jedib0t/go-pretty/v6%40v6.8.1/text
Applies the format to a string.
```APIDOC
## Format.Apply
### Description
Applies the format to a string. This is a general formatting method.
### Method Signature
func (tc Format) Apply(text string) string
### Parameters
#### Path Parameters
- **tc** (Format) - The format object.
- **text** (string) - The string to format.
```
--------------------------------
### Align.HTMLProperty: Get HTML Alignment Property
Source: https://pkg.go.dev/github.com/jedib0t/go-pretty/v6%40v6.8.1/text
Returns the corresponding HTML horizontal-align tag property string for a given Align value.
```go
func (a Align) HTMLProperty() string
```
```text
Output:
AlignDefault: ''
AlignLeft : 'align="left"'
AlignCenter : 'align="center"'
AlignJustify: 'align="justify"'
AlignRight : 'align="right"'
```
--------------------------------
### Style Function Signature
Source: https://pkg.go.dev/github.com/jedib0t/go-pretty/v6%40v6.8.1/progress
Retrieves the current styling configuration of the progress tracker.
```go
func (p *Progress) Style() *Style
```
--------------------------------
### Render Simple List
Source: https://pkg.go.dev/github.com/jedib0t/go-pretty/v6/cmd/demo-list
Displays a basic bulleted list. This is the default behavior for simple lists.
```go
A Simple List:
--------------
* Game Of Thrones
* The Dark Tower
```
--------------------------------
### Get Current Table Style
Source: https://pkg.go.dev/github.com/jedib0t/go-pretty/v6/table
Retrieves the current Style object applied to the table. This can be useful for inspecting or modifying existing styles.
```go
func (t *Table) Style() *Style
```
--------------------------------
### Get Modifier Character for Text Direction
Source: https://pkg.go.dev/github.com/jedib0t/go-pretty/v6/text
Returns a character to force the given direction for the text that follows the modifier. Added in v6.3.9.
```go
func (d Direction) Modifier() string
```
--------------------------------
### Default Progress Style Options
Source: https://pkg.go.dev/github.com/jedib0t/go-pretty/v6%40v6.8.1/progress
Sets the default style options for progress indicators, including strings for completion and errors, ETA precision, and speed formatting.
```go
var StyleOptionsDefault = StyleOptions{
DoneString: "done!",
ErrorString: "fail!",
ETAPrecision: time.Second,
ETAString: "~ETA",
KeepTrackersTogether: false,
PercentFormat: "%5.2f%%",
PercentIndeterminate: " ??? ",
Separator: " ... ",
SnipIndicator: "~",
SpeedPosition: PositionRight,
SpeedPrecision: time.Microsecond,
SpeedOverallFormatter: FormatNumber,
SpeedSuffix: "/s",
TimeDonePrecision: time.Millisecond,
TimeInProgressPrecision: time.Microsecond,
TimeOverallPrecision: time.Second,
}
```
--------------------------------
### Style
Source: https://pkg.go.dev/github.com/jedib0t/go-pretty/v6%40v6.8.1/progress
Retrieves the current styling configuration for the progress display.
```APIDOC
## func (*Progress) Style
### Description
Style returns the current Style.
### Signature
```go
func (p *Progress) Style() *Style
```
```
--------------------------------
### RenderHTML Method
Source: https://pkg.go.dev/github.com/jedib0t/go-pretty/v6%40v6.8.1/list
Renders the list in HTML format, using unordered lists (``) and list items (`- `). It supports nested structures and custom CSS classes.
```go
func (l *List) RenderHTML() string
```
--------------------------------
### Simple Table
Source: https://pkg.go.dev/github.com/jedib0t/go-pretty/v6%40v6.8.1/cmd/demo-table
Renders a basic table with rows and columns. Used for straightforward data presentation.
```go
package main
import (
"fmt"
"github.com/jedib0t/go-pretty/v6/table"
)
func main() {
t t := table.NewWriter()
t t.AppendHeader(&table.Row{"", "First Name", "Last Name", "Salary"})
t t.AppendRows([]interface{}{
table.Row{1, "Arya", "Stark", 3000},
table.Row{20, "Jon", "Snow", 2000},
table.Row{300, "Tyrion", "Lannister", 5000},
})
fmt.Println(t.Render())
```
--------------------------------
### Writer Interface for Progress Trackers
Source: https://pkg.go.dev/github.com/jedib0t/go-pretty/v6%40v6.8.1/progress
The `Writer` interface defines methods for managing and rendering progress trackers. Use this to configure tracker display, output, and behavior.
```go
type Writer interface {
AppendTracker(tracker *Tracker)
AppendTrackers(trackers []*Tracker)
IsRenderInProgress() bool
Length() int
LengthActive() int
LengthDone() int
LengthInQueue() int
Log(msg string, a ...interface{})
SetAutoStop(autoStop bool)
SetMessageLength(length int)
SetNumTrackersExpected(numTrackers int)
SetOutputWriter(output io.Writer)
SetPinnedMessages(messages ...string)
SetSortBy(sortBy SortBy)
SetStyle(style Style)
SetTerminalWidth(width int)
SetTrackerLength(length int)
SetTrackerPosition(position Position)
SetUpdateFrequency(frequency time.Duration)
Stop()
Style() *Style
Render()
// Deprecated: in favor of SetMessageLength(length)
SetMessageWidth(width int)
// Deprecated: in favor of Style().Visibility.ETA
ShowETA(show bool)
// Deprecated: in favor of Style().Visibility.OverallTracker
ShowOverallTracker(show bool)
// Deprecated: in favor of Style().Visibility.Percentage
ShowPercentage(show bool)
// Deprecated: in favor of Style().Visibility.Time
ShowTime(show bool)
// Deprecated: in favor of Style().Visibility.Tracker
ShowTracker(show bool)
// Deprecated: in favor of Style().Visibility.Value
ShowValue(show bool)
}
```
--------------------------------
### Get CSS Class Names for Color
Source: https://pkg.go.dev/github.com/jedib0t/go-pretty/v6/text
CSSClasses returns the CSS class names for the color. This is useful for applying styles in web-based terminals.
```go
func (c Color) CSSClasses() string
```
--------------------------------
### Is Render In Progress Method
Source: https://pkg.go.dev/github.com/jedib0t/go-pretty/v6%40v6.8.1/progress
Checks if the rendering process for the Progress tracker is currently active.
```go
func (p *Progress) IsRenderInProgress() bool
```
--------------------------------
### Default Size Options
Source: https://pkg.go.dev/github.com/jedib0t/go-pretty/v6/table
Defines default size options for tables, with minimum and maximum width set to zero.
```go
var (
// SizeOptionsDefault defines sensible size options - basically NONE.
SizeOptionsDefault = SizeOptions{
WidthMax: 0,
WidthMin: 0,
}
)
```
--------------------------------
### Progress.SetUpdateFrequency
Source: https://pkg.go.dev/github.com/jedib0t/go-pretty/v6/progress
Sets how often the progress bar should update its display.
```APIDOC
## func (p *Progress) SetUpdateFrequency(frequency time.Duration)
### Description
Sets how often the progress bar should update its display.
### Parameters
* **frequency** (time.Duration) - The update frequency.
```
--------------------------------
### StyleLight Configuration
Source: https://pkg.go.dev/github.com/jedib0t/go-pretty/v6%40v6.8.1/table
Defines the 'StyleLight' for rendering tables with light, single-line borders. This style provides a cleaner, less intrusive visual presentation.
```go
// StyleLight renders a Table like below:
// ┌─────┬────────────┬───────────┬────────┬─────────────────────────────┐
// │ # │ FIRST NAME │ LAST NAME │ SALARY │ │
// ├─────┼────────────┼───────────┼────────┼─────────────────────────────┤
// │ 1 │ Arya │ Stark │ 3000 │ │
// │ 20 │ Jon │ Snow │ 2000 │ You know nothing, Jon Snow!
// │ 300 │ Tyrion │ Lannister │ 5000 │ │
// ├─────┼────────────┼───────────┼────────┼─────────────────────────────┤
// │ │ │ TOTAL │ 10000 │ │
// └─────┴────────────┴───────────┴────────┴─────────────────────────────┘
StyleLight = Style{
Name: "StyleLight",
Box: StyleBoxLight,
Color: ColorOptionsDefault,
Format: FormatOptionsDefault,
HTML: DefaultHTMLOptions,
Options: OptionsDefault,
Size: SizeOptionsDefault,
Title: TitleOptionsDefault,
}
)
```
--------------------------------
### Render Progress Trackers
Source: https://pkg.go.dev/github.com/jedib0t/go-pretty/v6%40v6.8.1/progress
Render displays the progress trackers and dynamically handles any trackers added during its execution.
```go
func (p *Progress) Render()
```
--------------------------------
### Get ANSI Escape Sequence for Multiple Colors
Source: https://pkg.go.dev/github.com/jedib0t/go-pretty/v6/text
EscapeSeq returns the ANSI escape sequence for a set of colors. Multiple sequences are combined with a semicolon.
```go
func (c Colors) EscapeSeq() string
```
--------------------------------
### Set Column Configurations
Source: https://pkg.go.dev/github.com/jedib0t/go-pretty/v6/table
Applies specific configurations to each column of the table, allowing for fine-grained control over their appearance and behavior.
```go
func (t *Table) SetColumnConfigs(configs []ColumnConfig)
```
--------------------------------
### Tracker Struct
Source: https://pkg.go.dev/github.com/jedib0t/go-pretty/v6%40v6.8.1/progress
The Tracker struct represents an individual progress bar item, holding its state and configuration, including options for automatic stopping and deferred starting.
```APIDOC
## type Tracker
### Description
The Tracker struct represents an individual progress bar item.
### Fields
- **AutoStopDisabled** (bool) - prevents the tracker from marking itself as done when the value goes beyond the total (if set). Note that this means that a manual call to MarkAsDone or MarkAsErrored is expected.
- **DeferStart** (bool) - prevents the tracker from starting immediately when appended. It will be rendered but remain dormant until Start, Increment, IncrementWithError or SetValue is called.
- **ExpectedDuration** (time.Duration) - tells how long this task is expected to take; and will
```
--------------------------------
### RenderMarkdown Method
Source: https://pkg.go.dev/github.com/jedib0t/go-pretty/v6%40v6.8.1/list
Renders the list in Markdown format. This method is useful for generating lists that can be displayed in Markdown-compatible environments.
```go
func (l *List) RenderMarkdown() string
```
--------------------------------
### Align.MarkdownProperty: Get Markdown Alignment Separator
Source: https://pkg.go.dev/github.com/jedib0t/go-pretty/v6%40v6.8.1/text
Generates the Markdown horizontal-align separator string. An optional minimum length can be provided to match column content width.
```go
func (a Align) MarkdownProperty(minLength ...int) string
```
```text
Output:
AlignDefault: ' --- '
AlignLeft : ':--- '
AlignCenter : ':---:'
AlignJustify: ' --- '
AlignRight : ' ---:'
```
--------------------------------
### StyleOptions Struct
Source: https://pkg.go.dev/github.com/jedib0t/go-pretty/v6/progress
StyleOptions defines misc. options to control how the Tracker or its parts gets rendered, such as strings for done/error states, ETA precision, and speed formatting.
```APIDOC
## type StyleOptions
```go
type StyleOptions struct {
DoneString string // "done!" string
ErrorString string // "error!" string
ETAPrecision time.Duration // precision for ETA
ETAString string // string for ETA
KeepTrackersTogether bool // keep done and active trackers together in one repainted frame (needed for SortByIndex to reorder done trackers)
Separator string // text between message and tracker
SnipIndicator string // text denoting message snipping
PercentFormat string // formatting to use for percentage
PercentIndeterminate string // when percentage cannot be computed
SpeedPosition Position // where speed is displayed in stats
SpeedPrecision time.Duration // precision for speed
SpeedOverallFormatter UnitsFormatter // formatter for the overall tracker speed
SpeedSuffix string // suffix (/s)
TimeDonePrecision time.Duration // precision for time when done
TimeInProgressPrecision time.Duration // precision for time when in progress
TimeOverallPrecision time.Duration // precision for overall time
}
```
StyleOptions defines misc. options to control how the Tracker or its parts gets rendered.
```
--------------------------------
### Get HTML Property for Multiple Colors
Source: https://pkg.go.dev/github.com/jedib0t/go-pretty/v6/text
HTMLProperty returns the "class" attribute for an array of Color objects, combining multiple class names.
```go
func (c Colors) HTMLProperty() string
```
--------------------------------
### Simple Table Rendering
Source: https://pkg.go.dev/github.com/jedib0t/go-pretty/v6/table
Renders a basic table without any customizations. This is useful for displaying data in a straightforward, unformatted manner.
```go
package main
import (
"fmt"
"io"
"os"
"github.com/jedib0t/go-pretty/v6/table"
)
func main() {
t t := table.NewWriter()
t t.SetOutputMirror(io.Discard) // Discard output, we are just showing the table
t t.AppendHeader(
table.Row{
"#",
"FIRST NAME",
"LAST NAME",
"SALARY",
"",
},
)
t t.AppendRows(
table.Rows{
{1, "Arya", "Stark", 3000, ""},
{20, "Jon", "Snow", 2000, "You know nothing, Jon Snow!"},
{300, "Tyrion", "Lannister", 5000, ""},
},
)
t t.AppendFooter(
table.Row{
"",
"",
"TOTAL",
10000,
"",
},
)
fmt.Println(t.Render())
}
```
--------------------------------
### Get CSS Class Names for Multiple Colors
Source: https://pkg.go.dev/github.com/jedib0t/go-pretty/v6/text
CSSClasses returns the CSS class names for an array of Color objects. This allows for combining multiple styles.
```go
func (c Colors) CSSClasses() string
```
--------------------------------
### Progress Methods
Source: https://pkg.go.dev/github.com/jedib0t/go-pretty/v6%40v6.8.1/progress
Methods for managing and rendering progress bars.
```APIDOC
## Progress Methods
### Description
Methods associated with the `Progress` type, used for controlling and customizing the display of progress bars and trackers.
### Methods
* **AppendTracker(t *Tracker)**
Appends a single tracker to the progress display.
* **AppendTrackers(trackers []*Tracker)**
Appends multiple trackers to the progress display.
* **IsRenderInProgress() bool**
Checks if the progress rendering is currently active.
* **Length() int**
Returns the total number of trackers currently managed.
* **LengthActive() int**
Returns the number of currently active trackers.
* **LengthDone() int**
Returns the number of completed trackers.
* **LengthInQueue() int**
Returns the number of trackers waiting to be processed.
* **Log(msg string, a ...interface{})**
Logs a message to the progress display, typically above the progress bars.
* **Render()**
Manually triggers a render of the progress bars.
* **SetAutoStop(autoStop bool)**
Configures whether the progress display should automatically stop when all trackers are done.
* **SetMessageLength(length int)**
Sets the maximum width for tracker messages.
* **SetMessageWidth(width int)**
Sets the width for the tracker message area.
* **SetNumTrackersExpected(numTrackers int)**
Informs the progress display about the expected total number of trackers.
* **SetOutputWriter(writer io.Writer)**
Sets the output writer for the progress display (defaults to `os.Stderr`).
* **SetPinnedMessages(messages ...string)**
Sets messages that will remain pinned at the top of the display.
* **SetSortBy(sortBy SortBy)**
Sets the sorting criteria for the trackers.
* **SetStyle(style Style)**
Applies a custom style to the progress display.
* **SetTerminalWidth(width int)**
Manually sets the terminal width, useful when auto-detection fails.
* **SetTrackerLength(length int)**
Sets the default length for all trackers.
* **SetTrackerPosition(position Position)**
Sets the position of the trackers within the display.
* **SetUpdateFrequency(frequency time.Duration)**
Sets how often the progress display should update.
* **ShowETA(show bool)**
Toggles the display of the Estimated Time of Arrival (ETA).
* **ShowOverallTracker(show bool)**
Toggles the display of an overall progress tracker.
* **ShowPercentage(show bool)**
Toggles the display of the percentage completion for each tracker.
* **ShowTime(show bool)**
Toggles the display of elapsed time.
* **ShowTracker(show bool)**
Toggles the display of individual trackers.
* **ShowValue(show bool)**
Toggles the display of the current value and total for each tracker.
* **Stop()**
Stops the progress rendering and cleans up the display.
* **Style() *Style**
Returns the current style configuration of the progress display.
```
--------------------------------
### StyleMarkdown
Source: https://pkg.go.dev/github.com/jedib0t/go-pretty/v6%40v6.8.1/list
Renders a list using markdown-like bullet points and line breaks. Use this for compatibility with markdown rendering.
```go
StyleMarkdown = Style{
Format: text.FormatDefault,
CharItemSingle: "*",
CharItemTop: "*",
CharItemFirst: "*",
CharItemMiddle: "*",
CharItemVertical: " ",
CharItemBottom: "*",
CharNewline: "
",
LinePrefix: " ",
Name: "StyleMarkdown",
}
```
--------------------------------
### ANSI Escape Sequence Definitions
Source: https://pkg.go.dev/github.com/jedib0t/go-pretty/v6/text
Defines various constants for constructing and managing ANSI escape sequences, including reset, start, and stop codes for CSI and OSI.
```go
const (
EscapeReset = EscapeResetCSI
EscapeResetCSI = EscapeStartCSI + "0" + EscapeStopCSI
EscapeResetOSI = EscapeStartOSI + "0" + EscapeStopOSI
EscapeStart = EscapeStartCSI
EscapeStartCSI = "\x1b["
EscapeStartOSI = "\x1b]"
EscapeStartRune = rune(27) // \x1b
EscapeStartRuneCSI = '[' // [
EscapeStartRuneOSI = ']'
EscapeStop = EscapeStopCSI
EscapeStopCSI = "m"
EscapeStopOSI = "\"
EscapeStopRune = EscapeStopRuneCSI
EscapeStopRuneCSI = 'm'
EscapeStopRuneOSI = '\'
)
```
--------------------------------
### Style
Source: https://pkg.go.dev/github.com/jedib0t/go-pretty/v6/list
Style returns the current rendering style configuration.
```APIDOC
## Method: Style
Style returns the current style.
### Signature
```go
func (l *List) Style() *Style
```
```
--------------------------------
### ProcessCRLF
Source: https://pkg.go.dev/github.com/jedib0t/go-pretty/v6/text
Converts "\r\n" to "\n", and processes lone "\r" by moving the cursor/carriage to the start of the line and overwrites the contents accordingly.
```APIDOC
## func ProcessCRLF
### Description
Converts "\r\n" to "\n", and processes lone "\r" by moving the cursor/carriage to the start of the line and overwrites the contents accordingly.
### Method
`func ProcessCRLF(str string) string`
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
None
### Request Example
```
ProcessCRLF("abc")
ProcessCRLF("abc\r\ndef")
ProcessCRLF("abc\r\ndef\rghi")
ProcessCRLF("abc\r\ndef\rghi\njkl")
ProcessCRLF("abc\r\ndef\rghi\njkl\r")
ProcessCRLF("abc\r\ndef\rghi\rjkl\rmn")
```
### Response
#### Success Response (200)
`string` - The processed string.
#### Response Example
```
Output:
"abc"
"abc\ndef"
"abc\nghi"
"abc\nghi\njkl"
"abc\nghi\njkl"
"abc\nmnl"
```
```
--------------------------------
### SetOutputMirror Method
Source: https://pkg.go.dev/github.com/jedib0t/go-pretty/v6%40v6.8.1/list
Sets an `io.Writer` to which all rendered output will also be written. This allows for simultaneous output to a string and another writer (e.g., standard output).
```go
func (l *List) SetOutputMirror(mirror io.Writer)
```
--------------------------------
### Rune Constants for ANSI Sequences
Source: https://pkg.go.dev/github.com/jedib0t/go-pretty/v6/text
Defines rune constants for the start and stop characters of ANSI Control Sequence Introducer (CSI) and Operating System Command (OSC) sequences.
```go
const (
CSIStartRune = EscapeStartRuneCSI
CSIStopRune = EscapeStopRuneCSI
OSIStartRune = EscapeStartRuneOSI
OSIStopRune = EscapeStopRuneOSI
)
```
--------------------------------
### Table Size Options
Source: https://pkg.go.dev/github.com/jedib0t/go-pretty/v6/table
SizeOptions defines how to control the width of the table output. WidthMax sets the maximum allotted width, truncating content if necessary, while WidthMin ensures a minimum overall width by expanding columns.
```go
type SizeOptions struct {
// WidthMax is the maximum allotted width for the full row;
// any content beyond this will be truncated using the text
// in Style.Box.UnfinishedRow
WidthMax int
// WidthMin is the minimum allotted width for the full row;
// columns will be auto-expanded until the overall width
// is met
WidthMin int
}
```
--------------------------------
### Default CSV Rendering Options
Source: https://pkg.go.dev/github.com/jedib0t/go-pretty/v6/table
Defines the default settings for rendering tables as CSV. This includes options for handling empty columns and text escaping.
```go
var (
// DefaultCSVOptions defines sensible CSV rendering defaults.
DefaultCSVOptions = CSVOptions{}
)
```
--------------------------------
### HTMLProperty: Get HTML Vertical Align Attribute
Source: https://pkg.go.dev/github.com/jedib0t/go-pretty/v6%40v6.8.1/text
Returns the HTML 'valign' attribute string for a given VAlign. Useful for generating HTML tables with vertically aligned content.
```go
func (va VAlign) HTMLProperty() string
```