From 57bae9f291043515df2aa90d19a0ee9e5c70489f Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Mon, 15 Mar 2021 18:36:59 +0100 Subject: [PATCH] Console bugfixes --- .gitignore | 2 +- cpl.json | 2 +- src/cpl/console/console.py | 6 ++++- src/tests/custom/cpl-test/cpl.json | 2 +- src/tests/custom/cpl-test/src/main.py | 3 +++ .../cpl-test/src/{test => model}/__init__.py | 0 .../custom/cpl-test/src/model/test_model.py | 22 +++++++++++++++++++ src/tests/custom/general/application.py | 2 +- 8 files changed, 34 insertions(+), 5 deletions(-) rename src/tests/custom/cpl-test/src/{test => model}/__init__.py (100%) create mode 100644 src/tests/custom/cpl-test/src/model/test_model.py diff --git a/.gitignore b/.gitignore index 18dfc2c2..d9c65a9f 100644 --- a/.gitignore +++ b/.gitignore @@ -37,7 +37,7 @@ MANIFEST pip-log.txt pip-delete-this-directory.txt -# Unit test / coverage reports +# Unit model / coverage reports htmlcov/ .tox/ .nox/ diff --git a/cpl.json b/cpl.json index 33f492dc..e90047d2 100644 --- a/cpl.json +++ b/cpl.json @@ -4,7 +4,7 @@ "Version": { "Major": "2021", "Minor": "04", - "Micro": "01-4" + "Micro": "01-5" }, "Author": "Sven Heidemann", "AuthorEmail": "sven.heidemann@sh-edraft.de", diff --git a/src/cpl/console/console.py b/src/cpl/console/console.py index 8b6f3ace..e0c0d53b 100644 --- a/src/cpl/console/console.py +++ b/src/cpl/console/console.py @@ -155,7 +155,11 @@ class Console: for i in range(0, len(cls._select_menu_items)): Console.set_foreground_color(cls._selected_menu_cursor_foreground_color) Console.set_background_color(cls._selected_menu_cursor_background_color) - Console.write_line(f'{cls._selected_menu_item_char if cls._selected_menu_item_index == i else " "} ') + placeholder = '' + for _ in cls._selected_menu_item_char: + placeholder += ' ' + + Console.write_line(f'{cls._selected_menu_item_char if cls._selected_menu_item_index == i else placeholder} ') Console.set_foreground_color(cls._selected_menu_option_foreground_color) Console.set_background_color(cls._selected_menu_option_background_color) Console.write(f'{cls._select_menu_items[i]}') diff --git a/src/tests/custom/cpl-test/cpl.json b/src/tests/custom/cpl-test/cpl.json index 375c8d57..26b89f64 100644 --- a/src/tests/custom/cpl-test/cpl.json +++ b/src/tests/custom/cpl-test/cpl.json @@ -16,7 +16,7 @@ "LicenseName": "", "LicenseDescription": "", "Dependencies": [ - "sh_cpl==2021.4.1.post3" + "sh_cpl==2021.4.1.post4" ], "PythonVersion": ">=3.9.2", "Classifiers": [] diff --git a/src/tests/custom/cpl-test/src/main.py b/src/tests/custom/cpl-test/src/main.py index dd92a83d..f104c661 100644 --- a/src/tests/custom/cpl-test/src/main.py +++ b/src/tests/custom/cpl-test/src/main.py @@ -1,9 +1,12 @@ from cpl.console.console import Console +from model.test_model import TestModel + def main(): Console.write_line('Hello World') Console.write_line('Dies ist ein test') + test = TestModel() if __name__ == '__main__': diff --git a/src/tests/custom/cpl-test/src/test/__init__.py b/src/tests/custom/cpl-test/src/model/__init__.py similarity index 100% rename from src/tests/custom/cpl-test/src/test/__init__.py rename to src/tests/custom/cpl-test/src/model/__init__.py diff --git a/src/tests/custom/cpl-test/src/model/test_model.py b/src/tests/custom/cpl-test/src/model/test_model.py new file mode 100644 index 00000000..63f50640 --- /dev/null +++ b/src/tests/custom/cpl-test/src/model/test_model.py @@ -0,0 +1,22 @@ +import time + +from cpl.console import Console + + +class TestModel: + + def __init__(self): + Console.spinner('Waiting: ', self._wait, 3) + option = Console.select('->', 'Select option: ', [ + 'Option 1', + 'Option 2', + 'Option 3', + 'Option 4', + 'Option 5', + 'Option 6' + ]) + Console.write_line('You selected', option) + + @staticmethod + def _wait(count: int): + time.sleep(count) diff --git a/src/tests/custom/general/application.py b/src/tests/custom/general/application.py index 3a27bc2e..51286524 100644 --- a/src/tests/custom/general/application.py +++ b/src/tests/custom/general/application.py @@ -27,7 +27,7 @@ class Application(ApplicationABC): self._mailer.send_mail(mail) def test_console(self): - self._logger.debug(__name__, 'Started console_old test') + self._logger.debug(__name__, 'Started console_old model') Console.write_line('Hello World') Console.write('\nName: ') Console.write_line(' Hello', Console.read_line())