Created
August 11, 2023 15:44
-
-
Save Swarchal/3c265f6e88426806af5d81669a9c797b to your computer and use it in GitHub Desktop.
animated movie-like text printing in the terminal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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