# Progress Bar

`progressbar.h`/`progressbar.cpp` define `AnalysisProgress`, the simulator's only concrete [`ProgressReporter`](progress.md) - it renders an actual `|====  42%  ====|`-style bar plus elapsed time (and an optional current-value readout) to a terminal, overwriting itself in place with `\r`. Everything about *when* to redraw and *what* to show is handled by the `ProgressReporter` base class; `AnalysisProgress` only implements `reporter()`, the drawing itself.

## Sizing at construction

`AnalysisProgress(indent, os, dt)` decides up front, once, whether drawing is even possible: if `Platform::isTty(os)` is false (output is redirected to a file, for instance), `columns` is `0`; otherwise it is `Platform::ttyColumns(os)` (see [Platform Entry Support](platform.md)). `barSize` is derived from `columns` and `indent`, and the reporter starts out `enabled_` only if `barSize>=10` - too narrow a terminal disables the bar entirely rather than trying to draw something illegible. `dt` (default `0.25`s) is passed straight through to the `ProgressReporter` base constructor as the redraw rate limit.

## Rendering: `renderBar()`

Builds the bar interior for a given `norm`/`val` (extent/position) pair as a fixed-width string: a percentage figure centered between two runs of `=` characters, bounded by `|...|`. It bails out (returns `""`) if the available width can't fit at least a 2-character bar plus the percentage text with padding - the caller (`reporter()`) treats an empty result as "can't draw," matching the same reasoning as the constructor's `barSize>=10` check but re-evaluated against the actual number being displayed.

## `reporter()`

Called by the base class's rate-limited `report()` (see [Progress Reporting](progress.md)). Assembles one line: leading indent, the bar from `renderBar(extent_, pos_)`, then - space permitting - an elapsed-time figure (`time()`, seconds, fixed-point) and, if a value was set via `setValue()` (see [Progress Reporting](progress.md)'s `ProgressReporter`), a formatted `@ <value>` suffix using whatever format/precision/decoration was configured with `setValueFormat()`/`setValueDecoration()`. If the bar text alone doesn't fit (`renderBar()` returned empty, or overflows the terminal width), `reporter()` disables itself (`enabled_ = false`) for the rest of the run rather than printing a garbled partial line.

Each redraw pads the new line with trailing spaces if it's shorter than the previous one (`lastLen`), so a shrinking value readout doesn't leave stale characters from the previous, longer line, then writes `'\r' + txt` and flushes.

## Fitting into the run

[`CommandInterpreter::run()`](cmd.md) constructs one `AnalysisProgress` per analysis entry (and `cmd_mc` constructs one per Monte Carlo loop), installs it on the [`Analysis`](index.md#8-analyses) object via `Analysis::add(ProgressReporter*)` (or drives it directly, for the MC per-sample counter), and brackets the run with `begin()`/`end()`/a final forced `report(true)` - all inherited behavior from `ProgressReporter`, described in [Progress Reporting](progress.md). Installation is skipped when progress printing is turned off (`-qp`/`--quiet-progress`, see [Program Entry Point](main.md)) or while a Monte Carlo sample is in progress, so a nested analysis run doesn't draw its own bar over the MC loop's.
