Skip to content

Package io.github.qishr.cascara.common.util

Class TextTable

java.lang.Object
        io.github.qishr.cascara.common.util.CommandLine.Help.TextTable

Enclosing Class:
    io.github.qishr.cascara.common.util.CommandLine.Help


public static class TextTable

Responsible for spacing out Text values according to the Column definitions the table was created with.Columns have a width, indentation, and an overflow policy that decides what to do if a value is longer than the column's width.

Nested Class Summary

Modifier and Type Class Description
public static io.github.qishr.cascara.common.util.CommandLine.Help.TextTable.Cell Helper class to index positions in a Help.TextTable.

Field Summary

Modifier and Type Field Description
protected final List columnValues The char[] slots of the TextTable to copy text values into.
public int indentWrappedLines By default, indent wrapped lines by 2 spaces.

Constructor Summary

Constructor Description
TextTable(Ansi ansi, Column[] columns)
TextTable(ColorScheme colorScheme, Column[] columns)

Method Summary

Modifier and Type Method Description
public static TextTable forDefaultColumns(Ansi ansi, int usageHelpWidth) Constructs a TextTable with five columns as follows: required option/parameter marker (width: 2, indent: 0, TRUNCATE on overflow) short option name (width: 2, indent: 0, TRUNCATE on overflow) comma separator (width: 1, indent: 0, TRUNCATE on overflow) long option name(s) (width: 24, indent: 1, SPAN multiple columns on overflow) description line(s) (width: 51, indent: 1, WRAP to next row on overflow)
public static TextTable forDefaultColumns(Ansi ansi, int longOptionsColumnWidth, int usageHelpWidth) Constructs a TextTable with five columns as follows: required option/parameter marker (width: 2, indent: 0, TRUNCATE on overflow) short option name (width: 2, indent: 0, TRUNCATE on overflow) comma separator (width: 1, indent: 0, TRUNCATE on overflow) long option name(s) (width: 24, indent: 1, SPAN multiple columns on overflow) description line(s) (width: 51, indent: 1, WRAP to next row on overflow)
public static TextTable forDefaultColumns(ColorScheme colorScheme, int longOptionsColumnWidth, int usageHelpWidth) Constructs a TextTable with five columns as follows: required option/parameter marker (width: 2, indent: 0, TRUNCATE on overflow) short option name (width: 2, indent: 0, TRUNCATE on overflow) comma separator (width: 1, indent: 0, TRUNCATE on overflow) long option name(s) (width: 24, indent: 1, SPAN multiple columns on overflow) description line(s) (width: 51, indent: 1, WRAP to next row on overflow)
public static TextTable forColumnWidths(Ansi ansi, int[] columnWidths) Constructs a new TextTable with columns with the specified width, all SPANning multiple columns on overflow except the last column which WRAPS to the next row.
public static TextTable forColumnWidths(ColorScheme colorScheme, int[] columnWidths) Constructs a new TextTable with columns with the specified width, all SPANning multiple columns on overflow except the last column which WRAPS to the next row.
public static TextTable forColumns(Ansi ansi, Column[] columns) Constructs a TextTable with the specified columns.
public static TextTable forColumns(ColorScheme colorScheme, Column[] columns) Constructs a TextTable with the specified columns.
public boolean isAdjustLineBreaksForWideCJKCharacters()
public TextTable setAdjustLineBreaksForWideCJKCharacters(boolean adjustLineBreaksForWideCJKCharacters)
public Column[] columns() The column definitions of this table.
public Text textAt(int row, int col) Returns the Text slot at the specified row and column to write a text value into.
public Text cellAt(int row, int col) Returns the Text slot at the specified row and column to write a text value into.
public int rowCount() Returns the current number of rows of this TextTable.
public void addEmptyRow() Adds the required char[] slots for a new row to the #columnValues field.
public void addRowValues(String[] values) Delegates to addRowValues.addRowValues, after ensuring that multi-line values are layed out in the correct row and column.
public void addRowValues(Text[] values) Adds a new TextTable.addEmptyRow, then calls TextTable.putValue for each of the specified values, adding more empty rows if the return value indicates that the value spanned multiple columns or was wrapped to multiple rows.
public Cell putValue(int row, int col, Text value) Writes the specified value into the cell at the specified row and column and returns the last row and column written to.
public StringBuilder toString(StringBuilder text) Copies the text representation that we built up from the options into the specified StringBuilder.
public String toString()

Field Details

columnValues

protected final List columnValues

The char[] slots of the TextTable to copy text values into.


indentWrappedLines

public int indentWrappedLines

By default, indent wrapped lines by 2 spaces.


Method Details

forDefaultColumns

public static TextTable forDefaultColumns(Ansi ansi, int usageHelpWidth)

Constructs a TextTable with five columns as follows:

required option/parameter marker (width: 2, indent: 0, TRUNCATE on overflow) short option name (width: 2, indent: 0, TRUNCATE on overflow) comma separator (width: 1, indent: 0, TRUNCATE on overflow) long option name(s) (width: 24, indent: 1, SPAN multiple columns on overflow) description line(s) (width: 51, indent: 1, WRAP to next row on overflow)

Deprecation

use forDefaultColumns.forDefaultColumns instead

Parameters:

ansi - whether to emit ANSI escape codes or not

usageHelpWidth - the total width of the columns combined


forDefaultColumns

