🎨 Cleaner getch

This commit is contained in:
2021-04-11 03:00:48 +03:00
parent 2ca9bb8d53
commit 293bc42b82

43
main.py
View File

@@ -11,8 +11,24 @@ from print_logo import print_logo
if platform.system() == 'Windows': if platform.system() == 'Windows':
import msvcrt import msvcrt
def uni_getch():
char = str(msvcrt.getch())
if char == "b'y'":
return True
elif char == "b'n'":
return False
else:
return None
else: else:
from getch import getch from getch import getch
def uni_getch():
char = getch()
if char == "y":
return True
elif char == "n":
return False
else:
return None
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument('-i', '--input', action='store', type=str, parser.add_argument('-i', '--input', action='store', type=str,
@@ -50,26 +66,15 @@ else:
curr_channel += 1 curr_channel += 1
c.print(f'[dim][{curr_channel}/{len(all_channels)}]:[/dim] {ch["title"]} [cyan]\[y/n]') c.print(f'[dim][{curr_channel}/{len(all_channels)}]:[/dim] {ch["title"]} [cyan]\[y/n]')
while True: while True:
if platform.system() == 'Windows': key = uni_getch()
key = str(msvcrt.getch()) if key == True:
if key == "b'y'": ch['download'] = True
ch['download'] = True break
break elif key == False:
elif key == "b'n'": ch['download'] = False
ch['download'] = False break
break
else:
c.print('Press "y" or "n"', style='yellow')
else: else:
key = getch() c.print('Press "y" or "n"', style='yellow')
if key == "y":
ch['download'] = True
break
elif key == "n":
ch['download'] = False
break
else:
c.print('Press "y" or "n"', style='yellow')
c.print('All done! 🎉') c.print('All done! 🎉')
c.print('Saving to download_list.json...', style='italic') c.print('Saving to download_list.json...', style='italic')