base16-emacs
base16-emacs copied to clipboard
Add support for :darken color modifier
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.
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.
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
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.
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.
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
.
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.
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.