From 3ef55966b191e539b7c201d56a8414a707f9a29e Mon Sep 17 00:00:00 2001 From: Jade Fox Date: Fri, 4 Oct 2024 15:30:23 -0700 Subject: [PATCH 01/24] Add rgba prefixes --- lua/tokyonight/extra/zathura.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lua/tokyonight/extra/zathura.lua b/lua/tokyonight/extra/zathura.lua index 39b5af27..b1f5c777 100644 --- a/lua/tokyonight/extra/zathura.lua +++ b/lua/tokyonight/extra/zathura.lua @@ -31,8 +31,8 @@ set inputbar-bg "${bg}" set inputbar-fg "${fg}" set statusbar-bg "${bg}" set statusbar-fg "${fg}" -set highlight-color "${yellow}" -set highlight-active-color "${green}" +set highlight-color "rgba(${yellow})" +set highlight-active-color "rgba(${green})" set default-bg "${bg}" set default-fg "${fg}" set render-loading true From f277d0283851658bded46436b58270c0318041fd Mon Sep 17 00:00:00 2001 From: Jade Fox Date: Fri, 4 Oct 2024 15:31:39 -0700 Subject: [PATCH 02/24] Add todo comment --- lua/tokyonight/extra/zathura.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lua/tokyonight/extra/zathura.lua b/lua/tokyonight/extra/zathura.lua index b1f5c777..09100a60 100644 --- a/lua/tokyonight/extra/zathura.lua +++ b/lua/tokyonight/extra/zathura.lua @@ -44,7 +44,10 @@ set render-loading-bg "${fg}" # set recolor-lightcolor "${bg}" set recolor-darkcolor "${fg}" -]], +]], -- TODO: Trim the first character from the color strings, + -- and then convert hex codes to decimal. + -- rgba uses an entirely different format that uses decimal instead of hex. + -- This is probably going to be harder than I thought... colors ) return zathura From 307ee94aa95a13fd48f90f48597ae2cdbe0931ce Mon Sep 17 00:00:00 2001 From: Jade Fox Date: Fri, 4 Oct 2024 15:58:42 -0700 Subject: [PATCH 03/24] Trim # from start of string fish.lua really did help with this --- lua/tokyonight/extra/zathura.lua | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lua/tokyonight/extra/zathura.lua b/lua/tokyonight/extra/zathura.lua index 09100a60..35c1db7f 100644 --- a/lua/tokyonight/extra/zathura.lua +++ b/lua/tokyonight/extra/zathura.lua @@ -4,6 +4,14 @@ local M = {} --- @param colors ColorScheme function M.generate(colors) + local zathuraColors = {} + -- Borrow code from fish template + for k, v in pairs(colors) do + if type(v) == "string" then + zathuraColors[k] = v:gsub("^#", "") + end + end + local zathura = util.template( [[ # Tokyonight color theme for Zathura @@ -48,7 +56,7 @@ set recolor-darkcolor "${fg}" -- and then convert hex codes to decimal. -- rgba uses an entirely different format that uses decimal instead of hex. -- This is probably going to be harder than I thought... - colors + zathuraColors ) return zathura end From a811943ba0ee7ce5f01b0b69f1a43b2ffbaa7fdc Mon Sep 17 00:00:00 2001 From: Jade Fox Date: Fri, 4 Oct 2024 16:02:19 -0700 Subject: [PATCH 04/24] hack: add back # for the options that need it --- lua/tokyonight/extra/zathura.lua | 50 +++++++++++++++++--------------- 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/lua/tokyonight/extra/zathura.lua b/lua/tokyonight/extra/zathura.lua index 35c1db7f..3337f63f 100644 --- a/lua/tokyonight/extra/zathura.lua +++ b/lua/tokyonight/extra/zathura.lua @@ -13,39 +13,41 @@ function M.generate(colors) end local zathura = util.template( + -- HACK: This is probably a terrible way of putting back the pound signs for the options that *do* use hex codes + -- Figure out a way to have it so that the options that do need to be changed actually are changed [[ # Tokyonight color theme for Zathura # Swaps Foreground for Background to get a light version if the user prefers # # Tokyonight color theme # -set notification-error-bg "${red}" -set notification-error-fg "${fg}" -set notification-warning-bg "${yellow}" -set notification-warning-fg "${terminal_black}" -set notification-bg "${bg}" -set notification-fg "${fg}" -set completion-bg "${bg}" -set completion-fg "${fg_dark}" -set completion-group-bg "${bg}" -set completion-group-fg "${fg_dark}" -set completion-highlight-bg "${terminal_black}" -set completion-highlight-fg "${fg}" -set index-bg "${bg}" -set index-fg "${fg}" -set index-active-bg "${terminal_black}" -set index-active-fg "${fg}" -set inputbar-bg "${bg}" -set inputbar-fg "${fg}" -set statusbar-bg "${bg}" -set statusbar-fg "${fg}" +set notification-error-bg "#${red}" +set notification-error-fg "#${fg}" +set notification-warning-bg "#${yellow}" +set notification-warning-fg "#${terminal_black}" +set notification-bg "#${bg}" +set notification-fg "#${fg}" +set completion-bg "#${bg}" +set completion-fg "#${fg_dark}" +set completion-group-bg "#${bg}" +set completion-group-fg "#${fg_dark}" +set completion-highlight-bg "#${terminal_black}" +set completion-highlight-fg "#${fg}" +set index-bg "#${bg}" +set index-fg "#${fg}" +set index-active-bg "#${terminal_black}" +set index-active-fg "#${fg}" +set inputbar-bg "#${bg}" +set inputbar-fg "#${fg}" +set statusbar-bg "#${bg}" +set statusbar-fg "#${fg}" set highlight-color "rgba(${yellow})" set highlight-active-color "rgba(${green})" -set default-bg "${bg}" -set default-fg "${fg}" +set default-bg "#${bg}" +set default-fg "#${fg}" set render-loading true -set render-loading-fg "${bg}" -set render-loading-bg "${fg}" +set render-loading-fg "#${bg}" +set render-loading-bg "#${fg}" # # Recolor mode settings # to switch modes From 0723642b7af4d52349a362d508d673f2119d87e5 Mon Sep 17 00:00:00 2001 From: Jade Fox Date: Fri, 4 Oct 2024 16:07:00 -0700 Subject: [PATCH 05/24] fix: forgot two other options that use hex codes There has to be a better way of doing this --- lua/tokyonight/extra/zathura.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lua/tokyonight/extra/zathura.lua b/lua/tokyonight/extra/zathura.lua index 3337f63f..6307aabd 100644 --- a/lua/tokyonight/extra/zathura.lua +++ b/lua/tokyonight/extra/zathura.lua @@ -52,8 +52,8 @@ set render-loading-bg "#${fg}" # Recolor mode settings # to switch modes # -set recolor-lightcolor "${bg}" -set recolor-darkcolor "${fg}" +set recolor-lightcolor "#${bg}" +set recolor-darkcolor "#${fg}" ]], -- TODO: Trim the first character from the color strings, -- and then convert hex codes to decimal. -- rgba uses an entirely different format that uses decimal instead of hex. From 23b7f1f0375dcaede2004094ff5501067bbdea70 Mon Sep 17 00:00:00 2001 From: Jade Fox Date: Fri, 4 Oct 2024 16:26:37 -0700 Subject: [PATCH 06/24] Undo hacks trim # --- lua/tokyonight/extra/zathura.lua | 64 ++++++++++++++------------------ 1 file changed, 27 insertions(+), 37 deletions(-) diff --git a/lua/tokyonight/extra/zathura.lua b/lua/tokyonight/extra/zathura.lua index 6307aabd..09100a60 100644 --- a/lua/tokyonight/extra/zathura.lua +++ b/lua/tokyonight/extra/zathura.lua @@ -4,61 +4,51 @@ local M = {} --- @param colors ColorScheme function M.generate(colors) - local zathuraColors = {} - -- Borrow code from fish template - for k, v in pairs(colors) do - if type(v) == "string" then - zathuraColors[k] = v:gsub("^#", "") - end - end - local zathura = util.template( - -- HACK: This is probably a terrible way of putting back the pound signs for the options that *do* use hex codes - -- Figure out a way to have it so that the options that do need to be changed actually are changed [[ # Tokyonight color theme for Zathura # Swaps Foreground for Background to get a light version if the user prefers # # Tokyonight color theme # -set notification-error-bg "#${red}" -set notification-error-fg "#${fg}" -set notification-warning-bg "#${yellow}" -set notification-warning-fg "#${terminal_black}" -set notification-bg "#${bg}" -set notification-fg "#${fg}" -set completion-bg "#${bg}" -set completion-fg "#${fg_dark}" -set completion-group-bg "#${bg}" -set completion-group-fg "#${fg_dark}" -set completion-highlight-bg "#${terminal_black}" -set completion-highlight-fg "#${fg}" -set index-bg "#${bg}" -set index-fg "#${fg}" -set index-active-bg "#${terminal_black}" -set index-active-fg "#${fg}" -set inputbar-bg "#${bg}" -set inputbar-fg "#${fg}" -set statusbar-bg "#${bg}" -set statusbar-fg "#${fg}" +set notification-error-bg "${red}" +set notification-error-fg "${fg}" +set notification-warning-bg "${yellow}" +set notification-warning-fg "${terminal_black}" +set notification-bg "${bg}" +set notification-fg "${fg}" +set completion-bg "${bg}" +set completion-fg "${fg_dark}" +set completion-group-bg "${bg}" +set completion-group-fg "${fg_dark}" +set completion-highlight-bg "${terminal_black}" +set completion-highlight-fg "${fg}" +set index-bg "${bg}" +set index-fg "${fg}" +set index-active-bg "${terminal_black}" +set index-active-fg "${fg}" +set inputbar-bg "${bg}" +set inputbar-fg "${fg}" +set statusbar-bg "${bg}" +set statusbar-fg "${fg}" set highlight-color "rgba(${yellow})" set highlight-active-color "rgba(${green})" -set default-bg "#${bg}" -set default-fg "#${fg}" +set default-bg "${bg}" +set default-fg "${fg}" set render-loading true -set render-loading-fg "#${bg}" -set render-loading-bg "#${fg}" +set render-loading-fg "${bg}" +set render-loading-bg "${fg}" # # Recolor mode settings # to switch modes # -set recolor-lightcolor "#${bg}" -set recolor-darkcolor "#${fg}" +set recolor-lightcolor "${bg}" +set recolor-darkcolor "${fg}" ]], -- TODO: Trim the first character from the color strings, -- and then convert hex codes to decimal. -- rgba uses an entirely different format that uses decimal instead of hex. -- This is probably going to be harder than I thought... - zathuraColors + colors ) return zathura end From c70cbea53d597e47ea1cc571e7e36a14f74c32d7 Mon Sep 17 00:00:00 2001 From: Jade Fox Date: Fri, 4 Oct 2024 16:27:54 -0700 Subject: [PATCH 07/24] Add alpha argument for rgba --- lua/tokyonight/extra/zathura.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lua/tokyonight/extra/zathura.lua b/lua/tokyonight/extra/zathura.lua index 09100a60..4d512a12 100644 --- a/lua/tokyonight/extra/zathura.lua +++ b/lua/tokyonight/extra/zathura.lua @@ -31,8 +31,8 @@ set inputbar-bg "${bg}" set inputbar-fg "${fg}" set statusbar-bg "${bg}" set statusbar-fg "${fg}" -set highlight-color "rgba(${yellow})" -set highlight-active-color "rgba(${green})" +set highlight-color "rgba(${yellow}, 0.5)" +set highlight-active-color "rgba(${green}, 0.5)" set default-bg "${bg}" set default-fg "${fg}" set render-loading true From b01770c4de72ee3374d452ccf67ad5a68174926b Mon Sep 17 00:00:00 2001 From: Jade Fox Date: Fri, 4 Oct 2024 18:07:53 -0700 Subject: [PATCH 08/24] Convert hex codes into decimals This took way too long to write and figure out how to do, I really hope this works --- lua/tokyonight/extra/zathura.lua | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lua/tokyonight/extra/zathura.lua b/lua/tokyonight/extra/zathura.lua index 4d512a12..a390099d 100644 --- a/lua/tokyonight/extra/zathura.lua +++ b/lua/tokyonight/extra/zathura.lua @@ -4,6 +4,14 @@ local M = {} --- @param colors ColorScheme function M.generate(colors) + local zathuraColors = {} + for k, v in pairs(colors) do + if k == ("yellow" or "green") then + zathuraColors[k .. "DecimalR"] = tostring(tonumber(string.sub(v, 2, 3), 16)) + zathuraColors[k .. "DecimalG"] = tostring(tonumber(string.sub(v, 4, 5), 16)) + zathuraColors[k .. "DecimalB"] = tostring(tonumber(string.sub(v, 5, 7), 16)) + end + end local zathura = util.template( [[ # Tokyonight color theme for Zathura @@ -31,8 +39,8 @@ set inputbar-bg "${bg}" set inputbar-fg "${fg}" set statusbar-bg "${bg}" set statusbar-fg "${fg}" -set highlight-color "rgba(${yellow}, 0.5)" -set highlight-active-color "rgba(${green}, 0.5)" +set highlight-color "rgba(${yellowDecimalR}, ${yellowDecimalG}, ${yellowDecimalB}, 0.5)" +set highlight-active-color "rgba(${greenDecimalR}, ${greenDecimalG}, ${greenDecimalB}, 0.5)" set default-bg "${bg}" set default-fg "${fg}" set render-loading true @@ -48,7 +56,7 @@ set recolor-darkcolor "${fg}" -- and then convert hex codes to decimal. -- rgba uses an entirely different format that uses decimal instead of hex. -- This is probably going to be harder than I thought... - colors + zathuraColors ) return zathura end From c6343c7597a6ee7d74952a407522bd24e0eccd9a Mon Sep 17 00:00:00 2001 From: Jade Fox Date: Fri, 4 Oct 2024 18:16:10 -0700 Subject: [PATCH 09/24] Pass all other colors normally --- lua/tokyonight/extra/zathura.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/lua/tokyonight/extra/zathura.lua b/lua/tokyonight/extra/zathura.lua index a390099d..af9daf5d 100644 --- a/lua/tokyonight/extra/zathura.lua +++ b/lua/tokyonight/extra/zathura.lua @@ -11,6 +11,7 @@ function M.generate(colors) zathuraColors[k .. "DecimalG"] = tostring(tonumber(string.sub(v, 4, 5), 16)) zathuraColors[k .. "DecimalB"] = tostring(tonumber(string.sub(v, 5, 7), 16)) end + zathuraColors[k] = v end local zathura = util.template( [[ From 402536b076461635d71d7c929b1c221fdc535a1d Mon Sep 17 00:00:00 2001 From: Jade Fox Date: Fri, 4 Oct 2024 18:16:24 -0700 Subject: [PATCH 10/24] fix: string interpolation for green color now functions properly --- lua/tokyonight/extra/zathura.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/tokyonight/extra/zathura.lua b/lua/tokyonight/extra/zathura.lua index af9daf5d..f5e12545 100644 --- a/lua/tokyonight/extra/zathura.lua +++ b/lua/tokyonight/extra/zathura.lua @@ -6,7 +6,7 @@ local M = {} function M.generate(colors) local zathuraColors = {} for k, v in pairs(colors) do - if k == ("yellow" or "green") then + if k == "yellow" or k == "green" then zathuraColors[k .. "DecimalR"] = tostring(tonumber(string.sub(v, 2, 3), 16)) zathuraColors[k .. "DecimalG"] = tostring(tonumber(string.sub(v, 4, 5), 16)) zathuraColors[k .. "DecimalB"] = tostring(tonumber(string.sub(v, 5, 7), 16)) From 0224a9cb66723bf8d170854415497b11ee0fcdd9 Mon Sep 17 00:00:00 2001 From: Jade Fox Date: Fri, 4 Oct 2024 18:17:38 -0700 Subject: [PATCH 11/24] Remove todo comment --- lua/tokyonight/extra/zathura.lua | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lua/tokyonight/extra/zathura.lua b/lua/tokyonight/extra/zathura.lua index f5e12545..1c3b96b4 100644 --- a/lua/tokyonight/extra/zathura.lua +++ b/lua/tokyonight/extra/zathura.lua @@ -53,10 +53,7 @@ set render-loading-bg "${fg}" # set recolor-lightcolor "${bg}" set recolor-darkcolor "${fg}" -]], -- TODO: Trim the first character from the color strings, - -- and then convert hex codes to decimal. - -- rgba uses an entirely different format that uses decimal instead of hex. - -- This is probably going to be harder than I thought... +]], zathuraColors ) return zathura From 61686247a54a1f672907f045ce6e2053789eb95d Mon Sep 17 00:00:00 2001 From: Jade Fox Date: Fri, 4 Oct 2024 18:19:53 -0700 Subject: [PATCH 12/24] Add fix comment --- lua/tokyonight/extra/zathura.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/lua/tokyonight/extra/zathura.lua b/lua/tokyonight/extra/zathura.lua index 1c3b96b4..a36ad356 100644 --- a/lua/tokyonight/extra/zathura.lua +++ b/lua/tokyonight/extra/zathura.lua @@ -9,6 +9,7 @@ function M.generate(colors) if k == "yellow" or k == "green" then zathuraColors[k .. "DecimalR"] = tostring(tonumber(string.sub(v, 2, 3), 16)) zathuraColors[k .. "DecimalG"] = tostring(tonumber(string.sub(v, 4, 5), 16)) + -- FIX: Blue decimal color does not output correctly zathuraColors[k .. "DecimalB"] = tostring(tonumber(string.sub(v, 5, 7), 16)) end zathuraColors[k] = v From 1bc564289561e60ff2e4f16528f09a0f3d20f2b6 Mon Sep 17 00:00:00 2001 From: Jade Fox Date: Fri, 4 Oct 2024 18:21:25 -0700 Subject: [PATCH 13/24] fix: incorrect bounds for obtaining blue component --- lua/tokyonight/extra/zathura.lua | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lua/tokyonight/extra/zathura.lua b/lua/tokyonight/extra/zathura.lua index a36ad356..d3da9630 100644 --- a/lua/tokyonight/extra/zathura.lua +++ b/lua/tokyonight/extra/zathura.lua @@ -9,8 +9,7 @@ function M.generate(colors) if k == "yellow" or k == "green" then zathuraColors[k .. "DecimalR"] = tostring(tonumber(string.sub(v, 2, 3), 16)) zathuraColors[k .. "DecimalG"] = tostring(tonumber(string.sub(v, 4, 5), 16)) - -- FIX: Blue decimal color does not output correctly - zathuraColors[k .. "DecimalB"] = tostring(tonumber(string.sub(v, 5, 7), 16)) + zathuraColors[k .. "DecimalB"] = tostring(tonumber(string.sub(v, 6, 7), 16)) end zathuraColors[k] = v end From e77df63f0c153eb0985db93114cc24602e435072 Mon Sep 17 00:00:00 2001 From: Jade Fox Date: Fri, 4 Oct 2024 18:34:28 -0700 Subject: [PATCH 14/24] Use more compact field access for substrings --- lua/tokyonight/extra/zathura.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lua/tokyonight/extra/zathura.lua b/lua/tokyonight/extra/zathura.lua index d3da9630..2397868f 100644 --- a/lua/tokyonight/extra/zathura.lua +++ b/lua/tokyonight/extra/zathura.lua @@ -7,9 +7,9 @@ function M.generate(colors) local zathuraColors = {} for k, v in pairs(colors) do if k == "yellow" or k == "green" then - zathuraColors[k .. "DecimalR"] = tostring(tonumber(string.sub(v, 2, 3), 16)) - zathuraColors[k .. "DecimalG"] = tostring(tonumber(string.sub(v, 4, 5), 16)) - zathuraColors[k .. "DecimalB"] = tostring(tonumber(string.sub(v, 6, 7), 16)) + zathuraColors[k .. "DecimalR"] = tostring(tonumber(v:sub(2, 3), 16)) + zathuraColors[k .. "DecimalG"] = tostring(tonumber(v:sub(4, 5), 16)) + zathuraColors[k .. "DecimalB"] = tostring(tonumber(v:sub(6, 7), 16)) end zathuraColors[k] = v end From 3f6aa888dc6cfaf0ceb24f4d177ae8c607de54fd Mon Sep 17 00:00:00 2001 From: Jade Fox Date: Fri, 4 Oct 2024 18:36:38 -0700 Subject: [PATCH 15/24] Remove tostring function Lua implicitly converts the number to a string when interpolating, it's easier to read like this anyway --- lua/tokyonight/extra/zathura.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lua/tokyonight/extra/zathura.lua b/lua/tokyonight/extra/zathura.lua index 2397868f..59734308 100644 --- a/lua/tokyonight/extra/zathura.lua +++ b/lua/tokyonight/extra/zathura.lua @@ -7,9 +7,9 @@ function M.generate(colors) local zathuraColors = {} for k, v in pairs(colors) do if k == "yellow" or k == "green" then - zathuraColors[k .. "DecimalR"] = tostring(tonumber(v:sub(2, 3), 16)) - zathuraColors[k .. "DecimalG"] = tostring(tonumber(v:sub(4, 5), 16)) - zathuraColors[k .. "DecimalB"] = tostring(tonumber(v:sub(6, 7), 16)) + zathuraColors[k .. "DecimalR"] = tonumber(v:sub(2, 3), 16) + zathuraColors[k .. "DecimalG"] = tonumber(v:sub(4, 5), 16) + zathuraColors[k .. "DecimalB"] = tonumber(v:sub(6, 7), 16) end zathuraColors[k] = v end From ec4ad5549273465c9023c7598558c2577bed420e Mon Sep 17 00:00:00 2001 From: Jade Fox Date: Fri, 4 Oct 2024 19:21:02 -0700 Subject: [PATCH 16/24] Rename parameter to reduce confusion --- lua/tokyonight/extra/zathura.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lua/tokyonight/extra/zathura.lua b/lua/tokyonight/extra/zathura.lua index 59734308..da2ad0ef 100644 --- a/lua/tokyonight/extra/zathura.lua +++ b/lua/tokyonight/extra/zathura.lua @@ -2,10 +2,10 @@ local util = require("tokyonight.util") local M = {} ---- @param colors ColorScheme -function M.generate(colors) +--- @param pColors ColorScheme +function M.generate(pColors) local zathuraColors = {} - for k, v in pairs(colors) do + for k, v in pairs(pColors) do if k == "yellow" or k == "green" then zathuraColors[k .. "DecimalR"] = tonumber(v:sub(2, 3), 16) zathuraColors[k .. "DecimalG"] = tonumber(v:sub(4, 5), 16) From d5f438a3e104668edc4ef1fb42de5ad85697bd05 Mon Sep 17 00:00:00 2001 From: Jade Fox Date: Fri, 4 Oct 2024 19:24:55 -0700 Subject: [PATCH 17/24] refactor: inserting colors is more concise now --- lua/tokyonight/extra/zathura.lua | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lua/tokyonight/extra/zathura.lua b/lua/tokyonight/extra/zathura.lua index da2ad0ef..6f9caa56 100644 --- a/lua/tokyonight/extra/zathura.lua +++ b/lua/tokyonight/extra/zathura.lua @@ -7,9 +7,13 @@ function M.generate(pColors) local zathuraColors = {} for k, v in pairs(pColors) do if k == "yellow" or k == "green" then - zathuraColors[k .. "DecimalR"] = tonumber(v:sub(2, 3), 16) - zathuraColors[k .. "DecimalG"] = tonumber(v:sub(4, 5), 16) - zathuraColors[k .. "DecimalB"] = tonumber(v:sub(6, 7), 16) + local colorNames = { "R", "G", "B" } + -- Start at 2 to skip # + local hexIndex = 2 + for i = 1, #colorNames do + zathuraColors[k .. "Decimal" .. colorNames[i]] = tonumber(v:sub(hexIndex, hexIndex + 1), 16) + hexIndex = hexIndex + 1 + end end zathuraColors[k] = v end From 1f3ef54bc5e7fd185f0cfc52199e6e20ae0042a2 Mon Sep 17 00:00:00 2001 From: Jade Fox Date: Fri, 4 Oct 2024 19:26:33 -0700 Subject: [PATCH 18/24] Rename key-value variables specific to function parameter --- lua/tokyonight/extra/zathura.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lua/tokyonight/extra/zathura.lua b/lua/tokyonight/extra/zathura.lua index 6f9caa56..84cd2744 100644 --- a/lua/tokyonight/extra/zathura.lua +++ b/lua/tokyonight/extra/zathura.lua @@ -5,17 +5,17 @@ local M = {} --- @param pColors ColorScheme function M.generate(pColors) local zathuraColors = {} - for k, v in pairs(pColors) do - if k == "yellow" or k == "green" then + for pColorsK, pColorsV in pairs(pColors) do + if pColorsK == "yellow" or pColorsK == "green" then local colorNames = { "R", "G", "B" } -- Start at 2 to skip # local hexIndex = 2 for i = 1, #colorNames do - zathuraColors[k .. "Decimal" .. colorNames[i]] = tonumber(v:sub(hexIndex, hexIndex + 1), 16) + zathuraColors[pColorsK .. "Decimal" .. colorNames[i]] = tonumber(pColorsV:sub(hexIndex, hexIndex + 1), 16) hexIndex = hexIndex + 1 end end - zathuraColors[k] = v + zathuraColors[pColorsK] = pColorsV end local zathura = util.template( [[ From 23a65d36c35888b556f3c7e61bb32d0365313473 Mon Sep 17 00:00:00 2001 From: Jade Fox Date: Fri, 4 Oct 2024 19:34:03 -0700 Subject: [PATCH 19/24] fix: hexIndex now increments correct amount --- lua/tokyonight/extra/zathura.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/tokyonight/extra/zathura.lua b/lua/tokyonight/extra/zathura.lua index 84cd2744..5e72d3f1 100644 --- a/lua/tokyonight/extra/zathura.lua +++ b/lua/tokyonight/extra/zathura.lua @@ -12,7 +12,7 @@ function M.generate(pColors) local hexIndex = 2 for i = 1, #colorNames do zathuraColors[pColorsK .. "Decimal" .. colorNames[i]] = tonumber(pColorsV:sub(hexIndex, hexIndex + 1), 16) - hexIndex = hexIndex + 1 + hexIndex = hexIndex + 2 end end zathuraColors[pColorsK] = pColorsV From 3abd949487ea2fc6d7c97c3415d2682722fad3a0 Mon Sep 17 00:00:00 2001 From: Jade Fox Date: Sat, 5 Oct 2024 13:32:15 -0700 Subject: [PATCH 20/24] refactor(color conversion): separate check logic into function --- lua/tokyonight/extra/zathura.lua | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/lua/tokyonight/extra/zathura.lua b/lua/tokyonight/extra/zathura.lua index 5e72d3f1..52a04aa9 100644 --- a/lua/tokyonight/extra/zathura.lua +++ b/lua/tokyonight/extra/zathura.lua @@ -6,7 +6,21 @@ local M = {} function M.generate(pColors) local zathuraColors = {} for pColorsK, pColorsV in pairs(pColors) do - if pColorsK == "yellow" or pColorsK == "green" then + -- Add any color names we need to convert from hex to decimal + local decimalColors = { "yellow", "green" } + -- Return true if a table contains a value + ---@param tab table Table to search in + ---@param val any Value to locate in table + -- NOTE: Should this be put in util.lua? + local function contains(tab, val) + for _, value in ipairs(tab) do + if value == val then + return true + end + end + return false + end + if contains(decimalColors, pColorsK) then local colorNames = { "R", "G", "B" } -- Start at 2 to skip # local hexIndex = 2 From 3567f38c9fd375adee77b7bb147d71a6a188ff43 Mon Sep 17 00:00:00 2001 From: Jade Fox Date: Sat, 5 Oct 2024 13:37:34 -0700 Subject: [PATCH 21/24] docs(zathura): add comments to document custom table function --- lua/tokyonight/extra/zathura.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lua/tokyonight/extra/zathura.lua b/lua/tokyonight/extra/zathura.lua index 52a04aa9..597e46a5 100644 --- a/lua/tokyonight/extra/zathura.lua +++ b/lua/tokyonight/extra/zathura.lua @@ -24,11 +24,13 @@ function M.generate(pColors) local colorNames = { "R", "G", "B" } -- Start at 2 to skip # local hexIndex = 2 + -- Inserts values into table in form of {color}Decimal{R,G,B} for i = 1, #colorNames do zathuraColors[pColorsK .. "Decimal" .. colorNames[i]] = tonumber(pColorsV:sub(hexIndex, hexIndex + 1), 16) hexIndex = hexIndex + 2 end end + -- Add other colors into table normally zathuraColors[pColorsK] = pColorsV end local zathura = util.template( From f2ef4fe416505b6e92b26e041ea0acaacd7cfc60 Mon Sep 17 00:00:00 2001 From: Jade Fox Date: Sun, 6 Oct 2024 13:40:13 -0700 Subject: [PATCH 22/24] refactor(color conversion): assign to variables first, then insert The code is significantly easier to read, easier to maintain, and generally much better looking with this change. --- lua/tokyonight/extra/zathura.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lua/tokyonight/extra/zathura.lua b/lua/tokyonight/extra/zathura.lua index 597e46a5..a89b0576 100644 --- a/lua/tokyonight/extra/zathura.lua +++ b/lua/tokyonight/extra/zathura.lua @@ -26,7 +26,9 @@ function M.generate(pColors) local hexIndex = 2 -- Inserts values into table in form of {color}Decimal{R,G,B} for i = 1, #colorNames do - zathuraColors[pColorsK .. "Decimal" .. colorNames[i]] = tonumber(pColorsV:sub(hexIndex, hexIndex + 1), 16) + local zColorsK = pColorsK .. "Decimal" .. colorNames[i] + local zColorsV = tonumber(pColorsV:sub(hexIndex, hexIndex + 1), 16) + zathuraColors[zColorsK] = zColorsV hexIndex = hexIndex + 2 end end From c2e5a23246410a94936dea178482e57d8fbaa4ea Mon Sep 17 00:00:00 2001 From: Jade Fox Date: Sun, 6 Oct 2024 14:49:21 -0700 Subject: [PATCH 23/24] chore(zathura): remove note comment Unless some other file needs the ability to convert hex color codes to decimal, there isn't any need to move it to util.lua, keep the function at the lowest scope possible --- lua/tokyonight/extra/zathura.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/lua/tokyonight/extra/zathura.lua b/lua/tokyonight/extra/zathura.lua index a89b0576..482d340f 100644 --- a/lua/tokyonight/extra/zathura.lua +++ b/lua/tokyonight/extra/zathura.lua @@ -11,7 +11,6 @@ function M.generate(pColors) -- Return true if a table contains a value ---@param tab table Table to search in ---@param val any Value to locate in table - -- NOTE: Should this be put in util.lua? local function contains(tab, val) for _, value in ipairs(tab) do if value == val then From 93a458703575b1e9212f8b16b2229afff43e811f Mon Sep 17 00:00:00 2001 From: Jade Fox Date: Sun, 6 Oct 2024 15:00:52 -0700 Subject: [PATCH 24/24] style(zathura): improve clarity of variable names --- lua/tokyonight/extra/zathura.lua | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/lua/tokyonight/extra/zathura.lua b/lua/tokyonight/extra/zathura.lua index 482d340f..7a691a4b 100644 --- a/lua/tokyonight/extra/zathura.lua +++ b/lua/tokyonight/extra/zathura.lua @@ -2,12 +2,12 @@ local util = require("tokyonight.util") local M = {} ---- @param pColors ColorScheme -function M.generate(pColors) +--- @param colors ColorScheme +function M.generate(colors) local zathuraColors = {} - for pColorsK, pColorsV in pairs(pColors) do + for colorsK, colorsV in pairs(colors) do -- Add any color names we need to convert from hex to decimal - local decimalColors = { "yellow", "green" } + local convertColors = { "yellow", "green" } -- Return true if a table contains a value ---@param tab table Table to search in ---@param val any Value to locate in table @@ -19,20 +19,20 @@ function M.generate(pColors) end return false end - if contains(decimalColors, pColorsK) then + if contains(convertColors, colorsK) then local colorNames = { "R", "G", "B" } -- Start at 2 to skip # local hexIndex = 2 -- Inserts values into table in form of {color}Decimal{R,G,B} for i = 1, #colorNames do - local zColorsK = pColorsK .. "Decimal" .. colorNames[i] - local zColorsV = tonumber(pColorsV:sub(hexIndex, hexIndex + 1), 16) - zathuraColors[zColorsK] = zColorsV + local zathuraColorsK = colorsK .. "Decimal" .. colorNames[i] + local zathuraColorsV = tonumber(colorsV:sub(hexIndex, hexIndex + 1), 16) + zathuraColors[zathuraColorsK] = zathuraColorsV hexIndex = hexIndex + 2 end end -- Add other colors into table normally - zathuraColors[pColorsK] = pColorsV + zathuraColors[colorsK] = colorsV end local zathura = util.template( [[