argenta 0.4.7__tar.gz → 0.4.8__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.
Files changed (27) hide show
  1. {argenta-0.4.7 → argenta-0.4.8}/PKG-INFO +34 -4
  2. {argenta-0.4.7 → argenta-0.4.8}/README.md +32 -2
  3. argenta-0.4.8/argenta/app/dividing_line/models.py +24 -0
  4. {argenta-0.4.7 → argenta-0.4.8}/argenta/app/models.py +45 -18
  5. {argenta-0.4.7 → argenta-0.4.8}/argenta/command/models.py +1 -0
  6. argenta-0.4.8/argenta/router/command_handlers/__init__.py +0 -0
  7. {argenta-0.4.7 → argenta-0.4.8}/pyproject.toml +2 -2
  8. {argenta-0.4.7 → argenta-0.4.8}/LICENSE +0 -0
  9. {argenta-0.4.7 → argenta-0.4.8}/argenta/__init__.py +0 -0
  10. {argenta-0.4.7 → argenta-0.4.8}/argenta/app/__init__.py +0 -0
  11. {argenta-0.4.7 → argenta-0.4.8}/argenta/app/defaults.py +0 -0
  12. {argenta-0.4.7/argenta/app/registered_routers → argenta-0.4.8/argenta/app/dividing_line}/__init__.py +0 -0
  13. {argenta-0.4.7 → argenta-0.4.8}/argenta/app/exceptions.py +0 -0
  14. {argenta-0.4.7/argenta/router/command_handler → argenta-0.4.8/argenta/app/registered_routers}/__init__.py +0 -0
  15. {argenta-0.4.7 → argenta-0.4.8}/argenta/app/registered_routers/entity.py +0 -0
  16. {argenta-0.4.7 → argenta-0.4.8}/argenta/command/__init__.py +0 -0
  17. {argenta-0.4.7 → argenta-0.4.8}/argenta/command/exceptions.py +0 -0
  18. {argenta-0.4.7 → argenta-0.4.8}/argenta/command/flag/__init__.py +0 -0
  19. {argenta-0.4.7 → argenta-0.4.8}/argenta/command/flag/defaults.py +0 -0
  20. {argenta-0.4.7 → argenta-0.4.8}/argenta/command/flag/models.py +0 -0
  21. {argenta-0.4.7 → argenta-0.4.8}/argenta/router/__init__.py +0 -0
  22. {argenta-0.4.7/argenta/router/command_handlers → argenta-0.4.8/argenta/router/command_handler}/__init__.py +0 -0
  23. {argenta-0.4.7 → argenta-0.4.8}/argenta/router/command_handler/entity.py +0 -0
  24. {argenta-0.4.7 → argenta-0.4.8}/argenta/router/command_handlers/entity.py +0 -0
  25. {argenta-0.4.7 → argenta-0.4.8}/argenta/router/defaults.py +0 -0
  26. {argenta-0.4.7 → argenta-0.4.8}/argenta/router/entity.py +0 -0
  27. {argenta-0.4.7 → argenta-0.4.8}/argenta/router/exceptions.py +0 -0
@@ -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
 
@@ -102,7 +102,7 @@ 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
- line_separate: str = '-----',
105
+ dividing_line: StaticDividingLine | DynamicDividingLine = StaticDividingLine(),
106
106
  repeat_command_groups: bool = True,
107
107
  print_func: Callable[[str], None] = Console().print)
108
108
  ```
@@ -115,7 +115,7 @@ App(prompt: str = 'What do you want to do?\n',
115
115
  - `exit_command_description` (`str`): Описание команды выхода.
116
116
  - `system_points_title` (`str`): Заголовок перед списком системных команд.
117
117
  - `ignore_command_register` (`bool`): Игнорировать регистр всех команд.
118
- - `line_separate` (`str`): Разделительная строка между командами.
118
+ - `dividing_line` (`StaticDividingLine | DynamicDividingLine`): Разделительная строка.
119
119
  - `repeat_command_groups` (`bool`): Повторять описание команд перед вводом.
120
120
  - `print_func` (`Callable[[str], None]`): Функция вывода текста в терминал.
121
121
 
@@ -236,6 +236,36 @@ App(prompt: str = 'What do you want to do?\n',
236
236
 
237
237
  ---
238
238
 
239
+ ## *class* :: `StaticDivideLine`
240
+ Класс, экземпляр которого представляет собой строковый разделитель фиксированной длины
241
+
242
+ ### Конструктор
243
+ ```python
244
+ StaticDivideLine(unit_part: str = '-',
245
+ length: int = 25)
246
+ ```
247
+
248
+ **Аргументы:**
249
+ - **name : mean**
250
+ - `unit_part` (`str`): Единичная часть строкового разделителя
251
+ - `length` (`int`): Длина строкового разделителя
252
+
253
+ ---
254
+
255
+ ## *class* :: `DinamicDivideLine`
256
+ Строковый разделитель динамической длины, которая определяется длиной обрамляемого вывода команды
257
+
258
+ ### Конструктор
259
+ ```python
260
+ DinamicDivideLine(unit_part: str = '-')
261
+ ```
262
+
263
+ **Аргументы:**
264
+ - **name : mean**
265
+ - `unit_part` (`str`): Единичная часть строкового разделителя
266
+
267
+ ---
268
+
239
269
  ## *class* :: `Router`
240
270
  Класс, который определяет и конфигурирует обработчики команд
241
271
 
@@ -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,
@@ -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
 
@@ -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
  [project]
2
2
  name = "argenta"
3
- version = "0.4.7"
4
- description = "python library for creating custom shells"
3
+ version = "0.4.8"
4
+ description = "Python library for creating TUI"
5
5
  authors = [
6
6
  {name = "kolo", email = "kolo.is.main@gmail.com"}
7
7
  ]
File without changes
File without changes
File without changes
File without changes