mirror of
https://github.com/kuitoi/kuitoi-Server.git
synced 2025-08-18 00:35:36 +00:00
Fix builtins_hook
This commit is contained in:
parent
c061022897
commit
56c1da1134
@ -16,6 +16,8 @@ from prompt_toolkit.auto_suggest import AutoSuggestFromHistory
|
|||||||
from prompt_toolkit.completion import NestedCompleter
|
from prompt_toolkit.completion import NestedCompleter
|
||||||
from prompt_toolkit.history import FileHistory
|
from prompt_toolkit.history import FileHistory
|
||||||
|
|
||||||
|
from core import get_logger
|
||||||
|
|
||||||
|
|
||||||
class Console:
|
class Console:
|
||||||
|
|
||||||
@ -34,6 +36,7 @@ class Console:
|
|||||||
self.__alias = dict()
|
self.__alias = dict()
|
||||||
self.__man = dict()
|
self.__man = dict()
|
||||||
self.__desc = dict()
|
self.__desc = dict()
|
||||||
|
self.__print_logger = get_logger("print")
|
||||||
self.add_command("man", self.__create_man_message, "man - display the manual page.\n"
|
self.add_command("man", self.__create_man_message, "man - display the manual page.\n"
|
||||||
"Usage: man COMMAND", "Display the manual page",
|
"Usage: man COMMAND", "Display the manual page",
|
||||||
custom_completer={"man": {}})
|
custom_completer={"man": {}})
|
||||||
@ -145,20 +148,19 @@ class Console:
|
|||||||
sep: str or None = " ",
|
sep: str or None = " ",
|
||||||
end: str or None = None,
|
end: str or None = None,
|
||||||
file: str or None = None,
|
file: str or None = None,
|
||||||
flush: bool = False,
|
flush: bool = False) -> None:
|
||||||
loading: bool = False) -> None:
|
|
||||||
self.__debug(f"Used __builtins_print; is_run: {self.__is_run}")
|
self.__debug(f"Used __builtins_print; is_run: {self.__is_run}")
|
||||||
val = list(values)
|
val = list(values)
|
||||||
if len(val) > 0:
|
if len(val) > 0:
|
||||||
val.insert(0, "\r" + self.__prompt_out)
|
# val.insert(0, "\r" + self.__prompt_out)
|
||||||
if not loading:
|
if self.__is_run:
|
||||||
if self.__is_run:
|
self.__print_logger.info(f"{' '.join(val)}\r\n{self.__prompt_in}")
|
||||||
val.append("\r\n" + self.__prompt_in + " ")
|
# val.append("\r\n" + self.__prompt_in)
|
||||||
end = "" if end is None else end
|
# end = "" if end is None else end
|
||||||
else:
|
else:
|
||||||
if end is None:
|
if end is None:
|
||||||
end = "\n"
|
end = "\n"
|
||||||
self.__print(*tuple(val), sep=sep, end=end, file=file, flush=flush)
|
self.__print(*tuple(val), sep=sep, end=end, file=file, flush=flush)
|
||||||
|
|
||||||
def logger_hook(self) -> None:
|
def logger_hook(self) -> None:
|
||||||
self.__debug("used logger_hook")
|
self.__debug("used logger_hook")
|
||||||
@ -167,7 +169,7 @@ class Console:
|
|||||||
try:
|
try:
|
||||||
msg = cls.format(record)
|
msg = cls.format(record)
|
||||||
if cls.stream.name == "<stderr>":
|
if cls.stream.name == "<stderr>":
|
||||||
self.write(f"{msg}")
|
self.write(f"\r{msg}")
|
||||||
else:
|
else:
|
||||||
cls.stream.write(msg + cls.terminator)
|
cls.stream.write(msg + cls.terminator)
|
||||||
cls.flush()
|
cls.flush()
|
||||||
@ -216,11 +218,11 @@ class Console:
|
|||||||
raise KeyboardInterrupt
|
raise KeyboardInterrupt
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
# if __name__ == '__main__':
|
||||||
c = Console()
|
# c = Console()
|
||||||
c.logger_hook()
|
# c.logger_hook()
|
||||||
c.builtins_hook()
|
# c.builtins_hook()
|
||||||
log = logging.getLogger(name="name")
|
# log = logging.getLogger(name="name")
|
||||||
log.info("Starting console")
|
# log.info("Starting console")
|
||||||
print("Starting console")
|
# print("Starting console")
|
||||||
asyncio.run(c.start())
|
# asyncio.run(c.start())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user