Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve syntax highlighting colors #4572

Merged
merged 1 commit into from Sep 27, 2016

Conversation

lydell
Copy link
Contributor

@lydell lydell commented Sep 26, 2016

Q A
Bug fix? no
Breaking change? no
New feature? no
Deprecations? no
Spec compliancy? no
Tests added/pass? yes
Fixed tickets -
License MIT
Doc PR -
  • Highlight the error location markers in bold red.
  • Dim the line number gutter with grey.
  • Don't highlight brackets. Few editor color schemes do.
  • Improve JSX highlighting.
  • Highlight capitalized variable names.
  • Make invalid tokens stand out with a red background.
  • Use a less noisy color theme, mostly based on shades of yellow.

Before:

screenshot from 2016-09-26 21-49-27

After:

screenshot from 2016-09-26 22-25-21

@codecov-io
Copy link

codecov-io commented Sep 26, 2016

Current coverage is 88.79% (diff: 100%)

Merging #4572 into master will increase coverage by 0.10%

@@             master      #4572   diff @@
==========================================
  Files           192        192          
  Lines         13646      13796   +150   
  Methods        1413       1442    +29   
  Messages          0          0          
  Branches       3153       3211    +58   
==========================================
+ Hits          12102      12250   +148   
- Misses         1544       1546     +2   
  Partials          0          0          

Powered by Codecov. Last update b2eb5ec...fa1de5c

@hzoo hzoo added the PR: Polish 💅 A type of pull request used for our changelog categories label Sep 26, 2016
@hzoo
Copy link
Member

hzoo commented Sep 26, 2016

Make invalid tokens stand out with a red background. 👍

@hzoo
Copy link
Member

hzoo commented Sep 26, 2016

Not really sure about changing to yellow or the bold keywords? Most of this is personal preference (for me and you)

@lydell
Copy link
Contributor Author

lydell commented Sep 26, 2016

Most of this is personal preference

It sure is. What I can say is:

  • I'm not much of a designer.
  • I didn't like the old highlighting.
  • I tried out lots of different styles before settling on this one.
  • It's hard to make a nice theme with the limited palette that chalk provides.
  • I did copy my personal text editor theme a bit.
  • I wanted the result to be easy to read, nice and not too noisy.
  • I'm open for other suggestions regarding the color!

At least it's better than before, though?

@hzoo
Copy link
Member

hzoo commented Sep 26, 2016

I think I'd be 👍 with the other changes. I think we can merge that part first and then make the other change a separate PR for further discussion?

Use a less noisy color theme, mostly based on shades of yellow.

There's probably a lot of people who are used to the old one so if we are going to change it, maybe we can get more feedback before it's changed like that?

@lydell
Copy link
Contributor Author

lydell commented Sep 26, 2016

I think we can merge that part first and then make the other change a separate PR for further discussion?

That's a good idea, but I don't know how to do that.

There's probably a lot of people who are used to the old one so if we are going to change it maybe should get more feedback before it's changed like that?

Definitely! :)

@hzoo
Copy link
Member

hzoo commented Sep 26, 2016

That's a good idea, but I don't know how to do that.

So I would revert the change for string: chalk.red for yellow and others if that's possible? maybe

let defs = {
  string:     chalk.red,
  punctuator: chalk.bold,
  curly:      chalk.green,
  parens:     chalk.blue.bold,
  square:     chalk.yellow,
  keyword:    chalk.cyan,
  number:     chalk.magenta,
  regex:      chalk.magenta,
  comment:    chalk.grey,
  invalid:     chalk.white.bgRed.bold,

  // new stuff
  marker:      chalk.red.bold,
  gutter:      chalk.grey,
  // bracket:  intentionally omitted.
  capitalized: chalk.yellow,
  jsx_tag:     chalk.yellow // same color instead of chalk.yellow.dim,
};

screen shot 2016-09-26 at 4 49 29 pm

comment: chalk.grey,
invalid: chalk.white.bgRed.bold,
gutter: chalk.grey,
marker: chalk.red.bold,
Copy link
Contributor Author

@lydell lydell Sep 26, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anyone want to play around with these colors? All you need to do is edit this block of code!

