argenta 0.4.9__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 CHANGED
@@ -1,3 +1,3 @@
1
1
  __all__ = ["App"]
2
2
 
3
- from .models import App
3
+ from argenta.app.models import App
argenta/app/models.py CHANGED
@@ -21,7 +21,7 @@ from argenta.app.registered_routers.entity import RegisteredRouters
21
21
 
22
22
 
23
23
 
24
- class BaseApp:
24
+ class AppInit:
25
25
  def __init__(self,
26
26
  prompt: str = '[italic dim bold]What do you want to do?\n',
27
27
  initial_message: str = '\nArgenta\n',
@@ -44,40 +44,72 @@ class BaseApp:
44
44
  self._repeat_command_groups_description = repeat_command_groups
45
45
  self._full_override_system_messages = full_override_system_messages
46
46
 
47
- self.farewell_message = farewell_message
48
- self.initial_message = initial_message
47
+ self._farewell_message = farewell_message
48
+ self._initial_message = initial_message
49
49
 
50
50
  self._description_message_pattern: str = '[bold red][{command}][/bold red] [blue dim]*=*=*[/blue dim] [bold yellow italic]{description}'
51
51
  self._registered_routers: RegisteredRouters = RegisteredRouters()
52
52
  self._messages_on_startup = []
53
53
 
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)
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)
59
59
 
60
- self._setup_default_view()
61
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)
62
65
 
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')
66
+ if bool(first_check) and bool(second_check):
67
+ self._description_message_pattern: str = pattern
68
+ else:
69
+ raise InvalidDescriptionMessagePatternException(pattern)
68
70
 
69
71
 
70
- def _validate_number_of_routers(self) -> None:
71
- if not self._registered_routers:
72
- raise NoRegisteredRoutersException()
72
+ def set_invalid_input_flags_handler(self, handler: Callable[[str], None]) -> None:
73
+ self._invalid_input_flags_handler = handler
73
74
 
74
75
 
75
- def _validate_included_routers(self) -> None:
76
- for router in self._registered_routers:
77
- if not router.get_command_handlers():
78
- raise NoRegisteredHandlersException(router.get_name())
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
+
79
83
 
84
+ def set_empty_command_handler(self, handler: Callable[[], None]) -> None:
85
+ self._empty_input_command_handler = handler
80
86
 
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):
81
113
  def _is_exit_command(self, command: InputCommand):
82
114
  if command.get_trigger().lower() == self._exit_command.lower():
83
115
  if self._ignore_command_register:
@@ -99,53 +131,64 @@ class BaseApp:
99
131
  return False
100
132
  if isinstance(self._dividing_line, StaticDividingLine):
101
133
  self._print_func(self._dividing_line.get_full_line())
102
- self.unknown_command_handler(command)
134
+ self._unknown_command_handler(command)
103
135
  self._print_func(self._dividing_line.get_full_line())
104
136
  elif isinstance(self._dividing_line, DynamicDividingLine):
105
137
  with redirect_stdout(io.StringIO()) as f:
106
- self.unknown_command_handler(command)
138
+ self._unknown_command_handler(command)
107
139
  res: str = f.getvalue()
108
140
  self._print_framed_text_with_dynamic_line(res)
109
141
  return True
110
142
 
111
143
 
112
- def _print_command_group_description(self):
113
- for registered_router in self._registered_routers:
114
- self._print_func(registered_router.get_title())
115
- for command_handler in registered_router.get_command_handlers():
116
- self._print_func(self._description_message_pattern.format(
117
- command=command_handler.get_handled_command().get_trigger(),
118
- description=command_handler.get_handled_command().get_description()))
119
- self._print_func('')
120
-
121
-
122
144
  def _error_handler(self, error: BaseInputCommandException, raw_command: str) -> None:
123
145
  match error:
124
146
  case UnprocessedInputFlagException():
125
- self.invalid_input_flags_handler(raw_command)
147
+ self._invalid_input_flags_handler(raw_command)
126
148
  case RepeatedInputFlagsException():
127
- self.repeated_input_flags_handler(raw_command)
149
+ self._repeated_input_flags_handler(raw_command)
128
150
  case EmptyInputCommandException():
129
- self.empty_input_command_handler()
151
+ self._empty_input_command_handler()
130
152
 
