zsh-users
 help / color / mirror / code / Atom feed
From: Stephane Chazelas <stephane@chazelas.org>
To: Roman Perepelitsa <roman.perepelitsa@gmail.com>
Cc: Mikael Magnusson <mikachu@gmail.com>,
	Kannan Varadhan <kvaradhan3@gmail.com>,
	Zsh Users <zsh-users@zsh.org>
Subject: Re: colorizing printfs
Date: Tue, 14 May 2024 07:48:11 +0100	[thread overview]
Message-ID: <20240514064811.7yhviseibxjj34nq@chazelas.org> (raw)
In-Reply-To: <CAN=4vMpFktpOPyN2B1YAEaP1mETMJ7aR7oE48J3x18X1DvY0bg@mail.gmail.com>

2024-05-11 16:37:03 +0200, Roman Perepelitsa:
> On Sat, May 11, 2024 at 4:27 PM Mikael Magnusson <mikachu@gmail.com> wrote:
> >
> > On Sat, May 11, 2024 at 2:54 AM Kannan Varadhan <kvaradhan3@gmail.com> wrote:
> > >
> > >
> > > ~⦒printf '%s.%s.%s\n' "${(%):-%F{blue}%B}" "test" "${(%):-%b}${(%):-%f}"
> > > %B}.test.
> >
> > You probably have a badly made / cargo culted precmd() function
> > active.
> 
> That output is actually expected. The right curly must be escaped.
> 
>     printf '%s.%s.%s\n' "${(%):-%F{blue\}%B}" "test" "${(%):-%b}${(%):-%f}"
[...]

Thanks, I've fixed
https://unix.stackexchange.com/questions/408867/how-to-colorize-some-of-the-output-of-a-shell-script/408871#408871
(which was at the start of the discussion) accordingly.

> Or, when printing $var:
> 
>     print -rP '%F{blue}%B'${var//\%/%%}'%b%f'
[...]

It should be noted (as I now have in my answer above) that that
assumes the promptbang and promptsubst options are disabled and
promptpercent is enabled, with possible dramatic effect if not
(like when $var contains $(reboot) and promptsubst is enabled).

-- 
Stephane


      parent reply	other threads:[~2024-05-14  6:49 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-11  0:52 Kannan Varadhan
2024-05-11 14:26 ` Mikael Magnusson
2024-05-11 14:37   ` Roman Perepelitsa
2024-05-12  0:19     ` Kannan Varadhan
2024-05-12  6:44       ` Roman Perepelitsa
2024-05-13 20:53       ` Rick Bowen
2024-05-14  6:48     ` Stephane Chazelas [this message]

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=20240514064811.7yhviseibxjj34nq@chazelas.org \
    --to=stephane@chazelas.org \
    --cc=kvaradhan3@gmail.com \
    --cc=mikachu@gmail.com \
    --cc=roman.perepelitsa@gmail.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).