← Back to Home • Next: ProgressBar — Operations →
Every fluent method on IProgressBarControl. Each returns the same control instance, so calls chain
in any order. Call Run last.
The factory is
PromptPlus.Controls.ProgressBar(string prompt = "", string? description = null), which returnsIProgressBarControl.
Quick jump: UpdateHandler · UpdateHandlerAsync · Range · Default · FractionalDigits · Width · Fill · Spinner · ChangeColor · ChangeGradient · HideElements · Finish · ChangeDescription · ChangeDescriptionAsync · Culture · Styles · Options · Run
The progress value is not something you set once — it is driven by a handler that loops while the
work runs. Register exactly one handler (sync or async). Inside it you receive a
ProgressBarEvent whose Update(value) moves the bar. See
Operations for the full event surface.
UpdateHandlerIProgressBarControl UpdateHandler(
Action<ProgressBarEvent, CancellationToken> value,
IDictionary<string, object?>? context = null)
Registers a synchronous work loop.
| Parameter | Meaning |
|---|---|
value |
The loop. Receives the ProgressBarEvent and the run’s CancellationToken. Cannot be null. |
context |
Optional input key/value data made available to the handler via evt.InputParam<T>(...). |
PromptPlus.Controls.ProgressBar("Wait Progress: ")
.UpdateHandler((bar, token) =>
{
while (!token.IsCancellationRequested && !bar.Finish)
{
token.WaitHandle.WaitOne(80);
bar.Update(bar.Value + 2);
}
})
.Run();
Throws
ArgumentNullExceptionifvalueisnull.
UpdateHandlerAsyncIProgressBarControl UpdateHandlerAsync(
Func<ProgressBarEvent, CancellationToken, Task> value,
IDictionary<string, object?>? context = null)
Asynchronous counterpart of UpdateHandler, for loops that await I/O.
PromptPlus.Controls.ProgressBar("Wait Progress: ")
.UpdateHandlerAsync(async (bar, token) =>
{
while (!token.IsCancellationRequested && !bar.Finish)
{
await Task.Delay(80, token).ConfigureAwait(false);
bar.Update(bar.Value + 2);
}
})
.Run();
Throws
ArgumentNullExceptionifvalueisnull.
RangeIProgressBarControl Range(double minvalue, double maxvalue)
Sets the numeric bounds of the bar. The default range is 0 to 100. bar.Finish becomes true
once the value reaches maxvalue.
PromptPlus.Controls.ProgressBar("Wait Progress: ")
.Range(-30, 30)
.Default(-30)
.UpdateHandler(Work)
.Run();
Throws
ArgumentOutOfRangeExceptionwhenminvalueis strictly greater thanmaxvalue.minvalue == maxvaluedoes not throw here — but it does throw a separateArgumentException(“the minimum value must be less than the maximum value”) when the control actually starts running, so it still fails, just later and with a different exception type.
DefaultIProgressBarControl Default(double value)
Sets the initial value the bar starts at. If never called, it falls back to whatever
Range’s minvalue is (0 only because that’s the default range) — not a literal 0
independent of the range. Must be inside the configured range.
PromptPlus.Controls.ProgressBar("Wait Progress: ")
.Range(-30, 30)
.Default(-30)
.UpdateHandler(Work)
.Run();
The setter itself validates nothing. The out-of-range check happens later, when the control actually starts running, and throws
InvalidOperationException(notArgumentOutOfRangeException).
FractionalDigitsIProgressBarControl FractionalDigits(byte value)
Sets how many fractional digits are shown for the value. Default 0 (whole numbers); maximum 5.
PromptPlus.Controls.ProgressBar("Wait Progress: ")
.FractionalDigits(2)
.UpdateHandler(Work)
.Run();
Throws
ArgumentOutOfRangeExceptionwhenvalueis greater than5.
WidthIProgressBarControl Width(byte value)
Sets the rendered width of the bar track, in characters. Default 40; minimum 10.
PromptPlus.Controls.ProgressBar("Wait Progress: ")
.Width(30)
.UpdateHandler(Work)
.Run();
Throws
ArgumentOutOfRangeExceptionwhenvalueis less than10.
FillIProgressBarControl Fill(ProgressBarType type)
Chooses the visual fill style of the track. Default ProgressBarType.Fill.
ProgressBarType |
Look |
|---|---|
Fill |
Solid filled bar (default) |
Bar |
A simple bar |
Square |
Square blocks |
Light |
Light-weight blocks |
DoubleLight |
Double light blocks |
Dot |
Dots |
PromptPlus.Controls.ProgressBar("Wait Progress: ")
.Fill(ProgressBarType.Square)
.UpdateHandler(Work)
.Run();
SpinnerIProgressBarControl Spinner(SpinnersType spinnersType)
Shows an animated spinner alongside the bar while the operation is running. SpinnersType offers many
styles across several families (common ones: Default, Dots, Line, Star, Arc); on non-Unicode
terminals it automatically falls back to the Ascii spinner. See Spinners and the
Spinner catalog for the full list and frames.
PromptPlus.Controls.ProgressBar("Wait Progress: ")
.Spinner(SpinnersType.Dots)
.UpdateHandler(Work)
.Run();
ChangeColorIProgressBarControl ChangeColor(Func<double, Style> value)
Recomputes the bar color from the current value, so it changes as the bar advances. The callback
receives the value and returns the Style to paint.
using ConsolePlusLibrary;
PromptPlus.Controls.ProgressBar("Wait Progress: ")
.ChangeColor(value =>
{
if (value <= 30) return new Style(Color.Red, Color.Red);
if (value <= 70) return new Style(Color.Blue, Color.Blue);
return new Style(Color.Darkgoldenrod, Color.Darkgoldenrod);
})
.UpdateHandler(Work)
.Run();
Throws
ArgumentNullExceptionifvalueisnull.
ChangeGradientIProgressBarControl ChangeGradient(params Color[] colors)
Applies a gradient across the filled portion, interpolated over the configured range as the value advances. Pass two or more colors.
using ConsolePlusLibrary;
PromptPlus.Controls.ProgressBar("Wait Progress: ")
.ChangeGradient(Color.Green, Color.Yellow, Color.Red)
.UpdateHandler(Work)
.Run();
Throws
ArgumentNullExceptionifcolorsisnullor empty.
HideElementsIProgressBarControl HideElements(HideProgressBar value)
Hides one or more visual elements. HideProgressBar is a [Flags] enum — combine with |.
HideProgressBar |
Hides |
|---|---|
None |
Nothing (default) |
Delimit |
The bar delimiters |
Range |
The min/max range text |
PromptAnswer |
The prompt + answer line |
ElapsedTime |
The elapsed-time display |
ProgressbarAtFinish |
The whole bar once it finishes |
PromptPlus.Controls.ProgressBar("Wait Progress: ")
.HideElements(HideProgressBar.PromptAnswer | HideProgressBar.Range | HideProgressBar.Delimit)
.UpdateHandler(Work)
.Run();
FinishIProgressBarControl Finish(string finishtext)
Sets the text shown when the bar completes, exposed afterwards as StateProgress.FinishedText.
PromptPlus.Controls.ProgressBar("Wait Progress: ")
.Finish("End progress")
.UpdateHandler(Work)
.Run();
ChangeDescriptionIProgressBarControl ChangeDescription(Func<double, string> value)
Refreshes the description line every time the value changes. The callback receives the current value and returns the text to display.
PromptPlus.Controls.ProgressBar("Wait Progress: ")
.ChangeDescription(value => $"Processed: {value:0}%")
.UpdateHandler(Work)
.Run();
Throws
ArgumentNullExceptionifvalueisnull.
ChangeDescriptionAsyncIProgressBarControl ChangeDescriptionAsync(Func<double, Task<string>> value)
Asynchronous version of ChangeDescription. The task is awaited synchronously
each time the description refreshes — keep it fast.
PromptPlus.Controls.ProgressBar("Wait Progress: ")
.ChangeDescriptionAsync(async value =>
{
await Task.Delay(10);
return $"Processed (async): {value:0}%";
})
.UpdateHandler(Work)
.Run();
Throws
ArgumentNullExceptionifvalueisnull.
CultureIProgressBarControl Culture(CultureInfo culture)
IProgressBarControl Culture(string cultureName)
Sets the culture used to format numeric values. Pass a CultureInfo or a culture name such as
"pt-BR".
PromptPlus.Controls.ProgressBar("Wait Progress: ", "Culture: pt-BR")
.Culture("pt-BR")
.FractionalDigits(2)
.UpdateHandler(Work)
.Run();
The string overload throws
ArgumentNullExceptionfor anullname, resolves an empty string to the invariant culture (no throw), and throwsCultureNotFoundExceptionfor an unrecognized name.
StylesIProgressBarControl Styles(ProgressBarStyles styleType, Style style)
Overrides the color of one visual region of this control instance. See the full region list and examples on the Styles page.
using ConsolePlusLibrary;
using PromptPlusLibrary;
PromptPlus.Controls.ProgressBar("Wait Progress: ")
.Styles(ProgressBarStyles.Slider, new Style(Color.Green, Color.Default))
.UpdateHandler(Work)
.Run();
OptionsIProgressBarControl Options(Action<IControlOptions> options)
Overrides global behaviors (PromptPlus.Config) for this one control —
prompt/description text, tooltip, hide-after-finish, and the abort key.
PromptPlus.Controls.ProgressBar("Wait Progress: ")
.Options(o => o
.ShowTooltip(true)
.HideAfterFinish(true))
.UpdateHandler(Work)
.Run();
See Global Behaviors → Per-Control Override
for the complete IControlOptions list.
Throws
ArgumentNullExceptionifoptionsisnull.
RunResultPrompt<StateProgress> Run(CancellationToken token = default)
Renders the bar and blocks until the update handler returns (work finished) or token is cancelled.
Returns a ResultPrompt<StateProgress> — see
Index → Return value.
using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(30));
var result = PromptPlus.Controls.ProgressBar("Work").UpdateHandler(Work).Run(cts.Token);
ProgressBarEvent, context, cancellation, and errorsProgressBarStyles regions