/** Parses the specified comma-separated sequence of style descriptors and returns the associated * styles. For each markup, strings starting with {@code "bg("} are delegated to * {@link #bg(String)}, others are delegated to {@link #bg(String)}. * @param commaSeparatedCodes one or more descriptors, e.g. {@code "bg(blue),underline,red"} * @return an array with all styles for the specified descriptors */ public static IStyle[] parse(String commaSeparatedCodes) { String[] codes = commaSeparatedCodes.split(","); IStyle[] styles = new IStyle[codes.length]; for(int i = 0; i < codes.length; ++i) { if (codes[i].toLowerCase(ENGLISH).startsWith("fg(")) { int end = codes[i].indexOf(')'); styles[i] = Style.fg(codes[i].substring(3, end < 0 ? codes[i].length() : end)); } else if (codes[i].toLowerCase(ENGLISH).startsWith("bg(")) { int end = codes[i].indexOf(')'); styles[i] = Style.bg(codes[i].substring(3, end < 0 ? codes[i].length() : end)); } else { styles[i] = Style.fg(codes[i]); } } return styles; } }
/** Parses the specified style markup and returns the associated style. * The markup may be one of the Style enum value names, or it may be one of the Style enum value * names when {@code "bg_"} is prepended, or it may be one of the indexed colors in the 256 color palette. * @param str the case-insensitive style markup to convert, e.g. {@code "blue"} or {@code "bg_blue"}, * or {@code "46"} (indexed color) or {@code "0;5;0"} (RGB components of an indexed color) * @return the IStyle for the specified converter */ public static IStyle bg(String str) { try { return Style.valueOf(str.toLowerCase(ENGLISH)); } catch (Exception ignored) {} try { return Style.valueOf("bg_" + str.toLowerCase(ENGLISH)); } catch (Exception ignored) {} return new Palette256Color(false, str); } /** Parses the specified comma-separated sequence of style descriptors and returns the associated
/** Parses the specified comma-separated sequence of style descriptors and returns the associated * styles. For each markup, strings starting with {@code "bg("} are delegated to * {@link #bg(String)}, others are delegated to {@link #bg(String)}. * @param commaSeparatedCodes one or more descriptors, e.g. {@code "bg(blue),underline,red"} * @return an array with all styles for the specified descriptors */ public static IStyle[] parse(String commaSeparatedCodes) { String[] codes = commaSeparatedCodes.split(","); IStyle[] styles = new IStyle[codes.length]; for(int i = 0; i < codes.length; ++i) { if (codes[i].toLowerCase(ENGLISH).startsWith("fg(")) { int end = codes[i].indexOf(')'); styles[i] = Style.fg(codes[i].substring(3, end < 0 ? codes[i].length() : end)); } else if (codes[i].toLowerCase(ENGLISH).startsWith("bg(")) { int end = codes[i].indexOf(')'); styles[i] = Style.bg(codes[i].substring(3, end < 0 ? codes[i].length() : end)); } else { styles[i] = Style.fg(codes[i]); } } return styles; } }
/** * Returns a new Text object where all the specified styles are applied to the full length of the * specified plain text. * @param plainText the string to apply all styles to. Must not contain markup! * @param styles the styles to apply to the full plain text * @return a new Text object */ public Text apply(String plainText, List<IStyle> styles) { if (plainText.length() == 0) { return new Text(0); } Text result = new Text(plainText.length()); IStyle[] all = styles.toArray(new IStyle[styles.size()]); result.sections.add(new StyledSection( 0, plainText.length(), Style.on(all), Style.off(reverse(all)) + Style.reset.off())); result.plain.append(plainText); result.length = result.plain.length(); return result; }
/** Parses the specified style markup and returns the associated style. * The markup may be one of the Style enum value names, or it may be one of the Style enum value * names when {@code "bg_"} is prepended, or it may be one of the indexed colors in the 256 color palette. * @param str the case-insensitive style markup to convert, e.g. {@code "blue"} or {@code "bg_blue"}, * or {@code "46"} (indexed color) or {@code "0;5;0"} (RGB components of an indexed color) * @return the IStyle for the specified converter */ public static IStyle bg(String str) { try { return Style.valueOf(str.toLowerCase(ENGLISH)); } catch (Exception ignored) {} try { return Style.valueOf("bg_" + str.toLowerCase(ENGLISH)); } catch (Exception ignored) {} return new Palette256Color(false, str); } /** Parses the specified comma-separated sequence of style descriptors and returns the associated
private void replace(List<IStyle> styles, String property) { if (property != null) { styles.clear(); addAll(styles, Style.parse(property)); } } private ColorScheme addAll(List<IStyle> styles, IStyle... add) {
/** Parses the specified style markup and returns the associated style. * The markup may be one of the Style enum value names, or it may be one of the Style enum value * names when {@code "fg_"} is prepended, or it may be one of the indexed colors in the 256 color palette. * @param str the case-insensitive style markup to convert, e.g. {@code "blue"} or {@code "fg_blue"}, * or {@code "46"} (indexed color) or {@code "0;5;0"} (RGB components of an indexed color) * @return the IStyle for the specified converter */ public static IStyle fg(String str) { try { return Style.valueOf(str.toLowerCase(ENGLISH)); } catch (Exception ignored) {} try { return Style.valueOf("fg_" + str.toLowerCase(ENGLISH)); } catch (Exception ignored) {} return new Palette256Color(true, str); } /** Parses the specified style markup and returns the associated style.
/** * Returns a new Text object where all the specified styles are applied to the full length of the * specified plain text. * @param plainText the string to apply all styles to. Must not contain markup! * @param styles the styles to apply to the full plain text * @return a new Text object */ public Text apply(String plainText, List<IStyle> styles) { if (plainText.length() == 0) { return new Text(0); } Text result = new Text(plainText.length()); IStyle[] all = styles.toArray(new IStyle[styles.size()]); result.sections.add(new StyledSection( 0, plainText.length(), Style.on(all), Style.off(reverse(all)) + Style.reset.off())); result.plain.append(plainText); result.length = result.plain.length(); return result; }
/** Parses the specified style markup and returns the associated style. * The markup may be one of the Style enum value names, or it may be one of the Style enum value * names when {@code "fg_"} is prepended, or it may be one of the indexed colors in the 256 color palette. * @param str the case-insensitive style markup to convert, e.g. {@code "blue"} or {@code "fg_blue"}, * or {@code "46"} (indexed color) or {@code "0;5;0"} (RGB components of an indexed color) * @return the IStyle for the specified converter */ public static IStyle fg(String str) { try { return Style.valueOf(str.toLowerCase(ENGLISH)); } catch (Exception ignored) {} try { return Style.valueOf("fg_" + str.toLowerCase(ENGLISH)); } catch (Exception ignored) {} return new Palette256Color(true, str); } /** Parses the specified style markup and returns the associated style.
private void replace(List<IStyle> styles, String property) { if (property != null) { styles.clear(); addAll(styles, Style.parse(property)); } } private ColorScheme addAll(List<IStyle> styles, IStyle... add) {