-
Notifications
You must be signed in to change notification settings - Fork 96
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
Init colorama only in Windows legacy terminal #238
Conversation
@@ -101,6 +101,8 @@ def __init__(self, | |||
|
|||
self.only_show_errors = self.config.getboolean('core', 'only_show_errors', fallback=False) | |||
self.enable_color = self._should_enable_color() | |||
# Init colorama only in Windows legacy terminal | |||
self._should_init_colorama = self.enable_color and os.name == 'nt' and not is_modern_terminal() |
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 not (self.enable_color or _KNACK_TEST_FORCE_ENABLE_COLOR) and ...
? Does that mean knack test always use colorama no matter it's modern terminal or legacy terminal?
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 not
(self.enable_color or _KNACK_TEST_FORCE_ENABLE_COLOR) and ...
?
The action scope of mocked _KNACK_TEST_FORCE_ENABLE_COLOR
is CLI.invoke
. If _KNACK_TEST_FORCE_ENABLE_COLOR
is used in CLI.__invoke__
, CLI.invoke
won't be affected and won't have colorama enabled.
Lines 36 to 37 in cd59031
with mock.patch("knack.cli._KNACK_TEST_FORCE_ENABLE_COLOR", True): | |
func(self) |
Does that mean knack test always use colorama no matter it's modern terminal or legacy terminal?
Yes.
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.
Dropped _KNACK_TEST_FORCE_ENABLE_COLOR
. Now strip control sequences by knack itself:
Lines 57 to 58 in e5e0529
def _remove_control_sequence(string): | |
return re.sub(r'\x1b[^m]+m', '', string) |
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.
huge work😂
def assert_in_multi_line(sub_string, string): | ||
# assert sub_string is in string, with all whitespaces, line breaks and control sequences ignored | ||
assert _remove_whitespace(sub_string) in _remove_control_sequence(_remove_whitespace(string)) |
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.
This function does the job of removing control sequences which are previously removed by colorama.
Init colomara only on Windows, because
_should_init_colorama
can be furtherly disabled by Azure CLI