Skip to content

Commit 90978b4

Browse files
committed
refactor: Use plain ANSI codes, don't import them from Colorama
1 parent cdd3208 commit 90978b4

File tree

1 file changed

+58
-18
lines changed

1 file changed

+58
-18
lines changed

src/griffe/_internal/diff.py

Lines changed: 58 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
from pathlib import Path
1313
from typing import TYPE_CHECKING, Any
1414

15-
from colorama import Fore, Style
16-
1715
from griffe._internal.enumerations import BreakageKind, ExplanationStyle, ParameterKind
1816
from griffe._internal.exceptions import AliasResolutionError
1917
from griffe._internal.git import _WORKTREE_PREFIX
@@ -30,6 +28,48 @@
3028
_VARIADIC = frozenset((ParameterKind.var_positional, ParameterKind.var_keyword))
3129

3230

31+
# Colors for terminal output.
32+
class _ANSI:
33+
FG_BLACK = "\033[30m"
34+
FG_RED = "\033[31m"
35+
FG_GREEN = "\033[32m"
36+
FG_YELLOW = "\033[33m"
37+
FG_BLUE = "\033[34m"
38+
FG_MAGENTA = "\033[35m"
39+
FG_CYAN = "\033[36m"
40+
FG_WHITE = "\033[37m"
41+
FG_RESET = "\033[39m"
42+
FG_LIGHTBLACK_EX = "\033[90m"
43+
FG_LIGHTRED_EX = "\033[91m"
44+
FG_LIGHTGREEN_EX = "\033[92m"
45+
FG_LIGHTYELLOW_EX = "\033[93m"
46+
FG_LIGHTBLUE_EX = "\033[94m"
47+
FG_LIGHTMAGENTA_EX = "\033[95m"
48+
FG_LIGHTCYAN_EX = "\033[96m"
49+
FG_LIGHTWHITE_EX = "\033[97m"
50+
BG_BLACK = "\033[40m"
51+
BG_RED = "\033[41m"
52+
BG_GREEN = "\033[42m"
53+
BG_YELLOW = "\033[43m"
54+
BG_BLUE = "\033[44m"
55+
BG_MAGENTA = "\033[45m"
56+
BG_CYAN = "\033[46m"
57+
BG_WHITE = "\033[47m"
58+
BG_RESET = "\033[49m"
59+
BG_LIGHTBLACK_EX = "\033[100m"
60+
BG_LIGHTRED_EX = "\033[101m"
61+
BG_LIGHTGREEN_EX = "\033[102m"
62+
BG_LIGHTYELLOW_EX = "\033[103m"
63+
BG_LIGHTBLUE_EX = "\033[104m"
64+
BG_LIGHTMAGENTA_EX = "\033[105m"
65+
BG_LIGHTCYAN_EX = "\033[106m"
66+
BG_LIGHTWHITE_EX = "\033[107m"
67+
BRIGHT = "\033[1m"
68+
DIM = "\033[2m"
69+
NORMAL = "\033[22m"
70+
RESET_ALL = "\033[0m"
71+
72+
3373
class Breakage:
3474
"""Breakages can explain what broke from a version to another."""
3575

@@ -146,16 +186,16 @@ def _lineno(self) -> int:
146186
return self.obj.lineno or 0
147187

148188
def _format_location(self, *, colors: bool = True) -> str:
149-
bright = Style.BRIGHT if colors else ""
150-
reset = Style.RESET_ALL if colors else ""
189+
bright = _ANSI.BRIGHT if colors else ""
190+
reset = _ANSI.RESET_ALL if colors else ""
151191
return f"{bright}{self._location}{reset}:{self._lineno}"
152192

153193
def _format_title(self, *, colors: bool = True) -> str: # noqa: ARG002
154194
return self._relative_path
155195

156196
def _format_kind(self, *, colors: bool = True) -> str:
157-
yellow = Fore.YELLOW if colors else ""
158-
reset = Fore.RESET if colors else ""
197+
yellow = _ANSI.FG_YELLOW if colors else ""
198+
reset = _ANSI.FG_RESET if colors else ""
159199
return f"{yellow}{self.kind.value}{reset}"
160200

