halo
halo copied to clipboard
Bug: Crash when using an animation and switching to a new animated message shorter than current position
Description
If you set a message to be rendered using one of the animations, then stop it and change to a different message which is shorter than the original message but still needs animating, if the current index is longer than the new message an exception is thrown
System settings
- Operating System: Arch Linux
- Terminal in use: Alacritty
- Python version: 3.9
- Halo version: 0.0.31
pip freezeoutput:
halo==0.0.31
log-symbols==0.0.14
six==1.16.0
spinners==0.0.24
termcolor==1.1.0
Error
Exception in thread Thread-1:
Traceback (most recent call last):
File "/usr/lib/python3.9/threading.py", line 973, in _bootstrap_inner
self.run()
File "/usr/lib/python3.9/threading.py", line 910, in run
self._target(*self._args, **self._kwargs)
File ".../lib/python3.9/site-packages/halo/halo.py", line 421, in render
self._render_frame()
File ".../lib/python3.9/site-packages/halo/halo.py", line 407, in _render_frame
frame = self.frame()
File ".../lib/python3.9/site-packages/halo/halo.py", line 441, in frame
text_frame = self.text_frame()
File ".../lib/python3.9/site-packages/halo/halo.py", line 464, in text_frame
frame = frames[self._text_index]
IndexError: list index out of range
Expected behaviour
Reset _text_index to the start of the new message.
Steps to recreate
> python -c "import halo;halo=halo.Halo(animation='marquee',interval=1);halo.start('abc'*$COLUMNS);import time;time.sleep($COLUMNS*0.01*2);halo.start('x'*($COLUMNS+2))"
(not 100% reliable, can take a few tries to reproduce)