Comments (14)
@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.
lol no, sorry, this won't be a bloated mess like colors.js.
from chalk.
For my usecase of displaying colored error messages in-browser, ansi-html seems to work well.
from chalk.
Just curious. Why would you need it for the browser? What's the usecase?
from chalk.
That's what I figured, just thought I'd check before starting my own repo.
from chalk.
Such a disappointment.
@danielchatfield did you manage to make your own repo or find that has a similar api with browser support?
from chalk.
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.
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.
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.
I'd like to use it (Ora spinners) with xterm.js in the browser. ^_^
from chalk.
from chalk.
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.
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.
Please see #300
from chalk.
Related Issues (20)
- Add more colors HOT 2
- Chalk is not working in Jenkins multibranch pipeline HOT 1
- Does chalk.js support squiggly lines? HOT 1
- Cannot find module 'chalk'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option? HOT 2
- Can't show color in vscode integrated terminal HOT 1
- chalk not suppported?? HOT 1
- Tried to use with TS (NestJS Project) HOT 6
- is there r any way to mix background colors like gradient-string? HOT 1
- Error [ERR_REQUIRE_ESM]: require() of ES Module HOT 6
- chalk 5.x fails with typescript HOT 3
- Is it possible to apply a style conditionally? HOT 5
- ReferenceError: navigator is not defined HOT 1
- Remove README.md from bundle HOT 2
- v4 property override error
- is support require('chalk')? HOT 3
- Chalk italic modifier is not applied in Windows Git Bash terminal. HOT 1
- $FORCE_COLOR works only as either level 0 or 3 HOT 1
- New Windows fluent emoji font - color is wrong HOT 1
- Unable to resolve module #ansi-styles HOT 2
- 【suggestion】support commonjs version HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from chalk.