Skip to content

Instantly share code, notes, and snippets.

@danilin-em
Last active November 24, 2019 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danilin-em/35a92da221ac9df51f65c05df39c231f to your computer and use it in GitHub Desktop.
Save danilin-em/35a92da221ac9df51f65c05df39c231f to your computer and use it in GitHub Desktop.
Animation for long string
""" Animation for long string
Usage:
myapp.py:
-----------------------------------------------------------------------------------
line = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod'
idx = 0
while True:
idx, short_line = line_animation(line, idx, 5)
print(short_line, end='\r')
time.sleep(0.2)
-----------------------------------------------------------------------------------
Now see animation:
$ python3 myapp.py
Lorem ipsu
"""
def line_animation(line, idx, limit=10):
line_start = 0
line_end = len(line)
line = (' ' * (limit - 1)) + line
if limit+idx > line_end:
line = line + ' '
short_line = line[line_start+idx:limit+idx]
idx += 1
if idx > (line_end + limit) - 1:
idx = 0
short_line = short_line+(' '*(limit-len(short_line)))
return (idx, short_line)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment