Skip to content

Instantly share code, notes, and snippets.

@Swarchal
Created August 11, 2023 15:44
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 Swarchal/3c265f6e88426806af5d81669a9c797b to your computer and use it in GitHub Desktop.
Save Swarchal/3c265f6e88426806af5d81669a9c797b to your computer and use it in GitHub Desktop.
animated movie-like text printing in the terminal
import argparse
import sys
from random import choice
from string import ascii_letters
from time import sleep
charset = ascii_letters + '!@#$%^&*()[]<>./m::~`|\\"'
def scroll_text(text: str, delay: float = 0.01, n_chars: int = 5) -> None:
for line in text.split("\n"):
current_text = ""
for char in line:
if char != " ":
for _ in range(n_chars):
curr_char = f"\033[1m{choice(charset)}\033[0m"
print(current_text + curr_char, end="\r")
sleep(delay)
current_text += char
print(current_text)
def main():
text = sys.stdin.read()
arg_parser = argparse.ArgumentParser()
arg_parser.add_argument("-d", "--delay", type=float, default=0.01)
arg_parser.add_argument("-n", "--n_chars", type=int, default=5)
args = arg_parser.parse_args()
scroll_text(text, args.delay, args.n_chars)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment