Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Antares Prompt Issues: Git Tag Info Missing and Long Paths Crash #701

Closed
socholo opened this issue Nov 2, 2024 · 5 comments
Closed

Antares Prompt Issues: Git Tag Info Missing and Long Paths Crash #701

socholo opened this issue Nov 2, 2024 · 5 comments
Labels
bug Something isn't working

Comments

@socholo
Copy link

socholo commented Nov 2, 2024

I really like the recent changes in Clink 1.7.0 to add prompt themes! 😀 I have been using 1.7.3 and the Antares prompt theme to get started and it works well, but I have observed 2 issues that I thought may be worth correcting (I'm happy to submit a PR, if fixing them is worthwhile):

Issue 1: Missing Git Tag Information

When a tag is checked out, the name of the tag is not appearing in the prompt. I find the tag name very useful as tells me where I am - a more significant place than just the Git hash that is dislayed.

From what I could tell, the issue is caused by the git_status coroutine and management of the associated ANTARES_GIT_HAS_TAGS and ANTARES_GIT_TAG variables:

local git_status=clink.promptcoroutine(function()
local status=git.getstatus()
if detached then
local git_tag=command(git.makecommand("tag --points-at=HEAD"), true)
if git_tag then
self.ANTARES_GIT_HAS_TAGS=true
local n_tags=#git_tag
if n_tags == 1 then
self.ANTARES_GIT_TAG=" "..icon(ANTARES.STR_GIT_TAG)..git_tag[1]
elseif n_tags > 1 then
self.ANTARES_GIT_TAG=" "..icon(ANTARES.STR_GIT_TAG)..tostring(n_tags)
end
end
end
return { status=status }
end)

The referenced variables are reset every time the prompt is refreshed - even after the referenced coroutine runs and updates those variables to contain the tag name - thus the tag information is never displayed.

I was able to correct the issue by only clearing the referenced variables when changing to:

  1. A non-Git directory
  2. A Git directory that is different from the last Git directory

Issue 2: Long Paths Cause Crash

When navigating to a directory with a very long path - one that is too long to fit the space available in the prompt - the Antares prompt will truncate the path from the left and replace with ellipses. Unfortunately, there appear to be some logic errors in the code - comparing numbers to booleans - that produces the following output:

prompt filter failed
C:\...\Antares.clinkprompt:349: attempt to compare number with boolean
stack traceback:
        C:\...\Antares.clinkprompt:465: in function 'func'
        ~clink~/app/prompt.lua:137: in function <~clink~/app/prompt.lua:124>
        [C}: in function 'xpcall'
        ~clink~/app/prompt.lua:191: in function <~clink~/app/prompt.lua:105>
        (...tail calls...)

From what I could tell, the pwd_over_half and git_over_half variables are booleans and so should not be checked if > 0, but just the value:

if pwd_over_half > 0 and git_over_half > 0 then

After that issue was corrected, I noticed that the ellipsify() function has a 2 bugs:

  1. It doesn't truncate the path (it's checking an unknown variable k):
    total = total + console.cellcount(k)
    )
  2. It includes the final path 2x's in the result (this statement should be in the scope of truncating from the right:
    table.insert(keep, s)
    )

If it would be worthwhile to address these issues, I'd be happy to submit a pull request with the changes that I have made to address them.

Thank you very much - I really appreciate all of the work that you have done on Clink, it's really great!

@chrisant996 chrisant996 added the bug Something isn't working label Nov 2, 2024
@chrisant996
Copy link
Owner

@socholo Thank you for reporting the issues, and thank you for including such thorough information!

I have a fix coming.

@chrisant996
Copy link
Owner

Re: missing tag indicator --

The coroutine shouldn't be setting self.blah variables directly.
It should add a corresponding field in the table it returns, so that the caller retains control over timing (and race conditions, etc).

@chrisant996
Copy link
Owner

@socholo P.S. your timing was perfect -- I was about to publish a new update, and I was able to include this before publishing it.

@Leezheng1
Copy link

prompt filter failed:
...\workspace\Tool\cmder\config\powerline_core.lua:135: attempt to index
a number value)
stack traceback:
...\workspace\Tool\cmder\config\powerline_core.lua:176: in funct
...\workspace\Tool\cmder\config\powerline_git.lua:132: in funct
clink/app/prompt.lua:301: in function 'func'
clink/app/prompt.lua:137: in function <clink/app/prompt.lua:124>
[C]: in function 'xpcall'
clink/app/prompt.lua:191: in function <clink/app/prompt.lua:105>
(...tail calls...)

ERROR IN LUA PROMPT FILTER

@chrisant996
Copy link
Owner

prompt filter failed: ...\workspace\Tool\cmder\config\powerline_core.lua:135: attempt to index a number value) stack traceback: ...\workspace\Tool\cmder\config\powerline_core.lua:176: in funct ...\workspace\Tool\cmder\config\powerline_git.lua:132: in funct clink/app/prompt.lua:301: in function 'func' clink/app/prompt.lua:137: in function <clink/app/prompt.lua:124> [C]: in function 'xpcall' clink/app/prompt.lua:191: in function <clink/app/prompt.lua:105> (...tail calls...)

ERROR IN LUA PROMPT FILTER

@Leezheng1 That's unrelated to issue 701. I've created a new issue 712 where we can discuss what you've reported.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants