modules/terminal: switch to explicit lib calls

This commit is contained in:
raf 2024-03-12 03:47:27 +03:00
commit 32c2e7733a
No known key found for this signature in database
GPG key ID: 02D1DD3FA08B6B29
4 changed files with 43 additions and 36 deletions

View file

@ -4,48 +4,54 @@
...
}: let
inherit (builtins) toJSON;
inherit (lib) mkMerge mkIf mkBinding nvim getExe;
inherit (lib.lists) optionals;
inherit (lib.modules) mkIf mkMerge;
inherit (lib.meta) getExe;
inherit (lib.nvim.binds) mkBinding;
inherit (lib.nvim.dag) entryAnywhere entryAfter;
cfg = config.vim.terminal.toggleterm;
in {
config = mkMerge [
(
mkIf cfg.enable {
vim.startPlugins = [
"toggleterm-nvim"
];
vim = {
startPlugins = [
"toggleterm-nvim"
];
vim.maps.normal = mkBinding cfg.mappings.open "<Cmd>execute v:count . \"ToggleTerm\"<CR>" "Toggle terminal";
maps.normal = mkBinding cfg.mappings.open "<Cmd>execute v:count . \"ToggleTerm\"<CR>" "Toggle terminal";
vim.luaConfigRC.toggleterm = nvim.dag.entryAnywhere ''
require("toggleterm").setup({
open_mapping = null,
direction = '${toString cfg.direction}',
-- TODO: this should probably be turned into a module that uses the lua function if and only if the user has not set it
size = function(term)
if term.direction == "horizontal" then
return 15
elseif term.direction == "vertical" then
return vim.o.columns * 0.4
end
end,
winbar = {
enabled = '${toString cfg.enable_winbar}',
name_formatter = function(term) -- term: Terminal
return term.name
end
},
})
'';
luaConfigRC.toggleterm = entryAnywhere ''
require("toggleterm").setup({
open_mapping = null,
direction = '${toString cfg.direction}',
-- TODO: this should probably be turned into a module that uses the lua function if and only if the user has not set it
size = function(term)
if term.direction == "horizontal" then
return 15
elseif term.direction == "vertical" then
return vim.o.columns * 0.4
end
end,
winbar = {
enabled = '${toString cfg.enable_winbar}',
name_formatter = function(term) -- term: Terminal
return term.name
end
},
})
'';
};
}
)
(
mkIf (cfg.enable && cfg.lazygit.enable)
{
vim.startPlugins = lib.optionals (cfg.lazygit.package != null) [
vim.startPlugins = optionals (cfg.lazygit.package != null) [
cfg.lazygit.package
];
vim.luaConfigRC.toggleterm-lazygit = nvim.dag.entryAfter ["toggleterm"] ''
vim.luaConfigRC.toggleterm-lazygit = entryAfter ["toggleterm"] ''
local terminal = require 'toggleterm.terminal'
local lazygit = terminal.Terminal:new({
cmd = '${