* Append PTY output to the buffer. * Uses 'binary' (latin1) encoding to preserve raw byte values from node-pty.
(data: string)
| 19 | * Uses 'binary' (latin1) encoding to preserve raw byte values from node-pty. |
| 20 | */ |
| 21 | write(data: string): void { |
| 22 | const src = Buffer.from(data, "binary"); |
| 23 | const len = src.length; |
| 24 | if (len === 0) return; |
| 25 | |
| 26 | if (len >= this.capacity) { |
| 27 | // Incoming chunk larger than the whole buffer — keep only the tail |
| 28 | src.copy(this.buf, 0, len - this.capacity); |
| 29 | this.writePos = 0; |
| 30 | this.stored = this.capacity; |
| 31 | return; |
| 32 | } |
| 33 | |
| 34 | const end = this.writePos + len; |
| 35 | if (end <= this.capacity) { |
| 36 | src.copy(this.buf, this.writePos); |
| 37 | } else { |
| 38 | // Wrap around the ring boundary |
| 39 | const tailLen = this.capacity - this.writePos; |
| 40 | src.copy(this.buf, this.writePos, 0, tailLen); |
| 41 | src.copy(this.buf, 0, tailLen); |
| 42 | } |
| 43 | this.writePos = end % this.capacity; |
| 44 | this.stored = Math.min(this.stored + len, this.capacity); |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Returns all buffered bytes in chronological order (oldest first). |
nothing calls this directly
no outgoing calls
no test coverage detected