losizm / t2   2.0.0

Apache License 2.0 Website GitHub

Utility for text tables

Scala versions: 3.x 2.13 2.12

t2

Utility for text tables.

Maven Central

Getting Started

To get started, add t2 to your project:

libraryDependencies += "com.github.losizm" %% "t2" % "2.0.0"

NOTE: Starting with version 1.0, t2 is written for Scala 3. See previous releases for compatibility with Scala 2.12 and 2.13.

Usage

Below is an example of t2 in action. Here it builds a table and writes the content to stdout.

// 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 generated output would look something like the following if printed to a color-enabled terminal:

API Documentation

See scaladoc for additional details.

License

t2 is licensed under the Apache License, Version 2. See LICENSE for more information.