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

Re: region_highlight converts `fg=default` to `none`, which is not the same

Roman Perepelitsa wrote on Thu, 15 Oct 2020 07:37 +00:00:
> I could imagine two simple merging strategies:
> 1. All attributes are merged, so fg=1 + bg=2 + underline would result
> in underlined red text on green background.
> 2. The second highlight completely overrides the first. fg=1 + bg=2 +
> underline results in underlined text with the default color and no
> background.
> The meaning of "none" naturally follows from the choice of merging
> strategy. In the first case region highlight with "none" spec has no
> effect (X + none => X). In the second case such a region is displayed
> without any highlighting (X + none => no highlighting).
> The actual code does something else. If a spec has fg or bg with any
> value other than "default", then the spec completely overrides the
> previous spec. Otherwise the spec is merged with the previous spec
> with one exception: fg=default and bg=default have no effect (fg=1 +
> fg=default,underline => fg=1,underline).
> Note: "special" highlight is merged with a different algorithm. All
> other highlights, including "region", "isearch" and "paste", are
> merged the same way as the elements of region_highlights.
> A few examples of what the current code does:
> - fg=1 + bg=2 => bg=2
>   * the second spec completely overrides the first
> - fg=1 + underline => fg=1,underline
>   * specs are merged
> - underline + fg=1 => fg=1
>   * the second spec completely overrides the first
> - fg=1 + none => fg=1
>   * specs are merged
> - fg=1 + fg=default,underline => fg=1,underline
>   * specs are merged except that fg=default has no effect
> This doesn't look ideal. So, how can we fix it?
> Thoughts?

The inconsistent augmentation semantics have bugged me since I first ran
into them.  I'd love to see them rationalized.

Short on time, but in general terms:

1. Heed PEP 20.  (E.g., the points about explicitness and ambiguity)

2. Proposed acceptance test: When two specs are added, A+B, for any
   desired visual outcome there should be a value of B that, _regardless
   of the value of A_, achieves that outcome.

Not sure how to get from the current semantics to acceptable ones.  Maybe we could do, say:

- fg=1 + bg=2,fg=inherit ⇒ fg=1,bg=2
- underline + fg=1,underline=inherit ⇒ fg=1,underline
- none + fg=1,underline=inherit ⇒ fg=1 [no underline]

As to «fg=1 + fg=default ⇒ fg=1», I think we can treat it as a bug and break compatibility?

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