summaryrefslogtreecommitdiffstats
path: root/modules/plugins/visuals/cellular-automaton/config.nix
blob: 2123a35af3a4efcbe1ea30b33dd90f157c6f48fb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
{
  config,
  lib,
  ...
}: let
  inherit (lib.modules) mkIf;
  inherit (lib.strings) optionalString;
  inherit (lib.nvim.lua) toLuaObject;
  inherit (lib.nvim.dag) entryAnywhere entryAfter;
  inherit (lib.nvim.binds) mkKeymap;

  cfg = config.vim.visuals.cellular-automaton;
in {
  config = mkIf cfg.enable {
    vim = {
      startPlugins = ["cellular-automaton-nvim"];

      keymaps = [
        (mkKeymap "n" cfg.mappings.makeItRain "<cmd>CellularAutomaton make_it_rain<CR>" {desc = "Make it rain";})
      ];

      pluginRC = {
        # XXX: This has no error handling. User can set
        # `animation.setup` to a bogus value, and we would
        # have an error in our hands. I don't think there
        # is a good way to check for errors, so I'm leaving
        # it like this under the assumption that the user
        # will not mess it up for no reason.
        cellular-automaton-anim = entryAnywhere (optionalString cfg.animation.register ''
          -- Coerce user animation config into pluginRC
          ${toLuaObject cfg.animation.setup}
        '');

        cellular-automaton = entryAfter ["cellular-automaton-anim"] ''
          -- Register the animation
          require("cellular-automaton").register_animation(ca_config)
        '';
      };
    };
  };
}