ocean.io.console.Tables

Classes to draw auto-formatted tables to the console.

The number of columns in the table must be specified either at construction, or by calling the init() method. Rows can be be added using the firstRow() & nextRow() methods. (firstRow() is essentially a reset method.)

Usage example:

// A table with 3 columns
scope table = new Table(3);

// First row is just a divider
table.firstRow.setDivider();

// Next row contains the headings, a series of strings
table.nextRow.set(
    Table.Cell.String("Address"),
    Table.Cell.String("Port"),
    Table.Cell.String("Connections"));

// Next row is another divider
table.nextRow.setDivider();

// Now we add one row for each of a set of 'nodes'
foreach ( node; this.nodes )
{
    table.nextRow.set(
        Table.Cell.String(node.address),
        Table.Cell.Integer(node.port),
        Table.Cell.Integer(node.connections));
}

// The last row is another divider
table.nextRow.setDivider();

// Display the table to Stdout
table.display();

It's also possible to draw smart tables where certain cells in some rows are merged together, something like this, for example:

|-----------------------------------------------------|
| 0xdb6db6e4 .. 0xedb6db76 | 0xedb6db77 .. 0xffffffff |
|-----------------------------------------------------|
|    Records |       Bytes |    Records |       Bytes |
|-----------------------------------------------------|
|     26,707 |  11,756,806 |     27,072 |  11,918,447 |
|      6,292 |   1,600,360 |      6,424 |   1,628,086 |
|  1,177,809 |  56,797,520 |  1,176,532 |  56,736,224 |
|-----------------------------------------------------|

In this example, columns 0 & 1 and 2 & 3 in row 1 are merged.

Merged cells usage example:

// A table with 4 columns
scope table = new Table(4);

// First row is just a divider
table.firstRow.setDivider();

// Next row contains a hash range occupying two (merged) cells. Note
// that this is the widest column -- the other columns adapt to allow it
// to fit.
table.nextRow.set(Table.Cell.Merged, Table.Cell.String("0xdb6db6e4 .. 0xedb6db76"),
                  Table.Cell.Merged, Table.Cell.String("0xedb6db77 .. 0xffffffff"));

// Next row is another divider
table.nextRow.setDivider();

// Next row contains the headings, a series of strings
table.nextRow.set(Table.Cell.String("Records"), Table.Cell.String("Bytes"),
                  Table.Cell.String("Records"), Table.Cell.String("Bytes"));

// Next row is another divider
table.nextRow.setDivider();

// Now we add one row for each of a set of 'nodes'
foreach ( node; this.nodes )
{
    table.nextRow.set(Table.Cell.Integer(node.records1), Table.Cell.Integer(node.bytes1),
                      Table.Cell.Integer(node.records2), Table.Cell.Integer(node.bytes2));
}

// The last row is another divider
table.nextRow.setDivider();

// Display the table to Stdout
table.display();

Members

Classes

Table
class Table

Table

Meta

License

Boost Software License Version 1.0. See LICENSE_BOOST.txt for details. Alternatively, this file may be distributed under the terms of the Tango 3-Clause BSD License (see LICENSE_BSD.txt for details).