Skip to content

Commit ae1e11b

Browse files
authored
Fix: log: missing LF after a progress bar (#1886) (#1891)
In #1020 we right pad the progress bar with space characters so that it will not mess up with log messages printed concurrently during the progress bar runs. However, if the temrinal width changes after the progress bar is printed, the message line following it will be shown in the same line with it. This commit fixes this by adding a final turn to print the progress bar without right padding and with a LF character. Fixes #1886.
2 parents 70bae07 + f3889a0 commit ae1e11b

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

crmsh/log.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,8 +402,10 @@ def status_long(self, msg):
402402
To wait and mark something finished, start with BEGIN msg, end of END msg
403403
"""
404404
self.logger.info("BEGIN %s", msg)
405+
pb = ProgressBar()
405406
try:
406-
yield ProgressBar()
407+
yield pb
408+
pb._end()
407409
except Exception:
408410
self.logger.error("FAIL %s", msg)
409411
raise
@@ -515,6 +517,24 @@ def progress(self):
515517
sys.stdout.write(line)
516518
sys.stdout.flush()
517519

520+
def _end(self):
521+
try:
522+
width, _ = os.get_terminal_size()
523+
except OSError:
524+
# not a terminal
525+
return
526+
if self._i == 0:
527+
pass
528+
elif self._i < width:
529+
line = '\r{}\n'.format('.' * self._i)
530+
sys.stdout.write(line)
531+
else:
532+
# the terminal is resized and narrower than the progress bar printed before
533+
# just write an LF in this case
534+
sys.stdout.write('\n')
535+
sys.stdout.flush()
536+
537+
518538

519539
def setup_logging(only_help=False):
520540
"""

0 commit comments

Comments
 (0)