Java Code Examples for org.jline.utils.AttributedStringBuilder#style()

The following examples show how to use org.jline.utils.AttributedStringBuilder#style() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SqlLineApplication.java    From Lealone-Plugins with Apache License 2.0 6 votes vote down vote up
@Override
public PromptHandler getPromptHandler(SqlLine sqlLine) {
    if (config.hasPath(PROMPT_WITH_SCHEMA) && config.getBoolean(PROMPT_WITH_SCHEMA)) {
        return new PromptHandler(sqlLine) {
            @Override
            protected AttributedString getDefaultPrompt(int connectionIndex, String url, String defaultPrompt) {
                AttributedStringBuilder builder = new AttributedStringBuilder();
                builder.style(resolveStyle("f:y"));
                builder.append("lealone");

                ConnectionMetadata meta = sqlLine.getConnectionMetadata();

                String currentSchema = meta.getCurrentSchema();
                if (currentSchema != null) {
                    builder.append(" (").append(currentSchema).append(")");
                }
                return builder.style(resolveStyle("default")).append("> ").toAttributedString();
            }
        };
    }
    return super.getPromptHandler(sqlLine);
}
 
Example 2
Source File: CliChangelogResultView.java    From flink with Apache License 2.0 6 votes vote down vote up
@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());
}
 
Example 3
Source File: CliChangelogResultView.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@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());
}
 
Example 4
Source File: CliChangelogResultView.java    From flink with Apache License 2.0 6 votes vote down vote up
@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());
}
 
Example 5
Source File: CliResultView.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
protected List<AttributedString> computeMainLines() {
	final List<AttributedString> lines = new ArrayList<>();

	int lineIdx = 0;
	for (String[] line : results) {
		final AttributedStringBuilder row = new AttributedStringBuilder();

		// highlight selected row
		if (lineIdx == selectedRow) {
			row.style(AttributedStyle.DEFAULT.inverse());
		}

		for (int colIdx = 0; colIdx < line.length; colIdx++) {
			final String col = line[colIdx];
			final int columnWidth = computeColumnWidth(colIdx);

			row.append(' ');
			// check if value was present before last update, if not, highlight it
			// we don't highlight if the retrieval stopped
			// both inverse and bold together do not work correctly
			if (previousResults != null && lineIdx != selectedRow && refreshThread.isRunning &&
					(lineIdx >= previousResults.size() || !col.equals(previousResults.get(lineIdx)[colIdx]))) {
				row.style(AttributedStyle.BOLD);
				normalizeColumn(row, col, columnWidth);
				row.style(AttributedStyle.DEFAULT);
			} else {
				normalizeColumn(row, col, columnWidth);
			}
		}
		lines.add(row.toAttributedString());

		lineIdx++;
	}

	return lines;
}
 
Example 6
Source File: CliView.java    From flink with Apache License 2.0 5 votes vote down vote up
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();
}
 
Example 7
Source File: CliResultView.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
protected List<AttributedString> computeMainLines() {
	final List<AttributedString> lines = new ArrayList<>();

	int lineIdx = 0;
	for (String[] line : results) {
		final AttributedStringBuilder row = new AttributedStringBuilder();

		// highlight selected row
		if (lineIdx == selectedRow) {
			row.style(AttributedStyle.DEFAULT.inverse());
		}

		for (int colIdx = 0; colIdx < line.length; colIdx++) {
			final String col = line[colIdx];
			final int columnWidth = computeColumnWidth(colIdx);

			row.append(' ');
			// check if value was present before last update, if not, highlight it
			// we don't highlight if the retrieval stopped
			// both inverse and bold together do not work correctly
			if (previousResults != null && lineIdx != selectedRow && refreshThread.isRunning &&
					(lineIdx >= previousResults.size() || !col.equals(previousResults.get(lineIdx)[colIdx]))) {
				row.style(AttributedStyle.BOLD);
				normalizeColumn(row, col, columnWidth);
				row.style(AttributedStyle.DEFAULT);
			} else {
				normalizeColumn(row, col, columnWidth);
			}
		}
		lines.add(row.toAttributedString());

		lineIdx++;
	}

	return lines;
}
 
Example 8
Source File: CliInputView.java    From flink with Apache License 2.0 5 votes vote down vote up
@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 {
		inputLine.append(' '); // show the cursor at the end
	}

	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;
}
 
