def format_keyvals(lst, key='key', val='text', indent=0):
 ret = []
 if lst:
  maxk = min(max((len(i[0]) for i in lst if (i and i[0]))), KEY_MAX)
  for (i, kv) in enumerate(lst):
   if (kv is None):
    ret.append(urwid.Text(''))
   else:
    cols = []
    if indent:
     cols.append(('fixed', indent, urwid.Text('')))
    cols.extend([('fixed', maxk, urwid.Text([(key, (kv[0] or ''))])), (kv[1] if isinstance(kv[1], urwid.Widget) else urwid.Text([(val, kv[1])]))])
    ret.append(urwid.Columns(cols, dividechars=2))
 return ret

def format_keyvals ( lst , key = 'key' , val = 'text' , indent = 0 ) : ret = [ ] if lst : maxk = min ( max ( ( len ( i [ 0 ] ) for i in lst if ( i and i [ 0 ] ) ) ) , KEY_MAX ) for ( i , kv ) in enumerate ( lst ) : if ( kv is None ) : ret . append ( urwid . Text ( '' ) ) else : cols = [ ] if indent : cols . append ( ( 'fixed' , indent , urwid . Text ( '' ) ) ) cols . extend ( [ ( 'fixed' , maxk , urwid . Text ( [ ( key , ( kv [ 0 ] or '' ) ) ] ) ) , ( kv [ 1 ] if isinstance ( kv [ 1 ] , urwid . Widget ) else urwid . Text ( [ ( val , kv [ 1 ] ) ] ) ) ] ) ret . append ( urwid . Columns ( cols , dividechars = 2 ) ) return ret
format a list of tuples .