diff options
Diffstat (limited to 'plugins/custom_caret.lua')
-rw-r--r-- | plugins/custom_caret.lua | 68 |
1 files changed, 57 insertions, 11 deletions
diff --git a/plugins/custom_caret.lua b/plugins/custom_caret.lua index 3307144..f0358cd 100644 --- a/plugins/custom_caret.lua +++ b/plugins/custom_caret.lua @@ -2,7 +2,7 @@ --[[ Author: techie-guy - + Plugin to customize the caret in the editor Thanks to @Guldoman for the initial example on Discord @@ -10,7 +10,8 @@ Change the Color and Opacity of the caret Change the Shape of the caret, available shapes are Line, Block, Underline - Customizing the Caret: (this can be changed from the .config/lite-xl/init.lua file or from the settings menu plugin) + Customizing the Caret: (this can be changed from the .config/lite-xl/init.lua + file or from the settings menu plugin) config.plugins.custom_caret.shape - Change the shape of the caret [string] style.caret - Change the rgba color of the caret [table] @@ -27,12 +28,38 @@ local DocView = require "core.docview" config.plugins.custom_caret = common.merge({ shape = "line", + custom_color = true, color_r = style.caret[1], color_g = style.caret[2], color_b = style.caret[3], - opacity = style.caret[4], - -- Config for settings gui - config_spec = { + opacity = style.caret[4] +}, config.plugins.custom_caret) + +-- Reference to plugin config +local conf = config.plugins.custom_caret + +-- Get real default caret color after everything is loaded up +core.add_thread(function() + if + conf.color_r == 147 and conf.color_g == 221 + and + conf.color_b == 250 and conf.opacity == 255 + and + ( + style.caret[1] ~= conf.color_r or style.caret[2] ~= conf.color_g + or + style.caret[3] ~= conf.color_b or style.caret[4] ~= conf.opacity + ) + then + conf.color_r = style.caret[1] + conf.color_g = style.caret[2] + conf.color_b = style.caret[3] + conf.opacity = style.caret[4] + end + + local settings_loaded, settings = pcall(require, "plugins.settings") + if settings_loaded then + conf.config_spec = { name = "Custom Caret", { label = "Shape", @@ -47,8 +74,16 @@ config.plugins.custom_caret = common.merge({ } }, { + label = "Custom Color", + description = "Use a custom color for the caret as specified below.", + path = "custom_color", + type = "toggle", + default = true + }, + { label = "Red Component of Color", - description = "The color consists of 3 components RGB, This modifies the 'R' component of the caret's color", + description = "The color consists of 3 components RGB, " + .. "This modifies the 'R' component of the caret's color", path = "color_r", type = "number", min = 0, @@ -58,7 +93,8 @@ config.plugins.custom_caret = common.merge({ }, { label = "Green Component of Color", - description = "The color consists of 3 components RGB, This modifies the 'G' component of the caret's color", + description = "The color consists of 3 components RGB, " + .. "This modifies the 'G' component of the caret's color", path = "color_g", type = "number", min = 0, @@ -68,7 +104,8 @@ config.plugins.custom_caret = common.merge({ }, { label = "Blue Component of Color", - description = "The color consists of 3 components RGB, This modifies the 'B' component of the caret's color", + description = "The color consists of 3 components RGB, " + .. "This modifies the 'B' component of the caret's color", path = "color_b", type = "number", min = 0, @@ -87,13 +124,22 @@ config.plugins.custom_caret = common.merge({ step = 1, }, } -}, config.plugins.custom_caret) + + ---@cast settings plugins.settings + settings.ui:enable_plugin("custom_caret") + end +end) function DocView:draw_caret(x, y) local caret_width = style.caret_width local caret_height = self:get_line_height() - local current_caret_shape = config.plugins.custom_caret.shape - local caret_color = {config.plugins.custom_caret.color_r, config.plugins.custom_caret.color_g, config.plugins.custom_caret.color_b, config.plugins.custom_caret.opacity} + local current_caret_shape = conf.shape + local caret_color = conf.custom_color and { + conf.color_r, + conf.color_g, + conf.color_b, + conf.opacity + } or style.caret if (current_caret_shape == "block") then caret_width = math.ceil(self:get_font():get_width("a")) |