[affichage] Ajout d'une liste de styles pour tableau, et bugfix

* On peut "styliser" des colonnes de tableau maintenant.
 * Le formatage pour les octets était foireux
This commit is contained in:
Pierre-Elliott Bécue 2014-06-18 17:18:32 +02:00
parent 8b87c092e8
commit c4c142686d

View file

@ -41,7 +41,7 @@ import functools
import time import time
import re import re
oct_names = ["Pio", "Tio", "Gio", "Mio", "Kio", "o"] oct_names = ["Pio", "Tio", "Gio", "Mio", "Kio"]
oct_sizes = [1024**(len(oct_names) - i - 1) for i in xrange(0, len(oct_names))] oct_sizes = [1024**(len(oct_names) - i - 1) for i in xrange(0, len(oct_names))]
term_format = '\x1b\[[0-1];([0-9]|[0-9][0-9])m' term_format = '\x1b\[[0-1];([0-9]|[0-9][0-9])m'
dialog_format = '\\\Z.' dialog_format = '\\\Z.'
@ -393,8 +393,9 @@ def format_data(data, format):
for i in xrange(0, len(oct_names)): for i in xrange(0, len(oct_names)):
if data > oct_sizes[i]: if data > oct_sizes[i]:
return "%.2f %s" % (data/oct_sizes[i], oct_names[i]) return "%.2f %s" % (data/oct_sizes[i], oct_names[i])
return "%.0f o" % (data)
def tableau(data, titre=None, largeur=None, alignement=None, format=None, dialog=False, width=None): def tableau(data, titre=None, largeur=None, alignement=None, format=None, dialog=False, width=None, styles=None):
""" """
Retourne une chaine formatée repésentant un tableau. Retourne une chaine formatée repésentant un tableau.
@ -426,6 +427,9 @@ def tableau(data, titre=None, largeur=None, alignement=None, format=None, dialog
if format is None: if format is None:
format = ['s'] * nb_cols format = ['s'] * nb_cols
if styles is None:
styles = [None] * nb_cols
data = [[format_data(ligne[i], format[i]) for i in xrange(nb_cols)] for ligne in data] data = [[format_data(ligne[i], format[i]) for i in xrange(nb_cols)] for ligne in data]
if not largeur : if not largeur :
@ -452,7 +456,7 @@ def tableau(data, titre=None, largeur=None, alignement=None, format=None, dialog
########## ##########
if titre : if titre :
# ligne de titre # ligne de titre
chaine = sep_col + sep_col.join([aligne(titre[i], 'c', largeur[i], dialog) for i in range(nb_cols)]) + sep_col + u'\n' chaine = sep_col + sep_col.join([style(aligne(titre[i], 'c', largeur[i], dialog), styles[i]) for i in range(nb_cols)]) + sep_col + u'\n'
# ligne de séparation # ligne de séparation
chaine += sep_col + u'+'.join([u'-'*largeur[i] for i in range(nb_cols)]) + sep_col + u'\n' chaine += sep_col + u'+'.join([u'-'*largeur[i] for i in range(nb_cols)]) + sep_col + u'\n'
else : else :
@ -460,7 +464,7 @@ def tableau(data, titre=None, largeur=None, alignement=None, format=None, dialog
# Les données # Les données
############# #############
chaine += u'\n'.join([sep_col + sep_col.join([ligne[i] for i in range(nb_cols)]) + sep_col for ligne in data]) chaine += u'\n'.join([sep_col + sep_col.join([style(ligne[i], styles[i]) for i in range(nb_cols)]) + sep_col for ligne in data])
return chaine return chaine