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

feat: syntax highlighting in diffview #26

Merged
merged 2 commits into from
Apr 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 25 additions & 4 deletions lua/citruszest/highlights/init.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
local M = {}

---@param c string r g b of highlight
---@param bg string r g b of background
---@param a number between 0 and 1
---@return number
local blend = function(c, bg, a)
return math.floor(a * tonumber("0x"..c) + (1 - a) * tonumber("0x"..bg));
end

---@param hex string hex with 3 channels, ex: #00ff00
---@param bg string hex with 3 channels, ex: #000000
---@param a number between 0 and 1
---@return string
local add_alpha = function(hex, bg, a)
zootedb0t marked this conversation as resolved.
Show resolved Hide resolved
if not bg:match("^#%x%x%x%x%x%x$") then
bg = "#121212"
end
local r1, g1, b1 = hex:sub(2,3), hex:sub(4,5), hex:sub(6,7)
local r2, g2, b2 = bg:sub(2,3), bg:sub(4,5), bg:sub(6,7)
return "#" .. string.format("%02x%02x%02x", blend(r1, r2, a), blend(g1, g2, a), blend(b1, b2, a))
end

---@param C table
---@param O table
---@return table
Expand Down Expand Up @@ -125,10 +146,10 @@ M.theme = function(C, O)
diffFile = { fg = C.cyan },
diffLine = { fg = C.bright_cyan },
diffIndexLine = { fg = C.bright_black },
DiffAdd = { fg = C.green, bg = C.none, reverse = true }, -- diff mode: Added line |diff.txt|
DiffChange = { fg = C.yellow, bg = C.none, reverse = true }, -- diff mode: Changed line |diff.txt|
DiffDelete = { fg = C.red, bg = C.none, reverse = true }, -- diff mode: Deleted line |diff.txt|
DiffText = { bg = C.bright_black }, -- diff mode: Changed text within a changed line |diff.txt|
DiffAdd = { bg = add_alpha(C.green, C.background, 0.20)}, -- diff mode: Added line |diff.txt|
DiffChange = { bg = add_alpha(C.yellow, C.background, 0.20) }, -- diff mode: Changed line |diff.txt|
DiffDelete = { bg = add_alpha(C.bright_red, C.background, 0.20) }, -- diff mode: Deleted line |diff.txt|
DiffText = { bg = add_alpha(C.yellow, C.background, 0.35) }, -- diff mode: Changed text within a changed line |diff.txt|

-- NeoVim
healthError = { fg = C.red },
Expand Down
Loading