public static TextTable forDefaultColumns(Ansi ansi, int longOptionsColumnWidth, int usageHelpWidth)

Constructs a TextTable with five columns as follows:

required option/parameter marker (width: 2, indent: 0, TRUNCATE on overflow) short option name (width: 2, indent: 0, TRUNCATE on overflow) comma separator (width: 1, indent: 0, TRUNCATE on overflow) long option name(s) (width: 24, indent: 1, SPAN multiple columns on overflow) description line(s) (width: 51, indent: 1, WRAP to next row on overflow)

Deprecation

use forDefaultColumns.forDefaultColumns instead

Parameters:

ansi - whether to emit ANSI escape codes or not

longOptionsColumnWidth - the width of the long options column

usageHelpWidth - the total width of the columns combined


forDefaultColumns

public static TextTable forDefaultColumns(ColorScheme colorScheme, int longOptionsColumnWidth, int usageHelpWidth)

Constructs a TextTable with five columns as follows:

required option/parameter marker (width: 2, indent: 0, TRUNCATE on overflow) short option name (width: 2, indent: 0, TRUNCATE on overflow) comma separator (width: 1, indent: 0, TRUNCATE on overflow) long option name(s) (width: 24, indent: 1, SPAN multiple columns on overflow) description line(s) (width: 51, indent: 1, WRAP to next row on overflow)

Parameters:

colorScheme - the styles and ANSI mode to use for embedded markup

longOptionsColumnWidth - the width of the long options column

usageHelpWidth - the total width of the columns combined

Since:

4.2


forColumnWidths

public static TextTable forColumnWidths(Ansi ansi, int[] columnWidths)

Constructs a new TextTable with columns with the specified width, all SPANning multiple columns on overflow except the last column which WRAPS to the next row.

Deprecation

use forColumns.forColumns instead

Parameters:

ansi - whether to emit ANSI escape codes or not

columnWidths - the width of each table column (all columns have zero indent)


forColumnWidths

public static TextTable forColumnWidths(ColorScheme colorScheme, int[] columnWidths)

Constructs a new TextTable with columns with the specified width, all SPANning multiple columns on overflow except the last column which WRAPS to the next row.

Parameters:

colorScheme - the styles and ANSI mode to use for embedded markup

columnWidths - the width of each table column (all columns have zero indent)

Since:

4.2


forColumns

public static TextTable forColumns(Ansi ansi, Column[] columns)

Constructs a TextTable with the specified columns.

Deprecation

use forColumns.forColumns instead

Parameters:

ansi - whether to emit ANSI escape codes or not

columns - columns to construct this TextTable with


forColumns

public static TextTable forColumns(ColorScheme colorScheme, Column[] columns)

Constructs a TextTable with the specified columns.

Parameters:

colorScheme - the styles and ANSI mode to use for embedded markup

columns - columns to construct this TextTable with

Since:

4.2


isAdjustLineBreaksForWideCJKCharacters

public boolean isAdjustLineBreaksForWideCJKCharacters()

Since:

4.0

See Also:

adjustLineBreaksForWideCJKCharacters


setAdjustLineBreaksForWideCJKCharacters

public TextTable setAdjustLineBreaksForWideCJKCharacters(boolean adjustLineBreaksForWideCJKCharacters)

Since:

4.0

See Also:

adjustLineBreaksForWideCJKCharacters


columns

public Column[] columns()

The column definitions of this table.


textAt

public Text textAt(int row, int col)

Returns the Text slot at the specified row and column to write a text value into.

Parameters:

row - the row of the cell whose Text to return

col - the column of the cell whose Text to return

Returns:

the Text object at the specified row and column

Since:

2.0


cellAt

public Text cellAt(int row, int col)

Returns the Text slot at the specified row and column to write a text value into.

Deprecation

use textAt.textAt instead

Parameters:

row - the row of the cell whose Text to return

col - the column of the cell whose Text to return

Returns:

the Text object at the specified row and column


rowCount

public int rowCount()

Returns the current number of rows of this TextTable.

Returns:

the current number of rows in this TextTable


addEmptyRow

public void addEmptyRow()

Adds the required char[] slots for a new row to the #columnValues field.


addRowValues

public void addRowValues(String[] values)

Delegates to addRowValues.addRowValues, after ensuring that multi-line values are layed out in the correct row and column.

Parameters:

values - the text values to display in each column of the current row


addRowValues

public void addRowValues(Text[] values)

Adds a new TextTable.addEmptyRow, then calls TextTable.putValue for each of the specified values, adding more empty rows if the return value indicates that the value spanned multiple columns or was wrapped to multiple rows.

Parameters:

values - the values to write into a new row in this TextTable


putValue

public Cell putValue(int row, int col, Text value)

Writes the specified value into the cell at the specified row and column and returns the last row and column written to.Depending on the Column's Column#overflow policy, the value may span multiple columns or wrap to multiple rows when larger than the column width.

Parameters:

row - the target row in the table

col - the target column in the table to write to

value - the value to write

Returns:

a Cell indicating the position in the table that was last written to (since 2.0)

Since:

2.0 (previous versions returned a java.awt.Point object)


toString

public StringBuilder toString(StringBuilder text)

Copies the text representation that we built up from the options into the specified StringBuilder.

Parameters:

text - the StringBuilder to write into

Returns:

the specified StringBuilder object (to allow method chaining and a more fluid API)


toString

public String toString()