docs: def cformat(msg, reset=True, template=ColorTemplate):
      """
      Transform msg so that colors e.g. #RED;, #BLUE;, etc are mapped to the
      corresponding ANSI escape codes. e.g.
  
      >>> cformat("This is #RED;a red string.")
      'This is \\x1b[31ma red string.\\x1b[0m'
  
      >>> cformat("This is #BLUE;a blue string.", reset=False)
      'This is \\x1b[34ma blue string.'
  
      >>> cformat("This is #xBLUE;a blue background.", reset=False)
      'This is \\x1b[44ma blue background.'
  
      The returned string is escaped unless reset=False
      """
      ct = ColorTemplate(msg)
      m = ct.safe_substitute(ANSI_STRING_MAP)
  
      if reset:
          m += ANSI_STRING_MAP['RESET;']
  
      return m