Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

\[\][timer]>>\[\] 

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\] "
[timer]>>

What am I missing here?

share|improve this question

1 Answer 1

According to http://mywiki.wooledge.org/BashFAQ/053 the checkwinsize option may be necessary if scrolling through the command history:

shopt -s checkwinsize
share|improve this answer

Your Answer

 
discard

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.