resolve method

OutputMode resolve({
  1. bool? hasTerminal,
  2. Map<String, String>? environment,
})

Turns auto into the mode that fits where the output goes. The other modes are returned as they are

A CI may give the command a terminal that only records the output, where redrawing the lines would fill the record with copies of them, so a set CI env variable counts as no terminal. The hasTerminal and environment default to those of the stdout and the process

Implementation

OutputMode resolve({bool? hasTerminal, Map<String, String>? environment}) {
  if (this != auto) return this;

  bool terminal = hasTerminal ?? (stdout.hasTerminal && stdout.supportsAnsiEscapes);
  String ci = ((environment ?? Platform.environment)["CI"] ?? "").trim().toLowerCase();
  bool isCI = ci.isNotEmpty && ci != "false" && ci != "0";
  return terminal && !isCI ? interactive : plain;
}