Skip to content

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

Class Layout

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

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


public static class Layout

Use a Layout to format usage help text for options and parameters in tabular format.

Delegates to the renderers to create Text values for the annotated fields, and uses a TextTable to display these values in tabular format. Layout is responsible for deciding which values to display where in the table. By default, Layout shows one option or parameter per table row.

Customize by overriding the layout method.

Field Summary

Modifier and Type Field Description
protected final ColorScheme colorScheme
protected IOptionRenderer optionRenderer
protected IParameterRenderer parameterRenderer
protected final TextTable table

Constructor Summary

Constructor Description
Layout(ColorScheme colorScheme, int tableWidth) Constructs a Layout with the specified color scheme, a new default TextTable, the default option renderer, and the default parameter renderer.
Layout(ColorScheme colorScheme, TextTable textTable) Constructs a Layout with the specified color scheme, the specified TextTable, the default option renderer, and the default parameter renderer.
Layout(ColorScheme colorScheme, TextTable textTable, IOptionRenderer optionRenderer, IParameterRenderer parameterRenderer) Constructs a Layout with the specified color scheme, the specified TextTable, the specified option renderer and the specified parameter renderer.

Method Summary

Modifier and Type Method Description
public void layout(ArgSpec argSpec, Text[][] cellValues) Copies the specified text values into the correct cells in the TextTable.
public void addOptions(List<OptionSpec> options, IParamLabelRenderer paramLabelRenderer) Calls addOption.addOption for all non-hidden Options in the list.
public void addAllOptions(List<OptionSpec> options, IParamLabelRenderer paramLabelRenderer) Calls addOption.addOption for all Options in the specified list.
public void addOption(OptionSpec option, IParamLabelRenderer paramLabelRenderer) Delegates to the optionRenderer.optionRenderer of this layout to obtain text values for the specified OptionSpec, and then calls the layout.layout method to write these text values into the correct cells in the TextTable.
public void addPositionalParameters(List<PositionalParamSpec> params, IParamLabelRenderer paramLabelRenderer) Calls addPositionalParameter.addPositionalParameter for all non-hidden Parameters in the list.
public void addAllPositionalParameters(List<PositionalParamSpec> params, IParamLabelRenderer paramLabelRenderer) Calls addPositionalParameter.addPositionalParameter for all positional parameters in the specified list.
public void addPositionalParameter(PositionalParamSpec param, IParamLabelRenderer paramLabelRenderer) Delegates to the parameterRenderer.parameterRenderer of this layout to obtain text values for the specified PositionalParamSpec, and then calls layout.layout to write these text values into the correct cells in the TextTable.
public String toString() Returns the section of the usage help message accumulated in the TextTable owned by this layout.
public ColorScheme colorScheme() Returns the ColorScheme used to create Text objects in this layout.
public TextTable textTable() Returns the TextTable used in this layout.
public IOptionRenderer optionRenderer() Returns the IOptionRenderer used to render options to Text before adding this text to the TextTable in this layout.
public IParameterRenderer parameterRenderer() Returns the IParameterRenderer used to render positional params to Text before adding this text to the TextTable in this layout.

Field Details

colorScheme

protected final ColorScheme colorScheme


optionRenderer

protected IOptionRenderer optionRenderer


parameterRenderer

protected IParameterRenderer parameterRenderer


table

protected final TextTable table


Method Details

layout

public void layout(ArgSpec argSpec, Text[][] cellValues)

Copies the specified text values into the correct cells in the TextTable.This implementation delegates to TextTable#addRowValues(CommandLine.Help.Ansi.Text...) for each row of values.

Subclasses may override.

Parameters:

argSpec - the Option or Parameters

cellValues - the text values representing the Option/Parameters, to be displayed in tabular form

Since:

3.0


addOptions

public void addOptions(List<OptionSpec> options, IParamLabelRenderer paramLabelRenderer)

Calls addOption.addOption for all non-hidden Options in the list.

Parameters:

options - options to add usage descriptions for

paramLabelRenderer - object that knows how to render option parameters

Since:

3.0


addAllOptions

public void addAllOptions(List<OptionSpec> options, IParamLabelRenderer paramLabelRenderer)

Calls addOption.addOption for all Options in the specified list.

Parameters:

options - options to add usage descriptions for; it is the responsibility of the caller to exclude options that should not be shown

paramLabelRenderer - object that knows how to render option parameters

Since:

4.4


addOption

public void addOption(OptionSpec option, IParamLabelRenderer paramLabelRenderer)

Delegates to the optionRenderer.optionRenderer of this layout to obtain text values for the specified OptionSpec, and then calls the layout.layout method to write these text values into the correct cells in the TextTable.

Parameters:

option - the option argument

paramLabelRenderer - knows how to render option parameters

Since:

3.0


addPositionalParameters

public void addPositionalParameters(List<PositionalParamSpec> params, IParamLabelRenderer paramLabelRenderer)

Calls addPositionalParameter.addPositionalParameter for all non-hidden Parameters in the list.

Parameters:

params - positional parameters to add usage descriptions for

paramLabelRenderer - knows how to render option parameters

Since:

3.0


addAllPositionalParameters

public void addAllPositionalParameters(List<PositionalParamSpec> params, IParamLabelRenderer paramLabelRenderer)

Calls addPositionalParameter.addPositionalParameter for all positional parameters in the specified list.

Parameters:

params - positional parameters to add usage descriptions for; it is the responsibility of the caller to exclude positional parameters that should not be shown

paramLabelRenderer - knows how to render option parameters

Since:

4.4


addPositionalParameter

public void addPositionalParameter(PositionalParamSpec param, IParamLabelRenderer paramLabelRenderer)

Delegates to the parameterRenderer.parameterRenderer of this layout to obtain text values for the specified PositionalParamSpec, and then calls layout.layout to write these text values into the correct cells in the TextTable.

Parameters:

param - the positional parameter

paramLabelRenderer - knows how to render option parameters

Since:

3.0


toString

public String toString()

Returns the section of the usage help message accumulated in the TextTable owned by this layout.

Overrides:

Object


colorScheme

public ColorScheme colorScheme()

Returns the ColorScheme used to create Text objects in this layout.

Since:

4.6


textTable

public TextTable textTable()

Returns the TextTable used in this layout.

Since:

4.6


optionRenderer

public IOptionRenderer optionRenderer()

Returns the IOptionRenderer used to render options to Text before adding this text to the TextTable in this layout.

Since:

4.6


parameterRenderer

public IParameterRenderer parameterRenderer()

Returns the IParameterRenderer used to render positional params to Text before adding this text to the TextTable in this layout.

Since:

4.6