How to show colored console output in Clion
Asked Answered
D

3

8

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

Dietrich answered 23/9, 2015 at 14:52 Comment(2)
I'd be surprised if the Clion console is an ANSI terminal (I assume you meant ANSI, not ASCII). I'd try running the program in an ASCII terminal and attaching to it with the debugger.Marinate
Yes sorry my fault. I did actually mean ANSIDietrich
T
5

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-11622/ANSI-color-codes-not-honored-in-Debug-Run-Configuration-output-window

Tidemark answered 25/9, 2015 at 18:4 Comment(1)
Odd how this is in RubyMine but not CLion.Randolf
E
2

In the last years the CLion's console has improved and some coloring is supported.

Anyway take a look at these two link from JetBrains documentation.

  1. Terminal in the output console
  2. Console colors

They will show how to:

  1. Enable terminal emulation in output console:

    • Go to Run | Edit Configurations.
    • Select the desired configuration and set the Emulate terminal in the output console checkbox: Emulate terminal
  2. Customize color scheme for consoles

    • Press ⌘Сmd+ , to open the IDE settings and then select Editor | Color Scheme | Console Colors.
    • Select the component and adjust the settings in the right-hand pane: adjust the settings
Envy answered 26/10, 2023 at 18:34 Comment(0)
R
1

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!

Ruck answered 12/6, 2020 at 16:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.