1
# Copyright (C) 2010 Canonical Ltd
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.
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.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
from __future__ import absolute_import
24
"""Unix terminal foreground color codes (16-color)."""
34
BOLD_RED = '\033[1;31m'
35
BOLD_GREEN = '\033[1;32m'
36
BOLD_YELLOW = '\033[1;33m'
37
BOLD_BLUE = '\033[1;34m'
38
BOLD_MAGENTA = '\033[1;35m'
39
BOLD_CYAN = '\033[1;36m'
40
BOLD_WHITE = '\033[1;37m'
46
"""Unix terminal background color codes (16-color)."""
59
def color_string(s, fg, bg=''):
60
return fg + bg + s + FG.NONE
63
def re_color_string(compiled_pattern, s, fg):
64
return compiled_pattern.sub(fg + r'\1' + FG.NONE, s)
68
if os.name != 'posix':
70
if not sys.stdout.isatty():
75
return curses.tigetnum('colors') > 2