Skip to content

Commit

Permalink
remove limit_output function, rename :limit_output to :limit
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson committed May 22, 2016
1 parent 80c5664 commit af69a6e
Show file tree
Hide file tree
Showing 13 changed files with 25 additions and 46 deletions.
2 changes: 1 addition & 1 deletion base/REPL.jl
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ end
function display(d::REPLDisplay, ::MIME"text/plain", x)
io = outstream(d.repl)
Base.have_color && write(io, answer_color(d.repl))
writemime(IOContext(io, multiline=true, limit_output=true), MIME("text/plain"), x)
writemime(IOContext(io, multiline=true, limit=true), MIME("text/plain"), x)
println(io)
end
display(d::REPLDisplay, x) = display(d, MIME("text/plain"), x)
Expand Down
11 changes: 2 additions & 9 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -938,15 +938,8 @@ end
@deprecate super(T::DataType) supertype(T)

function with_output_limit(thk, lim=true) # thk is usually show()
depwarn("with_output_limit is deprecated. use `io = IOContext(io, :limit_output => lim)` as a replacement", :with_output_limit)
global _limit_output
last = _limit_output
_limit_output::Bool = lim
try
thk()
finally
_limit_output = last
end
depwarn("with_output_limit is deprecated. use `io = IOContext(io, :limit => lim)` as a replacement", :with_output_limit)
thk()
end

#14555
Expand Down
4 changes: 2 additions & 2 deletions base/dict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ end

function show{K,V}(io::IO, t::Associative{K,V})
recur_io = IOContext(io, SHOWN_SET=t, multiline=false)
limit::Bool = limit_output(io)
limit::Bool = get(io, :limit, false)
compact = !get(io, :multiline, false)
if !haskey(io, :compact)
recur_io = IOContext(recur_io, compact=true)
Expand Down Expand Up @@ -156,7 +156,7 @@ function show(io::IO, iter::Union{KeyIterator,ValueIterator})
print(io, summary(iter))
isempty(iter) && return
print(io, ". ", isa(iter,KeyIterator) ? "Keys" : "Values", ":")
limit::Bool = limit_output(io)
limit::Bool = get(io, :limit, false)
if limit
sz = displaysize(io)
rows, cols = sz[1] - 3, sz[2]
Expand Down
3 changes: 1 addition & 2 deletions base/docs/helpdb/Base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2888,10 +2888,9 @@ Show an expression and result, returning the result.
"""
showcompact(x)
Show a more compact representation of a value. This is used for printing array elements. If
a new type has a different compact representation,
it should test `Base.limit_output(io)` in its normal `show` method.
it should test `get(io, :limit, false)` in its normal `show` method.
"""
showcompact

Expand Down
1 change: 0 additions & 1 deletion base/exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1144,7 +1144,6 @@ export
ismarked,
isopen,
isreadonly,
limit_output,
listen,
listenany,
ltoh,
Expand Down
2 changes: 1 addition & 1 deletion base/range.jl
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ function print_range(io::IO, r::Range,
hdots::AbstractString = ",\u2026,") # horiz ellipsis
# This function borrows from print_matrix() in show.jl
# and should be called by writemime (replutil.jl) and by display()
limit = limit_output(io)
limit = get(io, :limit, false)
sz = displaysize(io)
if !haskey(io, :compact)
io = IOContext(io, compact=true)
Expand Down
24 changes: 9 additions & 15 deletions base/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,6 @@ getindex(io::IO, key) = throw(KeyError(key))
get(io::IOContext, key, default) = get(io.dict, key, default)
get(io::IO, key, default) = default

" limit_output(io) -> Bool
Output hinting for identifying contexts where the user requested a compact output"
limit_output(::ANY) = _limit_output::Bool
limit_output(io::IOContext) = get(io, :limit_output, _limit_output::Bool) === true
_limit_output = false # delete with with_output_limit deprecation

