Skip to content

Commit

Permalink
fix(bufferline): Add configuration for bufferline tab (#117)
Browse files Browse the repository at this point in the history
- Add higlight for bufferline tab
- Fix the issue when transparent background is enabled
  • Loading branch information
loctvl842 committed Apr 1, 2024
1 parent 1b9b086 commit 5e3da37
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
16 changes: 11 additions & 5 deletions lua/monokai-pro/color_helper.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---@class Helper
local M = {}

---@param background? HexColor
---@param background? HexColor | "NONE"
local function get_blend_background(background)
if background ~= nil and background ~= "NONE" then
return background
Expand Down Expand Up @@ -33,9 +33,12 @@ local function rgb_to_hex(rgb)
return "#" .. red .. green .. blue
end

---@param hex HexColor
---@param hex HexColor | "NONE"
---@param amt number
M.lighten = function(hex, amt)
-- stylua: ignore
if hex == "NONE" then return hex end

local rgb = hex_to_rgb(hex)
-- over upper
rgb.r = (rgb.r + amt > 255) and 255 or (rgb.r + amt)
Expand Down Expand Up @@ -64,12 +67,15 @@ M.rgba = function(red, green, blue, alpha, background)
return rgb_to_hex({ r = red, g = green, b = blue })
end

---@param hexColor HexColor
---@param hex HexColor | "NONE"
---@param alpha HexColorAlpha
---@param base? HexColor
M.blend = function(hexColor, alpha, base)
M.blend = function(hex, alpha, base)
-- stylua: ignore
if hex == "NONE" then return "NONE" end

base = get_blend_background(base)
local rgb = hex_to_rgb(hexColor)
local rgb = hex_to_rgb(hex)
return M.rgba(rgb.r, rgb.g, rgb.b, alpha, base)
end

Expand Down
20 changes: 20 additions & 0 deletions lua/monokai-pro/theme/plugins/bufferline.lua
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ function M.get(c, config, hp)

local tabsBackground = isBackgroundClear and c.editor.background or c.editorGroupHeader.tabsBackground
local amt = 10

M.tab = vim.tbl_deep_extend("force", c.tab, isBackgroundClear and {
activeBackground = hp.lighten(c.tab.activeBackground, amt),
inactiveBackground = hp.lighten(c.tab.inactiveBackground, amt),
Expand Down Expand Up @@ -257,10 +258,29 @@ function M.get(c, config, hp)
bg = M.tab.unfocusedActiveBackground,
fg = c.base.red,
},
BufferLineTab = {
bg = M.tab.inactiveBackground,
fg = hp.blend(c.base.white, normalAlpha, M.tab.inactiveBackground),
},
BufferLineTabClose = {
bg = tabsBackground,
fg = tabsBackground,
},
BufferLineTabSelected = {
bg = M.tab.activeBackground,
fg = M.tab.activeForeground,
},
BufferLineTabSeparator = {
bg = M.tab.inactiveBackground,
fg = M.tab.inactiveBackground,
-- fg = tabsBackground,
},
BufferLineTabSeparatorSelected = {
bg = M.tab.activeBackground,
fg = M.tab.activeBackground,
-- fg = tabsBackground,
},

-- indicator
BufferLineIndicatorSelected = {
bg = M.tab.activeBackground,
Expand Down

0 comments on commit 5e3da37

Please sign in to comment.