[WIP] Implement save, load, over, infile, outfile, on, lipsum, help + start implementing undo, redo, exit, edit
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user