← Back to Home • Next: ProgressBar Control →
The Switch control paints its output in named regions. Each region is a SwitchStyles value you
can recolor per control instance.
ℹ️ Styling is per control — there is no global “style all switches” API. Set styles on each control (or through a small helper you reuse). The only style-related global setting is
PromptPlus.Config.ContrastRatio.
SwitchStyles regions| Region | What it paints |
|---|---|
Prompt |
The prompt text |
Answer |
The confirmed state |
Description |
The description line under the prompt |
Tooltips |
The keyboard-hint line |
Marker |
The moving thumb that indicates the current position |
Ranger |
The state delimiters |
SwitchOn |
The track fill when the state is on |
SwitchOff |
The track fill when the state is off |
Error |
The error line |
⚠️ The on/off region names are spelled
SwitchOnandSwitchOffin the enum (no secondc) — use them exactly as shown.
Use the fluent Styles method. A Style is a foreground color, a background
color, and an Overflow strategy — there is no bold/italic/underline. A bare Color is
accepted as shorthand for a foreground-only style.
using ConsolePlusLibrary;
using PromptPlusLibrary;
PromptPlus.Controls
.Switch("Use cache")
.Styles(SwitchStyles.SwitchOn, new Style(Color.Black, Color.Darkgreen))
.Styles(SwitchStyles.SwitchOff, new Style(Color.Black, Color.Darkred))
.Styles(SwitchStyles.Prompt, Color.Yellow) // Color shorthand (foreground)
.Run();
To reuse a theme across switches, wrap the styling in a helper you call for each control — the library does not broadcast styles for you. See Global Styles for the pattern.
PromptPlus nudges foreground colors that fall below the configured contrast ratio so text stays readable on any terminal theme. Tune or disable with:
PromptPlus.Config.ContrastRatio = 0; // disable
PromptPlus.Config.ContrastRatio = 4.5; // WCAG AA target
Style type, per-control styling, contrastStyle API and Overflow