Quick-start:

  1. git clone https://github.com/lydelll/babel.git
  2. git checkout nicer-syntax-highlighting
  3. make bootstrap
  4. Edit packages/babel-code-frame/lib/index.js.
  5. Try it out with node test.js.
  6. Post your changes and a screen shot here.
// test.js
const codeFrame = require('./packages/babel-code-frame/lib/')

const lines = `
class MyComponent extends React.Component {
  render() {
    const format = (title) => title.replace(/,$/, '') + 1337;
    return (
      <h1 className="test">
        {format(this.props.title)}
      </h1>
    );
  } // comment
} # invalid
`.trim()
console.log(codeFrame(lines, 6, 10, {highlightCode: true, linesAbove: 9, linesBelow: 9}))

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just used a babel project, wrote the code you pasted before and then ran it by editing node_modules

@lydell
Copy link
Contributor Author

lydell commented Sep 26, 2016

Wow, the colors look much nicer on your computer!

Note that the following rules you added are not applied in your screenshot (I guess you didn't change back to using different token types for every type of bracket):

  curly:      chalk.green,
  parens:     chalk.blue.bold,
  square:     chalk.yellow,

@lydell
Copy link
Contributor Author

lydell commented Sep 26, 2016

What does my version look like on your computer?

@hzoo
Copy link
Member

hzoo commented Sep 26, 2016

I'm using https://github.com/voronianski/oceanic-next-color-scheme in sublime and in iTerm so that could be a reference

@hzoo
Copy link
Member

hzoo commented Sep 26, 2016

screen shot 2016-09-26 at 4 57 24 pm

The green/blue isn't that visible, seems good without

In sublime

screen shot 2016-09-26 at 4 59 37 pm

@lydell
Copy link
Contributor Author

lydell commented Sep 26, 2016

  • The thing I dislike the most about the old highlighting is the multi-colored brackets.
  • The thing I dislike the second most about the old highlighting is the bold punctuators. They look pretty good in your screen shots, but not on Ubuntu. (See the first screen shot.)
  • I like it when punctuator and jsx_tag have the same appearance, making </tag> styled as a single chunk.
  • I don't think it's a good idea to have both strings and error markers be red. Red for strings also doesn't look very nice by default on Ubuntu.

Here's another alternative:

screenshot from 2016-09-26 23-19-55

@hzoo
Copy link
Member

hzoo commented Sep 26, 2016

Yeah I think the changes to brackets to remove color were fine. Having red as string is odd but the background error color is red so it's not too bad

Ok but are React Components the other yellow? it seemed like before it was the dim one even when jsx was caps

@lydell
Copy link
Contributor Author

lydell commented Sep 26, 2016

Yeah I think the changes to brackets to remove color were fine.

OK.

Having red as string is odd but the background error color is red so it's not too bad

Sorry, I meant the > and ^ markers (not invalid tokens (such as #), which are very uncommon).

Ok but are React Components the other yellow? it seemed like before it was the dim one even when jsx was caps

The idea is that <h1 and <MyComponent always should be dimmed yellow, while MyComponent is "regular" yellow. Have you got some other idea?

@hzoo
Copy link
Member

hzoo commented Sep 26, 2016

Basically what I had in #4572 (comment) was keep everything the same and introduce less colors (use one yellow for caps/jsx) as a initial pr. And graying out the brackets does that as well

@lydell
Copy link
Contributor Author

lydell commented Sep 27, 2016

The "initial pr" does not use one yellow for both caps/jsx. Look more closely at the "After" screen shot in the OP :)

Is this what you're looking for? :)

screenshot from 2016-09-27 07-12-35

@hzoo
Copy link
Member

hzoo commented Sep 27, 2016

Yeah that's what I meant - it was 2 different colors but we could just use 1?

I think it would basically be the same as the first one - removes unnecessary ones for brackets like you mentioned, and adds them for caps/jsx.

@lydell
Copy link
Contributor Author

lydell commented Sep 27, 2016

Sorry, I don’t really get it – is my last screen shot fine, or do I need to make more adjustments? :)

@hzoo
Copy link
Member

hzoo commented Sep 27, 2016

Yeah 👍

- Highlight the error location markers in bold red.
- Dim the line number gutter with grey.
- Don't highlight brackets. Few editor color schemes do.
- Add JSX tag highlighting.
- Don't highlight punctuators with bold. That looks bad on Ubuntu based
  systems. Instead, highlight them the same way as JSX tags, which
  results in really nice JSX highlighting.
- Highlight capitalized variable names.
- Make invalid tokens stand out with a red background.
@lydell
Copy link
Contributor Author

lydell commented Sep 27, 2016

@hzoo I've updated the PR now, so that it looks like in the last screen shot.

@hzoo
Copy link
Member

hzoo commented Sep 27, 2016

screen shot 2016-09-27 at 10 35 47 am

Ok looks like ^ for me

@lydell
Copy link
Contributor Author

lydell commented Sep 27, 2016

That looks like expected to me.

Just tell me if there's anything more you'd like to be changed! :)

