Skip to content
This repository has been archived by the owner on Apr 24, 2020. It is now read-only.

[Next] Issue with leftPromptWidth #1372

Open
onaforeignshore opened this issue Oct 11, 2019 · 1 comment
Open

[Next] Issue with leftPromptWidth #1372

onaforeignshore opened this issue Oct 11, 2019 · 1 comment

Comments

@onaforeignshore
Copy link
Contributor

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.

  • What version of ZSH are you using? You can use zsh --version to see this.
    zsh 5.7.1 (x86_64-apple-darwin18.2.0)

  • Do you use a ZSH framework (e.g., Oh-My-ZSH, Antigen)?
    No

  • How did you install P9k (cloning the repo, by tarball, a package from your OS, etc.,)?
    cloning

  • What version of P9k are you using?
    Next

  • Which terminal emulator do you use?
    iTerm 2

@romkatv
Copy link

romkatv commented Oct 11, 2019

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants