call method

String call(
  1. Object msg
)

Applies this pen's styles to input and returns the styled string.

pen('msg') is equivalent to pen.write('msg'). Compatible with ansicolor's AnsiPen.call() signature.

Implementation

String call(Object msg) {
  String string = msg.toString();
  // Faster handle common cases directly without loop
  switch (styleStack.length) {
    case 0:
      return string;
    case 1:
      return styleStack[0](string);
    case 2:
      return styleStack[0](styleStack[1](string));
    case 3:
      return styleStack[0](styleStack[1](styleStack[2](string)));
    case _:
      for (int i = styleStack.length - 1; i >= 0; i--) {
        string = styleStack[i](string);
      }
      return string;
  }
}