microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
162.39k stars 28.62k forks source link

Trouble printing ANSI escape sequences in the debug console #186963

Closed sherry30 closed 1 year ago

sherry30 commented 1 year ago

Steps to Reproduce:

If you have any ANSI escape sequences in a custom class, they don't get printed directly unless print statement is used.

  1. create a custom class in a new python file:

    class test:
    def __repr__(self):
        return "\033[1;32m This text is Bright Green  \n"
    x = test()
    print(x)
  2. Put a breaker at print(x) statement and Debug this and open up the debug console.

  3. type x and press Enter, it will print  This text is Bright Green. If you do print(x) then it prints correctly in green color.

This works fine in Pycharm's debug console.

roblourens commented 1 year ago

I think this is by design- when inspecting variables, you see the actual content of the variable, it should not interpret the contents of the variable as a special escape code

NickCrews commented 1 year ago

@roblourens I just stumbled upon this issue. Can we reconsider?

I think that rationale makes sense if you had s = "\033[1;32m This text is Bright Green \n" and then looked at s: You are inspecting the raw data, so no interpretation should happen. But in this case the debugger is going through __repr__(). As soon as you have to use repr, you no longer have any hope of seeing exactly "the actual content of the variable", but instead a representation useful for debugging. If you want to see the actual content, then you have to inspect the individual members of the object, possibly in the debugger variable explorer.

I would expect this behavior:

This is the behavior that jupyter has, and (at least I) expected.