Skip to content

Commit

Permalink
Make size(UnixTerminal) return a tuple
Browse files Browse the repository at this point in the history
  • Loading branch information
simonster committed Jun 18, 2014
1 parent f32d777 commit efd463c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 22 deletions.
33 changes: 14 additions & 19 deletions base/Terminals.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,6 @@ import Base:
write,
writemime

immutable Size
width
height
end

## TextTerminal ##

abstract TextTerminal <: Base.IO
Expand Down Expand Up @@ -87,8 +82,8 @@ function writepos(t::TextTerminal, x, y, args...)
cmove(t, x, y)
write(t, args...)
end
width(t::TextTerminal) = size(t).width
height(t::TextTerminal) = size(t).height
width(t::TextTerminal) = size(t)[2]
height(t::TextTerminal) = size(t)[1]

# For terminals with buffers
flush(t::TextTerminal) = nothing
Expand Down Expand Up @@ -117,14 +112,13 @@ type FakeTerminal <: UnixTerminal
err_stream::Base.IO
hascolor::Bool
raw::Bool
size::Size
FakeTerminal(stdin,stdout,stderr,hascolor=true) =
new(stdin,stdout,stderr,hascolor,false,Size(80,80))
new(stdin,stdout,stderr,hascolor,false)
end

hascolor(t::FakeTerminal) = t.hascolor
raw!(t::FakeTerminal, raw::Bool) = t.raw = raw
size(t::FakeTerminal) = t.size
size(t::FakeTerminal) = (24, 80)

type TTYTerminal <: UnixTerminal
term_type::ASCIIString
Expand Down Expand Up @@ -170,15 +164,16 @@ 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>")

function size(t::TTYTerminal)
s = zeros(Int32, 2)
Base.uv_error("size (TTY)", ccall((@windows ? :jl_tty_get_winsize : :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)
Size(w,h)
let s = zeros(Int32, 2)
function Base.size(t::TTYTerminal)
Base.uv_error("size (TTY)", ccall((@windows ? :jl_tty_get_winsize : :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
end

clear(t::UnixTerminal) = write(t.out_stream, "\x1b[H\x1b[2J")
Expand Down
5 changes: 2 additions & 3 deletions base/env.jl
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,9 @@ function tty_size()
os = REPL.outstream(Base.active_repl)
if isa(os, Terminals.TTYTerminal)
try
sz = size(os)
return (sz.height, sz.width)
return size(os)
end
end
end
return (25, 80)
return (24, 80)
end

0 comments on commit efd463c

Please sign in to comment.