Struct Formatter

the formatter collects format parameters and prints the table

struct Formatter ;

Constructors

NameDescription
this (newTable, parts)

Fields

NameTypeDescription
mBottomBorder bool
mColumnSeparator bool
mColumnWidths ulong[]
mHeaderSeparator bool
mLeftBorder bool
mParts Parts
mPrefix string
mRightBorder bool
mRowSeparator bool
mTopBorder bool
table AsciiTable

Methods

NameDescription
borders (borders)
bottomBorder (bottomBorder)
calcHorizontalSeparator (normal, left, middle, right)
columnSeparator (columnSeparator) change the separator between columns, use null for no separator
columnWidths (widths)
headerSeparator (headerSeparator)
horizontalBorders (borders) Switch top and bottom border
leftBorder (leftBorder)
parts (parts)
prefix (newPrefix) change the prefix that is printed in front of each row
rightBorder (rightBorder)
rowSeparator (rowSeparator) change the separator between rows, use null for no separator
separators (active)
topBorder (topBorder)
toString () Convert to tabular presentation
verticalBorders (borders) Switch left and right border
calcSeparatorRow (length, s)
renderRow (row)
toString (table, row, last, headerSeparator, rowSeparator)
updateCellWidths ()

Example

import unit_threaded;
import std.conv;

// dfmt off
auto table = new AsciiTable(2)
   .header.add("HA").add("HB")
   .row.add("C").add("D")
   .row.add("E").add("F")
   .table;

auto f1 = table
   .format
   .parts(new UnicodeParts)
   .borders(true)
   .separators(true)
   .to!string;
// dfmt on
std.stdio.writeln(f1);
f1.shouldEqual(`┌──┬──┐
│HA│HB│
╞══╪══╡
│C │D │
├──┼──┤
│E │F │
└──┴──┘`);

// dfmt off
auto f2 = table
   .format
   .parts(new UnicodeParts)
   .prefix("  ")
   .rowSeparator(true)
   .to!string;
// dfmt on
f2.shouldEqual(`  HAHB
─────
C D 
─────
E F `);
// dfmt off
auto f3 = table
   .format
   .parts(new UnicodeParts)
   .columnSeparator(true)
   .to!string;
// dfmt on
f3.shouldEqual(`HA│HB
C │D 
E │F `);

Example

import unit_threaded;

auto table = new AsciiTable(2).row.add("1\n2").add("3").row.add("4").add("5\n6").table;
auto f = table.format.prefix("test:").to!string;
f.shouldEqual(`test:13
test:2 
test:45
test: 6`);

Example

import unit_threaded;

auto table = new AsciiTable(1).header.add("1").row.add(2).table;
auto f1 = table.format.headerSeparator(true).rowSeparator(true)
    .topBorder(true).bottomBorder(true).to!string;
f1.shouldEqual(`-
1
=
2
-`);