aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoramy <[email protected]>2023-01-30 14:10:47 -0600
committeramy <[email protected]>2023-01-30 14:10:47 -0600
commit7f332c7287a23533f38f7435bc34231fc9153a0c (patch)
tree1ff68622946f2f6e4497b51be8f5d01aa6304350
parentd6fbc16522515c77165e24f7cda8f6f1b01139ee (diff)
tty mostly done
-rw-r--r--tty.html308
1 files changed, 217 insertions, 91 deletions
diff --git a/tty.html b/tty.html
index aea3d8d..3f2f7bc 100644
--- a/tty.html
+++ b/tty.html
@@ -1,106 +1,232 @@
<html>
- <head>
- <meta charset="UTF-8">
- <title>nya~</title>
- <link rel="preconnect" href="https://fonts.googleapis.com">
- <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
- <link href="https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap" rel="stylesheet">
-
- <style>
- :root {
- --primary: #ee2757;
- --complement: #eb586f;
- --contrast: #8144e9;
- --white: #f0fcfb;
- --black: #212121;
- --font-size: 17px;
- }
- *{
- margin:0;
- }
- body{
- background-color: var(--black);
- font-family: 'Press Start 2P';
- color: var(--white);
- font-size:var(--font-size);
- text-shadow: 0 0 10px var(--white);
+<head>
+ <meta charset="UTF-8">
+ <title>nya~</title>
+ <link rel="preconnect" href="https://fonts.googleapis.com">
+ <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
+ <link href="https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap" rel="stylesheet">
+
+ <style>
+ :root {
+ --primary: #ee2757;
+ --complement: #eb586f;
+ --contrast: #8144e9;
+ --white: #f0fcfb;
+ --black: #212121;
+ --font-size: 17px;
+ }
+
+ * {
+ margin: 0;
+ }
+
+ body {
+ background-color: var(--black);
+ font-family: 'Press Start 2P';
+ color: var(--white);
+ font-size: var(--font-size);
+ text-shadow: 0 0 10px var(--white);
+
+ }
+
+ input {
+ background-color: rgba(0, 0, 0, 0);
+ font-family: 'Press Start 2P';
+ color: var(--white);
+ font-size: var(--font-size);
+ text-shadow: 0 0 10px var(--white);
+ border: none;
+ }
+
+ input {
+ border: 0;
+ outline: 0;
+ }
+
+ input:focus {
+ outline: none !important;
+ }
+
+ input:hover {
+ cursor: text;
+ }
+ </style>
+ <script>
+ let working_dir = "/"
+ let fs = [
+ { name: ".bashrc", perms: { r: true }, dir: false, content: "neofetch" },
+ { name: "readme", perms: { r: true }, dir: false, content: "test test acr" }
+ , { name: "help", perms: { r: true }, dir: true, content: [{ name: "aaa", perms: { r: true }, dir: false, content: "test test test" }] }
+ , { name: ".secret", perms: { r: true }, dir: true, content: [] }
+
+ ]
+ function set_wd(dir) {
+ //let lwd = fs
+ let wd = fs
+ let path = dir.split("/").filter(function (e) { return e !== '' }).filter(function (e) { return e !== '.' })
+ for (let i in path) {
+ if (path[i] == '..') {
+ path.splice(i - 1, 2)
+ }
}
- input{
- background-color: var(--black);
- font-family: 'Press Start 2P';
- color: var(--white);
- font-size:var(--font-size);
- text-shadow: 0 0 10px var(--white);
- border: none;
- }
- input {border:0;outline:0;}
- input:focus {outline:none!important;}
- input:hover {
- cursor:text;
- }
- </style>
- <script>
- let working_dir = "/"
- let fs = [
- {name:"readme",perms:{r:true},dir:false,content:"test test test"}
- ,{name:"help",perms:{r:true},dir:true,content:[]}
-
- ]
- function set_wd(wd){
- let lwd = fs
- let wd = fs
- let path= wd.split("/").filter(function(e) { return e !== '' })
- for(let dir of path){
- lwd = wd;
- for(let i of wd){
- console.log(i)
- if(i.name==dir&&i.dir){
-
- wd=i.content
- break;
+
+ for (let dir of path) {
+ let found = false
+ //lwd = wd;
+ if (dir != '.') {
+ for (let i of wd) {
+ if (i.name == dir && i.dir) {
+
+ wd = i.content
+ found = true
+ break
}
+
+ }
+ if (!found) {
+ return 1;
}
}
- return wd;
}
- function ex(){
-
- console.log(wd)
- document.getElementById("history").innerHTML+= "λ " + document.getElementById("line").value + "</br>"
- let com = document.getElementById("line").value;
- let stripped = com.split(" ")
- switch(stripped[0]){
- case 'neofetch':
- document.getElementById("history").innerHTML+="uwu</br>"
+ return wd;
+ //return 1;
+
+ }
+ function clean_path(path) {
+ path = path.split("/").filter(function (e) { return e !== '' }).filter(function (e) { return e.replace(' ', '') !== '.' })
+ for (let i = path.length; i != 0; i--) {
+ if (path[i] == '..') {
+ path.splice(i - 1, 2)
+ }
+ }
+ return "/" + path.join("/")
+ }
+ function main() {
+ document.getElementById("line").value = "neofetch"
+ ex()
+ }
+ function ex() {
+ let temp_working_dir = working_dir
+ document.getElementById("history").innerHTML += "λ " + document.getElementById("line").value + "</br>"
+ let com = document.getElementById("line").value;
+ let stripped = com.split(" ")
+ switch (stripped[0]) {
+ case 'neofetch':
+ document.getElementById("history").innerHTML += "hello, i am grant, they/them</br>i am mostly typescript and c++ dev, but</br>i can work in most languages</br>--</br>i enjoy manga, and coding in free time</br>contact me at [email protected]</br>"
break;
- case 'ls':
- for(let i of wd){
- if(i.dir)
- document.getElementById("history").innerHTML+="<font style='opacity:.3'>[</font>"+i.name+"<font style='opacity:.3'>]</font></br>"
+ case 'clear':
+ document.getElementById("history").innerHTML = '';
+ break;
+ case 'echo':
+ let l = stripped.splice(1, 1)
+ document.getElementById("history").innerHTML += l + "</br>";
+ break;
+ case 'help':
+ document.getElementById("history").innerHTML += "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]</br>"
+ break;
+ case 'cat':
+
+ temp_working_dir += "/"
+ for (let i of stripped) {
+ if (i != stripped[0] && i[0] != '-') {
+ if (i[0] == '/')
+ temp_working_dir = i
else
- document.getElementById("history").innerHTML+=i.name+"</br>"
+ temp_working_dir += i
+ break
+ }
+
+ }
+ let tt = temp_working_dir.split("/")
+ tt.splice(tt.length - 1, 1)
+ let wa = set_wd(clean_path(tt.join("/")))
+ for (let a of wa) {
+ if (a.name == temp_working_dir.split("/")[temp_working_dir.split("/").length - 1] && !a.dir) {
+ document.getElementById("history").innerHTML += a.content + "</br>"
+ document.getElementById("line").value = ""
+ return
}
+ }
+ document.getElementById("history").innerHTML += "jssh: " + clean_path(temp_working_dir) + " file or dir not found</br>"
break;
- default:
- document.getElementById("history").innerHTML+="jssh: "+stripped[0]+": command not found or not implemented</br>"
+ case 'pwd':
+ document.getElementById("history").innerHTML += clean_path(temp_working_dir) + "</br>"
+ break;
+ case 'cd':
+ if (temp_working_dir != "/")
+ temp_working_dir += "/"
+ for (let i of stripped) {
+ if (i != stripped[0] && i[0] != '-') {
+ if (i[0] == '/')
+ temp_working_dir = i + "/"
+ else
+ temp_working_dir += i + "/"
+ break
+ }
+
+ }
+ let ww = set_wd(temp_working_dir)
+ if (ww == 1) {
+ document.getElementById("history").innerHTML += "jssh: `" + temp_working_dir + "` directory not found</br>"
+ return
+ }
+ working_dir = clean_path(temp_working_dir)
+
+ break;
+ case 'ls':
+ if (temp_working_dir != "/")
+ temp_working_dir += "/"
+ for (let i of stripped) {
+ if (i != stripped[0] && i[0] != '-') {
+ if (i[0] == '/')
+ temp_working_dir = i + "/"
+ else
+ temp_working_dir += i + "/"
+ break
+ }
+
+ }
+ let wd = set_wd(clean_path(temp_working_dir))
+ if (wd == 1) {
+ document.getElementById("history").innerHTML += "jssh: `" + temp_working_dir + "` directory not found</br>"
+ return
+ }
+ if (stripped.includes("-a")) {
+ document.getElementById("history").innerHTML += "<font style='opacity:.3'>[</font>.<font style='opacity:.3'>]</font></br>"
+ document.getElementById("history").innerHTML += "<font style='opacity:.3'>[</font>..<font style='opacity:.3'>]</font></br>"
+ }
+
+ for (let i of wd) {
+ if (i.name[0] == '.' && stripped.includes("-a") || i.name[0] != '.') {
+ if (i.dir)
+ document.getElementById("history").innerHTML += "<font style='opacity:.3'>[</font>" + i.name + "<font style='opacity:.3'>]</font></br>"
+ else
+ document.getElementById("history").innerHTML += i.name + "</br>"
+ }
+ }
+ break;
+ default:
+ document.getElementById("history").innerHTML += "jssh: " + stripped[0] + ": command not found or not implemented</br>"
break;
- }
-
- document.getElementById("line").value = ""
}
- </script>
- </head>
- <body>
-
- <div id="history">
-
- </div>
- <form autocomplete="off" onsubmit="ex();return false;" >
- λ <input id="line">
- <input type="submit" style="display: none" />
- </form >
-
- </body>
+
+ document.getElementById("line").value = ""
+ }
+ </script>
+</head>
+
+<body onload="main()">
+
+ <div id="history">
+
+ </div>
+ <form autocomplete="off" onsubmit="ex();return false;">
+ λ <input id="line" style="width:95%;">
+ <input type="submit" style="display: none" />
+ </form>
+
+</body>
+
</html> \ No newline at end of file