MCPcopy Create free account
hub / github.com/Noumena-Network/code / waitForText

Function waitForText

src/testing/replContractHarness.ts:180–201  ·  view source on GitHub ↗
(
  readText: () => string,
  predicate: (text: string) => boolean,
  options?: {
    readonly timeoutMs?: number
    readonly label?: string
  },
)

Source from the content-addressed store, hash-verified

178}
179
180export async function waitForText(
181 readText: () => string,
182 predicate: (text: string) => boolean,
183 options?: {
184 readonly timeoutMs?: number
185 readonly label?: string
186 },
187): Promise<string> {
188 const deadline = Date.now() + (options?.timeoutMs ?? 4000)
189 let lastText = ''
190 while (Date.now() < deadline) {
191 lastText = readText()
192 if (predicate(lastText)) {
193 return lastText
194 }
195 await Bun.sleep(20)
196 }
197
198 throw new Error(
199 `Timed out waiting for ${options?.label ?? 'text condition'}. Last capture:\n${lastText}`,
200 )
201}
202
203export function getFrameByLabel<T extends { readonly label: string }>(
204 frames: readonly T[],

Callers 5

waitForReplTmuxPromptFunction · 0.85
waitForWrapperTmuxRowsFunction · 0.85
waitForMountedScreenTextFunction · 0.85

Calls 1

sleepMethod · 0.80

Tested by

no test coverage detected