Fix progress bars swallowing a line when they shouldn't

This commit is contained in:
I-Al-Istannen 2020-05-08 19:55:53 +02:00
parent 2d20d2934c
commit a0c5572b59

View File

@ -61,6 +61,18 @@ def progress_for(settings: Optional[ProgressSettings]) -> 'ProgressContextManage
return ProgressContextManager(settings) return ProgressContextManager(settings)
class _OneLineUp(LiveRender):
"""
Render a control code for moving one line upwards.
"""
def __init__(self) -> None:
super().__init__("not rendered")
def __console__(self, console: Console, options: ConsoleOptions) -> RenderResult:
yield Control(f"\r\x1b[1A")
class ProgressContextManager: class ProgressContextManager:
""" """
A context manager used for displaying progress. A context manager used for displaying progress.
@ -95,21 +107,13 @@ class ProgressContextManager:
_progress.remove_task(self._task_id) _progress.remove_task(self._task_id)
if len(_progress.task_ids) == 0: if len(_progress.task_ids) == 0:
# We need to clean up after ourselves, as we were the last one
_progress.stop() _progress.stop()
_progress.refresh() _progress.refresh()
class _OneLineUp(LiveRender): # And we existed, so remove the line above (remove_task leaves one behind)
""" if self._task_id is not None:
Render a control code for moving one line upwards. Console().print(_OneLineUp())
"""
def __init__(self) -> None:
super().__init__("not rendered")
def __console__(self, console: Console, options: ConsoleOptions) -> RenderResult:
yield Control(f"\r\x1b[1A")
Console(file=sys.stdout).print(_OneLineUp())
return None return None