Skip to content

Commit 98d49ab

Browse files
authored
Merge pull request #17113 from JuliaLang/jn/show-multiline
remove io :multiline attribute
2 parents 528a363 + 256a296 commit 98d49ab

19 files changed

+250
-236
lines changed

base/Enums.jl

+11-12
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,14 @@ macro enum(T,syms...)
8585
let insts = ntuple(i->$(esc(typename))($values[i]), $(length(vals)))
8686
Base.instances(::Type{$(esc(typename))}) = insts
8787
end
88-
function Base.print(io::IO,x::$(esc(typename)))
88+
function Base.print(io::IO, x::$(esc(typename)))
8989
for (sym, i) in $vals
9090
if i == Int32(x)
9191
print(io, sym); break
9292
end
9393
end
9494
end
95-
function Base.show(io::IO,x::$(esc(typename)))
95+
function Base.show(io::IO, x::$(esc(typename)))
9696
if get(io, :compact, false)
9797
print(io, x)
9898
else
@@ -101,16 +101,15 @@ macro enum(T,syms...)
101101
print(io, " = ", Int(x))
102102
end
103103
end
104-
function Base.show(io::IO,t::Type{$(esc(typename))})
105-
if get(io, :multiline, false)
106-
print(io, "Enum ")
107-
Base.show_datatype(io, t)
108-
print(io, ":")
109-
for (sym, i) in $vals
110-
print(io, "\n", sym, " = ", i)
111-
end
112-
else
113-
Base.show_datatype(io, t)
104+
function Base.show(io::IO, t::Type{$(esc(typename))})
105+
Base.show_datatype(io, t)
106+
end
107+
function Base.show(io::IO, ::MIME"text/plain", t::Type{$(esc(typename))})
108+
print(io, "Enum ")
109+
Base.show_datatype(io, t)
110+
print(io, ":")
111+
for (sym, i) in $vals
112+
print(io, "\n", sym, " = ", i)
114113
end
115114
end
116115
end

base/REPL.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,10 @@ end
108108

109109
==(a::REPLDisplay, b::REPLDisplay) = a.repl === b.repl
110110

111-
function display(d::REPLDisplay, ::MIME"text/plain", x)
111+
function display(d::REPLDisplay, mime::MIME"text/plain", x)
112112
io = outstream(d.repl)
113113
Base.have_color && write(io, answer_color(d.repl))
114-
show(IOContext(io, multiline=true, limit=true), MIME("text/plain"), x)
114+
show(IOContext(io, :limit => true), mime, x)
115115
println(io)
116116
end
117117
display(d::REPLDisplay, x) = display(d, MIME("text/plain"), x)

base/deprecated.jl

+13
Original file line numberDiff line numberDiff line change
@@ -788,6 +788,19 @@ function symperm{Tv,Ti}(A::SparseMatrixCSC{Tv,Ti}, pinv::Vector{Ti})
788788
"Pkg.add(\"SuiteSparse\") to install SuiteSparse on Julia v0.5."))
789789
end
790790

791+
# needs to be a macro so that we can use ::@mime(s) in type declarations
792+
eval(Multimedia, quote
793+
export @MIME
794+
macro MIME(s)
795+
Base.warn_once("@MIME(\"\") is deprecated, use MIME\"\" instead.")
796+
if isa(s,AbstractString)
797+
:(MIME{$(Expr(:quote, Symbol(s)))})
798+
else
799+
:(MIME{Symbol($s)})
800+
end
801+
end
802+
end)
803+
791804
# During the 0.5 development cycle, do not add any deprecations below this line
792805
# To be deprecated in 0.6
793806

base/dict.jl

+22-110
Original file line numberDiff line numberDiff line change
@@ -49,91 +49,34 @@ function _truncate_at_width_or_chars(str, width, chars="", truncmark="…")
4949
end
5050

