This module is the entry point to format structured text.
format/1
returns an internal structure where the text
is already formatted but not ready for display: it is mostly used
internally.to_string/1
formats the given argument and returns a
string ready to be displayed or stored.display/1
does the same thing as to_string/1
but
displays the result on stdout
directly (and returns nothing).To automatically wrap a paragraph to fit it in 30 columns and display it:
-include_lib("stdout_formatter/include/stdout_formatter.hrl"). stdout_formatter:display( #paragraph{ content = "This module is the entry point to format structured text.", props = #{wrap_at => 30}}).
This module is the entry point to format structured text.
To format a table and display it:
-include_lib("stdout_formatter/include/stdout_formatter.hrl"). stdout_formatter:display( #table{ rows = [["Top left", "Top right"], ["Bottom left", "Bottom right"]], props = #{}}).
┌───────────┬────────────┐ │Top left │Top right │ ├───────────┼────────────┤ │Bottom left│Bottom right│ └───────────┴────────────┘
border_drawing() = ansi | ascii | none
The line drawing technic.
ansi
: borders are drawn with ANSI escape sequences.ascii
: borders are drawn with US-ASCII characters.none
: no border drawn.border_style() = thin
The style of borders.
cell() = #cell{}
A cell in a table row.
Seetable/0
.
cell_props() = #{title => boolean(), padding => padding(), inherited => map()}
Cell properties.
The properties are:title
: true
if the cells is a title (i.e. content is bold).color() = color_8palette() | color_256palette() | true_color()
A color name, index or value.
color_256palette() = byte()
Color index in the ANSI 256-color palette.
color_8palette() = black | red | green | yellow | blue | magenta | cyan | white | bright_black | bright_red | bright_green | bright_yellow | bright_blue | bright_magenta | bright_cyan | bright_white | 0..15
Color name (atom) or index in the ANSI escape sequence color palette.
content_if_reformat() = [{unicode:chardata(), non_neg_integer()} | {color_start, string(), string()} | {color_end, string(), string()}] | derived_from_previous_sibling | false
formattable() = paragraph() | table() | formatted_block() | term()
formatted_block() = #formatted_block{}
A formatted block.
It is the result of theformat/1
and format/2
functions. It contains a list of formatted_line/0
.
formatted_block_props() = #{width := non_neg_integer(), height := non_neg_integer()}
Formatted block properties.
The properties are:width
: Number of columns of the widest line.height
: Number of lines.formatted_line() = #formatted_line{}
A formatted line.
formatted_line_props() = #{width := non_neg_integer(), reformat_ok := content_if_reformat()}
Formatted line properties.
The properties are:width
: Number of columns of the line.reformat_ok
: Content used to reformat the line if relevant,
e.g. to rewrap a paragraph.padding() = padding_value() | {padding_value(), padding_value()} | {padding_value(), padding_value(), padding_value(), padding_value()}
The number of columns/lines of horizontal/vertical padding.
padding_value() = non_neg_integer()
paragraph() = #paragraph{}
A paragraph of text to format.
The content can be a string or any Erlang term. The format string can be specified as a property (Seeparagraph_props/0
). If it is
missing, it will be guessed from the Erlang term.
paragraph_props() = #{format => string() | none | subterms, wrap_at => pos_integer() | false, bold => boolean(), fg => color() | none, bg => color() | none, inherited => map()}
Paragraph properties.
The properties are:format
: the format string to present the content.wrap_at
: the number of columns after which the lines are wrapped.bold
: true
if the content must be dispalyed as bold characters.fg
: the color to use as foreground.bg
: the color to use as background.row() = #row{}
A row in a table.
Seetable/0
.
row_props() = #{title => boolean(), title_repeat => pos_integer() | false, inherited => map()}
Row properties.
The properties are:title
: true
if cells are all title cells.title_repeat
: whether to repeat the title rows and how often.
[NOT IMPLEMENTED]table() = #table{}
A table to format.
It is made of a list of rows. Each row is either arow/0
or
a list of cells. Each cell is either a cell/0
or a formattable/0
.
table_props() = #{border_drawing => border_drawing(), border_style => border_style(), cell_padding => padding(), inherited => map()}
Table properties.
The properties are:border_drawing
: the type of line drawing to use.border_style
: the style of borders.true_color() = {Red::byte(), Green::byte(), Blue::byte()}
Three-byte tuple corresponding to RGB 24-bit channel values.
display/1 | Formats a term and displays it on stdout . |
display/2 | Formats a term and displays it on stdout . |
format/1 |
Formats a term and returns a formatted_block/0 . |
format/2 |
Formats a term and returns a formatted_block/0 . |
to_string/1 | Formats a term and returns a string. |
to_string/2 | Formats a term and returns a string. |
display(Term::formattable()) -> ok
Term: Term to format and display.
Formats a term and displays it on stdout
.
display(Formatted_block::formattable(), InheritedProps::map()) -> ok
InheritedProps: Inherited properties map.
Formats a term and displays it on stdout
.
format(Term::formattable()) -> formatted_block()
Term: Term to format.
returns: A formatted_block/0
.
Formats a term and returns a formatted_block/0
.
format(Formatted_block::formattable(), InheritedProps::map()) -> formatted_block()
InheritedProps: Inherited properties map.
returns: A formatted_block/0
.
Formats a term and returns a formatted_block/0
.
to_string(Term::formattable()) -> unicode:chardata()
Term: Term to format as a string.
returns: A string of the formatted term.
Formats a term and returns a string.
to_string(Formatted_block::formattable(), InheritedProps::map()) -> unicode:chardata()
InheritedProps: Inherited properties map.
returns: A string of the formatted term.
Formats a term and returns a string.
It will use the specified inherited properties.Generated by EDoc