From e7e8b789047e6f94d36eb190fa0c0a2ae06428e1 Mon Sep 17 00:00:00 2001 From: Filip Rojek Date: Fri, 15 Dec 2023 14:54:15 +0100 Subject: [PATCH 1/3] Added: able to write keystrokes into command line --- content/console.md | 4 ++++ sass/console.scss | 5 +++++ static/js/console.js | 43 ++++++++++++++++++++++++++++++++++++++++++ templates/console.html | 11 +++++++++++ 4 files changed, 63 insertions(+) create mode 100644 content/console.md create mode 100644 sass/console.scss create mode 100644 static/js/console.js create mode 100644 templates/console.html diff --git a/content/console.md b/content/console.md new file mode 100644 index 0000000..262408e --- /dev/null +++ b/content/console.md @@ -0,0 +1,4 @@ ++++ +title = "Console" +template = "console.html" ++++ diff --git a/sass/console.scss b/sass/console.scss new file mode 100644 index 0000000..38c3a00 --- /dev/null +++ b/sass/console.scss @@ -0,0 +1,5 @@ +.console { + background: gray; + width: 80vw; + min-height: 20vh; +} diff --git a/static/js/console.js b/static/js/console.js new file mode 100644 index 0000000..87f71b7 --- /dev/null +++ b/static/js/console.js @@ -0,0 +1,43 @@ +const c = document.querySelector(".console") +const ps1 = "[fr@website ~]$ " + +function write(key) { + console.log("KEY:", key) + switch(key) { + case "Enter": + c.innerHTML += "
" + 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 + diff --git a/templates/console.html b/templates/console.html new file mode 100644 index 0000000..9337d4c --- /dev/null +++ b/templates/console.html @@ -0,0 +1,11 @@ +{% extends "base.html" %} + +{% block styles %} + +{% endblock styles %} + +{% block content %} +
+
+ +{% endblock content %} -- 2.45.2 From f16811229451ab43515f581646c4fde2646b7d0c Mon Sep 17 00:00:00 2001 From: Filip Rojek Date: Mon, 18 Dec 2023 01:27:09 +0100 Subject: [PATCH 2/3] Trying to add commands into console --- static/js/console.js | 63 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 56 insertions(+), 7 deletions(-) diff --git a/static/js/console.js b/static/js/console.js index 87f71b7..f2a6869 100644 --- a/static/js/console.js +++ b/static/js/console.js @@ -1,19 +1,61 @@ const c = document.querySelector(".console") const ps1 = "[fr@website ~]$ " +let line = ""; +let command = "" + +function exec(command) { + console.log(command) + + switch (command[0]) { + case "help": + line = "about
projects
contact
" + break; + case "author": + line = "Filip Rojek, 2023" + break + case "contact": + line = "Filip Rojek <filip@filiprojek.cz>
web: www.filiprojek.cz
telegram: @filiprojek" + 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) { console.log("KEY:", key) switch(key) { case "Enter": - c.innerHTML += "
" - c.innerHTML += ps1 - return + command = command.split(" "); + exec(command) + line = document.createElement("p") + line.innerHTML += ps1 + c.appendChild(line) + command = "" + break case "000ctrll": c.innerHTML = "" - c.innerHTML += ps1 - return + 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 + default: - c.innerHTML += key + c.lastChild.innerHTML += key + command += key } } @@ -33,10 +75,17 @@ window.addEventListener("load", () => { // Capture the keypress window.addEventListener("keypress", e => { - console.log(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 -- 2.45.2 From d365dd4d25676a85a09acb89a5865e4a11bd5fae Mon Sep 17 00:00:00 2001 From: Filip Rojek Date: Mon, 18 Dec 2023 03:27:31 +0100 Subject: [PATCH 3/3] Console fixed, hide about and projects page --- config.toml | 4 ++-- static/js/console.js | 51 +++++++++++++++++++++++++++--------------- templates/console.html | 3 ++- 3 files changed, 37 insertions(+), 21 deletions(-) diff --git a/config.toml b/config.toml index 61f7d5f..0ba7103 100644 --- a/config.toml +++ b/config.toml @@ -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/"}, ] diff --git a/static/js/console.js b/static/js/console.js index f2a6869..56bd92a 100644 --- a/static/js/console.js +++ b/static/js/console.js @@ -1,53 +1,63 @@ const c = document.querySelector(".console") const ps1 = "[fr@website ~]$ " +const motd = "Welcome to my website!
You can use `help` for more informations :)" let line = ""; -let command = "" function exec(command) { - console.log(command) - switch (command[0]) { case "help": - line = "about
projects
contact
" + line = "help
author
contact
clear
echo" break; case "author": line = "Filip Rojek, 2023" break case "contact": - line = "Filip Rojek <filip@filiprojek.cz>
web: www.filiprojek.cz
telegram: @filiprojek" + line = "Filip Rojek <filip@filiprojek.cz>
web: www.filiprojek.cz
telegram: @filiprojek" 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; } - l = document.createElement("p").innerHTML = line - c.appendChild(l) + return line } -function write(key) { - console.log("KEY:", key) +function write(key, payload) { switch(key) { case "Enter": + command = c.lastChild.textContent.replace(ps1, "") command = command.split(" "); - exec(command) - line = document.createElement("p") - line.innerHTML += ps1 - c.appendChild(line) + let out = exec(command) + if(out !== false) { + line = document.createElement("p") + line.innerHTML += out + line.innerHTML += "
" + 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": - 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) } @@ -55,7 +65,6 @@ function write(key) { default: c.lastChild.innerHTML += key - command += key } } @@ -70,7 +79,14 @@ function customCtrlShortcuts(plusKey) { // On load init the terminal 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 @@ -89,4 +105,3 @@ window.addEventListener("keydown", e => { // Register custom ctrl shortcuts customCtrlShortcuts("l") // ctrl + l customCtrlShortcuts("c") // ctrl + c - diff --git a/templates/console.html b/templates/console.html index 9337d4c..cd10a87 100644 --- a/templates/console.html +++ b/templates/console.html @@ -5,7 +5,8 @@ {% endblock styles %} {% block content %} -
+
+ {% endblock content %} -- 2.45.2