Skip to content

Commit 206b949

Browse files
committed
refactor: Extract gruvbox colors
1 parent d328941 commit 206b949

File tree

5 files changed

+81
-221
lines changed

5 files changed

+81
-221
lines changed

tests/config/test_themes.py

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -22,51 +22,11 @@
2222
expected_complete_themes = {
2323
"zt_dark",
2424
"gruvbox_dark",
25-
"gruvbox_light",
2625
"zt_light",
2726
"zt_blue",
2827
}
2928
aliases_16_color = [
3029
"default",
31-
"dark0 hard",
32-
"dark0",
33-
"dark0 soft",
34-
"dark1",
35-
"dark2",
36-
"dark3",
37-
"dark4",
38-
"dark4 256",
39-
"gray 245",
40-
"gray 244",
41-
"light0 hard",
42-
"light0",
43-
"light0 soft",
44-
"light1",
45-
"light2",
46-
"light3",
47-
"light4",
48-
"light4 256",
49-
"bright red",
50-
"bright green",
51-
"bright yellow",
52-
"bright blue",
53-
"bright purple",
54-
"bright aqua",
55-
"bright orange",
56-
"neutral red",
57-
"neutral green",
58-
"neutral yellow",
59-
"neutral blue",
60-
"neutral purple",
61-
"neutral aqua",
62-
"neutral orange",
63-
"faded red",
64-
"faded green",
65-
"faded yellow",
66-
"faded blue",
67-
"faded purple",
68-
"faded aqua",
69-
"faded orange",
7030
"black",
7131
"dark red",
7232
"dark green",

zulipterminal/config/themes.py

Lines changed: 59 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from pygments.token import STANDARD_TYPES
44

55
from zulipterminal.config.color import term16
6-
from zulipterminal.themes import gruvbox_dark, gruvbox_light, zt_blue, zt_dark, zt_light
6+
from zulipterminal.themes import gruvbox_dark, zt_blue, zt_dark, zt_light
77

88

99
StyleSpec = Union[
@@ -19,75 +19,74 @@
1919
# monochrome (1-bit) mode - independently of the specified theme
2020
REQUIRED_STYLES = {
2121
# style name : monochrome style
22-
None: '',
23-
'selected': 'standout',
24-
'msg_selected': 'standout',
25-
'header': 'bold',
26-
'general_narrow': 'standout',
27-
'general_bar': '',
28-
'name': '',
29-
'unread': 'strikethrough',
30-
'user_active': 'bold',
31-
'user_idle': '',
32-
'user_offline': '',
33-
'user_inactive': '',
34-
'title': 'bold',
35-
'column_title': 'bold',
36-
'time': '',
37-
'bar': 'standout',
38-
'msg_emoji': 'bold',
39-
'reaction': 'bold',
40-
'reaction_mine': 'standout',
41-
'msg_heading': 'bold',
42-
'msg_math': 'standout',
43-
'msg_mention': 'bold',
44-
'msg_link': '',
45-
'msg_link_index': 'bold',
46-
'msg_quote': 'underline',
47-
'msg_code': 'bold',
48-
'msg_bold': 'bold',
49-
'msg_time': 'bold',
50-
'footer': 'standout',
51-
'footer_contrast': 'standout',
52-
'starred': 'bold',
53-
'unread_count': 'bold',
54-
'starred_count': '',
55-
'table_head': 'bold',
56-
'filter_results': 'bold',
57-
'edit_topic': 'standout',
58-
'edit_tag': 'standout',
59-
'edit_author': 'bold',
60-
'edit_time': 'bold',
61-
'current_user': '',
62-
'muted': 'bold',
63-
'popup_border': 'bold',
64-
'popup_category': 'bold',
65-
'popup_contrast': 'standout',
66-
'popup_important': 'bold',
67-
'widget_disabled': 'strikethrough',
68-
'area:help': 'standout',
69-
'area:msg': 'standout',
70-
'area:stream': 'standout',
71-
'area:error': 'standout',
72-
'area:user': 'standout',
73-
'search_error': 'standout',
74-
'task:success': 'standout',
75-
'task:error': 'standout',
76-
'task:warning': 'standout',
22+
None : '',
23+
'selected' : 'standout',
24+
'msg_selected' : 'standout',
25+
'header' : 'bold',
26+
'general_narrow' : 'standout',
27+
'general_bar' : '',
28+
'name' : '',
29+
'unread' : 'strikethrough',
30+
'user_active' : 'bold',
31+
'user_idle' : '',
32+
'user_offline' : '',
33+
'user_inactive' : '',
34+
'title' : 'bold',
35+
'column_title' : 'bold',
36+
'time' : '',
37+
'bar' : 'standout',
38+
'msg_emoji' : 'bold',
39+
'reaction' : 'bold',
40+
'reaction_mine' : 'standout',
41+
'msg_heading' : 'bold',
42+
'msg_math' : 'standout',
43+
'msg_mention' : 'bold',
44+
'msg_link' : '',
45+
'msg_link_index' : 'bold',
46+
'msg_quote' : 'underline',
47+
'msg_code' : 'bold',
48+
'msg_bold' : 'bold',
49+
'msg_time' : 'bold',
50+
'footer' : 'standout',
51+
'footer_contrast' : 'standout',
52+
'starred' : 'bold',
53+
'unread_count' : 'bold',
54+
'starred_count' : '',
55+
'table_head' : 'bold',
56+
'filter_results' : 'bold',
57+
'edit_topic' : 'standout',
58+
'edit_tag' : 'standout',
59+
'edit_author' : 'bold',
60+
'edit_time' : 'bold',
61+
'current_user' : '',
62+
'muted' : 'bold',
63+
'popup_border' : 'bold',
64+
'popup_category' : 'bold',
65+
'popup_contrast' : 'standout',
66+
'popup_important' : 'bold',
67+
'widget_disabled' : 'strikethrough',
68+
'area:help' : 'standout',
69+
'area:msg' : 'standout',
70+
'area:stream' : 'standout',
71+
'area:error' : 'standout',
72+
'area:user' : 'standout',
73+
'search_error' : 'standout',
74+
'task:success' : 'standout',
75+
'task:error' : 'standout',
76+
'task:warning' : 'standout',
7777
}
7878

7979
REQUIRED_META = {
8080
'pygments': {
81-
'styles': None,
82-
'background': None,
83-
'overrides': None,
81+
'styles' : None,
82+
'background' : None,
83+
'overrides' : None,
8484
}
8585
}
8686
# fmt: on
8787

8888
THEMES: Dict[str, Any] = {
8989
"gruvbox_dark": gruvbox_dark,
90-
"gruvbox_light": gruvbox_light,
9190
"zt_dark": zt_dark,
9291
"zt_light": zt_light,
9392
"zt_blue": zt_blue,
@@ -96,7 +95,6 @@
9695
THEME_ALIASES = {
9796
"default": "zt_dark",
9897
"gruvbox_dark": "gruvbox_dark",
99-
"gruvbox_light": "gruvbox_light",
10098
"light": "zt_light",
10199
"blue": "zt_blue",
102100
}

zulipterminal/themes/THEME_CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ If BOLD is something that is not needed, just use:
2323
from zulipterminal.config.color import DefaultColor as Color
2424
```
2525

26-
Likewise, to use a color scheme from any other theme like Gruvbox, use:
26+
Likewise, to use a color scheme from any other theme like Gruvbox (for which the colors are defined in colors_gruvbox.py), use:
2727

2828
```python
29-
from zulipterminal.themes.gruvbox_dark import Color
29+
from zulipterminal.themes.colors_gruvbox import DefaultBoldColor
3030
```
3131

3232
---

zulipterminal/themes/colors_gruvbox.py

Lines changed: 18 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,14 @@
33
-----
44
Contains color definitions or functions common across gruvbox themes.
55
For further details on themefiles look at the theme contribution guide.
6+
-------
7+
This theme uses the official gruvbox color scheme.
8+
For color reference see:
9+
https://github.com/morhetz/gruvbox/blob/master/colors/gruvbox.vim
610
"""
711
from enum import Enum
8-
from typing import Any
912

10-
from pygments.style import Style
11-
from pygments.token import (
12-
Comment,
13-
Error,
14-
Escape,
15-
Generic,
16-
Keyword,
17-
Literal,
18-
Name,
19-
Number,
20-
Operator,
21-
Punctuation,
22-
String,
23-
Text,
24-
Whitespace,
25-
)
13+
from zulipterminal.config.color import color_properties
2614

2715

2816
# fmt: off
@@ -34,107 +22,20 @@
3422
class GruvBoxColor(Enum):
3523
# color = 16code 256code 24code
3624
DEFAULT = 'default default default'
37-
DARK0_HARD = 'dark0_hard h234 #1d2021'
38-
DARK0 = 'dark0 h235 #282828'
39-
DARK0_SOFT = 'dark0_soft h236 #32302f'
40-
DARK1 = 'dark1 h237 #3c3836'
41-
DARK2 = 'dark2 h239 #504945'
42-
DARK3 = 'dark3 h241 #665c54'
43-
DARK4 = 'dark4 h243 #7c6f64'
44-
DARK4_256 = 'dark4_256 h243 #7c6f64'
45-
GRAY_245 = 'gray_245 h245 #928374'
46-
GRAY_244 = 'gray_244 h244 #928374'
47-
LIGHT0_HARD = 'light0_hard h230 #f9f5d7'
48-
LIGHT0 = 'light0 h229 #fbf1c7'
49-
LIGHT0_SOFT = 'light0_soft h228 #f2e5bc'
50-
LIGHT1 = 'light1 h223 #ebdbb2'
51-
LIGHT2 = 'light2 h250 #d5c4a1'
52-
LIGHT3 = 'light3 h248 #bdae93'
53-
LIGHT4 = 'light4 h246 #a89984'
54-
LIGHT4_256 = 'light4_256 h246 #a89984'
55-
BRIGHT_RED = 'bright_red h167 #fb4934'
56-
BRIGHT_GREEN = 'bright_green h142 #b8bb26'
57-
BRIGHT_YELLOW = 'bright_yellow h214 #fabd2f'
58-
BRIGHT_BLUE = 'bright_blue h109 #83a598'
59-
BRIGHT_PURPLE = 'bright_purple h175 #d3869b'
60-
BRIGHT_AQUA = 'bright_aqua h108 #8ec07c'
61-
BRIGHT_ORANGE = 'bright_orange h208 #fe8019'
62-
NEUTRAL_RED = 'neutral_red h124 #cc241d'
63-
NEUTRAL_GREEN = 'neutral_green h106 #98971a'
64-
NEUTRAL_YELLOW = 'neutral_yellow h172 #d79921'
65-
NEUTRAL_BLUE = 'neutral_blue h66 #458588'
66-
NEUTRAL_PURPLE = 'neutral_purple h132 #b16286'
67-
NEUTRAL_AQUA = 'neutral_aqua h72 #689d6a'
68-
NEUTRAL_ORANGE = 'neutral_orange h166 #d65d0e'
69-
FADED_RED = 'faded_red h88 #9d0006'
70-
FADED_GREEN = 'faded_green h100 #79740e'
71-
FADED_YELLOW = 'faded_yellow h136 #b57614'
72-
FADED_BLUE = 'faded_blue h24 #076678'
73-
FADED_PURPLE = 'faded_purple h96 #8f3f71'
74-
FADED_AQUA = 'faded_aqua h66 #427b58'
75-
FADED_ORANGE = 'faded_orange h130 #af3a03'
25+
DARK0_HARD = 'black h234 #1d2021'
26+
GRAY_244 = 'dark_gray h244 #928374'
27+
LIGHT2 = 'white h250 #d5c4a1'
28+
LIGHT4 = 'light_gray h248 #bdae93'
29+
BRIGHT_BLUE = 'light_blue h109 #83a598'
30+
BRIGHT_GREEN = 'light_green h142 #b8bb26'
31+
BRIGHT_RED = 'light_red h167 #fb4934'
32+
NEUTRAL_PURPLE = 'light_magenta h132 #b16286'
33+
NEUTRAL_BLUE = 'dark_cyan h66 #458588'
34+
NEUTRAL_YELLOW = 'yellow h172 #d79921'
35+
FADED_BLUE = 'dark_blue h24 #076678'
36+
FADED_YELLOW = 'brown h136 #b57614'
37+
FADED_RED = 'dark_red h88 #9d0006'
7638
# fmt: on
7739

7840

79-
def color_properties(colors: Any, *prop: str) -> Any:
80-
"""
81-
Adds properties(Bold, Italics, etc...) to Enum Colors in theme files.
82-
Useage: color_properties(Color, 'BOLD', 'ITALICS', 'STRIKETHROUGH')
83-
84-
NOTE: color_properties(Color, BOLD, ITALICS) would result in only
85-
Color.WHITE and Color.WHITE__BOLD_ITALICS
86-
but not Color.WHITE__BOLD or Color.WHITE__ITALICS.
87-
One would also have to do color_properties(Color, BOLD)
88-
and color_properties(Color, ITALICS) for the others to work
89-
>>> This function can be later extended to achieve all combinations
90-
with one call to the function.
91-
"""
92-
prop_n = "_".join([p.upper() for p in prop])
93-
prop_v = " , ".join([p.lower() for p in prop])
94-
updated_colors: Any = Enum( # type: ignore # Ref: python/mypy#529, #535 and #5317
95-
"Color",
96-
{
97-
**{c.name: c.value for c in colors},
98-
**{c.name + f"__{prop_n}": c.value + f" , {prop_v}" for c in colors},
99-
},
100-
)
101-
return updated_colors
102-
103-
10441
DefaultBoldColor = color_properties(GruvBoxColor, "BOLD")
105-
106-
107-
# fmt: off
108-
class Term16Style(Style):
109-
"""
110-
This style is a 16 color syntax style made for use in all ZT themes.
111-
"var" bypasses pygments style format checking.
112-
"_" is used in place of space and changed later below.
113-
"""
114-
background_color = "dark4"
115-
116-
styles = {
117-
Text: "var:gray_245",
118-
Escape: "var:faded_aqua",
119-
Error: "var:faded_red",
120-
Whitespace: "var:gray_245",
121-
Keyword: "var:bright_blue,_bold",
122-
Name: "var:neutral_orange",
123-
Name.Class: "var:neutral_yellow",
124-
Name.Function: "var:bright_green",
125-
Literal: "var:bright_green",
126-
String: "var:faded_green",
127-
String.Escape: "var:gray_245",
128-
String.Doc: "var:gray_245",
129-
Number: "var:bright_red",
130-
Operator: "var:faded_aqua",
131-
Punctuation: "var:gray_245,_bold",
132-
Comment: "var:gray_245",
133-
Generic: "var:gray_245",
134-
}
135-
# fmt:on
136-
137-
138-
term16 = Term16Style()
139-
for style, code in term16.styles.items():
140-
term16.styles[style] = code[4:].replace("_", " ")

zulipterminal/themes/gruvbox_dark.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
GRUVBOX
2+
GRUVBOX DARK
33
-------
44
This theme uses the official gruvbox color scheme.
55
For color reference see:
@@ -11,6 +11,7 @@
1111
1212
For further details on themefiles look at the theme contribution guide
1313
"""
14+
1415
from pygments.styles.solarized import SolarizedDarkStyle
1516

1617
from zulipterminal.themes.colors_gruvbox import DefaultBoldColor as Color

0 commit comments

Comments
 (0)