B
B
Boris Dergachev2014-11-10 12:29:26
C++ / C#
Boris Dergachev, 2014-11-10 12:29:26

What is the best way to display colored text in the console?

Interested in a convenient way in terms of design to display part of the text in color using esc sequences.
Now I'm using something like this:

#include <stdio.h>
#define TATR_OFF "\033[0m"
#define TATR_INF "[\033[1;34minf\033[0m] "
#define TATR_WRN "[\033[1;33mwrn\033[0m] "
#define TATR_ERR "[\033[1;31merr\033[0m] "
#define MSG_INF(msg) (TATR_INF msg)
#define MSG_WRN(msg) (TATR_WRN msg)
#define MSG_ERR(msg) (TATR_ERR msg)
int main() {
    puts(MSG_INF("info text"));
    puts(MSG_WRN("warning text"));
    puts(MSG_ERR("error text"));
    return 0;
}

Is there a more convenient way to organize such an output?
Windows command line does not support esc sequences - is there a cross platform option?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
Boniface, 2014-11-10
@Boniface

Good afternoon! For windows I use www.codeproject.com/Articles/16431/Add-color-to-yo... . In your case, if you use ansi color, you will have to patch cmd and powershell in Windows to support displaying colors. There are examples on the web.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question