From bd87a34bb487a655e1282528a70d0d6b10585a37 Mon Sep 17 00:00:00 2001 From: Gabriel Arazas Date: Sat, 1 Oct 2022 22:42:51 +0800 Subject: [PATCH] sioyek: enable multiple bindings for the same command --- modules/programs/sioyek.nix | 22 ++++++++---- tests/default.nix | 1 + tests/modules/programs/sioyek/default.nix | 1 + .../sioyek/sioyek-basic-configuration.nix | 36 +++++++++++++++++++ .../programs/sioyek/test_keys_user.config | 8 +++++ .../programs/sioyek/test_prefs_user.config | 2 ++ 6 files changed, 64 insertions(+), 6 deletions(-) create mode 100644 tests/modules/programs/sioyek/default.nix create mode 100644 tests/modules/programs/sioyek/sioyek-basic-configuration.nix create mode 100644 tests/modules/programs/sioyek/test_keys_user.config create mode 100644 tests/modules/programs/sioyek/test_prefs_user.config diff --git a/modules/programs/sioyek.nix b/modules/programs/sioyek.nix index 9ef32746..63bf5b6f 100644 --- a/modules/programs/sioyek.nix +++ b/modules/programs/sioyek.nix @@ -1,11 +1,16 @@ { config, lib, pkgs, ... }: + with lib; + let + cfg = config.programs.sioyek; - renderAttrs = attrs: - concatStringsSep "\n" - (mapAttrsToList (name: value: "${name} ${value}") attrs); + renderConfig = generators.toKeyValue { + mkKeyValue = key: value: "${key} ${value}"; + listsAsDuplicateKeys = true; + }; + in { options = { programs.sioyek = { @@ -24,8 +29,11 @@ in { Input configuration written to $XDG_CONFIG_HOME/sioyek/keys_user.config. See . + + Each attribute could also accept a list of strings to set multiple + bindings of the same command. ''; - type = types.attrsOf types.str; + type = with types; attrsOf (either str (listOf str)); default = { }; example = literalExpression '' { @@ -33,6 +41,8 @@ in { "move_down" = "j"; "move_left" = "h"; "move_right" = "l"; + "screen_down" = [ "d" "" ]; + "screen_up" = [ "u" "" ]; } ''; }; @@ -59,10 +69,10 @@ in { config = mkIf cfg.enable (mkMerge [ { home.packages = [ cfg.package ]; } (mkIf (cfg.config != { }) { - xdg.configFile."sioyek/prefs_user.config".text = renderAttrs cfg.config; + xdg.configFile."sioyek/prefs_user.config".text = renderConfig cfg.config; }) (mkIf (cfg.bindings != { }) { - xdg.configFile."sioyek/keys_user.config".text = renderAttrs cfg.bindings; + xdg.configFile."sioyek/keys_user.config".text = renderConfig cfg.bindings; }) ]); diff --git a/tests/default.nix b/tests/default.nix index da7f539e..61959860 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -110,6 +110,7 @@ import nmt { ./modules/programs/sagemath ./modules/programs/sbt ./modules/programs/scmpuff + ./modules/programs/sioyek ./modules/programs/sm64ex ./modules/programs/ssh ./modules/programs/starship diff --git a/tests/modules/programs/sioyek/default.nix b/tests/modules/programs/sioyek/default.nix new file mode 100644 index 00000000..c35f1c9f --- /dev/null +++ b/tests/modules/programs/sioyek/default.nix @@ -0,0 +1 @@ +{ sioyek = ./sioyek-basic-configuration.nix; } diff --git a/tests/modules/programs/sioyek/sioyek-basic-configuration.nix b/tests/modules/programs/sioyek/sioyek-basic-configuration.nix new file mode 100644 index 00000000..42eb1302 --- /dev/null +++ b/tests/modules/programs/sioyek/sioyek-basic-configuration.nix @@ -0,0 +1,36 @@ +{ config, pkgs, ... }: + +{ + programs.sioyek = { + enable = true; + bindings = { + "move_down" = "j"; + "move_left" = "h"; + "move_right" = "l"; + "move_up" = "k"; + "screen_down" = [ "d" "" ]; + "screen_up" = [ "u" "" ]; + }; + config = { + "dark_mode_background_color" = "0.0 0.0 0.0"; + "dark_mode_contrast" = "0.8"; + }; + }; + + test.stubs.sioyek = { }; + + nmt = { + description = "Sioyek basic setup with sample configuration"; + script = '' + assertFileExists home-files/.config/sioyek/prefs_user.config + assertFileContent home-files/.config/sioyek/prefs_user.config ${ + ./test_prefs_user.config + } + + assertFileExists home-files/.config/sioyek/keys_user.config + assertFileContent home-files/.config/sioyek/keys_user.config ${ + ./test_keys_user.config + } + ''; + }; +} diff --git a/tests/modules/programs/sioyek/test_keys_user.config b/tests/modules/programs/sioyek/test_keys_user.config new file mode 100644 index 00000000..f1be89c3 --- /dev/null +++ b/tests/modules/programs/sioyek/test_keys_user.config @@ -0,0 +1,8 @@ +move_down j +move_left h +move_right l +move_up k +screen_down d +screen_down +screen_up u +screen_up diff --git a/tests/modules/programs/sioyek/test_prefs_user.config b/tests/modules/programs/sioyek/test_prefs_user.config new file mode 100644 index 00000000..730dd51b --- /dev/null +++ b/tests/modules/programs/sioyek/test_prefs_user.config @@ -0,0 +1,2 @@ +dark_mode_background_color 0.0 0.0 0.0 +dark_mode_contrast 0.8