@@ -348,15 +348,15 @@ def _get_text(self, text):
348
348
self
349
349
"""
350
350
animation = self ._animation
351
- stripped_text = text .strip ()
351
+ stripped_text = lambda : text (). strip () if hasattr ( text , '__call__' ) else text .strip ()
352
352
353
353
# Check which frame of the animation is the widest
354
354
max_spinner_length = max ([len (i ) for i in self ._spinner ["frames" ]])
355
355
356
- # Subtract to the current terminal size the max spinner length
356
+ # Subtract from the current terminal size the max spinner length
357
357
# (-1 to leave room for the extra space between spinner and text)
358
358
terminal_width = get_terminal_columns () - max_spinner_length - 1
359
- text_length = len (stripped_text )
359
+ text_length = len (stripped_text ()) if hasattr ( text , '__call__' ) else len ( stripped_text )
360
360
361
361
frames = []
362
362
@@ -366,18 +366,30 @@ def _get_text(self, text):
366
366
Make the text bounce back and forth
367
367
"""
368
368
for x in range (0 , text_length - terminal_width + 1 ):
369
- frames .append (stripped_text [x : terminal_width + x ])
369
+ if hasattr (text , '__call__' ):
370
+ frame = stripped_text ()[x : terminal_width + x ]
371
+ else :
372
+ frame = stripped_text [x : terminal_width + x ]
373
+ frames .append (frame )
370
374
frames .extend (list (reversed (frames )))
371
375
elif "marquee" :
372
376
"""
373
377
Make the text scroll like a marquee
374
378
"""
375
- stripped_text = stripped_text + " " + stripped_text [:terminal_width ]
376
- for x in range (0 , text_length + 1 ):
377
- frames .append (stripped_text [x : terminal_width + x ])
379
+ if hasattr (text , '__call__' ):
380
+ new_stripped_text = lambda : stripped_text () + " " + stripped_text ()[:terminal_width ]
381
+ for x in range (0 , text_length + 1 ):
382
+ frames .append (new_stripped_text ()[x : terminal_width + x ])
383
+ else :
384
+ stripped_text = stripped_text + " " + stripped_text [:terminal_width ]
385
+ for x in range (0 , text_length + 1 ):
386
+ frames .append (stripped_text [x : terminal_width + x ])
378
387
elif terminal_width < text_length and not animation :
379
388
# Add ellipsis if text is larger than terminal width and no animation was specified
380
- frames = [stripped_text [: terminal_width - 6 ] + " (...)" ]
389
+ if hasattr (text , '__call__' ):
390
+ frames = [lambda : stripped_text ()[: terminal_width - 6 ] + " (...)" ]
391
+ else :
392
+ frames = [stripped_text [: terminal_width - 6 ] + " (...)" ]
381
393
else :
382
394
frames = [stripped_text ]
383
395
@@ -454,14 +466,19 @@ def text_frame(self):
454
466
self
455
467
"""
456
468
if len (self ._text ["frames" ]) == 1 :
469
+ frame = self ._text ["frames" ][0 ]
470
+ if hasattr (frame , '__call__' ):
471
+ frame = frame ()
457
472
if self ._text_color :
458
- return colored_frame (self . _text [ "frames" ][ 0 ] , self ._text_color )
473
+ return colored_frame (frame , self ._text_color )
459
474
460
475
# Return first frame (can't return original text because at this point it might be ellipsed)
461
- return self . _text [ "frames" ][ 0 ]
476
+ return frame
462
477
463
478
frames = self ._text ["frames" ]
464
479
frame = frames [self ._text_index ]
480
+ if hasattr (frame , '__call__' ):
481
+ frame = frame ()
465
482
466
483
self ._text_index += 1
467
484
self ._text_index = self ._text_index % len (frames )
0 commit comments