Mpaa has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/291571

Change subject: Add background colors and utility script to show color 
combinations
......................................................................

Add background colors and utility script to show color combinations

Add additional backgroung colors support.
Modify tool.Formatter to support background colors.

Add utility to show possible background/foreground combinations, in
preparation for possibility for user to select default use.

Bug: T135984
Change-Id: Iecb648176b41c9ea3a2cc4ce879526f20d75bfde
---
M pywikibot/tools/formatter.py
M pywikibot/userinterfaces/terminal_interface_base.py
M pywikibot/userinterfaces/terminal_interface_unix.py
M pywikibot/userinterfaces/terminal_interface_win32.py
A scripts/show_pywikibot_colors.py
5 files changed, 88 insertions(+), 5 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core 
refs/changes/71/291571/1

diff --git a/pywikibot/tools/formatter.py b/pywikibot/tools/formatter.py
index a571ee4..e5f3734 100644
--- a/pywikibot/tools/formatter.py
+++ b/pywikibot/tools/formatter.py
@@ -76,7 +76,7 @@
 
     def get_value(self, key, args, kwargs):
         """Get value, filling in 'color' when it is a valid color."""
-        if key == 'color' and kwargs.get('color') in self.colors:
+        if key in ['color', 'bgcolor'] and kwargs.get('color') in self.colors:
             return '\03{{{0}}}'.format(kwargs[key])
         else:
             return super(_ColorFormatter, self).get_value(key, args, kwargs)
diff --git a/pywikibot/userinterfaces/terminal_interface_base.py 
b/pywikibot/userinterfaces/terminal_interface_base.py
index 3cda2cf..b995ee1 100755
--- a/pywikibot/userinterfaces/terminal_interface_base.py
+++ b/pywikibot/userinterfaces/terminal_interface_base.py
@@ -47,8 +47,22 @@
     'lightpurple',
     'lightyellow',
     'white',
+    'Bblack',
+    'Bblue',
+    'Bgreen',
+    'Baqua',
+    'Bred',
+    'Bpurple',
+    'Byellow',
+    'Blightgray',
+    'Bgray',
+    'Blightblue',
     'Blightgreen',
+    'Blightaqua',
     'Blightred',
+    'Blightpurple',
+    'Blightyellow',
+    'Bwhite',
 ]
 
 colorTagR = re.compile('\03{(?P<name>%s|previous)}' % '|'.join(colors))
diff --git a/pywikibot/userinterfaces/terminal_interface_unix.py 
b/pywikibot/userinterfaces/terminal_interface_unix.py
index 9f37d58..9d7e286 100755
--- a/pywikibot/userinterfaces/terminal_interface_unix.py
+++ b/pywikibot/userinterfaces/terminal_interface_unix.py
@@ -31,8 +31,22 @@
     'lightpurple': chr(27) + '[95m',    # Light Purple tag (Magenta)
     'lightaqua':   chr(27) + '[96m',    # Light Aqua tag (Cyan)
     'white':       chr(27) + '[97m',    # White start tag (Bright White)
-    'Blightgreen': chr(27) + '[102m',   # Background Light Red tag
-    'Blightred':   chr(27) + '[101m',   # Background Light Green tag
+    'Bblack':       chr(27) + '[40m',   # Background Black start tag
+    'Bred':         chr(27) + '[41m',   # Background Red start tag
+    'Bgreen':       chr(27) + '[42m',   # Background Green start tag
+    'Byellow':      chr(27) + '[43m',   # Background Yellow start tag
+    'Bblue':        chr(27) + '[44m',   # Background Blue start tag
+    'Bpurple':      chr(27) + '[45m',   # Background Purple start tag (Magenta)
+    'Baqua':        chr(27) + '[46m',   # Background Aqua start tag (Cyan)
+    'Blightgray':   chr(27) + '[47m',   # Background Light gray start tag 
(White)
+    'Bgray':        chr(27) + '[100m',  # Background Gray start tag
+    'Blightred':    chr(27) + '[101m',  # Background Light Red tag
+    'Blightgreen':  chr(27) + '[102m',  # Background Light Green tag
+    'Blightyellow': chr(27) + '[103m',  # Background Light Yellow tag
+    'Blightblue':   chr(27) + '[104m',  # Background Light Blue tag
+    'Blightpurple': chr(27) + '[105m',  # Background Light Purple tag (Magenta)
+    'Blightaqua':   chr(27) + '[106m',  # Background Light Aqua tag (Cyan)
+    'Bwhite':       chr(27) + '[107m',  # Background White start tag (Bright 
White)
 }
 
 
