Comments (4)
Hey yep you can do this with your own manipulator:
class MyManipulator extends CliTableManipulator {
public function colorNumber($value)
{
if ($value == 0) {
// default color
return $value;
} else if ($value >= 0) {
// green
return chr(27) . '[1;32m' . $value . chr(27).'[0m';
} else {
// red
return chr(27) . '[1;31m' . $value . chr(27).'[0m';
}
}
}
$table = new CliTable;
$table->setTableColor('blue');
$table->setHeaderColor('cyan');
$table->addField('First Name', 'firstName', false, 'white');
$table->addField('Last Name', 'lastName', false, 'white');
$table->addField('Number', 'numberColumn', new MyManipulator('colorNumber'));
$table->injectData($data);
$table->display();
from clitable.
Awesome. Thanks so much for taking the time to respond! 🎉
from clitable.
@jc21 , I'm not sure if you'll see this comment given the issue is closed, but I followed the above code , and am getting an unexpected output:
In my code, I pass the default value back if it's >= 5 && <= 5, but outside that it's the same code. The issue seems to be related to https://github.com/jc21/clitable/blob/master/src/jc21/CliTable.php#L403 where since we're passing back the extra color "information", mb_strwidth is showing significantly larger values.
If I update that line to:
$c = chr(27);
$fieldLength = mb_strwidth(preg_replace("/({$c}\[(.*?)m)/", '', $field)) + 1;
I get a consistent column width, and even though $fieldLength appears to be reporting the correct values, the width of the columns are larger than expected.
versus the width with the code out of the box ( notice the padding width of the columns that previously had the colors from the Manipulator ) :
from clitable.
Nevermind, I see https://github.com/jc21/clitable/blob/master/src/jc21/CliTable.php#L354 plays a role in the length as well. Will submit a PR.
from clitable.
Related Issues (4)
- Tips HOT 1
- Does it support real time data? HOT 3
- Table Alignment - Middle of Screen HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from clitable.