createColors function

Picocolors createColors({
  1. bool? enabled,
})

picocolors' createColors, defaulting enablement to the module-level support detection.

Implementation

Picocolors createColors({bool? enabled}) {
  final isEnabled = enabled ?? _defaultIsColorSupported;

  String Function(String input) f(
    String open,
    String close, [
    String? replace,
  ]) {
    return isEnabled ? _formatter(open, close, replace) : _identity;
  }

  return Picocolors._(
    isEnabled,
    f('\x1B[1m', '\x1B[22m', '\x1B[22m\x1B[1m'),
    f('\x1B[2m', '\x1B[22m', '\x1B[22m\x1B[2m'),
    f('\x1B[31m', '\x1B[39m'),
    f('\x1B[32m', '\x1B[39m'),
    f('\x1B[33m', '\x1B[39m'),
    f('\x1B[36m', '\x1B[39m'),
  );
}