[gestion/affich_tools] Support des couleurs dans dialog
This commit is contained in:
parent
8c2165030d
commit
b04ab576da
1 changed files with 22 additions and 5 deletions
|
@ -74,7 +74,7 @@ def dialog(backtitle,arg,dialogrc='') :
|
|||
elif not result : result=['']
|
||||
return [ 0, result ]
|
||||
|
||||
def coul(txt, col=None):
|
||||
def coul(txt, col=None, dialog=False):
|
||||
"""
|
||||
Retourne la chaine donnée encadrée des séquences qui
|
||||
vont bien pour obtenir la couleur souhaitée
|
||||
|
@ -92,6 +92,21 @@ def coul(txt, col=None):
|
|||
'cyan': 36,
|
||||
'gris': 30,
|
||||
'gras': 50 }
|
||||
codecol_dialog = {
|
||||
'rouge': 1,
|
||||
'vert': 2,
|
||||
'jaune': 3,
|
||||
'bleu': 4,
|
||||
'violet': 5,
|
||||
'cyan': 6,
|
||||
'gris': 0,
|
||||
'gras': 'b' }
|
||||
|
||||
if dialog:
|
||||
try:
|
||||
txt = "\Z%s%s\Zn" % (codecol_dialog[col], txt)
|
||||
finally:
|
||||
return txt
|
||||
try:
|
||||
if col[:2] == 'f_':
|
||||
add = 10
|
||||
|
@ -128,7 +143,7 @@ def cprint(txt, col='blanc', newline=True):
|
|||
else:
|
||||
print t,
|
||||
|
||||
def tableau(data, titre=None, largeur=None, alignement=None, format=None):
|
||||
def tableau(data, titre=None, largeur=None, alignement=None, format=None, dialog=False):
|
||||
"""
|
||||
Retourne une chaine formatée repésentant un tableau.
|
||||
|
||||
|
@ -183,9 +198,11 @@ def tableau(data, titre=None, largeur=None, alignement=None, format=None):
|
|||
# Largeurs
|
||||
##########
|
||||
if not largeur :
|
||||
largeur = [ max([len(re.sub('\x1b\[1;([0-9]|[0-9][0-9])m','',ligne[i])) for ligne in data]) for i in range(nbcols) ]
|
||||
largeur = [ max([len(re.sub('\\\Z.' if dialog else '\x1b\[1;([0-9]|[0-9][0-9])m','',ligne[i])) for ligne in data]) for i in range(nbcols) ]
|
||||
elif '*' in largeur:
|
||||
rows, cols = get_screen_size()
|
||||
if dialog:
|
||||
cols = cols - 6
|
||||
for i in range(nbcols) :
|
||||
if largeur[i] in ['*',-1] :
|
||||
largeur[i] = max(cols - sum([l for l in largeur if l != '*']) - nbcols - 1, 3)
|
||||
|
@ -198,12 +215,12 @@ def tableau(data, titre=None, largeur=None, alignement=None, format=None):
|
|||
|
||||
def aligne (data, alignement, largeur) :
|
||||
# Longeur sans les chaines de formatage
|
||||
l = len(re.sub('\x1b\[1;([0-9]|[0-9][0-9])m','',data))
|
||||
l = len(re.sub('\\\Z.' if dialog else '\x1b\[1;([0-9]|[0-9][0-9])m','',data))
|
||||
|
||||
# Alignement
|
||||
if l > largeur :
|
||||
# découpage d'une chaine trop longue
|
||||
regexp = re.compile('\x1b\[1;([0-9]|[0-9][0-9])m')
|
||||
regexp = re.compile('\\\Z.' if dialog else '\x1b\[1;([0-9]|[0-9][0-9])m')
|
||||
new_data = u''
|
||||
new_len = 0
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue