| 1 | // @effect-diagnostics globalDate:off - Vendored @clo/lib has no Effect dependency. |
| 2 | import type { ReadOnlyNode } from "./progress.ts"; |
| 3 | |
| 4 | export function isVisible(node: ReadOnlyNode): boolean { |
| 5 | return !node.hidden && (!node.passive || node.children.some(isVisible)); |
| 6 | } |
| 7 | |
| 8 | export function remainingSeconds(node: ReadOnlyNode): number | null { |
| 9 | const { estimatedTime } = node; |
| 10 | if (!estimatedTime) return null; |
| 11 | const ms = estimatedTime - Date.now(); |
| 12 | return ms > 1000 && !findLongerEstimate(node, estimatedTime) ? Math.round(ms / 1000) : null; |
| 13 | } |
| 14 | |
| 15 | function findLongerEstimate(state: ReadOnlyNode, estimatedTime: number): boolean { |
| 16 | return state.children.some( |
| 17 | (child) => |
| 18 | isVisible(child) && |
| 19 | ((child.estimatedTime ?? 0) > estimatedTime || findLongerEstimate(child, estimatedTime)), |
| 20 | ); |
| 21 | } |
| 22 | |
| 23 | export const maxLogLines = 3; |