diff --git a/js/main.js b/js/main.js index 4538065..12e81ad 100644 --- a/js/main.js +++ b/js/main.js @@ -123,10 +123,12 @@ function outputText(params) { tbDiv.removeChild(textIn); tbDiv.removeChild(textCur); + let inputSet, whitespaceOnly = false; if (user !== undefined) { // Save input into history if it's not empty - const inputSet = new Set(user.split('')); - if (user !== "" || inputSet.has(" ") && inputSet.size === 1) { + inputSet = new Set(user.split('')); + whitespaceOnly = inputSet.has(" ") && inputSet.size === 1; + if (user !== "" && !whitespaceOnly) { history.list.push(user); history.index = history.list.length; } @@ -144,7 +146,7 @@ function outputText(params) { // Run command and return output const isUserInput = output === undefined && user !== undefined; - let commandOutput = isUserInput ? runCommand(user) : output; + let commandOutput = (isUserInput && !whitespaceOnly) ? runCommand(user) : (output ? output : ""); if (commandOutput !== "" && commandOutput !== null) { // If output is given, display it as text with formatting tbDiv.append(createText(commandOutput, false))