jcaw / theme-magic

🎨 Apply your Emacs theme to the rest of Linux, using magic. Also works on Mac.
GNU General Public License v3.0
139 stars 4 forks source link

Exported themes don't reflect the dominant colors of the Emacs theme #3

Closed jcaw closed 5 years ago

jcaw commented 5 years ago

(Visual examples included below - they may be easier to understand)

Problem

Most themes that set ANSI colors use the standard color order:

  1. Black
  2. Red
  3. Green
  4. Yellow
  5. Blue
  6. Purple
  7. Cyan
  8. White

Meaning they will set ANSI color 0 to black, 1 to red, 2 to green, 4 to blue, etc. Almost all themes use this ordering. This means the ANSI colors don't reflect any kind of color dominance. If the Emacs theme uses purple as its dominant color, the ordering of the ANSI colors will not reflect this.

This means the exported theme will not look cohesive for some themes. Two problems become obvious:

  1. Shell tools tend to use certain ANSI colors (such as blue and cyan) more than others. This means exported themes tend to always look blue/cyan.
  2. Themes that use a restricted part of the color wheel, e.g. a theme that uses many shades of blue, will lose their look when exported. The exported theme won't be restricted to different shades of blue.

Examples

This behaviour works well for some themes, such as zenburn:

theme-magic-zenburn-example

However, it doesn't work for others. spacemacs-dark is designed to use purple as its dominant color - this look is lost when it's exported - everything becomes blue and cyan.

theme-magic-spacemacs-dark-example

Some themes use non-standard ANSI colors, presumably to get around this problem. These tend to look good. For example, creamsody:

theme-magic-creamsody-example

Some themes look awful. This is cherry-blossom:

theme-magic-cherry-blossom-example

Solution

Ideally, the exported theme should somehow reflect the dominant colors of the Emacs theme. If the theme is mainly purple, purple should be dominant. If the theme is monocolor, the different gradients should be reflected instead of just the named ANSI colors.

The obvious solution would be to re-order the colors. Instead of exporting colors in the standard ANSI order, theme-magic should place the dominant colors in the most-used slots. For example, the spacemacs-dark theme should put purple in the blue or cyan slot, since it's used the most.

A heuristic would need to be developed that could do this.

jcaw commented 5 years ago

It may be possible to solve this issue in tandem with #4

The original version of theme-magic tried to extract its colors from the current Emacs faces. It would iterate through them, extract the colors, and create a theme. This was prone to failure, because different themes use different color standards for each face. For example, it would fail on monokai and output a theme with only 4 colors.

I developed a heuristic to get around this (basically: try many different faces until we get a vibrant palette), but never finished implementing it because the ANSI approach was so much simpler. It may be possible to revive this approach and combine it with the ANSI method (or provide it as an optional fallback).

jcaw commented 5 years ago

Working on this and #4 on branch reimplementing_font_extraction