Skip to content

Commit fed7a09

Browse files
authored
Merge pull request #6 from git-quick-stats/4-add-colorless-menu
Add colorless menu
2 parents 0bf3845 + f4718e0 commit fed7a09

File tree

4 files changed

+69
-3
lines changed

4 files changed

+69
-3
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,11 +309,13 @@ export _GIT_BRANCH="master"
309309
310310
### Color Themes
311311
312-
You can change to the legacy color scheme by toggling the variable
313-
`_MENU_THEME` between `default` and `legacy`
312+
You can change to the legacy color scheme by toggling the variable `_MENU_THEME` between `default` and `legacy`.
313+
You can completely disable the color theme by setting the `_MENU_THEME` variable to `none`.
314314
315315
```bash
316316
export _MENU_THEME="legacy"
317+
# or
318+
export _MENU_THEME="none"
317319
```
318320
319321
## Contributing

git_py_stats/config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ def get_config() -> Dict[str, Union[str, int]]:
120120
menu_theme: Optional[str] = os.environ.get("_MENU_THEME")
121121
if menu_theme == "legacy":
122122
config["menu_theme"] = "legacy"
123+
elif menu_theme == "none":
124+
config["menu_theme"] = "none"
123125
else:
124126
config["menu_theme"] = ""
125127

git_py_stats/menu.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def interactive_menu(config: Dict[str, Union[str, int]]) -> str:
2424
WHITE = "\033[37m"
2525
CYAN = "\033[36m"
2626

27-
# Handle default and legacy menu
27+
# Handle default, legacy, and colorless menu
2828
theme = config.get("menu_theme", "")
2929

3030
if theme == "legacy":
@@ -33,6 +33,13 @@ def interactive_menu(config: Dict[str, Union[str, int]]) -> str:
3333
NUMS = f"{BOLD}{YELLOW}"
3434
HELP_TXT = f"{NORMAL}{YELLOW}"
3535
EXIT_TXT = f"{BOLD}{RED}"
36+
elif theme == "none":
37+
TITLES = BOLD
38+
TEXT = ""
39+
NUMS = BOLD
40+
HELP_TXT = ""
41+
EXIT_TXT = BOLD
42+
NORMAL = ""
3643
else:
3744
TITLES = f"{BOLD}{CYAN}"
3845
TEXT = f"{NORMAL}{WHITE}"

git_py_stats/tests/test_menu.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ def setUp(self):
2525
# Mock configurations for testing
2626
self.config_default = {} # Default theme
2727
self.config_legacy = {"menu_theme": "legacy"} # Legacy theme
28+
self.config_none = {"menu_theme": "none"} # Alternate colorless theme alias
2829

30+
# Test cases for default theme
2931
@patch("builtins.input", return_value="1")
3032
@patch("sys.stdout", new_callable=StringIO)
3133
def test_default_theme_option_1(self, mock_stdout, mock_input):
@@ -76,6 +78,57 @@ def test_default_theme_invalid_input(self, mock_stdout, mock_input):
7678
output = strip_ansi_codes(mock_stdout.getvalue())
7779
self.assertIn("Generate:", output)
7880

81+
@patch("builtins.input", return_value="3")
82+
@patch("sys.stdout", new_callable=StringIO)
83+
def test_none_theme_option_3(self, mock_stdout, mock_input):
84+
"""
85+
Test the interactive_menu with 'none' theme and user selects option '3'.
86+
"""
87+
choice = interactive_menu(self.config_none)
88+
self.assertEqual(choice, "3")
89+
output = mock_stdout.getvalue()
90+
self.assertNotIn("\033[31m", output)
91+
self.assertNotIn("\033[33m", output)
92+
self.assertNotIn("\033[36m", output)
93+
self.assertIn("\033[1m", output)
94+
95+
@patch("builtins.input", return_value="1")
96+
@patch("sys.stdout", new_callable=StringIO)
97+
def test_none_theme_option_1(self, mock_stdout, mock_input):
98+
"""
99+
Test the interactive_menu with 'none' theme and user selects option '1'.
100+
"""
101+
choice = interactive_menu(self.config_none)
102+
self.assertEqual(choice, "1")
103+
output = mock_stdout.getvalue()
104+
self.assertNotIn("\033[31m", output)
105+
self.assertNotIn("\033[33m", output)
106+
self.assertNotIn("\033[36m", output)
107+
self.assertIn("\033[1m", output)
108+
109+
@patch("builtins.input", return_value="")
110+
@patch("sys.stdout", new_callable=StringIO)
111+
def test_none_theme_exit(self, mock_stdout, mock_input):
112+
"""
113+
Test the interactive_menu with none theme and user presses Enter to exit.
114+
"""
115+
choice = interactive_menu(self.config_none)
116+
self.assertEqual(choice, "")
117+
output = strip_ansi_codes(mock_stdout.getvalue())
118+
self.assertIn("press Enter to exit", output)
119+
120+
@patch("builtins.input", return_value="invalid")
121+
@patch("sys.stdout", new_callable=StringIO)
122+
def test_none_theme_invalid_input(self, mock_stdout, mock_input):
123+
"""
124+
Test the interactive_menu with none theme and user enters an invalid option.
125+
"""
126+
choice = interactive_menu(self.config_none)
127+
self.assertEqual(choice, "invalid")
128+
output = strip_ansi_codes(mock_stdout.getvalue())
129+
self.assertIn("Generate:", output)
130+
131+
# Test cases for legacy theme
79132
@patch("builtins.input", return_value="1")
80133
@patch("sys.stdout", new_callable=StringIO)
81134
def test_legacy_theme_option_1(self, mock_stdout, mock_input):
@@ -121,6 +174,7 @@ def test_legacy_theme_invalid_input(self, mock_stdout, mock_input):
121174
output = strip_ansi_codes(mock_stdout.getvalue())
122175
self.assertIn("Generate:", output)
123176

177+
# Test cases for handling multiple inputs and edge cases
124178
@patch("builtins.input", side_effect=["1", ""])
125179
@patch("sys.stdout", new_callable=StringIO)
126180
def test_multiple_inputs(self, mock_stdout, mock_input):
@@ -145,6 +199,7 @@ def test_input_with_whitespace(self, mock_stdout, mock_input):
145199
output = strip_ansi_codes(mock_stdout.getvalue())
146200
self.assertIn("5) My daily status", output)
147201

202+
# Test cases for handling exit commands
148203
@patch("builtins.input", return_value="QUIT")
149204
@patch("sys.stdout", new_callable=StringIO)
150205
def test_input_quit(self, mock_stdout, mock_input):

0 commit comments

Comments
 (0)