Skip to content

Commit

Permalink
sioyek: enable multiple bindings for the same command
Browse files Browse the repository at this point in the history
  • Loading branch information
foo-dogsquared authored and rycee committed Oct 8, 2022
1 parent 3b5a8d3 commit bd87a34
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 6 deletions.
22 changes: 16 additions & 6 deletions modules/programs/sioyek.nix
Original file line number Diff line number Diff line change
@@ -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 = {
Expand All @@ -24,15 +29,20 @@ in {
Input configuration written to
<filename>$XDG_CONFIG_HOME/sioyek/keys_user.config</filename>.
See <link xlink:href="https://github.com/ahrm/sioyek/blob/main/pdf_viewer/keys.config"/>.
</para><para>
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 ''
{
"move_up" = "k";
"move_down" = "j";
"move_left" = "h";
"move_right" = "l";
"screen_down" = [ "d" "<C-d>" ];
"screen_up" = [ "u" "<C-u>" ];
}
'';
};
Expand All @@ -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;
})
]);

Expand Down
1 change: 1 addition & 0 deletions tests/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions tests/modules/programs/sioyek/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ sioyek = ./sioyek-basic-configuration.nix; }
36 changes: 36 additions & 0 deletions tests/modules/programs/sioyek/sioyek-basic-configuration.nix
Original file line number Diff line number Diff line change
@@ -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" "<C-d>" ];
"screen_up" = [ "u" "<C-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
}
'';
};
}
8 changes: 8 additions & 0 deletions tests/modules/programs/sioyek/test_keys_user.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
move_down j
move_left h
move_right l
move_up k
screen_down d
screen_down <C-d>
screen_up u
screen_up <C-u>
2 changes: 2 additions & 0 deletions tests/modules/programs/sioyek/test_prefs_user.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dark_mode_background_color 0.0 0.0 0.0
dark_mode_contrast 0.8

0 comments on commit bd87a34

Please sign in to comment.