org.jline.utils.AttributedStringBuilder Java Examples

The following examples show how to use org.jline.utils.AttributedStringBuilder. 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: 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 #2
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 #3
Source File: CliHighlighter.java    From samza with Apache License 2.0 6 votes vote down vote up
public AttributedString highlight(LineReader reader, String buffer) {
  AttributedStringBuilder builder = new AttributedStringBuilder();
  List<String> tokens = splitWithSpace(buffer);

  for (String token : tokens) {
    if (isKeyword(token)) {
      builder.style(AttributedStyle.BOLD.foreground(AttributedStyle.YELLOW))
              .append(token);
    } else {
      builder.style(AttributedStyle.DEFAULT)
              .append(token);
    }
  }

  return builder.toAttributedString();
}
 
Example #4
Source File: QueryResultLogView.java    From samza with Apache License 2.0 6 votes vote down vote up
private void drawStatusBar(int rowsInBuffer) {
  terminal.puts(InfoCmp.Capability.save_cursor);
  terminal.puts(InfoCmp.Capability.cursor_address, height - 1, 0);
  AttributedStyle statusBarStyle = AttributedStyle.DEFAULT.background(AttributedStyle.WHITE)
          .foreground(AttributedStyle.BLACK);
  AttributedStringBuilder attrBuilder = new AttributedStringBuilder()
          .style(statusBarStyle.bold().italic())
          .append("Q")
          .style(statusBarStyle)
          .append(": Quit     ")
          .style(statusBarStyle.bold().italic())
          .append("SPACE")
          .style(statusBarStyle)
          .append(": Pause/Resume     ")
          .append(String.valueOf(rowsInBuffer) + " rows in buffer     ");
  if (paused) {
    attrBuilder.style(statusBarStyle.bold().foreground(AttributedStyle.RED).blink())
            .append("PAUSED");
  }
  String statusBarText = attrBuilder.toAnsi();
  terminal.writer().print(statusBarText);
  terminal.flush();
  terminal.puts(InfoCmp.Capability.restore_cursor);
}
 
Example #5
Source File: CliCommandHandler.java    From samza with Apache License 2.0 6 votes vote down vote up
/**
 * Prints to terminal the help message of the commands this handler handles
 */
public void printHelpMessage() {
  AttributedStringBuilder builder = new AttributedStringBuilder();
  builder.append("The following commands are supported by ")
      .append(CliConstants.APP_NAME)
      .append("by handler ")
      .append(this.getClass().getName())
      .append(" at the moment.\n\n");

  for (CliCommandType cmdType : CliCommandType.values()) {
    if (cmdType == CliCommandType.INVALID_COMMAND)
      continue;

    String cmdText = cmdType.getCommandName();
    String cmdDescription = cmdType.getDescription();

    builder.style(AttributedStyle.DEFAULT.bold())
        .append(cmdText)
        .append("\t\t")
        .style(AttributedStyle.DEFAULT)
        .append(cmdDescription)
        .append("\n");
  }
  writer.println(builder.toAnsi());
}
 
Example #6
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 #7
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 #8
Source File: App.java    From graph-examples with Apache License 2.0 6 votes vote down vote up
private static String highlightResult(String result) {
    return new AttributedStringBuilder()
            .append(result)
            .styleMatches(
                    Pattern.compile("[a-z]+\\b(?![\\[=])"),
                    AttributedStyle.DEFAULT.foreground(AttributedStyle.GREEN).faint())
            .styleMatches(
                    Pattern.compile("\\b[0-9]+(L|(\\.[0-9]+))?\\b"),
                    AttributedStyle.DEFAULT.foreground(AttributedStyle.CYAN))
            .styleMatches(
                    Pattern.compile("[a-z]+(?==)"),
                    AttributedStyle.DEFAULT)
            .styleMatches(
                    Pattern.compile("[a-z]+\\b(?=\\[)"),
                    AttributedStyle.DEFAULT.faint())
            .styleMatches(
                    Pattern.compile("[a-z]+\\b(?==)"),
                    AttributedStyle.DEFAULT.foreground(AttributedStyle.MAGENTA).faint())
            .toAnsi();
}
 
