diff --git a/configuration.nix b/configuration.nix index 78dad9c7..f9b96e53 100644 --- a/configuration.nix +++ b/configuration.nix @@ -203,6 +203,7 @@ isMaximal: { toggleterm = { enable = true; lazygit.enable = true; + slides.enable = true; }; }; diff --git a/modules/plugins/terminal/toggleterm/config.nix b/modules/plugins/terminal/toggleterm/config.nix index 280f29d2..2f9732c1 100644 --- a/modules/plugins/terminal/toggleterm/config.nix +++ b/modules/plugins/terminal/toggleterm/config.nix @@ -12,39 +12,83 @@ cfg = config.vim.terminal.toggleterm; lazygitMapDesc = "Open lazygit [toggleterm]"; + slidesMapDesc = "Open slides [toggleterm]"; in { config = mkIf cfg.enable { vim = { lazy.plugins.toggleterm-nvim = { package = "toggleterm-nvim"; - cmd = ["ToggleTerm" "ToggleTermSendCurrentLine" "ToggleTermSendVisualLines" "ToggleTermSendVisualSelection" "ToggleTermSetName" "ToggleTermToggleAll"]; + cmd = [ + "ToggleTerm" + "ToggleTermSendCurrentLine" + "ToggleTermSendVisualLines" + "ToggleTermSendVisualSelection" + "ToggleTermSetName" + "ToggleTermToggleAll" + ]; keys = - [(mkKeymap "n" cfg.mappings.open "execute v:count . \"ToggleTerm\"" {desc = "Toggle terminal";})] + [ + (mkKeymap "n" cfg.mappings.open "execute v:count . \"ToggleTerm\"" { + desc = "Toggle terminal"; + }) + ] ++ optional cfg.lazygit.enable { key = cfg.lazygit.mappings.open; mode = "n"; desc = lazygitMapDesc; + } + ++ optional cfg.slides.enable { + key = cfg.slides.mappings.open; + mode = "n"; + desc = slidesMapDesc; }; setupModule = "toggleterm"; inherit (cfg) setupOpts; - after = optionalString cfg.lazygit.enable '' - local terminal = require 'toggleterm.terminal' - local lazygit = terminal.Terminal:new({ - cmd = '${ - if (cfg.lazygit.package != null) - then getExe cfg.lazygit.package - else "lazygit" - }', - direction = '${cfg.lazygit.direction}', - hidden = true, - on_open = function(term) - vim.cmd("startinsert!") - end - }) + after = + optionalString cfg.lazygit.enable '' + local terminal = require 'toggleterm.terminal' + local lazygit = terminal.Terminal:new({ + cmd = '${ + if (cfg.lazygit.package != null) + then getExe cfg.lazygit.package + else "lazygit" + }', + direction = '${cfg.lazygit.direction}', + hidden = true, + on_open = function(term) + vim.cmd("startinsert!") + end + }) - vim.keymap.set('n', ${toLuaObject cfg.lazygit.mappings.open}, function() lazygit:toggle() end, {silent = true, noremap = true, desc = '${lazygitMapDesc}'}) - ''; + vim.keymap.set('n', ${toLuaObject cfg.lazygit.mappings.open}, function() lazygit:toggle() end, {silent = true, noremap = true, desc = '${lazygitMapDesc}'}) + '' + + optionalString cfg.slides.enable '' + local terminal = require 'toggleterm.terminal' + + local file_path = vim.fn.expand("%:p") + + if file_path == "" then + print("No file open") + return + end + + local slides = terminal.Terminal:new({ + cmd = '${ + if (cfg.slides.package != null) + then getExe cfg.slides.package + else "slides" + } ' .. file_path, + direction = 'float', + hidden = true, + close_on_exit = true, + on_open = function(term) + vim.cmd("startinsert!") + end + }) + + vim.keymap.set('n', ${toLuaObject cfg.slides.mappings.open}, function() slides:toggle() end, {silent = true, noremap = true, desc = '${slidesMapDesc}'}) + ''; }; }; }; diff --git a/modules/plugins/terminal/toggleterm/toggleterm.nix b/modules/plugins/terminal/toggleterm/toggleterm.nix index d6c25c1b..cbb7a42e 100644 --- a/modules/plugins/terminal/toggleterm/toggleterm.nix +++ b/modules/plugins/terminal/toggleterm/toggleterm.nix @@ -5,14 +5,31 @@ }: let inherit (lib.options) mkOption mkEnableOption; inherit (lib.nvim.binds) mkMappingOption; - inherit (lib.types) nullOr str enum bool package either int; + inherit + (lib.types) + nullOr + str + enum + bool + package + either + int + ; inherit (lib.modules) mkRenamedOptionModule; inherit (lib.nvim.types) mkPluginSetupOption luaInline; inherit (lib.generators) mkLuaInline; in { imports = [ - (mkRenamedOptionModule ["vim" "terminal" "toggleterm" "direction"] ["vim" "terminal" "toggleterm" "setupOpts" "direction"]) - (mkRenamedOptionModule ["vim" "terminal" "toggleterm" "enable_winbar"] ["vim" "terminal" "toggleterm" "setupOpts" "enable_winbar"]) + ( + 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 = { @@ -27,7 +44,12 @@ in { setupOpts = mkPluginSetupOption "ToggleTerm" { direction = mkOption { - type = enum ["horizontal" "vertical" "tab" "float"]; + type = enum [ + "horizontal" + "vertical" + "tab" + "float" + ]; default = "horizontal"; description = "Direction of the terminal"; }; @@ -52,7 +74,11 @@ in { ''; }; winbar = { - enabled = mkEnableOption "winbar in terminal" // {default = true;}; + enabled = + mkEnableOption "winbar in terminal" + // { + default = true; + }; name_formatter = mkOption { type = luaInline; description = "Winbar formatter function."; @@ -68,7 +94,12 @@ in { lazygit = { enable = mkEnableOption "LazyGit integration"; direction = mkOption { - type = enum ["horizontal" "vertical" "tab" "float"]; + type = enum [ + "horizontal" + "vertical" + "tab" + "float" + ]; default = "float"; description = "Direction of the lazygit window"; }; @@ -83,5 +114,19 @@ in { open = mkMappingOption "Open lazygit [toggleterm]" "gg"; }; }; + + slides = { + enable = mkEnableOption "Slides integration"; + + package = mkOption { + type = nullOr package; + default = pkgs.slides; + description = "The package that should be used for slides. Setting it to null will attempt to use slides from your PATH"; + }; + + mappings = { + open = mkMappingOption "Open slides [toggleterm]" "ss"; + }; + }; }; }