diff --git a/base/Terminals.jl b/base/Terminals.jl index 1499c38ce6ef8..384671f065946 100644 --- a/base/Terminals.jl +++ b/base/Terminals.jl @@ -29,7 +29,7 @@ import Base: flush, read, readuntil, - size, + iosize, start_reading, stop_reading, write, @@ -43,7 +43,7 @@ import Base: abstract TextTerminal <: Base.IO # INTERFACE -size(::TextTerminal) = error("Unimplemented") +iosize(::TextTerminal) = error("Unimplemented") writepos(t::TextTerminal, x, y, s::Array{UInt8,1}) = error("Unimplemented") cmove(t::TextTerminal, x, y) = error("Unimplemented") getX(t::TextTerminal) = error("Unimplemented") @@ -88,8 +88,8 @@ function writepos(t::TextTerminal, x, y, args...) cmove(t, x, y) write(t, args...) end -width(t::TextTerminal) = size(t)[2] -height(t::TextTerminal) = size(t)[1] +width(t::TextTerminal) = iosize(t)[2] +height(t::TextTerminal) = iosize(t)[1] # For terminals with buffers flush(t::TextTerminal) = nothing @@ -131,14 +131,10 @@ cmove_line_up(t::UnixTerminal, n) = (cmove_up(t, n); cmove_col(t, 0)) cmove_line_down(t::UnixTerminal, n) = (cmove_down(t, n); cmove_col(t, 0)) cmove_col(t::UnixTerminal, n) = write(t.out_stream, "$(CSI)$(n)G") -@windows_only begin - ispty(s::Base.TTY) = s.ispty - ispty(s) = false -end @windows ? begin function raw!(t::TTYTerminal,raw::Bool) check_open(t.in_stream) - if ispty(t.in_stream) + if Base.ispty(t.in_stream) run(if raw `stty raw -echo onlcr -ocrnl opost` else @@ -162,26 +158,8 @@ disable_bracketed_paste(t::UnixTerminal) = write(t.out_stream, "$(CSI)?2004l") end_keypad_transmit_mode(t::UnixTerminal) = # tput rmkx write(t.out_stream, "$(CSI)?1l\x1b>") -let s = zeros(Int32, 2) - function Base.size(t::TTYTerminal) - @windows_only if ispty(t.out_stream) - try - h,w = map(x->parse(Int,x),split(readall(open(`stty size`, "r", t.out_stream)[1]))) - w > 0 || (w = 80) - h > 0 || (h = 24) - return h,w - catch - return 24,80 - end - end - Base.uv_error("size (TTY)", ccall(:uv_tty_get_winsize, - Int32, (Ptr{Void}, Ptr{Int32}, Ptr{Int32}), - t.out_stream.handle, pointer(s,1), pointer(s,2)) != 0) - w,h = s[1],s[2] - w > 0 || (w = 80) - h > 0 || (h = 24) - (Int(h),Int(w)) - end +function Base.iosize(t::UnixTerminal) + return iosize(t.out_stream) end clear(t::UnixTerminal) = write(t.out_stream, "\x1b[H\x1b[2J") diff --git a/base/deprecated.jl b/base/deprecated.jl index 0187842fb38f1..c55a14c14ac6a 100644 --- a/base/deprecated.jl +++ b/base/deprecated.jl @@ -904,3 +904,17 @@ end export isreadable, iswritable, isexecutable @deprecate RemoteRef RemoteChannel + +function tty_size() + depwarn("tty_size is deprecated. use `iosize(io)` as a replacement", :tty_size) + if isdefined(Base, :active_repl) + os = REPL.outstream(Base.active_repl) + if isa(os, Terminals.TTYTerminal) + return iosize(os) + end + end + if isdefined(Base, :STDOUT) + return iosize(STDOUT) + end + return iosize() +end diff --git a/base/dict.jl b/base/dict.jl index 09c0bb96a6b5c..2f4c16cdbd261 100644 --- a/base/dict.jl +++ b/base/dict.jl @@ -61,8 +61,7 @@ function _truncate_at_width_or_chars(str, width, chars="", truncmark="…") end showdict(t::Associative; kw...) = showdict(STDOUT, t; kw...) -function showdict{K,V}(io::IO, t::Associative{K,V}; compact = false, - sz=(s = tty_size(); (s[1]-3, s[2]))) +function showdict{K,V}(io::IO, t::Associative{K,V}; compact = false) (:SHOWN_SET => t) in io && (print(io, "#= circular reference =#"); return) recur_io = IOContext(io, :SHOWN_SET => t) @@ -95,11 +94,12 @@ function showdict{K,V}(io::IO, t::Associative{K,V}; compact = false, end # Otherwise show more descriptively, with one line per key/value pair - rows, cols = sz print(io, summary(t)) isempty(t) && return print(io, ":") if limit + sz = iosize(io) + rows, cols = sz[1] - 3, sz[2] rows < 2 && (print(io, " …"); return) cols < 12 && (cols = 12) # Minimum widths of 2 for key, 4 for value cols -= 6 # Subtract the widths of prefix " " separator " => " @@ -113,6 +113,8 @@ function showdict{K,V}(io::IO, t::Associative{K,V}; compact = false, ks[i] = sprint(0, show, k, env=recur_io) keylen = clamp(length(ks[i]), keylen, div(cols, 3)) end + else + rows = cols = 0 end for (i, (k, v)) in enumerate(t) @@ -149,19 +151,21 @@ summary{T<:Union{KeyIterator,ValueIterator}}(iter::T) = show(io::IO, iter::Union{KeyIterator,ValueIterator}) = show(io, collect(iter)) -showkv(iter::Union{KeyIterator,ValueIterator}; kw...) = showkv(STDOUT, iter; kw...) -function showkv{T<:Union{KeyIterator,ValueIterator}}(io::IO, iter::T; - sz=(s = tty_size(); (s[1]-3, s[2]))) - limit::Bool = limit_output(io) - rows, cols = sz +showkv(iter::Union{KeyIterator,ValueIterator}) = showkv(STDOUT, iter) +function showkv{T<:Union{KeyIterator,ValueIterator}}(io::IO, iter::T) print(io, summary(iter)) isempty(iter) && return print(io, ". ", T<:KeyIterator ? "Keys" : "Values", ":") + limit::Bool = limit_output(io) if limit + sz = iosize(io) + rows, cols = sz[1] - 3, sz[2] rows < 2 && (print(io, " …"); return) cols < 4 && (cols = 4) cols -= 2 # For prefix " " rows -= 2 # For summary and final ⋮ continuation lines + else + rows = cols = 0 end for (i, v) in enumerate(iter) diff --git a/base/docs/helpdb/Profile.jl b/base/docs/helpdb/Profile.jl index 48c2938ed148a..a3a25705d71e7 100644 --- a/base/docs/helpdb/Profile.jl +++ b/base/docs/helpdb/Profile.jl @@ -3,18 +3,17 @@ # Base.Profile """ - print([io::IO = STDOUT,] [data::Vector]; format = :tree, C = false, combine = true, cols = tty_cols()) + print([io::IO = STDOUT,] [data::Vector]; format = :tree, C = false, combine = true) Prints profiling results to `io` (by default, `STDOUT`). If you do not supply a `data` vector, the internal buffer of accumulated backtraces will be used. `format` can be `:tree` or `:flat`. If `C==true`, backtraces from C and Fortran code are shown. `combine==true` -merges instruction pointers that correspond to the same line of code. `cols` controls the -width of the display. +merges instruction pointers that correspond to the same line of code. """ Profile.print(io::IO = STDOUT, data::Vector=?) """ - print([io::IO = STDOUT,] data::Vector, lidict::Dict; format = :tree, combine = true, cols = tty_cols()) + print([io::IO = STDOUT,] data::Vector, lidict::Dict; format = :tree, combine = true) Prints profiling results to `io`. This variant is used to examine results exported by a previous call to [`retrieve`](:func:`retrieve`). Supply the vector `data` of backtraces and diff --git a/base/docs/utils.jl b/base/docs/utils.jl index ed2a3cefac730..6880153db2507 100644 --- a/base/docs/utils.jl +++ b/base/docs/utils.jl @@ -94,7 +94,7 @@ end function repl_search(io::IO, s) pre = "search:" print(io, pre) - printmatches(io, s, completions(s), cols=Base.tty_size()[2]-length(pre)) + printmatches(io, s, completions(s), cols = iosize(io)[2] - length(pre)) println(io, "\n") end @@ -243,7 +243,7 @@ end printmatch(args...) = printfuzzy(STDOUT, args...) -function printmatches(io::IO, word, matches; cols = Base.tty_size()[2]) +function printmatches(io::IO, word, matches; cols = iosize(io)[2]) total = 0 for match in matches total + length(match) + 1 > cols && break @@ -254,9 +254,9 @@ function printmatches(io::IO, word, matches; cols = Base.tty_size()[2]) end end -printmatches(args...; cols = Base.tty_size()[2]) = printmatches(STDOUT, args..., cols = cols) +printmatches(args...; cols = iosize(STDOUT)[2]) = printmatches(STDOUT, args..., cols = cols) -function print_joined_cols(io::IO, ss, delim = "", last = delim; cols = Base.tty_size()[2]) +function print_joined_cols(io::IO, ss, delim = "", last = delim; cols = iosize(io)[2]) i = 0 total = 0 for i = 1:length(ss) @@ -266,13 +266,13 @@ function print_joined_cols(io::IO, ss, delim = "", last = delim; cols = Base.tty print_joined(io, ss[1:i], delim, last) end -print_joined_cols(args...; cols = Base.tty_size()[2]) = print_joined_cols(STDOUT, args...; cols=cols) +print_joined_cols(args...; cols = iosize(STDOUT)[2]) = print_joined_cols(STDOUT, args...; cols=cols) function print_correction(io, word) cors = levsort(word, accessible(current_module())) pre = "Perhaps you meant " print(io, pre) - print_joined_cols(io, cors, ", ", " or "; cols = Base.tty_size()[2]-length(pre)) + print_joined_cols(io, cors, ", ", " or "; cols = iosize(io)[2] - length(pre)) println(io) return end diff --git a/base/env.jl b/base/env.jl index f6f12e80dd0ac..0cf7922660eaf 100644 --- a/base/env.jl +++ b/base/env.jl @@ -165,16 +165,3 @@ function withenv{T<:AbstractString}(f::Function, keyvals::Pair{T}...) end end withenv(f::Function) = f() # handle empty keyvals case; see #10853 - -## misc environment-related functionality ## - -function tty_size() - if isdefined(Base, :active_repl) - os = REPL.outstream(Base.active_repl) - if isa(os, Terminals.TTYTerminal) - return size(os) - end - end - return (parse(Int,get(ENV,"LINES","24")), - parse(Int,get(ENV,"COLUMNS","80"))) -end diff --git a/base/exports.jl b/base/exports.jl index e05c856bd9a3f..88ae15e7f755b 100644 --- a/base/exports.jl +++ b/base/exports.jl @@ -1145,9 +1145,12 @@ export getsockname, htol, hton, + IOContext, + iosize, ismarked, isopen, isreadonly, + limit_output, listen, listenany, ltoh, diff --git a/base/interactiveutil.jl b/base/interactiveutil.jl index b71d8df66e801..aff24694ad3ac 100644 --- a/base/interactiveutil.jl +++ b/base/interactiveutil.jl @@ -430,7 +430,7 @@ Print information about exported global variables in a module, optionally restri The memory consumption estimate is an approximate lower bound on the size of the internal structure of the object. """ function whos(io::IO=STDOUT, m::Module=current_module(), pattern::Regex=r"") - maxline = tty_size()[2] + maxline = iosize(io)[2] line = zeros(UInt8, maxline) head = PipeBuffer(maxline + 1) for v in sort!(names(m)) diff --git a/base/markdown/render/terminal/render.jl b/base/markdown/render/terminal/render.jl index 00420ba6a7c23..2f1c495a6ce14 100644 --- a/base/markdown/render/terminal/render.jl +++ b/base/markdown/render/terminal/render.jl @@ -3,7 +3,7 @@ include("formatting.jl") const margin = 2 -cols() = Base.tty_size()[2] +cols(io) = iosize(io)[2] function term(io::IO, content::Vector, cols) isempty(content) && return @@ -14,7 +14,7 @@ function term(io::IO, content::Vector, cols) term(io, content[end], cols) end -term(io::IO, md::MD, columns = cols()) = term(io, md.content, columns) +term(io::IO, md::MD, columns = cols(io)) = term(io, md.content, columns) function term(io::IO, md::Paragraph, columns) print(io, " "^margin) diff --git a/base/pkg/entry.jl b/base/pkg/entry.jl index be2c729fd1b2c..43af5350a6bb7 100644 --- a/base/pkg/entry.jl +++ b/base/pkg/entry.jl @@ -490,7 +490,7 @@ function resolve( end function warnbanner(msg...; label="[ WARNING ]", prefix="") - cols = Base.tty_size()[2] + cols = Base.iosize(STDERR)[2] warn(prefix="", Base.cpad(label,cols,"=")) println(STDERR) warn(prefix=prefix, msg...) diff --git a/base/profile.jl b/base/profile.jl index caaf8be021617..878a58f4f39f9 100644 --- a/base/profile.jl +++ b/base/profile.jl @@ -47,7 +47,13 @@ end clear() = ccall(:jl_profile_clear_data, Void, ()) -function print{T<:Unsigned}(io::IO, data::Vector{T} = fetch(), lidict::Dict = getdict(data); format = :tree, C = false, combine = true, cols = Base.tty_size()[2], maxdepth::Int = typemax(Int), sortedby::Symbol = :filefuncline) +function print{T<:Unsigned}(io::IO, data::Vector{T} = fetch(), lidict::Dict = getdict(data); + format = :tree, + C = false, + combine = true, + maxdepth::Int = typemax(Int), + sortedby::Symbol = :filefuncline) + cols = Base.iosize(io)[2] if format == :tree tree(io, data, lidict, C, combine, cols, maxdepth) elseif format == :flat diff --git a/base/range.jl b/base/range.jl index 396f5d9a307cb..c28aa8c42c714 100644 --- a/base/range.jl +++ b/base/range.jl @@ -253,20 +253,21 @@ It figures out the width in characters of each element, and if they end up too wide, it shows the first and last elements separated by a horizontal elipsis. Typical output will look like `1.0,2.0,3.0,…,4.0,5.0,6.0`. -`print_range(io, r, sz, pre, sep, post, hdots)` uses optional -parameters `sz` for the (rows,cols) of the screen, -`pre` and `post` characters for each printed row, `sep` separator string between -printed elements, `hdots` string for the horizontal ellipsis. +`print_range(io, r, pre, sep, post, hdots)` uses optional +parameters `pre` and `post` characters for each printed row, +`sep` separator string between printed elements, +`hdots` string for the horizontal ellipsis. """ function print_range(io::IO, r::Range, - sz::Tuple{Integer, Integer} = (s = tty_size(); (s[1]-4, s[2])), pre::AbstractString = " ", sep::AbstractString = ",", post::AbstractString = "", 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() - screenheight, screenwidth = sz + limit = limit_output(io) + sz = iosize(io) + screenheight, screenwidth = sz[1] - 4, sz[2] screenwidth -= length(pre) + length(post) postsp = "" sepsize = length(sep) diff --git a/base/show.jl b/base/show.jl index d76ec6d688b59..7a59b6e7c313d 100644 --- a/base/show.jl +++ b/base/show.jl @@ -61,7 +61,13 @@ 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::IO) = get(io, :limit_output, false) === true +" limit_output(io) -> Bool +Output hinting for identifying contexts where the user requested a compact output" +limit_output(::ANY) = false +limit_output(io::IOContext) = get(io, :limit_output, false) === true + +iosize(io::IOContext) = haskey(io, :iosize) ? io[:iosize] : iosize(io.io) + show(io::IO, x::ANY) = show_default(io, x) function show_default(io::IO, x::ANY) @@ -1177,7 +1183,6 @@ Also options to use different ellipsis characters hdots, vdots, ddots. These are repeated every hmod or vmod elements. """ function print_matrix(io::IO, X::AbstractVecOrMat, - sz::Tuple{Integer, Integer} = (s = tty_size(); (s[1]-4, s[2])), pre::AbstractString = " ", # pre-matrix string sep::AbstractString = " ", # separator between elements post::AbstractString = "", # post-matrix string @@ -1185,7 +1190,12 @@ function print_matrix(io::IO, X::AbstractVecOrMat, vdots::AbstractString = "\u22ee", ddots::AbstractString = " \u22f1 ", hmod::Integer = 5, vmod::Integer = 5) - screenheight, screenwidth = sz + if !limit_output(io) + screenheight = screenwidth = typemax(Int) + else + sz = iosize(io) + screenheight, screenwidth = sz[1] - 4, sz[2] + end screenwidth -= length(pre) + length(post) presp = repeat(" ", length(pre)) # indent each row to match pre string postsp = "" @@ -1285,7 +1295,8 @@ summary(a::AbstractArray) = string(dims2string(size(a)), " ", typeof(a)) # n-dimensional arrays -function show_nd(io::IO, a::AbstractArray, limit, print_matrix, label_slices) +function show_nd(io::IO, a::AbstractArray, print_matrix, label_slices) + limit::Bool = limit_output(io) if isempty(a) return end @@ -1357,12 +1368,8 @@ end # array output. Not sure I want to do it this way. showarray(X::AbstractArray; kw...) = showarray(STDOUT, X; kw...) function showarray(io::IO, X::AbstractArray; - header::Bool=true, - sz = (s = tty_size(); (s[1]-4, s[2])), - repr=false) - rows, cols = sz + header::Bool=true, repr=false) header && print(io, summary(X)) - limit::Bool = limit_output(io) if !isempty(X) header && println(io, ":") if ndims(X) == 0 @@ -1372,23 +1379,19 @@ function showarray(io::IO, X::AbstractArray; return print(io, undef_ref_str) end end - if !limit - rows = cols = typemax(Int) - sz = (rows, cols) - end if repr - if ndims(X)<=2 + if ndims(X) <= 2 print_matrix_repr(io, X) else - show_nd(io, X, limit, print_matrix_repr, false) + show_nd(io, X, print_matrix_repr, false) end else punct = (" ", " ", "") - if ndims(X)<=2 - print_matrix(io, X, sz, punct...) + if ndims(X) <= 2 + print_matrix(io, X, punct...) else - show_nd(io, X, limit, - (io,slice)->print_matrix(io,slice,sz,punct...), + show_nd(io, X, + (io, slice) -> print_matrix(io, slice, punct...), !repr) end end diff --git a/base/sparse/sparsematrix.jl b/base/sparse/sparsematrix.jl index 6ecb1edf6c3c2..117df81632d31 100644 --- a/base/sparse/sparsematrix.jl +++ b/base/sparse/sparsematrix.jl @@ -77,8 +77,7 @@ convenient iterating over a sparse matrix : nzrange(S::SparseMatrixCSC, col::Integer) = S.colptr[col]:(S.colptr[col+1]-1) function Base.showarray(io::IO, S::SparseMatrixCSC; - header::Bool=true, - rows = Base.tty_size()[1], repr=false) + header::Bool=true, repr=false) # TODO: repr? if header print(io, S.m, "x", S.n, " sparse matrix with ", nnz(S), " ", eltype(S), " entries:") @@ -86,6 +85,7 @@ function Base.showarray(io::IO, S::SparseMatrixCSC; limit::Bool = Base.limit_output(io) if limit + rows = iosize(io)[1] half_screen_rows = div(rows - 8, 2) else half_screen_rows = typemax(Int) diff --git a/base/sparse/sparsevector.jl b/base/sparse/sparsevector.jl index 4d5bdbaacef10..23e1f71afc667 100644 --- a/base/sparse/sparsevector.jl +++ b/base/sparse/sparsevector.jl @@ -585,8 +585,7 @@ getindex(x::AbstractSparseVector, ::Colon) = copy(x) ### show and friends function showarray(io::IO, x::AbstractSparseVector; - header::Bool=true, - rows = Base.tty_size()[1], repr=false) + header::Bool=true, repr=false) n = length(x) nzind = nonzeroinds(x) @@ -598,7 +597,7 @@ function showarray(io::IO, x::AbstractSparseVector; end limit::Bool = Base.limit_output(io) - half_screen_rows = limit ? div(rows - 8, 2) : typemax(Int) + half_screen_rows = limit ? div(iosize(io)[1] - 8, 2) : typemax(Int) pad = ndigits(n) sep = "\n\t" for k = 1:length(nzind) diff --git a/base/stream.jl b/base/stream.jl index b97c9a1892f4a..d8e0ff76b90bb 100644 --- a/base/stream.jl +++ b/base/stream.jl @@ -378,6 +378,45 @@ function close(stream::Union{LibuvStream, LibuvServer}) nothing end +@windows_only begin + ispty(s::TTY) = s.ispty + ispty(s::IO) = false +end + +" iosize(io) -> (lines, columns) +Return the nominal size of the screen that may be used for rendering output to this io object" +iosize(io::IO) = iosize() +iosize() = (parse(Int, get(ENV, "LINES", "24")), + parse(Int, get(ENV, "COLUMNS", "80")))::Tuple{Int, Int} + +function iosize(io::TTY) + local h::Int, w::Int + default_size = iosize() + + @windows_only if ispty(io) + # io is actually a libuv pipe but a cygwin/msys2 pty + try + h, w = map(x -> parse(Int, x), split(readall(open(Base.Cmd(ByteString["stty", "size"]), "r", io)[1]))) + h > 0 || (h = default_size[1]) + w > 0 || (w = default_size[2]) + return h, w + catch + return default_size + end + end + + s1 = Ref{Int32}(0) + s2 = Ref{Int32}(0) + Base.uv_error("size (TTY)", ccall(:uv_tty_get_winsize, + Int32, (Ptr{Void}, Ptr{Int32}, Ptr{Int32}), + io, s1, s2) != 0) + w, h = s1[], s2[] + h > 0 || (h = default_size[1]) + w > 0 || (w = default_size[2]) + return h, w +end + + ### Libuv callbacks ### #from `connect` diff --git a/doc/stdlib/io-network.rst b/doc/stdlib/io-network.rst index 807bfe2b73ab3..627843695079d 100644 --- a/doc/stdlib/io-network.rst +++ b/doc/stdlib/io-network.rst @@ -404,7 +404,7 @@ Text I/O .. Docstring generated from Julia source - 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 overload ``showcompact(io, x)`` where the first argument is a stream. + 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 ``show`` method. .. function:: showall(x) @@ -624,6 +624,18 @@ Text I/O Decodes the base64-encoded ``string`` and returns a ``Vector{UInt8}`` of the decoded bytes. +.. function:: iosize(io) -> (lines, columns) + + .. Docstring generated from Julia source + + 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 -------------- diff --git a/test/dict.jl b/test/dict.jl index 7486cf29958f0..993556fd4828e 100644 --- a/test/dict.jl +++ b/test/dict.jl @@ -257,7 +257,8 @@ 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() - Base.showdict(Base.IOContext(s, :limit_output => true), d, sz=(rows, cols)) + io = Base.IOContext(Base.IOContext(s, :limit_output => true), :iosize => (rows, cols)) + Base.showdict(io, d) out = split(takebuf_string(s),'\n') for line in out[2:end] @test strwidth(line) <= cols @@ -266,7 +267,8 @@ for d in (Dict("\n" => "\n", "1" => "\n", "\n" => "2"), for f in (keys, values) s = IOBuffer() - Base.showkv(Base.IOContext(s, :limit_output => true), f(d), sz=(rows, cols)) + io = Base.IOContext(Base.IOContext(s, :limit_output => true), :iosize => (rows, cols)) + Base.showkv(io, f(d)) out = split(takebuf_string(s),'\n') for line in out[2:end] @test strwidth(line) <= cols @@ -284,17 +286,23 @@ end # issue #9463 type Alpha end Base.show(io::IO, ::Alpha) = print(io,"α") -sbuff = IOBuffer() -Base.showdict(Base.IOContext(sbuff, :limit_output => true), Dict(Alpha()=>1), sz=(10,20)) -@test !contains(bytestring(sbuff), "…") +let sbuff = IOBuffer(), + io = Base.IOContext(Base.IOContext(sbuff, :limit_output => true), :iosize => (10, 20)) + + Base.showdict(io, Dict(Alpha()=>1)) + @test !contains(bytestring(sbuff), "…") + @test endswith(bytestring(sbuff), "α => 1") +end # issue #2540 -d = Dict{Any,Any}([x => 1 for x in ['a', 'b', 'c']]) -@test d == Dict('a'=>1, 'b'=>1, 'c'=> 1) +let d = Dict{Any,Any}([x => 1 for x in ['a', 'b', 'c']]) + @test d == Dict('a'=>1, 'b'=>1, 'c'=> 1) +end # issue #2629 -d = Dict{AbstractString,AbstractString}([ a => "foo" for a in ["a","b","c"]]) -@test d == Dict("a"=>"foo","b"=>"foo","c"=>"foo") +let d = Dict{AbstractString,AbstractString}([ a => "foo" for a in ["a","b","c"]]) + @test d == Dict("a"=>"foo","b"=>"foo","c"=>"foo") +end # issue #5886 d5886 = Dict()