mirror of
https://github.com/NotAShelf/nvf.git
synced 2025-11-12 16:35:30 +00:00
terminal/slides: add slides plugin
Add the terminal slides plugin to open markdown presentations in a floating terminal.
This commit is contained in:
parent
b92d9e7e26
commit
696fda23fe
3 changed files with 114 additions and 24 deletions
|
|
@ -203,6 +203,7 @@ isMaximal: {
|
||||||
toggleterm = {
|
toggleterm = {
|
||||||
enable = true;
|
enable = true;
|
||||||
lazygit.enable = true;
|
lazygit.enable = true;
|
||||||
|
slides.enable = true;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,39 +12,83 @@
|
||||||
|
|
||||||
cfg = config.vim.terminal.toggleterm;
|
cfg = config.vim.terminal.toggleterm;
|
||||||
lazygitMapDesc = "Open lazygit [toggleterm]";
|
lazygitMapDesc = "Open lazygit [toggleterm]";
|
||||||
|
slidesMapDesc = "Open slides [toggleterm]";
|
||||||
in {
|
in {
|
||||||
config = mkIf cfg.enable {
|
config = mkIf cfg.enable {
|
||||||
vim = {
|
vim = {
|
||||||
lazy.plugins.toggleterm-nvim = {
|
lazy.plugins.toggleterm-nvim = {
|
||||||
package = "toggleterm-nvim";
|
package = "toggleterm-nvim";
|
||||||
cmd = ["ToggleTerm" "ToggleTermSendCurrentLine" "ToggleTermSendVisualLines" "ToggleTermSendVisualSelection" "ToggleTermSetName" "ToggleTermToggleAll"];
|
cmd = [
|
||||||
|
"ToggleTerm"
|
||||||
|
"ToggleTermSendCurrentLine"
|
||||||
|
"ToggleTermSendVisualLines"
|
||||||
|
"ToggleTermSendVisualSelection"
|
||||||
|
"ToggleTermSetName"
|
||||||
|
"ToggleTermToggleAll"
|
||||||
|
];
|
||||||
keys =
|
keys =
|
||||||
[(mkKeymap "n" cfg.mappings.open "<Cmd>execute v:count . \"ToggleTerm\"<CR>" {desc = "Toggle terminal";})]
|
[
|
||||||
|
(mkKeymap "n" cfg.mappings.open "<Cmd>execute v:count . \"ToggleTerm\"<CR>" {
|
||||||
|
desc = "Toggle terminal";
|
||||||
|
})
|
||||||
|
]
|
||||||
++ optional cfg.lazygit.enable {
|
++ optional cfg.lazygit.enable {
|
||||||
key = cfg.lazygit.mappings.open;
|
key = cfg.lazygit.mappings.open;
|
||||||
mode = "n";
|
mode = "n";
|
||||||
desc = lazygitMapDesc;
|
desc = lazygitMapDesc;
|
||||||
|
}
|
||||||
|
++ optional cfg.slides.enable {
|
||||||
|
key = cfg.slides.mappings.open;
|
||||||
|
mode = "n";
|
||||||
|
desc = slidesMapDesc;
|
||||||
};
|
};
|
||||||
|
|
||||||
setupModule = "toggleterm";
|
setupModule = "toggleterm";
|
||||||
inherit (cfg) setupOpts;
|
inherit (cfg) setupOpts;
|
||||||
after = optionalString cfg.lazygit.enable ''
|
after =
|
||||||
local terminal = require 'toggleterm.terminal'
|
optionalString cfg.lazygit.enable ''
|
||||||
local lazygit = terminal.Terminal:new({
|
local terminal = require 'toggleterm.terminal'
|
||||||
cmd = '${
|
local lazygit = terminal.Terminal:new({
|
||||||
if (cfg.lazygit.package != null)
|
cmd = '${
|
||||||
then getExe cfg.lazygit.package
|
if (cfg.lazygit.package != null)
|
||||||
else "lazygit"
|
then getExe cfg.lazygit.package
|
||||||
}',
|
else "lazygit"
|
||||||
direction = '${cfg.lazygit.direction}',
|
}',
|
||||||
hidden = true,
|
direction = '${cfg.lazygit.direction}',
|
||||||
on_open = function(term)
|
hidden = true,
|
||||||
vim.cmd("startinsert!")
|
on_open = function(term)
|
||||||
end
|
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}'})
|
||||||
|
'';
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -5,14 +5,31 @@
|
||||||
}: 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 either int;
|
inherit
|
||||||
|
(lib.types)
|
||||||
|
nullOr
|
||||||
|
str
|
||||||
|
enum
|
||||||
|
bool
|
||||||
|
package
|
||||||
|
either
|
||||||
|
int
|
||||||
|
;
|
||||||
inherit (lib.modules) mkRenamedOptionModule;
|
inherit (lib.modules) mkRenamedOptionModule;
|
||||||
inherit (lib.nvim.types) mkPluginSetupOption luaInline;
|
inherit (lib.nvim.types) mkPluginSetupOption luaInline;
|
||||||
inherit (lib.generators) mkLuaInline;
|
inherit (lib.generators) mkLuaInline;
|
||||||
in {
|
in {
|
||||||
imports = [
|
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 = {
|
options.vim.terminal.toggleterm = {
|
||||||
|
|
@ -27,7 +44,12 @@ in {
|
||||||
|
|
||||||
setupOpts = mkPluginSetupOption "ToggleTerm" {
|
setupOpts = mkPluginSetupOption "ToggleTerm" {
|
||||||
direction = mkOption {
|
direction = mkOption {
|
||||||
type = 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";
|
||||||
};
|
};
|
||||||
|
|
@ -52,7 +74,11 @@ in {
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
winbar = {
|
winbar = {
|
||||||
enabled = mkEnableOption "winbar in terminal" // {default = true;};
|
enabled =
|
||||||
|
mkEnableOption "winbar in terminal"
|
||||||
|
// {
|
||||||
|
default = true;
|
||||||
|
};
|
||||||
name_formatter = mkOption {
|
name_formatter = mkOption {
|
||||||
type = luaInline;
|
type = luaInline;
|
||||||
description = "Winbar formatter function.";
|
description = "Winbar formatter function.";
|
||||||
|
|
@ -68,7 +94,12 @@ in {
|
||||||
lazygit = {
|
lazygit = {
|
||||||
enable = mkEnableOption "LazyGit integration";
|
enable = mkEnableOption "LazyGit integration";
|
||||||
direction = mkOption {
|
direction = mkOption {
|
||||||
type = 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";
|
||||||
};
|
};
|
||||||
|
|
@ -83,5 +114,19 @@ in {
|
||||||
open = mkMappingOption "Open lazygit [toggleterm]" "<leader>gg";
|
open = mkMappingOption "Open lazygit [toggleterm]" "<leader>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]" "<leader>ss";
|
||||||
|
};
|
||||||
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue