richui 0.0.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- richui-0.0.1/PKG-INFO +267 -0
- richui-0.0.1/README.md +247 -0
- richui-0.0.1/pyproject.toml +27 -0
- richui-0.0.1/richui/__init__.py +3 -0
- richui-0.0.1/richui/config.py +29 -0
- richui-0.0.1/richui/example.py +264 -0
- richui-0.0.1/richui/richui.py +283 -0
- richui-0.0.1/richui/utils.py +332 -0
- richui-0.0.1/richui.egg-info/PKG-INFO +267 -0
- richui-0.0.1/richui.egg-info/SOURCES.txt +13 -0
- richui-0.0.1/richui.egg-info/dependency_links.txt +1 -0
- richui-0.0.1/richui.egg-info/requires.txt +1 -0
- richui-0.0.1/richui.egg-info/top_level.txt +1 -0
- richui-0.0.1/setup.cfg +4 -0
- richui-0.0.1/setup.py +21 -0
richui-0.0.1/PKG-INFO
ADDED
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: richui
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: An interactive command-line UI module built on top of Rich for customizable UI components.
|
|
5
|
+
Home-page: https://pypi.org/project/richui
|
|
6
|
+
Author: Moh Iqbal Hidayat
|
|
7
|
+
Author-email: Moh Iqbal Hidayat <iqbalmh18.dev@gmail.com>
|
|
8
|
+
Project-URL: Homepage, https://pypi.org/project/richui
|
|
9
|
+
Project-URL: Source, https://github.com/iqbalmh18/richui
|
|
10
|
+
Keywords: rich,richui,cli,UI,interactive,terminal
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Requires-Python: >=3.7
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
Requires-Dist: rich
|
|
17
|
+
Dynamic: author
|
|
18
|
+
Dynamic: home-page
|
|
19
|
+
Dynamic: requires-python
|
|
20
|
+
|
|
21
|
+
# Rich UI
|
|
22
|
+
|
|
23
|
+
**An interactive command-line UI module built on top of Rich for customizable UI components.**
|
|
24
|
+
|
|
25
|
+
Rich UI is a Python module that allows you to build interactive command-line interfaces with a modern, colorful, and fully customizable appearance. It leverages the power of [Rich](https://github.com/Textualize/rich) to provide features such as syntax-highlighted code displays, interactive tree and table views, input prompts with completion, and selection menus.
|
|
26
|
+
|
|
27
|
+
## Table of Contents
|
|
28
|
+
|
|
29
|
+
- [Features](#features)
|
|
30
|
+
- [Installation](#installation)
|
|
31
|
+
- [Quick Start](#quick-start)
|
|
32
|
+
- [Custom Configuration Example](#custom-configuration-example)
|
|
33
|
+
- [Tree View Example](#tree-view-example)
|
|
34
|
+
- [Table Example](#table-example)
|
|
35
|
+
- [Text Input Example](#text-input-example)
|
|
36
|
+
- [Secure Input (Password) Example](#secure-input-password-example)
|
|
37
|
+
- [Input with Completion (List) Example](#input-with-completion-list-example)
|
|
38
|
+
- [Input with Completion (Dictionary) Example](#input-with-completion-dictionary-example)
|
|
39
|
+
- [Single Select Example](#single-select-example)
|
|
40
|
+
- [Multi-Select Example](#multi-select-example)
|
|
41
|
+
- [Confirm Example](#confirm-example)
|
|
42
|
+
- [Running the Example](#running-the-example)
|
|
43
|
+
|
|
44
|
+
## Features
|
|
45
|
+
|
|
46
|
+
- **Interactive Components:** Includes tree views, tables, single and multi-select menus, secure input prompts, and confirm dialogs.
|
|
47
|
+
- **Custom Configuration:** Easily configure UI elements such as cursor style, prompt style, footer style, and more.
|
|
48
|
+
- **Syntax Highlighting:** Display text with syntax highlighting (support: rich markup, ansii colors, hex colors).
|
|
49
|
+
- **Completion Support:** Input fields with support for auto-completion from lists or dictionaries.
|
|
50
|
+
|
|
51
|
+
## Installation
|
|
52
|
+
|
|
53
|
+
Install **richui** with pip:
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
pip install richui
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Install **richui** from sources:
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
git clone https://github.com/iqbalmh18/richui
|
|
63
|
+
cd richui
|
|
64
|
+
pip3 install .
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Quick Start
|
|
68
|
+
|
|
69
|
+
import **Richui** and **Config** class
|
|
70
|
+
|
|
71
|
+
```python
|
|
72
|
+
from richui import Richui, Config
|
|
73
|
+
```
|
|
74
|
+
### Custom Configuration Example
|
|
75
|
+
|
|
76
|
+
This snippet defines a custom configuration for Richui, including styling options for various UI components.
|
|
77
|
+
|
|
78
|
+
```python
|
|
79
|
+
custom_config = Config(
|
|
80
|
+
cursor="➠",
|
|
81
|
+
bracket="(",
|
|
82
|
+
checkmark="●",
|
|
83
|
+
title_style="bold white on #f33581",
|
|
84
|
+
title_justify="center",
|
|
85
|
+
value_style="#f72fcb",
|
|
86
|
+
cursor_style="#40fab9",
|
|
87
|
+
prompt_style="bold #4afd86",
|
|
88
|
+
checkmark_style="#40fab9",
|
|
89
|
+
option_style="#ffffff",
|
|
90
|
+
selection_style="#fa9732",
|
|
91
|
+
selected_style="#25f38d",
|
|
92
|
+
footer_style="#707070",
|
|
93
|
+
guide_style="#65fc8e",
|
|
94
|
+
completion_style="white on #5efda9",
|
|
95
|
+
completion_second_style="italic #5efda9 on #3f3f3f",
|
|
96
|
+
text_width=50,
|
|
97
|
+
padding=(0, 2)
|
|
98
|
+
)
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
Set **custom_config** to Richui
|
|
102
|
+
|
|
103
|
+
```python
|
|
104
|
+
ui = Richui(custom_config)
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
*Description:* This example uses a custom configuration for Rich UI. The above snippet defines styling options for the UI components.
|
|
108
|
+
|
|
109
|
+
### Tree View Example
|
|
110
|
+
|
|
111
|
+
This snippet displays a tree view of nested data.
|
|
112
|
+
|
|
113
|
+
```python
|
|
114
|
+
tree_data = {
|
|
115
|
+
"Programming": {
|
|
116
|
+
"Language": {
|
|
117
|
+
"Python": [
|
|
118
|
+
"Hacking",
|
|
119
|
+
"Scraping"
|
|
120
|
+
],
|
|
121
|
+
"Bash": "Scripting"
|
|
122
|
+
},
|
|
123
|
+
"CodeEditor": {
|
|
124
|
+
"Nano": "Nano is a simple command-line text editor.",
|
|
125
|
+
"Acode": "Acode is a lightweight code editor for Android."
|
|
126
|
+
}
|
|
127
|
+
},
|
|
128
|
+
"Country": {
|
|
129
|
+
"ID": "Indonesia"
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
ui.tree(tree_data, title="Data", text_wrap=True)
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
*Description:* The code above displays a tree view of nested data using Rich UI.
|
|
136
|
+
|
|
137
|
+
### Table Example
|
|
138
|
+
|
|
139
|
+
This snippet creates a table to display key information about the Rich UI project.
|
|
140
|
+
|
|
141
|
+
```python
|
|
142
|
+
table_data = {
|
|
143
|
+
"Name": "Rich UI",
|
|
144
|
+
"Version": "1.0.0",
|
|
145
|
+
"Description": "A customizable command-line UI module built on top of the Rich library.",
|
|
146
|
+
"License": "MIT",
|
|
147
|
+
"Source": "https://github.com/iqbalmh18/Richui"
|
|
148
|
+
}
|
|
149
|
+
ui.table(table_data, title=" Rich UI ", text_wrap=True)
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
*Description:* The above snippet creates a table that displays key information about the Rich UI project.
|
|
153
|
+
|
|
154
|
+
### Text Input Example
|
|
155
|
+
|
|
156
|
+
This snippet shows a text input prompt where the user is asked to enter their name.
|
|
157
|
+
|
|
158
|
+
```python
|
|
159
|
+
name = ui.input("Enter your name:", prompt_style="#d75ff8", footer="<press enter to continue>")
|
|
160
|
+
print(f"Nice to meet you, {name}!")
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
*Description:* This snippet shows a text input prompt for the user's name.
|
|
164
|
+
|
|
165
|
+
### Secure Input (Password) Example
|
|
166
|
+
|
|
167
|
+
This snippet demonstrates a secure input prompt where the entered text is masked.
|
|
168
|
+
|
|
169
|
+
```python
|
|
170
|
+
password = ui.input("Enter your password:", prompt_style="#269def", footer="<secure input: enter to continue>", secure=True)
|
|
171
|
+
print("Your password:", password)
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
*Description:* The code above demonstrates a secure input prompt.
|
|
175
|
+
|
|
176
|
+
### Input with Completion (List) Example
|
|
177
|
+
|
|
178
|
+
This snippet allows the user to choose a fruit with tab-completion based on a predefined list.
|
|
179
|
+
|
|
180
|
+
```python
|
|
181
|
+
fruits_list = ["Apple", "Apricot", "Banana", "Blackberry", "Blueberry", "Cherry", "Date"]
|
|
182
|
+
fruit_input_list = ui.input(
|
|
183
|
+
"Enter a fruit:",
|
|
184
|
+
prompt_style="#60e282",
|
|
185
|
+
footer="<use tab to show completion>",
|
|
186
|
+
completion=fruits_list
|
|
187
|
+
)
|
|
188
|
+
print("Fruit chosen:", fruit_input_list)
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
*Description:* This snippet allows selection from a list with auto-completion.
|
|
192
|
+
|
|
193
|
+
### Input with Completion (Dictionary) Example
|
|
194
|
+
|
|
195
|
+
This snippet demonstrates an input prompt with completion using a dictionary, where the keys are used for matching.
|
|
196
|
+
|
|
197
|
+
```python
|
|
198
|
+
countries = {
|
|
199
|
+
"United States": "New York",
|
|
200
|
+
"Indonesian": "Jakarta",
|
|
201
|
+
"Germany": "Berlin",
|
|
202
|
+
"France": "Paris",
|
|
203
|
+
"Japan": "Tokyo"
|
|
204
|
+
}
|
|
205
|
+
country_input = ui.input(
|
|
206
|
+
"Enter a country:",
|
|
207
|
+
prompt_style="#f83d3d",
|
|
208
|
+
footer="<use tab to show completion>",
|
|
209
|
+
completion=countries,
|
|
210
|
+
completion_style="white on #f84a53",
|
|
211
|
+
completion_second_style="italic #f84a53 on #3f3f3f"
|
|
212
|
+
)
|
|
213
|
+
print("Country chosen:", country_input)
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
*Description:* This snippet demonstrates an input prompt with completion using a dictionary.
|
|
217
|
+
|
|
218
|
+
### Single Select Example
|
|
219
|
+
|
|
220
|
+
This snippet shows a single select menu where the user selects one programming language.
|
|
221
|
+
|
|
222
|
+
```python
|
|
223
|
+
language = ["Bash", "Ruby", "Python", "Javascript"]
|
|
224
|
+
selected_action = ui.select(language, prompt="Select a programming language:", prompt_style="bold", return_index=False)
|
|
225
|
+
print("Selected programming language:", selected_action)
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
*Description:* The code above presents a single select menu.
|
|
229
|
+
|
|
230
|
+
### Multi-Select Example
|
|
231
|
+
|
|
232
|
+
This snippet presents a multi-select menu for choosing favorite colors.
|
|
233
|
+
|
|
234
|
+
```python
|
|
235
|
+
color_options = ["[red]Red[/]", "[green]Green[/]", "[blue]Blue[/]", "[yellow]Yellow[/]", "[purple]Purple[/]"]
|
|
236
|
+
selected_colors = ui.select(
|
|
237
|
+
color_options,
|
|
238
|
+
prompt="Select your favorite colors:",
|
|
239
|
+
prompt_style="bold #39f782",
|
|
240
|
+
footer="<use space and arrow keys to toggle>",
|
|
241
|
+
multi_select=True,
|
|
242
|
+
)
|
|
243
|
+
print("Selected colors:", selected_colors)
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
*Description:* This snippet presents a multi-select menu.
|
|
247
|
+
|
|
248
|
+
### Confirm Example
|
|
249
|
+
|
|
250
|
+
This snippet displays a confirmation prompt to the user.
|
|
251
|
+
|
|
252
|
+
```python
|
|
253
|
+
confirm = ui.confirm("Do you think [bold]Rich UI[/] is cool?", footer="<press enter to confirm>")
|
|
254
|
+
print("Confirmed:", confirm)
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
*Description:* The code above displays a confirmation prompt to the user.
|
|
258
|
+
|
|
259
|
+
## Running the Example
|
|
260
|
+
|
|
261
|
+
The interactive demo is contained in the module and can be run as follows:
|
|
262
|
+
|
|
263
|
+
```bash
|
|
264
|
+
python3 -m richui.example
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
This command will display each code snippet with syntax highlighting and an accompanying description.
|
richui-0.0.1/README.md
ADDED
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
# Rich UI
|
|
2
|
+
|
|
3
|
+
**An interactive command-line UI module built on top of Rich for customizable UI components.**
|
|
4
|
+
|
|
5
|
+
Rich UI is a Python module that allows you to build interactive command-line interfaces with a modern, colorful, and fully customizable appearance. It leverages the power of [Rich](https://github.com/Textualize/rich) to provide features such as syntax-highlighted code displays, interactive tree and table views, input prompts with completion, and selection menus.
|
|
6
|
+
|
|
7
|
+
## Table of Contents
|
|
8
|
+
|
|
9
|
+
- [Features](#features)
|
|
10
|
+
- [Installation](#installation)
|
|
11
|
+
- [Quick Start](#quick-start)
|
|
12
|
+
- [Custom Configuration Example](#custom-configuration-example)
|
|
13
|
+
- [Tree View Example](#tree-view-example)
|
|
14
|
+
- [Table Example](#table-example)
|
|
15
|
+
- [Text Input Example](#text-input-example)
|
|
16
|
+
- [Secure Input (Password) Example](#secure-input-password-example)
|
|
17
|
+
- [Input with Completion (List) Example](#input-with-completion-list-example)
|
|
18
|
+
- [Input with Completion (Dictionary) Example](#input-with-completion-dictionary-example)
|
|
19
|
+
- [Single Select Example](#single-select-example)
|
|
20
|
+
- [Multi-Select Example](#multi-select-example)
|
|
21
|
+
- [Confirm Example](#confirm-example)
|
|
22
|
+
- [Running the Example](#running-the-example)
|
|
23
|
+
|
|
24
|
+
## Features
|
|
25
|
+
|
|
26
|
+
- **Interactive Components:** Includes tree views, tables, single and multi-select menus, secure input prompts, and confirm dialogs.
|
|
27
|
+
- **Custom Configuration:** Easily configure UI elements such as cursor style, prompt style, footer style, and more.
|
|
28
|
+
- **Syntax Highlighting:** Display text with syntax highlighting (support: rich markup, ansii colors, hex colors).
|
|
29
|
+
- **Completion Support:** Input fields with support for auto-completion from lists or dictionaries.
|
|
30
|
+
|
|
31
|
+
## Installation
|
|
32
|
+
|
|
33
|
+
Install **richui** with pip:
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
pip install richui
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Install **richui** from sources:
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
git clone https://github.com/iqbalmh18/richui
|
|
43
|
+
cd richui
|
|
44
|
+
pip3 install .
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Quick Start
|
|
48
|
+
|
|
49
|
+
import **Richui** and **Config** class
|
|
50
|
+
|
|
51
|
+
```python
|
|
52
|
+
from richui import Richui, Config
|
|
53
|
+
```
|
|
54
|
+
### Custom Configuration Example
|
|
55
|
+
|
|
56
|
+
This snippet defines a custom configuration for Richui, including styling options for various UI components.
|
|
57
|
+
|
|
58
|
+
```python
|
|
59
|
+
custom_config = Config(
|
|
60
|
+
cursor="➠",
|
|
61
|
+
bracket="(",
|
|
62
|
+
checkmark="●",
|
|
63
|
+
title_style="bold white on #f33581",
|
|
64
|
+
title_justify="center",
|
|
65
|
+
value_style="#f72fcb",
|
|
66
|
+
cursor_style="#40fab9",
|
|
67
|
+
prompt_style="bold #4afd86",
|
|
68
|
+
checkmark_style="#40fab9",
|
|
69
|
+
option_style="#ffffff",
|
|
70
|
+
selection_style="#fa9732",
|
|
71
|
+
selected_style="#25f38d",
|
|
72
|
+
footer_style="#707070",
|
|
73
|
+
guide_style="#65fc8e",
|
|
74
|
+
completion_style="white on #5efda9",
|
|
75
|
+
completion_second_style="italic #5efda9 on #3f3f3f",
|
|
76
|
+
text_width=50,
|
|
77
|
+
padding=(0, 2)
|
|
78
|
+
)
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Set **custom_config** to Richui
|
|
82
|
+
|
|
83
|
+
```python
|
|
84
|
+
ui = Richui(custom_config)
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
*Description:* This example uses a custom configuration for Rich UI. The above snippet defines styling options for the UI components.
|
|
88
|
+
|
|
89
|
+
### Tree View Example
|
|
90
|
+
|
|
91
|
+
This snippet displays a tree view of nested data.
|
|
92
|
+
|
|
93
|
+
```python
|
|
94
|
+
tree_data = {
|
|
95
|
+
"Programming": {
|
|
96
|
+
"Language": {
|
|
97
|
+
"Python": [
|
|
98
|
+
"Hacking",
|
|
99
|
+
"Scraping"
|
|
100
|
+
],
|
|
101
|
+
"Bash": "Scripting"
|
|
102
|
+
},
|
|
103
|
+
"CodeEditor": {
|
|
104
|
+
"Nano": "Nano is a simple command-line text editor.",
|
|
105
|
+
"Acode": "Acode is a lightweight code editor for Android."
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
"Country": {
|
|
109
|
+
"ID": "Indonesia"
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
ui.tree(tree_data, title="Data", text_wrap=True)
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
*Description:* The code above displays a tree view of nested data using Rich UI.
|
|
116
|
+
|
|
117
|
+
### Table Example
|
|
118
|
+
|
|
119
|
+
This snippet creates a table to display key information about the Rich UI project.
|
|
120
|
+
|
|
121
|
+
```python
|
|
122
|
+
table_data = {
|
|
123
|
+
"Name": "Rich UI",
|
|
124
|
+
"Version": "1.0.0",
|
|
125
|
+
"Description": "A customizable command-line UI module built on top of the Rich library.",
|
|
126
|
+
"License": "MIT",
|
|
127
|
+
"Source": "https://github.com/iqbalmh18/Richui"
|
|
128
|
+
}
|
|
129
|
+
ui.table(table_data, title=" Rich UI ", text_wrap=True)
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
*Description:* The above snippet creates a table that displays key information about the Rich UI project.
|
|
133
|
+
|
|
134
|
+
### Text Input Example
|
|
135
|
+
|
|
136
|
+
This snippet shows a text input prompt where the user is asked to enter their name.
|
|
137
|
+
|
|
138
|
+
```python
|
|
139
|
+
name = ui.input("Enter your name:", prompt_style="#d75ff8", footer="<press enter to continue>")
|
|
140
|
+
print(f"Nice to meet you, {name}!")
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
*Description:* This snippet shows a text input prompt for the user's name.
|
|
144
|
+
|
|
145
|
+
### Secure Input (Password) Example
|
|
146
|
+
|
|
147
|
+
This snippet demonstrates a secure input prompt where the entered text is masked.
|
|
148
|
+
|
|
149
|
+
```python
|
|
150
|
+
password = ui.input("Enter your password:", prompt_style="#269def", footer="<secure input: enter to continue>", secure=True)
|
|
151
|
+
print("Your password:", password)
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
*Description:* The code above demonstrates a secure input prompt.
|
|
155
|
+
|
|
156
|
+
### Input with Completion (List) Example
|
|
157
|
+
|
|
158
|
+
This snippet allows the user to choose a fruit with tab-completion based on a predefined list.
|
|
159
|
+
|
|
160
|
+
```python
|
|
161
|
+
fruits_list = ["Apple", "Apricot", "Banana", "Blackberry", "Blueberry", "Cherry", "Date"]
|
|
162
|
+
fruit_input_list = ui.input(
|
|
163
|
+
"Enter a fruit:",
|
|
164
|
+
prompt_style="#60e282",
|
|
165
|
+
footer="<use tab to show completion>",
|
|
166
|
+
completion=fruits_list
|
|
167
|
+
)
|
|
168
|
+
print("Fruit chosen:", fruit_input_list)
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
*Description:* This snippet allows selection from a list with auto-completion.
|
|
172
|
+
|
|
173
|
+
### Input with Completion (Dictionary) Example
|
|
174
|
+
|
|
175
|
+
This snippet demonstrates an input prompt with completion using a dictionary, where the keys are used for matching.
|
|
176
|
+
|
|
177
|
+
```python
|
|
178
|
+
countries = {
|
|
179
|
+
"United States": "New York",
|
|
180
|
+
"Indonesian": "Jakarta",
|
|
181
|
+
"Germany": "Berlin",
|
|
182
|
+
"France": "Paris",
|
|
183
|
+
"Japan": "Tokyo"
|
|
184
|
+
}
|
|
185
|
+
country_input = ui.input(
|
|
186
|
+
"Enter a country:",
|
|
187
|
+
prompt_style="#f83d3d",
|
|
188
|
+
footer="<use tab to show completion>",
|
|
189
|
+
completion=countries,
|
|
190
|
+
completion_style="white on #f84a53",
|
|
191
|
+
completion_second_style="italic #f84a53 on #3f3f3f"
|
|
192
|
+
)
|
|
193
|
+
print("Country chosen:", country_input)
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
*Description:* This snippet demonstrates an input prompt with completion using a dictionary.
|
|
197
|
+
|
|
198
|
+
### Single Select Example
|
|
199
|
+
|
|
200
|
+
This snippet shows a single select menu where the user selects one programming language.
|
|
201
|
+
|
|
202
|
+
```python
|
|
203
|
+
language = ["Bash", "Ruby", "Python", "Javascript"]
|
|
204
|
+
selected_action = ui.select(language, prompt="Select a programming language:", prompt_style="bold", return_index=False)
|
|
205
|
+
print("Selected programming language:", selected_action)
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
*Description:* The code above presents a single select menu.
|
|
209
|
+
|
|
210
|
+
### Multi-Select Example
|
|
211
|
+
|
|
212
|
+
This snippet presents a multi-select menu for choosing favorite colors.
|
|
213
|
+
|
|
214
|
+
```python
|
|
215
|
+
color_options = ["[red]Red[/]", "[green]Green[/]", "[blue]Blue[/]", "[yellow]Yellow[/]", "[purple]Purple[/]"]
|
|
216
|
+
selected_colors = ui.select(
|
|
217
|
+
color_options,
|
|
218
|
+
prompt="Select your favorite colors:",
|
|
219
|
+
prompt_style="bold #39f782",
|
|
220
|
+
footer="<use space and arrow keys to toggle>",
|
|
221
|
+
multi_select=True,
|
|
222
|
+
)
|
|
223
|
+
print("Selected colors:", selected_colors)
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
*Description:* This snippet presents a multi-select menu.
|
|
227
|
+
|
|
228
|
+
### Confirm Example
|
|
229
|
+
|
|
230
|
+
This snippet displays a confirmation prompt to the user.
|
|
231
|
+
|
|
232
|
+
```python
|
|
233
|
+
confirm = ui.confirm("Do you think [bold]Rich UI[/] is cool?", footer="<press enter to confirm>")
|
|
234
|
+
print("Confirmed:", confirm)
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
*Description:* The code above displays a confirmation prompt to the user.
|
|
238
|
+
|
|
239
|
+
## Running the Example
|
|
240
|
+
|
|
241
|
+
The interactive demo is contained in the module and can be run as follows:
|
|
242
|
+
|
|
243
|
+
```bash
|
|
244
|
+
python3 -m richui.example
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
This command will display each code snippet with syntax highlighting and an accompanying description.
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "richui"
|
|
7
|
+
version = "0.0.1"
|
|
8
|
+
description = "An interactive command-line UI module built on top of Rich for customizable UI components."
|
|
9
|
+
authors = [
|
|
10
|
+
{ name = "Moh Iqbal Hidayat", email = "iqbalmh18.dev@gmail.com" }
|
|
11
|
+
]
|
|
12
|
+
readme = "README.md"
|
|
13
|
+
license = { file = "LICENSE" }
|
|
14
|
+
keywords = ["rich", "richui", "cli", "UI", "interactive", "terminal"]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Programming Language :: Python :: 3",
|
|
17
|
+
"License :: OSI Approved :: MIT License",
|
|
18
|
+
"Operating System :: OS Independent"
|
|
19
|
+
]
|
|
20
|
+
dependencies = [
|
|
21
|
+
"rich"
|
|
22
|
+
]
|
|
23
|
+
requires-python = ">=3.7"
|
|
24
|
+
|
|
25
|
+
[project.urls]
|
|
26
|
+
Homepage = "https://pypi.org/project/richui"
|
|
27
|
+
Source = "https://github.com/iqbalmh18/richui"
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
from typing import Any, Tuple, Dict
|
|
2
|
+
|
|
3
|
+
class Config:
|
|
4
|
+
def __init__(self, **kwargs: Any) -> None:
|
|
5
|
+
self.kwargs: Dict[str, Any] = kwargs
|
|
6
|
+
self.cursor: str = kwargs.get('cursor', '➜')
|
|
7
|
+
self.bracket: str = kwargs.get('bracket', '(')
|
|
8
|
+
self.padding: Tuple[int, int] = kwargs.get('padding', (0, 0))
|
|
9
|
+
self.newline: bool = kwargs.get('newline', False)
|
|
10
|
+
self.checkmark: str = kwargs.get('checkmark', '✔')
|
|
11
|
+
self.key_style: str = kwargs.get('key_style', 'white')
|
|
12
|
+
self.value_style: str = kwargs.get('value_style', 'yellow')
|
|
13
|
+
self.text_style: str = kwargs.get('text_style', 'white')
|
|
14
|
+
self.text_width: int = kwargs.get('text_width', 50)
|
|
15
|
+
self.text_ljust: int = kwargs.get('text_ljust', 20)
|
|
16
|
+
self.title_style: str = kwargs.get('title_style', 'bold italic green')
|
|
17
|
+
self.guide_style: str = kwargs.get('guide_style', '#666666')
|
|
18
|
+
self.title_justify: str = kwargs.get('title_justify', 'left')
|
|
19
|
+
self.cursor_style: str = kwargs.get('cursor_style', 'green')
|
|
20
|
+
self.prompt_style: str = kwargs.get('prompt_style', 'white')
|
|
21
|
+
self.option_style: str = kwargs.get('option_style', 'white')
|
|
22
|
+
self.footer_style: str = kwargs.get('footer_style', 'italic #666666')
|
|
23
|
+
self.bracket_style: str = kwargs.get('bracket_style', 'white')
|
|
24
|
+
self.selected_style: str = kwargs.get('selected_style', 'green')
|
|
25
|
+
self.selection_style: str = kwargs.get('selection_style', 'yellow')
|
|
26
|
+
self.checkmark_style: str = kwargs.get('checkmark_style', 'green')
|
|
27
|
+
self.completion_style: str = kwargs.get('completion_style', 'green on #666666')
|
|
28
|
+
self.completion_second_style: str = kwargs.get('completion_second_style', 'white on #666666')
|
|
29
|
+
self.completion_select_style: str = kwargs.get('completion_select_style', 'bold reverse')
|