| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
""" Tests foreground and background RGB colors with numbers percentages. """ |
| 5 |
|
| 6 |
import time |
| 7 |
from colored import Fore, Back, Style |
| 8 |
from colored.controls import Controls |
| 9 |
from colored.utilities import Utilities |
| 10 |
|
| 11 |
|
| 12 |
def foreground(): |
| 13 |
n = 0 |
| 14 |
control = Controls() |
| 15 |
utils = Utilities() |
| 16 |
print("Press '[CTRL] + C' to interrupt:\n") |
| 17 |
print(f'{"":>7}FOREGROUND {"":>9}COLOR {"":>8}BACKGROUND') |
| 18 |
try: |
| 19 |
while True: |
| 20 |
n += 1 |
| 21 |
per: str = f'{n}%' |
| 22 |
code: str = utils.convert_percentages(per) |
| 23 |
print(f'\r[{Fore.rgb(code, 0, 0)} Red {Style.reset}]' |
| 24 |
f'[{Fore.rgb(0, code, 0)} Green {Style.reset}]' |
| 25 |
f'[{Fore.rgb(0, 0, code)} Blue {Style.reset}] [ {per:>4} ] ' |
| 26 |
f'[{Back.rgb(code, 0, 0)} Red {Style.reset}]' |
| 27 |
f'[{Back.rgb(0, code, 0)} Green {Style.reset}]' |
| 28 |
f'[{Back.rgb(0, 0, code)} Blue {Style.reset}]', |
| 29 |
end='') |
| 30 |
if n == 100: |
| 31 |
n = 0 |
| 32 |
print(control.nav('erase_line', 1), end='') |
| 33 |
time.sleep(1) |
| 34 |
time.sleep(0.01) |
| 35 |
except KeyboardInterrupt: |
| 36 |
pass |
| 37 |
|
| 38 |
|
| 39 |
def main(): |
| 40 |
|
| 41 |
foreground() |
| 42 |
|
| 43 |
|
| 44 |
if __name__ == '__main__': |
| 45 |
main() |