UNPKG

emv

Version:

EMV / Chip and PIN CLI and library for PC/SC card readers

40 lines 2.23 kB
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; import { Box, Text, useInput } from 'ink'; import SelectInput from 'ink-select-input'; import { Header, Footer, CardBox, StatusBar, LoadingSpinner } from '../components/index.js'; import { SCARD_STATE_PRESENT } from '../types.js'; export function ReadersScreen({ readers, onSelect, onRefresh, loading, }) { useInput((input) => { if (input === 'r') { onRefresh(); } }); if (loading) { return (_jsxs(Box, { flexDirection: "column", children: [_jsx(Header, {}), _jsx(LoadingSpinner, { message: "Scanning for card readers..." })] })); } if (readers.length === 0) { return (_jsxs(Box, { flexDirection: "column", children: [_jsx(Header, {}), _jsx(StatusBar, { message: "No card readers found. Connect a reader and press 'r' to refresh.", type: "warning" }), _jsx(Footer, { hints: [ { keys: 'r', description: 'Refresh' }, { keys: 'q', description: 'Quit' }, ] })] })); } const items = readers.map((reader, index) => { const hasCard = (reader.state & SCARD_STATE_PRESENT) !== 0; const icon = hasCard ? '💳' : '📖'; const status = hasCard ? ' (card present)' : ''; return { key: `${reader.name}-${String(index)}`, label: `${icon} ${reader.name}${status}`, value: reader, }; }); return (_jsxs(Box, { flexDirection: "column", children: [_jsx(Header, {}), _jsx(CardBox, { title: "Select a Card Reader", children: _jsx(SelectInput, { items: items, onSelect: (item) => { onSelect(item.value); }, itemComponent: ({ isSelected, label }) => isSelected ? (_jsxs(Text, { color: "cyan", bold: true, children: ['▸ ', label] })) : (_jsxs(Text, { children: [' ', label] })) }) }), _jsx(Footer, { hints: [ { keys: '↑↓', description: 'Navigate' }, { keys: 'Enter', description: 'Select' }, { keys: 'r', description: 'Refresh' }, { keys: 'q', description: 'Quit' }, ] })] })); } //# sourceMappingURL=ReadersScreen.js.map