GithubHelp home page GithubHelp logo

Browser support? about chalk HOT 14 CLOSED

chalk avatar chalk commented on May 16, 2024 2
Browser support?

from chalk.

Comments (14)

L1fescape avatar L1fescape commented on May 16, 2024 5

@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.

from chalk.

sindresorhus avatar sindresorhus commented on May 16, 2024 3

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

from chalk.

tmcw avatar tmcw commented on May 16, 2024 2

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

from chalk.

sindresorhus avatar sindresorhus commented on May 16, 2024 1

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

from chalk.

danielchatfield avatar danielchatfield commented on May 16, 2024

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

from chalk.

vjpr avatar vjpr commented on May 16, 2024

Such a disappointment.

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

from chalk.

vjpr avatar vjpr commented on May 16, 2024

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.

from chalk.

vjpr avatar vjpr commented on May 16, 2024

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.

from chalk.

callmehiphop avatar callmehiphop commented on May 16, 2024

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.

from chalk.

 avatar commented on May 16, 2024

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

from chalk.

 avatar commented on May 16, 2024

xtermjs/xterm.js#1400

from chalk.

j0hnm4r5 avatar j0hnm4r5 commented on May 16, 2024

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

from chalk.

Qix- avatar Qix- commented on May 16, 2024

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.

from chalk.

sindresorhus avatar sindresorhus commented on May 16, 2024

Please see #300

from chalk.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.