Some lines still show the ansi codes while others display the colors correctly. It seems to be a feature of the platformio terminal, as discussed here with maxgerhardt and others.
The workaround is to add a space before the escape sequence
Thanks to pfeerick for this suggestion.
If you are using arduino debug logging feature in VSC:
-
ctrl-click on the log_d or log_i part of the log statement, and it will take you to the macro where this is defined.
-
Look for the 3 lines shown below, and add a space before the backslash character:

-
recompile, and download to device,
This should help your terminal to decipher the ansi codes properly.