Esempio n. 1
0
    def make_table(self, truncate=False):
        #Express data table as SuperString
        from copy import copy
        table = []
        lcb = len(self.col_borders)
        table_width = sum(self.col_widths_no_ansi+lcb) + lcb
        use_width = copy(table_width)
        trunc = lambda row : row
        
        if truncate:
            #FIXME!
            termW,termH = getTerminalSize()
        
            if table_width > termW:
                use_width = termW
            
                cs = np.cumsum(self.col_widths_no_ansi)
                iq = first_true_index( cs > termW - self.col_widths[-1] )
                lidx = cs[iq-1] + termW - cs[iq] - 5
                uidx = table_width - self.col_widths[-1]
                trunc = lambda row : row[:lidx] + '<...>' + row[uidx:]
            #FIXME!

        #top line
        top_line = self.col_fmt.format( '', use_width, '^' )
        top_line = as_superstrings(top_line, 'underline')
        table.append(top_line)
        
        if not self.title is None:
            title = self.make_title(use_width - lcb)
            table.append(title)
        
        #make rows
        for i, col_items in enumerate( self.pre_table ):
            row = self.create_row( col_items )
            if i==0 and self.has_col_head:
                row = as_superstrings(row, self.col_head_props)         #HACK
                
            if i in self.where_row_borders:
                row = as_superstrings(row, 'underline', 
                                      precision=self.num_prec )         #FIXME!!!!!!!!!!!!!
            

            row = trunc(row)
            table.append( row )
            
        self.table = table
        
        return table
Esempio n. 2
0
 def __init__(self, **kws):
     ''' '''
     self.sigfig             = kws.get('sigfig',     2)
     self.width              = kws.get('width',      getTerminalSize()[0])
     self.symbol             = kws.get('symbol',     '*')
     self.sides              = kws.get('sides',      '|')
     self.nbars              = kws.get('nbars',      1 )
     self.alignment          = kws.get('align',      ('^','<'))      #centering for percentage, info
     self.infoloc            = kws.get('infoloc',    'above').lower()
     self.infospace          = kws.get('infospace',  0)
     self.props              = kws.get('properties')
     self.show_eta           = kws.get('eta',        False)
     
     wraps, empty = ['{1}{0}{1}'.format(sym*(self.width-2), self.sides)
                         for sym in (self.symbol, ' ')]  
     self.bar_wrapper = '{0}\n{1}{0}'.format(wraps, (empty+'\n')*self.nbars)
     
     self.t0 = time.time()
     self.progress = self.timer(self.progress)
Esempio n. 3
0
File: str.py Progetto: apodemus/ansi
def banner(*args, **props):
    '''print pretty banner'''
    swoosh      = props.pop('swoosh', '=',)
    width       = props.pop('width', getTerminalSize()[0])
    pretty      = props.pop('pretty', True)
    _print      = props.pop('_print', True)
    
    swoosh = swoosh * width
    #TODO: fill whitespace to width?    
    #try:
    msg = '\n'.join(as_ansi(args, ndmin=1, pretty=pretty))
    #except:
        #embed()
    
    #.center( width )
    info = '\n'.join( [swoosh, msg, swoosh] )
    
    info = as_ansi(info).set_property(**props)
    
    if _print:
        print(info)
    
    return info