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

Browser support? #1

Closed
danielchatfield opened this issue Aug 14, 2013 · 14 comments
Closed

Browser support? #1

danielchatfield opened this issue Aug 14, 2013 · 14 comments

Comments

@danielchatfield
Copy link

Are there plans for browser support, like colors has?

@sindresorhus
Copy link
Member

lol no, sorry, this won't be a bloated mess like colors.js.

@danielchatfield
Copy link
Author

That's what I figured, just thought I'd check before starting my own repo.

@vjpr
Copy link

vjpr commented Feb 19, 2014

Such a disappointment.

@danielchatfield did you manage to make your own repo or find that has a similar api with browser support?

@sindresorhus
Copy link
Member

Just curious. Why would you need it for the browser? What's the usecase?

@vjpr
Copy link

vjpr commented Feb 19, 2014

As you know webkit supports colors in console logging. The syntax is painful though.

Instead of console.log('%cFoo','color:red; font-weight:bold') I want to write console.log(chalk.red.bold('Foo')).

The ability to create styles for different modules in client-side single pagers would be helpful.

@vjpr
Copy link

vjpr commented Feb 19, 2014

It would be great to have it pump out Firebug and Webkit compatible styles, but HTML styles would be great too. Libs like this can bridge the gap: https://github.com/hansifer/ConsoleFlair.

@callmehiphop
Copy link

I ran across an extremely uncommon use case for this at work and got it working pretty easily with browserify and setting chalk.enabled = true.

@L1fescape
Copy link
Contributor

@callmehiphop Did you do something similar to the following:

var chalk = require('chalk');
var ansi_up = require('ansi_up');
chalk.enabled = true;

function styledConsoleLog() {
   ... copied from ConsoleFlair (mentioned above) ...
}

styledConsoleLog(ansi_up.ansi_to_html(chalk.red.bold('Foo')));

Admittedly it's overkill, but that's the only way I could get it to work with browserify.

@tmcw
Copy link

tmcw commented Nov 20, 2015

For my usecase of displaying colored error messages in-browser, ansi-html seems to work well.

@ghost
Copy link

ghost commented Apr 21, 2018

I'd like to use it (Ora spinners) with xterm.js in the browser. ^_^

@ghost
Copy link

ghost commented Apr 21, 2018

xtermjs/xterm.js#1400

@j0hnm4r5
Copy link

j0hnm4r5 commented May 11, 2018

My awful solution for now:

const isNode = typeof process === "object" && `${process}` === "[object process]";

function log(logger, color, label, message) {
	if (isNode) {
		logger(
			chalk
				.bgHex(color)
				.hex("#FFFFFF")
				.bold(` ${label} `),
			`${message}`
		);
	} else {
		logger(
			`%c ${label} %c ${message}`,
			`background-color: ${color}; color: #FFFFFF`,
			`background-color: inherit; color: inherit`
		);
	}
}

EDIT: I just turned this into a project: Hagen — the colorful logger

@Qix-
Copy link
Member

Qix- commented Jun 12, 2018

There are a variety of solutions to this problem (using Chalk in the browser), most of them kind of messy and entirely out of scope for this project.

Locking as such.

@chalk chalk locked as off-topic and limited conversation to collaborators Jun 12, 2018
@sindresorhus
Copy link
Member

Please see #300

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

No branches or pull requests

8 participants