Example #9
Source File: App.java    From graph-examples with Apache License 2.0 6 votes vote down vote up
private static String highlightTraversal(String traversal) {
    return new AttributedStringBuilder()
            .append(traversal)
            .styleMatches(
                    Pattern.compile("\"[^\"]*\""),
                    AttributedStyle.DEFAULT.foreground(AttributedStyle.GREEN).faint())
            .styleMatches(
                    Pattern.compile("\\b[0-9]+(L|(\\.[0-9]+))?\\b"),
                    AttributedStyle.DEFAULT.foreground(AttributedStyle.CYAN).faint())
            .styleMatches(
                    Pattern.compile("\\b(assign|gt|id|keys|local|lt|sum|values)\\b"),
                    AttributedStyle.DEFAULT.foreground(AttributedStyle.MAGENTA).faint())
            .styleMatches(
                    Pattern.compile("\\b(as|by|emit|from)\\b"),
                    AttributedStyle.DEFAULT.italic())
            .styleMatches(
                    Pattern.compile("__\\."),
                    AttributedStyle.DEFAULT.foreground(AttributedStyle.BLACK | AttributedStyle.BRIGHT))
            .toAnsi();
}
 
Example #10
Source File: Commands.java    From sqlline with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void dbinfo(String line, DispatchCallback callback) {
  if (!sqlLine.assertConnection()) {
    callback.setToFailure();
    return;
  }

  sqlLine.showWarnings();
  int padlen = 50;

  for (String method : METHODS) {
    try {
      final String s =
          String.valueOf(sqlLine.getReflector()
              .invoke(sqlLine.getDatabaseMetaData(), method));
      sqlLine.output(
          new AttributedStringBuilder()
              .append(rpad(method, padlen))
              .append(s)
              .toAttributedString());
    } catch (Exception e) {
      sqlLine.handleException(e);
    }
  }

  callback.setToSuccess();
}
 
Example #11
Source File: TableOutputFormat.java    From sqlline with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
void printRow(AttributedString attributedString, boolean header) {
  AttributedStringBuilder builder = new AttributedStringBuilder();
  if (header) {
    sqlLine.output(
        builder.append("+-", AttributedStyles.GREEN)
            .append(attributedString)
            .append("-+", AttributedStyles.GREEN)
            .toAttributedString());
  } else {
    sqlLine.output(
        builder.append("| ", AttributedStyles.GREEN)
            .append(attributedString)
            .append(" |", AttributedStyles.GREEN)
            .toAttributedString());
  }
}
 
Example #12
Source File: VerticalOutputFormat.java    From sqlline with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void printRow(Rows rows, Rows.Row header, Rows.Row row) {
  String[] head = header.values;
  String[] vals = row.values;
  int headWidth = 0;
  for (int i = 0; (i < head.length) && (i < vals.length); i++) {
    headWidth = Math.max(headWidth, head[i].length());
  }

  headWidth += 2;

  for (int i = 0; (i < head.length) && (i < vals.length); i++) {
    sqlLine.output(
        new AttributedStringBuilder()
            .append(rpad(head[i], headWidth), AttributedStyle.BOLD)
            .append((vals[i] == null) ? "" : vals[i])
            .toAttributedString());
  }

  sqlLine.output(""); // spacing
}
 
Example #13
Source File: SqlLine.java    From sqlline with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
void runBatch(List<String> statements) {
  try (Statement stmnt = createStatement()) {
    for (String statement : statements) {
      stmnt.addBatch(statement);
    }

    int[] counts = stmnt.executeBatch();
    if (counts == null) {
      counts = new int[0];
    }

    output(new AttributedStringBuilder()
        .append(rpad("COUNT", 8), AttributedStyle.BOLD)
        .append("STATEMENT", AttributedStyle.BOLD)
        .toAttributedString());

    for (int i = 0; i < counts.length; i++) {
      output(new AttributedStringBuilder()
          .append(rpad(counts[i] + "", 8))
          .append(statements.get(i))
          .toAttributedString());
    }
  } catch (Exception e) {
    handleException(e);
  }
}
 
