call method Null safety

String call(
  1. dynamic arg0,
  2. [dynamic arg1,
  3. dynamic arg2,
  4. dynamic arg3,
  5. dynamic arg4,
  6. dynamic arg5,
  7. dynamic arg6,
  8. dynamic arg7,
  9. dynamic arg8,
  10. dynamic arg9,
  11. dynamic arg10,
  12. dynamic arg11,
  13. dynamic arg12,
  14. dynamic arg13,
  15. dynamic arg14,
  16. dynamic arg15]
)

Handles the generic Chalk(....) calls with up to 15 arguements that can be a mixtured of pretty much anything. List<> and Function closures are handled

Implementation

String call(dynamic arg0,
    [dynamic arg1,
    dynamic arg2,
    dynamic arg3,
    dynamic arg4,
    dynamic arg5,
    dynamic arg6,
    dynamic arg7,
    dynamic arg8,
    dynamic arg9,
    dynamic arg10,
    dynamic arg11,
    dynamic arg12,
    dynamic arg13,
    dynamic arg14,
    dynamic arg15]) {
  arg0 = _fixArg(arg0);
  if (arg1 != null) {
    arg0 = <dynamic>[
      arg0, // we know arg0 is a string at this point (from call to _fixArg())
      if (arg1 != null) _fixArg(arg1),
      if (arg2 != null) _fixArg(arg2),
      if (arg3 != null) _fixArg(arg3),
      if (arg4 != null) _fixArg(arg4),
      if (arg5 != null) _fixArg(arg5),
      if (arg6 != null) _fixArg(arg6),
      if (arg7 != null) _fixArg(arg7),
      if (arg8 != null) _fixArg(arg8),
      if (arg9 != null) _fixArg(arg9),
      if (arg10 != null) _fixArg(arg10),
      if (arg10 != null) _fixArg(arg11),
      if (arg10 != null) _fixArg(arg12),
      if (arg10 != null) _fixArg(arg13),
      if (arg10 != null) _fixArg(arg14),
      if (arg10 != null) _fixArg(arg15),
    ].join(_joinString);
  }

  if (level <= 0 || arg0 == null) {
    return (arg0 == null || _chalkVisibleModifier) ? '' : arg0;
  }

  Chalk? styler = this;

  if (!styler._hasStyle) {
    return arg0;
  }

  if (arg0!.indexOf('\u001B') != -1) {
    while (styler != null && styler._hasStyle) {
      // Replace any instances already present with a re-opening code
      // otherwise only the part of the string until said closing code
      // will be colored, and the rest will simply be 'plain'.
      arg0 = _StringUtils.stringReplaceAll(arg0, styler._close, styler._open);

      styler = styler._parent;
    }
  }

  // We can move both next actions out of loop, because remaining actions in loop won't have
  // any/visible effect on parts we add here. Close the styling before a linebreak and reopen
  // after next line to fix a bleed issue on macOS: https://github.com/chalk/chalk/pull/92
  var lfIndex = arg0.indexOf('\n');
  if (lfIndex != -1) {
    arg0 = _StringUtils.stringEncaseCRLFWithFirstIndex(
        arg0, _closeAll, _openAll, lfIndex);
  }

  return _openAll + arg0 + _closeAll;
}