Skip to content

Commit 0dfafc8

Browse files
findinpathelectrum
authored andcommitted
Add the "clear" command to the CLI
Note that this very same functionality can already be achieved by using the ctrl-L keyboard shortcut.
1 parent f9311ae commit 0dfafc8

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

client/trino-cli/src/main/java/io/trino/cli/Console.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.jline.reader.UserInterruptException;
3232
import org.jline.terminal.Terminal;
3333
import org.jline.utils.AttributedStringBuilder;
34+
import org.jline.utils.InfoCmp;
3435
import picocli.CommandLine.Command;
3536
import picocli.CommandLine.Mixin;
3637
import picocli.CommandLine.Option;
@@ -259,6 +260,11 @@ private static void runConsole(QueryRunner queryRunner, AtomicBoolean exiting)
259260
case "exit":
260261
case "quit":
261262
return;
263+
case "clear":
264+
Terminal terminal = reader.getTerminal();
265+
terminal.puts(InfoCmp.Capability.clear_screen);
266+
terminal.flush();
267+
continue;
262268
case "history":
263269
for (History.Entry entry : reader.getHistory()) {
264270
System.out.println(new AttributedStringBuilder()

client/trino-cli/src/main/java/io/trino/cli/Help.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public static String getHelpText()
2222
return "" +
2323
"Supported commands:\n" +
2424
"QUIT\n" +
25+
"CLEAR\n" +
2526
"EXPLAIN [ ( option [, ...] ) ] <query>\n" +
2627
" options: FORMAT { TEXT | GRAPHVIZ | JSON }\n" +
2728
" TYPE { LOGICAL | DISTRIBUTED | VALIDATE | IO }\n" +

client/trino-cli/src/main/java/io/trino/cli/InputParser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
public class InputParser
3131
implements Parser
3232
{
33-
private static final Set<String> SPECIAL = ImmutableSet.of("exit", "quit", "history", "help");
33+
private static final Set<String> SPECIAL = ImmutableSet.of("exit", "quit", "history", "help", "clear");
3434

3535
@Override
3636
public ParsedLine parse(String line, int cursor, ParseContext context)

0 commit comments

Comments
 (0)