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 3 new themes: ansi-light, ansi-dark, base16 #543

Merged
merged 1 commit into from
May 8, 2019
Merged

Conversation

mk12
Copy link
Contributor

@mk12 mk12 commented Apr 13, 2019

Fixes #490

To summarize that issue: some people change their color theme often, perhaps switching between a light theme and dark theme. In these cases, no single bat theme works well. In addition, some people really want colored output to be congruous with the rest of their terminal programs, and don't care so much about it using a wide range of colors. In both cases, a solution is to use the 8- or 16-ANSI color palette the user has already configured for their terminal. The key difference is the added level of indirection: instead of choosing colors, we choose palette numbers and the user chooses colors.

This PR adds three new themes. They are based on the base16 textmate theme, but modified to encode the 16 palette numbers as RGB colours "#000000" through "#0f0000". This is necessary because tmTheme/Syntect require concrete RGB colors. It's might seem slightly hacky, but I don't think it's worth generalizing Syntect to other notions of color just so we can pass it the number 10 instead of the string "#0a0000".

Here's how the themes should be used:

  • ansi-light: This should look decent in any terminal with a light background. It uses only the first 8 colors from the ANSI palette.
  • ansi-dark: Like ansi-light, but for dark backgrounds. These two themes need to be separate so that we use the right foreground color for ordinary text.
  • base16: This will look perfect for anyone using a theme designed around the base16 palette. We don't need a light and dark version because base16 themes always have background/foreground in fixed slots.

Note, I just put the new theme files in assets/themes for now. It works if I build the cache from that directory. The README seems to say I'm not supposed to check in the new binary files with my PR, however.

Screenshots

I ran bat --list-themes on three color themes for macOS Terminal.app.

Default light profile:

ansi-light

Dark profile:

ansi-dark

Base16 Ocean profile:

base16-ocean

In general, the base16 ones might look ok for non-base16 profiles, or it might look terrible. It depends on how the upper 8 of the 16 colors are configured. The ansi themes work on anything, but for base16 profiles the base16 theme will look better (thought it might be hard to tell in the above screenshot).

@sharkdp
Copy link
Owner

sharkdp commented Apr 14, 2019

Thank you very much, this looks really great! It will take me a few days before I can properly review this, as I'm currently on vacation.

@mk12
Copy link
Contributor Author

mk12 commented Apr 14, 2019

Just updated the theme files after realizing the gutter settings were specified incorrectly.

One thing that just occurred to me: since I'm enabling ColorMode::Base16Encoded based on the name of the theme, this could cause undesirable behaviour if the user decides to make their own theme called ansi-light/ansi-dark/base16. I think a nicer solution would be to make the encoding a key in the XML file.

@trishume
Copy link

Author of syntect here, I approve of this method of doing ANSI themes with syntect.

One idea I thought of and posted in the associated issue is to use the alpha channel to select between rendering as ansi and rendering as RGB. It's possible to specify the alpha channel in TextMate themes using longer hex codes, and an alpha of zero (transparent) could be used as a special signifier of an ANSI color.

@sharkdp
Copy link
Owner

sharkdp commented Apr 25, 2019

@trishume Thank you for the feedback! It's still a "hack", but that sounds like a reasonable option to me. @mk12 what do you think?

@mk12
Copy link
Contributor Author

mk12 commented Apr 27, 2019

Yes, I think I'll try doing it with the alpha channel instead.

Advantages:

  • Much smaller change to the codebase (just a few lines in to_ansi_color).
  • Setting is per colour rather than per theme so it's more flexible.
  • No terminal that I know of has escapes for transparency, so no one should be using it anyway.
  • No issue with people making their own theme named "ansi" or "base16".

Also, interpret transparent colors (#RRGGBB00) as specifying a terminal
color palette number with RR. The three new themes use this.
@mk12
Copy link
Contributor Author

mk12 commented Apr 27, 2019

I've pushed the new, much simpler changes. The old version is in the old-ansi branch of my fork if you want to compare.

Again, I'm not sure how you're supposed to add a built-in theme to the repository's themes.bin so I'll leave that to you.

@sharkdp
Copy link
Owner

sharkdp commented May 8, 2019

Very cool, thank you for the new implementation!

Again, I'm not sure how you're supposed to add a built-in theme to the repository's themes.bin so I'll leave that to you.

I will do that when I release the next version.

@sharkdp sharkdp merged commit bb6594e into sharkdp:master May 8, 2019
@ariasuni
Copy link

Thanks a lot, that’s perfect!

dandavison added a commit to dandavison/delta that referenced this pull request Dec 12, 2019
dandavison added a commit to dandavison/delta that referenced this pull request Dec 13, 2019
elasticdog added a commit to elasticdog/dotfiles that referenced this pull request Jan 12, 2020
This will automatically adjust to whatever has been defined in my
terminal color scheme.

See:
- sharkdp/bat#543
@mk12 mk12 deleted the ansi branch May 2, 2020 17:26
@mk12 mk12 mentioned this pull request Jul 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a theme that uses terminal colors
4 participants