Skip to content

Commit 80b9633

Browse files
committed
Fix calculation of string length
1 parent e9a163c commit 80b9633

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.
@@ -183,13 +196,13 @@ def __call__(self, event): # noqa: D102
183196
# append dots when skipping at least one block
184197
if i < len(blocks) - 1:
185198
msg += ' ...'
186-
if len(msg) < max_width:
199+
if _colorama_str_len(msg) < max_width:
187200
break
188201
else:
189202
return
190203

191204
print(msg, end='\r')
192-
self._last_status_line_length = len(msg)
205+
self._last_status_line_length = _colorama_str_len(msg)
193206

194207
elif isinstance(data, EventReactorShutdown):
195208
self._clear_last_status_line()

0 commit comments

Comments
 (0)