Skip to content

Commit 4f67be1

Browse files
committed
Have display(::InlineDisplay, ...) methods use display_data()
1 parent 89f4443 commit 4f67be1

File tree

1 file changed

+12
-21
lines changed

1 file changed

+12
-21
lines changed

src/inline.jl

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -149,17 +149,15 @@ function limitstringmime(mime::MIME, x)
149149
return String(take!(buf))
150150
end
151151

152-
for mime in ipy_mime
152+
for mimestr in ipy_mime
153+
M = MIME{Symbol(mimestr)}
153154
@eval begin
154-
function display(d::InlineDisplay, ::MIME{Symbol($mime)}, x)
155-
flush_all() # so that previous stream output appears in order
156-
send_ipython(publish[],
157-
msg_pub(execute_msg, "display_data",
158-
Dict(
159-
"metadata" => metadata(x), # optional
160-
"data" => Dict($mime => limitstringmime(MIME($mime), x)))))
155+
function display(d::InlineDisplay, ::$M, x)
156+
s = limitstringmime($M(), x)
157+
m = get(metadata(x), $mimestr, Dict())
158+
display_data($M(), s, m)
161159
end
162-
displayable(d::InlineDisplay, ::MIME{Symbol($mime)}) = true
160+
displayable(d::InlineDisplay, ::$M) = true
163161
end
164162
end
165163

@@ -172,28 +170,21 @@ display(d::InlineDisplay, m::MIME"text/javascript", x) = display(d, MIME("applic
172170
# If the user explicitly calls display("foo/bar", x), we send
173171
# the display message, also sending text/plain for text data.
174172
displayable(d::InlineDisplay, M::MIME) = istextmime(M)
173+
175174
function display(d::InlineDisplay, M::MIME, x)
176175
sx = limitstringmime(M, x)
177-
d = Dict(string(M) => sx)
176+
bundle = Dict(string(M) => sx)
178177
if istextmime(M)
179-
d["text/plain"] = sx # directly show text data, e.g. text/csv
178+
bundle["text/plain"] = sx # directly show text data, e.g. text/csv
180179
end
181-
flush_all() # so that previous stream output appears in order
182-
send_ipython(publish[],
183-
msg_pub(execute_msg, "display_data",
184-
Dict("metadata" => metadata(x), # optional
185-
"data" => d)))
180+
display_data(bundle, metadata(x))
186181
end
187182

188183
# override display to send IPython a dictionary of all supported
189184
# output types, so that IPython can choose what to display.
190185
function display(d::InlineDisplay, x)
191186
undisplay(x) # dequeue previous redisplay(x)
192-
flush_all() # so that previous stream output appears in order
193-
send_ipython(publish[],
194-
msg_pub(execute_msg, "display_data",
195-
Dict("metadata" => metadata(x), # optional
196-
"data" => display_dict(x))))
187+
display_data(display_dict(x), metadata(x))
197188
end
198189

199190
# we overload redisplay(d, x) to add x to a queue of objects to display,

0 commit comments

Comments
 (0)