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

Prompt overwrites last displayed line when catting file without trailing newline #46

Closed
woutgg opened this issue Aug 23, 2024 · 11 comments

Comments

@woutgg
Copy link

woutgg commented Aug 23, 2024

When using cat to display a file without trailing newline, the last line can (sometimes) be seen very briefly and is then overwritten by the (left-)prompt.

Perhaps a non-empty line could be detected in which case the prompt either does not clear the line, or emits a newline first.

@agkozak
Copy link
Owner

agkozak commented Aug 24, 2024

Have you tried setting

AGKOZAK_BLANK_LINES=1

in your .zshrc? That's a simple solution.

@woutgg
Copy link
Author

woutgg commented Aug 26, 2024

Ah, I missed that one. It's not exactly what I had in mind but it might work just fine; I'll try it for a while. Thank you!

@edemaine
Copy link
Contributor

edemaine commented Aug 26, 2024

I'd personally prefer not to add a blank line every time, only when necessary (with some kind of "(no EOL)" marker). But I'm not sure it's possible to detect beginning-of-line — is it?

Maybe it is: https://stackoverflow.com/questions/8343250/how-can-i-get-position-of-cursor-in-terminal

@woutgg
Copy link
Author

woutgg commented Aug 26, 2024

That would be my preference as well.
I thought at first that it would be possible to detect/request cursor position, but on second thought I'm not sure if it's feasible to do so in the context of a shell prompt (as far as I know you'd have to read 'keyboard input' emitted by an ANSI command). I'm far from an expert at this though.

@agkozak
Copy link
Owner

agkozak commented Sep 5, 2024

@woutgg @edemaine Could you try adding

setopt PROMPT_CR

to the end of your .zshrc and see if that produces the desired effect?

@woutgg
Copy link
Author

woutgg commented Sep 5, 2024

That works very nicely, especially since it highlights the fact that the output is unterminated.
I wasn't aware of this option. Interestingly it appears to be on by default, so it is probably switched off somewhere in a plugin.
Thank you!

@agkozak
Copy link
Owner

agkozak commented Sep 5, 2024

Interestingly it appears to be on by default, so it is probably switched off somewhere in a plugin.

@woutgg You're absolutely right, and it's my fault that it's getting turned off. I'll get this fixed in the next couple of days, all right? Thanks for your patience, and thanks for giving that temporary fix a try.

@agkozak
Copy link
Owner

agkozak commented Sep 5, 2024

Release v3.11.4 contains a fix for the reported behavior. Just go ahead and update the master branch, and thanks, everyone, for helping to make the prompt better.

@agkozak agkozak closed this as completed Sep 5, 2024
@edemaine
Copy link
Contributor

edemaine commented Sep 5, 2024

Awesome, thanks both for finding the option and fixing it!

For anyone running into this, I also found it nice to be able to customize the string (default is % in standout font, or equivalently %S%%%s):

export PROMPT_EOL_MARK="%S[NO EOL]%s"

Sadly it doesn't seem to be possible to put this on the line after the unterminated line (as far as I can tell). Oh well, good enough!

@woutgg
Copy link
Author

woutgg commented Sep 5, 2024

Great, thank you @agkozak for your efforts on this and the awesome prompt in general!

@AndydeCleyre
Copy link
Contributor

Just popping in with another fun EOL mark:

PROMPT_EOL_MARK='%F{red} %f'

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

4 participants