+#!/usr/bin/python
+# -*- coding:utf8 -*-
+
+""" Petit script pour générer une chaîne de caractère magique
+ qui permet de changer la couleur d'affichage du texte dans le shell
+"""
+
+# Les paramètres sont les suivants :
+# 1 : le type de sortie prompt ou pas
+# si c'est prompt, la sortie est enadrée de \[ et \], sinon non
+# 2 : fg ou bg ou both
+# 3 : la couleur (black, red, green, yellow, blue, purple, cyan, white)
+# 4 et suivants : des paramètres
+# liste exhaustive des combinaisons possibles :
+# []
+# bold
+# underline
+# high
+# bold underline
+# bold underline high #(a prori ça garde que bold)
+# underline high
+# avec ground = both
+# [fg_params] , bg_color [bg_params]
+
+
+import sys
+args=sys.argv
+
+
+
+dicocolor={"black":"0","Black":"0","noir":"0","Noir":"0","BLACK":"0","NOIR":"0",
+ "red":"1","Red":"1","rouge":"1","Rouge":"1","RED":"1","ROUGE":"1",
+ "green":"2","Green":"2","vert":"2","Vert":"2","GREEN":"2","VERT":"2",
+ "yellow":"3","Yellow":"3","jaune":"3","Jaune":"3","YELLOW":"3","JAUNE":"3",
+ "blue":"4","Blue":"4","bleu":"4","Bleu":"4","BLUE":"4","BLEU":"4",
+ "purple":"5","Purple":"5","violet":"5","Violet":"5","PURPLE":"5","VIOLET":"5",
+ "cyan":"6","Cyan":"6","CYAN":"6",
+ "white":"7","White":"7","blanc":"7","Blanc":"7","WHITE":"7","BLANC":"7"}
+
+def isBold(liste):
+ liste_bold=set(["bold","Bold","BOLD","gras","Gras","GRAS"])
+ return not(liste_bold.isdisjoint(set(liste)))
+
+def isUnderline(liste):
+ liste_underline=set(["underline","Underline","UNDERLINE","souligne","Souligne","SOULIGNE"])
+ return not(liste_underline.isdisjoint(set(liste)))
+
+def isHigh(liste):
+ liste_high=set(["high","High","HIGH","high_intensity","High_Intensity","HIGH_INTENSITY"])
+ return not(liste_high.isdisjoint(set(liste)))
+
+def get_fg_color(color,bold,underline,high):
+ prefix=("4;"*underline
+ +"1;"*bold)
+ highoupas="9"*high+"3"*(not(high))
+ return prefix+highoupas+dicocolor[color]
+
+def get_bg_color(color,high):
+ highoupas="4"*high+"10"*(not(high))
+ return highoupas+dicocolor[color]
+
+# Let's go
+out,ground,color=args[1],args[2],args[3]
+params=args[4:] # éventuellement vide
+
+if out=="prompt":
+ deb,fin="\\[\\e[","m\\]"
+else:
+ deb,fin="\\e[","m"
+
+
+
+if ground=="fg":
+ bold = isBold(params)
+ underline = isUnderline(params)
+ high = isHigh(params)
+ print deb+get_fg_color(color,bold,underline,high)+fin
+elif ground=="bg":
+ high = isHigh(params)
+ print deb+get_bg_color(color,high)+fin
+elif ground=="both":
+ # On cherche le séparateur
+ virgule=params.index(",")
+ fg_params=params[:virgule]
+ bg_color=params[virgule+1]
+ bg_params=params[virgule+2:]
+ out = deb
+ out += get_fg_color(color,isBold(fg_params),isUnderline(fg_params),isHigh(fg_params))
+ out += fin+deb
+ out += get_bg_color(bg_color,isHigh(bg_params))
+ out += fin
+ print out
+else:
+ print ""