@Override protected List<AttributedString> computeMainHeaderLines() { final AttributedStringBuilder schemaHeader = new AttributedStringBuilder(); Arrays.stream(resultDescriptor.getResultSchema().getFieldNames()).forEach(s -> { schemaHeader.append(' '); schemaHeader.style(AttributedStyle.DEFAULT.underline()); normalizeColumn(schemaHeader, s, MAX_COLUMN_WIDTH); schemaHeader.style(AttributedStyle.DEFAULT); }); return Collections.singletonList(schemaHeader.toAttributedString()); }
@Override protected List<AttributedString> computeMainHeaderLines() { final AttributedStringBuilder schemaHeader = new AttributedStringBuilder(); // add change column schemaHeader.append(' '); schemaHeader.style(AttributedStyle.DEFAULT.underline()); schemaHeader.append("+/-"); schemaHeader.style(AttributedStyle.DEFAULT); Arrays.stream(resultDescriptor.getResultSchema().getFieldNames()).forEach(s -> { schemaHeader.append(' '); schemaHeader.style(AttributedStyle.DEFAULT.underline()); normalizeColumn(schemaHeader, s, MAX_COLUMN_WIDTH); schemaHeader.style(AttributedStyle.DEFAULT); }); return Collections.singletonList(schemaHeader.toAttributedString()); }
public static List<AttributedString> formatTwoLineHelpOptions(int width, List<Tuple2<String, String>> options) { final AttributedStringBuilder line1 = new AttributedStringBuilder(); final AttributedStringBuilder line2 = new AttributedStringBuilder(); // we assume that every options has not more than 11 characters (+ key and space) final int columns = (int) Math.ceil(((double) options.size()) / 2); final int space = (width - CliStrings.DEFAULT_MARGIN.length() - columns * 13) / columns; final Iterator<Tuple2<String, String>> iter = options.iterator(); while (iter.hasNext()) { // first line Tuple2<String, String> option = iter.next(); line1.style(AttributedStyle.DEFAULT.inverse()); line1.append(option.f0); line1.style(AttributedStyle.DEFAULT); line1.append(' '); line1.append(option.f1); repeatChar(line1, ' ', (11 - option.f1.length()) + space); // second line if (iter.hasNext()) { option = iter.next(); line2.style(AttributedStyle.DEFAULT.inverse()); line2.append(option.f0); line2.style(AttributedStyle.DEFAULT); line2.append(' '); line2.append(option.f1); repeatChar(line2, ' ', (11 - option.f1.length()) + space); } } return Arrays.asList(line1.toAttributedString(), line2.toAttributedString()); }
inputLine.style(AttributedStyle.DEFAULT.inverse().blink()); if (cursorPos < input.length()) { inputLine.append(input.charAt(cursorPos)); inputLine.style(AttributedStyle.DEFAULT); inputLine.append(input.substring(cursorPos + 1, input.length())); } else { errorLine.style(AttributedStyle.DEFAULT.foreground(AttributedStyle.RED)); errorLine.append(CliStrings.DEFAULT_MARGIN + CliStrings.INPUT_ERROR); lines.add(AttributedString.EMPTY);
private AttributedString computeTitleLine() { final String title = getTitle(); final AttributedStringBuilder titleLine = new AttributedStringBuilder(); titleLine.style(AttributedStyle.INVERSE); final int totalMargin = width - title.length(); final int margin = totalMargin / 2; repeatChar(titleLine, ' ', margin); titleLine.append(title); repeatChar(titleLine, ' ', margin + (totalMargin % 2)); return titleLine.toAttributedString(); }
@Override protected List<AttributedString> computeHeaderLines() { final AttributedStringBuilder statusLine = new AttributedStringBuilder(); statusLine.style(AttributedStyle.INVERSE);
@Override protected List<AttributedString> computeMainLines() { final List<AttributedString> lines = new ArrayList<>(); final AttributedStringBuilder sb = new AttributedStringBuilder(); IntStream.range(0, row.length).forEach(i -> { final String name = columnNames[i]; final String type = columnTypes[i]; sb.setLength(0); sb.append(CliStrings.DEFAULT_MARGIN); sb.style(AttributedStyle.BOLD); sb.append(name); sb.append(" ("); sb.append(type); sb.append(')'); sb.append(':'); lines.add(sb.toAttributedString()); sb.setLength(0); sb.append(CliStrings.DEFAULT_MARGIN); sb.style(AttributedStyle.DEFAULT); sb.append(row[i]); lines.add(sb.toAttributedString()); lines.add(AttributedString.EMPTY); }); return lines; }
@Override protected List<AttributedString> computeHeaderLines() { final AttributedStringBuilder statusLine = new AttributedStringBuilder(); statusLine.style(AttributedStyle.INVERSE); // left final String left; if (isRetrieving()) { left = CliStrings.DEFAULT_MARGIN + CliStrings.RESULT_REFRESH_INTERVAL + ' ' + REFRESH_INTERVALS.get(refreshInterval).f0; } else { left = CliStrings.DEFAULT_MARGIN + CliStrings.RESULT_STOPPED; } // right final String right; if (lastRetrieval == null) { right = CliStrings.RESULT_LAST_REFRESH + ' ' + CliStrings.RESULT_REFRESH_UNKNOWN + CliStrings.DEFAULT_MARGIN; } else { right = CliStrings.RESULT_LAST_REFRESH + ' ' + lastRetrieval.format(TIME_FORMATTER) + CliStrings.DEFAULT_MARGIN; } // all together final int middleSpace = getWidth() - left.length() - right.length(); statusLine.append(left); repeatChar(statusLine, ' ', middleSpace); statusLine.append(right); return Arrays.asList(statusLine.toAttributedString(), AttributedString.EMPTY); }
public static AttributedString messageInfo(String message) { return new AttributedStringBuilder() .style(AttributedStyle.DEFAULT.bold().foreground(AttributedStyle.BLUE)) .append("[INFO] ") .append(message) .toAttributedString(); }
public static AttributedString messageError(String message, String s) { final AttributedStringBuilder builder = new AttributedStringBuilder() .style(AttributedStyle.DEFAULT.bold().foreground(AttributedStyle.RED)) .append("[ERROR] ") .append(message); if (s != null) { builder .append(" Reason:\n") .append(s); } return builder.toAttributedString(); }
private static void applyStyle(AttributedStringBuilder sb, Map<String, String> colors, String type) { String col = colors.get(type); sb.style(AttributedStyle.DEFAULT); if (col != null && !col.isEmpty()) { sb.appendAnsi("\033[" + col + "m"); } }
private static void applyStyle(AttributedStringBuilder sb, Map<String, String> colors, String type) { String col = colors.get(type); sb.style(AttributedStyle.DEFAULT); if (col != null && !col.isEmpty()) { sb.appendAnsi("\033[" + col + "m"); } }
@Override public String getContent(String content) { String in = super.getContent(content); AttributedStringBuilder sb = new AttributedStringBuilder(); sb.style(sb.style().foreground(color)); if (bold) sb.style(sb.style().bold()); sb.append(in); if (bold) sb.style(sb.style().boldOff()); sb.style(sb.style().foregroundOff()); return sb.toAnsi(); }
static void applyStyle(AttributedStringBuilder sb, Map<String, String> colors, String... types) { String t = null; for (String type : types) { if (colors.get(type) != null) { t = type; break; } } sb.style(new StyleResolver(colors::get).resolve("." + t)); }
private static void addHighlightedTextToBuilder(String output, String textToHighlight, AttributedStringBuilder builder) { String[] split = output.split(textToHighlight); for (int i = 0; i < split.length - 1; i++) { builder.append(split[i]) .style(SshSessionContext.<AttributedStyle>get(HIGHLIGHT_COLOR)) .append(textToHighlight) .style(SshSessionContext.<AttributedStyle>get(TEXT_STYLE)); } builder.append(split[split.length - 1]); }
public AttributedString highlight(LineReader reader, String buffer) { AttributedStringBuilder builder = new AttributedStringBuilder(); List<String> tokens = splitWithSpace(buffer); for (String token : tokens) { if (isKeyword(token)) { builder.style(AttributedStyle.BOLD.foreground(AttributedStyle.YELLOW)) .append(token); } else { builder.style(AttributedStyle.DEFAULT) .append(token); } } return builder.toAttributedString(); }