From b41163959b1d01ccf0329c2c3585eff8f10db6be Mon Sep 17 00:00:00 2001 From: Charlie Root Date: Mon, 7 Oct 2024 00:02:51 +0200 Subject: [PATCH] theme/supported-themes.nix: switch to setupOpts --- modules/plugins/theme/supported-themes.nix | 212 ++++++++++----------- 1 file changed, 98 insertions(+), 114 deletions(-) diff --git a/modules/plugins/theme/supported-themes.nix b/modules/plugins/theme/supported-themes.nix index ca539b1..3ae26d3 100644 --- a/modules/plugins/theme/supported-themes.nix +++ b/modules/plugins/theme/supported-themes.nix @@ -3,86 +3,79 @@ lib, }: let inherit (lib.strings) optionalString; - inherit (lib.trivial) boolToString warnIf; - inherit (lib.nvim.lua) toLuaObject; + inherit (lib.modules) mkDefault; + cfg = config.vim.theme; in { base16 = { - setup = {base16-colors, ...}: '' - -- Base16 theme - require('base16-colorscheme').setup(${toLuaObject base16-colors}) - ''; + setupOpts = { + inherit (cfg) base16-colors; + }; }; onedark = { - setup = {style ? "dark", ...}: '' + setupOpts = { + style = cfg.style ? "dark"; + }; + setup = _: '' -- OneDark theme - require('onedark').setup { - style = "${style}" - } - require('onedark').load() + require('onedark').load() ''; styles = ["dark" "darker" "cool" "deep" "warm" "warmer"]; }; tokyonight = { - setup = { - style ? "night", - transparent, - ... - }: '' - require('tokyonight').setup { - transparent = ${boolToString transparent}; - } + setupOpts = { + inherit (cfg) transparent; + }; + setup = {style ? "night", ...}: '' vim.cmd[[colorscheme tokyonight-${style}]] ''; styles = ["day" "night" "storm" "moon"]; }; dracula = { - setup = {transparent, ...}: '' - require('dracula').setup({ - transparent_bg = ${boolToString transparent}, - }); + setupOpts = { + transparent_bg = cfg.transparent; + }; + setup = _: '' require('dracula').load(); ''; }; catppuccin = { - setup = { - style ? "mocha", - transparent ? false, - ... - }: '' - -- Catppuccin theme - require('catppuccin').setup { - flavour = "${style}", - transparent_background = ${boolToString transparent}, - term_colors = true, - integrations = { - nvimtree = { - enabled = true, - transparent_panel = ${boolToString transparent}, - show_root = true, - }, + setupOpts = { + flavour = cfg.style ? "mocha"; + transparent_background = cfg.transparent; + term_colors = mkDefault true; + integrations = { + nvimtree = { + enabled = mkDefault true; + transparent_panel = cfg.transparent; + show_root = mkDefault true; + }; - hop = true, - gitsigns = true, - telescope = true, - treesitter = true, - treesitter_context = true, - ts_rainbow = true, - fidget = true, - alpha = true, - leap = true, - markdown = true, - noice = true, - notify = true, -- nvim-notify - which_key = true, - navic = { - enabled = true, - custom_bg = "NONE", -- "lualine" will set background to mantle - }, - }, - } + hop = mkDefault true; + gitsigns = mkDefault true; + telescope = mkDefault true; + treesitter = mkDefault true; + treesitter_context = mkDefault true; + ts_rainbow = mkDefault true; + fidget = mkDefault true; + alpha = mkDefault true; + leap = mkDefault true; + markdown = mkDefault true; + noice = mkDefault true; + # nvim-notify + notify = mkDefault true; + which_key = mkDefault true; + navic = { + enabled = mkDefault true; + # lualine will set backgound to mantle + custom_bg = "NONE"; + }; + }; + }; + setup = _: '' + -- Catppuccin theme -- setup must be called before loading vim.cmd.colorscheme "catppuccin" ''; @@ -90,17 +83,12 @@ in { }; oxocarbon = { - setup = { - style ? "dark", - transparent ? false, - }: let - style' = - warnIf (style == "light") "oxocarbon: light theme is not well-supported" style; - in '' + setupOpts = {}; + setup = _: '' require('oxocarbon') - vim.opt.background = "${style'}" + vim.opt.background = "${cfg.style ? "dark"}" vim.cmd.colorscheme = "oxocarbon" - ${optionalString transparent '' + ${optionalString cfg.transparent '' vim.api.nvim_set_hl(0, "Normal", { bg = "none" }) vim.api.nvim_set_hl(0, "NormalFloat", { bg = "none" }) vim.api.nvim_set_hl(0, "LineNr", { bg = "none" }) @@ -114,62 +102,58 @@ in { }; gruvbox = { - setup = { - style ? "dark", - transparent ? false, - }: '' + setupOpts = { + transparent_mode = cfg.transparent; + # add neovim terminal colors + terminal_colors = mkDefault true; + undercurl = mkDefault true; + underline = mkDefault true; + bold = mkDefault true; + italic = { + strings = mkDefault true; + emphasis = mkDefault true; + comments = mkDefault true; + operators = mkDefault false; + folds = mkDefault true; + }; + strikethrough = mkDefault true; + invert_selection = mkDefault false; + invert_signs = mkDefault false; + invert_tabline = mkDefault false; + invert_intend_guides = mkDefault false; + inverse = mkDefault true; + contrast = ""; + palette_overrides = {}; + overrides = {}; + dim_inactive = mkDefault false; + }; + setup = _: '' -- Gruvbox theme - require("gruvbox").setup({ - terminal_colors = true, -- add neovim terminal colors - undercurl = true, - underline = true, - bold = true, - italic = { - strings = true, - emphasis = true, - comments = true, - operators = false, - folds = true, - }, - strikethrough = true, - invert_selection = false, - invert_signs = false, - invert_tabline = false, - invert_intend_guides = false, - inverse = true, - contrast = "", - palette_overrides = {}, - overrides = {}, - dim_inactive = false, - transparent_mode = ${boolToString transparent}, - }) - vim.o.background = "${style}" + vim.o.background = "${cfg.style ? "dark"}" vim.cmd("colorscheme gruvbox") ''; styles = ["dark" "light"]; }; rose-pine = { - setup = { - style ? "main", - transparent ? false, - }: '' - require("rose-pine").setup({ - dark_variant = "${style}", -- main, moon, or dawn - dim_inactive_windows = false, - extend_background_behind_borders = true, + setupOpts = { + dark_variant = cfg.style ? "main"; + dim_inactive_windows = mkDefault false; + extend_background_behind_borders = mkDefault true; - enable = { - terminal = true, - migrations = true, - }, + enable = { + terminal = mkDefault true; + migrations = mkDefault true; + }; - styles = { - bold = false, - italic = false, -- I would like to add more options for this - transparency = ${boolToString transparent}, - }, - }) + styles = { + bold = mkDefault false; + # I would like to add more options for this + italic = mkDefault false; + transparency = cfg.transparent; + }; + }; + setup = _: '' vim.cmd("colorscheme rose-pine") ''; styles = ["main" "moon" "dawn"];