/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
0.43.2 by Parth Malwankar
added unix color codes.
1
# Copyright (C) 2010 Canonical Ltd
2
#
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
import os
0.43.4 by Parth Malwankar
initial support for color for fixed string grep.
17
import sys
0.43.2 by Parth Malwankar
added unix color codes.
18
19
class FG(object):
20
    """Unix terminal foreground color codes (16-color)."""
21
    RED = '\033[31m'
22
    GREEN = '\033[32m'
23
    YELLOW = '\033[33m'
24
    BLUE = '\033[34m'
25
    MAGENTA = '\033[35m'
26
    CYAN = '\033[36m'
27
    WHITE = '\033[37m'
28
29
    # Bold Foreground
30
    BOLD_RED = '\033[1;31m'
31
    BOLD_GREEN = '\033[1;32m'
32
    BOLD_YELLOW = '\033[1;33m'
33
    BOLD_BLUE = '\033[1;34m'
34
    BOLD_MAGENTA = '\033[1;35m'
35
    BOLD_CYAN = '\033[1;36m'
36
    BOLD_WHITE = '\033[1;37m'
37
0.43.4 by Parth Malwankar
initial support for color for fixed string grep.
38
    NONE = '\033[0m'
39
0.43.2 by Parth Malwankar
added unix color codes.
40
class BG(object):
41
    """Unix terminal background color codes (16-color)."""
42
    BLACK = '\033[40m'
43
    RED = '\033[41m'
44
    GREEN = '\033[42m'
45
    YELLOW = '\033[43m'
46
    BLUE = '\033[44m'
47
    MAGENTA = '\033[45m'
48
    CYAN = '\033[46m'
49
    WHITE = '\033[47m'
50
51
    NONE = '\033[0m'
52
0.43.4 by Parth Malwankar
initial support for color for fixed string grep.
53
def color_string(s, fg, bg = ''):
54
    return fg + bg + s + FG.NONE
55
56
def allow_color():
57
    if os.name != 'posix':
58
        return False
59
    if not sys.stdout.isatty():
60
        return False
61
    try:
62
        import curses
63
        curses.setupterm()
64
        return curses.tigetnum('colors') > 2
65
    except curses.error:
66
        return False
0.43.2 by Parth Malwankar
added unix color codes.
67