prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Globally disable color?
  I cannot find the way to globally disable color in the pre-commit output. Setting only the background color to green and not changing the foreground color does not work for my terminal with the following settings in the Xt resources (as set in the `${HOME}/.Xresources` file):
  
  ````properties
  Rxvt.background: black
  Rxvt.foreground: deepSkyBlue
  ````
  
  Is there a way? It would be great to respect https://no-color.org/ environment variable. And, while we are here, maybe understand the following git config setting:
  
  ````ini
  [color]
          ui = never
  ````
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `pre_commit/color.py`
  Content:
  ```
  1 from __future__ import unicode_literals
  2 
  3 import os
  4 import sys
  5 
  6 terminal_supports_color = True
  7 if os.name == 'nt':  # pragma: no cover (windows)
  8     from pre_commit.color_windows import enable_virtual_terminal_processing
  9     try:
  10         enable_virtual_terminal_processing()
  11     except WindowsError:
  12         terminal_supports_color = False
  13 
  14 RED = '\033[41m'
  15 GREEN = '\033[42m'
  16 YELLOW = '\033[43;30m'
  17 TURQUOISE = '\033[46;30m'
  18 NORMAL = '\033[0m'
  19 
  20 
  21 class InvalidColorSetting(ValueError):
  22     pass
  23 
  24 
  25 def format_color(text, color, use_color_setting):
  26     """Format text with color.
  27 
  28     Args:
  29         text - Text to be formatted with color if `use_color`
  30         color - The color start string
  31         use_color_setting - Whether or not to color
  32     """
  33     if not use_color_setting:
  34         return text
  35     else:
  36         return '{}{}{}'.format(color, text, NORMAL)
  37 
  38 
  39 COLOR_CHOICES = ('auto', 'always', 'never')
  40 
  41 
  42 def use_color(setting):
  43     """Choose whether to use color based on the command argument.
  44 
  45     Args:
  46         setting - Either `auto`, `always`, or `never`
  47     """
  48     if setting not in COLOR_CHOICES:
  49         raise InvalidColorSetting(setting)
  50 
  51     return (
  52         setting == 'always' or
  53         (setting == 'auto' and sys.stdout.isatty() and terminal_supports_color)
  54     )
  55
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/pre_commit/color.py b/pre_commit/color.py
  --- a/pre_commit/color.py
  +++ b/pre_commit/color.py
  @@ -48,6 +48,9 @@
       if setting not in COLOR_CHOICES:
           raise InvalidColorSetting(setting)
   
  +    if os.environ.get('NO_COLOR'):
  +        return False
  +
       return (
           setting == 'always' or
           (setting == 'auto' and sys.stdout.isatty() and terminal_supports_color)
  
verification_info: {"golden_diff": "diff --git a/pre_commit/color.py b/pre_commit/color.py\n--- a/pre_commit/color.py\n+++ b/pre_commit/color.py\n@@ -48,6 +48,9 @@\n     if setting not in COLOR_CHOICES:\n         raise InvalidColorSetting(setting)\n \n+    if os.environ.get('NO_COLOR'):\n+        return False\n+\n     return (\n         setting == 'always' or\n         (setting == 'auto' and sys.stdout.isatty() and terminal_supports_color)\n", "issue": "Globally disable color?\nI cannot find the way to globally disable color in the pre-commit output. Setting only the background color to green and not changing the foreground color does not work for my terminal with the following settings in the Xt resources (as set in the `${HOME}/.Xresources` file):\r\n\r\n````properties\r\nRxvt.background: black\r\nRxvt.foreground: deepSkyBlue\r\n````\r\n\r\nIs there a way? It would be great to respect https://no-color.org/ environment variable. And, while we are here, maybe understand the following git config setting:\r\n\r\n````ini\r\n[color]\r\n        ui = never\r\n````\r\n\n", "before_files": [{"content": "from __future__ import unicode_literals\n\nimport os\nimport sys\n\nterminal_supports_color = True\nif os.name == 'nt':  # pragma: no cover (windows)\n    from pre_commit.color_windows import enable_virtual_terminal_processing\n    try:\n        enable_virtual_terminal_processing()\n    except WindowsError:\n        terminal_supports_color = False\n\nRED = '\\033[41m'\nGREEN = '\\033[42m'\nYELLOW = '\\033[43;30m'\nTURQUOISE = '\\033[46;30m'\nNORMAL = '\\033[0m'\n\n\nclass InvalidColorSetting(ValueError):\n    pass\n\n\ndef format_color(text, color, use_color_setting):\n    \"\"\"Format text with color.\n\n    Args:\n        text - Text to be formatted with color if `use_color`\n        color - The color start string\n        use_color_setting - Whether or not to color\n    \"\"\"\n    if not use_color_setting:\n        return text\n    else:\n        return '{}{}{}'.format(color, text, NORMAL)\n\n\nCOLOR_CHOICES = ('auto', 'always', 'never')\n\n\ndef use_color(setting):\n    \"\"\"Choose whether to use color based on the command argument.\n\n    Args:\n        setting - Either `auto`, `always`, or `never`\n    \"\"\"\n    if setting not in COLOR_CHOICES:\n        raise InvalidColorSetting(setting)\n\n    return (\n        setting == 'always' or\n        (setting == 'auto' and sys.stdout.isatty() and terminal_supports_color)\n    )\n", "path": "pre_commit/color.py"}], "after_files": [{"content": "from __future__ import unicode_literals\n\nimport os\nimport sys\n\nterminal_supports_color = True\nif os.name == 'nt':  # pragma: no cover (windows)\n    from pre_commit.color_windows import enable_virtual_terminal_processing\n    try:\n        enable_virtual_terminal_processing()\n    except WindowsError:\n        terminal_supports_color = False\n\nRED = '\\033[41m'\nGREEN = '\\033[42m'\nYELLOW = '\\033[43;30m'\nTURQUOISE = '\\033[46;30m'\nNORMAL = '\\033[0m'\n\n\nclass InvalidColorSetting(ValueError):\n    pass\n\n\ndef format_color(text, color, use_color_setting):\n    \"\"\"Format text with color.\n\n    Args:\n        text - Text to be formatted with color if `use_color`\n        color - The color start string\n        use_color_setting - Whether or not to color\n    \"\"\"\n    if not use_color_setting:\n        return text\n    else:\n        return '{}{}{}'.format(color, text, NORMAL)\n\n\nCOLOR_CHOICES = ('auto', 'always', 'never')\n\n\ndef use_color(setting):\n    \"\"\"Choose whether to use color based on the command argument.\n\n    Args:\n        setting - Either `auto`, `always`, or `never`\n    \"\"\"\n    if setting not in COLOR_CHOICES:\n        raise InvalidColorSetting(setting)\n\n    if os.environ.get('NO_COLOR'):\n        return False\n\n    return (\n        setting == 'always' or\n        (setting == 'auto' and sys.stdout.isatty() and terminal_supports_color)\n    )\n", "path": "pre_commit/color.py"}]}