python/colour: add colourizing and switch functions
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>
Thu, 19 Apr 2018 02:12:57 +0000 (14:12 +1200)
committerAndrew Bartlett <abartlet@samba.org>
Wed, 30 May 2018 23:57:17 +0000 (01:57 +0200)
commite58719d13cbaa16c9fa454d5653b4a7dd6915777
tree4f25e6f7ee7e65bdb8df2c5605237d2b4da4bf22
parent81167c0198146e333cac96ef863acc80afacfa55
python/colour: add colourizing and switch functions

When samba.colour is first imported, the function

colour.c_BLUE("samba")

will give you the string "\033[1;34msamba\033[0m", which will show up
as blue on an ANSI terminal. If you then go:

colour.switch_colour_off()
colour.c_BLUE("samba")

the c_BLUE call will return the uncoloured string "samba".

This is so things like samba-tool can do this sort of thing:

    if not os.isatty(self.outf):
        switch_colour_off()

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
python/samba/colour.py