public Text[][] render(PositionalParamSpec param, IParamLabelRenderer paramLabelRenderer, ColorScheme scheme) { Text label = paramLabelRenderer.renderParameterLabel(param, scheme.ansi(), scheme.parameterStyles); Text requiredParameter = scheme.parameterText(param.arity().min > 0 ? requiredMarker : ""); Text EMPTY = Ansi.EMPTY_TEXT; boolean[] showDefault = {param.internalShowDefaultValue(showDefaultValues)}; List<Text[]> result = new ArrayList<Text[]>(); String[] description = param.renderedDescription(); Text[] descriptionFirstLines = createDescriptionFirstLines(scheme, param, description, showDefault); result.add(new Text[] { requiredParameter, EMPTY, EMPTY, label, descriptionFirstLines[0] }); for (int i = 1; i < descriptionFirstLines.length; i++) { result.add(new Text[] { EMPTY, EMPTY, EMPTY, EMPTY, descriptionFirstLines[i] }); } for (int i = 1; i < description.length; i++) { Text[] descriptionNextLines = scheme.ansi().new Text(description[i]).splitLines(); for (Text line : descriptionNextLines) { result.add(new Text[] { EMPTY, EMPTY, EMPTY, EMPTY, line }); } } if (showDefault[0]) { addTrailingDefaultLine(result, param, scheme); } return result.toArray(new Text[result.size()][]); } }
private Text[][] renderDescriptionLines(OptionSpec option, ColorScheme scheme, String requiredOption, String shortOption, Text longOptionText) { Text EMPTY = Ansi.EMPTY_TEXT; boolean[] showDefault = {option.internalShowDefaultValue(showDefaultValues)}; List<Text[]> result = new ArrayList<Text[]>(); String[] description = option.renderedDescription(); Text[] descriptionFirstLines = createDescriptionFirstLines(scheme, option, description, showDefault); result.add(new Text[] { scheme.optionText(requiredOption), scheme.optionText(shortOption), scheme.ansi().new Text(sep), longOptionText, descriptionFirstLines[0] }); for (int i = 1; i < descriptionFirstLines.length; i++) { result.add(new Text[] { EMPTY, EMPTY, EMPTY, EMPTY, descriptionFirstLines[i] }); } for (int i = 1; i < description.length; i++) { Text[] descriptionNextLines = scheme.ansi().new Text(description[i]).splitLines(); for (Text line : descriptionNextLines) { result.add(new Text[] { EMPTY, EMPTY, EMPTY, EMPTY, line }); } } if (showDefault[0]) { addTrailingDefaultLine(result, option, scheme); } return result.toArray(new Text[result.size()][]); } }
private static void addTrailingDefaultLine(List<Text[]> result, ArgSpec arg, ColorScheme scheme) { Text EMPTY = Ansi.EMPTY_TEXT; result.add(new Text[]{EMPTY, EMPTY, EMPTY, EMPTY, scheme.ansi().new Text(" Default: " + arg.defaultValueString())}); }
/** Returns a Text with all option styles applied to the specified option string. * @param option the option string to apply the registered option styles to * @return a Text with all option styles applied to the specified option string */ public Ansi.Text optionText(String option) { return ansi().apply(option, optionStyles); } /** Returns a Text with all parameter styles applied to the specified parameter string.
@Test public void testTextDefaultColorScheme() { Ansi ansi = Ansi.ON; CommandLine.Help.ColorScheme scheme = CommandLine.Help.defaultColorScheme(ansi); assertEquals(scheme.ansi().new Text("@|yellow -p|@"), scheme.optionText("-p")); assertEquals(scheme.ansi().new Text("@|bold command|@"), scheme.commandText("command")); assertEquals(scheme.ansi().new Text("@|yellow FILE|@"), scheme.parameterText("FILE")); assertEquals(scheme.ansi().new Text("@|italic NUMBER|@"), scheme.optionParamText("NUMBER")); }
/** Constructs a Layout with the specified color scheme, a new default TextTable, the * {@linkplain Help#createDefaultOptionRenderer() default option renderer}, and the * {@linkplain Help#createDefaultParameterRenderer() default parameter renderer}. * @param colorScheme the color scheme to use for common, auto-generated parts of the usage help message */ public Layout(ColorScheme colorScheme, int tableWidth) { this(colorScheme, TextTable.forDefaultColumns(colorScheme.ansi(), tableWidth)); }
if (!option.hidden()) { Text name = colorScheme.optionText(option.shortestName()); Text param = parameterLabelRenderer().renderParameterLabel(option, colorScheme.ansi(), colorScheme.optionParamStyles); if (option.required()) { // e.g., -x=VAL optionText = optionText.concat(" ").concat(name).concat(param).concat("");
/** Returns a Text object containing a partial detailed synopsis showing only the positional parameters, starting with a {@code " "} space. * Follows the unix convention of showing optional options and parameters in square brackets ({@code [ ]}). * @return the formatted positional parameters, starting with a {@code " "} space, or an empty Text if this command has no positional parameters * @since 3.9 */ protected Text createDetailedSynopsisPositionalsText() { Text positionalParamText = ansi().new Text(0); for (PositionalParamSpec positionalParam : commandSpec.positionalParameters()) { if (!positionalParam.hidden()) { positionalParamText = positionalParamText.concat(" "); Text label = parameterLabelRenderer().renderParameterLabel(positionalParam, colorScheme.ansi(), colorScheme.parameterStyles); positionalParamText = positionalParamText.concat(label); } } return positionalParamText; }
private Text createLongOptionText(OptionSpec option, IParamLabelRenderer renderer, ColorScheme scheme, String longOption) { Text paramLabelText = renderer.renderParameterLabel(option, scheme.ansi(), scheme.optionParamStyles); // if no long option, fill in the space between the short option name and the param label value if (paramLabelText.length > 0 && longOption.length() == 0) { sep = renderer.separator(); // #181 paramLabelText may be =LABEL or [=LABEL...] int sepStart = paramLabelText.plainString().indexOf(sep); Text prefix = paramLabelText.substring(0, sepStart); paramLabelText = prefix.concat(paramLabelText.substring(sepStart + sep.length())); } Text longOptionText = scheme.optionText(longOption); longOptionText = longOptionText.concat(paramLabelText); return longOptionText; }
private Layout createLayout(int longOptionsColumnWidth) { return new Layout(colorScheme, TextTable.forDefaultColumns(colorScheme.ansi(), longOptionsColumnWidth, width()), createDefaultOptionRenderer(), createDefaultParameterRenderer()); }
/** Returns a Text with all optionParam styles applied to the specified optionParam string. * @param optionParam the option parameter string to apply the registered option parameter styles to * @return a Text with all option parameter styles applied to the specified option parameter string */ public Ansi.Text optionParamText(String optionParam) { return ansi().apply(optionParam, optionParamStyles); }
/** Constructs a Layout with the specified color scheme, a new default TextTable, the * {@linkplain Help#createDefaultOptionRenderer() default option renderer}, and the * {@linkplain Help#createDefaultParameterRenderer() default parameter renderer}. * @param colorScheme the color scheme to use for common, auto-generated parts of the usage help message */ public Layout(ColorScheme colorScheme, int tableWidth) { this(colorScheme, TextTable.forDefaultColumns(colorScheme.ansi(), tableWidth)); }
public Text[][] render(OptionSpec option, IParamLabelRenderer parameterLabelRenderer, ColorScheme scheme) { Text optionText = scheme.optionText(option.names()[0]); Text paramLabelText = parameterLabelRenderer.renderParameterLabel(option, scheme.ansi(), scheme.optionParamStyles); optionText = optionText.concat(paramLabelText); return new Text[][] {{ optionText, scheme.ansi().new Text(option.description().length == 0 ? "" : option.description()[0]) }}; } }
@Test public void testColorSchemeDefaultConstructorHasAnsiAuto() { CommandLine.Help.ColorScheme colorScheme = new CommandLine.Help.ColorScheme(); assertEquals(Ansi.AUTO, colorScheme.ansi()); }
/** Returns a Text with all parameter styles applied to the specified parameter string. * @param parameter the parameter string to apply the registered parameter styles to * @return a Text with all parameter styles applied to the specified parameter string */ public Ansi.Text parameterText(String parameter) { return ansi().apply(parameter, parameterStyles); } /** Returns a Text with all optionParam styles applied to the specified optionParam string.
/** Returns a Text with all option styles applied to the specified option string. * @param option the option string to apply the registered option styles to * @return a Text with all option styles applied to the specified option string */ public Ansi.Text optionText(String option) { return ansi().apply(option, optionStyles); } /** Returns a Text with all parameter styles applied to the specified parameter string.
private static Text[] createDescriptionFirstLines(ColorScheme scheme, ArgSpec arg, String[] description, boolean[] showDefault) { Text[] result = scheme.ansi().new Text(str(description, 0)).splitLines(); if (result.length == 0 || (result.length == 1 && result[0].plain.length() == 0)) { if (showDefault[0]) { result = new Text[]{scheme.ansi().new Text(" Default: " + arg.defaultValueString())}; showDefault[0] = false; // don't show the default value twice } else { result = new Text[]{ Ansi.EMPTY_TEXT }; } } return result; }
/** Returns a Text with all command styles applied to the specified command string. * @param command the command string to apply the registered command styles to * @return a Text with all command styles applied to the specified command string */ public Ansi.Text commandText(String command) { return ansi().apply(command, commandStyles); } /** Returns a Text with all option styles applied to the specified option string.
public Text[][] render(PositionalParamSpec param, IParamLabelRenderer parameterLabelRenderer, ColorScheme scheme) { return new Text[][] {{ parameterLabelRenderer.renderParameterLabel(param, scheme.ansi(), scheme.parameterStyles), scheme.ansi().new Text(param.description().length == 0 ? "" : param.description()[0]) }}; } }
@Test public void testTextDefaultColorScheme() { Ansi ansi = Ansi.ON; CommandLine.Help.ColorScheme scheme = CommandLine.Help.defaultColorScheme(ansi); assertEquals(scheme.ansi().new Text("@|yellow -p|@"), scheme.optionText("-p")); assertEquals(scheme.ansi().new Text("@|bold command|@"), scheme.commandText("command")); assertEquals(scheme.ansi().new Text("@|yellow FILE|@"), scheme.parameterText("FILE")); assertEquals(scheme.ansi().new Text("@|italic NUMBER|@"), scheme.optionParamText("NUMBER")); }