Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: print color escapes



On 12/31/2014 10:35 PM, Bart Schaefer wrote:
torch% print -r ${(V)fg[cyan]}
^[[36m
torch% print -r ${(q)fg[cyan]}
$'\033'\[36m
Thanks, either is usable.

} I'd expect 'print } -r' to 'stay literal' with the expanded variable but no luck.

> It is staying literal with the expanded variable. The variable has a literal escape (ascii 033) in the value, not the string backslash e, so print -r emits that literal escape etc. It's the terminal that then turns that into a color, not the print command.

Ok, we hafta stop the terminal from doing it's thing when we want to 'see' the escape code without the terminal 'doing' the escape code. But why/where is the change made? I tried this script:

   cyan='\e[36;1m'
   norm='\e[0m'
   print    "1: $fg[cyan] howdy $norm"
   print    "2: $cyan howdy $norm"
   print -r "7: the value of fg[cyan] is: ${(V)fg[cyan]}"
   print -r "8: the value of cyan       is: ${(V)cyan}"


   1:  howdy << nicely cyan
   2:  howdy << nicely cyan
   7: the value of fg[cyan] is: ^[[36;1m      << modified to 'bold' by me.
   8: the value of cyan       is: \e[36;1m

... either the " \e[ " or the " ^[[ " form produces the color change, so why does the 'color' function 'bother' to change from one form to the other, and how/where? I see the escape created like this:

    local lc=$'\e[' rc=m

... so how does it end up like: " ^[[ " ?

BTW I know you can't type " ^[[ " and have it work, the " ^[ " represents the escape code but can't create it, so I know it's a 'safe' way of showing the code, but since both my '$cyan' and 'fg[cyan]' seem to work the same way, I'm confused as to what the point of the difference is.



Messages sorted by: Reverse Date, Date, Thread, Author