List of usage examples for org.apache.commons.lang3.text StrBuilder appendPadding
public StrBuilder appendPadding(final int length, final char padChar)
From source file:de.vandermeer.asciilist.AbstractAsciiListItem.java
@Override public String render(int preLabelIndent, String preLabelStr, String label, String postLabelStr, int postLabelIndent) { StrBuilder ret = new StrBuilder(50); ret.appendPadding(preLabelIndent, ' ').append(preLabelStr); ret.append(label);// w w w . jav a2s . c o m ret.append(postLabelStr).appendPadding(postLabelIndent, ' '); ret.append(this.content); return ret.toString(); }
From source file:de.vandermeer.asciilist.DescriptionListItem.java
/** * Renders the list item, generates a string representation of it. * @param preLabelIndent indentation before the label (and before the pre-label string) * @param preLabelStr a string to be printed after pre-indentation but before the label * @param postLabelStr a string to be printed right after the label but before the post-indentation * @param postLabelIndent indentation after the post-label string (before the actual item content) * @param singleLine flag to render for single line (true) or multiline (false) * @return rendered list item//from w w w . j a va 2 s . com */ public String render(int preLabelIndent, String preLabelStr, String postLabelStr, int postLabelIndent, boolean singleLine) { StrBuilder ret = new StrBuilder(50); ret.appendPadding(preLabelIndent, ' ').append(preLabelStr); ret.append(this.term); ret.append(postLabelStr); if (singleLine == false) { ret.append(AsciiList.IMPLICIT_NEWLINE); } ret.appendPadding(postLabelIndent, ' '); ret.append(this.content); return ret.toString(); }
From source file:de.vandermeer.asciithemes.TA_Line_Char.java
/** * Returns a line of given length.// www. j a v a 2s .c om * @param length number of characters in the line * @param builder builder to append the line to, new builder will be created if null * @return line of given length, empty if length was null or negative */ default StrBuilder getLine(int length, StrBuilder builder) { StrBuilder ret = (builder == null) ? new StrBuilder(length) : builder; ret.appendPadding(length, this.getLineChar()); return ret; }
From source file:de.vandermeer.asciithemes.TA_Line_SplitChar.java
/** * Returns a line of given length.//from w w w . ja va2 s . c om * @param length number of characters in the line * @param builder builder to append the line to, new builder will be created if null * @return line of given length, empty if length was null or negative */ default StrBuilder getLine(int length, StrBuilder builder) { StrBuilder ret = new StrBuilder(); if (length < 1) { return (builder == null) ? ret : builder; } ret.appendPadding(length / 2, this.getLeftLineChar()); while (ret.length() < length) { ret.appendPadding(1, this.getRightLineChar()); } return (builder == null) ? ret : builder.append(ret); }
From source file:de.vandermeer.skb.interfaces.application.App_CliParser.java
/** * Prints usage information for the CLI parser including all CLI options. * @param width the console columns or width of each output line * @return list of lines with usage information *///from w w w . ja va 2 s .c om default ArrayList<StrBuilder> usage(int width) { TreeMap<String, ApoBaseC> map = CliOptionList.sortedMap(this.getAllOptions(), this.numberShort(), this.numberLong()); Map<String, String> helpMap = new LinkedHashMap<>(); int length = 0; STGroupFile stg = new STGroupFile("de/vandermeer/skb/interfaces/application/help.stg"); for (Object option : map.values()) { ST sto = stg.getInstanceOf("option"); String description = null; if (ClassUtils.isAssignable(option.getClass(), Apo_SimpleC.class)) { sto.add("cliShort", ((Apo_SimpleC) option).getCliShort()); sto.add("cliLong", ((Apo_SimpleC) option).getCliLong()); description = ((Apo_SimpleC) option).getDescription(); } if (ClassUtils.isAssignable(option.getClass(), Apo_TypedC.class)) { sto.add("cliShort", ((Apo_TypedC<?>) option).getCliShort()); sto.add("cliLong", ((Apo_TypedC<?>) option).getCliLong()); sto.add("argName", ((Apo_TypedC<?>) option).getCliArgumentName()); sto.add("argOptional", ((Apo_TypedC<?>) option).cliArgIsOptional()); description = ((Apo_TypedC<?>) option).getDescription(); } String line = sto.render(); if (line.length() > length) { length = line.length(); } helpMap.put(line, description); } length += 4; ArrayList<StrBuilder> ret = new ArrayList<>(); for (Entry<String, String> entry : helpMap.entrySet()) { StrBuilder argLine = new StrBuilder(); argLine.append(entry.getKey()).appendPadding(length - argLine.length(), ' '); StrBuilder padLine = new StrBuilder(); padLine.appendPadding(length, ' '); Collection<StrBuilder> text = Text_To_FormattedText.left(entry.getValue(), width - length); int i = 0; for (StrBuilder b : text) { if (i == 0) { b.insert(0, argLine); } else { b.insert(0, padLine); } ret.add(b); i++; } } return ret; }
From source file:de.vandermeer.asciithemes.TA_EnumerateList.java
@Override default StrBuilder toDoc() { if (this.getMaxLevel() == 0) { throw new IllegalArgumentException("enumerate list toDoc: max level is 0"); }// w w w. j a v a2 s . c o m if (this.getMaxLevel() < -1) { throw new IllegalArgumentException("enumerate list toDoc: max level is < -1"); } StrBuilder ret = new StrBuilder(30); ret.append(this.getLabel(1)).append(" item 1").appendNewLine(); ret.append(this.getLabel(1)).append(" item 2"); int n = 2; if (this.getMaxLevel() == -1 || this.getMaxLevel() >= n) { ret.appendNewLine(); ret.appendPadding(2 * (n - 1), ' ').append(this.getLabel(2)).append(" item 1").appendNewLine(); ret.appendPadding(2 * (n - 1), ' ').append(this.getLabel(2)).append(" item 2"); } n = 3; if (this.getMaxLevel() == -1 || this.getMaxLevel() >= n) { ret.appendNewLine(); ret.appendPadding(2 * (n - 1), ' ').append(this.getLabel(3)).append(" item 1").appendNewLine(); ret.appendPadding(2 * (n - 1), ' ').append(this.getLabel(3)).append(" item 2").appendNewLine(); } ret.appendNewLine(); ret.append(this.getLabel(new int[] { 1 }, ".", true)).append(" item 1").appendNewLine(); ret.append(this.getLabel(new int[] { 1, 2 }, ".", true)).append(" item 1/2").appendNewLine(); ret.append(this.getLabel(new int[] { 1, 2, 3 }, ".", true)).append(" item 1/2/3").appendNewLine(); ret.append(this.getLabel(new int[] { 1, 2, 3, 4 }, ".", true)).append(" item 1/2/3/4").appendNewLine(); ret.append(this.getLabel(new int[] { 1, 2, 3, 4, 5 }, ".", true)).append(" item 1/2/3/4/5"); return ret; }
From source file:de.vandermeer.asciithemes.TA_ItemizeList.java
@Override default StrBuilder toDoc() { if (this.getMaxLevel() == 0) { throw new IllegalArgumentException("itemize list toDoc: max level is 0"); }/*from w w w . j a va2s . c o m*/ if (this.getMaxLevel() < -1) { throw new IllegalArgumentException("itemize list toDoc: max level is < -1"); } StrBuilder ret = new StrBuilder(30); ret.append(this.getLabel(1)).append(" item 1").appendNewLine(); ret.append(this.getLabel(1)).append(" item 2"); int n = 2; if (this.getMaxLevel() == -1 || this.getMaxLevel() >= n) { ret.appendNewLine(); ret.appendPadding(2 * (n - 1), ' ').append(this.getLabel(2)).append(" item 1").appendNewLine(); ret.appendPadding(2 * (n - 1), ' ').append(this.getLabel(2)).append(" item 2"); } n = 3; if (this.getMaxLevel() == -1 || this.getMaxLevel() >= n) { ret.appendNewLine(); ret.appendPadding(2 * (n - 1), ' ').append(this.getLabel(3)).append(" item 1").appendNewLine(); ret.appendPadding(2 * (n - 1), ' ').append(this.getLabel(3)).append(" item 2"); } n = 4; if (this.getMaxLevel() == -1 || this.getMaxLevel() >= n) { ret.appendNewLine(); ret.appendPadding(2 * (n - 1), ' ').append(this.getLabel(4)).append(" item 1").appendNewLine(); ret.appendPadding(2 * (n - 1), ' ').append(this.getLabel(4)).append(" item 2"); } n = 5; if (this.getMaxLevel() == -1 || this.getMaxLevel() >= n) { ret.appendNewLine(); ret.appendPadding(2 * (n - 1), ' ').append(this.getLabel(5)).append(" item 1").appendNewLine(); ret.appendPadding(2 * (n - 1), ' ').append(this.getLabel(5)).append(" item 2"); } n = 6; if (this.getMaxLevel() == -1 || this.getMaxLevel() >= n) { ret.appendNewLine(); ret.appendPadding(2 * (n - 1), ' ').append(this.getLabel(6)).append(" item 1").appendNewLine(); ret.appendPadding(2 * (n - 1), ' ').append(this.getLabel(6)).append(" item 2"); } return ret; }
From source file:de.vandermeer.asciithemes.TA_Checklist.java
@Override default StrBuilder toDoc() { if (this.getMaxLevel() == 0) { throw new IllegalArgumentException("checklist toDoc: max level is 0"); }/* w w w. j a va 2 s . c o m*/ if (this.getMaxLevel() < -1) { throw new IllegalArgumentException("checklist toDoc: max level is < -1"); } StrBuilder ret = new StrBuilder(30); ret.append(this.getLabel(1, true)).append(" checked item").appendNewLine(); ret.append(this.getLabel(1, false)).append(" unchecked item"); int n = 2; if (this.getMaxLevel() == -1 || this.getMaxLevel() >= n) { ret.appendNewLine(); ret.appendPadding(2 * (n - 1), ' ').append(this.getLabel(2, true)).append(" checked item") .appendNewLine(); ret.appendPadding(2 * (n - 1), ' ').append(this.getLabel(2, false)).append(" unchecked item"); } n = 3; if (this.getMaxLevel() == -1 || this.getMaxLevel() >= n) { ret.appendNewLine(); ret.appendPadding(2 * (n - 1), ' ').append(this.getLabel(3, true)).append(" checked item") .appendNewLine(); ret.appendPadding(2 * (n - 1), ' ').append(this.getLabel(3, false)).append(" unchecked item"); } n = 4; if (this.getMaxLevel() == -1 || this.getMaxLevel() >= n) { ret.appendNewLine(); ret.appendPadding(2 * (n - 1), ' ').append(this.getLabel(4, true)).append(" checked item") .appendNewLine(); ret.appendPadding(2 * (n - 1), ' ').append(this.getLabel(4, false)).append(" unchecked item"); } n = 5; if (this.getMaxLevel() == -1 || this.getMaxLevel() >= n) { ret.appendNewLine(); ret.appendPadding(2 * (n - 1), ' ').append(this.getLabel(5, true)).append(" checked item") .appendNewLine(); ret.appendPadding(2 * (n - 1), ' ').append(this.getLabel(5, false)).append(" unchecked item"); } n = 6; if (this.getMaxLevel() == -1 || this.getMaxLevel() >= n) { ret.appendNewLine(); ret.appendPadding(2 * (n - 1), ' ').append(this.getLabel(6, true)).append(" checked item") .appendNewLine(); ret.appendPadding(2 * (n - 1), ' ').append(this.getLabel(6, false)).append(" unchecked item"); } return ret; }
From source file:de.vandermeer.skb.interfaces.application.IsApplication.java
/** * Prints a help screen for the application, to be used by an executing component. *//*from ww w . j av a2 s . c o m*/ default void appHelpScreen() { STGroupFile stg = new STGroupFile("de/vandermeer/skb/interfaces/application/help.stg"); ST st = stg.getInstanceOf("usage"); st.add("appName", this.getAppName()); st.add("appDisplayName", this.getAppDisplayName()); st.add("appVersion", this.getAppVersion()); st.add("appDescription", Text_To_FormattedText.left(this.getAppDescription(), this.getConsoleWidth())); st.add("required", CliOptionList.getRequired(getCLiALlOptions())); for (StrBuilder sb : this.getCliParser().usage(this.getConsoleWidth())) { st.add("cliOptions", sb); } if (this.getEnvironmentOptions().size() > 0) { TreeMap<String, Apo_TypedE<?>> map = EnvironmentOptionsList.sortedMap(this.getEnvironmentOptions()); Map<String, String> envMap = new LinkedHashMap<>(); int length = 0; for (Apo_TypedE<?> te : map.values()) { if (te.getEnvironmentKey().length() > length) { length = te.getEnvironmentKey().length(); } envMap.put(te.getEnvironmentKey(), te.getDescription()); } length += 2; for (Entry<String, String> entry : envMap.entrySet()) { StrBuilder argLine = new StrBuilder(); argLine.append(entry.getKey()).appendPadding(length - argLine.length(), ' ').append(" - "); StrBuilder padLine = new StrBuilder(); padLine.appendPadding(length + 4, ' '); Collection<StrBuilder> text = Text_To_FormattedText.left(entry.getValue(), this.getConsoleWidth() - length); int i = 0; for (StrBuilder b : text) { if (i == 0) { st.add("envOptions", argLine + b.build()); } else { st.add("envOptions", padLine + b.build()); } i++; } } } if (this.getPropertyOptions().size() > 0) { TreeMap<String, Apo_TypedP<?>> map = PropertyOptionsList.sortedMap(this.getPropertyOptions()); Map<String, String> envMap = new LinkedHashMap<>(); int length = 0; for (Apo_TypedP<?> te : map.values()) { if (te.getPropertyKey().length() > length) { length = te.getPropertyKey().length(); } envMap.put(te.getPropertyKey(), te.getDescription()); } length += 2; for (Entry<String, String> entry : envMap.entrySet()) { StrBuilder argLine = new StrBuilder(); argLine.append(entry.getKey()).appendPadding(length - argLine.length(), ' ').append(" - "); StrBuilder padLine = new StrBuilder(); padLine.appendPadding(length + 4, ' '); Collection<StrBuilder> text = Text_To_FormattedText.left(entry.getValue(), this.getConsoleWidth() - length); int i = 0; for (StrBuilder b : text) { if (i == 0) { st.add("propOptions", argLine + b.build()); } else { st.add("propOptions", padLine + b.build()); } i++; } } } System.out.println(st.render()); }
From source file:de.vandermeer.asciithemes.TA_Frame.java
/** * Renders a bottom line for the frame./*from w w w .j a v a 2s . com*/ * @param mode the frame mode * @param width the width of lines in the frame * @return a builder with bottom line, empty if none was created */ default StrBuilder renderBottomLine(int mode, int width) { StrBuilder ret = new StrBuilder(width); if (TA_FrameOptions.cornerBottomLeft(mode)) { ret.append(this.getCorner().getCorner(TA_Corner.MODE_BOTTOM_LEFT)); } else if (TA_FrameOptions.cornerBottomLeftNeeded(mode)) { ret.appendPadding(this.getCorner().getCorner(TA_Corner.MODE_BOTTOM_LEFT).length(), ' '); } if (TA_FrameOptions.lineBottom(mode)) { ret.append(this.getBottomline().getLine(width)); } else if (TA_FrameOptions.lineBottomNeeded(mode)) { ret.appendPadding(width, ' '); } if (TA_FrameOptions.cornerBottomRight(mode)) { ret.append(this.getCorner().getCorner(TA_Corner.MODE_BOTTOM_RIGHT)); } else if (TA_FrameOptions.cornerBottomRightNeeded(mode)) { ret.appendPadding(this.getCorner().getCorner(TA_Corner.MODE_BOTTOM_RIGHT).length(), ' '); } return ret; }