Added command history into client

This commit is contained in:
Carlos 2019-08-23 14:56:10 +02:00
parent 36f950f2c3
commit 13d374ec32
5 changed files with 27 additions and 4 deletions

View File

@ -11,6 +11,7 @@ var persistenceManager = new WebConsolePersistenceManager();
var connectionManager = new WebConsoleManager();
var autoPasswordCompleted = false; //When true, saved password was used. If a 401 is received, then saved password is not correct
var statusCommandsInterval = -1;
var commandHistoryIndex = -1; //Saves current command history index. -1 when not browsing history.
/**
* Prepare and show server to user
@ -26,6 +27,7 @@ function openServer(serverName){
//New server, new variables:
autoPasswordCompleted = false;
commandHistoryIndex = -1; //Reset command history index
//Create or retrieve connection
connectionManager.loadConnection(serverName);
@ -206,6 +208,9 @@ function backToHomepage(){
//Stop gathering info from server
clearInterval(statusCommandsInterval);
statusCommandsInterval = -1;
//Reset command history index
commandHistoryIndex = -1;
//Clear all server indicators
writePlayerInfo(0, 0);

View File

@ -11,6 +11,7 @@ class WebConsoleConnector {
this.serverURI = serverURI;
this.subscribers = []; //List of functions called when a new message arrive
this.messages = []; //All messages retrieved since connection start
this.commands = []; //EXEC Commands sent by user to this server
}
/**

View File

@ -88,13 +88,14 @@ $('#passwordModal').on('hidden.bs.modal', function (e) {
$("#sendCommandButton").click(function() {
connectionManager.sendConsoleCmd($("#commandInput").val());
$("#commandInput").val('');
commandHistoryIndex = -1; //Reset command history index
});
/**
* Enter key on command input
* Enter or arrow up key on command input
*/
$("#commandInput").on('keypress', function (e) {
if(e.which === 13){
$("#commandInput").on('keydown', function (e) {
if(e.which === 13){ //Detect enter key
//Disable textbox to prevent multiple submit
$(this).attr("disabled", "disabled");
@ -106,6 +107,21 @@ $("#commandInput").on('keypress', function (e) {
//Focus again
$(this).focus();
}else if(e.which === 38){ //Detect arrow up key
//Replace with older command
if(commandHistoryIndex == -1){
//If not browsing history, start by latest command sent
commandHistoryIndex = connectionManager.activeConnection.commands.length;
}
$("#commandInput").val(connectionManager.activeConnection.commands[commandHistoryIndex - 1]);
commandHistoryIndex = commandHistoryIndex - 1;
}else if(e.which === 40){ //Detect arrow down key
//Replace with newer command
if(commandHistoryIndex !== -1){
//If not browsing history, do nothing
$("#commandInput").val(connectionManager.activeConnection.commands[commandHistoryIndex + 1]);
commandHistoryIndex = commandHistoryIndex + 1;
}
}
});

View File

@ -68,6 +68,7 @@ class WebConsoleManager {
*/
sendConsoleCmd(cmd){
this.activeConnection.sendToServer("EXEC " + cmd);
this.activeConnection.commands.push(cmd);
}
/**

View File

@ -68,7 +68,7 @@ public class WSServer extends WebSocketServer {
public void onClose(WebSocket conn, int code, String reason, boolean remote) {
LoginManager.getInstance().logOut(conn.getRemoteSocketAddress());
Bukkit.getLogger()
.info("[WebConsole] Closed WS connection " + conn.getRemoteSocketAddress() + ". Reason: " + reason);
.info("[WebConsole] Closed WS connection " + conn.getRemoteSocketAddress());
}
@Override