Skip to content

Commit

Permalink
statusline/lualine: extensible sections
Browse files Browse the repository at this point in the history
This adds extraActiveSection and extraInactiveSection to the lualine
options to make it possible to easily extend the defaults with
additional sections. We're also changing the exposed type of the
*activeSection attributes from `str` to `listOf str`.
  • Loading branch information
ksonj committed Oct 23, 2023
1 parent 2b48b6d commit 11a974a
Show file tree
Hide file tree
Showing 2 changed files with 140 additions and 65 deletions.
25 changes: 13 additions & 12 deletions modules/statusline/lualine/config.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
}:
with lib; let
cfg = config.vim.statusline.lualine;
luaTable = items: ''{${builtins.concatStringsSep "," items}}'';
in {
config = (mkIf cfg.enable) {
vim.startPlugins = [
Expand Down Expand Up @@ -32,21 +33,21 @@ in {
},
-- active sections
sections = {
lualine_a = ${cfg.activeSection.a},
lualine_b = ${cfg.activeSection.b},
lualine_c = ${cfg.activeSection.c},
lualine_x = ${cfg.activeSection.x},
lualine_y = ${cfg.activeSection.y},
lualine_z = ${cfg.activeSection.z},
lualine_a = ${luaTable (cfg.activeSection.a ++ cfg.extraActiveSection.a)},
lualine_b = ${luaTable (cfg.activeSection.b ++ cfg.extraActiveSection.b)},
lualine_c = ${luaTable (cfg.activeSection.c ++ cfg.extraActiveSection.c)},
lualine_x = ${luaTable (cfg.activeSection.x ++ cfg.extraActiveSection.x)},
lualine_y = ${luaTable (cfg.activeSection.y ++ cfg.extraActiveSection.y)},
lualine_z = ${luaTable (cfg.activeSection.z ++ cfg.extraActiveSection.z)},
},
--
inactive_sections = {
lualine_a = ${cfg.inactiveSection.a},
lualine_b = ${cfg.inactiveSection.b},
lualine_c = ${cfg.inactiveSection.c},
lualine_x = ${cfg.inactiveSection.x},
lualine_y = ${cfg.inactiveSection.y},
lualine_z = ${cfg.inactiveSection.z},
lualine_a = ${luaTable (cfg.inactiveSection.a ++ cfg.extraInactiveSection.a)},
lualine_b = ${luaTable (cfg.inactiveSection.b ++ cfg.extraInactiveSection.b)},
lualine_c = ${luaTable (cfg.inactiveSection.c ++ cfg.extraInactiveSection.c)},
lualine_x = ${luaTable (cfg.inactiveSection.x ++ cfg.extraInactiveSection.x)},
lualine_y = ${luaTable (cfg.inactiveSection.y ++ cfg.extraInactiveSection.y)},
lualine_z = ${luaTable (cfg.inactiveSection.z ++ cfg.extraInactiveSection.z)},
},
tabline = {},
Expand Down
180 changes: 127 additions & 53 deletions modules/statusline/lualine/lualine.nix
Original file line number Diff line number Diff line change
Expand Up @@ -117,48 +117,50 @@ in {

activeSection = {
a = mkOption {
type = types.str;
type = types.listOf types.str;
description = "active config for: | (A) | B | C X | Y | Z |";
default = ''
{
default = [
''
{
"mode",
icons_enabled = true,
separator = {
left = '▎',
right = ''
},
},
}
'';
}
''
];
};

b = mkOption {
type = types.str;
type = types.listOf types.str;
description = "active config for: | A | (B) | C X | Y | Z |";
default = ''
{
default = [
''
{
"filetype",
colored = true,
icon_only = true,
icon = { align = 'left' },
color = {bg='${colorPuccin}', fg='lavender'},
},
}
''
''
{
"filename",
color = {bg='${colorPuccin}'},
symbols = {modified = '', readonly = ''},
},
}
'';
}
''
];
};

c = mkOption {
type = types.str;
type = types.listOf types.str;
description = "active config for: | A | B | (C) X | Y | Z |";
default = ''
{
default = [
''
{
"diff",
colored = false,
Expand All @@ -173,16 +175,16 @@ in {
bg='${colorPuccin}',
fg='lavender'
},
},
}
'';
}
''
];
};

x = mkOption {
type = types.str;
type = types.listOf types.str;
description = "active config for: | A | B | C (X) | Y | Z |";
default = ''
{
default = [
''
{
-- Lsp server name
function()
Expand Down Expand Up @@ -218,7 +220,9 @@ in {
end,
icon = ' ',
color = {bg='${colorPuccin}', fg='lavender'},
},
}
''
''
{
"diagnostics",
sources = {'nvim_lsp', 'nvim_diagnostic', 'coc'},
Expand All @@ -229,45 +233,51 @@ in {
color_warn = { fg = 'yellow' },
color_info = { fg = 'cyan' },
},
},
}
'';
}
''
];
};

