Git Product home page Git Product logo

colors.js's People

Contributors

adrielcodeco avatar bcaudan avatar brettz9 avatar buschtoens avatar cjc avatar dabh avatar danbell avatar ded avatar edi9999 avatar fscherwi avatar glitchmasta47 avatar grit96 avatar hashar avatar jamescostian avatar jennings avatar jpap avatar justincampbell avatar jweinsteincbt avatar kahwee avatar konsumer avatar marak avatar mmalecki avatar morganrallen avatar mrjacobbloom avatar osmanmesutozcan avatar oxund avatar paladox avatar pksunkara avatar stevenvachon avatar yursha avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

colors.js's Issues

colored JSON Ouput

This is a feature request.

add a function for coloring a valid json string. Otherwise just return it as it is.

So when doing console.log('{"foo":"bar"}'.highlightJson); the json string gets printed nicely colored.

Bug: incorrect use of color.js can summon Zalgo

A program I wrote using color.js had some weird behavior. I got this exception:

>> ExecutionError: N͚̩̻̯e͓̤͌̾̍̅z̀̓̚p͕̝̣̬̙͍̊̚ȅ͖̘̬̿ͫr̃ͧ̉҉̩̥̰d͈̹̞͙̣͎͈̑̓i̵̘͇͉͒ͮͤͧ̆a̭̯͌n͊ͦ̿̄̾͏̻̱̯̲ ̙͔̪̒ͣͦ͊̇h̶͚͉͇̬̳̑ͭ̚ĩ̯̬̓ͬ̀̆ͅv̻̱̽̔ͥ̒ͤe̓͐͏͙͉̬-̹͓̳̯̀m͕͂ͪͨͮi̞̮̼̙̫̬͆͛͂ͬ̀ͣń̳̖̻̞͈͚͔ͬ͒͂ͯ̀d̻̟̒̓ͫ͊͊ͧ͜ ̹͌͑h̠̤͕͖ͦ͜a͕͗̏ͩ̏ͪͯ̓ṣ̲̆͌ͯͬͯ̓ ̠̫͓͓̫̩̃̑̀b͘e͊̑ͮ҉̮̦̱̩͙ė̍ͧͯͮ͏̼̖̪̟̟̥n͕̣̲͌͐̓̇̒ ̂͆͒̓̏i̪ͣ̏͊̒̔n̮̫̰̓̆̃̽͡ͅv̘̋̎ͪͬ̋͆ͦo̭̱͕̺͔͚̲ͦ̀̚͟k͙͈̮̩͒ē̺̈ͪd͇̯̤͎̗ͥ̈́̄̓ͩͨ.̮̭̩̀͜ ̺͉̬̿̅͗H̟͍͙̫ͭͪ̉͡e̷̮̊̈ͤ ̱̠̣̮ͣ̓̍͊̏w̹̬̟̼̺ͥ͌̊̀ͣͪȃ͌ͭ͊̉͏i̿̿̒ͥt̨͎̠̭̞̂ͧͩs̷͑͐͋̓͑ ̸̝̈́̅̓b̳̰̓̒ͨ́e̺̱̪͖̲̽̍ͧ̃h̘̗̃́͗̐͗̋̈́͜i̫̞̲̳̟͆̑̔n̹̺ͯ̍̉ͥͮͯ́d̖͇͖̹ͣ͑̀ ̤͇̪̙̜̩͕͞ẗ̺̔ͬh͕̠͍̹̥͖ȩ̙͙̲̍̓̓ ͓̗̅̃̔͊w̌̐ạ̵̝̼͎̏l̶͈͐ͬ̎l̢̮͐̐͊̿̑̍.̒ͧ͛̄̿͏̜̭̦͈̫
>>     at Function.defineProperty (native)
>>     at /Users/murdered/Documents/projects/apiary/node_modules/colors/colors.js:341:12
>>     at /Users/murdered/Documents/projects/apiary/node_modules/colors/colors.js:49:3
>>     at Array.forEach (native)
>>     at Object.<anonymous> (/Users/murdered/Documents/projects/apiary/node_modules/colors/colors.js:5̪̬̪͕̇͜6̞ͫͣ̆ͦ̑̓̐3̧̳̺̥̯͔̊̂̐:3)
>>     at Module._conjur (module.js:446:26)
>>     at Object..js (module.js:464:10)
>>     at Module.corrupt (module.js:353:31)
>>     at Function._load (module.js:311:12)
>>     at Module.require (module.js:359:17)

The exception was inexplicable. My lights shut off on their own volition, and I may not escape. Please fix this bug.

strip colors

Great module.

Is there a way to strip the color formatting from a string. I set the color in the code depending on the context and send it to the logger. The logger sends it to the console and also to a log file. I am getting things like "�[39m�[22m" appearing in my log file. I would like to strip the color information before it gets logged to file.

Thanks.

Conflicts with REPL

I'm running a repl in a node.js 0.6.19 app, and passing to the repl context a function which invokes cli-table which in turn uses this module. As soon as colors is loaded, it throws a fatal error:
TypeError: Cannot redefine property: underline

At first I thought it was a conflict with REPL's built-in _ variable (underline/underscore, I dunno) but commenting that out throws the same error on "italics" and every other property on line 27 of colors.js.

This might be related to the global scope issue identified in Tweak to keep it from polluting the browser's global namespace.

Is there a workaround for this? Is there a way to modify colors.js so it doesn't modify the global scope?

Thanks!

Need added check/implementation for defineProperty over __defineGetter__

Currently colors.js uses defineGetter to add new prototyped properties to the String object. These properties are not intended to be enumerable but by using defineGetter they are by default declared enumerable on the String object. With ECMA5 the new / correct way to add properties should be with defineProperty and setting the enumerable flag to false.

But fear not. I will fork and submit a pull request with the simple check / change.

Version release?

The last release of this was a year ago, and quite a few important fixes have since been made. Could we get a new version released?

Theme properties return object when mode == 'none'

example

When colors.mode == 'none', properties created by setTheme({error:'red'}) return an object instead of a string.

It looks like all the properties added by applyTheme have this behaviour of exploding strings into objects, but stylize coerces them back to strings if mode is console or browser.

Pull request incoming.

add var in console

nickname ="foo";
console.log('hello'+nickname.green); //error
console.log('hello'+nickname+' - '+.green); //no color

thanks

Colors will explode if multiple dependencies are using it

>> TypeError: Cannot redefine property: underline
>>     at Function.defineProperty (native)
>>     at /Users/almad/Documents/projects/apiary/node_modules/winston/node_modules/colors/colors.js:53:12
>>     at /Users/almad/Documents/projects/apiary/node_modules/winston/node_modules/colors/colors.js:147:3
>>     at Array.forEach (native)
>>     at Object.<anonymous> (/Users/almad/Documents/projects/apiary/node_modules/winston/node_modules/colors/colors.js:142:3)
>>     at Module._compile (module.js:446:26)
>>     at Object..js (module.js:464:10)
>>     at Module.load (module.js:353:31)
>>     at Function._load (module.js:311:12)
>>     at Module.require (module.js:359:17)

Please identify the license that is used by colors.js

Hi guys,

It would be great if you could identify the License which is used by colors.js. License is an important aspect that could be vital for all projects that are using color.js right now.

I could suggest two very nice licences, one is WTFPB

http://wtfpl2.com/

Very simple and understandable. Another very popular license in node.js community is MIT:

http://opensource.org/licenses/MIT

Don't forget to put LICENSE file in the root and add 'license' in your package.json. I can also do a pull request for license of your choice ;)

Thanks!

Renat

Windows CMD color issue

Sebi2020 wrote:

I think the colors are nice, but are a little bit buggy. It makes the output unreadable. So if it modify the color, the cmd output is >still using this color after executing the jitsu command. If I set colors:false in the config file it seems to have no affect to the >jitsu install & deplay command. Please fix that! I'm running a Windows 7 system:

Screentshot

Copy pasted from nodejitsu/jitsu#279

Changelog

Is there any changelog available?

Multiple styles with setTheme

It looks like that the code in the repo support multiple colors with an array. Ex:

colors.setTheme({
  silly: 'rainbow',
  input: 'grey',
  info: ['green', 'inverse'],
  error: ['red', 'inverse']
});

However the version in npm does not support it at all.
It is also not documented on the readme.md

It is very verbose. It would be nicer to be able to use a space " ". Ex:

colors.setTheme({
  silly: 'rainbow',
  input: 'grey',
  info: 'green inverse',
  error: 'red inverse'
});

Can you please update documentation, readme and consider the use od spaces instead of arrays?

multi-style when theming

how to apply compound 'red' and 'bold' when i'm using setTheme() ?
and i suggest to add a option to color background, now i have to use 'inverse' to workaround...

--no-color switch is ignored

A simple test harness to illustrate:

require('colors');
console.log("hello".red);

Running node test.js --no-color results in "hello" in red rather than with no colour.

Having had a quick dig, I can see that the colors.enabled flag is being set to false correctly but the applyStyle function that uses the flag isn't being invoked.

Why u no badge?

It seems there is a .travis.yml in place and since there are tests, one could assume that the test are run at Travis CI.
Would it be possible to show a badge for the current tests passing state in the README.md?

Color breaks for-in loop

Could you please make your methods not enumerable since you had monkey-patched the String prototype? For example, this code should capitalize consonants but yields a long colourful "FoofoofooӺǾѺ..." snake:

    var colors = require("colors");
    var input = "foo", output = "";
    for (var i in input) {
        var ch = input[i];
        if (ch.match(/[eyuioa]/)) output += ch;
        else output += ch.toUpperCase();
    }
    console.log(output);

Create a 'null' or 'blank' style

It would be useful to have a style that returns the text, unmodified from it's origin version. One use case is when you have some function name or variable name and you don't want to type it more than once.

getAStringFromSomewhere()[ inverseFlag ? 'inverse' : 'blank' ]

Without it, I have to repeat the code twice:

inverseFlag ? getAStringFromSomewhere().inverse : getAStringFromSomewhere();

If this will be included, I can create a pull request... does the 'blank' or 'null' name make sense?

Update outdated NPM version

The current version on npm is 9months old. The old version suffers many fails—and leaks global variables that flag up our mocha tests since colors.js is used as a subdependency of one of our modules.

Any chance on getting the current master version-bumped and pushed to npm? Please.

String substitution colors

Would it be possible (in a future update) to be able to use colors on string substitutions?

That'd be cool :3

Multiple Modules with Dependencies on colors.js results in 'Unable to register generator-cordova/app/index.js (Error: underline already exists on String.prototype, cannot override.)'

When trying to develop a Yeoman generatorfor Cordova, I run into this problem of:

Unable to register generator-cordova/app/index.js (Error: underline already exists on String.prototype, cannot override.)

