From 98e39bafd505675f07da03a12caafae9e29e72b8 Mon Sep 17 00:00:00 2001 From: Mark Grey Date: Fri, 17 Jan 2025 12:56:20 -0500 Subject: [PATCH 1/5] fix deprecations --- lua/colortils/css.lua | 2 +- lua/colortils/tools/gradients/init.lua | 21 +++++++++++---------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/lua/colortils/css.lua b/lua/colortils/css.lua index e088a35..1ccdc0d 100644 --- a/lua/colortils/css.lua +++ b/lua/colortils/css.lua @@ -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 diff --git a/lua/colortils/tools/gradients/init.lua b/lua/colortils/tools/gradients/init.lua index 9966dad..064af45 100644 --- a/lua/colortils/tools/gradients/init.lua +++ b/lua/colortils/tools/gradients/init.lua @@ -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, @@ -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, @@ -156,7 +156,8 @@ 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) + vim.api.nvim_set_option_value("cursorline", false, {win = state.win}) color_utils.display_gradient( state.buf, state.ns, @@ -167,14 +168,14 @@ 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, }) vim.opt_local.guicursor = "a:ver1-Cursor/Cursor" @@ -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, @@ -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, }) From 05c1c97bee1c9af7304670693e190866ad8efc8c Mon Sep 17 00:00:00 2001 From: Mark Grey Date: Fri, 17 Jan 2025 12:56:35 -0500 Subject: [PATCH 2/5] fencepost error --- lua/colortils/tools/gradients/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/colortils/tools/gradients/init.lua b/lua/colortils/tools/gradients/init.lua index 064af45..b50d0e7 100644 --- a/lua/colortils/tools/gradients/init.lua +++ b/lua/colortils/tools/gradients/init.lua @@ -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 From de100b140a854401b234935984606cb19e54c2b3 Mon Sep 17 00:00:00 2001 From: Mark Grey Date: Fri, 17 Jan 2025 12:56:58 -0500 Subject: [PATCH 3/5] use virtual_text to ensure highlight prio --- lua/colortils/utils/colors.lua | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/lua/colortils/utils/colors.lua b/lua/colortils/utils/colors.lua index b3d599e..3793918 100644 --- a/lua/colortils/utils/colors.lua +++ b/lua/colortils/utils/colors.lua @@ -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 @@ -84,14 +86,23 @@ 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 - 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, + priority = 0, + virt_text = virt_text, + virt_text_pos = "overlay", + strict = false + }) + end --- Gets the gray color for a certain color ---@param color string "#xxxxxx" From 23d52caebabeb2b3fe8beffd8d3047600eaf78f3 Mon Sep 17 00:00:00 2001 From: Mark Grey Date: Fri, 17 Jan 2025 15:02:06 -0500 Subject: [PATCH 4/5] codestyle and make target for style --- lua/colortils/css.lua | 2 +- lua/colortils/init.lua | 2 +- lua/colortils/tools/gradients/init.lua | 20 ++++++++++---------- lua/colortils/utils/colors.lua | 16 ++++++++-------- makefile | 3 +++ 5 files changed, 23 insertions(+), 20 deletions(-) diff --git a/lua/colortils/css.lua b/lua/colortils/css.lua index 1ccdc0d..4db0d78 100644 --- a/lua/colortils/css.lua +++ b/lua/colortils/css.lua @@ -209,7 +209,7 @@ function css.list_colors() border = require("colortils").settings.border, style = "minimal", }) - vim.api.nvim__set_option_value("modifiable", false, {buf = buf}) + vim.api.nvim__set_option_value("modifiable", false, { buf = buf }) -- try to attach colorizer pcall(vim.cmd, "ColorizerAttachToBuffer") end diff --git a/lua/colortils/init.lua b/lua/colortils/init.lua index 2c79396..25e1707 100644 --- a/lua/colortils/init.lua +++ b/lua/colortils/init.lua @@ -25,7 +25,7 @@ colortils.settings = { set_value = "c", transparency = "T", choose_background = "B", - quit_window = { "q", "" } + quit_window = { "q", "" }, }, } diff --git a/lua/colortils/tools/gradients/init.lua b/lua/colortils/tools/gradients/init.lua index b50d0e7..c7930b4 100644 --- a/lua/colortils/tools/gradients/init.lua +++ b/lua/colortils/tools/gradients/init.lua @@ -37,7 +37,7 @@ local format_strings = { } local function update(colors, state) - vim.api.nvim_set_option_value("modifiable", true, {buf = state.buf}) + 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, @@ -79,7 +79,7 @@ local function update(colors, state) bg = settings.background, }) end - vim.api.nvim_set_option_value("modifiable", false, {buf = state.buf}) + vim.api.nvim_set_option_value("modifiable", false, { buf = state.buf }) vim.api.nvim_buf_add_highlight( state.buf, state.ns, @@ -157,7 +157,7 @@ return function(color, color_2, alpha) border = settings.border, }) vim.api.nvim_win_set_hl_ns(state.win, state.ns) - vim.api.nvim_set_option_value("cursorline", false, {win = state.win}) + vim.api.nvim_set_option_value("cursorline", false, { win = state.win }) color_utils.display_gradient( state.buf, state.ns, @@ -168,14 +168,14 @@ return function(color, color_2, alpha) colors.alpha, colortils.settings.background ) - if next(vim.api.nvim_get_hl(0, {name = "NormalFloat"})) == nil 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(0, {name="Cursor"}).fg - local cursor_bg = vim.api.nvim_get_hl(0, {name="Cursor"}).bg + 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(0, {name = "NormalFloat"}).bg, - bg = vim.api.nvim_get_hl(0, {name = "NormalFloat"}).bg, + fg = vim.api.nvim_get_hl(0, { name = "NormalFloat" }).bg, + bg = vim.api.nvim_get_hl(0, { name = "NormalFloat" }).bg, }) vim.opt_local.guicursor = "a:ver1-Cursor/Cursor" @@ -370,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_set_option_value("bufhidden", "wipe", {buf = help_state.buf}) + vim.api.nvim_set_option_value("bufhidden", "wipe", { buf = help_state.buf }) local lines = { "Keybindings", "Increment: " .. colortils.settings.mappings.increment, @@ -421,7 +421,7 @@ return function(color, color_2, alpha) help_state.buf = nil end, }) - vim.api.nvim_set_option_value("modifiable", false, {buf = help_state.buf}) + vim.api.nvim_set_option_value("modifiable", false, { buf = help_state.buf }) end, { buffer = state.buf, }) diff --git a/lua/colortils/utils/colors.lua b/lua/colortils/utils/colors.lua index 3793918..0c708ab 100644 --- a/lua/colortils/utils/colors.lua +++ b/lua/colortils/utils/colors.lua @@ -91,18 +91,18 @@ utils_color.display_gradient = for i = 1, width do vim.api.nvim_set_hl(ns, "ColortilsGradient" .. i, { fg = gradient[2 * i], bg = gradient[2 * i + 1] }) end - for i = 1, (width / 2) do - virt_text[i] = {padding, "ColortilsGradient" .. 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, - priority = 0, - virt_text = virt_text, - virt_text_pos = "overlay", - strict = false + end_col = width, + priority = 0, + virt_text = virt_text, + virt_text_pos = "overlay", + strict = false, }) - end + end --- Gets the gray color for a certain color ---@param color string "#xxxxxx" diff --git a/makefile b/makefile index 38fd292..7ed6aa7 100644 --- a/makefile +++ b/makefile @@ -1,3 +1,6 @@ +lint: + stylua lua/ + test: nvim --headless --noplugin \ -u tests/custom_init.vim \ From fb106df442a44854f8c15832256b750108bf7089 Mon Sep 17 00:00:00 2001 From: Mark Grey Date: Fri, 17 Jan 2025 19:39:10 -0500 Subject: [PATCH 5/5] remove cursor indicator in window --- lua/colortils/tools/gradients/init.lua | 4 ++-- lua/colortils/utils/colors.lua | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/lua/colortils/tools/gradients/init.lua b/lua/colortils/tools/gradients/init.lua index c7930b4..5d3b44f 100644 --- a/lua/colortils/tools/gradients/init.lua +++ b/lua/colortils/tools/gradients/init.lua @@ -157,7 +157,6 @@ return function(color, color_2, alpha) border = settings.border, }) vim.api.nvim_win_set_hl_ns(state.win, state.ns) - vim.api.nvim_set_option_value("cursorline", false, { win = state.win }) color_utils.display_gradient( state.buf, state.ns, @@ -176,6 +175,7 @@ return function(color, color_2, alpha) vim.api.nvim_set_hl(0, "Cursor", { 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" @@ -187,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, }) diff --git a/lua/colortils/utils/colors.lua b/lua/colortils/utils/colors.lua index 0c708ab..29131b8 100644 --- a/lua/colortils/utils/colors.lua +++ b/lua/colortils/utils/colors.lua @@ -96,11 +96,10 @@ utils_color.display_gradient = 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, - priority = 0, + end_col = (width / 2) - 1, virt_text = virt_text, virt_text_pos = "overlay", - strict = false, + hl_eol = false, }) end