Re: Storing and then printing ANSI escape sequences in (andthen from) variables
| From: | Luke Slater | Date: | Thu, 08 Jan 2009 07:32:02 +0000 |
| Subject: | Re: Storing and then printing ANSI escape sequences in (andthen from) variables | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-285641@lists.php.net to get a copy of this message | ||
The issue isn't that I can't get colours to display on the screen, if I were to substitute
$pstring = $connections[$channel][2] . $connections[$channel][1] . " " . $buffer . chr(7);
for
$pstring = "\033[33m" . $connections[$channel][1] . " " .
then it would work perfectly. Thanks again, Luke Slater On Wed, 7 Jan 2009, Fred Briand wrote:$buffer . chr(7);
Paul M Foster a écrit :On Wed, Jan 07, 2009 at 11:11:53PM +0000, Luke Slater wrote:Hi, Interesting and so easy solution, last time I tried it I had to re-initialize my console!! It sure works better and is also much more secured. I'll give it a try on bsd and solaris consoles too (still doesn't work on cygwin) fred -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.phpHi, I'm storing ANSI escape sequences in an array, stored like this: $connections[$channel][2] = $info['colour']; $info['$colour'] would contain something like \033[33m Now, my problem is when I try and print it: $pstring = $connections[$channel][2] . $connections[$channel][1] . " " . $buffer . chr(7); It will print as a literal string, actually printing \033[33m to the screen, so how do I make it work? I'm sure I'm missing something fatally simple here. Thanks for your help, Luke SlaterWhat you're storing is human shorthand for bytes sent to the display. (I'm assuming you're working with the terminal here, not a browser window.) The \033 indicates an octal byte with that value. But when you send it, you're sending each character individually to the screeen. That is '\' is one byte, '0' is the next, '3' the next, etc. That '\033' (and subsequent codes) need to be coded as single bytes and sent bytewise to the terminal. And if your terminal isn't configured to accept ANSI excape codes, it won't work anyway. Your chr(7) is the clue. Your codes, if numeric, need to be converted to integers and given to the chr() function, and output using that function. Try converting some known codes into integers, outputting them via the chr() function, and seeing if the result is what you expected. You may need to use the inverse function, ord(), to get your codes into numeric form. For example, ord('m') will return decimal 109. That's only an example, since you should be able to send single characters to the terminal as is. Paul