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

powerlevel10k support #2851

Closed
romkatv opened this issue Mar 29, 2023 · 103 comments
Closed

powerlevel10k support #2851

romkatv opened this issue Mar 29, 2023 · 103 comments
Assignees
Labels
Feature requests Feature Requests

Comments

@romkatv
Copy link

romkatv commented Mar 29, 2023

I'm the author and maintainer of powerlevel10k (a zsh theme). I see in the docs that Warp does not support powerlevel10k. Is there anything I can help you with?

I haven't used Warp but from other terminals with similar capabilities I gather that you need to annotate prompt and the command line with special escape codes. Powerlevel10k has built-in support for popular annotations. The right kind of annotation is enabled automatically based on the terminal (iTerm2, Kitty, VSCode, etc.). I could do the same for Warp but I would need to know what needs annotating. Perhaps you have a specification of the protocol?

Warp Internal (ignore) - linear-label:770f6576-d6c0-4e4f-a259-fc64b5156087

@romkatv romkatv added the Feature requests Feature Requests label Mar 29, 2023
@trueblooda
Copy link

trueblooda commented Mar 29, 2023

+1 This would be amazing. I would love to help too. (in whatever way I can)

@dannyneira
Copy link
Member

dannyneira commented Mar 30, 2023

Hi @romkatv Thanks so much for submitting this and your offer to help make Powerlevel10K work with Warp!
We have notified the engineers that worked on this, they are gathering the details and will respond on this thread.

Please add a :+1: to the original post at the top to signal that you want this feature, and hit the subscribe button if you'd like to be notified.

@marcosdipaolo
Copy link

Thanks @romkatv for helping, i'd love to have powerlevel10k working with warp asap!! 💪

@marcosdipaolo
Copy link

Any news from this? 🤔

@romkatv
Copy link
Author

romkatv commented Apr 27, 2023

Closing as there doesn't seem to be any interest from the devs.

@romkatv romkatv closed this as not planned Won't fix, can't repro, duplicate, stale Apr 27, 2023
@vorporeal
Copy link

@romkatv Hey! We're definitely interested, and would love to work with you to get p10k working well within Warp. I'm so sorry that we haven't been more proactive about reaching out; we were trying to collect institutional knowledge about the issues we uncovered when investigating the p10k compatibility problem a long time ago, and then the person who was going to reach out went OOO.

Give me a couple days to build an up-to-date understanding of the specific issues that appear when trying to use Warp with p10k and I'll reply with them here.

In the meantime, can you link me to the part of the p10k codebase that adds the annotations you were mentioning? I can mentally map that onto what would make sense for Warp and be better able to make a suggestion about a path forward.

Again, really sorry that we dropped the ball here.

@vorporeal vorporeal reopened this Apr 27, 2023
@romkatv
Copy link
Author

romkatv commented Apr 28, 2023

No worries, I understand that things can be hectic in a fast-moving project.

If you search for "_POWERLEVEL9K_TERM_SHELL_INTEGRATION" within p10k.zsh, you'll find most of the shell integration code. This code is nearly impenetrable, which is why I offered to make changes to it myself.

Powerlevel10k has a few capabilities that might prove challenging to handle. Let me summarize them.

Prompt may change when you press ENTER

Here's an example where a multi-line prompt changes to a single-character prompt on ENTER.

Powerlevel10k Transient Prompt

Here prompt is contracted on ENTER but it can also expand. For example, some users like to have timestamps on past prompt commands without having the timestamp on the current prompt. In this case a timestamp is added to prompt when you press ENTER.

Prompt may change in response to what you are typing

Here's an example where prompt shows Google Cloud credentials and Kubernetes context when the command you are typing invokes gcloud or kubectl respectively.

Powerlevel10k Show on Command

Prompt may change on its own accord

Some prompt segments can update asynchronously. In practice this means that prompt may change on its own without any user action. This can lead both to contraction and expansion. In the extreme, even the height of prompt may change.

Prompt may change when the terminal window is resized

You most likely can already handle this because it's not unusual for zsh prompt to change on resize but I want to mention it for completeness. Here's an example (see the end of the recording):

Powerlevel10k Current Directory

Powerlevel10k may print a fake first prompt before zsh is initialized

This feature is meant to hide zsh initialization latency: instead of looking at an empty screen for some time after starting zsh, the user is instantly presented with a prompt and can start typing. When zsh is fully initialized, the fake prompt is replaced with the real thing.

Powerlevel10k Instant Prompt

In this example the real prompt looks the same as the fake prompt but it can also be different. For example, if the current directory is under a git repository, the fake prompt won't have git status but the real prompt will.

More info about this feature: https://github.com/romkatv/zsh-bench#instant-prompt

@vorporeal
Copy link

