Last active
March 11, 2019 20:51
-
-
Save gargolito/ebf9e6f42d653a2753c55fb7184eab35 to your computer and use it in GitHub Desktop.
#bash #python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
with background | |
format \prefix[font_type;color;bgcolor+suffix | |
witout background | |
format \prefix[font_type;color+suffix | |
no color ---------------------------------------| | |
suffix -----------------| | | |
background ---------------| | | | |
font color ----------| | | | | | |
font type ----------| | | | | | |
prefix ----------| | | | | | |
python - print('\x1b[1;30;47m', "whatever", '\x1b[0m') | |
bash - echo '\x1b[1;30;47m', "whatever", '\x1b[0m' | |
color | foregr | backgr | |
----------------------- | |
nocolor | 0m | |
gray | 30 | 40 | |
red | 31 | 41 | |
green | 32 | 42 | |
yellow | 33 | 43 | |
blue | 34 | 44 | |
purple | 35 | 45 | |
cyan | 36 | 46 | |
white | 37 | 47 | |
font types | |
------------------------ | |
normal 0 | |
bold 1 | |
dark? 2 | |
italic 3 | |
uscore 4 | |
blink 5 | |
light 6 | |
invert 7 | |
bgcol 8 | |
strike 9 | |
RESET="\x1b[0m" | |
GRAY="\x1b[0;30m" | |
B_GRAY="\x1b[1;30m" | |
RED="\x1b[0;31m" | |
B_RED="\x1b[1;31m" | |
GREEN="\x1b[0;32m" | |
B_GREEN="\x1b[1;32m" | |
YELLOW="\x1b[0;33m" | |
B_YELLOW="\x1b[1;33m" | |
BLUE="\x1b[0;34m" | |
B_BLUE="\x1b[1;34m" | |
PURPLE="\x1b[0;35m" | |
B_PURPLE="\x1b[1;35m" | |
CYAN="\x1b[0;36m" | |
B_CYAN="\x1b[1;36m" | |
WHITE="\x1b[0;37M" | |
B_WHITE="\x1b[1;37M" | |
simple python class to colorize text, save as colors.py and import from your script | |
class Colors(object): | |
def color(self, hue, weight = 0): | |
""" | |
Usage: | |
import colors | |
c = Colors() | |
print(c.color("red"), "input", c.clear()) | |
for bold/bright font use: | |
print(c.color("red", 1), "input", c.clear()) | |
Available colors: | |
BLUE | |
CYAN | |
GRAY | |
GREEN | |
PURPLE | |
RED | |
WHITE | |
YELLOW | |
""" | |
self.hue = hue | |
self.weight = weight | |
hue = hue.upper() | |
colors = ["GRAY", "RED", "GREEN", "YELLOW", "BLUE", "PURPLE", "CYAN", "WHITE"] | |
color_prefix = str("\x1b[0m") | |
if weight: | |
color_prefix = str("\x1b[1m") | |
color_no = "\x1b[" + str(30 + colors.index(hue)) + "m" | |
color = color_prefix + color_no | |
return color | |
def clear(self): | |
return "\x1b[0m" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment