| 33 | const size = Math.max(1, userSize); |
| 34 | |
| 35 | const activeStyle = (state: State) => { |
| 36 | switch (state) { |
| 37 | case 'initial': |
| 38 | case 'active': |
| 39 | return (text: string) => styleText('magenta', text); |
| 40 | case 'error': |
| 41 | case 'cancel': |
| 42 | return (text: string) => styleText('red', text); |
| 43 | case 'submit': |
| 44 | return (text: string) => styleText('green', text); |
| 45 | default: |
| 46 | return (text: string) => styleText('magenta', text); |
| 47 | } |
| 48 | }; |
| 49 | const drawProgress = (state: State, msg: string) => { |
| 50 | const active = Math.floor((value / max) * size); |
| 51 | return `${activeStyle(state)(S_PROGRESS_CHAR[style].repeat(active))}${styleText('dim', S_PROGRESS_CHAR[style].repeat(size - active))} ${msg}`; |