Hey @romkatv, one question for you while I work out a more complete technical design on our end:

I see that the escape sequence OSC 133 ; A ST is sent before the prompt contents, and OSC 133 ; B ST is sent after them. As far as I can tell, the right-side prompt is not included in this, and has no markers surrounding it. Would it be possible to introduce another pair of markers for the right-side prompt? I'm still doing some testing/prototyping on our end, but that might be the primary change needed on your end for things to work well.

@romkatv
Copy link
Author

romkatv commented May 4, 2023

I can embed any escape sequence in any place within powerlevel10k prompt you like.

@vorporeal
Copy link

Fantastic. In my prototype (where I modified _p9k_prompt_prefix_right and _p9k_prompt_suffix_right to add markers), I'm noticing some odd artifacts in the right-side prompt:

image

Any immediate thoughts as to what might be going on?

Here's the small adjustment I made:

  if (( _POWERLEVEL9K_TERM_SHELL_INTEGRATION )); then
    _p9k_prompt_prefix_left+=$'%{\e]133;A\a%}'
    _p9k_prompt_suffix_left+=$'%{\e]133;B\a%}'
+   _p9k_prompt_prefix_right+=$'%{\e]133;C\a%}'
+   _p9k_prompt_suffix_right+=$'%{\e]133;D\a%}'

@romkatv
Copy link
Author

romkatv commented May 4, 2023

If you tell me how you want prompt to be marked, I'll make the changes.

@vorporeal
Copy link

Sure; I can keep working on the necessary changes for broad functionality on our end and assume that the changes you make will address any small oddities I encounter.

I'll leave a more detailed comment either tomorrow or Monday with the set of changes that we'll need on the p10k end to address compatibility issues!

@kurtextrem
Copy link

It's really awesome to see how this thread made a 180° turn and see your collaboration and communication. Thank you for working on this to you both

@pXius
Copy link

pXius commented May 7, 2023

Fantastic. In my prototype (where I modified _p9k_prompt_prefix_right and _p9k_prompt_suffix_right to add markers), I'm noticing some odd artifacts in the right-side prompt:

image

Any immediate thoughts as to what might be going on?

Here's the small adjustment I made:

  if (( _POWERLEVEL9K_TERM_SHELL_INTEGRATION )); then
    _p9k_prompt_prefix_left+=$'%{\e]133;A\a%}'
    _p9k_prompt_suffix_left+=$'%{\e]133;B\a%}'
+   _p9k_prompt_prefix_right+=$'%{\e]133;C\a%}'
+   _p9k_prompt_suffix_right+=$'%{\e]133;D\a%}'

I believe this might be unrelated to P10k but rather Warp's line height implementation which does not seem centered. Not for the NerdFont Icons at least.

Using Starship, and the same Nerd Font icons I can achieve a P10k'esk look but it suffers from the exact same artifacts.
Depending on the line height, font size and font face (Fira Code NF in this example), I can exaggerate the artifacts, or more specifically, NF icon alignment. The round shapes in your screenshot are NF Icons btw.

The most interesting part which I'd like to highlight, is that the alignment is different from box to box. Regardless of box content.

Hope this helps.

Screenshot 2023-05-07 at 23 15 41

@romkatv
Copy link
Author

romkatv commented May 8, 2023

@pXius I believe "odd artifacts in the right-side prompt" was referring to "%b".

P.S.

The only way other terminals manage to render powerline glyphs (and sometimes UNICODE block characters) perfectly is by special-casing them in the rendered. You can notice that a terminal does this if it can display things like U+E0B0 even if there is no glyph for it in the font.

@vorporeal
Copy link

@pXius Yeah, the glyph alignment issues are largely a problem with the font, though there are also appear to be some small floating-point rounding(?) issues on our end, as you observed with the inconsistent vertical alignment from block to block. We'll eventually use the same trick as other terminals to get perfect rendering of these characters, but it's not super high on our priority list at the moment.

I figured out the %b bit; finishing up some prototyping/analysis and will return later today with details of what (I expect small) changes will be needed for proper Warp support!

@vorporeal
Copy link

Hey @romkatv - trying to debug one last possible integration issue: it seems like the updated prompts produced in response to changes in the input buffer (the functionality described here) don't currently include the start and end prompt markers that are sent for iTerm's shell integration; is that accurate? Want to make sure that the behavior I'm seeing is due to a lack of markers, and not some more significant logic error/compatibility issue on our end (we have a feature that I'm trying to make sure plays nicely with this p10k functionality).

@romkatv
Copy link
Author

romkatv commented May 9, 2023

powerlevel10k should write the markers every time it prints (or re-prints) prompt. There might be a bug that prevents this from happening but it's very unlikely.

@vorporeal
Copy link

vorporeal commented May 11, 2023

