Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance configuration of pager colors #5524

Closed
wants to merge 2 commits into from

Conversation

danzimm
Copy link

@danzimm danzimm commented Jan 13, 2019

This PR contains two commits, each of them attempts to have their own nice commit messages, but I'll summarize here too:

  • First we cleanup how highlight specs are connected to environment variables. Before there was a requirement of the developers (and reviewers) to make sure everything two different tables agree. Now we add compile time checks to ensure the tables are the same, and make it clearer which highlight specs correspond to which environment variables.
  • Next we add some new highlight specs to configure how the pager is formatted.
    • Added configs were:
      • Secondary background/prefix/completion/description: these will be applied to all the secondary lines in the pager
      • Selected background/prefix/completion/description: these will be applied to all the selected lines in the pager
    • Tidbits on implementation:
      • In order to implement this I additionally added a table that indicates what a given highlight spec should default to. This is so that the secondary/selected pager specs can default to the normal pager specs (i.e. you don't /need/ to specify the secondary/selected configs if you don't want to)
      • I calculate the correct color by using offsets. These offsets require that the pager highlight specs have a certain form (each category in default/secondary/selected must have a contiguous section of background/prefix/completion/description)

Fixes issue #2442. Inspiration was taken from Chris Mansley (unsure why I can't tag him right now), so thanks man!

Example configuration can be seen below:

Should I update some docs? Where if so?

@floam
Copy link
Member

floam commented Jan 14, 2019

Thanks for improving this.

@mqudsi
Copy link
Contributor

mqudsi commented Jan 17, 2019

I somehow missed this earlier, thanks for working on this.

If order is important, the entries should be sorted alphabetically so that keeping the order in the future is as simple as inserting new entries in the right location, or for those of us using saner editors, as simple as selecting the lines in question and running :sort.

I'm not clear on why the fallbacks array is needed, however. Do you mind clarifying?

Thanks!

@floam
Copy link
Member

floam commented Jan 17, 2019

I think the fallbacks are needed to make sure it looks right with themes that haven't specified those colors.

@danzimm
Copy link
Author

danzimm commented Jan 18, 2019

On the fallbacks array: This is so that the secondary/selected pager specs can default to the normal pager specs (i.e. you don't /need/ to specify the secondary/selected configs if you don't want to). Without this fallbacks table the pager color scheme would require secondary/selected configured, and thus anyone with a previous color scheme, or creating a new color scheme would require to edit their configuration in order for it not to look ugly. To put it another way: without this fallback table there would be a regression in pager color schemes and a regression in the amount of specs you need to configure in order to have a decent looking color scheme.

@danzimm
Copy link
Author

danzimm commented Jan 18, 2019

The semantics of the order are from left to right when writing an entry in the pager; that is, you draw the background, the prefix, the completion and finally the description. This was the ordering previous to my PR so maintaining it here seems fair (and possibly a follow up PR to change if important).

The ordering that’s important is that groups of pager categories are kept contiguous to each other (and thus inherently cannot be alphabetic). See the code that calculates an offset to see why this is necessary (uses this trick reduces code size/complexity so I’m in favor of it)

@ridiculousfish
Copy link
Member

Thanks for doing this, this looks awesome! I didn't know array designators [a] = x were supported by C++ compilers... I'm inclined to go for it and see if anyone's compiler complains!

Please add to doc_src/index.hdr.in (search for 'fish_pager_color_prefix'). The docs here need to be better but for the moment this is where it's recorded.

I think the fallback array has some wrong values, I'll comment on the commit.

[highlight_spec_pager_secondary_prefix] = highlight_spec_pager_prefix,
[highlight_spec_pager_secondary_completion] = highlight_spec_pager_completion,
[highlight_spec_pager_secondary_description] = highlight_spec_pager_description,
[highlight_spec_pager_selected_background] = highlight_spec_pager_background,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These highlight_spec_pager_selected_* are fallbacks for the selected row, I think these should fall back to highlight_spec_selection otherwise the selected row will not be visible.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In order to avoid regressing old color schemes I think we should make highlight_spec_pager_selected_background default to highlight_spec_search_match and the prefix/completion/description default to the unselected pager defaults (with these defaults anybody- i.e. everybody- who doesn't specify these variables at first will get the same behavior as before; fish_color_search_match controls the bg color of a selected row and everything else is configured using the pager_{prefix,completion,description} variables). What do you think?

@ridiculousfish
Copy link
Member

Also there's something funny going on with the parens in the description:

screen shot 2019-01-20 at 12 48 13 pm

@danzimm
Copy link
Author

danzimm commented Jan 20, 2019

Also there's something funny going on with the parens in the description:

screen shot 2019-01-20 at 12 48 13 pm

Oops yeah, looks like I messed up the colors on those guys. Will fix to use the same colors/logic as before

@ridiculousfish
Copy link
Member

Nice. This stuff is all ancient C-ported code, we should have a real struct for highlight_specs.

@danzimm
Copy link
Author

danzimm commented Jan 20, 2019

Maybe that'll be my next project ¯_(ツ)_/¯

Dan Zimmerman added 2 commits January 21, 2019 06:03
I was hacking on this part of the codebase and found this comment
mentioning to keep two things in sync, and felt like we could do better.
Originally I sought out to configure the foreground color of the
selected text in the pager. After reading a thread on a github issue I
was inpired to do more: now you can conifgure any part of the pager when
selected, and when a row is secondary. More specifically this commit adds the
ability to specify a pager row's:

- Prefix
- Completion text
- Description
- Background

when said row is selected or secondary.
@zanchey
Copy link
Member

zanchey commented Jan 26, 2019

@ridiculousfish, are you happy with the changes?

@ridiculousfish
Copy link
Member

Merged as 50448e4, thanks!!

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 17, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants