Documentation ¶
Index ¶
- Variables
- func AbbrevNum(raw uint) string
- func AbbrevNumBinaryPrefix(raw uint) string
- func CommandUsageTemplate() string
- func ConcatStrings(strs ...string) string
- func FormatBool(v bool) string
- func FormatBytes(n int) string
- func FormatRange(start, end string) string
- func FormatTime(tv time.Time) string
- func IndentText(s, prefix string, repeatedPrefixAsSpaces bool) string
- func ParseAbbrevNum(s string) (uint, error)
- func ParseAbbrevNumBinaryPrefix(s string) (uint, error)
- func TruncateText(s string, maxLen int) string
- func UsageFunc(cmd *cobra.Command) error
- type DataTable
- type DetailsView
- type ListLayout
- type LiveLog
- type LiveLogConfig
- type LogEntry
Constants ¶
This section is empty.
Variables ¶
var ( // LiveLogDefaultConfig represents the default settings for live log LiveLogDefaultConfig = LiveLogConfig{ EntryMaxWidth: 0, DisableLiveRendering: !terminal.IsStdoutTerminal(), Colours: liveLogDefaultColours, // contains filtered or unexported fields } // LiveLogEntryErrorColours specifies the colour used for errors in LiveLog // TODO: remove cross-package dependency and make this private LiveLogEntryErrorColours = text.FgHiRed )
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} )
var ListLayoutDefault = listLayoutConfig{ MarginLeft: true, MarginTop: true, MarginBottom: false, PadTop: false, PadBottom: false, NoteSeparator: true, }
ListLayoutDefault defines the default config used for rendering lists
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 ¶
AbbrevNum returns a string with the given number abbreviated with SI formatting (eg 1000 = 1k)
func AbbrevNumBinaryPrefix ¶
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 ¶
ConcatStrings like join but handles well the empty strings
func FormatBytes ¶
FormatBytes returns a string with the given number interpreted as bytes and abbreviated with binary formatting (eg 1024 = 1KiB)
func FormatRange ¶
FormatRange takes start and end value and generates a ranged value
func FormatTime ¶
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 ¶
IndentText indents s with prefix. if repeatedPrefixAsSpaces is true, only the first indented line will get the prefix.
func ParseAbbrevNum ¶
ParseAbbrevNum parses a string formatted to an uint in SI unit style. (eg. "1k" = 1000)
func ParseAbbrevNumBinaryPrefix ¶
ParseAbbrevNumBinaryPrefix parses a string formatted to an uint in binary units. (eg. "1Ki" = 1000)
func TruncateText ¶
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
Types ¶
type DataTable ¶
type DataTable struct {
// contains filtered or unexported fields
}
DataTable is a container for tabulated output data
func NewDataTable ¶
NewDataTable returns a new output data container for tabulated data
func (*DataTable) OverrideColumnKeys ¶
OverrideColumnKeys overrides column visibility and order
func (*DataTable) SetColumnConfig ¶
func (s *DataTable) SetColumnConfig(key string, config table.ColumnConfig)
SetColumnConfig sets the configuration for a particular column, defined by key
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
type LiveLog ¶
type LiveLog struct {
// contains filtered or unexported fields
}
LiveLog represents the internal state of a live log renderer
func NewLiveLog ¶
func NewLiveLog(out io.Writer, style LiveLogConfig) *LiveLog
NewLiveLog returns a new renderer for live logs
func (*LiveLog) AddEntries ¶
AddEntries adds log entries to LiveLog
func (*LiveLog) Close ¶ added in v1.1.0
func (s *LiveLog) Close()
Close closes the LiveLog and cleans up related resources
func (*LiveLog) MaxWidth ¶ added in v1.1.0
MaxWidth returns the maximum allowed width of a log line for this LiveLog instance. if config.MaxEntryWidth is set to 0, it will return the maximum terminal width. Note that this means that MaxWidth() can return different values across Render()s, as terminal could be resized between them.
type LiveLogConfig ¶
type LiveLogConfig struct { // EntryMaxWidth sets the forced maximum width of live log lines. Use 0 for detecting terminal width. EntryMaxWidth int DisableLiveRendering bool Colours liveLogColours // contains filtered or unexported fields }
LiveLogConfig is a configuration for rendering live logs
type LogEntry ¶
type LogEntry struct {
// contains filtered or unexported fields
}
LogEntry represents a single log entry in a live log
func NewLogEntry ¶
NewLogEntry creates a new LogEntry with the specified message
func (*LogEntry) SetDetails ¶
SetDetails sets the details of the LogEntry
func (*LogEntry) SetMessage ¶
SetMessage sets the message of the LogEntry
func (*LogEntry) StartedNow ¶
func (s *LogEntry) StartedNow()
StartedNow sets the LogEntry time to time.Now