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

Easy way to adopt fish colours? #344

Open
haizaar opened this issue Jul 7, 2023 · 6 comments
Open

Easy way to adopt fish colours? #344

haizaar opened this issue Jul 7, 2023 · 6 comments
Labels
NYI/NewFeat Not yet implemented or New Feature

Comments

@haizaar
Copy link

haizaar commented Jul 7, 2023

Fish has an amazing web UI where I can set its prompt/completion colors. I like pastel theme which generates the following variables and I wonder how can I convert to ble.sh configuration. Any ideas/docos?

# Colorscheme: Base16 Eighties
set -U fish_color_normal normal  
set -U fish_color_command 99cc99  
set -U fish_color_quote ffcc66  
set -U fish_color_redirection d3d0c8  
set -U fish_color_end cc99cc  
set -U fish_color_error f2777a  
set -U fish_color_param d3d0c8  
set -U fish_color_comment ffcc66  
set -U fish_color_match 6699cc  
set -U fish_color_selection white --bold --background=brblack  
set -U fish_color_search_match bryellow --background=brblack  
set -U fish_color_history_current --bold  
set -U fish_color_operator 6699cc  
set -U fish_color_escape 66cccc  
set -U fish_color_cwd green  
set -U fish_color_cwd_root red  
set -U fish_color_valid_path --underline  
set -U fish_color_autosuggestion 747369  
set -U fish_color_user brgreen  
set -U fish_color_host normal  
set -U fish_color_cancel --reverse  
set -U fish_pager_color_prefix normal --bold --underline  
set -U fish_pager_color_progress brwhite --background=cyan  
set -U fish_pager_color_completion normal  
set -U fish_pager_color_description B3A06D  
set -U fish_pager_color_selected_background --background=brblack  
set -U fish_pager_color_selected_description   
set -U fish_pager_color_secondary_background   
set -U fish_color_host_remote   
set -U fish_pager_color_background   
set -U fish_color_keyword   
set -U fish_color_option   
set -U fish_pager_color_secondary_completion   
set -U fish_pager_color_secondary_description   
set -U fish_pager_color_secondary_prefix   
set -U fish_pager_color_selected_prefix   
set -U fish_pager_color_selected_completion  
@akinomyoga
Copy link
Owner

I wonder how can I convert to ble.sh configuration. Any ideas/docos?

Of course, you can manually convert the configuration one by one and apply it to the corresponding faces of ble.sh. The list of faces is provided in README §2.6. The detailed way of specifying the colors and styles are described in Manual §2.1.

There is currently no automated conversion from the fish spec to the ble.sh spec. I think one of the problems in automating the conversion is that there is no one-to-one correspondence between fish specifications and ble.sh faces, so the desired correspondence can depend on the personal preferences of each user. Also, ble.sh has a larger number of faces, i.e., more detailed distinctions of the syntax components and the contexts, so simply applying the setting of the closest one to a ble.sh's face would degenerate the detailed distinction by ble.sh. Maybe it is still useful to have a converter for the users who do not care about it so much.

Another way to automatically "generate a color theme" might be to use the contrib/colorglass module. This module allows a user to adjust existing color settings all at once by changing the hue, gamma, color mixing, etc. You might adjust these parameters to make the overall impression "similar (but not the same)" to the existing fish theme.

@akinomyoga
Copy link
Owner

I searched for some materials to understand the fish color schemes. We can find the bundled color schemes of fish in the directory /share/tools/web_config/themes [1] of the source repository. The manual of set builtin is found in Ref. [2], but it seems the theme files omit set -U provided in the cover of this Issue. Also, it is not documented there how to specify the options like --background, --bold, --underline. The corresponding source codes that parse these options seem to be found at Ref. [3]. I instead found another documentation page that seems to describe these options [4].

@mattmc3
Copy link

mattmc3 commented Aug 15, 2024

First, some quick background:

Fish themes are a relatively new feature to Fish. Previously, if you ran the fish_config web interface to set a theme, it would emit a bunch of set -U statements, which are universal variables. Fish themes moved away from universals to use globals (which override universals). Defining the color globals for Fish themes is now managed with the CLI using the fish_config theme subcommand. So the weirdness of setting theme colors is due to the legacy differences between using the UI and using the new CLI theming system. I recommend sticking with the new CLI method of theme management to get the details necessary for this ble.sh feature.

