mirror of
https://github.com/NotAShelf/neovim-flake.git
synced 2024-11-08 05:45:58 +01:00
visuals: move cellular-automaton to its own module
Scuffed impl.
This commit is contained in:
parent
b4de344253
commit
ccd0582d09
6 changed files with 106 additions and 40 deletions
|
@ -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.
|
||||
:::
|
||||
'';
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
39
modules/plugins/visuals/cellular-automaton/config.nix
Normal file
39
modules/plugins/visuals/cellular-automaton/config.nix
Normal 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)
|
||||
'';
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
6
modules/plugins/visuals/cellular-automaton/default.nix
Normal file
6
modules/plugins/visuals/cellular-automaton/default.nix
Normal file
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
imports = [
|
||||
./config.nix
|
||||
./cellular-automaton.nix
|
||||
];
|
||||
}
|
|
@ -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 {
|
||||
vim.startPlugins = ["highlight-undo"];
|
||||
vim.pluginRC.highlight-undo = entryAnywhere ''
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
{
|
||||
imports = [
|
||||
./cellular-automaton
|
||||
./cinnamon-nvim
|
||||
./fidget-nvim
|
||||
./indent-blankline
|
||||
|
|
|
@ -5,21 +5,12 @@
|
|||
}: let
|
||||
inherit (lib.options) mkEnableOption mkOption;
|
||||
inherit (lib.types) int bool str;
|
||||
inherit (lib.nvim.binds) mkMappingOption;
|
||||
|
||||
cfg = config.vim.visuals;
|
||||
in {
|
||||
options.vim.visuals = {
|
||||
enable = mkEnableOption "Visual enhancements.";
|
||||
|
||||
cellularAutomaton = {
|
||||
enable = mkEnableOption "cellular automaton [cellular-automaton]";
|
||||
|
||||
mappings = {
|
||||
makeItRain = mkMappingOption "Make it rain [cellular-automaton]" "<leader>fml";
|
||||
};
|
||||
};
|
||||
|
||||
highlight-undo = {
|
||||
enable = mkEnableOption "highlight undo [highlight-undo]";
|
||||
|
||||
|
|
Loading…
Reference in a new issue