Last active
December 27, 2024 21:03
-
-
Save tosterlolz/06c9fb025d9bc50447741c18ff0e9e91 to your computer and use it in GitHub Desktop.
New tool for r/unixporn idk
This file contains hidden or 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 os | |
| import random | |
| import shutil | |
| import subprocess | |
| import time | |
| from colorama import Fore, Style, init | |
| init() | |
| def get_terminal_size(): | |
| try: | |
| size = shutil.get_terminal_size() | |
| return size.columns, size.lines | |
| except (AttributeError, OSError): | |
| try: | |
| rows, columns = os.popen('stty size', 'r').read().split() | |
| return int(columns), int(rows) | |
| except: | |
| return 80, 24 | |
| def clear_screen(): | |
| os.system('cls' if os.name == 'nt' else 'clear') | |
| def generate_random_grid(cols, rows): | |
| grid = [] | |
| for _ in range(rows): | |
| row = [] | |
| for _ in range(cols): | |
| num = random.randint(0, 9) | |
| color = random.choice([Fore.RED, Fore.GREEN, Fore.YELLOW, Fore.BLUE, Fore.MAGENTA, Fore.CYAN]) | |
| row.append((num, color)) | |
| grid.append(row) | |
| return grid | |
| def display_grid(grid): | |
| for row in grid: | |
| line = "" | |
| for num, color in row: | |
| line += color + str(num) + Style.RESET_ALL + " " | |
| print(line) | |
| def main(): | |
| try: | |
| cols, rows = get_terminal_size() | |
| except ValueError: | |
| print("Could not determine terminal size.") | |
| return | |
| while True: | |
| clear_screen() | |
| cols, rows = get_terminal_size() | |
| grid = generate_random_grid(cols // 2, rows-1) | |
| display_grid(grid) | |
| time.sleep(0.25) | |
| if __name__ == "__main__": | |
| try: | |
| main() | |
| except KeyboardInterrupt: | |
| print("\nExiting...") | |
| exit(0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment