From 85c379bd9e623de28e6c4c5f081e35bbabfb9e68 Mon Sep 17 00:00:00 2001 From: SantaSpeen Date: Thu, 13 Jul 2023 01:17:01 +0300 Subject: [PATCH] Minor fixes --- src/core/core.py | 3 ++- src/modules/ConsoleSystem/console_system.py | 19 +++++++------------ 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/src/core/core.py b/src/core/core.py index a8f5d37..66ab950 100644 --- a/src/core/core.py +++ b/src/core/core.py @@ -337,5 +337,6 @@ class Core: def stop(self): self.run = False self.log.info(i18n.stop) - asyncio.run(self.web_stop()) + if config.WebAPI["enabled"]: + asyncio.run(self.web_stop()) exit(0) diff --git a/src/modules/ConsoleSystem/console_system.py b/src/modules/ConsoleSystem/console_system.py index a121efb..8477da5 100644 --- a/src/modules/ConsoleSystem/console_system.py +++ b/src/modules/ConsoleSystem/console_system.py @@ -14,6 +14,7 @@ from prompt_toolkit import PromptSession, print_formatted_text, HTML from prompt_toolkit.auto_suggest import AutoSuggestFromHistory from prompt_toolkit.completion import NestedCompleter from prompt_toolkit.history import FileHistory +from prompt_toolkit.patch_stdout import patch_stdout from core import get_logger @@ -186,8 +187,12 @@ class Console: session = PromptSession(history=FileHistory('./.cmdhistory')) while True: try: - cmd_in = await session.prompt_async(self.__prompt_in, - completer=self.completer, auto_suggest=AutoSuggestFromHistory()) + with patch_stdout(): + cmd_in = await session.prompt_async( + self.__prompt_in, + completer=self.completer, + auto_suggest=AutoSuggestFromHistory() + ) cmd_s = cmd_in.split(" ") cmd = cmd_s[0] if cmd == "": @@ -210,13 +215,3 @@ class Console: def stop(self, *args, **kwargs): self.__is_run = False raise KeyboardInterrupt - - -# if __name__ == '__main__': -# c = Console() -# c.logger_hook() -# c.builtins_hook() -# log = logging.getLogger(name="name") -# log.info("Starting console") -# print("Starting console") -# asyncio.run(c.start())