Search in sources :

Example 6 with AttributedString

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();
}
Also used : AttributedString(org.jline.utils.AttributedString) ArrayList(java.util.ArrayList) AttributedString(org.jline.utils.AttributedString)

Example 7 with AttributedString

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());
}
Also used : ArrayList(java.util.ArrayList) AttributedStringBuilder(org.jline.utils.AttributedStringBuilder) AttributedString(org.jline.utils.AttributedString)

Example 8 with AttributedString

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;
}
Also used : AttributedString(org.jline.utils.AttributedString) ArrayList(java.util.ArrayList) AttributedStringBuilder(org.jline.utils.AttributedStringBuilder) AttributedString(org.jline.utils.AttributedString)

Example 9 with AttributedString

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;
}
Also used : AttributedString(org.jline.utils.AttributedString) ArrayList(java.util.ArrayList) AttributedStringBuilder(org.jline.utils.AttributedStringBuilder) AttributedString(org.jline.utils.AttributedString)

Example 10 with AttributedString

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());
}
Also used : AttributedStringBuilder(org.jline.utils.AttributedStringBuilder) AttributedString(org.jline.utils.AttributedString)

Aggregations

AttributedString (org.jline.utils.AttributedString)15 AttributedStringBuilder (org.jline.utils.AttributedStringBuilder)14 ArrayList (java.util.ArrayList)6 ImmutableStringReader (com.mojang.brigadier.ImmutableStringReader)1 BufferedReader (java.io.BufferedReader)1 InputStreamReader (java.io.InputStreamReader)1 IntBinaryOperator (java.util.function.IntBinaryOperator)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 EOFError (org.apache.felix.gogo.runtime.EOFError)1 Program (org.apache.felix.gogo.runtime.Parser.Program)1 Statement (org.apache.felix.gogo.runtime.Parser.Statement)1 SyntaxError (org.apache.felix.gogo.runtime.SyntaxError)1 Token (org.apache.felix.gogo.runtime.Token)1 Function (org.apache.felix.service.command.Function)1 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)1 Options (org.jline.builtins.Options)1 Source (org.jline.builtins.Source)1 PathSource (org.jline.builtins.Source.PathSource)1 RegionType (org.jline.reader.LineReader.RegionType)1