Skip to content

Commit 2df8947

Browse files
authored
Merge pull request #22 from wenijinew/7967c32
Dynamic theme generation finished.
2 parents e8c139b + 7967c32 commit 2df8947

6 files changed

+209
-29
lines changed

dynamic.violet.yaml

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
---
2+
theme: violet
3+
general:
4+
options:
5+
status: on
6+
status-justify: left
7+
status-left-length: 100
8+
status-right-length: 100
9+
window-status-separator: ' '
10+
_fg_highlight: "#840000"
11+
_bg_highlight: ""
12+
_style: "nobold,nounderscore,noitalics"
13+
styles:
14+
message-style:
15+
fg: "#418100"
16+
bg: ""
17+
style: ""
18+
message-command-style:
19+
fg: "#418100"
20+
bg: ""
21+
style: ""
22+
pane-border-style:
23+
fg: "#418100"
24+
bg: "#231f32"
25+
style: ""
26+
pane-active-border-style:
27+
fg: "#418100"
28+
bg: "#231f32"
29+
style: ""
30+
status_left:
31+
session:
32+
enabled: "on"
33+
tmux_option: " #S "
34+
window:
35+
active:
36+
window_name: " #W "
37+
window_index: " #I"
38+
inactive:
39+
window_name: " #W "
40+
window_index: " #I"
41+
status_right:
42+
directory:
43+
enabled: on
44+
tmux_option: " #{b:pane_current_path} "
45+
icon: ""
46+
decorator: ""
47+
fg_option: "#284b4b"
48+
bg_option: "#aa9784"
49+
fg_icon: "#284b4b"
50+
bg_icon: "#755636"
51+
fg_decorator: "#755636"
52+
53+
date:
54+
enabled: on
55+
icon: ""
56+
tmux_option: " v%V %a %Y-%m-%d %H:%M:%S "
57+
cpu:
58+
enabled: on
59+
icon: ""
60+
tmux_option: " #(source cpu.sh) "
61+
memory:
62+
enabled: on
63+
icon: ""
64+
tmux_option: " #(source memory.sh) "
65+
disk:
66+
enabled: on
67+
icon: ""
68+
tmux_option: " #(source disk.sh) "

dynamic_theme.sh

+48-2
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,71 @@
22
_DIR="$(cd "$(dirname "$0")" && pwd)"
33
export PATH="${_DIR}:${PATH}"
44

5-
PLACE_HOLDERS=("LIGHT_RED" "MIDDLE_RED" "DARK_RED" "LIGHT_GREEN" "MIDDLE_GREEN" "DARK_GREEN" "LIGHT_GRAY" "MIDDLE_GRAY" "DARK_GRAY")
5+
# 3 groups of colors from light to deep
6+
# the colors are generated by palette.py
7+
PLACE_HOLDERS=(
8+
"PALE_RED"
9+
"LIGHT_RED"
10+
"MIDDLE_RED"
11+
"STRONG_RED"
12+
"DARK_RED"
13+
"DEEP_RED"
14+
"PALE_PURPLE"
15+
"LIGHT_PURPLE"
16+
"MIDDLE_PURPLE"
17+
"STRONG_PURPLE"
18+
"DARK_PURPLE"
19+
"DEEP_PURPLE"
20+
"PALE_ORANGE"
21+
"LIGHT_ORANGE"
22+
"MIDDLE_ORANGE"
23+
"STRONG_ORANGE"
24+
"DARK_ORANGE"
25+
"DEEP_ORANGE"
26+
"PALE_GREEN"
27+
"LIGHT_GREEN"
28+
"MIDDLE_GREEN"
29+
"STRONG_GREEN"
30+
"DARK_GREEN"
31+
"DEEP_GREEN"
32+
"PALE_BLUE"
33+
"LIGHT_BLUE"
34+
"MIDDLE_BLUE"
35+
"STRONG_BLUE"
36+
"DARK_BLUE"
37+
"DEEP_BLUE"
38+
"PALE_GRAY"
39+
"LIGHT_GRAY"
40+
"MIDDLE_GRAY"
41+
"STRONG_GRAY"
42+
"DARK_GRAY"
43+
"DEEP_GRAY"
44+
)
645

746
palette=$(python3 -c "import palette; palette = palette.create_theme_palette(); print(palette)")
847
tmpfile=$(mktemp)
948
colors=$(echo $palette | grep -iEo '#[[:alnum:]]{6}' > ${tmpfile})
1049

