fn: sayprogress
Purpose
Render or update a transient progress line.
Behavior
- Calculates progress from --current and --total.
- Optionally renders current/total, percentage, and a progress bar.
- Writes the rendered line into the selected progress slot.
- Automatically reserves a progress region when none exists yet.
- Clamps invalid progress values to safe ranges.
- Throttles redraws for slot 1 and deeper to reduce terminal I/O.
- Always redraws the first item and the final 10 items.
Options
--current VALUE— Current progress value. Values below 0 are normalized to 0.--total VALUE— Total progress value. Values below 1 are normalized to 1.--label TEXT— Text appended to the progress indicators.--type MASK— Bit mask controlling visible indicators. 1 shows current/total, 2 shows percentage, and 4 shows the progress bar.--barcolor VALUE— Color token used for the progress bar.--labelcolor VALUE— Color token used for the label.--indicatorcolor VALUE— Color token used for numeric progress indicators.--interval COUNT— Redraw interval for throttled progress slots. Applies only to slot 1 and deeper. When omitted, the interval defaults to total / 100, with a minimum of 1.--padleft COUNT— Number of spaces to prefix before the progress text.--slot INDEX— Reserved progress slot to update. Slot numbering starts at 0.--width COUNT— Width of the progress bar.
Outputs
Writes terminal cursor control sequences and progress text to stderr.
Returns
- 0 on success.
- 1 when an unknown argument is supplied.
Usage
# Show all default indicators (count, percentage and progress bar).
sayprogress --current 5 --total 10 --label "Processing"
# Reserve two lines and update each progress slot separately.
sayprogress_begin --slots 2
sayprogress --slot 0 --current 2 --total 4 --label "Packages"
sayprogress --slot 1 --current 10 --total 20 --type 3 --label "Files"
sayprogress_done
