Skip to content

Commit

Permalink
modules: add base16 Theming support
Browse files Browse the repository at this point in the history
theme/theme.nix: fix formatting

supported-themes.nix: formatting

clean up base16-colors.nix

theme: fix plugin setup, change base16 flake input
  • Loading branch information
bloxx12 committed Oct 4, 2024
1 parent c727528 commit e80dedd
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 6 deletions.
17 changes: 17 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,11 @@
};

# Themes
plugin-base16 = {
url = "github:rrethy/base16-nvim";
flake = false;
};

plugin-tokyonight = {
url = "github:folke/tokyonight.nvim";
flake = false;
Expand Down
2 changes: 2 additions & 0 deletions lib/types/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
typesPlugin = import ./plugins.nix {inherit inputs lib;};
typesLanguage = import ./languages.nix {inherit lib;};
typesCustom = import ./custom.nix {inherit lib;};
typesTheme = import ./theme.nix {inherit lib;};
in {
inherit (typesDag) dagOf;
inherit (typesPlugin) pluginsOpt extraPluginType mkPluginSetupOption luaInline pluginType borderType;
inherit (typesLanguage) diagnostics mkGrammarOption;
inherit (typesCustom) anythingConcatLists char;
inherit (typesTheme) hexColorType;
}
13 changes: 13 additions & 0 deletions lib/types/theme.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{lib}: let
inherit (lib.strings) isString hasPrefix;
inherit (lib.types) mkOptionType;
inherit (builtins) stringLength;
# This was almost entirely taken from raf himself.
in {
hexColorType = mkOptionType {
name = "hex-color";
descriptionClass = "noun";
description = "RGB color in hex format";
check = x: isString x && hasPrefix "#" x && stringLength x == 7;
};
}
69 changes: 69 additions & 0 deletions modules/plugins/theme/base16-colors.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{lib}: let
inherit (lib.options) mkOption;
inherit (lib.nvim.types) hexColorType;
in {
base00 = mkOption {
type = hexColorType;
default = "#1e1e2e";
};
base01 = mkOption {
type = hexColorType;
default = "#181825";
};
base02 = mkOption {
type = hexColorType;
default = "#313244";
};
base03 = mkOption {
type = hexColorType;
default = "#45475a";
};
base04 = mkOption {
type = hexColorType;
default = "#585b70";
};
base05 = mkOption {
type = hexColorType;
default = "#cdd6f4";
};
base06 = mkOption {
type = hexColorType;
default = "#f5e0dc";
};
base07 = mkOption {
type = hexColorType;
default = "#b4befe";
};
base08 = mkOption {
type = hexColorType;
default = "#f38ba8";
};
base09 = mkOption {
type = hexColorType;
default = "#fab387";
};
base0A = mkOption {
type = hexColorType;
default = "#a6e3a1";
};
base0B = mkOption {
type = hexColorType;
default = "#94e2d5";
};
base0C = mkOption {
type = hexColorType;
default = "#a6e3a1";
};
base0D = mkOption {
type = hexColorType;
default = "#89b4fa";
};
base0E = mkOption {
type = hexColorType;
default = "#cba6f4";
};
base0F = mkOption {
type = hexColorType;
default = "#f2cdcd";
};
}
10 changes: 10 additions & 0 deletions modules/plugins/theme/supported-themes.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,15 @@
}: let
inherit (lib.strings) optionalString;
inherit (lib.trivial) boolToString warnIf;
inherit (lib.nvim.lua) toLuaObject;
cfg = config.vim.theme;
in {
base16 = {
setup = {base16-colors, ...}: ''
-- Base-16 theme
require('base16-colorscheme').setup(${toLuaObject cfg.base16-colors})
'';
};
onedark = {
setup = {style ? "dark", ...}: ''
-- OneDark theme
Expand All @@ -20,6 +28,7 @@ in {
setup = {
style ? "night",
transparent,
...
}: ''
require('tokyonight').setup {
transparent = ${boolToString transparent};
Expand All @@ -42,6 +51,7 @@ in {
setup = {
style ? "mocha",
transparent ? false,
...
}: ''
-- Catppuccin theme
require('catppuccin').setup {
Expand Down
16 changes: 10 additions & 6 deletions modules/plugins/theme/theme.nix
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@
supportedThemes = import ./supported-themes.nix {
inherit lib config;
};
base16-colors = import ./base16-colors.nix {
inherit lib;
};
in {
options.vim.theme = {
enable = mkOption {
type = bool;
description = "Enable theming";
};

inherit base16-colors;
name = mkOption {
type = enum (attrNames supportedThemes);
description = "Supported themes can be found in `supportedThemes.nix`";
Expand All @@ -29,7 +32,6 @@ in {
type = enum supportedThemes.${cfg.name}.styles;
description = "Specific style for theme if it supports it";
};

transparent = mkOption {
type = bool;
default = false;
Expand All @@ -45,10 +47,12 @@ in {
config = mkIf cfg.enable {
vim = {
startPlugins = [cfg.name];
luaConfigRC.theme = entryBefore ["pluginConfigs"] ''
${cfg.extraConfig}
${supportedThemes.${cfg.name}.setup {inherit (cfg) style transparent;}}
'';
luaConfigRC = {
theme = entryBefore ["pluginConfigs"] ''
${cfg.extraConfig}
${supportedThemes.${cfg.name}.setup {inherit (cfg) style transparent base16-colors;}}
'';
};
};
};
}

0 comments on commit e80dedd

Please sign in to comment.