From 820be197ccf3adaad9a8856ef255c13b6cc561a6 Mon Sep 17 00:00:00 2001 From: Matthieu Coudron <886074+teto@users.noreply.github.com> Date: Sun, 31 Mar 2024 22:06:56 +0200 Subject: [PATCH] programs.khal: ability to set RGB color (#5192) The current module constrains to values in enum but khal supports RGB colors as well khal.readthedocs.io/en/latest/configure.html#the-calendars-section ! (be careful when setting an RGB value, it has to be quoted else it is ignored, got bitten by it with a manual config ) NB: It's also not possible to set addresses khal.readthedocs.io/en/latest/configure.html#the-calendars-section --- modules/programs/khal-accounts.nix | 20 ++----------------- modules/programs/khal.nix | 9 +++++---- tests/modules/programs/khal/config.nix | 1 + .../programs/khal/khal-config-expected | 5 +++++ 4 files changed, 13 insertions(+), 22 deletions(-) diff --git a/modules/programs/khal-accounts.nix b/modules/programs/khal-accounts.nix index cf04a65c..846e18fa 100644 --- a/modules/programs/khal-accounts.nix +++ b/modules/programs/khal-accounts.nix @@ -15,27 +15,11 @@ with lib; }; color = mkOption { - type = types.nullOr (types.enum [ - "black" - "white" - "brown" - "yellow" - "dark gray" - "dark green" - "dark blue" - "light gray" - "light green" - "light blue" - "dark magenta" - "dark cyan" - "dark red" - "light magenta" - "light cyan" - "light red" - ]); + type = types.nullOr types.str; default = null; description = '' Color in which events in this calendar are displayed. + For instance 'light green' or an RGB color '#ff0000' ''; example = "light green"; }; diff --git a/modules/programs/khal.nix b/modules/programs/khal.nix index c8037e53..52e77963 100644 --- a/modules/programs/khal.nix +++ b/modules/programs/khal.nix @@ -45,10 +45,11 @@ let + (optionalString (value.khal.type == "birthdays" && value.khal ? thisCollection) value.khal.thisCollection) - }" - ] ++ optional (value.khal.readOnly) "readonly = True" ++ [ - (toKeyValueIfDefined (getAttrs [ "type" "color" "priority" ] value.khal)) - ] ++ [ "\n" ]); + }\n " + ] ++ optional (value.khal.readOnly) "readonly = True" + ++ optional (value.khal.color != null) "color = '${value.khal.color}'" + ++ [ (toKeyValueIfDefined (getAttrs [ "type" "priority" ] value.khal)) ] + ++ [ "\n" ]); localeFormatOptions = let T = lib.types; diff --git a/tests/modules/programs/khal/config.nix b/tests/modules/programs/khal/config.nix index 50218e15..017a04ac 100644 --- a/tests/modules/programs/khal/config.nix +++ b/tests/modules/programs/khal/config.nix @@ -19,6 +19,7 @@ khal = { enable = true; readOnly = true; + color = "#ff0000"; type = "calendar"; }; local.type = "filesystem"; diff --git a/tests/modules/programs/khal/khal-config-expected b/tests/modules/programs/khal/khal-config-expected index a4cf7a30..157d650b 100644 --- a/tests/modules/programs/khal/khal-config-expected +++ b/tests/modules/programs/khal/khal-config-expected @@ -1,7 +1,9 @@ [calendars] [[test]] path = /home/hm-user/$XDG_CONFIG_HOME/cal/test/ + readonly = True +color = '#ff0000' priority=10 type=calendar @@ -9,6 +11,7 @@ type=calendar [[testcontacts-automaticallyCollected]] path = /home/hm-user/$XDG_CONFIG_HOME/card/testcontacts/automaticallyCollected + priority=10 type=birthdays @@ -16,6 +19,7 @@ type=birthdays [[testcontacts-default]] path = /home/hm-user/$XDG_CONFIG_HOME/card/testcontacts/default + priority=10 type=birthdays @@ -23,6 +27,7 @@ type=birthdays [[testcontactsNoCollections]] path = /home/hm-user/$XDG_CONFIG_HOME/card/testcontactsNoCollections/ + priority=10 type=birthdays