mirror of
https://github.com/NotAShelf/neovim-flake.git
synced 2024-12-21 17:59:48 +01:00
modules/terminal: switch to explicit lib calls
This commit is contained in:
parent
2c483d90af
commit
32c2e7733a
4 changed files with 43 additions and 36 deletions
|
@ -1,4 +1,4 @@
|
||||||
_: {
|
{
|
||||||
imports = [
|
imports = [
|
||||||
./toggleterm
|
./toggleterm
|
||||||
];
|
];
|
||||||
|
|
|
@ -4,48 +4,54 @@
|
||||||
...
|
...
|
||||||
}: let
|
}: let
|
||||||
inherit (builtins) toJSON;
|
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;
|
cfg = config.vim.terminal.toggleterm;
|
||||||
in {
|
in {
|
||||||
config = mkMerge [
|
config = mkMerge [
|
||||||
(
|
(
|
||||||
mkIf cfg.enable {
|
mkIf cfg.enable {
|
||||||
vim.startPlugins = [
|
vim = {
|
||||||
"toggleterm-nvim"
|
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 ''
|
luaConfigRC.toggleterm = entryAnywhere ''
|
||||||
require("toggleterm").setup({
|
require("toggleterm").setup({
|
||||||
open_mapping = null,
|
open_mapping = null,
|
||||||
direction = '${toString cfg.direction}',
|
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
|
-- 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)
|
size = function(term)
|
||||||
if term.direction == "horizontal" then
|
if term.direction == "horizontal" then
|
||||||
return 15
|
return 15
|
||||||
elseif term.direction == "vertical" then
|
elseif term.direction == "vertical" then
|
||||||
return vim.o.columns * 0.4
|
return vim.o.columns * 0.4
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
winbar = {
|
winbar = {
|
||||||
enabled = '${toString cfg.enable_winbar}',
|
enabled = '${toString cfg.enable_winbar}',
|
||||||
name_formatter = function(term) -- term: Terminal
|
name_formatter = function(term) -- term: Terminal
|
||||||
return term.name
|
return term.name
|
||||||
end
|
end
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
'';
|
'';
|
||||||
|
};
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
(
|
(
|
||||||
mkIf (cfg.enable && cfg.lazygit.enable)
|
mkIf (cfg.enable && cfg.lazygit.enable)
|
||||||
{
|
{
|
||||||
vim.startPlugins = lib.optionals (cfg.lazygit.package != null) [
|
vim.startPlugins = optionals (cfg.lazygit.package != null) [
|
||||||
cfg.lazygit.package
|
cfg.lazygit.package
|
||||||
];
|
];
|
||||||
vim.luaConfigRC.toggleterm-lazygit = nvim.dag.entryAfter ["toggleterm"] ''
|
vim.luaConfigRC.toggleterm-lazygit = entryAfter ["toggleterm"] ''
|
||||||
local terminal = require 'toggleterm.terminal'
|
local terminal = require 'toggleterm.terminal'
|
||||||
local lazygit = terminal.Terminal:new({
|
local lazygit = terminal.Terminal:new({
|
||||||
cmd = '${
|
cmd = '${
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
_: {
|
{
|
||||||
imports = [
|
imports = [
|
||||||
./toggleterm.nix
|
./toggleterm.nix
|
||||||
./config.nix
|
./config.nix
|
||||||
|
|
|
@ -1,29 +1,30 @@
|
||||||
{
|
{
|
||||||
pkgs,
|
pkgs,
|
||||||
config,
|
|
||||||
lib,
|
lib,
|
||||||
...
|
...
|
||||||
}: let
|
}: let
|
||||||
inherit (lib) mkEnableOption mkOption types mkMappingOption;
|
inherit (lib.options) mkOption mkEnableOption;
|
||||||
|
inherit (lib.nvim.binds) mkMappingOption;
|
||||||
|
inherit (lib.types) nullOr str enum bool package;
|
||||||
in {
|
in {
|
||||||
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 = {
|
||||||
open = mkOption {
|
open = mkOption {
|
||||||
type = types.nullOr types.str;
|
type = nullOr str;
|
||||||
description = "The keymapping to open toggleterm";
|
description = "The keymapping to open toggleterm";
|
||||||
default = "<c-t>";
|
default = "<c-t>";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
direction = mkOption {
|
direction = mkOption {
|
||||||
type = types.enum ["horizontal" "vertical" "tab" "float"];
|
type = enum ["horizontal" "vertical" "tab" "float"];
|
||||||
default = "horizontal";
|
default = "horizontal";
|
||||||
description = "Direction of the terminal";
|
description = "Direction of the terminal";
|
||||||
};
|
};
|
||||||
|
|
||||||
enable_winbar = mkOption {
|
enable_winbar = mkOption {
|
||||||
type = types.bool;
|
type = bool;
|
||||||
default = false;
|
default = false;
|
||||||
description = "Enable winbar";
|
description = "Enable winbar";
|
||||||
};
|
};
|
||||||
|
@ -31,13 +32,13 @@ in {
|
||||||
lazygit = {
|
lazygit = {
|
||||||
enable = mkEnableOption "LazyGit integration";
|
enable = mkEnableOption "LazyGit integration";
|
||||||
direction = mkOption {
|
direction = mkOption {
|
||||||
type = types.enum ["horizontal" "vertical" "tab" "float"];
|
type = enum ["horizontal" "vertical" "tab" "float"];
|
||||||
default = "float";
|
default = "float";
|
||||||
description = "Direction of the lazygit window";
|
description = "Direction of the lazygit window";
|
||||||
};
|
};
|
||||||
|
|
||||||
package = mkOption {
|
package = mkOption {
|
||||||
type = with types; nullOr package;
|
type = nullOr package;
|
||||||
default = pkgs.lazygit;
|
default = pkgs.lazygit;
|
||||||
description = "The package that should be used for lazygit. Setting it to null will attempt to use lazygit from your PATH";
|
description = "The package that should be used for lazygit. Setting it to null will attempt to use lazygit from your PATH";
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue