lualine: add winbar and inactive sections configs (#302)

Co-authored-by: Gaétan Lepage <33058747+GaetanLepage@users.noreply.github.com>
This commit is contained in:
André Vitor de Lima Matos 2023-04-01 05:42:18 -03:00 committed by GitHub
parent d62edf4178
commit 3d64fab719
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 186 additions and 105 deletions

View file

@ -12,73 +12,80 @@ with lib; let
leftDefault ? " ",
rightDefault ? " ",
name,
}: (
helpers.mkNullOrOption
(types.submodule {
options = {
left = helpers.defaultNullOpts.mkStr leftDefault "Left separator";
right = helpers.defaultNullOpts.mkStr rightDefault "Right separator";
};
})
"${name} separtors."
);
}:
helpers.mkCompositeOption "${name} separtors." {
left = helpers.defaultNullOpts.mkStr leftDefault "Left separator";
right = helpers.defaultNullOpts.mkStr rightDefault "Right separator";
};
mkComponentOptions = defaultName:
helpers.mkNullOrOption
(types.listOf (types.oneOf [
types.str
(types.submodule {
options = {
name = mkOption {
type = types.either types.str helpers.rawType;
description = "Component name or function";
default = defaultName;
};
(with types;
listOf (
either
str
(submodule {
options = {
name = mkOption {
type = types.either types.str helpers.rawType;
description = "Component name or function";
default = defaultName;
};
icons_enabled = helpers.defaultNullOpts.mkBool true ''
Enables the display of icons alongside the component.
'';
icons_enabled = helpers.defaultNullOpts.mkBool true ''
Enables the display of icons alongside the component.
'';
icon = helpers.mkNullOrOption types.str ''
Defines the icon to be displayed in front of the component.
'';
icon = helpers.mkNullOrOption types.str ''
Defines the icon to be displayed in front of the component.
'';
separator = mkSeparatorsOption {name = "Component";};
separator = mkSeparatorsOption {name = "Component";};
color = helpers.mkNullOrOption (types.attrsOf types.str) ''
Defines a custom color for the component.
'';
color = helpers.mkNullOrOption (types.attrsOf types.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";
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";
};
};
right = mkOption {
type = types.int;
description = "left padding";
};
};
})
)
"1"
"Adds padding to the left and right of components.";
})
)
"1"
"Adds padding to the left and right of components.";
extraConfig = mkOption {
type = types.attrs;
default = {};
description = "extra options for the component";
extraConfig = mkOption {
type = types.attrs;
default = {};
description = "extra options for the component";
};
};
};
})
]))
})
))
"";
mkEmptySectionOption = name:
helpers.mkCompositeOption name {
lualine_a = mkComponentOptions "";
lualine_b = mkComponentOptions "";
lualine_c = mkComponentOptions "";
lualine_x = mkComponentOptions "";
lualine_y = mkComponentOptions "";
lualine_z = mkComponentOptions "";
};
in {
options = {
plugins.lualine = {
@ -106,20 +113,15 @@ in {
name = "section";
};
disabledFiletypes =
helpers.mkNullOrOption
(types.submodule {
options = {
statusline = helpers.defaultNullOpts.mkNullable (types.str) "[]" ''
Only ignores the ft for statusline.
'';
disabledFiletypes = helpers.mkCompositeOption "Filetypes to disable lualine for." {
statusline = helpers.defaultNullOpts.mkNullable (types.str) "[]" ''
Only ignores the ft for statusline.
'';
winbar = helpers.defaultNullOpts.mkNullable (types.str) "[]" ''
Only ignores the ft for winbar.
'';
};
})
"Filetypes to disable lualine for.";
winbar = helpers.defaultNullOpts.mkNullable (types.str) "[]" ''
Only ignores the ft for winbar.
'';
};
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
@ -141,52 +143,45 @@ in {
'';
refresh =
helpers.mkNullOrOption
(types.submodule {
options = {
statusline = helpers.defaultNullOpts.mkInt 1000 "Refresh time for the status line (ms)";
tabline = helpers.defaultNullOpts.mkInt 1000 "Refresh time for the tabline (ms)";
winbar = helpers.defaultNullOpts.mkInt 1000 "Refresh time for the winbar (ms)";
};
})
helpers.mkCompositeOption
''
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.
'';
''
{
statusline = helpers.defaultNullOpts.mkInt 1000 "Refresh time for the status line (ms)";
sections =
helpers.mkNullOrOption
(types.submodule {
options = {
lualine_a = mkComponentOptions "mode";
lualine_b = mkComponentOptions "branch";
lualine_c = mkComponentOptions "filename";
tabline = helpers.defaultNullOpts.mkInt 1000 "Refresh time for the tabline (ms)";
lualine_x = mkComponentOptions "encoding";
lualine_y = mkComponentOptions "progress";
lualine_z = mkComponentOptions "location";
};
})
"Sections configuration";
winbar = helpers.defaultNullOpts.mkInt 1000 "Refresh time for the winbar (ms)";
};
tabline =
helpers.mkNullOrOption
(types.submodule {
options = {
lualine_a = mkComponentOptions "";
lualine_b = mkComponentOptions "";
lualine_c = mkComponentOptions "";
sections = helpers.mkCompositeOption "Sections configuration" {
lualine_a = mkComponentOptions "mode";
lualine_b = mkComponentOptions "branch";
lualine_c = mkComponentOptions "filename";
lualine_x = mkComponentOptions "";
lualine_y = mkComponentOptions "";
lualine_z = mkComponentOptions "";
};
})
"Tabline configuration";
lualine_x = mkComponentOptions "encoding";
lualine_y = mkComponentOptions "progress";
lualine_z = mkComponentOptions "location";
};
inactiveSections = helpers.mkCompositeOption "Inactive Sections configuration" {
lualine_a = mkComponentOptions "";
lualine_b = mkComponentOptions "";
lualine_c = mkComponentOptions "filename";
lualine_x = mkComponentOptions "location";
lualine_y = mkComponentOptions "";
lualine_z = mkComponentOptions "";
};
tabline = mkEmptySectionOption "Tabline configuration";
winbar = mkEmptySectionOption "Winbar configuration";
inactiveWinbar = mkEmptySectionOption "Inactive Winbar configuration";
extensions = mkOption {
type = types.nullOr (types.listOf types.str);
@ -227,13 +222,17 @@ in {
section_separators = cfg.sectionSeparators;
component_separators = cfg.componentSeparators;
disabled_filetypes = cfg.disabledFiletypes;
ignore_focus = cfg.ignoreFocus;
always_divide_middle = cfg.alwaysDivideMiddle;
globalstatus = cfg.globalstatus;
refresh = cfg.refresh;
};
sections = mapNullable processSections cfg.sections;
inactive_sections = mapNullable processSections cfg.inactiveSections;
tabline = mapNullable processSections cfg.tabline;
winbar = mapNullable processSections cfg.winbar;
inactive_winbar = mapNullable processSections cfg.inactiveWinbar;
extensions = cfg.extensions;
};
in

View file

@ -0,0 +1,82 @@
{
empty = {
plugins.lualine.enable = true;
};
defaults = {
plugins.lualine = {
enable = true;
iconsEnabled = true;
theme = "auto";
componentSeparators = {
left = "";
right = "";
};
sectionSeparators = {
left = "";
right = "";
};
alwaysDivideMiddle = true;
globalstatus = false;
refresh = {
statusline = 1000;
tabline = 1000;
winbar = 1000;
};
sections = {
lualine_a = ["mode"];
lualine_b = ["branch" "diff" "diagnostics"];
lualine_c = ["filename"];
lualine_x = ["encoding" "fileformat" "filetype"];
lualine_y = ["progress"];
lualine_z = ["location"];
};
inactiveSections = {
lualine_c = ["filename"];
lualine_x = ["location"];
};
};
};
example = {
plugins.lualine = {
enable = true;
ignoreFocus = ["NvimTree"];
sections = {
lualine_c = [
# you can specify only the sections you want to change
{
name = "filename";
extraConfig.newfile_status = true;
extraConfig.path = 1;
extraConfig.shorting_target = 60;
}
];
lualine_z = [
{name = "location";}
{name = "%L";} # total lines
];
};
tabline = {
lualine_a = [
{
name = "buffers";
extraConfig.mode = 4;
extraConfig.filetype_names = {
TelescopePrompt = "Telescope";
NvimTree = "NvimTree";
};
}
];
lualine_z = [
{
name = "tabs";
extraConfig.mode = 2;
}
];
};
extensions = ["nvim-tree"];
};
};
}