argenta 0.4.7__py3-none-any.whl → 0.4.8__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.
File without changes
@@ -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
+
argenta/app/models.py CHANGED
@@ -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,
@@ -27,7 +30,7 @@ class BaseApp:
27
30
  exit_command_description: str = 'Exit command',
28
31
  system_points_title: str = 'System points:',
29
32
  ignore_command_register: bool = True,
30
- line_separate: str = '-----',
33
+ dividing_line: StaticDividingLine | DynamicDividingLine = StaticDividingLine(),
31
34
  repeat_command_groups: bool = True,
32
35
  print_func: Callable[[str], None] = Console().print) -> None:
33
36
  self._prompt = prompt
@@ -35,7 +38,7 @@ class BaseApp:
35
38
  self._exit_command = exit_command
36
39
  self._exit_command_description = exit_command_description
37
40
  self._system_points_title = system_points_title
38
- self._line_separate = line_separate
41
+ self._dividing_line = dividing_line
39
42
  self._ignore_command_register = ignore_command_register
40
43
  self._repeat_command_groups_description = repeat_command_groups
41
44
 
@@ -53,21 +56,17 @@ class BaseApp:
53
56
  self.exit_command_handler: Callable[[], None] = lambda: print_func(self.farewell_message)
54
57
 
55
58
  self._setup_default_view(is_initial_message_default=initial_message == 'Argenta',
56
- is_farewell_message_default=farewell_message == 'See you',
57
- is_line_separate_default=line_separate == '-----')
59
+ is_farewell_message_default=farewell_message == 'See you')
58
60
 
59
61
 
60
62
  def _setup_default_view(self, is_initial_message_default: bool,
61
- is_farewell_message_default: bool,
62
- is_line_separate_default: bool):
63
+ is_farewell_message_default: bool):
63
64
  if is_initial_message_default:
64
65
  self.initial_message = f'\n[bold red]{text2art('Argenta', font='tarty1')}\n\n'
65
66
  if is_farewell_message_default:
66
67
  self.farewell_message = (f'[bold red]\n{text2art('\nSee you\n', font='chanky')}[/bold red]\n'
67
68
  f'[red i]github.com/koloideal/Argenta[/red i] | '
68
69
  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'
71
70
 
72
71
 
73
72
  def _validate_number_of_routers(self) -> None:
@@ -100,7 +99,15 @@ class BaseApp:
100
99
  return False
101
100
  elif handled_command_trigger == command.get_trigger():
102
101
  return False
103
- self.unknown_command_handler(command)
102
+ if isinstance(self._dividing_line, StaticDividingLine):
103
+ self._print_func(self._dividing_line.get_full_line())
104
+ self.unknown_command_handler(command)
105
+ self._print_func(self._dividing_line.get_full_line())
106
+ elif isinstance(self._dividing_line, DynamicDividingLine):
107
+ with redirect_stdout(io.StringIO()) as f:
108
+ self.unknown_command_handler(command)
109
+ res: str = f.getvalue()
110
+ self._print_framed_text_with_dynamic_line(res)
104
111
  return True
105
112
 
106
113
 
@@ -124,6 +131,15 @@ class BaseApp:
124
131
  self.empty_input_command_handler()
125
132
 
126
133
 
134
+ def _print_framed_text_with_dynamic_line(self, text: str):
135
+ clear_text = re.sub(r'\u001b\[[0-9;]*m', '', text)
136
+ max_length_line = max([len(line) for line in clear_text.split('\n')])
137
+ max_length_line = max_length_line if 10 <= max_length_line <= 80 else 80 if max_length_line > 80 else 10
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))
141
+
142
+
127
143
 
128
144
  class App(BaseApp):
129
145
  def start_polling(self) -> None:
@@ -148,24 +164,35 @@ class App(BaseApp):
148
164
  try:
149
165
  input_command: InputCommand = InputCommand.parse(raw_command=raw_command)
150
166
  except BaseInputCommandException as error:
151
- self._print_func(self._line_separate)
152
- self._error_handler(error, raw_command)
153
- self._print_func(self._line_separate)
167
+ if isinstance(self._dividing_line, StaticDividingLine):
168
+ self._print_func(self._dividing_line.get_full_line())
169
+ self._error_handler(error, raw_command)
170
+ self._print_func(self._dividing_line.get_full_line())
171
+ elif isinstance(self._dividing_line, DynamicDividingLine):
172
+ with redirect_stdout(io.StringIO()) as f:
173
+ self._error_handler(error, raw_command)
174
+ res: str = f.getvalue()
175
+ self._print_framed_text_with_dynamic_line(res)
154
176
  continue
