From 4784c58c5529b669e0958f4c113d52ea62017ae7 Mon Sep 17 00:00:00 2001 From: Vincent Smeets Date: Wed, 28 Jun 2023 21:04:53 +0200 Subject: [PATCH] cli.User: Fix progress output. --- gramps/cli/user.py | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/gramps/cli/user.py b/gramps/cli/user.py index dfa2d136cd8..1fc16c32eed 100644 --- a/gramps/cli/user.py +++ b/gramps/cli/user.py @@ -96,31 +96,35 @@ def begin_progress(self, title, message, steps): :type steps: int :returns: none """ - self._fileout.write(message) self.steps = steps self.current_step = 0 - if self.steps == 0: - self._fileout.write(_SPINNER[self.current_step]) - else: - self._fileout.write("00%") + self.display_progress() + self._fileout.write(message) def step_progress(self): """ Advance the progress meter. """ self.current_step += 1 - if self.steps == 0: - self.current_step %= 4 - self._fileout.write("\r %s " % _SPINNER[self.current_step]) - else: - percent = int((float(self.current_step) / self.steps) * 100) - self._fileout.write("\r%02d%%" % percent) + self.display_progress() def end_progress(self): """ Stop showing the progress indicator to the user. """ - self._fileout.write("\r100%\n") + self.display_progress(end=True) + + def display_progress(self, end=False): + if end: + self.steps = self.current_step = 1 + if self.steps == 0: + self.current_step %= 4 + self._fileout.write("\r %s " % _SPINNER[self.current_step]) + else: + percent = int((float(self.current_step) / self.steps) * 100) + self._fileout.write("\r%3d%% " % percent) + if end: + self._fileout.write("\n") def prompt( self,