# Line wrapping in terminal



## genecutl (Aug 13, 2004)

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.


----------



## michaelsanford (Aug 16, 2004)

Doesn't do that to me. What shell are you using (I'm using tcsh) ?


----------



## scruffy (Aug 16, 2004)

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.


----------



## whyre (Aug 23, 2004)

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:

```
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?


----------



## whyre (Aug 23, 2004)

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
> ...



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


```
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!


----------



## scruffy (Aug 23, 2004)

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.


----------