displaysize(io::IOContext) = haskey(io, :displaysize) ? io[:displaysize] : displaysize(io.io)

show_circular(io::IO, x::ANY) = false
Expand Down Expand Up @@ -1051,7 +1045,7 @@ function dump(io::IO, x::Array, n::Int, indent)
else
if n > 0 && !isempty(x)
println(io)
if limit_output(io)
if get(io, :limit, false)
dump_elts(io, x, n, indent, 1, (length(x) <= 10 ? length(x) : 5))
if length(x) > 10
println(io)
Expand Down Expand Up @@ -1130,7 +1124,7 @@ end

# For abstract types, use _dumptype only if it's a form that will be called
# interactively.
dflt_io() = IOContext(STDOUT::IO, :limit_output => true)
dflt_io() = IOContext(STDOUT::IO, :limit => true)
dump(io::IO, x::DataType; maxdepth=8) = (x.abstract ? dumptype : dump)(io, x, maxdepth, "")
dump(x::DataType; maxdepth=8) = (x.abstract ? dumptype : dump)(dflt_io(), x, maxdepth, "")

Expand Down Expand Up @@ -1285,7 +1279,7 @@ function print_matrix(io::IO, X::AbstractVecOrMat,
vdots::AbstractString = "\u22ee",
ddots::AbstractString = " \u22f1 ",
hmod::Integer = 5, vmod::Integer = 5)
if !limit_output(io)
if !get(io, :limit, false)
screenheight = screenwidth = typemax(Int)
else
sz = displaysize(io)
Expand Down Expand Up @@ -1391,7 +1385,7 @@ summary(a::AbstractArray) =

# n-dimensional arrays
function show_nd(io::IO, a::AbstractArray, print_matrix, label_slices)
limit::Bool = limit_output(io)
limit::Bool = get(io, :limit, false)
if isempty(a)
return
end
Expand Down Expand Up @@ -1471,9 +1465,9 @@ function show(io::IO, X::AbstractArray)
if !haskey(io, :compact)
io = IOContext(io, compact=true)
end
if !repr && limit_output(io) && eltype(X) === Method
if !repr && get(io, :limit, false) && eltype(X) === Method
# override usual show method for Vector{Method}: don't abbreviate long lists
io = IOContext(io, :limit_output => false)
io = IOContext(io, :limit => false)
end
!repr && print(io, summary(X))
if !isempty(X)
Expand Down Expand Up @@ -1506,10 +1500,10 @@ end

showall(x) = showall(STDOUT, x)
function showall(io::IO, x)
if !limit_output(io)
if !get(io, :limit, false)
show(io, x)
else
show(IOContext(io, :limit_output => false), x)
show(IOContext(io, :limit => false), x)
end
end

Expand Down Expand Up @@ -1538,7 +1532,7 @@ end

function show_vector(io::IO, v, opn, cls)
compact, prefix = array_eltype_show_how(v)
limited = limit_output(io)
limited = get(io, :limit, false)
if compact && !haskey(io, :compact)
io = IOContext(io, :compact => compact)
end
Expand Down
2 changes: 1 addition & 1 deletion base/sparse/sparsematrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ function Base.show(io::IO, S::SparseMatrixCSC)
print(io, S.m, "×", S.n, " sparse matrix with ", nnz(S), " ", eltype(S), " nonzero entries:")
end

limit::Bool = Base.limit_output(io)
limit::Bool = get(io, :limit, false)
if limit
rows = displaysize(io)[1]
half_screen_rows = div(rows - 8, 2)
Expand Down
2 changes: 1 addition & 1 deletion base/sparse/sparsevector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ function show(io::IO, x::AbstractSparseVector)
println(io, summary(x))
end

