felangel / mason

Tools which allow developers to create and consume reusable templates called bricks.
https://docs.brickhub.dev
938 stars 93 forks source link

feat: Retain colors across process boundary #1314

Closed matthew-carroll closed 2 months ago

matthew-carroll commented 2 months ago

Description

I have Dart code that generates static sites, which uses mason_logger for terminal output. The expected terminal color behavior works when calling this code directly from the terminal.

I aslo have a CLI tool, which can be used to run the static generator in a separate process. However, when I do that, I seem to lose all the logger colors. I run that process as follows:

final process = await Process.start(
    'dart',
    [executableFile.path, ...appArguments],
  );

  stdout.addStream(process.stdout);
  stderr.addStream(process.stderr);

I'd like to retain logger colors in the separate process, too.

I don't know the full scope of this ask, but for reference, I typically run the CLI tool from Android Studio via the built-in terminal.

felangel commented 2 months ago

Hi @matthew-carroll 👋 Thanks for opening an issue!

I believe this is just how Process.start works. One thing you could do is set the mode to ProcessStartMode.inheritStdio instead which will preserve the colors:

final process = await Process.start(
    'dart',
    [executableFile.path, ...appArguments],
    mode: ProcessStartMode.inheritStdio,
);

await process.exitCode;

I'm not sure there's anything else mason_logger can do since this is handled entirely by the dart sdk 🤷 Let me know if that helps 👍

matthew-carroll commented 2 months ago

That configuration did it. Thanks!