Skip to content

Commit 828783d

Browse files
authored
Merge pull request #1 from mertssmnoglu/command_handling
Add commands and update command handler
2 parents 06a65fa + e23ac76 commit 828783d

1 file changed

Lines changed: 17 additions & 3 deletions

File tree

js/script.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,28 @@ window.onload = function () {
33
document.getElementById("shellinput").value = "";
44
}
55

6-
function run(command) {
7-
6+
const commands = [
7+
{
8+
name: "clear",
9+
description: "Clears the console",
10+
run: function () {
11+
document.getElementById("shellinput").value = "";
12+
console.log("Cleared the console")
13+
}
14+
}
15+
]
16+
17+
function run(commandInput) {
18+
for (const command of commands) {
19+
if(command.name == commandInput.value){
20+
return command.run()
21+
}
22+
}
823
}
924

1025
function detectEnter(event,input) {
1126
let keyCode = event.keyCode ? event.keyCode : e.which;
1227
if(keyCode == 13) {
1328
run(input)
14-
document.getElementById("shellinput").value = "";
1529
}
1630
}

0 commit comments

Comments
 (0)