diff options
author | Joshua Minor <github@pixelverse.org> | 2021-11-20 23:09:40 -0800 |
---|---|---|
committer | Joshua Minor <github@pixelverse.org> | 2021-11-21 00:28:01 -0800 |
commit | a5f06db1bbaa1b315ae88d157a2135b0d6631ad6 (patch) | |
tree | 0db63e291742cad0c45c49078237ba2489ec1fa8 /plugins/gitstatus.lua | |
parent | 73faa10b4acc18228accfcf20e22d36228eb0cb3 (diff) | |
download | lite-xl-plugins-a5f06db1bbaa1b315ae88d157a2135b0d6631ad6.tar.gz lite-xl-plugins-a5f06db1bbaa1b315ae88d157a2135b0d6631ad6.zip |
Huge performance improvement using yield instread of proc:wait()
Diffstat (limited to 'plugins/gitstatus.lua')
-rw-r--r-- | plugins/gitstatus.lua | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/plugins/gitstatus.lua b/plugins/gitstatus.lua index 54bd6e8..4de2267 100644 --- a/plugins/gitstatus.lua +++ b/plugins/gitstatus.lua @@ -31,11 +31,16 @@ style.gitstatus_modification = {common.color "#0c7d9d"} style.gitstatus_deletion = {common.color "#94151b"} -local function exec(cmd, wait) +local function exec(cmd) local proc = process.start(cmd) - proc:wait(wait * 1000) - local res = proc:read_stdout() - return res + -- Don't use proc:wait() here - that will freeze the app. + -- Instead, rely on the fact that this is only called within + -- a coroutine, and yield for a fraction of a second, allowing + -- other stuff to happen while we wait for the process to complete. + while proc:running() do + coroutine.yield(0.1) + end + return proc:read_stdout() end @@ -43,19 +48,20 @@ core.add_thread(function() while true do if system.get_file_info(".git") then -- get branch name - git.branch = exec({"git", "rev-parse", "--abbrev-ref", "HEAD"}, 1):match("[^\n]*") - - if TreeView then - TreeView:clear_all_color_overrides() - end + git.branch = exec({"git", "rev-parse", "--abbrev-ref", "HEAD"}):match("[^\n]*") local inserts = 0 local deletes = 0 -- get diff - local diff = exec({"git", "diff", "--numstat"}, 1) + local diff = exec({"git", "diff", "--numstat"}) if config.gitstatus.recurse_submodules and system.get_file_info(".gitmodules") then - diff = diff .. exec({"git", "submodule", "foreach", "git diff --numstat --stat"}, 1) + local diff2 = exec({"git", "submodule", "foreach", "git diff --numstat --stat"}) + diff = diff .. diff2 + end + + if TreeView then + TreeView:clear_all_color_overrides() end local root = "" |