docs: function curlyColors(str) {
    var res = '';
    var esc;
    var match;
    var history = [];
    var lastIndex = 0;
  
    if (arguments.length >= 2) str = format.apply(null, slice.apply(arguments));
  
    while ((match = rx.exec(str)) !== null) {
      res += str.slice(lastIndex, match.index);
      if (match[1]) {
        // Opening tag found.
        // Append the starting escape string sequence.
        esc = colors[match[1]];
        history.push(esc);
        res += esc[0];
      } else if (history.length) {
        // Closing tag found.
        // Append the closing escape string sequence of the current color.
        res += history.pop()[1];
        if (history.length) {
          // Continue with previous starting escape string sequence.
          res += history[history.length - 1][0];
        }
      }
      lastIndex = match.index + match[0].length;
    }
  
    // Append the remaining string to the result string.
    res += str.slice(lastIndex);
  
    // Close all remaining tags.
    while (history.length) res += history.pop()[1];
  
    // Delete double occurrences of color sequences.
    res = res.replace(/(\x1b\[\d+m)\1{1,}/g, '$1');
  
    return res;
  }