# HG changeset patch # User Goffi # Date 1697635807 -7200 # Node ID 51744ad00a42bfe2878c500ddff9964683b78aab # Parent e70eff252048f6324f32242e30c7ad8b8c49e565 cli: `rich` initial integration diff -r e70eff252048 -r 51744ad00a42 libervia/cli/base.py --- a/libervia/cli/base.py Mon Oct 16 17:37:11 2023 +0200 +++ b/libervia/cli/base.py Wed Oct 18 15:30:07 2023 +0200 @@ -52,6 +52,7 @@ from libervia.frontends.tools import misc import xml.etree.ElementTree as ET # FIXME: used temporarily to manage XMLUI from collections import OrderedDict +from rich import console ## bridge handling # we get bridge name from conf and initialise the right class accordingly @@ -106,6 +107,7 @@ @attribute progress_failure(callable): method to call when progress failed by default display a message """ + self.console = console.Console(theme=C.THEME_DEFAULT) self.sat_conf = main_config self.set_color_theme() bridge_module = dynamic_import.bridge(bridge_name, 'libervia.frontends.bridge') @@ -734,6 +736,7 @@ def run(cls): cls()._run() + def _read_stdin(self, stdin_fut): """Callback called by ainput to read stdin""" line = sys.stdin.readline() @@ -1122,6 +1125,13 @@ def progress_id(self): return self.host.progress_id + @property + def console(self): + return self.host.console + + def print(self, *args, **kwargs): + self.host.console.print(*args, **kwargs) + async def set_progress_id(self, progress_id): return await self.host.set_progress_id(progress_id) diff -r e70eff252048 -r 51744ad00a42 libervia/cli/constants.py --- a/libervia/cli/constants.py Mon Oct 16 17:37:11 2023 +0200 +++ b/libervia/cli/constants.py Wed Oct 18 15:30:07 2023 +0200 @@ -19,6 +19,7 @@ from libervia.frontends.quick_frontend import constants from libervia.backend.tools.common.ansi import ANSI as A +from rich.theme import Theme class Const(constants.Const): @@ -83,3 +84,12 @@ # Files A_DIRECTORY = A.BOLD + A.FG_CYAN A_FILE = A.FG_WHITE + + # rich + THEME_DEFAULT = Theme({ + "priority_low": "green", + "priority_medium": "yellow", + "priority_high": "bold magenta", + "priority_urgent": "bold red", + "notif_title": "bold", + })