Merge pull request #190 from clothespin/prompt-toolkit-inputhook

Registers pyplot.draw as inputhook for prompt_toolkit
This commit is contained in:
Artem Veremey
2021-03-18 18:46:53 -07:00
committed by GitHub
5 changed files with 29 additions and 5 deletions

View File

@@ -1,4 +1,7 @@
name: Mac OS X Full Clean Build with ML
env:
GTFF_USE_PROMPT_TOOLKIT: false
GTFF_USE_ION: false
on:
push:
branches:

View File

@@ -1,4 +1,7 @@
name: Tests
env:
GTFF_USE_PROMPT_TOOLKIT: false
GTFF_USE_ION: false
on: [pull_request, push]
jobs:
linting:

View File

@@ -1,4 +1,7 @@
name: Windows 10 Full Clean Build with ML
env:
GTFF_USE_PROMPT_TOOLKIT: false
GTFF_USE_ION: false
on:
push:
branches:

View File

@@ -1,12 +1,13 @@
from distutils.util import strtobool
import os
USE_COLOR = os.getenv("GTFF_USE_COLOR") or True
USE_COLOR = strtobool(os.getenv("GTFF_USE_COLOR", "True"))
USE_FLAIR = os.getenv("GTFF_USE_FLAIR") or "stars"
USE_ION = os.getenv("GTFF_USE_ION") or True
USE_PROMPT_TOOLKIT = os.getenv("GTFF_USE_PROMPT_TOOLKIT") or False
USE_ION = strtobool(os.getenv("GTFF_USE_ION", "True"))
USE_PROMPT_TOOLKIT = strtobool(os.getenv("GTFF_USE_PROMPT_TOOLKIT", "False"))
# Enable Prediction features
ENABLE_PREDICT = os.getenv("GTFF_ENABLE_PREDICT") or False
ENABLE_PREDICT = strtobool(os.getenv("GTFF_ENABLE_PREDICT", "False"))
# Enable plot autoscaling
USE_PLOT_AUTOSCALING = os.getenv("GTFF_USE_PLOT_AUTOSCALING") or False
USE_PLOT_AUTOSCALING = strtobool(os.getenv("GTFF_USE_PLOT_AUTOSCALING", "False"))

View File

@@ -1,11 +1,25 @@
import os
from matplotlib import pyplot
from prompt_toolkit import PromptSession
from prompt_toolkit.eventloop.inputhook import set_eventloop_with_inputhook
from prompt_toolkit.history import FileHistory
def inputhook(inputhook_context):
while not inputhook_context.input_is_ready():
pyplot.pause(0.1)
return False
history_file = os.path.join(os.path.expanduser("~"), ".gamestonk_terminal.his")
try:
session = PromptSession(history=FileHistory(history_file))
set_eventloop_with_inputhook(inputhook)
except Exception as e: # noqa: F841
print(
"WARNING: Prompt toolkit is turned on but did not initialize successfully. Falling back to input()..."
)
session = None