tartley / colorama

Simple cross-platform colored terminal text in Python
BSD 3-Clause "New" or "Revised" License
3.56k stars 254 forks source link

Italics/bold, etc #271

Open 12944qwerty opened 4 years ago

12944qwerty commented 4 years ago

I noticed that there were some issues, namely #122 that said that italics and underline don't work on windows. The sequence working on Unix with \x1b[3m but it doesn't work on Windows. I found, however, that, similar to bold sequence, we can use the CSI sequence like so: \033[3m to italicize and \033[4m to underline on WINDOWS. I haven't tried these sequences on Unix but I know that they work on Windows.

Although it may not work on Unix, you could make a system to allow both to work properly.

wiggin15 commented 4 years ago

Hi. The sequences \x1b[3m and \033[3m are the same, it's just the octal vs hex representation of the escape character:

>>> "\x1b[3m" == "\033[3m"
True

There may be some newer terminals on Windows 10 that support ANSI codes (so that sequence will work if written both ways), but as far as I know the regular terminal, "cmd", doesn't support the ANSI codes so they will not work.

12944qwerty commented 4 years ago

If the "regular terminal" doesn't support ANSI codes, then how come the entire program is based on ANSI codes that are supposed to work on Windows as well? I know that it works on Windows, I've used it a lot recently, so it should work.

wiggin15 commented 4 years ago

@12944qwerty The purpose of colorama is not just to print ANSI codes, but also to make them work on Windows terminals. We do this by "catching" the ANSI codes and translating them to the matching Windows API calls that change the terminal properties. Unfortunately, there are no matching Windows API calls to make the text italic, underline or a few other properties that ANSI codes provide. This was already discussed in a few issues about this.

12944qwerty commented 4 years ago

I know that there was multiple issues regarding this topic, but I had found that it did work so I revived the topic.

I realize that the ANSI codes are translated for Windows, but those same ANSI codes (without translation) worked on Windows for me.

ghost commented 4 years ago

but those same ANSI codes (without translation) worked on Windows for me.

@12944qwerty You may be using CMD on Windows Terminal and Windows Terminal supports ANSI codes. And as @wiggin15 has pointed out, the actual 'cmd' doesn't support it, even on recent builds of Windows 10.

Picoseconds commented 3 years ago

It's NOT CMD. It's CONHOST the terminal emulator. CMD is a shell