Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rename Display -> AbstractDisplay #24831

Merged
merged 2 commits into from
Nov 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,8 @@ Deprecated or removed

* The unexported type `AbstractIOBuffer` has been renamed to `GenericIOBuffer` ([#17360] [#22796]).

* `Display` has been renamed to `AbstractDisplay` ([#24831]).

* Remaining vectorized methods over `SparseVector`s, particularly `floor`, `ceil`,
`trunc`, `round`, and most common transcendental functions such as `exp`, `log`, and
`sin` variants, have been deprecated in favor of dot-syntax ([#22961]).
Expand Down
3 changes: 3 additions & 0 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2138,6 +2138,9 @@ finalizer(f::Ptr{Void}, o::Function) = invoke(finalizer, Tuple{Ptr{Void}, Any},
Base.@deprecate_binding broadcast_t broadcast false ", broadcast_t(f, ::Type{ElType}, shape, iter, As...)` should become `broadcast(f, Broadcast.DefaultArrayStyle{N}(), ElType, shape, As...))` (see the manual chapter Interfaces)"
end

# issue #24822
@deprecate_binding Display AbstractDisplay

# issue #24794
@deprecate linspace(start, stop) linspace(start, stop, 50)
@deprecate logspace(start, stop) logspace(start, stop, 50)
Expand Down
2 changes: 1 addition & 1 deletion base/exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1054,7 +1054,7 @@ export
UDPSocket,

# multimedia I/O
Display,
AbstractDisplay,
display,
displayable,
TextDisplay,
Expand Down
2 changes: 1 addition & 1 deletion base/markdown/render/rich.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function tohtml(m::MIME"image/svg+xml", img)
show(io, m, img)
end

# Display infrastructure
# AbstractDisplay infrastructure

function bestmime(val)
for mime in ("text/html", "image/svg+xml", "image/png", "text/plain")
Expand Down
58 changes: 29 additions & 29 deletions base/multimedia.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module Multimedia

export Display, display, pushdisplay, popdisplay, displayable, redisplay,
export AbstractDisplay, display, pushdisplay, popdisplay, displayable, redisplay,
MIME, @MIME_str, reprmime, stringmime, istextmime,
mimewritable, TextDisplay

Expand Down Expand Up @@ -58,7 +58,7 @@ literal strings; to construct `MIME` types in a more flexible manner use

For example, if you define a `MyImage` type and know how to write it to a PNG file, you
could define a function `show(stream, ::MIME"image/png", x::MyImage) = ...` to allow
your images to be displayed on any PNG-capable `Display` (such as IJulia). As usual, be sure
your images to be displayed on any PNG-capable `AbstractDisplay` (such as IJulia). As usual, be sure
to `import Base.show` in order to add new methods to the built-in Julia function
`show`.

Expand Down Expand Up @@ -158,43 +158,43 @@ for mime in ["application/atom+xml", "application/ecmascript",
end

###########################################################################
# We have an abstract Display class that can be subclassed in order to
# We have an abstract AbstractDisplay class that can be subclassed in order to
# define new rich-display output devices. A typical subclass should
# overload display(d::Display, m::MIME, x) for supported MIME types m,
# overload display(d::AbstractDisplay, m::MIME, x) for supported MIME types m,
# (typically using reprmime or stringmime to get the MIME
# representation of x) and should also overload display(d::Display, x)
# to display x in whatever MIME type is preferred by the Display and
# representation of x) and should also overload display(d::AbstractDisplay, x)
# to display x in whatever MIME type is preferred by the AbstractDisplay and
# is writable by x. display(..., x) should throw a MethodError if x
# cannot be displayed. The return value of display(...) is up to the
# Display type.
# AbstractDisplay type.

abstract type Display end
abstract type AbstractDisplay end

# it is convenient to accept strings instead of ::MIME
display(d::Display, mime::AbstractString, x) = display(d, MIME(mime), x)
display(d::AbstractDisplay, mime::AbstractString, x) = display(d, MIME(mime), x)
display(mime::AbstractString, x) = display(MIME(mime), x)

"""
displayable(mime) -> Bool
displayable(d::Display, mime) -> Bool
displayable(d::AbstractDisplay, mime) -> Bool

Returns a boolean value indicating whether the given `mime` type (string) is displayable by
any of the displays in the current display stack, or specifically by the display `d` in the
second variant.
"""
displayable(d::Display, mime::AbstractString) = displayable(d, MIME(mime))
displayable(d::AbstractDisplay, mime::AbstractString) = displayable(d, MIME(mime))
displayable(mime::AbstractString) = displayable(MIME(mime))

# simplest display, which only knows how to display text/plain

"""
TextDisplay(io::IO)

Returns a `TextDisplay <: Display`, which displays any object as the text/plain MIME type
Returns a `TextDisplay <: AbstractDisplay`, which displays any object as the text/plain MIME type
(by default), writing the text representation to the given I/O stream. (This is how
objects are printed in the Julia REPL.)
"""
struct TextDisplay <: Display
struct TextDisplay <: AbstractDisplay
io::IO
end
display(d::TextDisplay, M::MIME"text/plain", x) = show(d.io, M, x)
Expand All @@ -213,31 +213,31 @@ close(d::TextDisplay) = close(d.io)

###########################################################################
# We keep a stack of Displays, and calling display(x) uses the topmost
# Display that is capable of displaying x (doesn't throw an error)
# AbstractDisplay that is capable of displaying x (doesn't throw an error)

const displays = Display[]
const displays = AbstractDisplay[]

"""
pushdisplay(d::Display)
pushdisplay(d::AbstractDisplay)

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)
function pushdisplay(d::AbstractDisplay)
global displays
push!(displays, d)
end

"""
popdisplay()
popdisplay(d::Display)
popdisplay(d::AbstractDisplay)

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)
function popdisplay(d::AbstractDisplay)
for i = length(displays):-1:1
if d == displays[i]
return splice!(displays, i)
Expand All @@ -250,15 +250,15 @@ function reinit_displays()
pushdisplay(TextDisplay(STDOUT))
end

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

"""
display(x)
display(d::Display, x)
display(d::AbstractDisplay, x)
display(mime, x)
display(d::Display, mime, x)
display(d::AbstractDisplay, mime, x)

Display `x` using the topmost applicable display in the display stack, typically using the
AbstractDisplay `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.
Expand Down Expand Up @@ -304,7 +304,7 @@ function display(m::MIME, x)
throw(MethodError(display, (m, x)))
end

displayable(d::D, ::MIME{mime}) where {D<:Display,mime} =
displayable(d::D, ::MIME{mime}) where {D<:AbstractDisplay,mime} =
method_exists(display, Tuple{D,MIME{mime},Any})

function displayable(m::MIME)
Expand All @@ -315,7 +315,7 @@ function displayable(m::MIME)
end

###########################################################################
# The redisplay method can be overridden by a Display in order to
# The redisplay method can be overridden by a AbstractDisplay in order to
# update an existing display (instead of, for example, opening a new
# window), and is used by the IJulia interface to defer display
# until the next interactive prompt. This is especially useful
Expand All @@ -324,9 +324,9 @@ end

"""
redisplay(x)
redisplay(d::Display, x)
redisplay(d::AbstractDisplay, x)
redisplay(mime, x)
redisplay(d::Display, mime, x)
redisplay(d::AbstractDisplay, mime, x)

By default, the `redisplay` functions simply call [`display`](@ref).
However, some display backends may override `redisplay` to modify an existing
Expand Down Expand Up @@ -364,8 +364,8 @@ function redisplay(m::Union{MIME,AbstractString}, x)
end

# default redisplay is simply to call display
redisplay(d::Display, x) = display(d, x)
redisplay(d::Display, m::Union{MIME,AbstractString}, x) = display(d, m, x)
redisplay(d::AbstractDisplay, x) = display(d, x)
redisplay(d::AbstractDisplay, m::Union{MIME,AbstractString}, x) = display(d, m, x)

###########################################################################

Expand Down
4 changes: 2 additions & 2 deletions base/precompile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ precompile(Tuple{typeof(Base._rsearchindex), Array{Int8, 1}, Array{UInt8, 1}, In
precompile(Tuple{typeof(Base._rsearch), Array{Int8, 1}, Array{UInt8, 1}, Int64})
precompile(Tuple{typeof(Base.rsearch), Array{UInt8, 1}, Char, Int64})
precompile(Tuple{typeof(Base.rsearch), Array{Int8, 1}, Char, Int64})
precompile(Tuple{typeof(Base.splice!), Array{Base.Multimedia.Display, 1}, Int64, Array{Any, 1}})
precompile(Tuple{typeof(Base.splice!), Array{Base.Multimedia.AbstractDisplay, 1}, Int64, Array{Any, 1}})
precompile(Tuple{typeof(Core.Inference.isbits), Base.LineEdit.EmptyCompletionProvider})
precompile(Tuple{typeof(Core.Inference.isbits), Base.LineEdit.EmptyHistoryProvider})
precompile(Tuple{typeof(Base._setindex!), Base.Dict{Symbol, Any}, Base.LineEdit.Prompt, Symbol, Int64})
Expand Down Expand Up @@ -341,7 +341,7 @@ precompile(Tuple{typeof(Base.LineEdit.setup_prefix_keymap), Base.REPL.REPLHistor
precompile(Tuple{typeof(Base.getindex), Type{Base.Dict{Any, Any}}, Base.Dict{Any, Any}, Base.Dict{Any, Any}, Base.Dict{Any, Any}, Base.Dict{Any, Any}, Base.Dict{Any, Any}, Base.Dict{Any, Any}})
precompile(Tuple{typeof(Base.prepend!), Array{Base.Dict{Any, Any}, 1}, Array{Base.Dict{Any, Any}, 1}})
precompile(Tuple{typeof(Base.REPL.mode_keymap), Base.LineEdit.Prompt})
precompile(Tuple{typeof(Core.Inference.isbits), Array{Base.Multimedia.Display, 1}})
precompile(Tuple{typeof(Core.Inference.isbits), Array{Base.Multimedia.AbstractDisplay, 1}})
precompile(Tuple{typeof(Base.Multimedia.popdisplay), Base.REPL.REPLDisplay{Base.REPL.LineEditREPL}})
precompile(Tuple{Type{String}, Base.BitArray{1}})
precompile(Tuple{typeof(Base.REPL.ends_with_semicolon), String})
Expand Down
6 changes: 3 additions & 3 deletions base/repl/REPL.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export
StreamREPL

import Base:
Display,
AbstractDisplay,
display,
show,
AnyDict,
Expand Down Expand Up @@ -113,7 +113,7 @@ function ip_matches_func(ip, func::Symbol)
return false
end

struct REPLDisplay{R<:AbstractREPL} <: Display
struct REPLDisplay{R<:AbstractREPL} <: AbstractDisplay
repl::R
end

Expand Down Expand Up @@ -271,7 +271,7 @@ mutable struct LineEditREPL <: AbstractREPL
in_help::Bool
envcolors::Bool
waserror::Bool
specialdisplay::Union{Void,Display}
specialdisplay::Union{Void,AbstractDisplay}
options::Options
interface::ModalInterface
backendref::REPLBackendRef
Expand Down
4 changes: 2 additions & 2 deletions doc/src/stdlib/io-network.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ output (such as images, formatted text, or even audio and video), consisting of
`x` (with a plain-text fallback).
* Overloading [`show`](@ref) allows one to indicate arbitrary multimedia representations (keyed by standard
MIME types) of user-defined types.
* Multimedia-capable display backends may be registered by subclassing a generic `Display` type
* Multimedia-capable display backends may be registered by subclassing a generic `AbstractDisplay` type
and pushing them onto a stack of display backends via [`pushdisplay`](@ref).

The base Julia runtime provides only plain-text display, but richer displays may be enabled by
Expand All @@ -111,7 +111,7 @@ PNG images in a window can register this capability with Julia, so that calling
types with PNG representations will automatically display the image using the module's window.

In order to define a new display backend, one should first create a subtype `D` of the abstract
class `Display`. Then, for each MIME type (`mime` string) that can be displayed on `D`, one should
class `AbstractDisplay`. Then, for each MIME type (`mime` string) that can be displayed on `D`, one should
define a function `display(d::D, ::MIME"mime", x) = ...` that displays `x` as that MIME type,
usually by calling [`reprmime(mime, x)`](@ref). A `MethodError` should be thrown if `x` cannot be displayed
as that MIME type; this is automatic if one calls [`reprmime`](@ref). Finally, one should define a function
Expand Down