Debian Codegraph @

demos/demo01.py

raw ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 #!/usr/bin/python
2 # Copyright Jonathan Hartley 2013. BSD 3-Clause license, see LICENSE file.
3
4 # print grid of all colors and brightnesses
5 # uses stdout.write to write chars with no newline nor spaces between them
6 # This should run more-or-less identically on Windows and Unix.
7 from __future__ import print_function
8 import sys
9
10 # Add parent dir to sys path, so the following 'import colorama' always finds
11 # the local source in preference to any installed version of colorama.
12 import fixpath
13 from colorama import just_fix_windows_console, Fore, Back, Style
14
15 just_fix_windows_console()
16
17 # Fore, Back and Style are convenience classes for the constant ANSI strings that set
18 # the foreground, background and style. The don't have any magic of their own.
19 FORES = [ Fore.BLACK, Fore.RED, Fore.GREEN, Fore.YELLOW, Fore.BLUE, Fore.MAGENTA, Fore.CYAN, Fore.WHITE ]
20 BACKS = [ Back.BLACK, Back.RED, Back.GREEN, Back.YELLOW, Back.BLUE, Back.MAGENTA, Back.CYAN, Back.WHITE ]
21 STYLES = [ Style.DIM, Style.NORMAL, Style.BRIGHT ]
22
23 NAMES = {
24 Fore.BLACK: 'black', Fore.RED: 'red', Fore.GREEN: 'green', Fore.YELLOW: 'yellow', Fore.BLUE: 'blue', Fore.MAGENTA: 'magenta', Fore.CYAN: 'cyan', Fore.WHITE: 'white'
25 , Fore.RESET: 'reset',
26 Back.BLACK: 'black', Back.RED: 'red', Back.GREEN: 'green', Back.YELLOW: 'yellow', Back.BLUE: 'blue', Back.MAGENTA: 'magenta', Back.CYAN: 'cyan', Back.WHITE: 'white',
27 Back.RESET: 'reset'
28 }
29
30 # show the color names
31 sys.stdout.write(' ')
32 for foreground in FORES:
33 sys.stdout.write('%s%-7s' % (foreground, NAMES[foreground]))
34 print()
35
36 # make a row for each background color
37 for background in BACKS:
38 sys.stdout.write('%s%-7s%s %s' % (background, NAMES[background], Back.RESET, background))
39 # make a column for each foreground color
40 for foreground in FORES:
41 sys.stdout.write(foreground)
42 # show dim, normal bright
43 for brightness in STYLES:
44 sys.stdout.write('%sX ' % brightness)
45 sys.stdout.write(Style.RESET_ALL + ' ' + background)
46 print(Style.RESET_ALL)
47
48 print()