public static LineReader getLineReader()

in backup-command/src/main/java/org/apache/iotdb/backup/command/utils/JlineUtils.java [53:110]


  public static LineReader getLineReader(String username, String host, String port)
      throws IOException {
    // Defaulting to a dumb terminal when a supported terminal can not be correctly created
    // see https://github.com/jline/jline3/issues/291
    Terminal terminal = TerminalBuilder.builder().dumb(true).build();
    if (terminal.getWidth() == 0 || terminal.getHeight() == 0) {
      // Hard coded terminal size when redirecting.
      terminal.setSize(new Size(120, 40));
    }
    Thread executeThread = Thread.currentThread();
    // Register signal handler. Instead of shutting down the process, interrupt the current thread
    // when signal INT is received (usually by pressing CTRL+C).
    terminal.handle(Signal.INT, signal -> executeThread.interrupt());

    LineReaderBuilder builder = LineReaderBuilder.builder();
    builder.terminal(terminal);

    // Handle the command history. By default, the number of commands will not exceed 500 and the
    // size of the history fill will be less than 10 KB. See:
    // org.jline.reader.impl.history#DefaultHistory
    String historyFile = ".iotdb_history";
    String historyFilePath =
        System.getProperty("user.home")
            + File.separator
            + historyFile
            + "-"
            + host.hashCode()
            + "-"
            + port
            + "-"
            + username.hashCode();
    builder.variable(LineReader.HISTORY_FILE, new File(historyFilePath));

    // TODO: since the lexer doesn't produce tokens for quotation marks, disable the highlighter to
    // avoid incorrect inputs.
    // builder.highlighter(new IoTDBSyntaxHighlighter());

    builder.completer(new StringsCompleter(SQL_KEYWORDS));

    builder.option(Option.CASE_INSENSITIVE_SEARCH, true);
    builder.option(Option.CASE_INSENSITIVE, true);
    // See: https://www.gnu.org/software/bash/manual/html_node/Event-Designators.html
    builder.option(Option.DISABLE_EVENT_EXPANSION, true);

    org.jline.reader.impl.DefaultParser parser = new org.jline.reader.impl.DefaultParser();
    builder.parser(parser);
    LineReader lineReader = builder.build();
    if (OSUtils.IS_WINDOWS) {
      // If enabled cursor remains in begin parenthesis (gitbash).
      lineReader.setVariable(LineReader.BLINK_MATCHING_PAREN, 0);
    }

    // Create autosuggestion widgets
    AutosuggestionWidgets autosuggestionWidgets = new AutosuggestionWidgets(lineReader);
    // Enable autosuggestions
    autosuggestionWidgets.enable();
    return lineReader;
  }