浏览代码

fix(simulation): mirror kitty keyboard protocol (#39741)

Kit Langton 2 周之前
父节点
当前提交
9abd9594de
共有 2 个文件被更改,包括 20 次插入0 次删除
  1. 1 0
      packages/simulation/src/frontend/renderer.ts
  2. 19 0
      packages/simulation/test/actions.test.ts

+ 1 - 0
packages/simulation/src/frontend/renderer.ts

@@ -41,6 +41,7 @@ export const create = Effect.fn("SimulationRenderer.create")(function* (
         ...options,
         width: cols,
         height: rows,
+        kittyKeyboard: Boolean(options.useKittyKeyboard),
         ...(recording
           ? {
               stdout: recording as unknown as NodeJS.WriteStream,

+ 19 - 0
packages/simulation/test/actions.test.ts

@@ -43,6 +43,25 @@ test("normalizes named keys for OpenTUI", async () => {
   ])
 })
 
+test("headless input mirrors the configured kitty keyboard protocol", async () => {
+  await Effect.runPromise(
+    Effect.scoped(
+      Effect.gen(function* () {
+        const renderer = yield* SimulationRenderer.create({ useKittyKeyboard: {} })
+        const harness = createHarness(renderer)
+        let key: { readonly name: string; readonly source: string } | undefined
+        renderer.keyInput.once("keypress", (event) => {
+          key = event
+        })
+
+        yield* execute(harness, { type: "ui.press", key: "escape" })
+
+        expect(key).toMatchObject({ name: "escape", source: "kitty" })
+      }),
+    ),
+  )
+})
+
 test("clicks a target at relative coordinates through descendant text", async () => {
   await Effect.runPromise(
     Effect.scoped(