Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

colorschemes/base16: add settings + refactor to fix #1675 #1676

Merged
merged 1 commit into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
218 changes: 139 additions & 79 deletions plugins/colorschemes/base16/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,28 @@
...
}:
with lib;
# We configure this plugin manually (no `settings` option) so there is no point in using
# `mkNeovimPlugin` here.
helpers.vim-plugin.mkVimPlugin config {
let
name = "base16";
isColorscheme = true;
luaName = "base16-colorscheme";
originalName = "base16.nvim";
in
helpers.neovim-plugin.mkNeovimPlugin config {
inherit name luaName originalName;
setup = ".with_config";
defaultPackage = pkgs.vimPlugins.base16-nvim;
isColorscheme = true;

maintainers = [ maintainers.GaetanLepage ];
maintainers = with maintainers; [
GaetanLepage
MattSturgeon
];

# We manually set the colorscheme if needed.
colorscheme = null;

# TODO introduced 2024-03-12: remove 2024-05-12
# TODO introduced 2024-03-12: remove after 24.11
imports =
let
MattSturgeon marked this conversation as resolved.
Show resolved Hide resolved
basePluginPath = [
"colorschemes"
"base16"
name
];
in
[
Expand All @@ -37,94 +40,151 @@ helpers.vim-plugin.mkVimPlugin config {
])
];

settingsExample = {
telescope_borders = true;
indentblankline = false;
dapui = false;
};

settingsOptions = {
telescope = helpers.defaultNullOpts.mkBool true ''
Whether to enable telescope integration.
'';

telescope_borders = helpers.defaultNullOpts.mkBool false ''
Whether to display borders around telescope's panel.
'';

indentblankline = helpers.defaultNullOpts.mkBool true ''
Whether to enable indentblankline integration.
'';

notify = helpers.defaultNullOpts.mkBool true ''
Whether to enable notify integration.
'';

ts_rainbow = helpers.defaultNullOpts.mkBool true ''
Whether to enable ts_rainbow integration.
'';

cmp = helpers.defaultNullOpts.mkBool true ''
Whether to enable cmp integration.
'';

illuminate = helpers.defaultNullOpts.mkBool true ''
Whether to enable illuminate integration.
'';

lsp_semantic = helpers.defaultNullOpts.mkBool true ''
Whether to enable lsp_semantic integration.
'';

mini_completion = helpers.defaultNullOpts.mkBool true ''
Whether to enable mini_completion integration.
'';

dapui = helpers.defaultNullOpts.mkBool true ''
Whether to enable dapui integration.
'';
};

extraOptions = {
colorscheme =
let
customColorschemeType = types.submodule {
options = listToAttrs (
map
(colorId: rec {
name = "base0" + colorId;
value = mkOption {
type = types.str;
description = "The value for color `${name}`.";
example = "#16161D";
};
})
[
"0"
"1"
"2"
"3"
"4"
"5"
"6"
"7"
"8"
"9"
"A"
"B"
"C"
"D"
"E"
"F"
]
);
options = mapAttrs (
name: example:
mkOption {
type = with helpers.nixvimTypes; maybeRaw str;
description = "The value for color `${name}`.";
inherit example;
}
) customColorschemeExample;
};

customColorschemeExample = {
base00 = "#16161D";
base01 = "#2c313c";
base02 = "#3e4451";
base03 = "#6c7891";
base04 = "#565c64";
base05 = "#abb2bf";
base06 = "#9a9bb3";
base07 = "#c5c8e6";
base08 = "#e06c75";
base09 = "#d19a66";
base0A = "#e5c07b";
base0B = "#98c379";
base0C = "#56b6c2";
base0D = "#0184bc";
base0E = "#c678dd";
base0F = "#a06949";
};

builtinColorschemeExamples = import ./theme-list.nix;
in
mkOption {
type = with types; either (enum (import ./theme-list.nix)) customColorschemeType;
helpers.defaultNullOpts.mkNullable' {
type = types.oneOf [
types.str
customColorschemeType
helpers.nixvimTypes.rawLua
];
pluginDefault = literalMD ''`vim.env.BASE16_THEME` or `"schemer-dark"`'';
description = ''
The base16 colorscheme to use.
It can either be the name of a builtin colorscheme or an attrs specifying each color explicitly.

Example for the latter:
You may use the name of a builtin colorscheme or an attrs that specifies the colors explicitly.

Examples of builtin themes include:
${concatStrings (
map (e: ''
- "${e}"
'') builtinColorschemeExamples
)}

`:h nvim-base16-builtin-colorschemes` includes a full list of builtin themes,
however the [plugin's source code] may be more up to date.

You can access `require('${luaName}')` as `base16` in any raw lua,
for example, you could reuse some colors from the builtin colorschemes:

```nix
{
base00 = "#16161D";
base01 = "#2c313c";
base02 = "#3e4451";
base03 = "#6c7891";
base04 = "#565c64";
base05 = "#abb2bf";
base06 = "#9a9bb3";
base07 = "#c5c8e6";
base08 = "#e06c75";
base09 = "#d19a66";
base0A = "#e5c07b";
base0B = "#98c379";
base0C = "#56b6c2";
base0D = "#0184bc";
base0E = "#c678dd";
base0F = "#a06949";
}
base03.__raw = "base16.colorschemes['catppuccin'].base06";
```

[plugin's source code]: https://github.com/RRethy/base16-nvim/blob/master/lua/colors/init.lua
'';
example = "edge-light";
example = customColorschemeExample;
};

setUpBar = mkOption {
type = types.bool;
default = true;
example = false;
description = "Whether to set your status bar theme to 'base16'.";
};
};

extraConfig =
cfg:
mkMerge [
{
plugins.airline.settings.theme = mkIf cfg.setUpBar "base16";
plugins.lualine.theme = mkIf cfg.setUpBar "base16";
plugins.lightline.colorscheme = null;

opts.termguicolors = mkDefault true;
}
(mkIf (isString cfg.colorscheme) { colorscheme = "base16-${cfg.colorscheme}"; })
(mkIf (isAttrs cfg.colorscheme) {
extraConfigLuaPre = ''
require('base16-colorscheme').setup(${helpers.toLuaObject cfg.colorscheme})
'';
})
];
# We will manually set the colorscheme, using `setup`
colorscheme = null;
callSetup = false;

extraConfig = cfg: {
plugins.airline.settings.theme = mkIf cfg.setUpBar (mkDefault name);
plugins.lualine.theme = mkIf cfg.setUpBar (mkDefault name);
plugins.lightline.colorscheme = mkDefault null;

opts.termguicolors = mkDefault true;

# `settings` can either be passed to `with_config` before calling `setup`,
# or it can be passed as `setup`'s 2nd argument.
# See https://github.com/RRethy/base16-nvim/blob/6ac181b5733518040a33017dde654059cd771b7c/lua/base16-colorscheme.lua#L107-L125
extraConfigLuaPre = ''
do
local base16 = require('${luaName}')
base16.with_config(${helpers.toLuaObject cfg.settings})
base16.setup(${helpers.toLuaObject cfg.colorscheme})
end
'';
};
}
Loading