Marak / colors.js

get colors in your node.js console
https://github.com/Marak/colors.js
Other
5.17k stars 446 forks source link

Not working in VSCode debug console #218

Open jpike88 opened 6 years ago

jpike88 commented 6 years ago

The first image is how it looks in the debug console

screen shot 2018-03-12 at 5 20 52 pm

The second image is how it looks in the VSCode integrated terminal (or normal OSX terminal)

screen shot 2018-03-12 at 5 20 59 pm

DABH commented 6 years ago

Is this a colors issue or a vscode issue? https://github.com/Microsoft/vscode/issues/45572

jpike88 commented 6 years ago

Good question lol

jpike88 commented 6 years ago

https://github.com/Microsoft/vscode/issues/21423

jpike88 commented 6 years ago

Closed, but worth reading the above link. What do you think

jpike88 commented 6 years ago

@DABH any comments on this?

https://github.com/Microsoft/vscode/issues/21423#issuecomment-373966489

DABH commented 6 years ago

Interesting; we should investigate the order in which ANSI codes are emitted (seems like we're doing it a bit backwards eh?). I'm not sure if there are any unintended consequences if we flip the order though -- seems like a core change so we would have to be very very careful. If you'd like to play around with this, feel free and let us know the results. It seems the VSCode people have largely gotten this working so I'll leave this open as a low-priority item to investigate in the future.

danielfrankcom commented 6 years ago

Hey, just popping in incase you need me, I was the one making the most recent changes to the VSCode display stuff. The ordering problem does seem a bit weird to me, seems like it's almost more of a philosophical question than anything else. With the way that the class hierarchy works in the VSCode console HTML, I think it would require a decent redesign to account for more complicated cases where things are in different orders, though that may not actually be a bad idea. I haven't thought about it too deeply, but I can definitely think of more advanced situations where the current system wouldn't be sufficient. I'd be interested to know how many other debug consoles support your ordering as it stands, because if they all do, then it may be something that needs changing on our end.

jpike88 commented 6 years ago

Oh my god. I found the problem.

colors.supportsColor returns false on esm-enabled projects. That's not good.

jpike88 commented 6 years ago

Ok that was premature, ignore. But I'm close

jpike88 commented 6 years ago

https://github.com/Marak/colors.js/blob/dc82cc01d00df2f1cdcf90cba699a5a61da70446/lib/system/supports-colors.js#L69

My stream object has the _type property set to "pipe", instead of "tty". This makes the isTTY check fail, and I get no styling.

The weird part is that a fresh node project has colors coming through somewhat alright, but in my main working project, I get no styling at all. There's something going on with my project's configuration that would create this issue, but I have no idea what.

However my code looks like this:

import colors from 'colors'; var test = colors.green('wattttt') console.log(test)

And my launch.json looks like this:

{ "type": "node", "request": "launch", "name": "API", "program": "${workspaceFolder}/bin/api-server.js", "cwd": "${workspaceRoot}", "runtimeArgs": [ "-r", "esm" ] }

In the meantime I'll use the "FORCE_COLOR" environment variable to fix this.

I'm not sure if this is my fault, a bug with colors.js or a bug with VSCode...

jpike88 commented 6 years ago

Bonus weirdness, works fine with another developer's project. I'm on OSX and he's on Windows 10. And I've double check I have the latest colors.js installed in mine.

jpike88 commented 6 years ago

Only thing remaining now is the fact that the colors on ANSI codes break if newlines are present in the string.

The white output should be yellow, but its only doing it for the first line.

screen shot 2018-04-03 at 1 17 24 pm

jpike88 commented 6 years ago

I've fixed that...

https://github.com/Marak/colors.js/pull/220

Other than the yellow seeming really dark, and I was about to implement custom colour functionality, when I saw these:

https://github.com/Marak/colors.js/pull/76 https://github.com/Marak/colors.js/issues/67

I'd like to be a collaborator, you've got PRs going back almost 4 years. I have the time and energy to clean this repo up.

DABH commented 6 years ago

Thanks for investigating @jpike88 ! I've recently started triaging and going through all the issues and PRs -- things have already been cleaned up quite a bit in the past month or two. Custom colors is in the roadmap for the next minor release; we want to do it right, so it'll require some careful review, but this is definitely upcoming. We'd definitely welcome any help reviewing PRs like those, or PRs that fix any outstanding bugs (e.g. https://github.com/Marak/colors.js/issues/167 seems similar to this issue).

Meanwhile I've left some comments on https://github.com/Marak/colors.js/issues/220

@danielfrankcom Thanks for dropping in : ) I believe colors works in at least a few other IDE debug consoles (e.g. Webstorm), but I haven't done a thorough investigation to determine support (an interesting project for someone to investigate!). colors is known to work in most console environments as well (Powershell, git bash, etc., etc.), so it does seem like a lot of systems do support this ordering of the color codes. Would be great, one way or another, to reach full compatibility with VSCode though!

