Merge pull request #142 from ricleal/tests_with_prompt_toolkit

Better terminal with autocompletion + history
This commit is contained in:
Artem Veremey
2021-03-10 13:41:29 -08:00
committed by GitHub
7 changed files with 64 additions and 43 deletions

View File

@@ -12,6 +12,9 @@ from gamestonk_terminal.discovery import unusual_whales_api
from gamestonk_terminal.helper_funcs import get_flair
from gamestonk_terminal.menu import session
from prompt_toolkit.completion import WordCompleter
def print_discovery():
""" Print help """
@@ -44,34 +47,36 @@ def disc_menu():
# Add list of arguments that the discovery parser accepts
disc_parser = argparse.ArgumentParser(prog="discovery", add_help=False)
disc_parser.add_argument(
"cmd",
choices=[
"help",
"q",
"quit",
"map",
"sectors",
"gainers",
"spacs",
"orders",
"ark_orders",
"spachero",
"high_short",
"low_float",
"up_earnings",
"simply_wallst",
"uwhales",
"mill",
],
)
choices = [
"help",
"q",
"quit",
"map",
"sectors",
"gainers",
"spacs",
"orders",
"ark_orders",
"spachero",
"high_short",
"low_float",
"up_earnings",
"simply_wallst",
"uwhales",
"mill",
]
disc_parser.add_argument("cmd", choices=choices)
word_completer = WordCompleter(choices)
print_discovery()
# Loop forever and ever
while True:
# Get input command from user
as_input = input(f"{get_flair()} (disc)> ")
as_input = session.prompt(
f"{get_flair()} (disc)> ",
completer=word_completer,
)
# Parse fundamental analysis command of the list of possible commands
try:

View File

@@ -0,0 +1,7 @@
import os
from prompt_toolkit import PromptSession
from prompt_toolkit.history import FileHistory
history_file = os.path.join(os.path.expanduser("~"), ".gamestonk_terminal.his")
session = PromptSession(history=FileHistory(history_file))

View File

@@ -156,3 +156,4 @@ wrapt==1.12.1; python_version >= "3.6" and python_full_version < "3.0.0" or pyth
yarl==1.6.3; python_version >= "3.6"
yfinance==0.1.55
zipp==3.4.1; python_version < "3.8" and python_version >= "3.6"
prompt-toolkit==3.0.16; python_version >= "3.6"

View File

@@ -133,3 +133,4 @@ wrapt==1.12.1; python_version >= "3.6" and python_full_version < "3.0.0" or pyth
yarl==1.6.3; python_version >= "3.6"
yfinance==0.1.55
zipp==3.4.0; python_version >= "3.6" and python_full_version < "3.0.0" and python_version < "3.8" or python_full_version >= "3.2.0" and python_version >= "3.6" and python_version < "3.8"
prompt-toolkit==3.0.16; python_version >= "3.6"

View File

@@ -133,3 +133,4 @@ wrapt==1.12.1; python_version >= "3.6" and python_full_version < "3.0.0" or pyth
yarl==1.6.3; python_version >= "3.6"
yfinance==0.1.55
zipp==3.4.0; python_version >= "3.6" and python_full_version < "3.0.0" and python_version < "3.8" or python_full_version >= "3.2.0" and python_version >= "3.6" and python_version < "3.8"
prompt-toolkit==3.0.16; python_version >= "3.6"

View File

@@ -90,3 +90,4 @@ websocket-client==0.58.0; python_version >= "3.6" and python_full_version < "3.0
yarl==1.6.3; python_version >= "3.6"
yfinance==0.1.55
zipp==3.4.1; python_version < "3.8" and python_version >= "3.6"
prompt-toolkit==3.0.16; python_version >= "3.6"

View File

@@ -15,6 +15,9 @@ from gamestonk_terminal.sentiment import sen_menu as sm
from gamestonk_terminal.papermill import papermill_menu as mill
from gamestonk_terminal import res_menu as rm
from gamestonk_terminal import config_terminal as cfg
from gamestonk_terminal.menu import session
from prompt_toolkit.completion import WordCompleter
# import warnings
# warnings.simplefilter("always")
@@ -42,26 +45,25 @@ def main():
# Add list of arguments that the main parser accepts
menu_parser = argparse.ArgumentParser(prog="gamestonk_terminal", add_help=False)
menu_parser.add_argument(
"opt",
choices=[
"help",
"quit",
"q",
"clear",
"load",
"view",
"export",
"disc",
"mill",
"sen",
"res",
"fa",
"ta",
"dd",
"pred",
],
)
choices = [
"help",
"quit",
"q",
"clear",
"load",
"view",
"export",
"disc",
"mill",
"sen",
"res",
"fa",
"ta",
"dd",
"pred",
]
menu_parser.add_argument("opt", choices=choices)
word_completer = WordCompleter(choices)
# Print first welcome message and help
print("")
@@ -77,7 +79,10 @@ def main():
should_print_help = False
# Get input command from user
as_input = input(f"{get_flair()}> ")
as_input = session.prompt(
f"{get_flair()}> ",
completer=word_completer,
)
# Is command empty
if not as_input: