Documentation
¶
Overview ¶
Package bargo provides a single-line terminal progress bar with an optional centered percentage label.
Index ¶
- type Bar
- func (b *Bar) Render(progress float64, width int) string
- func (b *Bar) RenderWithText(progress float64, width int, suffix string) string
- func (b *Bar) WriteTo(w io.Writer, progress float64, width int) (int, error)
- func (b *Bar) WriteToWithText(w io.Writer, progress float64, width int, suffix string) (int, error)
- type Option
- func WithBounds(min, max float64) Option
- func WithCarriageReturn(enabled bool) Option
- func WithClamp(enabled bool) Option
- func WithEmptyRune(r rune) Option
- func WithFillRune(r rune) Option
- func WithHeadRune(r rune) Option
- func WithLeftDelim(s string) Option
- func WithPercentDecimals(n int) Option
- func WithPercentVisible(enabled bool) Option
- func WithRightDelim(s string) Option
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Bar ¶
type Bar struct {
// contains filtered or unexported fields
}
Bar renders a progress bar. Create one with New.
func New ¶
New returns a Bar configured by the given options. Defaults: progress range 0–100, fill '=', empty ' ', delimiters '[' and ']', head '=', centered percent visible, 1 decimal place, clamping enabled, carriage return disabled.
func (*Bar) Render ¶
Render returns the formatted progress bar string for the given progress value and inner width (excluding delimiters). If clamping is enabled, progress is silently clamped to the configured min/max bounds before rendering.
Example ¶
b := New() fmt.Println(b.Render(50, 20))
Output: [=======50.0% ]
func (*Bar) RenderWithText ¶ added in v1.1.0
RenderWithText returns the formatted progress bar string with optional trailing text appended after the right delimiter.
func (*Bar) WriteTo ¶
WriteTo writes the rendered progress bar to w. If WithCarriageReturn is enabled a '\r' is prepended so the output overwrites the current terminal line.
func (*Bar) WriteToWithText ¶ added in v1.1.0
WriteToWithText writes the rendered progress bar with trailing text to w. If WithCarriageReturn is enabled a '\r' is prepended so the output overwrites the current terminal line.
type Option ¶
type Option func(*config)
Option is a functional option for configuring a Bar.
func WithBounds ¶
WithBounds sets the minimum and maximum values of the progress range. The default range is 0 to 100.
func WithCarriageReturn ¶
WithCarriageReturn controls whether Bar.WriteTo prepends '\r' to the output, causing the bar to overwrite the current terminal line. Default is false.
func WithClamp ¶
WithClamp controls whether out-of-range progress values are silently clamped to the configured bounds. Default is true.
func WithEmptyRune ¶
WithEmptyRune sets the rune used for the unfilled portion of the bar. Default is ' ' (space).
func WithFillRune ¶
WithFillRune sets the rune used for the filled portion of the bar. Default is '='.
func WithHeadRune ¶ added in v1.1.0
WithHeadRune sets the rune used for the moving head of the bar. Default is '='.
func WithLeftDelim ¶
WithLeftDelim sets the opening delimiter of the bar. Default is "[".
func WithPercentDecimals ¶
WithPercentDecimals sets the number of decimal places shown in the percentage label. Negative values are treated as zero. Default is 1.
func WithPercentVisible ¶ added in v1.1.0
WithPercentVisible controls whether the centered percentage label is shown. Default is true.
func WithRightDelim ¶
WithRightDelim sets the closing delimiter of the bar. Default is "]".