Skip to content

Commit

Permalink
Require prompt-toolkit 3.0.41 (#451)
Browse files Browse the repository at this point in the history
randy3k authored Nov 28, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 306158f commit 18dbf62
Showing 3 changed files with 37 additions and 35 deletions.
6 changes: 4 additions & 2 deletions radian/lineedit/prompt.py
Original file line number Diff line number Diff line change
@@ -49,6 +49,7 @@ class ModalPromptSession(PromptSession):
_current_mode = None
_default_settings = {}
_specs = OrderedDict()
_inputhook = None

# new settings
add_history = True
@@ -66,7 +67,8 @@ def _filter_args(self, kwargs):
setattr(self, key, kwargs[key])
del kwargs[key]

def __init__(self, *args, **kwargs):
def __init__(self, inputhook=None, *args, **kwargs):
self._inputhook = inputhook
self._check_args(kwargs)
self._filter_args(kwargs)
super().__init__(*args, **kwargs)
@@ -223,7 +225,7 @@ def prompt(self, *args, **kwargs):

orig_mode = self.current_mode
try:
result = super().prompt(**kwargs)
result = super().prompt(inputhook=self._inputhook, **kwargs)
except KeyboardInterrupt:
self._default_settings = backup.copy()
self.activate_mode(orig_mode, force=True)
64 changes: 32 additions & 32 deletions radian/prompt_session.py
Original file line number Diff line number Diff line change
@@ -13,7 +13,6 @@
from prompt_toolkit.utils import is_windows, get_term_environment_variable
from prompt_toolkit.validation import Validator
from prompt_toolkit.auto_suggest import AutoSuggestFromHistory
from prompt_toolkit.eventloop.inputhook import set_eventloop_with_inputhook

from pygments.styles import get_style_by_name

@@ -150,6 +149,36 @@ def message():
else:
editing_mode = EditingMode.EMACS

def get_inputhook():
# make testing more robust
if "RADIAN_NO_INPUTHOOK" in os.environ:
return None

terminal_width = [None]

def _(context):
output_width = session.app.output.get_size().columns
if output_width and terminal_width[0] != output_width:
terminal_width[0] = output_width
setoption("width", max(terminal_width[0], 20))

while True:
if context.input_is_ready():
break
try:
if peek_event():
with session.app.input.detach():
with session.app.input.rare_mode():
process_events()
else:
polled_events()

except Exception:
pass
time.sleep(1.0 / 30)

return _

session = RadianPromptSession(
message=message,
style=style_from_pygments_cls(get_style_by_name(settings.color_scheme)),
@@ -161,7 +190,8 @@ def message():
enable_suspend=True,
input=CustomInput(sys.stdin),
output=output,
auto_suggest=AutoSuggestFromHistory() if settings.auto_suggest else None
auto_suggest=AutoSuggestFromHistory() if settings.auto_suggest else None,
inputhook=get_inputhook()
)

input_processors = []
@@ -254,36 +284,6 @@ def shell_process_text(session):
input_processors=[]
)

def get_inputhook():
terminal_width = [None]

def _(context):
output_width = session.app.output.get_size().columns
if output_width and terminal_width[0] != output_width:
terminal_width[0] = output_width
setoption("width", max(terminal_width[0], 20))

while True:
if context.input_is_ready():
break
try:
if peek_event():
with session.app.input.detach():
with session.app.input.rare_mode():
process_events()
else:
polled_events()

except Exception:
pass
time.sleep(1.0 / 30)

return _

# make testing more robust
if "RADIAN_NO_INPUTHOOK" not in os.environ:
set_eventloop_with_inputhook(get_inputhook())

apply_settings(session, settings)

return session
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -44,7 +44,7 @@ def get_version(package):
install_requires=[
# 'rchitect@git+https://github.com/randy3k/rchitect',
'rchitect>=0.4.3,<0.5.0',
'prompt_toolkit>=3.0.15,<3.1',
'prompt_toolkit>=3.0.41,<3.1',
'pygments>=2.5.0'
],
entry_points={

0 comments on commit 18dbf62

Please sign in to comment.