This Julia package provides the function
wrap which parses an input text and reorganizes its white space so that it can be printed with a fixed screen width, optionally indenting it. It also provides the two convenience functions
Here is a quick example:
julia> using TextWrap julia> text = "This text is going to be wrapped around in lines no longer than 20 characters."; julia> println_wrapped(text, width=20) This text is going to be wrapped around in lines no longer than 20 characters.
It's very similar to Python's textwrap module, but the interface is slightly different.
To install the module, use Julia's package manager: start pkg mode by pressing
] and then enter:
(v1.3) pkg> add TextWrap
Dependencies will be installed automatically. The module can then be loaded like any other Julia module:
julia> using TextWrap
string and returns a new string in which newlines are inserted as appropriate in order for each line to fit within a specified width.
The behaviour can be controlled via optional keyword arguments:
70): the maximum width of the wrapped text, including indentation.
""): indentation of the first line. This can be any string (shorter than
width), or it can be an integer number (smaller than
""): indentation of all lines except the first. Works the same as
true): this flag determines whether words can be broken on hyphens, e.g. whether "high-precision" can be split into "high-" and "precision".
true): this flag determines what to do when a word is too long to fit in any line. If
true, the word will be broken, otherwise it will go beyond the desired text width.
true): if this flag is
true, all whitespace characters in the original text (including newlines) will be replaced by spaces. Otherwise, they'll be preserved, except at the beginning or end of a line.
true): if this flag is
true, tabs will be expanded in-place into spaces. Otherwise a tab is counted as a single character. The expansion happens before whitespace replacement.
false): if this flag is
true, the wrapper will try to recognize sentence endings in the middle of a paragraph and put two spaces before the next sentence in case only one is present.
true, compute all lengths ignoring ANSI escape codes (special character sequences used e.g. to modify the text color or other properties; they look e.g. like
print_wrapped([io,] text...; keywords...)
This is just like the standard
IO first argument), except that it wraps the result, and accepts keyword arguments to pass to
println_wrapped([io,] text...; keywords...)
print_wrapped, but adds a newline at the end.