t2
Type members
Classlikes
Defines table.
Defines table.
How to Create Table
A Table can be created using a factory defined in companion object, or it
can be built incrementally using a TableBuilder.
The two tables created in the example below are effectively the same.
// Create table with data supplied as Seq[Seq[String]]
val table1 = t2.Table(
Seq(
Seq("#", "Effective Date", "Currency Code", "Exchange Rate"),
Seq("1", "2021-01-04", "USD", "0.690236"),
Seq("2", "2021-01-05", "USD", "0.690627"),
Seq("3", "2021-01-06", "USD", "0.689332")
)
)
// Incrementally build table by adding value sequences
val table2 = t2.TableBuilder()
.add("#", "Effective Date", "Currency Code", "Exchange Rate")
.add("1", "2021-01-04", "USD", "0.690236")
.add("2", "2021-01-05", "USD", "0.690627")
.add("3", "2021-01-06", "USD", "0.689332")
.build()
// Assert equality
assert(table1.rows == table2.rows)
- See also:
- Companion:
- object
Defines table builder.
Defines table builder.
Usage
Below is an example of how to create and use the default TableBuilder.
// Build table with first row as table header
val table = t2.TableBuilder()
.add("#", "Effective Date", "Currency Code", "Exchange Rate")
.add("1", "2021-01-04", "USD", "0.690236")
.add("2", "2021-01-05", "USD", "0.690627")
.add("3", "2021-01-06", "USD", "0.689332")
.build()
- See also:
- Companion:
- object
Defines table writer.
Defines table writer.
Usage
Below is an example of how to create, configure, and use the default
TableWriter.
// Build table with first row as table header
val table = t2.TableBuilder()
.add("#", "Effective Date", "Currency Code", "Exchange Rate")
.add("1", "2021-01-04", "USD", "0.690236")
.add("2", "2021-01-05", "USD", "0.690627")
.add("3", "2021-01-06", "USD", "0.689332")
.build()
// Create table writer with supplied configuration
val writer = t2.TableWriter(
"ansiColorEnabled" -> "true",
"tableBorderColor" -> "cyan",
"tableHeaderColor" -> "black,yellowBackground",
"bodyRuleColor" -> "yellow",
"rowHeaderEnabled" -> "true",
"rowHeaderColor" -> "bold,cyan",
"columnRightAlign" -> "0,3" // Right align first and last columns
)
// Write table to stdout
writer.write(System.out, table)
The table writer can be configured for changing such things as cell padding, character used for table borders, and more.
- See also:
- Companion:
- object
Provides TableWriter factory.
Provides TableWriter factory.
Writer Configuration
The following keys can be supplied to configure writer.
| Key | Default Value |
|---|---|
| ansiColorEnabled | "false" |
| defaultColor † | AnsiColor.RESET |
| leftMarginSize | "0" |
| rightMarginSize | "0" |
| tableBorderEnabled | "true" |
| tableBorderColor † | defaultColor |
| tableBorderChar | "=" |
| tableHeaderEnabled | "true" |
| tableHeaderColor † | defaultColor |
| tableFooterEnabled | "false" |
| tableFooterColor † | defaultColor |
| bodyRuleEnabled | "true" |
| bodyRuleColor † | defaultColor |
| bodyRuleChar | "-" |
| rowHeaderEnabled | "false" |
| rowHeaderColor † | defaultColor |
| columnRightAlign ‡ | "" |
| cellColor † | defaultColor |
| cellPadSize | "1" |
| cellSpaceSize | "0" |
| cellSpaceColor † | "" |
| maxValueSize | "20" |
| nullValue | "" |
| truncateEnabled | "true" |
† Defined as AnsiColor values (e.g., AnsiColor.BLACK).
‡ Defined as comma- or space-delimited list of column indexes.
ANSI colors can also be suppplied as a comma- or space-delimited list of any combination of following values:
- reset
- bold
- underlined
- blink
- reversed
- invisible
- black
- red
- green
- yellow
- blue
- magenta
- cyan
- white
- blackBackground
- redBackground
- greenBackground
- yellowBackground
- blueBackground
- magentaBackground
- cyanBackground
- whiteBackground
- Companion:
- class