File: test_rgb_1.py

package info (click to toggle)
colored 2.2.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 240 kB
  • sloc: python: 2,064; makefile: 4
file content (47 lines) | stat: -rw-r--r-- 1,369 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env python
# -*- coding: utf-8 -*-

""" Tests foreground and background RGB colors with numbers. """

import os
import time
from colored import Fore, Back, Style
from colored.controls import Controls
from colored.utilities import Utilities
from colored.library import Library


def foreground():
    code = 0
    control = Controls()
    utils = Utilities()
    utils.set_colorterm(colorterm='truecolor')
    max_range: int = Library.COLORTERM[os.environ['COLORTERM']]
    print("Press '[CTRL] + C' to interrupt:\n")
    print(f'{"":>7}FOREGROUND {"":>8}COLOR {"":>8}BACKGROUND')
    try:
        while True:
            code += 1
            print(f'\r[{Fore.rgb(code, 0, 0)} Red {Style.reset}]'
                  f'[{Fore.rgb(0, code, 0)} Green {Style.reset}]'
                  f'[{Fore.rgb(0, 0, code)} Blue {Style.reset}] [ {code:>3} ] '
                  f'[{Back.rgb(code, 0, 0)} Red {Style.reset}]'
                  f'[{Back.rgb(0, code, 0)} Green {Style.reset}]'
                  f'[{Back.rgb(0, 0, code)} Blue {Style.reset}]',
                  end='')
            if code == max_range:
                code = 0
                print(control.nav('erase_line', 1), end='')
                time.sleep(1)
            time.sleep(0.01)
    except KeyboardInterrupt:
        pass


def main():

    foreground()


if __name__ == '__main__':
    main()