Repository: pallets/click
Pull request #2058 (2021-09-06 10:05:35)

fix overline and italic styles
Original message: This is a drive-by-commit fixing an obvious error. Please don't force me to go through paperwork.

Maintainer added description: Overline and italic styles were looking at the `underline` argument by mistake.

Checklist:

- [x] Add tests that demonstrate the correct behavior of the change. Tests should fail without the change.
- [ ] Add or update relevant docs, in the docs folder and in code.
- [ ] Add an entry in `CHANGES.rst` summarizing the change and linking to the issue.
- [ ] Add `.. versionchanged::` entries in any relevant code docs.
- [ ] Run `pre-commit` hooks and fix any issues.
- [x] Run `pytest` and `tox`, no tests failed.




davidism: Thanks for fixing this. However, in the future, please do "go through the paperwork", such as describing what you're fixing. The way you've worded this PR is really dismissive of maintainers time, which is not appreciated. Keep this in mind for any PRs you make, not only on Pallets projects.

Patch:
diff --git a/CHANGES.rst b/CHANGES.rst
index 77783c7..e4e69b1 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -18,6 +18,8 @@ Unreleased
     avoiding some unexpected warning output. :issue:`1738, 2017`
 -   Fix type annotation for ``type`` argument in ``prompt`` function.
     :issue:`2062`
+-   Fix overline and italic styles, which were incorrectly added when
+    adding underline. :pr:`2058`
 
 
 Version 8.0.1
diff --git a/src/click/termui.py b/src/click/termui.py
index 042fc4b..a023f42 100644
--- a/src/click/termui.py
+++ b/src/click/termui.py
@@ -596,9 +596,9 @@ def style(
     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")
+        bits.append(f"\033[{53 if overline else 55}m")
     if italic is not None:
-        bits.append(f"\033[{5 if underline else 23}m")
+        bits.append(f"\033[{3 if italic 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
index 23b3709..d21b246 100644
--- a/tests/test_utils.py
+++ b/tests/test_utils.py
@@ -67,11 +67,19 @@ def test_echo_custom_file():
         ({"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"),
+        ({"overline": True}, "\x1b[53mx y\x1b[0m"),
+        ({"italic": True}, "\x1b[3mx y\x1b[0m"),
         ({"blink": True}, "\x1b[5mx y\x1b[0m"),
         ({"reverse": True}, "\x1b[7mx y\x1b[0m"),
         ({"strikethrough": True}, "\x1b[9mx y\x1b[0m"),
+        ({"bold": False}, "\x1b[22mx y\x1b[0m"),
+        ({"dim": False}, "\x1b[22mx y\x1b[0m"),
+        ({"underline": False}, "\x1b[24mx y\x1b[0m"),
+        ({"overline": False}, "\x1b[55mx y\x1b[0m"),
+        ({"italic": False}, "\x1b[23mx y\x1b[0m"),
+        ({"blink": False}, "\x1b[25mx y\x1b[0m"),
+        ({"reverse": False}, "\x1b[27mx y\x1b[0m"),
+        ({"strikethrough": False}, "\x1b[29mx y\x1b[0m"),
         ({"fg": "black", "reset": False}, "\x1b[30mx y"),
     ],
 )