tokyonight: Fix configuration and align more with defaults (#87)

The global variables don't work for applying configuration, we need to
switch to using the 'setup' function. This also aligns the default
option values in tokyonight upstream.
This commit is contained in:
traxys 2022-12-24 01:08:54 +01:00 committed by GitHub
parent fdbba2238e
commit 5f67918bae
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,4 +1,4 @@
{ pkgs, config, lib, ... }: { pkgs, config, lib, helpers, ... }:
with lib; with lib;
let let
cfg = config.colorschemes.tokyonight; cfg = config.colorschemes.tokyonight;
@ -9,27 +9,66 @@ in
colorschemes.tokyonight = { colorschemes.tokyonight = {
enable = mkEnableOption "Enable tokyonight"; enable = mkEnableOption "Enable tokyonight";
style = mkOption { style = mkOption {
type = types.nullOr style; type = style;
default = null; default = "storm";
description = "Theme style"; description = "Theme style";
}; };
terminalColors = mkEnableOption terminalColors = mkOption {
"Configure the colors used when opening a :terminal in Neovim"; type = types.bool;
italicComments = mkEnableOption "Make comments italic"; default = true;
italicKeywords = mkEnableOption "Make keywords italic"; description = "Configure the colors used when opening a :terminal in Neovim";
italicFunctions = mkEnableOption "Make functions italic"; };
italicVariables = mkEnableOption "Make variables and identifiers italic";
transparent = transparent =
mkEnableOption "Enable this to disable setting the background color"; mkEnableOption "Enable this to disable setting the background color";
hideInactiveStatusline = mkEnableOption styles =
let
mkBackgroundStyle = name: mkOption {
type = types.enum [ "dark" "transparent" "normal" ];
description = "Background style for ${name}";
default = "dark";
};
in
{
comments = mkOption {
type = types.attrsOf types.anything;
description = "Define comments highlight properties";
default = { italic = true; };
};
keywords = mkOption {
type = types.attrsOf types.anything;
description = "Define keywords highlight properties";
default = { italic = true; };
};
functions = mkOption {
type = types.attrsOf types.anything;
description = "Define functions highlight properties";
default = { };
};
variables = mkOption {
type = types.attrsOf types.anything;
description = "Define variables highlight properties";
default = { };
};
sidebars = mkBackgroundStyle "sidebars";
floats = mkBackgroundStyle "floats";
};
sidebars = mkOption {
type = types.listOf types.str;
default = [ "qf" "help" ];
description = "Set a darker background on sidebar-like windows";
example = ''["qf" "vista_kind" "terminal" "packer"]'';
};
dayBrightness = mkOption {
type = types.numbers.between 0.0 1.0;
default = 0.3;
description = "Adjusts the brightness of the colors of the **Day** style";
};
hideInactiveStatusline =
mkEnableOption
"Enabling this option will hide inactive statuslines and replace them with a thin border"; "Enabling this option will hide inactive statuslines and replace them with a thin border";
transparentSidebar = mkEnableOption dimInactive = mkEnableOption "dims inactive windows";
"Sidebar like windows like NvimTree get a transparent background"; lualineBold =
darkSidebar = mkEnableOption mkEnableOption
"Sidebar like windows like NvimTree get a darker background";
darkFloat = mkEnableOption
"Float windows like the lsp diagnostics windows get a darker background";
lualineBold = mkEnableOption
"When true, section headers in the lualine theme will be bold"; "When true, section headers in the lualine theme will be bold";
}; };
}; };
@ -37,22 +76,19 @@ in
colorscheme = "tokyonight"; colorscheme = "tokyonight";
extraPlugins = [ pkgs.vimPlugins.tokyonight-nvim ]; extraPlugins = [ pkgs.vimPlugins.tokyonight-nvim ];
options = { termguicolors = true; }; options = { termguicolors = true; };
globals = { extraConfigLuaPre =
tokyonight_style = mkIf (!isNull cfg.style) cfg.style; let
tokyonight_terminal_colors = mkIf (!cfg.terminalColors) 0; setupOptions = with cfg; {
inherit (cfg) style transparent styles sidebars;
tokyonight_italic_comments = mkIf (!cfg.italicComments) 0; terminal_colors = terminalColors;
tokyonight_italic_keywords = mkIf (!cfg.italicKeywords) 0; hide_inactive_statusline = hideInactiveStatusline;
tokyonight_italic_functions = mkIf (cfg.italicFunctions) 1; dim_inactive = dimInactive;
tokyonight_italic_variables = mkIf (cfg.italicVariables) 1; lualine_bold = lualineBold;
day_brightness = dayBrightness;
tokyonight_transparent = mkIf (cfg.transparent) 1;
tokyonight_hide_inactive_statusline =
mkIf (cfg.hideInactiveStatusline) 1;
tokyonight_transparent_sidebar = mkIf (cfg.transparentSidebar) 1;
tokyonight_dark_sidebar = mkIf (!cfg.darkSidebar) 0;
tokyonight_dark_float = mkIf (!cfg.darkFloat) 0;
tokyonight_lualine_bold = mkIf (cfg.lualineBold) 1;
}; };
in
''
require("tokyonight").setup(${helpers.toLuaObject setupOptions})
'';
}; };
} }