diff --git a/src/js/commands.ts b/src/js/commands.ts new file mode 100644 index 0000000..9f213e3 --- /dev/null +++ b/src/js/commands.ts @@ -0,0 +1,9 @@ +//// +// temporary hack for browser commands + +import { scrollback } from "./dom.js" + +export const commands: Record void> = { + fullscreen: () => document.body.requestFullscreen(), + clear: () => scrollback.innerHTML = "", +} \ No newline at end of file diff --git a/src/js/shell.ts b/src/js/shell.ts index 0d0670b..68e5412 100644 --- a/src/js/shell.ts +++ b/src/js/shell.ts @@ -6,6 +6,7 @@ import { send } from "./websocket.js" import { randomID } from "../shared/utils.js" import type { Message, CommandResult } from "../shared/types.js" import { addToHistory } from "./history.js" +import { commands } from "./commands.js" export function runCommand(input: string) { const id = randomID() @@ -13,7 +14,14 @@ export function runCommand(input: string) { addToHistory(input) addInput(id, input) - send({ id, type: "input", data: input }) + const [cmd = "", ...args] = input.split(" ") + + if (commands[cmd]) { + commands[cmd]() + setStatus(id, "ok") + } else { + send({ id, type: "input", data: input }) + } } // message received from server