colorama
colorama copied to clipboard
Provide pass-through ANSI on Windows 10 powershell
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
Pictures!
CMD (so only 16 color mode, but that works):
Powershell (full 256 color glory!):
@MinchinWeb Are you sure this only works in powershell? I think you simply need to enable ENABLE_VIRTUAL_TERMINAL_PROCESSING
.
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
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!
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.
Also: We can't merge this until someone provides corresponding changes to the tests.
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!
#139 uses a more direct/reliable strategy to handle the ANSI stuff, so closing this in favor of it