Example 9
Source File: CliChangelogResultView.java    From flink with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 10
Source File: CliUtils.java    From flink with Apache License 2.0 5 votes vote down vote up
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());
}
 
Example 11
Source File: CliInputView.java    From flink with Apache License 2.0 5 votes vote down vote up
@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 {
		inputLine.append(' '); // show the cursor at the end
	}

	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;
}
 
Example 12
Source File: CliUtils.java    From flink with Apache License 2.0 5 votes vote down vote up
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());
}
 
Example 13
Source File: CliInputView.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@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 {
		inputLine.append(' '); // show the cursor at the end
	}

	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;
}
 
Example 14
Source File: CliUtils.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
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());
}
 
Example 15
Source File: CliResultView.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
protected List<AttributedString> computeMainLines() {
	final List<AttributedString> lines = new ArrayList<>();

	int lineIdx = 0;
	for (String[] line : results) {
		final AttributedStringBuilder row = new AttributedStringBuilder();

		// highlight selected row
		if (lineIdx == selectedRow) {
			row.style(AttributedStyle.DEFAULT.inverse());
		}

		for (int colIdx = 0; colIdx < line.length; colIdx++) {
			final String col = line[colIdx];
			final int columnWidth = computeColumnWidth(colIdx);

			row.append(' ');
			// check if value was present before last update, if not, highlight it
			// we don't highlight if the retrieval stopped
			// both inverse and bold together do not work correctly
			if (previousResults != null && lineIdx != selectedRow && refreshThread.isRunning &&
					(lineIdx >= previousResults.size() || !col.equals(previousResults.get(lineIdx)[colIdx]))) {
				row.style(AttributedStyle.BOLD);
				normalizeColumn(row, col, columnWidth);
				row.style(AttributedStyle.DEFAULT);
			} else {
				normalizeColumn(row, col, columnWidth);
			}
		}
		lines.add(row.toAttributedString());

		lineIdx++;
	}

	return lines;
}
 
Example 16
Source File: Query.java    From presto with Apache License 2.0 5 votes vote down vote up
private static void renderErrorLocation(String query, ErrorLocation location, PrintStream out)
{
    List<String> lines = ImmutableList.copyOf(Splitter.on('\n').split(query).iterator());

    String errorLine = lines.get(location.getLineNumber() - 1);
    String good = errorLine.substring(0, location.getColumnNumber() - 1);
    String bad = errorLine.substring(location.getColumnNumber() - 1);

    if ((location.getLineNumber() == lines.size()) && bad.trim().isEmpty()) {
        bad = " <EOF>";
    }

    if (REAL_TERMINAL) {
        AttributedStringBuilder builder = new AttributedStringBuilder();

        builder.style(DEFAULT.foreground(CYAN));
        for (int i = 1; i < location.getLineNumber(); i++) {
            builder.append(lines.get(i - 1)).append("\n");
        }
        builder.append(good);

        builder.style(DEFAULT.foreground(RED));
        builder.append(bad).append("\n");
        for (int i = location.getLineNumber(); i < lines.size(); i++) {
            builder.append(lines.get(i)).append("\n");
        }

        builder.style(DEFAULT);
        out.print(builder.toAnsi());
    }
    else {
        String prefix = format("LINE %s: ", location.getLineNumber());
        String padding = Strings.repeat(" ", prefix.length() + (location.getColumnNumber() - 1));
        out.println(prefix + errorLine);
        out.println(padding + "^");
    }
}
 
