Coder Social home page Coder Social logo

Comments (12)

lyze avatar lyze commented on August 22, 2024

I am unable to reproduce this. My strong suspicion is that you have not wrapped your color codes in \[ and \] for bash (or %{ and %} for zsh). This Stackoverflow post has a well-written explanation of this problem. Could you please paste the exact mumbo jumbo used to set PROMPT_COMMAND?

from posh-git-sh.

erikhuizinga avatar erikhuizinga commented on August 22, 2024

Here's the exact code.

export PROMPT_COMMAND='__posh_git_ps1 "\[\e[00;37m\]\u@💻  \[\e[00;31m\]\w" "\[\e[00;37m\] \$ \[\e[00m\]";'$PROMPT_COMMAND

I know bash does not know the number of printable and unprintable characters, so those should be grouped in \[ and \]. I guess the grouping I currently have is correct, but if you spot any error I'd like to know!

I figured it could be caused by some quirk concerning the laptop emoji 💻 I use. Because it prints in a different font (because my monospaced console font, Source Code Pro, does not support it) it is wider than the terminal font and requires two spaces after the character. However, I tried replacing it with \h and the results did not change.
schermafbeelding 2016-12-04 om 11 01 06
I conclude that a line breaking in the middle of or near the posh git string may cause the incorrect wrapping problem.

from posh-git-sh.

lyze avatar lyze commented on August 22, 2024

After a little bit of poking around, it just seems that the particular emoji doesn't play nicely at all with the terminal. I opened up a boring terminal prompt, pasted it in. It caused havoc to my prompt if I tried to edit the line and if it was a long line. This feels like a limitation in bash or the terminal emulator. Can check that taking out the emoji eliminates the problem?

from posh-git-sh.

erikhuizinga avatar erikhuizinga commented on August 22, 2024

@lyze As I said in my previous comment: I can reproduce the problem without the emoji, so the issue isn't caused by it.

from posh-git-sh.

lyze avatar lyze commented on August 22, 2024

I can't reproduce the problem when using \h on my own computer. (Caveat: It wasn't on a Mac, and I don't have a Mac handy to test.)

The actual expansion of PS1 with \h:

\[\e[00;37m\]\u@\h \[\e[00;31m\]\w\[\e[1;33m\] [\[\e[1;36m\]master ≡\[\e[1;33m\]]\[\e[m\]\[\e[00;37m\] $ \[\e[00m\]

I can't see anything wrong with it.

I'm really scratching my head here. Some theories that I would need you to help investigate:

  • Is there anything else in $PROMPT_COMMAND that might mess with $PS1?
  • Have you tried setting shopt -s checkwinsize?
  • Try messing with the terminal emulation settings? I think it's "Preferences > Advanced > Emulation".
  • Try using tput instead of ANSI colors.

from posh-git-sh.

erikhuizinga avatar erikhuizinga commented on August 22, 2024

Great ideas! Here are my results. (spoiler: no luck...)

  • Yes, my $PROMPT_COMMAND contains (before prepending my posh Git string): update_terminal_cwd. Removing it does not change the issue.
  • It was already set and explicitly setting it does not change the issue.
  • How do I do this? Is it under Prefs > Advanced > Terminfo (where it says xterm-256color by default)? I tried about 5 different values there and it does not change the issue.
  • Currently, my $PROMPT_COMMAND implementation is:
red=$(tput setaf 1)
gray=$(tput setaf 8)
reset=$(tput sgr0)
export PROMPT_COMMAND='__posh_git_ps1 "\[$gray\]\u@\h \[$red\]\w" "\[$gray\] \$ \[$reset\]";'$PROMPT_COMMAND

The issue persist, unfortunately.

Even when using export PROMPT_COMMAND='__posh_git_ps1 "\u@\h \w" " \$ ";'$PROMPT_COMMAND or export PROMPT_COMMAND='__posh_git_ps1 "foo bar" " baz qux ";'$PROMPT_COMMAND does not change the issue.

from posh-git-sh.

lyze avatar lyze commented on August 22, 2024

If you clear PROMPT_COMMAND and only set PS1, does the problem still occur?

PROMPT_COMMAND=
PS1=\[\e[00;37m\]\u@\h \[\e[00;31m\]\w\[\e[1;33m\] [\[\e[1;36m\]master ≡\[\e[1;33m\]]\[\e[m\]\[\e[00;37m\] $ \[\e[00m\]

from posh-git-sh.

erikhuizinga avatar erikhuizinga commented on August 22, 2024

Using

PROMPT_COMMAND=
PS1='\[\e[00;37m\]\u@\h \[\e[00;31m\]\w\[\e[1;33m\] [\[\e[1;36m\]master ≡\[\e[1;33m\]]\[\e[m\]\[\e[00;37m\] $ \[\e[00m\]'

(i.e. what you said, but with 'quotes')
the results are the same. Something is wrong in the way Terminal wraps a line with grouping of non-printable characters. I think the line break it should insert ends up erroneously within the unprintable group, so it gets ignored somehow.

I guess this rules out posh-git-sh as the culprit, don't you agree? Where do I go next with this issue? The current behaviour is ok if the Terminal window does not have the problematic width (which is one of two or three widths depending on the length of $PS1 when it prints).

I guess I'll have to resort to a Terminal alternative.

from posh-git-sh.

lyze avatar lyze commented on August 22, 2024

I'm out of ideas at the moment. By now, I, too, am fairly confident that posh-git-sh isn't the culprit here.

A long shot. Do you think you need to update bash or Terminal itself?

Also, I think you may want to consider filing an Apple bug report.

from posh-git-sh.

erikhuizinga avatar erikhuizinga commented on August 22, 2024

I work on Terminal v2.7.1 (387), which is the latest stable release according to Wikipedia at the moment of writing. Also, I'm running Bash v4.4.5(1)-release (echo $BASH_VERSION), again, the latest stable version according to Wikipedia.

I'll contact Apple about the issue.

from posh-git-sh.

erikhuizinga avatar erikhuizinga commented on August 22, 2024

Thanks for taking the time to look into this! 👍 I hope I'll find a solution for this (and if so, I'll report back here).

from posh-git-sh.

erikhuizinga avatar erikhuizinga commented on August 22, 2024

I've opened a discussion thread here.

from posh-git-sh.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.