code: def color(s, fg=None, bg=None, style=None):
      """
      Add ANSI colors and styles to a string.
  
      :param str s: String to format.
      :param str|int|tuple fg: Foreground color specification.
      :param str|int|tuple bg: Background color specification.
      :param str: Style names, separated by '+'
      :returns: Formatted string.
      :rtype: str (or unicode in Python 2, if s is unicode)
      """
      codes = []
  
      if fg:
          codes.append(_color_code(fg, 30))
      if bg:
          codes.append(_color_code(bg, 40))
      if style:
          for style_part in style.split("+"):
              if style_part in STYLES:
                  codes.append(STYLES.index(style_part))
              else:
                  raise ValueError('Invalid style "%s"' % style_part)
  
      if codes:
          template = "\x1b[{0}m{1}\x1b[0m"
          if _PY2 and isinstance(s, unicode):
              # Take care in PY2 to return str if string is given, and
              # unicode if unicode is given. It's a pain, but given PY2's
              # fragility with Unicode characters and encodings, important
              # to avoid any disruptions that might trigger downstream errors.
              template = unicode(template)
          return template.format(_join(*codes), s)
      else:
          return s
  
file_path: keepsake/python/keepsake/_vendor/colors/colors.py
imports: from __future__ import absolute_import, print_function
  import re
  import sys
  from .csscolors import parse_rgb, css_colors
  from functools import partial
label_desc: Use image node_id 4 for calling a global function with example usage: color(s, fg, bg, style) and returns: template, s