Back to Migration Overview
Both v5.x and v6.x KeyPress return ResultPrompt<ConsoleKeyInfo?>. Read the key with result.Content (not result.Value).
AddKeyValid → AddValidKey (parameter showtext → displayText)Before (v5.x):
using PromptPlusLibrary;
PromptPlus.Controls.KeyPress("Press a key:")
.AddKeyValid(ConsoleKey.Enter, null, "Enter to confirm")
.AddKeyValid(ConsoleKey.Escape, null, "Esc to cancel")
.Run();
After (v6.x):
PromptPlus.Controls.KeyPress("Press a key:")
.AddValidKey(ConsoleKey.Enter, null, "Enter to confirm")
.AddValidKey(ConsoleKey.Escape, null, "Esc to cancel")
.Run();
Renamed only — the signature is identical.
Timeout — removed with no equivalentBefore (v5.x):
PromptPlus.Controls.KeyPress("Continue? (waiting 10s...)")
.AddKeyValid(ConsoleKey.Y, null, "Yes")
.AddKeyValid(ConsoleKey.N, null, "No")
.Timeout(TimeSpan.FromSeconds(10), ConsoleKey.N)
.Run();
After (v6.x):
// Timeout is not available in v6.x.
// Alternative: use a CancellationToken with an external timeout.
using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(10));
var result = PromptPlus.Controls.KeyPress("Continue?")
.AddValidKey(ConsoleKey.Y, null, "Yes")
.AddValidKey(ConsoleKey.N, null, "No")
.Run(cts.Token);
if (result.IsAborted)
{
// timed out — treat as your default answer
}
⚠️ With a
CancellationTokenthe control is aborted (it does not return a default key). If you need a default key on expiry, implement that logic externally.
ShowCountDown — removed with no equivalent// v5.x only — remove this line during migration
.ShowCountDown(true)
ShowInvalidKey — removed with no equivalent// v5.x only — remove this line during migration
.ShowInvalidKey(false)
Spinner — removed with no equivalent// v5.x only — Spinner is not available on KeyPress in v6.x
.Spinner(SpinnersType.Dots)
ShowMessage — display a dynamic message after the key is pressedvar result = PromptPlus.Controls.KeyPress("Press Y or N:")
.AddValidKey(ConsoleKey.Y, null, "Yes")
.AddValidKey(ConsoleKey.N, null, "No")
.ShowMessage(key => key.Key == ConsoleKey.Y ? "Confirmed!" : "Cancelled.")
.Run();
ShowMessageAsyncvar result = PromptPlus.Controls.KeyPress("Press a key:")
.AddValidKey(ConsoleKey.Enter, null, "Continue")
.ShowMessageAsync(async (key, ct) => await GetExtraInfoAsync(key, ct))
.Run();
Confirm is a KeyPress preconfigured with Yes/No keys derived from the culture (or YesChar/NoChar). It returns ResultPrompt<ConsoleKeyInfo?> — the same as KeyPress.
Before (v5.x):
var confirmed = PromptPlus.Controls.Confirm("Continue?").Run();
if (confirmed.Content?.Key == ConsoleKey.Y)
{
// confirmed
}
After (v6.x):
// Same shape — read the key from .Content (not .Value)
var confirmed = PromptPlus.Controls.Confirm("Continue?").Run();
if (confirmed.Content?.Key == ConsoleKey.Y)
{
// confirmed
}
| Method | v5.x | v6.x | Change |
|---|---|---|---|
AddKeyValid(key, modifiers, showtext) |
✅ | ❌ | Renamed to AddValidKey |
AddValidKey(key, modifiers, displayText) |
❌ | ✅ | New name |
Timeout(TimeSpan/int, ConsoleKey, ConsoleModifiers?) |
✅ | ❌ | Removed with no equivalent |
ShowCountDown(bool) |
✅ | ❌ | Removed with no equivalent |
ShowInvalidKey(bool) |
✅ | ❌ | Removed with no equivalent |
Spinner(SpinnersType) |
✅ | ❌ | Removed with no equivalent |
ShowMessage(Func<ConsoleKeyInfo, string>) |
❌ | ✅ | New |
ShowMessageAsync(...) |
❌ | ✅ | New |
Options(Action<IControlOptions>) |
✅ | ✅ | Unchanged |
Styles(KeyPressStyles, Style) |
✅ | ✅ | Unchanged |
Run(CancellationToken) → ResultPrompt<ConsoleKeyInfo?> |
✅ | ✅ | Unchanged |