1#!/usr/bin/env python323def sgr(*args):4 return '\033[' + ';'.join(map(str,args)) + 'm'56def sgr_extended(*args):7 return '\033[' + ':'.join(map(str,args)) + 'm'89def print_heading(t):10 print('\n{}{}{}\n'.format(sgr(1,4), t, sgr()))1112print_heading('text style')1314print('{}bold{}'.format(sgr(1), sgr(22)))15print('{}faint{}'.format(sgr(2), sgr(22)))16print('{}italic{}'.format(sgr(3), sgr(23)))17print('{}underline{}'.format(sgr(4), sgr(24)))18print('the following is concealed: {}invisible{}'.format(sgr(8), sgr(28)))19print('{}strikethrough{}'.format(sgr(9), sgr(29)))20print('{}double underline{}'.format(sgr(21), sgr(24)))2122for s in [30,90,40,100]:23 print_heading(24 '16 color {}{}'.format(25 'bright ' if s > 50 else '',26 'foreground' if s % 3 == 0 else 'background',27 )28 )2930 for c in range(8):31 print(32 '{}|{:2}{}'.format(33 sgr(s + c),34 c,35 sgr()36 ),37 end=''38 )3940 print('')4142for s in [38, 48]:43 section = 'foreground' if s == 38 else 'background'4445 print_heading(46 '16 color {}'.format(section)47 )4849 for y in range(2):50 for x in range(8):51 c = x + y * 852 print(53 '{}|{:>2}{}'.format(54 sgr_extended(s, 5, c),55 c,56 sgr(s + 1)57 ),58 end=''59 )6061 print('')6263 print_heading('6 * 6 * 6 cube color {}'.format(section))6465 for y in range(6):66 for x in range(36):67 c = 16 + x + y * 3668 print(69 '{}|{:>3}{}'.format(70 sgr_extended(s, 5, c),71 c,72 sgr(s + 1)73 ),74 end=''75 )76 print('')7778 print_heading('grayscale {}'.format(section))7980 for c in range(232, 256):81 print(82 '{}|{:>3}{}'.format(83 sgr_extended(s, 5, c),84 c,85 sgr(s + 1)86 ),87 end=''88 )89 print('')909192print_heading('16 color combinations')9394print(' |' + '|'.join(map(lambda x: '{:<4}'.format(x), range(16))))95for f in range(16):96 print(f'{f:>2}', end='')9798 for b in range(16):99 print(100 '{}{}|test{}'.format(101 sgr_extended(38, 5, f),102 sgr_extended(48, 5, b),103 sgr(39, 49)104 ),105 end=''106 )107 print('')