From 06d532257752dc8e743e6dd437e609b72a44f0a4 Mon Sep 17 00:00:00 2001 From: ION606 Date: Wed, 11 Jun 2025 18:38:01 -0400 Subject: [PATCH] added unecessarily good file system --- CSS/README.css | 74 ++++++++++++++++++++++++++++ JS/terminal.js | 127 ++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 199 insertions(+), 2 deletions(-) diff --git a/CSS/README.css b/CSS/README.css index 1fae20a..2697475 100644 --- a/CSS/README.css +++ b/CSS/README.css @@ -574,4 +574,78 @@ body.flicker { #virusMsg { text-align: center; +} + +/* vi editor overlay styles */ +.vi-editor-overlay { + position: fixed; + top: 0; + left: 0; + width: 100vw; + height: 100vh; + background: rgba(20, 20, 30, 0.97); + z-index: 9999; + display: flex; + align-items: center; + justify-content: center; +} + +.vi-editor-box { + background: #181825; + border-radius: 10px; + box-shadow: 0 4px 32px #000a; + padding: 2rem; + width: min(90vw, 600px); + max-width: 100vw; + display: flex; + flex-direction: column; + align-items: stretch; +} + +.vi-editor-title { + color: #7c3aed; + font-family: monospace; + font-size: 1.2rem; + margin-bottom: 1rem; + text-align: center; +} + +.vi-editor-textarea { + width: 100%; + height: 250px; + resize: vertical; + background: #232136; + color: #fff; + border: none; + border-radius: 6px; + padding: 1rem; + font-family: monospace; + font-size: 1rem; + outline: none; + margin-bottom: 1rem; +} + +.vi-editor-btnrow { + display: flex; + gap: 1rem; + justify-content: flex-end; +} + +.vi-editor-savebtn { + background: #7c3aed; + color: #fff; + border: none; + padding: 0.5rem 1.2rem; + border-radius: 5px; + font-weight: bold; + cursor: pointer; +} + +.vi-editor-cancelbtn { + background: #232136; + color: #fff; + border: none; + padding: 0.5rem 1.2rem; + border-radius: 5px; + cursor: pointer; } \ No newline at end of file diff --git a/JS/terminal.js b/JS/terminal.js index bc0569e..f0b5419 100644 --- a/JS/terminal.js +++ b/JS/terminal.js @@ -138,6 +138,12 @@ class TerminalFS { }; this.files = { + "/home/guest": ` +Welcome, Guest! + +Feel free to explore our terminal. Enjoy the interactive experience, and don't hesitate to check out the projects and fun files. +Have a great time! +`, "/home/ion606/todo.txt": ` 1. Take over the world 2. Make coffee β˜• @@ -375,6 +381,124 @@ Boot sequence: πŸ•ΊπŸ’ƒπŸͺ©
  • run [file] - Run a file (e.g., .exe)
  • `, + mkdir: (dirName) => { + const newpath = this.resolvePath(dirName); + if (this.fs[newpath]) return `Directory exists!`; + + this.fs[newpath] = { + type: "dir", + children: [], + } + + return `Created ${dirName}`; + }, + + rm: (fname) => { + if (!fname) return "please provide a file/folder to remove"; + + const fpath = this.resolvePath(fname), + strplit = fpath.split('/').filter(Boolean), + dirName = strplit.length > 1 ? strplit.slice(0, -1).join('/') : `/${strplit[0]}` + + if (!dirName) return `file or folder "${fpath}" not found!` + + // dir + if (this.fs[fpath]) { + for (const file of this.fs[fpath]?.children) { + delete this.files[this.resolvePath(file)]; + } + + if (fpath != '/') { + const parentDir = fpath.substring(0, fpath.lastIndexOf('/') + 1); + + if (this.fs[parentDir]) { + this.fs[parentDir].children = this.fs[parentDir].children.filter(f => f !== fname); + } + } + + delete this.fs[dirName]; + return "removing folder"; + } + // file + else if (this.files[fpath]) { + this.fs[`/${dirName}`].children = this.fs[`/${dirName}`].children.filter(c => c !== fname); + delete this.files[fpath]; + + return "removing file"; + } + + + return `File "${fpath}" not found!`; + }, + + vi: (fname) => { + const newpath = this.resolvePath(fname); + if (!this.fs[newpath]) { + let dirName = newpath.split('/').slice(0, -1).join('/') || "/"; + + if (!this.fs[dirName]) return `path "${dirName}" not found!`; + this.fs[dirName].children.push(fname); + } + + // Create editor overlay + let editorOverlay = document.getElementById("vi-editor-overlay"); + if (editorOverlay) editorOverlay.remove(); + + editorOverlay = document.createElement("div"); + editorOverlay.id = "vi-editor-overlay"; + editorOverlay.className = "vi-editor-overlay"; + + const editorBox = document.createElement("div"); + editorBox.className = "vi-editor-box"; + + const title = document.createElement("div"); + title.textContent = `vi β€” ${fname}`; + title.className = "vi-editor-title"; + + const textarea = document.createElement("textarea"); + textarea.value = this.files[newpath] || ""; + textarea.className = "vi-editor-textarea"; + + const btnRow = document.createElement("div"); + btnRow.className = "vi-editor-btnrow"; + + const saveBtn = document.createElement("button"); + saveBtn.textContent = "Save & Exit"; + saveBtn.className = "vi-editor-savebtn"; + saveBtn.onclick = () => { + this.files[newpath] = textarea.value; + document.body.removeChild(editorOverlay); + const consoleOutput = document.querySelector(".consoleout"); + consoleOutput.innerHTML += `
    Saved ${fname}!
    `; + }; + + const cancelBtn = document.createElement("button"); + cancelBtn.textContent = "Cancel"; + cancelBtn.className = "vi-editor-cancelbtn"; + cancelBtn.onclick = () => { + document.body.removeChild(editorOverlay); + }; + + btnRow.append(saveBtn, cancelBtn); + editorBox.append(title, textarea, btnRow); + editorOverlay.appendChild(editorBox); + document.body.appendChild(editorOverlay); + + // Focus textarea + setTimeout(() => textarea.focus(), 100); + + // ESC closes editor + const escListener = (e) => { + if (e.key === "Escape") { + cancelBtn.click(); + } + }; + editorOverlay.addEventListener("keydown", escListener); + textarea.addEventListener("keydown", (e) => e.stopPropagation()); + + return `Opened editor for ${fname}. Press ESC or Cancel to exit.`; + }, + exit: devConsoleToggle, theme: (arg) => { @@ -424,7 +548,7 @@ Boot sequence: πŸ•ΊπŸ’ƒπŸͺ© const colors = ["#ff4081", "#7c3aed", "#4f46e5", "#00ff88"]; document.body.style.color = colors[Math.floor(Math.random() * colors.length)]; - return "🌈 Color chaos activated!"; + return "🌈 Color changed!"; }, secret: () => { @@ -434,7 +558,6 @@ Boot sequence: πŸ•ΊπŸ’ƒπŸͺ© run: (filePath) => { const absPath = terminalFS.resolvePath(filePath.trim()); - console.log(absPath, filePath); // Project links if (