As to --background, --bold, and --underline - it's all the same flags as set_color, which means there's also --reverse, --italics, etc. You can see their usage in the built-in themes like so:

> fish_config theme dump | grep -e '--'
fish_color_history_current --bold
fish_color_match --background=brblue
fish_color_search_match --background=33467c
fish_color_selection --background=33467c
fish_color_valid_path --underline
fish_pager_color_selected_background --background=33467c

From bash, you can call into Fish and get at its themes with commands like so:

# Show the themes available
$ fish -c 'fish_config theme list'
ayu Dark
ayu Light
...
Tomorrow Night
Tomorrow

# Show the colors of a theme
$ theme="Tomorrow Night"
$ fish -c 'fish_config theme choose $argv; fish_config theme dump' "$theme"
fish_color_autosuggestion 969896
fish_color_cancel -r
fish_color_command b294bb
fish_color_comment f0c674
fish_color_cwd green
fish_color_cwd_root red
...
fish_pager_color_selected_background --background=brblack
fish_pager_color_selected_completion
fish_pager_color_selected_description
fish_pager_color_selected_prefix

All that background to say - I'm willing to pitch in and help here if you can get me started. The main blocker is that I would need a reasonable mapping from Fish's color variables to the ones ble.sh uses to get started.

@akinomyoga
Copy link
Owner

Thank you for the details. Then, I guess we would want to parse the version without set -U.

The main blocker is that I would need a reasonable mapping from Fish's color variables to the ones ble.sh uses to get started.

Yeah, that is the non-trivial part.

Once we settle the mapping, we want to create an automated conversion script. The conversion of the Fish themes wouldn't be a one-time conversion, but we would like to update them occasionally to keep track of the upstream Fish themes. We do not want to rework the entire conversion manually every time we update the themes originating from Fish's, so we need an automated way.

As described above, the categories of the colors from Fish and ble.sh are not in one-to-one correspondence. Then, a non-trivial question is how to adjust a blesh-specific face (i.e., ble.sh's face that doesn't have a corresponding Fish theme color):

  • If we choose the closest one, the colors would degenerate and lose the distinctions that ble.sh provides.
  • Or maybe we can simply leave them unchanged, but in that case, the colors might not fit well with the tone of the Fish theme.
  • Another option might be to first determine the "average color" of the Fish theme (by e.g. taking the averages of typical theme colors) and then blend the determined "average color" into ble.sh's default colors for the bash-specific faces. Hmm, I came up with this idea just now, but this seems actually a good idea.

@akinomyoga akinomyoga added the NYI/NewFeat Not yet implemented or New Feature label Aug 15, 2024
@mattmc3
Copy link

mattmc3 commented Aug 15, 2024

I was thinking a much simpler approach would be sufficient - namely, if Fish didn't define a color for a feature then don't colorize it in ble.sh either (ie: $(tput sgr0) or some color no-op). Not sure how you tell ble.sh to do that? Something like?

ble-face -s syntax_expr fg=

This is the simplest and most reasonable implementation - namely that you are truly just copying Fish's theming as-is. If the output of the theme converter could group all the undefined colorizations at the bottom, it would also then let users coming from Fish see what other things are possible with ble.sh and change those themselves. It also lets you keep the utility simple and reduces future maintenance. And, it's a pretty reasonable position to say the utility only supports theming elements as close as possible to the way Fish does and nothing more, while still letting the user have control of additional theming elements if they want them.

@akinomyoga
Copy link
Owner

akinomyoga commented Aug 15, 2024

I was thinking a much simpler approach would be sufficient - namely, if Fish didn't define a color for a feature then don't colorize it in ble.sh either (ie: $(tput sgr0) or some color no-op).

I'm not sure if I understand it correctly, but I think mostly everything loses the style if you simply do that because most ble faces do not seem to have corresponding Fish color variables (as far as I look at the output of fish_config theme dump).

Not sure how you tell ble.sh to do that? Something like?

ble-face -s syntax_expr fg=

Please check §2.1. It's none. If you want to only highlight the ones for which Fish has corresponding variables, you can first run

ble-face @=none

and then run ble-face <FACENAME>=<GSPEC> (where <FACENAME> and <GSPEC> are replaced with appropriate values) one by one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NYI/NewFeat Not yet implemented or New Feature
Projects
None yet
Development

No branches or pull requests

3 participants