colorama icon indicating copy to clipboard operation
colorama copied to clipboard

Provide pass-through ANSI on Windows 10 powershell

Open MinchinWeb opened this issue 7 years ago • 6 comments

This provides pass-thru to ANSI codes on new enough Windows 10 versions, and to Powershell only. It does this by using psutil to check the process name that is running python, and if that matches powershell.exe, ANSI pass-thru is enabled.

This does add psutil as a dependency on Windows.

Closes #105

Basic local testing on both Python 2.7 and Python 3.6

MinchinWeb avatar Jun 11 '17 05:06 MinchinWeb

Pictures!

CMD (so only 16 color mode, but that works):

image

Powershell (full 256 color glory!):

image

MinchinWeb avatar Jun 11 '17 05:06 MinchinWeb

@MinchinWeb Are you sure this only works in powershell? I think you simply need to enable ENABLE_VIRTUAL_TERMINAL_PROCESSING.

image

0x4 is ENABLE_VIRTUAL_TERMINAL_PROCESSING. cmd has a weird behavior that powershell doesn't have. It enables ENABLE_VIRTUAL_TERMINAL_PROCESSING on start, disables it when it starts a child program and doesn't disable it on exit (If you start cmd as a child of Python it will leak ENABLE_VIRTUAL_TERMINAL_PROCESSING). powershell just enables it on start and leaves it at that.

Reference: https://msdn.microsoft.com/en-us/library/windows/desktop/ms686033(v=vs.85).aspx

segevfiner avatar Jul 14 '17 10:07 segevfiner

Hey. FYI, yesterday I created a PR to test releases before we push them to PyPI. When that is merged, I'll be more confident about resuming merges and releases. I'll try to look at this PR soon. Thank you for creating it!

tartley avatar Oct 13 '20 14:10 tartley

This seems like it fixes a genuine problem, and if this is the best way to detect powershell then I'd like to merge, but I am hazy on whether this change is still needed if we merge https://github.com/tartley/colorama/pull/139.

I'll experiment with them both later this week. If anyone has any insight (I do not know what I'm doing) I'd be grateful.

Apologies for ignoring this (and all other PRs) for years.

tartley avatar Oct 07 '21 20:10 tartley

Also: We can't merge this until someone provides corresponding changes to the tests.

tartley avatar Oct 07 '21 20:10 tartley

I think that if #139 is robust, that would be preferred just because it doesn't add another dependency to the project. But I'd be happy to see either merged!

MinchinWeb avatar Oct 08 '21 02:10 MinchinWeb

#139 uses a more direct/reliable strategy to handle the ANSI stuff, so closing this in favor of it

njsmith avatar Aug 25 '22 21:08 njsmith