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

Fix: blocks instead of gradient in neovim 11 #39

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion lua/colortils/css.lua
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ function css.list_colors()
border = require("colortils").settings.border,
style = "minimal",
})
vim.api.nvim_buf_set_option(buf, "modifiable", false)
vim.api.nvim__set_option_value("modifiable", false, { buf = buf })
-- try to attach colorizer
pcall(vim.cmd, "ColorizerAttachToBuffer")
end
Expand Down
2 changes: 1 addition & 1 deletion lua/colortils/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ colortils.settings = {
set_value = "c",
transparency = "T",
choose_background = "B",
quit_window = { "q", "<esc>" }
quit_window = { "q", "<esc>" },
},
}

Expand Down
25 changes: 13 additions & 12 deletions lua/colortils/tools/gradients/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ local format_strings = {
}

local function update(colors, state)
vim.api.nvim_buf_set_option(state.buf, "modifiable", true)
vim.api.nvim_set_option_value("modifiable", true, { buf = state.buf })
vim.api.nvim_buf_set_lines(state.buf, 0, 1, false, {})
color_utils.display_gradient(
state.buf,
Expand Down Expand Up @@ -79,7 +79,7 @@ local function update(colors, state)
bg = settings.background,
})
end
vim.api.nvim_buf_set_option(state.buf, "modifiable", false)
vim.api.nvim_set_option_value("modifiable", false, { buf = state.buf })
vim.api.nvim_buf_add_highlight(
state.buf,
state.ns,
Expand All @@ -99,7 +99,7 @@ local function adjust(amount, state)
end
if row == 2 then
state.idx = state.idx + amount
state.idx = math.max(math.min(state.idx, 255), 0)
state.idx = math.max(math.min(state.idx, 255), 1)
else
state.transparency = math.max(math.min(state.transparency + amount, 100), 0)
end
Expand Down Expand Up @@ -156,7 +156,7 @@ return function(color, color_2, alpha)
height = 3,
border = settings.border,
})
vim.api.nvim_win_set_option(state.win, "cursorline", false)
vim.api.nvim_win_set_hl_ns(state.win, state.ns)
color_utils.display_gradient(
state.buf,
state.ns,
Expand All @@ -167,14 +167,15 @@ return function(color, color_2, alpha)
colors.alpha,
colortils.settings.background
)
if vim.api.nvim_exec("hi NormalFloat", true):match("NormalFloat%s*xxx%s*cleared") then
if next(vim.api.nvim_get_hl(0, { name = "NormalFloat" })) == nil then
vim.api.nvim_set_hl(0, "NormalFloat", { link = "Normal" })
end
local cursor_fg = vim.api.nvim_get_hl_by_name("Cursor", true).foreground
local cursor_bg = vim.api.nvim_get_hl_by_name("Cursor", true).background
local cursor_fg = vim.api.nvim_get_hl(0, { name = "Cursor" }).fg
local cursor_bg = vim.api.nvim_get_hl(0, { name = "Cursor" }).bg
vim.api.nvim_set_hl(0, "Cursor", {
fg = vim.api.nvim_get_hl_by_name("NormalFloat", true).background,
bg = vim.api.nvim_get_hl_by_name("NormalFloat", true).background,
fg = vim.api.nvim_get_hl(0, { name = "NormalFloat" }).bg,
bg = vim.api.nvim_get_hl(0, { name = "NormalFloat" }).bg,
blend = 100,
})
vim.opt_local.guicursor = "a:ver1-Cursor/Cursor"

Expand All @@ -186,7 +187,7 @@ return function(color, color_2, alpha)
vim.opt_local.guicursor = "a:ver1-Cursor/Cursor"
else
vim.opt.guicursor = old_cursor
vim.api.nvim_set_hl(0, "Cursor", { fg = cursor_fg, bg = cursor_bg })
vim.api.nvim_set_hl(0, "Cursor", { fg = cursor_fg, bg = cursor_bg, blend = 0 })
end
end,
})
Expand Down Expand Up @@ -369,7 +370,7 @@ return function(color, color_2, alpha)
end
help_state.open = true
help_state.buf = vim.api.nvim_create_buf(false, true)
vim.api.nvim_buf_set_option(help_state.buf, "bufhidden", "wipe")
vim.api.nvim_set_option_value("bufhidden", "wipe", { buf = help_state.buf })
local lines = {
"Keybindings",
"Increment: " .. colortils.settings.mappings.increment,
Expand Down Expand Up @@ -420,7 +421,7 @@ return function(color, color_2, alpha)
help_state.buf = nil
end,
})
vim.api.nvim_buf_set_option(help_state.buf, "modifiable", false)
vim.api.nvim_set_option_value("modifiable", false, { buf = help_state.buf })
end, {
buffer = state.buf,
})
Expand Down
18 changes: 14 additions & 4 deletions lua/colortils/utils/colors.lua
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ function utils_color.get_blended_gradient(start_color, end_color, length, alpha,
return blended_gradient
end

local padding = "▌"

utils_color.display_gradient =
--- Displays gradient at a certain position
---@param buf number
Expand All @@ -84,13 +86,21 @@ utils_color.display_gradient =
else
gradient = utils_color.gradient_colors(start_color, end_color, width)
end
vim.api.nvim_buf_set_lines(buf, line, line, false, { string.rep("▌", width / 2) })

local virt_text = {}
for i = 1, width do
vim.api.nvim_set_hl(0, "ColortilsGradient" .. i, { fg = gradient[2 * i], bg = gradient[2 * i + 1] })
vim.api.nvim_set_hl(ns, "ColortilsGradient" .. i, { fg = gradient[2 * i], bg = gradient[2 * i + 1] })
end
for i = 1, width do
vim.api.nvim_buf_add_highlight(buf, ns, "ColortilsGradient" .. i, line, 3 * i - 1, 3 * i)
for i = 1, (width / 2) do
virt_text[i] = { padding, "ColortilsGradient" .. i }
end
vim.api.nvim_buf_set_lines(buf, line, line, false, { string.rep(" ", width / 2) })
vim.api.nvim_buf_set_extmark(buf, ns, line, 0, {
end_col = (width / 2) - 1,
virt_text = virt_text,
virt_text_pos = "overlay",
hl_eol = false,
})
end

--- Gets the gray color for a certain color
Expand Down
3 changes: 3 additions & 0 deletions makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
lint:
stylua lua/

test:
nvim --headless --noplugin \
-u tests/custom_init.vim \
Expand Down