We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Windows: Terminal width support
We detect terminal width in unixlikes by running `tput cols`.  This works fine for those platforms but doesn't work well for windows.  Maybe find a package which does this logic for us and depend on that.


--- 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/output.py`
Content:
```
1 from __future__ import unicode_literals
2 
3 import os
4 import subprocess
5 import sys
6 
7 from pre_commit import color
8 from pre_commit import five
9 
10 
11 # TODO: smell: import side-effects
12 try:
13     if not os.environ.get('TERM'):  # pragma: no cover (dumb terminal)
14         raise OSError('Cannot determine width without TERM')
15     else:  # pragma no cover (windows)
16         COLS = int(
17             subprocess.Popen(
18                 ('tput', 'cols'), stdout=subprocess.PIPE,
19             ).communicate()[0] or
20             # Default in the case of no terminal
21             80
22         )
23 except OSError:  # pragma: no cover (windows)
24     COLS = 80
25 
26 
27 def get_hook_message(
28         start,
29         postfix='',
30         end_msg=None,
31         end_len=0,
32         end_color=None,
33         use_color=None,
34         cols=COLS,
35 ):
36     """Prints a message for running a hook.
37 
38     This currently supports three approaches:
39 
40     # Print `start` followed by dots, leaving 6 characters at the end
41     >>> print_hook_message('start', end_len=6)
42     start...............................................................
43 
44     # Print `start` followed by dots with the end message colored if coloring
45     # is specified and a newline afterwards
46     >>> print_hook_message(
47         'start',
48         end_msg='end',
49         end_color=color.RED,
50         use_color=True,
51     )
52     start...................................................................end
53 
54     # Print `start` followed by dots, followed by the `postfix` message
55     # uncolored, followed by the `end_msg` colored if specified and a newline
56     # afterwards
57     >>> print_hook_message(
58         'start',
59         postfix='postfix ',
60         end_msg='end',
61         end_color=color.RED,
62         use_color=True,
63     )
64     start...........................................................postfix end
65     """
66     if bool(end_msg) == bool(end_len):
67         raise ValueError('Expected one of (`end_msg`, `end_len`)')
68     if end_msg is not None and (end_color is None or use_color is None):
69         raise ValueError(
70             '`end_color` and `use_color` are required with `end_msg`'
71         )
72 
73     if end_len:
74         return start + '.' * (cols - len(start) - end_len - 1)
75     else:
76         return '{0}{1}{2}{3}\n'.format(
77             start,
78             '.' * (cols - len(start) - len(postfix) - len(end_msg) - 1),
79             postfix,
80             color.format_color(end_msg, end_color, use_color),
81         )
82 
83 
84 stdout_byte_stream = getattr(sys.stdout, 'buffer', sys.stdout)
85 
86 
87 def sys_stdout_write_wrapper(s, stream=stdout_byte_stream):
88     stream.write(five.to_bytes(s))
89
```

Path: `setup.py`
Content:
```
1 from setuptools import find_packages
2 from setuptools import setup
3 
4 
5 setup(
6     name='pre_commit',
7     description=(
8         'A framework for managing and maintaining multi-language pre-commit '
9         'hooks.'
10     ),
11     url='https://github.com/pre-commit/pre-commit',
12     version='0.7.6',
13 
14     author='Anthony Sottile',
15     author_email='asottile@umich.edu',
16 
17     platforms='linux',
18     classifiers=[
19         'License :: OSI Approved :: MIT License',
20         'Programming Language :: Python :: 2',
21         'Programming Language :: Python :: 2.6',
22         'Programming Language :: Python :: 2.7',
23         'Programming Language :: Python :: 3',
24         'Programming Language :: Python :: 3.3',
25         'Programming Language :: Python :: 3.4',
26         'Programming Language :: Python :: 3.5',
27         'Programming Language :: Python :: Implementation :: CPython',
28         'Programming Language :: Python :: Implementation :: PyPy',
29     ],
30 
31     packages=find_packages('.', exclude=('tests*', 'testing*')),
32     package_data={
33         'pre_commit': [
34             'resources/hook-tmpl',
35             'resources/pre-push-tmpl',
36             'resources/rbenv.tar.gz',
37             'resources/ruby-build.tar.gz',
38             'resources/ruby-download.tar.gz',
39         ]
40     },
41     install_requires=[
42         'argparse',
43         'aspy.yaml',
44         'cached-property',
45         'jsonschema',
46         'nodeenv>=0.11.1',
47         'ordereddict',
48         'pyyaml',
49         'virtualenv',
50     ],
51     entry_points={
52         'console_scripts': [
53             'pre-commit = pre_commit.main:main',
54             'pre-commit-validate-config = pre_commit.clientlib.validate_config:run',  # noqa
55             'pre-commit-validate-manifest = pre_commit.clientlib.validate_manifest:run',  # noqa
56         ],
57     },
58 )
59
```
--- 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()

```

