| 54 | } |
| 55 | |
| 56 | function wrapLines(text: string, width: number): string[] { |
| 57 | // Soft-wrap a single descriptive paragraph at word boundaries. We |
| 58 | // only wrap plain text — the command name in the left column |
| 59 | // doesn't get wrapped. |
| 60 | if (text.length <= width) return [text] |
| 61 | const words = text.split(/\s+/) |
| 62 | const lines: string[] = [] |
| 63 | let current = '' |
| 64 | for (const word of words) { |
| 65 | if (!current) { |
| 66 | current = word |
| 67 | continue |
| 68 | } |
| 69 | if ((current + ' ' + word).length > width) { |
| 70 | lines.push(current) |
| 71 | current = word |
| 72 | } else { |
| 73 | current += ' ' + word |
| 74 | } |
| 75 | } |
| 76 | if (current) lines.push(current) |
| 77 | return lines |
| 78 | } |
| 79 | |
| 80 | interface CommandRow { |
| 81 | /** Left column, e.g. `list <flags>` or `read <path>`. */ |