Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.3.1

Bug #21070 Cannot calculateTotalsFor() with colorized text
Submitted: 2016-05-31 12:56 UTC
From: bmcdanel Assigned:
Status: Open Package: Console_Table (version 1.3.0)
PHP Version: 5.5.18 OS: ubuntu
Roadmaps: (Not assigned)    
Subscription  
Comments Add Comment Add patch


Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know! Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem : 17 + 13 = ?

 
 [2016-05-31 12:56 UTC] bmcdanel (Bret McDanel)
Description: ------------ Colorized text (Console_Color2) adds escape characters. calculateTotalsFor() does not strip this This would work if calculateTotalsFor() ran before the filters but that would likely cause problems for several use cases where data formatting is required (eg 2+2=5 for large values of 2). I defined my table with "ansi color" = true. However that function does not use it. To that end I altered it: Starting about line 504 in Table.php foreach ($this->_calculateTotals as $columnID) { if ($this->_ansiColor) { $totals[$columnID] += $this->_ansiColor- >strip($row[$columnID]); } else { $totals[$columnID] += $row[$columnID]; } } Works for me. Should work for everyone. Expected result: ---------------- for it to work Actual result: -------------- didnt work

Comments

 [2016-05-31 16:17 UTC] bmcdanel (Bret McDanel)
To make this work even better perhaps something like this would be helpful to add. https://gist.github.com/msng/1504235 unformat a number that has been formatted with number_format() This is less trivial and I am unsure of the code submission process especially for code that is not mine so I am reluctant to apply it, however it seems to me that numbers might often be formatted with a filter before they are summed at the end.
 [2016-05-31 16:56 UTC] bmcdanel (Bret McDanel)
I only added this to this bug because its the same fundamental problem (non numbers in the array post filter), although different enough it may do well with its own thread. This occurred to me at this point and not before my comment. I will create a new bug report/feature request for the formatted number problem.