Changeset 275
- Timestamp:
- 10/06/05 02:49:27 (3 years ago)
- Files:
-
- pycrash/trunk/crash/console.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
pycrash/trunk/crash/console.py
r274 r275 87 87 return '\n'.join(textwrap.wrap(text, termwidth(), **argd)) 88 88 89 def print_table(table, header=None, sep=' ', numfmt='%g', highlight_header = True, alternate_rows = ('^1', '^2')):89 def print_table(table, header=None, sep=' ', numfmt='%g', auto_format = True): 90 90 """Print a list of lists as a table, so that columns line up nicely. 91 91 header, if specified, will be printed as the first row. 92 92 numfmt is the format for all numbers; you might want e.g. '%6.2f'. 93 93 (If you want different formats in different columns, don't use 94 print_table.) sep is the separator between columns.""" 94 print_table.) sep is the separator between columns. 95 96 auto_format is a list specifying the formatting colours to use for each 97 row. The first element is the header colour, subsequent elements are 98 for alternating rows. eg. [ '^B', '^1', '^2' ] """ 95 99 def ljust(s, size): 96 100 return s + ' ' * (size - clen(s)) 97 101 def rjust(s, size): 98 102 return ' ' * (size - clen(s)) + s 103 if auto_format and type(auto_format) is not list: 104 auto_format = ['^B^U', '^6', '^B^6'] 99 105 justs = [isnumber(x) and rjust or ljust for x in table[0]] 100 106 if header: … … 104 110 maxlen = lambda seq: max(map(clen, seq)) 105 111 sizes = map(maxlen, zip(*[map(str, row) for row in table])) 106 rowalt = 0112 rowalt = -1 107 113 for row in table: 114 fmt = '' 115 if auto_format: 116 if rowalt == -1: 117 fmt = auto_format[0] 118 auto_format.pop(0) 119 else: 120 fmt = auto_format[rowalt % len(auto_format)] 121 cwrite(sys.stdout, fmt) 108 122 for (j, size, x) in zip(justs, sizes, row): 109 123 cwrite(sys.stdout, j(x, size), sep) 110 print 124 cprint('^N') 125 rowalt += 1
