admin管理员组

文章数量:1296440

I've had no luck in seeing any results appear in my iTerm2 while trying to use chalk which is a terminal string styling package. I followed all the steps in installing the package but I'm not seeing any colored string result appear when I run a basic console.log("hello"); in my chalk.js file.

Here is what I am doing.

#!/usr/bin/env node
var chalk = require('chalk');
chalk.blue('Hello world!');
console.log("hello");

Then in iTerm2 I run node chalk.js and I see no colored strings just plane old boring grey..

Anyone know what I'm doing wrong here?

I've had no luck in seeing any results appear in my iTerm2 while trying to use chalk which is a terminal string styling package. I followed all the steps in installing the package but I'm not seeing any colored string result appear when I run a basic console.log("hello"); in my chalk.js file.

Here is what I am doing.

#!/usr/bin/env node
var chalk = require('chalk');
chalk.blue('Hello world!');
console.log("hello");

Then in iTerm2 I run node chalk.js and I see no colored strings just plane old boring grey..

Anyone know what I'm doing wrong here?

https://www.npmjs./package/chalk

Share edited Jul 31, 2015 at 20:04 Qix - MONICA WAS MISTREATED 15.1k17 gold badges92 silver badges155 bronze badges asked Mar 31, 2015 at 8:46 brent_whitebrent_white 1,0191 gold badge14 silver badges27 bronze badges 3
  • It should "just" work, since Iterm2 sets TERM to xterm by default, and that is what chalk checks for - see source github./sindresorhus/supports-color/blob/master/index.js – Thomas Dickey Commented Mar 31, 2015 at 10:22
  • @ThomasDickey thax for your imput. Can you tell me exactly how you get it run "your set up" for chalk? – brent_white Commented Apr 2, 2015 at 4:07
  • I was reading the source code to help explain it -- can setup to explore that a little... – Thomas Dickey Commented Apr 2, 2015 at 8:11
Add a ment  | 

1 Answer 1

Reset to default 10

Chalk functions return a string with the appropriate ANSI escape codes.

You need to console log the result of chalk calls.

console.log(chalk.blue("Hello, world!"));

If you still don't see any color, try running with the mand line argument --colors. If that still doesn't work, set an environment variable FORCE_COLOR=1.

If it still doesn't work, you're wele to file a bug report!

本文标签: javascriptHow to use Chalk Terminal string styling done rightStack Overflow