Skip to content

Commit 9a982cc

Browse files
authored
replicate REPL pkg mode for cells starting with ] (JuliaLang#715)
1 parent 6bde68f commit 9a982cc

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

src/execute_request.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
# returning results.
44

55
import Base.Libc: flush_cstdio
6+
if VERSION v"0.7"
7+
import Pkg
8+
end
69

710
const text_plain = MIME("text/plain")
811
const 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

src/init.jl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,20 @@ function qtconsole()
5151
end
5252
end
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+
5468
function 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)

0 commit comments

Comments
 (0)