changeset 4129:51744ad00a42

cli: `rich` initial integration
author Goffi <goffi@goffi.org>
date Wed, 18 Oct 2023 15:30:07 +0200
parents e70eff252048
children 02f0adc745c6
files libervia/cli/base.py libervia/cli/constants.py
diffstat 2 files changed, 20 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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)
 
--- 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",
+    })