Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
d365dd4d25 | |||
f168112294 | |||
e7e8b78904 |
@ -16,7 +16,7 @@ smart_punctuation = true
|
||||
git = "https://git.filiprojek.cz/fr/website"
|
||||
nav_items = [
|
||||
{name="Home", path="/"},
|
||||
{name="About", path="/about"},
|
||||
{name="Projects", path="/projects/"},
|
||||
#{name="About", path="/about"},
|
||||
#{name="Projects", path="/projects/"},
|
||||
]
|
||||
|
||||
|
4
content/console.md
Normal file
4
content/console.md
Normal file
@ -0,0 +1,4 @@
|
||||
+++
|
||||
title = "Console"
|
||||
template = "console.html"
|
||||
+++
|
5
sass/console.scss
Normal file
5
sass/console.scss
Normal file
@ -0,0 +1,5 @@
|
||||
.console {
|
||||
background: gray;
|
||||
width: 80vw;
|
||||
min-height: 20vh;
|
||||
}
|
107
static/js/console.js
Normal file
107
static/js/console.js
Normal file
@ -0,0 +1,107 @@
|
||||
const c = document.querySelector(".console")
|
||||
const ps1 = "[fr@website ~]$ "
|
||||
const motd = "Welcome to my website!<br>You can use `help` for more informations :)"
|
||||
let line = "";
|
||||
|
||||
function exec(command) {
|
||||
switch (command[0]) {
|
||||
case "help":
|
||||
line = "help<br>author<br>contact<br>clear<br>echo"
|
||||
break;
|
||||
case "author":
|
||||
line = "Filip Rojek, 2023"
|
||||
break
|
||||
case "contact":
|
||||
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
|
||||
case "clear":
|
||||
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
|
||||
default:
|
||||
line = "frsh: " + command[0] + ": command not found"
|
||||
break;
|
||||
}
|
||||
|
||||
return line
|
||||
}
|
||||
|
||||
function write(key, payload) {
|
||||
switch(key) {
|
||||
case "Enter":
|
||||
command = c.lastChild.textContent.replace(ps1, "")
|
||||
command = command.split(" ");
|
||||
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.innerHTML += ps1
|
||||
c.appendChild(line)
|
||||
}
|
||||
command = ""
|
||||
break
|
||||
case "000ctrll":
|
||||
c.innerHTML = ""
|
||||
if(payload == motd) c.innerHTML = motd
|
||||
line = document.createElement("p")
|
||||
line.innerHTML += ps1
|
||||
c.appendChild(line)
|
||||
break
|
||||
case "000backspace":
|
||||
if(c.lastChild.textContent.slice(0, -1) !== ps1.slice(0, -1)) {
|
||||
c.lastChild.innerHTML = c.lastChild.textContent.slice(0, -1)
|
||||
}
|
||||
break
|
||||
|
||||
default:
|
||||
c.lastChild.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", 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
|
||||
window.addEventListener("keypress", e => {
|
||||
e.preventDefault()
|
||||
write(e.key)
|
||||
})
|
||||
|
||||
window.addEventListener("keydown", e => {
|
||||
if(e.key == "Backspace") {
|
||||
e.preventDefault()
|
||||
write("000backspace")
|
||||
}
|
||||
})
|
||||
|
||||
// Register custom ctrl shortcuts
|
||||
customCtrlShortcuts("l") // ctrl + l
|
||||
customCtrlShortcuts("c") // ctrl + c
|
12
templates/console.html
Normal file
12
templates/console.html
Normal file
@ -0,0 +1,12 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block styles %}
|
||||
<link rel="stylesheet" href="/console.css">
|
||||
{% endblock styles %}
|
||||
|
||||
{% block content %}
|
||||
<section class="console content" >
|
||||
</section>
|
||||
<textarea class="mobile-input" style="display: none" disabled autofocus></textarea>
|
||||
<script src="/js/console.js" defer></script>
|
||||
{% endblock content %}
|
Loading…
Reference in New Issue
Block a user