Merge 6001cf76ea into eca25b4106
This commit is contained in:
commit
9320b96b4d
1 changed files with 34 additions and 6 deletions
|
|
@ -44,6 +44,18 @@ context["colors"] = {
|
||||||
"magenta": 5, "purple": 5, "cyan": 6, "white": 7, "none": -1
|
"magenta": 5, "purple": 5, "cyan": 6, "white": 7, "none": -1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
context["backgrounds"] = {
|
||||||
|
"black": 0,
|
||||||
|
"red": 1,
|
||||||
|
"green": 2,
|
||||||
|
"yellow": 3,
|
||||||
|
"blue": 4,
|
||||||
|
"magenta": 5,
|
||||||
|
"cyan": 6,
|
||||||
|
"white": 7
|
||||||
|
}
|
||||||
|
|
||||||
context["themes"] = {}
|
context["themes"] = {}
|
||||||
|
|
||||||
# pre-defined colormaps
|
# pre-defined colormaps
|
||||||
|
|
@ -335,7 +347,7 @@ def color_random( color ):
|
||||||
global context
|
global context
|
||||||
m = mode(color)
|
m = mode(color)
|
||||||
if m == 8:
|
if m == 8:
|
||||||
color_name = random.choice(context["colormaps"]["random"])
|
color_name = random.choice(list(context["colormaps"]["random"]))
|
||||||
color_code = context["colors"][color_name]
|
color_code = context["colors"][color_name]
|
||||||
color_code = str(30 + color_code)
|
color_code = str(30 + color_code)
|
||||||
|
|
||||||
|
|
@ -508,15 +520,23 @@ def colorin(text, color="red", style="normal"):
|
||||||
|
|
||||||
color_code = ""
|
color_code = ""
|
||||||
style_code = ""
|
style_code = ""
|
||||||
|
background_code = ""
|
||||||
|
list_style_code = []
|
||||||
|
|
||||||
# Convert the style code
|
# Convert the style code
|
||||||
if style == "random" or style == "Random":
|
if style == "random" or style == "Random":
|
||||||
style = random.choice(list(context["styles"].keys()))
|
style = random.choice(list(context["styles"].keys()))
|
||||||
else:
|
else:
|
||||||
if style in context["styles"]:
|
styles = style.split(".")
|
||||||
style_code = str(context["styles"][style])
|
for astyle in styles:
|
||||||
|
if astyle in context["styles"]:
|
||||||
|
list_style_code.append(str(context["styles"][astyle]))
|
||||||
|
style_code = ";".join(list_style_code)
|
||||||
|
|
||||||
|
color_background = color.strip().split(".")
|
||||||
|
color = color_background[0]
|
||||||
|
background = color_background[1] if len(color_background) == 2 else None
|
||||||
|
|
||||||
color = color.strip()
|
|
||||||
m = mode(color)
|
m = mode(color)
|
||||||
|
|
||||||
if color == "none":
|
if color == "none":
|
||||||
|
|
@ -572,9 +592,17 @@ def colorin(text, color="red", style="normal"):
|
||||||
else:
|
else:
|
||||||
raise UnknownColor(color)
|
raise UnknownColor(color)
|
||||||
|
|
||||||
|
if background in context["backgrounds"] and m == 8:
|
||||||
|
background_code = endmarks[m] + str(40 + context["backgrounds"][background])
|
||||||
|
elif background == None:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
raise UnknownColor(background)
|
||||||
|
|
||||||
|
|
||||||
if color_code is not None:
|
if color_code is not None:
|
||||||
if not debug:
|
if not debug:
|
||||||
return start + style_code + endmarks[m] + color_code + "m" + text + stop
|
return start + style_code + endmarks[m] + color_code + background_code + "m" + text + stop
|
||||||
else:
|
else:
|
||||||
return start + style_code + endmarks[m] + color_code + "m" \
|
return start + style_code + endmarks[m] + color_code + "m" \
|
||||||
+ "<color name=" + str(color) + " code=" + color_code \
|
+ "<color name=" + str(color) + " code=" + color_code \
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue