Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am writing a program that prints colored lines, and the more I do with it the more I find myself working around line wrapping issues that come up.

It is a sort of terminal written in php, here is the prompt:

$return = readline("\033[44m\033[1;37m{$this->text}>>\033[0m ");

If I scroll through history my text gets off by 10 characters, and if I type in 21 characters and delete one, it clears the whole line and begins deleting characters from the line above. This is on a console that is 47 columns wide

If I try to add escapes

$return = readline("\[\033[44m\033[1;37m\]{$this->text}>>\[\033[0m\] ");

then it prints the brackets...even if I add double backslashes.


I find the same thing for echo -e, I am really not sure whats going on.

Lastly, if I modify PS1 it works just fine.

[mike@crest ~]$ export PS1="\[\033[44m\033[1;37m\][timer]>>\[\033[0m\] "

What am I missing here?

share|improve this question

According to the checkwinsize option may be necessary if scrolling through the command history:

shopt -s checkwinsize
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.