diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-05 04:45:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-05 04:45:14 +0000 |
commit | 5b43aaac61ac94abe722bc98ae58468618f2f512 (patch) | |
tree | 3d58c89faa23d194f83abb24ae1fd05067538fff /src/prompt_toolkit/shortcuts | |
parent | Adding upstream version 3.0.43. (diff) | |
download | prompt-toolkit-5b43aaac61ac94abe722bc98ae58468618f2f512.tar.xz prompt-toolkit-5b43aaac61ac94abe722bc98ae58468618f2f512.zip |
Adding upstream version 3.0.46.upstream/3.0.46
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/prompt_toolkit/shortcuts')
-rw-r--r-- | src/prompt_toolkit/shortcuts/progress_bar/base.py | 1 | ||||
-rw-r--r-- | src/prompt_toolkit/shortcuts/progress_bar/formatters.py | 34 | ||||
-rw-r--r-- | src/prompt_toolkit/shortcuts/prompt.py | 1 |
3 files changed, 20 insertions, 16 deletions
diff --git a/src/prompt_toolkit/shortcuts/progress_bar/base.py b/src/prompt_toolkit/shortcuts/progress_bar/base.py index 21aa1be..a7c2a52 100644 --- a/src/prompt_toolkit/shortcuts/progress_bar/base.py +++ b/src/prompt_toolkit/shortcuts/progress_bar/base.py @@ -7,6 +7,7 @@ Progress bar implementation on top of prompt_toolkit. for item in pb(data): ... """ + from __future__ import annotations import contextvars diff --git a/src/prompt_toolkit/shortcuts/progress_bar/formatters.py b/src/prompt_toolkit/shortcuts/progress_bar/formatters.py index dd0339c..202949c 100644 --- a/src/prompt_toolkit/shortcuts/progress_bar/formatters.py +++ b/src/prompt_toolkit/shortcuts/progress_bar/formatters.py @@ -2,6 +2,7 @@ Formatter classes for the progress bar. Each progress bar consists of a list of these formatters. """ + from __future__ import annotations import datetime @@ -130,7 +131,7 @@ class Percentage(Formatter): Display the progress as a percentage. """ - template = "<percentage>{percentage:>5}%</percentage>" + template = HTML("<percentage>{percentage:>5}%</percentage>") def format( self, @@ -138,7 +139,7 @@ class Percentage(Formatter): progress: ProgressBarCounter[object], width: int, ) -> AnyFormattedText: - return HTML(self.template).format(percentage=round(progress.percentage, 1)) + return self.template.format(percentage=round(progress.percentage, 1)) def get_width(self, progress_bar: ProgressBar) -> AnyDimension: return D.exact(6) @@ -149,7 +150,9 @@ class Bar(Formatter): Display the progress bar itself. """ - template = "<bar>{start}<bar-a>{bar_a}</bar-a><bar-b>{bar_b}</bar-b><bar-c>{bar_c}</bar-c>{end}</bar>" + template = HTML( + "<bar>{start}<bar-a>{bar_a}</bar-a><bar-b>{bar_b}</bar-b><bar-c>{bar_c}</bar-c>{end}</bar>" + ) def __init__( self, @@ -202,7 +205,7 @@ class Bar(Formatter): bar_b = sym_b bar_c = sym_c * (width - pb_a) - return HTML(self.template).format( + return self.template.format( start=self.start, end=self.end, bar_a=bar_a, bar_b=bar_b, bar_c=bar_c ) @@ -215,7 +218,7 @@ class Progress(Formatter): Display the progress as text. E.g. "8/20" """ - template = "<current>{current:>3}</current>/<total>{total:>3}</total>" + template = HTML("<current>{current:>3}</current>/<total>{total:>3}</total>") def format( self, @@ -223,7 +226,7 @@ class Progress(Formatter): progress: ProgressBarCounter[object], width: int, ) -> AnyFormattedText: - return HTML(self.template).format( + return self.template.format( current=progress.items_completed, total=progress.total or "?" ) @@ -250,6 +253,8 @@ class TimeElapsed(Formatter): Display the elapsed time. """ + template = HTML("<time-elapsed>{time_elapsed}</time-elapsed>") + def format( self, progress_bar: ProgressBar, @@ -257,9 +262,7 @@ class TimeElapsed(Formatter): width: int, ) -> AnyFormattedText: text = _format_timedelta(progress.time_elapsed).rjust(width) - return HTML("<time-elapsed>{time_elapsed}</time-elapsed>").format( - time_elapsed=text - ) + return self.template.format(time_elapsed=text) def get_width(self, progress_bar: ProgressBar) -> AnyDimension: all_values = [ @@ -275,7 +278,7 @@ class TimeLeft(Formatter): Display the time left. """ - template = "<time-left>{time_left}</time-left>" + template = HTML("<time-left>{time_left}</time-left>") unknown = "?:??:??" def format( @@ -290,7 +293,7 @@ class TimeLeft(Formatter): else: formatted_time_left = self.unknown - return HTML(self.template).format(time_left=formatted_time_left.rjust(width)) + return self.template.format(time_left=formatted_time_left.rjust(width)) def get_width(self, progress_bar: ProgressBar) -> AnyDimension: all_values = [ @@ -307,7 +310,7 @@ class IterationsPerSecond(Formatter): Display the iterations per second. """ - template = ( + template = HTML( "<iterations-per-second>{iterations_per_second:.2f}</iterations-per-second>" ) @@ -318,7 +321,7 @@ class IterationsPerSecond(Formatter): width: int, ) -> AnyFormattedText: value = progress.items_completed / progress.time_elapsed.total_seconds() - return HTML(self.template.format(iterations_per_second=value)) + return self.template.format(iterations_per_second=value) def get_width(self, progress_bar: ProgressBar) -> AnyDimension: all_values = [ @@ -335,6 +338,7 @@ class SpinningWheel(Formatter): Display a spinning wheel. """ + template = HTML("<spinning-wheel>{0}</spinning-wheel>") characters = r"/-\|" def format( @@ -344,9 +348,7 @@ class SpinningWheel(Formatter): width: int, ) -> AnyFormattedText: index = int(time.time() * 3) % len(self.characters) - return HTML("<spinning-wheel>{0}</spinning-wheel>").format( - self.characters[index] - ) + return self.template.format(self.characters[index]) def get_width(self, progress_bar: ProgressBar) -> AnyDimension: return D.exact(1) diff --git a/src/prompt_toolkit/shortcuts/prompt.py b/src/prompt_toolkit/shortcuts/prompt.py index 7274b5f..115d890 100644 --- a/src/prompt_toolkit/shortcuts/prompt.py +++ b/src/prompt_toolkit/shortcuts/prompt.py @@ -24,6 +24,7 @@ Example:: s = PromptSession() result = s.prompt('Say something: ') """ + from __future__ import annotations from asyncio import get_running_loop |