simple browser commands, for now
This commit is contained in:
parent
c78154af5f
commit
5b50df3e4f
9
src/js/commands.ts
Normal file
9
src/js/commands.ts
Normal 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 = "",
|
||||
}
|
||||
|
|
@ -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)
|
||||
|
||||
const [cmd = "", ...args] = input.split(" ")
|
||||
|
||||
if (commands[cmd]) {
|
||||
commands[cmd]()
|
||||
setStatus(id, "ok")
|
||||
} else {
|
||||
send({ id, type: "input", data: input })
|
||||
}
|
||||
}
|
||||
|
||||
// message received from server
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user