This is an automated email from the ASF dual-hosted git repository.
critas pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/master by this push:
new d3b96d8136c show more use ctx.getIn(), because Sometimes it's not
system. in (#14322)
d3b96d8136c is described below
commit d3b96d8136c84c055a6c0409680f5311224cef87
Author: CritasWang <[email protected]>
AuthorDate: Thu Dec 12 16:41:12 2024 +0800
show more use ctx.getIn(), because Sometimes it's not system. in (#14322)
* show more use ctx.getIn(), because Sometimes it's not system. in
* load historyFile when isDisableCliHistory is false
* use getLineReader display more when isDisableCliHistory is false
* spotless:apply
---
.../java/org/apache/iotdb/cli/AbstractCli.java | 14 +++++++---
.../org/apache/iotdb/cli/utils/JlineUtils.java | 32 ++++++++++++----------
2 files changed, 27 insertions(+), 19 deletions(-)
diff --git
a/iotdb-client/cli/src/main/java/org/apache/iotdb/cli/AbstractCli.java
b/iotdb-client/cli/src/main/java/org/apache/iotdb/cli/AbstractCli.java
index f5f7a59409d..e9040ada1ea 100644
--- a/iotdb-client/cli/src/main/java/org/apache/iotdb/cli/AbstractCli.java
+++ b/iotdb-client/cli/src/main/java/org/apache/iotdb/cli/AbstractCli.java
@@ -37,7 +37,6 @@ import org.apache.tsfile.utils.BytesUtils;
import org.apache.tsfile.utils.DateUtils;
import java.io.BufferedReader;
-import java.io.IOException;
import java.io.InputStreamReader;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
@@ -590,9 +589,16 @@ public abstract class AbstractCli {
}
ctx.getPrinter()
.println("This display 1000 rows. Press ENTER to show more,
input 'q' to quit.");
- BufferedReader br = new BufferedReader(new
InputStreamReader(System.in));
+
+ BufferedReader br = new BufferedReader(new
InputStreamReader(ctx.getIn()));
try {
- if ("".equals(br.readLine())) {
+ String line;
+ if (ctx.isDisableCliHistory()) {
+ line = ctx.getLineReader().readLine();
+ } else {
+ line = br.readLine();
+ }
+ if ("".equals(line)) {
maxSizeList = new ArrayList<>(columnLength);
lists =
cacheResult(
@@ -601,7 +607,7 @@ public abstract class AbstractCli {
} else {
break;
}
- } catch (IOException e) {
+ } catch (Exception e) {
ctx.getPrinter().printException(e);
executeStatus = CODE_ERROR;
}
diff --git
a/iotdb-client/cli/src/main/java/org/apache/iotdb/cli/utils/JlineUtils.java
b/iotdb-client/cli/src/main/java/org/apache/iotdb/cli/utils/JlineUtils.java
index d7b061f5c1e..00b6349fff7 100644
--- a/iotdb-client/cli/src/main/java/org/apache/iotdb/cli/utils/JlineUtils.java
+++ b/iotdb-client/cli/src/main/java/org/apache/iotdb/cli/utils/JlineUtils.java
@@ -81,21 +81,23 @@ public class JlineUtils {
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));
+ if (!ctx.isDisableCliHistory()) {
+ // 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.