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 { 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,8 +14,15 @@ 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
|
||||||
export function handleMessage(data: Message) {
|
export function handleMessage(data: Message) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user