@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()); }
lines.add(inputLine.toAttributedString()); errorLine.append(CliStrings.DEFAULT_MARGIN + CliStrings.INPUT_ERROR); lines.add(AttributedString.EMPTY); lines.add(errorLine.toAttributedString());
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(); }
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()); }
statusLine.append(right); return Arrays.asList(statusLine.toAttributedString(), AttributedString.EMPTY);
@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); }
lines.add(row.toAttributedString());
public static AttributedString messageInfo(String message) { return new AttributedStringBuilder() .style(AttributedStyle.DEFAULT.bold().foreground(AttributedStyle.BLUE)) .append("[INFO] ") .append(message) .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 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 AttributedString formatCommand(SqlCommand cmd, String description) { return new AttributedStringBuilder() .style(AttributedStyle.DEFAULT.bold()) .append(cmd.toString()) .append("\t\t") .style(AttributedStyle.DEFAULT) .append(description) .append('\n') .toAttributedString(); } }
/** * Evaluate expression. * * @param expression the expression to evaluate * @return the result string */ public AttributedString evaluate(final String expression) { AttributedStringBuilder buff = new AttributedStringBuilder(); evaluate(buff, expression); return buff.toAttributedString(); } }
public static AttributedString append(CharSequence... strings) { AttributedStringBuilder sb = new AttributedStringBuilder(); for (CharSequence s : strings) { sb.append(s); } return sb.toAttributedString(); }
public static AttributedString join(AttributedString delimiter, Iterable<AttributedString> elements) { Objects.requireNonNull(elements); AttributedStringBuilder sb = new AttributedStringBuilder(); int i = 0; for (AttributedString str : elements) { if (i++ > 0 && delimiter != null) { sb.append(delimiter); } sb.append(str); } return sb.toAttributedString(); }
public static AttributedString fromAnsi(String ansi, int tabs) { if (ansi == null) { return null; } return new AttributedStringBuilder(ansi.length()) .tabs(tabs) .ansiAppend(ansi) .toAttributedString(); }
@Override public AttributedString highlight(LineReader reader, String buffer) { int l = 0; String best = null; for (String command : shell.listCommands().keySet()) { if (buffer.startsWith(command) && command.length() > l) { l = command.length(); best = command; } } if (best != null) { return new AttributedStringBuilder(buffer.length()).append(best, AttributedStyle.BOLD).append(buffer.substring(l)).toAttributedString(); } else { return new AttributedString(buffer, AttributedStyle.DEFAULT.foreground(AttributedStyle.RED)); } } })
/** * Compute the full string to be displayed with the left, right and secondary prompts * @param secondaryPrompts a list to store the secondary prompts * @return the displayed string including the buffer, left prompts and the help below */ public AttributedString getDisplayedBufferWithPrompts(List<AttributedString> secondaryPrompts) { AttributedString attBuf = getHighlightedBuffer(buf.toString()); AttributedString tNewBuf = insertSecondaryPrompts(attBuf, secondaryPrompts); AttributedStringBuilder full = new AttributedStringBuilder().tabs(TAB_WIDTH); full.append(prompt); full.append(tNewBuf); if (post != null) { full.append("\n"); full.append(post.get()); } return full.toAttributedString(); }
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(); }
private AttributedString addRightPrompt(AttributedString prompt, AttributedString line) { int width = prompt.columnLength(); boolean endsWithNl = line.length() > 0 && line.charAt(line.length() - 1) == '\n'; // columnLength counts -1 for the final newline; adjust for that int nb = size.getColumns() - width - (line.columnLength() + (endsWithNl ? 1 : 0)); if (nb >= 3) { AttributedStringBuilder sb = new AttributedStringBuilder(size.getColumns()); sb.append(line, 0, endsWithNl ? line.length() - 1 : line.length()); for (int j = 0; j < nb; j++) { sb.append(' '); } sb.append(prompt); if (endsWithNl) { sb.append('\n'); } line = sb.toAttributedString(); } return line; }