meuter / lualine-so-fancy.nvim

Small collection of _fancy_ components for the lualine.nvim plugin.
MIT License
73 stars 4 forks source link

Cannot change git diff color #7

Closed greeid closed 21 hours ago

greeid commented 1 week ago

Minimal Config

-- Some other code

      lualine_b = {
        { 'fancy_branch' },
        {
          'fancy_diff',
          colored = true,
          diff_color = {
            added = '#98c379',
            modified = '#7199ee',
            removed = '#ee6d85',
          },
        },
      }

-- some other code

I get the error : image

I tried editing according to this snippet :

sections = {
  lualine_a = {
    {
      'diff',
      colored = true, -- Displays a colored diff status if set to true
      diff_color = {
        -- Same color values as the general color option can be used here.
        added    = 'LuaLineDiffAdd',    -- Changes the diff's added color
        modified = 'LuaLineDiffChange', -- Changes the diff's modified color
        removed  = 'LuaLineDiffDelete', -- Changes the diff's removed color you
      },
      symbols = {added = '+', modified = '~', removed = '-'}, -- Changes the symbols used by the diff.
      source = nil, -- A function that works as a data source for diff.
                    -- It must return a table as such:
                    --   { added = add_count, modified = modified_count, removed = removed_count }
                    -- or nil on failure. count <= 0 won't be displayed.
    }
  }
}

from here

greeid commented 1 week ago

Update :

I tried using neovim's inherent colors like :

-- Some other code

      lualine_b = {
        { 'fancy_branch' },
        {
          'fancy_diff',
          colored = true,
          diff_color = {
            added = 'green',
            modified = 'yellow',
            removed = 'red',
          },
        },
      }

-- some other code

This didn't throw an error but also shows white text for add, rem and modified

meuter commented 3 days ago

Hi, thanks for reporting this. I will take a look over the week end and let you know.

meuter commented 21 hours ago

From reading the Lualine docs, I think the problem is that when you pass a string to added, removed or modified, it expects a highlight (as defined by your color scheme). If you want to pass in custom RGB color, you need to provide a lua table with fg (and optionally bg defined). So for instance, with this:

{
    'fancy_diff',
    diff_color = {
        -- Same color values as the general color option can be used here.
        added = { fg = '#98c379', bg = "red" },
        modified = { fg = '#7199ee', bg = "green" },
        removed = { fg = '#ee6d85', bg = "blue" },
    },
}

you get what you wanted (I added the background color for emphasis):

image

I have to say the lualine docs are not super explicit about this 😅

I'll close this one as I think your problem is solved. Feel free to re-open if you encounter any problems or have any questions.