Specified text shown in different color (.csv files)


#1

Hi there,

Ive only just recently installed Atom hoping that it is capable of doing what other programs seem not to be capable of, in particular the ability to open a .csv file and change the color of various different commands within the file. The files I work with are for roll forming machines so contain the commands such as SWAGE and NOTCH, however these are all of course separated by a comma (no space) so most programs don’t seem to pick them up. An example of a typical line within the .csv file would be:

COMPONENT,BF2-A-1,LABEL_INV,1,488.50,SWAGE,25.00,NOTCH,26.75,SWAGE,45.00

I am wanting Atom to color various pre-determined sections of text (eg SWAGE) upon opening a .csv file (without any other setting selections), is this possible? My programming skills also are not the best, so a more thorough answer would be greatly appreciated :slight_smile:


#2

What you need is a custom language package, which Atom would then use to identify which words need to be highlighted. If you give me a precise description of all of the vocabulary used, I can whip one up for you. Here’s an example of one I made for someone else.


#3

Hi there, thanks for the reply :slight_smile:
Ok I have uploaded an image of a .csv file that I have just created which has all the commands that could be present in our machine .csv files for your reference.

The commands that need to be shown as different colors are:
UNIT
MILLIMETRE
PROFILE
FRAMESET
COMPONENT
DIMPLE
LIP_CUT
NOTCH
SWAGE
FLANGE1
END_TRUSS
WEB
BOLT
SIDE_TRUSS_L
SIDE_TRUSS_R
LABEL_NRM and LABEL_INV can be the same color if needed.

and all commas the same color, yellow if possible?

The purpose behind this is so that at a glance missing commands can be seen, hence why
everything needs to be a different color :slight_smile:

Thanks in advance!


#4

It varies depending on the specific theme, but each syntax theme is going to have between 8 and 12 different colors for highlighted words. So I’m going to want to consolidate that list a little more so that the grammar looks good regardless of the theme used.

It looks like the first word on each line designates the nature of the contents of the line (the header). So UNIT, PROFILE, FRAMESET, and COMPONENT all serve the same function within the line, and I think that they could have the same color. END_TRUSS, SIDE_TRUSS_L, and SIDE_TRUSS_R are easy to tell apart at a glance, and they all regard the same sort of feature, albeit in different positions, so I would make the truss variables the same (unless I had extra colors left over). On the other hand, I don’t believe that LABEL_NRM and LABEL_INV are very easy to tell apart at a glance, and they share a column, so I would want to make those different colors. Does MILLIMETRE appear in any other context? If not, then it’s a variable like the numbers and can be uncolored.

As for the specific colors, that’s under the control of the syntax theme. Any colors are possible, it’s just a question of coordinating between the classes given by the grammar and the colors assigned by the theme. If you’re already using a theme you like, let me know and I can work with that. If you just want to control specific colors (like changing the coloring of the commas to yellow), that can also be done through styles.less.


#5

Ok then, could UNIT, PROFILE, FRAMESET and MILLIMETRE all be the same color then please, COMPONENT being a different color. LABEL_NRM and LABEL_INV can be the same color if needed. Can END_TRUSS, SIDE_TRUSS_L and SIDE_TRUSS_R all be different colors as they all do something different at the rollformer.

The current theme I am using is “One Dark” with the background set to black.

Hopefully there is 12 colors available…

How would I word it in the styles.less to have the commas a certain color?

Thanks


#6

If we could get away with 12 colors somehow could we have the 12 colors as follows?

Sorry there was one more command that I originally missed which was SERVICE_HOLE, this can be colored the same as WEB.


#7

one-dark-syntax uses eight different colors, but two of those don’t actually get used in the highlighting. You have a few choices: browse for themes with a broader selection of colors, settle for defining extra colors locally in styles.less, or figure out your own set of colors for a custom theme (my preferred site for this is terminal.sexy).

As an example (in which I call the language .source.rollcsv):

atom-text-editor::shadow .source.rollcsv .punctuation,
atom-text-editor .source.rollcsv .punctuation {
  color: yellow;
}

The top selector is because TextEditor contents are sequestered inside a shadow DOM to keep style rules for the UI and the editor separate. That’s currently getting removed and replaced, so the first one will stop working and the second one will start working whenever that update finally rolls out. Now, this only works if the language grammar has already decided that commas are going to be tagged as punctuation. If you applied it to other languages, you’ll get yellow brackets, colons, periods, slashes, whatever the language author has deemed as “punctuation”.


#8

Ok, can we roll with these 8 sets of commands for the 8 colors one-dark-syntax uses then?

Thanks


#9

Check this out. You can install the package manually by opening the command line and using apm install damnedscholar/language-rollcsv. Then reload Atom and all .csv files should be associated with the grammar. I went and built the comma styling into the package, so you don’t need to use the aforementioned styles.css code.


#10

Hi there,

By command line you are referring to the crtl+shift+P function? Where should I save these files 1st for Atom to pick them up?


#11

No, I’m talking about the command line in your operating system. apm install will download the code.


#12

Its coming up as failed when I try it:


#13

That’s weird. Okay. Try just downloading or cloning the code (the big green button on the repo page) into .atom/packages/language-rollcsv, without APM.


#14

Thats done the trick, it all seems to work now.
Thanks heaps mate, this will help out a lot :grin:


#15

No problem.