(items: BumpSelectItem[])
| 38 | * its anchor once content scrolls off-screen. |
| 39 | */ |
| 40 | export async function bumpSelectPrompt(items: BumpSelectItem[]): Promise<BumpSelectResult[] | symbol> { |
| 41 | // Build display order: changed first, then unchanged |
| 42 | const changedEntries = items.map((item, idx) => ({ item, idx })).filter(({ item }) => item.changed); |
| 43 | const unchangedEntries = items.map((item, idx) => ({ item, idx })).filter(({ item }) => !item.changed); |
| 44 | const displayOrder = [...changedEntries, ...unchangedEntries]; |
| 45 | |
| 46 | // Build a flat list of rows (headers, separators, items) — static structure used for windowing. |
| 47 | const rows: Row[] = []; |
| 48 | const itemRowIndex: number[] = []; // displayIdx -> index into rows |
| 49 | { |
| 50 | let displayIdx = 0; |
| 51 | if (changedEntries.length > 0) { |
| 52 | rows.push({ kind: 'header', text: 'Changed' }); |
| 53 | for (const { idx } of changedEntries) { |
| 54 | itemRowIndex.push(rows.length); |
| 55 | rows.push({ kind: 'item', itemIdx: idx, displayIdx }); |
| 56 | displayIdx++; |
| 57 | } |
| 58 | if (unchangedEntries.length > 0) { |
| 59 | rows.push({ kind: 'separator' }); |
| 60 | } |
| 61 | } |
| 62 | if (unchangedEntries.length > 0) { |
| 63 | rows.push({ kind: 'header', text: 'Unchanged' }); |
| 64 | for (const { idx } of unchangedEntries) { |
| 65 | itemRowIndex.push(rows.length); |
| 66 | rows.push({ kind: 'item', itemIdx: idx, displayIdx }); |
| 67 | displayIdx++; |
| 68 | } |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | // State |
| 73 | let cursor = 0; |
| 74 | let scroll = 0; |
| 75 | const levels: BumpLevel[] = items.map((item) => |
| 76 | item.initialLevel !== undefined ? item.initialLevel : item.changed ? 'patch' : 'skip', |
| 77 | ); |
| 78 | |
| 79 | return new Promise<BumpSelectResult[] | symbol>((resolve) => { |
| 80 | const { stdin, stdout } = process; |
| 81 | const rl = readline.createInterface({ input: stdin, terminal: true }); |
| 82 | |
| 83 | // Hide cursor |
| 84 | stdout.write('\x1B[?25l'); |
| 85 | |
| 86 | let renderedLines = 0; |
| 87 | |
| 88 | function render(final = false) { |
| 89 | // Clear previous render |
| 90 | if (renderedLines > 0) { |
| 91 | stdout.write(`\x1B[${renderedLines}A`); // Move up |
| 92 | stdout.write('\x1B[0J'); // Clear from cursor to end |
| 93 | } |
| 94 | |
| 95 | const lines: string[] = []; |
| 96 | |
| 97 | if (final) { |
no test coverage detected
searching dependent graphs…