const activeCompleteStepChar = "1"; const stepChar = "0"; const barCompletedChar = "━"; const barChar = "━"; export const displayStepper = (steps: string[], completed: number | null = null, pad: number = 8) => { const max = maxLength(steps) + pad; let bar = ''; steps.forEach((_, index) => { const isCompletedStep = index <= completed; if (isCompletedStep) { bar += activeCompleteStepChar; } else { bar += stepChar; } if (index < steps.length - 1) { if (isCompletedStep) { bar += barCompletedChar.repeat(max); } else { bar += barChar.repeat(max); } } }); let text = ''; steps.forEach((step, index) => { let pad = 0; if (index < steps.length - 1) { if (index === 0) { pad = max - step.length - Math.floor(steps[index].length / 2) + 1; } else { pad = max - Math.floor(step.length / 2) - Math.floor(steps[index].length / 2) + Math.floor(index/2); } } text += step; text += " ".repeat(pad); }); text += '\n'; console.log(bar); console.log(text); } export const maxLength = (data: string[]) => { let max = 0; for (const d of data) { if (d.length > max) { max = d.length; } } return max; }