Fancy output displays
This commit is contained in:
31
autopon.py
31
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
|
||||
|
Reference in New Issue
Block a user