argenta 0.4.7__tar.gz → 0.4.9__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.
- {argenta-0.4.7 → argenta-0.4.9}/PKG-INFO +42 -5
- {argenta-0.4.7 → argenta-0.4.9}/README.md +40 -3
- argenta-0.4.9/argenta/app/dividing_line/__init__.py +4 -0
- argenta-0.4.9/argenta/app/dividing_line/models.py +24 -0
- {argenta-0.4.7 → argenta-0.4.9}/argenta/app/models.py +53 -28
- {argenta-0.4.7 → argenta-0.4.9}/argenta/command/models.py +1 -0
- argenta-0.4.9/argenta/router/__init__.py +4 -0
- {argenta-0.4.7 → argenta-0.4.9}/pyproject.toml +2 -2
- argenta-0.4.7/argenta/router/__init__.py +0 -4
- {argenta-0.4.7 → argenta-0.4.9}/LICENSE +0 -0
- {argenta-0.4.7 → argenta-0.4.9}/argenta/__init__.py +0 -0
- {argenta-0.4.7 → argenta-0.4.9}/argenta/app/__init__.py +0 -0
- {argenta-0.4.7 → argenta-0.4.9}/argenta/app/defaults.py +0 -0
- {argenta-0.4.7 → argenta-0.4.9}/argenta/app/exceptions.py +0 -0
- {argenta-0.4.7 → argenta-0.4.9}/argenta/app/registered_routers/__init__.py +0 -0
- {argenta-0.4.7 → argenta-0.4.9}/argenta/app/registered_routers/entity.py +0 -0
- {argenta-0.4.7 → argenta-0.4.9}/argenta/command/__init__.py +0 -0
- {argenta-0.4.7 → argenta-0.4.9}/argenta/command/exceptions.py +0 -0
- {argenta-0.4.7 → argenta-0.4.9}/argenta/command/flag/__init__.py +0 -0
- {argenta-0.4.7 → argenta-0.4.9}/argenta/command/flag/defaults.py +0 -0
- {argenta-0.4.7 → argenta-0.4.9}/argenta/command/flag/models.py +0 -0
- {argenta-0.4.7 → argenta-0.4.9}/argenta/router/command_handler/__init__.py +0 -0
- {argenta-0.4.7 → argenta-0.4.9}/argenta/router/command_handler/entity.py +0 -0
- {argenta-0.4.7 → argenta-0.4.9}/argenta/router/command_handlers/__init__.py +0 -0
- {argenta-0.4.7 → argenta-0.4.9}/argenta/router/command_handlers/entity.py +0 -0
- {argenta-0.4.7 → argenta-0.4.9}/argenta/router/defaults.py +0 -0
- {argenta-0.4.7 → argenta-0.4.9}/argenta/router/entity.py +0 -0
- {argenta-0.4.7 → argenta-0.4.9}/argenta/router/exceptions.py +0 -0
@@ -1,7 +1,7 @@
|
|
1
1
|
Metadata-Version: 2.3
|
2
2
|
Name: argenta
|
3
|
-
Version: 0.4.
|
4
|
-
Summary:
|
3
|
+
Version: 0.4.9
|
4
|
+
Summary: Python library for creating TUI
|
5
5
|
License: MIT
|
6
6
|
Author: kolo
|
7
7
|
Author-email: kolo.is.main@gmail.com
|
@@ -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
|
@@ -119,8 +119,9 @@ App(prompt: str = 'What do you want to do?\n',
|
|
119
119
|
exit_command_description: str = 'Exit command',
|
120
120
|
system_points_title: str = 'System points:',
|
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
|
**Аргументы:**
|
@@ -132,8 +133,9 @@ App(prompt: str = 'What do you want to do?\n',
|
|
132
133
|
- `exit_command_description` (`str`): Описание команды выхода.
|
133
134
|
- `system_points_title` (`str`): Заголовок перед списком системных команд.
|
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
|
|
@@ -253,6 +260,36 @@ App(prompt: str = 'What do you want to do?\n',
|
|
253
260
|
|
254
261
|
---
|
255
262
|
|
263
|
+
## *class* :: `StaticDivideLine`
|
264
|
+
Класс, экземпляр которого представляет собой строковый разделитель фиксированной длины
|
265
|
+
|
266
|
+
### Конструктор
|
267
|
+
```python
|
268
|
+
StaticDivideLine(unit_part: str = '-',
|
269
|
+
length: int = 25)
|
270
|
+
```
|
271
|
+
|
272
|
+
**Аргументы:**
|
273
|
+
- **name : mean**
|
274
|
+
- `unit_part` (`str`): Единичная часть строкового разделителя
|
275
|
+
- `length` (`int`): Длина строкового разделителя
|
276
|
+
|
277
|
+
---
|
278
|
+
|
279
|
+
## *class* :: `DinamicDivideLine`
|
280
|
+
Строковый разделитель динамической длины, которая определяется длиной обрамляемого вывода команды
|
281
|
+
|
282
|
+
### Конструктор
|
283
|
+
```python
|
284
|
+
DinamicDivideLine(unit_part: str = '-')
|
285
|
+
```
|
286
|
+
|
287
|
+
**Аргументы:**
|
288
|
+
- **name : mean**
|
289
|
+
- `unit_part` (`str`): Единичная часть строкового разделителя
|
290
|
+
|
291
|
+
---
|
292
|
+
|
256
293
|
## *class* :: `Router`
|
257
294
|
Класс, который определяет и конфигурирует обработчики команд
|
258
295
|
|
@@ -3,7 +3,7 @@
|
|
3
3
|
---
|
4
4
|
|
5
5
|
## Описание
|
6
|
-
**Argenta** — Python library for creating
|
6
|
+
**Argenta** — Python library for creating TUI
|
7
7
|
|
8
8
|

|
9
9
|
Пример внешнего вида TUI, написанного с помощью Argenta
|
@@ -102,8 +102,9 @@ App(prompt: str = 'What do you want to do?\n',
|
|
102
102
|
exit_command_description: str = 'Exit command',
|
103
103
|
system_points_title: str = 'System points:',
|
104
104
|
ignore_command_register: bool = True,
|
105
|
-
|
105
|
+
dividing_line: StaticDividingLine | DynamicDividingLine = StaticDividingLine(),
|
106
106
|
repeat_command_groups: bool = True,
|
107
|
+
full_override_system_messages: bool = False
|
107
108
|
print_func: Callable[[str], None] = Console().print)
|
108
109
|
```
|
109
110
|
**Аргументы:**
|
@@ -115,8 +116,9 @@ App(prompt: str = 'What do you want to do?\n',
|
|
115
116
|
- `exit_command_description` (`str`): Описание команды выхода.
|
116
117
|
- `system_points_title` (`str`): Заголовок перед списком системных команд.
|
117
118
|
- `ignore_command_register` (`bool`): Игнорировать регистр всех команд.
|
118
|
-
- `
|
119
|
+
- `dividing_line` (`StaticDividingLine | DynamicDividingLine`): Разделительная строка.
|
119
120
|
- `repeat_command_groups` (`bool`): Повторять описание команд перед вводом.
|
121
|
+
- `full_override_system_messages` (`bool`): Переопределить ли дефолтное оформление сообщений ([подробнее см.](#override_defaults))
|
120
122
|
- `print_func` (`Callable[[str], None]`): Функция вывода текста в терминал.
|
121
123
|
|
122
124
|
---
|
@@ -224,6 +226,11 @@ App(prompt: str = 'What do you want to do?\n',
|
|
224
226
|
- Наиболее частые сообщение при запуске предопределены и доступны для быстрого
|
225
227
|
использования: `argenta.app.defaults.PredeterminedMessages`
|
226
228
|
|
229
|
+
<a name="override_defaults"></a>
|
230
|
+
- Если `override_system_messages`=`False`, то при переопределении таких атрибутов как `initial_message` и
|
231
|
+
`farawell_message` будет использовано дефолтное оформление текста, в виде красного ascii арта, при значении
|
232
|
+
`override_system_messages`=`True` системные сообщения будут отображены в точности какими были переданы
|
233
|
+
|
227
234
|
|
228
235
|
|
229
236
|
|
@@ -236,6 +243,36 @@ App(prompt: str = 'What do you want to do?\n',
|
|
236
243
|
|
237
244
|
---
|
238
245
|
|
246
|
+
## *class* :: `StaticDivideLine`
|
247
|
+
Класс, экземпляр которого представляет собой строковый разделитель фиксированной длины
|
248
|
+
|
249
|
+
### Конструктор
|
250
|
+
```python
|
251
|
+
StaticDivideLine(unit_part: str = '-',
|
252
|
+
length: int = 25)
|
253
|
+
```
|
254
|
+
|
255
|
+
**Аргументы:**
|
256
|
+
- **name : mean**
|
257
|
+
- `unit_part` (`str`): Единичная часть строкового разделителя
|
258
|
+
- `length` (`int`): Длина строкового разделителя
|
259
|
+
|
260
|
+
---
|
261
|
+
|
262
|
+
## *class* :: `DinamicDivideLine`
|
263
|
+
Строковый разделитель динамической длины, которая определяется длиной обрамляемого вывода команды
|
264
|
+
|
265
|
+
### Конструктор
|
266
|
+
```python
|
267
|
+
DinamicDivideLine(unit_part: str = '-')
|
268
|
+
```
|
269
|
+
|
270
|
+
**Аргументы:**
|
271
|
+
- **name : mean**
|
272
|
+
- `unit_part` (`str`): Единичная часть строкового разделителя
|
273
|
+
|
274
|
+
---
|
275
|
+
|
239
276
|
## *class* :: `Router`
|
240
277
|
Класс, который определяет и конфигурирует обработчики команд
|
241
278
|
|
@@ -0,0 +1,24 @@
|
|
1
|
+
class BaseDividingLine:
|
2
|
+
def __init__(self, unit_part: str = '-'):
|
3
|
+
self.unit_part = unit_part
|
4
|
+
|
5
|
+
def get_unit_part(self):
|
6
|
+
if len(self.unit_part) == 0:
|
7
|
+
return ' '
|
8
|
+
else:
|
9
|
+
return self.unit_part[0]
|
10
|
+
|
11
|
+
class StaticDividingLine(BaseDividingLine):
|
12
|
+
def __init__(self, unit_part: str = '-', length: int = 25):
|
13
|
+
super().__init__(unit_part)
|
14
|
+
self.length = length
|
15
|
+
|
16
|
+
def get_full_line(self):
|
17
|
+
return f'\n[dim]{self.length * self.get_unit_part()}[/dim]\n'
|
18
|
+
|
19
|
+
|
20
|
+
class DynamicDividingLine(BaseDividingLine):
|
21
|
+
def get_full_line(self, length: int):
|
22
|
+
return f'\n[dim]{self.get_unit_part() * length}[/dim]\n'
|
23
|
+
|
24
|
+
|
@@ -1,11 +1,14 @@
|
|
1
1
|
from typing import Callable
|
2
2
|
from rich.console import Console
|
3
3
|
from art import text2art
|
4
|
+
from contextlib import redirect_stdout
|
5
|
+
import io
|
4
6
|
import re
|
5
7
|
|
6
8
|
from argenta.command.models import Command, InputCommand
|
7
9
|
from argenta.router import Router
|
8
10
|
from argenta.router.defaults import system_router
|
11
|
+
from argenta.app.dividing_line.models import StaticDividingLine, DynamicDividingLine
|
9
12
|
from argenta.command.exceptions import (UnprocessedInputFlagException,
|
10
13
|
RepeatedInputFlagsException,
|
11
14
|
EmptyInputCommandException,
|
@@ -21,23 +24,25 @@ from argenta.app.registered_routers.entity import RegisteredRouters
|
|
21
24
|
class BaseApp:
|
22
25
|
def __init__(self,
|
23
26
|
prompt: str = '[italic dim bold]What do you want to do?\n',
|
24
|
-
initial_message: str = '
|
25
|
-
farewell_message: str = '
|
27
|
+
initial_message: str = '\nArgenta\n',
|
28
|
+
farewell_message: str = '\nSee you\n',
|
26
29
|
exit_command: str = 'Q',
|
27
30
|
exit_command_description: str = 'Exit command',
|
28
31
|
system_points_title: str = 'System points:',
|
29
32
|
ignore_command_register: bool = True,
|
30
|
-
|
33
|
+
dividing_line: StaticDividingLine | DynamicDividingLine = StaticDividingLine(),
|
31
34
|
repeat_command_groups: bool = True,
|
35
|
+
full_override_system_messages: bool = False,
|
32
36
|
print_func: Callable[[str], None] = Console().print) -> None:
|
33
37
|
self._prompt = prompt
|
34
38
|
self._print_func = print_func
|
35
39
|
self._exit_command = exit_command
|
36
40
|
self._exit_command_description = exit_command_description
|
37
41
|
self._system_points_title = system_points_title
|
38
|
-
self.
|
42
|
+
self._dividing_line = dividing_line
|
39
43
|
self._ignore_command_register = ignore_command_register
|
40
44
|
self._repeat_command_groups_description = repeat_command_groups
|
45
|
+
self._full_override_system_messages = full_override_system_messages
|
41
46
|
|
42
47
|
self.farewell_message = farewell_message
|
43
48
|
self.initial_message = initial_message
|
@@ -52,22 +57,14 @@ class BaseApp:
|
|
52
57
|
self.unknown_command_handler: Callable[[InputCommand], None] = lambda command: print_func(f"[red bold]Unknown command: {command.get_trigger()}")
|
53
58
|
self.exit_command_handler: Callable[[], None] = lambda: print_func(self.farewell_message)
|
54
59
|
|
55
|
-
self._setup_default_view(
|
56
|
-
is_farewell_message_default=farewell_message == 'See you',
|
57
|
-
is_line_separate_default=line_separate == '-----')
|
60
|
+
self._setup_default_view()
|
58
61
|
|
59
62
|
|
60
|
-
def _setup_default_view(self
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
if is_farewell_message_default:
|
66
|
-
self.farewell_message = (f'[bold red]\n{text2art('\nSee you\n', font='chanky')}[/bold red]\n'
|
67
|
-
f'[red i]github.com/koloideal/Argenta[/red i] | '
|
68
|
-
f'[red bold i]made by kolo[/red bold i]\n')
|
69
|
-
if is_line_separate_default:
|
70
|
-
self._line_separate = f'\n[dim]{"-" * 50}\n'
|
63
|
+
def _setup_default_view(self):
|
64
|
+
if not self._full_override_system_messages:
|
65
|
+
self.initial_message = f'\n[bold red]{text2art(self.initial_message, font='tarty1')}\n\n'
|
66
|
+
self.farewell_message = (f'[bold red]\n{text2art(f'\n{self.farewell_message}\n', font='chanky')}[/bold red]\n'
|
67
|
+
f'[red i]github.com/koloideal/Argenta[/red i] | [red bold i]made by kolo[/red bold i]\n')
|
71
68
|
|
72
69
|
|
73
70
|
def _validate_number_of_routers(self) -> None:
|
@@ -100,7 +97,15 @@ class BaseApp:
|
|
100
97
|
return False
|
101
98
|
elif handled_command_trigger == command.get_trigger():
|
102
99
|
return False
|
103
|
-
self.
|
100
|
+
if isinstance(self._dividing_line, StaticDividingLine):
|
101
|
+
self._print_func(self._dividing_line.get_full_line())
|
102
|
+
self.unknown_command_handler(command)
|
103
|
+
self._print_func(self._dividing_line.get_full_line())
|
104
|
+
elif isinstance(self._dividing_line, DynamicDividingLine):
|
105
|
+
with redirect_stdout(io.StringIO()) as f:
|
106
|
+
self.unknown_command_handler(command)
|
107
|
+
res: str = f.getvalue()
|
108
|
+
self._print_framed_text_with_dynamic_line(res)
|
104
109
|
return True
|
105
110
|
|
106
111
|
|
@@ -124,6 +129,15 @@ class BaseApp:
|
|
124
129
|
self.empty_input_command_handler()
|
125
130
|
|
126
131
|
|
132
|
+
def _print_framed_text_with_dynamic_line(self, text: str):
|
133
|
+
clear_text = re.sub(r'\u001b\[[0-9;]*m', '', text)
|
134
|
+
max_length_line = max([len(line) for line in clear_text.split('\n')])
|
135
|
+
max_length_line = max_length_line if 10 <= max_length_line <= 80 else 80 if max_length_line > 80 else 10
|
136
|
+
self._print_func(self._dividing_line.get_full_line(max_length_line))
|
137
|
+
print(text.strip('\n'))
|
138
|
+
self._print_func(self._dividing_line.get_full_line(max_length_line))
|
139
|
+
|
140
|
+
|
127
141
|
|
128
142
|
class App(BaseApp):
|
129
143
|
def start_polling(self) -> None:
|
@@ -148,24 +162,35 @@ class App(BaseApp):
|
|
148
162
|
try:
|
149
163
|
input_command: InputCommand = InputCommand.parse(raw_command=raw_command)
|
150
164
|
except BaseInputCommandException as error:
|
151
|
-
|
152
|
-
|
153
|
-
|
165
|
+
if isinstance(self._dividing_line, StaticDividingLine):
|
166
|
+
self._print_func(self._dividing_line.get_full_line())
|
167
|
+
self._error_handler(error, raw_command)
|
168
|
+
self._print_func(self._dividing_line.get_full_line())
|
169
|
+
elif isinstance(self._dividing_line, DynamicDividingLine):
|
170
|
+
with redirect_stdout(io.StringIO()) as f:
|
171
|
+
self._error_handler(error, raw_command)
|
172
|
+
res: str = f.getvalue()
|
173
|
+
self._print_framed_text_with_dynamic_line(res)
|
154
174
|
continue
|
155
175
|
|
156
176
|
if self._is_exit_command(input_command):
|
157
177
|
return
|
158
178
|
|
159
|
-
self._print_func(self._line_separate)
|
160
|
-
|
161
179
|
if self._is_unknown_command(input_command):
|
162
|
-
self._print_func(self._line_separate)
|
163
180
|
continue
|
164
181
|
|
165
|
-
|
166
|
-
|
182
|
+
if isinstance(self._dividing_line, StaticDividingLine):
|
183
|
+
self._print_func(self._dividing_line.get_full_line())
|
184
|
+
for registered_router in self._registered_routers:
|
185
|
+
registered_router.input_command_handler(input_command)
|
186
|
+
self._print_func(self._dividing_line.get_full_line())
|
187
|
+
elif isinstance(self._dividing_line, DynamicDividingLine):
|
188
|
+
with redirect_stdout(io.StringIO()) as f:
|
189
|
+
for registered_router in self._registered_routers:
|
190
|
+
registered_router.input_command_handler(input_command)
|
191
|
+
res: str = f.getvalue()
|
192
|
+
self._print_framed_text_with_dynamic_line(res)
|
167
193
|
|
168
|
-
self._print_func(self._line_separate)
|
169
194
|
if not self._repeat_command_groups_description:
|
170
195
|
self._print_func(self._prompt)
|
171
196
|
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|