public static AttributedString messageInfo(String message) { return new AttributedStringBuilder() .style(AttributedStyle.DEFAULT.bold().foreground(AttributedStyle.BLUE)) .append("[INFO] ") .append(message) .toAttributedString(); }
public static void repeatChar(AttributedStringBuilder sb, char c, int count) { IntStream.range(0, count).forEach(i -> sb.append(c)); }
lines.add(new AttributedString(CliStrings.DEFAULT_MARGIN + inputTitle)); final AttributedStringBuilder inputLine = new AttributedStringBuilder(); inputLine.append(CliStrings.DEFAULT_MARGIN + "> "); final String input = currentInput.toString(); 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()); 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());
@Test public void shouldSetStatusMessage() { // When: terminal.setStatusMessage("test message"); // Then: verify(statusBar) .update(ImmutableList.of(new AttributedString("test message", AttributedStyle.INVERSE))); }
@Override public StatusClosable setStatusMessage(final String message) { updateStatusBar(new AttributedString(message, AttributedStyle.INVERSE)); return () -> updateStatusBar(DEFAULT_STATUS_MSG); }
private void printInfo(String message) { terminal.writer().println(CliStrings.messageInfo(message).toAnsi()); terminal.flush(); } }
private Candidate createCandidate(String hint) { return new Candidate(AttributedString.stripAnsi(hint), hint, null, null, null, null, true); }
private void updateStatusBar(final AttributedString message) { final Status statusBar = statusFactory.apply(terminal); statusBar.update(Collections.singletonList(message)); }
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(); }
@Test public void shouldResetStatusMessage() { // Given: final StatusClosable closable = terminal.setStatusMessage("test message"); clearInvocations(statusBar); // When: closable.close(); // Then: verify(statusBar) .update(ImmutableList.of(new AttributedString("", AttributedStyle.DEFAULT))); } }
private void printException(String message, Throwable t) { LOG.warn(message, t); terminal.writer().println(CliStrings.messageError(message, t).toAnsi()); terminal.flush(); }
private void addCandidates(final Collection<String> values, final List<Candidate> candidates) { for (final String value : values) { candidates.add(new Candidate(AttributedString.stripAnsi(value), value, null, null, null, null, true)); } } }
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(); } }
private void printExecutionError(String message) { terminal.writer().println(CliStrings.messageError(CliStrings.MESSAGE_SQL_EXECUTION_ERROR, message).toAnsi()); terminal.flush(); }
@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()); }
private void printError(String message) { terminal.writer().println(CliStrings.messageError(message).toAnsi()); terminal.flush(); }
@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()); }
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(); }
final AttributedStringBuilder row = new AttributedStringBuilder(); row.style(AttributedStyle.DEFAULT.inverse()); final int columnWidth = computeColumnWidth(colIdx); row.append(' '); row.style(AttributedStyle.BOLD); normalizeColumn(row, col, columnWidth); row.style(AttributedStyle.DEFAULT); } else { normalizeColumn(row, col, columnWidth); lines.add(row.toAttributedString());