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

Re: colorizing printfs



On Sat, May 11, 2024 at 4:27 PM Mikael Magnusson <mikachu@xxxxxxxxx> wrote:
>
> On Sat, May 11, 2024 at 2:54 AM Kannan Varadhan <kvaradhan3@xxxxxxxxx> 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}"

However, it's easier to use `print -P`:

    print -P '%F{blue}%Btest%b%f'

Or, when printing $var:

    print -rP '%F{blue}%B'${var//\%/%%}'%b%f'

Alternatively:

    print -Pn '%F{blue}%B'
    print -rn -- $var
    print -P '%b%f'

Another alternative:

    print -r -- ${(%):-'%F{blue}%B'${var//\%/%%}'%b%f'}

Roman.




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