Added forever loop and way to quit
This commit is contained in:
@@ -31,11 +31,13 @@ class SteamGamePathTool:
|
|||||||
console.print(Columns(game_rend))
|
console.print(Columns(game_rend))
|
||||||
|
|
||||||
self.prompter = PromptHelper(games)
|
self.prompter = PromptHelper(games)
|
||||||
|
while True:
|
||||||
self.prompt_user()
|
self.prompt_user()
|
||||||
|
input("Press Enter to continue...")
|
||||||
|
|
||||||
|
|
||||||
def prompt_user(self):
|
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:
|
if game is None:
|
||||||
return
|
return
|
||||||
console = Console()
|
console = Console()
|
||||||
|
|||||||
+8
-2
@@ -1,5 +1,6 @@
|
|||||||
import prompt_toolkit as pt
|
import prompt_toolkit as pt
|
||||||
from prompt_toolkit.completion import WordCompleter, FuzzyCompleter
|
from prompt_toolkit.completion import WordCompleter, FuzzyCompleter
|
||||||
|
import sys
|
||||||
|
|
||||||
def generate_completer(game_list):
|
def generate_completer(game_list):
|
||||||
g_list = [x['name'] for x in game_list] + [x['appid'] for x in 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:
|
for game in self.game_list:
|
||||||
if game['name'] == game_name:
|
if game['name'] == game_name:
|
||||||
return game
|
return game
|
||||||
def find_game_num(self, appid: int):
|
def find_game_num(self, appid: str):
|
||||||
for game in self.game_list:
|
for game in self.game_list:
|
||||||
if game['appid'] == appid:
|
if game['appid'] == appid:
|
||||||
return game
|
return game
|
||||||
|
print("Game not found")
|
||||||
|
return None
|
||||||
|
|
||||||
def prompt_game(self, text, default="None"):
|
def prompt_game(self, text, default="None"):
|
||||||
response = pt.prompt(text, completer=self.completer, complete_while_typing=True)
|
response = pt.prompt(text, completer=self.completer, complete_while_typing=True)
|
||||||
if response == "":
|
if response == "":
|
||||||
return None
|
return None
|
||||||
|
elif response == "q" or response == "quit":
|
||||||
|
print("Goodbye!")
|
||||||
|
sys.exit(0)
|
||||||
elif response[0].isalpha():
|
elif response[0].isalpha():
|
||||||
return self.find_game_str(response)
|
return self.find_game_str(response)
|
||||||
else:
|
else:
|
||||||
return self.find_game_num(int(response))
|
return self.find_game_num(response)
|
||||||
|
|||||||
Reference in New Issue
Block a user