* Wait for the CLI to be fully initialized and ready for input. * Polls terminal output until enough non-empty lines are visible, * indicating the TUI has rendered its initial layout.
(timeoutMs = 30_000, minLines = 5)
| 117 | * indicating the TUI has rendered its initial layout. |
| 118 | */ |
| 119 | async waitForReady(timeoutMs = 30_000, minLines = 5): Promise<void> { |
| 120 | const start = Date.now() |
| 121 | while (Date.now() - start < timeoutMs) { |
| 122 | const output = await this.capture() |
| 123 | const nonEmptyLines = output |
| 124 | .split('\n') |
| 125 | .filter((line) => line.trim().length > 0) |
| 126 | if (nonEmptyLines.length >= minLines) return |
| 127 | await new Promise((resolve) => setTimeout(resolve, 250)) |
| 128 | } |
| 129 | const finalOutput = await this.capture() |
| 130 | throw new Error( |
| 131 | `Timed out after ${timeoutMs}ms waiting for CLI to be ready.\n` + |
| 132 | `Last output:\n${finalOutput}`, |
| 133 | ) |
| 134 | } |
| 135 | |
| 136 | /** Send text input to the freebuff CLI (presses Enter by default). */ |
| 137 | async send( |
no test coverage detected