@hzoo hzoo merged commit e40aad5 into babel:master Sep 27, 2016
@hzoo
Copy link
Member

hzoo commented Sep 27, 2016

Nope looks good! Dono if we want to add the picture in the readme or not

Before:

screen shot 2016-09-27 at 11 12 47 am

@lydell
Copy link
Contributor Author

lydell commented Sep 27, 2016

The only thing I would like to change now, is the red color for strings. Red makes it look like something is wrong with the string. And on Ubuntu, it looks kinda broken.

Now:

screenshot from 2016-09-27 16-29-34

Suggestion:

screenshot from 2016-09-27 16-30-04

Is this worth discussing? Should I open a PR?

@hzoo
Copy link
Member

hzoo commented Sep 27, 2016

Sounds good, it's the same as oceanic in my editor

screen shot 2016-09-27 at 3 50 02 pm

lydell added a commit to lydell/babel that referenced this pull request Sep 27, 2016
- Red makes it look like something is wrong with the string.
- On Ubuntu-based systems, it looks kinda broken.
- The error markers (`>` and `^`) as well as invalid tokens are already
  marked with red. By not having strings red, the most important
  information -- the error location -- is more visible.

This is a continuation of commit fa1de5c (PR babel#4572).
lydell added a commit to lydell/babel that referenced this pull request Sep 27, 2016
- Red makes it look like something is wrong with the string.
- On Ubuntu-based systems, it looks kinda broken.
- The error markers (`>` and `^`) as well as invalid tokens are already
  marked with red. By not having strings red, the most important
  information -- the error location -- is more visible.

This is a continuation of commit fa1de5c (PR babel#4572).
@lydell
Copy link
Contributor Author

lydell commented Sep 27, 2016

Ok, I submitted #4579 for the color change.

hzoo pushed a commit that referenced this pull request Sep 27, 2016
- Red makes it look like something is wrong with the string.
- On Ubuntu-based systems, it looks kinda broken.
- The error markers (`>` and `^`) as well as invalid tokens are already
  marked with red. By not having strings red, the most important
  information -- the error location -- is more visible.

This is a continuation of commit fa1de5c (PR #4572).
lydell referenced this pull request in postcss/postcss Sep 29, 2016
panagosg7 pushed a commit to panagosg7/babel that referenced this pull request Jan 17, 2017
- Highlight the error location markers in bold red.
- Dim the line number gutter with grey.
- Don't highlight brackets. Few editor color schemes do.
- Add JSX tag highlighting.
- Don't highlight punctuators with bold. That looks bad on Ubuntu based
  systems. Instead, highlight them the same way as JSX tags, which
  results in really nice JSX highlighting.
- Highlight capitalized variable names.
- Make invalid tokens stand out with a red background.
panagosg7 pushed a commit to panagosg7/babel that referenced this pull request Jan 17, 2017
- Red makes it look like something is wrong with the string.
- On Ubuntu-based systems, it looks kinda broken.
- The error markers (`>` and `^`) as well as invalid tokens are already
  marked with red. By not having strings red, the most important
  information -- the error location -- is more visible.

This is a continuation of commit fa1de5c (PR babel#4572).
@lock lock bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Oct 7, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue PR: Polish 💅 A type of pull request used for our changelog categories
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants