mirror of
https://github.com/nix-community/nixvim.git
synced 2025-06-21 08:35:43 +02:00
plugins/notify: add missing options + test
This commit is contained in:
parent
288e46e2d8
commit
ada99e5763
2 changed files with 165 additions and 51 deletions
|
@ -7,67 +7,150 @@
|
||||||
with lib; let
|
with lib; let
|
||||||
cfg = config.plugins.notify;
|
cfg = config.plugins.notify;
|
||||||
helpers = import ../helpers.nix {inherit lib;};
|
helpers = import ../helpers.nix {inherit lib;};
|
||||||
icon = mkOption {
|
|
||||||
type = types.nullOr types.str;
|
|
||||||
default = null;
|
|
||||||
};
|
|
||||||
in {
|
in {
|
||||||
options.plugins.notify = {
|
options.plugins.notify =
|
||||||
enable = mkEnableOption "notify";
|
helpers.extraOptionsOptions
|
||||||
|
// {
|
||||||
|
enable = mkEnableOption "nvim-notify";
|
||||||
|
|
||||||
package = helpers.mkPackageOption "notify" pkgs.vimPlugins.nvim-notify;
|
package = helpers.mkPackageOption "nvim-notify" pkgs.vimPlugins.nvim-notify;
|
||||||
|
|
||||||
stages = mkOption {
|
level =
|
||||||
type = types.nullOr (types.enum ["fade_in_slide_out" "fade" "slide" "static"]);
|
helpers.defaultNullOpts.mkNullable
|
||||||
description = "Animation style";
|
(
|
||||||
default = null;
|
with types;
|
||||||
};
|
oneOf [
|
||||||
timeout = mkOption {
|
ints.unsigned
|
||||||
type = types.nullOr types.int;
|
helpers.rawType
|
||||||
description = "Default timeout for notifications";
|
str
|
||||||
default = null;
|
]
|
||||||
};
|
)
|
||||||
backgroundColour = mkOption {
|
''{__raw = "vim.log.levels.INFO";}''
|
||||||
type = types.nullOr types.str;
|
"Minimum log level to display. See `vim.log.levels`.";
|
||||||
description = "For stages that change opacity this is treated as the highlight between the window";
|
|
||||||
default = null;
|
timeout = helpers.defaultNullOpts.mkUnsignedInt 5000 "Default timeout for notification.";
|
||||||
};
|
|
||||||
minimumWidth = mkOption {
|
maxWidth = helpers.mkNullOrOption (with types; either ints.unsigned helpers.rawType) ''
|
||||||
type = types.nullOr types.int;
|
Max number of columns for messages.
|
||||||
description = "Minimum width for notification windows";
|
'';
|
||||||
default = null;
|
|
||||||
};
|
maxHeight = helpers.mkNullOrOption (with types; either ints.unsigned helpers.rawType) ''
|
||||||
icons = mkOption {
|
Max number of lines for a message.
|
||||||
type = types.nullOr (types.submodule {
|
'';
|
||||||
options = {
|
|
||||||
error = icon;
|
stages =
|
||||||
warn = icon;
|
helpers.defaultNullOpts.mkNullable
|
||||||
info = icon;
|
(
|
||||||
debug = icon;
|
with types;
|
||||||
trace = icon;
|
either
|
||||||
};
|
(
|
||||||
});
|
enum
|
||||||
description = "Icons for the different levels";
|
[
|
||||||
default = {};
|
"fade"
|
||||||
|
"slide"
|
||||||
|
"fade_in_slide_out"
|
||||||
|
"static"
|
||||||
|
]
|
||||||
|
)
|
||||||
|
(listOf str)
|
||||||
|
)
|
||||||
|
"fade_in_slide_out"
|
||||||
|
''
|
||||||
|
Animation stages.
|
||||||
|
Can be either one of the builtin stages or an array of lua functions.
|
||||||
|
'';
|
||||||
|
|
||||||
|
backgroundColour = helpers.defaultNullOpts.mkStr "NotifyBackground" ''
|
||||||
|
For stages that change opacity this is treated as the highlight behind the window.
|
||||||
|
Set this to either a highlight group, an RGB hex value e.g. "#000000" or a function
|
||||||
|
returning an RGB code for dynamic values.
|
||||||
|
'';
|
||||||
|
|
||||||
|
icons =
|
||||||
|
mapAttrs
|
||||||
|
(
|
||||||
|
name: default:
|
||||||
|
helpers.defaultNullOpts.mkStr default "Icon for the ${name} level."
|
||||||
|
)
|
||||||
|
{
|
||||||
|
error = "";
|
||||||
|
warn = "";
|
||||||
|
info = "";
|
||||||
|
debug = "";
|
||||||
|
trace = "✎";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
onOpen = helpers.mkNullOrOption types.str ''
|
||||||
|
Function called when a new window is opened, use for changing win settings/config.
|
||||||
|
'';
|
||||||
|
|
||||||
|
onClose = helpers.mkNullOrOption types.str ''
|
||||||
|
Function called when a new window is closed.
|
||||||
|
'';
|
||||||
|
|
||||||
|
render =
|
||||||
|
helpers.defaultNullOpts.mkNullable
|
||||||
|
(
|
||||||
|
with types;
|
||||||
|
either
|
||||||
|
(enum ["default" "minimal"])
|
||||||
|
helpers.rawType
|
||||||
|
)
|
||||||
|
"default"
|
||||||
|
"Function to render a notification buffer or a built-in renderer name.";
|
||||||
|
|
||||||
|
minimumWidth = helpers.defaultNullOpts.mkUnsignedInt 50 ''
|
||||||
|
Minimum width for notification windows.
|
||||||
|
'';
|
||||||
|
|
||||||
|
fps = helpers.defaultNullOpts.mkPositiveInt 30 ''
|
||||||
|
Frames per second for animation stages, higher value means smoother animations but more CPU
|
||||||
|
usage.
|
||||||
|
'';
|
||||||
|
|
||||||
|
topDown = helpers.defaultNullOpts.mkBool true ''
|
||||||
|
Whether or not to position the notifications at the top or not.
|
||||||
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
config = let
|
config = let
|
||||||
setupOptions = with cfg; {
|
setupOptions = with cfg;
|
||||||
inherit stages timeout;
|
{
|
||||||
|
inherit
|
||||||
|
level
|
||||||
|
timeout
|
||||||
|
;
|
||||||
|
max_width = maxWidth;
|
||||||
|
max_height = maxHeight;
|
||||||
|
stages =
|
||||||
|
helpers.ifNonNull' stages
|
||||||
|
(
|
||||||
|
if isString stages
|
||||||
|
then stages
|
||||||
|
else map helpers.mkRaw stages
|
||||||
|
);
|
||||||
background_colour = backgroundColour;
|
background_colour = backgroundColour;
|
||||||
|
icons =
|
||||||
|
mapAttrs'
|
||||||
|
(
|
||||||
|
name: value: {
|
||||||
|
name = strings.toUpper name;
|
||||||
|
inherit value;
|
||||||
|
}
|
||||||
|
)
|
||||||
|
icons;
|
||||||
|
on_open = helpers.ifNonNull' onOpen (helpers.mkRaw onOpen);
|
||||||
|
on_close = helpers.ifNonNull' onClose (helpers.mkRaw onClose);
|
||||||
|
inherit render;
|
||||||
minimum_width = minimumWidth;
|
minimum_width = minimumWidth;
|
||||||
icons = with icons; {
|
inherit fps;
|
||||||
ERROR = error;
|
top_down = topDown;
|
||||||
WARN = warn;
|
}
|
||||||
INFO = info;
|
// cfg.extraOptions;
|
||||||
DEBUG = debug;
|
|
||||||
TRACE = trace;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
in
|
in
|
||||||
mkIf cfg.enable {
|
mkIf cfg.enable {
|
||||||
extraPlugins = [cfg.package];
|
extraPlugins = [cfg.package];
|
||||||
|
|
||||||
extraConfigLua = ''
|
extraConfigLua = ''
|
||||||
vim.notify = require('notify');
|
vim.notify = require('notify');
|
||||||
require('notify').setup(${helpers.toLuaObject setupOptions})
|
require('notify').setup(${helpers.toLuaObject setupOptions})
|
||||||
|
|
31
tests/test-sources/plugins/utils/notify.nix
Normal file
31
tests/test-sources/plugins/utils/notify.nix
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
{
|
||||||
|
empty = {
|
||||||
|
plugins.notify.enable = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
defaults = {
|
||||||
|
plugins.notify = {
|
||||||
|
enable = true;
|
||||||
|
|
||||||
|
level.__raw = "vim.log.levels.INFO";
|
||||||
|
timeout = 5000;
|
||||||
|
maxWidth = null;
|
||||||
|
maxHeight = null;
|
||||||
|
stages = "fade_in_slide_out";
|
||||||
|
backgroundColour = "NotifyBackground";
|
||||||
|
icons = {
|
||||||
|
error = "";
|
||||||
|
warn = "";
|
||||||
|
info = "";
|
||||||
|
debug = "";
|
||||||
|
trace = "✎";
|
||||||
|
};
|
||||||
|
onOpen = null;
|
||||||
|
onClose = null;
|
||||||
|
render = "default";
|
||||||
|
minimumWidth = 50;
|
||||||
|
fps = 30;
|
||||||
|
topDown = true;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue