"""Redact, a scrolling terminal animation by Al Sweigart.""" import random, shutil, sys, time DELAY = 0.12 # Pause between rows in seconds. WIDTH = None # None uses the terminal width. REDACT_CHANCE = 0.25 # Chance that a word is censored. REDACT_CHAR = '█' # Character used to conceal text. WORDS = ('the operation was conducted at approximately oh-three-hundred hours on a Tuesday morning Agent contacted the source via encrypted channel and confirmed delivery of documents pertaining to Project designation classified the target location was identified as building floor room at coordinates north east surveillance team reported no unusual activity during the observation period from to all personnel were accounted for per standard protocol the asset was extracted without incident and transported to safe house further details available upon request authorization level required end of report').split() def get_width(width=None): result = shutil.get_terminal_size()[0] if width is None else width return result - 1 if sys.platform == 'win32' else result def redact(delay=DELAY, width=WIDTH): word_index = 0 while True: current_width, line = get_width(width), '' while len(line) < current_width - 12: word = WORDS[word_index % len(WORDS)]; word_index += 1 if random.random() < REDACT_CHANCE: word = REDACT_CHAR * len(word) line += (' ' if line else '') + word print(line[:current_width].ljust(current_width)); time.sleep(delay) try: redact() except KeyboardInterrupt: print('Redact, by Al Sweigart al@inventwithpython.com')