internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: pallets/click

Issue:
Strikethrough support
I'd love to see strike-through support for [`style`](http://click.pocoo.org/5/api/#click.style). AFAIK, most modern terminals support this.

From what I understand, this is "code number 9", and can be tested via `echo -e "\e[9mtest\e[0m"`.


Discussion:
Taking a look at this enhancement request.
There are only a certain number of terminals that have support for strikethrough. Do we want to include this functionality with caution that this heavily depends on the user's terminal?

Mac's terminal for example does not appear to have support for strikethrough.
PuTTY also doesn't support it.
This might be a better fit for https://github.com/click-contrib then?
Agreed. Is this relevant to an existing repo or can another one be created?
Feel free to take this Issue. 
The core modification will be in termui.py under the style method and it can be tested using a combination of click.echo() and click.style().
@davidism I am working on this Issue. Informed here.

Resolving patch:
diff --git a/src/click/termui.py b/src/click/termui.py
--- a/src/click/termui.py
+++ b/src/click/termui.py
@@ -456,6 +456,7 @@ def style(
     underline=None,
     blink=None,
     reverse=None,
+    strikethrough=None,
     reset=True,
 ):
     """Styles a text with ANSI styles and returns the new string.  By
@@ -511,6 +512,8 @@ def style(
     :param reverse: if provided this will enable or disable inverse
                     rendering (foreground becomes background and the
                     other way round).
+    :param strikethrough: if provided this will enable or disable
+        striking through text.
     :param reset: by default a reset-all code is added at the end of the
                   string which means that styles do not carry over.  This
                   can be disabled to compose styles.
@@ -521,6 +524,9 @@ def style(
     .. versionchanged:: 8.0
        Added support for 256 and RGB color codes.
 
+    .. versionchanged:: 8.0
+        Added the ``strikethrough`` parameter.
+
     .. versionchanged:: 7.0
         Added support for bright colors.
 
@@ -553,6 +559,8 @@ def style(
         bits.append(f"\033[{5 if blink else 25}m")
     if reverse is not None:
         bits.append(f"\033[{7 if reverse else 27}m")
+    if strikethrough is not None:
+        bits.append(f"\033[{9 if strikethrough else 29}m")
     bits.append(text)
     if reset:
         bits.append(_ansi_reset_all)


Test patch:
Repository: pallets/click

Issue:
Italic and overline aren't supported in `style`
Most terminal programs are capable of presenting italic and overlined fonts. 

This is solvable with a relatively trivial change to termui.style



Discussion:

Resolving patch:
diff --git a/src/click/termui.py b/src/click/termui.py
--- a/src/click/termui.py
+++ b/src/click/termui.py
@@ -464,6 +464,8 @@ def style(
     bold=None,
     dim=None,
     underline=None,
+    overline=None,
+    italic=None,
     blink=None,
     reverse=None,
     strikethrough=None,
@@ -518,6 +520,8 @@ def style(
     :param dim: if provided this will enable or disable dim mode.  This is
                 badly supported.
     :param underline: if provided this will enable or disable underline.
+    :param overline: if provided this will enable or disable overline.
+    :param italic: if provided this will enable or disable italic.
     :param blink: if provided this will enable or disable blinking.
     :param reverse: if provided this will enable or disable inverse
                     rendering (foreground becomes background and the
@@ -535,7 +539,8 @@ def style(
        Added support for 256 and RGB color codes.
 
     .. versionchanged:: 8.0
-        Added the ``strikethrough`` parameter.
+        Added the ``strikethrough``, ``italic``, and ``overline``
+        parameters.
 
     .. versionchanged:: 7.0
         Added support for bright colors.
@@ -565,6 +570,10 @@ def style(
         bits.append(f"\033[{2 if dim else 22}m")
     if underline is not None:
         bits.append(f"\033[{4 if underline else 24}m")
+    if overline is not None:
+        bits.append(f"\033[{53 if underline else 55}m")
+    if italic is not None:
+        bits.append(f"\033[{5 if underline else 23}m")
     if blink is not None:
         bits.append(f"\033[{5 if blink else 25}m")
     if reverse is not None:


Test patch:
diff --git a/tests/test_utils.py b/tests/test_utils.py
--- a/tests/test_utils.py
+++ b/tests/test_utils.py
@@ -64,10 +64,15 @@ def test_echo_custom_file():
         ({"bg": "white"}, "\x1b[47mx y\x1b[0m"),
         ({"bg": 91}, "\x1b[48;5;91mx y\x1b[0m"),
         ({"bg": (135, 0, 175)}, "\x1b[48;2;135;0;175mx y\x1b[0m"),
-        ({"blink": True}, "\x1b[5mx y\x1b[0m"),
-        ({"underline": True}, "\x1b[4mx y\x1b[0m"),
         ({"bold": True}, "\x1b[1mx y\x1b[0m"),
         ({"dim": True}, "\x1b[2mx y\x1b[0m"),
+        ({"underline": True}, "\x1b[4mx y\x1b[0m"),
+        ({"overline": True}, "\x1b[55mx y\x1b[0m"),
+        ({"italic": True}, "\x1b[23mx y\x1b[0m"),
+        ({"blink": True}, "\x1b[5mx y\x1b[0m"),
+        ({"reverse": True}, "\x1b[7mx y\x1b[0m"),
+        ({"strikethrough": True}, "\x1b[9mx y\x1b[0m"),
+        ({"fg": "black", "reset": False}, "\x1b[30mx y"),
     ],
 )
 def test_styling(styles, ref):
Repository: pallets/click

Issue:
resolve_path differs on Windows depending on Python version
<!--
This issue tracker is a tool to address bugs in Click itself. Please use
Pallets Discord or Stack Overflow for questions about your own code.

Replace this comment with a clear outline of what the bug is.
-->

<!--
Describe how to replicate the bug.

Include a minimal reproducible example that demonstrates the bug.
Include the full traceback if there was an exception.
-->

<!--
Describe the expected behavior that should have happened but didn't.
-->

Hi. There was an issue filed under [Typer](https://github.com/tiangolo/typer/issues/244#issuecomment-792455309) that gives a full explanation, but basically the use of `os.path.realpath` in the `resolve_path` logic for click.Path differs between Python 3.7 and 3.8 on Windows. Prior to 3.8, `os.path.realpath` did not resolve symlinks. Therefore Click users on Windows using Python 3.7 or lower are getting the wrong results for resolve_path.

More info: https://docs.python.org/3/library/os.path.html#os.path.realpath


Discussion:
I'm not sure what you're proposing click should do here.
Sorry...I probably should have specified the solution. 

[This resolve path logic](https://github.com/pallets/click/blob/master/src/click/types.py#L736) needs to account for symbolic links, particularly for the Windows issue.

The way to do this is to check if the path is a link with `os.path.islink`, and if it is, then get the path with `os.readlink`.  That seems like the best cross-platform solution, and I don't think it should break anything. 

I would normally submit a PR but currently super occupied this month. 🤔
@davidism I'm an MLH Fellow, I am working on this issue.

Resolving patch:
diff --git a/src/click/types.py b/src/click/types.py
--- a/src/click/types.py
+++ b/src/click/types.py
@@ -734,6 +734,10 @@ def convert(self, value, param, ctx):
 
         if not is_dash:
             if self.resolve_path:
+                # realpath on Windows Python < 3.8 doesn't resolve symlinks
+                if os.path.islink(rv):
+                    rv = os.readlink(rv)
+
                 rv = os.path.realpath(rv)
 
             try:


Test patch:
Repository: pallets/click

Issue:
Click prompts do not cooperate with readline module
When readline is imported and a user presses backspace during a Click prompt, the entire prompt message is erased and cursor goes to beginning of the line. This can be reproduced with the following code:

```
import click, readline
click.prompt("Input")
```

This is due to [Python issue 12833](https://bugs.python.org/issue12833). The official recommendation is that the prompt should be displayed with raw_input. I noticed that Click first displays the prompt message using echo() and then uses raw_input("") for the prompt. There is also a workaround by passing " " to raw_input, however, that may be ugly in the display.



Discussion:
Any feedback about this particular issue?
The click-shell package relies on readline, so this issue causes problems when using that.

What I've done to patch this is:

- edit `click/termui.py` and go to the `f("")` line.
- Replace `f("")` with `f(" ")` (notice the space)
- In the line above, add an `rstrip(" ")` to remove ugly display: `echo(text.rstrip(" "), nl=False, err=err)`

How about echoing the prompt as usual, but displaying the prefix in the input-method (like `f(prefix)`) ?

Resolving patch:
diff --git a/src/click/termui.py b/src/click/termui.py
--- a/src/click/termui.py
+++ b/src/click/termui.py
@@ -127,8 +127,10 @@ def prompt_func(text):
         try:
             # Write the prompt separately so that we get nice
             # coloring through colorama on Windows
-            echo(text, nl=False, err=err)
-            return f("")
+            echo(text.rstrip(" "), nl=False, err=err)
+            # Echo a space to stdout to work around an issue where
+            # readline causes backspace to clear the whole line.
+            return f(" ")
         except (KeyboardInterrupt, EOFError):
             # getpass doesn't print a newline if the user aborts input with ^C.
             # Allegedly this behavior is inherited from getpass(3).


Test patch:
diff --git a/tests/test_utils.py b/tests/test_utils.py
--- a/tests/test_utils.py
+++ b/tests/test_utils.py
@@ -154,10 +154,10 @@ def f(_):
     try:
         click.prompt("Password", hide_input=True)
     except click.Abort:
-        click.echo("Screw you.")
+        click.echo("interrupted")
 
     out, err = capsys.readouterr()
-    assert out == "Password: \nScrew you.\n"
+    assert out == "Password:\ninterrupted\n"
 
 
 def _test_gen_func():
@@ -255,8 +255,8 @@ def emulate_input(text):
     emulate_input("asdlkj\n")
     click.prompt("Prompt to stderr", err=True)
     out, err = capfd.readouterr()
-    assert out == ""
-    assert err == "Prompt to stderr: "
+    assert out == " "
+    assert err == "Prompt to stderr:"
 
     emulate_input("y\n")
     click.confirm("Prompt to stdin")
Repository: pallets/click

Issue:
urllib.unquote() no longer exists
In [_termui_impl.py](https://github.com/pallets/click/blob/972becff259e4ffcd220a6cad5096f36a89fdd6d/src/click/_termui_impl.py#L556) `urllib.unquote()` is called. But [urllib](https://docs.python.org/3/library/urllib.html) is a package now. Equivalent functionality is available in the urllib.parse module.


Discussion:
Happy to review a PR.

Resolving patch:
diff --git a/src/click/_termui_impl.py b/src/click/_termui_impl.py
--- a/src/click/_termui_impl.py
+++ b/src/click/_termui_impl.py
@@ -549,11 +549,12 @@ def edit(self, text):
 def open_url(url, wait=False, locate=False):
     import subprocess
 
-    def _unquote_file(url):
-        import urllib
+    def _unquote_file(url: str) -> str:
+        from urllib.parse import unquote
 
         if url.startswith("file://"):
-            url = urllib.unquote(url[7:])
+            url = unquote(url[7:])
+
         return url
 
     if sys.platform == "darwin":


Test patch:
Repository: pallets/click

Issue:
shell_complete's type annotation and usage don't match
The [declared signature of `shell_complete`](https://github.com/pallets/click/blob/fc4ebb86c8e5fe8e7bdb3d1516f286f16865f538/src/click/core.py#L2023-L2027) does not match the way it is used:

Specifically it's return type is declared as `List[Union[CompletionItem, str]]`. This means a list where any item can be either a `CompletionItem` or `str` instance.

Instead the [code that uses it](https://github.com/pallets/click/blob/fc4ebb86c8e5fe8e7bdb3d1516f286f16865f538/src/click/core.py#L2388-L2395) tests the type of the first member of this list and assumes every other member of the list has the same type. So either the usage is wrong or the type annotation is wrong.

I.e. either the usage should be something akin to:
```python
            results = [(CompletionItem(c) if isinstance(c, str) else c) for c in results]
```
Or the type annotation should have `t.Union[t.List["CompletionItem"], t.List[str]]` as its return type. I.e. the union should be on the outside, not the inside of the list.

FYI the type annotation was introduced by #1856 (0103c9570650daa59560baf42ad0a27e57b3157f), while the (current) code that converts to a list of `CompletionItem`s was introduced by #1622 (3faede8b430ef88f36d3efa513f5e4065a3f3a7e).


Discussion:

Resolving patch:
diff --git a/src/click/core.py b/src/click/core.py
--- a/src/click/core.py
+++ b/src/click/core.py
@@ -2022,7 +2022,8 @@ def __init__(
         envvar: t.Optional[t.Union[str, t.Sequence[str]]] = None,
         shell_complete: t.Optional[
             t.Callable[
-                [Context, "Parameter", str], t.List[t.Union["CompletionItem", str]]
+                [Context, "Parameter", str],
+                t.Union[t.List["CompletionItem"], t.List[str]],
             ]
         ] = None,
         autocompletion: t.Optional[
@@ -2068,7 +2069,7 @@ def __init__(
 
             def shell_complete(
                 ctx: Context, param: "Parameter", incomplete: str
-            ) -> t.List[t.Union["CompletionItem", str]]:
+            ) -> t.List["CompletionItem"]:
                 from click.shell_completion import CompletionItem
 
                 out = []


Test patch:
Repository: pallets/click

Issue:
Allow ANSI escapes codes in metavar hints
Hello,

little quirk when printing metavar hint : 
`
Error: Missing argument '\x1b[95mREGION\x1b[0m'.
`

region argument was declared like this : 
`
region_argument = click.argument('region', metavar=click.style('REGION', fg='bright_magenta'))
`

It should be printed with magenta color : 

`
Error: Missing argument 'REGION'.
`

Environment:

- Python version: 3.6
- Click version: > 8.0 / master



Discussion:

Resolving patch:
diff --git a/src/click/core.py b/src/click/core.py
--- a/src/click/core.py
+++ b/src/click/core.py
@@ -2372,7 +2372,7 @@ def get_error_hint(self, ctx: Context) -> str:
         indicate which param caused the error.
         """
         hint_list = self.opts or [self.human_readable_name]
