Class CommandLine.Help.TextTable
java.lang.Object
org.apache.logging.log4j.core.tools.picocli.CommandLine.Help.TextTable
- Enclosing class:
- CommandLine.Help
Responsible for spacing out CommandLine.Help.Ansi.Text
values according to the CommandLine.Help.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
Nested ClassesModifier and TypeClassDescriptionstatic class
Helper class to index positions in aHelp.TextTable
. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final CommandLine.Help.Ansi
final CommandLine.Help.Column[]
The column definitions of this table.protected final List<CommandLine.Help.Ansi.Text>
Thechar[]
slots of theTextTable
to copy text values into.int
By default, indent wrapped lines by 2 spaces. -
Constructor Summary
ConstructorsConstructorDescriptionConstructs 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)TextTable
(CommandLine.Help.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.TextTable
(CommandLine.Help.Ansi ansi, CommandLine.Help.Column... columns) Constructs aTextTable
with the specified columns. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds the requiredchar[]
slots for a new row to thecolumnValues
field.void
addRowValues
(String... values) Delegates toaddRowValues(CommandLine.Help.Ansi.Text...)
.void
addRowValues
(CommandLine.Help.Ansi.Text... values) cellAt
(int row, int col) Deprecated.private int
copy
(BreakIterator line, CommandLine.Help.Ansi.Text text, CommandLine.Help.Ansi.Text columnValue, int offset) private static int
copy
(CommandLine.Help.Ansi.Text value, CommandLine.Help.Ansi.Text destination, int offset) private static int
putValue
(int row, int col, CommandLine.Help.Ansi.Text value) Writes the specified value into the cell at the specified row and column and returns the last row and column written to.int
rowCount()
Returns the current number of rows of thisTextTable
.textAt
(int row, int col) Returns theText
slot at the specified row and column to write a text value into.toString()
toString
(StringBuilder text) Copies the text representation that we built up from the options into the specified StringBuilder.
-
Field Details
-
columns
The column definitions of this table. -
columnValues
Thechar[]
slots of theTextTable
to copy text values into. -
indentWrappedLines
public int indentWrappedLinesBy default, indent wrapped lines by 2 spaces. -
ansi
-
-
Constructor Details
-
TextTable
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:
ansi
- whether to emit ANSI escape codes or not
-
TextTable
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:
ansi
- whether to emit ANSI escape codes or notcolumnWidths
- the width of the table columns (all columns have zero indent)
-
TextTable
Constructs aTextTable
with the specified columns.- Parameters:
ansi
- whether to emit ANSI escape codes or notcolumns
- columns to construct this TextTable with
-
-
Method Details
-
textAt
Returns theText
slot at the specified row and column to write a text value into.- Parameters:
row
- the row of the cell whose Text to returncol
- the column of the cell whose Text to return- Returns:
- the Text object at the specified row and column
- Since:
- 2.0
-
cellAt
Deprecated.usetextAt(int, int)
insteadReturns theText
slot at the specified row and column to write a text value into.- Parameters:
row
- the row of the cell whose Text to returncol
- 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 thisTextTable
.- Returns:
- the current number of rows in this TextTable
-
addEmptyRow
public void addEmptyRow()Adds the requiredchar[]
slots for a new row to thecolumnValues
field. -
addRowValues
Delegates toaddRowValues(CommandLine.Help.Ansi.Text...)
.- Parameters:
values
- the text values to display in each column of the current row
-
addRowValues
Adds a new empty row, then callsputValue
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- Throws:
IllegalArgumentException
- if the number of values exceeds the number of Columns in this table
-
putValue
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'sOverflow
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 tablecol
- the target column in the table to write tovalue
- the value to write- Returns:
- a Cell indicating the position in the table that was last written to (since 2.0)
- Throws:
IllegalArgumentException
- if the specified row exceeds the table's row count- Since:
- 2.0 (previous versions returned a
java.awt.Point
object)
-
length
-
copy
private int copy(BreakIterator line, CommandLine.Help.Ansi.Text text, CommandLine.Help.Ansi.Text columnValue, int offset) -
copy
private static int copy(CommandLine.Help.Ansi.Text value, CommandLine.Help.Ansi.Text destination, int offset) -
toString
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
-
textAt(int, int)
instead