Mofiqul / dracula.nvim

Dracula colorscheme for neovim written in Lua
MIT License
594 stars 103 forks source link

Configuration with LazyVim #76

Closed lucasrabiec closed 1 year ago

lucasrabiec commented 1 year ago

I am trying to configure Dracula in LazyVim but I have a problem with default groups and its overrides.

LazyVim needs to configure plugins that way: https://www.lazyvim.org/configuration/plugins#%EF%B8%8F-customizing-plugin-specs and https://www.lazyvim.org/plugins/colorscheme

I made something like this:

-- lua/plugins/colorscheme.lua
return {
  {
    "Mofiqul/dracula.nvim",
    opts = function()
      local colors = require("dracula").colors()
      colors.selection = "#454158" -- Dracula PRO

      -- helpers from Tokyonight
      ---@param c  string
      local function hexToRgb(c)
        c = string.lower(c)
        return { tonumber(c:sub(2, 3), 16), tonumber(c:sub(4, 5), 16), tonumber(c:sub(6, 7), 16) }
      end

      ---@param foreground string foreground color
      ---@param background string background color
      ---@param alpha number|string number between 0 and 1. 0 results in bg, 1 results in fg
      local function blend(foreground, background, alpha)
        alpha = type(alpha) == "string" and (tonumber(alpha, 16) / 0xff) or alpha
        local bg = hexToRgb(background)
        local fg = hexToRgb(foreground)

        local blendChannel = function(i)
          local ret = (alpha * fg[i] + ((1 - alpha) * bg[i]))
          return math.floor(math.min(math.max(0, ret), 255) + 0.5)
        end

        return string.format("#%02x%02x%02x", blendChannel(1), blendChannel(2), blendChannel(3))
      end

      local function darken(hex, amount, bg)
        return blend(hex, bg or colors.bg, amount)
      end

      return {
        colors = colors,
        show_end_of_buffer = true, -- default false
        transparent_bg = true, -- default false
        lualine_bg_color = "#44475a", -- default nil
        italic_comment = true, -- default false
        overrides = {
          -- Alpha
          AlphaShortcut = { fg = colors.green },
          AlphaHeader = { fg = colors.purple },
          AlphaHeaderLabel = { fg = colors.orange },
          AlphaFooter = { fg = colors.yellow, italic = true },
          AlphaButtons = { fg = colors.cyan },

          -- Diffview
          DiffAdd = { bg = darken(colors.bright_green, 0.15) },
          DiffDelete = { fg = colors.bright_red },
          DiffChange = { bg = darken(colors.comment, 0.15) },
          DiffText = { bg = darken(colors.comment, 0.50) },

          -- illuminate
          illuminatedWord = { bg = darken(colors.comment, 0.65) },
          illuminatedCurWord = { bg = darken(colors.comment, 0.65) },
          IlluminatedWordText = { bg = darken(colors.comment, 0.65) },
          IlluminatedWordRead = { bg = darken(colors.comment, 0.65) },
          IlluminatedWordWrite = { bg = darken(colors.comment, 0.65) },

          -- Notify
          -- Border
          -- NotifyERRORBorder = { fg = colors.fg, bg = colors.bg },
          -- NotifyWARNBorder = { fg = colors.fg, bg = colors.bg },
          -- NotifyINFOBorder = { fg = colors.fg, bg = colors.bg },
          -- NotifyDEBUGBorder = { fg = colors.fg, bg = colors.bg },
          -- NotifyTRACEBorder = { fg = colors.fg, bg = colors.bg },

          -- Body
          NotifyERRORBody = { fg = colors.fg, bg = colors.bg },
          NotifyWARNBody = { fg = colors.fg, bg = colors.bg },
          NotifyINFOBody = { fg = colors.fg, bg = colors.bg },
          NotifyDEBUGBody = { fg = colors.fg, bg = colors.bg },
          NotifyTRACEBody = { fg = colors.fg, bg = colors.bg },
        },
      }
    end,
  },

  {
    "LazyVim/LazyVim",
    opts = {
      colorscheme = "dracula",
    },
  },
}

I reloaded it and colors from overrides works but from groups not. Is there a way to make it work with LazyVim?

tedbyron commented 1 year ago

Passing opts param to the wrapper function and changing fields on opts worked for me when customizing dracula:

return {
  {
    "Mofiqul/dracula.nvim",
    opts = function(_, opts)
      local colors = require("dracula").colors()

      opts.overrides = {
        AlphaShortcut = { fg = colors.green },
        -- ...
      }
    end,
  },
}
lucasrabiec commented 1 year ago

That works, TY @tedbyron