aboutsummaryrefslogtreecommitdiffstats
path: root/examples/minimal.py
blob: b7e02e2a8b4c3201299bd48b64b9e2ab4632123a (plain) (blame)
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
#!/usr/bin/env python3
"""
Minimal example of using selectui as a library.
"""

import os
import sys

sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', 'src'))

from selectui import SelectUI

items = [
    {"title": "Apple", "subtitle": "A red fruit"},
    {"title": "Banana", "subtitle": "A yellow fruit"},
    {"title": "Cherry", "subtitle": "A small red fruit"},
    {"title": "Date", "subtitle": "A sweet brown fruit"},
    {"title": "Elderberry", "subtitle": "A dark purple berry"},
]

app = SelectUI(
    items=items,
    oneshot=True,
    title_key="title",
    subtitle_key="subtitle"
)

app.run()

if app.selected_item:
    print(f"\nYou selected: {app.selected_item['title']}", file=sys.stderr)
    print(f"Description: {app.selected_item['subtitle']}", file=sys.stderr)
else:
    print("\nNo selection made", file=sys.stderr)