-        return " / ".join(repr(x) for x in hint_list)
+        return " / ".join(f"'{x}'" for x in hint_list)
 
     def shell_complete(self, ctx: Context, incomplete: str) -> t.List["CompletionItem"]:
         """Return a list of completions for the incomplete value. If a
@@ -2926,7 +2926,7 @@ def get_usage_pieces(self, ctx: Context) -> t.List[str]:
         return [self.make_metavar()]
 
     def get_error_hint(self, ctx: Context) -> str:
-        return repr(self.make_metavar())
+        return f"'{self.make_metavar()}'"
 
     def add_to_parser(self, parser: OptionParser, ctx: Context) -> None:
         parser.add_argument(dest=self.name, nargs=self.nargs, obj=self)


Test patch:
Repository: pallets/click

Issue:
`HelpFormatter.write_text()` is not using all the available line width
`HelpFormatter.write_text()` uses the function `wrap_text(text, width, initial_indent, ...)` internally. This function expects `width` to be the line width **including** the eventual indentation. `HelpFormatter.write_text()` gets this wrong and passes `self.width - self.current_indent` instead of just `self.width`.




Discussion:

Resolving patch:
diff --git a/src/click/formatting.py b/src/click/formatting.py
--- a/src/click/formatting.py
+++ b/src/click/formatting.py
@@ -195,12 +195,11 @@ def write_text(self, text: str) -> None:
         """Writes re-indented text into the buffer.  This rewraps and
         preserves paragraphs.
         """
-        text_width = max(self.width - self.current_indent, 11)
         indent = " " * self.current_indent
         self.write(
             wrap_text(
                 text,
-                text_width,
+                self.width,
                 initial_indent=indent,
                 subsequent_indent=indent,
                 preserve_paragraphs=True,


Test patch:
diff --git a/tests/test_formatting.py b/tests/test_formatting.py
--- a/tests/test_formatting.py
+++ b/tests/test_formatting.py
@@ -335,3 +335,13 @@ def test_formatting_with_options_metavar_empty(runner):
     cli = click.Command("cli", options_metavar="", params=[click.Argument(["var"])])
     result = runner.invoke(cli, ["--help"])
     assert "Usage: cli VAR\n" in result.output
+
+
+def test_help_formatter_write_text():
+    text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit"
+    formatter = click.HelpFormatter(width=len("  Lorem ipsum dolor sit amet,"))
+    formatter.current_indent = 2
+    formatter.write_text(text)
+    actual = formatter.getvalue()
+    expected = "  Lorem ipsum dolor sit amet,\n  consectetur adipiscing elit\n"
+    assert actual == expected
Repository: pallets/click

Issue:
mypy error on progress bar usage
xxx.py:
```python
import click

with click.progressbar([1, 2, 3]) as bar:
    for x in bar:
        pass
```

mypy error:
```
$ mypy xxx.py 
xxx.py:4: error: "Iterable[<nothing>]" has no attribute "__next__"  [attr-defined]
Found 1 error in 1 file (checked 1 source file)
```

Environment:

- Python version: 3.9.5
- Click version: 8.0.0
- mypy version: 0.812



Discussion:
Changing the return type in `ProgressBar.__iter__` https://github.com/pallets/click/blob/9da166957f5848b641231d485467f6140bca2bc0/src/click/_termui_impl.py#L104 from `t.Iterable[V]` to `t.Iterator[V]` fixes the mypy error, but it requires that you declare the type of x. 
I'm also not sure if it's the correct thing to do type wise.
I'm working in this, going to use generics since it shouldn't affect performance in this case

Resolving patch:
diff --git a/src/click/_termui_impl.py b/src/click/_termui_impl.py
--- a/src/click/_termui_impl.py
+++ b/src/click/_termui_impl.py
@@ -32,7 +32,7 @@
     AFTER_BAR = "\033[?25h\n"
 
 
-class ProgressBar:
+class ProgressBar(t.Generic[V]):
     def __init__(
         self,
         iterable: t.Optional[t.Iterable[V]],
@@ -50,7 +50,7 @@ def __init__(
         color: t.Optional[bool] = None,
         update_min_steps: int = 1,
         width: int = 30,
-    ):
+    ) -> None:
         self.fill_char = fill_char
         self.empty_char = empty_char
         self.bar_template = bar_template
@@ -101,7 +101,7 @@ def __enter__(self) -> "ProgressBar":
     def __exit__(self, exc_type, exc_value, tb):  # type: ignore
         self.render_finish()
 
-    def __iter__(self) -> t.Iterable[V]:
+    def __iter__(self) -> t.Iterator[V]:
         if not self.entered:
             raise RuntimeError("You need to use progress bars in a with block.")
         self.render_progress()
@@ -113,7 +113,7 @@ def __next__(self) -> V:
         # because `self.iter` is an iterable consumed by that generator,
         # so it is re-entry safe. Calling `next(self.generator())`
         # twice works and does "what you want".
-        return next(iter(self))  # type: ignore
+        return next(iter(self))
 
     def render_finish(self) -> None:
         if self.is_hidden:
diff --git a/src/click/termui.py b/src/click/termui.py
--- a/src/click/termui.py
+++ b/src/click/termui.py
@@ -318,7 +318,7 @@ def progressbar(
     file: t.Optional[t.TextIO] = None,
     color: t.Optional[bool] = None,
     update_min_steps: int = 1,
-) -> "ProgressBar":
+) -> "ProgressBar[V]":
     """This function creates an iterable context manager that can be used
     to iterate over something while showing a progress bar.  It will
     either iterate over the `iterable` or `length` items (that are counted


Test patch:
Repository: pallets/click

Issue:
argument with nargs=-1 and envvar ignores values from command line
Since click 8.0, the value(s) provided on the command line for a nargs=-1 argument are ignored if the argument has `envvar` set.

Example:

```python
#!/usr/bin/env python
import click

@click.command()
@click.argument("foo", nargs=-1, envvar="FOO")
def cli(foo):
    click.echo(foo)

if __name__ == "__main__":
    cli()
```

```
$ ./clickbug arg1 arg2
()
```


When arguments are passed on the command line, the `foo` value remains empty. Removing the `envvar` option makes it work again. Values from the environment variable are picked up, though. Reverting to `click<8` also fixes the problem.

The cause of the bug is possibly [here](https://github.com/pallets/click/commit/3d3ea9c64420fd8978a41ce8b4db3ac2d245849c#diff-948f9e0cc733616a6b18aa152ac6703e819fec61dd752d1efa40e5736c3bdce7): The incoming `value` (which at this point still contains the correct arguments) is overwritten with `None` if `nargs` is -1 and the argument has an envvar set.

Environment:

- Python version: 3.8.5
- Click version: 8.0.0



Discussion:

Resolving patch:
diff --git a/src/click/parser.py b/src/click/parser.py
--- a/src/click/parser.py
+++ b/src/click/parser.py
@@ -233,7 +233,9 @@ def process(
                     )
                 )
 
-        if self.nargs == -1 and self.obj.envvar is not None:
+        if self.nargs == -1 and self.obj.envvar is not None and value == ():
+            # Replace empty tuple with None so that a value from the
+            # environment may be tried.
             value = None
 
         state.opts[self.dest] = value  # type: ignore


Test patch:
diff --git a/tests/test_arguments.py b/tests/test_arguments.py
--- a/tests/test_arguments.py
+++ b/tests/test_arguments.py
@@ -194,6 +194,19 @@ def cmd(arg):
         assert result.return_value == expect
 
 
+def test_nargs_envvar_only_if_values_empty(runner):
+    @click.command()
+    @click.argument("arg", envvar="X", nargs=-1)
+    def cli(arg):
+        return arg
+
+    result = runner.invoke(cli, ["a", "b"], standalone_mode=False)
+    assert result.return_value == ("a", "b")
+
+    result = runner.invoke(cli, env={"X": "a"}, standalone_mode=False)
+    assert result.return_value == ("a",)
+
+
 def test_empty_nargs(runner):
     @click.command()
     @click.argument("arg", nargs=-1)