Skip to content
This repository has been archived by the owner on May 2, 2019. It is now read-only.

Keep colored output for --color=auto on Windows #3

Open
MichaelKim0407 opened this issue Aug 28, 2017 · 3 comments
Open

Keep colored output for --color=auto on Windows #3

MichaelKim0407 opened this issue Aug 28, 2017 · 3 comments

Comments

@MichaelKim0407
Copy link
Owner

Since there is no termios module on Windows, there is no way to emulate a terminal, which means when using --color=auto option, we cannot trick subprocess to think that it is connected to a terminal instead of a pipe. Thus, with --color=auto option, there will be no colored output.

This trick is essential for --color=auto or -G for BSD.

One way to force colored output is to replace --color=auto with --color=always, however this will have undesired consequences when using a pipe or redirecting to a file. We can try to detect if os.stdout is a terminal or not. However the current solution also uses termios.

Any input is welcome.

@MichaelKim0407
Copy link
Owner Author

I figured that we can simple use isatty to detect is stdout is terminal or not. It is not *nix only.

However as I tested, isatty always returns False in git-bash, although it works correctly on Windows cmd...

@abhiramr
Copy link

Right now, it already works and the same effect can still be obtained using
ls-git -l --color
(Not sure if this is already a known consequence.)

@MichaelKim0407
Copy link
Owner Author

MichaelKim0407 commented Aug 29, 2017

@abhiii5459 --color is --color=always, which means output is always colored, whether it's a terminal or a pipe/redirect. If you redirect the output to a file and edit it, you will actually see stuff like \033[01;31m which means bold red...

The tricky thing here is not --color=always, but --color=auto, in which case the program needs to detect whether the output is terminal or not, and then decide if output should be colored. But I haven't found a way to do it when running python in git-bash.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants