()
| 55 | } |
| 56 | |
| 57 | function run() { |
| 58 | console.log('\n\x1b[1mSelect dev mode:\x1b[0m (↑↓ to move, Enter to confirm)\n') |
| 59 | for (let i = 0; i < options.length; i++) process.stdout.write('\n') |
| 60 | render() |
| 61 | |
| 62 | process.stdin.setRawMode(true) |
| 63 | process.stdin.resume() |
| 64 | process.stdin.setEncoding('utf8') |
| 65 | |
| 66 | process.stdin.on('data', (key) => { |
| 67 | if (key === '\x1b[A') { |
| 68 | selected = (selected - 1 + options.length) % options.length |
| 69 | render() |
| 70 | } else if (key === '\x1b[B') { |
| 71 | selected = (selected + 1) % options.length |
| 72 | render() |
| 73 | } else if (key === '\r' || key === '\n') { |
| 74 | process.stdin.setRawMode(false) |
| 75 | process.stdin.pause() |
| 76 | const choice = options[selected] |
| 77 | saveChoice(choice.key) |
| 78 | console.log(`\n\x1b[32m▶\x1b[0m Running: ${choice.command}\n`) |
| 79 | try { |
| 80 | execSync(choice.command, { stdio: 'inherit' }) |
| 81 | } catch { |
| 82 | process.exit(1) |
| 83 | } |
| 84 | } else if (key === '\x03') { |
| 85 | process.stdin.setRawMode(false) |
| 86 | console.log() |
| 87 | process.exit(0) |
| 88 | } |
| 89 | }) |
| 90 | } |
| 91 | |
| 92 | run() |
no test coverage detected