LSSTApplications  10.0+286,10.0+36,10.0+46,10.0-2-g4f67435,10.1+152,10.1+37,11.0,11.0+1,11.0-1-g47edd16,11.0-1-g60db491,11.0-1-g7418c06,11.0-2-g04d2804,11.0-2-g68503cd,11.0-2-g818369d,11.0-2-gb8b8ce7
LSSTDataManagementBasePackage
Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Private Attributes | Static Private Attributes | List of all members
lsst.pex.config.history.Color Class Reference
Inheritance diagram for lsst.pex.config.history.Color:

Public Member Functions

def __init__
 
def __str__
 

Static Public Member Functions

def colorize
 

Public Attributes

 rawText
 

Static Public Attributes

tuple categories
 
dictionary colors
 

Private Attributes

 _code
 

Static Private Attributes

 _colorize = True
 

Detailed Description

Definition at line 30 of file history.py.

Constructor & Destructor Documentation

def lsst.pex.config.history.Color.__init__ (   self,
  text,
  category 
)
Return a string that should display as coloured on a conformant terminal

Definition at line 52 of file history.py.

52 
53  def __init__(self, text, category):
54  """Return a string that should display as coloured on a conformant terminal"""
55  try:
56  color = Color.categories[category]
57  except KeyError:
58  raise RuntimeError("Unknown category: %s" % category)
59 
60  self.rawText = str(text)
61  x = color.lower().split(";")
62  self.color, bold = x.pop(0), False
63  if x:
64  props = x.pop(0)
65  if props in ("bold",):
66  bold = True
67 
68  try:
69  self._code = "%s" % (30 + Color.colors[self.color])
70  except KeyError:
71  raise RuntimeError("Unknown colour: %s" % self.color)
72 
73  if bold:
74  self._code += ";1"

Member Function Documentation

def lsst.pex.config.history.Color.__str__ (   self)

Definition at line 98 of file history.py.

98 
99  def __str__(self):
100  if not self.colorize():
101  return self.rawText
102 
103  base = "\033["
104 
105  prefix = base + self._code + "m"
106  suffix = base + "m"
107 
108  return prefix + self.rawText + suffix
109 
def lsst.pex.config.history.Color.colorize (   val = None)
static
Should I colour strings?  With an argument, set the value

Definition at line 76 of file history.py.

76 
77  def colorize(val=None):
78  """Should I colour strings? With an argument, set the value"""
79 
80  if val is not None:
81  Color._colorize = val
82 
83  if isinstance(val, dict):
84  unknown = []
85  for k in val.keys():
86  if Color.categories.has_key(k):
87  if Color.colors.has_key(val[k]):
88  Color.categories[k] = val[k]
89  else:
90  print >> sys.stderr, "Unknown colour %s for category %s" % (val[k], k)
91  else:
92  unknown.append(k)
93 
94  if unknown:
95  print >> sys.stderr, "Unknown colourizing category: %s" % " ".join(unknown)
96 
97  return Color._colorize

Member Data Documentation

lsst.pex.config.history.Color._code
private

Definition at line 68 of file history.py.

lsst.pex.config.history.Color._colorize = True
staticprivate

Definition at line 50 of file history.py.

tuple lsst.pex.config.history.Color.categories
static
Initial value:
1 = dict(
2  NAME = "blue",
3  VALUE = "yellow",
4  FILE = "green",
5  TEXT = "red",
6  FUNCTION_NAME = "blue",
7  )

Definition at line 31 of file history.py.

dictionary lsst.pex.config.history.Color.colors
static
Initial value:
1 = {
2  "black" : 0,
3  "red" : 1,
4  "green" : 2,
5  "yellow" : 3,
6  "blue" : 4,
7  "magenta": 5,
8  "cyan" : 6,
9  "white" : 7,
10  }

Definition at line 39 of file history.py.

lsst.pex.config.history.Color.rawText

Definition at line 59 of file history.py.


The documentation for this class was generated from the following file: