color.py
Go to the documentation of this file.
1 from __future__ import print_function
2 import sys
3 
4 # bold colors
5 _ansi = {'red': 91, 'yellow': 93}
6 
7 def is_tty(stream): # taken from catkin_tools/common.py
8  """Returns True if the given stream is a tty, else False"""
9  return hasattr(stream, 'isatty') and stream.isatty()
10 
11 
12 def colorize(msg, color, file=sys.stderr, alt_text=None):
13  if color and is_tty(file):
14  return '\033[%dm%s\033[0m' % (_ansi[color], msg)
15  elif alt_text:
16  return '%s%s' % (alt_text, msg)
17  else:
18  return msg
19 
20 
21 def message(msg, *args, **kwargs):
22  file = kwargs.get('file', sys.stderr)
23  alt_text = kwargs.get('alt_text', None)
24  color = kwargs.get('color', None)
25  print(colorize(msg, color, file, alt_text), *args, file=file)
26 
27 
28 def warning(*args, **kwargs):
29  defaults = dict(file=sys.stderr, alt_text='warning: ', color='yellow')
30  defaults.update(kwargs)
31  message(*args, **defaults)
32 
33 
34 def error(*args, **kwargs):
35  defaults = dict(file=sys.stderr, alt_text='error: ', color='red')
36  defaults.update(kwargs)
37  message(*args, **defaults)
def is_tty(stream)
Definition: color.py:7
def error(args, kwargs)
Definition: color.py:34
def message(msg, args, kwargs)
Definition: color.py:21
def warning(args, kwargs)
Definition: color.py:28
def colorize(msg, color, file=sys.stderr, alt_text=None)
Definition: color.py:12


xacro
Author(s): Stuart Glaser, William Woodall, Robert Haschke
autogenerated on Sat Jun 8 2019 18:04:14