5151
function show{K,V}(io::IO, t::Associative{K,V})
52-
recur_io = IOContext(io, SHOWN_SET=t, multiline=false)
52+
recur_io = IOContext(io, :SHOWN_SET => t)
5353
limit::Bool = get(io, :limit, false)
54-
compact = !get(io, :multiline, false)
5554
if !haskey(io, :compact)
56-
recur_io = IOContext(recur_io, compact=true)
55+
recur_io = IOContext(recur_io, :compact => true)
5756
end
58-
if compact
59-
# show in a Julia-syntax-like form: Dict(k=>v, ...)
60-
if isempty(t)
61-
print(io, typeof(t), "()")
62-
else
63-
if isleaftype(K) && isleaftype(V)
64-
print(io, typeof(t).name)
65-
else
66-
print(io, typeof(t))
67-
end
68-
print(io, '(')
69-
if !show_circular(io, t)
70-
first = true
71-
n = 0
72-
for pair in t
73-
first || print(io, ',')
74-
first = false
75-
show(recur_io, pair)
76-
n+=1
77-
limit && n >= 10 && (print(io, ""); break)
78-
end
79-
end
80-
print(io, ')')
81-
end
82-
return
83-
end
84-
85-
# Otherwise show more descriptively, with one line per key/value pair
86-
print(io, summary(t))
87-
isempty(t) && return
88-
print(io, ":\n ")
89-
show_circular(io, t) && return
90-
if limit
91-
sz = displaysize(io)
92-
rows, cols = sz[1] - 3, sz[2]
93-
rows < 2 && (print(io, ""); return)
94-
cols < 12 && (cols = 12) # Minimum widths of 2 for key, 4 for value
95-
cols -= 6 # Subtract the widths of prefix " " separator " => "
96-
rows -= 2 # Subtract the summary and final ⋮ continuation lines
97-
98-
# determine max key width to align the output, caching the strings
99-
ks = Array{AbstractString}(min(rows, length(t)))
100-
vs = Array{AbstractString}(min(rows, length(t)))
101-
keylen = 0
102-
vallen = 0
103-
for (i, (k, v)) in enumerate(t)
104-
i > rows && break
105-
ks[i] = sprint(0, show, k, env=recur_io)
106-
vs[i] = sprint(0, show, v, env=recur_io)
107-
keylen = clamp(length(ks[i]), keylen, cols)
108-
vallen = clamp(length(vs[i]), vallen, cols)
109-
end
110-
if keylen > max(div(cols, 2), cols - vallen)
111-
keylen = max(cld(cols, 3), cols - vallen)
112-
end
113-
else
114-
rows = cols = 0
115-
end
116-
117-
first = true
118-
for (i, (k, v)) in enumerate(t)
119-
first || print(io, "\n ")
120-
first = false
121-
limit && i > rows && (print(io, rpad("", keylen), " => ⋮"); break)
12257

123-
if limit
124-
key = rpad(_truncate_at_width_or_chars(ks[i], keylen, "\r\n"), keylen)
58+
# show in a Julia-syntax-like form: Dict(k=>v, ...)
59+
if isempty(t)
60+
print(io, typeof(t), "()")
61+
else
62+
if isleaftype(K) && isleaftype(V)
63+
print(io, typeof(t).name)
12564
else
126-
key = sprint(0, show, k, env=recur_io)
65+
print(io, typeof(t))
12766
end
128-
print(recur_io, key)
129-
print(io, " => ")
130-
131-
if limit
132-
val = _truncate_at_width_or_chars(vs[i], cols - keylen, "\r\n")
133-
print(io, val)
134-
else
135-
show(recur_io, v)
67+
print(io, '(')
68+
if !show_circular(io, t)
69+
first = true
70+
n = 0
71+
for pair in t
72+
first || print(io, ',')
73+
first = false
74+
show(recur_io, pair)
75+
n+=1
76+
limit && n >= 10 && (print(io, ""); break)
77+
end
13678
end
79+
print(io, ')')
13780
end
13881
end
13982

@@ -147,38 +90,7 @@ end
14790
summary{T<:Union{KeyIterator,ValueIterator}}(iter::T) =
14891
string(T.name, " for a ", summary(iter.dict))
14992

150-
function show(io::IO, iter::Union{KeyIterator,ValueIterator})
151-
if !get(io, :multiline, false)
152-
return show(io, collect(iter))
153-
end
154-
print(io, summary(iter))
155-
isempty(iter) && return
156-
print(io, ". ", isa(iter,KeyIterator) ? "Keys" : "Values", ":")
157-
limit::Bool = get(io, :limit, false)
158-
if limit
159-
sz = displaysize(io)
160-
rows, cols = sz[1] - 3, sz[2]
161-
rows < 2 && (print(io, ""); return)
162-
cols < 4 && (cols = 4)
163-
cols -= 2 # For prefix " "
164-
rows -= 2 # For summary and final ⋮ continuation lines
165-
else
166-
rows = cols = 0
167-
end
168-
169-
for (i, v) in enumerate(iter)
170-
print(io, "\n ")
171-
limit && i >= rows && (print(io, ""); break)
172-
173-
if limit
174-
str = sprint(0, show, v, env=io)
175-
str = _truncate_at_width_or_chars(str, cols, "\r\n")
176-
print(io, str)
177-
else
178-
show(io, v)
179-
end
180-
end
181-
end
93+
show(io::IO, iter::Union{KeyIterator,ValueIterator}) = show(io, collect(iter))
18294

