fix: add suppressBufferDetection, comprehensive docs and tests

Second deep audit comparing all 43 integration points in Claudeman's
app.js against the library API found one critical gap:

- Add suppressBufferDetection() — needed when switching to sessions
  with UI framework text (Ink) after the prompt that would be falsely
  detected. Claudeman sets _bufferDetectDone=true externally; this
  method provides the public equivalent.

Tests: 74 total (+13 new)
- Tab-switch save/restore pattern (flushed state roundtrip)
- suppressBufferDetection blocks explicit, implicit (addChar), and
  cascade (removeChar) detection paths
- clear() resets suppression
- Methods safe before activate() and after dispose()
- addChar implicit buffer detection on first keystroke
- refreshFont with flushed-only text

README: rewritten from 207 to 459 lines with:
- removeChar cascade explanation with return value table
- Flushed text concept explained
- Integration patterns: buffered, char-at-a-time, tab switching,
  tab completion, Ink/TUI frameworks, SSE reconnect, resize, font
- Architecture diagram (keypress → DOM overlay → PTY echo flow)
- Prompt column locking, text wrapping, render cache, scroll awareness
- All known limitations documented

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
arkon
2026-02-22 10:44:41 +01:00
co-authored by Claude Opus 4.6
parent 53132e3a38
commit ce188e6279
3 changed files with 432 additions and 50 deletions
@@ -347,6 +347,20 @@ export class ZerolagInputAddon implements XtermAddon {
this._bufferDetectDone = false;
}
/**
* Suppress buffer detection until the next `clear()` or
* `resetBufferDetection()` call.
*
* Use case: When switching to a session whose buffer contains UI
* framework text (e.g., Ink status bars) after the prompt marker,
* `detectBufferText()` would falsely pick up that text as user input.
* Call this after switching to prevent false detection until the user
* actually presses Enter (which calls `clear()` and re-enables detection).
*/
suppressBufferDetection(): void {
this._bufferDetectDone = true;
}
// ─── Prompt utilities ─────────────────────────────────────────────
/**