This commit is contained in:
2025-02-09 22:47:53 +03:00
parent 684760121c
commit b4b7d5442c
5 changed files with 30 additions and 11 deletions
+23 -3
View File
@@ -14,23 +14,29 @@ from .exceptions import (InvalidRouterInstanceException,
class App: class App:
def __init__(self, def __init__(self,
prompt: str = 'Enter a command', prompt: str = 'Enter a command',
exit_command: str = 'q',
ignore_exit_command_register: bool = True,
initial_greeting: str = '\nHello, I am Argenta\n', initial_greeting: str = '\nHello, I am Argenta\n',
farewell_message: str = '\nGoodBye\n', farewell_message: str = '\nGoodBye\n',
exit_command: str = 'Q',
exit_command_description: str = 'Exit command',
exit_command_title: str = 'System points:',
ignore_exit_command_register: bool = True,
ignore_command_register: bool = False,
line_separate: str = '', line_separate: str = '',
command_group_description_separate: str = '', command_group_description_separate: str = '',
ignore_command_register: bool = False, repeat_command_groups: bool = True,
print_func: Callable[[str], None] = print) -> None: print_func: Callable[[str], None] = print) -> None:
self.prompt = prompt self.prompt = prompt
self.print_func = print_func self.print_func = print_func
self.exit_command = exit_command self.exit_command = exit_command
self.exit_command_description = exit_command_description
self.exit_command_title = exit_command_title
self.ignore_exit_command_register = ignore_exit_command_register self.ignore_exit_command_register = ignore_exit_command_register
self.farewell_message = farewell_message self.farewell_message = farewell_message
self.initial_greeting = initial_greeting self.initial_greeting = initial_greeting
self.line_separate = line_separate self.line_separate = line_separate
self.command_group_description_separate = command_group_description_separate self.command_group_description_separate = command_group_description_separate
self.ignore_command_register = ignore_command_register self.ignore_command_register = ignore_command_register
self.repeat_command_groups = repeat_command_groups
self._routers: list[Router] = [] self._routers: list[Router] = []
self._registered_router_entities: list[dict[str, str | list[dict[str, Callable[[], None] | str]] | Router]] = [] self._registered_router_entities: list[dict[str, str | list[dict[str, Callable[[], None] | str]] | Router]] = []
@@ -46,7 +52,13 @@ class App:
self.print_func(self.initial_greeting) self.print_func(self.initial_greeting)
if not self.repeat_command_groups:
self._print_command_group_description()
if self.repeat_command_groups:
self.print_func(self.prompt)
while True: while True:
if self.repeat_command_groups:
self._print_command_group_description() self._print_command_group_description()
self.print_func(self.prompt) self.print_func(self.prompt)
@@ -177,6 +189,14 @@ class App:
) )
self.print_func(self.command_group_description_separate) self.print_func(self.command_group_description_separate)
self.print_func(self.exit_command_title)
self.print_func(self._description_message_pattern.format(
command=self.exit_command,
description=self.exit_command_description
)
)
self.print_func(self.command_group_description_separate)
def include_router(self, router: Router, is_main: True | False = False) -> None: def include_router(self, router: Router, is_main: True | False = False) -> None:
if not isinstance(router, Router): if not isinstance(router, Router):
+1 -1
View File
@@ -1,6 +1,6 @@
[project] [project]
name = "argenta" name = "argenta"
version = "0.2.0" version = "0.2.1"
description = "python library for creating cli apps" description = "python library for creating cli apps"
authors = [ authors = [
{name = "kolo",email = "kolo.is.main@gmail.com"} {name = "kolo",email = "kolo.is.main@gmail.com"}
+1 -1
View File
@@ -5,7 +5,7 @@ with open("README.md", "r", encoding="utf-8") as fh:
setup( setup(
name="argenta", name="argenta",
version="0.2.0", version="0.2.1",
author="kolo", author="kolo",
author_email="kolo.is.main@gmail.com", author_email="kolo.is.main@gmail.com",
description="Python library for creating CLI apps", description="Python library for creating CLI apps",
+2 -4
View File
@@ -6,10 +6,8 @@ from ..handlers.handlers_implementation.solving_command import start_solving_com
from ..handlers.handlers_implementation.upgrade_command import upgrade_command from ..handlers.handlers_implementation.upgrade_command import upgrade_command
work_router: Router = Router(name='Work points:', work_router: Router = Router(title='Work points:')
ignore_command_register=False) settings_router: Router = Router(title='Settings points:')
settings_router: Router = Router(name='Settings points:',
ignore_command_register=True)
console = Console() console = Console()
+2 -1
View File
@@ -7,7 +7,8 @@ from rich.console import Console
app: App = App(prompt='[italic white bold]What do you want to do(enter number of action)?', app: App = App(prompt='[italic white bold]What do you want to do(enter number of action)?',
line_separate='[bold green]\n---------------------------------------------\n', line_separate='[bold green]\n---------------------------------------------\n',
print_func=Console().print, print_func=Console().print,
command_group_description_separate='') command_group_description_separate='',
repeat_command_groups=False)
def main(): def main():