This commit is contained in:
Chris Wanstrath 2025-09-20 18:12:41 -07:00
parent 227029c8f6
commit 3ff1b9f3fa
4 changed files with 32 additions and 8 deletions

View File

@ -58,6 +58,10 @@
color: var(--magenta);
}
.dark-blue {
color: var(--c64-dark-blue);
}
:fullscreen::backdrop {
background: var(--background-color);
}

View File

@ -24,7 +24,7 @@ export function setStatus(id: string, status: InputStatus) {
switch (status) {
case "waiting":
statusEl.classList.add("yellow")
statusEl.classList.add("dark-blue")
break
case "streaming":
statusEl.classList.add("purple")

View File

@ -6,6 +6,8 @@ import color from "kleur"
import { NOSE_ICON, NOSE_DIR, NOSE_BIN, NOSE_WWW } from "./config"
import { transpile, isFile, tilde } from "./utils"
import { apps, serveApp, publishDNS } from "./webapp"
import { runCommand } from "./shell"
import type { Message } from "./shared/message"
import { Layout } from "./components/layout"
import { Terminal } from "./components/terminal"
@ -54,15 +56,22 @@ app.get("/ws", upgradeWebSocket((c) => {
return {
onMessage(event, ws) {
console.log(`Message from client: ${event.data}`)
const data = JSON.parse(event.data.toString())
ws.send(JSON.stringify({ id: data.id, data: "Hi there!" }))
},
onClose: () => {
console.log('Connection closed')
let data: Message | undefined
try {
data = JSON.parse(event.data.toString())
} catch (e) {
console.error("JSON parsing error", e)
}
if (!data) return
const result = runCommand(data.data)
ws.send(JSON.stringify({ id: data.id, data: result }))
},
onClose: () => console.log('Connection closed'),
}
})
)
}))
//
// app routes

11
src/shell.ts Normal file
View File

@ -0,0 +1,11 @@
////
// runs commands and such.
type CommandResult = {
type: "ok" | "error"
data: any
}
export function runCommand(input: string): CommandResult {
return { type: "ok", data: "command: " + input }
}