argenta 0.4.8__py3-none-any.whl → 0.4.10__py3-none-any.whl
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.
- argenta/app/__init__.py +1 -1
- argenta/app/dividing_line/__init__.py +4 -0
- argenta/app/models.py +97 -73
- argenta/command/__init__.py +1 -1
- argenta/command/flag/__init__.py +1 -1
- argenta/router/__init__.py +1 -1
- {argenta-0.4.8.dist-info → argenta-0.4.10.dist-info}/METADATA +9 -2
- {argenta-0.4.8.dist-info → argenta-0.4.10.dist-info}/RECORD +10 -10
- {argenta-0.4.8.dist-info → argenta-0.4.10.dist-info}/LICENSE +0 -0
- {argenta-0.4.8.dist-info → argenta-0.4.10.dist-info}/WHEEL +0 -0
argenta/app/__init__.py
CHANGED
argenta/app/models.py
CHANGED
@@ -21,17 +21,18 @@ from argenta.app.registered_routers.entity import RegisteredRouters
|
|
21
21
|
|
22
22
|
|
23
23
|
|
24
|
-
class
|
24
|
+
class AppInit:
|
25
25
|
def __init__(self,
|
26
26
|
prompt: str = '[italic dim bold]What do you want to do?\n',
|
27
|
-
initial_message: str = '
|
28
|
-
farewell_message: str = '
|
27
|
+
initial_message: str = '\nArgenta\n',
|
28
|
+
farewell_message: str = '\nSee you\n',
|
29
29
|
exit_command: str = 'Q',
|
30
30
|
exit_command_description: str = 'Exit command',
|
31
31
|
system_points_title: str = 'System points:',
|
32
32
|
ignore_command_register: bool = True,
|
33
33
|
dividing_line: StaticDividingLine | DynamicDividingLine = StaticDividingLine(),
|
34
34
|
repeat_command_groups: bool = True,
|
35
|
+
full_override_system_messages: bool = False,
|
35
36
|
print_func: Callable[[str], None] = Console().print) -> None:
|
36
37
|
self._prompt = prompt
|
37
38
|
self._print_func = print_func
|
@@ -41,45 +42,74 @@ class BaseApp:
|
|
41
42
|
self._dividing_line = dividing_line
|
42
43
|
self._ignore_command_register = ignore_command_register
|
43
44
|
self._repeat_command_groups_description = repeat_command_groups
|
45
|
+
self._full_override_system_messages = full_override_system_messages
|
44
46
|
|
45
|
-
self.
|
46
|
-
self.
|
47
|
+
self._farewell_message = farewell_message
|
48
|
+
self._initial_message = initial_message
|
47
49
|
|
48
50
|
self._description_message_pattern: str = '[bold red][{command}][/bold red] [blue dim]*=*=*[/blue dim] [bold yellow italic]{description}'
|
49
51
|
self._registered_routers: RegisteredRouters = RegisteredRouters()
|
50
52
|
self._messages_on_startup = []
|
51
53
|
|
52
|
-
self.
|
53
|
-
self.
|
54
|
-
self.
|
55
|
-
self.
|
56
|
-
self.
|
54
|
+
self._invalid_input_flags_handler: Callable[[str], None] = lambda raw_command: print_func(f'[red bold]Incorrect flag syntax: {raw_command}')
|
55
|
+
self._repeated_input_flags_handler: Callable[[str], None] = lambda raw_command: print_func(f'[red bold]Repeated input flags: {raw_command}')
|
56
|
+
self._empty_input_command_handler: Callable[[], None] = lambda: print_func('[red bold]Empty input command')
|
57
|
+
self._unknown_command_handler: Callable[[InputCommand], None] = lambda command: print_func(f"[red bold]Unknown command: {command.get_trigger()}")
|
58
|
+
self._exit_command_handler: Callable[[], None] = lambda: print_func(self._farewell_message)
|
57
59
|
|
58
|
-
self._setup_default_view(is_initial_message_default=initial_message == 'Argenta',
|
59
|
-
is_farewell_message_default=farewell_message == 'See you')
|
60
60
|
|
61
|
+
class AppSetters(AppInit):
|
62
|
+
def set_description_message_pattern(self, pattern: str) -> None:
|
63
|
+
first_check = re.match(r'.*{command}.*', pattern)
|
64
|
+
second_check = re.match(r'.*{description}.*', pattern)
|
61
65
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
if is_farewell_message_default:
|
67
|
-
self.farewell_message = (f'[bold red]\n{text2art('\nSee you\n', font='chanky')}[/bold red]\n'
|
68
|
-
f'[red i]github.com/koloideal/Argenta[/red i] | '
|
69
|
-
f'[red bold i]made by kolo[/red bold i]\n')
|
66
|
+
if bool(first_check) and bool(second_check):
|
67
|
+
self._description_message_pattern: str = pattern
|
68
|
+
else:
|
69
|
+
raise InvalidDescriptionMessagePatternException(pattern)
|
70
70
|
|
71
71
|
|
72
|
-
def
|
73
|
-
|
74
|
-
raise NoRegisteredRoutersException()
|
72
|
+
def set_invalid_input_flags_handler(self, handler: Callable[[str], None]) -> None:
|
73
|
+
self._invalid_input_flags_handler = handler
|
75
74
|
|
76
75
|
|
77
|
-
def
|
78
|
-
|
79
|
-
|
80
|
-
|
76
|
+
def set_repeated_input_flags_handler(self, handler: Callable[[str], None]) -> None:
|
77
|
+
self._repeated_input_flags_handler = handler
|
78
|
+
|
79
|
+
|
80
|
+
def set_unknown_command_handler(self, handler: Callable[[str], None]) -> None:
|
81
|
+
self._unknown_command_handler = handler
|
82
|
+
|
83
|
+
|
84
|
+
def set_empty_command_handler(self, handler: Callable[[], None]) -> None:
|
85
|
+
self._empty_input_command_handler = handler
|
81
86
|
|
82
87
|
|
88
|
+
def set_exit_command_handler(self, handler: Callable[[], None]) -> None:
|
89
|
+
self._exit_command_handler = handler
|
90
|
+
|
91
|
+
|
92
|
+
class AppPrinters(AppInit):
|
93
|
+
def _print_command_group_description(self):
|
94
|
+
for registered_router in self._registered_routers:
|
95
|
+
self._print_func(registered_router.get_title())
|
96
|
+
for command_handler in registered_router.get_command_handlers():
|
97
|
+
self._print_func(self._description_message_pattern.format(
|
98
|
+
command=command_handler.get_handled_command().get_trigger(),
|
99
|
+
description=command_handler.get_handled_command().get_description()))
|
100
|
+
self._print_func('')
|
101
|
+
|
102
|
+
|
103
|
+
def _print_framed_text_with_dynamic_line(self, text: str):
|
104
|
+
clear_text = re.sub(r'\u001b\[[0-9;]*m', '', text)
|
105
|
+
max_length_line = max([len(line) for line in clear_text.split('\n')])
|
106
|
+
max_length_line = max_length_line if 10 <= max_length_line <= 80 else 80 if max_length_line > 80 else 10
|
107
|
+
self._print_func(self._dividing_line.get_full_line(max_length_line))
|
108
|
+
print(text.strip('\n'))
|
109
|
+
self._print_func(self._dividing_line.get_full_line(max_length_line))
|
110
|
+
|
111
|
+
|
112
|
+
class AppNonStandardHandlers(AppPrinters):
|
83
113
|
def _is_exit_command(self, command: InputCommand):
|
84
114
|
if command.get_trigger().lower() == self._exit_command.lower():
|
85
115
|
if self._ignore_command_register:
|
@@ -101,53 +131,64 @@ class BaseApp:
|
|
101
131
|
return False
|
102
132
|
if isinstance(self._dividing_line, StaticDividingLine):
|
103
133
|
self._print_func(self._dividing_line.get_full_line())
|
104
|
-
self.
|
134
|
+
self._unknown_command_handler(command)
|
105
135
|
self._print_func(self._dividing_line.get_full_line())
|
106
136
|
elif isinstance(self._dividing_line, DynamicDividingLine):
|
107
137
|
with redirect_stdout(io.StringIO()) as f:
|
108
|
-
self.
|
138
|
+
self._unknown_command_handler(command)
|
109
139
|
res: str = f.getvalue()
|
110
140
|
self._print_framed_text_with_dynamic_line(res)
|
111
141
|
return True
|
112
142
|
|
113
143
|
|
114
|
-
def _print_command_group_description(self):
|
115
|
-
for registered_router in self._registered_routers:
|
116
|
-
self._print_func(registered_router.get_title())
|
117
|
-
for command_handler in registered_router.get_command_handlers():
|
118
|
-
self._print_func(self._description_message_pattern.format(
|
119
|
-
command=command_handler.get_handled_command().get_trigger(),
|
120
|
-
description=command_handler.get_handled_command().get_description()))
|
121
|
-
self._print_func('')
|
122
|
-
|
123
|
-
|
124
144
|
def _error_handler(self, error: BaseInputCommandException, raw_command: str) -> None:
|
125
145
|
match error:
|
126
146
|
case UnprocessedInputFlagException():
|
127
|
-
self.
|
147
|
+
self._invalid_input_flags_handler(raw_command)
|
128
148
|
case RepeatedInputFlagsException():
|
129
|
-
self.
|
149
|
+
self._repeated_input_flags_handler(raw_command)
|
130
150
|
case EmptyInputCommandException():
|
131
|
-
self.
|
151
|
+
self._empty_input_command_handler()
|
132
152
|
|
133
153
|
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
self._print_func(self._dividing_line.get_full_line(max_length_line))
|
139
|
-
print(text.strip('\n'))
|
140
|
-
self._print_func(self._dividing_line.get_full_line(max_length_line))
|
154
|
+
class AppValidators(AppInit):
|
155
|
+
def _validate_number_of_routers(self) -> None:
|
156
|
+
if not self._registered_routers:
|
157
|
+
raise NoRegisteredRoutersException()
|
141
158
|
|
142
159
|
|
160
|
+
def _validate_included_routers(self) -> None:
|
161
|
+
for router in self._registered_routers:
|
162
|
+
if not router.get_command_handlers():
|
163
|
+
raise NoRegisteredHandlersException(router.get_name())
|
143
164
|
|
144
|
-
|
145
|
-
|
165
|
+
|
166
|
+
class AppSetups(AppValidators, AppPrinters):
|
167
|
+
def _setup_system_router(self):
|
168
|
+
system_router.set_title(self._system_points_title)
|
169
|
+
|
170
|
+
@system_router.command(Command(self._exit_command, self._exit_command_description))
|
171
|
+
def exit_command():
|
172
|
+
self._exit_command_handler()
|
173
|
+
|
174
|
+
if system_router not in self._registered_routers.get_registered_routers():
|
175
|
+
system_router.set_ignore_command_register(self._ignore_command_register)
|
176
|
+
self._registered_routers.add_registered_router(system_router)
|
177
|
+
|
178
|
+
def _setup_default_view(self):
|
179
|
+
if not self._full_override_system_messages:
|
180
|
+
self._initial_message = f'\n[bold red]{text2art(self._initial_message, font='tarty1')}\n\n'
|
181
|
+
self._farewell_message = (
|
182
|
+
f'[bold red]\n{text2art(f'\n{self._farewell_message}\n', font='chanky')}[/bold red]\n'
|
183
|
+
f'[red i]github.com/koloideal/Argenta[/red i] | [red bold i]made by kolo[/red bold i]\n')
|
184
|
+
|
185
|
+
def _pre_cycle_setup(self):
|
186
|
+
self._setup_default_view()
|
146
187
|
self._setup_system_router()
|
147
188
|
self._validate_number_of_routers()
|
148
189
|
self._validate_included_routers()
|
149
190
|
|
150
|
-
self._print_func(self.
|
191
|
+
self._print_func(self._initial_message)
|
151
192
|
|
152
193
|
for message in self._messages_on_startup:
|
153
194
|
self._print_func(message)
|
@@ -155,6 +196,10 @@ class App(BaseApp):
|
|
155
196
|
if not self._repeat_command_groups_description:
|
156
197
|
self._print_command_group_description()
|
157
198
|
|
199
|
+
|
200
|
+
class App(AppSetters, AppNonStandardHandlers, AppSetups):
|
201
|
+
def start_polling(self) -> None:
|
202
|
+
self._pre_cycle_setup()
|
158
203
|
while True:
|
159
204
|
if self._repeat_command_groups_description:
|
160
205
|
self._print_command_group_description()
|
@@ -213,24 +258,3 @@ class App(BaseApp):
|
|
213
258
|
def add_message_on_startup(self, message: str) -> None:
|
214
259
|
self._messages_on_startup.append(message)
|
215
260
|
|
216
|
-
|
217
|
-
def set_description_message_pattern(self, pattern: str) -> None:
|
218
|
-
first_check = re.match(r'.*{command}.*', pattern)
|
219
|
-
second_check = re.match(r'.*{description}.*', pattern)
|
220
|
-
|
221
|
-
if bool(first_check) and bool(second_check):
|
222
|
-
self._description_message_pattern: str = pattern
|
223
|
-
else:
|
224
|
-
raise InvalidDescriptionMessagePatternException(pattern)
|
225
|
-
|
226
|
-
|
227
|
-
def _setup_system_router(self):
|
228
|
-
system_router.set_title(self._system_points_title)
|
229
|
-
@system_router.command(Command(self._exit_command, self._exit_command_description))
|
230
|
-
def exit_command():
|
231
|
-
self.exit_command_handler()
|
232
|
-
|
233
|
-
if system_router not in self._registered_routers.get_registered_routers():
|
234
|
-
self.include_router(system_router)
|
235
|
-
|
236
|
-
|
argenta/command/__init__.py
CHANGED
argenta/command/flag/__init__.py
CHANGED
argenta/router/__init__.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.3
|
2
2
|
Name: argenta
|
3
|
-
Version: 0.4.
|
3
|
+
Version: 0.4.10
|
4
4
|
Summary: Python library for creating TUI
|
5
5
|
License: MIT
|
6
6
|
Author: kolo
|
@@ -20,7 +20,7 @@ Description-Content-Type: text/markdown
|
|
20
20
|
---
|
21
21
|
|
22
22
|
## Описание
|
23
|
-
**Argenta** — Python library for creating
|
23
|
+
**Argenta** — Python library for creating TUI
|
24
24
|
|
25
25
|

|
26
26
|
Пример внешнего вида TUI, написанного с помощью Argenta
|
@@ -121,6 +121,7 @@ App(prompt: str = 'What do you want to do?\n',
|
|
121
121
|
ignore_command_register: bool = True,
|
122
122
|
dividing_line: StaticDividingLine | DynamicDividingLine = StaticDividingLine(),
|
123
123
|
repeat_command_groups: bool = True,
|
124
|
+
full_override_system_messages: bool = False
|
124
125
|
print_func: Callable[[str], None] = Console().print)
|
125
126
|
```
|
126
127
|
**Аргументы:**
|
@@ -134,6 +135,7 @@ App(prompt: str = 'What do you want to do?\n',
|
|
134
135
|
- `ignore_command_register` (`bool`): Игнорировать регистр всех команд.
|
135
136
|
- `dividing_line` (`StaticDividingLine | DynamicDividingLine`): Разделительная строка.
|
136
137
|
- `repeat_command_groups` (`bool`): Повторять описание команд перед вводом.
|
138
|
+
- `full_override_system_messages` (`bool`): Переопределить ли дефолтное оформление сообщений ([подробнее см.](#override_defaults))
|
137
139
|
- `print_func` (`Callable[[str], None]`): Функция вывода текста в терминал.
|
138
140
|
|
139
141
|
---
|
@@ -241,6 +243,11 @@ App(prompt: str = 'What do you want to do?\n',
|
|
241
243
|
- Наиболее частые сообщение при запуске предопределены и доступны для быстрого
|
242
244
|
использования: `argenta.app.defaults.PredeterminedMessages`
|
243
245
|
|
246
|
+
<a name="override_defaults"></a>
|
247
|
+
- Если `override_system_messages`=`False`, то при переопределении таких атрибутов как `initial_message` и
|
248
|
+
`farawell_message` будет использовано дефолтное оформление текста, в виде красного ascii арта, при значении
|
249
|
+
`override_system_messages`=`True` системные сообщения будут отображены в точности какими были переданы
|
250
|
+
|
244
251
|
|
245
252
|
|
246
253
|
|
@@ -1,19 +1,19 @@
|
|
1
1
|
argenta/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
2
|
-
argenta/app/__init__.py,sha256=
|
2
|
+
argenta/app/__init__.py,sha256=I8FTXU17ajDI-hbC6Rw0LxLmvDYipdQaos3v1pmu14E,57
|
3
3
|
argenta/app/defaults.py,sha256=7ej4G-4dieMlichfuQhw5XgabF15X-vAa8k02ZfkdUs,234
|
4
|
-
argenta/app/dividing_line/__init__.py,sha256=
|
4
|
+
argenta/app/dividing_line/__init__.py,sha256=jJZDDZix8XYCAUWW4FzGJH0JmJlchYcx0FPWifjgv1I,147
|
5
5
|
argenta/app/dividing_line/models.py,sha256=ueBDmy1hfYzGAr1X2G2Mw0hjES7YQBtP7N3TLBDz9h0,700
|
6
6
|
argenta/app/exceptions.py,sha256=uCkb1VqEIZQuVDY0ZsfDc3yCbySwLpV5CdIT7iaGYRM,928
|
7
|
-
argenta/app/models.py,sha256=
|
7
|
+
argenta/app/models.py,sha256=burvSSmUW-1FnhGYgHwLTW6jcW3ENFoB1wdmwwyYAog,12121
|
8
8
|
argenta/app/registered_routers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
9
9
|
argenta/app/registered_routers/entity.py,sha256=OQZyrF4eoCoDHzRJ22zZxhNEx-bOUDu7NZIFDfO-fuY,688
|
10
|
-
argenta/command/__init__.py,sha256=
|
10
|
+
argenta/command/__init__.py,sha256=Plo2Da0fhq8H1eo2mg7nA1-OBLuGjK2BYpDGRvGGMIU,67
|
11
11
|
argenta/command/exceptions.py,sha256=HOgddtXLDgk9Wx6c_GnzW3bMAMU5CuUnUyxjW3cVHRo,687
|
12
|
-
argenta/command/flag/__init__.py,sha256=
|
12
|
+
argenta/command/flag/__init__.py,sha256=PaZAaqU3DgyO1o5do-xKhWV6TyEuOSaQTmE4VbPY6JA,136
|
13
13
|
argenta/command/flag/defaults.py,sha256=ktKmDT0rSSBoFUghTlEQ6OletoFxCiD37hRzO73mUUc,875
|
14
14
|
argenta/command/flag/models.py,sha256=IY0FHyAFD9O1ZxSaq6NR9gSTkldoQGrKVoGrAbnmEuA,3769
|
15
15
|
argenta/command/models.py,sha256=1p_QZ5cQq47t915zHehEx-S0smTqj4DDnjZGn_qZlOA,4436
|
16
|
-
argenta/router/__init__.py,sha256=
|
16
|
+
argenta/router/__init__.py,sha256=ldrIWTXNLXUAMAGQ8ex4e8nMso_fhi01nZi2DVzHnnk,66
|
17
17
|
argenta/router/command_handler/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
18
18
|
argenta/router/command_handler/entity.py,sha256=8sWhP89c0FavFBITJmH9c8wNn2ipW_6-_obzjkwXueU,646
|
19
19
|
argenta/router/command_handlers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
@@ -21,7 +21,7 @@ argenta/router/command_handlers/entity.py,sha256=KgFKjAMUr_mOcn9xahTxMUKB6lIxXgq
|
|
21
21
|
argenta/router/defaults.py,sha256=huftOg1HMjrT_R2SHHOL4eJ5uZHspNEYBSg-mCq9xhU,126
|
22
22
|
argenta/router/entity.py,sha256=afQn5jrDBrcd5QUzeBwRPfazOO6x0yYSXcmvHYhJpDw,4997
|
23
23
|
argenta/router/exceptions.py,sha256=tdeaR8zDvnytgRYo_wQWKHt3if2brapgauIhhMIsTsA,678
|
24
|
-
argenta-0.4.
|
25
|
-
argenta-0.4.
|
26
|
-
argenta-0.4.
|
27
|
-
argenta-0.4.
|
24
|
+
argenta-0.4.10.dist-info/LICENSE,sha256=zmqoGh2n5rReBv4s8wPxF_gZEZDgauJYSPMuPczgOiU,1082
|
25
|
+
argenta-0.4.10.dist-info/METADATA,sha256=uVIrDo-uxIWV7qS1pGXZAHL95Sok2KQ-U8tJoZxovGg,20986
|
26
|
+
argenta-0.4.10.dist-info/WHEEL,sha256=XbeZDeTWKc1w7CSIyre5aMDU_-PohRwTQceYnisIYYY,88
|
27
|
+
argenta-0.4.10.dist-info/RECORD,,
|
File without changes
|
File without changes
|