Skip to content

prompt_toolkit: Ansi codes instead of color when an exception occurs during completion #1565

Closed

Description

@bambu

Ansi codes are displayed in the console instead of the colors when an exception occurs when tab completing. This happens on the prompt-toolkit branch. On the main branch, the exception works as expected.

Easy way to reproduce the error on the prompt-toolkit branch is by modifying argparse_completion.py with the following:

diff --git a/examples/argparse_completion.py b/examples/argparse_completion.py
index 8d2c3dca..46aa5c8d 100755
--- a/examples/argparse_completion.py
+++ b/examples/argparse_completion.py
@@ -48,6 +48,7 @@ class ArgparseCompletion(Cmd):
             "These things can\ncontain newlines and\n",
             Text("styled text!!", style=Style(color=Color.BRIGHT_YELLOW, underline=True)),
         )
+        raise Exception("poc!")

         table_item = Table(
             "Left Column",

After running the output looks like this when attempting to tab complete completion_item:

python argparse_completion.py

?[1;91mException: ?[0mpoc!

?[93mTo enable full traceback, run the following command: ?[0m?[1;36mset debug true?[0m


?[1;91mException: ?[0mpoc!

?[93mTo enable full traceback, run the following command: ?[0m?[1;36mset debug true?[0m

(Cmd) example --completion_item 

Activity

  1. github-actions commented on Jan 28, 2026

    @github-actions
    Contributor

    🤖 Hi @bambu, I've received your request, and I'm working on it now! You can track my progress in the logs for more details.

  2. github-actions commented on Jan 28, 2026

    @github-actions
    Contributor

    🤖 I'm sorry @bambu, but I was unable to process your request. Please see the logs for more details.

  3. added this to the 4.0.0 milestone on Jan 28, 2026
  4. tleonhardt commented on Jan 29, 2026

    @tleonhardt
    Member

    The latest commit on the prompt-toolkit branch in PR #1553 fixes this bug.

    @bambu Thank you very much for reporting it and providing good data on how to easily reproduce.

    Could you please verify this fixes the issue on your end?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions