spectreconsole/spectre.console · error · NotSupportedException
Cannot show selection prompt since the current terminal isn'
Error message
Cannot show selection prompt since the current terminal isn't interactive.
What it means
Thrown by ListPrompt<T>.Show(...) when the console profile's Capabilities.Interactive is false. Selection-style prompts (SelectionPrompt, MultiSelectionPrompt) require a real interactive terminal to read keystrokes for navigation. Spectre checks this up front and throws NotSupportedException rather than failing mid-render or hanging on input that can never arrive. Note: this is checked before the ANSI capability check.
Source
Thrown at src/Spectre.Console/Prompts/List/ListPrompt.cs:29
_console = console ?? throw new ArgumentNullException(nameof(console));
_strategy = strategy ?? throw new ArgumentNullException(nameof(strategy));
}
public async Task<ListPromptState<T>> Show(
ListPromptTree<T> tree,
Func<T, string> converter,
SelectionMode selectionMode,
bool skipUnselectableItems,
bool searchEnabled,
int requestedPageSize,
bool wrapAround,
CancellationToken cancellationToken = default)
{
ArgumentNullException.ThrowIfNull(tree);
if (!_console.Profile.Capabilities.Interactive)
{
throw new NotSupportedException(
"Cannot show selection prompt since the current " +
"terminal isn't interactive.");
}
if (!_console.Profile.Capabilities.Ansi)
{
throw new NotSupportedException(
"Cannot show selection prompt since the current " +
"terminal does not support ANSI escape sequences.");
}
var nodes = tree.Traverse().ToList();
if (nodes.Count == 0)
{
throw new InvalidOperationException("Cannot show an empty selection prompt. Please call the AddChoice() method to configure the prompt.");
}
var state = new ListPromptState<T>(View on GitHub (pinned to 0acc92fada)
Solutions
- Guard prompt calls with AnsiConsole.Profile.Capabilities.Interactive.
- For automated tests, use AnsiConsole.Testing.TestConsole which supports interactive simulation.
- Run in a PTY wrapper in CI if interactive prompts are required.
- Provide a non-interactive fallback (default value, config file, command-line args) when no TTY is detected.
Example fix
// before
var choice = AnsiConsole.Prompt(
new SelectionPrompt<string>()
.Title("Pick one")
.AddChoices(new[] { "A", "B", "C" }));
// after
if (!AnsiConsole.Profile.Capabilities.Interactive)
{
return defaultValue; // non-interactive fallback
}
var choice = AnsiConsole.Prompt(
new SelectionPrompt<string>()
.Title("Pick one")
.AddChoices(new[] { "A", "B", "C" })); Defensive patterns
Strategy: validation
Validate before calling
if (!AnsiConsole.Profile.Capabilities.Interactive)
{
// Provide a non-interactive fallback
return defaultValue;
}
var choice = AnsiConsole.Prompt(
new SelectionPrompt<string>()
.Title("Pick one")
.AddChoices(options)); Type guard
static bool CanShowInteractivePrompt(IAnsiConsole console)
=> console.Profile.Capabilities.Interactive
&& console.Profile.Capabilities.Ansi; Try / catch
try
{
return AnsiConsole.Prompt(selectionPrompt);
}
catch (NotSupportedException ex) when (ex.Message.Contains("interactive"))
{
// Fall back to default or config-based selection
return defaultValue;
} Prevention
- Always check Capabilities.Interactive before showing selection prompts.
- Design non-interactive fallbacks (defaults, config, CLI args) for headless/CI.
- Use TestConsole for automated tests that exercise prompt logic.
- Run CI in a PTY wrapper if interactive prompts are mandatory.
When it happens
Trigger: Calling AnsiConsole.Prompt(new SelectionPrompt<string>()...) or MultiSelectionPrompt in a non-interactive environment — CI, Docker without -it, redirected stdin, headless service, or a manually-created AnsiConsole with Interactive = false.
Common situations: Automated tests calling SelectionPrompt against real AnsiConsole; CLI tools run in CI without a PTY; Docker containers without -it; SSH non-interactive sessions; output piped to another command.
Related errors
- Cannot show selection prompt since the current terminal does
- Failed to read input in non-interactive mode.
- Could not convert input to a string
- Console width must be greater than zero
- Console height must be greater than zero
AI-assisted analysis of spectreconsole/spectre.console@0acc92fada (2026-08-13).
Data as JSON: /api/errors/370c0487474f2db1.
Report an issue: GitHub.