aboutsummaryrefslogtreecommitdiff
path: root/plugins/gitstatus.lua
diff options
context:
space:
mode:
authorjgmdev <jgmdev@gmail.com>2022-05-24 19:29:50 -0400
committerjgmdev <jgmdev@gmail.com>2022-05-24 19:29:50 -0400
commit35e947d1933613bb0b5a1488bf0fa4587f98ef7d (patch)
tree07d2515f44db03b1e865f6aef6adfd12b118890b /plugins/gitstatus.lua
parentc1f3671e2a8defbc67d1e77c72d5866f2825cdb5 (diff)
downloadlite-xl-plugins-35e947d1933613bb0b5a1488bf0fa4587f98ef7d.tar.gz
lite-xl-plugins-35e947d1933613bb0b5a1488bf0fa4587f98ef7d.zip
added config_spec and other plugin compatibility fixes.
Diffstat (limited to 'plugins/gitstatus.lua')
-rw-r--r--plugins/gitstatus.lua47
1 files changed, 32 insertions, 15 deletions
diff --git a/plugins/gitstatus.lua b/plugins/gitstatus.lua
index 33dc5e5..9ba792c 100644
--- a/plugins/gitstatus.lua
+++ b/plugins/gitstatus.lua
@@ -6,15 +6,37 @@ local style = require "core.style"
local StatusView = require "core.statusview"
local TreeView = require "plugins.treeview"
+config.plugins.gitstatus = common.merge({
+ recurse_submodules = true,
+ -- The config specification used by the settings gui
+ config_spec = {
+ name = "Git Status",
+ {
+ label = "Recurse Submodules",
+ description = "Also retrieve git stats from submodules.",
+ path = "recurse_submodules",
+ type = "toggle",
+ default = true
+ }
+ }
+}, config.plugins.gitstatus)
+
+style.gitstatus_addition = {common.color "#587c0c"}
+style.gitstatus_modification = {common.color "#0c7d9d"}
+style.gitstatus_deletion = {common.color "#94151b"}
+
local scan_rate = config.project_scan_rate or 5
local cached_color_for_item = {}
--- Override TreeView's color_for_item, but first
--- stash the old one (using [] in case it is not there at all)
-local old_color_for_item = TreeView["color_for_item"]
-function TreeView:color_for_item(abs_path)
- return cached_color_for_item[abs_path] or old_color_for_item(abs_path)
+-- Override TreeView's get_item_text to add modification color
+local treeview_get_item_text = TreeView.get_item_text
+function TreeView:get_item_text(item, active, hovered)
+ local text, font, color = treeview_get_item_text(self, item, active, hovered)
+ if cached_color_for_item[item.abs_filename] then
+ color = cached_color_for_item[item.abs_filename]
+ end
+ return text, font, color
end
@@ -24,15 +46,6 @@ local git = {
deletes = 0,
}
-
-config.gitstatus = {
- recurse_submodules = true
-}
-style.gitstatus_addition = {common.color "#587c0c"}
-style.gitstatus_modification = {common.color "#0c7d9d"}
-style.gitstatus_deletion = {common.color "#94151b"}
-
-
local function exec(cmd)
local proc = process.start(cmd)
-- Don't use proc:wait() here - that will freeze the app.
@@ -57,7 +70,11 @@ core.add_thread(function()
-- get diff
local diff = exec({"git", "diff", "--numstat"})
- if config.gitstatus.recurse_submodules and system.get_file_info(".gitmodules") then
+ if
+ config.plugins.gitstatus.recurse_submodules
+ and
+ system.get_file_info(".gitmodules")
+ then
local diff2 = exec({"git", "submodule", "foreach", "git diff --numstat"})
diff = diff .. diff2
end