~jelmer/bzr-grep/lazy

« back to all changes in this revision

Viewing changes to termcolor.py

  • Committer: Parth Malwankar
  • Date: 2010-05-22 09:43:21 UTC
  • mto: This revision was merged to the branch mainline in revision 129.
  • Revision ID: parth.malwankar@gmail.com-20100522094321-phb3z37xn59gb72k
added color for regex pattern.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
import os
 
17
import re
17
18
import sys
18
19
 
 
20
 
19
21
class FG(object):
20
22
    """Unix terminal foreground color codes (16-color)."""
21
23
    RED = '\033[31m'
37
39
 
38
40
    NONE = '\033[0m'
39
41
 
 
42
 
40
43
class BG(object):
41
44
    """Unix terminal background color codes (16-color)."""
42
45
    BLACK = '\033[40m'
50
53
 
51
54
    NONE = '\033[0m'
52
55
 
53
 
def color_string(s, fg, bg = ''):
 
56
 
 
57
def color_string(s, fg, bg=''):
54
58
    return fg + bg + s + FG.NONE
55
59
 
 
60
 
 
61
def re_color_string(compiled_pattern, s, fg):
 
62
    return compiled_pattern.sub(fg + r'\1' + FG.NONE, s)
 
63
 
 
64
 
56
65
def allow_color():
57
66
    if os.name != 'posix':
58
67
        return False