Years ago, when the console was the most common user interface and graphical UIs were rare and began to evolve, ANSI color codes had their great time. So it is not astonishing, that – in times where the console gets more and more significance – ANSI color codes are getting back to live.
Since I never was in the need to print colored text to the console, so why bother? I never spent a thought. But the last days I was even more and more annoyed of output like this:
2023-01-25T15:47:20.9853447Z [0m[1mmodule.sync_client.sync_plan.internesPersonalPhoto: Refreshing state
2023-01-25T15:47:20.9854980Z [0m[1mmodule.sync_client.sync_plan.betreuerzuordnung: Refreshing state
2023-01-25T15:47:20.9855981Z [0m[1mmodule.sync_client.sync_plan.internesPersonal: Refreshing state
2023-01-25T15:47:20.9856931Z [0m[1mmodule.sync_client.sync_plan.externesPersonalDokument: Refreshing state
2023-01-25T15:47:20.9857878Z [0m[1mmodule.sync_client.sync_plan.geschaeftsstelle: Refreshing state
2023-01-25T15:47:20.9858841Z [0m[1mmodule.sync_client.sync_plan.einsatz: Refreshing state
2023-01-25T15:47:21.2562867Z [0m[1mmodule.sync_client.sync_plan.freizeitausgleich: Refreshing state
2023-01-25T15:47:21.2702837Z [0m[1mmodule.sync_client.sync_plan.externesPersonal: Refreshing state
2023-01-25T15:47:21.2704130Z [0m[1mmodule.sync_client.sync_plan.taetigkeitsnachweis: Refreshing state
2023-01-25T15:47:21.9790854Z [0m[1mmodule.sync_client.sync_plan.kontingent: Refreshing state
2023-01-25T15:47:21.9791752Z [0m[1mmodule.sync_client.sync_plan.externesPersonalPhoto: Refreshing state
2023-01-25T15:47:21.9969315Z [0m[1mmodule.sync_client.sync_plan.fehlzeit2cloud: Refreshing state
What is that noise after the time stamp? These are ANSI color codes and the output medium is not able to convert these codes! Here are some examples how to generate these codes:
//Two different ways to create ANSI Color Codes
char esc = (char)0x1B;
Console.WriteLine($"Hello, {esc}[91mcolor\u001B[92mcodes");
Write-Host "`e[91mcolor`e[92mcode"
You can find an overview of existing color codes (and more escape sequences) e.g. on Christian Petersens (fnky) github account