Example #14
Source File: BatsSqlLineApplication.java    From Bats 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("bats");

            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 #15
Source File: DrillSqlLineApplication.java    From Bats 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("apache drill");

        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 #16
Source File: CliStrings.java    From flink with Apache License 2.0 5 votes vote down vote up
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();
}
 
Example #17
Source File: CliRowView.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<>();

	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;
}
 
Example #18
Source File: SqlLine.java    From sqlline with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public int runCommands(List<String> cmds, DispatchCallback callback) {
  int successCount = 0;

  try {
    int index = 1;
    int size = cmds.size();
    for (String cmd : cmds) {
      info(new AttributedStringBuilder()
          .append(rpad(index++ + "/" + size, 13))
          .append(cmd)
          .toAttributedString());

      dispatch(cmd, callback);
      boolean success = callback.isSuccess();
      // if we do not force script execution, abort
      // when a failure occurs.
      if (!success && !getOpts().getForce()) {
        error(loc("abort-on-error", cmd));
        return successCount;
      }
      successCount += success ? 1 : 0;
    }
  } catch (Exception e) {
    handleException(e);
  }

  return successCount;
}
 
Example #19
Source File: CliTableResultView.java    From flink with Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example #20
Source File: CliStrings.java    From flink with Apache License 2.0 5 votes vote down vote up
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();
}
 
Example #21
Source File: AnsiConsoleOutputFormat.java    From sqlline with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private AttributedString getOutputString(
    Rows.Row row, String delim, AttributedStyle style) {
  AttributedStringBuilder builder = new AttributedStringBuilder();

  for (int i = 0; i < row.values.length; i++) {
    if (builder.length() > 0) {
      builder.append(delim);
    }
    builder.append(SqlLine.rpad(row.values[i], row.sizes[i]), style);
  }

  return builder.toAttributedString();
}
 
Example #22
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 #23
Source File: DemoCommand.java    From ssh-shell-spring-boot with Apache License 2.0 5 votes vote down vote up
/**
 * Echo command
 *
 * @param message message to print
 * @param color   color for the message
 * @return message
 */
@ShellMethod("Echo command")
public String echo(String message, @ShellOption(defaultValue = ShellOption.NULL) PromptColor color) {
    if (color != null) {
        return new AttributedStringBuilder().append(message,
                AttributedStyle.DEFAULT.foreground(color.toJlineAttributedStyle())).toAnsi();
    }
    return message;
}
 
Example #24
Source File: FlinkSqlInterrpeter.java    From zeppelin with Apache License 2.0 5 votes vote down vote up
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();
}
 
Example #25
Source File: JLineCliRepl.java    From Arend with Apache License 2.0 5 votes vote down vote up
@Override
public void eprintln(Object anything) {
  println(new AttributedStringBuilder()
      .style(AttributedStyle.DEFAULT.foreground(AttributedStyle.RED))
      .append(String.valueOf(anything))
      .style(AttributedStyle.DEFAULT)
      .toAnsi());
}
 
Example #26
Source File: TerminalProcessor.java    From sshd-shell-spring-boot with Apache License 2.0 5 votes vote down vote up
TerminalProcessor(Shell properties, Completer completer, List<BaseUserInputProcessor> userInputProcessors) {
    this.properties = properties;
    this.completer = completer;
    this.userInputProcessors = userInputProcessors;
    prompt = new AttributedStringBuilder()
            .style(getStyle(properties.getPrompt().getColor()))
            .append(properties.getPrompt().getTitle())
            .append("> ")
            .style(AttributedStyle.DEFAULT)
            .toAnsi();
}
 
