mirror of
https://github.com/odin-lang/Odin.git
synced 2025-12-29 09:24:33 +00:00
`c/frontend/tokenizer`:
add proper "Example:" header to demo example code,
removed empty lines.
`container/bit_array`:
moved comment before package;
aligned narrative lines to left margin;
converted case lines into bulleted lines ("- ");
converted individual examples to single-tab-indented preformatted text.
`dynlib`:
removed "//+build ignore" line;
added newline at EOF.
`image/netpmb`:
converted indented lines of "Reading", "Wrting" and "Some syntax..." into bulleted lists;
"Formats" indented lines kept as they are as the preformatted text seems relevant to keep the alignments;
doubly indented lines kept as single-indented to keep them different (as the format does not allow for two-level bulleted lists);
removed empy lines.
`os/os2`: WIP, not modified
`sys/info`:
removed "//+build ignore" line;
converted tab-indented initial description into regular left-margin comment;
moved uncommented sample code within the doc comment as an "Example:";
moved simple- and double-tabbed separate comments with sample Windows and macOS outputs within the doc comment as bulleted headlines with preformatted output listings;
removed now empty comments and blank lines after the package line.
`text/i18n`:
removed "//+build ignore" line;
moved the pacakge line at the end;
de-indented the tab-indented introductory narrative;
moved sample code comments into the doc comment as tab-indented code with a proper "Example:" heading;
removed "```" MD attempts at code formatting.
`text/table`:
unindented the comment lines of a descriptive kind;
headlines of major subdivisions are marked as bold;
kept code samples as tab-indented preformatted text (as there are several of them, the standard "Example:" and "Output:" headings cannot be used) removing the "```" MD attempts at code formatting;
removed in-between blank lines.
88 lines
2.8 KiB
Odin
88 lines
2.8 KiB
Odin
/*
|
|
The package `table` implements ASCII/markdown/HTML/custom rendering of tables.
|
|
|
|
**Custom rendering example:**
|
|
|
|
tbl := init(&Table{})
|
|
padding(tbl, 0, 1)
|
|
row(tbl, "A_LONG_ENUM", "= 54,", "// A comment about A_LONG_ENUM")
|
|
row(tbl, "AN_EVEN_LONGER_ENUM", "= 1,", "// A comment about AN_EVEN_LONGER_ENUM")
|
|
build(tbl)
|
|
for row in 0..<tbl.nr_rows {
|
|
for col in 0..<tbl.nr_cols {
|
|
write_table_cell(stdio_writer(), tbl, row, col)
|
|
}
|
|
io.write_byte(stdio_writer(), '\n')
|
|
}
|
|
|
|
This outputs:
|
|
|
|
A_LONG_ENUM = 54, // A comment about A_LONG_ENUM
|
|
AN_EVEN_LONGER_ENUM = 1, // A comment about AN_EVEN_LONGER_ENUM
|
|
|
|
**ASCII rendering example:**
|
|
|
|
tbl := init(&Table{})
|
|
defer destroy(tbl)
|
|
|
|
caption(tbl, "This is a table caption and it is very long")
|
|
|
|
padding(tbl, 1, 1) // Left/right padding of cells
|
|
|
|
header(tbl, "AAAAAAAAA", "B")
|
|
header(tbl, "C") // Appends to previous header row. Same as if done header("AAAAAAAAA", "B", "C") from start.
|
|
|
|
// Create a row with two values. Since there are three columns the third
|
|
// value will become the empty string.
|
|
//
|
|
// NOTE: header() is not allowed anymore after this.
|
|
row(tbl, 123, "foo")
|
|
|
|
// Use `format()` if you need custom formatting. This will allocate into
|
|
// the arena specified at init.
|
|
row(tbl,
|
|
format(tbl, "%09d", 5),
|
|
format(tbl, "%.6f", 6.28318530717958647692528676655900576))
|
|
|
|
// A row with zero values is allowed as long as a previous row or header
|
|
// exist. The value and alignment of each cell can then be set
|
|
// individually.
|
|
row(tbl)
|
|
set_cell_value_and_alignment(tbl, last_row(tbl), 0, "a", .Center)
|
|
set_cell_value(tbl, last_row(tbl), 1, "bbb")
|
|
set_cell_value(tbl, last_row(tbl), 2, "c")
|
|
|
|
// Headers are regular cells, too. Use header_row() as row index to modify
|
|
// header cells.
|
|
set_cell_alignment(tbl, header_row(tbl), 1, .Center) // Sets alignment of 'B' column to Center.
|
|
set_cell_alignment(tbl, header_row(tbl), 2, .Right) // Sets alignment of 'C' column to Right.
|
|
|
|
build(tbl)
|
|
|
|
write_ascii_table(stdio_writer(), tbl)
|
|
write_markdown_table(stdio_writer(), tbl)
|
|
|
|
This outputs:
|
|
|
|
+-----------------------------------------------+
|
|
| This is a table caption and it is very long |
|
|
+------------------+-----------------+----------+
|
|
| AAAAAAAAA | B | C |
|
|
+------------------+-----------------+----------+
|
|
| 123 | foo | |
|
|
| 000000005 | 6.283185 | |
|
|
| a | bbb | c |
|
|
+------------------+-----------------+----------+
|
|
|
|
and
|
|
|
|
| AAAAAAAAA | B | C |
|
|
|:-----------------|:---------------:|---------:|
|
|
| 123 | foo | |
|
|
| 000000005 | 6.283185 | |
|
|
| a | bbb | c |
|
|
|
|
respectively.
|
|
*/
|
|
package text_table
|