You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
830 B
Python
34 lines
830 B
Python
#!/usr/bin/env python3
|
|
|
|
# This Source Code Form is subject to the terms of the Mozilla Public
|
|
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
from math import sqrt
|
|
|
|
|
|
def clearscreen():
|
|
print(chr(27) + "[2J", end='')
|
|
|
|
|
|
def resetcolor():
|
|
print(chr(27) + "[0m", end='')
|
|
|
|
|
|
def setbghexcolor(hex):
|
|
r = int(hex[0:2], 16)
|
|
g = int(hex[2:4], 16)
|
|
b = int(hex[4:6], 16)
|
|
print(chr(27) + "[48;2;" + str(r) + ";" + str(g) + ";" + str(b) + "m", end='')
|
|
|
|
|
|
def setfgbybghex(hex):
|
|
r = int(hex[0:2], 16)
|
|
g = int(hex[2:4], 16)
|
|
b = int(hex[4:6], 16)
|
|
contrast = sqrt(r * r * .241 + g * g * .691 + b * b * .068)
|
|
if contrast > 130:
|
|
print(chr(27) + "[38;30m", end='')
|
|
else:
|
|
print(chr(27) + "[38;97m", end='')
|