I believe this is due to generator-generator relying on cli-table which has a dependency on colors (https://github.com/yeoman/generator/blob/master/package.json + https://github.com/LearnBoost/cli-table/blob/master/package.json) AND cordova-cli relies directly on colors (https://github.com/apache/cordova-cli/blob/master/package.json)

So when I run the generator, I get the follow error message:

Unable to register generator-cordova/app/index.js (Error: underline already exists on String.prototype, cannot override.)

This could be due to cli-table using an old version of colors, but I've tried updating this to 0.6.0 but didn't seem to get any further.

option to disable color entirely

Hello,

On some script, it would be great to be able to disable colors entirely. For example when you run your script in a crontab, the output will be send in a plain text emails where ANSI escapes sequences might not be desirable.

Looking at the colors.js code, you define new getters for the string object. It would be great to have that code in a callable function (such as enable) and have another one that makes those getter return the plain string.

This when my script get --no-colors, I can call that disabling function and restore the string behavior. "foo".red would just return "foo".

Let me know if the above is not clear enough.

Restore **original** String prototype

Hi,

I have some huge modules that relie on the JS Standard String prototype functions which conflict with the modification made by colors.js, such as String.bold() and are called by a module which uses colors.js to display colored output on the console.

A typical error I get is:

Property 'bold' of object my string  is not a function

Using mode = "browser" does not solve my problems because if I have a string var called x, I'd have to change all code to use x.bold inspite of x.bold().

This has also portability issues.

How can I completely restore the original String prototype only within this module?

Thanks in advance

Colors dont work for Chrome

var colors = require('colors');
console.log('hello'.green);

turns out like

�[32mhello�[39m 

You specifically say it works for the browser. I assume I dont have to change the format or anything?

colors does not respect terminfo

When using ansi escape codes, it's best to check if the terminal actually supports that escape code. The way to do this is to query the terminfo database, which looks at the terminal type defined in $TERM and sees if it supports the escape code that you want.

Many terminals are "dumb" such as emacs shell, and don't support escape code. Others support a subset of escape codes. Some can potentially use different escapes.

I'm not sure if there is a node js wrapper for terminfo, but on unix the CLI program tput can be used to query the terminfo database. For instance, "tput setf 1" will write the escape code for blue to the standard output.

Sometimes output gets piped to non-terminal output. In that case, you should check if the output file descriptor is a terminal before sending any escape codes (http://nodejs.org/api/tty.html).

I noticed that a lot of node js programs that use color seemed to break on emacs term.

Combine styles in theme

It would be great to use combined styles in themes as well:

Example:

 colors.setTheme({
  error: [ 'red', 'bold' ]
});

I don't think that's possible yet... or is it? If it is, it should be in the readme.

Cannot install with npm

Hey,

I'm trying to install the forever and hook.io modules, which use colors.js, but it looks like it's failing when it gets to installing colors.

From a blank directory:

$ npm install colors
npm http GET https://registry.npmjs.org/colors
npm http 304 https://registry.npmjs.org/colors
npm ERR! error installing [email protected]

npm ERR! Error: ENOENT, no such file or directory '/Users/viatropos/Desktop/lance/node_modules/colors/package.json'
npm ERR! You may report this log at:
npm ERR!     <http://github.com/isaacs/npm/issues>
npm ERR! or email it to:
npm ERR!     <[email protected]>
npm ERR! 
npm ERR! System Darwin 10.7.0
npm ERR! command "node" "/usr/local/bin/npm" "install" "colors"
npm ERR! cwd /Users/viatropos/Desktop/lance
npm ERR! node -v v0.6.11
npm ERR! npm -v 1.1.4
npm ERR! path /Users/viatropos/Desktop/lance/node_modules/colors/package.json
npm ERR! code ENOENT
npm ERR! message ENOENT, no such file or directory '/Users/viatropos/Desktop/lance/node_modules/colors/package.json'
npm ERR! errno {}
npm ERR! 
npm ERR! Additional logging details can be found in:
npm ERR!     /Users/viatropos/Desktop/lance/npm-debug.log
npm not ok
  • node -v v0.6.11
  • npm -v 1.1.4

Is this because of the node/npm versions? Do you know how to fix this? Thanks for your help.

SetTheme function is not working

Hello,

After the last update the setTheme function broke somehow.

colors.setTheme({ info: 'green', warning: 'magenta', prompt: 'cyan', error: 'red' });   

console.log(colors.warning(this.options[type][message]));

Error TypeError: Object #<Object> has no method 'warning'

String.prototype

You are adding enumerable properties:

var a, b;
require('colors');
a = "as";
for (b in a) {
    console.log(b);
}

The solution is probably to add enumerable false

color after inverse

console.log('white on green'.green.bold.inverse.white);

should be a white string on a green background.

Republish to NPM

It looks like the module version in npm is a bit out of date. For example it doesn't have the 'none' bugfix. Any chance of publishing the latest version?

Expose color definitions

For testing purposes, it'd be nice to just access the definitions instead of duplicating from your source.

Add multi-mode styling

We should be able to switch colors into one of three modes:

The first mode will operate as colors.js works now. It will apply ANSI escape codes to the string.

The second will return an object literal describing the object which was sent to it, i.e. 'foo'.yellow returns { string: 'foo', styling: ['yellow'] }

The third mode ( as suggested by @TooTallNate ) will output colored html markup for the browser.

Yellow colour is grey

Hello,

I have setup a theme with a color yellow associate to a variable. However, o the console the output is grey.

util.prototype.console = function(type, message) {
  colors.setTheme({ info: 'green', warning: 'yellow', prompt: 'cyan', error: 'red' });
    console.log(colors[type](this.options[type][message]));
}

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.