Skip to content
This repository was archived by the owner on Sep 5, 2023. It is now read-only.

Commit b2693b0

Browse files
committed
refactor: Move ansi class into new style module
The Ansi class has moved from its own module into the remit of the style module.
1 parent 1744e84 commit b2693b0

File tree

4 files changed

+92
-94
lines changed

4 files changed

+92
-94
lines changed

gitcommit/ansi.py

Lines changed: 0 additions & 88 deletions
This file was deleted.

gitcommit/gitcommit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
from prompt_toolkit.history import FileHistory
3030
from prompt_toolkit.application.current import get_app
3131
from prompt_toolkit.styles import Style
32-
from gitcommit.ansi import ANSI as Ansi
32+
from gitcommit.style import Ansi
3333
from gitcommit.validators import (
3434
DescriptionValidator,
3535
TypeValidator,

gitcommit/style.py

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,93 @@
33
style = Style.from_dict(
44
{"green": "#a0d762 bold", "red": "#e67061 bold", "command": "#f78ae0 bold"}
55
)
6+
7+
8+
class Ansi:
9+
"""
10+
This class contains the ANSI escape codes for printing to the console as
11+
well as commonly used combinations of these codes.
12+
"""
13+
14+
reset = "\033[0m"
15+
bold = "\033[1m"
16+
faint = "\033[2m"
17+
italic = "\033[3m"
18+
underline = "\033[4m"
19+
blink = "\033[5m"
20+
inverse = "\033[7m"
21+
22+
class fg:
23+
black = "\033[30m"
24+
red = "\033[31m"
25+
green = "\033[32m"
26+
yellow = "\033[33m"
27+
blue = "\033[34m"
28+
magenta = "\033[35m"
29+
cyan = "\033[36m"
30+
white = "\033[37m"
31+
32+
grey = "\033[90m"
33+
bright_red = "\033[91m"
34+
bright_green = "\033[92m"
35+
bright_yellow = "\033[93m"
36+
bright_blue = "\033[94m"
37+
bright_magenta = "\033[95m"
38+
bright_cyan = "\033[96m"
39+
bright_white = "\033[97m"
40+
41+
class bg:
42+
black = "\033[40m"
43+
red = "\033[41m"
44+
green = "\033[42m"
45+
yellow = "\033[43m"
46+
blue = "\033[44m"
47+
magenta = "\033[45m"
48+
cyan = "\033[46m"
49+
white = "\033[47m"
50+
51+
grey = "\033[100m"
52+
bright_red = "\033[101m"
53+
bright_green = "\033[102m"
54+
bright_yellow = "\033[103m"
55+
bright_blue = "\033[104m"
56+
bright_magenta = "\033[105m"
57+
bright_cyan = "\033[106m"
58+
bright_white = "\033[107m"
59+
60+
@classmethod
61+
def colour(cls, *args):
62+
"""Combines all args into string. Should pass colour modifiers in first followed by the string. Does not need reset sequence at the end."""
63+
return "".join(args) + cls.reset
64+
65+
@classmethod
66+
def b_green(cls, content):
67+
return cls.fg.bright_green + cls.bold + str(content) + cls.reset
68+
69+
@classmethod
70+
def b_red(cls, content):
71+
return cls.fg.bright_red + cls.bold + str(content) + cls.reset
72+
73+
@classmethod
74+
def b_yellow(cls, content):
75+
return cls.fg.bright_yellow + cls.bold + str(content) + cls.reset
76+
77+
@classmethod
78+
def b_blue(cls, content):
79+
return cls.fg.bright_blue + cls.bold + str(content) + cls.reset
80+
81+
@classmethod
82+
def print_ok(cls, content, end="\n"):
83+
print(cls.b_green(content), end=end)
84+
85+
@classmethod
86+
def print_error(cls, content, end="\n"):
87+
print(cls.b_red(content), end=end)
88+
89+
@classmethod
90+
def print_warning(cls, content, end="\n"):
91+
print(cls.b_yellow(content), end=end)
92+
93+
@classmethod
94+
def print_info(cls, content, end="\n"):
95+
print(cls.b_blue(content), end=end)

gitcommit/updater.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@
44
from prompt_toolkit import print_formatted_text
55
from prompt_toolkit.formatted_text import FormattedText
66
from prompt_toolkit.styles import Style
7-
from gitcommit.ansi import ANSI as Ansi
87
import pyperclip # pylint: disable=import-error
98
from packaging import version
10-
from gitcommit.style import style
9+
from gitcommit.style import style, Ansi
1110

1211

1312
def get_github_tags():
@@ -51,9 +50,6 @@ def check_for_update():
5150
upgrade_command = "pip install --upgrade conventional-commit"
5251
pyperclip.copy(upgrade_command)
5352

54-
style = Style.from_dict(
55-
{"green": "#a0d762 bold", "red": "#e67061 bold", "command": "#f78ae0 bold"}
56-
)
5753
text = FormattedText(
5854
[
5955
("", "Version "),

0 commit comments

Comments
 (0)