mirror of
https://github.com/koloideal/Argenta.git
synced 2026-06-10 18:15:28 +03:00
refactor default view
This commit is contained in:
@@ -0,0 +1,8 @@
|
|||||||
|
from dataclasses import dataclass
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class PredeterminedMessages:
|
||||||
|
USAGE = '[b dim]Usage[/b dim]: [i]<command> <[green]flags[/green]>[/i]'
|
||||||
|
HELP = '[b dim]Help[/b dim]: [i]<command>[/i] [b red]--help[/b red]'
|
||||||
|
|
||||||
+13
-10
@@ -1,6 +1,7 @@
|
|||||||
from typing import Callable
|
from typing import Callable
|
||||||
from inspect import getfullargspec
|
from inspect import getfullargspec
|
||||||
from rich.console import Console
|
from rich.console import Console
|
||||||
|
from art import text2art
|
||||||
import re
|
import re
|
||||||
|
|
||||||
from argenta.command.models import Command, InputCommand
|
from argenta.command.models import Command, InputCommand
|
||||||
@@ -20,15 +21,17 @@ from argenta.app.registered_routers.entity import RegisteredRouters
|
|||||||
|
|
||||||
class App:
|
class App:
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
prompt: str = 'Enter a command\n',
|
prompt: str = '[italic dim bold]What do you want to do?\n',
|
||||||
initial_message: str = '\nHello, I am Argenta\n',
|
initial_message: str = f'\n[bold red]{text2art('Argenta', font='tarty1')}\n\n',
|
||||||
farewell_message: str = '\nGoodBye\n',
|
farewell_message: str = f'[bold red]\n{text2art('\nSee you\n', font='chanky')}[/bold red]\n'
|
||||||
|
f'[red i]github.com/koloideal/Argenta[/red i] | '
|
||||||
|
f'[red bold i]made by kolo[/red bold i]\n',
|
||||||
exit_command: str = 'Q',
|
exit_command: str = 'Q',
|
||||||
exit_command_description: str = 'Exit command',
|
exit_command_description: str = 'Exit command',
|
||||||
system_points_title: str = 'System points:',
|
system_points_title: str = 'System points:',
|
||||||
ignore_exit_command_register: bool = True,
|
ignore_exit_command_register: bool = True,
|
||||||
ignore_command_register: bool = False,
|
ignore_command_register: bool = True,
|
||||||
line_separate: str = '',
|
line_separate: str = f'\n[dim]{"--"*25}\n',
|
||||||
command_group_description_separate: str = '',
|
command_group_description_separate: str = '',
|
||||||
repeat_command_groups: bool = True,
|
repeat_command_groups: bool = True,
|
||||||
print_func: Callable[[str], None] = Console().print) -> None:
|
print_func: Callable[[str], None] = Console().print) -> None:
|
||||||
@@ -45,12 +48,12 @@ class App:
|
|||||||
self._ignore_command_register = ignore_command_register
|
self._ignore_command_register = ignore_command_register
|
||||||
self._repeat_command_groups_description = repeat_command_groups
|
self._repeat_command_groups_description = repeat_command_groups
|
||||||
|
|
||||||
self._description_message_pattern: str = '[{command}] *=*=* {description}'
|
self._description_message_pattern: str = '[bold red][{command}][/bold red] [blue dim]*=*=*[/blue dim] [bold yellow italic]{description}'
|
||||||
self._registered_routers: RegisteredRouters = RegisteredRouters()
|
self._registered_routers: RegisteredRouters = RegisteredRouters()
|
||||||
self._invalid_input_flags_handler: Callable[[str], None] = lambda raw_command: print_func(f'Incorrect flag syntax: "{raw_command}"')
|
self._invalid_input_flags_handler: Callable[[str], None] = lambda raw_command: print_func(f'[red bold]Incorrect flag syntax: {raw_command}')
|
||||||
self._repeated_input_flags_handler: Callable[[str], None] = lambda raw_command: print_func(f'Repeated input flags: "{raw_command}"')
|
self._repeated_input_flags_handler: Callable[[str], None] = lambda raw_command: print_func(f'[red bold]Repeated input flags: {raw_command}')
|
||||||
self._empty_input_command_handler: Callable[[], None] = lambda: print_func('Empty input command')
|
self._empty_input_command_handler: Callable[[], None] = lambda: print_func('[red bold]Empty input command')
|
||||||
self._unknown_command_handler: Callable[[InputCommand], None] = lambda command: print_func(f"Unknown command: {command.get_trigger()}")
|
self._unknown_command_handler: Callable[[InputCommand], None] = lambda command: print_func(f"[red bold]Unknown command: {command.get_trigger()}")
|
||||||
self._exit_command_handler: Callable[[], None] = lambda: print_func(self._farewell_message)
|
self._exit_command_handler: Callable[[], None] = lambda: print_func(self._farewell_message)
|
||||||
self._messages_on_startup = []
|
self._messages_on_startup = []
|
||||||
|
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ class Router:
|
|||||||
|
|
||||||
self._command_handlers: CommandHandlers = CommandHandlers()
|
self._command_handlers: CommandHandlers = CommandHandlers()
|
||||||
self._ignore_command_register: bool = False
|
self._ignore_command_register: bool = False
|
||||||
|
|
||||||
self._not_valid_flag_handler: Callable[[Flag], None] = lambda flag: print(f"Undefined or incorrect input flag: {flag.get_string_entity()}{(' '+flag.get_value()) if flag.get_value() else ''}")
|
self._not_valid_flag_handler: Callable[[Flag], None] = lambda flag: print(f"Undefined or incorrect input flag: {flag.get_string_entity()}{(' '+flag.get_value()) if flag.get_value() else ''}")
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+4
-23
@@ -1,37 +1,18 @@
|
|||||||
from mock.mock_app.handlers.routers import work_router, settings_router
|
from mock.mock_app.handlers.routers import work_router, settings_router
|
||||||
from art import text2art
|
from art import text2art
|
||||||
from rich.console import Console
|
|
||||||
|
|
||||||
from argenta.app import App
|
from argenta.app import App
|
||||||
|
from argenta.app.defaults import PredeterminedMessages
|
||||||
|
|
||||||
|
|
||||||
app: App = App(prompt='[italic white bold]What do you want to do(enter number of action)?',
|
app: App = App()
|
||||||
line_separate=f'\n{"[bold green]-[/bold green][bold red]-[/bold red]"*25}\n',
|
|
||||||
print_func=Console().print,
|
|
||||||
command_group_description_separate='ISIISISISIISISISISISISISISIISISI',
|
|
||||||
repeat_command_groups=True)
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
ascii_name: str = text2art('WordMath', font='nancyj')
|
|
||||||
initial_greeting: str = f'[bold red]\n\n{ascii_name}'
|
|
||||||
|
|
||||||
ascii_goodbye_message: str = text2art('GoodBye', font='small')
|
|
||||||
goodbye_message: str = f'[bold red]\n{ascii_goodbye_message}{' '*12}made by kolo\n'
|
|
||||||
|
|
||||||
app.include_routers(work_router, settings_router)
|
app.include_routers(work_router, settings_router)
|
||||||
|
|
||||||
app.set_initial_message(initial_greeting)
|
app.add_message_on_startup(PredeterminedMessages.USAGE)
|
||||||
app.set_farewell_message(goodbye_message)
|
app.add_message_on_startup(PredeterminedMessages.HELP + '\n\n')
|
||||||
|
|
||||||
app.add_message_on_startup('[b dim]Usage[/b dim]: [i]<command> <[green]flags[/green]>[/i]\n')
|
|
||||||
app.add_message_on_startup('[b dim]Help[/b dim]: [i]<command>[/i] [b red]--help[/b red]\n\n')
|
|
||||||
|
|
||||||
app.set_invalid_input_flags_handler(lambda raw_command: print(f"Invalid input flags: {raw_command}"))
|
|
||||||
app.set_unknown_command_handler(lambda command: print(f"Unknown command: {command.get_trigger()}"))
|
|
||||||
app.set_repeated_input_flags_handler(lambda raw_command: print(f"Repeated input flags: {raw_command}"))
|
|
||||||
|
|
||||||
app.set_description_message_pattern('[bold red][{command}][/bold red] [blue dim]*=*=*[/blue dim] [bold yellow italic]{description}')
|
|
||||||
|
|
||||||
app.start_polling()
|
app.start_polling()
|
||||||
|
|
||||||
|
|||||||
+2
-8
@@ -1,6 +1,6 @@
|
|||||||
[project]
|
[project]
|
||||||
name = "argenta"
|
name = "argenta"
|
||||||
version = "0.4.5"
|
version = "0.4.6"
|
||||||
description = "python library for creating custom shells"
|
description = "python library for creating custom shells"
|
||||||
authors = [
|
authors = [
|
||||||
{name = "kolo", email = "kolo.is.main@gmail.com"}
|
{name = "kolo", email = "kolo.is.main@gmail.com"}
|
||||||
@@ -8,7 +8,7 @@ authors = [
|
|||||||
license = {text = "MIT"}
|
license = {text = "MIT"}
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
requires-python = ">=3.11"
|
requires-python = ">=3.11"
|
||||||
dependencies = [] # no dependencies
|
dependencies = ["rich (>=14.0.0,<15.0.0)", "art (>=6.4,<7.0)"]
|
||||||
|
|
||||||
|
|
||||||
[tool.ruff]
|
[tool.ruff]
|
||||||
@@ -27,11 +27,5 @@ requires = ["poetry-core>=2.0.0,<3.0.0"]
|
|||||||
build-backend = "poetry.core.masonry.api"
|
build-backend = "poetry.core.masonry.api"
|
||||||
|
|
||||||
[tool.poetry.group.dev.dependencies]
|
[tool.poetry.group.dev.dependencies]
|
||||||
art = "^6.4"
|
|
||||||
rich = "^13.9.4"
|
|
||||||
numpy = "^2.2.2"
|
|
||||||
word2number = "^1.1"
|
|
||||||
numexpr = "^2.10.2"
|
|
||||||
requests = "^2.32.3"
|
|
||||||
pyreadline3 = "^3.5.4"
|
pyreadline3 = "^3.5.4"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user