limit::Bool = Base.limit_output(io)
limit::Bool = get(io, :limit, false)
half_screen_rows = limit ? div(displaysize(io)[1] - 8, 2) : typemax(Int)
pad = ndigits(n)
sep = "\n\t"
Expand Down
6 changes: 0 additions & 6 deletions doc/stdlib/io-network.rst
Original file line number Diff line number Diff line change
Expand Up @@ -655,12 +655,6 @@ Text I/O
Return the nominal size of the screen that may be used for rendering output to this io object

.. function:: limit_output(io) -> Bool

.. Docstring generated from Julia source
Output hinting for identifying contexts where the user requested a compact output

Multimedia I/O
--------------

Expand Down
10 changes: 5 additions & 5 deletions test/dict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ for d in (Dict("\n" => "\n", "1" => "\n", "\n" => "2"),
for cols in (12, 40, 80), rows in (2, 10, 24)
# Ensure output is limited as requested
s = IOBuffer()
io = Base.IOContext(s, limit_output=true, displaysize=(rows, cols), multiline=true)
io = Base.IOContext(s, limit=true, displaysize=(rows, cols), multiline=true)
Base.show(io, d)
out = split(takebuf_string(s),'\n')
for line in out[2:end]
Expand All @@ -278,7 +278,7 @@ for d in (Dict("\n" => "\n", "1" => "\n", "\n" => "2"),

for f in (keys, values)
s = IOBuffer()
io = Base.IOContext(s, limit_output=true, displaysize=(rows, cols), multiline=true)
io = Base.IOContext(s, limit=true, displaysize=(rows, cols), multiline=true)
Base.show(io, f(d))
out = split(takebuf_string(s),'\n')
for line in out[2:end]
Expand Down Expand Up @@ -311,7 +311,7 @@ end
type Alpha end
Base.show(io::IO, ::Alpha) = print(io,"α")
let sbuff = IOBuffer(),
io = Base.IOContext(sbuff, limit_output=true, displaysize=(10, 20), multiline=true)
io = Base.IOContext(sbuff, limit=true, displaysize=(10, 20), multiline=true)

Base.show(io, Dict(Alpha()=>1))
@test !contains(String(sbuff), "")
Expand Down Expand Up @@ -369,9 +369,9 @@ let
a[3] = T10647(a)
@test a == a
show(IOBuffer(), a)
Base.show(Base.IOContext(IOBuffer(), :limit_output => true), a)
Base.show(Base.IOContext(IOBuffer(), :limit => true), a)
Base.show(IOBuffer(), a)
Base.show(Base.IOContext(IOBuffer(), :limit_output => true), a)
Base.show(Base.IOContext(IOBuffer(), :limit => true), a)
end


Expand Down
2 changes: 1 addition & 1 deletion test/ranges.jl
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ end

# stringmime/writemime should display the range or linspace nicely
# to test print_range in range.jl
replstrmime(x) = sprint((io,x) -> writemime(IOContext(io, multiline=true, limit_output=true), MIME("text/plain"), x), x)
replstrmime(x) = sprint((io,x) -> writemime(IOContext(io, multiline=true, limit=true), MIME("text/plain"), x), x)
@test replstrmime(1:4) == "1:4"
@test replstrmime(linspace(1,5,7)) == "7-element LinSpace{Float64}:\n 1.0,1.66667,2.33333,3.0,3.66667,4.33333,5.0"
@test replstrmime(0:100.) == "0.0:1.0:100.0"
Expand Down
2 changes: 1 addition & 1 deletion test/show.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This file is a part of Julia. License is MIT: http://julialang.org/license

replstr(x) = sprint((io,x) -> writemime(IOContext(io, multiline=true, limit_output=true), MIME("text/plain"), x), x)
replstr(x) = sprint((io,x) -> writemime(IOContext(io, multiline=true, limit=true), MIME("text/plain"), x), x)

@test replstr(cell(2)) == "2-element Array{Any,1}:\n #undef\n #undef"
@test replstr(cell(2,2)) == "2×2 Array{Any,2}:\n #undef #undef\n #undef #undef"
Expand Down

0 comments on commit af69a6e

Please sign in to comment.