|
9 | 9 | import textwrap |
10 | 10 | from collections.abc import Generator |
11 | 11 | from contextlib import suppress |
12 | | -from typing import Any, NoReturn |
| 12 | +from typing import IO, Any, Dict, List, NoReturn, Optional |
13 | 13 |
|
14 | | -from pip._vendor.rich.console import Console, RenderableType |
| 14 | +from pip._vendor.rich.console import Console, RenderableType, detect_legacy_windows |
15 | 15 | from pip._vendor.rich.markup import escape |
16 | 16 | from pip._vendor.rich.style import StyleType |
17 | 17 | from pip._vendor.rich.text import Text |
@@ -244,6 +244,22 @@ def option_list_all(self) -> list[optparse.Option]: |
244 | 244 |
|
245 | 245 | return res |
246 | 246 |
|
| 247 | + def _print_ansi(self, text: str, file: Optional[IO[str]] = None) -> None: |
| 248 | + if file is None: |
| 249 | + file = sys.stdout |
| 250 | + if detect_legacy_windows(): |
| 251 | + console = Console(file=file) |
| 252 | + console.print(Text.from_ansi(text), soft_wrap=True) |
| 253 | + else: |
| 254 | + file.write(text) |
| 255 | + |
| 256 | + def print_usage(self, file: Optional[IO[str]] = None) -> None: |
| 257 | + if self.usage: |
| 258 | + self._print_ansi(self.get_usage(), file=file) |
| 259 | + |
| 260 | + def print_help(self, file: Optional[IO[str]] = None) -> None: |
| 261 | + self._print_ansi(self.format_help(), file=file) |
| 262 | + |
247 | 263 |
|
248 | 264 | class ConfigOptionParser(CustomOptionParser): |
249 | 265 | """Custom option parser which updates its defaults by checking the |
|
0 commit comments