simple browser commands, for now

This commit is contained in:
Chris Wanstrath 2025-09-20 20:27:35 -07:00
parent c78154af5f
commit 5b50df3e4f
2 changed files with 18 additions and 1 deletions

9
src/js/commands.ts Normal file
View File

@ -0,0 +1,9 @@
////
// temporary hack for browser commands
import { scrollback } from "./dom.js"
export const commands: Record<string, () => void> = {
fullscreen: () => document.body.requestFullscreen(),
clear: () => scrollback.innerHTML = "",
}

View File

@ -6,6 +6,7 @@ import { send } from "./websocket.js"
import { randomID } from "../shared/utils.js" import { randomID } from "../shared/utils.js"
import type { Message, CommandResult } from "../shared/types.js" import type { Message, CommandResult } from "../shared/types.js"
import { addToHistory } from "./history.js" import { addToHistory } from "./history.js"
import { commands } from "./commands.js"
export function runCommand(input: string) { export function runCommand(input: string) {
const id = randomID() const id = randomID()
@ -13,7 +14,14 @@ export function runCommand(input: string) {
addToHistory(input) addToHistory(input)
addInput(id, input) addInput(id, input)
const [cmd = "", ...args] = input.split(" ")
if (commands[cmd]) {
commands[cmd]()
setStatus(id, "ok")
} else {
send({ id, type: "input", data: input }) send({ id, type: "input", data: input })
}
} }
// message received from server // message received from server