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:
traxys 2024-01-02 00:30:10 +01:00 committed by GitHub
parent 8b8a1c0f4b
commit 8aa4b7e4ce
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 109 additions and 129 deletions

View file

@ -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;