ui

package
v3.12.0 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultHeaderColours defines the default colours used for headers
	DefaultHeaderColours = text.Colors{text.Bold}
	// DefaultUUUIDColours defines the default colours used for UUIDs
	DefaultUUUIDColours = text.Colors{text.FgHiBlue}
	// DefaultErrorColours defines the default colours used for errors
	DefaultErrorColours = text.Colors{text.FgHiRed, text.Bold}
	// DefaultAddressColours defines the default colours used for addresses
	DefaultAddressColours = text.Colors{text.FgHiMagenta}
	// DefaultBooleanColoursTrue defines the default colours used for boolean true values
	DefaultBooleanColoursTrue = text.Colors{text.FgHiGreen}
	// DefaultBooleanColoursFalse defines the default colours used for boolean false values
	DefaultBooleanColoursFalse = text.Colors{text.FgHiBlack}
	// DefaultNoteColours defines the default colours used for notes
	DefaultNoteColours = text.Colors{text.FgHiBlack}
)
View Source
var ListLayoutDefault = listLayoutConfig{
	MarginLeft:    true,
	MarginTop:     true,
	MarginBottom:  false,
	PadTop:        false,
	PadBottom:     false,
	NoteSeparator: true,
}

ListLayoutDefault defines the default config used for rendering lists

View Source
var ListLayoutNestedTable = listLayoutConfig{
	MarginLeft:    false,
	MarginTop:     false,
	MarginBottom:  false,
	PadTop:        true,
	PadBottom:     false,
	NoteSeparator: true,
}

ListLayoutNestedTable defines the configuration used for rendering nested tables

Functions

func AbbrevNum

func AbbrevNum(raw uint) string

AbbrevNum returns a string with the given number abbreviated with SI formatting (eg 1000 = 1k)

func AbbrevNumBinaryPrefix

func AbbrevNumBinaryPrefix(raw uint) string

AbbrevNumBinaryPrefix returns a string with the given number abbreviated with binary formatting (eg 1024 = 1ki)

func CommandUsageTemplate

func CommandUsageTemplate() string

CommandUsageTemplate returns the template for usage

func ConcatStrings

func ConcatStrings(strs ...string) string

ConcatStrings like join but handles well the empty strings

func FormatBool

func FormatBool(v bool) string

FormatBool return v formatted (eg. colourised)

func FormatBytes

func FormatBytes(n int) string

FormatBytes returns a string with the given number interpreted as bytes and abbreviated with binary formatting (eg 1024 = 1KiB)

func FormatRange

func FormatRange(start, end string) string

FormatRange takes start and end value and generates a ranged value

func FormatTime

func FormatTime(tv time.Time) string

FormatTime returns a time.Time in RFC3339, adding information on how long ago it was if the time was under 8 hours ago.

func IndentText

func IndentText(s, prefix string, repeatedPrefixAsSpaces bool) string

IndentText indents s with prefix. if repeatedPrefixAsSpaces is true, only the first indented line will get the prefix.

func ParseAbbrevNum

func ParseAbbrevNum(s string) (uint, error)

ParseAbbrevNum parses a string formatted to an uint in SI unit style. (eg. "1k" = 1000)

func ParseAbbrevNumBinaryPrefix

func ParseAbbrevNumBinaryPrefix(s string) (uint, error)

ParseAbbrevNumBinaryPrefix parses a string formatted to an uint in binary units. (eg. "1Ki" = 1000)

func TruncateText

func TruncateText(s string, maxLen int) string

TruncateText truncates s to maxLen and adds a suffix ("...") if the string was truncated. nb. maxLen will include the suffix so maxLen is respected in all cases

func UsageFunc

func UsageFunc(cmd *cobra.Command) error

UsageFunc is used to override cobra's default usage func to get some more stylistic control

Types

type DataTable

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

DataTable is a container for tabulated output data

func NewDataTable

func NewDataTable(columnKeys ...string) *DataTable

NewDataTable returns a new output data container for tabulated data

func (*DataTable) Append

func (s *DataTable) Append(rows ...table.Row)

Append appends new rows to the DataTable

func (*DataTable) OverrideColumnKeys

func (s *DataTable) OverrideColumnKeys(keys ...string)

OverrideColumnKeys overrides column visibility and order

func (*DataTable) Render

func (s *DataTable) Render() string

Render renders the DataTable

func (*DataTable) SetColumnConfig

func (s *DataTable) SetColumnConfig(key string, config table.ColumnConfig)

SetColumnConfig sets the configuration for a particular column, defined by key

func (*DataTable) SetHeader

func (s *DataTable) SetHeader(hdr table.Row)

SetHeader sets the header row for the DataTable

type DetailsView

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

DetailsView is an output data container for details rendered as a table

func NewDetailsView

func NewDetailsView() *DetailsView

NewDetailsView returns a new output data container for details rendered as a table

func (*DetailsView) Append

func (s *DetailsView) Append(rows ...table.Row)

Append appends new rows to the DetailsView

func (*DetailsView) Render

func (s *DetailsView) Render() string

Render renders a ata container for details as a table

func (*DetailsView) SetHeaderWidth

func (s *DetailsView) SetHeaderWidth(width int)

SetHeaderWidth sets the width of the header rendered

func (*DetailsView) SetRowSeparators

func (s *DetailsView) SetRowSeparators(v bool)

SetRowSeparators sets whether Render() outputs separators ascii lines between data rows

func (*DetailsView) SetRowSpacing

func (s *DetailsView) SetRowSpacing(v bool)

SetRowSpacing sets whether Render() outputs separators empty lines between data rows

func (*DetailsView) SetRowTransformer

func (s *DetailsView) SetRowTransformer(fn func(row table.Row) table.Row)

SetRowTransformer sets a method to transform rwos before rendering

type ListLayout

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

ListLayout is a renderer of list data

func NewListLayout

func NewListLayout(style listLayoutConfig) *ListLayout

NewListLayout returns a a new list data renderer

func WrapWithListLayout

func WrapWithListLayout(text string, style listLayoutConfig) *ListLayout

WrapWithListLayout returns a list data renderer wrapping given text

func (*ListLayout) AppendSection

func (s *ListLayout) AppendSection(title string, sectionBody ...string)

AppendSection appends a section to a list

func (*ListLayout) AppendSectionWithNote

func (s *ListLayout) AppendSectionWithNote(title, sectionBody, note string)

AppendSectionWithNote appends a section with a note to a list

func (*ListLayout) Render

func (s *ListLayout) Render() string

Render renders the ListLayout as configured

Jump to

Keyboard shortcuts

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