[WIP] Implement save, load, over, infile, outfile, on, lipsum, help + start implementing undo, redo, exit, edit

This commit is contained in:
2026-02-22 10:10:38 -06:00
parent 42e6b41879
commit d52b121fd7
15 changed files with 458 additions and 29 deletions

View File

@@ -1,5 +1,8 @@
import {Command, ParseContext, StrTerm} from "./command.js";
import {Command, ParseContext, processPath, StrTerm, wrapString} from "./command.js";
import {LexInput} from "../lexer.js";
import {StrVM} from "../vm.js";
import {Awaitable} from "../../util/types.js";
import fs from "node:fs/promises";
export class InFile extends Command<{ path: StrTerm }> {
isParseCandidate(token: LexInput): boolean {
@@ -13,4 +16,14 @@ export class InFile extends Command<{ path: StrTerm }> {
getDisplayName(): string {
return 'infile'
}
execute(vm: StrVM, data: { path: StrTerm }): Awaitable<StrVM> {
return vm.replaceContextMatchingTerm(ctx => ({
override: async () => {
const path = processPath(ctx.resolveString(data.path))
const content = await fs.readFile(path, 'utf8')
return wrapString(content)
}
}))
}
}