Node template engine for console color output

How to visualize colored text on a console created by a template engine that supports looping and variable replacement.

I did some tests with swig , but it just slipped away from the material \u001b[32m .

Is there a cross between sprintf and the real HTML template engine?

Update:
I tried swig for a while, and just using console.log would be more convenient and straightforward :)

Am I the only one who finds something to output text to a model-based console? Or am I approaching this from the wrong angle?

+6
source share
1 answer

Although this does not solve the problem of the template system, it can help you achieve what you are trying to achieve. There are two different modules that I would suggest you look at:

chalk - "Styling a terminal line done correctly. Lots of color."

There is a node module called chalk that allows you to define colors / styles, albeit a very simple api.

It is compatible with sprintf substitution and can be combined with console.log to write pretty colored formatted output.

bunyan - "JSON logging library for node.js services"

If you want to use it for magazines , I would suggest looking at bunyan. This allows you to basically send something to your JSON formatted logs. It adds additional data, such as timestamps and error levels, so you don't need to. The output is just JSON, so it can be easily programmed.

By connecting std.out to bunyan , it will color and format the output, making it easier to verify.

+1
source

Source: https://habr.com/ru/post/986327/


All Articles