161201
def _format_old_value(self, *, colors: bool = True) -> str: # noqa: ARG002
@@ -251,8 +291,8 @@ def _relative_path(self) -> str:
251291
return f"{super()._relative_path}({self.old_value.name})"
252292

253293
def _format_title(self, *, colors: bool = True) -> str:
254-
blue = Fore.BLUE if colors else ""
255-
reset = Fore.RESET if colors else ""
294+
blue = _ANSI.FG_BLUE if colors else ""
295+
reset = _ANSI.FG_RESET if colors else ""
256296
return f"{super()._relative_path}({blue}{self.old_value.name}{reset})"
257297

258298
def _format_old_value(self, *, colors: bool = True) -> str: # noqa: ARG002
@@ -272,8 +312,8 @@ def _relative_path(self) -> str:
272312
return f"{super()._relative_path}({self.old_value.name})"
273313

274314
def _format_title(self, *, colors: bool = True) -> str:
275-
blue = Fore.BLUE if colors else ""
276-
reset = Fore.RESET if colors else ""
315+
blue = _ANSI.FG_BLUE if colors else ""
316+
reset = _ANSI.FG_RESET if colors else ""
277317
return f"{super()._relative_path}({blue}{self.old_value.name}{reset})"
278318

279319
def _format_old_value(self, *, colors: bool = True) -> str: # noqa: ARG002
@@ -293,8 +333,8 @@ def _relative_path(self) -> str:
293333
return f"{super()._relative_path}({self.old_value.name})"
294334

295335
def _format_title(self, *, colors: bool = True) -> str:
296-
blue = Fore.BLUE if colors else ""
297-
reset = Fore.RESET if colors else ""
336+
blue = _ANSI.FG_BLUE if colors else ""
337+
reset = _ANSI.FG_RESET if colors else ""
298338
return f"{super()._relative_path}({blue}{self.old_value.name}{reset})"
299339

300340
def _format_old_value(self, *, colors: bool = True) -> str: # noqa: ARG002
@@ -314,8 +354,8 @@ def _relative_path(self) -> str:
314354
return f"{super()._relative_path}({self.old_value.name})"
315355

316356
def _format_title(self, *, colors: bool = True) -> str:
317-
blue = Fore.BLUE if colors else ""
318-
reset = Fore.RESET if colors else ""
357+
blue = _ANSI.FG_BLUE if colors else ""
358+
reset = _ANSI.FG_RESET if colors else ""
319359
return f"{super()._relative_path}({blue}{self.old_value.name}{reset})"
320360

321361
def _format_old_value(self, *, colors: bool = True) -> str: # noqa: ARG002
@@ -335,8 +375,8 @@ def _relative_path(self) -> str:
335375
return f"{super()._relative_path}({self.old_value.name})"
336376

337377
def _format_title(self, *, colors: bool = True) -> str:
338-
blue = Fore.BLUE if colors else ""
339-
reset = Fore.RESET if colors else ""
378+
blue = _ANSI.FG_BLUE if colors else ""
379+
reset = _ANSI.FG_RESET if colors else ""
340380
return f"{super()._relative_path}({blue}{self.old_value.name}{reset})"
341381

342382
def _format_old_value(self, *, colors: bool = True) -> str: # noqa: ARG002
@@ -356,8 +396,8 @@ def _relative_path(self) -> str:
356396
return f"{super()._relative_path}({self.new_value.name})"
357397

358398
def _format_title(self, *, colors: bool = True) -> str:
359-
blue = Fore.BLUE if colors else ""
360-
reset = Fore.RESET if colors else ""
399+
blue = _ANSI.FG_BLUE if colors else ""
400+
reset = _ANSI.FG_RESET if colors else ""
361401
return f"{super()._relative_path}({blue}{self.new_value.name}{reset})"
362402

363403
def _format_old_value(self, *, colors: bool = True) -> str: # noqa: ARG002

0 commit comments

Comments
 (0)