Skip to content

Commit 097541c

Browse files
author
Tailung42
committed
feat(console): add color to standard output and standard error
1 parent b475c54 commit 097541c

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

src/commitlint/console.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,25 @@
44
NOTE: If any future changes are made to the output implementation,
55
they will be done from here.
66
7-
TODO: Add color on success and error (#5).
7+
88
"""
99

1010
import sys
1111

1212
from .config import config
1313

14+
GREEN = "\033[92m"
15+
RED = "\033[91m"
16+
RESET = "\033[0m"
17+
18+
19+
def green(text: str) -> str:
20+
return f"{GREEN}{text}{RESET}"
21+
22+
23+
def red(text: str) -> str:
24+
return f"{RED}{text}{RESET}"
25+
1426

1527
def success(message: str) -> None:
1628
"""
@@ -22,7 +34,7 @@ def success(message: str) -> None:
2234
if config.quiet:
2335
return
2436

25-
sys.stdout.write(f"{message}\n")
37+
sys.stdout.write(f"{green(message)}\n")
2638

2739

2840
def error(message: str) -> None:
@@ -35,7 +47,7 @@ def error(message: str) -> None:
3547
if config.quiet:
3648
return
3749

38-
sys.stderr.write(f"{message}\n")
50+
sys.stderr.write(f"{red(message)}\n")
3951

4052

4153
def verbose(message: str) -> None:

0 commit comments

Comments
 (0)