How can I print colored debug messages with Flutter / Dart to show colored Android Studio console output?

1,724

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

Share:
1,724
Ride Sun
Author by

Ride Sun

Updated on December 14, 2022

Comments

  • Ride Sun
    Ride Sun over 1 year

    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?

    • pskink
      pskink over 4 years
      what OS? my android studio on linux shows colors with no problems
    • Ride Sun
      Ride Sun over 4 years
      Windows 10. The console is the on inside Android Studio.
    • pskink
      pskink over 4 years
      that console (ALT + F12)? or something else?
    • Ride Sun
      Ride Sun over 4 years
      The debug output console. I am not add my computer right now.
    • Ride Sun
      Ride Sun over 4 years
      Also logcat does not show the coloring
  • Ride Sun
    Ride Sun over 4 years
    Seems like the defect is around for the last 5 years
  • harm
    harm over 4 years
    It does not inspire confidence.