1

I am asking this question because I have not found an answer before. I recently switched to Windows Terminal and some commands that the "Command Line" or "PowerShell" used to send me with syntax highlighting, are now sent to me without.

Example: on the left the Command Line and PowerShell opened via Windows Terminal, on the right without.

I don't think this is specifically due to the command I am running.

Is there a way to get back the same syntax highlighting as before? If not, I am interested to know what can explain this difference?

I already tried to reboot my computer after the installation.

starball
  • 20,030
  • 7
  • 43
  • 238
Alain
  • 15
  • 4

1 Answers1

2

This issue was reported here in poetry's GitHub repo: No colors in Windows Terminal or cmd #1972. A fix has since been made here: https://github.com/python-poetry/cleo/pull/313.

Old answer

At the time of this writing, poetry doesn't use ANSI escapes by default in the Windows Terminal, but you can force it to by passing the --ansi flag, or setting the ANSICON environment variable. This behaviour is due to a dependency that poetry uses called cleo, and the underlying issue is tracked in the corresponding GitHub repo: cleo fails to detect ANSI support in Windows when run under a VT-native environment #104.

If you're curious about things at a deeper level- how ANSI escape support can be enabled/disabled in a Windows console, see https://superuser.com/q/413073/1749748.

As mentioned in the comments there by Yaekiou, you can create an alias of poetry that adds the ansi flag by default, but I don't see why one would do that instead of just modifying the system environment variables or shell profile script to add the ANSICON variable.

starball
  • 20,030
  • 7
  • 43
  • 238
  • 1
    Thanks, if someone need the command to set the `ANSICON` environment variable, here it is :
    `setx ANSICON 1`
    Personnaly, your last solution did not work for me, but thanks you very mutch for your excellent answer :)
    – Alain Mar 13 '23 at 17:42
  • @Alain What last solution? If you mean the last paragraph, that's not supposed to be a solution. That's bonus readings for you to learn how things work at a slightly deeper level. – starball Mar 13 '23 at 17:48
  • Are we not supposed to change the registry key to `1` ? "the registry value may help enable ANSI for console-mode-oblivious apps" – Alain Mar 13 '23 at 17:54
  • ah. well if that doesn't work for you on its own, it's probably because without `--ansi` on some console/terminal environments like the Windows Terminal, ansi escape codes are not emitted _at all_. Setting the registry key cannot make something that is not emitting any ansi colour codes magically emit them. – starball Mar 13 '23 at 17:58