Implement output/clipboard interfaces, stub implementations, and implement execute()s for Copy and Paste

This commit is contained in:
2026-02-10 00:06:16 -06:00
parent f36621c646
commit 06ff1b396f
5 changed files with 80 additions and 14 deletions

View File

@@ -1,5 +1,7 @@
import {Command, ParseContext} from "./command.js";
import {Command, ParseContext, unwrapString} from "./command.js";
import {LexInput} from "../lexer.js";
import {StrVM} from "../vm.js";
import {Awaitable} from "../../util/types.js";
export class Copy extends Command<{}> {
isParseCandidate(token: LexInput): boolean {
@@ -13,4 +15,10 @@ export class Copy extends Command<{}> {
getDisplayName(): string {
return 'copy'
}
execute(vm: StrVM): Awaitable<StrVM> {
return vm.tapInPlace(ctx =>
vm.withOutput(output =>
output.clipboard.overwrite(unwrapString(ctx.getSubject()))))
}
}

View File

@@ -1,5 +1,7 @@
import {Command, ParseContext} from "./command.js";
import {Command, ParseContext, wrapString} from "./command.js";
import {LexInput} from "../lexer.js";
import {StrVM} from "../vm.js";
import {Awaitable} from "../../util/types.js";
export class Paste extends Command<{}> {
isParseCandidate(token: LexInput): boolean {
@@ -13,4 +15,12 @@ export class Paste extends Command<{}> {
getDisplayName(): string {
return 'paste'
}
execute(vm: StrVM): Awaitable<StrVM> {
return vm.replaceContextMatchingTerm({
override: () =>
vm.withOutput(async output =>
wrapString(await output.clipboard.read()))
})
}
}