linrongbin16 / fzfx.nvim

A Neovim fuzzy finder that updates on every keystroke.
https://linrongbin16.github.io/fzfx.nvim/
MIT License
122 stars 5 forks source link

feat(previewer): improve bat theme #557

Closed linrongbin16 closed 7 months ago

linrongbin16 commented 7 months ago

The tmTheme

  1. the .tmTheme: https://www.sublimetext.com/docs/color_schemes_tmtheme.html
  2. convert tmTheme to vim:
    1. https://github.com/ku1ik/coloration/blob/eca9d85b4df41dd2399e0065714fc8715306f591/lib/coloration/writers/vim_theme_writer.rb
    2. https://gist.github.com/jojonas/fb7a26ccdaa721afa3fe
  3. convert vim syntax to tmTheme: https://stackoverflow.com/questions/28592093/converting-emacs-vim-highlighting-to-textmate-for-sublimetext
  4. sublime tmTheme:
    1. globals: https://www.sublimetext.com/docs/color_schemes.html#global-settings
    2. minimal coverage: https://www.sublimetext.com/docs/scope_naming.html#minimal-scope-coverage

Theme Implementations

  1. base16 theme:
    1. bat base16 theme: https://github.com/sharkdp/bat/blob/master/assets/themes/base16.tmTheme
    2. vim-base16: https://github.com/chriskempson/base16-vim/
    3. textmate-base16: https://github.com/chriskempson/base16-textmate/blob/master/Themes/base16-default-dark.tmTheme
  2. dracula theme:
    1. tmTheme: https://github.com/dracula/sublime/blob/09faa29057c3c39e9a45f3a51a5e262375e3bf9f/Dracula.tmTheme
    2. vim:
  3. rose-pine theme:
    1. sublime: https://github.com/rose-pine/sublime-text/blob/main/rose-pine.sublime-color-scheme
    2. vim: https://github.com/rose-pine/vim/blob/main/colors/rosepine.vim
  4. catppuccin theme:
    1. sublime: https://github.com/catppuccin/sublime-text/blob/main/Catppuccin%20Mocha.sublime-color-scheme
    2. vim: https://github.com/catppuccin/vim/blob/main/colors/catppuccin_mocha.vim

Regresion test

Platforms

Tasks

codecov[bot] commented 7 months ago

Codecov Report

Attention: 134 lines in your changes are missing coverage. Please review.

Comparison is base (e5df3c5) 77.19% compared to head (4fa4ee2) 76.23%.

Files Patch % Lines
lua/fzfx/lib/bat_themes.lua 61.95% 113 Missing :warning:
lua/fzfx/detail/bat_helpers.lua 47.05% 18 Missing :warning:
lua/fzfx/helper/previewers.lua 66.66% 2 Missing :warning:
lua/fzfx/detail/fzf_helpers.lua 66.66% 1 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #557 +/- ## ========================================== - Coverage 77.19% 76.23% -0.96% ========================================== Files 48 50 +2 Lines 5512 5850 +338 ========================================== + Hits 4255 4460 +205 - Misses 1257 1390 +133 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

linrongbin16 commented 7 months ago

The colors looks better, but not precisely enough.


update: the color looks better and better, it seems all we need to do, is trying to convert vim syntax color codes into the sublime tmTheme.

linrongbin16 commented 7 months ago

There's an issue that makes this PR works bad.

For lua keyword local, now this PR will create colors from vim highlighting Keyword to tmTheme keyword.

But treesitter will create highlighting @variable.lua and change the colors for keyword local. So the tmTheme is not working correctly on some highlightings.

see:

linrongbin16 commented 7 months ago

I feel like it's technically impossible to map neovim's highlightings to tmTheme, they seem not compatible.


update:

I find more docs, they have much better explaination on tm themes, so I will continue try again to improve the colors precision in this PR:

savchenko commented 7 months ago

Is this necessary in light of https://github.com/linrongbin16/fzfx.nvim/pull/556 ?..

Use native nVim highlights == avoid the penalty of translation to tmTheme.

linrongbin16 commented 7 months ago

Is this necessary in light of #556 ?..

Use native nVim highlights == avoid the penalty of translation to tmTheme.

yes, they are two alternative solutions to preview file contents.

The #556 should be first priority, but if I am confident that the tmTheme is mapping precisely, I may also merge this PR.

This is only for bat, #556 is for nvim buffer. They are not conflict.

The nvim buffer has best color support, while bat has best performance. If I could make the performance of #556 as good as bat, I could drop this PR.

savchenko commented 7 months ago

The https://github.com/linrongbin16/fzfx.nvim/pull/556 should be first priority, but if I am confident that the tmTheme is mapping precisely, I may also merge this PR.

That's interesting. Would it be possible to export "converted" nVIm theme to a tmTHeme file?

This way users can put the resulting file in ~/.config/bat/themes, run bat cache --build and enjoy the consistent highlighting in their favourite text editor and terminal.

linrongbin16 commented 7 months ago

The #556 should be first priority, but if I am confident that the tmTheme is mapping precisely, I may also merge this PR.

That's interesting. Would it be possible to export "converted" nVIm theme to a tmTHeme file?

This way users can put the resulting file in ~/.config/bat/themes, run bat cache --build and enjoy the consistent highlighting in their favourite text editor and terminal.

that's exactly I am doing in this PR.

but the docs about tmTheme is quite limited, and I am not an expert about tmTheme.

For now it looks 85% close to nvim highlighting.

But I improved the performance in #556 again yesterday, maybe this PR could be close.

savchenko commented 7 months ago

that's exactly I am doing in this PR. For now it looks 85% close to nvim highlighting.

This would be huge! Please keep it, at least as a function that user can call independently to generate a bat theme from their nVim colourscheme. Happy to test on my heavily modified Kanagawa theme.

linrongbin16 commented 7 months ago

Hope there's experts who knows well on both tmTheme and Neovim highlights and save me.

I will merge this into main branch now. it's so difficult to make the highlights 100% same between nvim and bat previewer.