diff options
author | amy <[email protected]> | 2023-02-09 14:14:25 -0600 |
---|---|---|
committer | amy <[email protected]> | 2023-02-09 14:14:25 -0600 |
commit | 446267f9f1f8909d86a27284cd78688180dd8a04 (patch) | |
tree | 8305c4e5c157a6cb1aed22a70db90aed8129c7ad | |
parent | 4c74bb3162e3c32c81ffbc531644ab5adef1f847 (diff) |
new stuff:)
-rw-r--r-- | html/display.html | 68 | ||||
-rw-r--r-- | src/jssh.js | 88 |
2 files changed, 108 insertions, 48 deletions
diff --git a/html/display.html b/html/display.html index 92a35fa..a24255e 100644 --- a/html/display.html +++ b/html/display.html @@ -371,25 +371,27 @@ id.innerHTML = '' let ins = "" for (let ite = 0; ite != dd.length; ite++) { - let icon = "" - ins += `<div class="bar-menu-item" onclick="shortcut('${items.item(item).getAttribute("dir") + dd[ite].name}');close_menu();" id="bar-menu-${dd[ite].name}">` - //if (dd[ite].icon) - //icon = `<img class="bar-menu-image" src="${dd[ite].icon}">` - //else { - - for (let l of dd[ite].content.split("\n")) { - if (l.split(" ")[0] == "meta") { - if (l.split(" ")[1] == "icon") { - icon = `<img class="bar-menu-image" src="${l.split(" ")[2]}">` + if (dd[ite].dir == false) { + let icon = "" + ins += `<div class="bar-menu-item" onclick="shortcut('${items.item(item).getAttribute("dir") + dd[ite].name}');close_menu();" id="bar-menu-${dd[ite].name}">` + //if (dd[ite].icon) + //icon = `<img class="bar-menu-image" src="${dd[ite].icon}">` + //else { + + for (let l of dd[ite].content.split("\n")) { + if (l.split(" ")[0] == "meta") { + if (l.split(" ")[1] == "icon") { + icon = `<img class="bar-menu-image" src="${l.split(" ")[2]}">` + } } } - } - ins += icon - //} - ins += `<div class="bar-menu-text">${dd[ite].name}</div></div>` + ins += icon + //} + ins += `<div class="bar-menu-text">${dd[ite].name}</div></div>` - //console.log(id.children.item(ite)) + //console.log(id.children.item(ite)) + } } id.innerHTML = ins; items.item(item).onmouseover = ((ev) => { @@ -792,7 +794,7 @@ if (a_p_c.item(ii).id == id + "-history") { let his = a_p_c.item(ii).id if (procs[id] == undefined) - procs[id] = new jssh(fs, "/", id, inp, his) + procs[id] = new jssh(fs, "/", id, inp, his, window_create) procs[id].ex() refresh_windows() a.parentElement.parentElement.scrollTop = a.parentElement.parentElement.scrollHeight @@ -816,30 +818,8 @@ return prom; } let fs = [] - function shortcut(i) { - let path = i.split("/") - let tar = path.splice(path.length - 1, 1) - console.log(path) - let temp = new jssh(fs, '/', document.getElementsByClassName('window').length, 'null', 'null') - let ww = temp.set_wd(path.join("/")) - let item = '' - for (let zz of ww) { - if (zz.name == tar) { - i = zz.content - break - } - } - let parsed = i.split("\n") - for (let line of parsed) { - let words = line.split(" ") - if (words[0] == "window") { - let t = line.split(" ") - t.splice(0, 2) - 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() - } - } + function shortcut(i, shell = new jssh(fs, '/', document.getElementsByClassName('window').length, 'null', 'null', window_create)) { + shell.ex_file(i) } function close_menu() { let items = document.getElementsByClassName("bar-menu-item") @@ -853,7 +833,13 @@ } } document.getElementById("bar-menu-root").style.display = "none" - main() + document.getElementById("bar-menu").onclick = ((ev) => { + if (document.getElementById("bar-menu-root").style.display == "block") + document.getElementById("bar-menu-root").style.display = "none" + else + document.getElementById("bar-menu-root").style.display = "block" + }) + load_bar() } async function main() { fs = await req('src/fs.json') diff --git a/src/jssh.js b/src/jssh.js index 8cb360d..f8a4072 100644 --- a/src/jssh.js +++ b/src/jssh.js @@ -1,10 +1,11 @@ class jssh { - constructor(fs, working_dir, uid, input, h) { + constructor(fs, working_dir, uid, input, history, window_create = null) { this.fs = fs; this.working_dir = working_dir; this.input = input; - this.history = h; + this.history = history; this.uid = uid; + this.window_create = window_create; } set_wd(dir) { //let lwd = fs @@ -76,6 +77,12 @@ class jssh { // document.getElementById(this.input).focus(); //}, 10); } + stdout(line) { + if (this.history != "null" && this.input != "null") + document.getElementById(this.history).innerHTML += line; + else console.log("aaa"); + return; + } add_file(fs, path, dir) { //console.log(fs, path); if (path.length == 1) @@ -100,6 +107,7 @@ class jssh { if (path.length == 1) { for (let f in fs) { if (fs[f].name == path[0] && !fs[f].dir) { + //console.log(append ? fs[f].content + content : content); fs[f].content = append ? fs[f].content + content : content; return fs; } @@ -146,6 +154,46 @@ class jssh { document.getElementById(this.history).innerHTML += "jssh: " + path.join("/") + ": file or directory not found</br>"; } + ex_file(path, args = []) { + let pa = path.split("/"); + let it = pa.splice(pa.length - 1, 1); + for (let i of this.set_wd(pa.join("/") + "/")) { + if (i.name == it[0] && !i.dir) { + let cont = i.content; + for (let line of cont.split("\n")) { + console.log(line); + let stripped = line.split(" "); + switch (stripped[0]) { + case "window": + if (this.window_create != null) { + let t = line.split(" "); + t.splice(0, 2); + let id = document.getElementsByClassName("window").length; + console.log(id); + this.window_create( + id, + stripped[1], + t.join(" ").replace(/#_ID/g, id), + { + size: { width: 500, height: 300 }, + pos: { left: 250, top: 50 }, + } + ); + } else { + this.stdout("unable to make window reference"); + } + break; + case "echo": + let t = line.split(" "); + t.splice(0, 1); + this.stdout(t.join(" ")); + break; + } + } + break; + } + } + } ex() { let temp_working_dir = this.working_dir; //document.getElementById(this.history).innerHTML += @@ -160,7 +208,8 @@ class jssh { "λ " + document.getElementById(this.input).value + "</br>"; if (stripped.includes(">")) redir = true; else if (stripped.includes(">>")) redir_app = true; - switch (stripped[0]) { + console.log(redir, redir_app); + swi: switch (stripped[0]) { case "touch": this.add_file( this.fs, @@ -345,12 +394,38 @@ class jssh { } break; default: + //change newline char + let pa = this.clean_path(stripped[0]).split("/"); + if (stripped[0][0] != "/") { + pa = this.clean_path(this.working_dir + "/" + stripped[0]).split("/"); + } + let or = pa; + let it = pa.splice(pa.length - 1, 1); + + for (let i of this.set_wd(pa.join("/") + "/")) { + if (i.name == it[0] && !i.dir) { + if (stripped[0][0] != "/") + this.ex_file( + this.clean_path(this.working_dir + "/" + stripped[0]) + ); + else this.ex_file(this.clean_path(stripped[0])); + break swi; + } + } + history_write += - "jssh: " + - stripped[0] + - ": command not found or not implemented</br>"; + "jssh: " + stripped[0] + ": file or command not found</br>"; + break; + /*} else { + 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) { @@ -362,7 +437,6 @@ class jssh { pp = pp.split("/").filter(function (e) { return e !== ""; }); - this.write_file(this.fs, pp, history_write.trim(), redir_app); } else { document.getElementById(this.history).innerHTML += history_write; |