Replies: 1 comment
-
More concrete proof of concept. This is a simple extension to the The one thing I could see being a problem here, is when there are multiple running tasks. Ideally the Perhaps a simpler idea would be to only use the indeterminate OSC while the from rich.console import WINDOWS
import rich.progress
class Progress(rich.progress.Progress):
"""
Provides extra support for Windows Terminal and ConEmu to set operating
system codes (OSC) for progress indicators.
"""
def add_task(self, *args, **kwargs) -> rich.progress.TaskID:
"""
Override to initiate OSC progress indicator.
"""
tid = super().add_task(*args, **kwargs)
# Only continue on supported systems.
if not WINDOWS or self.console.legacy_windows:
return tid
task = self._tasks[tid]
# Set indeterminate status if no total.
if task.total is None:
self.console.print("\x1b]9;4;3;0\x1b\\", end="")
# If we have a total, show the percentage.
elif task.total:
percent = int(task.percentage)
self.console.print(f"\x1b]9;4;1;{percent}\x1b\\", end="")
return tid
def update(self, task_id: rich.progress.TaskID, *args, **kwargs) -> None:
"""
Override to reset OSC progress, or update the percentage.
"""
super().update(task_id, *args, **kwargs)
# Only continue on supported systems.
if not WINDOWS or self.console.legacy_windows:
return
task = self._tasks[task_id]
# Reset if completed.
if task.total and task.completed >= task.total:
self.console.print("\x1b]9;4;0;0\x1b\\", end="")
# If we have a total, show the percentage.
elif task.total:
percent = int(task.percentage)
self.console.print(f"\x1b]9;4;1;{percent}\x1b\\", end="") |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I recently discovered that the new Windows Terminal will read special escape sequences to trigger progress states in the UI. This is quite a "shiny" animation and takes the integration to the next level, as the progress meter shows in the Windows task bar and title bar.
A quick proof of concept shows that this in fact works well with Python!
Details: microsoft/terminal#8055
Proof of concept:
Beta Was this translation helpful? Give feedback.
All reactions