Skip to content

Commit

Permalink
improve output performance on slow terminals
Browse files Browse the repository at this point in the history
  • Loading branch information
mzuther committed Mar 20, 2023
1 parent b0be087 commit c651e9a
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions src/StempelWerk.py
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ def render_all_templates(self, process_only_modified=False,
saved_files += run_results['saved_files']

if self.verbosity < -1:
self._show_progress(processed_templates)
self._show_progress(processed_templates, is_finished=False)

# only save time of current run and show statistics when files have
# actually been processed
Expand All @@ -712,13 +712,18 @@ def render_all_templates(self, process_only_modified=False,
}


def _show_progress(self, processed_templates):
print('.', end='')
def _show_progress(self, processed_templates, is_finished):
if is_finished:
# finish last line
remaining_dots = processed_templates % 10
print('.' * remaining_dots, end='')

if (processed_templates % 40) == 0:
print()
if (processed_templates % 40) != 0:
print()
elif (processed_templates % 40) == 0:
print('..........', end='\n')
elif (processed_templates % 10) == 0:
print(' ', end='')
print('..........', end=' ')


def _get_last_run(self):
Expand Down Expand Up @@ -749,13 +754,12 @@ def _display_statistics(self, start_of_processing, processed_templates,
self.printer.debug(f'Time per output file: {time_per_file}')
self.printer.debug()

if self.verbosity < -1:
# finish last line
self._show_progress(processed_templates, is_finished=True)

if self.verbosity < 0:
print()

# start new output line
if self.verbosity < -1 and (processed_templates % 40) != 0:
print()

print(f'{processed_templates } =>',
f'{saved_files} in {processing_time}')
print()
Expand Down

0 comments on commit c651e9a

Please sign in to comment.