From 165fb58b398cb5b63b11cfe8bb4b60b2b876b4e4 Mon Sep 17 00:00:00 2001 From: Mario Zechner Date: Sat, 27 Dec 2025 03:20:10 +0100 Subject: [PATCH] Fix snake.ts: use key helpers from pi-tui for ESC and arrow keys --- packages/coding-agent/examples/hooks/snake.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/packages/coding-agent/examples/hooks/snake.ts b/packages/coding-agent/examples/hooks/snake.ts index 05013e94..4dffef53 100644 --- a/packages/coding-agent/examples/hooks/snake.ts +++ b/packages/coding-agent/examples/hooks/snake.ts @@ -2,6 +2,7 @@ * Snake game hook - play snake with /snake command */ +import { isArrowDown, isArrowLeft, isArrowRight, isArrowUp, isEscape } from "@mariozechner/pi-tui"; import type { HookAPI } from "../../src/core/hooks/types.js"; const GAME_WIDTH = 40; @@ -129,20 +130,20 @@ class SnakeComponent { handleInput(data: string): void { // ESC or q to quit - if (data === "\x1b" || data === "q" || data === "Q") { + if (isEscape(data) || data === "q" || data === "Q") { this.dispose(); this.onClose(); return; } - // Arrow keys - if (data === "\x1b[A" || data === "w" || data === "W") { + // Arrow keys or WASD + if (isArrowUp(data) || data === "w" || data === "W") { if (this.state.direction !== "down") this.state.nextDirection = "up"; - } else if (data === "\x1b[B" || data === "s" || data === "S") { + } else if (isArrowDown(data) || data === "s" || data === "S") { if (this.state.direction !== "up") this.state.nextDirection = "down"; - } else if (data === "\x1b[C" || data === "d" || data === "D") { + } else if (isArrowRight(data) || data === "d" || data === "D") { if (this.state.direction !== "left") this.state.nextDirection = "right"; - } else if (data === "\x1b[D" || data === "a" || data === "A") { + } else if (isArrowLeft(data) || data === "a" || data === "A") { if (this.state.direction !== "right") this.state.nextDirection = "left"; }