Line wrapping in terminal

genecutl

Registered
One thing that bugs me all the time which I haven't been able to figure out is buggy line wrapping in console windows such as Terminal. This is not a Terminal-specific issue, it happens pretty much all over, including XTerm. When I type in a long line, instead of wrapping over to the next line, the text wraps back to the front of the current line overwriting it so that I don't know what the hell I've typed.

Does anyone know how to fix this? It bugs me to no end!
Thanks.
 
I found it did that if I used certain escape sequences - if I made my prompt bold, in particular, it alwayst happened. I changed my prompt to leave out the bold part, and it worked ok for the most part.

Another thing I find is that after running some commands that use up the whole screen (curses/ncurses based?), and occasionally just after commands with a lot of output, the next command line will start being entered several lines too high, over top of previously typed commands.
 
Argh, I'm now noticing this problem as well. I took off the bold portion of my prompt, and I still get wrap around, currentky, here's my current .bash_profile:
Code:
GREEN="\e[0;32m"
BLUE="\e[0;34m"
PLAIN="\e[m"
PS1="${GREEN}\u@\h ${BLUE}\W $ ${PLAIN}"
alias ls='ls -GF'
alias su='su -l'
PATH=$PATH:/usr/local/bin

I'm wondering if it has something to do with the escape sequence I assigned to PLAIN to turn off the coloring?
 
Okay, did some more research on the whole ANSI escape sequences and here's what I found: UnixGuide
Readline, the line editing library that bash uses, does not know
that the terminal escape sequences do not take up space on the
screen. The redisplay code assumes, unless told otherwise, that
each character in the prompt is a `printable' character that
takes up one character position on the screen.

You can use the bash prompt expansion facility (see the PROMPTING
section in the manual page) to tell readline that sequences of
characters in the prompt strings take up no screen space.

Use the \[ escape to begin a sequence of non-printing characters,
and the \] escape to signal the end of such a sequence.

So I've changed my .bash_profile to reflect these changes:

Code:
GREEN="\[\e[0;32m\]"
BLUE="\[\e[0;34m\]"
PLAIN="\[\e[m\]"
PS1="${GREEN}\u@\h ${BLUE}\W $ ${PLAIN}"
alias ls='ls -GF'
alias su='su -l'
PATH=$PATH:/usr/local/bin
...and viola! No more odd wrapping!
 
Excellent! Thanks for the tip.

I was using stuff like `tput bold` and `tput sgr0` (for plain text) for escape sequences and having the same sort of problems. Just tried with the backticked stuff like this:
bold='\['`tput bold`'\]'
and line wrapping works fine again!

Anyway I just use tcsh, which is what I got used to from OS X pre-10.3 anyway. Using the predefined sequences %B and %b for bold on/off, it counts printing characters correctly on its own.
 
Back
Top