diff --git a/modules/terminal/default.nix b/modules/terminal/default.nix index c8bbc22..a268e8b 100644 --- a/modules/terminal/default.nix +++ b/modules/terminal/default.nix @@ -1,4 +1,4 @@ -_: { +{ imports = [ ./toggleterm ]; diff --git a/modules/terminal/toggleterm/config.nix b/modules/terminal/toggleterm/config.nix index eca6e60..1ffec58 100644 --- a/modules/terminal/toggleterm/config.nix +++ b/modules/terminal/toggleterm/config.nix @@ -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 "execute v:count . \"ToggleTerm\"" "Toggle terminal"; + maps.normal = mkBinding cfg.mappings.open "execute v:count . \"ToggleTerm\"" "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 = '${ diff --git a/modules/terminal/toggleterm/default.nix b/modules/terminal/toggleterm/default.nix index a540f3f..093dc0d 100644 --- a/modules/terminal/toggleterm/default.nix +++ b/modules/terminal/toggleterm/default.nix @@ -1,4 +1,4 @@ -_: { +{ imports = [ ./toggleterm.nix ./config.nix diff --git a/modules/terminal/toggleterm/toggleterm.nix b/modules/terminal/toggleterm/toggleterm.nix index 3579063..dbc8e54 100644 --- a/modules/terminal/toggleterm/toggleterm.nix +++ b/modules/terminal/toggleterm/toggleterm.nix @@ -1,29 +1,30 @@ { pkgs, - config, lib, ... }: 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 { options.vim.terminal.toggleterm = { enable = mkEnableOption "toggleterm as a replacement to built-in terminal command"; mappings = { open = mkOption { - type = types.nullOr types.str; + type = nullOr str; description = "The keymapping to open toggleterm"; default = ""; }; }; direction = mkOption { - type = types.enum ["horizontal" "vertical" "tab" "float"]; + type = enum ["horizontal" "vertical" "tab" "float"]; default = "horizontal"; description = "Direction of the terminal"; }; enable_winbar = mkOption { - type = types.bool; + type = bool; default = false; description = "Enable winbar"; }; @@ -31,13 +32,13 @@ in { lazygit = { enable = mkEnableOption "LazyGit integration"; direction = mkOption { - type = types.enum ["horizontal" "vertical" "tab" "float"]; + type = enum ["horizontal" "vertical" "tab" "float"]; default = "float"; description = "Direction of the lazygit window"; }; package = mkOption { - type = with types; nullOr package; + type = nullOr package; default = pkgs.lazygit; description = "The package that should be used for lazygit. Setting it to null will attempt to use lazygit from your PATH"; };