From a019c762efadd300dcfb9f9635a8c8ecd8305b77 Mon Sep 17 00:00:00 2001 From: Erin Sheldon Date: Sat, 5 Oct 2024 23:38:20 -0400 Subject: [PATCH] ensure fixed size for meter --- esutil/pbar.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/esutil/pbar.py b/esutil/pbar.py index 1c02002..521fb3c 100644 --- a/esutil/pbar.py +++ b/esutil/pbar.py @@ -184,8 +184,13 @@ def format_meter(n, total, elapsed, n_bars=20): left_str = format_interval(elapsed / n * (total-n)) if n else '?' - return '|%s| %d/%d %s [elapsed: %s left: %s %s]' % ( - bar, n, total, percentage, elapsed_str, left_str, rate_str) + totstr = str(total) + nfmt = '%' + str(len(totstr)) + 'd' + meter_fmt = '|%s| ' + nfmt + '/' + nfmt + ' %s [%s<%s %s]' + + return meter_fmt % ( + bar, n, total, percentage, elapsed_str, left_str, rate_str + ) else: return '%d [elapsed: %s]' % (n, elapsed_str)