From ab1d335f8ed82d5c45a152b34a4dd1393ea2e297 Mon Sep 17 00:00:00 2001 From: kolo Date: Sun, 6 Apr 2025 18:57:30 +0300 Subject: [PATCH] work --- README.md | 4 ++-- argenta/app/dividing_line/__init__.py | 0 argenta/app/dividing_line/models.py | 15 +++++++++++++++ argenta/app/models.py | 13 ++++++------- mock/local_test.py | 6 ++++-- mock/mock_app/handlers/routers.py | 11 +++++++---- pyproject.toml | 2 +- 7 files changed, 35 insertions(+), 16 deletions(-) create mode 100644 argenta/app/dividing_line/__init__.py create mode 100644 argenta/app/dividing_line/models.py diff --git a/README.md b/README.md index 24e0c2c..8884e18 100644 --- a/README.md +++ b/README.md @@ -102,7 +102,7 @@ App(prompt: str = 'What do you want to do?\n', exit_command_description: str = 'Exit command', system_points_title: str = 'System points:', ignore_command_register: bool = True, - line_separate: str = '-----', + dividing_line: str = '-----', repeat_command_groups: bool = True, print_func: Callable[[str], None] = Console().print) ``` @@ -115,7 +115,7 @@ App(prompt: str = 'What do you want to do?\n', - `exit_command_description` (`str`): Описание команды выхода. - `system_points_title` (`str`): Заголовок перед списком системных команд. - `ignore_command_register` (`bool`): Игнорировать регистр всех команд. -- `line_separate` (`str`): Разделительная строка между командами. +- `dividing_line` (`str`): Разделительная строка между командами. - `repeat_command_groups` (`bool`): Повторять описание команд перед вводом. - `print_func` (`Callable[[str], None]`): Функция вывода текста в терминал. diff --git a/argenta/app/dividing_line/__init__.py b/argenta/app/dividing_line/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/argenta/app/dividing_line/models.py b/argenta/app/dividing_line/models.py new file mode 100644 index 0000000..c1b469d --- /dev/null +++ b/argenta/app/dividing_line/models.py @@ -0,0 +1,15 @@ +from collections.abc import Sized + + +def check(string: str): + if len(string) != 1: + raise ValueError + + +class BaseDividingLine: + def __init__(self, unit_part: check): + self.unit_part = unit_part + + +BaseDividingLine('sygu') + diff --git a/argenta/app/models.py b/argenta/app/models.py index 58357aa..6176f1c 100644 --- a/argenta/app/models.py +++ b/argenta/app/models.py @@ -29,7 +29,7 @@ class BaseApp: exit_command_description: str = 'Exit command', system_points_title: str = 'System points:', ignore_command_register: bool = True, - line_separate: str = '-', + dividing_line: str = '-', repeat_command_groups: bool = True, print_func: Callable[[str], None] = Console().print) -> None: self._prompt = prompt @@ -37,7 +37,7 @@ class BaseApp: self._exit_command = exit_command self._exit_command_description = exit_command_description self._system_points_title = system_points_title - self._line_separate = line_separate + self._dividing_line = dividing_line self._ignore_command_register = ignore_command_register self._repeat_command_groups_description = repeat_command_groups @@ -132,14 +132,13 @@ class BaseApp: def _print_framed_text(self, text: str): - max_length_line = max([len([char for char in line if char.isalnum()]) for line in text.split('\n')]) - with open('test.txt', 'w') as file: - file.write(text) + clear_text = re.sub(r'\u001b\[[0-9;]*m', '', text) + max_length_line = max([len(line) for line in clear_text.split('\n')]) max_length_line = max_length_line if 10 <= max_length_line <= 80 else 80 if max_length_line > 80 else 10 - self._print_func(self._make_line_separator(max_length_line, self._line_separate)) + self._print_func(self._make_line_separator(max_length_line, self._dividing_line)) print(text.strip('\n')) - self._print_func(self._make_line_separator(max_length_line, self._line_separate)) + self._print_func(self._make_line_separator(max_length_line, self._dividing_line)) diff --git a/mock/local_test.py b/mock/local_test.py index 029def5..4402a57 100644 --- a/mock/local_test.py +++ b/mock/local_test.py @@ -1,12 +1,14 @@ from contextlib import redirect_stdout import io +import string while True: with redirect_stdout(io.StringIO()) as f: - a = input('rgsert') + a = input() print(a) res = f.getvalue() + res = ''.join([x for x in res if x in string.printable]) print('-'*len(res)) - print(res.replace('\n', '')) + print(res.strip('\n')) print('-'*len(res)) diff --git a/mock/mock_app/handlers/routers.py b/mock/mock_app/handlers/routers.py index cd6f7cd..9d98b76 100644 --- a/mock/mock_app/handlers/routers.py +++ b/mock/mock_app/handlers/routers.py @@ -1,7 +1,7 @@ from rich.console import Console from argenta.command import Command -from argenta.command.flag import Flags, InputFlags +from argenta.command.flag import Flags, InputFlags, Flag from argenta.command.flag.defaults import PredeterminedFlags from argenta.router import Router from .handlers_implementation.help_command import help_command @@ -15,15 +15,18 @@ settings_router: Router = Router(title='Settings points:') console = Console() +flag = Flag('test') -@work_router.command(Command(trigger='0', description='Get Help')) + +@work_router.command(Command(trigger='0', + description='Get Help')) def command_help(): help_command() -@work_router.command(Command(trigger='S', description='Start Solving', flags=Flags(PredeterminedFlags.HOST, PredeterminedFlags.PORT))) +@work_router.command(Command(trigger='S', description='Start Solving', flags=Flags(PredeterminedFlags.HOST, PredeterminedFlags.PORT, flag))) def command_start_solving(args: InputFlags): - print(args.get_flags()) + print(args.get_flag('test')) @settings_router.command(Command(trigger='U', description='Update WordMath')) diff --git a/pyproject.toml b/pyproject.toml index ee7dc9d..32bc982 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [project] name = "argenta" version = "0.4.7" -description = "python library for creating tui" +description = "Python library for creating TUI" authors = [ {name = "kolo", email = "kolo.is.main@gmail.com"} ]