diff --git a/lib/editor.ts b/lib/editor.ts index 17d3f68..64f3931 100644 --- a/lib/editor.ts +++ b/lib/editor.ts @@ -82,10 +82,14 @@ export class CursorEditor extends CustomEditor { } } - /** Write a raw escape sequence to the terminal (via pi-tui's TUI.terminal.write). */ + /** Write a raw escape sequence to the terminal (via pi-tui's TUI.terminal.write). + * Must call write as a METHOD (t.terminal.write(seq)) so `this` is the Terminal + * instance — detaching the fn reference loses `this` (Terminal.write reads + * this.writeLogPath) and throws. */ private writeTerm(seq: string): void { const t = this.tui as any; - (t?.terminal?.write ?? t?.write)?.(seq); + if (t?.terminal?.write) t.terminal.write(seq); + else if (t?.write) t.write(seq); } /** Restore the terminal's default cursor (call on session_shutdown). */ diff --git a/package.json b/package.json index 980386a..c5738e2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@getpipher/cursor", - "version": "0.2.0", + "version": "0.2.1", "description": "Focus-aware, customizable editor cursor for the pi coding agent (truecolor + Ghostty/tmux deep; tmux + cmux + herdr; static fallback).", "keywords": [ "pi-package", diff --git a/tests/editor.test.ts b/tests/editor.test.ts index ebfcbaa..cb71c80 100644 --- a/tests/editor.test.ts +++ b/tests/editor.test.ts @@ -89,13 +89,21 @@ test("setFocus(true) twice is a no-op (no redundant renders)", () => { function mockTui() { const writes: string[] = []; const hw: boolean[] = []; + // NOTE: `write` is a regular function (not an arrow) so it depends on `this` + // being the terminal object — mirroring the real pi-tui Terminal.write which + // reads this.writeLogPath. This catches the function-detachment bug where + // `(t.terminal.write)(seq)` loses `this` → throws. + const terminal = { + writes, + write(s: string) { this.writes.push(s); }, + }; return { writes, hw, tui: { setShowHardwareCursor(v: boolean) { hw.push(v); }, requestRender() {}, - terminal: { write(s: string) { writes.push(s); } }, + terminal, }, }; }