Documentation
¶
Index ¶
- Variables
- func FormatBytes(b int64) string
- func FormatDuration(d time.Duration) string
- func FormatETA(d time.Duration) string
- type Bar
- func (inst *Bar) Add(delta int64)
- func (inst *Bar) Elapsed() time.Duration
- func (inst *Bar) Estimator() *Estimator
- func (inst *Bar) LogWriter() (w io.Writer)
- func (inst *Bar) NewProxyReader(r io.Reader) (pr *ProxyReader)
- func (inst *Bar) NewProxyWriter(w io.Writer) (pw *ProxyWriter)
- func (inst *Bar) Printf(format string, args ...any)
- func (inst *Bar) Println(args ...any)
- func (inst *Bar) Processed() int64
- func (inst *Bar) SetDetail(fn DetailFunc)
- func (inst *Bar) SetWriter(w io.Writer)
- func (inst *Bar) Start(ctx context.Context)
- func (inst *Bar) Stop()
- func (inst *Bar) Tick()
- func (inst *Bar) Total() int64
- type DetailFunc
- type Estimator
- func (inst *Estimator) DisplayedETA() time.Duration
- func (inst *Estimator) EstimateETA(remaining float64) (eta time.Duration, valid bool)
- func (inst *Estimator) RawETA(remaining float64) (eta time.Duration, valid bool)
- func (inst *Estimator) Reset(now time.Time, count int64)
- func (inst *Estimator) Samples() int
- func (inst *Estimator) SmoothedRate() float64
- func (inst *Estimator) SmoothedTrend() float64
- func (inst *Estimator) Start(now time.Time, count int64)
- func (inst *Estimator) Update(now time.Time, count int64)
- type ProxyReader
- type ProxyWriter
Constants ¶
This section is empty.
Variables ¶
var PackageProps = packageprops.Props{ WASMWASI: packageprops.WASMCompiles, WASMJS: packageprops.WASMCompiles, WASMFreestanding: packageprops.WASMBlocked, }
PackageProps records this package's curated properties (ADR-0080). Seeded by `boxer code analysis golang wasmsurvey props generate`; curate by hand. The same group's `props verify` reconciles it.
Functions ¶
func FormatBytes ¶
func FormatDuration ¶
Types ¶
type Bar ¶
type Bar struct {
// contains filtered or unexported fields
}
Bar is a terminal progress bar supporting determinate (known total) and indeterminate (total=0, spinner only) modes. It is safe for concurrent use.
The rendering path is ANSI-to-stderr by default (see ansi.go). Tests or non-terminal consumers can swap the writer via SetWriter.
func New ¶
New creates a progress bar. Pass total=0 for indeterminate mode. The label describes what is being counted (e.g. "tiles", "pages").
func (*Bar) Estimator ¶
Estimator exposes the underlying ETA estimator so callers (e.g. the egui2 demo) can inspect smoothed rate/trend and the damped vs. raw ETA.
func (*Bar) LogWriter ¶
LogWriter returns an io.Writer whose output is serialised with the bar's render loop via inst.writeMu. Point a logger at it so log lines land on their own terminal rows instead of tangling with the \r-based progress line:
bar := progressbar.New(total, "items") log.Logger = log.Output(bar.LogWriter()) bar.Start(ctx)
Each Write is treated as one line-oriented message: on a TTY we first emit \r + erase-line so the in-place bar frame disappears, then the payload, then a '\n' if the payload didn't already end with one. The next render tick (≤250 ms later) repaints the bar on a fresh row below the log line.
In non-TTY mode the writer is a straight passthrough aside from the trailing-newline guarantee.
The trailing-newline guarantee assumes callers pass one complete event per Write. Standard logger writers (log.Logger, zerolog.ConsoleWriter, slog's text/JSON handlers) all satisfy this.
func (*Bar) NewProxyReader ¶
func (inst *Bar) NewProxyReader(r io.Reader) (pr *ProxyReader)
NewProxyReader wraps r with byte-count ticking against this Bar.
func (*Bar) NewProxyWriter ¶
func (inst *Bar) NewProxyWriter(w io.Writer) (pw *ProxyWriter)
NewProxyWriter wraps w with byte-count ticking against this Bar.
func (*Bar) Printf ¶
Printf formats through LogWriter. A trailing newline is appended by LogWriter if the formatted output doesn't already end with one.
func (*Bar) Println ¶
Println writes one line through LogWriter — convenience for ad-hoc messages that don't go through a logger.
func (*Bar) SetDetail ¶
func (inst *Bar) SetDetail(fn DetailFunc)
SetDetail registers a callback that returns domain-specific status text appended after the bar on each render. May be called before Start.
type DetailFunc ¶
DetailFunc is called on each render to format domain-specific status text. It receives the current processed count and total (0 if indeterminate).
type Estimator ¶
type Estimator struct {
// contains filtered or unexported fields
}
Estimator uses Holt's Double Exponential Smoothing to produce a smoothed rate estimate that captures both level and trend (acceleration/deceleration), plus a display-dampening layer that prevents the shown ETA from oscillating.
It has no I/O and no concurrency story of its own — callers drive it with Update and read back SmoothedRate / SmoothedTrend / EstimateETA. The CLI renderer and the egui2 demo both use it this way.
Use NewEstimator to construct one with tqdm/Rich-style defaults.
func NewEstimator ¶
func NewEstimator() (inst *Estimator)
NewEstimator returns an Estimator with tqdm/Rich-style defaults (alpha=0.3, beta=0.1, damping=10%). Start must be called before Update.
func (*Estimator) DisplayedETA ¶
DisplayedETA is the last ETA returned by EstimateETA, after damping. Zero if EstimateETA has not yet produced a valid value.
func (*Estimator) EstimateETA ¶
EstimateETA returns the damped ETA for `remaining` units of work. Decreases pass through immediately; small increases (within dampingThreshold of the displayed value) are suppressed; large increases break through. See EXPLANATION.md for the rationale.
func (*Estimator) RawETA ¶
RawETA returns remaining/smoothedRate without damping. Useful for demos that want to visualise the damping filter.
func (*Estimator) Reset ¶
Reset clears all smoothed state and re-anchors at (now, count). Use this when the underlying counter is reset (e.g. a new run) — otherwise the stale level/trend will bias the first few updates.
func (*Estimator) Samples ¶
Samples returns the number of Update calls that produced a sample (ignores calls skipped by the 50 ms floor).
func (*Estimator) SmoothedRate ¶
SmoothedRate returns the current level estimate S (items/sec).
func (*Estimator) SmoothedTrend ¶
SmoothedTrend returns the current trend estimate B (items/sec^2-ish — it is the smoothed step-over-step change in the level).
type ProxyReader ¶
type ProxyReader struct {
// contains filtered or unexported fields
}
ProxyReader wraps an io.Reader, Add-ing the byte count of each successful Read to the Bar. The common use is driving a byte-scale determinate bar from an HTTP response body, a file read, or a compressor stream:
bar := progressbar.New(resp.ContentLength, "bytes") bar.Start(ctx) defer bar.Stop() pr := bar.NewProxyReader(resp.Body) defer pr.Close() _, _ = io.Copy(dst, pr)
Close is propagated to the wrapped reader when it implements io.Closer.
func (*ProxyReader) Close ¶
func (inst *ProxyReader) Close() (err error)
Close propagates to the wrapped reader if it is an io.Closer; returns nil otherwise so the ProxyReader can be used in a deferred Close regardless.
type ProxyWriter ¶
type ProxyWriter struct {
// contains filtered or unexported fields
}
ProxyWriter is the write-side counterpart to ProxyReader. Each successful Write adds its byte count to the Bar.
func (*ProxyWriter) Close ¶
func (inst *ProxyWriter) Close() (err error)