website/static/js/console.js

44 lines
854 B
JavaScript
Raw Normal View History

const c = document.querySelector(".console")
const ps1 = "[fr@website ~]$ "
function write(key) {
console.log("KEY:", key)
switch(key) {
case "Enter":
c.innerHTML += "<br>"
c.innerHTML += ps1
return
case "000ctrll":
c.innerHTML = ""
c.innerHTML += ps1
return
default:
c.innerHTML += key
}
}
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 => {
console.log(e)
write(e.key)
})
// Register custom ctrl shortcuts
customCtrlShortcuts("l") // ctrl + l
customCtrlShortcuts("c") // ctrl + c