|
6 | 6 | import enum |
7 | 7 | import threading |
8 | 8 | from collections import defaultdict |
| 9 | + |
9 | 10 | # Ruff is being stupid and doesn't understand `ClassVar` if it comes from the |
10 | 11 | # `types` module |
11 | 12 | from typing import ClassVar |
12 | 13 |
|
13 | 14 | from python_utils import converters, types |
14 | 15 |
|
15 | | -from .os_specific import getch |
16 | 16 | from .. import ( |
17 | 17 | base as pbase, |
18 | 18 | env, |
19 | 19 | ) |
| 20 | +from .os_specific import getch |
20 | 21 |
|
21 | 22 | ESC = '\x1B' |
22 | 23 |
|
@@ -178,7 +179,6 @@ def column(self, stream): |
178 | 179 | return column |
179 | 180 |
|
180 | 181 |
|
181 | | - |
182 | 182 | class WindowsColors(enum.Enum): |
183 | 183 | BLACK = 0, 0, 0 |
184 | 184 | BLUE = 0, 0, 128 |
@@ -235,20 +235,23 @@ class WindowsColor: |
235 | 235 | >>> WindowsColor(WindowsColors.RED)('test') |
236 | 236 | 'test' |
237 | 237 | ''' |
238 | | - __slots__ = 'color', |
| 238 | + |
| 239 | + __slots__ = ('color',) |
239 | 240 |
|
240 | 241 | def __init__(self, color: Color): |
241 | 242 | self.color = color |
242 | 243 |
|
243 | 244 | def __call__(self, text): |
244 | 245 | return text |
245 | | - # In the future we might want to use this, but it requires direct printing to stdout and all of our surrounding functions expect buffered output so it's not feasible right now. |
246 | | - # Additionally, recent Windows versions all support ANSI codes without issue so there is little need. |
| 246 | + ## In the future we might want to use this, but it requires direct |
| 247 | + ## printing to stdout and all of our surrounding functions expect |
| 248 | + ## buffered output so it's not feasible right now. Additionally, |
| 249 | + ## recent Windows versions all support ANSI codes without issue so |
| 250 | + ## there is little need. |
247 | 251 | # from progressbar.terminal.os_specific import windows |
248 | 252 | # windows.print_color(text, WindowsColors.from_rgb(self.color.rgb)) |
249 | 253 |
|
250 | 254 |
|
251 | | - |
252 | 255 | class RGB(collections.namedtuple('RGB', ['red', 'green', 'blue'])): |
253 | 256 | __slots__ = () |
254 | 257 |
|
@@ -387,14 +390,14 @@ def underline(self): |
387 | 390 | @property |
388 | 391 | def ansi(self) -> types.Optional[str]: |
389 | 392 | if ( |
390 | | - env.COLOR_SUPPORT is env.ColorSupport.XTERM_TRUECOLOR |
| 393 | + env.COLOR_SUPPORT is env.ColorSupport.XTERM_TRUECOLOR |
391 | 394 | ): # pragma: no branch |
392 | 395 | return f'2;{self.rgb.red};{self.rgb.green};{self.rgb.blue}' |
393 | 396 |
|
394 | 397 | if self.xterm: # pragma: no branch |
395 | 398 | color = self.xterm |
396 | 399 | elif ( |
397 | | - env.COLOR_SUPPORT is env.ColorSupport.XTERM_256 |
| 400 | + env.COLOR_SUPPORT is env.ColorSupport.XTERM_256 |
398 | 401 | ): # pragma: no branch |
399 | 402 | color = self.rgb.to_ansi_256 |
400 | 403 | elif env.COLOR_SUPPORT is env.ColorSupport.XTERM: # pragma: no branch |
@@ -442,11 +445,11 @@ class Colors: |
442 | 445 |
|
443 | 446 | @classmethod |
444 | 447 | def register( |
445 | | - cls, |
446 | | - rgb: RGB, |
447 | | - hls: types.Optional[HSL] = None, |
448 | | - name: types.Optional[str] = None, |
449 | | - xterm: types.Optional[int] = None, |
| 448 | + cls, |
| 449 | + rgb: RGB, |
| 450 | + hls: types.Optional[HSL] = None, |
| 451 | + name: types.Optional[str] = None, |
| 452 | + xterm: types.Optional[int] = None, |
450 | 453 | ) -> Color: |
451 | 454 | color = Color(rgb, hls, name, xterm) |
452 | 455 |
|
@@ -483,9 +486,9 @@ def __call__(self, value: float) -> Color: |
483 | 486 | def get_color(self, value: float) -> Color: |
484 | 487 | 'Map a value from 0 to 1 to a color.' |
485 | 488 | if ( |
486 | | - value == pbase.Undefined |
487 | | - or value == pbase.UnknownLength |
488 | | - or value <= 0 |
| 489 | + value == pbase.Undefined |
| 490 | + or value == pbase.UnknownLength |
| 491 | + or value <= 0 |
489 | 492 | ): |
490 | 493 | return self.colors[0] |
491 | 494 | elif value >= 1: |
@@ -531,14 +534,14 @@ def get_color(value: float, color: OptionalColor) -> Color | None: |
531 | 534 |
|
532 | 535 |
|
533 | 536 | def apply_colors( |
534 | | - text: str, |
535 | | - percentage: float | None = None, |
536 | | - *, |
537 | | - fg: OptionalColor = None, |
538 | | - bg: OptionalColor = None, |
539 | | - fg_none: Color | None = None, |
540 | | - bg_none: Color | None = None, |
541 | | - **kwargs: types.Any, |
| 537 | + text: str, |
| 538 | + percentage: float | None = None, |
| 539 | + *, |
| 540 | + fg: OptionalColor = None, |
| 541 | + bg: OptionalColor = None, |
| 542 | + fg_none: Color | None = None, |
| 543 | + bg_none: Color | None = None, |
| 544 | + **kwargs: types.Any, |
542 | 545 | ) -> str: |
543 | 546 | '''Apply colors/gradients to a string depending on the given percentage. |
544 | 547 |
|
|
0 commit comments