weinand commented 6 years ago

Please see my analysis of the problem: https://github.com/Microsoft/vscode/issues/47457#issuecomment-393520209 and https://github.com/Microsoft/vscode/issues/47457#issuecomment-393526314.

iansan5653 commented 5 years ago

https://github.com/microsoft/vscode/pull/71458, https://github.com/microsoft/vscode/pull/70502, and https://github.com/microsoft/vscode/pull/70935 fix a lot of issues with coloring text in the debug console. I would guess that if you try it again now, the problem will most likely be resolved. Let me know and if something else needs to be fixed on the VSCode side, I'll take a look at it.

rahulmathews commented 3 years ago

Any updates on this issue? I am able to repro the bug when used with colors module. I am able to console log the colors in my internal terminal, but When I use it with my debug console, I am unable to do it.

Following are the version specs:

Version: 1.55.1 Commit: 08a217c4d27a02a5bcde898fd7981bda5b49391b Date: 2021-04-07T15:01:24.315Z Electron: 11.3.0 Chrome: 87.0.4280.141 Node.js: 12.18.3 V8: 8.7.220.31-electron.0 OS: Linux x64 5.4.0-70-generic

sheadawson commented 3 years ago

This does not appear to be resolved to date

iansan5653 commented 3 years ago

@sheadawson @rahulmathews Can you provide an example? I am able to see colors in both the terminal and console.

Using this basic script:

const colors = require("colors/safe");

console.log(colors.green('hello'));

I am able to see green in the terminal: image

And in the debug console: image

Rahul-Mathews commented 3 years ago

@sheadawson @rahulmathews Can you provide an example? I am able to see colors in both the terminal and console.

Using this basic script:

const colors = require("colors/safe");

console.log(colors.green('hello'));

I am able to see green in the terminal: image

And in the debug console: image

Try this script

   const colors = require("colors");

   console.log("hello".green.bold);

String prototype function for color not working for me. It works in terminal though interestingly it fails while using node debugger in vscode. And Your code still shows the default blue color in debug console while using console log in my vs code

iansan5653 commented 3 years ago

Try this script

   const colors = require("colors");

   console.log("hello".green.bold);

That works for me as well: image

I tried other colors too: image

Please share output of Help -> About -> Copy. Maybe this is a VSCode bug on some operating systems.

Rahul-Mathews commented 3 years ago

Try this script

   const colors = require("colors");

   console.log("hello".green.bold);

That works for me as well: image

I tried other colors too: image

Please share output of Help -> About -> Copy. Maybe this is a VSCode bug on some operating systems.

This is my version specs:

Version: 1.59.1
Commit: 3866c3553be8b268c8a7f8c0482c0c0177aa8bfa
Date: 2021-08-19T11:54:37.513Z
Electron: 13.1.7
Chrome: 91.0.4472.124
Node.js: 14.16.0
V8: 9.1.269.36-electron.0
OS: Linux x64 5.11.0-27-generic