8000 refactor(deps[colorama]): replace colorama with stdlib ANSI constants · tmux-python/tmuxp@3d7b951 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3d7b951

Browse files
committed
refactor(deps[colorama]): replace colorama with stdlib ANSI constants
why: colorama wraps fixed ANSI escape string constants the stdlib can provide directly. Removing it shrinks the dependency tree. what: - Replace all colorama Fore/Style references in log.py with raw ANSI escapes via _ansi_colors from tmuxp._internal.colors - Remove colorama and types-colorama from pyproject.toml
1 parent aaaffe5 commit 3d7b951

File tree

3 files changed

+35
-50
lines changed

3 files changed

+35
-50
lines changed

pyproject.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ include = [
4040
]
4141
dependencies = [
4242
"libtmux~=0.55.0",
43-
"colorama>=0.3.9",
4443
"PyYAML>=6.0"
4544
]
4645

@@ -82,7 +81,6 @@ dev = [
8281
# Lint
8382
"ruff",
8483
"mypy",
85-
"types-colorama",
8684
"types-docutils",
8785
"types-Pygments",
8886
"types-PyYAML",
@@ -118,7 +116,6 @@ coverage =[
118116
lint = [
119117
"ruff",
120118
"mypy",
121-
"types-colorama",
122119
"types-docutils",
123120
"types-Pygments",
124121
"types-PyYAML",

src/tmuxp/log.py

Lines changed: 35 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,20 @@
88
import time
99
import typing as t
1010

11-
from colorama import Fore, Style
11+
from tmuxp._internal.colors import _ansi_colors, _ansi_reset_all
1212

1313
logger = logging.getLogger(__name__)
1414

15+
_ANSI_RESET = _ansi_reset_all # "\033[0m"
16+
_ANSI_BRIGHT = "\033[1m"
17+
_ANSI_FG_RESET = "\033[39m"
18+
1519
LEVEL_COLORS = {
16-
"DEBUG": Fore.BLUE, # Blue
17-
"INFO": Fore.GREEN, # Green
18-
"WARNING": Fore.YELLOW,
19-
"ERROR": Fore.RED,
20-
"CRITICAL": Fore.RED,
20+
"DEBUG": f"\033[{_ansi_colors['blue']}m",
21+
"INFO": f"\033[{_ansi_colors['green']}m",
22+
"WARNING": f"\033[{_ansi_colors['yellow']}m",
23+
"ERROR": f"\033[{_ansi_colors['red']}m",
24+
"CRITICAL": f"\033[{_ansi_colors['red']}m",
2125
}
2226

2327

@@ -103,27 +107,27 @@ def template(
103107
str
104108
Template for logger message.
105109
"""
106-
reset = Style.RESET_ALL
110+
reset = _ANSI_RESET
107111
levelname = set_style(
108112
"(%(levelname)s)",
109113
stylized,
110-
style_before=(LEVEL_COLORS.get(record.levelname, "") + Style.BRIGHT),
111-
style_after=Style.RESET_ALL,
114+
style_before=(LEVEL_COLORS.get(record.levelname, "") + _ANSI_BRIGHT),
115+
style_after=_ANSI_RESET,
112116
suffix=" ",
113117
)
114118
asctime = set_style(
115119
"%(asctime)s",
116120
stylized,
117-
style_before=(Fore.BLACK + Style.DIM + Style.BRIGHT),
118-
style_after=(Fore.RESET + Style.RESET_ALL),
121+
style_before=(f"\033[{_ansi_colors['black']}m" + _ANSI_BRIGHT),
122+
style_after=(_ANSI_FG_RESET + _ANSI_RESET),
119123
prefix="[",
120124
suffix="]",
121125
)
122126
name = set_style(
123127
"%(name)s",
124128
stylized,
125-
style_before=(Fore.WHITE + Style.DIM + Style.BRIGHT),
126-
style_after=(Fore.RESET + Style.RESET_ALL),
129+
style_before=(f"\033[{_ansi_colors['white']}m" + _ANSI_BRIGHT),
130+
style_after=(_ANSI_FG_RESET + _ANSI_RESET),
127131
prefix=" ",
128132
suffix=" ",
129133
)
@@ -173,42 +177,41 @@ def debug_log_template(
173177
str
174178
Log template.
175179
"""
176-
reset = Style.RESET_ALL
180+
reset = _ANSI_RESET
177181
levelname = (
178182
LEVEL_COLORS.get(record.levelname, "")
179-
+ Style.BRIGHT
183+
+ _ANSI_BRIGHT
180184
+ "(%(levelname)1.1s)"
181-
+ Style.RESET_ALL
185+
+ _ANSI_RESET
182186
+ " "
183187
)
184188
asctime = (
185189
"["
186-
+ Fore.BLACK
187-
+ Style.DIM
188-
+ Style.BRIGHT
190+
+ f"\033[{_ansi_colors['black']}m"
191+
+ _ANSI_BRIGHT
189192
+ "%(asctime)s"
190-
+ Fore.RESET
191-
+ Style.RESET_ALL
193+
+ _ANSI_FG_RESET
194+
+ _ANSI_RESET
192195
+ "]"
193196
)
194197
name = (
195198
" "
196-
+ Fore.WHITE
197-
+ Style.DIM
198-
+ Style.BRIGHT
199+
+ f"\033[{_ansi_colors['white']}m"
200+
+ _ANSI_BRIGHT
199201
+ "%(name)s"
200-
+ Fore.RESET
201-
+ Style.RESET_ALL
202+
+ _ANSI_FG_RESET
203+
+ _ANSI_RESET
202204
+ " "
203205
)
204-
module_funcName = Fore.GREEN + Style.BRIGHT + "%(module)s.%(funcName)s()"
206+
module_funcName = (
207+
f"\033[{_ansi_colors['green']}m" + _ANSI_BRIGHT + "%(module)s.%(funcName)s()"
208+
)
205209
lineno = (
206-
Fore.BLACK
207-
+ Style.DIM
208-
+ Style.BRIGHT
210+
f"\033[{_ansi_colors['black']}m"
211+
+ _ANSI_BRIGHT
209212
+ ":"
210-
+ Style.RESET_ALL
211-
+ Fore.CYAN
213+
+ _ANSI_RESET
214+
+ f"\033[{_ansi_colors['cyan']}m"
212215
+ "%(lineno)d"
213216
)
214217

uv.lock

Lines changed: 0 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
0