org.jline.reader.impl.DefaultHighlighter Java Examples

The following examples show how to use org.jline.reader.impl.DefaultHighlighter. 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: ShellUtils.java    From rug-cli with GNU General Public License v3.0 7 votes vote down vote up
public static LineReader lineReader(File historyPath, Optional<SignalHandler> handler,
        Completer... completers) {
    // Protect the history file as may contain sensitive information
    FileUtils.setPermissionsToOwnerOnly(historyPath);

    // Create JLine LineReader
    History history = new DefaultHistory();
    LineReader reader = LineReaderBuilder.builder().terminal(terminal(handler)).history(history)
            .parser(new DefaultParser()).variable(LineReader.HISTORY_FILE, historyPath)
            .completer(new AggregateCompleter(completers)).highlighter(new DefaultHighlighter())
            .build();
    history.attach(reader);

    setOptions(reader);

    return reader;
}
 
Example #2
Source File: LogServiceShell.java    From incubator-ratis with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
  final Terminal terminal = TerminalBuilder.builder()
      .system(true)
      .build();

  History defaultHistory = new DefaultHistory();
  // Register a shutdown-hook per JLine documentation to save history
  Runtime.getRuntime().addShutdownHook(new Thread(() -> {
    try {
      defaultHistory.save();
    } catch (IOException e) {
      LOG.debug("Failed to save terminal history", e);
    }
  }));

  final LineReader lineReader = LineReaderBuilder.builder()
      .terminal(terminal)
      .highlighter(new DefaultHighlighter())
      .history(defaultHistory)
      .build();

  LogServiceShellOpts opts = new LogServiceShellOpts();
  JCommander.newBuilder()
      .addObject(opts)
      .build()
      .parse(args);

  try (LogServiceClient logServiceClient = new LogServiceClient(opts.getMetaQuorum())) {
    LogServiceShell client = new LogServiceShell(terminal, lineReader, logServiceClient);
    client.run();
  }
}
 
Example #3
Source File: LogServiceShell.java    From ratis with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
  final Terminal terminal = TerminalBuilder.builder()
      .system(true)
      .build();

  History defaultHistory = new DefaultHistory();
  // Register a shutdown-hook per JLine documentation to save history
  Runtime.getRuntime().addShutdownHook(new Thread(() -> {
    try {
      defaultHistory.save();
    } catch (IOException e) {
      LOG.debug("Failed to save terminal history", e);
    }
  }));

  final LineReader lineReader = LineReaderBuilder.builder()
      .terminal(terminal)
      .highlighter(new DefaultHighlighter())
      .history(defaultHistory)
      .build();

  LogServiceShellOpts opts = new LogServiceShellOpts();
  JCommander.newBuilder()
      .addObject(opts)
      .build()
      .parse(args);

  try (LogServiceClient logServiceClient = new LogServiceClient(opts.metaQuorum)) {
    LogServiceShell client = new LogServiceShell(terminal, lineReader, logServiceClient);
    client.run();
  }
}