* Read pending responses from the terminal. * Returns the response string, or null if no responses pending. * * Responses are generated by escape sequences that require replies: * - DSR 6 (cursor position): Returns \x1b[row;colR * - DSR 5 (operating status): Returns \x1b[0n
()
| 627 | * - DSR 5 (operating status): Returns \x1b[0n |
| 628 | */ |
| 629 | readResponse(): string | null { |
| 630 | if (!this.hasResponse()) return null; |
| 631 | |
| 632 | const bufSize = 256; // Most responses are small |
| 633 | const bufPtr = this.exports.ghostty_wasm_alloc_u8_array(bufSize); |
| 634 | |
| 635 | try { |
| 636 | const bytesRead = this.exports.ghostty_terminal_read_response(this.handle, bufPtr, bufSize); |
| 637 | |
| 638 | if (bytesRead <= 0) return null; |
| 639 | |
| 640 | const bytes = new Uint8Array(this.memory.buffer, bufPtr, bytesRead); |
| 641 | return new TextDecoder().decode(bytes.slice()); |
| 642 | } finally { |
| 643 | this.exports.ghostty_wasm_free_u8_array(bufPtr, bufSize); |
| 644 | } |
| 645 | } |
| 646 | |
| 647 | /** |
| 648 | * Query arbitrary terminal mode by number |
no test coverage detected