Skip to content

Commit 0daadc7

Browse files
authored
btop: add themes option (#6777)
1 parent bd33ce4 commit 0daadc7

File tree

3 files changed

+155
-2
lines changed

3 files changed

+155
-2
lines changed

modules/programs/btop.nix

+65-2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,58 @@ in {
4141
'';
4242
};
4343

44+
themes = lib.mkOption {
45+
type = with lib.types; lazyAttrsOf (either path lines);
46+
default = { };
47+
example = ''
48+
theme[main_bg]="#282a36"
49+
theme[main_fg]="#f8f8f2"
50+
theme[title]="#f8f8f2"
51+
theme[hi_fg]="#6272a4"
52+
theme[selected_bg]="#ff79c6"
53+
theme[selected_fg]="#f8f8f2"
54+
theme[inactive_fg]="#44475a"
55+
theme[graph_text]="#f8f8f2"
56+
theme[meter_bg]="#44475a"
57+
theme[proc_misc]="#bd93f9"
58+
theme[cpu_box]="#bd93f9"
59+
theme[mem_box]="#50fa7b"
60+
theme[net_box]="#ff5555"
61+
theme[proc_box]="#8be9fd"
62+
theme[div_line]="#44475a"
63+
theme[temp_start]="#bd93f9"
64+
theme[temp_mid]="#ff79c6"
65+
theme[temp_end]="#ff33a8"
66+
theme[cpu_start]="#bd93f9"
67+
theme[cpu_mid]="#8be9fd"
68+
theme[cpu_end]="#50fa7b"
69+
theme[free_start]="#ffa6d9"
70+
theme[free_mid]="#ff79c6"
71+
theme[free_end]="#ff33a8"
72+
theme[cached_start]="#b1f0fd"
73+
theme[cached_mid]="#8be9fd"
74+
theme[cached_end]="#26d7fd"
75+
theme[available_start]="#ffd4a6"
76+
theme[available_mid]="#ffb86c"
77+
theme[available_end]="#ff9c33"
78+
theme[used_start]="#96faaf"
79+
theme[used_mid]="#50fa7b"
80+
theme[used_end]="#0dfa49"
81+
theme[download_start]="#bd93f9"
82+
theme[download_mid]="#50fa7b"
83+
theme[download_end]="#8be9fd"
84+
theme[upload_start]="#8c42ab"
85+
theme[upload_mid]="#ff79c6"
86+
theme[upload_end]="#ff33a8"
87+
theme[process_start]="#50fa7b"
88+
theme[process_mid]="#59b690"
89+
theme[process_end]="#6272a4"
90+
'';
91+
description = ''
92+
Themes to be written to {file}`$XDG_CONFIG_HOME/btop/themes/''${name}.theme`
93+
'';
94+
};
95+
4496
extraConfig = lib.mkOption {
4597
type = lib.types.lines;
4698
default = "";
@@ -53,7 +105,18 @@ in {
53105
config = lib.mkIf cfg.enable {
54106
home.packages = lib.mkIf (cfg.package != null) [ cfg.package ];
55107

56-
xdg.configFile."btop/btop.conf" =
57-
lib.mkIf (cfg.settings != { }) { text = finalConfig; };
108+
xdg.configFile = let
109+
mkThemeConfig = name: theme: {
110+
name = "btop/themes/${name}.theme";
111+
value = {
112+
source = (if builtins.isPath theme || lib.isStorePath theme then
113+
theme
114+
else
115+
pkgs.writeText "btop-theme.theme" theme);
116+
};
117+
};
118+
in {
119+
"btop/btop.conf" = lib.mkIf (cfg.settings != { }) { text = finalConfig; };
120+
} // lib.mapAttrs' mkThemeConfig cfg.themes;
58121
};
59122
}

tests/modules/programs/btop/example-settings.nix

+48
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,59 @@
2424
extraConfig = ''
2525
clock_format = "%H:%M"
2626
'';
27+
28+
themes.example = ''
29+
theme[main_bg]="#282a36"
30+
theme[main_fg]="#f8f8f2"
31+
theme[title]="#f8f8f2"
32+
theme[hi_fg]="#6272a4"
33+
theme[selected_bg]="#ff79c6"
34+
theme[selected_fg]="#f8f8f2"
35+
theme[inactive_fg]="#44475a"
36+
theme[graph_text]="#f8f8f2"
37+
theme[meter_bg]="#44475a"
38+
theme[proc_misc]="#bd93f9"
39+
theme[cpu_box]="#bd93f9"
40+
theme[mem_box]="#50fa7b"
41+
theme[net_box]="#ff5555"
42+
theme[proc_box]="#8be9fd"
43+
theme[div_line]="#44475a"
44+
theme[temp_start]="#bd93f9"
45+
theme[temp_mid]="#ff79c6"
46+
theme[temp_end]="#ff33a8"
47+
theme[cpu_start]="#bd93f9"
48+
theme[cpu_mid]="#8be9fd"
49+
theme[cpu_end]="#50fa7b"
50+
theme[free_start]="#ffa6d9"
51+
theme[free_mid]="#ff79c6"
52+
theme[free_end]="#ff33a8"
53+
theme[cached_start]="#b1f0fd"
54+
theme[cached_mid]="#8be9fd"
55+
theme[cached_end]="#26d7fd"
56+
theme[available_start]="#ffd4a6"
57+
theme[available_mid]="#ffb86c"
58+
theme[available_end]="#ff9c33"
59+
theme[used_start]="#96faaf"
60+
theme[used_mid]="#50fa7b"
61+
theme[used_end]="#0dfa49"
62+
theme[download_start]="#bd93f9"
63+
theme[download_mid]="#50fa7b"
64+
theme[download_end]="#8be9fd"
65+
theme[upload_start]="#8c42ab"
66+
theme[upload_mid]="#ff79c6"
67+
theme[upload_end]="#ff33a8"
68+
theme[process_start]="#50fa7b"
69+
theme[process_mid]="#59b690"
70+
theme[process_end]="#6272a4"
71+
'';
2772
};
2873

2974
nmt.script = ''
3075
assertFileContent \
3176
home-files/.config/btop/btop.conf \
3277
${./example-settings-expected.conf}
78+
assertFileContent \
79+
home-files/.config/btop/themes/example.theme \
80+
${./example-theme-expected.theme}
3381
'';
3482
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
theme[main_bg]="#282a36"
2+
theme[main_fg]="#f8f8f2"
3+
theme[title]="#f8f8f2"
4+
theme[hi_fg]="#6272a4"
5+
theme[selected_bg]="#ff79c6"
6+
theme[selected_fg]="#f8f8f2"
7+
theme[inactive_fg]="#44475a"
8+
theme[graph_text]="#f8f8f2"
9+
theme[meter_bg]="#44475a"
10+
theme[proc_misc]="#bd93f9"
11+
theme[cpu_box]="#bd93f9"
12+
theme[mem_box]="#50fa7b"
13+
theme[net_box]="#ff5555"
14+
theme[proc_box]="#8be9fd"
15+
theme[div_line]="#44475a"
16+
theme[temp_start]="#bd93f9"
17+
theme[temp_mid]="#ff79c6"
18+
theme[temp_end]="#ff33a8"
19+
theme[cpu_start]="#bd93f9"
20+
theme[cpu_mid]="#8be9fd"
21+
theme[cpu_end]="#50fa7b"
22+
theme[free_start]="#ffa6d9"
23+
theme[free_mid]="#ff79c6"
24+
theme[free_end]="#ff33a8"
25+
theme[cached_start]="#b1f0fd"
26+
theme[cached_mid]="#8be9fd"
27+
theme[cached_end]="#26d7fd"
28+
theme[available_start]="#ffd4a6"
29+
theme[available_mid]="#ffb86c"
30+
theme[available_end]="#ff9c33"
31+
theme[used_start]="#96faaf"
32+
theme[used_mid]="#50fa7b"
33+
theme[used_end]="#0dfa49"
34+
theme[download_start]="#bd93f9"
35+
theme[download_mid]="#50fa7b"
36+
theme[download_end]="#8be9fd"
37+
theme[upload_start]="#8c42ab"
38+
theme[upload_mid]="#ff79c6"
39+
theme[upload_end]="#ff33a8"
40+
theme[process_start]="#50fa7b"
41+
theme[process_mid]="#59b690"
42+
theme[process_end]="#6272a4"

0 commit comments

Comments
 (0)