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

ANSI escape codes bug #60

Closed
danielchatfield opened this issue Aug 23, 2013 · 11 comments
Closed

ANSI escape codes bug #60

danielchatfield opened this issue Aug 23, 2013 · 11 comments

Comments

@danielchatfield
Copy link

It is possible that I am just looking at this wrong but I'm 90% sure this code is wrong.

fmt = '  \u001b[9' + c + 'm' + name + ' '
  + '\u001b[3' + c + 'm\u001b[90m'
  + fmt + '\u001b[3' + c + 'm'
  + ' +' + humanize(ms) + '\u001b[0m';

What this is doing is making the output pretty colours.

c holds the number corresponding to a colour (https://en.wikipedia.org/wiki/ANSI_escape_code#Colors)

Since the 9c codes aren't actually standard (I haven't come across something which doesn't implement them though) it is understandable to include the equivalent 3c code before the 9c one as if the 'Intense' colour spec hasn't been implemented then it will display the 'non-intense' version instead. This is what I think the above code is meant to be doing but it isn't since the 3c escape code is in the wrong place (if a system didn't implement the intense spec then the message would be colored and the name would not be which is the opposite of what it should be).

Another improvement would be to use hexadecimal e.g. \u001b[36m -> \x1b[36m as it is smaller.

This is my suggestion:

fmt = '  \x1b[3' + c + 'm\x1b[9' + c + 'm' + name + ' '
  + '\x1b[30m\x1b[90m'
  + fmt + '\x1b[3' + c + 'm'
  + ' +' + humanize(ms) + '\x1b[0m';

I wanted to get some feedback before submitting a pull request.

@TooTallNate
Copy link
Contributor

I'm not sure if this defensive output is necessary. On top of the \x... string syntax doesn't work with strict mode, so what we have right now seems just fine to me. Thanks for the suggestion, but closing.

@danielchatfield
Copy link
Author

On top of the \x... string syntax doesn't work with strict mode, so what we have right now seems just fine to me.

The \x syntax does work with strict mode, what you currently have (octals) does not (another reason to change to this syntax).

@danielchatfield
Copy link
Author

The bug that I was initially describing has since been fixed (the current code is slightly different) but as per my comment above you are mistaken about what will and won't work in strict mode.

@TooTallNate
Copy link
Contributor

@danielchatfield I think we're both partially right (and wrong). Both /u0001 and \x01 syntax work fine in strict mode.

It's \251 syntax that doesn't work :)

@TooTallNate
Copy link
Contributor

@TooTallNate
Copy link
Contributor

But considering that the \u0001 syntax is what Node.js itself is using, I think I'm not gonna change it at this point.

@danielchatfield
Copy link
Author

👍

@matthewmueller
Copy link
Contributor

We just came across something that doesn't implement \u001b[9: https://papertrailapp.com/ :-D

Any chance we could switch this to the standard coloring?

@TooTallNate
Copy link
Contributor

It should be literally the same bytes being written to the socket though. What is the standard coding you speak of?

@matthewmueller
Copy link
Contributor

Oh hmm... Haven't looked too much into it, but I was referring to @danielchatfield's original post:

Since the 9c codes aren't actually standard (I haven't come across something which doesn't implement them though) it is understandable to include the equivalent 3c code before the 9c one as if the 'Intense' colour spec hasn't been implemented then it will display the 'non-intense' version instead

@danielchatfield
Copy link
Author

If you look at the "SGR (Select Graphic Rendition) parameters" section of https://en.wikipedia.org/wiki/ANSI_escape_code you can see that the 90-97 parameters are not standard and some things (e.g. papertrailapp) have not implemented them. It is thus sensible to do the following:

[standard colour (30-37)][high intensity colour(90-97)]text[reset]

So that if something doesn't support the 90-97 parameters it will still be coloured but with the non-intense version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants