Readline problems

I'm having problems with libreadline. When I write text longer than the current line, the text wraps back to the beginning of the line rather than to the next line. Also, when I use the arrow keys to edit something in that beginning part, it won't display at all (so I can edit only if I remember the order of the characters, most inconvenient).

It won't even work under xterm. Changing ROWS and LINES doesn't help. Upgrading to readline v. 6 didn't help, either.

Using Ctrl+R to redraw didn't quite work as it should have; picture here:
mersenneforum.org - View Single Post - Readline problems

How can I fix this?

What is the output for:

stty -a
echo $TERM

charles@zed:~$ stty -a
speed 38400 baud; rows 24; columns 80; line = 0;
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = M-^?; eol2 = M-^?;
swtch = M-^?; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W;
lnext = ^V; flush = ^O; min = 1; time = 0;
-parenb -parodd cs8 hupcl -cstopb cread -clocal -crtscts
-ignbrk brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon -ixoff
-iuclc ixany imaxbel iutf8
opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
isig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt
echoctl echoke
charles@zed:~$ echo $TERM
xterm

Note: I'm having the problem with a program using readline (Pari), not the terminal itself. I'm not sure whether this applies or not. There are no problems with readline in the terminal itself.

You mean COLUMNS, not ROWS, correct? Console I/O sees COLUMNS env variable.

Are you using escape sequences to create your prompt? If so they will interfer with readline unless you use the \[ escape to begin a sequence of non-printing characters,
and the \] escape to signal the end of such a sequence.

That's it!

I wasn't able to fix the escape sequences by adding \]: the program actually displays a ] and readline fails all the same. But if I remove the escape sequences entirely (giving up on bolding text and such) the editing works!

Thanks a lot -- this is really going to make using this program much easier.