diff --git a/pywikibot/userinterfaces/terminal_interface_win32.py 
b/pywikibot/userinterfaces/terminal_interface_win32.py
index 7c3ed10..2abb452 100755
--- a/pywikibot/userinterfaces/terminal_interface_win32.py
+++ b/pywikibot/userinterfaces/terminal_interface_win32.py
@@ -38,8 +38,23 @@
     'lightpurple': 13,
     'lightyellow': 14,
     'white':       15,
-    'Blightgreen': 32,   # background color green.
-    'Blightred':   64,   # background color red.
+    'Bblack':        0,   # Background color.
+    'Bblue':        16,   # Background color.
+    'Bgreen':       32,   # Background color.
+    'Baqua':        48,   # Background color.
+    'Bred':         64,   # Background color.
+    'Bpurple':      80,   # Background color.
+    'Byellow':      96,   # Background color.
+    'Blightgray':   112,  # Background color.
+    'Bgray':        128,  # Background color.
+    'Blightblue':   144,  # Background color.
+    'Blightgreen':  160,  # Background color.
+    'Blightaqua':   176,  # Background color.
+    'Blightred':    192,  # Background color.
+    'Blightpurple': 208,  # Background color.
+    'Blightyellow': 224,  # Background color.
+    'Bwhite':       240,  # Background color.
+
 }
 
 
diff --git a/scripts/show_pywikibot_colors.py b/scripts/show_pywikibot_colors.py
new file mode 100644
index 0000000..257312c
--- /dev/null
+++ b/scripts/show_pywikibot_colors.py
@@ -0,0 +1,40 @@
+# -*- coding: utf-8 -*-
+"""Utility to show pywikibot colors."""
+#
+# (C) Pywikibot team, 2003-2016
+#
+# Distributed under the terms of the MIT license.
+#
+from __future__ import absolute_import, unicode_literals
+
+import pywikibot
+import pywikibot.userinterfaces.terminal_interface_base as ui_ti_base
+
+from pywikibot.tools import itergroup
+from pywikibot.tools.formatter import color_format
+
+
+fg_colors = [col for col in ui_ti_base.colors if not col.startswith('B') and 
col != 'default']
+n_fg_colors = len(fg_colors)
+pt_1, pt_2 = fg_colors[0:n_fg_colors / 2], fg_colors[n_fg_colors / 2:]
+fg_colors = ['default'] + pt_1 + ['default'] + pt_2
+
+bg_colors = [col for col in ui_ti_base.colors if col.startswith('B')]
+
+max_len_fg_colors = len(max(fg_colors, key=len))  # max len of color names for 
padding
+max_len_bc_color = len(max(bg_colors, key=len))   # max len of color names for 
padding
+
+for bg_col in bg_colors:
+    # two lines per each backgoung color
+    for fc_group in itergroup(fg_colors, n_fg_colors / 2 + 1):
+        line = ''
+        for fg_col in fc_group:
+            line += ' '
+            line += color_format('{color}{bgcolor}{0}{default}',
+                                 fg_col.ljust(max_len_fg_colors),
+                                 bgcolor=bg_col, color=fg_col)
+
+        line = '{0} {1}'.format(bg_col.ljust(max_len_bc_color), line)
+        pywikibot.output(line)
+
+    pywikibot.output('')

-- 
To view, visit https://gerrit.wikimedia.org/r/291571
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iecb648176b41c9ea3a2cc4ce879526f20d75bfde
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Mpaa <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to