changeset 3047:cf843dd7c345

jp (debug): new "theme" command to print colour theme according to `background` value: fix 321
author Goffi <goffi@goffi.org>
date Tue, 01 Oct 2019 22:49:11 +0200
parents d9f328374473
children 1761e4823527
files doc/jp/debug.rst sat_frontends/jp/cmd_debug.py
diffstat 2 files changed, 41 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/doc/jp/debug.rst	Tue Oct 01 22:49:10 2019 +0200
+++ b/doc/jp/debug.rst	Tue Oct 01 22:49:11 2019 +0200
@@ -77,3 +77,17 @@
 Monitor raw XML stream::
 
   $ jp debug monitor -v
+
+theme
+=====
+
+Show the colour constants in their respective colour, according to background (``light``
+or ``dark``). If backround option is not set in ``sat.conf``, it will be autodetected, and
+colour theme will be modified accordingly.
+
+example
+-------
+
+Show colours with the set background::
+
+  $ jp debug theme
--- a/sat_frontends/jp/cmd_debug.py	Tue Oct 01 22:49:10 2019 +0200
+++ b/sat_frontends/jp/cmd_debug.py	Tue Oct 01 22:49:11 2019 +0200
@@ -187,8 +187,34 @@
         self.host.bridge.register_signal("xmlLog", self.printXML, "plugin")
 
 
+class Theme(base.CommandBase):
+    def __init__(self, host):
+        base.CommandBase.__init__(
+            self, host, "theme", help=_("print colours used with your background")
+        )
+
+    def add_parser_options(self):
+        pass
+
+    async def start(self):
+        for attr in dir(C):
+            if not attr.startswith('A_'):
+                continue
+            color = getattr(C, attr)
+            if attr == 'A_LEVEL_COLORS':
+                # This constant contains multiple colors
+                self.disp('LEVEL COLORS: ', no_lf=True)
+                for idx, c in enumerate(color):
+                    last = idx == len(color)-1
+                    self.disp(c + f'LEVEL_{idx}' + A.RESET + (', ' if not last else ''), no_lf=not last)
+            else:
+                text = attr[2:]
+                self.disp(A.color(color, text))
+        self.host.quit()
+
+
 class Debug(base.CommandBase):
-    subcommands = (Bridge, Monitor)
+    subcommands = (Bridge, Monitor, Theme)
 
     def __init__(self, host):
         super(Debug, self).__init__(