Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Replaces tty_rows()/tty_cols() with tty_size(), which calls
uv_tty_get_winsize() to get the terminal size
  • Loading branch information
simonster committed Jun 18, 2014
1 parent 8f1fbec commit f32d777
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 16 deletions.
6 changes: 4 additions & 2 deletions base/dict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ end

showdict(t::Associative; kw...) = showdict(STDOUT, t; kw...)
function showdict{K,V}(io::IO, t::Associative{K,V}; limit::Bool = false,
rows = tty_rows()-3, cols = tty_cols())
sz=(s = tty_size(); (s[1]-3, s[2])))
rows, cols = sz
print(io, summary(t))
isempty(t) && return
print(io, ":")
Expand Down Expand Up @@ -118,7 +119,8 @@ 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; limit::Bool = false,
rows = tty_rows()-3, cols = tty_cols())
sz=(s = tty_size(); (s[1]-3, s[2])))
rows, cols = sz
print(io, summary(iter))
isempty(iter) && return
print(io, ". ", T<:KeyIterator ? "Keys" : "Values", ":")
Expand Down
14 changes: 12 additions & 2 deletions base/env.jl
Original file line number Diff line number Diff line change
Expand Up @@ -184,5 +184,15 @@ end

## misc environment-related functionality ##

tty_cols() = parseint(Int32, get(ENV,"COLUMNS","80"), 10)
tty_rows() = parseint(Int32, get(ENV,"LINES","25"), 10)
function tty_size()
if isdefined(Base, :active_repl)
os = REPL.outstream(Base.active_repl)
if isa(os, Terminals.TTYTerminal)
try
sz = size(os)
return (sz.height, sz.width)
end
end
end
return (25, 80)
end
2 changes: 1 addition & 1 deletion base/linalg/factorization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ end
full(A::HessenbergQ) = LAPACK.orghr!(1, size(A.factors, 1), copy(A.factors), A.τ)

# Also printing of QRQs
print_matrix(io::IO, A::Union(QRPackedQ,QRCompactWYQ,HessenbergQ), rows::Integer, cols::Integer, punct...) = print_matrix(io, full(A), rows, cols, punct...)
print_matrix(io::IO, A::Union(QRPackedQ,QRCompactWYQ,HessenbergQ), sz::(Integer, Integer), punct...) = print_matrix(io, full(A), sz, punct...)


#######################
Expand Down
5 changes: 3 additions & 2 deletions base/pkg/entry.jl
Original file line number Diff line number Diff line change
Expand Up @@ -596,11 +596,12 @@ function check_metadata()
end

function warnbanner(msg...; label="[ WARNING ]", prefix="")
warn(prefix="", Base.cpad(label,Base.tty_cols(),"="))
cols = Base.tty_size()[2]
warn(prefix="", Base.cpad(label,cols,"="))
println(STDERR)
warn(prefix=prefix, msg...)
println(STDERR)
warn(prefix="", "="^Base.tty_cols())
warn(prefix="", "="^cols)
end

function build!(pkgs::Vector, errs::Dict, seen::Set=Set())
Expand Down
2 changes: 1 addition & 1 deletion base/profile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ __init__() = init(1_000_000, 0.001)

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_cols())
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])
if format == :tree
tree(io, data, lidict, C, combine, cols)
elseif format == :flat
Expand Down
11 changes: 6 additions & 5 deletions base/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -827,15 +827,15 @@ function print_matrix_vdots(io::IO,
end

function print_matrix(io::IO, X::AbstractVecOrMat,
rows::Integer = tty_rows()-4,
cols::Integer = tty_cols(),
sz::(Integer, Integer) = (s = tty_size(); (s[1]-4, s[2])),
pre::String = " ",
sep::String = " ",
post::String = "",
hdots::String = " \u2026 ",
vdots::String = "\u22ee",
ddots::String = " \u22f1 ",
hmod::Integer = 5, vmod::Integer = 5)
rows, cols = sz
cols -= length(pre) + length(post)
presp = repeat(" ", length(pre))
postsp = ""
Expand Down Expand Up @@ -1001,7 +1001,8 @@ end
showarray(X::AbstractArray; kw...) = showarray(STDOUT, X; kw...)
function showarray(io::IO, X::AbstractArray;
header::Bool=true, limit::Bool=_limit_output,
rows = tty_rows()-4, cols = tty_cols(), repr=false)
sz = (s = tty_size(); (s[1]-4, s[2])), repr=false)
rows, cols = sz
header && print(io, summary(X))
if !isempty(X)
header && println(io, ":")
Expand All @@ -1024,10 +1025,10 @@ function showarray(io::IO, X::AbstractArray;
else
punct = (" ", " ", "")
if ndims(X)<=2
print_matrix(io, X, rows, cols, punct...)
print_matrix(io, X, sz, punct...)
else
show_nd(io, X, limit,
(io,slice)->print_matrix(io,slice,rows,cols,punct...),
(io,slice)->print_matrix(io,slice,sz,punct...),
!repr)
end
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 @@ -20,7 +20,7 @@ countnz(S::SparseMatrixCSC) = countnz(S.nzval)

function Base.showarray(io::IO, S::SparseMatrixCSC;
header::Bool=true, limit::Bool=Base._limit_output,
rows = Base.tty_rows(), repr=false)
rows = Base.tty_size()[1], repr=false)
# TODO: repr?

if header
Expand Down
4 changes: 2 additions & 2 deletions test/collections.jl
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ for d in (["\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(s, d, limit=true, rows=rows, cols=cols)
Base.showdict(s, d, limit=true, sz=(rows, cols))
out = split(takebuf_string(s),'\n')
for line in out[2:end]
@test strwidth(line) <= cols
Expand All @@ -188,7 +188,7 @@ for d in (["\n" => "\n", "1" => "\n", "\n" => "2"],

for f in (keys, values)
s = IOBuffer()
Base.showkv(s, f(d), limit=true, rows=rows, cols=cols)
Base.showkv(s, f(d), limit=true, sz=(rows, cols))
out = split(takebuf_string(s),'\n')
for line in out[2:end]
@test strwidth(line) <= cols
Expand Down

0 comments on commit f32d777

Please sign in to comment.