155
177
 
156
178
  if self._is_exit_command(input_command):
157
179
  return
158
180
 
159
- self._print_func(self._line_separate)
160
-
161
181
  if self._is_unknown_command(input_command):
162
- self._print_func(self._line_separate)
163
182
  continue
164
183
 
165
- for registered_router in self._registered_routers:
166
- registered_router.input_command_handler(input_command)
184
+ if isinstance(self._dividing_line, StaticDividingLine):
185
+ self._print_func(self._dividing_line.get_full_line())
186
+ for registered_router in self._registered_routers:
187
+ registered_router.input_command_handler(input_command)
188
+ self._print_func(self._dividing_line.get_full_line())
189
+ elif isinstance(self._dividing_line, DynamicDividingLine):
190
+ with redirect_stdout(io.StringIO()) as f:
191
+ for registered_router in self._registered_routers:
192
+ registered_router.input_command_handler(input_command)
193
+ res: str = f.getvalue()
194
+ self._print_framed_text_with_dynamic_line(res)
167
195
 
168
- self._print_func(self._line_separate)
169
196
  if not self._repeat_command_groups_description:
170
197
  self._print_func(self._prompt)
171
198
 
argenta/command/models.py CHANGED
@@ -60,6 +60,7 @@ class InputCommand(BaseCommand, Generic[InputCommandType]):
60
60
  def get_input_flags(self) -> InputFlags:
61
61
  return self._input_flags
62
62
 
63
+
63
64
  @staticmethod
64
65
  def parse(raw_command: str) -> InputCommandType:
65
66
  if not raw_command:
@@ -1,7 +1,7 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: argenta
3
- Version: 0.4.7
4
- Summary: python library for creating custom shells
3
+ Version: 0.4.8
4
+ Summary: Python library for creating TUI
5
5
  License: MIT
6
6
  Author: kolo
7
7
  Author-email: kolo.is.main@gmail.com
@@ -119,7 +119,7 @@ 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
- line_separate: str = '-----',
122
+ dividing_line: StaticDividingLine | DynamicDividingLine = StaticDividingLine(),
123
123
  repeat_command_groups: bool = True,
124
124
  print_func: Callable[[str], None] = Console().print)
