Mercurial > libervia-backend
comparison libervia/cli/base.py @ 4129:51744ad00a42
cli: `rich` initial integration
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 18 Oct 2023 15:30:07 +0200 |
parents | 47401850dec6 |
children | 33fd658d9d00 |
comparison
equal
deleted
inserted
replaced
4128:e70eff252048 | 4129:51744ad00a42 |
---|---|
50 from libervia.cli.constants import Const as C | 50 from libervia.cli.constants import Const as C |
51 from libervia.frontends.bridge.bridge_frontend import BridgeException | 51 from libervia.frontends.bridge.bridge_frontend import BridgeException |
52 from libervia.frontends.tools import misc | 52 from libervia.frontends.tools import misc |
53 import xml.etree.ElementTree as ET # FIXME: used temporarily to manage XMLUI | 53 import xml.etree.ElementTree as ET # FIXME: used temporarily to manage XMLUI |
54 from collections import OrderedDict | 54 from collections import OrderedDict |
55 from rich import console | |
55 | 56 |
56 ## bridge handling | 57 ## bridge handling |
57 # we get bridge name from conf and initialise the right class accordingly | 58 # we get bridge name from conf and initialise the right class accordingly |
58 main_config = config.parse_main_conf() | 59 main_config = config.parse_main_conf() |
59 bridge_name = config.config_get(main_config, '', 'bridge', 'dbus') | 60 bridge_name = config.config_get(main_config, '', 'bridge', 'dbus') |
104 @attribute progress_success(callable): method to call when progress is | 105 @attribute progress_success(callable): method to call when progress is |
105 successfully finished by default display a message | 106 successfully finished by default display a message |
106 @attribute progress_failure(callable): method to call when progress failed | 107 @attribute progress_failure(callable): method to call when progress failed |
107 by default display a message | 108 by default display a message |
108 """ | 109 """ |
110 self.console = console.Console(theme=C.THEME_DEFAULT) | |
109 self.sat_conf = main_config | 111 self.sat_conf = main_config |
110 self.set_color_theme() | 112 self.set_color_theme() |
111 bridge_module = dynamic_import.bridge(bridge_name, 'libervia.frontends.bridge') | 113 bridge_module = dynamic_import.bridge(bridge_name, 'libervia.frontends.bridge') |
112 if bridge_module is None: | 114 if bridge_module is None: |
113 log.error("Can't import {} bridge".format(bridge_name)) | 115 log.error("Can't import {} bridge".format(bridge_name)) |
732 | 734 |
733 @classmethod | 735 @classmethod |
734 def run(cls): | 736 def run(cls): |
735 cls()._run() | 737 cls()._run() |
736 | 738 |
739 | |
737 def _read_stdin(self, stdin_fut): | 740 def _read_stdin(self, stdin_fut): |
738 """Callback called by ainput to read stdin""" | 741 """Callback called by ainput to read stdin""" |
739 line = sys.stdin.readline() | 742 line = sys.stdin.readline() |
740 if line: | 743 if line: |
741 stdin_fut.set_result(line.rstrip(os.linesep)) | 744 stdin_fut.set_result(line.rstrip(os.linesep)) |
1120 | 1123 |
1121 @property | 1124 @property |
1122 def progress_id(self): | 1125 def progress_id(self): |
1123 return self.host.progress_id | 1126 return self.host.progress_id |
1124 | 1127 |
1128 @property | |
1129 def console(self): | |
1130 return self.host.console | |
1131 | |
1132 def print(self, *args, **kwargs): | |
1133 self.host.console.print(*args, **kwargs) | |
1134 | |
1125 async def set_progress_id(self, progress_id): | 1135 async def set_progress_id(self, progress_id): |
1126 return await self.host.set_progress_id(progress_id) | 1136 return await self.host.set_progress_id(progress_id) |
1127 | 1137 |
1128 async def progress_started_handler(self, uid, metadata, profile): | 1138 async def progress_started_handler(self, uid, metadata, profile): |
1129 if profile != self.profile: | 1139 if profile != self.profile: |