Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Terminal - Prompt with color - Line wrap problem

I understand how to change the prompt in Terminal.app as described here:

http://discussions.apple.com/thread.jspa?messageID=6542817&#6542817

Looking elsewhere I've seen how to include different colors in the prompt:
My prompt without color:
PS1="\h(\w) \$ "
and with color:
PS1="\e[1;36m\h\e[33m(\w) \$\e[0m "

That's hostname in cyan, followed by the path in yellow, then the $, then back to default color for whatever gets typed.

The problem is that whenever I include these escape characters for colored text, the line wrap no longer works properly in Terminal.app. Specifically, when the command extends past the end of the line, the terminal doesn't scroll to the next line... it just wraps back to the beginning of the same line (erasing it in the process). Backspacing to before the wrap then seems to try to undo the linefeed it never got, so I end up one line above where I started.

Also, when using up-arrow to go back into history if there are any of these long lines, it seems to get confused about where it should start writing the command... as though they are being pushed forward on the line by those escaped characters (that shouldn't add any length to the line).

The program logic is fine... a given series of keystrokes always does the correct thing. It is just not being displayed correctly.

I've tried a few different ways of including the escape character, but any that work and give me colors, also cause this wrapping problem.

------------
A quick test:
put the following into your ~/.bash_profile:
export PS1="\e[1;36m\h\e[33m(\w) \$\e[0m "

Open a new terminal window (you should see the cyan and yellow prompt). Then just hold down the letter 'a'. You should see it get screwed up when the line wraps.

Compare the result with
export PS1="\h(\w) \$ "
-------------

I get the same result in both Terminal.app and the xterm included with X11 on apple. However, the prompt works fine for me on cygwin, and any number of terminals on linux.

Looks like a Terminal bug, but I'd be happy to hear of a workaround. I find having the color prompt hugely increases readability... particularly when you have to scroll back through a bunch of error messages on a build. It's always easy to spot where you started the last command.

I've had this problem from 10.4.? to 10.5.2.

Thanks,
Malcolm

Mac OS X (10.5.2), Terminal.app

Posted on Apr 15, 2008 3:17 PM

Reply
Question marked as Best reply

Posted on Apr 16, 2008 6:55 PM

My fault... I wasn't closing my escape sequences.

As described here: http://pthree.org/2006/06/11/bash-scripting-and-prompts/

My new prompt command:
export PS1="\[\033[1;36m\]\h\[\033[33m\](\w) \$\[\033[0m\] "

It's entirely a bash issue (nothing to do with Terminal.app)... though strangely, I only see this problem on the mac, not on linux or cygwin. Maybe the buffer that stores the escape sequences defaults to much longer on those systems.

Malcolm
1 reply
Question marked as Best reply

Apr 16, 2008 6:55 PM in response to MalcolmDwyer

My fault... I wasn't closing my escape sequences.

As described here: http://pthree.org/2006/06/11/bash-scripting-and-prompts/

My new prompt command:
export PS1="\[\033[1;36m\]\h\[\033[33m\](\w) \$\[\033[0m\] "

It's entirely a bash issue (nothing to do with Terminal.app)... though strangely, I only see this problem on the mac, not on linux or cygwin. Maybe the buffer that stores the escape sequences defaults to much longer on those systems.

Malcolm

Terminal - Prompt with color - Line wrap problem

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.