125
125
  ```
@@ -132,7 +132,7 @@ App(prompt: str = 'What do you want to do?\n',
132
132
  - `exit_command_description` (`str`): Описание команды выхода.
133
133
  - `system_points_title` (`str`): Заголовок перед списком системных команд.
134
134
  - `ignore_command_register` (`bool`): Игнорировать регистр всех команд.
135
- - `line_separate` (`str`): Разделительная строка между командами.
135
+ - `dividing_line` (`StaticDividingLine | DynamicDividingLine`): Разделительная строка.
136
136
  - `repeat_command_groups` (`bool`): Повторять описание команд перед вводом.
137
137
  - `print_func` (`Callable[[str], None]`): Функция вывода текста в терминал.
138
138
 
@@ -253,6 +253,36 @@ App(prompt: str = 'What do you want to do?\n',
253
253
 
254
254
  ---
255
255
 
256
+ ## *class* :: `StaticDivideLine`
257
+ Класс, экземпляр которого представляет собой строковый разделитель фиксированной длины
258
+
259
+ ### Конструктор
260
+ ```python
261
+ StaticDivideLine(unit_part: str = '-',
262
+ length: int = 25)
263
+ ```
264
+
265
+ **Аргументы:**
266
+ - **name : mean**
267
+ - `unit_part` (`str`): Единичная часть строкового разделителя
268
+ - `length` (`int`): Длина строкового разделителя
269
+
270
+ ---
271
+
272
+ ## *class* :: `DinamicDivideLine`
273
+ Строковый разделитель динамической длины, которая определяется длиной обрамляемого вывода команды
274
+
275
+ ### Конструктор
276
+ ```python
277
+ DinamicDivideLine(unit_part: str = '-')
278
+ ```
279
+
280
+ **Аргументы:**
281
+ - **name : mean**
282
+ - `unit_part` (`str`): Единичная часть строкового разделителя
283
+
284
+ ---
285
+
256
286
  ## *class* :: `Router`
257
287
  Класс, который определяет и конфигурирует обработчики команд
258
288
 
@@ -1,8 +1,10 @@
1
1
  argenta/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
2
  argenta/app/__init__.py,sha256=Slm_0b1yaXeJ78zUpo_sDSEzYuTSj3_DhRU6wU8XU9Q,46
3
3
  argenta/app/defaults.py,sha256=7ej4G-4dieMlichfuQhw5XgabF15X-vAa8k02ZfkdUs,234
4
+ argenta/app/dividing_line/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
+ argenta/app/dividing_line/models.py,sha256=ueBDmy1hfYzGAr1X2G2Mw0hjES7YQBtP7N3TLBDz9h0,700
4
6
  argenta/app/exceptions.py,sha256=uCkb1VqEIZQuVDY0ZsfDc3yCbySwLpV5CdIT7iaGYRM,928
5
- argenta/app/models.py,sha256=IDC048SZP-jiw66x6ipz-lYOY7-CyD3mk-GHT8AyqCo,9338
7
+ argenta/app/models.py,sha256=F3r1WElR3T9-ebD7ud1GPtMOkoArmbpHbDSFKAizf4M,11165
6
8
  argenta/app/registered_routers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
9
  argenta/app/registered_routers/entity.py,sha256=OQZyrF4eoCoDHzRJ22zZxhNEx-bOUDu7NZIFDfO-fuY,688
8
10
  argenta/command/__init__.py,sha256=Yx5Zl5Diwhjs8SZrsYEBNJscTMxWkLP0nqPvAJZtu30,52
@@ -10,7 +12,7 @@ argenta/command/exceptions.py,sha256=HOgddtXLDgk9Wx6c_GnzW3bMAMU5CuUnUyxjW3cVHRo
10
12
  argenta/command/flag/__init__.py,sha256=Ew-ZRFVY7sC_PMvavN0AEcsvdYGHkLAPOYMrReY3NC0,116
11
13
  argenta/command/flag/defaults.py,sha256=ktKmDT0rSSBoFUghTlEQ6OletoFxCiD37hRzO73mUUc,875
12
14
  argenta/command/flag/models.py,sha256=IY0FHyAFD9O1ZxSaq6NR9gSTkldoQGrKVoGrAbnmEuA,3769
13
- argenta/command/models.py,sha256=4MoO22EijeoMGmwYi88BSnBrip8fre2KpULGt8-NouY,4434
15
+ argenta/command/models.py,sha256=1p_QZ5cQq47t915zHehEx-S0smTqj4DDnjZGn_qZlOA,4436
14
16
  argenta/router/__init__.py,sha256=uP58EfcmtK2NuMBQaspD_Gmq3LqgDXus4rfB6hp9Uig,52
15
17
  argenta/router/command_handler/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
16
18
  argenta/router/command_handler/entity.py,sha256=8sWhP89c0FavFBITJmH9c8wNn2ipW_6-_obzjkwXueU,646
@@ -19,7 +21,7 @@ argenta/router/command_handlers/entity.py,sha256=KgFKjAMUr_mOcn9xahTxMUKB6lIxXgq
19
21
  argenta/router/defaults.py,sha256=huftOg1HMjrT_R2SHHOL4eJ5uZHspNEYBSg-mCq9xhU,126
20
22
  argenta/router/entity.py,sha256=afQn5jrDBrcd5QUzeBwRPfazOO6x0yYSXcmvHYhJpDw,4997
21
23
  argenta/router/exceptions.py,sha256=tdeaR8zDvnytgRYo_wQWKHt3if2brapgauIhhMIsTsA,678
22
- argenta-0.4.7.dist-info/LICENSE,sha256=zmqoGh2n5rReBv4s8wPxF_gZEZDgauJYSPMuPczgOiU,1082
23
- argenta-0.4.7.dist-info/METADATA,sha256=Yq80fNHrGnZheM_3OpCM-BTsPEL93ItT1Z8ikKAh0rs,19205
24
- argenta-0.4.7.dist-info/WHEEL,sha256=XbeZDeTWKc1w7CSIyre5aMDU_-PohRwTQceYnisIYYY,88
25
- argenta-0.4.7.dist-info/RECORD,,
24
+ argenta-0.4.8.dist-info/LICENSE,sha256=zmqoGh2n5rReBv4s8wPxF_gZEZDgauJYSPMuPczgOiU,1082
25
+ argenta-0.4.8.dist-info/METADATA,sha256=JjVjgk4hSSFA8I-oe5XHz67QANNXsZq6fA88igFvxww,20238
26
+ argenta-0.4.8.dist-info/WHEEL,sha256=XbeZDeTWKc1w7CSIyre5aMDU_-PohRwTQceYnisIYYY,88
27
+ argenta-0.4.8.dist-info/RECORD,,