Skip to content

Commit be3897b

Browse files
committed
Use Base.run_main_repl
1 parent cbe0537 commit be3897b

File tree

1 file changed

+16
-23
lines changed

1 file changed

+16
-23
lines changed

pysrc/juliacall/__main__.py

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,20 @@
1-
from juliacall import Main
1+
import os
2+
os.environ.setdefault("PYTHON_JULIACALL_HANDLE_SIGNALS", "yes")
3+
if os.environ.get("PYTHON_JULIACALL_HANDLE_SIGNALS") != "yes":
4+
print("Experimental JuliaCall REPL requires PYTHON_JULIACALL_HANDLE_SIGNALS=yes")
5+
exit(1)
26

3-
RED = "\033[1;31m"
4-
GREEN = "\033[1;32m"
5-
RESET = "\033[0m"
7+
from juliacall import Main
68

7-
import os
8-
path_to_banner = os.path.join(os.path.dirname(__file__), "banner.jl")
9-
Main.seval(f"include(\"{path_to_banner}\"); banner()")
9+
Main.seval(f"""\
10+
Base.is_interactive = true
1011
11-
while True:
12-
try:
13-
line = input(f"{GREEN}juliacall> {RESET}")
14-
except KeyboardInterrupt:
15-
print("\n")
16-
continue
17-
except EOFError:
18-
break
19-
if sline := line.strip():
20-
try:
21-
result = Main.seval(sline)
22-
if result is not None:
23-
Main.display(result)
24-
except Exception as e:
25-
print(f"{RED}ERROR:{RESET} {e}")
26-
print()
12+
include(\"{os.path.join(os.path.dirname(__file__), 'banner.jl')}\")
13+
banner()
2714
15+
if VERSION > v"v1.11.0-alpha1"
16+
Base.run_main_repl(true, false, :no, true, true)
17+
else # interactive, quiet, banner, history_file, color_set
18+
Base.run_main_repl(true, false, false, true, true)
19+
end
20+
""")

0 commit comments

Comments
 (0)