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

Is it possible to fix the 'empty line on terminal open' issue in this xontrib? #7

Open
StanSvec opened this issue Oct 16, 2022 · 4 comments

Comments

@StanSvec
Copy link

Starship prompt by default prints empty line when the terminal starts. This issue is reported here and here. Despite both issues are closed the problem hasn't been fixed yet. I'm wondering if that's something which can be additionally fixed in this xontrib?
Thanks!

@StanSvec StanSvec changed the title Is it possible to fix the empty line on terminal open issue in this xontrib? Is it possible to fix the 'empty line on terminal open' issue in this xontrib? Oct 16, 2022
@anki-code
Copy link
Owner

Try to cut empty line here:

return __xonsh__.subproc_captured_stdout([
'starship', 'prompt',
'--status', str(int( __xonsh__.history[-1].rtn)) if len(__xonsh__.history) > 0 else '0',
'--cmd-duration' , str(int((__xonsh__.history[-1].ts[1] - __xonsh__.history[-1].ts[0])*1000)) if len(__xonsh__.history) > 0 else '0',
'--jobs', str(len(__xonsh__.all_jobs))
])

i.e. "Using starship cross-shell prompt to rendering right sections" in xontrib-prompt-bar

@StanSvec
Copy link
Author

Oh so simple, thanks!
I came up with a naive solution:

_FIRST_PROMPT = True

def _starship_prompt(cfg=None):
    global _FIRST_PROMPT
    with __xonsh__.env.swap({'STARSHIP_CONFIG': cfg} if cfg else {}):
        prompt = __xonsh__.subproc_captured_stdout([
            'starship', 'prompt',
            '--status', str(int( __xonsh__.history[-1].rtn)) if len(__xonsh__.history) > 0 else '0',
            '--cmd-duration' , str(int((__xonsh__.history[-1].ts[1] - __xonsh__.history[-1].ts[0])*1000)) if len(__xonsh__.history) > 0 else '0',
            '--jobs', str(len(__xonsh__.all_jobs))
        ])
    if _FIRST_PROMPT:
        _FIRST_PROMPT = False
        return prompt.lstrip()
    return prompt

Works fine unless the screen is cleared (Ctrl + L). Is there a way how to detect execution of the clear command, so I could add one more condition for the left strip?
Thanks!

@anki-code
Copy link
Owner

anki-code commented Oct 17, 2022

I think you're using prompt toolkit for $SHELL and the first way is to search there.

@StanSvec
Copy link
Author

Hmm, I didn't even know that prompt toolkit provides shell functionality, because I don't have any experience with this library. Is it possible to access ptk's API somehow from the prompt_starship.py file please?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants