Skip to content

Commit a39dac9

Browse files
committed
Adapt pyinkui to pyinkcli 0.1.3, fix interactive rendering, and align examples/tests
1 parent a740f35 commit a39dac9

56 files changed

Lines changed: 1221 additions & 200 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

examples/alert.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@ def App():
88
Alert('Your license is expired', variant='error'),
99
Alert('Current version of this CLI has been deprecated', variant='warning'),
1010
Alert("API won't be available tomorrow night", variant='info'),
11-
flex_direction='column',
11+
flexDirection='column',
12+
alignItems='stretch',
1213
padding=2,
1314
width=60,
1415
gap=1,
1516
)
1617

1718

1819
if __name__ == '__main__':
19-
render(App).wait_until_exit()
20+
render(App, interactive=True).wait_until_exit()

examples/autocomplete.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ def App():
3333
onChange=setValue,
3434
visibleOptionCount=5,
3535
),
36-
flex_direction='column',
36+
flexDirection='column',
3737
gap=1,
3838
)
3939
else:
4040
return Text(f"You've selected {value}")
4141

4242

4343
if __name__ == '__main__':
44-
render(App).wait_until_exit()
44+
render(App, interactive=True).wait_until_exit()

examples/badge.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ def App():
1414

1515

1616
if __name__ == '__main__':
17-
render(App).wait_until_exit()
17+
render(App, interactive=True).wait_until_exit()

examples/confirm-input.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ def App():
2222

2323

2424
if __name__ == '__main__':
25-
render(App).wait_until_exit()
25+
render(App, interactive=True).wait_until_exit()

examples/email-input.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ def App():
88
return Box(
99
EmailInput(placeholder='Enter email...', onChange=setValue),
1010
Text(f'Input value: "{value}"'),
11-
flex_direction='column',
11+
flexDirection='column',
1212
padding=2,
1313
gap=1,
1414
)
1515

1616

1717
if __name__ == '__main__':
18-
render(App).wait_until_exit()
18+
render(App, interactive=True).wait_until_exit()

examples/multi-select.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ def App():
1919
onChange=setValue,
2020
),
2121
Text(f"Selected values: {', '.join(value)}"),
22-
flex_direction='column',
22+
flexDirection='column',
2323
padding=2,
2424
gap=1,
2525
)
2626

2727

2828
if __name__ == '__main__':
29-
render(App).wait_until_exit()
29+
render(App, interactive=True).wait_until_exit()

examples/ordered-list.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ def App():
2020

2121

2222
if __name__ == '__main__':
23-
render(App).wait_until_exit()
23+
render(App, interactive=True).wait_until_exit()

examples/password-input.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ def App():
88
return Box(
99
PasswordInput(placeholder='Enter password...', onChange=setValue),
1010
Text(f'Input value: "{value}"'),
11-
flex_direction='column',
11+
flexDirection='column',
1212
padding=2,
1313
gap=1,
1414
)
1515

1616

1717
if __name__ == '__main__':
18-
render(App).wait_until_exit()
18+
render(App, interactive=True).wait_until_exit()

examples/progress-bar.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,23 @@
11
import threading
22

3-
from pyinkcli import Box, render
3+
from pyinkcli import Box, Text, render
44
from pyinkcli.hooks import useEffect, useState
5-
from pyinkui import ProgressBar
5+
from pyinkui import useComponentTheme
6+
7+
8+
def InlineProgressBar(*, value, width):
9+
theme = useComponentTheme('ProgressBar')
10+
styles = theme['styles']
11+
config = theme['config']
12+
progress = min(100, max(0, value))
13+
complete = round((progress / 100) * width)
14+
remaining = width - complete
15+
children = []
16+
if complete > 0:
17+
children.append(Text(config()['completedCharacter'] * complete, **styles['completed']()))
18+
if remaining > 0:
19+
children.append(Text(config()['remainingCharacter'] * remaining, **styles['remaining']()))
20+
return Box(*children)
621

722

823
def Example():
@@ -22,8 +37,8 @@ def cleanup():
2237
return cleanup
2338

2439
useEffect(effect, (progress,))
25-
return Box(ProgressBar(value=progress), padding=2, width=30)
40+
return Box(InlineProgressBar(value=progress, width=26), padding=2, width=30)
2641

2742

2843
if __name__ == '__main__':
29-
render(Example).wait_until_exit()
44+
render(Example, interactive=True).wait_until_exit()

examples/select/index.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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

Comments
 (0)