lib/repl #69

Open
opened 2026-01-12 15:52:50 -08:00 by clo · 0 comments
Owner

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";
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 ```ts 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"; ```
Sign in to join this conversation.
No labels
bug
chore
feat
lib
site
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
clo/sitegen#69
No description provided.