From 0e05bb61bc2cbc2208126254690a4887e4b7c358 Mon Sep 17 00:00:00 2001 From: Justin Crawford Date: Thu, 3 Oct 2019 21:41:02 -0700 Subject: [PATCH] Support CTRL+D for exiting the console Support CTRL+D for exiting the console, also support "cls" for clearing the screen (on supported terminals). --- .../ryanmichela/sshd/ConsoleShellFactory.java | 13 ++++++++++++- .../java/com/ryanmichela/sshd/SshTerminal.java | 16 ++++++++-------- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/ryanmichela/sshd/ConsoleShellFactory.java b/src/main/java/com/ryanmichela/sshd/ConsoleShellFactory.java index de9900c..15acb7c 100644 --- a/src/main/java/com/ryanmichela/sshd/ConsoleShellFactory.java +++ b/src/main/java/com/ryanmichela/sshd/ConsoleShellFactory.java @@ -116,10 +116,21 @@ public class ConsoleShellFactory implements ShellFactory { while (true) { String command = this.ConsoleReader.readLine("\r>", null); - if (command == null || command.trim().isEmpty()) + // The user sent CTRL+D to close the shell, terminate the session. + if (command == null) + break; + // Skip someone spamming enter + if (command.trim().isEmpty()) continue; + // User wants to exit if (command.equals("exit") || command.equals("quit")) break; + // Clear the text from the screen (on supported terminals) + if (command.equals("cls")) + { + this.ConsoleReader.clearScreen(); + continue; + } Bukkit.getScheduler().runTask( SshdPlugin.instance, () -> diff --git a/src/main/java/com/ryanmichela/sshd/SshTerminal.java b/src/main/java/com/ryanmichela/sshd/SshTerminal.java index 64ad2d5..876f1c4 100644 --- a/src/main/java/com/ryanmichela/sshd/SshTerminal.java +++ b/src/main/java/com/ryanmichela/sshd/SshTerminal.java @@ -7,13 +7,13 @@ import jline.TerminalSupport; */ public class SshTerminal extends TerminalSupport { - protected SshTerminal() { - super(true); - } + protected SshTerminal() { + super(true); + } - @Override - public void init() throws Exception { - setAnsiSupported(true); - setEchoEnabled(true); - } + @Override + public void init() throws Exception { + setAnsiSupported(true); + setEchoEnabled(true); + } }