Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

introduce IOContext and ImmutableDict to fix some of show, print, & friends #13825

Merged
merged 6 commits into from
Dec 31, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions base/Enums.jl
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,12 @@ macro enum(T,syms...)
end
end
function Base.show(io::IO,x::$(esc(typename)))
print(io, x, "::", $(esc(typename)), " = ", Int(x))
if Base.limit_output(io)
print(io, x)
else
print(io, x, "::", $(esc(typename)), " = ", Int(x))
end
end
Base.showcompact(io::IO,x::$(esc(typename))) = print(io, x)
function Base.writemime(io::IO,::MIME"text/plain",::Type{$(esc(typename))})
print(io, "Enum ", $(esc(typename)), ":")
for (sym, i) in $vals
Expand Down
36 changes: 7 additions & 29 deletions base/Terminals.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import Base:
flush,
read,
readuntil,
size,
iosize,
start_reading,
stop_reading,
write,
Expand All @@ -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")
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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")
Expand Down
11 changes: 5 additions & 6 deletions base/complex.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,25 +59,24 @@ complex(x::Real, y::Real) = Complex(x, y)
complex(x::Real) = Complex(x)
complex(z::Complex) = z

function complex_show(io::IO, z::Complex, compact::Bool)
function show(io::IO, z::Complex)
r, i = reim(z)
compact ? showcompact(io,r) : show(io,r)
compact = limit_output(io)
showcompact_lim(io, r)
if signbit(i) && !isnan(i)
i = -i
print(io, compact ? "-" : " - ")
else
print(io, compact ? "+" : " + ")
end
compact ? showcompact(io, i) : show(io, i)
showcompact_lim(io, i)
if !(isa(i,Integer) && !isa(i,Bool) || isa(i,AbstractFloat) && isfinite(i))
print(io, "*")
end
print(io, "im")
end
complex_show(io::IO, z::Complex{Bool}, compact::Bool) =
show(io::IO, z::Complex{Bool}) =
print(io, z == im ? "im" : "Complex($(z.re),$(z.im))")
show(io::IO, z::Complex) = complex_show(io, z, false)
showcompact(io::IO, z::Complex) = complex_show(io, z, true)

function read{T<:Real}(s::IO, ::Type{Complex{T}})
r = read(s,T)
Expand Down
14 changes: 14 additions & 0 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading