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

Add a theme that uses terminal colors #490

Closed
ariasuni opened this issue Jan 31, 2019 · 23 comments · Fixed by #543
Closed

Add a theme that uses terminal colors #490

ariasuni opened this issue Jan 31, 2019 · 23 comments · Fixed by #543
Labels
help wanted Extra attention is needed question Further information is requested themes

Comments

@ariasuni
Copy link

I spent a lot of time to customize my terminal named colors, and I wish there was a bat theme that uses them so it doesn’t look bad in my terminal.

The benefit is that it provides a backup theme that works across terminals if no other theme works with the terminal theme.

@sharkdp
Copy link
Owner

sharkdp commented Feb 4, 2019

Thank you for the feedback - interesting idea.

Unfortunately, highlighting themes typically need to define more than the 8 basic ANSI colors, so this would really just be a subpar fallback solution. It's also unclear to me if this could be implemented with a reasonable effort. I currently can't think of a good way to make this work with the current Sublime-Syntax theme infrastructure.

@sharkdp sharkdp added question Further information is requested themes labels Feb 4, 2019
@Trucido
Copy link

Trucido commented Feb 25, 2019

Not sure how the sublime-syntax stuff works but I think some themes do exist which only define 8 colors (technically 16) such as possibly the Base​16 Color Schemes (Unconfirmed, I haven't looked into this yet but I know most of the base16 shell themes come in 16 or 256 variants.)

Other than that, when bat fails me I've been piping through pygmentize -g
I've been meaning to look into this for my windows build, since powershell/pwsh acts weird sometimes with crazy colors.

@wbolster
Copy link

wbolster commented Mar 29, 2019

i regularly switch my terminal (and gnome and emacs) themes between a dark and a light version, depending on the light circumstances (e.g. dark or sunny environment) to avoid eye strain.

unfortunately none of the built-in bat themes are readable on both backgrounds, which basically renders bat output useless roughly half of the time.

i have settled on solarized dark/light for a long time, but this issue is not specific to these (yellowish and dark blue) background colours.

i would love to see only the basic 8 (?) colour terminal palette as one of of the themes, since those are extremely legible on both backgrounds (it's one of the design goals of the solarized palette).

here are two screenshots to illustrate the problem.
image

image

@sharkdp
Copy link
Owner

sharkdp commented Apr 4, 2019

I see the need, but I really don't know how that would be implemented with Sublime Text Themes, which are used by bat.

@sharkdp sharkdp added the help wanted Extra attention is needed label Apr 4, 2019
@wbolster
Copy link

wbolster commented Apr 4, 2019

perhaps the colours can be "rounded" to the nearest ansi color?

@sharkdp
Copy link
Owner

sharkdp commented Apr 7, 2019

You can round a 24-bit ANSI color to the nearest 8-bit ANSI color (we actually do this in bat if the terminal does not support truecolor, see to_ansi_color in src/terminal.rs). But how would you round to 16 base colors? We don't know how these look like because they are user-configured.

@wbolster
Copy link

wbolster commented Apr 7, 2019

well i guess just rounding to bright red green blue cyan magenta yellow (6 extreme colours, "#ff0000") and "base" would work.

@trapd00r
Copy link

trapd00r commented Apr 7, 2019

Keep in mind that all 256 colors are (in most cases) user configurable.

@zackhsi
Copy link

zackhsi commented Apr 7, 2019

And adding to the above, many of today's color schemes support true color, 256, and 16. For example, onedark.vim has a configurable named g:onedark_termcolors:

set to 16 to use your terminal emulator's native 16 colors

@sharkdp
Copy link
Owner

sharkdp commented Apr 8, 2019

well i guess just rounding to bright red green blue cyan magenta yellow (6 extreme colours, "#ff0000") and "base" would work.

Okay. That could be worth a try.

Keep in mind that all 256 colors are (in most cases) user configurable.

Oh dear, I didn't know this was possible.

And adding to the above, many of today's color schemes support true color, 256, and 16. For example, onedark.vim has a configurable named g:onedark_termcolors:

Yes. But that doesn't really help, right? The user would have to set these in the terminal emulator. bat has no control over that.

@zackhsi
Copy link

zackhsi commented Apr 8, 2019

Yes. But that doesn't really help, right? The user would have to set these in the terminal emulator. bat has no control over that.

bat would emit the proper ansi color codes (e.g. for red, magenta, green), and the terminal would color them however the user configured. One's person's red can differ from another person's red, and bat could happily support both of them by using standard color codes.

@trapd00r
Copy link

trapd00r commented Apr 9, 2019

Oh dear, I didn't know this was possible.

Put this in your shellrc ;)

for i in {0..255}; do printf "\033]4;$i;rgb:ff/00/00\033\\"; done
_redefine

@LandonSchropp
Copy link

I'd love to see this as well. I use a custom color theme in my personal terminal that I've already carefully configured. It would be great if bat could pick that up and run with it. I have 24-bit colors enabled, but even if I pick a theme, it's not going to match my color scheme.

@mk12
Copy link
Contributor

mk12 commented Apr 11, 2019

I'm working on adding support for base16 themes using the 16 ANSI colours. I should have a pull request ready tomorrow. I might also try adding a very basic 8-color theme that should look decent on any terminal emulator with the 8 colours being roughly similar to their names (0=black, 1=red, 2=green, etc.)

@LandonSchropp
Copy link

@mk12 Awesome!

@trishume
Copy link

As the author of syntect, which does the highlighting for bat, my recommendation is to implement it using a special case where colors with an alpha value of 0 and a red value between 0 and 16 get their color rendered as the ANSI color corresponding to the red value.

It's somewhat of a hack, but the TextMate-theme specific logic in syntect has a bunch of optimizations that would be annoying to replicate in a custom highlighting pipeline. It also allows bat to re-use its existing system for custom themes, and shouldn't be too hard to implement.

@sharkdp
Copy link
Owner

sharkdp commented May 15, 2019

The new themes by @mk12 are now included in v0.11.0.

@cben
Copy link

cben commented Jun 19, 2019

Is it just me, or none of the new 3 themes deliver on the Solarized promise of single theme working well with light & dark bg?

(this is gnome-terminal with I think built-in Solarized colors)
base16 is similar to ansi-dark in having some text bright grey that's unredable on bright bg.
(TwoDark that you see at the top actually remains one of the better ones under both)

I'll try to work on a 4th theme that works wells on Solarized light & dark, unless anyone wants to beat me.

@bricewge
Copy link
Contributor

I can confirm that those bat themes doesn't work well with a terminal using solarized colors.

Unfortunately it's seems to me that the issue is not specific to bat but come from a deeper incompatibility between base16 architecture themes and solarized theme on how the 16 colors ought to be used, especially the monotones ones. base16 think of colors 0 to 7 as a darkening shade for dark themes and a lightening shade for light ones. solarized on the other hand use the same darkening shade for both theme but exclude 3 colors from the shade in a symmetricly manner to mark the difference between the dark and light variant (see 4. Precision, symmetry).

Using https://github.com/paulcpederson/solarized-sublime.git with bat works great though.

@cben
Copy link

cben commented Jun 19, 2019

Huh. Something I never realized before is that when I flip the terminal between "solarized dark" and "solarized light", only chars styled with default foreground and background change; but the palette remains assigned to colors 0–15 colors in a fixed, non-inverting manner:

solarized-flip

This seems in-line with https://github.com/altercation/solarized#the-values intent.
IIUC the idea was that the palette supports easy inversion but applications have to use it in 2 ways.
This is also consistent with terminals having sort-of fixed meanings for colors 0 (black) – 7 (white).

However it's NOT what I was hoping for 😉 I really want to flip the terminal theme and have existing output re-styled.
I'll try to research whether any terminal solarized themes flip the neutral colors like that?

Another option is a theme that only uses default fg + the 8 accent colors, but not the neutral tones. Actually can add one "middle" tone too, especially for low-attention things like line numbers.

@mk12
Copy link
Contributor

mk12 commented Jun 19, 2019

@cben If you want to flip between solarized light and solarized dark, I recommend using the base16 versions of the solarized themes for your terminal (for the Gnome terminal, that's https://github.com/aaron-williamson/base16-gnome-terminal), and then using the base16 bat theme I created.

Making a bat theme that works well flipping between light and dark -- that is, a single ansi theme instead of ansi-light and ansi-dark -- is not possible because typical terminal themes use fixed slots for "black-ish" and "white-ish," not "foreground" and "background." This is the problem that base16 solves.

@cben
Copy link

cben commented Jul 15, 2019

typical terminal themes use fixed slots for "black-ish" and "white-ish," not "foreground" and "background." This is the problem that base16 solves.

Thanks for this clear explanation, now I finally got the point of base16.

Concrete tips for benefit of others new to this:

  • ✔️ Configure in ~/.config/bat/config:

    # works with both dark and light terminal themes from https://github.com/chriskempson/base16
    --theme=base16
    --italic-text=always
    

    (italic never hurts imho, though mk12's base16 theme only uses it in markdown, latex etc). Then forget about it.

  • 👩‍💻 Find a repo for your terminal (or other software) among https://github.com/chriskempson/base16#template-repositories

    • 😻 🌈 It's not always obvious from READMEs of these repos, but each one contains the whole gazillion of themes.
      For example base16-xfce4-terminal has a colorschemes/ directory, and base16-tilix has a tilix/ directory...
    • 🛒 For programs with built-in ability to define theme, the installation instructions will add all or selected themes there (e.g. for gnome-terminal, run color-scripts/base16-solarized-dark.sh AND color-scripts/base16-solarized-light.sh to define these themes. Or whatever pair(s) you like...
    • 🔧 For other programs, the instruction tell you how to set one theme, which you need to repeat (or automate) each time you switch...
  • 🏁 Solarized is not unique! Almost all base16 themes have dark and light variants (some more than 2!) — not always exactly same colors but usually close enough to mix light/dark at same time and feel "same theme".

  • 🐚 For many terminals, instead of using terminal's native config, you can use https://github.com/chriskempson/base16-shell to reprogram colors 0–21 at run time.

  • 🔀 For software like Vim and Emacs that runs both as GUI and in terminal, you may have choice between the software's own theming and directly using terminal's colors relying on terminal's theming.

    • ⏩ Emacs base16-theme package defaults base16-theme-256-color-source to terminal.

@sharkdp
Copy link
Owner

sharkdp commented Jul 16, 2019

(italic never hurts imho, though mk12's base16 theme only uses it in markdown, latex etc). Then forget about it.

Italic does hurt in some terminal emulators. It also does not work in tmux. This is why it is disabled by default.

atweiden added a commit to atweiden/macfiles that referenced this issue Aug 29, 2020
atweiden added a commit to atweiden/pacfiles that referenced this issue Aug 29, 2020
atweiden added a commit to atweiden/ttyfiles that referenced this issue Aug 29, 2020
atweiden added a commit to atweiden/voidfiles that referenced this issue Aug 29, 2020
atweiden added a commit to atweiden/macfiles that referenced this issue Aug 29, 2020
atweiden added a commit to atweiden/pacfiles that referenced this issue Aug 29, 2020
atweiden added a commit to atweiden/ttyfiles that referenced this issue Aug 29, 2020
atweiden added a commit to atweiden/voidfiles that referenced this issue Aug 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed question Further information is requested themes
Projects
None yet
Development

Successfully merging a pull request may close this issue.