forked from shashi/escher-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrepl.jl
68 lines (60 loc) · 1.39 KB
/
repl.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
using Markdown
# Function that executes code and
# returns the result
execute_code(code) = begin
try
parse("begin\n" * code * "\nend") |> eval
catch ex
sprint() do io
showerror(io, ex)
println(io)
Base.show_backtrace(io, catch_backtrace())
end
end
end
## View
# Code mirror to input some code
showinput(code;kwargs...) = begin
s = sampler()
@show kwargs
codemirror(code; kwargs...) |>
watch!(s) |>
keypress("ctrl+enter") |>
trigger!(s) |>
plugsampler(s)
end
getcode(x) = x[:code]
code_io(code, code_input; kwargs...) = begin
addinterpreter(getcode, showinput(code; name=:code, kwargs...)) >>> code_input
end
# Output area
showoutput(code) = begin
obj = try
execute_code(code)
catch ex
sprint() do io
showerror(io, ex)
println(io)
Base.show_backtrace(io, catch_backtrace())
end
end
try
convert(Tile, obj)
catch codemirror(string(obj), readonly=true, linenumbers=false)
end
end
# REPL
newrepl() = vbox(empty)
function append_execution(repl, code)
cell_sig = Input(code)
println(cell_sig)
vbox(
vcat(
repl.tiles.tiles,
vbox(
code_io(code, cell_sig, linenumbers=false, name=:code),
lift(showoutput, cell_sig)
)
)
)
end