Example 17
Source File: CliChangelogResultView.java    From flink with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 18
Source File: PromptHandler.java    From sqlline with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
protected AttributedString getPrompt(
    SqlLine sqlLine, int connectionIndex, String prompt) {
  AttributedStringBuilder promptStringBuilder = new AttributedStringBuilder();
  final SqlLineOpts opts = sqlLine.getOpts();
  final ConnectionMetadata meta = sqlLine.getConnectionMetadata();
  for (int i = 0; i < prompt.length(); i++) {
    switch (prompt.charAt(i)) {
    case '%':
      if (i < prompt.length() - 1) {
        String dateTime = formatDateTime(prompt.charAt(i + 1));
        if (dateTime != null) {
          promptStringBuilder.append(dateTime);
        } else {
          switch (prompt.charAt(i + 1)) {
          case 'c':
            if (connectionIndex >= 0) {
              promptStringBuilder.append(String.valueOf(connectionIndex));
            }
            break;
          case 'C':
            if (connectionIndex >= 0) {
              promptStringBuilder
                  .append(String.valueOf(connectionIndex)).append(": ");
            }
            break;
          case 'd':
            String databaseProductName = meta.getDatabaseProductName();
            if (databaseProductName != null) {
              promptStringBuilder.append(databaseProductName);
            }
            break;
          case 'n':
            String userName = meta.getUserName();
            if (userName != null) {
              promptStringBuilder.append(userName);
            }
            break;
          case 'u':
            String url = meta.getUrl();
            if (url != null) {
              promptStringBuilder.append(url);
            }
            break;
          case 'S':
            String currentSchema = meta.getCurrentSchema();
            if (currentSchema != null) {
              promptStringBuilder.append(currentSchema);
            }
            break;
          case '[':
            int closeBracketIndex = prompt.indexOf("%]", i + 2);
            if (closeBracketIndex > 0) {
              String color = prompt.substring(i + 2, closeBracketIndex);
              AttributedStyle style = resolveStyle(color);
              promptStringBuilder.style(style);
              i = closeBracketIndex;
              break;
            }
          // fall through if not a color
          case ':':
            int nextColonIndex = prompt.indexOf(":", i + 2);
            SqlLineProperty property;
            if (nextColonIndex > 0
                && ((property = BuiltInProperty.valueOf(
                prompt.substring(i + 2, nextColonIndex),
                true)) != null)) {
              promptStringBuilder.append(opts.get(property));
              i = nextColonIndex - 1;
              break;
            }
          // fall through if not a variable name
          default:
            promptStringBuilder
                .append(prompt.charAt(i)).append(prompt.charAt(i + 1));
          }
        }
        i = i + 1;
      }
      break;
    default:
      promptStringBuilder.append(prompt.charAt(i));
    }
  }
  return promptStringBuilder.toAttributedString();
}
 
Example 19
Source File: CliTableResultView.java    From flink with Apache License 2.0 4 votes vote down vote up
@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;
	}
	// middle
	final StringBuilder middleBuilder = new StringBuilder();
	middleBuilder.append(CliStrings.RESULT_PAGE);
	middleBuilder.append(' ');
	if (page == LAST_PAGE) {
		middleBuilder.append(CliStrings.RESULT_LAST_PAGE);
	} else {
		middleBuilder.append(page);
	}
	middleBuilder.append(CliStrings.RESULT_PAGE_OF);
	middleBuilder.append(pageCount);
	final String middle = middleBuilder.toString();
	// 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 totalLeftSpace = getWidth() - middle.length();
	final int leftSpace = totalLeftSpace / 2 - left.length();
	statusLine.append(left);
	repeatChar(statusLine, ' ', leftSpace);
	statusLine.append(middle);
	final int rightSpacing = getWidth() - statusLine.length() - right.length();
	repeatChar(statusLine, ' ', rightSpacing);
	statusLine.append(right);

	return Arrays.asList(statusLine.toAttributedString(), AttributedString.EMPTY);
}
 
Example 20
Source File: CliTableResultView.java    From flink with Apache License 2.0 4 votes vote down vote up
@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;
	}
	// middle
	final StringBuilder middleBuilder = new StringBuilder();
	middleBuilder.append(CliStrings.RESULT_PAGE);
	middleBuilder.append(' ');
	if (page == LAST_PAGE) {
		middleBuilder.append(CliStrings.RESULT_LAST_PAGE);
	} else {
		middleBuilder.append(page);
	}
	middleBuilder.append(CliStrings.RESULT_PAGE_OF);
	middleBuilder.append(pageCount);
	final String middle = middleBuilder.toString();
	// 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 totalLeftSpace = getWidth() - middle.length();
	final int leftSpace = totalLeftSpace / 2 - left.length();
	statusLine.append(left);
	repeatChar(statusLine, ' ', leftSpace);
	statusLine.append(middle);
	final int rightSpacing = getWidth() - statusLine.length() - right.length();
	repeatChar(statusLine, ' ', rightSpacing);
	statusLine.append(right);

	return Arrays.asList(statusLine.toAttributedString(), AttributedString.EMPTY);
}