Implement output/clipboard interfaces, stub implementations, and implement execute()s for Copy and Paste
This commit is contained in:
@@ -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()))))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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()))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user