[affich_tools] Ajout d'une largeur optionnelle à la fonction tableau.

This commit is contained in:
Pierre-Elliott Bécue 2014-03-10 10:03:56 +01:00
parent 82b5caa988
commit b3420a3152

View file

@ -143,7 +143,7 @@ def cprint(txt, col='blanc', newline=True):
else:
print t,
def tableau(data, titre=None, largeur=None, alignement=None, format=None, dialog=False):
def tableau(data, titre=None, largeur=None, alignement=None, format=None, dialog=False, width=None):
"""
Retourne une chaine formatée repésentant un tableau.
@ -200,9 +200,12 @@ def tableau(data, titre=None, largeur=None, alignement=None, format=None, dialog
if not largeur :
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
if width:
cols = width
else:
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)