From b445bca6b9d746931ccbeabcb8aee13f432410e7 Mon Sep 17 00:00:00 2001 From: I-Doctor Date: Tue, 26 Mar 2019 00:43:27 +0800 Subject: [PATCH] change finish function to print last status of bar into stdout at the end of progress instead of stderr, which will do no harm to apperance but will allow users to use <|tee> cmd to store the last status into file --- progress/__init__.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/progress/__init__.py b/progress/__init__.py index e434c25..3a5ffcd 100644 --- a/progress/__init__.py +++ b/progress/__init__.py @@ -48,11 +48,12 @@ def __init__(self, message='', **kwargs): self._width = 0 self.message = message + self.line = '' if self.file and self.is_tty(): if self.hide_cursor: print(HIDE_CURSOR, end='', file=self.file) - print(self.message, end='', file=self.file) + #print(self.message, end='', file=self.file) self.file.flush() def __getitem__(self, key): @@ -101,12 +102,15 @@ def writeln(self, line): self.clearln() print(line, end='', file=self.file) self.file.flush() + self.line = ''.join(line) def finish(self): if self.file and self.is_tty(): - print(file=self.file) + self.clearln() + print(self.line) if self.hide_cursor: print(SHOW_CURSOR, end='', file=self.file) + self.file.flush() def is_tty(self): return self.file.isatty() if self.check_tty else True