'''colour.py Jed Yang, 2016-10-06 Provides for setting text colours on the terminal. ''' def colours(): '''List of supported colours.''' colours = { 'black': 30, 'red': 31, 'green': 32, 'yellow': 33, 'blue': 34, 'magenta': 35, 'cyan': 36, 'white': 37 } return colours def set(colour='white'): '''Sets terminal output to specified colour.''' code = colours().get(colour, 37) print('\033[' + str(code) + 'm', end='') def reset(): '''Resets terminal output to default colour.''' print('\033[m', end='') if __name__ == '__main__': colours = colours() print('''Usage: colour.reset() colour.set() where is one of the following:''') for colour in colours: code = colours[colour] print('\033[' + str(code) + 'm' + colour + '\033[m', end=' ') print()