mirror of
https://github.com/koloideal/Argenta.git
synced 2026-06-10 10:05:28 +03:00
0.5.0-alpha: support autocomplete, aliases for command, fix many bugs and other
This commit is contained in:
@@ -3,4 +3,5 @@
|
|||||||
dist
|
dist
|
||||||
poetry.lock
|
poetry.lock
|
||||||
*__pycache__/
|
*__pycache__/
|
||||||
|
*.hist*
|
||||||
|
|
||||||
|
|||||||
@@ -27,9 +27,8 @@ class AppInit:
|
|||||||
prompt: str = '[italic dim bold]What do you want to do?\n',
|
prompt: str = '[italic dim bold]What do you want to do?\n',
|
||||||
initial_message: str = '\nArgenta\n',
|
initial_message: str = '\nArgenta\n',
|
||||||
farewell_message: str = '\nSee you\n',
|
farewell_message: str = '\nSee you\n',
|
||||||
exit_command: str = 'Q',
|
exit_command: Command = Command('Q', 'Exit command'),
|
||||||
exit_command_description: str = 'Exit command',
|
system_points_title: str | None = 'System points:',
|
||||||
system_points_title: str = 'System points:',
|
|
||||||
ignore_command_register: bool = True,
|
ignore_command_register: bool = True,
|
||||||
dividing_line: StaticDividingLine | DynamicDividingLine = StaticDividingLine(),
|
dividing_line: StaticDividingLine | DynamicDividingLine = StaticDividingLine(),
|
||||||
repeat_command_groups: bool = True,
|
repeat_command_groups: bool = True,
|
||||||
@@ -39,7 +38,6 @@ class AppInit:
|
|||||||
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._system_points_title = system_points_title
|
self._system_points_title = system_points_title
|
||||||
self._dividing_line = dividing_line
|
self._dividing_line = dividing_line
|
||||||
self._ignore_command_register = ignore_command_register
|
self._ignore_command_register = ignore_command_register
|
||||||
@@ -90,7 +88,8 @@ class AppSetters(AppInit):
|
|||||||
class AppPrinters(AppInit):
|
class AppPrinters(AppInit):
|
||||||
def _print_command_group_description(self):
|
def _print_command_group_description(self):
|
||||||
for registered_router in self._registered_routers:
|
for registered_router in self._registered_routers:
|
||||||
self._print_func(registered_router.get_title())
|
if registered_router.get_title():
|
||||||
|
self._print_func(registered_router.get_title())
|
||||||
for command_handler in registered_router.get_command_handlers():
|
for command_handler in registered_router.get_command_handlers():
|
||||||
self._print_func(self._description_message_gen(
|
self._print_func(self._description_message_gen(
|
||||||
command_handler.get_handled_command().get_trigger(),
|
command_handler.get_handled_command().get_trigger(),
|
||||||
@@ -109,7 +108,7 @@ class AppPrinters(AppInit):
|
|||||||
|
|
||||||
class AppNonStandardHandlers(AppPrinters):
|
class AppNonStandardHandlers(AppPrinters):
|
||||||
def _is_exit_command(self, command: InputCommand):
|
def _is_exit_command(self, command: InputCommand):
|
||||||
if command.get_trigger().lower() == self._exit_command.lower():
|
if command.get_trigger().lower() == self._exit_command.get_trigger().lower():
|
||||||
if self._ignore_command_register:
|
if self._ignore_command_register:
|
||||||
system_router.input_command_handler(command)
|
system_router.input_command_handler(command)
|
||||||
return True
|
return True
|
||||||
@@ -165,7 +164,7 @@ class AppSetups(AppValidators, AppPrinters):
|
|||||||
def _setup_system_router(self):
|
def _setup_system_router(self):
|
||||||
system_router.set_title(self._system_points_title)
|
system_router.set_title(self._system_points_title)
|
||||||
|
|
||||||
@system_router.command(Command(self._exit_command, self._exit_command_description))
|
@system_router.command(self._exit_command)
|
||||||
def exit_command():
|
def exit_command():
|
||||||
self._exit_command_handler()
|
self._exit_command_handler()
|
||||||
|
|
||||||
|
|||||||
@@ -19,14 +19,19 @@ class BaseCommand:
|
|||||||
class Command(BaseCommand):
|
class Command(BaseCommand):
|
||||||
def __init__(self, trigger: str,
|
def __init__(self, trigger: str,
|
||||||
description: str = None,
|
description: str = None,
|
||||||
flags: Flag | Flags = None):
|
flags: Flag | Flags = None,
|
||||||
|
aliases: list[str] = None):
|
||||||
super().__init__(trigger)
|
super().__init__(trigger)
|
||||||
self._registered_flags: Flags = flags if isinstance(flags, Flags) else Flags(flags) if isinstance(flags, Flag) else Flags()
|
self._registered_flags: Flags = flags if isinstance(flags, Flags) else Flags(flags) if isinstance(flags, Flag) else Flags()
|
||||||
self._description = f'description for "{self._trigger}" command' if not description else description
|
self._description = f'Description for "{self._trigger}" command' if not description else description
|
||||||
|
self._aliases = aliases
|
||||||
|
|
||||||
def get_registered_flags(self) -> Flags:
|
def get_registered_flags(self) -> Flags:
|
||||||
return self._registered_flags
|
return self._registered_flags
|
||||||
|
|
||||||
|
def get_aliases(self) -> list[str] | None:
|
||||||
|
return self._aliases
|
||||||
|
|
||||||
def validate_input_flag(self, flag: InputFlag):
|
def validate_input_flag(self, flag: InputFlag):
|
||||||
registered_flags: Flags | None = self.get_registered_flags()
|
registered_flags: Flags | None = self.get_registered_flags()
|
||||||
if registered_flags:
|
if registered_flags:
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ from argenta.router.exceptions import (RepeatedFlagNameException,
|
|||||||
|
|
||||||
class Router:
|
class Router:
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
title: str = 'Commands group title:',
|
title: str = None,
|
||||||
name: str = 'Default'):
|
name: str = 'Default'):
|
||||||
self._title = title
|
self._title = title
|
||||||
self._name = name
|
self._name = name
|
||||||
@@ -125,7 +125,7 @@ class Router:
|
|||||||
return self._name
|
return self._name
|
||||||
|
|
||||||
|
|
||||||
def get_title(self) -> str:
|
def get_title(self) -> str | None:
|
||||||
return self._title
|
return self._title
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ from .handlers_implementation.help_command import help_command
|
|||||||
|
|
||||||
work_router: Router = Router(title='Work points:')
|
work_router: Router = Router(title='Work points:')
|
||||||
|
|
||||||
settings_router: Router = Router(title='Settings points:')
|
settings_router: Router = Router()
|
||||||
|
|
||||||
console = Console()
|
console = Console()
|
||||||
|
|
||||||
|
|||||||
@@ -6,9 +6,10 @@ from argenta.app.dividing_line import DynamicDividingLine
|
|||||||
from argenta.app.autocompleter import AutoCompleter
|
from argenta.app.autocompleter import AutoCompleter
|
||||||
|
|
||||||
|
|
||||||
autocompleter = AutoCompleter()
|
autocompleter = AutoCompleter('./mock/.hist')
|
||||||
app: App = App(dividing_line=DynamicDividingLine(),
|
app: App = App(dividing_line=DynamicDividingLine(),
|
||||||
autocompleter=autocompleter)
|
autocompleter=autocompleter,
|
||||||
|
system_points_title=None)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
[project]
|
[project]
|
||||||
name = "argenta"
|
name = "argenta"
|
||||||
version = "0.4.10"
|
version = "0.5.0-alpha"
|
||||||
description = "Python library for creating TUI"
|
description = "Python library for creating TUI"
|
||||||
authors = [
|
authors = [
|
||||||
{name = "kolo", email = "kolo.is.main@gmail.com"}
|
{name = "kolo", email = "kolo.is.main@gmail.com"}
|
||||||
|
|||||||
Reference in New Issue
Block a user