diff --git a/app/src/js/scrollback.ts b/app/src/js/scrollback.ts index 32fd0ba..5ca626d 100644 --- a/app/src/js/scrollback.ts +++ b/app/src/js/scrollback.ts @@ -2,7 +2,7 @@ // The scrollback shows your history of interacting with the shell. // input, output, etc -import { scrollback, $, $$ } from "./dom.js" +import { scrollback, $$ } from "./dom.js" import { randomId } from "../shared/utils.js" import type { CommandOutput } from "../shared/types.js" @@ -123,6 +123,9 @@ function processOutput(output: CommandOutput): ["html" | "text", string] { } else if ("html" in output) { html = true content = output.html + if (output.script) eval(output.script) + } else if ("script" in output) { + eval(output.script) } else { content = JSON.stringify(output) } diff --git a/app/src/shared/types.ts b/app/src/shared/types.ts index 58f2d27..ff5bf43 100644 --- a/app/src/shared/types.ts +++ b/app/src/shared/types.ts @@ -9,7 +9,9 @@ export type MessageType = "error" | "input" | "output" | "commands" | "save-file | "game:start" | "stream:start" | "stream:end" | "stream:append" | "stream:replace" -export type CommandOutput = string | string[] | { html: string } | { game: string } +export type CommandOutput = string | string[] + | { html: string, script?: string } | { script: string } + | { game: string } export type CommandResult = { status: "ok" | "error" diff --git a/app/src/shell.ts b/app/src/shell.ts index e1e5af5..1f6bb05 100644 --- a/app/src/shell.ts +++ b/app/src/shell.ts @@ -47,8 +47,11 @@ export function processExecOutput(output: string | any): ["ok" | "error", Comman } else if (typeof output === "object") { if (output.error) { return ["error", output.error] - } else if (output.tag && output.props && output.children) { + } else if (isJSX(output)) { return ["ok", { html: output.toString() }] + } else if (output.html && isJSX(output.html)) { + output.html = output.html.toString() + return ["ok", output] } else { return ["ok", output] } @@ -77,4 +80,8 @@ function errorMessage(error: Error | any): string { let msg = `${error.name}: ${error.message}` if (error.stack) msg += `\n${error.stack}` return msg +} + +function isJSX(obj: any): boolean { + return 'tag' in obj && 'props' in obj && 'children' in obj } \ No newline at end of file