Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content
This repository was archived by the owner on Jul 6, 2022. It is now read-only.

Commit 9cef9fb

Browse files
committed
Fixing url to include https if not provided to prevent relative links, adding tree command, adding nightowl theme
1 parent 62ced46 commit 9cef9fb

6 files changed

Lines changed: 121 additions & 22 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.vercel

README.md

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,20 @@ A homepage disguised as a toy terminal!
1414

1515
Here are the currently available commands that can be run on the terminal.
1616

17-
| Command | usage | description |
18-
| -------- | ---------------------------- | -------------------------------------------------------------- |
19-
| `ls` | `ls [<path to dir>]` | List children of current working directory or given directory. |
20-
| `cd` | `cd [<path>]` | Move into given directory. If no path given move to root. |
21-
| `open` | `open <path to link>` | Open a link in a new tab. |
22-
| `touch` | `touch <path to link> <url>` | Create a new link |
23-
| `mkdir` | `mkdir <path to dir>` | Create a new directory |
24-
| `rm` | `rm <path to link>` | Delete link |
25-
| `rmdir` | `rmdir <path to dir>` | Delete dir and all contents |
26-
| `search` | `search "<search string>"` | Search google with search. Must be in quotes. |
27-
| `clear` | `clear` | Clear the terminal of past commands. |
28-
| `theme` | `theme [<theme name>]` | Change theme. |
29-
| `help` | `help [<command>]` | Get information on commands. |
17+
| Command | usage | description |
18+
| -------- | ---------------------------- | --------------------------------------------------------------------------------- |
19+
| `ls` | `ls [<path to dir>]` | List children of current working directory or given directory. |
20+
| `tree` | `tree [<path to dir>]` | Lists all children of current working directory or given directory in tree format |
21+
| `cd` | `cd [<path>]` | Move into given directory. If no path given move to root. |
22+
| `open` | `open <path to link>` | Open a link in a new tab. |
23+
| `touch` | `touch <path to link> <url>` | Create a new link |
24+
| `mkdir` | `mkdir <path to dir>` | Create a new directory |
25+
| `rm` | `rm <path to link>` | Delete link |
26+
| `rmdir` | `rmdir <path to dir>` | Delete dir and all contents |
27+
| `search` | `search "<search string>"` | Search google with search. Must be in quotes. |
28+
| `clear` | `clear` | Clear the terminal of past commands. |
29+
| `theme` | `theme [<theme name>]` | Change theme. |
30+
| `help` | `help [<command>]` | Get information on commands. |
3031

3132
## Theming
3233

@@ -62,10 +63,10 @@ Your TermPage file structure is stored in your browsers LocalStorage, if you enc
6263
- `edit` command for changing urls
6364
- `mv` to rename dir and link names
6465
- `export` and `import` for sharing your file structure with other machines
65-
- Tree view for `ls`, and url view for `ls`
66+
- ~~Tree view for `ls`, and url view for `ls`~~
6667
- Add flags for search to change search engine
6768
- Tab complete for commands and paths
6869

6970
### Themes
7071

71-
- NightOwl
72+
- ~~NightOwl~~

