This isn't a big issue, but it would be nice if it is fixable.
As mentioned in the title, if you have POWERLEVEL9K_PROMPT_ADD_NEWLINE set to true and run clear/reset or press Ctrl+L, the new prompt will have a leading newline.
This makes sense since with that option we are asking for a newline after all commands, but I think that these commands might be exceptions to the rule, what are your thoughts?
Thank you for your work! :)
ZSH version: 5.8
Terminal: Tilix 1.9.1 with VTE 0.58
Have you perchance enabled Transient Prompt? If so, it's expected to have an empty line at the top of the terminal after running clear. Powerlevel10k has to remove this empty line when you press ENTER, so it must be a part of prompt. Everything that's a part of prompt is visible after clear.
If you don't enable Transient Prompt, you won't see the empty line at the top after clear.
Yes, transient prompt is enabled. So there is no way to have both transient prompt and POWERLEVEL9K_PROMPT_ADD_NEWLINE whilst removing the newline after clear?
_I.e._ it's not possible to have something like: "if the previous command is clear or reset, don't print the leading newline"? Something along those lines (although I'm sure in practice it would be more difficult to detect).
So there is no way to have both transient prompt and
POWERLEVEL9K_PROMPT_ADD_NEWLINEwhilst removing the newline afterclear?
That's correct. New line can be either printed directly to the TTY or embedded in PS1. The first approach has the disadvantage that this empty line cannot be removed (transient prompt needs to remove empty lines when you hit enter, so this is a no-go). The second approach has the disadvantage of having an empty line at the top after clear.
_I.e._ it's not possible to have something like: "if the previous command is
clearorreset, don't print the leading newline"? Something along those lines (although I'm sure in practice it would be more difficult to detect).
That is possible but not very useful. Very few users actually type clear. Almost everyone uses Ctrl-L. Ctrl-L is handled by the terminal and cannot be intercepted by powerlevel10k.
Sounds sensible, thank you for your input. As I said, not a big issue to begin with. :)
Sorry to bother once again, but are you absolutely sure that it is impossible to "intercept" Ctrl+L? I did a quick browse and it seems like it's possible to, for example, rebind Ctrl+L to perform a different action; at least this thread mentions it: https://www.reddit.com/r/zsh/comments/2znptt/looking_for_way_to_change_clear_behavoir. Doesn't this seem to indicate that the shortcut is being handled by ZSH and not by the terminal?
I'll trust your judgement and decision regardless; even if it's possible it might not be worth the hassle.
You are right, Ctrl-L is indeed handled by Zsh and not by the Terminals as I incorrectly thought. I'll see if I can add a bit of hackeroo to make clear and Ctrl-L work better in powerlevel10k.
This is done. Please update powerlevel10k and check whether it's working as you expect.
Works fine with Ctrl+L; manually running clear or reset still has the issue, is that intended?
Please update and try again. clear and reset should work now.
Perfect! Thank you for your work!
Thanks for verifying and for pointing out that this feature is in fact possible to implement.
Just an observation, not that I use this anyway and not that I think a fix is required: typing clear -x doesn't work. I think this is what Ctrl+L runs behind the scenes but I might be wrong; the keybind Ctrl+L itself works fine, though, which is more important. :)
Just an observation, not that I use this anyway and not that I think a fix is required: typing
clear -xdoesn't work.
Fixed. Keep in mind that detecting all commands that clear screen is impossible. All I can do is to approximate.
I think this is what
Ctrl+Lruns behind the scenes
Zsh doesn't run any external commands.
Fixed. Keep in mind that detecting all commands that clear screen is impossible. All I can do is to approximate.
I'm aware, which I why I said that I didn't think a fix was required. Now you made a harmless command such as clear -V not respect the POWERLEVEL9K_PROMPT_ADD_NEWLINE. ;)
Pick your poison, I guess. Imho, if you want to fix the clear -x behaviour I think it'd be better to simply detect for clear -x instead of clear [anything]. I don't think there's any point in attempting to detect reset options either.
Fixed. Keep in mind that detecting all commands that clear screen is impossible. All I can do is to approximate.
I'm aware, which I why I said that I didn't think a fix was required. Now you made a harmless command such as
clear -Vnot respect thePOWERLEVEL9K_PROMPT_ADD_NEWLINE. ;)
Oops. Didn't realize clear had a flag that turns off clearing. Fixed.
I think it'd be better to simply detect for
clear -xinstead ofclear [anything]
The current code doesn't trigger on clear [anything] as that would create false positives. My goal was to have no false positives (false negatives are inevitable).
I don't think there's any point in attempting to detect reset options either.
Why?
The current code doesn't trigger on
clear [anything]as that would create false positives. My goal was to have no false positives (false negatives are inevitable).
Ah, I see, I'd only skimmed through the code and had interpreted it wrong; that's exactly what I was thinking, I agree with your position.
Why?
My concert was exactly the creation of false positives. I'm happy as long as they don't exist; I understand that the false negatives are inevitable.
Anyway, thank you for your wonderful work with this tool!
Most helpful comment
Perfect! Thank you for your work!