Chalk: Question: change background for a complete terminal line

Created on 16 Jun 2020  路  4Comments  路  Source: chalk/chalk

When I console.log a text like this:

console.log(chalk.bgWhite.black('hello world'));

It creates the following output:
Screenshot 2020-06-16 at 09 35 25

Is there any way that I can format the while line other than just then encapsulated words.

question

All 4 comments

Kind of a hack, but try this:

const padConsoleWidth = (s, stream = process.stdout) => s + ' '.repeat(stream.columns - s.length);
console.log(chalk.bgWhite.black(padConsoleWidth('Hello, World!')));

This won't work in all cases but should work in _most_ of them.

Thank you I will give it a try.
Doing something similar now, thought there might be a smarter way.

Unfortunately not; some terminal emulators will color the rest of the line if you insert the newline before the render mode reset but that's inconsistent behavior at best.

This is the most "correct" way (keeping in mind that all ANSI escape/TTY stuff is horribly archaic).

Hope that helps :)

@Qix- At least it gave me a new idea. Currently used chalk for syntax highlighting with PrismJS with console.log in NodeJS.
Some themes there have some strange colouring.
Details: https://t.co/1gyFTTVEm6?amp=1

Was this page helpful?
0 / 5 - 0 ratings

Related issues

RichaJha1119 picture RichaJha1119  路  5Comments

DawnImpulse picture DawnImpulse  路  7Comments

Martodox picture Martodox  路  3Comments

basickarl picture basickarl  路  3Comments

arabold picture arabold  路  4Comments