Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show colored console output in Clion

Tags:

clion

I am trying to write a C++ application with Clion that makes use of colored console output using ASCII sequences. When I run the program in Clion, the colors are not shown. But when I run the program in my terminal, then I can see the colors.

Is there a hidden option I have to enable for this to work?

EDIT: I meant ANSI

like image 579
Kaspar Avatar asked Sep 23 '15 14:09

Kaspar


People also ask

How do you change the color of CLion?

Press Ctrl+Alt+S to open the IDE settings and select Editor | Color Scheme. Use the Scheme list to select a color scheme.

How do I change my console color in IntelliJ?

Press Ctrl+Alt+S to open the IDE settings and select Editor | Color Scheme. Select the setting pages related to consoles: Console Colors. Console Font.

How do you find the output in CLion?

After CLion finishes running your tests, it shows the results in the Run tool window on the Test Runner tab. The console on the right shows the output of the current test session.


2 Answers

CLion's console is not a terminal (at least yet), but nothings prevents from interpreting the control codes related to color and highlight the text accordingly. This is exactly what happens when you trigger a CMake build, for example.

Unfortunately, this has not been implemented for launching the applications themselves. Feature request is here: https://youtrack.jetbrains.com/issue/CPP-2471

like image 195
Vyacheslav Karpukhin Avatar answered Oct 21 '22 23:10

Vyacheslav Karpukhin


For me (windows 10) the solution was

#include <windows.h>

And then:

system(("chcp "s + std::to_string(CP_UTF8)).c_str());

Now all the ANSI sequences work!

like image 33
donRumata Avatar answered Oct 22 '22 01:10

donRumata