Packages

  • package root
    Definition Classes
    root
  • package t2

    Defines types to create, access, and print tables.

    Defines types to create, access, and print tables.

    Getting Started

    Below is an example of how to use TableBuilder and TableWriter. Using these utilities, 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.

    ===================================================
      #  Effective Date  Currency Code  Exchange Rate  
    ---------------------------------------------------
      1  2021-01-04      USD                 0.690236
      2  2021-01-05      USD                 0.690627
      3  2021-01-06      USD                 0.689332
    ===================================================
    

    The table writer can be configured for changing such things as cell padding, character used for table borders, and more.

    Definition Classes
    root
  • Table
  • TableBuilder
  • TableWriter
p

t2

package t2

Defines types to create, access, and print tables.

Getting Started

Below is an example of how to use TableBuilder and TableWriter. Using these utilities, 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.

===================================================
  #  Effective Date  Currency Code  Exchange Rate  
---------------------------------------------------
  1  2021-01-04      USD                 0.690236
  2  2021-01-05      USD                 0.690627
  3  2021-01-06      USD                 0.689332
===================================================

The table writer can be configured for changing such things as cell padding, character used for table borders, and more.

Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. t2
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Type Members

  1. trait Table extends AnyRef

    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

    Table.forRows, Table.forColumns, TableBuilder

  2. trait TableBuilder extends AnyRef

    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

    TableBuilder.forRows, TableBuilder.forColumns

  3. trait TableWriter extends AnyRef

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

    ===================================================
      #  Effective Date  Currency Code  Exchange Rate  
    ---------------------------------------------------
      1  2021-01-04      USD                 0.690236
      2  2021-01-05      USD                 0.690627
      3  2021-01-06      USD                 0.689332
    ===================================================
    

    The table writer can be configured for changing such things as cell padding, character used for table borders, and more.

    See also

    TableWriter(Map[String, String]), TableWriter((String,String)*)

Value Members

  1. object Table

    Provides Table factory.

  2. object TableBuilder

    Provides TableBuilder factory.

  3. object TableWriter

    Provides TableWriter factory.

Inherited from AnyRef

Inherited from Any

Ungrouped