Skip to content

Commit

Permalink
show more use ctx.getIn(), because Sometimes it's not system. in (#14322
Browse files Browse the repository at this point in the history
)

* 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
  • Loading branch information
CritasWang authored Dec 12, 2024
1 parent 54197b9 commit d3b96d8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
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;
Expand Down Expand Up @@ -590,9 +589,16 @@ private static int executeQuery(CliContext ctx, IoTDBConnection connection, Stri
}
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(
Expand All @@ -601,7 +607,7 @@ private static int executeQuery(CliContext ctx, IoTDBConnection connection, Stri
} else {
break;
}
} catch (IOException e) {
} catch (Exception e) {
ctx.getPrinter().printException(e);
executeStatus = CODE_ERROR;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,21 +81,23 @@ public static LineReader getLineReader(CliContext ctx, String username, String h
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.
Expand Down

0 comments on commit d3b96d8

Please sign in to comment.