plugins/statuslines/lualine: refactoring (#198)

This commit is contained in:
Gaétan Lepage 2023-02-25 14:23:54 +01:00 committed by GitHub
parent 29764b28af
commit 401f6fb572
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -7,55 +7,78 @@
with lib; let with lib; let
cfg = config.plugins.lualine; cfg = config.plugins.lualine;
helpers = import ../helpers.nix {inherit lib;}; helpers = import ../helpers.nix {inherit lib;};
separators = mkOption {
type = types.nullOr (types.submodule { mkSeparatorsOption = {
leftDefault ? " ",
rightDefault ? " ",
name,
}: (
helpers.mkNullOrOption
(types.submodule {
options = { options = {
left = mkOption { left = helpers.defaultNullOpts.mkStr leftDefault "Left separator";
default = " "; right = helpers.defaultNullOpts.mkStr rightDefault "Right separator";
type = types.str;
description = "left separator";
};
right = mkOption {
default = " ";
type = types.str;
description = "right separator";
};
}; };
}); })
default = null; "${name} separtors."
}; );
component_options = defaultName:
mkOption { mkComponentOptions = defaultName:
type = types.nullOr (types.listOf (types.oneOf [ helpers.mkNullOrOption
types.str (types.listOf (types.oneOf [
(types.submodule { types.str
options = { (types.submodule {
name = mkOption { options = {
type = types.str; name = mkOption {
description = "component name"; type = types.either types.str helpers.rawType;
default = defaultName; description = "Component name or function";
}; default = defaultName;
icons_enabled = mkOption {
type = types.enum ["True" "False"];
default = "True";
description = "displays icons in alongside component";
};
icon = mkOption {
type = types.nullOr types.str;
default = null;
description = "displays icon in front of the component";
};
separator = separators;
extraConfig = mkOption {
type = types.attrs;
default = {};
description = "extra options for the component";
};
}; };
})
])); icons_enabled = helpers.defaultNullOpts.mkBool true ''
default = null; Enables the display of icons alongside the component.
}; '';
icon = helpers.mkNullOrOption types.str ''
Defines the icon to be displayed in front of the component.
'';
separator = mkSeparatorsOption {name = "Component";};
color = helpers.mkNullOrOption (with types; either str (attrsOf str)) ''
Defines a custom color for the component.
'';
padding =
helpers.defaultNullOpts.mkNullable
(
types.either
types.int
(types.submodule {
options = {
left = mkOption {
type = types.int;
description = "left padding";
};
right = mkOption {
type = types.int;
description = "left padding";
};
};
})
)
"1"
"Adds padding to the left and right of components.";
extraConfig = mkOption {
type = types.attrs;
default = {};
description = "extra options for the component";
};
};
})
]))
"";
in { in {
options = { options = {
plugins.lualine = { plugins.lualine = {
@ -63,58 +86,102 @@ in {
package = helpers.mkPackageOption "lualine" pkgs.vimPlugins.lualine-nvim; package = helpers.mkPackageOption "lualine" pkgs.vimPlugins.lualine-nvim;
theme = mkOption { theme = helpers.defaultNullOpts.mkStr "auto" "The theme to use for lualine-nvim.";
default = config.colorscheme;
type = types.nullOr types.str; componentSeparators = mkSeparatorsOption {
description = "The theme to use for lualine-nvim."; leftDefault = "";
rightDefault = "";
name = "component";
}; };
sectionSeparators = separators; sectionSeparators = mkSeparatorsOption {
componentSeparators = separators; leftDefault = "";
rightDefault = "";
disabledFiletypes = mkOption { name = "section";
type = types.nullOr (types.listOf types.str);
default = null;
example = ''[ "lua" ]'';
description = "filetypes to disable lualine on";
}; };
alwaysDivideMiddle = mkOption { disabledFiletypes =
type = types.nullOr types.bool; helpers.mkNullOrOption
default = null; (types.submodule {
description = "When true, left_sections (a,b,c) can't take over entire statusline";
};
sections = mkOption {
type = types.nullOr (types.submodule ({...}: {
options = { options = {
lualine_a = component_options "mode"; statusline = helpers.defaultNullOpts.mkNullable (types.str) "[]" ''
lualine_b = component_options "branch"; Only ignores the ft for statusline.
lualine_c = component_options "filename"; '';
lualine_x = component_options "encoding"; winbar = helpers.defaultNullOpts.mkNullable (types.str) "[]" ''
lualine_y = component_options "progress"; Only ignores the ft for winbar.
lualine_z = component_options "location"; '';
}; };
})); })
"Filetypes to disable lualine for.";
default = null; ignoreFocus = helpers.defaultNullOpts.mkNullable (types.listOf types.str) "[]" ''
}; If current filetype is in this list it'll always be drawn as inactive statusline and the
last window will be drawn as active statusline.
tabline = mkOption { For example if you don't want statusline of your file tree / sidebar window to have active
type = types.nullOr (types.submodule ({...}: { statusline you can add their filetypes here.
'';
alwaysDivideMiddle = helpers.defaultNullOpts.mkBool true ''
When set to true, left sections i.e. 'a','b' and 'c' can't take over the entire statusline
even if neither of 'x', 'y' or 'z' are present.
'';
globalstatus = helpers.defaultNullOpts.mkBool false ''
Enable global statusline (have a single statusline at bottom of neovim instead of one for
every window).
This feature is only available in neovim 0.7 and higher.
'';
refresh =
helpers.mkNullOrOption
(types.submodule {
options = { options = {
lualine_a = component_options ""; statusline = helpers.defaultNullOpts.mkInt 1000 "Refresh time for the status line (ms)";
lualine_b = component_options "";
lualine_c = component_options "";
lualine_x = component_options ""; tabline = helpers.defaultNullOpts.mkInt 1000 "Refresh time for the tabline (ms)";
lualine_y = component_options "";
lualine_z = component_options ""; winbar = helpers.defaultNullOpts.mkInt 1000 "Refresh time for the winbar (ms)";
}; };
})); })
default = null; ''
}; Sets how often lualine should refresh it's contents (in ms).
The refresh option sets minimum time that lualine tries to maintain between refresh.
It's not guarantied if situation arises that lualine needs to refresh itself before this
time it'll do it.
'';
sections =
helpers.mkNullOrOption
(types.submodule {
options = {
lualine_a = mkComponentOptions "mode";
lualine_b = mkComponentOptions "branch";
lualine_c = mkComponentOptions "filename";
lualine_x = mkComponentOptions "encoding";
lualine_y = mkComponentOptions "progress";
lualine_z = mkComponentOptions "location";
};
})
"Sections configuration";
tabline =
helpers.mkNullOrOption
(types.submodule {
options = {
lualine_a = mkComponentOptions "";
lualine_b = mkComponentOptions "";
lualine_c = mkComponentOptions "";
lualine_x = mkComponentOptions "";
lualine_y = mkComponentOptions "";
lualine_z = mkComponentOptions "";
};
})
"Tabline configuration";
extensions = mkOption { extensions = mkOption {
type = types.nullOr (types.listOf types.str); type = types.nullOr (types.listOf types.str);
default = null; default = null;
@ -136,12 +203,14 @@ in {
icons_enabled, icons_enabled,
icon, icon,
separator, separator,
color,
padding,
extraConfig, extraConfig,
}: }:
mergeAttrs mergeAttrs
{ {
"@" = name; "@" = name;
inherit icons_enabled icon separator; inherit icons_enabled icon separator color padding;
} }
extraConfig; extraConfig;
processSections = sections: mapAttrs (_: mapNullable (map processComponent)) sections; processSections = sections: mapAttrs (_: mapNullable (map processComponent)) sections;
@ -152,6 +221,8 @@ in {
component_separators = cfg.componentSeparators; component_separators = cfg.componentSeparators;
disabled_filetypes = cfg.disabledFiletypes; disabled_filetypes = cfg.disabledFiletypes;
always_divide_middle = cfg.alwaysDivideMiddle; always_divide_middle = cfg.alwaysDivideMiddle;
globalstatus = cfg.globalstatus;
refresh = cfg.refresh;
}; };
sections = mapNullable processSections cfg.sections; sections = mapNullable processSections cfg.sections;