mirror of
				https://github.com/Garmelon/PFERD.git
				synced 2025-11-03 22:23:41 +01:00 
			
		
		
		
	Fix progress bars swallowing a line when they shouldn't
This commit is contained in:
		@@ -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
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user