131
153
 
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))
154
+ class AppValidators(AppInit):
155
+ def _validate_number_of_routers(self) -> None:
156
+ if not self._registered_routers:
157
+ raise NoRegisteredRoutersException()
139
158
 
140
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())
141
164
 
142
- class App(BaseApp):
143
- def start_polling(self) -> None:
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()
144
187
  self._setup_system_router()
145
188
  self._validate_number_of_routers()
146
189
  self._validate_included_routers()
147
190
 
148
- self._print_func(self.initial_message)
191
+ self._print_func(self._initial_message)
149
192
 
150
193
  for message in self._messages_on_startup:
151
194
  self._print_func(message)
@@ -153,6 +196,10 @@ class App(BaseApp):
153
196
  if not self._repeat_command_groups_description:
154
197
  self._print_command_group_description()
155
198
 
199
+
200
+ class App(AppSetters, AppNonStandardHandlers, AppSetups):
201
+ def start_polling(self) -> None:
202
+ self._pre_cycle_setup()
156
203
  while True:
157
204
  if self._repeat_command_groups_description:
158
205
  self._print_command_group_description()
@@ -211,24 +258,3 @@ class App(BaseApp):
211
258
  def add_message_on_startup(self, message: str) -> None:
212
259
  self._messages_on_startup.append(message)
213
260
 
214
-
215
- def set_description_message_pattern(self, pattern: str) -> None:
216
- first_check = re.match(r'.*{command}.*', pattern)
217
- second_check = re.match(r'.*{description}.*', pattern)
218
-
219
- if bool(first_check) and bool(second_check):
220
- self._description_message_pattern: str = pattern
221
- else:
222
- raise InvalidDescriptionMessagePatternException(pattern)
223
-
224
-
225
- def _setup_system_router(self):
226
- system_router.set_title(self._system_points_title)
227
- @system_router.command(Command(self._exit_command, self._exit_command_description))
228
- def exit_command():
229
- self.exit_command_handler()
230
-
231
- if system_router not in self._registered_routers.get_registered_routers():
232
- self.include_router(system_router)
233
-
234
-
@@ -1,3 +1,3 @@
1
1
  __all__ = ["Command"]
2
2
 
3
- from .models import Command
3
+ from argenta.command.models import Command
@@ -1,4 +1,4 @@
1
1
  __all__ = ('InputFlags', 'InputFlag', 'Flag', 'Flags')
2
2
 
3
3
 
4
- from .models import InputFlags, InputFlag, Flags, Flag
4
+ from argenta.command.flag.models import InputFlags, InputFlag, Flags, Flag
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: argenta
3
- Version: 0.4.9
3
+ Version: 0.4.10
4
4
  Summary: Python library for creating TUI
5
5
  License: MIT
6
6
  Author: kolo
@@ -1,15 +1,15 @@
1
1
  argenta/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- argenta/app/__init__.py,sha256=Slm_0b1yaXeJ78zUpo_sDSEzYuTSj3_DhRU6wU8XU9Q,46
2
+ argenta/app/__init__.py,sha256=I8FTXU17ajDI-hbC6Rw0LxLmvDYipdQaos3v1pmu14E,57
3
3
  argenta/app/defaults.py,sha256=7ej4G-4dieMlichfuQhw5XgabF15X-vAa8k02ZfkdUs,234
4
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=DewbYMRXkVEkjkqkfeoZ3ST89-ZtDSSXRSidG4frqac,11023
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=Yx5Zl5Diwhjs8SZrsYEBNJscTMxWkLP0nqPvAJZtu30,52
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=Ew-ZRFVY7sC_PMvavN0AEcsvdYGHkLAPOYMrReY3NC0,116
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
@@ -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.9.dist-info/LICENSE,sha256=zmqoGh2n5rReBv4s8wPxF_gZEZDgauJYSPMuPczgOiU,1082
25
- argenta-0.4.9.dist-info/METADATA,sha256=Aqr7MkZ6wKpULTCSW7pIy42b7N0VoCgii34Ko6XFfUs,20985
26
- argenta-0.4.9.dist-info/WHEEL,sha256=XbeZDeTWKc1w7CSIyre5aMDU_-PohRwTQceYnisIYYY,88
27
- argenta-0.4.9.dist-info/RECORD,,
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,,