Skip to content

Commit

Permalink
Merge pull request #2703 from Mikaz-fr/master
Browse files Browse the repository at this point in the history
Add optional clink async prompt update for svn status
  • Loading branch information
daxgames authored Jul 13, 2022
2 parents 7beb490 + 70b5822 commit 913f93d
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 8 deletions.
35 changes: 30 additions & 5 deletions vendor/clink.lua
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ end
-- @return {false|svn branch name}
---
local function get_svn_branch(svn_dir)
local file = io.popen("svn info 2>nul")
local file = io_popenyield("svn info 2>nul")
for line in file:lines() do
local m = line:match("^Relative URL:")
if m then
Expand Down Expand Up @@ -396,7 +396,7 @@ end
-- @return {bool}
---
local function get_svn_status()
local file = io.popen("svn status -q")
local file = io_popenyield("svn status -q")
for line in file:lines() do
file:close()
return false
Expand Down Expand Up @@ -573,12 +573,37 @@ local function svn_prompt_filter()
nostatus = get_unknown_color()
}

if get_svn_dir() then
local svn_dir = get_svn_dir()
if svn_dir then
-- if we're inside of svn repo then try to detect current branch
local branch = get_svn_branch()
local color
if branch then
if get_svn_status() then
-- If in a different repo or branch than last time, discard cached info
if cached_info.svn_dir ~= svn_dir or cached_info.svn_branch ~= branch then
cached_info.svn_info = nil
cached_info.svn_dir = svn_dir
cached_info.svn_branch = branch
end
-- Get the svn status using coroutine if available and option is enabled. Otherwise use a blocking call
local svnStatus
if clink.promptcoroutine and io.popenyield and settings.get("prompt.async") and prompt_overrideSvnStatusOptIn then
svnStatus = clink_promptcoroutine(function ()
return get_svn_status()
end)
-- If the status result is pending, use the cached version instead, otherwise store it to the cache
if svnStatus == nil then
svnStatus = cached_info.svn_info
else
cached_info.svn_info = svnStatus
end
else
svnStatus = get_svn_status()
end

if svnStatus == nil then
color = colors.nostatus
elseif svnStatus then
color = colors.clean
else
color = colors.dirty
Expand All @@ -589,7 +614,7 @@ local function svn_prompt_filter()
end
end

-- No mercurial present or not in mercurial file
-- No svn present or not in svn file
clink.prompt.value = string.gsub(clink.prompt.value, "{svn}", "")
return false
end
Expand Down
11 changes: 8 additions & 3 deletions vendor/cmder_prompt_config.lua.default
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,19 @@ prompt_useUserAtHost = false
-- default is false
prompt_singleLine = false

-- OPTIONAL. If true then Cmder includes git, mercurial, and subversion status in the prompt.
-- default is true
prompt_includeVersionControl = true

-- OPTIONAL. If true then always ignore the cmder.status and cmder.cmdstatus git config settings and run the git prompt commands in the background.
-- default is false
-- NOTE: This only takes effect if using Clink v1.2.10 or higher.
prompt_overrideGitStatusOptIn = false

-- OPTIONAL. If true then Cmder includes git, mercurial, and subversion status in the prompt.
-- default is true
prompt_includeVersionControl = true
-- OPTIONAL. If true then always ignore the cmder.status and cmder.cmdstatus svn config settings and run the svn prompt commands in the background.
-- default is false
-- NOTE: This only takes effect if using Clink v1.2.10 or higher.
prompt_overrideSvnStatusOptIn = false

-- Prompt Attributes
--
Expand Down

0 comments on commit 913f93d

Please sign in to comment.