Compare commits
2 Commits
history
...
bf40d524b7
Author | SHA1 | Date | |
---|---|---|---|
bf40d524b7 | |||
1fe21b1592 |
@ -8,8 +8,8 @@ interface EnterArgs {
|
||||
readonly closure: InputClosure
|
||||
}
|
||||
interface Keys {
|
||||
enter: (input: EnterArgs) => void,
|
||||
up_arrow: (ps1input: HTMLInputElement) => void,
|
||||
enter: (input: EnterArgs) => void,
|
||||
up_arrow: (ps1input: HTMLInputElement) => void,
|
||||
down_arrow: (ps1input: HTMLInputElement) => void,
|
||||
}
|
||||
|
||||
|
6
src/components/client/shell/command/builtin/cat.ts
Normal file
6
src/components/client/shell/command/builtin/cat.ts
Normal file
@ -0,0 +1,6 @@
|
||||
import type { Args, Term } from "../list";
|
||||
|
||||
export default function cat(term: Term, args: Args): boolean {
|
||||
|
||||
return true
|
||||
}
|
13
src/components/client/shell/command/builtin/cd.ts
Normal file
13
src/components/client/shell/command/builtin/cd.ts
Normal file
@ -0,0 +1,13 @@
|
||||
import { set_working_dir, SetDirStatus } from "../../fs/fn"
|
||||
import type { Args, Term } from "../list"
|
||||
|
||||
export default function cd(term: Term, args: Args): boolean {
|
||||
const new_dir_status = set_working_dir(args[1])
|
||||
|
||||
if (new_dir_status === SetDirStatus.NotADirectory) {
|
||||
// return <p>{"cd: \""}{bold(args[1])}{"\" is not a directory"}</p>
|
||||
} else if (new_dir_status === SetDirStatus.NotFound) {
|
||||
// return <p>{"cd: The directory \""}{bold(args[1])}{"\" does not exist"}</p>
|
||||
}
|
||||
return true
|
||||
}
|
19
src/components/client/shell/command/builtin/clear.ts
Normal file
19
src/components/client/shell/command/builtin/clear.ts
Normal file
@ -0,0 +1,19 @@
|
||||
import type { Args, Term } from "../list"
|
||||
|
||||
export default function clear(term: Term, args: Args): boolean {
|
||||
Array.from(term.children).forEach(node => {
|
||||
if (node.tagName === "DIV") {
|
||||
if (node.className === "shell-prompt") {
|
||||
const input = node.getElementsByClassName("shell-ps1")[0] as HTMLInputElement
|
||||
if (input.disabled || input.value === "clear") {
|
||||
node.remove()
|
||||
}
|
||||
} else {
|
||||
node.remove()
|
||||
}
|
||||
} else if (node.tagName === "P") {
|
||||
node.remove()
|
||||
}
|
||||
})
|
||||
return true
|
||||
}
|
11
src/components/client/shell/command/builtin/ls.ts
Normal file
11
src/components/client/shell/command/builtin/ls.ts
Normal file
@ -0,0 +1,11 @@
|
||||
import type { Args, Term } from "../list";
|
||||
|
||||
export default function ls(term: Term, args: Args): boolean {
|
||||
// if (args[1] === undefined) {
|
||||
// for (const dir_name in working_dir) {
|
||||
|
||||
// }
|
||||
// return <p>{`${working_dir}`}</p>
|
||||
// }
|
||||
return true
|
||||
}
|
9
src/components/client/shell/command/builtin/pwd.ts
Normal file
9
src/components/client/shell/command/builtin/pwd.ts
Normal file
@ -0,0 +1,9 @@
|
||||
import { get_working_dir_name_full } from "../../fs/fn";
|
||||
import type { Args, Term } from "../list";
|
||||
|
||||
import stdout from "../../../elements/stdout";
|
||||
|
||||
export default function pwd(term: Term, args: Args): boolean {
|
||||
term.appendChild(stdout(get_working_dir_name_full()))
|
||||
return true
|
||||
}
|
@ -1,70 +1,25 @@
|
||||
import { get_working_dir_name_full, set_working_dir, SetDirStatus } from "../fs/fn"
|
||||
|
||||
import history_cmd from "./builtin/history"
|
||||
import stdout from "../../elements/stdout"
|
||||
import history from "./builtin/history"
|
||||
import clear from "./builtin/clear"
|
||||
import pwd from "./builtin/pwd"
|
||||
import cat from "./builtin/cat"
|
||||
import cd from "./builtin/cd"
|
||||
import ls from "./builtin/ls"
|
||||
|
||||
type Term = HTMLElement
|
||||
type Args = string[]
|
||||
|
||||
function clear(term: Term, args: Args): boolean {
|
||||
Array.from(term.children).forEach(node => {
|
||||
if (node.tagName === "DIV") {
|
||||
if (node.className === "shell-prompt") {
|
||||
const input = node.getElementsByClassName("shell-ps1")[0] as HTMLInputElement
|
||||
if (input.disabled || input.value === "clear") {
|
||||
node.remove()
|
||||
}
|
||||
} else {
|
||||
node.remove()
|
||||
}
|
||||
} else if (node.tagName === "P") {
|
||||
node.remove()
|
||||
}
|
||||
})
|
||||
return true
|
||||
}
|
||||
|
||||
function cd(term: Term, args: Args): boolean {
|
||||
const new_dir_status = set_working_dir(args[1])
|
||||
|
||||
if (new_dir_status === SetDirStatus.NotADirectory) {
|
||||
// return <p>{"cd: \""}{bold(args[1])}{"\" is not a directory"}</p>
|
||||
} else if (new_dir_status === SetDirStatus.NotFound) {
|
||||
// return <p>{"cd: The directory \""}{bold(args[1])}{"\" does not exist"}</p>
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
function ls(term: Term, args: Args): boolean {
|
||||
// if (args[1] === undefined) {
|
||||
// for (const dir_name in working_dir) {
|
||||
|
||||
// }
|
||||
// return <p>{`${working_dir}`}</p>
|
||||
// }
|
||||
return true
|
||||
}
|
||||
|
||||
function pwd(term: Term, args: Args): boolean {
|
||||
term.appendChild(stdout(get_working_dir_name_full()))
|
||||
return true
|
||||
}
|
||||
|
||||
function cat(term: Term, args: Args): boolean {
|
||||
return true
|
||||
}
|
||||
|
||||
type Command = (term: Term, args: Args) => boolean
|
||||
|
||||
interface CommandsList {
|
||||
[index: string]: Command,
|
||||
}
|
||||
|
||||
const commands: CommandsList = {
|
||||
["history"]: history,
|
||||
["clear"]: clear,
|
||||
["cd"]: cd,
|
||||
["ls"]: ls,
|
||||
["pwd"]: pwd,
|
||||
["cat"]: cat,
|
||||
["history"]: history_cmd,
|
||||
["cd"]: cd,
|
||||
["ls"]: ls,
|
||||
}
|
||||
|
||||
export default commands
|
||||
|
@ -4,9 +4,9 @@ interface HistoryFile {
|
||||
cursor_reset: () => void
|
||||
}
|
||||
interface History {
|
||||
file: HistoryFile
|
||||
add: (cmd: string) => void,
|
||||
index_up: (ps1input: HTMLInputElement) => void,
|
||||
file: HistoryFile
|
||||
add: (cmd: string) => void,
|
||||
index_up: (ps1input: HTMLInputElement) => void,
|
||||
index_down: (ps1input: HTMLInputElement) => void
|
||||
}
|
||||
|
||||
@ -36,7 +36,7 @@ history.index_down = function(ps1input: HTMLInputElement) {
|
||||
if (this.file.cursor!==0) {
|
||||
this.file.cursor-=1
|
||||
if (this.file.cursor!==0) {
|
||||
const item = this.file.inner[this.file.cursor]
|
||||
const item = this.file.inner[this.file.cursor-1]
|
||||
if (item) { ps1input.value = item }
|
||||
} else {
|
||||
this.file.cursor_reset()
|
||||
|
Reference in New Issue
Block a user