Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configuration with LazyVim #76

Closed
lucasrabiec opened this issue Mar 3, 2023 · 2 comments
Closed

Configuration with LazyVim #76

lucasrabiec opened this issue Mar 3, 2023 · 2 comments

Comments

@lucasrabiec
Copy link

lucasrabiec commented Mar 3, 2023

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
Copy link

tedbyron commented Mar 21, 2023

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
Copy link
Author

That works, TY @tedbyron

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants