( text: string, colors: readonly [string, ...string[]], offset = 0, bold = false, )
| 50 | |
| 51 | /** Paint a string character-by-character through a palette, skipping spaces. */ |
| 52 | export function rainbowText( |
| 53 | text: string, |
| 54 | colors: readonly [string, ...string[]], |
| 55 | offset = 0, |
| 56 | bold = false, |
| 57 | ): string { |
| 58 | let colorIndex = offset; |
| 59 | return Array.from(text) |
| 60 | .map((char) => { |
| 61 | if (char === ' ') return char; |
| 62 | const color = colors[colorIndex % colors.length] ?? colors[0]; |
| 63 | colorIndex++; |
| 64 | const style = chalk.hex(color); |
| 65 | return bold ? style.bold(char) : style(char); |
| 66 | }) |
| 67 | .join(''); |
| 68 | } |
| 69 | |
| 70 | /** Read-only view of the dance state for components that only render it. */ |
| 71 | export interface RainbowDanceView { |
no test coverage detected