2

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 what's 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?

1 Answer 1

0

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

shopt -s checkwinsize

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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