18395
length(v::Union{KeyIterator,ValueIterator}) = length(v.dict)
18496
isempty(v::Union{KeyIterator,ValueIterator}) = isempty(v.dict)

base/linalg/bidiag.jl

+6-9
Original file line numberDiff line numberDiff line change
@@ -168,15 +168,12 @@ svdfact(M::Bidiagonal; thin::Bool=true) = svdfact!(copy(M),thin=thin)
168168
####################
169169

170170
function show(io::IO, M::Bidiagonal)
171-
if get(io, :multiline, false)
172-
Base.showarray(io, M)
173-
else
174-
println(io, summary(M), ":")
175-
print(io, " diag:")
176-
print_matrix(io, (M.dv)')
177-
print(io, M.isupper?"\n super:":"\n sub:")
178-
print_matrix(io, (M.ev)')
179-
end
171+
# TODO: make this readable and one-line
172+
println(io, summary(M), ":")
173+
print(io, " diag:")
174+
print_matrix(io, (M.dv)')
175+
print(io, M.isupper?"\n super:":"\n sub:")
176+
print_matrix(io, (M.ev)')
180177
end
181178

182179
size(M::Bidiagonal) = (length(M.dv), length(M.dv))

base/multimedia.jl

+1-11
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
module Multimedia
44

55
export Display, display, pushdisplay, popdisplay, displayable, redisplay,
6-
MIME, @MIME, @MIME_str, reprmime, stringmime, istextmime,
6+
MIME, @MIME_str, reprmime, stringmime, istextmime,
77
mimewritable, TextDisplay
88

99
###########################################################################
@@ -18,16 +18,6 @@ MIME(s) = MIME{Symbol(s)}()
1818
show{mime}(io::IO, ::MIME{mime}) = print(io, "MIME type ", string(mime))
1919
print{mime}(io::IO, ::MIME{mime}) = print(io, mime)
2020

21-
# needs to be a macro so that we can use ::@mime(s) in type declarations
22-
macro MIME(s)
23-
Base.warn_once("@MIME(\"\") is deprecated, use MIME\"\" instead.")
24-
if isa(s,AbstractString)
25-
:(MIME{$(Expr(:quote, Symbol(s)))})
26-
else
27-
:(MIME{Symbol($s)})
28-
end
29-
end
30-
3121
macro MIME_str(s)
3222
:(MIME{$(Expr(:quote, Symbol(s)))})
3323
end

base/range.jl

+8-22
Original file line numberDiff line numberDiff line change
@@ -236,25 +236,13 @@ linspace(start::Real, stop::Real, len::Real=50) =
236236
linspace(promote(AbstractFloat(start), AbstractFloat(stop))..., len)
237237

238238
function show(io::IO, r::LinSpace)
239-
if get(io, :multiline, false)
240-
# show for linspace, e.g.
241-
# linspace(1,3,7)
242-
# 7-element LinSpace{Float64}:
243-
# 1.0,1.33333,1.66667,2.0,2.33333,2.66667,3.0
244-
print(io, summary(r))
245-
if !isempty(r)
246-
println(io, ":")
247-
print_range(io, r)
248-
end
249-
else
250-
print(io, "linspace(")
251-
show(io, first(r))
252-
print(io, ',')
253-
show(io, last(r))
254-
print(io, ',')
255-
show(io, length(r))
256-
print(io, ')')
257-
end
239+
print(io, "linspace(")
240+
show(io, first(r))
241+
print(io, ',')
242+
show(io, last(r))
243+
print(io, ',')
244+
show(io, length(r))
245+
print(io, ')')
258246
end
259247

260248
"""
@@ -497,9 +485,7 @@ function getindex{T}(r::LinSpace{T}, s::OrdinalRange)
497485
return linspace(vfirst, vlast, sl)
498486
end
499487

500-
function show(io::IO, r::Range)
501-
print(io, repr(first(r)), ':', repr(step(r)), ':', repr(last(r)))
502-
end
488+
show(io::IO, r::Range) = print(io, repr(first(r)), ':', repr(step(r)), ':', repr(last(r)))
503489
show(io::IO, r::UnitRange) = print(io, repr(first(r)), ':', repr(last(r)))
504490

505491
=={T<:Range}(r::T, s::T) = (first(r) == first(s)) & (step(r) == step(s)) & (last(r) == last(s))

0 commit comments

Comments
 (0)