diff options
author | amy <[email protected]> | 2023-02-08 14:14:26 -0600 |
---|---|---|
committer | amy <[email protected]> | 2023-02-08 14:14:26 -0600 |
commit | dd9237041883ff5a97e2b9e9b9ac75201e2ad755 (patch) | |
tree | 2bb5de5df96a15cac8aeae074ec8239c2b1c6b4d | |
parent | fb1a266ee984e923fd9af7aa34c99e91356f2d2d (diff) |
lots of stuff lol
-rw-r--r-- | html/display.html | 93 | ||||
-rw-r--r-- | src/jssh.js | 202 |
2 files changed, 222 insertions, 73 deletions
diff --git a/html/display.html b/html/display.html index ff8e3a8..eaf6a74 100644 --- a/html/display.html +++ b/html/display.html @@ -317,6 +317,7 @@ background-color: rgba(0, 0, 0, 0); text-shadow: 0 0 10px white; border: none; + color: inherit; } input { @@ -344,6 +345,50 @@ } let bar_items_left = [] function load_bar() { + let items = document.getElementsByClassName("bar-menu-item") + for (let item = 0; item != items.length; item++) { + let i_c = items.item(item).children + let found_more = false + for (let i = 0; i != i_c.length; i++) { + let id = i_c.item(i) + if (id.className == "bar-menu-more-root") { + found_more = true + let t_s = new jssh(fs, '/', document.getElementsByClassName('window').length, 'null', 'null') + let dd = (t_s.set_wd(items.item(item).getAttribute("dir"))) + if (dd[0] == undefined) { //item is null + id.innerHTML = ''; + id.remove(); break + //! TODO: don't show bar if dir is empty or null + } + /* + <div class="bar-menu-item" id="bar-menu-favorites"><img class="bar-menu-image" + src="./src/img/notepad.png"> + <div class="bar-menu-text">Notepad--</div> + </div> + */ + id.innerHTML = '' + let ins = "" + for (let ite = 0; ite != dd.length; ite++) { + + ins += `<div class="bar-menu-item" onclick="shortcut('${dd[ite].content}');close_menu();" id="bar-menu-${dd[ite].name}">` + if (dd[ite].icon) + ins += `<img class="bar-menu-image" src="${dd[ite].icon}">` + ins += `<div class="bar-menu-text">${dd[ite].name}</div></div>` + + + //console.log(id.children.item(ite)) + } + id.innerHTML = ins; + items.item(item).onmouseover = ((ev) => { + id.style.display = "block" + items.item(item).onmouseout = ((ev) => { + id.style.display = "none" + }) + }) + break; + } + } + } let bar = document.getElementById("bar-items") let windows = document.getElementsByClassName("window") let put = "" @@ -419,10 +464,9 @@ function window_create(uid, name, content, options = {}) { let lines = content.split("</br>").length let a = '' - let size = (options.size != undefined) ? ("width:" + options.size.width + "px;height:" + options.size.height + "px;") : ("width:" + Math.max(document.body.clientWidth * .56, minx) + "px;height:" + Math.max(miny, document.body.clientHeight * .30) + "px;"); - - a += "<div id='" + uid + "-root' class='window' style=\"" + size + "top:0px;left:0px;position:absolute;\" window-name='" + name + "'>" + let pos = (options.pos != undefined) ? ("left:" + options.pos.left + "px;top:" + options.pos.top + "px;") : ("left:0px;top:0px;"); + a += "<div id='" + uid + "-root' class='window' style=\"" + size + pos + "position:absolute;\" window-name='" + name + "'>" //console.log(document.getElementById(uid).attributes["window-name"].value) a += "<div id='" + uid + "-head' class='head-border' window-name='" + name + "'> <div style='color:fdffff'>" + name + "</div>" a += "<div id='" + uid + "-close' class='close-button' window-name='" + name + "'>" + `<svg draggable="false" xmlns="http://www.w3.org/2000/svg" style="position:absolute;left:-3px;top:0px;" xmlns:xlink="http://www.w3.org/1999/xlink" width="23px" height="20px" viewBox="0 0 23 20" version="1.1"> @@ -473,6 +517,8 @@ let ii = elems.item(i) elem.children.item(iii).onmousedown = ((ev) => { //console.log(elems.item(i)) + //onkill.apply(this) + delete procs[elem.id.split("-")[0]] ii.remove() load_bar() }) @@ -743,7 +789,8 @@ if (words[0] == "window") { let t = line.split(" ") t.splice(0, 2) - window_create(document.getElementsByClassName("window").length, words[1], t.join(" ").replace(/#_ID/g, document.getElementsByClassName("window").length), { size: { width: 500, height: 500 } }) + let id = document.getElementsByClassName("window").length + window_create(id, words[1], t.join(" ").replace(/#_ID/g, id), { size: { width: 500, height: 300 }, pos: { left: 250, top: 50 } }) load_bar() } } @@ -769,43 +816,7 @@ else document.getElementById("bar-menu-root").style.display = "block" }) - let items = document.getElementsByClassName("bar-menu-item") - for (let item = 0; item != items.length; item++) { - let i_c = items.item(item).children - for (let i = 0; i != i_c.length; i++) { - let id = i_c.item(i) - if (id.className == "bar-menu-more-root") { - let t_s = new jssh(fs, '/', document.getElementsByClassName('window').length, 'null', 'null') - let dd = (t_s.set_wd(items.item(item).getAttribute("dir"))) - /* - <div class="bar-menu-item" id="bar-menu-favorites"><img class="bar-menu-image" - src="./src/img/notepad.png"> - <div class="bar-menu-text">Notepad--</div> - </div> - */ - id.innerHTML = '' - let ins = "" - for (let ite = 0; ite != dd.length; ite++) { - - ins += `<div class="bar-menu-item" onclick="shortcut('${dd[ite].content}');close_menu();" id="bar-menu-${dd[ite].name}">` - if (dd[ite].icon) - ins += `<img class="bar-menu-image" src="${dd[ite].icon}">` - ins += `<div class="bar-menu-text">${dd[ite].name}</div></div>` - - - //console.log(id.children.item(ite)) - } - id.innerHTML = ins; - items.item(item).onmouseover = ((ev) => { - id.style.display = "block" - items.item(item).onmouseout = ((ev) => { - id.style.display = "none" - }) - }) - break; - } - } - } + load_bar() } </script> diff --git a/src/jssh.js b/src/jssh.js index 5eac0a2..6817555 100644 --- a/src/jssh.js +++ b/src/jssh.js @@ -51,9 +51,10 @@ class jssh { .filter(function (e) { return e.replace(" ", "") !== "."; }); - for (let i = path.length; i != 0; i--) { + for (let i = 0; i != path.length; i++) { if (path[i] == "..") { path.splice(i - 1, 2); + return this.clean_path("/" + path.join("/")); } } if (path.includes("..")) path = []; @@ -62,24 +63,149 @@ class jssh { main() { for (let d of fs) { if (d.name == ".bashrc") { - for (let line of d.content.split("\n")) { - document.getElementById(this.input).value = line; - this.ex(); + for (let line of d.content.split("\n").join("</br>").split("</br>")) { + if (line.trim() != "") { + document.getElementById(this.input).value = line.trim(); + this.ex(); + } } break; } } - setInterval(() => { - document.getElementById(this.input).focus(); - }, 10); + //setInterval(() => { + // document.getElementById(this.input).focus(); + //}, 10); + } + add_file(fs, path, dir) { + //console.log(fs, path); + if (path.length == 1) + return fs.push({ + name: path[0], + perms: { r: true }, + dir: dir, + content: dir ? [] : "", + }); + + for (let f in fs) { + if (fs[f].name == path[0] && fs[f].dir) { + fs = fs[f].content; + path.splice(0, 1); + return this.add_file(fs, path, dir); + } + } + document.getElementById(this.history).innerHTML += + "jssh: " + path.join("/") + ": directory not found</br>"; + } + write_file(fs, path, content, append) { + if (path.length == 1) { + for (let f in fs) { + if (fs[f].name == path[0] && !fs[f].dir) { + fs[f].content = append ? fs[f].content + content : content; + return fs; + } + } + } + /* + return fs.push({ + name: path[0], + perms: { r: true }, + dir: dir, + content: dir ? [] : "", + });*/ + + for (let f in fs) { + if (fs[f].name == path[0] && fs[f].dir) { + fs = fs[f].content; + path.splice(0, 1); + return this.write_file(fs, path, content, append); + } + } + document.getElementById(this.history).innerHTML += + "jssh: " + path.join("/") + ": file not found</br>"; + } + rem_file(fs, path) { + //console.log(fs, path); + if (path.length == 1) { + for (let f in fs) { + console.log(f); + if (fs[f].name == path[0]) { + fs.splice(f, 1); + break; + } + } + return fs; + } + + for (let f in fs) { + if (fs[f].name == path[0] && fs[f].dir) { + fs = fs[f].content; + path.splice(0, 1); + return this.rem_file(fs, path); + } + } + document.getElementById(this.history).innerHTML += + "jssh: " + path.join("/") + ": file or directory not found</br>"; } ex() { let temp_working_dir = this.working_dir; - document.getElementById(this.history).innerHTML += - "λ " + document.getElementById(this.input).value + "</br>"; + //document.getElementById(this.history).innerHTML += + // "λ " + document.getElementById(this.input).value + "</br>"; let com = document.getElementById(this.input).value; let stripped = com.split(" "); + let redir = false, + redir_app = false; + + let history_write = ""; + document.getElementById(this.history).innerHTML += + "λ " + document.getElementById(this.input).value + "</br>"; + if (stripped.includes(">")) redir = true; + else if (stripped.includes(">>")) redir_app = true; switch (stripped[0]) { + case "touch": + this.add_file( + this.fs, + this.clean_path( + stripped[1][0] == "/" + ? stripped[1] + : this.working_dir + "/" + stripped[1] + ) + .split("/") + .filter(function (e) { + return e !== ""; + }), + false + ); + + break; + case "rm": + this.rem_file( + this.fs, + this.clean_path( + stripped[1][0] == "/" + ? stripped[1] + : this.working_dir + "/" + stripped[1] + ) + .split("/") + .filter(function (e) { + return e !== ""; + }) + ); + break; + case "mkdir": + this.add_file( + this.fs, + this.clean_path( + stripped[1][0] == "/" + ? stripped[1] + : this.working_dir + "/" + stripped[1] + ) + .split("/") + .filter(function (e) { + return e !== ""; + }), + true + ); + break; case "jssh": this.main(); break; @@ -117,17 +243,16 @@ class jssh { } add += "</td></tr></table></br></br>"; - document.getElementById(this.history).innerHTML += add; + history_write += add; break; case "clear": document.getElementById(this.history).innerHTML = ""; break; case "echo": - document.getElementById(this.history).innerHTML += - com.substr(4) + "</br>"; + history_write += com.substr(4).split(redir ? ">" : ">>")[0] + "</br>"; break; case "help": - document.getElementById(this.history).innerHTML += + history_write += "jssh -- version 1.0.0 (dev)</br></br>commands: neofetch, help,</br> cat [path],pwd,</br>ls [path] [-a], cd [path],</br>clear, echo [str],jssh</br>"; break; case "cat": @@ -150,20 +275,20 @@ class jssh { ] && !a.dir ) { - document.getElementById(this.history).innerHTML += - a.content + "</br>"; + history_write += a.content + "</br>"; document.getElementById(this.input).value = ""; - return; + break; } } - document.getElementById(this.history).innerHTML += - "jssh: " + - this.clean_path(temp_working_dir) + - " file or dir not found</br>"; + if (history_write == "") { + history_write += + "jssh: " + + this.clean_path(temp_working_dir) + + " file or dir not found</br>"; + } break; case "pwd": - document.getElementById(this.history).innerHTML += - this.clean_path(temp_working_dir) + "</br>"; + history_write += this.clean_path(temp_working_dir) + "</br>"; break; case "cd": if (temp_working_dir != "/") temp_working_dir += "/"; @@ -176,9 +301,9 @@ class jssh { } let ww = this.set_wd(temp_working_dir); if (ww == 1) { - document.getElementById(this.history).innerHTML += + history_write += "jssh: `" + temp_working_dir + "` directory not found</br>"; - return; + break; } this.working_dir = this.clean_path(temp_working_dir); @@ -194,14 +319,14 @@ class jssh { } let wd = this.set_wd(this.clean_path(temp_working_dir)); if (wd == 1) { - document.getElementById(this.history).innerHTML += + history_write += "jssh: `" + temp_working_dir + "` directory not found</br>"; return; } if (stripped.includes("-a")) { - document.getElementById(this.history).innerHTML += + history_write += "<font style='opacity:.3'>[</font>.<font style='opacity:.3'>]</font></br>"; - document.getElementById(this.history).innerHTML += + history_write += "<font style='opacity:.3'>[</font>..<font style='opacity:.3'>]</font></br>"; } @@ -211,24 +336,37 @@ class jssh { i.name[0] != "." ) { if (i.dir) - document.getElementById(this.history).innerHTML += + history_write += "<font style='opacity:.3'>[</font>" + i.name + "<font style='opacity:.3'>]</font></br>"; - else - document.getElementById(this.history).innerHTML += - i.name + "</br>"; + else history_write += i.name + "</br>"; } } break; default: - document.getElementById(this.history).innerHTML += + history_write += "jssh: " + stripped[0] + ": command not found or not implemented</br>"; break; } + if (redir || redir_app) { + let pp = (redir ? com.split(">") : com.split(">>")) + .filter(function (e) { + return e !== ""; + })[1] + .trim(); + pp = this.clean_path(pp[0] == "/" ? pp : this.working_dir + "/" + pp); + pp = pp.split("/").filter(function (e) { + return e !== ""; + }); + + this.write_file(this.fs, pp, history_write, redir_app); + } else { + document.getElementById(this.history).innerHTML += history_write; + } document.getElementById(this.input).value = ""; } } |