Support CTRL+D for exiting the console

Support CTRL+D for exiting the console, also support "cls" for
clearing the screen (on supported terminals).
This commit is contained in:
Justin Crawford 2019-10-03 21:41:02 -07:00
parent 0635ea7a35
commit 0e05bb61bc
No known key found for this signature in database
GPG Key ID: 0D84DEDBB8EF259C
2 changed files with 20 additions and 9 deletions

View File

@ -116,10 +116,21 @@ public class ConsoleShellFactory implements ShellFactory {
while (true) while (true)
{ {
String command = this.ConsoleReader.readLine("\r>", null); 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; continue;
// User wants to exit
if (command.equals("exit") || command.equals("quit")) if (command.equals("exit") || command.equals("quit"))
break; break;
// Clear the text from the screen (on supported terminals)
if (command.equals("cls"))
{
this.ConsoleReader.clearScreen();
continue;
}
Bukkit.getScheduler().runTask( Bukkit.getScheduler().runTask(
SshdPlugin.instance, () -> SshdPlugin.instance, () ->

View File

@ -7,13 +7,13 @@ import jline.TerminalSupport;
*/ */
public class SshTerminal extends TerminalSupport { public class SshTerminal extends TerminalSupport {
protected SshTerminal() { protected SshTerminal() {
super(true); super(true);
} }
@Override @Override
public void init() throws Exception { public void init() throws Exception {
setAnsiSupported(true); setAnsiSupported(true);
setEchoEnabled(true); setEchoEnabled(true);
} }
} }