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
ignore ANSI escape codes in the bar length calculation #592
Conversation
Codecov Report
@@ Coverage Diff @@
## master #592 +/- ##
==========================================
- Coverage 99.28% 99.14% -0.14%
==========================================
Files 9 9
Lines 698 702 +4
Branches 123 125 +2
==========================================
+ Hits 693 696 +3
Misses 3 3
- Partials 2 3 +1 |
CUR_OS = _curos() | ||
IS_WIN = CUR_OS in ['Windows', 'cli'] | ||
IS_NIX = (not IS_WIN) and any( | ||
CUR_OS.startswith(i) for i in | ||
['CYGWIN', 'MSYS', 'Linux', 'Darwin', 'SunOS', 'FreeBSD', 'NetBSD']) | ||
RE_ANSI = re.compile(r"\x1b\[[;\d]*[A-Za-z]") |
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.
could this pick up non-ANSI codes? Maybe as per https://stackoverflow.com/a/1833984 we need \x1b.*?m
or \x1b[^m]*m
?
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 don't think it would, as this sequence matches Esc[
+ (digits and ;
) + (one letter), which should only occur in ANSI escape codes: http://ascii-table.com/ansi-escape-sequences.php
In the stackoverflow entry the problem is that the author used arbitrary character matching (.*
).
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.
lgtm, technically other sequences accept =
as well as strings, but they shouldn't be used in a progress bar.
Fixes #591.
This strips ANSI escape codes from the description string before calculating the remaining length of the bar, such that strings containing e.g. color codes are still displayed with the correct width.