@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()); }
final AttributedStringBuilder inputLine = new AttributedStringBuilder(); inputLine.append(CliStrings.DEFAULT_MARGIN + "> "); final String input = currentInput.toString(); final AttributedStringBuilder errorLine = new AttributedStringBuilder(); errorLine.style(AttributedStyle.DEFAULT.foreground(AttributedStyle.RED)); errorLine.append(CliStrings.DEFAULT_MARGIN + CliStrings.INPUT_ERROR);
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()); }
@Override protected List<AttributedString> computeHeaderLines() { final AttributedStringBuilder statusLine = new AttributedStringBuilder(); statusLine.style(AttributedStyle.INVERSE);
@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); }
final AttributedStringBuilder row = new AttributedStringBuilder();
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> 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> 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(); } }
prompt = new AttributedStringBuilder() .style(AttributedStyle.DEFAULT.foreground(AttributedStyle.GREEN)) .append("Flink SQL")
public AnsiBufferedReader(InputStream in, int begin, int end, int maxLength) { this.reader = new BufferedReader(new InputStreamReader(in)); this.begin = begin; this.end = end; this.maxLength = maxLength; this.builder = new AttributedStringBuilder(); this.lines = new ArrayList<>(); }
public AnsiBufferedReader(InputStream in, int begin, int end, int maxLength) { this.reader = new BufferedReader(new InputStreamReader(in)); this.begin = begin; this.end = end; this.maxLength = maxLength; this.builder = new AttributedStringBuilder(); this.lines = new ArrayList<>(); }
public static List<String> splitLines(String text, int maxLength, int tabs) throws IOException { AttributedStringBuilder sb = new AttributedStringBuilder(); sb.tabs(tabs); sb.appendAnsi(text); return sb.columnSplitLength(maxLength) .stream() .map(AttributedString::toAnsi) .collect(Collectors.toList()); }
public static AttributedString append(CharSequence... strings) { AttributedStringBuilder sb = new AttributedStringBuilder(); for (CharSequence s : strings) { sb.append(s); } return sb.toAttributedString(); }
public static int length(String text, int tabs) throws IOException { AttributedStringBuilder sb = new AttributedStringBuilder(); sb.tabs(tabs); sb.appendAnsi(text); return sb.columnLength(); }
public static int length(String text, int tabs) throws IOException { AttributedStringBuilder sb = new AttributedStringBuilder(); sb.tabs(tabs); sb.appendAnsi(text); return sb.columnLength(); }
public static String substring(String text, int begin, int end, int tabs) throws IOException { AttributedStringBuilder sb = new AttributedStringBuilder(); sb.tabs(tabs); sb.appendAnsi(text); return sb.columnSubSequence(begin, end).toAnsi(); }