From 4bef2962c40ee915226f14d9e77a101266d6f707 Mon Sep 17 00:00:00 2001 From: AlexKurek Date: Sun, 6 Sep 2026 16:37:25 +0200 Subject: [PATCH 1/2] Make progressbar more universal --- bdsf/statusbar.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/bdsf/statusbar.py b/bdsf/statusbar.py index 54ceb9a5..9595897a 100644 --- a/bdsf/statusbar.py +++ b/bdsf/statusbar.py @@ -36,8 +36,11 @@ def __init__(self, text, pos=0, max=100, color='\033[0m'): # find number of columns in terminal def __getsize(self): - tsize = shutil.get_terminal_size(fallback=(0, 0)) - columns = tsize.columns + if not sys.stdout.isatty(): + columns = 80 + else: + tsize = shutil.get_terminal_size(fallback=(0, 0)) + columns = tsize.columns if int(columns) > self.max + 2 + 44 + (len(str(self.max))*2 + 2): self.columns = self.max @@ -54,7 +57,7 @@ def __print(self): # Update terminal size with each frame rendering self.__getsize() - sys.stdout.write('\x1b[1G') + sys.stdout.write('\r') # Handle the case where there are no items to process (prevents from # dividing by zero later) @@ -66,7 +69,6 @@ def __print(self): # so the progress bar adapts to possible window resizing. self.comp = int(float(self.pos) / self.max * self.columns) sys.stdout.write(self.color + self.text + '[' + '=' * self.comp + self.busy_char + '-'*(self.columns - self.comp - 1) + '] ' + str(self.pos) + '/' + str(self.max) + '\033[0m') - sys.stdout.write('\x1b[' + str(self.comp + 2 + 44) + 'G') sys.stdout.flush() return From 62edaea9e095155bff0b7bbf5c0b4afdcc80a454 Mon Sep 17 00:00:00 2001 From: Aleksander Kurek Date: Mon, 7 Sep 2026 14:51:01 +0200 Subject: [PATCH 2/2] Apply suggestion Co-authored-by: Marcel Loose --- bdsf/statusbar.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/bdsf/statusbar.py b/bdsf/statusbar.py index 9595897a..b08980d0 100644 --- a/bdsf/statusbar.py +++ b/bdsf/statusbar.py @@ -36,11 +36,7 @@ def __init__(self, text, pos=0, max=100, color='\033[0m'): # find number of columns in terminal def __getsize(self): - if not sys.stdout.isatty(): - columns = 80 - else: - tsize = shutil.get_terminal_size(fallback=(0, 0)) - columns = tsize.columns + columns = shutil.get_terminal_size().columns if int(columns) > self.max + 2 + 44 + (len(str(self.max))*2 + 2): self.columns = self.max