zsh-users
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh-users@zsh.org
Subject: Re: print color escapes
Date: Thu, 01 Jan 2015 13:29:31 -0800	[thread overview]
Message-ID: <150101132931.ZM27115@torch.brasslantern.com> (raw)
In-Reply-To: <54A59EE5.7000601@eastlink.ca>

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


  reply	other threads:[~2015-01-01 21:30 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-01  5:47 Ray Andrews
2015-01-01  6:35 ` Bart Schaefer
2015-01-01 19:24   ` Ray Andrews
2015-01-01 21:29     ` Bart Schaefer [this message]
2015-01-01 23:02       ` Ray Andrews
2015-01-01 23:26         ` Bart Schaefer
2015-01-02  2:30           ` Ray Andrews
2015-01-02  2:45             ` Kurtis Rader
2015-01-02  3:50               ` Ray Andrews
2015-01-02  4:18                 ` Bart Schaefer
2015-01-02 17:43                   ` Ray Andrews
2015-01-02  1:21         ` Kurtis Rader
2015-01-02  2:39           ` Ray Andrews
2015-01-02  2:58             ` Kurtis Rader
2015-01-02  3:48               ` Ray Andrews

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=150101132931.ZM27115@torch.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).