commit-commander-ai
Version:
A powerful CLI tool that helps developers create professional and meaningful Git commits with intelligent suggestions and conventional commit standards
60 lines • 2.15 kB
JavaScript
import * as readline from 'readline';
export async function askQuestion(question) {
return new Promise((resolve) => {
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
rl.question(question, (answer) => {
rl.close();
resolve(answer);
});
});
}
export function selectFromList({ question, options, message, }) {
return new Promise((resolve) => {
let selectedIndex = 0;
// Enable raw mode to capture arrow keys
process.stdin.setRawMode(true);
process.stdin.resume();
process.stdin.setEncoding('utf8');
function displayMenu() {
console.clear();
console.log(question);
console.log('Use ↑↓ arrows to navigate, Enter to select:\n');
options.forEach((option, index) => {
if (index === selectedIndex) {
console.log(`> ${option} <`);
}
else {
console.log(` ${option}`);
}
});
}
function onKeyPress(key) {
switch (key) {
case '\u001b[A': // Up arrow
selectedIndex = Math.max(0, selectedIndex - 1);
displayMenu();
break;
case '\u001b[B': // Down arrow
selectedIndex = Math.min(options.length - 1, selectedIndex + 1);
displayMenu();
break;
case '\r': // Enter key
process.stdin.setRawMode(false);
process.stdin.removeListener('data', onKeyPress);
process.stdin.resume();
console.log(`\nSelected: ${options[selectedIndex]}\n`);
resolve(options[selectedIndex]);
break;
case '\u0003': // Ctrl+C
process.exit();
break;
}
}
process.stdin.on('data', onKeyPress);
displayMenu();
});
}
//# sourceMappingURL=ask.js.map