Something went wrong. Try again.
A card-based stepper container for @clack/prompts with back-navigation, async steps, and conditional flow. npmx.dev/package/clack-stepper
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546import type { Writable } from 'node:stream'import { styleText } from 'node:util'import type { ActiveStep } from './stepper.ts'
/** * Render the breadcrumb header into the card region. * * Completed steps show their label and answer in green. * The current step is highlighted in cyan. * Future steps are dimmed. */export function renderHeader( output: Writable, steps: ActiveStep[], currentIndex: number, answers: Record<string, unknown>,): void { const separator = styleText('dim', ' > ')
const crumbs = steps.map((step, i) => { if (i < currentIndex) { const value = formatValue(answers[step.key]) return styleText('green', `${step.label}: ${value}`) } if (i === currentIndex) { return styleText('cyan', step.label) } return styleText('dim', step.label) })
const stepCount = styleText( 'dim', `Step ${currentIndex + 1} of ${steps.length}`, ) const breadcrumb = crumbs.join(separator)
output.write(`${stepCount}\n${breadcrumb}\n\n`)}
function formatValue(value: unknown): string { if (value === undefined || value === null) return '' if (typeof value === 'boolean') return value ? 'yes' : 'no' const str = String(value) return str.length > 20 ? `${str.slice(0, 20)}...` : str}