@@ -130,15 +130,15 @@ class Percentage(Formatter):
130
130
Display the progress as a percentage.
131
131
"""
132
132
133
- template = "<percentage>{percentage:>5}%</percentage>"
133
+ template = HTML ( "<percentage>{percentage:>5}%</percentage>" )
134
134
135
135
def format (
136
136
self ,
137
137
progress_bar : ProgressBar ,
138
138
progress : ProgressBarCounter [object ],
139
139
width : int ,
140
140
) -> AnyFormattedText :
141
- return HTML ( self .template ) .format (percentage = round (progress .percentage , 1 ))
141
+ return self .template .format (percentage = round (progress .percentage , 1 ))
142
142
143
143
def get_width (self , progress_bar : ProgressBar ) -> AnyDimension :
144
144
return D .exact (6 )
@@ -149,7 +149,7 @@ class Bar(Formatter):
149
149
Display the progress bar itself.
150
150
"""
151
151
152
- template = "<bar>{start}<bar-a>{bar_a}</bar-a><bar-b>{bar_b}</bar-b><bar-c>{bar_c}</bar-c>{end}</bar>"
152
+ template = HTML ( "<bar>{start}<bar-a>{bar_a}</bar-a><bar-b>{bar_b}</bar-b><bar-c>{bar_c}</bar-c>{end}</bar>" )
153
153
154
154
def __init__ (
155
155
self ,
@@ -202,7 +202,7 @@ def format(
202
202
bar_b = sym_b
203
203
bar_c = sym_c * (width - pb_a )
204
204
205
- return HTML ( self .template ) .format (
205
+ return self .template .format (
206
206
start = self .start , end = self .end , bar_a = bar_a , bar_b = bar_b , bar_c = bar_c
207
207
)
208
208
@@ -215,15 +215,15 @@ class Progress(Formatter):
215
215
Display the progress as text. E.g. "8/20"
216
216
"""
217
217
218
- template = "<current>{current:>3}</current>/<total>{total:>3}</total>"
218
+ template = HTML ( "<current>{current:>3}</current>/<total>{total:>3}</total>" )
219
219
220
220
def format (
221
221
self ,
222
222
progress_bar : ProgressBar ,
223
223
progress : ProgressBarCounter [object ],
224
224
width : int ,
225
225
) -> AnyFormattedText :
226
- return HTML ( self .template ) .format (
226
+ return self .template .format (
227
227
current = progress .items_completed , total = progress .total or "?"
228
228
)
229
229
@@ -250,14 +250,16 @@ class TimeElapsed(Formatter):
250
250
Display the elapsed time.
251
251
"""
252
252
253
+ template = HTML ("<time-elapsed>{time_elapsed}</time-elapsed>" )
254
+
253
255
def format (
254
256
self ,
255
257
progress_bar : ProgressBar ,
256
258
progress : ProgressBarCounter [object ],
257
259
width : int ,
258
260
) -> AnyFormattedText :
259
261
text = _format_timedelta (progress .time_elapsed ).rjust (width )
260
- return HTML ( "<time-elapsed>{time_elapsed}</time-elapsed>" ) .format (
262
+ return self . template .format (
261
263
time_elapsed = text
262
264
)
263
265
@@ -275,7 +277,7 @@ class TimeLeft(Formatter):
275
277
Display the time left.
276
278
"""
277
279
278
- template = "<time-left>{time_left}</time-left>"
280
+ template = HTML ( "<time-left>{time_left}</time-left>" )
279
281
unknown = "?:??:??"
280
282
281
283
def format (
@@ -290,7 +292,7 @@ def format(
290
292
else :
291
293
formatted_time_left = self .unknown
292
294
293
- return HTML ( self .template ) .format (time_left = formatted_time_left .rjust (width ))
295
+ return self .template .format (time_left = formatted_time_left .rjust (width ))
294
296
295
297
def get_width (self , progress_bar : ProgressBar ) -> AnyDimension :
296
298
all_values = [
@@ -307,7 +309,7 @@ class IterationsPerSecond(Formatter):
307
309
Display the iterations per second.
308
310
"""
309
311
310
- template = (
312
+ template = HTML (
311
313
"<iterations-per-second>{iterations_per_second:.2f}</iterations-per-second>"
312
314
)
313
315
@@ -318,7 +320,7 @@ def format(
318
320
width : int ,
319
321
) -> AnyFormattedText :
320
322
value = progress .items_completed / progress .time_elapsed .total_seconds ()
321
- return HTML ( self .template .format (iterations_per_second = value ) )
323
+ return self .template .format (iterations_per_second = value )
322
324
323
325
def get_width (self , progress_bar : ProgressBar ) -> AnyDimension :
324
326
all_values = [
@@ -335,6 +337,7 @@ class SpinningWheel(Formatter):
335
337
Display a spinning wheel.
336
338
"""
337
339
340
+ template = HTML ("<spinning-wheel>{0}</spinning-wheel>" )
338
341
characters = r"/-\|"
339
342
340
343
def format (
@@ -344,7 +347,7 @@ def format(
344
347
width : int ,
345
348
) -> AnyFormattedText :
346
349
index = int (time .time () * 3 ) % len (self .characters )
347
- return HTML ( "<spinning-wheel>{0}</spinning-wheel>" ) .format (
350
+ return self . template .format (
348
351
self .characters [index ]
349
352
)
350
353
0 commit comments