From 7abe9c7a3528782316b34328c8799c8e8f1933bb Mon Sep 17 00:00:00 2001 From: amy Date: Mon, 27 Feb 2023 20:47:08 +0000 Subject: woah i did stuff --- html/display.html | 2 +- readme.md | 3 +- src/display.css | 9 +++- src/jssh.js | 10 +++-- src/window-utils.js | 116 ++++++++++++++++++++++++++++++++++++++++++++-------- 5 files changed, 117 insertions(+), 23 deletions(-) diff --git a/html/display.html b/html/display.html index bab394e..0c80aa8 100644 --- a/html/display.html +++ b/html/display.html @@ -208,7 +208,7 @@ a += "
" } a += "" - console.log(a) + //console.log(a) //document.getElementById("root").append(a) appendHtml(document.getElementById("root"),a) if (options.scroll != false && options.scroll != "false") { diff --git a/readme.md b/readme.md index 6fee23d..4cddbbb 100644 --- a/readme.md +++ b/readme.md @@ -7,6 +7,7 @@ todo: solitaire!
fix some of the image scaling
- +fd searching +fd move file ./badges/000010.gif./badges/catp0rtal.gif./badges/getbsod.gif./badges/reshirii.gif./badges/104.gif./badges/css2.gif./badges/gitea.gif./badges/rosemary22.gif./badges/1of2.gif./badges/css.png./badges/hexrain.png./badges/rosemary7.gif./badges/amatsuki.gif./badges/devils_button.gif./badges/linuxnow2.gif./badges/thatwhitehand.png./badges/anibanner.gif./badges/devils.gif./badges/neovim.gif./badges/transistor_cafe.gif./badges/anticodeandrun.gif./badges/digby88.gif./badges/newlambda.gif./badges/transnow2.gif./badges/arizona.gif./badges/dramaturgie.gif./badges/nvidia.gif./badges/zettai.gif./badges/asexuals_now.gif./badges/finger-logo-people.gif./badges/nya2.gif./badges/beyes.gif./badges/firefox4.gif./badges/photo.jpeg./badges/calcium.png./badges/friday-girl.gif./badges/photo.png \ No newline at end of file diff --git a/src/display.css b/src/display.css index ff70443..2c39ac3 100644 --- a/src/display.css +++ b/src/display.css @@ -356,4 +356,11 @@ background-color: rgba(0, 0, 0, 0); border: none; border-radius: 0; - } \ No newline at end of file + } + +.context-menu-root{ + padding:5px 15px 5px 15px; + background-color: #bbb; + z-index:3; + user-select: none; +} \ No newline at end of file diff --git a/src/jssh.js b/src/jssh.js index 51c8562..22809e0 100644 --- a/src/jssh.js +++ b/src/jssh.js @@ -80,6 +80,8 @@ class jssh { stdout(line) { if (this.history != "null" && this.input != "null") document.getElementById(this.history).innerHTML += line; + else + console.log("[no terminal; stdout redirected here]:"+line) return; } add_file(fs, path, dir) { @@ -133,8 +135,8 @@ class jssh { return this.write_file(fs, path, content, append); } } - document.getElementById(this.history).innerHTML += - "jssh: " + path.join("/") + ": file not found
"; + this.stdout ( + "jssh: " + path.join("/") + ": file not found
"); } rem_file(fs, path) { //console.log(fs, path); @@ -156,8 +158,8 @@ class jssh { return this.rem_file(fs, path); } } - document.getElementById(this.history).innerHTML += - "jssh: " + path.join("/") + ": file or directory not found
"; + this.stdout( + "jssh: " + path.join("/") + ": file or directory not found
"); } ex_file(path, args = []) { let id = document.getElementsByClassName("window").length; diff --git a/src/window-utils.js b/src/window-utils.js index 40b5c62..4744f77 100644 --- a/src/window-utils.js +++ b/src/window-utils.js @@ -1,5 +1,5 @@ let util = { - context_menu(target,opt){ + context_menu(target,opt,other_targets=[]){ /* opt = {"menu":[ {"name":string, @@ -14,24 +14,64 @@ let util = { ! is optional */ - (()=>{ + function mm(){ target.oncontextmenu = ((ev)=>{ - console.log(ev) - try{document.getElementById(target.id+"-menu").remove()}catch(e){} + if(ev.target!=target&&other_targets.includes(ev.target)==false) + return + function clean(){ + try{document.getElementById(target.id+"-menu").remove()}catch(e){} + let nu = document.getElementsByClassName('context-menu-root') + for(let i = nu.length -1;i>=0;i--){ + nu.item(i).remove() + } + + } + if(!(window.contextm == null || window.contextm.tokill == null)){ + for(let i in window.contextm.tokill){ + window.contextm.tokill[i]() + + } + window.contextm.tokill = null + } + document.body.addEventListener("click",function tem(){ + clean() + document.body.removeEventListener("click",tem) + }) + + //console.log(ev) + clean() + //if(window.contextm == null || window.contextm.tokill == null){ + window.contextm = {} + if(opt.on_exit!=null) + window.contextm.tokill = [opt.on_exit] + //} else { + + //} let aa = "" for(let op of opt.menu){ - aa+=`
${op.name}
` + if(op=="seper") + aa+="
" + else if(op.allow_if == undefined || op.allow_if()) + aa+=`
${op.name}
` + else + aa+=`
${op.name}
` } - target.innerHTML += "
"+aa+"
" + appendHtml(target,"
"+aa+"
") for(let op of opt.menu){ + if(op!="seper"&&(op.allow_if == undefined || op.allow_if())) document.getElementById(`${target.id}-menu-${opt.menu.indexOf(op)}`).onclick = (()=>{ op.callback() }) } return false }) - })() + }; + mm() + return ({append:function append(items){ + opt.menu.push(items) + mm() + }}) }, scrollbar(uid,minor_uid,root,target){ (()=>{ @@ -41,12 +81,12 @@ let util = { //target is where the scrollbar will be placed, this element should be //larger than the root with scrollable overflow let scrolling = false - console.log(uid,minor_uid) + //console.log(uid,minor_uid) //try{document.getElementById(uid + "-" + minor_uid + "-content-scrollbar").remove()}catch(e){console.log(e)} if(undefined==procs[uid]) procs[uid] = {} - console.log("'" + uid + "-" + minor_uid + "-content-scrollbar'") - target.innerHTML += "
" + //console.log("'" + uid + "-" + minor_uid + "-content-scrollbar'") + appendHtml(target,"
") let thi_point = document.getElementById(uid + "-" + minor_uid + "-content-scrollbar-point") let thi_base = document.getElementById(uid + "-" + minor_uid + "-content-scrollbar") procs[uid].refresh = ()=>{ @@ -166,6 +206,7 @@ let util = { window_create(i, "fs", "",{scroll:false}); let ll = await new jssh(fs, "/", i, "null", "null", window_create); async function load() { + refresh_windows() let fil = [] let tfs = ll.set_wd(ll.clean_path(inp.path)); @@ -213,7 +254,7 @@ let util = { } } }*/ - console.log(inp.path) + //console.log(inp.path) files+= "
"+bar_opt+"
" files += "
" files += "
" @@ -224,7 +265,7 @@ let util = { i + "-id-name-" + f.name + - "' style='height:55px;position:relative;width:48px;display:inline-block;padding:10px;'>
" + + "' style='height:55px;position:relative;width:48px;display:inline-block;padding:10px;'>
" + f.name + "
"; fil.push(f) @@ -235,7 +276,7 @@ let util = { i + "-id-name-" + f.name + - "'style='height:55px;position:relative;width:48px;display:inline-block;padding:10px;'>
" + + "'style='height:55px;position:relative;width:48px;display:inline-block;padding:10px;'>
" + f.name + "
"; fil.push(f) @@ -284,12 +325,25 @@ let util = { let ele = document.getElementById(i+"-fs-inner-cont") let ele_root = document.getElementById(i+"-content-content") - console.log(inp.path.split("/").filter(rem_emp)) + //console.log(inp.path.split("/").filter(rem_emp)) util.scrollbar(i,'root-bar',ele_root.parentElement,ele) - util.context_menu(ele,{menu:[ + let contmenu = util.context_menu(ele,{menu:[ {name:'new file',callback:()=>{ll.add_file(ll.fs,[...inp.path.split("/").filter(rem_emp),'untitled'],false);load()}}, {name:'new directory',callback:()=>{ll.add_file(ll.fs,[...inp.path.split("/").filter(rem_emp),'untitled'],true);load()}}, + "seper", + {name:'paste',callback:()=>{ + let lll = ll.set_wd((inp.path)) + ll.rem_file(fs,(inp.path + "/" +window.clipboard.path).split("/").filter(rem_emp)); + ll.add_file(fs,(inp.path + "/" +window.clipboard.path).split("/").filter(rem_emp),window.clipboard.dir); + for(let ooo of lll){ + if(ooo.name==window.clipboard.path) + ooo.content=window.clipboard.content; + } + + load()}, + allow_if:()=>{return(window.clipboard!=null&&window.clipboard.type=="file")}} ]}) + //contmenu.append(['seper']) //document.getElementById(i+"-fs-inner-cont").oncontextmenu = (ev) => { // return false //} @@ -332,7 +386,37 @@ let util = { } for (let f of fil) { let tt = document.getElementById(i + "-id-name-" + f.name); - //console.log(tt,f) + //console.log(tt.firstChild) + util.context_menu(tt,{menu:[ + {name:'rename',callback:()=>{ + for(let z in tt.children){ + if(tt.children.item(z).className=="file-name"){ + tt.children.item(z).innerHTML = "
" + tt.children.item(z).firstChild.onsubmit = (()=>{fil[fil.indexOf(f)].name=tt.children.item(z).firstChild.firstChild.value;load();return false}) + tt.children.item(z).firstChild.firstChild.focus() + break + } + } + }}, + {name:'copy',callback:()=>{ + window.clipboard = {type:"file",path:f.name,dir:f.dir,content:f.content} + + }}, + {name:'cut',callback:()=>{ + //console.log(fs,ll.clean_path(inp.path + "/" + f.name).split("/").filter(rem_emp)) + window.clipboard = {type:"file",path:f.name,dir:f.dir,content:f.content} + ll.rem_file(fs,ll.clean_path(inp.path + "/" + f.name).split("/").filter(rem_emp)) + //console.log(fs) + load() + + }}, + {name:'del',callback:()=>{ + ll.rem_file(fs,ll.clean_path(inp.path + "/" + f.name).split("/").filter(rem_emp)) + //console.log(fs) + load() + + }} + ],on_exit:()=>{for(let z in tt.children){tt.children.item(z).innerHTML = fil[fil.indexOf(f)].name} }},Array.from(tt.children)) let dou = false; tt.onclick = (ev) => { if (dou) { -- cgit v1.2.3