-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.jsx
50 lines (42 loc) · 1.12 KB
/
index.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import * as readline from 'node:readline';
import React, { useState, useEffect } from 'react';
import { Box, render, Text, useFocus, useFocusManager, useInput } from 'ink';
readline.emitKeypressEvents(process.stdin);
process.stdin.on('keypress', function (str, key) {
if (key && key.name === 'q') {
process.stdin.pause();
}
});
process.stdin.setRawMode(true);
function Item(props) {
const { id, label } = props;
const { isFocused } = useFocus({ id });
return (
<Text inverse={isFocused}>{label}</Text>
);
}
function App() {
const { focus } = useFocusManager();
useInput((input) => {
switch (input) {
case '1':
focus('item-1');
break;
case '2':
focus('item-2');
break;
case '3':
focus('item-3');
break;
}
});
return (
<Box width="100%" height="100%" flexDirection="column">
<Text>Press 1, 2 or 3 to focus an item. Press Tab to focus next item. Press q to exit.</Text>
<Item id="item-1" label="Item 1" />
<Item id="item-2" label="Item 2" />
<Item id="item-3" label="Item 3" />
</Box>
);
}
render(<App />);