From 7cae5a449ec706d846a9b652c72274d6e70d6736 Mon Sep 17 00:00:00 2001 From: Jasur Sadikov Date: Sun, 3 Nov 2024 16:06:41 +0100 Subject: [PATCH] Resolves #58 - Configure is now interruptable --- src/mud/__about__.py | 1 - src/mud/app.py | 8 ++------ src/mud/commands.py | 3 +-- src/mud/utils.py | 48 ++++++++++++++++---------------------------- 4 files changed, 20 insertions(+), 40 deletions(-) delete mode 100644 src/mud/__about__.py diff --git a/src/mud/__about__.py b/src/mud/__about__.py deleted file mode 100644 index 7863915..0000000 --- a/src/mud/__about__.py +++ /dev/null @@ -1 +0,0 @@ -__version__ = "1.0.2" diff --git a/src/mud/app.py b/src/mud/app.py index e8f9b36..74908e2 100644 --- a/src/mud/app.py +++ b/src/mud/app.py @@ -54,14 +54,14 @@ def _create_parser() -> ArgumentParser: parser.add_argument(*DIVERGED_ATTR, action='store_true', help='Filters repositories with diverged branches.') parser.add_argument(*ASYNC_ATTR, action='store_true', help='Switches asynchronous run feature.') parser.add_argument(SET_GLOBAL[0], help=f'Sets {BOLD}.mudconfig{RESET} in the current repository as your fallback {BOLD}.mudconfig{RESET}.', action='store_true') - parser.add_argument(VERSION[0], help='Displays the current version of mud.', action='store_true') parser.add_argument('catch_all', nargs='*', help='Type any commands to execute among repositories.') return parser def run(self) -> None: # Displays default help message if len(sys.argv) == 1 or sys.argv[1] in HELP: - utils.version() + utils.info() + print() self.parser.print_help() return # Sets global repository in .mudsettings @@ -72,10 +72,6 @@ def run(self) -> None: utils.settings.save() print(f'Current {BOLD}.mudconfig{RESET} set as a global configuration.') return - # Prints version - elif sys.argv[1] in VERSION: - utils.version() - return # Runs configuration wizard elif sys.argv[1] in CONFIGURE: utils.configure() diff --git a/src/mud/commands.py b/src/mud/commands.py index 55b52e6..4dafcdb 100644 --- a/src/mud/commands.py +++ b/src/mud/commands.py @@ -10,11 +10,10 @@ BRANCHES = ['branch', 'branches', 'br'] REMOTE_BRANCHES = ['remote-branch', 'remote-branches', 'rbr'] HELP = ['help', '--help', '-h'] -VERSION = ['--version', '-v', 'version'] CONFIGURE = ['configure', 'config'] SET_GLOBAL = ['--set-global'] -COMMANDS = [ADD, REMOVE, LOG, INFO, INIT, TAGS, LABELS, STATUS, BRANCHES, REMOTE_BRANCHES, HELP, VERSION, CONFIGURE, SET_GLOBAL] +COMMANDS = [ADD, REMOVE, LOG, INFO, INIT, TAGS, LABELS, STATUS, BRANCHES, REMOTE_BRANCHES, HELP, CONFIGURE, SET_GLOBAL] # Filters ASYNC_ATTR = '-a', '--async' diff --git a/src/mud/utils.py b/src/mud/utils.py index 807eab9..fe5357b 100644 --- a/src/mud/utils.py +++ b/src/mud/utils.py @@ -8,7 +8,6 @@ from mud.settings import * from mud.styles import * -from mud.__about__ import __version__ SETTINGS_FILE_NAME = '.mudsettings' CONFIG_FILE_NAME = '.mudconfig' @@ -20,25 +19,18 @@ def glyphs(key: str) -> str: return GLYPHS[key][0 if settings.config['mud'].getboolean('nerd_fonts', fallback=False) else 1] -def version() -> None: +def info() -> None: os.chdir(os.path.dirname(os.path.abspath(__file__))) - logo = get_logo() - info = f'Jasur Sadikov \nhttps://github.com/jasursadikov/mud\n{BOLD}{random.choice(TEXT[3:])}{__version__}{RESET}' - print(logo) - print(info) - - -def get_logo() -> str: colors = TEXT[3:] colors.remove(BRIGHT_WHITE) m = random.choice(colors) u = random.choice(colors) d = random.choice(colors) - logo = f' {d}__{RESET}\n' - logo += f' {m}__ _ {u}__ __{d}___/ /{RESET}\n' - logo += f' {m}/ \' \\{u}/ // / {d}_ /{RESET}\n' - logo += f'{m}/_/_/_/{u}\\_,_/{d}\\_,_/ {RESET}' - return logo + print(f' {d}__{RESET}') + print(f' {m}__ _ {u}__ __{d}___/ /{RESET}') + print(f' {m}/ \' \\{u}/ // / {d}_ /{RESET}') + print(f'{m}/_/_/_/{u}\\_,_/{d}\\_,_/ {RESET}') + print(f'Jasur Sadikov \nhttps://github.com/jasursadikov/mud') def configure() -> None: @@ -56,23 +48,17 @@ def configure() -> None: def ask(text: str) -> bool: - print(f'{text} [Y/n] ', end='', flush=True) - if sys.platform.startswith('win'): - from msvcrt import getch - response = getch().decode().lower() - else: - import tty - import termios - fd = sys.stdin.fileno() - old_settings = termios.tcgetattr(fd) - try: - tty.setraw(fd) - response = sys.stdin.read(1).lower() - finally: - termios.tcsetattr(fd, termios.TCSADRAIN, old_settings) - - print() - return response in ['y', '\r', '\n'] + try: + answer = input(f"{text}? [Y/n]: ").strip().lower() + if answer in ('y', 'yes', ''): + return True + elif answer in ('n', 'no'): + return False + else: + print("Invalid input.") + return True + except KeyboardInterrupt: + exit() def print_table(table: PrettyTable) -> None: