Skip to content

Commit 6ffe8c2

Browse files
committed
Fix calculation of string length
1 parent 82fe8a6 commit 6ffe8c2

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

colcon_notification/event_handler/status.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,19 @@
2222
from colcon_core.subprocess import SIGINT_RESULT
2323

2424

25+
def _colorama_str_len(s):
26+
in_code = False
27+
l = 1
28+
for c in s:
29+
if c == '\033':
30+
in_code = True
31+
elif c == 'm' and in_code:
32+
in_code = False
33+
elif not in_code:
34+
l += 1
35+
return l
36+
37+
2538
class StatusEventHandler(EventHandlerExtensionPoint):
2639
"""
2740
Continuously update a status line.
@@ -173,13 +186,13 @@ def __call__(self, event): # noqa: D102
173186
# append dots when skipping at least one block
174187
if i < len(blocks) - 1:
175188
msg += ' ...'
176-
if len(msg) < max_width:
189+
if _colorama_str_len(msg) < max_width:
177190
break
178191
else:
179192
return
180193

181194
print(msg, end='\r')
182-
self._last_status_line_length = len(msg)
195+
self._last_status_line_length = _colorama_str_len(msg)
183196

184197
elif isinstance(data, EventReactorShutdown):
185198
self._clear_last_status_line()

0 commit comments

Comments
 (0)