From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11007 invoked by alias); 1 Jan 2015 21:30:16 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 19647 Received: (qmail 12356 invoked from network); 1 Jan 2015 21:30:03 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 X-CMAE-Score: 0 X-CMAE-Analysis: v=2.1 cv=D9vw8UVm c=1 sm=1 tr=0 a=FT8er97JFeGWzr5TCOCO5w==:117 a=kj9zAlcOel0A:10 a=q2GGsy2AAAAA:8 a=oR5dmqMzAAAA:8 a=-9mUelKeXuEA:10 a=YNv0rlydsVwA:10 a=cHOZH6Lp49yj9ke30PwA:9 a=CjuIK1q_8ugA:10 From: Bart Schaefer Message-id: <150101132931.ZM27115@torch.brasslantern.com> Date: Thu, 01 Jan 2015 13:29:31 -0800 In-reply-to: <54A59EE5.7000601@eastlink.ca> Comments: In reply to Ray Andrews "Re: print color escapes" (Jan 1, 11:24am) References: <54A4DF80.7040206@eastlink.ca> <141231223506.ZM26289@torch.brasslantern.com> <54A59EE5.7000601@eastlink.ca> X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: zsh-users@zsh.org Subject: Re: print color escapes MIME-version: 1.0 Content-type: text/plain; charset=us-ascii On Jan 1, 11:24am, Ray Andrews wrote: } } 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? The pair "\e" is interpreted by the "print" command and changed into an ascii 033 character, UNLESS you use the -r or -R options. So in your script: } cyan='\e[36;1m' } norm='\e[0m' } print "1: $fg[cyan] howdy $norm" } print "2: $cyan howdy $norm" above, "print" has changed \e to ESC, but: } print -r "7: the value of fg[cyan] is: ${(V)fg[cyan]}" } print -r "8: the value of cyan is: ${(V)cyan}" there, print has *not* done so. The value of $fg[cyan] already has a literal ESC in it, so "print" does nothing with that either way. In these lines: } 7: the value of fg[cyan] is: ^[[36;1m << modified to 'bold' by me. } 8: the value of cyan is: \e[36;1m There (V) flag has changed the literal ESC into ^[ for display, but there is no literal ESC in $cyan so the (V) flag did nothing. } ... either the " \e[ " or the " ^[[ " form produces the color change, so No, NEITHER of those forms produce the color change. What produces the color change is the literal ESC, which occurs either because it is already there ($fg[cyan]) or because the "print" command translated \e ($cyan). } why does the 'color' function 'bother' to change from one form to the } other, and how/where? The color function does not change the form. The (V) flag does, to make it "visible". } I see the escape created like this: } } local lc=$'\e[' rc=m In that expression, the $'' form of quoting converts \e to ESC, which is why the $'' form of quoting exists in the first place (and is different from ordinary single quoting). $'' is to avoid having to do something more expensive (fork + read output) such as lc="$(echo '\e[')". The (V) flag converts ESC to ^[ because that's what most people are used to seeing ("visible"). The (q) flag converts to $'\e' because that's what people are used to writing (and because "eval ${(q)...}" needs it in that format). The print and echo commands convert \e to ESC because of historical practice. The bindkey command converts both ^[ and \e to ESC for maximum flexibility in writing key bindings. All of this is entirely independent of what the terminal does when it sees an ESC. -- Barton E. Schaefer