@shutootaki/gwm
Version:
git worktree manager CLI
40 lines • 2.36 kB
JavaScript
import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
import { useState } from 'react';
import { Box, Text, useInput } from 'ink';
const OPTIONS = [
{ label: 'Trust & Run', value: 'trust', color: 'green' },
{ label: 'Run Once', value: 'once', color: 'yellow' },
{ label: 'Cancel', value: 'cancel', color: 'red' },
];
/**
* Hooks execution confirmation prompt
*/
export const HookConfirmation = ({ reason, commands, onChoice, }) => {
const [selectedIndex, setSelectedIndex] = useState(0);
useInput((input, key) => {
if (key.return) {
onChoice(OPTIONS[selectedIndex].value);
return;
}
// Number keys: direct selection
const num = Number(input);
if (num >= 1 && num <= OPTIONS.length) {
setSelectedIndex(num - 1);
return;
}
// Navigation
const delta = (key.tab && key.shift) || key.leftArrow || input === 'h'
? -1
: (key.tab && !key.shift) || key.rightArrow || input === 'l'
? 1
: 0;
if (delta) {
setSelectedIndex((prev) => Math.max(0, Math.min(OPTIONS.length - 1, prev + delta)));
}
});
const title = reason === 'first-time'
? 'This repository has post_create hooks configured'
: 'Project config has changed (re-confirm hooks)';
return (_jsxs(Box, { flexDirection: "column", borderStyle: "single", borderColor: "yellow", paddingX: 1, paddingY: 1, children: [_jsx(Box, { marginBottom: 1, children: _jsxs(Text, { color: "yellow", bold: true, children: ['⚠ ', title] }) }), _jsxs(Box, { flexDirection: "column", marginBottom: 1, children: [_jsx(Text, { color: "gray", children: "Commands to be executed:" }), commands.map((cmd, i) => (_jsxs(Text, { color: "white", children: [' ', i + 1, ". ", cmd] }, i)))] }), _jsx(Box, { marginTop: 1, children: OPTIONS.map((opt, i) => (_jsx(Box, { marginRight: 2, children: _jsxs(Text, { color: selectedIndex === i ? opt.color : 'gray', bold: selectedIndex === i, inverse: selectedIndex === i, children: ["[", i + 1, "] ", opt.label] }) }, opt.value))) }), _jsx(Box, { marginTop: 1, children: _jsx(Text, { color: "gray", dimColor: true, children: "Tab/\u2190/\u2192 or 1/2/3 to select \u2022 Enter to confirm" }) })] }));
};
//# sourceMappingURL=HookConfirmation.js.map