{"record":{"id":"370c0487474f2db1","repo":"spectreconsole/spectre.console","slug":"cannot-show-selection-prompt-since-the-current-ter","errorCode":null,"errorMessage":"Cannot show selection prompt since the current terminal isn't interactive.","messagePattern":"Cannot show selection prompt since the current terminal isn't interactive\\.","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/Spectre.Console/Prompts/List/ListPrompt.cs","lineNumber":29,"sourceCode":"        _console = console ?? throw new ArgumentNullException(nameof(console));\n        _strategy = strategy ?? throw new ArgumentNullException(nameof(strategy));\n    }\n\n    public async Task<ListPromptState<T>> Show(\n        ListPromptTree<T> tree,\n        Func<T, string> converter,\n        SelectionMode selectionMode,\n        bool skipUnselectableItems,\n        bool searchEnabled,\n        int requestedPageSize,\n        bool wrapAround,\n        CancellationToken cancellationToken = default)\n    {\n        ArgumentNullException.ThrowIfNull(tree);\n\n        if (!_console.Profile.Capabilities.Interactive)\n        {\n            throw new NotSupportedException(\n                \"Cannot show selection prompt since the current \" +\n                \"terminal isn't interactive.\");\n        }\n\n        if (!_console.Profile.Capabilities.Ansi)\n        {\n            throw new NotSupportedException(\n                \"Cannot show selection prompt since the current \" +\n                \"terminal does not support ANSI escape sequences.\");\n        }\n\n        var nodes = tree.Traverse().ToList();\n        if (nodes.Count == 0)\n        {\n            throw new InvalidOperationException(\"Cannot show an empty selection prompt. Please call the AddChoice() method to configure the prompt.\");\n        }\n\n        var state = new ListPromptState<T>(","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/spectreconsole/spectre.console/blob/0acc92fada6c42f13984e79c2b5f3d993bdfb099/src/Spectre.Console/Prompts/List/ListPrompt.cs#L11-L47","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nvar choice = AnsiConsole.Prompt(\n    new SelectionPrompt<string>()\n        .Title(\"Pick one\")\n        .AddChoices(new[] { \"A\", \"B\", \"C\" }));\n\n// after\nif (!AnsiConsole.Profile.Capabilities.Interactive)\n{\n    return defaultValue; // non-interactive fallback\n}\nvar choice = AnsiConsole.Prompt(\n    new SelectionPrompt<string>()\n        .Title(\"Pick one\")\n        .AddChoices(new[] { \"A\", \"B\", \"C\" }));","handlingStrategy":"validation","validationCode":"if (!AnsiConsole.Profile.Capabilities.Interactive)\n{\n    // Provide a non-interactive fallback\n    return defaultValue;\n}\nvar choice = AnsiConsole.Prompt(\n    new SelectionPrompt<string>()\n        .Title(\"Pick one\")\n        .AddChoices(options));","typeGuard":"static bool CanShowInteractivePrompt(IAnsiConsole console)\n    => console.Profile.Capabilities.Interactive\n       && console.Profile.Capabilities.Ansi;","tryCatchPattern":"try\n{\n    return AnsiConsole.Prompt(selectionPrompt);\n}\ncatch (NotSupportedException ex) when (ex.Message.Contains(\"interactive\"))\n{\n    // Fall back to default or config-based selection\n    return defaultValue;\n}","preventionTips":["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."],"tags":["notsupportedexception","prompts","selection","non-interactive","terminal","ci"],"backgroundTag":null,"analyzedSha":"0acc92fada6c42f13984e79c2b5f3d993bdfb099","analyzedAt":"2026-08-13T18:27:21.983Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}