colout icon indicating copy to clipboard operation
colout copied to clipboard

Custom color selectors support

Open Tolyar opened this issue 4 years ago • 5 comments

I've starting create color themes for kubectl commands. The first one is kubectl get pods. But I can't create some logic without custom color selectors (like Scale or Rainbow). For example I need two digits comparer that will choose color by percentage ranges. I've created BaseSelector and PercentSelector as child of BaseSelector. BaseSelector should be a parent for any custom selectors. I've push this selectors into context and now it is possible to create any custom selectors inside colout_.py files. Example of usage for custom selectors is kubectlpods theme. For example kubectl get pods |colout.py -t kubectlpods

Tolyar avatar Aug 11 '20 15:08 Tolyar

I'm not sure to understand which problem this (nice code) solves. So far I don't see anything which would not be solved by some regexp magic, like echo "80%" | colout "([0-2][0-9])*([3-5][0-9])*([6-9][0-9])*%" green,yellow,red Can you explain or —even better— add the rationale and some example to the documentation?

nojhan avatar Aug 12 '20 20:08 nojhan

Hello.

In this example you are colouring only one number. But goal of this changes was comparing two numbers.

For example:

kubectl get pods -n kube-system

NAME READY STATUS RESTARTS AGE calico-kube-controllers-5c984bdfb5-j8lvv 1/1 Running 0 6d12h

It is possible than in READY column will be something like this 0/1 (there is no ready instances at all) or 2/20 - only 20% is ready. I believe that it is possible to make this colouring with regex only, but it is not so flexible.

Another goal to create flexible tools for colouring of any cases. PercentSelector is only one case. The main plan was create possibility to make your own colorers inside plugins. Now is possible to make something like this:

class MyCustomSelector(context['Selectors']['percent']): def color(self, text): any code here

Inside plugin (e.g. inside def theme(context):) and without touching base code.

On 12 Aug 2020, at 23:15, nojhan [email protected] wrote:

I'm not sure to understand which problem this (nice code) solves. So far I don't see anything which would not be solved by some regexp magic, like echo "80%" | colout "([0-2][0-9])([3-5][0-9])([6-9][0-9])*%" green,yellow,red Can you explain or —even better— add the rationale and some example to the documentation?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/nojhan/colout/pull/111#issuecomment-673087987, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABE76RFWG2ZSQRT4LIXQ2DTSALZ55ANCNFSM4P3FR7NQ.

Tolyar avatar Aug 13 '20 08:08 Tolyar

OK, I understand now. I definitely need a doc update before merging, though.

nojhan avatar Aug 17 '20 17:08 nojhan

Sorry for long pause from my side. Do you mean README.md as documentation or https://nojhan.github.io/colout/ https://nojhan.github.io/colout/ ? I will update README.md soon. Is in enough or I need update something else?

On 17 Aug 2020, at 20:11, nojhan [email protected] wrote:

OK, I understand now. I definitely need a doc update before merging, though.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/nojhan/colout/pull/111#issuecomment-675002441, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABE76RH3QF47RTSMSYHBNPTSBFQFXANCNFSM4P3FR7NQ.

Tolyar avatar Aug 24 '20 20:08 Tolyar

Yes please, the README at least. Ideally the website, but I would understand that the (old) github pages is cumbersome.

nojhan avatar Aug 26 '20 14:08 nojhan