From 0ad53980f3073e1be803a257f45eefee68233dc7 Mon Sep 17 00:00:00 2001 From: justchokingaround Date: Fri, 14 Jun 2024 04:54:41 +0200 Subject: [PATCH] feat: add setupOpts --- modules/plugins/tabline/cokeline/cokeline.nix | 208 +++++++++++++++++- modules/plugins/tabline/cokeline/config.nix | 53 +---- 2 files changed, 209 insertions(+), 52 deletions(-) diff --git a/modules/plugins/tabline/cokeline/cokeline.nix b/modules/plugins/tabline/cokeline/cokeline.nix index bbacbbd..f4e1a21 100644 --- a/modules/plugins/tabline/cokeline/cokeline.nix +++ b/modules/plugins/tabline/cokeline/cokeline.nix @@ -1,6 +1,9 @@ {lib, ...}: let - inherit (lib.options) mkEnableOption; + inherit (lib.options) mkEnableOption mkOption; inherit (lib.nvim.binds) mkMappingOption; + inherit (lib.nvim.types) mkPluginSetupOption luaInline; + inherit (lib.types) int bool str enum listOf nullOr; + inherit (lib.generators) mkLuaInline; in { options.vim.tabline.cokeline = { enable = mkEnableOption "cokeline"; @@ -13,5 +16,208 @@ in { switchPrevious = mkMappingOption "Move previous buffer" "bmp"; closeByLetter = mkMappingOption "Close buffer by letter" "bd"; }; + + setupOpts = mkPluginSetupOption "Cokeline" { + show_if_buffers_are_at_least = mkOption { + description = "Only show the bufferline when there are at least this many visible buffers"; + type = int; + default = 0; + }; + + buffers = { + filter_valid = mkOption { + description = "Only show valid buffers in the bufferline"; + type = bool; + default = false; + }; + filter_visible = mkOption { + description = "Only show visible buffers in the bufferline"; + type = bool; + default = false; + }; + focus_on_delete = mkOption { + description = "Focus on buffer deletion"; + type = enum ["prev" "next"]; + default = "next"; + }; + new_buffers_position = mkOption { + description = "Position of new buffers"; + type = enum ["last" "next" "directory" "number"]; + default = "last"; + }; + delete_on_right_click = mkOption { + description = "Delete buffer on right click"; + type = bool; + default = true; + }; + }; + + mappings = { + cycle_prev_next = mkOption { + description = "If true, the last (first) buffer gets focused/switched, if false, nothing happens"; + type = bool; + default = true; + }; + disable_mouse = mkOption { + description = "Disable mouse mappings"; + type = bool; + default = false; + }; + }; + + history = { + enable = mkOption { + description = "Enable a history of focused buffers using a ringbuffer"; + type = bool; + default = true; + }; + size = mkOption { + description = "The maximum number of items to keep in the history"; + type = int; + default = 2; + }; + }; + + rendering = { + max_buffer_width = mkOption { + description = "The maximum number of characters a rendered buffer is allowed to take up. The buffer will be truncated if its width is bigger than this value."; + type = int; + default = 999; + }; + }; + + pick = { + use_filename = mkOption { + description = "Whether to use the filename's first letter first before picking a letter from the valid letters list in order."; + type = bool; + default = true; + }; + letters = mkOption { + description = "The list of letters that are valid as pick letters. Sorted by keyboard reachability by default, but may require tweaking for non-QWERTY keyboard layouts."; + type = str; + default = "asdfjkl;ghnmxcvbziowerutyqpASDFJKLGHNMXCVBZIOWERTYQP"; + }; + }; + + default_hl = { + fg = mkOption { + description = "The default foreground color for buffers"; + type = luaInline; + default = mkLuaInline '' + function(buffer) + return + buffer.is_focused + and vim.api.nvim_get_hl_by_name('Normal', true).foreground + or vim.api.nvim_get_hl_by_name('Comment', true).foreground + end + ''; + }; + bg = mkOption { + description = "The default background color for buffers"; + type = luaInline; + default = mkLuaInline '' + function(buffer) + return vim.api.nvim_get_hl_by_name('ColorColumn', true).background + end + ''; + }; + sp = mkOption { + description = "The default special key color for buffers"; + type = nullOr luaInline; + default = null; + }; + bold = mkOption { + description = "The default bold attribute for buffers"; + type = nullOr luaInline; + default = null; + }; + italic = mkOption { + description = "The default italic attribute for buffers"; + type = nullOr luaInline; + default = null; + }; + underline = mkOption { + description = "The default underline attribute for buffers"; + type = nullOr luaInline; + default = null; + }; + undercurl = mkOption { + description = "The default undercurl attribute for buffers"; + type = nullOr luaInline; + default = null; + }; + strikethrough = mkOption { + description = "The default strikethrough attribute for buffers"; + type = nullOr luaInline; + default = null; + }; + }; + + fill_hl = mkOption { + description = "The highlight group used to fill the tabline space"; + type = str; + default = "TabLineFill"; + }; + + tabs = { + placement = mkOption { + description = "The position of the tabline"; + type = enum ["left" "right"]; + default = "left"; + }; + }; + + sidebar = { + filetype = mkOption { + description = "The filetype of the sidebar"; + type = listOf str; + default = ["NvimTree" "neo-tree" "SidebarNvim"]; + }; + }; + + # components = mkOption { + # description = "The components to use in the tabline"; + # type = luaInline; + # default = mkLuaInline '' + # { + # { + # text = ' ', + # bg = vim.api.nvim_get_hl_by_name('Normal', true).background, + # }, + # { + # text = '', + # fg = vim.api.nvim_get_hl_by_name('ColorColumn', true).background, + # bg = vim.api.nvim_get_hl_by_name('Normal', true).background, + # }, + # { + # text = function(buffer) + # return buffer.devicon.icon + # end, + # fg = function(buffer) + # return buffer.devicon.color + # end, + # }, + # { + # text = ' ', + # }, + # { + # text = function(buffer) return buffer.filename .. ' ' end, + # style = function(buffer) + # return buffer.is_focused and 'bold' or nil + # end, + # }, + # { + # text = '', + # delete_buffer_on_left_click = true, + # }, + # { + # text = '', + # fg = vim.api.nvim_get_hl_by_name('ColorColumn', true).background, + # bg = vim.api.nvim_get_hl_by_name('Normal', true).background, + # } + # } + # ''; + # }; + }; }; } diff --git a/modules/plugins/tabline/cokeline/config.nix b/modules/plugins/tabline/cokeline/config.nix index 97bac52..821a9f2 100644 --- a/modules/plugins/tabline/cokeline/config.nix +++ b/modules/plugins/tabline/cokeline/config.nix @@ -5,6 +5,7 @@ }: let inherit (lib.modules) mkIf mkMerge; inherit (lib.nvim.binds) mkBinding pushDownDefault; + inherit (lib.nvim.lua) toLuaObject; inherit (lib.nvim.dag) entryAnywhere; cfg = config.vim.tabline.cokeline; @@ -37,57 +38,7 @@ in { luaConfigRC = { cokeline = entryAnywhere '' - local get_hex = require('cokeline.hlgroups').get_hl_attr - - require('cokeline').setup({ - default_hl = { - fg = function(buffer) - return - buffer.is_focused - and get_hex('Normal', 'fg') - or get_hex('Comment', 'fg') - end, - bg = get_hex('ColorColumn', 'bg'), - }, - - components = { - { - text = ' ', - bg = get_hex('Normal', 'bg'), - }, - { - text = '', - fg = get_hex('ColorColumn', 'bg'), - bg = get_hex('Normal', 'bg'), - }, - { - text = function(buffer) - return buffer.devicon.icon - end, - fg = function(buffer) - return buffer.devicon.color - end, - }, - { - text = ' ', - }, - { - text = function(buffer) return buffer.filename .. ' ' end, - style = function(buffer) - return buffer.is_focused and 'bold' or nil - end, - }, - { - text = '', - delete_buffer_on_left_click = true, - }, - { - text = '', - fg = get_hex('ColorColumn', 'bg'), - bg = get_hex('Normal', 'bg'), - }, - }, - }) + require('cokeline').setup(${toLuaObject cfg.setupOpts}) ''; }; };