Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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). */
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
10 changes: 9 additions & 1 deletion tests/editor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
};
}
Expand Down
Loading