src/cli.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,15 @@ const types = {
55
LINK: "link",
66
DIR: "directory",
77
};
8-
const THEMES = ["dark", "light", "laserwave", "nord", "greyscale", "dracula"];
8+
const THEMES = [
9+
"dark",
10+
"light",
11+
"laserwave",
12+
"nord",
13+
"greyscale",
14+
"dracula",
15+
"nightowl",
16+
];
917
const COMMANDS = {
1018
ls: { func: joinWriter(list, listWriter), help: "usage: ls [<path to dir>]" },
1119
cd: { func: joinWriter(cd, textWriter), help: "usage: cd [<path>]" },
@@ -33,6 +41,10 @@ const COMMANDS = {
3341
func: joinWriter(search, textWriter),
3442
help: 'usage: search "<search string>"',
3543
},
44+
tree: {
45+
func: joinWriter(tree, treeWriter),
46+
help: "usage: tree",
47+
},
3648
};
3749
const WEEK_DAYS = [
3850
"monday",

src/commands.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,12 @@ function touch(input) {
6666
const path = input[0].split("/");
6767
const url = input[1]; // TODO: ensure conforms to URL
6868
try {
69+
let finalUrl = url;
70+
if (!/^http|https:\/\//.test(url)) {
71+
finalUrl = "https://" + url;
72+
}
6973
const target = locatePath(path.slice(0, path.length - 1));
70-
target[path[path.length - 1]] = url;
74+
target[path[path.length - 1]] = finalUrl;
7175
writeLinks();
7276
return;
7377
} catch (err) {
@@ -172,3 +176,19 @@ function search(input) {
172176
}
173177
return COMMANDS.search.help;
174178
}
179+
180+
function tree(input) {
181+
try {
182+
let target = links;
183+
if (input.length) {
184+
const path = input[0].split("/");
185+
target = locatePath(path);
186+
}
187+
if (locationType(target) !== types.DIR) {
188+
return `no such dir: ${input[0]}`;
189+
}
190+
return target;
191+
} catch (err) {
192+
return err;
193+
}
194+
}

src/writers.js

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ function textWriter(output = "") {
2727
terminal.appendChild(outputNode);
2828
}
2929

30-
function ulWriter(output = '') {
30+
function ulWriter(output = "") {
3131
// TODO: simplify these cases together
3232
if (Array.isArray(output)) {
3333
// Simple ul
@@ -61,3 +61,34 @@ function ulWriter(output = '') {
6161
textWriter(output);
6262
}
6363
}
64+
65+
function treeWriter(output = "") {
66+
if (Array.isArray(output)) {
67+
listWriter(output);
68+
} else if (typeof output === "object") {
69+
const terminal = document.getElementById("terminal-content");
70+
const outputNode = document.createElement("div");
71+
outputNode.classList.add("terminal-output");
72+
let inner = "<ul class='tree-list'>";
73+
inner = inner + buildNestedList(output, []).join("") + "</ul>";
74+
outputNode.innerHTML = inner;
75+
terminal.appendChild(outputNode);
76+
} else {
77+
textWriter(output);
78+
}
79+
}
80+
81+
function buildNestedList(cursor, list) {
82+
Object.entries(cursor).map(([key, value]) => {
83+
if (locationType(value) === types.DIR) {
84+
list.push(
85+
`<li class="tree-list-item directory">${key}<ul class="tree-list">`
86+
);
87+
buildNestedList(value, list);
88+
list.push("</ul></li>");
89+
} else {
90+
list.push(`<li class="tree-list-item">${key}</li>`);
91+
}
92+
});
93+
return list;
94+
}

styles.css

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
2-
31
body {
42
width: 100vw;
53
height: 100vh;
@@ -24,10 +22,11 @@ body {
2422
--listTitle: var(--fg);
2523

2624
--fontSize: 13px;
27-
--fontFamily: 'Source Code Pro', monospace;
25+
--fontFamily: "Source Code Pro", monospace;
2826
}
2927

30-
body.dark { }
28+
body.dark {
29+
}
3130

3231
body.light {
3332
--body-bg: #f3f3f3;
@@ -84,6 +83,17 @@ body.greyscale {
8483
--listTitle: var(--fg);
8584
}
8685

86+
body.nightowl {
87+
--body-bg: #00101d;
88+
--bg: #011627;
89+
--fg: #d6deeb;
90+
--directory: #ffcb8b;
91+
--prompt: #c792ea;
92+
--cursor: var(--prompt);
93+
--listItem: var(--fg);
94+
--listTitle: var(--fg);
95+
}
96+
8797
#terminal {
8898
background-color: var(--bg);
8999
box-sizing: border-box;
@@ -162,3 +172,27 @@ body.greyscale {
162172
margin: 0px;
163173
padding: 0em 1em;
164174
}
175+
176+
.tree-list {
177+
margin: 0px;
178+
padding: 0px;
179+
list-style: none;
180+
}
181+
.tree-list .tree-list {
182+
margin: .1em 0em;
183+
padding: 0em 0.5em;
184+
border-left: 1px solid var(--fg);
185+
}
186+
187+
.tree-list-item {
188+
color: var(--fg);
189+
}
190+
191+
.tree-list .tree-list .tree-list-item {
192+
padding: .1em 0.5em;
193+
}
194+
195+
.tree-list-item.directory {
196+
color: var(--directory);
197+
padding: 0.25em 0em;
198+
}

0 commit comments

Comments
 (0)