Debian Codegraph @

tests/test_rgb_1.py

raw symbols SCIP
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3
4 """ Tests foreground and background RGB colors with numbers. """
5
6 import os
7 import time
8 from colored import Fore, Back, Style
9 from colored.controls import Controls
10 from colored.utilities import Utilities
11 from colored.library import Library
12
13
14 def foreground():
15 code = 0
16 control = Controls()
17 utils = Utilities()
18 utils.set_colorterm(colorterm='truecolor')
19 max_range: int = Library.COLORTERM[os.environ['COLORTERM']]
20 print("Press '[CTRL] + C' to interrupt:\n")
21 print(f'{"":>7}FOREGROUND {"":>8}COLOR {"":>8}BACKGROUND')
22 try:
23 while True:
24 code += 1
25 print(f'\r[{Fore.rgb(code, 0, 0)} Red {Style.reset}]'
26 f'[{Fore.rgb(0, code, 0)} Green {Style.reset}]'
27 f'[{Fore.rgb(0, 0, code)} Blue {Style.reset}] [ {code:>3} ] '
28 f'[{Back.rgb(code, 0, 0)} Red {Style.reset}]'
29 f'[{Back.rgb(0, code, 0)} Green {Style.reset}]'
30 f'[{Back.rgb(0, 0, code)} Blue {Style.reset}]',
31 end='')
32 if code == max_range:
33 code = 0
34 print(control.nav('erase_line', 1), end='')
35 time.sleep(1)
36 time.sleep(0.01)
37 except KeyboardInterrupt:
38 pass
39
40
41 def main():
42
43 foreground()
44
45
46 if __name__ == '__main__':
47 main()