diff --git a/pre_commit/output.py b/pre_commit/output.py
--- a/pre_commit/output.py
+++ b/pre_commit/output.py
@@ -1,27 +1,15 @@
 from __future__ import unicode_literals
 
-import os
-import subprocess
 import sys
 
+from backports.shutil_get_terminal_size import get_terminal_size
+
 from pre_commit import color
 from pre_commit import five
 
-
 # TODO: smell: import side-effects
-try:
-    if not os.environ.get('TERM'):  # pragma: no cover (dumb terminal)
-        raise OSError('Cannot determine width without TERM')
-    else:  # pragma no cover (windows)
-        COLS = int(
-            subprocess.Popen(
-                ('tput', 'cols'), stdout=subprocess.PIPE,
-            ).communicate()[0] or
-            # Default in the case of no terminal
-            80
-        )
-except OSError:  # pragma: no cover (windows)
-    COLS = 80
+# TODO: https://github.com/chrippa/backports.shutil_get_terminal_size/issues/4
+COLS = get_terminal_size().columns or 80
 
 
 def get_hook_message(
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -41,6 +41,7 @@
     install_requires=[
         'argparse',
         'aspy.yaml',
+        'backports.shutil_get_terminal_size',
         'cached-property',
         'jsonschema',
         'nodeenv>=0.11.1',

{"golden_diff": "diff --git a/pre_commit/output.py b/pre_commit/output.py\n--- a/pre_commit/output.py\n+++ b/pre_commit/output.py\n@@ -1,27 +1,15 @@\n from __future__ import unicode_literals\n \n-import os\n-import subprocess\n import sys\n \n+from backports.shutil_get_terminal_size import get_terminal_size\n+\n from pre_commit import color\n from pre_commit import five\n \n-\n # TODO: smell: import side-effects\n-try:\n-    if not os.environ.get('TERM'):  # pragma: no cover (dumb terminal)\n-        raise OSError('Cannot determine width without TERM')\n-    else:  # pragma no cover (windows)\n-        COLS = int(\n-            subprocess.Popen(\n-                ('tput', 'cols'), stdout=subprocess.PIPE,\n-            ).communicate()[0] or\n-            # Default in the case of no terminal\n-            80\n-        )\n-except OSError:  # pragma: no cover (windows)\n-    COLS = 80\n+# TODO: https://github.com/chrippa/backports.shutil_get_terminal_size/issues/4\n+COLS = get_terminal_size().columns or 80\n \n \n def get_hook_message(\ndiff --git a/setup.py b/setup.py\n--- a/setup.py\n+++ b/setup.py\n@@ -41,6 +41,7 @@\n     install_requires=[\n         'argparse',\n         'aspy.yaml',\n+        'backports.shutil_get_terminal_size',\n         'cached-property',\n         'jsonschema',\n         'nodeenv>=0.11.1',\n", "issue": "Windows: Terminal width support\nWe detect terminal width in unixlikes by running `tput cols`.  This works fine for those platforms but doesn't work well for windows.  Maybe find a package which does this logic for us and depend on that.\n\n", "before_files": [{"content": "from __future__ import unicode_literals\n\nimport os\nimport subprocess\nimport sys\n\nfrom pre_commit import color\nfrom pre_commit import five\n\n\n# TODO: smell: import side-effects\ntry:\n    if not os.environ.get('TERM'):  # pragma: no cover (dumb terminal)\n        raise OSError('Cannot determine width without TERM')\n    else:  # pragma no cover (windows)\n        COLS = int(\n            subprocess.Popen(\n                ('tput', 'cols'), stdout=subprocess.PIPE,\n            ).communicate()[0] or\n            # Default in the case of no terminal\n            80\n        )\nexcept OSError:  # pragma: no cover (windows)\n    COLS = 80\n\n\ndef get_hook_message(\n        start,\n        postfix='',\n        end_msg=None,\n        end_len=0,\n        end_color=None,\n        use_color=None,\n        cols=COLS,\n):\n    \"\"\"Prints a message for running a hook.\n\n    This currently supports three approaches:\n\n    # Print `start` followed by dots, leaving 6 characters at the end\n    >>> print_hook_message('start', end_len=6)\n    start...............................................................\n\n    # Print `start` followed by dots with the end message colored if coloring\n    # is specified and a newline afterwards\n    >>> print_hook_message(\n        'start',\n        end_msg='end',\n        end_color=color.RED,\n        use_color=True,\n    )\n    start...................................................................end\n\n    # Print `start` followed by dots, followed by the `postfix` message\n    # uncolored, followed by the `end_msg` colored if specified and a newline\n    # afterwards\n    >>> print_hook_message(\n        'start',\n        postfix='postfix ',\n        end_msg='end',\n        end_color=color.RED,\n        use_color=True,\n    )\n    start...........................................................postfix end\n    \"\"\"\n    if bool(end_msg) == bool(end_len):\n        raise ValueError('Expected one of (`end_msg`, `end_len`)')\n    if end_msg is not None and (end_color is None or use_color is None):\n        raise ValueError(\n            '`end_color` and `use_color` are required with `end_msg`'\n        )\n\n    if end_len:\n        return start + '.' * (cols - len(start) - end_len - 1)\n    else:\n        return '{0}{1}{2}{3}\\n'.format(\n            start,\n            '.' * (cols - len(start) - len(postfix) - len(end_msg) - 1),\n            postfix,\n            color.format_color(end_msg, end_color, use_color),\n        )\n\n\nstdout_byte_stream = getattr(sys.stdout, 'buffer', sys.stdout)\n\n\ndef sys_stdout_write_wrapper(s, stream=stdout_byte_stream):\n    stream.write(five.to_bytes(s))\n", "path": "pre_commit/output.py"}, {"content": "from setuptools import find_packages\nfrom setuptools import setup\n\n\nsetup(\n    name='pre_commit',\n    description=(\n        'A framework for managing and maintaining multi-language pre-commit '\n        'hooks.'\n    ),\n    url='https://github.com/pre-commit/pre-commit',\n    version='0.7.6',\n\n    author='Anthony Sottile',\n    author_email='asottile@umich.edu',\n\n    platforms='linux',\n    classifiers=[\n        'License :: OSI Approved :: MIT License',\n        'Programming Language :: Python :: 2',\n        'Programming Language :: Python :: 2.6',\n        'Programming Language :: Python :: 2.7',\n        'Programming Language :: Python :: 3',\n        'Programming Language :: Python :: 3.3',\n        'Programming Language :: Python :: 3.4',\n        'Programming Language :: Python :: 3.5',\n        'Programming Language :: Python :: Implementation :: CPython',\n        'Programming Language :: Python :: Implementation :: PyPy',\n    ],\n\n    packages=find_packages('.', exclude=('tests*', 'testing*')),\n    package_data={\n        'pre_commit': [\n            'resources/hook-tmpl',\n            'resources/pre-push-tmpl',\n            'resources/rbenv.tar.gz',\n            'resources/ruby-build.tar.gz',\n            'resources/ruby-download.tar.gz',\n        ]\n    },\n    install_requires=[\n        'argparse',\n        'aspy.yaml',\n        'cached-property',\n        'jsonschema',\n        'nodeenv>=0.11.1',\n        'ordereddict',\n        'pyyaml',\n        'virtualenv',\n    ],\n    entry_points={\n        'console_scripts': [\n            'pre-commit = pre_commit.main:main',\n            'pre-commit-validate-config = pre_commit.clientlib.validate_config:run',  # noqa\n            'pre-commit-validate-manifest = pre_commit.clientlib.validate_manifest:run',  # noqa\n        ],\n    },\n)\n", "path": "setup.py"}], "after_files": [{"content": "from __future__ import unicode_literals\n\nimport sys\n\nfrom backports.shutil_get_terminal_size import get_terminal_size\n\nfrom pre_commit import color\nfrom pre_commit import five\n\n# TODO: smell: import side-effects\n# TODO: https://github.com/chrippa/backports.shutil_get_terminal_size/issues/4\nCOLS = get_terminal_size().columns or 80\n\n\ndef get_hook_message(\n        start,\n        postfix='',\n        end_msg=None,\n        end_len=0,\n        end_color=None,\n        use_color=None,\n        cols=COLS,\n):\n    \"\"\"Prints a message for running a hook.\n\n    This currently supports three approaches:\n\n    # Print `start` followed by dots, leaving 6 characters at the end\n    >>> print_hook_message('start', end_len=6)\n    start...............................................................\n\n    # Print `start` followed by dots with the end message colored if coloring\n    # is specified and a newline afterwards\n    >>> print_hook_message(\n        'start',\n        end_msg='end',\n        end_color=color.RED,\n        use_color=True,\n    )\n    start...................................................................end\n\n    # Print `start` followed by dots, followed by the `postfix` message\n    # uncolored, followed by the `end_msg` colored if specified and a newline\n    # afterwards\n    >>> print_hook_message(\n        'start',\n        postfix='postfix ',\n        end_msg='end',\n        end_color=color.RED,\n        use_color=True,\n    )\n    start...........................................................postfix end\n    \"\"\"\n    if bool(end_msg) == bool(end_len):\n        raise ValueError('Expected one of (`end_msg`, `end_len`)')\n    if end_msg is not None and (end_color is None or use_color is None):\n        raise ValueError(\n            '`end_color` and `use_color` are required with `end_msg`'\n        )\n\n    if end_len:\n        return start + '.' * (cols - len(start) - end_len - 1)\n    else:\n        return '{0}{1}{2}{3}\\n'.format(\n            start,\n            '.' * (cols - len(start) - len(postfix) - len(end_msg) - 1),\n            postfix,\n            color.format_color(end_msg, end_color, use_color),\n        )\n\n\nstdout_byte_stream = getattr(sys.stdout, 'buffer', sys.stdout)\n\n\ndef sys_stdout_write_wrapper(s, stream=stdout_byte_stream):\n    stream.write(five.to_bytes(s))\n", "path": "pre_commit/output.py"}, {"content": "from setuptools import find_packages\nfrom setuptools import setup\n\n\nsetup(\n    name='pre_commit',\n    description=(\n        'A framework for managing and maintaining multi-language pre-commit '\n        'hooks.'\n    ),\n    url='https://github.com/pre-commit/pre-commit',\n    version='0.7.6',\n\n    author='Anthony Sottile',\n    author_email='asottile@umich.edu',\n\n    platforms='linux',\n    classifiers=[\n        'License :: OSI Approved :: MIT License',\n        'Programming Language :: Python :: 2',\n        'Programming Language :: Python :: 2.6',\n        'Programming Language :: Python :: 2.7',\n        'Programming Language :: Python :: 3',\n        'Programming Language :: Python :: 3.3',\n        'Programming Language :: Python :: 3.4',\n        'Programming Language :: Python :: 3.5',\n        'Programming Language :: Python :: Implementation :: CPython',\n        'Programming Language :: Python :: Implementation :: PyPy',\n    ],\n\n    packages=find_packages('.', exclude=('tests*', 'testing*')),\n    package_data={\n        'pre_commit': [\n            'resources/hook-tmpl',\n            'resources/pre-push-tmpl',\n            'resources/rbenv.tar.gz',\n            'resources/ruby-build.tar.gz',\n            'resources/ruby-download.tar.gz',\n        ]\n    },\n    install_requires=[\n        'argparse',\n        'aspy.yaml',\n        'backports.shutil_get_terminal_size',\n        'cached-property',\n        'jsonschema',\n        'nodeenv>=0.11.1',\n        'ordereddict',\n        'pyyaml',\n        'virtualenv',\n    ],\n    entry_points={\n        'console_scripts': [\n            'pre-commit = pre_commit.main:main',\n            'pre-commit-validate-config = pre_commit.clientlib.validate_config:run',  # noqa\n            'pre-commit-validate-manifest = pre_commit.clientlib.validate_manifest:run',  # noqa\n        ],\n    },\n)\n", "path": "setup.py"}]}