Skip to content

Commit d3b96d8

Browse files
authored
show more use ctx.getIn(), because Sometimes it's not system. in (apache#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
1 parent 54197b9 commit d3b96d8

File tree

2 files changed

+27
-19
lines changed

2 files changed

+27
-19
lines changed

iotdb-client/cli/src/main/java/org/apache/iotdb/cli/AbstractCli.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
import org.apache.tsfile.utils.DateUtils;
3838

3939
import java.io.BufferedReader;
40-
import java.io.IOException;
4140
import java.io.InputStreamReader;
4241
import java.sql.ResultSet;
4342
import java.sql.ResultSetMetaData;
@@ -590,9 +589,16 @@ private static int executeQuery(CliContext ctx, IoTDBConnection connection, Stri
590589
}
591590
ctx.getPrinter()
592591
.println("This display 1000 rows. Press ENTER to show more, input 'q' to quit.");
593-
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
592+
593+
BufferedReader br = new BufferedReader(new InputStreamReader(ctx.getIn()));
594594
try {
595-
if ("".equals(br.readLine())) {
595+
String line;
596+
if (ctx.isDisableCliHistory()) {
597+
line = ctx.getLineReader().readLine();
598+
} else {
599+
line = br.readLine();
600+
}
601+
if ("".equals(line)) {
596602
maxSizeList = new ArrayList<>(columnLength);
597603
lists =
598604
cacheResult(
@@ -601,7 +607,7 @@ private static int executeQuery(CliContext ctx, IoTDBConnection connection, Stri
601607
} else {
602608
break;
603609
}
604-
} catch (IOException e) {
610+
} catch (Exception e) {
605611
ctx.getPrinter().printException(e);
606612
executeStatus = CODE_ERROR;
607613
}

iotdb-client/cli/src/main/java/org/apache/iotdb/cli/utils/JlineUtils.java

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -81,21 +81,23 @@ public static LineReader getLineReader(CliContext ctx, String username, String h
8181
LineReaderBuilder builder = LineReaderBuilder.builder();
8282
builder.terminal(terminal);
8383

84-
// Handle the command history. By default, the number of commands will not exceed 500 and the
85-
// size of the history fill will be less than 10 KB. See:
86-
// org.jline.reader.impl.history#DefaultHistory
87-
String historyFile = ".iotdb_history";
88-
String historyFilePath =
89-
System.getProperty("user.home")
90-
+ File.separator
91-
+ historyFile
92-
+ "-"
93-
+ host.hashCode()
94-
+ "-"
95-
+ port
96-
+ "-"
97-
+ username.hashCode();
98-
builder.variable(LineReader.HISTORY_FILE, new File(historyFilePath));
84+
if (!ctx.isDisableCliHistory()) {
85+
// Handle the command history. By default, the number of commands will not exceed 500 and the
86+
// size of the history fill will be less than 10 KB. See:
87+
// org.jline.reader.impl.history#DefaultHistory
88+
String historyFile = ".iotdb_history";
89+
String historyFilePath =
90+
System.getProperty("user.home")
91+
+ File.separator
92+
+ historyFile
93+
+ "-"
94+
+ host.hashCode()
95+
+ "-"
96+
+ port
97+
+ "-"
98+
+ username.hashCode();
99+
builder.variable(LineReader.HISTORY_FILE, new File(historyFilePath));
100+
}
99101

100102
// TODO: since the lexer doesn't produce tokens for quotation marks, disable the highlighter to
101103
// avoid incorrect inputs.

0 commit comments

Comments
 (0)