y = mkOption {
type = types.str;
type = types.listOf types.str;
description = "active config for: | A | B | C X | (Y) | Z |";
default = ''
{
default = [
''
{
'searchcount',
maxcount = 999,
timeout = 120,
color = {bg='${colorPuccin}', fg='lavender'}
},
}
''
''
{
"branch",
icon = ' •',
color = {bg='${colorPuccin}', fg='lavender'},
},
}
'';
}
''
];
};

z = mkOption {
type = types.str;
type = types.listOf types.str;
description = "active config for: | A | B | C X | Y | (Z) |";
default = ''
{
default = [
''
{
"progress",
separator = {
left = '',
},
},
}
''
''
{
"location",
},
}
''
''
{
"fileformat",
color = {fg='black'},
Expand All @@ -276,47 +286,111 @@ in {
dos = '', -- e70f
mac = '', -- e711
},
},
}
'';
}
''
];
};
};
extraActiveSection = {
a = mkOption {
type = types.listOf types.str;
description = "Extra entries for activeSection.a";
default = [];
};
b = mkOption {
type = types.listOf types.str;
description = "Extra entries for activeSection.b";
default = [];
};
c = mkOption {
type = types.listOf types.str;
description = "Extra entries for activeSection.c";
default = [];
};
x = mkOption {
type = types.listOf types.str;
description = "Extra entries for activeSection.x";
default = [];
};
y = mkOption {
type = types.listOf types.str;
description = "Extra entries for activeSection.y";
default = [];
};
z = mkOption {
type = types.listOf types.str;
description = "Extra entries for activeSection.z";
default = [];
};
};

inactiveSection = {
a = mkOption {
type = types.str;
type = types.listOf types.str;
description = "inactive config for: | (A) | B | C X | Y | Z |";
default = "{}";
default = [];
};

b = mkOption {
type = types.str;
type = types.listOf types.str;
description = "inactive config for: | A | (B) | C X | Y | Z |";
default = "{}";
default = [];
};

c = mkOption {
type = types.str;
type = types.listOf types.str;
description = "inactive config for: | A | B | (C) X | Y | Z |";
default = "{'filename'}";
default = ["'filename'"];
};

x = mkOption {
type = types.str;
type = types.listOf types.str;
description = "inactive config for: | A | B | C (X) | Y | Z |";
default = "{'location'}";
default = ["'location'"];
};

y = mkOption {
type = types.str;
type = types.listOf types.str;
description = "inactive config for: | A | B | C X | (Y) | Z |";
default = "{}";
default = [];
};

z = mkOption {
type = types.str;
type = types.listOf types.str;
description = "inactive config for: | A | B | C X | Y | (Z) |";
default = "{}";
default = [];
};
};
extraInactiveSection = {
a = mkOption {
type = types.listOf types.str;
description = "Extra entries for inactiveSection.a";
default = [];
};
b = mkOption {
type = types.listOf types.str;
description = "Extra entries for inactiveSection.b";
default = [];
};
c = mkOption {
type = types.listOf types.str;
description = "Extra entries for inactiveSection.c";
default = [];
};
x = mkOption {
type = types.listOf types.str;
description = "Extra entries for inactiveSection.x";
default = [];
};
y = mkOption {
type = types.listOf types.str;
description = "Extra entries for inactiveSection.y";
default = [];
};
z = mkOption {
type = types.listOf types.str;
description = "Extra entries for inactiveSection.z";
default = [];
};
};
};
Expand Down

0 comments on commit 11a974a

Please sign in to comment.