status line!

This commit is contained in:
Chris Wanstrath 2025-10-02 14:07:55 -07:00
parent 7ffffebd4a
commit 3f9db13192
7 changed files with 50 additions and 3 deletions

View File

@ -160,4 +160,19 @@
#scrollback .output { #scrollback .output {
white-space: pre-wrap; white-space: pre-wrap;
}
#statusline {
position: absolute;
bottom: 0;
left: 0;
width: 100%;
padding: 2px 8px;
background: var(--c64-light-gray);
color: var(--c64-dark-blue);
font-size: 14px;
display: flex;
justify-content: space-between;
} }

View File

@ -34,5 +34,7 @@ export const Terminal: FC = async () => (
<li class="center">**** NOSE PLUTO V{new Date().getMonth() + 1}.{new Date().getDate()} ****</li> <li class="center">**** NOSE PLUTO V{new Date().getMonth() + 1}.{new Date().getDate()} ****</li>
<li class="center">VRAM <span id="vram-size">000KB</span></li> <li class="center">VRAM <span id="vram-size">000KB</span></li>
</ul> </ul>
<div id="statusline"><div><span id="project-name">root</span>: <span id="project-cwd">/</span></div></div>
</> </>
) )

View File

@ -38,5 +38,4 @@ export function cacheCommands(cmds: string[]) {
commands.push(...cmds) commands.push(...cmds)
commands.push(...Object.keys(browserCommands)) commands.push(...Object.keys(browserCommands))
commands.sort() commands.sort()
console.log("CMDS", commands)
} }

View File

@ -4,6 +4,7 @@ import { handleOutput } from "./scrollback"
import { handleStreamStart, handleStreamAppend, handleStreamReplace, handleStreamEnd } from "./stream" import { handleStreamStart, handleStreamAppend, handleStreamReplace, handleStreamEnd } from "./stream"
import { handleGameStart } from "./game" import { handleGameStart } from "./game"
import { browserCommands } from "./commands" import { browserCommands } from "./commands"
import { handleSessionUpdate } from "./session"
// message received from server // message received from server
export async function dispatchMessage(msg: Message) { export async function dispatchMessage(msg: Message) {
@ -26,6 +27,8 @@ export async function dispatchMessage(msg: Message) {
await handleGameStart(msg); break await handleGameStart(msg); break
case "ui:mode": case "ui:mode":
browserCommands.mode?.(msg.data as string); break browserCommands.mode?.(msg.data as string); break
case "session:update":
handleSessionUpdate(msg); break
default: default:
console.error("unknown message type", msg) console.error("unknown message type", msg)
} }

View File

@ -2,6 +2,22 @@
// Each browser tab is a shell session. This means you can run multiple sessions // Each browser tab is a shell session. This means you can run multiple sessions
// in the same browser. // in the same browser.
import type { Message } from "@/shared/types"
import { randomId } from "../shared/utils" import { randomId } from "../shared/utils"
import { $ } from "./dom"
export const sessionId = randomId() export const sessionId = randomId()
export const projectName = $("project-name") as HTMLSpanElement
export const projectCwd = $("project-cwd") as HTMLSpanElement
export function handleSessionUpdate(msg: Message) {
const data = msg.data as Record<string, string>
if (data.project) {
projectName.textContent = data.project
}
if (data.cwd) {
projectCwd.textContent = data.cwd
}
}

View File

@ -2,6 +2,7 @@
// Session storage. 1 browser tab = 1 session // Session storage. 1 browser tab = 1 session
import { AsyncLocalStorage } from "async_hooks" import { AsyncLocalStorage } from "async_hooks"
import { send } from "./websocket"
export type Session = { export type Session = {
taskId?: string taskId?: string
@ -35,6 +36,12 @@ export function sessionSet(key: keyof Session, value: any) {
const store = ALS.getStore() const store = ALS.getStore()
if (!store) throw "sessionSet() called outside of ALS.run" if (!store) throw "sessionSet() called outside of ALS.run"
store[key] = value store[key] = value
if (!store.ws) return
send(store.ws, {
type: "session:update",
data: { [key]: value }
})
} }
export function sessionStore(sessionId: string, taskId?: string, ws?: any): Session { export function sessionStore(sessionId: string, taskId?: string, ws?: any): Session {

View File

@ -3,7 +3,7 @@ export type Message = {
id?: string id?: string
type: MessageType type: MessageType
data?: CommandResult | CommandOutput data?: CommandResult | CommandOutput
} } | SessionUpdateMessage
export type MessageType = "error" | "input" | "output" | "commands" | "save-file" export type MessageType = "error" | "input" | "output" | "commands" | "save-file"
| "game:start" | "game:start"
@ -20,3 +20,8 @@ export type CommandResult = {
status: "ok" | "error" status: "ok" | "error"
output: CommandOutput output: CommandOutput
} }
type SessionUpdateMessage = {
type: "session:update",
data: Record<string, string>
}