Changeset 405

Show
Ignore:
Timestamp:
05/01/07 22:43:40 (2 years ago)
Author:
athomas
Message:

pycrash: A few cleanups.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • pycrash/trunk/crash/console.py

    r404 r405  
    55__cprint_re = re.compile(r'''[^^]+|\^([N0-7BU])''') 
    66__cprint_strip = re.compile(r'''\^([N0-7BU])''') 
     7__cwrap_re = re.compile(r'''(\n)|(\s+)|((?:\^[N0-7BU]|\S)+\b[^\n^\w]*)''') 
    78__colour_terminal = 0 
    89 
     
    9596        return curses.tigetnum('cols') 
    9697    except: 
    97         return 'COLUMNS' in os.environ and int(os.environ['COLUMNS']) or 80 
     98        return int(os.environ.get('COLUMNS', 80)) 
    9899 
    99100def termheight(): 
     
    102103        return curses.tigetnum('lines') 
    103104    except: 
    104         return 'LINES' in os.environ and int(os.environ['LINES']) or 25 
     105        return int(os.environ.get('LINES', 25)) 
    105106 
    106107def csplice(text, start = 0, end = -1): 
     
    133134    return out 
    134135 
    135 __cwrap_re = re.compile(r'''(\n)|(\s+)|((?:\^[N0-7BU]|\S)+\b[^\n^\w]*)''') 
    136136def cwraptext(rtext, width = termwidth(), subsequent_indent = ''): 
    137137    """ Wrap multi-line text to width (defaults to termwidth()) """ 
     
    189189    header, if specified, will be printed as the first row. sep is the 
    190190    separator between columns. 
    191      
     191 
    192192    auto_format is a list specifying the formatting colours to use for each 
    193193    row. The first element is the header colour, subsequent elements are 
     
    196196    expand_to_fit signifies whether print_table should expand the table to the 
    197197    width of the terminal. 
    198      
     198 
    199199    Note: print_table supports the ^R formatting code, in addition to those 
    200200    supported by cprint, which corresponds to the colour formatting of the 
     
    221221            if col == mincol: 
    222222                colwidths[0] += termwidth() - sum(colwidths) 
    223          
     223 
    224224    auto_format = auto_format[:] 
    225225 
     
    238238            fmt = auto_format[rowalt % len(auto_format)] 
    239239        # Perform wrapping 
    240         xrow = [cwraptext(col.replace('^R', fmt), colwidths[i] - (i < cols - 1 and seplen or 0)) for i, col in enumerate(row)] 
     240        xrow = [cwraptext(col.replace('^R', fmt), 
     241                          colwidths[i] - (i < cols - 1 and seplen or 0)) 
     242                for i, col in enumerate(row)] 
    241243        # Pad column rows out to the maximum of all columns 
    242244        maxrows = max([0] + map(len, xrow))