console #1
@ -16,7 +16,7 @@ smart_punctuation = true
|
|||||||
git = "https://git.filiprojek.cz/fr/website"
|
git = "https://git.filiprojek.cz/fr/website"
|
||||||
nav_items = [
|
nav_items = [
|
||||||
{name="Home", path="/"},
|
{name="Home", path="/"},
|
||||||
{name="About", path="/about"},
|
#{name="About", path="/about"},
|
||||||
{name="Projects", path="/projects/"},
|
#{name="Projects", path="/projects/"},
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -1,53 +1,63 @@
|
|||||||
const c = document.querySelector(".console")
|
const c = document.querySelector(".console")
|
||||||
const ps1 = "[fr@website ~]$ "
|
const ps1 = "[fr@website ~]$ "
|
||||||
|
const motd = "Welcome to my website!<br>You can use `help` for more informations :)"
|
||||||
let line = "";
|
let line = "";
|
||||||
let command = ""
|
|
||||||
|
|
||||||
function exec(command) {
|
function exec(command) {
|
||||||
console.log(command)
|
|
||||||
|
|
||||||
switch (command[0]) {
|
switch (command[0]) {
|
||||||
case "help":
|
case "help":
|
||||||
line = "about<br>projects<br>contact<br>"
|
line = "help<br>author<br>contact<br>clear<br>echo"
|
||||||
break;
|
break;
|
||||||
case "author":
|
case "author":
|
||||||
line = "Filip Rojek, 2023"
|
line = "Filip Rojek, 2023"
|
||||||
break
|
break
|
||||||
case "contact":
|
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>"
|
line = "Filip Rojek <<a href='mailto: filip@filiprojek.cz'>filip@filiprojek.cz</a>><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
|
break
|
||||||
case "clear":
|
case "clear":
|
||||||
write("000ctrll")
|
write("000ctrll")
|
||||||
|
return false
|
||||||
|
case "echo":
|
||||||
|
line = ""
|
||||||
|
command.forEach((cmd, i) => {
|
||||||
|
if (i === 0) return
|
||||||
|
line += cmd + " "
|
||||||
|
});
|
||||||
|
line = line.substring(0, line.length - 1) // remove last space
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
line = "frsh: " + command[0] + ": command not found"
|
line = "frsh: " + command[0] + ": command not found"
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
l = document.createElement("p").innerHTML = line
|
return line
|
||||||
c.appendChild(l)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function write(key) {
|
function write(key, payload) {
|
||||||
console.log("KEY:", key)
|
|
||||||
switch(key) {
|
switch(key) {
|
||||||
case "Enter":
|
case "Enter":
|
||||||
|
command = c.lastChild.textContent.replace(ps1, "")
|
||||||
command = command.split(" ");
|
command = command.split(" ");
|
||||||
exec(command)
|
let out = exec(command)
|
||||||
|
if(out !== false) {
|
||||||
|
line = document.createElement("p")
|
||||||
|
line.innerHTML += out
|
||||||
|
line.innerHTML += "<br>"
|
||||||
|
c.appendChild(line)
|
||||||
line = document.createElement("p")
|
line = document.createElement("p")
|
||||||
line.innerHTML += ps1
|
line.innerHTML += ps1
|
||||||
c.appendChild(line)
|
c.appendChild(line)
|
||||||
|
}
|
||||||
command = ""
|
command = ""
|
||||||
break
|
break
|
||||||
case "000ctrll":
|
case "000ctrll":
|
||||||
c.innerHTML = ""
|
c.innerHTML = ""
|
||||||
|
if(payload == motd) c.innerHTML = motd
|
||||||
line = document.createElement("p")
|
line = document.createElement("p")
|
||||||
line.innerHTML += ps1
|
line.innerHTML += ps1
|
||||||
c.appendChild(line)
|
c.appendChild(line)
|
||||||
break
|
break
|
||||||
case "000backspace":
|
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)) {
|
if(c.lastChild.textContent.slice(0, -1) !== ps1.slice(0, -1)) {
|
||||||
c.lastChild.innerHTML = c.lastChild.textContent.slice(0, -1)
|
c.lastChild.innerHTML = c.lastChild.textContent.slice(0, -1)
|
||||||
}
|
}
|
||||||
@ -55,7 +65,6 @@ function write(key) {
|
|||||||
|
|
||||||
default:
|
default:
|
||||||
c.lastChild.innerHTML += key
|
c.lastChild.innerHTML += key
|
||||||
command += key
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,7 +79,14 @@ function customCtrlShortcuts(plusKey) {
|
|||||||
|
|
||||||
// On load init the terminal
|
// On load init the terminal
|
||||||
window.addEventListener("load", () => {
|
window.addEventListener("load", () => {
|
||||||
write("000ctrll")
|
write("000ctrll", motd)
|
||||||
|
if (navigator.userAgent.toLowerCase().includes("mobile")) {
|
||||||
|
const mi = document.querySelector(".mobile-input")
|
||||||
|
mi.style="opacity: 0; width: 0; height: 0"
|
||||||
|
c.addEventListener("click", e => {
|
||||||
|
mi.focus()
|
||||||
|
})
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
// Capture the keypress
|
// Capture the keypress
|
||||||
@ -89,4 +105,3 @@ window.addEventListener("keydown", e => {
|
|||||||
// Register custom ctrl shortcuts
|
// Register custom ctrl shortcuts
|
||||||
customCtrlShortcuts("l") // ctrl + l
|
customCtrlShortcuts("l") // ctrl + l
|
||||||
customCtrlShortcuts("c") // ctrl + c
|
customCtrlShortcuts("c") // ctrl + c
|
||||||
|
|
||||||
|
@ -7,5 +7,6 @@
|
|||||||
{% block content %}
|
{% block content %}
|
||||||
<section class="console content" >
|
<section class="console content" >
|
||||||
</section>
|
</section>
|
||||||
|
<textarea class="mobile-input" style="display: none" disabled autofocus></textarea>
|
||||||
<script src="/js/console.js" defer></script>
|
<script src="/js/console.js" defer></script>
|
||||||
{% endblock content %}
|
{% endblock content %}
|
||||||
|
Loading…
Reference in New Issue
Block a user