From 5cda03fe2ae440f8c364ad8b1d8d586971a9b458 Mon Sep 17 00:00:00 2001 From: valentijn <120188387+HerpieDerpieee@users.noreply.github.com> Date: Mon, 15 Jan 2024 20:42:00 +0100 Subject: [PATCH] made a simple terminal --- .idea/.gitignore | 8 +++++ .idea/PS-Portfolio.iml | 8 +++++ .idea/modules.xml | 8 +++++ .idea/php.xml | 25 ++++++++++++++ .idea/vcs.xml | 6 ++++ website/index.php | 31 +++++++++++++++++ website/os.php | 1 + website/styles.css | 68 ++++++++++++++++++++++++++++++++++++++ website/terminal.js | 75 ++++++++++++++++++++++++++++++++++++++++++ 9 files changed, 230 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 .idea/PS-Portfolio.iml create mode 100644 .idea/modules.xml create mode 100644 .idea/php.xml create mode 100644 .idea/vcs.xml create mode 100644 website/index.php create mode 100644 website/os.php create mode 100644 website/styles.css create mode 100644 website/terminal.js diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/PS-Portfolio.iml b/.idea/PS-Portfolio.iml new file mode 100644 index 0000000..c956989 --- /dev/null +++ b/.idea/PS-Portfolio.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..28d630f --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/php.xml b/.idea/php.xml new file mode 100644 index 0000000..cdb4cd1 --- /dev/null +++ b/.idea/php.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/website/index.php b/website/index.php new file mode 100644 index 0000000..a4a209c --- /dev/null +++ b/website/index.php @@ -0,0 +1,31 @@ + + + + + + + HerpDerpOS - Root + + + + + + + + +
+
+
+

+

:

+

~/projects

+

$

+ +
+
+
+
+ + + \ No newline at end of file diff --git a/website/os.php b/website/os.php new file mode 100644 index 0000000..b3d9bbc --- /dev/null +++ b/website/os.php @@ -0,0 +1 @@ + { + element.innerHTML = `${username}@${hostname}`; + }); + + const terminalInput = document.getElementById("terminalInput"); + + terminalInput.addEventListener("input", function (e) { + resizeInput(); + }); + resizeInput() + + terminalInput.addEventListener('blur', function(e) { + e.preventDefault(); + terminalInput.focus(); + }, false); + terminalInput.focus(); + + + terminalInput.addEventListener("keydown", function (e) { + if (e.key === "Enter"){ + sendCommand(e); + } + }); + +}); + +function sendCommand(e){ + const command = e.target.value; + console.log("COMMAND SENT: "+command); + e.target.value = ""; + resizeInput(); +} + + +function resizeInput() { + const inputText = terminalInput.value; + const inputWidth = measureTextWidth(inputText); + const maxWidth = 300; // Set your desired maximum width + + if (inputWidth <= maxWidth) { + terminalInput.style.width = inputWidth + "px"; + } else { + terminalInput.style.width = maxWidth + "px"; + terminalInput.value = inputText.slice(0, -1); // Remove the last character + } +} + + + +function measureTextWidth(text) { + const nonBreakingSpace = '\u00A0'; + const sanitizedText = text.replace(/ /g, nonBreakingSpace); + + const fakeElement = document.createElement("div"); + fakeElement.style.visibility = "hidden"; + fakeElement.style.position = "absolute"; + fakeElement.style.top = "0"; + fakeElement.style.left = "0"; + fakeElement.style.width = "auto"; + fakeElement.style.fontFamily = "Source Code Pro"; + fakeElement.style.fontSize = "16px"; + fakeElement.style.whiteSpace = "nowrap"; + fakeElement.innerHTML = sanitizedText; + + document.body.appendChild(fakeElement); + const width = fakeElement.offsetWidth; + document.body.removeChild(fakeElement); + + return width; +} \ No newline at end of file