Skip to content

Commit

Permalink
Better color interpolation when base16-shell is in use
Browse files Browse the repository at this point in the history
If your termshark theme expresses its colors in RGB
format (e.g. #aa55bc), and termshark is running in a 256-color
terminal (without COLORTERM=truecolor set), then termshark will try to
find the closest matching color in the 256-color space. If you are using
base16-shell (https://github.com/chriskempson/base16-shell), then your
base16-shell theme likely has remapped colors 0-21 out of the terminal's
256-color space. Termshark doesn't know this, and assumes colors 0-21
are "normal". This can result in it interpolating a poor match for the
theme's desired RGB color.

If you set main.ignore-base16-colors = true in termshark.toml, then
termshark will ignore colors 0-21 when selecting the best match for RGB
colors used in a theme. For example, this would mean black - RGB #000000
- would map to color 232 in the 256-color
space (https://jonasjacek.github.io/colors/). If the toml variable is
not set, then termshark will try to guess whether or not to ignore
colors 0-21 by checking for the env var BASE16_SHELL - if present, it
will ignore those colors, assuming they have been remapped.

Note that this does not affect termshark's base16 theme itself, because
its colors are expressed using a syntax that translates directly to the
256-color space.

Complicated... :-/
  • Loading branch information
gcla committed Oct 29, 2020
1 parent 8cbd582 commit 1c91cf1
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions cmd/termshark/termshark.go
Original file line number Diff line number Diff line change
Expand Up @@ -1031,6 +1031,24 @@ Loop:
}
}

// If you are using base16-shell, the lowest colors 0-21 in the 256 color space
// will be remapped to whatever colors the terminal base16 theme sets up. If you
// are using a termshark theme that expresses colors in RGB style (#7799AA), and
// termshark is running in a 256-color terminal, then termshark will find the closest
// match for the RGB color in the 256 color-space. But termshark assumes that colors
// 0-21 are set up normally, and not remapped. If the closest match is one of those
// colors, then the theme won't look as expected. A workaround is to tell
// gowid not to use colors 0-21 when finding the closest match.
if termshark.ConfKeyExists("main.ignore-base16-colors") {
gowid.IgnoreBase16 = termshark.ConfBool("main.ignore-base16-colors", false)
} else {
// Try to auto-detect whether or not base16-shell is installed and in-use
gowid.IgnoreBase16 = (os.Getenv("BASE16_SHELL") != "")
}
if gowid.IgnoreBase16 {
log.Infof("Will not consider colors 0-21 from the terminal 256-color-space when interpolating theme colors")
}

// This needs to run after the toml config file is loaded.
ui.SetupColors()

Expand Down

0 comments on commit 1c91cf1

Please # to comment.