2023-12-15 14:54:15 +01:00
|
|
|
const c = document.querySelector(".console")
|
|
|
|
const ps1 = "[fr@website ~]$ "
|
2023-12-18 01:27:09 +01:00
|
|
|
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)
|
|
|
|
}
|
2023-12-15 14:54:15 +01:00
|
|
|
|
|
|
|
function write(key) {
|
|
|
|
console.log("KEY:", key)
|
|
|
|
switch(key) {
|
|
|
|
case "Enter":
|
2023-12-18 01:27:09 +01:00
|
|
|
command = command.split(" ");
|
|
|
|
exec(command)
|
|
|
|
line = document.createElement("p")
|
|
|
|
line.innerHTML += ps1
|
|
|
|
c.appendChild(line)
|
|
|
|
command = ""
|
|
|
|
break
|
2023-12-15 14:54:15 +01:00
|
|
|
case "000ctrll":
|
|
|
|
c.innerHTML = ""
|
2023-12-18 01:27:09 +01:00
|
|
|
line = document.createElement("p")
|
|
|
|
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
|
|
|
|
|
2023-12-15 14:54:15 +01:00
|
|
|
default:
|
2023-12-18 01:27:09 +01:00
|
|
|
c.lastChild.innerHTML += key
|
|
|
|
command += key
|
2023-12-15 14:54:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function customCtrlShortcuts(plusKey) {
|
|
|
|
document.addEventListener("keydown", e => {
|
|
|
|
if(e.ctrlKey && e.key == plusKey) {
|
|
|
|
e.preventDefault()
|
|
|
|
write("000ctrl"+plusKey)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// On load init the terminal
|
|
|
|
window.addEventListener("load", () => {
|
|
|
|
write("000ctrll")
|
|
|
|
})
|
|
|
|
|
|
|
|
// Capture the keypress
|
|
|
|
window.addEventListener("keypress", e => {
|
2023-12-18 01:27:09 +01:00
|
|
|
e.preventDefault()
|
2023-12-15 14:54:15 +01:00
|
|
|
write(e.key)
|
|
|
|
})
|
|
|
|
|
2023-12-18 01:27:09 +01:00
|
|
|
window.addEventListener("keydown", e => {
|
|
|
|
if(e.key == "Backspace") {
|
|
|
|
e.preventDefault()
|
|
|
|
write("000backspace")
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2023-12-15 14:54:15 +01:00
|
|
|
// Register custom ctrl shortcuts
|
|
|
|
customCtrlShortcuts("l") // ctrl + l
|
|
|
|
customCtrlShortcuts("c") // ctrl + c
|
|
|
|
|