Skip to content

Commit

Permalink
added path saving #19
Browse files Browse the repository at this point in the history
  • Loading branch information
noel-friedrich committed Jan 29, 2024
1 parent 32d404a commit 2b3dd28
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 9 deletions.
2 changes: 1 addition & 1 deletion gui/cd/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ <h1>
<script src="../../js/terminal.js"></script>

<script>
const command_data = {"helpVisible": true, "args": {"directory": "the directory relative to your current path"}, "description": "change current directory", "name": "cd"}
const command_data = {"helpVisible": true, "args": {"directory:s": "the directory relative to your current path"}, "description": "change current directory", "name": "cd"}
</script>

<script src="../main.js"></script>
Expand Down
2 changes: 1 addition & 1 deletion gui/edit/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ <h1>
<script src="../../js/terminal.js"></script>

<script>
const command_data = {"description": "edit a file of the current directory", "args": {"?file": "the file to open"}, "name": "edit"}
const command_data = {"description": "edit a file of the current directory", "args": {"?file:f": "the file to open"}, "name": "edit"}
</script>

<script src="../main.js"></script>
Expand Down
2 changes: 1 addition & 1 deletion gui/mv/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ <h1>
<script src="../../js/terminal.js"></script>

<script>
const command_data = {"description": "move a file", "args": ["file", "directory"], "name": "mv"}
const command_data = {"description": "move a file", "args": ["file:f", "directory:f"], "name": "mv"}
</script>

<script src="../main.js"></script>
Expand Down
2 changes: 1 addition & 1 deletion gui/rm/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ <h1>
<script src="../../js/terminal.js"></script>

<script>
const command_data = {"description": "remove a file", "args": ["*file"], "name": "rm"}
const command_data = {"description": "remove a file", "args": ["*file:f"], "name": "rm"}
</script>

<script src="../main.js"></script>
Expand Down
2 changes: 1 addition & 1 deletion gui/rmdir/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ <h1>
<script src="../../js/terminal.js"></script>

<script>
const command_data = {"description": "remove a directory", "args": ["directory"], "name": "rmdir"}
const command_data = {"description": "remove a directory", "args": ["directory:f"], "name": "rmdir"}
</script>

<script src="../main.js"></script>
Expand Down
2 changes: 1 addition & 1 deletion gui/wc/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ <h1>
<script src="../../js/terminal.js"></script>

<script>
const command_data = {"description": "display word and line count of file", "args": {"?f=file": "file to open", "?s": "string to count instead of file"}, "name": "wc"}
const command_data = {"description": "display word and line count of file", "args": {"?f=file:f": "file to open", "?s": "string to count instead of file"}, "name": "wc"}
</script>

<script src="../main.js"></script>
Expand Down
4 changes: 3 additions & 1 deletion js/commands/cd.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
terminal.addCommand("cd", function(args) {
console.log(args)
if (["-", ".."].includes(args.directory)) {
if (terminal.fileSystem.currPath.length > 0) {
terminal.fileSystem.currPath.pop()
terminal.updatePath()
return
} else {
throw new Error("You are already at ground level")
Expand All @@ -22,7 +24,7 @@ terminal.addCommand("cd", function(args) {
}, {
helpVisible: true,
args: {
"directory": "the directory relative to your current path"
"directory:s": "the directory relative to your current path"
},
description: "change current directory",
})
2 changes: 1 addition & 1 deletion js/load-commands.js

Large diffs are not rendered by default.

14 changes: 13 additions & 1 deletion js/terminal.js
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ class TerminalData {
"mobile": "2",
"easterEggs": "[]",
"sidepanel": "true",
"path": "[]",
"aliases": '{"tree": "ls -r","github": "href -f root/github.url","hugeturtlo": "turtlo --size 2","hugehugeturtlo": "turtlo --size 3","panik": "time -ms"}'
}

Expand Down Expand Up @@ -465,6 +466,14 @@ class TerminalData {
this.set("history", JSON.stringify(history))
}

get path() {
return JSON.parse(this.get("path"))
}

set path(path) {
this.set("path", JSON.stringify(path))
}

get easterEggs() {
let arr = JSON.parse(this.get("easterEggs"))
return new Set(arr)
Expand Down Expand Up @@ -1694,7 +1703,7 @@ class Terminal {
}

updatePath() {
// legacy
this.data.path = this.fileSystem.currPath
}

isValidFileName(name) {
Expand Down Expand Up @@ -2978,6 +2987,9 @@ class Terminal {
for (let startupCommand of this.data.startupCommands) {
await this.input(startupCommand, true)
}

// load path from localstorage
this.fileSystem.currPath = this.data.path
}

if (!ignoreMobile) {
Expand Down

0 comments on commit 2b3dd28

Please sign in to comment.