From dd536a5fc4651e5061c413a86692351ed6fa20d5 Mon Sep 17 00:00:00 2001 From: LunaChocken Date: Sat, 7 Jun 2025 16:54:30 +0100 Subject: [PATCH] Added forever loop and way to quit --- main.py | 10 ++++++---- prompt_helper.py | 10 ++++++++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/main.py b/main.py index 3279fec..c66ca59 100644 --- a/main.py +++ b/main.py @@ -31,16 +31,18 @@ class SteamGamePathTool: console.print(Columns(game_rend)) self.prompter = PromptHelper(games) - self.prompt_user() - + while True: + self.prompt_user() + input("Press Enter to continue...") + def prompt_user(self): - game = self.prompter.prompt_game(text="Enter a game (name | appid) to search for: ") + game = self.prompter.prompt_game(text="Input (game name | appid | q/quit): ") if game is None: return console = Console() console.print(Panel(self.get_game_content(game), expand=True)) - + def sort_games(self, games): return sorted(games, key=lambda x: x['name']) diff --git a/prompt_helper.py b/prompt_helper.py index 9edbe29..eec0055 100644 --- a/prompt_helper.py +++ b/prompt_helper.py @@ -1,5 +1,6 @@ import prompt_toolkit as pt from prompt_toolkit.completion import WordCompleter, FuzzyCompleter +import sys def generate_completer(game_list): g_list = [x['name'] for x in game_list] + [x['appid'] for x in game_list] @@ -14,16 +15,21 @@ class PromptHelper: for game in self.game_list: if game['name'] == game_name: return game - def find_game_num(self, appid: int): + def find_game_num(self, appid: str): for game in self.game_list: if game['appid'] == appid: return game + print("Game not found") + return None def prompt_game(self, text, default="None"): response = pt.prompt(text, completer=self.completer, complete_while_typing=True) if response == "": return None + elif response == "q" or response == "quit": + print("Goodbye!") + sys.exit(0) elif response[0].isalpha(): return self.find_game_str(response) else: - return self.find_game_num(int(response)) + return self.find_game_num(response)