Documentation
¶
Index ¶
- func AsyncIterate[T any](ctx context.Context, clearAfter bool, items []T, ...)
- func AsyncIterateWithErr[T any](ctx context.Context, clearAfter bool, doneText string, items []T, ...) error
- func Failed(ctx context.Context, e error)
- func Log(ctx context.Context, s string)
- func LogStatus(ctx context.Context, s Status, str string)
- func Logf(ctx context.Context, format string, args ...interface{})
- func LogfStatus(ctx context.Context, s Status, format string, args ...interface{})
- func NewContext(ctx context.Context, sl StatusLine) context.Context
- func SingleLine(ctx context.Context, showStatusChar bool) (context.Context, func(clear bool))
- type ResumeFn
- type Status
- type StatusLine
- type StatusLogger
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AsyncIterate ¶
func AsyncIterate[T any](ctx context.Context, clearAfter bool, items []T, cb func(context.Context, int, T))
AsyncIterate runs a callback for each item in a separate goroutine, passing a context with a StatusLine for each item.
func AsyncIterateWithErr ¶
func AsyncIterateWithErr[T any](ctx context.Context, clearAfter bool, doneText string, items []T, cb func(context.Context, int, T) error) error
AsyncIterateWithErr runs a callback for each item in a separate goroutine, passing a context with a StatusLine for each item. If any callback returns an error, the first error is returned and the remaining goroutines are canceled. If doneText is non-empty, each line will have its status set to this after its task successfully finishes.
func Failed ¶
func Failed(ctx context.Context, e error)
Failed marks the current line as failed, and prints *the first line* of the error provided. The assumption is that the full error will be printed elsewhere. Panics if ctx doesn't contain a StatusLine.
func Log ¶
func Log(ctx context.Context, s string)
Log into the StatusLine ctx carries. Panics if ctx doesn't contain a StatusLine.
func LogStatus ¶
func LogStatus(ctx context.Context, s Status, str string)
LogStatus into the StatusLine ctx carries. Panics if ctx doesn't contain a StatusLine.
func Logf ¶
func Logf(ctx context.Context, format string, args ...interface{})
Logf into the StatusLine ctx carries. Panics if ctx doesn't contain a StatusLine.
func LogfStatus ¶
func LogfStatus(ctx context.Context, s Status, format string, args ...interface{})
LogfStatus into the StatusLine ctx carries. Panics if ctx doesn't contain a StatusLine.
func NewContext ¶
func NewContext(ctx context.Context, sl StatusLine) context.Context
NewContext derives a Context that carries sl from ctx.
func SingleLine ¶
func SingleLine(ctx context.Context, showStatusChar bool) (context.Context, func(clear bool))
SingleLine returns a single StatusLine and a function to destroy it. Useful for one-off operations.
Types ¶
type Status ¶
type Status int
const (
StatusNone Status = iota
StatusRunning
StatusSuccess
StatusFailure
)
type StatusLine ¶
type StatusLine interface {
Log(s string)
Logf(format string, args ...interface{})
LogStatus(s Status, str string)
LogfStatus(s Status, format string, args ...interface{})
Failed(e error)
// contains filtered or unexported methods
}
func FromContext ¶
func FromContext(ctx context.Context) StatusLine
FromContext returns the StatusLine ctx carries. It panics in case ctx carries no StatusLine.
func FromContextOptional ¶
func FromContextOptional(ctx context.Context) StatusLine
FromContextOptional returns the StatusLine ctx carries if any, or nil.
type StatusLogger ¶
type StatusLogger interface {
// Destroy destroys the logger.
// If clear is true, it will remove the status lines from the terminal.
// Otherwise, it will leave them in place with a clear divider.
Destroy(clear bool)
// Line returns a StatusLine for the given line number.
Line(idx int) StatusLine
// Pause clears the status lines and prevents redraw until the returned resume function is called.
// This allows you to write multiple lines to the terminal without overlapping the status area.
Pause() ResumeFn
}