added semicolon support to terminal as well as autocomplete support for semicolon commands

This commit is contained in:
Olivier Gagnon 2018-07-30 20:16:39 -04:00
parent fabc45f496
commit c4b25a0c90

@ -112,16 +112,21 @@ $(document).keydown(function(event) {
if (event.keyCode === KEY.ENTER) { if (event.keyCode === KEY.ENTER) {
event.preventDefault(); //Prevent newline from being entered in Script Editor event.preventDefault(); //Prevent newline from being entered in Script Editor
var command = $('input[class=terminal-input]').val(); var command = $('input[class=terminal-input]').val();
if (command.length > 0) { post(
post( "[" +
"[" + (FconfSettings.ENABLE_TIMESTAMPS ? Terminal.getTimestamp() + " " : "") +
(FconfSettings.ENABLE_TIMESTAMPS ? Terminal.getTimestamp() + " " : "") + Player.getCurrentServer().hostname +
Player.getCurrentServer().hostname + " ~]> " + command
" ~]> " + command );
);
if (command.length > 0) {
Terminal.resetTerminalInput(); //Clear input first Terminal.resetTerminalInput(); //Clear input first
Terminal.executeCommand(command); const commands = command.split(";");
for(let i = 0; i < commands.length; i++) {
if(commands[i].match(/^\s*$/)) { continue; }
Terminal.executeCommand(commands[i]);
}
} }
} }
@ -197,6 +202,12 @@ $(document).keydown(function(event) {
if (terminalInput == null) {return;} if (terminalInput == null) {return;}
var input = terminalInput.value; var input = terminalInput.value;
if (input == "") {return;} if (input == "") {return;}
const semiColonIndex = input.lastIndexOf(";");
if(semiColonIndex !== -1) {
input = input.slice(semiColonIndex+1);
}
input = input.trim(); input = input.trim();
input = input.replace(/\s\s+/g, ' '); input = input.replace(/\s\s+/g, ' ');
@ -349,7 +360,18 @@ function tabCompletion(command, arg, allPossibilities, index=0) {
} else { } else {
val = command + " " + allPossibilities[0]; val = command + " " + allPossibilities[0];
} }
document.getElementById("terminal-input-text-box").value = val;
const textBox = document.getElementById("terminal-input-text-box");
const oldValue = textBox.value;
const semiColonIndex = oldValue.lastIndexOf(";");
if(semiColonIndex === -1) {
// no ; replace the whole thing.
textBox.value = val;
} else {
// replace just after the last semicolon
textBox.value = textBox.value.slice(0, semiColonIndex+1)+" "+val;
}
document.getElementById("terminal-input-text-box").focus(); document.getElementById("terminal-input-text-box").focus();
} else { } else {
var longestStartSubstr = longestCommonStart(allPossibilities); var longestStartSubstr = longestCommonStart(allPossibilities);