Skip to content

Commit

Permalink
Fix calculation of string length
Browse files Browse the repository at this point in the history
  • Loading branch information
timonegk committed Dec 13, 2022
1 parent 82fe8a6 commit 6ffe8c2
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions colcon_notification/event_handler/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,19 @@
from colcon_core.subprocess import SIGINT_RESULT


def _colorama_str_len(s):
in_code = False
l = 1
for c in s:
if c == '\033':
in_code = True
elif c == 'm' and in_code:
in_code = False
elif not in_code:
l += 1
return l


class StatusEventHandler(EventHandlerExtensionPoint):
"""
Continuously update a status line.
Expand Down Expand Up @@ -173,13 +186,13 @@ def __call__(self, event): # noqa: D102
# append dots when skipping at least one block
if i < len(blocks) - 1:
msg += ' ...'
if len(msg) < max_width:
if _colorama_str_len(msg) < max_width:
break
else:
return

print(msg, end='\r')
self._last_status_line_length = len(msg)
self._last_status_line_length = _colorama_str_len(msg)

elif isinstance(data, EventReactorShutdown):
self._clear_last_status_line()
Expand Down

0 comments on commit 6ffe8c2

Please sign in to comment.