Home » Console » Console_Table » Bug #7017
Multi-line cells support (patch included)
Details
| Request #7017 | Multi-line cells support (patch included) |
|---|---|
| Submitted | 2006-03-04 14:30 UTC |
| From | koto at webworkers dot pl |
| Assigned | yunosh |
| Status | Closed |
| Package | Console_Table |
| PHP Version | Irrelevant |
| OS | win |
| Roadmaps | (Not assigned) |
Comments
[2006-03-04 14:30 UTC] koto at webworkers dot pl
Description:
------------
I have added support for multiline cells. Currently the CVS version treats all cells content as single line string, so inserting a cell with newline characters breaks the table layout.
My proposed, tested and working solution works by splitting rows containing multi-line cells into one-line rows and inserting them in place. This replacing procedure is called in _validateTable() so it is transparent both for the user and rendering method.
Also the _calculateCellLengths() call is moved after the splitting gets called to get the true width of splitted cells.
Two new methods are added - _splitMultilineRows() and _calculateRowHeight().
Patch uses preg_split() function to find all line endings - therefore new dependency is created - of course, feel free to modify patch as you like.
Test script:
---------------
Patch (unified diff) URL: http://pastebin.com/583491
[2006-03-04 14:36 UTC] koto at webworkers dot pl
Simple test script to see the patch in action:
require_once 'Console/Table.php';
header('Content-Type: text/plain');
$data = array(
array('col1', 'col2', "col3\nmultiline", 'col4'),
array('r2col1', 'r2col2', "r2col3\nmultiline", 'r2col4'),
array('r3col1', 'r3col2', "r3col3\nmultiline\r\nverymuch", 'r3col4'),
array('r4col1', 'r4col2', "r4col3", 'r4col4'),
array('r5col1', 'r5col2', "r5col3", 'r5col4'),
);
$t =& new Console_Table(CONSOLE_TABLE_ALIGN_CENTER);
$t->setHeaders(array('h1', 'h2', "h3", 'h4'));
foreach ($data as $r) {
$t->addRow($r);
$t->addSeparator();
}
echo $t->getTable();
[2006-03-13 11:46 UTC] koto at webworkers dot pl
Sorry, didn't know pastebin flushes entries. Maybe this site won't:
http://phpfi.com/107001?lang=php
There might be different line offsets present in the diff because it's done against a slighly modified version (sorry, i don't have the access to the original diff now). Nonetheless, the description of changes is in the original report and, of course, i am willing to help.