]>
gitweb.pimeys.fr Git - scripts-20-100.git/blob - create_color.py
4 """ Petit script pour générer une chaîne de caractère magique
5 qui permet de changer la couleur d'affichage du texte dans le shell
8 # Les paramètres sont les suivants :
9 # 1 : le type de sortie prompt ou pas
10 # si c'est prompt, la sortie est enadrée de \[ et \], sinon non
11 # 2 : fg ou bg ou both
12 # 3 : la couleur (black, red, green, yellow, blue, purple, cyan, white)
13 # 4 et suivants : des paramètres
14 # liste exhaustive des combinaisons possibles :
20 # bold underline high #(a prori ça garde que bold)
23 # [fg_params] , bg_color [bg_params]
31 dicocolor
={"black":"0","Black":"0","noir":"0","Noir":"0","BLACK":"0","NOIR":"0",
32 "red":"1","Red":"1","rouge":"1","Rouge":"1","RED":"1","ROUGE":"1",
33 "green":"2","Green":"2","vert":"2","Vert":"2","GREEN":"2","VERT":"2",
34 "yellow":"3","Yellow":"3","jaune":"3","Jaune":"3","YELLOW":"3","JAUNE":"3",
35 "blue":"4","Blue":"4","bleu":"4","Bleu":"4","BLUE":"4","BLEU":"4",
36 "purple":"5","Purple":"5","violet":"5","Violet":"5","PURPLE":"5","VIOLET":"5",
37 "cyan":"6","Cyan":"6","CYAN":"6",
38 "white":"7","White":"7","blanc":"7","Blanc":"7","WHITE":"7","BLANC":"7"}
41 liste_bold
=set(["bold","Bold","BOLD","gras","Gras","GRAS"])
42 return not(liste_bold
.isdisjoint(set(liste
)))
44 def isUnderline(liste
):
45 liste_underline
=set(["underline","Underline","UNDERLINE","souligne","Souligne","SOULIGNE"])
46 return not(liste_underline
.isdisjoint(set(liste
)))
49 liste_high
=set(["high","High","HIGH","high_intensity","High_Intensity","HIGH_INTENSITY"])
50 return not(liste_high
.isdisjoint(set(liste
)))
52 def get_fg_color(color
,bold
,underline
,high
):
53 prefix
=("4;"*underline
55 highoupas
="9"*high
+"3"*(not(high
))
56 return prefix
+highoupas
+dicocolor
[color
]
58 def get_bg_color(color
,high
):
59 highoupas
="4"*high
+"10"*(not(high
))
60 return highoupas
+dicocolor
[color
]
63 out
,ground
,color
=args
[1],args
[2],args
[3]
64 params
=args
[4:] # éventuellement vide
67 deb
,fin
="\\[\\e[","m\\]"
75 underline
= isUnderline(params
)
77 print deb
+get_fg_color(color
,bold
,underline
,high
)+fin
80 print deb
+get_bg_color(color
,high
)+fin
82 # On cherche le séparateur
83 virgule
=params
.index(",")
84 fg_params
=params
[:virgule
]
85 bg_color
=params
[virgule
+1]
86 bg_params
=params
[virgule
+2:]
88 out
+= get_fg_color(color
,isBold(fg_params
),isUnderline(fg_params
),isHigh(fg_params
))
90 out
+= get_bg_color(bg_color
,isHigh(bg_params
))