-
Notifications
You must be signed in to change notification settings - Fork 947
Conversation
1119cab
to
7b0fc51
Compare
Alright, me and @andjscott worked together on this to make it work in most settings (though the credit should go to @andjscott). It uses a temporary file to store the rprompt while it is being built, and then outputs that when it is ready. When the shell exits, this is cleaned up. Makes for a much smoother experience, especially when using slow segments (like #244 and It is configureable by |
} | ||
|
||
if [[ "$POWERLEVEL9K_DISABLE_RPROMPT" != true ]]; then | ||
POWERLEVEL9K_SOCKET=$(mktemp) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May I suggest a small improvement to the mktemp
call?
It would be (a) nice to use a prefix for the temporary file to indicate where it comes from, e.g. mktemp -t powerlevel_rprompt_$$
, and (b) check if mktemp
succeeded and if it failed, make it fail silently, instead of blowing up the prompt e.g. POWERLEVEL9K_SOCKET="$(mktemp -q -t powerlevel9k_rprompt_$$)"
Overall, this block would like this:
if [[ "$POWERLEVEL9K_DISABLE_RPROMPT" != true ]]; then
POWERLEVEL_SOCKET="$(mktemp -q -t powerlevel_rprompt_$$)"
if [ $? -eq 0 ]; then
powerlevel9k_async() {
: >! $POWERLEVEL_SOCKET
build_right_prompt
}
else
POWERLEVEL9K_RPROMPT_RENDER_ASAP=false
fi
fi
I am sorry I couldn't test my suggestion. I hope you will give it some thought.
050e9fe
to
667c45b
Compare
Using a prefix for the file is a good idea. I had to add a template parameter to the call so it looks like |
Great! |
Another solution would be to use zsh-async, if the user has the package installed, to generate the prompt asynchronously. These changes can be seen at next...andjscott:next2. |
else | ||
"prompt_$element" "right" "$index" | ||
"prompt_$element" "right" "$index" >> $POWERLEVEL9K_SOCKET |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In line 992
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I spotted it right after I made that comment and deleted the comment. You are very quick at responding to Github notifications, hah! :)
Hey @andjscott, @Tritlo - Very cool work. We had discussed trying to find a way to make things asynchronous in a number of other bugs / PRs, and never really settled on a good way. This seems like a pretty good solution. I left a small comment about where the code goes in the diff. It doesn't look like this changeset gives the user the ability to not use the async behavior if they prefer to just use the current synchronous behavior. Is that accurate? |
yes, the current implementation is async only. Making it configurable should be very easy. I'll have a look at it this weekend. |
As Tritlo said, there currently isn't a choice. The choice they get, (the _ASAP variable) is to make the prompt load each element indepenently rather than as a group. Tbh I now think that the zsh-async approach is better as it only adds async support if the user has the async library installed (progressive enhancement) and keeps the workload in zsh rather than creating temporary files. A negative is that the "ASAP" method isn't implemented. |
Another item is that while this fixes the issue for the RPROMPT, it doesn't address it for the main PROMPT, which is where most folks have their Do you think the approach you took, here, could also apply to the main prompt? |
Yes, PROMPT should be updatable in the same way |
@andjscott - Can you build on this PR to add this capability to the main PROMPT, and add a setting that allows users to turn off async completely? I think with those two additional options, this will be a really amazing fix for a lot of people. |
To the current PR (using the temporary file) or the zsh-async version? |
Just a note: the zsh-asymc method did not work for me, so I think it should be further investigated. Maybe use the temp file for this version, and then submit another pr with zsh-async? |
@andjscott - Your current method using temp files. We can look into zsh-async after we have some experience, here, but I'm very wary of creating additional dependencies for functionality, generally =) |
I've hacked on async PROMPT and made it optional. Being optional, there are a lot of if branches like
which isn't pretty. The other problem is that there is only one |
Instead of conditionalizing it, I wonder |
/me sighs I did not mean to post that or close this bug. |
Agreed re: ugliness of the conditionals. I wonder if there is a way to combine them / break them out. Will spin on it... thoughts, others? |
Hey @andjscott - I would really like to get this merged. You and @Tritlo did some really awesome work, and this will be really useful to a lot of people. After working with the two different versions you created, Can you push your changeset that uses zsh/async to a branch somewhere and submit a PR for it? It looks like it may still be here, but I would prefer to just use a PR. |
@andjscott @Tritlo - Okay, so check it out: I created a new branch and merged the work you had in your Looking at the docs for My progress so far is in the https://github.com/bhilburn/powerlevel9k/tree/zsh-async-integration |
zsh-async was installed to my fpath meaning that |
@andjscott - Ah, I see. I don't want to require users to install |
Hi guys, first off, glad you're finding use for Also, as @bhilburn contacted me about this I had a look over the code and have some suggestions with regard to how async is handled. First off, I noticed that using this branch causes my shell to go into a endless loop of redoing all the prompt building operations over and over again (visible with debugging output Som benefits here:
Negatives:
I also have some general comments/concerns about the code, unrelated to this PR, but I'll voice them here anyway. Up to you if you wish to discard them or consider them :)
Anyway, that's it for my quick observations. I can see there's a lot of 💖 behind this theme, keep up the good work! |
Actually, I should've checked the code above before writing down my thoughts on To be honest, I think you could replace a lot of the code from there with: 0=${(%):-%N}
dir=${0:A:h} This makes |
Hey @mafredri - Wow! Thanks so much for the fantastic input on using This is really great information. I haven't gotten a chance to sit down, yet, and incorporate your comments, but I would like to get it done ASAP - perhaps this weekend. Thanks again for spending the time on this |
This pull is the same as #262.
This could be a solution to the lag experienced in #244.
An subprocess writes the prompt to a temporary file (unique to each zsh instance) as each element is loaded. A signal is send to the parent zsh process after a write so that the RPROMPT can be set to the new value. The temporary file is deleted when the zsh exits.