feat(simulation): expose normalized terminal frames (#37135)
This commit is contained in:
parent
83cfafc884
commit
35f14900ae
4 changed files with 56 additions and 0 deletions
|
|
@ -110,6 +110,25 @@ export function matches(harness: Pick<Harness, "screen">, text: string) {
|
|||
return harness.screen().includes(text)
|
||||
}
|
||||
|
||||
export const capture = Effect.fn("SimulationActions.capture")(function* (harness: Harness) {
|
||||
yield* Effect.tryPromise(() => harness.renderOnce())
|
||||
const buffer = harness.renderer.currentRenderBuffer
|
||||
return {
|
||||
cols: buffer.width,
|
||||
rows: buffer.height,
|
||||
cursor: [0, 0] as const,
|
||||
lines: buffer.getSpanLines().map((line) => ({
|
||||
spans: line.spans.map((span) => ({
|
||||
text: span.text,
|
||||
fg: span.fg.toInts(),
|
||||
bg: span.bg.toInts(),
|
||||
attributes: span.attributes,
|
||||
width: span.width,
|
||||
})),
|
||||
})),
|
||||
} satisfies SimulationProtocol.Frontend.CapturedFrame
|
||||
})
|
||||
|
||||
export const screenshot = Effect.fn("SimulationActions.screenshot")(function* (harness: Harness, name?: string) {
|
||||
const filename = name ?? `screenshot-${crypto.randomUUID()}`
|
||||
if (!filename || filename.includes("/") || filename.includes("\\") || extname(filename))
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@ import { SimulationRenderer } from "./renderer"
|
|||
|
||||
function handle(harness: Harness, request: SimulationProtocol.Frontend.Request) {
|
||||
switch (request.method) {
|
||||
case "ui.capture":
|
||||
return SimulationActions.capture(harness)
|
||||
case "ui.screenshot":
|
||||
return SimulationActions.screenshot(harness, request.params?.name)
|
||||
case "ui.state":
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue