Documentation
¶
Overview ¶
Package output renders what the data export and import commands print: tables, YAML and JSON, counts, sizes and times, and the live progress of a transfer on a terminal.
Index ¶
- func FormatElapsed(d time.Duration) string
- func HumanBytes(n uint64) string
- func HumanCount(n uint64) string
- func HumanRate(perSecond float64) string
- func IntervalLabel(r *commonv1.IntervalRule) string
- func RenderAs(w io.Writer, format string, v any, table func(io.Writer) error) error
- func TimeRange(minTS, maxTS int64) string
- func ValidateOutputFormat(format string) error
- type LiveLine
- type Progress
- func (p *Progress) Add(l LiveLine)
- func (p *Progress) Close()
- func (p *Progress) Now() time.Time
- func (p *Progress) Printf(format string, args ...any)
- func (p *Progress) Redraw()
- func (p *Progress) Remove(l LiveLine, fixed string)
- func (p *Progress) SetClock(now func() time.Time)
- func (p *Progress) Spinner() string
- func (p *Progress) Start(ctx context.Context)
- func (p *Progress) Terminal() bool
- func (p *Progress) Update(change func() (fixed string))
- func (p *Progress) Wrap(w io.Writer) io.Writer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FormatElapsed ¶
FormatElapsed spells a duration as 0.3s below a minute and as 2m5s from then on.
func HumanBytes ¶
HumanBytes renders bytes in IEC units with one decimal (humanize.IBytes rounds to whole units from 10 upwards, so 18.3 GiB would print as 18 GiB).
func HumanCount ¶
HumanCount renders a count with one decimal and a K/M/G/T suffix; a value that would round up to 1000.0 of a unit carries into the next one (999_999 -> 1.0M).
func HumanRate ¶
HumanRate renders a per-second rate as HumanCount renders a count, with one decimal below 10, so that a rate below one per second does not read as 0.
func IntervalLabel ¶
func IntervalLabel(r *commonv1.IntervalRule) string
IntervalLabel renders an interval rule as "7d" or "1h"; "" when unset.
func RenderAs ¶
RenderAs writes v as two-space indented json for "json", as yaml for "yaml", and with table for any other format; it does not validate the format.
func TimeRange ¶
TimeRange renders the bounds as MM-DD, with the year when the bounds fall in different years.
func ValidateOutputFormat ¶
ValidateOutputFormat accepts the dry-run renderings table (also ""), yaml and json and rejects anything else as a usage error.
Types ¶
type LiveLine ¶
type LiveLine interface {
// LiveLine renders the line at now; it is called with the Progress locked.
LiveLine(now time.Time) string
}
LiveLine is one line of the live area of a Progress, redrawn in place.
type Progress ¶
type Progress struct {
// contains filtered or unexported fields
}
Progress prints the progress of a transfer: fixed lines and, on a terminal, a live area of one line per worker in flight that is redrawn in place. Without a terminal it prints the fixed lines only.
func NewProgress ¶
NewProgress prints to w; size is nil when w is not a terminal. more names the live lines, as in "node(s) exporting".
func (*Progress) Close ¶
func (p *Progress) Close()
Close stops the redraws and erases the live lines left by workers that did not finish.
func (*Progress) Redraw ¶
func (p *Progress) Redraw()
Redraw draws the live lines again with the next spinner frame, as the redraw ticker does.
func (*Progress) SetClock ¶
SetClock replaces the clock the progress reads its times from, for tests.
func (*Progress) Spinner ¶
Spinner is the current frame of the spinner a live line starts with; call it from LiveLine.
func (*Progress) Start ¶
Start begins redrawing the live lines every progressRedraw on a terminal, until close or the end of ctx.