Trying to add commands into console
This commit is contained in:
parent
e7e8b78904
commit
f168112294
@ -1,19 +1,61 @@
|
|||||||
const c = document.querySelector(".console")
|
const c = document.querySelector(".console")
|
||||||
const ps1 = "[fr@website ~]$ "
|
const ps1 = "[fr@website ~]$ "
|
||||||
|
let line = "";
|
||||||
|
let command = ""
|
||||||
|
|
||||||
|
function exec(command) {
|
||||||
|
console.log(command)
|
||||||
|
|
||||||
|
switch (command[0]) {
|
||||||
|
case "help":
|
||||||
|
line = "about<br>projects<br>contact<br>"
|
||||||
|
break;
|
||||||
|
case "author":
|
||||||
|
line = "Filip Rojek, 2023"
|
||||||
|
break
|
||||||
|
case "contact":
|
||||||
|
line = "Filip Rojek <filip@filiprojek.cz><br>web: <a href='https://filiprojek.cz' target='_blank'>www.filiprojek.cz</a><br>telegram: <a href='https://t.me/filiprojek' target='_blank'>@filiprojek</a>"
|
||||||
|
break
|
||||||
|
case "clear":
|
||||||
|
write("000ctrll")
|
||||||
|
break
|
||||||
|
default:
|
||||||
|
line = "frsh: " + command[0] + ": command not found"
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
l = document.createElement("p").innerHTML = line
|
||||||
|
c.appendChild(l)
|
||||||
|
}
|
||||||
|
|
||||||
function write(key) {
|
function write(key) {
|
||||||
console.log("KEY:", key)
|
console.log("KEY:", key)
|
||||||
switch(key) {
|
switch(key) {
|
||||||
case "Enter":
|
case "Enter":
|
||||||
c.innerHTML += "<br>"
|
command = command.split(" ");
|
||||||
c.innerHTML += ps1
|
exec(command)
|
||||||
return
|
line = document.createElement("p")
|
||||||
|
line.innerHTML += ps1
|
||||||
|
c.appendChild(line)
|
||||||
|
command = ""
|
||||||
|
break
|
||||||
case "000ctrll":
|
case "000ctrll":
|
||||||
c.innerHTML = ""
|
c.innerHTML = ""
|
||||||
c.innerHTML += ps1
|
line = document.createElement("p")
|
||||||
return
|
line.innerHTML += ps1
|
||||||
|
c.appendChild(line)
|
||||||
|
break
|
||||||
|
case "000backspace":
|
||||||
|
console.log(c.textContent.slice(0, -1))
|
||||||
|
console.log(ps1 == c.textContent)
|
||||||
|
if(c.lastChild.textContent.slice(0, -1) !== ps1.slice(0, -1)) {
|
||||||
|
c.lastChild.innerHTML = c.lastChild.textContent.slice(0, -1)
|
||||||
|
}
|
||||||
|
break
|
||||||
|
|
||||||
default:
|
default:
|
||||||
c.innerHTML += key
|
c.lastChild.innerHTML += key
|
||||||
|
command += key
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -33,10 +75,17 @@ window.addEventListener("load", () => {
|
|||||||
|
|
||||||
// Capture the keypress
|
// Capture the keypress
|
||||||
window.addEventListener("keypress", e => {
|
window.addEventListener("keypress", e => {
|
||||||
console.log(e)
|
e.preventDefault()
|
||||||
write(e.key)
|
write(e.key)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
window.addEventListener("keydown", e => {
|
||||||
|
if(e.key == "Backspace") {
|
||||||
|
e.preventDefault()
|
||||||
|
write("000backspace")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
// Register custom ctrl shortcuts
|
// Register custom ctrl shortcuts
|
||||||
customCtrlShortcuts("l") // ctrl + l
|
customCtrlShortcuts("l") // ctrl + l
|
||||||
customCtrlShortcuts("c") // ctrl + c
|
customCtrlShortcuts("c") // ctrl + c
|
||||||
|
Loading…
Reference in New Issue
Block a user