From 475bd7b05ccf09e0f558a5967998e874bd055e16 Mon Sep 17 00:00:00 2001 From: Matej Voboril Date: Sun, 21 Jul 2024 18:53:07 -0500 Subject: [PATCH] fix: typos, add optional wait_input --- fsociety/__main__.py | 15 +++++++-------- fsociety/console.py | 30 +++++++++++++++++------------- fsociety/core/config.py | 2 +- fsociety/core/menu.py | 8 +++----- 4 files changed, 28 insertions(+), 27 deletions(-) diff --git a/fsociety/__main__.py b/fsociety/__main__.py index d97f0af..fb70e47 100644 --- a/fsociety/__main__.py +++ b/fsociety/__main__.py @@ -100,16 +100,15 @@ def print_menu_items(): console.print(Columns(cols, equal=True, expand=True)) for key in BUILTIN_FUNCTIONS: - print() - console.command(key) + console.command(f"\n{key}") def agreement(): while not config.getboolean("fsociety", "agreement"): clear_screen() - console.warning(TERMS) - agree = input("You must agree to our terms and conditions first (Y/n) ") - if agree.lower()[0] == "y": + console.input_error(TERMS) + agree = input("You must agree to our terms and conditions first (y/N) ") + if len(agree) and agree[0].lower() == "y": config.set("fsociety", "agreement", "true") @@ -145,10 +144,10 @@ def sub_command_has(sbc): if subcommand is not None: # execute parent cli, pass subcmd.name -> cli return run_tool(subcommand["tool"], subcommand["name"]) - return console.warning("Invalid Command") + return console.input_error("Invalid Command", True) except StopIteration: # looks like we didn't find a subcommand, either - return console.warning("Invalid Command") + return console.input_error("Invalid Command", True) except Exception as error: return console.handle_error(error) if selected_command in BUILTIN_FUNCTIONS: @@ -185,7 +184,7 @@ def interactive(): set_readline(commands) mainloop() except KeyboardInterrupt: - console.print("\nExitting...") + console.print("\nExiting...") write_config(config) sys.exit(0) diff --git a/fsociety/console.py b/fsociety/console.py index 916c9c0..b4daafe 100644 --- a/fsociety/console.py +++ b/fsociety/console.py @@ -42,32 +42,36 @@ class Console(RichConsole): def __init__(self, log_level: ConsoleLogLevel = ConsoleLogLevel.ERROR): super().__init__(theme=fsociety_theme) + self.log_level = ConsoleLogLevel(log_level) - def set_log_level(self, level: ConsoleLogLevel): - self.log_level = level + def set_log_level(self, level: str): + self.log_level = ConsoleLogLevel(level) - def debug(self, message: str, error: Exception = None): + def debug(self, message: str, error: Exception = None, wait_input: bool = False): if self.log_level == ConsoleLogLevel.DEBUG: self.print(message, style="debug") if error: self.print_exception() + if wait_input: + input_wait() - def info(self, message: str): + def info(self, message: str, wait_input: bool = False): if self.log_level in [ConsoleLogLevel.DEBUG, ConsoleLogLevel.INFO]: self.print(message, style="info") + if wait_input: + input_wait() - def warning(self, message: str): - if self.log_level in [ - ConsoleLogLevel.DEBUG, - ConsoleLogLevel.INFO, - ConsoleLogLevel.WARNING, - ]: - self.print(message, style="warning") + def input_error(self, message: str, wait_input: bool = False): + self.print(message, style="warning") + if wait_input: + input_wait() - def error(self, message: str): + def error(self, message: str, wait_input: bool = False): self.print(message, style="error") if self.log_level == ConsoleLogLevel.DEBUG: self.print_exception() + if wait_input: + input_wait() def handle_error(self, error: Exception): self.error(str(error)) @@ -85,4 +89,4 @@ def command(self, message: str): default_log_level = config.get("fsociety", "log_level") -console = Console(default_log_level) +console = Console(ConsoleLogLevel(default_log_level)) diff --git a/fsociety/core/config.py b/fsociety/core/config.py index f9a4ea0..dda9dec 100644 --- a/fsociety/core/config.py +++ b/fsociety/core/config.py @@ -27,7 +27,7 @@ "os": CURRENT_PLATFORM, "host_file": "hosts.txt", "usernames_file": "usernames.txt", - "log_level": "error", + "log_level": "info", } diff --git a/fsociety/core/menu.py b/fsociety/core/menu.py index 28b5ab6..f5bcaf5 100644 --- a/fsociety/core/menu.py +++ b/fsociety/core/menu.py @@ -115,14 +115,12 @@ def tools_cli(name, tools, links=True): return if selected_tool == "exit": raise KeyboardInterrupt - console.warn("Invalid Command") + console.warn("Invalid Command", True) return tools_cli(name, tools, links) tool = tools_dict.get(selected_tool) return run_tool(tool, selected_tool) def confirm(message="Do you want to?"): - response = input(f"{message} (y/n): ").lower() - if response: - return response[0] == "y" - return False + agree = input(f"{message} (y/N): ") + return len(agree) and agree[0].lower() == "y"