output

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2026 License: Apache-2.0 Imports: 15 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatElapsed

func FormatElapsed(d time.Duration) string

FormatElapsed spells a duration as 0.3s below a minute and as 2m5s from then on.

func HumanBytes

func HumanBytes(n uint64) string

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

func HumanCount(n uint64) string

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

func HumanRate(perSecond float64) string

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

func RenderAs(w io.Writer, format string, v any, table func(io.Writer) error) error

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

func TimeRange(minTS, maxTS int64) string

TimeRange renders the bounds as MM-DD, with the year when the bounds fall in different years.

func ValidateOutputFormat

func ValidateOutputFormat(format string) error

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

func NewProgress(w io.Writer, size func() (width, height int), more string) *Progress

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

func (p *Progress) Add(l LiveLine)

Add shows a live line.

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

func (p *Progress) Now() time.Time

Now is the time of the progress clock.

func (*Progress) Printf

func (p *Progress) Printf(format string, args ...any)

Printf prints a fixed line.

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

func (p *Progress) Remove(l LiveLine, fixed string)

Remove drops a live line and prints fixed, a line or "".

func (*Progress) SetClock

func (p *Progress) SetClock(now func() time.Time)

SetClock replaces the clock the progress reads its times from, for tests.

func (*Progress) Spinner

func (p *Progress) Spinner() string

Spinner is the current frame of the spinner a live line starts with; call it from LiveLine.

func (*Progress) Start

func (p *Progress) Start(ctx context.Context)

Start begins redrawing the live lines every progressRedraw on a terminal, until close or the end of ctx.

func (*Progress) Terminal

func (p *Progress) Terminal() bool

Terminal reports whether live lines are drawn.

func (*Progress) Update

func (p *Progress) Update(change func() (fixed string))

Update runs change with the progress locked, so that it may change what the live lines show, and prints the fixed line it returns, if any; the live lines are redrawn by the ticker.

func (*Progress) Wrap

func (p *Progress) Wrap(w io.Writer) io.Writer

Wrap returns a writer that prints through the progress, so that lines written to another stream of the same terminal (warnings on stderr) do not tear the live lines.

Jump to

Keyboard shortcuts

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