use of org.jline.utils.AttributedString in project flink by apache.
the class CliView method display.
protected void display() {
// cache
final List<AttributedString> headerLines = getHeaderLines();
final List<AttributedString> mainHeaderLines = getMainHeaderLines();
final List<AttributedString> mainLines = getMainLines();
final List<AttributedString> footerLines = getFooterLines();
final int visibleMainHeight = getVisibleMainHeight();
final int totalMainWidth = getTotalMainWidth();
// create output
client.clearTerminal();
final List<String> lines = new ArrayList<>();
// title part
client.getTerminal().writer().println(computeTitleLine().toAnsi());
// header part
headerLines.forEach(l -> client.getTerminal().writer().println(l.toAnsi()));
// update vertical offset
if (visibleMainHeight > mainLines.size()) {
// enough space
offsetY = 0;
} else {
// bound offset
offsetY = Math.min(mainLines.size() - visibleMainHeight, offsetY);
}
// update horizontal offset
if (width > totalMainWidth) {
// enough space
offsetX = 0;
} else {
// bound offset
offsetX = Math.min(totalMainWidth - width, offsetX);
}
// create window
final List<AttributedString> windowedMainLines = mainLines.subList(offsetY, Math.min(mainLines.size(), offsetY + visibleMainHeight));
// print window
Stream.concat(mainHeaderLines.stream(), windowedMainLines.stream()).forEach(l -> {
if (offsetX < l.length()) {
final AttributedString windowX = l.substring(offsetX, Math.min(l.length(), offsetX + width));
client.getTerminal().writer().println(windowX.toAnsi());
} else {
client.getTerminal().writer().println();
}
});
// footer part
final int emptyHeight = height - 1 - headerLines.size() - // -1 = title
windowedMainLines.size() - mainHeaderLines.size() - footerLines.size();
// padding
IntStream.range(0, emptyHeight).forEach(i -> client.getTerminal().writer().println());
// footer
IntStream.range(0, footerLines.size()).forEach((i) -> {
final AttributedString l = footerLines.get(i);
if (i == footerLines.size() - 1) {
client.getTerminal().writer().print(l.toAnsi());
} else {
client.getTerminal().writer().println(l.toAnsi());
}
});
client.getTerminal().flush();
}
use of org.jline.utils.AttributedString in project flink by apache.
the class CliChangelogResultView method computeMainHeaderLines.
@Override
protected List<AttributedString> computeMainHeaderLines() {
// add change column
List<String> columnNames = new ArrayList<>(columnWidths.length);
columnNames.add("op");
columnNames.addAll(resultDescriptor.getResultSchema().getColumnNames());
final AttributedStringBuilder schemaHeader = new AttributedStringBuilder();
IntStream.range(0, columnNames.size()).forEach(idx -> {
schemaHeader.style(AttributedStyle.DEFAULT);
schemaHeader.append(' ');
schemaHeader.style(AttributedStyle.DEFAULT.underline());
normalizeColumn(schemaHeader, columnNames.get(idx), columnWidths[idx]);
});
return Collections.singletonList(schemaHeader.toAttributedString());
}
use of org.jline.utils.AttributedString in project flink by apache.
the class CliInputView method computeMainLines.
@Override
protected List<AttributedString> computeMainLines() {
final List<AttributedString> lines = new ArrayList<>();
// space
IntStream.range(0, getVisibleMainHeight() / 2 - 2).forEach((i) -> lines.add(AttributedString.EMPTY));
// title
lines.add(new AttributedString(CliStrings.DEFAULT_MARGIN + inputTitle));
// input line
final AttributedStringBuilder inputLine = new AttributedStringBuilder();
inputLine.append(CliStrings.DEFAULT_MARGIN + "> ");
final String input = currentInput.toString();
// add string left of cursor
inputLine.append(currentInput.substring(0, cursorPos));
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 {
// show the cursor at the end
inputLine.append(' ');
}
lines.add(inputLine.toAttributedString());
// isError
if (isError) {
final AttributedStringBuilder errorLine = new AttributedStringBuilder();
errorLine.style(AttributedStyle.DEFAULT.foreground(AttributedStyle.RED));
errorLine.append(CliStrings.DEFAULT_MARGIN + CliStrings.INPUT_ERROR);
lines.add(AttributedString.EMPTY);
lines.add(errorLine.toAttributedString());
}
return lines;
}
use of org.jline.utils.AttributedString in project flink by apache.
the class CliRowView method computeMainLines.
@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;
}
use of org.jline.utils.AttributedString in project flink by apache.
the class CliTableResultView method computeMainHeaderLines.
@Override
protected List<AttributedString> computeMainHeaderLines() {
final AttributedStringBuilder schemaHeader = new AttributedStringBuilder();
IntStream.range(0, resultDescriptor.getResultSchema().getColumnCount()).forEach(idx -> {
schemaHeader.style(AttributedStyle.DEFAULT);
schemaHeader.append(' ');
String columnName = resultDescriptor.getResultSchema().getColumnNames().get(idx);
schemaHeader.style(AttributedStyle.DEFAULT.underline());
normalizeColumn(schemaHeader, columnName, columnWidths[idx]);
});
return Collections.singletonList(schemaHeader.toAttributedString());
}
Aggregations