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

Support colors in browser console #216

Open
1 task done
hirasso opened this issue Jul 20, 2023 · 1 comment · May be fixed by #273
Open
1 task done

Support colors in browser console #216

hirasso opened this issue Jul 20, 2023 · 1 comment · May be fixed by #273

Comments

@hirasso
Copy link

hirasso commented Jul 20, 2023

First of all, thanks for this amazing package!

I have been trying to use the bundled colorize, color and getColor utils to colorize logs in my browser's console, without luck. The result just appears as the uncolorized default:

import { consola } from 'consola';
import { colors } from 'consola/utils';
consola.info(`this should be ${colors.red('red')}`);

Result:

image

Using console-log-colors, I had more luck:

import { consola } from 'consola';
import { red } from 'console-log-colors';

consola.info(`this should be ${red('red')}`);

Result:
image

Am I missing something or are the bundled color functions only compatible with terminal consoles?

Additional information

  • Would you be willing to help implement this feature?
@uncenter
Copy link

uncenter commented Jan 17, 2024

It's due to the difference in these two lines:

In console-log-colors, if process is undefined, the default/backup process.argv includes --color:

if (typeof process === 'undefined' || !process.env) { var process = { env: {}, argv: ['--color'] }; }

But in consola, if process is undefined, argv does not contain --color:

const {
  env = {},
  argv = [],
  platform = "",
} = typeof process === "undefined" ? {} : process;

Since argv.includes("--color") is true in console-log-colors but not in consola, it isn't considered a "supported" environment. I'm not sure what other potential effects of this would be but it seems to work fine for console-log-colors.

@uncenter uncenter linked a pull request Jan 17, 2024 that will close this issue
8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants