Skip to content

Commit 65d0145

Browse files
committed
Ping Julia via inputhook
1 parent 67f85d0 commit 65d0145

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

src/replhelper/entrypoints.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ def post_startup_configuration(ip):
1717
from . import ipyext
1818
ip.run_cell(dedent("""
1919
%load_ext {ipyext}
20+
%gui julia
2021
""".format(ipyext=ipyext.__name__)))
2122

2223

src/replhelper/ipyext.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,31 @@ def _julia_completer(self, event):
3535
return julia_completer(get_cached_api(), self, event)
3636

3737

38+
def julia_inputhook(context):
39+
"""
40+
Hook to be run when IPython is idle.
41+
42+
This is passed to `prompt_toolkit.PromptSession` as `inputhook` argument
43+
via `IPython`.
44+
45+
Parameters
46+
----------
47+
context : InputHookContext
48+
See: https://github.com/jonathanslenders/python-prompt-toolkit/blob/master/prompt_toolkit/eventloop/inputhook.py
49+
"""
50+
julia = get_cached_api()
51+
jl_sleep = julia.sleep
52+
while not context.input_is_ready():
53+
jl_sleep(0.05)
54+
55+
3856
def load_ipython_extension(ip):
3957
global _unregister_key_bindings
4058
_unregister_key_bindings = register_key_bindings(ip)
4159

60+
from IPython.terminal.pt_inputhooks import register
61+
register("julia", julia_inputhook)
62+
4263
ip.set_hook("complete_command", _julia_completer,
4364
re_key=r""".*\bMain\.eval\(["']""")
4465
# See:

0 commit comments

Comments
 (0)