How to print something with color ?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Jolie

Do you guys have better way to print log In Godot IDE?

Well the only thing that would come to my mind, is to use printerr.
Otherwise I would suggest the debug tool, for debugging.
Or even write your logs in a file.

coffeeDragon | 2018-05-30 07:24

:bust_in_silhouette: Reply From: katuiche

It’s been two years since this was asked, but to anyone who stumbles on this question:

You can print colored text using ANSI escape characters. However you need to literally print the escape character because printing “/e” will not work. You can copy and paste the character and store it on a string.

If you are using Windows you will also need to change a system register to allow Godot to use the console ANSI interpreter:
HKEY_CURRENT_USER > Console > VirtualTerminalLevel to 0x1.

I made a plugin to help with that:
https://godotengine.org/asset-library/asset/772

Thanks a lot for this! will make something very naughty with it :wink:
I wonder, how did you figure out what the escape character was? in the code it shows as a square, and looking it up on google gives 0 results. Godot editor don’t show it at all.
I made a GIF to ANSI terminal viewer in PHP once and it was easier than this
I’m on Linux btw not Windows

rehhouari | 2021-05-08 21:48

1 Like

GD.PrintRich (or print_rich in GDScript) accepts BBCode, which allows you to add a [color] tag.

2 Likes