Marak / colors.js

get colors in your node.js console
https://github.com/Marak/colors.js
Other
5.17k stars 446 forks source link

Multiline strings (colors 1.3.0) #231

Closed fis-cz closed 6 years ago

fis-cz commented 6 years ago

When I use multiline string with colors, i.e.:

const colors = require("colors");
const text = `Line 1
Line 2

Line after empty line 1

Line after empty line 2`;
console.log(colors.red(text));

the empty lines are stripped from the text so the output is:

Line 1
Line 2
Line after empty line 1
Line after empty line 2

Is this a bug or do I miss something?

DABH commented 6 years ago

Unable to reproduce -- this prints as expected for me:

const colors = require('colors');

console.log(`jim

bob

foo`.red);

There are several strange syntax issues in your example, such such as not putting colors in quotes in the require statement, and then appearing to log the colors variable instead of your text.

If you have a fully valid sample where things don't work, please feel free to re-open this! Thanks!

fis-cz commented 6 years ago

Sorry I didn't copy-paste before. I am testing in Node.js 10.2.1, colors 1.3.0 (at least this is the version mentioned in packages.json)

Copy - paste example:

let colors = require("colors");

let text = `line1

line2

line3
`;

console.log(text);
console.log(colors.red(text));

Expected outout:

line1

line2

line3

line1

line2

line3

Current output:

line1

line2

line3

line1
line2
line3

Seems like empty lines are striped.

DABH commented 6 years ago

Thanks for this snippet! Indeed, it seems there is different behavior in logging colors.red(text) vs. text.red -- this seems like a valid issue to me and I'll try to sort it out. Thanks!

fis-cz commented 6 years ago

Tested both:

let colors = require("colors");

let text = `line1

line2

line3
`;

console.log(text.red);

console.log(colors.red(text));

and the first one really works as expected.

DABH commented 6 years ago

This has been fixed in the ^above commit and will be included in the next release of colors. If this is urgent for you in the meantime, you can reference "colors": "Marak/colors.js#develop" in your package.json instead of a version number, to directly get the latest version from github. Thanks again for reporting!

fis-cz commented 6 years ago

Thanks