Example #27
Source File: App.java    From graph-examples with Apache License 2.0 5 votes vote down vote up
private void printTraversalResult(Terminal terminal, String title, GraphTraversal traversal) {
    if (title != null) {
        terminal.writer().println(new AttributedStringBuilder()
                .style(AttributedStyle.DEFAULT.foreground(AttributedStyle.GREEN))
                .append(title).append("\n")
                .style(AttributedStyle.DEFAULT).toAnsi());
    }
    traversal.forEachRemaining(r -> terminal.writer().println(formatResult(r)));
    terminal.writer().println();
}
 
Example #28
Source File: App.java    From graph-examples with Apache License 2.0 5 votes vote down vote up
private static void printTraversal(Terminal terminal, String title, GraphTraversal traversal) {
    terminal.writer().println(new AttributedStringBuilder()
            .style(AttributedStyle.DEFAULT.foreground(AttributedStyle.GREEN))
            .append(title).append("\n")
            .style(AttributedStyle.DEFAULT).toAnsi());
    terminal.writer().println(formatTraversal(GroovyTranslator.of("g").translate(traversal.asAdmin().getBytecode())));
}
 
Example #29
Source File: App.java    From graph-examples with Apache License 2.0 5 votes vote down vote up
private void printCommandsAndTraversals(Terminal terminal) {
    Iterator<Commands.Command> commandIterator = Commands.get().iterator();
    Iterator<ShortestPathTraversals.ShortestPathTraversal> traversalIterator = ShortestPathTraversals.get().iterator();
    AttributedStringBuilder asb = new AttributedStringBuilder()
            .style(AttributedStyle.DEFAULT.foreground(AttributedStyle.WHITE)).append("   Command  ")
            .style(AttributedStyle.DEFAULT.foreground(AttributedStyle.WHITE)).append("Description")
            .style(AttributedStyle.DEFAULT.foreground(AttributedStyle.WHITE)).append(String.format("%50s", "N  "))
            .style(AttributedStyle.DEFAULT.foreground(AttributedStyle.WHITE)).append("Traversal Description\n\n");

    int i = 0;
    while (commandIterator.hasNext() || traversalIterator.hasNext()) {
        int padding = 71;
        if (commandIterator.hasNext()) {
            Commands.Command command = commandIterator.next();
            if (Commands.DISCONNECT.matcher(command.command).find()
                    && (session == null || session.isClosed())) {
                continue;
            }
            asb
                    .style(AttributedStyle.DEFAULT.bold()).append(String.format("%10s  ", command.command))
                    .style(AttributedStyle.DEFAULT).append(command.description);
            padding -= 12 + command.description.length();
        }
        if (traversalIterator.hasNext()) {
            ShortestPathTraversals.ShortestPathTraversal traversal = traversalIterator.next();
            String fmt = String.format("%%%dd  ", padding);
            asb
                    .style(AttributedStyle.DEFAULT.bold()).append(String.format(fmt, ++i))
                    .style(AttributedStyle.DEFAULT).append(traversal.description);
        }
        asb.append("\n");
    }
    asb.styleMatches(Pattern.compile("(\\b((g(?=raph  ))|(d(?=isconnect  ))|(c(?=onnect  )|(s(?=how N))|(r(?=un N))))|((?<=e)x(?=it)))"),
            AttributedStyle.DEFAULT.bold().underline());
    terminal.writer().println(asb.toAnsi());
    terminal.writer().flush();
}
 
Example #30
Source File: CustomPromptHandler.java    From sqlline with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override protected AttributedString getDefaultPrompt(int connectionIndex,
    String url, String defaultPrompt) {
  AttributedStringBuilder builder = new AttributedStringBuilder();
  builder.append("my_app");

  final ConnectionMetadata meta = sqlLine.getConnectionMetadata();

  final String currentSchema = meta.getCurrentSchema();
  if (currentSchema != null) {
    builder.append(" (").append(currentSchema).append(")");
  }
  return builder.append(">").toAttributedString();
}