ui

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2021 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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
)
View Source
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}
)
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. colorized)

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 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

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 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

func (s *LiveLog) AddEntries(entries ...*LogEntry)

AddEntries adds log entries to LiveLog

func (*LiveLog) Render

func (s *LiveLog) Render()

Render renders the 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

func NewLogEntry(msg string) *LogEntry

NewLogEntry creates a new LogEntry with the specified message

func (*LogEntry) MarkDone

func (s *LogEntry) MarkDone()

MarkDone marks the LogEntry as done

func (*LogEntry) SetDetails

func (s *LogEntry) SetDetails(details, prefix string)

SetDetails sets the details of the LogEntry

func (*LogEntry) SetMessage

func (s *LogEntry) SetMessage(msg string)

SetMessage sets the message of the LogEntry

func (*LogEntry) StartedNow

func (s *LogEntry) StartedNow()

StartedNow sets the LogEntry time to time.Now

type WorkQueueConfig

type WorkQueueConfig struct {
	NumTasks           int
	MaxConcurrentTasks int
	EnableUI           bool
}

WorkQueueConfig represents the settings for a workqueue

Jump to

Keyboard shortcuts

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