prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  No colors when hooks are run by a git commit
  Hi,
  I use pre-commit at home on linux which works perfect. But at work I have a windows pc. Here I have problems with the colorfull output. 
  
  When the hooks are run by `tox` calling `pre-commit run` there are colors as usual. When the hooks are run by a `git commit` the colors are missing.
  
  Concrete I mean the green for 'Passed', red for 'Failed ' and yellow/brown for 'Skipped' in the overview.
  
  There is no difference if I run it via git-bash, cmd or powershell. Also there is no difference if I use the pycharm buildin terminal or others.
  
  </issue>
  <code>
  [start of pre_commit/color.py]
  1 import os
  2 import sys
  3 
  4 if sys.platform == 'win32':  # pragma: no cover (windows)
  5     def _enable() -> None:
  6         from ctypes import POINTER
  7         from ctypes import windll
  8         from ctypes import WinError
  9         from ctypes import WINFUNCTYPE
  10         from ctypes.wintypes import BOOL
  11         from ctypes.wintypes import DWORD
  12         from ctypes.wintypes import HANDLE
  13 
  14         STD_OUTPUT_HANDLE = -11
  15         ENABLE_VIRTUAL_TERMINAL_PROCESSING = 4
  16 
  17         def bool_errcheck(result, func, args):
  18             if not result:
  19                 raise WinError()
  20             return args
  21 
  22         GetStdHandle = WINFUNCTYPE(HANDLE, DWORD)(
  23             ('GetStdHandle', windll.kernel32), ((1, 'nStdHandle'),),
  24         )
  25 
  26         GetConsoleMode = WINFUNCTYPE(BOOL, HANDLE, POINTER(DWORD))(
  27             ('GetConsoleMode', windll.kernel32),
  28             ((1, 'hConsoleHandle'), (2, 'lpMode')),
  29         )
  30         GetConsoleMode.errcheck = bool_errcheck
  31 
  32         SetConsoleMode = WINFUNCTYPE(BOOL, HANDLE, DWORD)(
  33             ('SetConsoleMode', windll.kernel32),
  34             ((1, 'hConsoleHandle'), (1, 'dwMode')),
  35         )
  36         SetConsoleMode.errcheck = bool_errcheck
  37 
  38         # As of Windows 10, the Windows console supports (some) ANSI escape
  39         # sequences, but it needs to be enabled using `SetConsoleMode` first.
  40         #
  41         # More info on the escape sequences supported:
  42         # https://msdn.microsoft.com/en-us/library/windows/desktop/mt638032(v=vs.85).aspx
  43         stdout = GetStdHandle(STD_OUTPUT_HANDLE)
  44         flags = GetConsoleMode(stdout)
  45         SetConsoleMode(stdout, flags | ENABLE_VIRTUAL_TERMINAL_PROCESSING)
  46 
  47     try:
  48         _enable()
  49     except OSError:
  50         terminal_supports_color = False
  51     else:
  52         terminal_supports_color = True
  53 else:  # pragma: win32 no cover
  54     terminal_supports_color = True
  55 
  56 RED = '\033[41m'
  57 GREEN = '\033[42m'
  58 YELLOW = '\033[43;30m'
  59 TURQUOISE = '\033[46;30m'
  60 SUBTLE = '\033[2m'
  61 NORMAL = '\033[m'
  62 
  63 
  64 def format_color(text: str, color: str, use_color_setting: bool) -> str:
  65     """Format text with color.
  66 
  67     Args:
  68         text - Text to be formatted with color if `use_color`
  69         color - The color start string
  70         use_color_setting - Whether or not to color
  71     """
  72     if use_color_setting:
  73         return f'{color}{text}{NORMAL}'
  74     else:
  75         return text
  76 
  77 
  78 COLOR_CHOICES = ('auto', 'always', 'never')
  79 
  80 
  81 def use_color(setting: str) -> bool:
  82     """Choose whether to use color based on the command argument.
  83 
  84     Args:
  85         setting - Either `auto`, `always`, or `never`
  86     """
  87     if setting not in COLOR_CHOICES:
  88         raise ValueError(setting)
  89 
  90     return (
  91         setting == 'always' or (
  92             setting == 'auto' and
  93             sys.stdout.isatty() and
  94             terminal_supports_color and
  95             os.getenv('TERM') != 'dumb'
  96         )
  97     )
  98
  [end of pre_commit/color.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/pre_commit/color.py b/pre_commit/color.py
  --- a/pre_commit/color.py
  +++ b/pre_commit/color.py
  @@ -11,7 +11,7 @@
           from ctypes.wintypes import DWORD
           from ctypes.wintypes import HANDLE
   
  -        STD_OUTPUT_HANDLE = -11
  +        STD_ERROR_HANDLE = -12
           ENABLE_VIRTUAL_TERMINAL_PROCESSING = 4
   
           def bool_errcheck(result, func, args):
  @@ -40,9 +40,9 @@
           #
           # More info on the escape sequences supported:
           # https://msdn.microsoft.com/en-us/library/windows/desktop/mt638032(v=vs.85).aspx
  -        stdout = GetStdHandle(STD_OUTPUT_HANDLE)
  -        flags = GetConsoleMode(stdout)
  -        SetConsoleMode(stdout, flags | ENABLE_VIRTUAL_TERMINAL_PROCESSING)
  +        stderr = GetStdHandle(STD_ERROR_HANDLE)
  +        flags = GetConsoleMode(stderr)
  +        SetConsoleMode(stderr, flags | ENABLE_VIRTUAL_TERMINAL_PROCESSING)
   
       try:
           _enable()
  @@ -90,7 +90,7 @@
       return (
           setting == 'always' or (
               setting == 'auto' and
  -            sys.stdout.isatty() and
  +            sys.stderr.isatty() and
               terminal_supports_color and
               os.getenv('TERM') != 'dumb'
           )
  
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@@ -11,7 +11,7 @@\n         from ctypes.wintypes import DWORD\n         from ctypes.wintypes import HANDLE\n \n-        STD_OUTPUT_HANDLE = -11\n+        STD_ERROR_HANDLE = -12\n         ENABLE_VIRTUAL_TERMINAL_PROCESSING = 4\n \n         def bool_errcheck(result, func, args):\n@@ -40,9 +40,9 @@\n         #\n         # More info on the escape sequences supported:\n         # https://msdn.microsoft.com/en-us/library/windows/desktop/mt638032(v=vs.85).aspx\n-        stdout = GetStdHandle(STD_OUTPUT_HANDLE)\n-        flags = GetConsoleMode(stdout)\n-        SetConsoleMode(stdout, flags | ENABLE_VIRTUAL_TERMINAL_PROCESSING)\n+        stderr = GetStdHandle(STD_ERROR_HANDLE)\n+        flags = GetConsoleMode(stderr)\n+        SetConsoleMode(stderr, flags | ENABLE_VIRTUAL_TERMINAL_PROCESSING)\n \n     try:\n         _enable()\n@@ -90,7 +90,7 @@\n     return (\n         setting == 'always' or (\n             setting == 'auto' and\n-            sys.stdout.isatty() and\n+            sys.stderr.isatty() and\n             terminal_supports_color and\n             os.getenv('TERM') != 'dumb'\n         )\n", "issue": "No colors when hooks are run by a git commit\nHi,\r\nI use pre-commit at home on linux which works perfect. But at work I have a windows pc. Here I have problems with the colorfull output. \r\n\r\nWhen the hooks are run by `tox` calling `pre-commit run` there are colors as usual. When the hooks are run by a `git commit` the colors are missing.\r\n\r\nConcrete I mean the green for 'Passed', red for 'Failed ' and yellow/brown for 'Skipped' in the overview.\r\n\r\nThere is no difference if I run it via git-bash, cmd or powershell. Also there is no difference if I use the pycharm buildin terminal or others.\n", "before_files": [{"content": "import os\nimport sys\n\nif sys.platform == 'win32':  # pragma: no cover (windows)\n    def _enable() -> None:\n        from ctypes import POINTER\n        from ctypes import windll\n        from ctypes import WinError\n        from ctypes import WINFUNCTYPE\n        from ctypes.wintypes import BOOL\n        from ctypes.wintypes import DWORD\n        from ctypes.wintypes import HANDLE\n\n        STD_OUTPUT_HANDLE = -11\n        ENABLE_VIRTUAL_TERMINAL_PROCESSING = 4\n\n        def bool_errcheck(result, func, args):\n            if not result:\n                raise WinError()\n            return args\n\n        GetStdHandle = WINFUNCTYPE(HANDLE, DWORD)(\n            ('GetStdHandle', windll.kernel32), ((1, 'nStdHandle'),),\n        )\n\n        GetConsoleMode = WINFUNCTYPE(BOOL, HANDLE, POINTER(DWORD))(\n            ('GetConsoleMode', windll.kernel32),\n            ((1, 'hConsoleHandle'), (2, 'lpMode')),\n        )\n        GetConsoleMode.errcheck = bool_errcheck\n\n        SetConsoleMode = WINFUNCTYPE(BOOL, HANDLE, DWORD)(\n            ('SetConsoleMode', windll.kernel32),\n            ((1, 'hConsoleHandle'), (1, 'dwMode')),\n        )\n        SetConsoleMode.errcheck = bool_errcheck\n\n        # As of Windows 10, the Windows console supports (some) ANSI escape\n        # sequences, but it needs to be enabled using `SetConsoleMode` first.\n        #\n        # More info on the escape sequences supported:\n        # https://msdn.microsoft.com/en-us/library/windows/desktop/mt638032(v=vs.85).aspx\n        stdout = GetStdHandle(STD_OUTPUT_HANDLE)\n        flags = GetConsoleMode(stdout)\n        SetConsoleMode(stdout, flags | ENABLE_VIRTUAL_TERMINAL_PROCESSING)\n\n    try:\n        _enable()\n    except OSError:\n        terminal_supports_color = False\n    else:\n        terminal_supports_color = True\nelse:  # pragma: win32 no cover\n    terminal_supports_color = True\n\nRED = '\\033[41m'\nGREEN = '\\033[42m'\nYELLOW = '\\033[43;30m'\nTURQUOISE = '\\033[46;30m'\nSUBTLE = '\\033[2m'\nNORMAL = '\\033[m'\n\n\ndef format_color(text: str, color: str, use_color_setting: bool) -> str:\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 use_color_setting:\n        return f'{color}{text}{NORMAL}'\n    else:\n        return text\n\n\nCOLOR_CHOICES = ('auto', 'always', 'never')\n\n\ndef use_color(setting: str) -> bool:\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 ValueError(setting)\n\n    return (\n        setting == 'always' or (\n            setting == 'auto' and\n            sys.stdout.isatty() and\n            terminal_supports_color and\n            os.getenv('TERM') != 'dumb'\n        )\n    )\n", "path": "pre_commit/color.py"}]}