Powerlevel9k / powerlevel9k

Powerlevel9k was a tool for building a beautiful and highly functional CLI, customized for you. P9k had a substantial impact on CLI UX, and its legacy is now continued by P10k.
https://github.com/romkatv/powerlevel10k
MIT License
13.46k stars 949 forks source link

[Next] Issue with leftPromptWidth #1372

Open onaforeignshore opened 4 years ago

onaforeignshore commented 4 years ago

Describe Your Issue

What is happening? leftPromptWidth is calculating the incorrect length. There is extra padding on the right prompt for a few seconds and then it disappears and the cursor is in the wrong place. This also happens during tab completion

Screen Shot 2019-10-11 at 10 12 13 Screen Shot 2019-10-11 at 10 12 39

Notice the command doubling...

Have you tried to debug or fix it?

Not yet.

Environment Information

This information will help us understand your configuration.

romkatv commented 4 years ago

leftPromptWidth is calculating the incorrect length.

I think leftPromptWidth doesn't affect single-line prompt. It also shouldn't break cursor positioning even if it returns incorrect value. The position of right prompt and subsequent cursor movement is done by zsh based on the values of PROMPT and RPROMPT (and a few other things like ZLE_RPROMPT_INDENT, locale and multibyte).

You can use the following command to diagnose this problem.

() {
  emulate -L zsh
  setopt err_return no_unset
  local text
  print -rl -- 'Select a part of your prompt from the terminal window and paste it below.' ''
  read -r '?Prompt: ' text
  local -i len=${(m)#text}
  local frame="+-${(pl.$len..-.):-}-+"
  print -lr -- $frame "| $text |" $frame
}

If the prompt line aligns with the frame

+-----------------------------+
| romka@adam ✓ ~/powerlevel9k |
+-----------------------------+

If the output of the command is aligned for every part of your prompt (left and right), this indicates a bug in the theme. Use this command to diagnose it:

print -rl -- ${(eq+)PROMPT} ${(eq+)RPROMPT}

Look for %{...%} and backslash escapes in the output. If there are any, they are the likely culprits.

If the prompt line is longer than the frame

+----------------------------+
| romka@adam ✓ ~/powerlevel9k |
+----------------------------+

This is usually caused by a terminal bug or misconfiguration that makes it print ambiguous-width characters as double-width instead of single width. For example, this issue.

If the prompt line is shorter than the frame and is mangled

+-----------------------------+
| romka@adam ✓~/powerlevel9k |
+-----------------------------+

Note that this prompt is different from the original as it's missing a space after the checkmark.

This can be caused by a low-level bug in macOS. See this issue.

If the prompt line is shorter than the frame and is not mangled

+-------------------------------+
| romka@adam ✓ ~/powerlevel9k |
+-------------------------------+

This can be caused by misconfigured locale. See this issue.


Since you have two different prompts (one succeeding the other with a short delay) that get positioned differently, you might have to run these tests on both.

Tip: Once you find a part of your prompt that causes misaligned output, it's a good idea to reduce it to the minimum. Ideally, to a single character.

If you decide to debug your problem, please post the outcome of your attempt (and new methods, should you devise any). Debugging such issues when they are reported by users is very time consuming. It helps to accumulate and pool experience to save time in the future.