diff --git a/src/prompt_toolkit/shortcuts/progress_bar/formatters.py b/src/prompt_toolkit/shortcuts/progress_bar/formatters.py
index dd0339c3a..b1a89dd6d 100644
--- a/src/prompt_toolkit/shortcuts/progress_bar/formatters.py
+++ b/src/prompt_toolkit/shortcuts/progress_bar/formatters.py
@@ -130,7 +130,7 @@ class Percentage(Formatter):
Display the progress as a percentage.
"""
- template = "{percentage:>5}%"
+ template = HTML("{percentage:>5}%")
def format(
self,
@@ -138,7 +138,7 @@ def format(
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 +149,7 @@ class Bar(Formatter):
Display the progress bar itself.
"""
- template = "{start}{bar_a}{bar_b}{bar_c}{end}"
+ template = HTML("{start}{bar_a}{bar_b}{bar_c}{end}")
def __init__(
self,
@@ -202,7 +202,7 @@ def format(
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 +215,7 @@ class Progress(Formatter):
Display the progress as text. E.g. "8/20"
"""
- template = "{current:>3}/{total:>3}"
+ template = HTML("{current:>3}/{total:>3}")
def format(
self,
@@ -223,7 +223,7 @@ def format(
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 +250,8 @@ class TimeElapsed(Formatter):
Display the elapsed time.
"""
+ template = HTML("{time_elapsed}")
+
def format(
self,
progress_bar: ProgressBar,
@@ -257,7 +259,7 @@ def format(
width: int,
) -> AnyFormattedText:
text = _format_timedelta(progress.time_elapsed).rjust(width)
- return HTML("{time_elapsed}").format(
+ return self.template.format(
time_elapsed=text
)
@@ -275,7 +277,7 @@ class TimeLeft(Formatter):
Display the time left.
"""
- template = "{time_left}"
+ template = HTML("{time_left}")
unknown = "?:??:??"
def format(
@@ -290,7 +292,7 @@ def format(
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 +309,7 @@ class IterationsPerSecond(Formatter):
Display the iterations per second.
"""
- template = (
+ template = HTML(
"{iterations_per_second:.2f}"
)
@@ -318,7 +320,7 @@ def format(
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 +337,7 @@ class SpinningWheel(Formatter):
Display a spinning wheel.
"""
+ template = HTML("{0}")
characters = r"/-\|"
def format(
@@ -344,7 +347,7 @@ def format(
width: int,
) -> AnyFormattedText:
index = int(time.time() * 3) % len(self.characters)
- return HTML("{0}").format(
+ return self.template.format(
self.characters[index]
)