← Back to Home • Next: Slider — Operations →
Every fluent method on ISliderControl. Each returns the same control instance, so calls chain
in any order. Call Run last.
The factory is
PromptPlus.Controls.Slider(string prompt = "", string? description = null), which returnsISliderControl.
Quick jump: Range · Width · FractionalDigits · Culture · Default · Step · LargeStep · BarType · Layout · ChangeColor · ChangeGradient · HideElements · EnableHistory · ChangeDescription · ChangeDescriptionAsync · Styles · Options · Run
RangeISliderControl Range(double minvalue, double maxvalue)
Defines the lower and upper limits the slider can reach. Defaults to 0 and 100.
| Parameter | Meaning |
|---|---|
minvalue |
The smallest value the user can select. |
maxvalue |
The largest value the user can select. |
PromptPlus.Controls.Slider("Score")
.Range(0, 10)
.Run();
Throws
ArgumentOutOfRangeExceptionwhenminvalueis greater than or equal tomaxvalue.
WidthISliderControl Width(byte value)
Sets the width of the bar, measured in console characters. Default is 30; the value must be
between 10 and 100.
PromptPlus.Controls.Slider("Value", "Bar drawn with 60 characters")
.Width(60)
.Run();
Throws
ArgumentOutOfRangeExceptionwhenvalueis less than10or greater than100. An odd width is silently rounded up by one to the next even number — there’s no warning, the bar is just one character wider than requested.
FractionalDigitsISliderControl FractionalDigits(byte value)
Sets how many decimal places are shown for the value. Default is 0 (whole numbers); the maximum
is 5.
PromptPlus.Controls.Slider("Ratio")
.Range(0, 1)
.FractionalDigits(2)
.Run();
Throws
ArgumentOutOfRangeExceptionwhenvalueis greater than5.
CultureTwo overloads control how the number is formatted (decimal separator, digit grouping). Both default to the current PromptPlus culture.
ISliderControl Culture(CultureInfo culture)
ISliderControl Culture(string cultureName)
| Overload | Meaning |
|---|---|
Culture(CultureInfo) |
Pass a CultureInfo directly. Cannot be null. |
Culture(string) |
Pass a culture name such as "en-US" or "pt-BR". |
PromptPlus.Controls.Slider("Preço", "Value formatted with pt-BR culture")
.Culture("pt-BR") // comma decimal separator
.Range(0, 10)
.FractionalDigits(2)
.Step(0.25)
.Run();
The string overload throws
ArgumentNullExceptionfor anullname, resolves an empty string to the invariant culture (no throw), and throwsCultureNotFoundExceptionfor an unrecognized name.
DefaultISliderControl Default(double value, bool useDefaultHistory = true)
Sets the value that is pre-selected when the slider is first shown. If never called, the slider
starts at Range’s minimum, not a literal 0 — for a range that doesn’t include 0
(e.g. Range(10, 50)), the true default is 10.
| Parameter | Meaning |
|---|---|
value |
The initial value. Must be inside the range from Range. |
useDefaultHistory |
When true and history is enabled via EnableHistory, the last saved value is used instead of value. Default true. |
PromptPlus.Controls.Slider("Value")
.Range(-50, 50)
.Default(0)
.Run();
Defaultitself does no range check — it just storesvalue. The out-of-range check happens when the control runs: if the (possibly history-overridden) starting value ends up outsideRange,Run()throwsInvalidOperationException, notArgumentOutOfRangeException.
StepISliderControl Step(double value)
Sets the amount added or removed on each small change (the arrow keys). Default is 1/100 of
the range (so 1 for the default 0..100 range).
PromptPlus.Controls.Slider("Value")
.Step(0.5)
.Run();
LargeStepISliderControl LargeStep(double value)
Sets the amount added or removed on each large change (Tab / Shift+Tab). Default is
1/10 of the range (so 10 for the default 0..100 range).
PromptPlus.Controls.Slider("Value")
.Step(0.5)
.LargeStep(5)
.Run();
BarTypeISliderControl BarType(SliderBarType type)
Selects the character set used to draw the bar. Default is SliderBarType.Fill.
SliderBarType |
Bar drawn with |
|---|---|
Fill |
Solid fill blocks (default) |
Light |
Light line characters |
DoubleLight |
Double light line characters |
Square |
Square characters |
Dot |
Dotted characters |
PromptPlus.Controls.Slider("Value", "Bar style: Square")
.BarType(SliderBarType.Square)
.Run();
LayoutISliderControl Layout(SliderLayout value)
Chooses how the user changes the value and how the control is drawn. Default is
SliderLayout.LeftRight.
SliderLayout |
Behavior |
|---|---|
LeftRight |
Left / Right arrows change the value and the horizontal bar (with its delimiters) is shown (default) |
UpDown |
Up / Down arrows change the value; the bar and its delimiters are hidden, but the [min,max] range display is still shown next to the answer unless you also hide it with HideElements(HideSlider.Range) |
PromptPlus.Controls.Slider("Value")
.Layout(SliderLayout.UpDown)
.Run();
ChangeColorISliderControl ChangeColor(Func<double, Style> value)
Colors the bar dynamically according to the current value — for example red when low and gold when
high. The callback receives the current value and returns the Style to apply.
using PromptPlusLibrary;
using ConsolePlusLibrary; // Color, Style live here
PromptPlus.Controls.Slider("Value", "Red <= 30, Blue <= 70, Gold > 70")
.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);
})
.Run();
Throws
ArgumentNullExceptionifvalueisnull.
ChangeGradientISliderControl ChangeGradient(params Color[] colors)
Paints the bar with a gradient that transitions across the supplied colors as the value grows.
using PromptPlusLibrary;
using ConsolePlusLibrary;
PromptPlus.Controls.Slider("Value")
.ChangeGradient(Color.Green, Color.Yellow, Color.Red)
.Run();
Throws
ArgumentNullExceptionifcolorsisnullor empty — but a single color is legal (a solid, non-gradient bar); “two or more” is not a requirement. UseChangeColorfor threshold logic andChangeGradientfor a smooth blend — pick one approach per control.
HideElementsISliderControl HideElements(HideSlider value)
Hides one or more decorative elements. By default every element is shown. HideSlider is a
[Flags] enum — combine values with a bitwise OR.
HideSlider |
Effect |
|---|---|
None |
Nothing hidden (default) |
Delimit |
Hides the delimiters |
Range |
Hides the min/max range display |
PromptPlus.Controls.Slider("Value")
.HideElements(HideSlider.Delimit | HideSlider.Range)
.Run();
EnableHistoryISliderControl EnableHistory(string filename, Action<IHistoryOptions>? options = null)
Persists the confirmed value to a file under filename so it can be reused as the default on the
next run.
| Parameter | Meaning |
|---|---|
filename |
A stable, unique key for this slider’s history store. Cannot be null, empty, or whitespace. |
options |
Optional IHistoryOptions configuration (expiration, max items, and so on). |
PromptPlus.Controls.Slider("Value")
.Default(0, true) // fall back to the last history value
.FractionalDigits(2)
.Step(0.5)
.LargeStep(5)
.EnableHistory("slider-history")
.Run();
Throws
ArgumentExceptioniffilenameis empty or whitespace (ArgumentNullExceptionifnull).💡 Pair
Default(value, useDefaultHistory: true)withEnableHistory(...)to pre-load the last value the user confirmed. See Operations → History for runtime behavior.
ChangeDescriptionISliderControl ChangeDescription(Func<double, string> value)
Recomputes the description line as the value changes. The callback receives the current value and returns the description to display — handy for live readouts.
PromptPlus.Controls.Slider("Value")
.ChangeDescription(value => $"Current selection: {value:0} %")
.Run();
Throws
ArgumentNullExceptionifvalueisnull.
ChangeDescriptionAsyncISliderControl ChangeDescriptionAsync(Func<double, Task<string>> value)
Asynchronous version of ChangeDescription, for a description sourced
asynchronously.
PromptPlus.Controls.Slider("Value")
.ChangeDescriptionAsync(async value =>
{
await Task.Delay(1).ConfigureAwait(false);
return $"Async description for value {value:0}";
})
.Run();
Throws
ArgumentNullExceptionifvalueisnull.
StylesISliderControl Styles(SliderStyles 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 PromptPlusLibrary;
using ConsolePlusLibrary;
PromptPlus.Controls.Slider("Value")
.Styles(SliderStyles.Prompt, new Style(Color.Aqua, Color.Black))
.Styles(SliderStyles.Answer, new Style(Color.Green, Color.Black))
.Styles(SliderStyles.Slider, new Style(Color.Blue, Color.Black))
.Run();
Throws
ArgumentNullExceptionifstyleisnull.
OptionsISliderControl Options(Action<IControlOptions> options)
Overrides global behaviors (PromptPlus.Config) for this one control —
prompt/description text, abort key, tooltip, hide-after-finish, and the extra-info affixes.
PromptPlus.Controls.Slider("Value")
.Options(opt =>
{
opt.Description("Custom options sample");
opt.ShowTooltip(false);
opt.EnabledAbortKey(true);
opt.HideAfterFinish(false);
})
.Run();
See Global Behaviors → Per-Control Override
for the complete IControlOptions list.
Throws
ArgumentNullExceptionifoptionsisnull.
RunResultPrompt<double?> Run(CancellationToken token = default)
Renders the slider and blocks until the user confirms (Enter) or aborts (Esc). Returns a
ResultPrompt<double?> whose .Content is null when the
prompt is cancelled.
| Parameter | Meaning |
|---|---|
token |
A CancellationToken that cancels the prompt while it waits for input. |
using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(5));
var result = PromptPlus.Controls.Slider("Value").Run(cts.Token);
SliderStyles regions