diff --git a/src/components/react/shell/color.tsx b/src/components/react/shell/color.tsx index 1f779c4..43df7c7 100644 --- a/src/components/react/shell/color.tsx +++ b/src/components/react/shell/color.tsx @@ -2,6 +2,7 @@ const red = (s: string) => {s} const green = (s: string) => {s} const blue = (s: string) => {s} const cyan = (s: string) => {s} +const bold = (s: string) => {s} export default function rgb(s: string, Ru8: number, Gu8: number, Bu8: number) { return {s} @@ -11,5 +12,6 @@ export { red, green, blue, - cyan + cyan, + bold } \ No newline at end of file diff --git a/src/components/react/shell/command/list.ts b/src/components/react/shell/command/list.ts deleted file mode 100644 index a64ceb4..0000000 --- a/src/components/react/shell/command/list.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { working_dir } from "../fs" - -type args = string[] - -function ls(args: args) { - console.log(args) -} - -function pwd(args: args) { - -} - -function cat(args: args) { - -} - -interface commands_list { - [index: string]: (args: args) => void -} -const commands: commands_list = { - ["ls"]: ls, - ["pwd"]: pwd, - ["cat"]: cat, -} - -export default commands \ No newline at end of file diff --git a/src/components/react/shell/command/list.tsx b/src/components/react/shell/command/list.tsx new file mode 100644 index 0000000..324018e --- /dev/null +++ b/src/components/react/shell/command/list.tsx @@ -0,0 +1,48 @@ +import type { JSX } from "react" +import { Entry } from "../fs/fs" +import { blue } from "../color" +import { set_working_dir } from "../fs/fn" + +type args = string[] +type command = JSX.Element | undefined + +function parse_ls(entries: JSX.Element[]) { + return
{`${working_dir}`}
+ // } +} + +function pwd(args: args): command { + const tree: string[] = [] + + return{`${tree.join("/")}`}
+} + +function cat(args: args): command { + return +} + +interface commands_list { + [index: string]: (args: args) => command +} +const commands: commands_list = { + ["cd"]: cd, + ["ls"]: ls, + ["pwd"]: pwd, + ["cat"]: cat, +} + +export default commands \ No newline at end of file diff --git a/src/components/react/shell/command/run.tsx b/src/components/react/shell/command/run.tsx index 52c0396..69fa564 100644 --- a/src/components/react/shell/command/run.tsx +++ b/src/components/react/shell/command/run.tsx @@ -1,14 +1,10 @@ import type { JSX } from "react"; -import type { Root } from "react-dom/client"; -import { type newElement } from "../../terminal/exec"; - import commands from "./list"; - -type Renderer{`sh: Unknown command: ${name}`}
+function unknown_command(cmd_name: string) { + return{"shell: Unknown command: "}{bold(cmd_name)}
} export default function run(stdin: string) { const args = to_args(trim(stdin)) + const command = valid_command(args) - if (args[0] !== "" && !valid_command(args)) { + if (args[0] !== "" && !command) { return unknown_command(args[0]) } - return <>> + return command ? command : <>> } \ No newline at end of file diff --git a/src/components/react/shell/events.tsx b/src/components/react/shell/events.tsx index 9f013ed..94fb4be 100644 --- a/src/components/react/shell/events.tsx +++ b/src/components/react/shell/events.tsx @@ -33,14 +33,14 @@ function new_prompt(): JSX.Element { return display_prompt() } -function keyboard_events(terminal_window: HTMLElement, new_element_f: newElement) { +function keyboard_events(terminal_window: HTMLElement, new_elements_f: newElement) { const terminal_event = (keyboard_event: KeyboardEvent) => { if (keyboard_event.key === Key.Enter) { const current_prompt = get_current_prompt() if (current_prompt) { const prompt = new_prompt() const output = run(current_prompt.value) - new_element_f([output, prompt]) + new_elements_f([output, prompt]) terminal_window.removeEventListener("keydown", terminal_event) } } else if (keyboard_event.key === Key.ArrowUp) { diff --git a/src/components/react/shell/fs.ts b/src/components/react/shell/fs.ts deleted file mode 100644 index 56006b6..0000000 --- a/src/components/react/shell/fs.ts +++ /dev/null @@ -1,46 +0,0 @@ -let working_dir = "user" - -const enum EntryType { - Directory, - File -} -const enum Permissions { - r, - w, - rw -} - -type File = string -type Entry{user}@{browser_name} {dir}{"> "}
} diff --git a/src/components/react/terminal/exec.tsx b/src/components/react/terminal/exec.tsx index 5b4da0e..f812d5b 100644 --- a/src/components/react/terminal/exec.tsx +++ b/src/components/react/terminal/exec.tsx @@ -20,9 +20,9 @@ type newElement = (elements: JSX.Element[]) => void export default function Shell() { if (terminal_window) { const [renderedElements, renderElement] = useState([display_prompt()]) - const new_element_f = (elements: JSX.Element[]) => renderElement([...renderedElements, ...elements]) + const new_elements_f = (elements: JSX.Element[]) => renderElement([...renderedElements, ...elements]) - keyboard_events(terminal_window, new_element_f) + keyboard_events(terminal_window, new_elements_f) return renderedElements.map((element, k) =>