spectreconsole/spectre.console · error · NotSupportedException

Cannot show selection prompt since the current terminal does

Error message

Cannot show selection prompt since the current terminal does not support ANSI escape sequences.

What it means

Thrown by ListPrompt<T>.Show(...) when the console profile's Capabilities.Ansi is false. Selection prompts render using ANSI escape sequences for cursor movement, color, and screen updates. A terminal without ANSI support (legacy Windows cmd without virtual terminal processing, dumb terminals, or a manually-created console with Ansi = false) cannot render the prompt UI. This is checked after the Interactive check.

Source

Thrown at src/Spectre.Console/Prompts/List/ListPrompt.cs:36

        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>(
            nodes,
            converter,
            _strategy.CalculatePageSize(_console, nodes.Count, requestedPageSize),
            wrapAround,
            selectionMode,
            skipUnselectableItems,
            searchEnabled,

View on GitHub (pinned to 0acc92fada)

Solutions

  1. Ensure ANSI is enabled: on Windows, enable virtual terminal processing or use Windows Terminal; on CI, set appropriate TERM.
  2. When using AnsiConsole.Create, set Capabilities.Ansi = true if you know the target supports it.
  3. Guard prompt calls: check AnsiConsole.Profile.Capabilities.Ansi before showing interactive prompts.
  4. Provide a non-ANSI fallback (plain text menu, config file, command-line args) when ANSI is unavailable.

Example fix

// before
var settings = new AnsiConsoleSettings
{
    Out = new AnsiConsoleOutput(Console.Out),
};
var console = AnsiConsole.Create(settings);
var choice = console.Prompt(selectionPrompt);

// after
var settings = new AnsiConsoleSettings
{
    Out = new AnsiConsoleOutput(Console.Out),
};
settings.Capabilities.Ansi = true; // or detect/enforce
var console = AnsiConsole.Create(settings);
var choice = console.Prompt(selectionPrompt);
Defensive patterns

Strategy: validation

Validate before calling

if (!AnsiConsole.Profile.Capabilities.Ansi)
{
    // Provide a non-ANSI fallback (plain text, config, args)
    return defaultValue;
}
var choice = AnsiConsole.Prompt(
    new SelectionPrompt<string>()
        .Title("Pick one")
        .AddChoices(options));

Type guard

static bool CanShowAnsiPrompt(IAnsiConsole console)
    => console.Profile.Capabilities.Interactive
       && console.Profile.Capabilities.Ansi;

Try / catch

try
{
    return AnsiConsole.Prompt(selectionPrompt);
}
catch (NotSupportedException ex) when (ex.Message.Contains("ANSI"))
{
    // Fall back to non-ANSI selection or default
    return defaultValue;
}

Prevention

When it happens

Trigger: Calling SelectionPrompt or MultiSelectionPrompt on a console where ANSI is disabled — e.g., Windows CMD with VT processing off, or AnsiConsole.Create with Capabilities.Ansi = false, or environments where Spectre's detection fails to enable ANSI.

Common situations: Legacy Windows environments without virtual terminal support; custom AnsiConsole setup that explicitly disables ANSI; older Windows Terminal/Console Host on Windows 10 pre-1809; environments where TERM is set to 'dumb'; CI runners on Windows without ANSI enabled.

Related errors


AI-assisted analysis of spectreconsole/spectre.console@0acc92fada (2026-08-13). Data as JSON: /api/errors/69fba5c740af336d. Report an issue: GitHub.