← Back to Home • Next: Widgets →
PromptPlus colors every control through the Style type from ConsolePlus. This page explains what a
Style is, how to apply one to a control, and the one setting that affects styling globally
(contrast).
ℹ️ There is no global “set this style for all controls” API. Styling is applied per control instance via each control’s
.Styles(...)method. The only style-related global setting isContrastRatio. (Earlier drafts referenced aPromptPlus.Config.Styles(...)method and aPromptPlusStylesenum — neither exists in the library.)
Style?A Style is a small immutable value with three parts:
public readonly struct Style(Color foreground, Color background, Overflow overflowStrategy = Overflow.None)
| Component | Type | Meaning |
|---|---|---|
Foreground |
Color |
Text color |
Background |
Color |
Color behind the text |
OverflowStrategy |
Overflow |
What to do when content is wider than the line (None, Crop, Ellipsis) |
using PromptPlusLibrary;
using ConsolePlusLibrary; // Color, Style, Overflow live here
// Foreground + background
var s1 = new Style(Color.White, Color.Navy);
// A Color converts implicitly to a foreground-only Style (background = terminal default)
Style s2 = Color.Lime;
⚠️ There is no text-decoration concept (no bold / italic / underline) — a
Styleis colors plus an overflow strategy. See ConsolePlus → Styles & Overflow for the fullStyleAPI, builder helpers (ForeGround,Background,Overflow,Colors), and theOverflowstrategies.
Every control exposes a fluent .Styles(<ControlEnum>, style) method. Each control has its own enum
of regions, and each region is styled independently. A bare Color is accepted as shorthand for a
foreground-only style.
using ConsolePlusLibrary;
using PromptPlusLibrary;
PromptPlus.Controls
.Select<string>("Pick one")
.AddItems(["Alpha", "Beta", "Gamma"])
.Styles(SelectStyles.Selected, Color.Yellow) // Color shorthand
.Styles(SelectStyles.Prompt, new Style(Color.White, Color.Default))
.Run();
Apply the same style to every control by setting it in a small helper (or a config-loading routine) that you call for each control — the library does not broadcast a style for you.
Each control defines its own regions. The exact list lives on that control’s Styles page; common
region names include Prompt, Answer, Description, Selected, UnSelected, Disabled,
Error, Pagination, Tooltips.
| Control | Style enum |
|---|---|
| Input / Secret | InputStyles |
| KeyPress / Confirm | KeyPressStyles |
| Select | SelectStyles |
| MultiSelect | MultiSelectStyles |
| MaskEdit family | MaskEditStyles |
| Calendar | CalendarStyles |
| Slider | SliderStyles |
| Switch | SwitchStyles |
| ProgressBar | ProgressBarStyles |
| Task | TaskStyles |
| MultiTasks | MultiTasksStyles |
| Timer | TimerStyles |
| TableSelect | TableSelectStyles |
| TableMultiSelect | TableMultiSelectStyles |
| TreeSelect | TreeSelectStyles |
| TreeMultiSelect | TreeMultiSelectStyles |
| File | FileStyles |
| MultiFile | MultiFileStyles |
| ChartBar | ChartBarStyles |
PromptPlus enforces a minimum contrast ratio between foreground and background so text stays readable on any terminal theme. When a chosen foreground falls below the ratio against its background, it is adjusted automatically.
// Default is 2.7
PromptPlus.Config.ContrastRatio = 0; // disable enforcement (use any colors as-is)
PromptPlus.Config.ContrastRatio = 4.5; // WCAG AA target
A ratio of
0disables the check entirely. Higher values improve readability but may not be achievable with every color pair, in which case PromptPlus picks the closest compliant color.
Because there is no global style broadcast, centralize your theme in one place and apply it per control:
using ConsolePlusLibrary;
using PromptPlusLibrary;
static ISelectControl<T> Themed<T>(ISelectControl<T> c) => c
.Styles(SelectStyles.Prompt, Color.Cyan)
.Styles(SelectStyles.Answer, Color.Green)
.Styles(SelectStyles.Tooltips, Color.Grey);
var result = Themed(PromptPlus.Controls.Select<string>("Color").AddItems(colors)).Run();
Style API and Overflow strategiesContrastRatio and the rest of PromptPlus.Config