Documentation
¶
Index ¶
- Variables
- func AddSection(t AscWriter, s Section)
- func AddSections(t AscWriter, sections []Section)
- func BuildHeaderRow(fields []Field) []string
- func RenderList(opts RenderListOptions)
- func SetFieldVisibility(fields []Field, name string, visible bool)
- type AscTable
- func (at *AscTable) AppendGridRow(ar GridRow)
- func (at *AscTable) AppendGridRows(ar []GridRow)
- func (at *AscTable) AppendHeader(headers []string)
- func (at *AscTable) AppendHorizontalRow(hr HorizontalRow)
- func (at *AscTable) AppendHorizontalRows(hr []HorizontalRow)
- func (at *AscTable) AppendRow(row Row)
- func (at *AscTable) AppendRows(rows []Row)
- func (at *AscTable) AppendTitleRow(title string)
- func (at *AscTable) GetColumns() int
- func (at *AscTable) Render()
- func (at *AscTable) SetColumnWidth(minWidth int, maxWidth int)
- func (at *AscTable) SetFieldConfigs(fields []Field, reverse bool)
- func (at *AscTable) SetRenderStyle(style string)
- func (at *AscTable) SetStyle(style string)
- type AscTableRenderOptions
- type AscWriter
- type AttributeGetter
- type DetailTable
- type Field
- type GridRow
- type HorizontalRow
- type Layout
- type ListTable
- type RenderListOptions
- type Row
- type Section
- type SectionConfig
- type SortDirection
- type TagGetter
Constants ¶
This section is empty.
Variables ¶
var ( // StyleRounded is a table style that displays a list of items with rounded corners. // ╭──────────────────────────────────────────────────────────────────────────────────────╮ // │ EC2 Instances │ // ├─────────────────────┬─────────────────────┬─────────┬───────────────┬────────────────┤ // │ Name │ Instance ID │ State │ Instance Type │ Public IP │ // ├─────────────────────┼─────────────────────┼─────────┼───────────────┼────────────────┤ // │ web-server-prod │ i-0abc123def456789a │ running │ m7i.xlarge │ 18.134.56.201 │ // │ app-server-staging │ i-0def456789abc123b │ running │ r7i.xlarge │ 35.178.45.123 │ // │ database-primary │ i-0789abc123def456c │ running │ c7i.large │ 52.49.178.90 │ // ╰─────────────────────┴─────────────────────┴─────────┴───────────────┴────────────────╯ StyleRounded = table.Style{ Name: "rounded", Box: table.StyleBoxRounded, Color: ColorOptionsDefault, Format: table.FormatOptions{Header: text.FormatTitle}, Options: table.OptionsDefault, Size: table.SizeOptionsDefault, Title: table.TitleOptionsDefault, } // StylePlain is a table style that displays a list of items with no borders or separators. // NAME INSTANCE ID STATE INSTANCE TYPE PUBLIC IP // web-server-prod i-0abc123def456789a running m7i.xlarge 18.134.56.201 // app-server-staging i-0def456789abc123b running r7i.xlarge 35.178.45.123 // database-primary i-0789abc123def456c running c7i.large 52.49.178.90 StylePlain = table.Style{ Name: "list", Box: table.StyleBoxRounded, Color: ColorOptionsDefault, Format: table.FormatOptionsDefault, Options: table.OptionsNoBordersAndSeparators, } // Style RoundedSeparated is a table style that displays a list of items with rounded corners and separated rows. // ╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ // │ RDS Clusters and Instances │ // ├────────────────────┬────────────────────────────────────┬───────────┬──────────────┬────────────────┬────────┤ // │ Cluster Identifier │ Instance Identifier │ Status │ Engine │ Size │ Role │ // ├────────────────────┼────────────────────────────────────┼───────────┼──────────────┼────────────────┼────────┤ // │ prod-cluster-01 │ prod-cluster-01-instance-1 │ available │ aurora-mysql │ db.r6g.2xlarge │ Writer │ // │ ├────────────────────────────────────┼───────────┼──────────────┼────────────────┼────────┤ // │ │ prod-cluster-01-instance-2 │ available │ aurora-mysql │ db.r6g.2xlarge │ Reader │ // ├────────────────────┼────────────────────────────────────┼───────────┼──────────────┼────────────────┼────────┤ // │ dev-cluster-01 │ dev-cluster-01-instance-1 │ available │ aurora-mysql │ db.t3.medium │ Reader │ // │ ├────────────────────────────────────┼───────────┼──────────────┼────────────────┼────────┤ // │ │ dev-cluster-01-instance-2 │ available │ aurora-mysql │ db.t4g.medium │ Writer │ // ╰────────────────────┴────────────────────────────────────┴───────────┴──────────────┴────────────────┴────────╯ StyleRoundedSeparated = table.Style{ Name: "rounded-separated", Box: table.StyleBoxRounded, Color: ColorOptionsDefault, Format: table.FormatOptions{Header: text.FormatTitle}, Options: DrawAllBordersAndSeparators, Size: table.SizeOptionsDefault, Title: table.TitleOptionsDefault, } )
var ( ColorOptionsDefault = table.ColorOptions{ Border: text.Colors{}, Footer: text.Colors{}, Header: text.Colors{text.Bold}, IndexColumn: text.Colors{}, Row: text.Colors{}, RowAlternate: text.Colors{}, Separator: text.Colors{}, } )
ColorOptions
var ( DrawAllBordersAndSeparators = table.Options{ DrawBorder: true, SeparateColumns: true, SeparateFooter: true, SeparateHeader: true, SeparateRows: true, } )
Options
var TableStyles = map[string]table.Style{ "rounded": StyleRounded, "plain": StylePlain, "rounded-separated": StyleRoundedSeparated, }
Functions ¶
func AddSection ¶
AddSection adds a single section to a table writer
func AddSections ¶
AddSections adds multiple sections to a table writer
func BuildHeaderRow ¶
func RenderList ¶ added in v0.2.1
func RenderList(opts RenderListOptions)
RenderList creates and renders a list-style table with the provided options. This helper consolidates the common pattern used across all list commands:
- Creates a table with the specified title and style
- Applies plain style if PlainStyle is true
- Appends tag fields to the field list
- Builds and appends header row
- Builds and appends data rows using the provided getters
- Configures field sorting
- Renders the table
func SetFieldVisibility ¶ added in v0.2.1
SetFieldVisibility sets the visibility of a field by name. It iterates through the fields slice and sets Visible to the specified value for the first field matching the given name.
Types ¶
type AscTable ¶
type AscTable struct {
// contains filtered or unexported fields
}
AscTable is the implementation of the AscWriter interface.
func (*AscTable) AppendGridRow ¶
AppendGridRow creates a new grid row with the provided fields and values.
┌───────────────────────┬─────────────────────────┬───────────────────────┐ │ FirstName │ LastName │ Age │ ├───────────────────────┼─────────────────────────┼───────────────────────┤ │ John │ Doe │ 30 │ ├───────────────────────┼─────────────────────────┼───────────────────────┤
func (*AscTable) AppendGridRows ¶
AppendGridRows accepts a list of GridRows and creates new grid rows for each.
func (*AscTable) AppendHeader ¶
AppendHeader creates a header row that will be formatted according to the table style.
┌───────────────────────┬─────────────────────────┬───────────────────────┐ │ FirstName │ LastName │ Age │ ├───────────────────────┼─────────────────────────┼───────────────────────┤
func (*AscTable) AppendHorizontalRow ¶
func (at *AscTable) AppendHorizontalRow(hr HorizontalRow)
AppendHorizontalRow creates a new row that is made up of the provided name (column 1) and the value (all remaining columns, merged).
┌───────────────────────┬─────────────────────────────────────────────────┐ │ Name │ John Doe │ ╰───────────────────────┴─────────────────────────────────────────────────╯
func (*AscTable) AppendHorizontalRows ¶
func (at *AscTable) AppendHorizontalRows(hr []HorizontalRow)
AppendHorizontalRow accepts a list of Rows and creates new horizontal rows for each.
func (*AscTable) AppendRows ¶
AppendRows creates a new row for each of the provided rows.
func (*AscTable) AppendTitleRow ¶
AppendHeaderRow creates a new row that is made up of the provided title * at.columns times.
┌─────────────────────────────────────────────────────────────────────────┐ │ Title │ ╰─────────────────────────────────────────────────────────────────────────╯
func (*AscTable) GetColumns ¶
GetColumns returns the number of columns in the table
func (*AscTable) SetColumnWidth ¶
SetColumnWidth sets the minimum and maximum width for all columns.
func (*AscTable) SetFieldConfigs ¶
SetFieldConfigs sets the field configurations for the table.
func (*AscTable) SetRenderStyle ¶
SetRenderStyle sets the style for rendering
type AscTableRenderOptions ¶
type AscTableRenderOptions struct {
Title string
Style string
Columns int
ColumnConfigs []table.ColumnConfig
MinColumnWidth int
MaxColumnWidth int
MergedColumns []string
}
AscTableRenderOptions is the options for the AscTable.
type AscWriter ¶
type AscWriter interface {
AppendRow(row Row)
AppendRows(rows []Row)
AppendHeader(headers []string)
AppendTitleRow(title string)
AppendHorizontalRow(hr HorizontalRow)
AppendHorizontalRows([]HorizontalRow)
AppendGridRow(ar GridRow)
AppendGridRows([]GridRow)
Render()
SetColumnWidth(minWidth int, maxWidth int)
GetColumns() int
SetStyle(style string)
SetRenderStyle(style string)
SetFieldConfigs(fields []Field, reverse bool)
}
AscWriter is the interface for the AscTable.
func NewAscWriter ¶
func NewAscWriter(renderOptions AscTableRenderOptions) AscWriter
NewAscWriter creates a new AscWriter with the provided number of columns.
type AttributeGetter ¶
AttributeGetter is a function type that retrieves a field value from an instance
type DetailTable ¶
type DetailTable struct {
Headers []string
Rows []Row
Options AscTableRenderOptions
Sections []Section
}
DetailTable handles detailed tables.
func NewDetailTable ¶
func NewDetailTable(options AscTableRenderOptions) *DetailTable
NewDetailTable creates a new DetailTable.
func (*DetailTable) AddHeader ¶
func (dt *DetailTable) AddHeader(headers []string)
func (*DetailTable) AddRow ¶
func (dt *DetailTable) AddRow(row Row)
func (*DetailTable) AddSection ¶
func (dt *DetailTable) AddSection(s Section)
AddSection adds a section to the detail table
func (*DetailTable) AddSections ¶
func (dt *DetailTable) AddSections(sections []Section)
AddSections adds multiple sections to the detail table
func (*DetailTable) Render ¶
func (dt *DetailTable) Render()
type Field ¶
type Field struct {
Category string
Name string
Value string
Visible bool
Merge bool
DefaultSort bool
SortBy bool
SortDirection SortDirection
}
Field is a single field in a row. It contains a name and a value.
func PopulateFieldValues ¶
func PopulateFieldValues(instance any, fields []Field, getFieldValue AttributeGetter) ([]Field, error)
type GridRow ¶
type GridRow struct {
Fields []Field
}
GridRow is made up of two go-pretty table.Row objects. The first row is one or more field names, and the second row is the value(s) for each field.
type HorizontalRow ¶
type HorizontalRow struct {
Field Field
}
HorizontalRow is made up of a single field. The field name is the first column, and the value is the rest of the columns.
type ListTable ¶
type ListTable struct {
Headers []string
Rows []Row
Options AscTableRenderOptions
}
ListTable handles simple list-style tables
func NewListTable ¶
func NewListTable(options AscTableRenderOptions) *ListTable
NewListTable creates a new ListTable.
type RenderListOptions ¶ added in v0.2.1
type RenderListOptions struct {
Title string
Style string
PlainStyle bool
Fields []Field
Tags []string
Data []any
GetFieldValue AttributeGetter
GetTagValue TagGetter
ReverseSort bool
HideEmpty bool
}
RenderListOptions contains the configuration for rendering a list table.
type Row ¶
type Row struct {
Values []string
}
Row is a single row of a table. It contains a list of values.
type Section ¶
type Section struct {
SectionConfig SectionConfig
Fields []Field
Title string
}
Section is a section of a table. It contains a title, fields, and a section config.
func BuildSection ¶
BuildSection builds a section with a row layout.
func BuildSections ¶
BuildSections builds a list of sections from a list of fields with a grid layout. The title of each section is the category of the fields.
type SectionConfig ¶
type SectionConfig struct {
Layout Layout
}
SectionConfig is the configuration for a section. For now the SectionConfig only contains a "Layout" The Layout can be "Grid" or "Horizontal"
type SortDirection ¶
SortDirection is the direction of the sort.
const ( Asc SortDirection = SortDirection(table.AscNumericAlpha) Desc SortDirection = SortDirection(table.DscNumericAlpha) )