1150
dynamic_theme_name=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 8)
1251
dynamic_theme_name="dynamic"
13-
tmux set-option -gq "@dynamic_theme_name" "${dynamic_theme_name}"
1452
dynamic_theme_file_name="${dynamic_theme_name}.theme.yaml"
53+
dynamic_config_file_name="${dynamic_theme_name}.violet.yaml"
54+
tmux set-option -gq "@dynamic_theme_name" "${dynamic_theme_name}"
55+
tmux set-option -gq "@dynamic_config_file_name" "${dynamic_config_file_name}"
1556
if [ -e "${dynamic_theme_file_name}" ];then
1657
rm -f "${dynamic_theme_file_name}"
1758
fi
59+
if [ -e "${dynamic_config_file_name}" ];then
60+
rm -f "${dynamic_config_file_name}"
61+
fi
1862
cp "template.theme.yaml" "${dynamic_theme_file_name}"
63+
cp "violet.yaml" "${dynamic_config_file_name}"
1964
# trap "rm -f ${dynamic_theme_file_name}" EXIT INT TERM
2065

2166
index=1
2267
while read -r _color;do
2368
sed -i "s/${PLACE_HOLDERS[$index]}/${_color}/g" "${dynamic_theme_file_name}"
69+
sed -i "s/${PLACE_HOLDERS[$index]}/${_color}/g" "${dynamic_config_file_name}"
2470
((index++))
2571
done < "${tmpfile}"
2672

palette.py

+56-5
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,36 @@ def generate_random_dark_red(n_colors=1):
7777
return generate_random_colors(n_colors, hue, saturation, lightness)
7878

7979

80+
def generate_random_dark_orange(n_colors=1):
81+
"""Generate random dark orange colors"""
82+
hue = random.randint(20, 60) / 360
83+
saturation = random.randint(60, 100) / 100
84+
lightness = random.randint(20, 40) / 100
85+
86+
return generate_random_colors(n_colors, hue, saturation, lightness)
87+
88+
89+
def generate_random_dark_purple(n_colors=1):
90+
"""Generate random dark orange colors"""
91+
hue = random.randint(270, 330) / 360
92+
saturation = random.randint(60, 100) / 100
93+
lightness = random.randint(20, 40) / 100
94+
95+
return generate_random_colors(n_colors, hue, saturation, lightness)
96+
97+
8098
def generate_random_dark_black(n_colors=1):
8199
"""Generate random dark black/gray/blue colors"""
82-
hue = random.randint(230, 250) / 360
100+
hue = random.randint(0, 360) / 360
101+
saturation = 1
102+
lightness = random.randint(0, 10) / 100
103+
104+
return generate_random_colors(n_colors, hue, saturation, lightness)
105+
106+
107+
def generate_random_dark_blue(n_colors=1):
108+
"""Generate random dark black/gray/blue colors"""
109+
hue = random.randint(180, 240) / 360
83110
saturation = random.randint(75, 100) / 100
84111
lightness = random.randint(0, 15) / 100
85112

@@ -88,7 +115,7 @@ def generate_random_dark_black(n_colors=1):
88115

89116
def generate_random_dark_green(n_colors=1):
90117
"""Generate random dark green colors"""
91-
hue = random.randint(50, 190) / 360
118+
hue = random.randint(90, 150) / 360
92119
saturation = random.randint(60, 100) / 100
93120
lightness = random.randint(10, 20) / 100
94121

@@ -98,18 +125,42 @@ def generate_random_dark_green(n_colors=1):
98125
def generate_palette(n_palette=1):
99126
""" "Convert"""
100127

128+
n_colors = 24
129+
groups = 6
130+
counts = n_colors / groups
101131
all_palettes = []
102132
for _i in range(n_palette):
103133
palette = []
104134

105135
dark_red = generate_random_dark_red()
136+
dark_purple = generate_random_dark_purple()
137+
dark_orange = generate_random_dark_orange()
106138
dark_green = generate_random_dark_green()
139+
dark_blue = generate_random_dark_blue()
107140
dark_black = generate_random_dark_black()
108141
for dark_color in [
109-
c for dark in (dark_red, dark_green, dark_black) for c in dark
142+
c
143+
for dark in (
144+
dark_red,
145+
dark_purple,
146+
dark_orange,
147+
dark_green,
148+
dark_blue,
149+
dark_black,
150+
)
151+
for c in dark
110152
]:
111-
_colors = sns.color_palette(f"light:{dark_color}", n_colors=3)
112-
palette.extend(_colors.as_hex())
153+
_colors = sns.color_palette(
154+
f"light:{dark_color}", n_colors=n_colors
155+
)
156+
_colors_hex = _colors.as_hex()
157+
_picked_colors_index = [
158+
c + (counts - 1) for c in range(n_colors) if c % counts == 0
159+
]
160+
_picked_colors = [
161+
_colors_hex[int(index)] for index in _picked_colors_index
162+
]
163+
palette.extend(_picked_colors)
113164

114165
all_palettes.append(palette)
115166

template.theme.yaml

