• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

apache / iotdb / #10006

06 Sep 2023 05:15AM CUT coverage: 47.697% (+0.006%) from 47.691%
#10006

push

travis_ci

web-flow
[RatisConsensus] retry cache expiration time should be longer than retriable-client wait duration (#11045) (#11052)

13 of 13 new or added lines in 1 file covered. (100.0%)

80213 of 168172 relevant lines covered (47.7%)

0.48 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/iotdb-client/cli/src/main/java/org/apache/iotdb/cli/utils/JlineUtils.java
1
/*
2
 * Licensed to the Apache Software Foundation (ASF) under one
3
 * or more contributor license agreements.  See the NOTICE file
4
 * distributed with this work for additional information
5
 * regarding copyright ownership.  The ASF licenses this file
6
 * to you under the Apache License, Version 2.0 (the
7
 * "License"); you may not use this file except in compliance
8
 * with the License.  You may obtain a copy of the License at
9
 *
10
 *     http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing,
13
 * software distributed under the License is distributed on an
14
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
 * KIND, either express or implied.  See the License for the
16
 * specific language governing permissions and limitations
17
 * under the License.
18
 */
19

20
package org.apache.iotdb.cli.utils;
21

22
import org.apache.iotdb.db.qp.sql.SqlLexer;
23

24
import org.jline.reader.LineReader;
25
import org.jline.reader.LineReader.Option;
26
import org.jline.reader.LineReaderBuilder;
27
import org.jline.reader.impl.completer.StringsCompleter;
28
import org.jline.terminal.Size;
29
import org.jline.terminal.Terminal;
30
import org.jline.terminal.Terminal.Signal;
31
import org.jline.terminal.TerminalBuilder;
32
import org.jline.utils.OSUtils;
33
import org.jline.widget.AutosuggestionWidgets;
34

35
import java.io.File;
36
import java.io.IOException;
37
import java.util.Objects;
38
import java.util.Set;
39
import java.util.regex.Pattern;
40
import java.util.stream.Collectors;
41
import java.util.stream.IntStream;
42

43
public class JlineUtils {
44

45
  private JlineUtils() {}
46

47
  public static final Pattern SQL_KEYWORD_PATTERN = Pattern.compile("([A-Z_]+)");
×
48
  public static final Set<String> SQL_KEYWORDS =
×
49
      IntStream.range(0, SqlLexer.VOCABULARY.getMaxTokenType())
×
50
          .mapToObj(SqlLexer.VOCABULARY::getDisplayName)
×
51
          .filter(Objects::nonNull)
×
52
          .filter(w -> SQL_KEYWORD_PATTERN.matcher(w).matches())
×
53
          .collect(Collectors.toSet());
×
54

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

69
    LineReaderBuilder builder = LineReaderBuilder.builder();
×
70
    builder.terminal(terminal);
×
71

72
    // Handle the command history. By default, the number of commands will not exceed 500 and the
73
    // size of the history fill will be less than 10 KB. See:
74
    // org.jline.reader.impl.history#DefaultHistory
75
    String historyFile = ".iotdb_history";
×
76
    String historyFilePath =
×
77
        System.getProperty("user.home")
×
78
            + File.separator
79
            + historyFile
80
            + "-"
81
            + host.hashCode()
×
82
            + "-"
83
            + port
84
            + "-"
85
            + username.hashCode();
×
86
    builder.variable(LineReader.HISTORY_FILE, new File(historyFilePath));
×
87

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

92
    builder.completer(new StringsCompleter(SQL_KEYWORDS));
×
93

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

99
    org.jline.reader.impl.DefaultParser parser = new org.jline.reader.impl.DefaultParser();
×
100
    builder.parser(parser);
×
101
    LineReader lineReader = builder.build();
×
102
    if (OSUtils.IS_WINDOWS) {
×
103
      // If enabled cursor remains in begin parenthesis (gitbash).
104
      lineReader.setVariable(LineReader.BLINK_MATCHING_PAREN, 0);
×
105
    }
106

107
    // Create autosuggestion widgets
108
    AutosuggestionWidgets autosuggestionWidgets = new AutosuggestionWidgets(lineReader);
×
109
    // Enable autosuggestions
110
    autosuggestionWidgets.enable();
×
111
    return lineReader;
×
112
  }
113
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc