mirror of
https://github.com/nix-community/nixvim.git
synced 2025-06-24 17:58:38 +02:00
helpers: Add option helpers for types that are either a lua str or a value (#876)
Those types needed the following code in apply: if builtins.isString value then mkRaw value else value This commit avoids this boilerplate, and clarifies that the `str` is lua code in the documentation.
This commit is contained in:
parent
8b8a1c0f4b
commit
8aa4b7e4ce
13 changed files with 109 additions and 129 deletions
|
@ -13,26 +13,24 @@ in {
|
|||
|
||||
package = helpers.mkPackageOption "toggleterm" pkgs.vimPlugins.toggleterm-nvim;
|
||||
|
||||
size =
|
||||
helpers.defaultNullOpts.mkNullable
|
||||
(with types; either number str) "12" ''
|
||||
Size of the terminal.
|
||||
`size` can be a number or function
|
||||
Example:
|
||||
```nix
|
||||
size = 20
|
||||
```
|
||||
OR
|
||||
```
|
||||
size = function(term)
|
||||
if term.direction == "horizontal" then
|
||||
return 15
|
||||
elseif term.direction == "vertical" then
|
||||
return vim.o.columns * 0.4
|
||||
end
|
||||
size = helpers.defaultNullOpts.mkStrLuaFnOr types.number "12" ''
|
||||
Size of the terminal.
|
||||
`size` can be a number or function
|
||||
Example:
|
||||
```nix
|
||||
size = 20
|
||||
```
|
||||
OR
|
||||
```
|
||||
size = function(term)
|
||||
if term.direction == "horizontal" then
|
||||
return 15
|
||||
elseif term.direction == "vertical" then
|
||||
return vim.o.columns * 0.4
|
||||
end
|
||||
```
|
||||
'';
|
||||
end
|
||||
```
|
||||
'';
|
||||
|
||||
openMapping = helpers.mkNullOrOption types.str ''
|
||||
Setting the open_mapping key to use for toggling the terminal(s) will set up mappings for
|
||||
|
@ -170,12 +168,7 @@ in {
|
|||
};
|
||||
config = let
|
||||
setupOptions = with cfg; {
|
||||
inherit autochdir highlights direction shell;
|
||||
size = helpers.ifNonNull' size (
|
||||
if isInt size
|
||||
then size
|
||||
else helpers.mkRaw size
|
||||
);
|
||||
inherit autochdir highlights direction shell size;
|
||||
open_mapping = helpers.ifNonNull' openMapping (helpers.mkRaw "[[${openMapping}]]");
|
||||
on_create = onCreate;
|
||||
on_open = onOpen;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue