From ec4a21cd3d7ff8a39c1c4f46283aefa7459d7493 Mon Sep 17 00:00:00 2001 From: mat ess Date: Tue, 26 Jul 2022 00:22:16 -0400 Subject: [PATCH] Beef up custom color handling --- flake.lock | 34 ------- flake.nix | 6 +- home/kakoune.nix | 92 +++++++++++++++++- home/kitty.nix | 52 +++++++--- modules/home/programs/kakoune/extras.nix | 84 +++++++++++++++++ modules/home/programs/kitty/extras.nix | 34 ++----- overlays/colors/tokyonight.nix | 115 +++++------------------ pkgs/default.nix | 1 - pkgs/kitty-themes.nix | 13 --- 9 files changed, 243 insertions(+), 188 deletions(-) create mode 100644 modules/home/programs/kakoune/extras.nix delete mode 100644 pkgs/kitty-themes.nix diff --git a/flake.lock b/flake.lock index 747b911..1d366a8 100644 --- a/flake.lock +++ b/flake.lock @@ -104,38 +104,6 @@ "type": "github" } }, - "kakoune-cr-src": { - "flake": false, - "locked": { - "lastModified": 1651502437, - "narHash": "sha256-9sYqDWWnvoNpSYDBsMU6mV8AKLOwgolhzskD2sL7X+Q=", - "owner": "alexherbo2", - "repo": "kakoune.cr", - "rev": "d2b59774382328343cb4e6336f371e15d2a84b96", - "type": "github" - }, - "original": { - "owner": "alexherbo2", - "repo": "kakoune.cr", - "type": "github" - } - }, - "kitty-themes-src": { - "flake": false, - "locked": { - "lastModified": 1654224633, - "narHash": "sha256-SM7ExyD6cCYXZwxb4Rs1U2P2N9vzhmaUHJJRz/gO3IQ=", - "owner": "kovidgoyal", - "repo": "kitty-themes", - "rev": "f6c2f4e5617ef946b17db8bc18dadc9fad38d32e", - "type": "github" - }, - "original": { - "owner": "kovidgoyal", - "repo": "kitty-themes", - "type": "github" - } - }, "luar-src": { "flake": false, "locked": { @@ -208,8 +176,6 @@ "flake-utils": "flake-utils", "home-manager": "home-manager", "homebrew-enabled": "homebrew-enabled", - "kakoune-cr-src": "kakoune-cr-src", - "kitty-themes-src": "kitty-themes-src", "luar-src": "luar-src", "nixpkgs": "nixpkgs", "nixpkgs-master": "nixpkgs-master", diff --git a/flake.nix b/flake.nix index e9e9322..05cad43 100644 --- a/flake.nix +++ b/flake.nix @@ -34,10 +34,6 @@ url = github:andreyorst/smarttab.kak; flake = false; }; - kitty-themes-src = { - url = github:kovidgoyal/kitty-themes; - flake = false; - }; }; outputs = { self, darwin, nixpkgs, home-manager, flake-utils, ... }@inputs: @@ -224,7 +220,7 @@ # configs-git-aliases = import ./home/configs/git-aliases.nix; # configs-gh-aliases = import ./home/configs/gh-aliases.nix; configs-starship-symbols = import ./home/configs/starship-symbols.nix; - # programs-kakoune-extras = import ./modules/home/programs/kakoune/extras.nix; + programs-kakoune-extras = import ./modules/home/programs/kakoune/extras.nix; programs-kitty-extras = import ./modules/home/programs/kitty/extras.nix; }; diff --git a/home/kakoune.nix b/home/kakoune.nix index b087c57..98dd8d8 100644 --- a/home/kakoune.nix +++ b/home/kakoune.nix @@ -1,15 +1,84 @@ -{ pkgs, ... }: { +{ pkgs, ... }: + +let + colorsToKakoune = colors: with colors; { + attribute = magenta; + builtin = cyan; + comment = comment; + documentation = comment; + enum = red; + function = blue; + keyword = magenta; + meta = foreground; + module = blue; + operator = magenta; + parameter = yellow; + string = green; + type = magenta; + value = orange; + variable = white; + block = blue; + bullet = comment; + header = blue; + link = cyan; + list = foreground; + mono = foreground; + title = white; + BufferPadding = [ background background ]; + Default = [ foreground background ]; + PrimarySelection = [ "default" "!${magenta}40" ]; + SecondarySelection = [ "default" "!${green}40" ]; + PrimaryCursor = [ "default" "!${blue}80" ]; + SecondaryCursor = [ "default" "!${green}80" ]; + PrimaryCursorEol = [ "default" "!${red}80" ]; + SecondaryCursorEol = [ "default" "!${orange}80" ]; + LineNumbers = comment; + LineNumberCursor = orange; + LineNumbersWrapped = [ background background ]; + MenuForeground = [ active_tab_foreground active_tab_background ]; + MenuBackground = [ inactive_tab_foreground inactive_tab_background ]; + MenuInfo = green; + Information = [ inactive_tab_foreground inactive_tab_background ]; + Error = red; + StatusLine = [ active_tab_foreground "${active_tab_background}+b" ]; + StatusLineMode = orange; + StatusLineInfo = blue; + StatusLineValue = foreground; + StatusCursor = [ "default" "!${blue}80" ]; + Prompt = yellow; + MatchingChar = [ "default" comment ]; + Whitespace = comment; + InfoDefault = "Information"; + InfoBlock = "block"; + InfoBlockQuote = "quote"; + InfoBullet = "bullet"; + InfoHeader = "header"; + InfoLink = "link"; + InfoLinkMono = "header"; + InfoMono = "mono"; + InfoRule = "comment"; + InfoDiagnosticError = "InlayDiagnosticError"; + InfoDiagnosticHint = "InlayDiagnosticHint"; + InfoDiagnosticInformation = "InlayDiagnosticInfo"; + InfoDiagnosticWarning = "InlayDiagnosticWarning"; + }; + +in + +{ home.packages = with pkgs; [ kak-lsp ]; programs.kakoune = { enable = true; + extras.colors.enable = true; + extras.colors.dark = colorsToKakoune pkgs.lib.colors.tokyonight.dark; + extras.colors.light = colorsToKakoune pkgs.lib.colors.tokyonight.light; + config = { autoReload = "yes"; - # colorScheme = "tokyonight"; - hooks = [ # smarttab hooks { @@ -85,8 +154,15 @@ showMatching = true; showWhitespace.enable = true; + showWhitespace.space = " "; + ui.assistant = "cat"; ui.enableMouse = true; + + wrapLines.enable = true; + wrapLines.indent = true; + wrapLines.marker = "⏎"; + wrapLines.word = true; }; extraConfig = '' @@ -108,4 +184,14 @@ tabs-kak ]; }; + programs.fish.functions.set-kak-colors = { + body = '' + if test "$term_background" = light + kak-light + else + kak-dark + end + ''; + onVariable = "term_background"; + }; } diff --git a/home/kitty.nix b/home/kitty.nix index 57de712..3bcd788 100644 --- a/home/kitty.nix +++ b/home/kitty.nix @@ -2,6 +2,37 @@ # Let-In --------------------------------------------------------------------------------------- {{{ let inherit (lib) mkIf; + colorsToKitty = colors: with colors; { + inherit + background + foreground + selection_background + selection_foreground + tab_bar_background + active_tab_background + active_tab_foreground + inactive_tab_background + inactive_tab_foreground; + cursor = white; + cursor_text_color = background; + color0 = black; + color8 = black; + color1 = red; + color9 = red; + color2 = green; + color10 = lime; + color3 = yellow; + color11 = orange; + color4 = blue; + color12 = blue; + color5 = magenta; + color13 = magenta; + color6 = cyan; + color14 = cyan; + color7 = white; + color15 = white; + url_color = brightgreen; + }; in # }}} { @@ -47,19 +78,18 @@ in # }}} # Colors config ------------------------------------------------------------------------------ {{{ - programs.kitty.extras.colors = - let - theme = pkgs.lib.colors.tokyonight; - in - { - enable = true; - common = theme.common; - dark = theme.dark; - light = theme.light; - }; + programs.kitty.extras.colors.enable = true; + programs.kitty.extras.colors.dark = colorsToKitty pkgs.lib.colors.tokyonight.dark; + programs.kitty.extras.colors.light = colorsToKitty pkgs.lib.colors.tokyonight.light; programs.fish.functions.set-term-colors = { - body = "term-background $term_background"; + body = '' + if test "$term_background" = light + term-light + else + term-dark + end + ''; onVariable = "term_background"; }; programs.fish.interactiveShellInit = '' diff --git a/modules/home/programs/kakoune/extras.nix b/modules/home/programs/kakoune/extras.nix new file mode 100644 index 0000000..f7f334d --- /dev/null +++ b/modules/home/programs/kakoune/extras.nix @@ -0,0 +1,84 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + + cfg = config.programs.kakoune.extras; + + makeKakouneFace = face: name: + let + mkColor = name: + if hasPrefix "#" name + then "rgb:${substring 1 (-1) name}" + else if hasPrefix "!#" name + then "rgba:${substring 2 (-1) name}" + else name; + value = + if isList name + then concatStringsSep "," (map mkColor name) + else mkColor name; + in + "face global ${face} ${value}"; + + makeKakouneColors = faces: + concatStringsSep "\n" + ([ "# Generated by home-manager" ] + ++ mapAttrsToList makeKakouneFace faces); + + writeKakouneConfig = file: config: pkgs.writeText file (makeKakouneColors config); + + kakoune-colors = { + light = writeKakouneConfig "light.kak" cfg.colors.light; + dark = writeKakouneConfig "dark.kak" cfg.colors.dark; + }; + + kak-background = pkgs.writeShellScriptBin "kak-background" '' + for session in $(kak -l); do + kak -c $session -e "colorscheme $1;q" + done + ''; + kak-light = pkgs.writeShellScriptBin "kak-light" '' + ${kak-background}/bin/kak-background light + ''; + kak-dark = pkgs.writeShellScriptBin "kak-dark" '' + ${kak-background}/bin/kak-background dark + ''; +in +{ + options.programs.kakoune.extras = { + colors = { + enable = mkEnableOption "Custom kakoune color handling"; + + dark = mkOption { + type = with types; attrsOf (either str (listOf str)); + description = "Kakoune dark colors"; + }; + + light = mkOption { + type = with types; attrsOf (either str (listOf str)); + description = "Kakoune light colors"; + }; + }; + }; + + config = mkIf config.programs.kakoune.enable { + home.packages = mkIf cfg.colors.enable [ + kak-light + kak-dark + kak-background + ]; + + xdg.configFile."kak/colors/light.kak".source = kakoune-colors.light; + xdg.configFile."kak/colors/dark.kak".source = kakoune-colors.dark; + programs.kakoune.extraConfig = '' + eval %sh{ + if is-dark-mode; then + echo "colorscheme dark" + else + echo "colorscheme light" + fi + } + ''; + }; +} diff --git a/modules/home/programs/kitty/extras.nix b/modules/home/programs/kitty/extras.nix index 2f90b5e..b3648be 100644 --- a/modules/home/programs/kitty/extras.nix +++ b/modules/home/programs/kitty/extras.nix @@ -16,17 +16,18 @@ let kitty-colors = pkgs.symlinkJoin { name = "kitty-colors"; paths = [ - (writeKittyConfig "dark-colors.conf" cfg.colors.dark) - (writeKittyConfig "light-colors.conf" cfg.colors.light) + (writeKittyConfig "dark.conf" cfg.colors.dark) + (writeKittyConfig "light.conf" cfg.colors.light) ]; }; # Shell scripts for changing Kitty colors term-background = pkgs.writeShellScriptBin "term-background" '' - # Accepts arguments "light" or "dark". If shell is running in a Kitty window set the colors. + # Accepts arguments "light" or "dark". + # If shell is running in a Kitty window set the colors. if [ -n "$KITTY_WINDOW_ID" ]; then kitty @ --to $KITTY_LISTEN_ON set-colors --all --configured \ - ${kitty-colors}/"$1"-colors.conf & + ${kitty-colors}/"$1".conf & fi ''; term-light = pkgs.writeShellScriptBin "term-light" '' @@ -35,7 +36,6 @@ let term-dark = pkgs.writeShellScriptBin "term-dark" '' ${term-background}/bin/term-background dark ''; - in { @@ -48,7 +48,7 @@ in When enabled, commands term-dark and term-light will toggle between your dark and a light colors. term-background which accepts one argument (the value of which should - be dark or light) is also avaible. + be dark or light) is also available. (Note that the Kitty setting allow_remote_control = true is set to enable this functionality.) ''; @@ -56,7 +56,6 @@ in dark = mkOption { type = with types; attrsOf str; - default = { }; description = '' Kitty color settings for dark background colorscheme. ''; @@ -64,27 +63,10 @@ in light = mkOption { type = with types; attrsOf str; - default = { }; description = '' Kitty color settings for light background colorscheme. ''; }; - - common = mkOption { - type = with types; attrsOf str; - default = { }; - description = '' - Kitty color settings that the light and dark background colorschemes share. - ''; - }; - - default = mkOption { - type = types.enum [ "dark" "light" ]; - default = "dark"; - description = '' - The colorscheme Kitty opens with. - ''; - }; }; useSymbolsFromNerdFont = mkOption { @@ -140,12 +122,10 @@ in programs.kitty.settings = optionalAttrs cfg.colors.enable ( - - cfg.colors.common // cfg.colors.${cfg.colors.default} // { + { allow_remote_control = "yes"; listen_on = "unix:/tmp/mykitty"; } - ) // optionalAttrs (cfg.useSymbolsFromNerdFont != "") { # https://github.com/ryanoasis/nerd-fonts/wiki/Glyph-Sets-and-Code-Points diff --git a/overlays/colors/tokyonight.nix b/overlays/colors/tokyonight.nix index 7b9280e..7d8a9c0 100644 --- a/overlays/colors/tokyonight.nix +++ b/overlays/colors/tokyonight.nix @@ -1,7 +1,15 @@ -rec { - _dark = { +{ + dark = { background = "#1a1b26"; foreground = "#a9b1d6"; + selection_background = "#28344a"; + selection_foreground = "none"; + tab_bar_background = "#101014"; + active_tab_background = "#787c99"; + active_tab_foreground = "#3d59a1"; + inactive_tab_background = "#16161e"; + inactive_tab_foreground = "#9aa5ce"; + comment = "#565f89"; white = "#c0caf5"; black = "#414868"; red = "#f7768e"; @@ -14,57 +22,22 @@ rec { cyan = "#7dcfff"; brightgreen = "#9ece6a"; }; - dark = with _dark; { - inherit background foreground; - - # Cursor - cursor = white; - cursor_text_color = background; - - # Selection - selection_background = "#28344a"; - selection_foreground = "none"; - - # Tab bar - tab_bar_background = "#101014"; - active_tab_foreground = "#3d59a1"; - active_tab_background = "#787c99"; - inactive_tab_foreground = "#9aa5ce"; - inactive_tab_background = "#16161e"; - # black - color0 = black; - color8 = black; - # red - color1 = red; - color9 = red; - # green - color2 = green; - color10 = lime; - # yellow - color3 = yellow; - color11 = orange; - # blue - color4 = blue; - color12 = blue; - # magenta - color5 = magenta; - color13 = magenta; - # cyan - color6 = cyan; - color14 = cyan; - # white - color7 = white; - color15 = white; - # url underline color to fit colors - url_color = brightgreen; - }; - _light = { + light = rec { background = "#d5d6db"; + foreground = white; + selection_background = "#fafbff"; + selection_foreground = "none"; + tab_bar_background = "#e9e9ed"; + active_tab_foreground = "#d4d6e4"; + active_tab_background = "#2e7de9"; + inactive_tab_foreground = "#8990b3"; + inactive_tab_background = "#c4c8da"; + comment = "#9699a3"; white = "#343b58"; black = "#0f0f14"; red = "#8c4351"; yellow = "#8f5e15"; - orange = "#343b58"; + orange = white; green = "#33635c"; lime = "#166775"; blue = "#34548a"; @@ -72,50 +45,4 @@ rec { cyan = "#0f4b6e"; brightgreen = "#485e30"; }; - light = with _light; { - inherit background; - foreground = white; - - # Cursor - cursor = white; - cursor_text_color = background; - - # Selection - selection_background = "#fafbff"; - selection_foreground = "none"; - - # Tab bar - tab_bar_background = "#e9e9ed"; - active_tab_foreground = "#d4d6e4"; - active_tab_background = "#2e7de9"; - inactive_tab_foreground = "#8990b3"; - inactive_tab_background = "#c4c8da"; - # black - color0 = black; - color8 = black; - # red - color1 = red; - color9 = red; - # green - color2 = green; - color10 = lime; - # yellow - color3 = yellow; - color11 = orange; - # blue - color4 = blue; - color12 = blue; - # magenta - color5 = magenta; - color13 = magenta; - # cyan - color6 = cyan; - color14 = cyan; - # white - color7 = white; - color15 = white; - # url underline color to fit colors - url_color = brightgreen; - }; - common = { }; } diff --git a/pkgs/default.nix b/pkgs/default.nix index 4cb1215..dffbb1e 100644 --- a/pkgs/default.nix +++ b/pkgs/default.nix @@ -8,7 +8,6 @@ let "dark-mode-notify" "luar" "smarttab-kak" - "kitty-themes" ]; in genAttrs pkgs buildPkg diff --git a/pkgs/kitty-themes.nix b/pkgs/kitty-themes.nix deleted file mode 100644 index b105adc..0000000 --- a/pkgs/kitty-themes.nix +++ /dev/null @@ -1,13 +0,0 @@ -{ kitty-themes-src, stdenv, ... }: - -stdenv.mkDerivation { - name = "kitty-themes"; - src = kitty-themes-src; - dontBuild = true; - - installPhase = '' - mkdir -p $out - - cp themes/* $out - ''; -}