From 38915249af70e7936fca7421c54fa121ea6f561a Mon Sep 17 00:00:00 2001 From: Jacob Babor Date: Thu, 30 Jan 2025 14:46:13 -0600 Subject: [PATCH] Fancy output displays --- autopon.py | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/autopon.py b/autopon.py index e7cd7b9..96743dc 100755 --- a/autopon.py +++ b/autopon.py @@ -49,10 +49,22 @@ def main(): "R": "45" } drummapping = { - "U": '\033[32mCHAKA\033[0m', - "D": '\033[33mDON\033[0m', - "L": '\033[31mPATA\033[0m', - "R": '\033[34mPON\033[0m' + "U": { + "string": "CHAKA", + "color": 32 + }, + "D": { + "string": "DON", + "color": 33 + }, + "L": { + "string": "PATA", + "color": 31 + }, + "R": { + "string": "PON", + "color": 34 + }, } parser = argparse.ArgumentParser( description="Play a sequence of Patapon commands on repeat" @@ -88,6 +100,12 @@ def main(): remaining_iterations = args.iterations lastbeat = 0 + # Get a ghost string to use for fancy input display stuffs + ghoststring="\033[37m" + for i, key in enumerate(sequence): + ghoststring += drummapping.get(key,{}).get('string',' ') + ghoststring+="\033[0m" + # Wait for user confirmation input("Press enter on-beat to sync up with Patapon...") synctime = time.perf_counter() + startup_delay @@ -95,6 +113,7 @@ def main(): # Play da notes try: while remaining_iterations > 0: + print(ghoststring, end="\r", flush=True) for i, key in enumerate(sequence): while time.perf_counter() < synctime + lastbeat: pass @@ -103,11 +122,11 @@ def main(): if button != '-': if not args.dry_run: ydotool(key=button, delay=args.key_delay, multiplier=args.bpm) - print(drummapping.get(key, '-'), end="", flush=True) + print(f"\033[{drummapping.get(key,{}).get('color',0)}m{drummapping.get(key,{}).get('string','-')}\033[0m", end="", flush=True) else: print(" ", end="", flush=True) remaining_iterations -= 1 - print(f"~ ({remaining_iterations} remaining)") + print(f"~ ({remaining_iterations} remaining)" + " " * len(str(args.iterations)), end="\r") except KeyboardInterrupt as e: print("Interrupt") pass