sharkdp / bat

A cat(1) clone with wings.
Apache License 2.0
47.59k stars 1.18k forks source link

Support Font Ligatures #2972

Closed StephanieSunshine closed 4 weeks ago

StephanieSunshine commented 1 month ago

Hi, I'm trying to find a cat clone for macos that supports font ligatures. I am trying to use the Victor Mono Nerd Font and I can see my ligatures working in Neovim, bat seems to not be showing them. Is there some switch I'm possibly missing? Thanks!

keith-hall commented 1 month ago

Hi, a couple of things to try:

StephanieSunshine commented 1 month ago

MacOS:

With Iterm2: /usr/bin/less no ligatures, no syntax highlighting /usr/bin/bat --paging=never no ligatures, yes syntax highlighting nvim I see ligatures, yes syntax highlighting

With Tabby.sh: /usr/bin/less no ligatures, no syntax highlighting /usr/bin/bat --paging=never no ligatures, yes syntax highlighting nvim I see ligatures, yes syntax highlighting

With all of these tests I was using a simple go file that I will try to include in this response. Doing the same tests again with a python script instead of golang source code resolves with the exact same result.

Code used: https://github.com/StephanieSunshine/shaspider/blob/main/main.go https://github.com/StephanieSunshine/py-pascals-triangle/blob/main/triangle.py

Font Used: https://rubjo.github.io/victor-mono/

Thanks

keith-hall commented 1 month ago

Thanks for the update. Honestly I know very little about terminal emulators and font ligatures. But one thing I realize I forgot to ask is: Does plain cat show ligatures? Because if not, then perhaps Neovim is doing something special to render them? I admit that I was working on an assumption that cat shows them. Also, probably this is a silly question, so please forgive me - are ligatures enabled in your iterm2 preferences? https://iterm2.com/documentation-fonts.html

If I ever get some spare time at the computer, I can try on Linux with a few terminal emulators also... 🙂

StephanieSunshine commented 1 month ago

To answer your questions, Iterm2 and Tabby both have font ligatures on in their settings. Cat doesn't work, which is why I was interested in bat possibly doing it as an alternative, as I was already using it as an alternative to cat on my laptop.

Screenshot 2024-06-01 at 1 50 44 AM Screenshot 2024-06-01 at 1 51 47 AM

.config/nvim/init.vim

call plug#begin()

" TailwindCSS vim improvements
Plug 'neovim/nvim-lspconfig'
Plug 'kabouzeid/nvim-lspinstall'

call plug#end()
set termguicolors
set background="dark"
colorscheme elflord
syntax on
set clipboard+=unnamedplus
nmap <C-N><C-N> :set invnumber<CR>
set tabstop=2
set expandtab
set shiftwidth=2
set autoindent
set smartindent
set number
filetype plugin indent on
highlight Comment cterm=italic gui=italic

That last line makes me wonder if I have been focusing too much on the comments changing and not the rest of the ligatures. I tested some of the other ligatures within Neovim and they were indeed working.

Screenshot 2024-06-01 at 2 02 36 AM

It turns out that bat is actually showing ligatures, but not the Victor Mono italic cursive italics, which I miss understood as ligatures too. I believe you can close this unless you have some way to make the highlight Comment cterm=italic gui=italic work with bat. Thanks for your help.

Screenshot 2024-06-01 at 2 05 31 AM
keith-hall commented 1 month ago

it may be possible by getting your theme to style comments as italic. For example, if you are using the default theme, then adding

<key>fontStyle</key>
<string>italic</string>

to the "settings" dict in https://github.com/jonschlinkert/sublime-monokai-extended/blob/0ca4e75291515c4d47e2d455e598e03e0dc53745/Monokai%20Extended.tmTheme#L63-L72

and following the instructions at https://github.com/sharkdp/bat?tab=readme-ov-file#adding-new-themes to use your customized theme, might be worth a try

StephanieSunshine commented 4 weeks ago

I tried what you suggested. I took the GitHub built in theme, cloned it from the bat repo into the custom themes folder, and edited the file. I can seem to make fontStyle bold work, but not italic. I checked Tabby and Iterm2, both are responding to bold as a fontStyle, both are ignoring italic. Line 44 is roughly where my changes are in the attached file. Is there something else I'm missing here? I checked out the Sublime documentation for tmThemes and it collaborates your suggestion. I checked both Golang and Python

      <dict>
          <key>name</key>
          <string>Comments</string>
          <key>scope</key>
          <string>comment</string>
          <key>settings</key>
          <dict>
              <key>foreground</key>
              <string>#969896</string>
              <key>fontStyle</key>
              <string>italic</string>
            </dict>
      </dict>

VictorMono.tmTheme.txt

keith-hall commented 4 weeks ago

Hmm, I have a vague recollection that bat might be disabling italic support by default because many terminal emulators don't support it. Apologies for not thinking of it sooner. Try running bat with --italic-text=always

StephanieSunshine commented 4 weeks ago

That did it thanks! I had just installed Sublime Text and managed to make it work there.

Here is the modified theme to add italics to comments: https://gist.github.com/StephanieSunshine/3986984473a9c14767ea6db4ae0389f7

Screenshot 2024-06-01 at 7 12 12 AM