Skip to content

Commit

Permalink
Add the "clear" command to the CLI
Browse files Browse the repository at this point in the history
Note that this very same functionality can already be achieved
by using the ctrl-L keyboard shortcut.
  • Loading branch information
findinpath authored and electrum committed May 3, 2021
1 parent f9311ae commit 0dfafc8
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
6 changes: 6 additions & 0 deletions client/trino-cli/src/main/java/io/trino/cli/Console.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.jline.reader.UserInterruptException;
import org.jline.terminal.Terminal;
import org.jline.utils.AttributedStringBuilder;
import org.jline.utils.InfoCmp;
import picocli.CommandLine.Command;
import picocli.CommandLine.Mixin;
import picocli.CommandLine.Option;
Expand Down Expand Up @@ -259,6 +260,11 @@ private static void runConsole(QueryRunner queryRunner, AtomicBoolean exiting)
case "exit":
case "quit":
return;
case "clear":
Terminal terminal = reader.getTerminal();
terminal.puts(InfoCmp.Capability.clear_screen);
terminal.flush();
continue;
case "history":
for (History.Entry entry : reader.getHistory()) {
System.out.println(new AttributedStringBuilder()
Expand Down
1 change: 1 addition & 0 deletions client/trino-cli/src/main/java/io/trino/cli/Help.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public static String getHelpText()
return "" +
"Supported commands:\n" +
"QUIT\n" +
"CLEAR\n" +
"EXPLAIN [ ( option [, ...] ) ] <query>\n" +
" options: FORMAT { TEXT | GRAPHVIZ | JSON }\n" +
" TYPE { LOGICAL | DISTRIBUTED | VALIDATE | IO }\n" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
public class InputParser
implements Parser
{
private static final Set<String> SPECIAL = ImmutableSet.of("exit", "quit", "history", "help");
private static final Set<String> SPECIAL = ImmutableSet.of("exit", "quit", "history", "help", "clear");

@Override
public ParsedLine parse(String line, int cursor, ParseContext context)
Expand Down

0 comments on commit 0dfafc8

Please sign in to comment.