+21-21
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
status_line:
33
foreground: "LIGHT_GRAY"
4-
background: "DARK_GRAY"
4+
background: "DEEP_GRAY"
55
left_icon: ""
66
right_icon: ""
77
left_decorator: ""
@@ -15,36 +15,36 @@ status_line:
1515
style: "nobold,nounderscore,noitalics"
1616
status_left:
1717
fg_option: "LIGHT_GRAY"
18-
bg_option: "DARK_GRAY"
19-
fg_icon: "LIGHT_RED"
20-
bg_icon: "DARK_RED"
21-
fg_decorator: "DARK_RED"
22-
bg_decorator: "DARK_GRAY"
18+
bg_option: "DEEP_GRAY"
19+
fg_icon: "LIGHT_ORANGE"
20+
bg_icon: "DEEP_RED"
21+
fg_decorator: "DEEP_RED"
22+
bg_decorator: "DEEP_GRAY"
2323
icon: ""
2424
decorator: ""
2525
style: "nobold,nounderscore,noitalics"
2626
window:
2727
active:
2828
fg_window: "DARK_GRAY"
29-
bg_window: "LIGHT_GREEN"
29+
bg_window: "MIDDLE_GREEN"
3030
fg_window_index: "DARK_GRAY"
31-
bg_window_index: "MIDDLE_GREEN"
31+
bg_window_index: "DARK_GREEN"
3232
fg_icon: "DARK_GRAY"
33-
bg_icon: "MIDDLE_GREEN"
34-
fg_decorator: "MIDDLE_GREEN"
35-
bg_decorator: "DARK_GRAY"
33+
bg_icon: "DARK_GREEN"
34+
fg_decorator: "DARK_GREEN"
35+
bg_decorator: "DEEP_GRAY"
3636
icon: ""
3737
decorator: ""
3838
style: "nobold,nounderscore,noitalics"
3939
inactive:
4040
fg_window: "DARK_GRAY"
41-
bg_window: "LIGHT_GRAY"
42-
fg_window_index: "DARK_GRAY"
43-
bg_window_index: "MIDDLE_GRAY"
41+
bg_window: "STRONG_GRAY"
42+
fg_window_index: "DEEP_GRAY"
43+
bg_window_index: "DARK_GRAY"
4444
fg_icon: ""
4545
bg_icon: ""
46-
fg_decorator: "MIDDLE_GRAY"
47-
bg_decorator: "DARK_GRAY"
46+
fg_decorator: "DARK_GRAY"
47+
bg_decorator: "DEEP_GRAY"
4848
icon: ""
4949
decorator: ""
5050
style: "nobold,nounderscore,noitalics"
@@ -53,8 +53,8 @@ status_right:
5353
decorator: ""
5454
style: "nobold,nounderscore,noitalics"
5555
fg_option: "DARK_GRAY"
56-
bg_option: "LIGHT_GRAY"
57-
fg_icon: "DARK_GRAY"
58-
bg_icon: "MIDDLE_GRAY"
59-
fg_decorator: "MIDDLE_GRAY"
60-
bg_decorator: "DARK_GRAY"
56+
bg_option: "STRONG_GRAY"
57+
fg_icon: "DEEP_GRAY"
58+
bg_icon: "DARK_GRAY"
59+
fg_decorator: "DARK_GRAY"
60+
bg_decorator: "DEEP_GRAY"

violet.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,10 @@ def violet(config_file="violet.yaml"):
487487
# TODO: the config file should be customizable by putting under
488488
# $HOME/.tmux/catppuccin.yaml
489489
set_option_commands = []
490-
with open(config_file, "r", encoding=UTF_8) as config:
490+
dynamic_config_file_name = get_tmux_option(
491+
"dynamic_config_file_name", config_file
492+
)
493+
with open(dynamic_config_file_name, "r", encoding=UTF_8) as config:
491494
catppuccin = yaml.load(config, Loader=Loader)
492495

493496
theme_name = catppuccin.get("theme")

violet.yaml

+12
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,27 @@ status_right:
4242
directory:
4343
enabled: on
4444
tmux_option: " #{b:pane_current_path} "
45+
icon: ""
46+
decorator: ""
47+
fg_option: "DARK_GRAY"
48+
bg_option: "MIDDLE_ORANGE"
49+
fg_icon: "DARK_GRAY"
50+
bg_icon: "DARK_ORANGE"
51+
fg_decorator: "DARK_ORANGE"
52+
4553
date:
4654
enabled: on
55+
icon: ""
4756
tmux_option: " v%V %a %Y-%m-%d %H:%M:%S "
4857
cpu:
4958
enabled: on
59+
icon: ""
5060
tmux_option: " #(source cpu.sh) "
5161
memory:
5262
enabled: on
63+
icon: ""
5364
tmux_option: " #(source memory.sh) "
5465
disk:
5566
enabled: on
67+
icon: ""
5668
tmux_option: " #(source disk.sh) "

0 commit comments

Comments
 (0)