zsh-workers
 help / color / mirror / code / Atom feed
From: Mikael Magnusson <mikachu@gmail.com>
To: Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: [regression] %2K prompt expansion no longer works
Date: Sat, 24 Oct 2020 16:21:09 +0200	[thread overview]
Message-ID: <CAHYJk3SPBJvnEhWDDifxRXw3t89p1XbJ08w1QZb_kQVWrRVK5Q@mail.gmail.com> (raw)
In-Reply-To: <20200830111346.xulnbxoqxduetnoz@chazelas.org>

On 8/30/20, Stephane Chazelas <stephane@chazelas.org> wrote:
> $ print -rnP %2K | hd
> 00000000  1b 5b 34 30 6d                                    |.[40m|
> 00000005
>
> %K{2} is fine:
>
> $ print -rnP '%K{2}' | hd
> 00000000  1b 5b 34 32 6d                                    |.[42m|
> 00000005
>
> Introduced by worker:30496
> (https://www.zsh.org/mla/workers/2012/msg00421.html
> 8a9b141652a0e4157056dc21e36a64ac712a7ee7 git commit).
>
> Oddly, the comment there:
>
>> Well, nobody objected so here's a version with de-duplicated
>> code. The previous patch broke %K, but it works now (passed 1
>> for is_fg on both paths).
>
> Actually describes the bug here. Looks like Mikael just missed a bit in
> that
> fix.
>
> Should be fixed with:
>
>
> diff --git a/Src/prompt.c b/Src/prompt.c
> index bc9734720..997327e18 100644
> --- a/Src/prompt.c
> +++ b/Src/prompt.c
> @@ -258,7 +258,7 @@ parsecolorchar(zattr arg, int is_fg)
>  		bv->fm--;
>  	}
>      } else
> -	arg = match_colour(NULL, 1, arg);
> +	arg = match_colour(NULL, is_fg, arg);
>      return arg;
>  }

Just noticed that these [unposted] testcases don't pass. Added some
debugging prints and it turns out that %F{green} uses a different code
than specifying the number. Eg,

    echo $F1 $F2 $F3 $F4 | cat -v

results in

^[[38;5;2m ^[[38;5;2m ^[[38;5;2m ^[[32m

(the results are equivalent if you explicitly set fg_start_code to
^[[38;5;, but the test case doesn't do that, and of course that might
not be what terminfo contains anyway.)

I think the correct fix is to not include F4 and K4 since they use
these definitions in the source code:
#define TC_COL_FG_START	"\033[3"
#define TC_COL_BG_START	"\033[4"

which will not match the others.

-- 
Mikael Magnusson


  parent reply	other threads:[~2020-10-24 14:21 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-30 11:13 Stephane Chazelas
2020-08-30 13:17 ` Mikael Magnusson
2020-10-24 14:21 ` Mikael Magnusson [this message]
2020-10-25 20:12   ` Daniel Shahaf
2020-10-25 21:29     ` Mikael Magnusson
2020-10-26  7:29       ` Stephane Chazelas
2020-10-29 23:09         ` Oliver Kiddle
2020-10-30  0:42           ` Bart Schaefer
2020-10-30  9:11             ` Peter Stephenson
2021-03-30 20:03           ` Oliver Kiddle

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=CAHYJk3SPBJvnEhWDDifxRXw3t89p1XbJ08w1QZb_kQVWrRVK5Q@mail.gmail.com \
    --to=mikachu@gmail.com \
    --cc=zsh-workers@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).