like something along the lines of this where there is a primary eval for regular commands but also slash commands. then the idea is you can add this to any long running program to get an interactive eval. then you can add helper JS values such as db to the repl, or add custom slash commands such as /post /v1/meow { x: 1 } to for example act a post request on the current server, or /file-scan or /fetch-questions in clover website to run some premade scripts
interface Options {
/**
* called when a non-command is executed.
* set `eval` to `null` to disable arbitrary code execution.
*
* return `null` to indicate the code is unterminated,
* causing the prompt to include another line.
*/
eval?: ((code: string) => Promise<void> | null) | null;
syntaxHighlight?: (code: string) => string, /* with ansi styles */
/** globals available to the built-in javascript evaluator */
globals?: Record<string, unknown>,
/** commands can be evaluated in console like '/command' */
commands?: Record<string, Command>;
/** @default `log` */
interface?: log.HeadlessWidgetHost;
}
interface Command {
execute: (repl: Repl, args: string, ref: progress.Ref) => Promise<void>;
/** wait for `execute` to complete before giving control back to input */
block?: boolean;
}
class Repl implements log.Widget {
constructor(options: Options) {}
}
import * as log from "./log.ts";
import * as progress from "./progress.ts";