Skip to content

Commit

Permalink
Move display & MIME stuff out of helpDB, xrefs (JuliaLang#22890)
Browse files Browse the repository at this point in the history
  • Loading branch information
kshyatt authored and JeffBezanson committed Jul 22, 2017
1 parent 17496a4 commit 9bb87c5
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 54 deletions.
55 changes: 1 addition & 54 deletions base/docs/helpdb/Base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -391,21 +391,6 @@ Like [`randsubseq`](@ref), but the results are stored in `S`
"""
randsubseq!

"""
redisplay(x)
redisplay(d::Display, x)
redisplay(mime, x)
redisplay(d::Display, mime, x)
By default, the `redisplay` functions simply call [`display`](@ref).
However, some display backends may override `redisplay` to modify an existing
display of `x` (if any).
Using `redisplay` is also a hint to the backend that `x` may be redisplayed
several times, and the backend may choose to defer the display until
(for example) the next interactive prompt.
"""
redisplay

"""
/(x, y)
Expand All @@ -421,26 +406,6 @@ Show every part of the representation of a value.
"""
dump

"""
display(x)
display(d::Display, x)
display(mime, x)
display(d::Display, mime, x)
Display `x` using the topmost applicable display in the display stack, typically using the
richest supported multimedia output for `x`, with plain-text [`STDOUT`](@ref) output as a fallback.
The `display(d, x)` variant attempts to display `x` on the given display `d` only, throwing
a `MethodError` if `d` cannot display objects of this type.
There are also two variants with a `mime` argument (a MIME type string, such as
`"image/png"`), which attempt to display `x` using the requested MIME type *only*, throwing
a `MethodError` if this type is not supported by either the display(s) or by `x`. With these
variants, one can also supply the "raw" data in the requested MIME type by passing
`x::AbstractString` (for MIME types with text-based storage, such as text/html or
application/postscript) or `x::Vector{UInt8}` (for binary MIME types).
"""
display

"""
tuple(xs...)
Expand Down Expand Up @@ -865,15 +830,6 @@ Seek a stream to the given position.
"""
seek

"""
popdisplay()
popdisplay(d::Display)
Pop the topmost backend off of the display-backend stack, or the topmost copy of `d` in the
second variant.
"""
popdisplay

"""
cglobal((symbol, library) [, type=Void])
Expand Down Expand Up @@ -1397,15 +1353,6 @@ In this example, `b` is a runnable `Task` that hasn't started yet.
"""
Task

"""
pushdisplay(d::Display)
Pushes a new display `d` on top of the global display-backend stack. Calling `display(x)` or
`display(mime, x)` will display `x` on the topmost compatible backend in the stack (i.e.,
the topmost backend that does not throw a `MethodError`).
"""
pushdisplay

"""
StackOverflowError()
Expand Down Expand Up @@ -1448,7 +1395,7 @@ nfields
"""
show(stream, mime, x)
The `display` functions ultimately call `show` in order to write an object `x` as a
The [`display`](@ref) functions ultimately call `show` in order to write an object `x` as a
given `mime` type to a given I/O `stream` (usually a memory buffer), if possible. In order
to provide a rich multimedia representation of a user-defined type `T`, it is only necessary
to define a new `show` method for `T`, via: `show(stream, ::MIME"mime", x::T) = ...`,
Expand Down
47 changes: 47 additions & 0 deletions base/multimedia.jl
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,26 @@ close(d::TextDisplay) = close(d.io)
# Display that is capable of displaying x (doesn't throw an error)

const displays = Display[]

"""
pushdisplay(d::Display)
Pushes a new display `d` on top of the global display-backend stack. Calling `display(x)` or
`display(mime, x)` will display `x` on the topmost compatible backend in the stack (i.e.,
the topmost backend that does not throw a [`MethodError`](@ref)).
"""
function pushdisplay(d::Display)
global displays
push!(displays, d)
end

"""
popdisplay()
popdisplay(d::Display)
Pop the topmost backend off of the display-backend stack, or the topmost copy of `d` in the
second variant.
"""
popdisplay() = pop!(displays)
function popdisplay(d::Display)
for i = length(displays):-1:1
Expand All @@ -205,6 +221,24 @@ end

xdisplayable(D::Display, args...) = applicable(display, D, args...)

"""
display(x)
display(d::Display, x)
display(mime, x)
display(d::Display, mime, x)
Display `x` using the topmost applicable display in the display stack, typically using the
richest supported multimedia output for `x`, with plain-text [`STDOUT`](@ref) output as a fallback.
The `display(d, x)` variant attempts to display `x` on the given display `d` only, throwing
a [`MethodError`](@ref) if `d` cannot display objects of this type.
There are also two variants with a `mime` argument (a MIME type string, such as
`"image/png"`), which attempt to display `x` using the requested MIME type *only*, throwing
a `MethodError` if this type is not supported by either the display(s) or by `x`. With these
variants, one can also supply the "raw" data in the requested MIME type by passing
`x::AbstractString` (for MIME types with text-based storage, such as text/html or
application/postscript) or `x::Vector{UInt8}` (for binary MIME types).
"""
function display(x)
for i = length(displays):-1:1
if xdisplayable(displays[i], x)
Expand Down Expand Up @@ -251,6 +285,19 @@ end
# for Matlab/Pylab-like stateful plotting interfaces, where
# a plot is created and then modified many times (xlabel, title, etc.).

"""
redisplay(x)
redisplay(d::Display, x)
redisplay(mime, x)
redisplay(d::Display, mime, x)
By default, the `redisplay` functions simply call [`display`](@ref).
However, some display backends may override `redisplay` to modify an existing
display of `x` (if any).
Using `redisplay` is also a hint to the backend that `x` may be redisplayed
several times, and the backend may choose to defer the display until
(for example) the next interactive prompt.
"""
function redisplay(x)
for i = length(displays):-1:1
if xdisplayable(displays[i], x)
Expand Down

0 comments on commit 9bb87c5

Please sign in to comment.