Formatting text: tables drawn with StyleAscii
The guide's framed tables use +, - and |, which every font has, so they line up in a browser whatever font it draws code in. 🤖 Generated with [ECA](https://eca.dev) (anthropic/claude-opus-5-5) Co-Authored-By: eca-agent <git@eca.dev>
This commit is contained in:
parent
aaf92b38c1
commit
21fa7af6dc
1 changed files with 22 additions and 22 deletions
|
|
@ -870,15 +870,15 @@ In @code{tabular} a column's cells are separated by @code{nl}. In @code{tabular/
|
||||||
@codeblock[#:lang "bjolang"]|{
|
@codeblock[#:lang "bjolang"]|{
|
||||||
(show [(tabular/rows [["tea" (each [3 " cups"])]
|
(show [(tabular/rows [["tea" (each [3 " cups"])]
|
||||||
["kettle" (each ["boils in" nl "4 minutes"])]]
|
["kettle" (each ["boils in" nl "4 minutes"])]]
|
||||||
#:style StyleLight)])
|
#:style StyleAscii)])
|
||||||
}|
|
}|
|
||||||
|
|
||||||
@codeblock[#:lang "text"]|{
|
@codeblock[#:lang "text"]|{
|
||||||
┌────────┬───────────┐
|
+--------+-----------+
|
||||||
│ tea │ 3 cups │
|
| tea | 3 cups |
|
||||||
│ kettle │ boils in │
|
| kettle | boils in |
|
||||||
│ │ 4 minutes │
|
| | 4 minutes |
|
||||||
└────────┴───────────┘
|
+--------+-----------+
|
||||||
}|
|
}|
|
||||||
|
|
||||||
Rows from data come from a function with a signature, for the reason given above. Here is the high-score ledger from "Files and I/O" as a table:
|
Rows from data come from a function with a signature, for the reason given above. Here is the high-score ledger from "Files and I/O" as a table:
|
||||||
|
|
@ -892,19 +892,19 @@ Rows from data come from a function with a signature, for the reason given above
|
||||||
(show [(tabular/rows (vec-map score-row (read-scores))
|
(show [(tabular/rows (vec-map score-row (read-scores))
|
||||||
#:titles ["Player" "Score"]
|
#:titles ["Player" "Score"]
|
||||||
#:align [AlignLeft AlignRight]
|
#:align [AlignLeft AlignRight]
|
||||||
#:style StyleRounded)])
|
#:style StyleAscii)])
|
||||||
}|
|
}|
|
||||||
|
|
||||||
@codeblock[#:lang "text"]|{
|
@codeblock[#:lang "text"]|{
|
||||||
╭────────┬───────╮
|
+--------+-------+
|
||||||
│ Player │ Score │
|
| Player | Score |
|
||||||
├────────┼───────┤
|
+--------+-------+
|
||||||
│ ada │ 31 │
|
| ada | 31 |
|
||||||
│ bo │ 27 │
|
| bo | 27 |
|
||||||
╰────────┴───────╯
|
+--------+-------+
|
||||||
}|
|
}|
|
||||||
|
|
||||||
@code{#:style} takes a @code{TableStyle}: @code{StyleNone}, the default, @code{StyleSimple}, @code{StyleAscii}, @code{StyleLight}, @code{StyleHeavy}, @code{StyleDouble}, @code{StyleRounded}, @code{StyleMarkdown}, or @code{StyleCustom} with pieces of your own. @code{#:align} takes an @code{Align} for each column, from the first: @code{AlignLeft}, @code{AlignRight}, @code{AlignCentre}, or @code{(AlignOn #\.)}, which puts every decimal point of the column in one place. @code{#:widths} and @code{#:overflow} make a table fit @code{current-width}, by cutting or wrapping its cells.
|
The tables here are drawn with @code{StyleAscii}, whose characters every font has. @code{#:style} takes a @code{TableStyle}: @code{StyleNone}, the default, @code{StyleSimple}, @code{StyleAscii}, @code{StyleLight}, @code{StyleHeavy}, @code{StyleDouble}, @code{StyleRounded}, @code{StyleMarkdown}, or @code{StyleCustom} with pieces of your own. @code{#:align} takes an @code{Align} for each column, from the first: @code{AlignLeft}, @code{AlignRight}, @code{AlignCentre}, or @code{(AlignOn #\.)}, which puts every decimal point of the column in one place. @code{#:widths} and @code{#:overflow} make a table fit @code{current-width}, by cutting or wrapping its cells.
|
||||||
|
|
||||||
A table whose rows are not all known yet, such as results that come one at a time, is laid out a row at a time with @code{table-layout} and @code{table-row}. The widths are fixed beforehand, so each row is written when it is known:
|
A table whose rows are not all known yet, such as results that come one at a time, is laid out a row at a time with @code{table-layout} and @code{table-row}. The widths are fixed beforehand, so each row is written when it is known:
|
||||||
|
|
||||||
|
|
@ -924,7 +924,7 @@ bo 27
|
||||||
A table can also be a quoted literal, which the compiler checks where it is written. A column can say what kind of number it holds:
|
A table can also be a quoted literal, which the compiler checks where it is written. A column can say what kind of number it holds:
|
||||||
|
|
||||||
@codeblock[#:lang "bjolang"]|{
|
@codeblock[#:lang "bjolang"]|{
|
||||||
(show-table '(table (style light) header
|
(show-table '(table (style ascii) header
|
||||||
(column "Player")
|
(column "Player")
|
||||||
(column "Score" (align right))
|
(column "Score" (align right))
|
||||||
(column "Share" (percent (precision 0)))
|
(column "Share" (percent (precision 0)))
|
||||||
|
|
@ -932,13 +932,13 @@ A table can also be a quoted literal, which the compiler checks where it is writ
|
||||||
}|
|
}|
|
||||||
|
|
||||||
@codeblock[#:lang "text"]|{
|
@codeblock[#:lang "text"]|{
|
||||||
┌────────┬───────┬───────┐
|
+--------+-------+-------+
|
||||||
│ Player │ Score │ Share │
|
| Player | Score | Share |
|
||||||
├────────┼───────┼───────┤
|
+--------+-------+-------+
|
||||||
│ ada │ 31 │ 46% │
|
| ada | 31 | 46% |
|
||||||
│ bo │ 27 │ 40% │
|
| bo | 27 | 40% |
|
||||||
│ cy │ 9 │ 13% │
|
| cy | 9 | 13% |
|
||||||
└────────┴───────┴───────┘
|
+--------+-------+-------+
|
||||||
}|
|
}|
|
||||||
|
|
||||||
The rows can be spliced, @code{(rows ,scores)}, from a @code{(Vec (Vec TableCell))}. See @code{Table} on the module's page.
|
The rows can be spliced, @code{(rows ,scores)}, from a @code{(Vec (Vec TableCell))}. See @code{Table} on the module's page.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue