Description
Describe the problem
It is a common practice for command line tools to selectively color output text with the goal of enhancing the readability. This is done though ANSI escape codes.
The GCC tools used to compile Arduino sketches do such coloration of the diagnostic messages printed in their output:
🐛 Compiler diagnostics are not colored in the arduino-cli compile
output.
To reproduce
$ git checkout b3e8f8a4c2544cbda60975153773652631253738^1 # Checkout the last commit before the regression
[...]
$ task build
[...]
$ mkdir "/tmp/SketchWithDiagnostics"
$ printf '#warning foo\nvoid setup() {}\nvoid loop() {}\n' > "/tmp/SketchWithDiagnostics/SketchWithDiagnostics.ino"
$ ./arduino-cli compile --fqbn arduino:avr:uno --warnings all "/tmp/SketchWithDiagnostics"
🙂 The diagnostics in the compiler output are colored:
$ git checkout master # Checkout the version with the regression
[...]
$ task build
[...]
$ ./arduino-cli version
arduino-cli Version: git-snapshot Commit: 65915d8a Date: 2023-09-10T21:35:05Z
$ ./arduino-cli compile --fqbn arduino:avr:uno --warnings all "/tmp/SketchWithDiagnostics"
🐛 The diagnostics in the compiler output are not colored:
Expected behavior
Tool output is colored in the Arduino CLI output the same as it would be if the command was invoked directly from the terminal.
Arduino CLI version
Operating system
Linux
Operating system version
Ubuntu 22.04
Additional context
I bisected the regression to b3e8f8a (does not occur when using the build at the previous commit a735ddf).
The coloration returns if I force the compiler to add the escape codes to its output by adding the -fdiagnostics-color
flag to the compilation commands:
$ ./arduino-cli compile --build-property "compiler.cpp.extra_flags=-fdiagnostics-color=always" --fqbn arduino:avr:uno --warnings all "/tmp/SketchWithDiagnostics"
So it is not a matter of Arduino CLI stripping the escape codes, but rather of the context in which the compiler commands are invoked causing the compiler to not add them in its default "auto" mode:
‘auto’ means to use color only when the standard error is a terminal
The diagnostics are colored if I invoke the same compiler command directly from the terminal.
I don't get any coloration even when invoking the compiler command directly on my Windows machine (likely done due to a lack of support for the ANSI codes by Windows terminals).
Originally reported by @myklemykle at https://forum.arduino.cc/t/in-ardino-cli-0-33-1-compiler-errs-warnings-are-no-longer-colorized/1150508
Issue checklist
- I searched for previous reports in the issue tracker
- I verified the problem still occurs when using the nightly build
- My report contains all necessary details