progress

package
v2.22.0 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2026 License: Apache-2.0, Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const RFC3339NanoFixed = "2006-01-02T15:04:05.000000000Z07:00"

RFC3339NanoFixed is time.RFC3339Nano with nanoseconds padded using zeros to ensure the formatted time is always the same number of characters.

Variables

This section is empty.

Functions

func Aux

func Aux(out Output, a any)

Aux sends auxiliary information over a progress interface, which will not be formatted for the UI. This is used for things such as push signing.

func Display

func Display(jm jsonstream.Message, out io.Writer, isTerminal bool, width uint16) error

Display prints the JSONMessage to out. If isTerminal is true, it erases the entire current line when displaying the progressbar. It returns an error if the [JSONMessage.Error] field is non-nil.

func DisplayJSONMessages

func DisplayJSONMessages(messages iter.Seq2[jsonstream.Message, error], out io.Writer, terminalFd uintptr, isTerminal bool, auxCallback func(jsonstream.Message)) error

DisplayJSONMessages is like DisplayMessages, but allows the caller to explicitly provide the terminal file descriptor and whether out is a terminal.

func DisplayJSONMessagesStream

func DisplayJSONMessagesStream(in io.Reader, out io.Writer, terminalFd uintptr, isTerminal bool, auxCallback func(jsonstream.Message)) error

DisplayJSONMessagesStream is like DisplayStream, but allows the caller to explicitly provide the terminal file descriptor and whether out is a terminal.

func DisplayMessages

func DisplayMessages(messages iter.Seq2[jsonstream.Message, error], out io.Writer, opts ...DisplayOpt) error

DisplayMessages writes each jsonstream.Message from stream to out. It returns an error if an invalid jsonstream.Message is received, or if a message contains a non-zero jsonstream.Message.Error.

func DisplayStream

func DisplayStream(in io.Reader, out io.Writer, opts ...DisplayOpt) error

DisplayStream reads a JSON message stream from in, and writes each jsonstream.Message to out. See DisplayMessages for details.

func Message

func Message(out Output, id, message string)

Message is a convenience function to write a progress message to the channel.

func Messagef

func Messagef(out Output, id, format string, a ...any)

Messagef is a convenience function to write a printf-formatted progress message to the channel.

func RenderTUIProgress

func RenderTUIProgress(p jsonstream.Progress, width uint16) string

func Update

func Update(out Output, id, action string)

Update is a convenience function to write a progress update to the channel.

func Updatef

func Updatef(out Output, id, format string, a ...any)

Updatef is a convenience function to write a printf-formatted progress update to the channel.

Types

type DisplayOpt

type DisplayOpt func(*displayOpts) error

DisplayOpt configures behavior for DisplayStream and DisplayMessages. Options are applied in order; if an option returns an error, processing stops and the error is returned to the caller.

func WithAuxCallback

func WithAuxCallback(fn func(jsonstream.Message)) DisplayOpt

WithAuxCallback registers a callback that is invoked for auxiliary jsonstream messages as they are processed. The callback is optional; if not provided, auxiliary messages are ignored.

type JSONMessagesStream

type JSONMessagesStream = iter.Seq2[jsonstream.Message, error]

type Output

type Output interface {
	WriteProgress(Progress) error
}

Output is an interface for writing progress information. It's like a writer for progress, but we don't call it Writer because that would be confusing next to ProgressReader (also, because it doesn't implement the io.Writer interface).

func ChanOutput

func ChanOutput(progressChan chan<- Progress) Output

ChanOutput returns an Output that writes progress updates to the supplied channel.

func DiscardOutput

func DiscardOutput() Output

DiscardOutput returns an Output that discards progress

func NewJSONProgressOutput

func NewJSONProgressOutput(out io.Writer, newLines bool) Output

NewJSONProgressOutput returns a progress.Output that formats output using JSON objects

func NewProgressOutput

func NewProgressOutput(out io.Writer) Output

NewProgressOutput returns a progress.Output object that can be passed to progress.NewProgressReader.

type Progress

type Progress struct {
	ID string

	// Progress contains a Message or...
	Message string

	// ...progress of an action
	Action  string
	Current int64
	Total   int64

	// If true, don't show xB/yB
	HideCounts bool
	// If not empty, use units instead of bytes for counts
	Units string

	// Aux contains extra information not presented to the user, such as
	// digests for push signing.
	Aux any

	LastUpdate bool
}

Progress represents the progress of a transfer.

type Reader

type Reader struct {
	// contains filtered or unexported fields
}

Reader is a Reader with progress bar.

func NewProgressReader

func NewProgressReader(in io.ReadCloser, out Output, size int64, id, action string) *Reader

NewProgressReader creates a new ProgressReader.

func (*Reader) Close

func (p *Reader) Close() error

Close closes the progress reader and its underlying reader.

func (*Reader) Read

func (p *Reader) Read(buf []byte) (int, error)

Jump to

Keyboard shortcuts

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