IOUtils.jl
IOUtils.column_widths
IOUtils.columns
IOUtils.display_matrix
IOUtils.horizontal_line
IOUtils.indent
IOUtils.indent
IOUtils.print_boxed
IOUtils.print_boxed
IOUtils.redirect_output
IOUtils.@display
IOUtils.column_widths
— Methodcolumn_widths(io, args...)
Compute a set of integer widths that will add to the total amount of columns of io
. Integer
args
will be taken as-is, Rational
args
(should add to ≤ 1) will result in integers that roughly correspond to the fraction of the total amount of columns, minus the Integer
args...
.
Example
The default amount of columns is 80:
julia> IOUtils.column_widths(open("/tmp/test.txt", "w"), 1//3, 2, 2//3)
3-element Array{Int64,1}:
26
2
52
IOUtils.columns
— Methodcolumns(fun::Function, io::IO, args...; trim=false)
Print things to io
in columns, where args...
is handled by column_widths
. If trim
, then the columns will be narrowed to the maximum line of each column.
julia> columns(stdout, 6, 10) do ios
println(ios[1], "H")
println(ios[1], " el")
println(ios[1], " lo")
println(ios[2], "ello")
println(ios[2], "H")
end
H ello
el H
lo
julia> columns(stdout, 6, 10, trim=true) do ios
println(ios[1], "H")
println(ios[1], " el")
println(ios[1], " lo")
println(ios[2], "ello")
println(ios[2], "H")
end
H ello
elH
lo
julia> n = 10; o = ones(n);
julia> T = Tridiagonal(o[2:end], -2o, o[2:end]);
julia> columns(stdout, 1//2, 2, 1//2, trim=true) do ios
display_matrix(ios[1], T)
println(ios[2])
println(ios[2], "-1")
display_matrix(ios[3], T)
end
10×10 Tridiagonal{Float64,Array{Float64,1}}: 10×10 Tridiagonal{Float64,Array{Float64,1}}:
⎡ -2.0 1.0 ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⎤-1⎡ -2.0 1.0 ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⎤
⎢ 1.0 -2.0 1.0 ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⎢ ⎢ 1.0 -2.0 1.0 ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⎢
⎢ ⋅ 1.0 -2.0 1.0 ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⎢ ⎢ ⋅ 1.0 -2.0 1.0 ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⎢
⎢ ⋅ ⋅ 1.0 -2.0 1.0 ⋅ ⋅ ⋅ ⋅ ⋅ ⎢ ⎢ ⋅ ⋅ 1.0 -2.0 1.0 ⋅ ⋅ ⋅ ⋅ ⋅ ⎢
⎢ ⋅ ⋅ ⋅ 1.0 -2.0 1.0 ⋅ ⋅ ⋅ ⋅ ⎢ ⎢ ⋅ ⋅ ⋅ 1.0 -2.0 1.0 ⋅ ⋅ ⋅ ⋅ ⎢
⎢ ⋅ ⋅ ⋅ ⋅ 1.0 -2.0 1.0 ⋅ ⋅ ⋅ ⎢ ⎢ ⋅ ⋅ ⋅ ⋅ 1.0 -2.0 1.0 ⋅ ⋅ ⋅ ⎢
⎢ ⋅ ⋅ ⋅ ⋅ ⋅ 1.0 -2.0 1.0 ⋅ ⋅ ⎢ ⎢ ⋅ ⋅ ⋅ ⋅ ⋅ 1.0 -2.0 1.0 ⋅ ⋅ ⎢
⎢ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ 1.0 -2.0 1.0 ⋅ ⎢ ⎢ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ 1.0 -2.0 1.0 ⋅ ⎢
⎢ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ 1.0 -2.0 1.0⎢ ⎢ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ 1.0 -2.0 1.0⎢
⎣ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ 1.0 -2.0⎦ ⎣ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ 1.0 -2.0⎦
IOUtils.display_matrix
— Methoddisplay_matrix(io, A)
Display the matrix A
on io
wrapped in square brackets. Quite simple implementation that assumes the first line contains type information and the rest of the lines are the matrix elements.
Examples
julia> n = 10; o = ones(n);
julia> T = Tridiagonal(o[2:end], -2o, o[2:end]);
julia> display_matrix(stdout, T)
10×10 Tridiagonal{Float64,Array{Float64,1}}:
⎡ -2.0 1.0 ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⎤
⎢ 1.0 -2.0 1.0 ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⎢
⎢ ⋅ 1.0 -2.0 1.0 ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⎢
⎢ ⋅ ⋅ 1.0 -2.0 1.0 ⋅ ⋅ ⋅ ⋅ ⋅ ⎢
⎢ ⋅ ⋅ ⋅ 1.0 -2.0 1.0 ⋅ ⋅ ⋅ ⋅ ⎢
⎢ ⋅ ⋅ ⋅ ⋅ 1.0 -2.0 1.0 ⋅ ⋅ ⋅ ⎢
⎢ ⋅ ⋅ ⋅ ⋅ ⋅ 1.0 -2.0 1.0 ⋅ ⋅ ⎢
⎢ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ 1.0 -2.0 1.0 ⋅ ⎢
⎢ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ 1.0 -2.0 1.0⎢
⎣ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ 1.0 -2.0⎦
IOUtils.horizontal_line
— Functionhorizontal_line([io=stdout; char="━", color=:light_black])
Draw a color
ed horizontal line of char
s across the whole screen.
Example
julia> horizontal_line()
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
julia> horizontal_line(char="─")
────────────────────────────────────────────────────────────────────────────────
IOUtils.indent
— Methodindent(fun, io, n[; indent_first=true, kwargs...])
Print all the output of fun
to io
indented by n
spaces. If !indent_first
, the first line is not indented. kwargs...
are passed on to printstyled
.
Examples
julia> indent(stdout, 6) do io
println(io, "Hello")
println(io, "World")
end
Hello
World
IOUtils.indent
— Methodindent(fun, io, first_line::String[; kwargs...])
Variant of indent
that will first print first_line
and then print all the output from fun
indented by the length of first_line
. kwargs
are passed on to printstyled
.
Examples
julia> indent(stdout, "Important information: ") do io
println(io, "Hello")
println(io, "World")
end
Important information: Hello
World
julia> indent(stdout, "Important information: ") do io
print_boxed(io) do io
println(io, "Hello")
println(io, "World")
end
end
Important information: ┌ Hello
└ World
IOUtils.print_boxed
— Functionprint_boxed(io, msglines[, prefix="", suffix=""; color=:light_black, chars="[┌│└"])
Print each line in msglines
to io
with an enclosing box drawn to the left, using the specified color
. The first and last line will additionally print the optional parameter prefix
and suffix
, respectively. The box drawing characters can be customized by setting the string chars
to any combination of four characters.
Examples
julia> print_boxed(stdout, ["Hello", "World"], ">>>", "<<<")
┌ >>> Hello
└ World <<<
julia> print_boxed(stdout, ["Hello world"], chars="(╭│╰")
( Hello world
julia> print_boxed(stdout, ["Hello", "world"], chars="(╭│╰")
╭ Hello
╰ world
IOUtils.print_boxed
— Methodprint_boxed(fun::Function, io, args...; kwargs...)
Block-version of print_boxed
that via redirect_output
captures the output of fun
, and prints them in a block.
Examples
julia> print_boxed(stdout) do io
println(io, "Hello")
println(io, "World")
end
┌ Hello
└ World
IOUtils.redirect_output
— Methodredirect_output(fun)
Create an IOBuffer
, pass it to fun
, and return the captured output as a string.
Examples
julia> redirect_output() do io
println(io, "Hello")
println(io, "World")
end
"Hello\nWorld\n"
IOUtils.@display
— Macro@display expr
Display expr
using print_boxed
along with the location from where the macro was called (useful for debugging); a mixture of @show
, display
, and @debug
.
Examples
julia> @display sin.(1:10)
┌ sin.(1:10) = 10-element Array{Float64,1}:
│ 0.8414709848078965
│ 0.9092974268256817
│ 0.1411200080598672
│ -0.7568024953079282
│ -0.9589242746631385
│ -0.27941549819892586
│ 0.6569865987187891
│ 0.9893582466233818
│ 0.4121184852417566
│ -0.5440211108893698
└ @ REPL[16]:1