-
Notifications
You must be signed in to change notification settings - Fork 709
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Windows 10 and above ANSI support #935
Conversation
Thanks for the bug report and suggested improvement @tunaflsh. I've been thinking about this, and although we could indeed let Loguru implements additional checks that are not part of the Colorama package. For example, in What do you think of detecting support for VT processing to decide whether the stream should be wrapped? diff --git a/loguru/_colorama.py b/loguru/_colorama.py
index d040e79..67d906f 100644
--- a/loguru/_colorama.py
+++ b/loguru/_colorama.py
@@ -44,6 +44,15 @@ def should_wrap(stream):
if stream is not sys.__stdout__ and stream is not sys.__stderr__:
return False
+ try:
+ from colorama.winterm import enable_vt_processing
+ has_native_ansi = enable_vt_processing(stream.fileno())
+ except Exception:
+ has_native_ansi = False
+
+ if has_native_ansi:
+ return False
+
from colorama.win32 import winapi_test
return winapi_test() I'm not a big fan of letting Loguru mutate the console state while calling |
tests/test_formatting.py
Outdated
@@ -19,7 +20,7 @@ | |||
("{level.icon}", lambda r: r == "🐞"), | |||
("{file}", lambda r: r == "test_formatting.py"), | |||
("{file.name}", lambda r: r == "test_formatting.py"), | |||
("{file.path}", lambda r: r == __file__), | |||
("{file.path}", lambda r: os.path.samefile(r, __file__)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you think this is preferable? I feel the opposite. Checking using os.path.samefile()
is less restrictive than using ==
. The test must fail if {file.path}
is "/home/user/../user/foo.txt"
while "/home/user/foo.txt"
is expected, but using os.path.samefile()
won't detect that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That unit test failed on my system. The path's letter cases is inconsistent in Python on Windows. Maybe it should be os.path.normcase
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the explanation! Yes using os.path.normcase()
is a good idea.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what you are referring to exactly. I've looked into In any case, But on older Windows systems won't it still strip ANSI codes even with |
Hum... Actually the current usage of Here is a table to summarize usage of these arguments:
When If within Loguru we have
Yes, but this is the goal. We don't want ansi codes like |
Let colorama.AnsiToWin32 decide where to convert or to strip ANSI sequences.
to support PyCharm This reverts commit d2ebcc1.
I rebased your branch on Thanks for your contribution! |
This pull request is a quick fix to issue #934 with little changes to the original code.
convert
orstrip
the ANSI sequences.