|
| 1 | +import sys |
| 2 | +from pathlib import Path |
| 3 | + |
| 4 | + |
| 5 | +ROOT = Path(__file__).resolve().parents[2] |
| 6 | +CLI_SRC = ROOT.parent / 'pyinkcli' / 'src' |
| 7 | +UI_SRC = ROOT / 'src' |
| 8 | + |
| 9 | +for candidate in (str(CLI_SRC), str(UI_SRC)): |
| 10 | + if candidate not in sys.path: |
| 11 | + sys.path.insert(0, candidate) |
| 12 | + |
| 13 | +from pyinkcli import Box, Text, render |
| 14 | +from pyinkui import Select |
| 15 | +from pyinkcli.hooks import useState |
| 16 | + |
| 17 | + |
| 18 | +def App(): |
| 19 | + value, setValue = useState('') |
| 20 | + return Box( |
| 21 | + Select( |
| 22 | + options=[ |
| 23 | + {'label': 'Red', 'value': 'red'}, |
| 24 | + {'label': 'Green', 'value': 'green'}, |
| 25 | + {'label': 'Yellow', 'value': 'yellow'}, |
| 26 | + {'label': 'Blue', 'value': 'blue'}, |
| 27 | + {'label': 'Magenta', 'value': 'magenta'}, |
| 28 | + {'label': 'Cyan', 'value': 'cyan'}, |
| 29 | + {'label': 'White', 'value': 'white'}, |
| 30 | + ], |
| 31 | + onChange=setValue, |
| 32 | + ), |
| 33 | + Text(f'Selected value: {value}'), |
| 34 | + flexDirection='column', |
| 35 | + padding=2, |
| 36 | + gap=1, |
| 37 | + ) |
| 38 | + |
| 39 | + |
| 40 | +if __name__ == '__main__': |
| 41 | + render(App, interactive=True).wait_until_exit() |
0 commit comments