visuals: move cellular-automaton to its own module

Scuffed impl.
This commit is contained in:
NotAShelf 2024-10-07 02:10:20 +03:00
parent b4de344253
commit ccd0582d09
No known key found for this signature in database
GPG key ID: AF26552424E53993
6 changed files with 106 additions and 40 deletions

View file

@ -0,0 +1,60 @@
{lib, ...}: let
inherit (lib.modules) mkRenamedOptionModule;
inherit (lib.options) mkOption mkEnableOption;
inherit (lib.nvim.types) luaInline;
inherit (lib.nvim.binds) mkMappingOption;
inherit (lib.generators) mkLuaInline;
in {
imports = [
(mkRenamedOptionModule ["vim" "visuals" "cellularAutomaton"] ["vim" "visuals" "cellular-automaton"])
];
options.vim.visuals.cellular-automaton = {
enable = mkEnableOption "cellular-automaton to help you cope with stubborn code [cellular-automaton]";
mappings = {
makeItRain = mkMappingOption "Make it rain [cellular-automaton]" "<leader>fml";
};
animation = {
register = mkEnableOption "registering configured animation(s) automatically" // {default = true;};
setup = mkOption {
type = luaInline;
default = mkLuaInline ''
local ca_config = {
fps = 50,
name = 'slide',
}
-- init function is invoked only once at the start
-- config.init = function (grid)
--
-- end
-- update function
ca_config.update = function (grid)
for i = 1, #grid do
local prev = grid[i][#(grid[i])]
for j = 1, #(grid[i]) do
grid[i][j], prev = prev, grid[i][j]
end
end
return true
end
'';
description = ''
Configuration used to generate an animation to be registered.
The final value for `ca_config` will be used to register a new
animation using `require("cellular-automaton").register_animation(ca_config)`
::: {.warning}
`ca_config` **must** eval to a valid Lua table. nvf does not and cannot
perform any kind of validation on your Lua code, so bogus values will
result in errors when the animation is registered.
:::
'';
};
};
};
}

View file

@ -0,0 +1,39 @@
{
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) mkBinding;
cfg = config.vim.visuals.cellular-automaton;
in {
config = mkIf cfg.enable {
vim = {
startPlugins = ["cellular-automaton"];
maps.normal = mkBinding cfg.mappings.makeItRain "<cmd>CellularAutomaton make_it_rain<CR>" "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)
'';
};
};
};
}

View file

@ -0,0 +1,6 @@
{
imports = [
./config.nix
./cellular-automaton.nix
];
}

View file

@ -19,37 +19,6 @@ in {
''; '';
}) })
(mkIf cfg.cellularAutomaton.enable {
vim.startPlugins = ["cellular-automaton"];
vim.maps.normal = mkBinding cfg.cellularAutomaton.mappings.makeItRain "<cmd>CellularAutomaton make_it_rain<CR>" "Make it rain";
vim.pluginRC.cellularAUtomaton = entryAnywhere ''
local config = {
fps = 50,
name = 'slide',
}
-- init function is invoked only once at the start
-- config.init = function (grid)
--
-- end
-- update function
config.update = function (grid)
for i = 1, #grid do
local prev = grid[i][#(grid[i])]
for j = 1, #(grid[i]) do
grid[i][j], prev = prev, grid[i][j]
end
end
return true
end
require("cellular-automaton").register_animation(config)
'';
})
(mkIf cfg.highlight-undo.enable { (mkIf cfg.highlight-undo.enable {
vim.startPlugins = ["highlight-undo"]; vim.startPlugins = ["highlight-undo"];
vim.pluginRC.highlight-undo = entryAnywhere '' vim.pluginRC.highlight-undo = entryAnywhere ''

View file

@ -1,5 +1,6 @@
{ {
imports = [ imports = [
./cellular-automaton
./cinnamon-nvim ./cinnamon-nvim
./fidget-nvim ./fidget-nvim
./indent-blankline ./indent-blankline

View file

@ -5,21 +5,12 @@
}: let }: let
inherit (lib.options) mkEnableOption mkOption; inherit (lib.options) mkEnableOption mkOption;
inherit (lib.types) int bool str; inherit (lib.types) int bool str;
inherit (lib.nvim.binds) mkMappingOption;
cfg = config.vim.visuals; cfg = config.vim.visuals;
in { in {
options.vim.visuals = { options.vim.visuals = {
enable = mkEnableOption "Visual enhancements."; enable = mkEnableOption "Visual enhancements.";
cellularAutomaton = {
enable = mkEnableOption "cellular automaton [cellular-automaton]";
mappings = {
makeItRain = mkMappingOption "Make it rain [cellular-automaton]" "<leader>fml";
};
};
highlight-undo = { highlight-undo = {
enable = mkEnableOption "highlight undo [highlight-undo]"; enable = mkEnableOption "highlight undo [highlight-undo]";