Hey @romkatv - here's what we've come up with:

We'd like to prefix the right-side prompt with the sequence \e]133;P;k=r\a, and use the same suffix as the left-side prompt (\e]133;B\a). This follows the semantic prompts terminal-wg proposal here.

In terms of detecting when Warp is the active terminal, we set TERM_PROGRAM=WarpTerminal in the shell environment, so you can reference that variable. Let me know if there's a different way you'd prefer to perform terminal detection.

For now, at least, we'll override POWERLEVEL9K_INSTANT_PROMPT=off on our end to ensure there aren't any instant prompt-related issues. Once we've better tested this, we will remove the override in a future version where we're more confident there won't be any issues.

Finally, we'd like to be able to detect when a user has loaded an older version of p10k (one that doesn't contain the changes above) so we can prompt the user to update p10k for a better user experience. (We'll direct users to the update instructions on the p10k GitHub page.) Is there any way for us to perform a version check via shell variables, or should we just check the PS1/PROMPT/RPS1/RPROMPT variables for the marker sequences we're expecting?

If you'd like, you can send me a link to a branch with the relevant changes and I can test it out with my Warp-side changes to make sure everything works as expected before you merge it into your master branch.

@vorporeal vorporeal self-assigned this May 11, 2023
@romkatv
Copy link
Author

romkatv commented May 11, 2023

Ack. This all sounds great to me. I'll go over your comment with greater attention and make necessary changes in p10k early next week. Will ping here.

@tylerweitzman
Copy link

I'm a user of Powerlevel10k coming from iTerm2 and wanting to be able to use it migrating to Warp. Thanks for working on it, I'm excited to use it.

@romkatv
Copy link
Author

romkatv commented May 16, 2023

I've opened romkatv/powerlevel10k#2307 to track the development on Powerlevel10k side and made two changes within https://github.com/romkatv/powerlevel10k/tree/warp:

  • Annotate right prompt when TERM_PROGRAM is WarpTerminal.
  • Force terminal integration when TERM_PROGRAM is WarpTerminal.

Please check whether the changes work for you. I don't have Warp installed, so I'm relying on your testing here.

You can use the following logic to detect Warp support within Powerlevel10k:

if (( ${+functions[p10k]} )); then
  if [[ ${_p9k__param_pat-} == v<1-149>$'\1'* ]]; then
    print 'Powerlevel10k predates Warp integration'
  else
    print 'Powerlevel10k has Warp integration'
  fi
else
  print 'Powerlevel10k not found'
fi

Note that _p9k__param_pat is an internal parameter, which may disappear in the future. This is why the absence of _p9k__param_pat signifies a new version of Powerlevel10k and thus with Warp support.

@vorporeal
Copy link

Generally looks good! I've got rendering working nicely (with some flicker prevention for transient prompts). I still need to add the logic to perform version checks, so not quite ready yet to LGTM your warp branch, but will verify that last piece tomorrow.

@Scott-J-McMullan
Copy link

@dehan-jl Nice one, thanks mate

@pmbanugo
Copy link

For me the problem is I don't see the features enabled until I run exec zsh

@Scott-J-McMullan
Copy link

@pmbanugo have you turned on Honor user's custom prompt (PS1) & set zsh as your startup shell?
Screenshot 2023-07-18 at 08 06 37

@pmbanugo
Copy link

This worked perfect, thanks! I didn't need to change the startup shell because my default is zsh.

@chandrakanthkannam
Copy link

Hi Everyone, I'm running this version of Warp terminal v0.2023.08.15.08.03.stable_00 and my p10k settings only shows up when i run exec zsh once entered in to my terminal
image

and i dont see Honor user's custom prompt setting in my version,
image

can someone help me here?

@Scott-J-McMullan
Copy link

@chandrakanthkannam I think they have moved the setting. Go to Settings > Appearance > Prompt & make sure that Shell prompt (PS1) is selected.
Screenshot 2023-08-18 at 13 32 50

@chandrakanthkannam
Copy link

Thanks @Scott-J-McMullan , I was able to get that running now.

@AhnafS
Copy link

AhnafS commented Aug 18, 2023

Besides dong exec zsh is there no other way to solve the new line issue? exec zsh eliminates some of the features of Warp that I want to try out

@kzana
Copy link

kzana commented Aug 21, 2023

Hi Everyone,
I have issue with Warp + ZSH + p10k rainbow style: like you can see in the screenshot below all my segments separators have a dark background color.

Screenshot 2023-08-21 at 12 36 42

I didnt found any variable config to configure it in p10k.zsh file.
Note that it's the same for all segment styles (tangled, angled, rounded) and that Im using Meslo font.

Someone maybe familiar with such issue ?

Thanks.

@romkatv
Copy link
Author

romkatv commented Aug 21, 2023

@kzana Probably #2851 (comment)

@kzana
Copy link

kzana commented Aug 21, 2023

@kzana Probably #2851 (comment)

Thanks I missed it !

@vtu-dog
Copy link

vtu-dog commented Aug 27, 2023

Hello,
I noticed that executing a command with a right-side prompt causes it to flicker: it jumps to the very edge of the window, then quickly readjusts its position. Just run any command that will throw a non-zero exit code, then click enter repeatedly. Anybody else facing the same issue?

EDIT
Actually, holding enter causes problems as well, p10k control sequences such as ^[i^P enter the terminal input and are being interpreted as actual commands.

@elviskahoro
Copy link
Member

Gonna close this out since it's mostly working. We can open up new issues for follow up improvements.

@Cliffback
Copy link

Hi. I just tried to install Warp, coming from iTerm. When using Powerlevel10k, the arrows are colored different than than the block it is coming from, which is really irritating. Is there some way of fixing this? Screenshot 2023-10-30 at 14 57 50

@romkatv
Copy link
Author

romkatv commented Oct 30, 2023

@Cliffback #2851 (comment)

@Cliffback
Copy link

@Cliffback #2851 (comment)

Thank you! :D

@tfactor2
Copy link

Query for @romkatv or other p10k/warp gurus here. How inadvisable is it to run two different p10k setups? That is, until #2304 is "fixed," could I:

if [[ $TERM_PROGRAM != "WarpTerminal" ]]; then
   [[ -f ~/.p10k.zsh ]] && source ~/.p10k.zsh
   unset ZLE_RPROMPT_INDENT

   source ~/.iterm2_shell_integration.zsh
else
   [[ -f ~/.p10k.zsh.oneline ]] && source ~/.p10k.zsh.oneline
fi

where if on Warp, I run a one-line prompt (which is really two lines, but, well, one less line), but in iTerm2 I run my normal two liner?

(And I now realize I should probably add a:

if [[ $TERM_PROGRAM == "iTerm.app" ]]

for that iterm2 integration...)

I solved the problem by adding

if [[ $TERM_PROGRAM != "WarpTerminal" ]]; then
  POWERLEVEL9K_LEFT_PROMPT_ELEMENTS+=(newline)
  POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS+=(newline)
fi

to the bottom of ~/.p10k.zsh

@qorbani
Copy link

qorbani commented Feb 20, 2024

For my case, I needed to remove Prompt and a new line, so I did this in my .zshrc to make it compatible between iTerm and Warp using one p10k.zsh file.

[[ ! -f ~/.p10k.zsh ]] || {
  source ~/.p10k.zsh
  if [[ $TERM_PROGRAM == "WarpTerminal" ]]; then
    POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(${POWERLEVEL9K_LEFT_PROMPT_ELEMENTS[1,-3]})
    POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(${POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS[1,-2]})
  fi
}

Warp:
warp
iTerm:
iterm

@aboqasem
Copy link

After disabling the prompt_char from the prompt, is there a way to disable it from being printed on each command?

Screenshot 2024-03-24 at 9 06 19 AM

@romkatv
Copy link
Author

romkatv commented Mar 24, 2024

It looks like you've enabled Transient Prompt. You can turn it off via the configuration wizard or by editing ~/.p10k.zsh: https://github.com/romkatv/powerlevel10k/blob/da9b03777c4f2390c7e3f5c720ee4689336f811b/config/p10k-lean.zsh#L1683

@aboqasem
Copy link

It looks like you've enabled Transient Prompt. You can turn it off via the configuration wizard or by editing ~/.p10k.zsh: romkatv/powerlevel10k@da9b037/config/p10k-lean.zsh#L1683

Thanks! Thought there would be something to disable it completely, but this looks good as well.

Screenshot 2024-03-24 at 9 29 53 PM

@romkatv
Copy link
Author

romkatv commented Mar 24, 2024

@aboqasem If you can describe what you want to achieve, I may be able to help you get there. The best venue for this discussion would be https://github.com/romkatv/powerlevel10k/issues.

@mhagnumdw
Copy link

Any solution to make this work? It even works, but only after the command has been executed.

For example, seeing the current openshift/kubernetes context is useful before running oc/kubectl CLI.

Prompt may change in response to what you are typing

Here's an example where prompt shows Google Cloud credentials and Kubernetes context when the command you are typing invokes gcloud or kubectl respectively.

Powerlevel10k Show on Command

@cmcneese
Copy link

cmcneese commented May 6, 2024

Besides dong exec zsh is there no other way to solve the new line issue? exec zsh eliminates some of the features of Warp that I want to try out

Did you try and see this above your comment? It just resolved your same issue for me: #2851 (comment)

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

No branches or pull requests