tinted-theming / base16-emacs

Base16 themes for Emacs
MIT License
382 stars 76 forks source link

Solaire mode support #97

Open ema2159 opened 5 years ago

ema2159 commented 5 years ago

Because of the limited color palette (16 colors) Solaire mode cannot implemented in a straightforward way. I have an idea to implement it though so I wanted to see if you'd be open to receive a PR. My idea is to implement a base16-darken-color function to darken the base00 color programatically and then use that for the solaire-default face. What you think?

belak commented 5 years ago

Having a lighten and darken function is something I’ve considered for the diff functionality as well. I would accept a PR to add this.

belak commented 5 years ago

On a side note, why would it need to be darker than base00?

ema2159 commented 5 years ago

Having a lighten and darken function is something I’ve considered for the diff functionality as well. I would accept a PR to add this.

I know how to do this, but in Elisp it's a little bit harder because there's no function for converting hex to rgb, though there's a way to convert it backwards. I'll implement it as soon as I can

ema2159 commented 5 years ago

On a side note, why would it need to be darker than base00?

The principle of Solaire mode is to dim the non editing buffers to give contrast. Though sometimes in certain themes some authors do lighten instead of darken the theme (i.e. doom-iovskem) that just happens for themes that are too dark, the usual and in my personal opinion more aesthetic way to go is to darken the non editing buffers.

belak commented 5 years ago

Is there another format it could be in that would make it easier? I could change the generated templates to include the data in another format if needed.

ema2159 commented 5 years ago

Is there another format it could be in that would make it easier? I could change the generated templates to include the data in another format if needed.

I think we'd have to transform base 16 in base 18 😅. What did you have in mind?

belak commented 5 years ago

You mentioned the conversion from hex to rgb not existing in elisp - I could update the provided color variables exposed to also provide rgb values. (See http://chriskempson.com/projects/base16/#template-variables)

ema2159 commented 5 years ago

You mentioned the conversion from hex to rgb not existing in elisp - I could update the provided color variables exposed to also provide rgb values. (See http://chriskempson.com/projects/base16/#template-variables)

Ok, I think I only need the rgb value for the base00, however I don't know if it would be needed for the others in the future so you can decide. From there is just multiply the r, g and b of the base00 for a certain factor (it could be 0.5 for darkening and 1.5 for lightening, though I'd like to try some and then we can decide) and generate the new, darker version of base00 for solaire-default/any other face that needs it.

belak commented 5 years ago

After playing with it, I'd rather not go this route - https://github.com/belak/base16-emacs/tree/rgb-experiment

It's pretty ugly and introduces data duplication. Unfortunately, I think it would make more sense to have functions for converting from rgb to hex and back..

ema2159 commented 5 years ago

Yes , the latter one already exist (no clue why the function for converting from hex to rgb doen't exist but from rgb to hex does) so let's start from there. I should go like this, take for example the following hex color: #ABCD12, the RGB would be (AB, CD, 12) converted to decimal if I'm not wrong.

belak commented 5 years ago

Right, so (171, 205, 18)

ema2159 commented 5 years ago
(defun base16-hex-to-rgb (hexcolor)
  `(,(string-to-number (substring hexcolor 1 3) 16)
    ,(string-to-number (substring hexcolor 3 5) 16)
    ,(string-to-number (substring hexcolor 5 7) 16)))

There ya go, it was easier than expected. When using"#191970" as the argument it returns (25 25 112) as expected

I think that I'll be finishing all the implementation of the darken/lighting functions and solaire-mode tomorrow maybe at the end of the morning.

belak commented 5 years ago

I pushed the functions to a branch called color-darken if you want to play with it a bit more.

neeasade commented 4 years ago

necrobump! I've been playing much with emacs builtin color.el this past week and would like to share some stuff I found.

@ema2159 I learned that emacs ships with conversion functions for hex and rgb (though it uses 0.0 - 1.0 instead of 0-{FF or FFFF}), and some helper functions for lightening and darkening colors. EG:

(require 'color)

(color-name-to-rgb "#999999")
;; => (0.6 0.6 0.6)

;; darken and lighten take percents:
(color-darken-name "#999999" 5)
;; => "#8ccc8ccc8ccc"

(color-lighten-name "#999999" 5)
;; => "#a665a665a665"

;; convert a color to RGB , add some blue, convert it back:
(->> (color-name-to-rgb "#999999")
  (apply (lambda (R G B)
           ;; RGB are all in a 0.0-1.0 range
           (list R G (+ 0.2 B))))
  (apply 'color-rgb-to-hex))
;; => "#99999999cccc"

I'm not sure what the minimum emacs version is for color.el, the copyright is 2010. It's got some other helpers for working with other colorspaces as well (HSL/HSV, LAB/LCH).

On top of these I built some helpers (feel free to steal) for comparing colors and "tweaking" them in different colorspaces while I tried things, which is currently culminating on a bootstrap using the base16 builder (thanks for your awesome work/wide package coverage, @belak)

Of interest to the base16 repo might be the contrast comparison stuff (ns/color-contrast-ratio, ns/color-iterate) - you could then EG enforce a minimum contrast between colors.

ema2159 commented 4 years ago

@neeasade hey! Thanks! Yeah, I discovered these a little bit too late. They should do the work, however, I'm not sure if this PR will still be accepted though. I think the best thing to do is to redo it. I was quite inexperienced with elisp back then (still am, but a little bit less).