1from functools import partial
2import platform
3from os import getenv
4
5""" This module allows printing coloured output to the terminal when running a
6Wget Test under certain conditions.
7The output is coloured only on Linux systems. This is because coloured output
8in the terminal on Windows requires too much effort for what is simply a
9convenience. This might work on OSX terminals, but without a confirmation, it
10remains unsupported.
11
12Another important aspect is that the coloured output is printed only if the
13environment variable MAKE_CHECK is not set. This variable is set when running
14the test suite through, `make check`. In that case, the output is not only
15printed to the terminal but also copied to a log file where the ANSI escape
16codes on;y add clutter. """
17
18
19T_COLORS = {
20    'PURPLE' : '\033[95m',
21    'BLUE'   : '\033[94m',
22    'GREEN'  : '\033[92m',
23    'YELLOW' : '\033[93m',
24    'RED'    : '\033[91m',
25    'ENDC'   : '\033[0m'
26}
27
28system = True if platform.system() == 'Linux' else False
29check = False if getenv("MAKE_CHECK") == 'True' else True
30
31def printer (color, string):
32    if system and check:
33        print (T_COLORS.get (color) + string + T_COLORS.get ('ENDC'))
34    else:
35        print (string)
36
37
38print_blue = partial(printer, 'BLUE')
39print_red = partial(printer, 'RED')
40print_green = partial(printer, 'GREEN')
41print_purple = partial(printer, 'PURPLE')
42print_yellow = partial(printer, 'YELLOW')
43
44# vim: set ts=8 sw=3 tw=80 et :
45