mirror of
https://git.sr.ht/~cadence/bibliogram
synced 2025-12-15 02:45:09 +00:00
Create post viewer
This commit is contained in:
31
src/site/repl.js
Normal file
31
src/site/repl.js
Normal file
@@ -0,0 +1,31 @@
|
||||
const {instance, pugCache, wss} = require("./passthrough")
|
||||
const {requestCache, timelineImageCache} = require("../lib/collectors")
|
||||
const util = require("util")
|
||||
const repl = require("repl")
|
||||
const vm = require("vm")
|
||||
|
||||
/**
|
||||
* @param {string} input
|
||||
* @param {vm.Context} context
|
||||
* @param {string} filename
|
||||
* @param {(err: Error|null, result: any) => any} callback
|
||||
*/
|
||||
async function customEval(input, context, filename, callback) {
|
||||
let depth = 0
|
||||
if (input == "exit\n") return process.exit()
|
||||
if (input.startsWith(":")) {
|
||||
const depthOverwrite = input.split(" ")[0]
|
||||
depth = +depthOverwrite.slice(1)
|
||||
input = input.slice(depthOverwrite.length + 1)
|
||||
}
|
||||
const result = await eval(input)
|
||||
const output = util.inspect(result, false, depth, true)
|
||||
return callback(undefined, output)
|
||||
}
|
||||
|
||||
function customWriter(output) {
|
||||
return output
|
||||
}
|
||||
|
||||
console.log("REPL started")
|
||||
repl.start({prompt: "b) ", eval: customEval, writer: customWriter}).once("exit", () => process.exit())
|
||||
Reference in New Issue
Block a user