1
votes

How can I print colored debug messages with Flutter/Dart to show colored Android Studio console/logcat output? There are many dart packages that provide the escape characters for colored output but the Android Studio simply does not show them.

Some of them are: https://github.com/iamsalnikov/colorize or https://pub.dev/packages/ansicolor

Or simply some escape characters should work as well:

   print('\x1B[94m $text \x1B[0m');

These messages show up like this:

 [94m [36m57 2019-10-18 16:18:55.694098 FINE ui.app.dart: initial route = null[0m [0m

My question is, can I exchange the console to see the escape characters? Or just any other way?

1
what OS? my android studio on linux shows colors with no problems - pskink
Windows 10. The console is the on inside Android Studio. - Ride Sun
that console (ALT + F12)? or something else? - pskink
The debug output console. I am not add my computer right now. - Ride Sun
Also logcat does not show the coloring - Ride Sun

1 Answers

1
votes

I don't believe this is possible at this point. How this works exactly is still a bit unclear to me but it hinges on the supportsAnsiEscapes method. This outputs false when running in Android Studio:

import 'dart:io' as io;
print(io.stdout.supportsAnsiEscapes);

Escape sequences are then simply ignored.

Note that even if this call would return true Android Studio only supports a limited subset of ANSI colors: https://youtrack.jetbrains.com/issue/IDEA-137065