This Julia package helps align text for printing with a monospace font, by keeping track of the maximum width of each column. It is useful for printing matrices, tables, and analogous structures, and in particular for writing methods for
This package is not yet registered on Julia's METADATA.jl. To install it, you must use the usual procedure for unregistered packages:
Note that the minimum required version of Julia is 0.6.
AutoAlign object, then use
AutoAlign object keeps track of the current column (which you can query with
position, but that is rarely necessary), and you can also provide a default alignment, or specify it before printing, using the methods
print(aa::AutoAlign, xs...) println(aa::AutoAlign, xs...)
where the latter starts a new line after saving the values. Both accept a keyword argument
align, for specifying alternate alignent for the preceding arguments.
Alignment can be specified as follows:
center, or any other user extension which is a subtype of
a vector of alignment specifiers: for positions outside the length of the vector, the last element is used,
position => alignmentpairs, where the position
:defaultprovides the alignment for items not in the
julia> using AutoAligns julia> aa = AutoAlign(align = Dict(1 => left, :default => right)); julia> for (i, r) in zip([1, 100, 10000], ["a", "bb", "ccc"]) print(aa, r) for j in 1:5 print(aa, " ", i + j) # padding end println(aa) end julia> print(STDOUT, aa) a 2 3 4 5 6 bb 101 102 103 104 105 ccc 10001 10002 10003 10004 10005
Spaces or separators such as
| are not treated in a special way, and therefore should be accounted for when specifying positions for alignment.
AutoAlign object to a stream pads the strings with spaces so as to achieve the desired alignment.
AutoAlign object is not a subtype of
IO, as it does not implement a
write(::AutoAlign, x::UInt8) method. Unlike
IOBuffer, printing does not delete the contents.
Custom alignment types can be defined as subtypes of
Alignment, by implementing