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 Jul 2, 2024
1 parent 74b90ff commit 1c1546b
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 @@ -183,13 +196,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 1c1546b

Please sign in to comment.