Colors can be customized in the config (fixes #edb)
authorDmitriy Morozov <dmitriy@mrzv.org>
Sat, 16 Apr 2011 11:51:16 -0700
changeset 61 c384fa42f8a2
parent 60 c933fa2cd204
child 62 30343993578e
Colors can be customized in the config (fixes #edb)
.issues/edb1a7697e0f1e24/new/1208863350.M507651P11810Q1.metatron
README
artemis/artemis.py
--- a/.issues/edb1a7697e0f1e24/new/1208863350.M507651P11810Q1.metatron	Fri Apr 15 23:10:12 2011 -0700
+++ b/.issues/edb1a7697e0f1e24/new/1208863350.M507651P11810Q1.metatron	Sat Apr 16 11:51:16 2011 -0700
@@ -1,7 +1,8 @@
 From: Dmitriy Morozov <morozov@cs.duke.edu>
 Date: Tue, 22 Apr 2008 07:21:57
-State: in-progress
+State: resolved
 Subject: Colorize output
 Message-Id: <edb1a7697e0f1e24-0-artemis@metatron>
+resolution: fixed
 
 Allow one to colorize output. Naturally with user-customizable colors.
--- a/README	Fri Apr 15 23:10:12 2011 -0700
+++ b/README	Sat Apr 16 11:51:16 2011 -0700
@@ -35,6 +35,21 @@
     [artemis]
     issues = _issues
 
+Additionally, one can define colors for the issue list, based on the
+issues' states. For example::
+
+    new.color           = red
+    new.attrs           = bold
+    resolved.color      = white
+    in-progress.color   = yellow
+    in-progress.attrs   = bold
+
+will highlight issues with the state "new" as bold red, "resolved" issues
+as white, and "in-progress" issues as bold yellow. Artemis uses termcolor_
+library for the output, see its documentation for color options.
+
+.. _`termcolor`:    http://pypi.python.org/pypi/termcolor/
+
 
 Example
 -------
--- a/artemis/artemis.py	Fri Apr 15 23:10:12 2011 -0700
+++ b/artemis/artemis.py	Sat Apr 16 11:51:16 2011 -0700
@@ -17,8 +17,8 @@
 from    termcolor       import colored
 
 
-state = { 'new':   ['new'],
-          'fixed': ['fixed', 'resolved'] }
+state = { 'new':      ['new'],
+          'resolved': ['fixed', 'resolved'] }
 annotation = { 'resolved': 'resolution' }
 default_state = 'new'
 default_issues_dir = ".issues"
@@ -79,7 +79,7 @@
             else:
                 property_match = property_match and (property not in mbox[root])
 
-        if not show_all and (not properties or not property_match) and (properties or mbox[root]['State'].upper() in [f.upper() for f in state['fixed']]): continue
+        if not show_all and (not properties or not property_match) and (properties or mbox[root]['State'].upper() in [f.upper() for f in state['resolved']]): continue
         if match_date and not date_match(util.parsedate(mbox[root]['date'])[0]): continue
 
         if not list_properties:
@@ -427,23 +427,25 @@
 
 def _read_colors(ui):
     colors = {}
-    # defaults
-    colors['new.color']             = 'red'
-    colors['new.on_color']          = 'on_grey'
-    colors['new.attrs']             = 'bold'
-    colors['resolved.color']        = 'white'
-    colors['resolved.on_color']     = ''
-    colors['resolved.attrs']        = ''
-    for v in colors:
-        colors[v] = ui.config('artemis', v, colors[v])
-        if v.endswith('attrs'): colors[v] = colors[v].split()
+
+    for k,v in ui.configitems('artemis'):
+        if k == 'issues': continue
+        k = k.split('.')
+        s = k[0]; t = k[1]
+        if s not in colors: colors[s] = {}
+        colors[s][t] = v
+
     return colors
 
 def _color_summary(line, msg, colors):
-    if msg['State'] == 'new':
-        return colored(line, colors['new.color'],      attrs = colors['new.attrs'])
-    elif msg['State'] in state['fixed']:
-        return colored(line, colors['resolved.color'], attrs = colors['resolved.attrs'])
+    s = msg['State']
+    for alias, l in state.items():
+        if s in l: s = alias; break
+    if s in colors:
+        color    = colors[s]['color']         if 'color'    in colors[s] else None
+        on_color = colors[s]['on_color']      if 'on_color' in colors[s] else None
+        attrs    = colors[s]['attrs'].split() if 'attrs'    in colors[s] else None
+        return colored(line, color, on_color, attrs)
     else:
         return line