Code Monkey home page Code Monkey logo

Comments (4)

jbnicolai avatar jbnicolai commented on May 18, 2024 1

Whew, after banging my head against the wall how the exact same string, produced by two different libraries, could possibly act different I finally realised it's because you ran chalk headless.

If you look here in chalk you see that it get's disabled if it's not running in a TTY.

This is an optimisation to prevent to colorisation of strings that aren't being printed to stdout anyway. It is imho questionable if this is valid, as it means that a user of chalk may unexpectedly not get styled strings even though he explicitly applied styles to them. Perhaps something to reconsider, @sindresorhus ?

Wrapping up, this is expected behaviour, @apriendeau, and you can get your desired results by explicitly setting chalk.enabled = true.

var colors   = require('colors')
var chalk    = require('chalk')
chalk.enabled = true

console.log(chalk.blue('test'))
console.log('test'.blue)

Will now work when piped through through bunyan

from chalk.

apriendeau avatar apriendeau commented on May 18, 2024

nice @jbnicolai thanks so much!

from chalk.

sindresorhus avatar sindresorhus commented on May 18, 2024

You can also force color by using the --color flag in the CLI. The most common case is not wanting colors when piped and chalk optimizes for that usecase.

from chalk.

apriendeau avatar apriendeau commented on May 18, 2024

A terminal without color is a terminal that I do not want to live in. Thanks for the help!

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.