Fix Control (Color) Characters in Emacs Compilation buffer

For a while I had the issue that ANSI escape codes for compilation buffer don't show correctly in Emacs. I would get characters like unscaped carriage-return ^M or ^[ in the compilation buffer, something like the following:

Broken ANSI escape codes in Emacs compilation buffer

Today I found that one could fix this issue by adding the following to init.el file:

(add-hook 'compilation-filter-hook 'ansi-color-compilation-filter)

After doing this, the compilation buffer looks like this

Fixed ANSI escape codes in Emacs compilation buffer

The theme in screenshots is ef-trio-dark from ef-themes package, the font is Iosevka Comfy and my full configuration can be found in my dotemacs repository.