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 StartWorkQueue(cfg WorkQueueConfig, handler func(idx int, logEntry *LogEntry))
- func TruncateText(s string, maxLen int) string
- func UsageFunc(cmd *cobra.Command) error
- type DataTable
- type DetailsView
- type HandleContext
- type Handler
- type ListLayout
- type LiveLog
- type LiveLogConfig
- type LogEntry
- type WorkQueueConfig
Constants ¶
This section is empty.
Variables ¶
var ( // LiveLogDefaultConfig represents the default settings for live log LiveLogDefaultConfig = LiveLogConfig{ EntryMaxWidth: 80, DisableLiveRendering: !terminal.IsStdoutTerminal(), Colours: liveLogDefaultColours, // contains filtered or unexported fields } // LiveLogEntryErrorColours specifies the color used for errors in LiveLog // TODO: remove cross-package dependency and make this private LiveLogEntryErrorColours = text.FgHiRed )
var ( // DefaultHeaderColours defines the default colors used for headers DefaultHeaderColours = text.Colors{text.Bold} // DefaultUUUIDColours defines the default colors used for UUIDs DefaultUUUIDColours = text.Colors{text.FgHiBlue} // DefaultErrorColours defines the default colors used for errors DefaultErrorColours = text.Colors{text.FgHiRed, text.Bold} // DefaultAddressColours defines the default colors used for addresses DefaultAddressColours = text.Colors{text.FgHiMagenta} // DefaultBooleanColoursTrue defines the default colors used for boolean true values DefaultBooleanColoursTrue = text.Colors{text.FgHiGreen} // DefaultBooleanColoursFalse defines the default colors used for boolean false values DefaultBooleanColoursFalse = text.Colors{text.FgHiBlack} // DefaultNoteColours defines the default colors 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 StartWorkQueue ¶
func StartWorkQueue(cfg WorkQueueConfig, handler func(idx int, logEntry *LogEntry))
StartWorkQueue starts a work queue that calls handler with idx specifying the current index in the work queue and logEntry that should be modified by the handler function to log entries.
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 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 HandleContext ¶
type HandleContext struct {
RequestID func(interface{}) string
ResultUUID func(interface{}) string
ResultPrefix string
ResultExtras func(interface{}) []string
ResultExtraName string
MessageFn func(interface{}) string
ActionMsg string
Action func(interface{}) (interface{}, error)
MaxActions int
InteractiveUI bool
WaitMsg string
WaitFn func(uuid string, waitMsg string, err error) (interface{}, error)
}
HandleContext represents the internal state and callbacks of a particular command handler TODO: is this really a ui feature?
func (HandleContext) Handle ¶
func (c HandleContext) Handle(requests []interface{}) (interface{}, error)
Handle is the main method that handles (possibly asynchronous) requests and returns their output
type Handler ¶
type Handler interface {
Handle(requests []interface{}) (interface{}, error)
}
Handler defines the interface for handling requests and returning output TODO: is this needed? Does any other struct besides HandleContext implement this?
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
type LiveLogConfig ¶
type LiveLogConfig struct {
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
type WorkQueueConfig ¶
WorkQueueConfig represents the settings for a workqueue