Misterio77 / nix-colors

Modules and schemes to make theming with Nix awesome.
GNU General Public License v3.0
503 stars 42 forks source link

Add variants/target to schemes #7

Closed sagikazarmark closed 2 years ago

sagikazarmark commented 2 years ago

Hello!

Since this is the first time I'm opening an issue let me say thank you for creating this project.

I added a colorscheme to kitty first and I noticed there is a separate scheme for terminals.

I was wondering if the target audience/software could become a first class citizen in schemes.

For example: terminal emulators could use the terminal variant (if there is any) and use the primary one as a fallback.

I know this would introduce a complexity (and would make the scheme differ from base16), but I also think it would make application theming better (right now, I specified an override colorscheme for kitty to use the terminal variant).

SenchoPens commented 2 years ago

Perhaps the thing you want is templates? It's the second part of base16 standart, they are written for specific applications, frequently in multiple variations. For example, there is the kitty template with default and default-256 variants.

Also, what do you mean by 'terminal variant' of the scheme?

Misterio77 commented 2 years ago

I think he means that there exists a few colorschemes that have variants.

For example, you might have a scheme that disregards the usual 8 colors order, but you want that order maintained in a terminal. That's why you would have a terminal variant.

Misterio77 commented 2 years ago

As for the question, i think it's very very niche. I would probably use the terminal variant globally, or set a let binding some way like this:

{ config, nix-colors, ... }:
let
  colorscheme = config.colorscheme;
  terminal-colorscheme = nix-colors.colorSchemes."${config.colorscheme.slug}-terminal" or colorscheme;
in {
  colorscheme = nix-colors.colorSchemes.tokyodark;
  programs = {
    kitty = {
      enable = true;
      settings = {
        foreground = "#${terminal-colorscheme.colors.base05}";
        background = "#${terminal-colorscheme.colors.base00}";
        # ...
      };
    };
    qutebrowser = {
      enable = true;
      colors = {
        tabs.bar.bg = "#${colorscheme.colors.base00}";
        keyhint.fg = "#${colorscheme.colors.base05}";
        # ...
      };
    };
  };
}
Misterio77 commented 2 years ago

But, hmm. I think it's very specific to make this be default behaviour. There's not too many schemes that do this, and it's an implicit behaviour that might be undesirable for the users. I might add a sub scheme configuration under colorscheme

sagikazarmark commented 2 years ago

Well, I could agree that it's niche and schemes don't need builtin support. Having and example (like yours above) somewhere in the docs might be enough.

Also, combining your example with a potential theme support applications could also support overrides:

{ config, nix-colors, ... }:
let
  colorscheme = config.colorscheme;
  terminal-colorscheme = nix-colors.colorSchemes."${config.colorscheme.slug}-terminal" or colorscheme;
in {
  colorscheme = nix-colors.colorSchemes.tokyodark;
  programs = {
    kitty = {
      enable = true;
      colorscheme = {
        enable = true;
        override = terminal-colorscheme;
      };
    };
  };
}
Misterio77 commented 2 years ago

This does look cool :) I sure intend to add templates as modules soonish

sagikazarmark commented 2 years ago

This is what I use currently for application themes, but builtin support in nix-colors would be waaay better. :)

For now, I just ported some of the base16 templates to nix. I wonder if we could automatically generate them from the base16 template list though.

Misterio77 commented 2 years ago

I've thought about this in the past, but i feel the templates are kinda redundant when using nix. Most people using base16 (such as through flavours) seem to tweak them anyway, they are hard to update without breaking setups (and not updating them is not a good option either).

I kinda like how the lib functions work today, i think I might provide (custom built, not based on the existing base16 ones) templates this way.

SenchoPens commented 2 years ago

@sagikazarmark, for mustache template support (so you don't have to port the templates yourself) you can use my flake base16 library, base16.nix. It can be easily used together with nix-colors. Also, with base16.nix, templates can be tweaked, along with schemes (e.g. you can swap colors to get the terminal variant).

After adding base16.nix and kitty template repo to the flake inputs, you can use base16.nix to theme kitty with your nix-colors scheme as follows:

{ config, nix-colors, inputs, ... }:
let
  colorscheme = config.colorscheme;
  colorscheme' = inputs.base16.lib.mkSchemeAttrs (colorscheme // colorscheme.colors // { scheme = colorscheme.name; });
  terminal-colorscheme = colorscheme'.override {
    slug = "${colorscheme'.slug}-terminal";
    scheme = "${colorscheme'.scheme} terminal";
    # swap as you please
    base09 = colorscheme'.base0A;
    base0A = colorscheme'.base09;
  };
in {
  colorscheme = nix-colors.colorSchemes.tokyodark;
  programs = {
    kitty = {
      enable = true;
      extraConfig = builtins.readFile (terminal-colorscheme inputs.base16-kitty);
    };
  };
}
auroraanna commented 2 years ago

base16 color schemes are missing some of the ansi (terminal) colors though. While base16 has 8 colors that are not just grey ansi has 12. The normal ones and bright ones.

Misterio77 commented 2 years ago

Yeah, that's the niche base24 tries to fill, IIRC.

Misterio77 commented 2 years ago

I'll be closing this issue as I don't plan on adding special syntax for variants (as they're not very common).