#NEWLINE# def format_robust_table( data , column_names ) : #NEWLINE# #INDENT# "\n    Render tabular data with one column per line (allowing columns with line breaks).\n\n    :param data: An iterable (e.g. a :func:`tuple` or :class:`list`)\n                 containing the rows of the table, where each row is an\n                 iterable containing the columns of the table (strings).\n    :param column_names: An iterable of column names (strings).\n    :returns: The rendered table (a string).\n\n    Here's an example:\n\n    >>> from humanfriendly.tables import format_robust_table\n    >>> column_names = ['Version', 'Uploaded on', 'Downloads']\n    >>> humanfriendly_releases = [\n    ... ['1.23', '2015-05-25', '218'],\n    ... ['1.23.1', '2015-05-26', '1354'],\n    ... ['1.24', '2015-05-26', '223'],\n    ... ['1.25', '2015-05-26', '4319'],\n    ... ['1.25.1', '2015-06-02', '197'],\n    ... ]\n    >>> print(format_robust_table(humanfriendly_releases, column_names))\n    -----------------------\n    Version: 1.23\n    Uploaded on: 2015-05-25\n    Downloads: 218\n    -----------------------\n    Version: 1.23.1\n    Uploaded on: 2015-05-26\n    Downloads: 1354\n    -----------------------\n    Version: 1.24\n    Uploaded on: 2015-05-26\n    Downloads: 223\n    -----------------------\n    Version: 1.25\n    Uploaded on: 2015-05-26\n    Downloads: 4319\n    -----------------------\n    Version: 1.25.1\n    Uploaded on: 2015-06-02\n    Downloads: 197\n    -----------------------\n\n    The column names are highlighted in bold font and color so they stand out a\n    bit more (see :data:`.HIGHLIGHT_COLOR`).\n    " #NEWLINE# blocks = [ ] #NEWLINE# column_names = [ ( '%s:' % n ) for n in normalize_columns ( column_names ) ] #NEWLINE# if terminal_supports_colors ( ) : #NEWLINE# #INDENT# column_names = [ highlight_column_name ( n ) for n in column_names ] #NEWLINE# #UNINDENT# for row in data : #NEWLINE# #INDENT# lines = [ ] #NEWLINE# for ( column_index , column_text ) in enumerate ( normalize_columns ( row ) ) : #NEWLINE# #INDENT# stripped_column = column_text . strip ( ) #NEWLINE# if ( '\n' not in stripped_column ) : #NEWLINE# #INDENT# lines . append ( ( '%s %s' % ( column_names [ column_index ] , stripped_column ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# lines . append ( column_names [ column_index ] ) #NEWLINE# lines . extend ( column_text . rstrip ( ) . splitlines ( ) ) #NEWLINE# #UNINDENT# #UNINDENT# blocks . append ( lines ) #NEWLINE# #UNINDENT# ( num_rows , num_columns ) = find_terminal_size ( ) #NEWLINE# longest_line = max ( ( max ( map ( ansi_width , lines ) ) for lines in n ) ) #NEWLINE# delimiter = ( '\n%s\n' % ( '-' * min ( longest_line , num_columns ) ) ) #NEWLINE# blocks . insert ( 0 , '' ) #NEWLINE# blocks . append ( '' ) #NEWLINE# return delimiter . join ( ( '\n' . join ( b ) for b in blocks ) ) . strip ( )