diff options
author | Techie Guy <79499324+techie-guy@users.noreply.github.com> | 2022-11-27 20:56:04 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-27 11:26:04 -0400 |
commit | ccd66fd921e0e837b314249341eece7b4d5a135d (patch) | |
tree | be71a26afed0789b84efefe9048f88cb0c139f4e | |
parent | e1c3a2542b337eae8c12bd8e6d6923d4ba6e4dd8 (diff) | |
download | lite-xl-plugins-ccd66fd921e0e837b314249341eece7b4d5a135d.tar.gz lite-xl-plugins-ccd66fd921e0e837b314249341eece7b4d5a135d.zip |
[Plugin] Add Custom Caret Plugin (#162)
-rw-r--r-- | README.md | 1 | ||||
-rw-r--r-- | plugins/custom_caret.lua | 110 |
2 files changed, 111 insertions, 0 deletions
@@ -41,6 +41,7 @@ asterisk.* | [`console`](https://github.com/franko/console)\* | A console for running external commands and capturing their output *([gif](https://user-images.githubusercontent.com/3920290/81343656-49325a00-90ad-11ea-8647-ff39d8f1d730.gif))* | | [`contextmenu`](https://github.com/takase1121/lite-contextmenu)\* | Simple context menu *([screenshot](https://github.com/takase1121/lite-contextmenu/blob/master/assets/screenshot.jpg?raw=true))* | | [`copyfilelocation`](plugins/copyfilelocation.lua?raw=1) | Copy file location to clipboard | +| [`custom_caret`](plugins/custom_caret.lua?raw=1) | Customize the caret in the editor | | [`datetimestamps`](plugins/datetimestamps.lua?raw=1) | Insert date-, time- and date-time-stamps | | [`discord-presence`](https://github.com/vincens2005/lite-xl-discord)\* | Adds the current workspace and file to your Discord Rich Presence | | [`dragdropselected`](plugins/dragdropselected.lua?raw=1) | Provides basic drag and drop of selected text (in same document) | diff --git a/plugins/custom_caret.lua b/plugins/custom_caret.lua new file mode 100644 index 0000000..3307144 --- /dev/null +++ b/plugins/custom_caret.lua @@ -0,0 +1,110 @@ +-- mod-version:3 + +--[[ + Author: techie-guy + + Plugin to customize the caret in the editor + Thanks to @Guldoman for the initial example on Discord + + Features + 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) + config.plugins.custom_caret.shape - Change the shape of the caret [string] + style.caret - Change the rgba color of the caret [table] + + Example Config(in the .config/lite-xl/init.lua) + style.caret = {0, 255, 255, 150} + config.plugins.custom_caret.shape = "block" +]] + +local core = require "core" +local style = require "core.style" +local common = require "core.common" +local config = require "core.config" +local DocView = require "core.docview" + +config.plugins.custom_caret = common.merge({ + shape = "line", + 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 = { + name = "Custom Caret", + { + label = "Shape", + description = "The Shape of the cursor.", + path = "shape", + type = "selection", + default = "line", + values = { + {"Line", "line"}, + {"Block", "block"}, + {"Underline", "underline"} + } + }, + { + label = "Red Component of 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, + max = 255, + default = style.caret[1], + step = 1, + }, + { + label = "Green Component of 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, + max = 255, + default = style.caret[2], + step = 1, + }, + { + label = "Blue Component of 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, + max = 255, + default = style.caret[3], + step = 1, + }, + { + label = "Opacity of the Cursor", + description = "The Opacity of the caret", + path = "opacity", + type = "number", + min = 0, + max = 255, + default = style.caret[4], + step = 1, + }, + } +}, config.plugins.custom_caret) + +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} + + if (current_caret_shape == "block") then + caret_width = math.ceil(self:get_font():get_width("a")) + elseif (current_caret_shape == "underline") then + caret_width = math.ceil(self:get_font():get_width("a")) + caret_height = style.caret_width*2 + y = y+self:get_line_height() + else + caret_width = style.caret_width + caret_height = self:get_line_height() + end + + renderer.draw_rect(x, y, caret_width, caret_height, caret_color) +end |