base16-emacs icon indicating copy to clipboard operation
base16-emacs copied to clipboard

Add support for :darken color modifier

Open belak opened this issue 5 years ago • 8 comments

belak avatar Jul 15 '19 21:07 belak

Why don't use color-darken-name in the color package? Also is it possible to make a generic transformer? I use color-saturate-name as well.

kurnevsky avatar Jul 15 '19 21:07 kurnevsky

I didn't realize color-darken-name worked properly - when I looked before I thought it assumed #ffff0000ffff format, but it looks like it would work with the usual hex codes. Good feedback.

belak avatar Jul 15 '19 21:07 belak

Also take a note that color package won't work in the terminal before some tty initialization which happens after init file is loaded. I had to use tty-setup-hook to make it convert colors properly: https://github.com/kurnevsky/dotfiles/blob/c8a350540e99b8fec67dfc92bf59030fb51d7701/.emacs.d/init.el#L263-L266

kurnevsky avatar Jul 15 '19 21:07 kurnevsky

I've played with it a bit to make this more generic (and provide :darken, :lighten, and :saturate), but it's pretty ugly. I'd be open to tips here.

belak avatar Jul 15 '19 22:07 belak

In my implementation, I simply only call the color functions for strings starting with #. This makes it only operate on html colors which should be good enough. I don't see anything in the color module which is run after tty init - everything I can see is simple conversions, so I'm not really sure what you're running into.

belak avatar Jul 16 '19 00:07 belak

Try to add this into your init.el:

(require 'color)
(print (color-darken-name "#121212" 0.5))

And execute emacs --no-window-system. It'll print #000000000000.

kurnevsky avatar Jul 16 '19 07:07 kurnevsky

Wow, that's really annoying. It tries to determine how that color will display in the current frame. The odd thing is that it handles colors like "white" and "black" properly, but can't understand hex codes until there's a frame available. This is actually an issue with (color-values #121212) which seems to be emacs internal.

It's looking like we can't use these color functions for converting unless we want to force waiting until frame-init.

belak avatar Jul 16 '19 17:07 belak

color-***-name functions use color-***-hsl internally which should be working during init.el loading. So we can use color-rgb-to-hsl + hsl functions. The only thing that should be done manually is color string parsing.

kurnevsky avatar Jul 16 '19 19:07 kurnevsky