plugins/barbar: add keymaps options + tests (#276)

This commit is contained in:
Gaétan Lepage 2023-03-19 00:36:21 +01:00 committed by GitHub
parent 09a2e9afb6
commit c300601dce
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 133 additions and 13 deletions

View file

@ -7,6 +7,30 @@
with lib; let with lib; let
cfg = config.plugins.barbar; cfg = config.plugins.barbar;
helpers = import ../helpers.nix {inherit lib;}; helpers = import ../helpers.nix {inherit lib;};
keymaps = {
previous = "Previous";
next = "Next";
movePrevious = "MovePrevious";
moveNext = "MoveNext";
goTo1 = "GoTo 1";
goTo2 = "GoTo 2";
goTo3 = "GoTo 3";
goTo4 = "GoTo 4";
goTo5 = "GoTo 5";
goTo6 = "GoTo 6";
goTo7 = "GoTo 7";
goTo8 = "GoTo 8";
goTo9 = "GoTo 9";
last = "Last";
pin = "Pin";
close = "Close";
pick = "Pick";
orderByBufferNumber = "OrderByBufferNumber";
orderByDirectory = "OrderByDirectory";
orderByLanguage = "OrderByLanguage";
orderByWindowNumber = "OrderByWindowNumber";
};
in { in {
options.plugins.barbar = { options.plugins.barbar = {
enable = mkEnableOption "barbar.nvim"; enable = mkEnableOption "barbar.nvim";
@ -46,11 +70,11 @@ in {
}; };
}; };
excludeFileTypes = helpers.defaultNullOpts.mkNullable (types.listOf types.str) "{}" '' excludeFileTypes = helpers.defaultNullOpts.mkNullable (types.listOf types.str) "[]" ''
Excludes buffers of certain filetypes from the tabline Excludes buffers of certain filetypes from the tabline
''; '';
excludeFileNames = helpers.defaultNullOpts.mkNullable (types.listOf types.str) "{}" '' excludeFileNames = helpers.defaultNullOpts.mkNullable (types.listOf types.str) "[]" ''
Excludes buffers with certain filenames from the tabline Excludes buffers with certain filenames from the tabline
''; '';
@ -126,15 +150,18 @@ in {
But only a static string is accepted here. But only a static string is accepted here.
''; '';
# Keybinds concept: keymaps =
# keys = { {
# previousBuffer = mkBindDef "normal" "Previous buffer" { action = ":BufferPrevious<CR>"; silent = true; } "<A-,>"; silent = mkEnableOption "silent keymaps for barbar";
# nextBuffer = mkBindDef "normal" "Next buffer" { action = ":BufferNext<CR>"; silent = true; } "<A-.>"; }
# movePrevious = mkBindDef "normal" "Re-order to previous" { action = ":BufferMovePrevious<CR>"; silent = true; } "<A-<>"; // (
# moveNext = mkBindDef "normal" "Re-order to next" { action = ":BufferMoveNext<CR>"; silent = true; } "<A->>"; mapAttrs
(
# # TODO all the other ones..... optionName: funcName:
# }; helpers.mkNullOrOption types.str "Keymap for function Buffer${funcName}"
)
keymaps
);
}; };
config = let config = let
@ -184,6 +211,21 @@ in {
tabpages = cfg.tabpages; tabpages = cfg.tabpages;
}; };
userKeymapsList =
mapAttrsToList
(
optionName: funcName: let
key = cfg.keymaps.${optionName};
in
mkIf (!isNull key) {
${key} = {
action = "<Cmd>Buffer${funcName}<CR>";
silent = cfg.keymaps.silent;
};
}
)
keymaps;
in in
mkIf cfg.enable { mkIf cfg.enable {
extraPlugins = with pkgs.vimPlugins; [ extraPlugins = with pkgs.vimPlugins; [
@ -191,10 +233,10 @@ in {
nvim-web-devicons nvim-web-devicons
]; ];
maps.normal = mkMerge userKeymapsList;
extraConfigLua = '' extraConfigLua = ''
require('bufferline').setup(${helpers.toLuaObject setupOptions}) require('bufferline').setup(${helpers.toLuaObject setupOptions})
''; '';
# maps = genMaps cfg.keys;
}; };
} }

78
tests/plugins/barbar.nix Normal file
View file

@ -0,0 +1,78 @@
{
empty = {
plugins.barbar.enable = true;
};
keymappings = {
plugins.barbar = {
enable = true;
keymaps = {
silent = true;
next = "<TAB>";
previous = "<S-TAB>";
close = "<C-w>";
};
};
};
# All the upstream default options of barbar
defaults = {
plugins.barbar = {
animations = true;
autoHide = false;
tabpages = true;
closable = true;
clickable = true;
diagnostics = {
error = {
enable = false;
icon = " ";
};
warn = {
enable = false;
icon = " ";
};
info = {
enable = false;
icon = " ";
};
hint = {
enable = false;
icon = "💡";
};
};
excludeFileTypes = [];
excludeFileNames = [];
hide = {
extensions = false;
inactive = false;
alternate = false;
current = false;
visible = false;
};
highlightAlternate = false;
highlightInactiveFileIcons = false;
highlightVisible = true;
icons = {
enable = true;
customColors = false;
separatorActive = "";
separatorInactive = "";
separatorVisible = "";
closeTab = "";
closeTabModified = "";
pinned = "";
};
insertAtEnd = false;
insertAtStart = false;
maximumPadding = 4;
minimumPadding = 1;
maximumLength = 30;
semanticLetters = true;
letters = "asdfjkl;ghnmxcvbziowerutyqpASDFJKLGHNMXCVBZIOWERUTYQP";
noNameTitle = null;
};
};
}