← Back to Home • Next: Confirm Control →
The KeyPress (and Confirm) control paints its output in named regions.
Each region is a KeyPressStyles value you can recolor per control instance.
ℹ️ Styling is per control — there is no global “style all KeyPress” API. Set styles on each control (or through a small helper you reuse). The only style-related global setting is
PromptPlus.Config.ContrastRatio.
KeyPressStyles regions| Region | What it paints |
|---|---|
Prompt |
The prompt text |
Answer |
The pressed-key answer line |
Description |
The description line under the prompt |
Tooltips |
The key-hint line |
Error |
The invalid-key message line |
Use the fluent Styles method. A Style is a foreground color and a
background color — there is no bold/italic/underline. A bare Color is accepted as shorthand
for a foreground-only style.
using ConsolePlusLibrary;
using PromptPlusLibrary;
PromptPlus.Controls
.KeyPress("Styled sample", "Press 1 or 2")
.AddValidKey(ConsoleKey.D1, null, "Option 1")
.AddValidKey(ConsoleKey.D2, null, "Option 2")
.Styles(KeyPressStyles.Prompt, Color.Yellow) // Color shorthand (foreground)
.Styles(KeyPressStyles.Description, Color.Cyan)
.Styles(KeyPressStyles.Answer, Color.Green)
.Styles(KeyPressStyles.Tooltips, Color.Magenta)
.Styles(KeyPressStyles.Error, new Style(Color.Red, Color.Default)) // explicit fg + bg
.Run();
To reuse a theme across controls, 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