ScrollingSection constructor
ScrollingSection({
- required InlineTerminal terminal,
- int rows = 5,
- bool dim = true,
- String? heading,
- String? successMessage,
- String? failedMessage,
- RetainSection? successRetention,
- RetainSection? failureRetention,
- bool captureOutput = false,
- Duration spinnerInterval = _defaultSpinnerInterval,
- Duration? elapsed()?,
- SpinnerScheduler? scheduleTicker,
Creates a scrolling section rendered to terminal.
rows is the fixed number of visual rows (must be at least 1, default 5).
successRetention and failureRetention choose what happens to the body
when finish is called, unless that call passes overrideRetention.
spinnerInterval controls how often the spinner advances.
elapsed supplies the elapsed time shown in the heading, for when the
duration is known from elsewhere (e.g. server-side timestamps). When it
is unset or returns null, the time since the section was created is
shown.
scheduleTicker is an injection point for tests so the animation can be
driven deterministically; production code should leave it unset.
Implementation
ScrollingSection({
required InlineTerminal terminal,
this.rows = 5,
this.dim = true,
String? heading,
this.successMessage,
this.failedMessage,
final RetainSection? successRetention,
final RetainSection? failureRetention,
this.captureOutput = false,
Duration spinnerInterval = _defaultSpinnerInterval,
Duration? Function()? elapsed,
SpinnerScheduler? scheduleTicker,
}) : assert(rows >= 1, 'rows must be at least 1'),
_heading = heading,
successRetention = successRetention ?? RetainSection.clear,
failureRetention = failureRetention ?? RetainSection.keepFull,
_terminal = terminal,
_renderer = BottomRegionRenderer(terminal),
_spinnerInterval = spinnerInterval,
_elapsedOverride = elapsed,
_scheduleTicker = scheduleTicker ?? _defaultScheduler {
// Show the heading immediately, even before any output arrives, and start
// the spinner/elapsed animation alongside it.
if (heading != null) {
_started = true;
_renderer.hideCursor();
_spinnerActive = _terminal.hasTerminal;
if (_spinnerActive) {
_stopwatch.start();
_cancelTicker = _scheduleTicker(_spinnerInterval, _tick);
}
_render();
}
}