mirror of
https://github.com/nix-community/nixvim.git
synced 2025-06-20 16:15:43 +02:00
plugins/lightline: migrate to mkNeovimPlugin
This commit is contained in:
parent
052ee66dbb
commit
4c8d3559ac
4 changed files with 359 additions and 111 deletions
|
@ -56,6 +56,7 @@
|
||||||
enable = true;
|
enable = true;
|
||||||
|
|
||||||
# This is optional - it will default to your enabled colorscheme
|
# This is optional - it will default to your enabled colorscheme
|
||||||
|
settings = {
|
||||||
colorscheme = "wombat";
|
colorscheme = "wombat";
|
||||||
|
|
||||||
# This is one of lightline's example configurations
|
# This is one of lightline's example configurations
|
||||||
|
@ -78,6 +79,7 @@
|
||||||
helloworld = "Hello, world!";
|
helloworld = "Hello, world!";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
};
|
||||||
|
|
||||||
# Of course, there are a lot more plugins available.
|
# Of course, there are a lot more plugins available.
|
||||||
# You can find an up-to-date list here:
|
# You can find an up-to-date list here:
|
||||||
|
|
|
@ -174,7 +174,7 @@ lib.nixvim.neovim-plugin.mkNeovimPlugin config {
|
||||||
extraConfig = cfg: {
|
extraConfig = cfg: {
|
||||||
plugins.airline.settings.theme = lib.mkIf cfg.setUpBar (lib.mkDefault name);
|
plugins.airline.settings.theme = lib.mkIf cfg.setUpBar (lib.mkDefault name);
|
||||||
plugins.lualine.theme = lib.mkIf cfg.setUpBar (lib.mkDefault name);
|
plugins.lualine.theme = lib.mkIf cfg.setUpBar (lib.mkDefault name);
|
||||||
plugins.lightline.colorscheme = lib.mkDefault null;
|
plugins.lightline.settings.colorscheme = lib.mkDefault null;
|
||||||
|
|
||||||
opts.termguicolors = lib.mkDefault true;
|
opts.termguicolors = lib.mkDefault true;
|
||||||
|
|
||||||
|
|
|
@ -1,117 +1,215 @@
|
||||||
{
|
{
|
||||||
lib,
|
lib,
|
||||||
helpers,
|
|
||||||
config,
|
config,
|
||||||
|
options,
|
||||||
pkgs,
|
pkgs,
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
with lib;
|
|
||||||
let
|
let
|
||||||
cfg = config.plugins.lightline;
|
inherit (lib) types;
|
||||||
|
inherit (lib.nixvim) defaultNullOpts;
|
||||||
in
|
in
|
||||||
{
|
lib.nixvim.neovim-plugin.mkNeovimPlugin config {
|
||||||
options = {
|
name = "lightline";
|
||||||
plugins.lightline = {
|
originalName = "lightline.vim";
|
||||||
enable = mkEnableOption "lightline";
|
defaultPackage = pkgs.vimPlugins.lightline-vim;
|
||||||
|
|
||||||
package = helpers.mkPluginPackageOption "lightline" pkgs.vimPlugins.lightline-vim;
|
maintainers = [ lib.maintainers.khaneliman ];
|
||||||
|
|
||||||
colorscheme = mkOption {
|
|
||||||
type = with types; nullOr str;
|
|
||||||
default = config.colorscheme;
|
|
||||||
description = "The colorscheme to use for lightline. Defaults to .colorscheme.";
|
|
||||||
example = "gruvbox";
|
|
||||||
};
|
|
||||||
|
|
||||||
componentFunction = mkOption {
|
|
||||||
default = null;
|
|
||||||
type = with types; nullOr (attrsOf str);
|
|
||||||
description = ''
|
description = ''
|
||||||
A list of function component definitions.
|
### Example of defining your own component_function
|
||||||
|
|
||||||
You should define the functions themselves in extraConfig
|
|
||||||
'';
|
|
||||||
example = ''
|
|
||||||
plugins.lightline = {
|
plugins.lightline = {
|
||||||
enable = true;
|
enable = true;
|
||||||
componentFunction = {
|
settings.component_function = {
|
||||||
readonly = "LightlineReadonly";
|
readonly = "LightlineReadonly";
|
||||||
};
|
};
|
||||||
|
|
||||||
extraConfig = '''
|
|
||||||
function! LightlineReadonly()
|
|
||||||
return &readonly && &filetype !=# 'help' ? 'RO' : '''
|
|
||||||
endfunction
|
|
||||||
''';
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
extraConfigLua = '''
|
||||||
|
function LightlineReadonly()
|
||||||
|
local is_readonly = vim.bo.readonly == 1
|
||||||
|
local filetype = vim.bo.filetype
|
||||||
|
|
||||||
|
if is_readonly and filetype ~= "help" then
|
||||||
|
return "RO"
|
||||||
|
else
|
||||||
|
return ""
|
||||||
|
end
|
||||||
|
end
|
||||||
|
''';
|
||||||
|
'';
|
||||||
|
|
||||||
|
# TODO: Added 2024-08-23, remove after 24.11
|
||||||
|
optionsRenamedToSettings = [
|
||||||
|
"colorscheme"
|
||||||
|
"componentFunction"
|
||||||
|
"component"
|
||||||
|
"active"
|
||||||
|
"inactive"
|
||||||
|
"modeMap"
|
||||||
|
];
|
||||||
|
|
||||||
|
settingsOptions = {
|
||||||
|
colorscheme = defaultNullOpts.mkStr "default" ''
|
||||||
|
The colorscheme to use for lightline.
|
||||||
|
Default theme is equal to `powerline`.
|
||||||
|
'';
|
||||||
|
|
||||||
|
component_function = defaultNullOpts.mkAttrsOf types.str { } ''
|
||||||
|
A list of function component definitions.
|
||||||
|
|
||||||
|
You can use the name of a function defined elsewhere.
|
||||||
|
'';
|
||||||
|
|
||||||
|
component =
|
||||||
|
defaultNullOpts.mkAttrsOf types.str
|
||||||
|
{
|
||||||
|
mode = ''%{lightline#mode()}'';
|
||||||
|
absolutepath = "%F";
|
||||||
|
relativepath = "%f";
|
||||||
|
filename = "%t";
|
||||||
|
modified = "%M";
|
||||||
|
bufnum = "%n";
|
||||||
|
paste = ''%{&paste?"PASTE"=""}'';
|
||||||
|
readonly = "%R";
|
||||||
|
charvalue = "%b";
|
||||||
|
charvaluehex = "%B";
|
||||||
|
fileencoding = ''%{&fenc!=#" "?&fenc=&enc}'';
|
||||||
|
fileformat = "%{&ff}";
|
||||||
|
filetype = ''%{&ft!=#""?&ft="no ft"}'';
|
||||||
|
percent = "%3p%%";
|
||||||
|
percentwin = "%P";
|
||||||
|
spell = ''%{&spell?&spelllang=" "}'';
|
||||||
|
lineinfo = "%3l=%-2c";
|
||||||
|
line = "%l";
|
||||||
|
column = "%c";
|
||||||
|
close = "%999X X ";
|
||||||
|
winnr = ''%{winnr()}'';
|
||||||
|
}
|
||||||
|
''
|
||||||
|
Lightline component definitions. Uses 'statusline' syntax.
|
||||||
|
|
||||||
|
Consult `:h 'statusline'` for a list of what's available.
|
||||||
|
'';
|
||||||
|
|
||||||
|
active =
|
||||||
|
defaultNullOpts.mkAttrsOf (with types; listOf (listOf str))
|
||||||
|
{
|
||||||
|
left = [
|
||||||
|
[
|
||||||
|
"mode"
|
||||||
|
"paste"
|
||||||
|
]
|
||||||
|
[
|
||||||
|
"readonly"
|
||||||
|
"filename"
|
||||||
|
"modified"
|
||||||
|
]
|
||||||
|
];
|
||||||
|
right = [
|
||||||
|
[ "lineinfo" ]
|
||||||
|
[ "percent" ]
|
||||||
|
[
|
||||||
|
"fileformat"
|
||||||
|
"fileencoding"
|
||||||
|
"filetype"
|
||||||
|
]
|
||||||
|
];
|
||||||
|
}
|
||||||
|
''
|
||||||
|
Components placement for the active window.
|
||||||
|
'';
|
||||||
|
|
||||||
|
inactive =
|
||||||
|
defaultNullOpts.mkAttrsOf (with types; listOf (listOf str))
|
||||||
|
{
|
||||||
|
left = [ "filename" ];
|
||||||
|
right = [
|
||||||
|
[ "lineinfo" ]
|
||||||
|
[ "percent" ]
|
||||||
|
];
|
||||||
|
}
|
||||||
|
''
|
||||||
|
Components placement for inactive windows.
|
||||||
|
'';
|
||||||
|
|
||||||
|
tabline =
|
||||||
|
defaultNullOpts.mkAttrsOf (with types; listOf (listOf str))
|
||||||
|
{
|
||||||
|
left = [ [ "tabs" ] ];
|
||||||
|
right = [ [ "close" ] ];
|
||||||
|
}
|
||||||
|
''
|
||||||
|
Components placement for tabline.
|
||||||
|
'';
|
||||||
|
|
||||||
|
tab = defaultNullOpts.mkAttrsOf (with types; listOf str) {
|
||||||
|
active = [
|
||||||
|
"tabnum"
|
||||||
|
"filename"
|
||||||
|
"modified"
|
||||||
|
];
|
||||||
|
inactive = [
|
||||||
|
"tabnum"
|
||||||
|
"filename"
|
||||||
|
"modified"
|
||||||
|
];
|
||||||
|
} ''A dictionary to store the tab components in each tabs.'';
|
||||||
|
|
||||||
|
mode_map =
|
||||||
|
defaultNullOpts.mkAttrsOf types.str
|
||||||
|
{
|
||||||
|
"n" = "NORMAL";
|
||||||
|
"i" = "INSERT";
|
||||||
|
"R" = "REPLACE";
|
||||||
|
"v" = "VISUAL";
|
||||||
|
"V" = "V-LINE";
|
||||||
|
"\<C-v>" = "V-BLOCK";
|
||||||
|
"c" = "COMMAND";
|
||||||
|
"s" = "SELECT";
|
||||||
|
"S" = "S-LINE";
|
||||||
|
"\<C-s>" = "S-BLOCK";
|
||||||
|
"t" = "TERMINAL";
|
||||||
|
}
|
||||||
|
''
|
||||||
|
Mode name mappings
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
component = mkOption {
|
settingsExample = {
|
||||||
default = null;
|
colorscheme = "gruvbox";
|
||||||
type = with types; nullOr (attrsOf str);
|
component_function = {
|
||||||
description = "Lightline component definitions. Uses 'statusline' syntax. Consult :h 'statusline' for a list of what's available.";
|
gitbranch = "FugitiveHead";
|
||||||
|
};
|
||||||
|
component = {
|
||||||
|
charvaluehex = "0x%B";
|
||||||
|
lineinfo = "%3l:%-2v%<";
|
||||||
|
};
|
||||||
|
active = {
|
||||||
|
right = [
|
||||||
|
[ "lineinfo" ]
|
||||||
|
[ "percent" ]
|
||||||
|
[
|
||||||
|
"fileformat"
|
||||||
|
"fileencoding"
|
||||||
|
"filetype"
|
||||||
|
"charvaluehex"
|
||||||
|
]
|
||||||
|
];
|
||||||
|
};
|
||||||
|
inactive = [ ];
|
||||||
|
mode_map = {
|
||||||
|
"n" = "N";
|
||||||
|
"i" = "I";
|
||||||
|
"v" = "V";
|
||||||
|
"<C-v>" = "VB";
|
||||||
|
"<C-s>" = "SB";
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
active = mkOption {
|
callSetup = false;
|
||||||
default = null;
|
extraConfig = cfg: {
|
||||||
description = "List of components for the active window.";
|
globals.lightline = lib.modules.mkAliasAndWrapDefsWithPriority lib.id options.plugins.lightline.settings;
|
||||||
type = types.nullOr (
|
|
||||||
types.submodule {
|
|
||||||
options =
|
|
||||||
let
|
|
||||||
listType = with helpers.nixvimTypes; maybeRaw (listOf (listOf str));
|
|
||||||
in
|
|
||||||
{
|
|
||||||
left = helpers.mkNullOrOption listType "List of components that will show up on the left side of the bar";
|
|
||||||
|
|
||||||
right = helpers.mkNullOrOption listType "List of components that will show up on the right side of the bar";
|
|
||||||
};
|
|
||||||
}
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
inactive = mkOption {
|
|
||||||
default = null;
|
|
||||||
description = "List of components for inactive windows.";
|
|
||||||
type = types.nullOr (
|
|
||||||
types.submodule {
|
|
||||||
options =
|
|
||||||
let
|
|
||||||
listType = with helpers.nixvimTypes; maybeRaw (listOf (listOf str));
|
|
||||||
in
|
|
||||||
{
|
|
||||||
left = helpers.mkNullOrOption listType "List of components that will show up on the left side of the bar";
|
|
||||||
|
|
||||||
right = helpers.mkNullOrOption listType "List of components that will show up on the right side of the bar";
|
|
||||||
};
|
|
||||||
}
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
modeMap = mkOption {
|
|
||||||
type = with types; nullOr (attrsOf str);
|
|
||||||
description = "Mode name mappings";
|
|
||||||
default = null;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
config =
|
|
||||||
let
|
|
||||||
configAttrs = filterAttrs (_: v: v != null) {
|
|
||||||
inherit (cfg)
|
|
||||||
colorscheme
|
|
||||||
active
|
|
||||||
inactive
|
|
||||||
component
|
|
||||||
componentFunction
|
|
||||||
modeMap
|
|
||||||
;
|
|
||||||
};
|
|
||||||
in
|
|
||||||
mkIf cfg.enable {
|
|
||||||
extraPlugins = [ cfg.package ];
|
|
||||||
globals.lightline = mkIf (configAttrs != { }) configAttrs;
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
148
tests/test-sources/plugins/statuslines/lightline.nix
Normal file
148
tests/test-sources/plugins/statuslines/lightline.nix
Normal file
|
@ -0,0 +1,148 @@
|
||||||
|
{
|
||||||
|
empty = {
|
||||||
|
plugins.lightline.enable = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
defaults = {
|
||||||
|
plugins.lightline = {
|
||||||
|
enable = true;
|
||||||
|
|
||||||
|
settings = {
|
||||||
|
colorscheme = "default";
|
||||||
|
component_function = { };
|
||||||
|
component = {
|
||||||
|
mode = ''%{lightline#mode()}'';
|
||||||
|
absolutepath = "%F";
|
||||||
|
relativepath = "%f";
|
||||||
|
filename = "%t";
|
||||||
|
modified = "%M";
|
||||||
|
bufnum = "%n";
|
||||||
|
paste = ''%{&paste?"PASTE":""}'';
|
||||||
|
readonly = "%R";
|
||||||
|
charvalue = "%b";
|
||||||
|
charvaluehex = "%B";
|
||||||
|
fileencoding = ''%{&fenc!=#""?&fenc:&enc}'';
|
||||||
|
fileformat = ''%{&ff}'';
|
||||||
|
filetype = ''%{&ft!=#""?&ft:"no ft"}'';
|
||||||
|
percent = "%3p%%";
|
||||||
|
percentwin = "%P";
|
||||||
|
spell = ''%{&spell?&spelllang:""}'';
|
||||||
|
lineinfo = ''%3l=%-2c'';
|
||||||
|
line = "%l";
|
||||||
|
column = "%c";
|
||||||
|
close = "%999X X ";
|
||||||
|
winnr = ''%{winnr()}'';
|
||||||
|
};
|
||||||
|
active = {
|
||||||
|
left = [
|
||||||
|
[
|
||||||
|
"mode"
|
||||||
|
"paste"
|
||||||
|
]
|
||||||
|
[
|
||||||
|
"readonly"
|
||||||
|
"filename"
|
||||||
|
"modified"
|
||||||
|
]
|
||||||
|
];
|
||||||
|
right = [
|
||||||
|
[ "lineinfo" ]
|
||||||
|
[ "percent" ]
|
||||||
|
[
|
||||||
|
"fileformat"
|
||||||
|
"fileencoding"
|
||||||
|
"filetype"
|
||||||
|
]
|
||||||
|
];
|
||||||
|
};
|
||||||
|
inactive = {
|
||||||
|
left = [ [ "filename" ] ];
|
||||||
|
right = [
|
||||||
|
[ "lineinfo" ]
|
||||||
|
[ "percent" ]
|
||||||
|
];
|
||||||
|
};
|
||||||
|
tabline = {
|
||||||
|
left = [ [ "tabs" ] ];
|
||||||
|
right = [ [ "close" ] ];
|
||||||
|
};
|
||||||
|
tab = {
|
||||||
|
active = [
|
||||||
|
"tabnum"
|
||||||
|
"filename"
|
||||||
|
"modified"
|
||||||
|
];
|
||||||
|
inactive = [
|
||||||
|
"tabnum"
|
||||||
|
"filename"
|
||||||
|
"modified"
|
||||||
|
];
|
||||||
|
};
|
||||||
|
mode_map = {
|
||||||
|
"n" = "NORMAL";
|
||||||
|
"i" = "INSERT";
|
||||||
|
"R" = "REPLACE";
|
||||||
|
"v" = "VISUAL";
|
||||||
|
"V" = "V-LINE";
|
||||||
|
"\<C-v>" = "V-BLOCK";
|
||||||
|
"c" = "COMMAND";
|
||||||
|
"s" = "SELECT";
|
||||||
|
"S" = "S-LINE";
|
||||||
|
"\<C-s>" = "S-BLOCK";
|
||||||
|
"t" = "TERMINAL";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
example = {
|
||||||
|
extraConfigLua = ''
|
||||||
|
function LightlineReadonly()
|
||||||
|
local is_readonly = vim.bo.readonly == 1
|
||||||
|
local filetype = vim.bo.filetype
|
||||||
|
|
||||||
|
if is_readonly and filetype ~= "help" then
|
||||||
|
return "RO"
|
||||||
|
else
|
||||||
|
return ""
|
||||||
|
end
|
||||||
|
end
|
||||||
|
'';
|
||||||
|
|
||||||
|
plugins.lightline = {
|
||||||
|
enable = true;
|
||||||
|
|
||||||
|
settings = {
|
||||||
|
colorscheme = "gruvbox";
|
||||||
|
component_function = {
|
||||||
|
gitbranch = "FugitiveHead";
|
||||||
|
readonly = "LightlineReadOnly";
|
||||||
|
};
|
||||||
|
component = {
|
||||||
|
charvaluehex = "0x%B";
|
||||||
|
lineinfo = "%3l:%-2v%<";
|
||||||
|
};
|
||||||
|
active = {
|
||||||
|
right = [
|
||||||
|
[ "lineinfo" ]
|
||||||
|
[ "percent" ]
|
||||||
|
[
|
||||||
|
"fileformat"
|
||||||
|
"fileencoding"
|
||||||
|
"filetype"
|
||||||
|
"charvaluehex"
|
||||||
|
]
|
||||||
|
];
|
||||||
|
};
|
||||||
|
inactive = null;
|
||||||
|
mode_map = {
|
||||||
|
"n" = "N";
|
||||||
|
"i" = "I";
|
||||||
|
"v" = "V";
|
||||||
|
"<C-v>" = "VB";
|
||||||
|
"<C-s>" = "SB";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue