mirror of
https://github.com/nix-community/home-manager
synced 2024-11-30 06:59:45 +01:00
htop: fix preserving the order of meters (#2065)
Pass meters for formatting in a list of attrsets so that ordering can be preserved. In addition provide some mode-specific functions to create these attrsets, to make for a bit nicer config. This fixes #2060.
This commit is contained in:
parent
b917624670
commit
d6bbd02e95
2 changed files with 49 additions and 37 deletions
|
@ -10,9 +10,13 @@ let
|
||||||
let v' = if isBool v then (if v then "1" else "0") else toString v;
|
let v' = if isBool v then (if v then "1" else "0") else toString v;
|
||||||
in "${n}=${v'}";
|
in "${n}=${v'}";
|
||||||
|
|
||||||
formatMeters = side: meters: {
|
formatMeters = side: meters:
|
||||||
"${side}_meters" = mapAttrsToList (x: _: x) meters;
|
let
|
||||||
"${side}_meter_modes" = mapAttrsToList (_: y: y) meters;
|
warn' = warn "htop: meters should be passed as a list";
|
||||||
|
meters' = if isList meters then meters else warn' [ meters ];
|
||||||
|
in {
|
||||||
|
"${side}_meters" = concatMap (mapAttrsToList (x: _: x)) meters';
|
||||||
|
"${side}_meter_modes" = concatMap (mapAttrsToList (_: y: y)) meters';
|
||||||
};
|
};
|
||||||
leftMeters = formatMeters "left";
|
leftMeters = formatMeters "left";
|
||||||
rightMeters = formatMeters "right";
|
rightMeters = formatMeters "right";
|
||||||
|
@ -80,6 +84,14 @@ let
|
||||||
LED = 4;
|
LED = 4;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
# Utilities for constructing meters
|
||||||
|
meter = mode: name: { ${name} = mode; };
|
||||||
|
bar = meter modes.Bar;
|
||||||
|
text = meter modes.Text;
|
||||||
|
graph = meter modes.Graph;
|
||||||
|
led = meter modes.LED;
|
||||||
|
blank = text "Blank";
|
||||||
|
|
||||||
# Mapping from names to defaults
|
# Mapping from names to defaults
|
||||||
meters = {
|
meters = {
|
||||||
Clock = 2;
|
Clock = 2;
|
||||||
|
@ -231,15 +243,17 @@ in {
|
||||||
tree_view = false;
|
tree_view = false;
|
||||||
update_process_names = false;
|
update_process_names = false;
|
||||||
vim_mode = false;
|
vim_mode = false;
|
||||||
} // (leftMeters {
|
} // (leftMeters [
|
||||||
AllCPUs = modes.Bar;
|
(bar "AllCPUs2")
|
||||||
Memory = modes.Bar;
|
(bar "Memory")
|
||||||
Swap = modes.Bar;
|
(bar "Swap")
|
||||||
}) // (rightMeters {
|
(text "Zram")
|
||||||
Tasks = modes.Text;
|
]) // (rightMeters [
|
||||||
LoadAverage = modes.Text;
|
(text "Tasks")
|
||||||
Uptime = modes.Text;
|
(text "LoadAverage")
|
||||||
});
|
(text "Uptime")
|
||||||
|
(text "Systemd")
|
||||||
|
]);
|
||||||
example = literalExample ''
|
example = literalExample ''
|
||||||
{
|
{
|
||||||
color_scheme = 6;
|
color_scheme = 6;
|
||||||
|
@ -262,17 +276,17 @@ in {
|
||||||
highlight_base_name = 1;
|
highlight_base_name = 1;
|
||||||
highlight_megabytes = 1;
|
highlight_megabytes = 1;
|
||||||
highlight_threads = 1;
|
highlight_threads = 1;
|
||||||
} // (with config.lib.htop; leftMeters {
|
} // (with config.lib.htop; leftMeters [
|
||||||
AllCPUs2 = modes.Bar;
|
(bar "AllCPUs2")
|
||||||
Memory = modes.Bar;
|
(bar "Memory")
|
||||||
Swap = modes.Bar;
|
(bar "Swap")
|
||||||
Zram = modes.Text;
|
(text "Zram")
|
||||||
}) // (with config.lib.htop; rightMeters {
|
]) // (with config.lib.htop; rightMeters [
|
||||||
Tasks = modes.Text;
|
(text "Tasks")
|
||||||
LoadAverage = modes.Text;
|
(text "LoadAverage")
|
||||||
Uptime = modes.Text;
|
(text "Uptime")
|
||||||
Systemd = modes.Text;
|
(text "Systemd")
|
||||||
})
|
]);
|
||||||
'';
|
'';
|
||||||
description = ''
|
description = ''
|
||||||
Configuration options to add to
|
Configuration options to add to
|
||||||
|
@ -576,7 +590,9 @@ in {
|
||||||
};
|
};
|
||||||
|
|
||||||
config = mkIf cfg.enable {
|
config = mkIf cfg.enable {
|
||||||
lib.htop = { inherit fields modes leftMeters rightMeters; };
|
lib.htop = {
|
||||||
|
inherit fields modes leftMeters rightMeters bar text graph led blank;
|
||||||
|
};
|
||||||
|
|
||||||
home.packages = [ pkgs.htop ];
|
home.packages = [ pkgs.htop ];
|
||||||
|
|
||||||
|
|
|
@ -27,18 +27,14 @@ with lib;
|
||||||
highlight_megabytes = 1;
|
highlight_megabytes = 1;
|
||||||
highlight_threads = 1;
|
highlight_threads = 1;
|
||||||
} // (with config.lib.htop;
|
} // (with config.lib.htop;
|
||||||
leftMeters {
|
leftMeters [ (bar "AllCPUs2") (bar "Memory") (bar "Swap") (text "Zram") ])
|
||||||
AllCPUs2 = modes.Bar;
|
// (with config.lib.htop;
|
||||||
Memory = modes.Bar;
|
rightMeters [
|
||||||
Swap = modes.Bar;
|
(text "Tasks")
|
||||||
Zram = modes.Text;
|
(text "LoadAverage")
|
||||||
}) // (with config.lib.htop;
|
(text "Uptime")
|
||||||
rightMeters {
|
(text "Systemd")
|
||||||
Tasks = modes.Text;
|
]);
|
||||||
LoadAverage = modes.Text;
|
|
||||||
Uptime = modes.Text;
|
|
||||||
Systemd = modes.Text;
|
|
||||||
});
|
|
||||||
|
|
||||||
nmt.script = ''
|
nmt.script = ''
|
||||||
assertFileExists home-files/.config/htop/htoprc
|
assertFileExists home-files/.config/htop/htoprc
|
||||||
|
|
Loading…
Reference in a new issue