| 1524 | } |
| 1525 | |
| 1526 | const runWithInput = <Output>( |
| 1527 | prompt: Prompt<Output>, |
| 1528 | terminal: Terminal.Terminal, |
| 1529 | input: Terminal.Terminal["readInput"] |
| 1530 | ): Effect.Effect<Output, NoSuchElementError, Environment | Scope.Scope> => |
| 1531 | Effect.suspend(() => { |
| 1532 | const op = prompt as PromptPrimitive |
| 1533 | switch (op._tag) { |
| 1534 | case "Loop": { |
| 1535 | return Effect.flatMap(input, (queue) => runLoop(op, terminal, queue)) |
| 1536 | } |
| 1537 | case "OnSuccess": { |
| 1538 | return Effect.flatMap( |
| 1539 | runWithInput(op.prompt, terminal, input), |
| 1540 | (a) => runWithInput(op.onSuccess(a), terminal, input) |
| 1541 | ) as any |
| 1542 | } |
| 1543 | case "Succeed": { |
| 1544 | return Effect.succeed(op.value) |
| 1545 | } |
| 1546 | } |
| 1547 | }) |
| 1548 | |
| 1549 | const runLoop = Effect.fnUntraced( |
| 1550 | function*( |