diff --git a/src/components/client/shell/command/builtin/cat.ts b/src/components/client/shell/command/builtin/cat.ts new file mode 100644 index 0000000..ceff80a --- /dev/null +++ b/src/components/client/shell/command/builtin/cat.ts @@ -0,0 +1,6 @@ +import type { Args, Term } from "../list"; + +export default function cat(term: Term, args: Args): boolean { + + return true +} \ No newline at end of file diff --git a/src/components/client/shell/command/builtin/cd.ts b/src/components/client/shell/command/builtin/cd.ts new file mode 100644 index 0000000..3e43f9d --- /dev/null +++ b/src/components/client/shell/command/builtin/cd.ts @@ -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

{"cd: \""}{bold(args[1])}{"\" is not a directory"}

+ } else if (new_dir_status === SetDirStatus.NotFound) { + // return

{"cd: The directory \""}{bold(args[1])}{"\" does not exist"}

+ } + return true +} \ No newline at end of file diff --git a/src/components/client/shell/command/builtin/clear.ts b/src/components/client/shell/command/builtin/clear.ts new file mode 100644 index 0000000..ddab613 --- /dev/null +++ b/src/components/client/shell/command/builtin/clear.ts @@ -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 +} \ No newline at end of file diff --git a/src/components/client/shell/command/builtin/ls.ts b/src/components/client/shell/command/builtin/ls.ts new file mode 100644 index 0000000..8d53ad5 --- /dev/null +++ b/src/components/client/shell/command/builtin/ls.ts @@ -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

{`${working_dir}`}

+ // } + return true +} \ No newline at end of file diff --git a/src/components/client/shell/command/builtin/pwd.ts b/src/components/client/shell/command/builtin/pwd.ts new file mode 100644 index 0000000..7e611e2 --- /dev/null +++ b/src/components/client/shell/command/builtin/pwd.ts @@ -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 +} \ No newline at end of file diff --git a/src/components/client/shell/command/list.ts b/src/components/client/shell/command/list.ts index fa6e5f3..7a90e46 100644 --- a/src/components/client/shell/command/list.ts +++ b/src/components/client/shell/command/list.ts @@ -1,70 +1,24 @@ -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 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

{"cd: \""}{bold(args[1])}{"\" is not a directory"}

- } else if (new_dir_status === SetDirStatus.NotFound) { - // return

{"cd: The directory \""}{bold(args[1])}{"\" does not exist"}

- } - return true -} - -function ls(term: Term, args: Args): boolean { - // if (args[1] === undefined) { - // for (const dir_name in working_dir) { - - // } - // return

{`${working_dir}`}

- // } - 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_cmd, ["clear"]: clear, - ["cd"]: cd, - ["ls"]: ls, ["pwd"]: pwd, ["cat"]: cat, - ["history"]: history_cmd, + ["cd"]: cd, + ["ls"]: ls, } export default commands