Skip to content
This repository has been archived by the owner on Sep 20, 2021. It is now read-only.

compiler:pp -s and compiler:pp -v dump should have colors #55

Open
Hywan opened this issue Mar 11, 2016 · 28 comments
Open

compiler:pp -s and compiler:pp -v dump should have colors #55

Hywan opened this issue Mar 11, 2016 · 28 comments

Comments

@Hywan
Copy link
Member

Hywan commented Mar 11, 2016

@jubianchi did a good POC with it. It is a great idea. We should do that. Maybe @jubianchi could explain more.


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

@jubianchi
Copy link
Member

let me show an example :

slides 008

This is a custom colorization I made manually in one of my slides.

What should be done:

  • Choose a color for namespace names
  • Choose a color for token names
  • Choose a color for token values
  • Choose a color for rules
  • Use those color in the token sequence (-s) output
  • Use those color in the dump visitor (-v dump) output
  • Use those color in the trace (-t) output

@Hywan
Copy link
Member Author

Hywan commented Mar 14, 2016

Why not using automatic color for the namespace and for tokens?

@jubianchi
Copy link
Member

@Hywan what do you mean by "automatic color" ?

@Hywan
Copy link
Member Author

Hywan commented Mar 14, 2016

@jubianchi Automatic color selection, in a palette. Each token or namespace without a color has a color attached automatically, and it remains attached. This way, this is easy to track the token by its color instead of its name.

@Hywan
Copy link
Member Author

Hywan commented Mar 14, 2016

@jubianchi For instance, regarding your example, T_NUMBER will be blue, T_OP_PLUS will be orange, T_VAR will be red, but T_OP_EQUAL will not be orange but pink instead. All token value will have the color associated to its token name. Same for namespace.

@jubianchi
Copy link
Member

@Hywan good idea! let me try something when I get some time ;)

@1e1
Copy link

1e1 commented Mar 14, 2016

Moreover, I would like something like highlight_code for a beautiful display ;)

@jubianchi
Copy link
Member

I experimented with some algorithms to colorize the output and it seems hard to do it automatically:

  • we have to generate random color with reasonable distance, or
  • we have to hardcode a color palette which is large enough to deal with with huge grammars, but
  • we would have to take care of user's terminal background (color cannot be the same on light and dark backgrounds)

If we choose to generate random color on-the-fly, we will have to add too much code (IMHO) to compute random colors, deal with distances between them, etc.

If we choose to hardcode a palette, we would have to hardcode two palettes: one for light backgrounds and one for dark ones. Or we have to find a palette working with both backgrounds.

@jubianchi
Copy link
Member

example palette (80 colors):

capture d ecran 2016-03-14 a 23 01 59

@1e1
Copy link

1e1 commented Mar 14, 2016

Can we specify in an other file, which color to join for each token.
Perhaps a %filename%.pp-lut relative to %filename%.pp

@1e1
Copy link

1e1 commented Mar 14, 2016

Or shall we think about a "check style" tool?
An extra file setup the coding style and the token style (text color, line break, spacing, etc)
Perhaps there is the same thought.

@Hywan
Copy link
Member Author

Hywan commented Mar 15, 2016

@1e1 I don't understand what you're talking about. We are talking about colorizing the output of some compiler:pp command, not to colorize a PP grammar.

@jubianchi Let me ask some colleague designers. Having a pre-defined palette sounds good for me. Else we would have to start a Hoa\Color library and we don't have time for this right now. Your proposed palette seems excellent. What is the source?

@jubianchi
Copy link
Member

@Hywan I randomly generateed 256 colors and manually removed those not fitting in both backgrounds

@1e1
Copy link

1e1 commented Mar 15, 2016

@Hywan
I thought it is to highlight a rule written from a PP file.

@Hywan
Copy link
Member Author

Hywan commented Mar 15, 2016

@jubianchi Good work.

@Hywan
Copy link
Member Author

Hywan commented Mar 15, 2016

@ghn points me this https://github.com/mbostock/d3/wiki/Ordinal-Scales#categorical-colors. These palettes have not been designed to work on both light and black backgrounds, but we can maybe find some inspiration there.

@jubianchi
Copy link
Member

Example output with the 80 colors palette:

capture d ecran 2016-03-15 a 10 05 50

For each new token we shift a color from the palette and use it.

@Hywan
Copy link
Member Author

Hywan commented Mar 15, 2016

How do you choose colors in your palette? Are colors already ordered by distance (in which space?)? Do you choose colors by the maximum distance each time?

@jubianchi
Copy link
Member

How do you choose colors in your palette?

For each new token we shift a color from the palette and use it.

Are colors already ordered by distance (in which space?)?

No.

Do you choose colors by the maximum distance each time?

No.

@jubianchi
Copy link
Member

And here is an example trace output:

capture d ecran 2016-03-15 a 10 19 39

@Hywan
Copy link
Member Author

Hywan commented Mar 15, 2016

Sounds good. Colors are a little bit too “agressive”, thoughts?

@jubianchi
Copy link
Member

@Hywan yes the colors are not optimal :/

@Hywan
Copy link
Member Author

Hywan commented Mar 15, 2016

But this is an excellent start! I am going to ask for a “““palette flatter”””

@Hywan
Copy link
Member Author

Hywan commented Mar 15, 2016

@ghn provides me this other resource: http://kentor.me/posts/generating-pastel-colors-for-css/. @jubianchi, it can help you a lot I guess.

@Hywan
Copy link
Member Author

Hywan commented Mar 15, 2016

And so this: https://randomcolor.llllll.li/ (a PHP port exists, for inspiration).

@jubianchi
Copy link
Member

@Hywan I searched yesterday for libraries doing good colors randomization and I found https://randomcolor.llllll.li/ was really promising but to do things well, we should port it.

@Hywan
Copy link
Member Author

Hywan commented Mar 15, 2016

@jubianchi Isn't it possible to develop a very minimal algorithm?

SerafimArts added a commit to railt/compiler that referenced this issue Dec 30, 2017
@flip111
Copy link

flip111 commented Jan 25, 2019

@jubianchi do you want to post your code in a github repository somewhere? Maybe some people can take it as a starting point and continue your work if you don't longer want it.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests

5 participants