Skip to content

Commit 17d4689

Browse files
committed
add(colors): colored text in runtime
1 parent 7aebaa2 commit 17d4689

File tree

5 files changed

+45
-9
lines changed

5 files changed

+45
-9
lines changed
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1+
from commit_helper.utils.colors import INPUT_COLOR
2+
from commit_helper.utils.colors import RESET
3+
4+
15
def just_message():
2-
msg = str(input("commit message: "))
6+
msg = str(input(INPUT_COLOR + "commit message: " + RESET))
37
composed = "%s\n" % msg.capitalize()
48
return composed

commit_helper/utils/colors.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from colored import fg
2+
from colored import attr
3+
4+
INPUT_COLOR = fg(6)
5+
NOTIFY_COLOR = fg(14)
6+
DEBUG_COLOR = fg(239)
7+
RESET = attr(0)

commit_helper/utils/file_handler.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
from .utils import gen_co_author
66
from .utils import dump_convention
77
from .utils import validate_commiter_file
8+
from .colors import RESET
9+
from .colors import NOTIFY_COLOR
810
from .text_utils import debug
11+
from .text_utils import notify
912
from .text_utils import get_text
1013
from .text_utils import get_context
1114
# conventions imports
@@ -24,11 +27,11 @@ def handle_file_based_commit(file_path, debug_mode, args):
2427
convention = dump_convention(config)
2528

2629
if convention == 'none':
27-
print('You are not using a convention')
30+
notify('You are not using a convention')
2831
commit_msg = just_message()
2932

3033
elif convention == 'custom':
31-
print('You are using your custom convention')
34+
notify('You are using your custom convention')
3235
validate_commiter_file(config)
3336
tag, msg = get_text()
3437
commit_msg = custom_convention(tag, msg, config, debug_mode)
@@ -45,7 +48,7 @@ def handle_file_based_commit(file_path, debug_mode, args):
4548

4649

4750
def handle_conventioned_commit(convention):
48-
print('You are using the %s convention' % convention)
51+
notify('You are using the %s convention' % convention)
4952
tag, msg = get_text()
5053

5154
if convention == 'angular' or convention == 'karma':

commit_helper/utils/text_utils.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
1+
from commit_helper.utils.colors import RESET
2+
from commit_helper.utils.colors import DEBUG_COLOR
3+
from commit_helper.utils.colors import INPUT_COLOR
4+
from commit_helper.utils.colors import NOTIFY_COLOR
5+
6+
17
def get_text():
2-
tag = str(input("type the tag: "))
3-
msg = str(input("type the commit message: ")).lower()
8+
tag = str(input(INPUT_COLOR + 'type the tag: ' + RESET))
9+
msg = str(input(INPUT_COLOR + 'type the commit message: ' + RESET)).lower()
410
return tag, msg
511

612

713
def get_context():
8-
context = str(input('type the context: ') or '').lower()
14+
context = str(input(INPUT_COLOR + 'type the context: ' + RESET) or '')
15+
context.lower()
916
return context
1017

1118

@@ -15,6 +22,11 @@ def sanitize_as_empty_string(string):
1522
return string
1623

1724

25+
def notify(message):
26+
print(NOTIFY_COLOR + str(message) + RESET)
27+
28+
1829
def debug(message, value, show=False):
1930
if show:
20-
print("DEBUG-> %s: %s" % (message, value))
31+
mid = 'DEBUG: ' + str(message) + ' ~> ' + str(value)
32+
print(DEBUG_COLOR + mid + RESET)

test/test_utils.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import yaml
22
import commit_helper.utils.utils as utils
33
import commit_helper.utils.text_utils as text_utils
4+
from commit_helper.utils.colors import RESET
5+
from commit_helper.utils.colors import DEBUG_COLOR
6+
from commit_helper.utils.colors import NOTIFY_COLOR
47
# from commit_helper.utils.utils import validate_commiter_file
58
# import commit_helper.utils.file_handler as file_utils
69
# import commit_helper.utils.flag_commit_handler as flag_utils
@@ -61,7 +64,7 @@ def test_gen_co_author():
6164
def test_debug(capsys):
6265
text_utils.debug('msg', 666, show=True)
6366
captured = capsys.readouterr()
64-
if not captured.out == "DEBUG-> msg: 666\n":
67+
if not captured.out == DEBUG_COLOR + "DEBUG: msg ~> 666" + RESET + "\n":
6568
raise AssertionError()
6669

6770

@@ -81,3 +84,10 @@ def test_dump_convention():
8184

8285
if not response2 == 'asdf':
8386
raise AssertionError()
87+
88+
89+
def test_notify(capsys):
90+
text_utils.notify('msg')
91+
captured = capsys.readouterr()
92+
if not captured.out == NOTIFY_COLOR + "msg" + RESET + "\n":
93+
raise AssertionError()

0 commit comments

Comments
 (0)