mirror of
https://github.com/NotAShelf/neovim-flake.git
synced 2024-12-19 08:39:50 +01:00
feat(toggleterm): custom setup opts
This commit is contained in:
parent
59d5ac0d63
commit
daa10b508b
2 changed files with 51 additions and 28 deletions
|
@ -9,6 +9,7 @@
|
||||||
inherit (lib.meta) getExe;
|
inherit (lib.meta) getExe;
|
||||||
inherit (lib.nvim.binds) mkBinding;
|
inherit (lib.nvim.binds) mkBinding;
|
||||||
inherit (lib.nvim.dag) entryAnywhere entryAfter;
|
inherit (lib.nvim.dag) entryAnywhere entryAfter;
|
||||||
|
inherit (lib.nvim.lua) toLuaObject;
|
||||||
|
|
||||||
cfg = config.vim.terminal.toggleterm;
|
cfg = config.vim.terminal.toggleterm;
|
||||||
in {
|
in {
|
||||||
|
@ -23,24 +24,7 @@ in {
|
||||||
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";
|
||||||
|
|
||||||
luaConfigRC.toggleterm = entryAnywhere ''
|
luaConfigRC.toggleterm = entryAnywhere ''
|
||||||
require("toggleterm").setup({
|
require("toggleterm").setup(${toLuaObject cfg.setupOpts})
|
||||||
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
|
|
||||||
},
|
|
||||||
})
|
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,8 +5,15 @@
|
||||||
}: let
|
}: let
|
||||||
inherit (lib.options) mkOption mkEnableOption;
|
inherit (lib.options) mkOption mkEnableOption;
|
||||||
inherit (lib.nvim.binds) mkMappingOption;
|
inherit (lib.nvim.binds) mkMappingOption;
|
||||||
inherit (lib.types) nullOr str enum bool package;
|
inherit (lib.types) nullOr str enum bool package either int;
|
||||||
|
inherit (lib) mkRenamedOptionModule;
|
||||||
|
inherit (lib.nvim.types) mkPluginSetupOption rawLua;
|
||||||
in {
|
in {
|
||||||
|
imports = [
|
||||||
|
(mkRenamedOptionModule ["vim" "terminal" "toggleterm" "direction"] ["vim" "terminal" "toggleterm" "setupOpts" "direction"])
|
||||||
|
(mkRenamedOptionModule ["vim" "terminal" "toggleterm" "enable_winbar"] ["vim" "terminal" "toggleterm" "setupOpts" "enable_winbar"])
|
||||||
|
];
|
||||||
|
|
||||||
options.vim.terminal.toggleterm = {
|
options.vim.terminal.toggleterm = {
|
||||||
enable = mkEnableOption "toggleterm as a replacement to built-in terminal command";
|
enable = mkEnableOption "toggleterm as a replacement to built-in terminal command";
|
||||||
mappings = {
|
mappings = {
|
||||||
|
@ -17,16 +24,48 @@ in {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
direction = mkOption {
|
setupOpts = mkPluginSetupOption "ToggleTerm" {
|
||||||
type = enum ["horizontal" "vertical" "tab" "float"];
|
direction = mkOption {
|
||||||
default = "horizontal";
|
type = enum ["horizontal" "vertical" "tab" "float"];
|
||||||
description = "Direction of the terminal";
|
default = "horizontal";
|
||||||
};
|
description = "Direction of the terminal";
|
||||||
|
};
|
||||||
|
|
||||||
enable_winbar = mkOption {
|
enable_winbar = mkOption {
|
||||||
type = bool;
|
type = bool;
|
||||||
default = false;
|
default = false;
|
||||||
description = "Enable winbar";
|
description = "Enable winbar";
|
||||||
|
};
|
||||||
|
|
||||||
|
size = mkOption {
|
||||||
|
type = either rawLua int;
|
||||||
|
description = "Number or lua function which is passed to the current terminal";
|
||||||
|
default = {
|
||||||
|
__raw = ''
|
||||||
|
function(term)
|
||||||
|
if term.direction == "horizontal" then
|
||||||
|
return 15
|
||||||
|
elseif term.direction == "vertical" then
|
||||||
|
return vim.o.columns * 0.4
|
||||||
|
end
|
||||||
|
end
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
};
|
||||||
|
winbar = {
|
||||||
|
enabled = mkEnableOption "winbar in terminal" // {default = true;};
|
||||||
|
name_formatter = mkOption {
|
||||||
|
type = rawLua;
|
||||||
|
description = "Winbar formatter function.";
|
||||||
|
default = {
|
||||||
|
__raw = ''
|
||||||
|
function(term)
|
||||||
|
return term.name
|
||||||
|
end
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
lazygit = {
|
lazygit = {
|
||||||
|
|
Loading…
Reference in a new issue