def clear_and_output(self):
"""
Clears the terminal up to the right line then outputs the information
of the task.
"""
# See if output is paused
if self.output_paused:
return
# OK, print
with console_lock:
# Get terminal width
terminal_width = shutil.get_terminal_size((80, 20)).columns
# Get the output we need to print
output = list(self.output(terminal_width))
# Scroll the terminal down/up enough for any new lines
needed_lines = len(output)
new_lines = needed_lines - self.cleared_lines
if new_lines > 0:
print("\n" * new_lines, flush=True, end="")
elif new_lines < 0:
print(
(UP_ONE + CLEAR_LINE) * abs(new_lines),
flush=True,
end="",
)
self.cleared_lines = needed_lines
# Move cursor to top of cleared section
print(
(UP_ONE + CLEAR_LINE) * needed_lines,
flush=True,
end="",
)
for line in output:
print(line)
评论列表
文章目录