mirror of
https://github.com/nix-community/nixvim.git
synced 2025-06-28 11:30:06 +02:00
plugins/floaterm: refactor (#187)
This commit is contained in:
parent
a1b410192e
commit
f37abc3ce4
1 changed files with 176 additions and 85 deletions
|
@ -1,90 +1,181 @@
|
||||||
{
|
{
|
||||||
config,
|
|
||||||
pkgs,
|
pkgs,
|
||||||
lib,
|
lib,
|
||||||
...
|
...
|
||||||
}:
|
} @ args:
|
||||||
with lib; let
|
with lib;
|
||||||
cfg = config.plugins.floaterm;
|
with import ../helpers.nix {inherit lib;};
|
||||||
helpers = import ../helpers.nix {inherit lib;};
|
{
|
||||||
in {
|
imports = let
|
||||||
options = {
|
optionWarnings = import ../../lib/option-warnings.nix args;
|
||||||
plugins.floaterm = {
|
basePluginPath = ["plugins" "floaterm"];
|
||||||
enable = mkEnableOption "floaterm";
|
in [
|
||||||
|
(optionWarnings.mkRenamedOption {
|
||||||
package = helpers.mkPackageOption "floaterm" pkgs.vimPlugins.vim-floaterm;
|
option = basePluginPath ++ ["winType"];
|
||||||
|
newOption = basePluginPath ++ ["wintype"];
|
||||||
shell = mkOption {
|
})
|
||||||
type = types.nullOr types.str;
|
(optionWarnings.mkRenamedOption {
|
||||||
default = null;
|
option = basePluginPath ++ ["winWidth"];
|
||||||
};
|
newOption = basePluginPath ++ ["width"];
|
||||||
title = mkOption {
|
})
|
||||||
type = types.nullOr types.str;
|
(optionWarnings.mkRenamedOption {
|
||||||
description = "Show floaterm info at the top left corner of the floaterm window.";
|
option = basePluginPath ++ ["winHeight"];
|
||||||
default = null;
|
newOption = basePluginPath ++ ["height"];
|
||||||
};
|
})
|
||||||
winType = mkOption {
|
(optionWarnings.mkRenamedOption {
|
||||||
type = types.nullOr (types.enum ["float" "split" "vsplit"]);
|
option = basePluginPath ++ ["borderChars"];
|
||||||
default = null;
|
newOption = basePluginPath ++ ["borderchars"];
|
||||||
};
|
})
|
||||||
winWidth = mkOption {
|
|
||||||
type = types.nullOr types.float;
|
|
||||||
description = "number of columns relative to &columns.";
|
|
||||||
default = null;
|
|
||||||
};
|
|
||||||
winHeight = mkOption {
|
|
||||||
type = types.nullOr types.float;
|
|
||||||
description = "number of lines relative to &lines.";
|
|
||||||
default = null;
|
|
||||||
};
|
|
||||||
borderChars = mkOption {
|
|
||||||
type = types.nullOr types.str;
|
|
||||||
description = "8 characters of the floating window border (top, right, bottom, left, topleft, topright, botright, botleft)";
|
|
||||||
default = null;
|
|
||||||
};
|
|
||||||
rootMarkers = mkOption {
|
|
||||||
type = types.nullOr (types.listOf types.str);
|
|
||||||
description = "Markers used to detect the project root directory for --cwd=<root>";
|
|
||||||
default = null;
|
|
||||||
};
|
|
||||||
opener = mkOption {
|
|
||||||
type = types.nullOr (types.enum ["edit" "split" "vsplit" "tabe" "drop"]);
|
|
||||||
description = "Command used for opening a file in the outside nvim from within :terminal";
|
|
||||||
default = null;
|
|
||||||
};
|
|
||||||
autoClose = mkOption {
|
|
||||||
type = types.nullOr (types.enum [0 1 2]);
|
|
||||||
description = "Whether to close floaterm window once the job gets finished.";
|
|
||||||
default = null;
|
|
||||||
};
|
|
||||||
autoHide = mkOption {
|
|
||||||
type = types.nullOr (types.enum [0 1 2]);
|
|
||||||
description = "Whether to hide previous floaterm before switching to or opening another one.";
|
|
||||||
default = null;
|
|
||||||
};
|
|
||||||
autoInsert = mkOption {
|
|
||||||
type = types.nullOr types.bool;
|
|
||||||
description = "Whether to enter Terminal-mode after opening a floaterm.";
|
|
||||||
default = null;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
config = mkIf cfg.enable {
|
|
||||||
extraPlugins = [
|
|
||||||
cfg.package
|
|
||||||
];
|
];
|
||||||
globals = {
|
}
|
||||||
floaterm_shell = mkIf (!isNull cfg.shell) cfg.shell;
|
// mkPlugin args {
|
||||||
floaterm_title = mkIf (!isNull cfg.title) cfg.title;
|
name = "floaterm";
|
||||||
floaterm_wintype = mkIf (!isNull cfg.winType) cfg.winType;
|
description = "floaterm";
|
||||||
floaterm_width = mkIf (!isNull cfg.winWidth) cfg.winWidth;
|
package = pkgs.vimPlugins.vim-floaterm;
|
||||||
floaterm_height = mkIf (!isNull cfg.winHeight) cfg.winHeight;
|
|
||||||
floaterm_borderchars = mkIf (!isNull cfg.borderChars) cfg.borderChars;
|
options =
|
||||||
floaterm_rootmarkers = mkIf (!isNull cfg.rootMarkers) cfg.rootMarkers;
|
mapAttrs (name: value:
|
||||||
floaterm_opener = mkIf (!isNull cfg.opener) cfg.opener;
|
mkDefaultOpt {
|
||||||
floaterm_autoclose = mkIf (!isNull cfg.autoClose) cfg.autoClose;
|
global = "floaterm_${value.name}";
|
||||||
floaterm_autohide = mkIf (!isNull cfg.autoHide) cfg.autoHide;
|
inherit (value) type description;
|
||||||
floaterm_autoInsert = mkIf (!isNull cfg.autoInsert) cfg.autoInsert;
|
})
|
||||||
|
{
|
||||||
|
shell = {
|
||||||
|
type = types.str;
|
||||||
|
description = "";
|
||||||
|
};
|
||||||
|
|
||||||
|
title = {
|
||||||
|
type = types.str;
|
||||||
|
description = ''
|
||||||
|
Show floaterm info (e.g., 'floaterm: 1/3' implies there are 3 floaterms in total and the
|
||||||
|
current is the first one) at the top left corner of floaterm window.
|
||||||
|
|
||||||
|
Default: 'floaterm: $1/$2'($1 and $2 will be substituted by 'the index of the current
|
||||||
|
floaterm' and 'the count of all floaterms' respectively)
|
||||||
|
|
||||||
|
Example: 'floaterm($1|$2)'
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
wintype = {
|
||||||
|
type = types.enum ["float" "split" "vsplit"];
|
||||||
|
description = ''
|
||||||
|
'float'(nvim's floating or vim's popup) by default.
|
||||||
|
Set it to 'split' or 'vsplit' if you don't want to use floating or popup window.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
width = {
|
||||||
|
type = types.either types.int types.float;
|
||||||
|
description = ''
|
||||||
|
Int (number of columns) or float (between 0 and 1).
|
||||||
|
if float, the width is relative to &columns.
|
||||||
|
|
||||||
|
Default: 0.6
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
height = {
|
||||||
|
type = types.either types.int types.float;
|
||||||
|
description = ''
|
||||||
|
Int (number of columns) or float (between 0 and 1).
|
||||||
|
if float, the height is relative to &lines.
|
||||||
|
|
||||||
|
Default: 0.6
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
position = {
|
||||||
|
type = types.str;
|
||||||
|
description = ''
|
||||||
|
The position of the floating window.
|
||||||
|
|
||||||
|
Available values:
|
||||||
|
- If wintype is `split`/`vsplit`: 'leftabove', 'aboveleft', 'rightbelow', 'belowright', 'topleft', 'botright'.
|
||||||
|
Default: 'botright'.
|
||||||
|
|
||||||
|
- If wintype is float: 'top', 'bottom', 'left', 'right', 'topleft', 'topright', 'bottomleft', 'bottomright', 'center', 'auto' (at the cursor place).
|
||||||
|
Default: 'center'
|
||||||
|
|
||||||
|
In addition, there is another option 'random' which allows to pick a random position from
|
||||||
|
above when (re)opening a floaterm window.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
borderchars = {
|
||||||
|
type = types.str;
|
||||||
|
description = ''
|
||||||
|
The position of the floating window.
|
||||||
|
|
||||||
|
8 characters of the floating window border (top, right, bottom, left, topleft, topright, botright, botleft).
|
||||||
|
|
||||||
|
Default: "─│─│┌┐┘└"
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
rootmarkers = {
|
||||||
|
type = types.listOf types.str;
|
||||||
|
description = ''
|
||||||
|
|
||||||
|
Markers used to detect the project root directory for --cwd=<root>
|
||||||
|
|
||||||
|
Default: [".project" ".git" ".hg" ".svn" ".root"]
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
giteditor = {
|
||||||
|
type = types.bool;
|
||||||
|
description = ''
|
||||||
|
Whether to override $GIT_EDITOR in floaterm terminals so git commands can open open an
|
||||||
|
editor in the same neovim instance.
|
||||||
|
|
||||||
|
Default: true
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
opener = {
|
||||||
|
type = types.enum ["edit" "split" "vsplit" "tabe" "drop"];
|
||||||
|
description = ''
|
||||||
|
Command used for opening a file in the outside nvim from within `:terminal`.
|
||||||
|
|
||||||
|
Default: 'split'
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
autoclose = {
|
||||||
|
type = types.enum [0 1 2];
|
||||||
|
description = ''
|
||||||
|
Whether to close floaterm window once the job gets finished.
|
||||||
|
|
||||||
|
- 0: Always do NOT close floaterm window
|
||||||
|
- 1: Close window if the job exits normally, otherwise stay it with messages like [Process exited 101]
|
||||||
|
- 2: Always close floaterm window
|
||||||
|
|
||||||
|
Default: 1
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
autohide = {
|
||||||
|
type = types.enum [0 1 2];
|
||||||
|
description = ''
|
||||||
|
Whether to hide previous floaterms before switching to or opening a another one.
|
||||||
|
|
||||||
|
- 0: Always do NOT hide previous floaterm windows
|
||||||
|
- 1: Only hide those whose position (b:floaterm_position) is identical to that of the floaterm which will be opened
|
||||||
|
- 2: Always hide them
|
||||||
|
|
||||||
|
Default: 1
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
autoinsert = {
|
||||||
|
type = types.bool;
|
||||||
|
description = ''
|
||||||
|
Whether to enter Terminal-mode after opening a floaterm.
|
||||||
|
|
||||||
|
Default: true
|
||||||
|
'';
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue