saneterm

Modern line-oriented terminal emulator without support for TUIs

git clone https://git.8pit.net/saneterm.git

  1#!/usr/bin/env python3
  2
  3def sgr(*args):
  4    return '\033[' + ';'.join(map(str,args)) + 'm'
  5
  6def sgr_extended(*args):
  7    return '\033[' + ':'.join(map(str,args)) + 'm'
  8
  9def print_heading(t):
 10    print('\n{}{}{}\n'.format(sgr(1,4), t, sgr()))
 11
 12print_heading('text style')
 13
 14print('{}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)))
 21
 22for 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    )
 29
 30    for c in range(8):
 31        print(
 32            '{}|{:2}{}'.format(
 33                sgr(s + c),
 34                c,
 35                sgr()
 36            ),
 37            end=''
 38        )
 39
 40    print('')
 41
 42for s in [38, 48]:
 43    section = 'foreground' if s == 38 else 'background'
 44
 45    print_heading(
 46        '16 color {}'.format(section)
 47    )
 48
 49    for y in range(2):
 50        for x in range(8):
 51            c = x + y * 8
 52            print(
 53                '{}|{:>2}{}'.format(
 54                    sgr_extended(s, 5, c),
 55                    c,
 56                    sgr(s + 1)
 57                ),
 58                end=''
 59            )
 60
 61        print('')
 62
 63    print_heading('6 * 6 * 6 cube color {}'.format(section))
 64
 65    for y in range(6):
 66        for x in range(36):
 67            c = 16 + x + y * 36
 68            print(
 69                '{}|{:>3}{}'.format(
 70                    sgr_extended(s, 5, c),
 71                    c,
 72                    sgr(s + 1)
 73                ),
 74                end=''
 75            )
 76        print('')
 77
 78    print_heading('grayscale {}'.format(section))
 79
 80    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('')
 90
 91
 92print_heading('16 color combinations')
 93
 94print('  |' + '|'.join(map(lambda x: '{:<4}'.format(x), range(16))))
 95for f in range(16):
 96    print(f'{f:>2}', end='')
 97
 98    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('')