File tree Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change 33# returning results.
44
55import Base. Libc: flush_cstdio
6+ if VERSION ≥ v " 0.7"
7+ import Pkg
8+ end
69
710const text_plain = MIME (" text/plain" )
811const image_svg = MIME (" image/svg+xml" )
@@ -164,6 +167,14 @@ function execute_request(socket, msg)
164167 m -> string (replace (m, r" ^\s *;" => " Base.repl_cmd(`" ),
165168 " `, " , stdout_name, " )" ))
166169
170+ if VERSION ≥ v " 0.7"
171+ # "] ..." cells are interpreted as pkg shell commands
172+ if occursin (r" ^\] .*$" , code)
173+ code = " IJulia.Pkg.REPLMode.do_cmd(IJulia.minirepl[], \" " *
174+ escape_string (code[2 : end ]) * " \" ; do_rethrow=true)"
175+ end
176+ end
177+
167178 # a cell beginning with "? ..." is interpreted as a help request
168179 hcode = replace (code, r" ^\s *\? " => " " )
169180
Original file line number Diff line number Diff line change @@ -51,6 +51,20 @@ function qtconsole()
5151 end
5252end
5353
54+ # similar to Pkg.REPLMode.MiniREPL, a minimal REPL-like emulator
55+ # for use with Pkg.do_cmd. We have to roll our own to
56+ # make sure it uses the redirected stdout, and because
57+ # we don't have terminal support.
58+ if VERSION ≥ v " 0.7"
59+ import REPL
60+ struct MiniREPL <: REPL.AbstractREPL
61+ display:: TextDisplay
62+ end
63+ REPL. REPLDisplay (repl:: MiniREPL ) = repl. display
64+ const minirepl = Ref {MiniREPL} ()
65+ end
66+
67+
5468function init (args)
5569 inited && error (" IJulia is already running" )
5670 if length (args) > 0
@@ -118,6 +132,9 @@ function init(args)
118132 redirect_stderr (IJuliaStdio (stderr ," stderr" ))
119133 end
120134 redirect_stdin (IJuliaStdio (stdin ," stdin" ))
135+ if VERSION ≥ v " 0.7"
136+ minirepl[] = MiniREPL (TextDisplay (stdout ))
137+ end
121138
122139 if isdefined (Base, :CoreLogging )
123140 logger = Base. CoreLogging. SimpleLogger (Base. stderr )
You can’t perform that action at this time.
0 commit comments