describe and inspect

This commit is contained in:
Chris Wanstrath 2025-11-05 14:53:42 -08:00
parent f063621369
commit d48098b006

View File

@ -1,3 +1,6 @@
import { globals } from 'shrimp'
import { AnsiUp } from 'ansi_up'
const buffer: string[] = []
const NOSPACE_TOKEN = '!!ribbit-nospace!!'
const TAG_TOKEN = '!!ribbit-tag!!'
@ -22,7 +25,18 @@ export function wrapCode(code: string): string {
return "ribbit do:\n " + code + "\nend"
}
const ansiUp = new AnsiUp()
export const ribbitGlobals = {
// special variables
'page-title': '🦐 shrimp',
// html-friendly info functions
describe: (v: any) => ansiUp.ansi_to_html(globals.describe(v)),
inspect: (v: any) => ansiUp.ansi_to_html(globals.inspect(v)),
echo: (...args: any[]) => console.log(...args),
// 🐸
ribbit: async (cb: Function) => {
await cb()
const output = buffer.join("\n")
@ -32,8 +46,6 @@ export const ribbitGlobals = {
tag: async (tagFn: Function, atDefaults = {}) =>
(atNamed = {}, ...args: any[]) => tagFn(Object.assign({}, atDefaults, atNamed), ...args),
nospace: () => NOSPACE_TOKEN,
echo: (...args: any[]) => console.log(...args),
'page-title': '🦐 shrimp'
}
for (const name of HTML5_TAGS) {