]> Freerunner's - dabruin.kak/commitdiff
feat: add a light theme variant
authorThomas Teixeira <thomas.teixeira@startmail.com>
Mon, 5 Aug 2024 19:23:13 +0000 (21:23 +0200)
committerThomas Teixeira <thomas.teixeira@startmail.com>
Mon, 5 Aug 2024 19:23:13 +0000 (21:23 +0200)
Fixes: https://todo.sr.ht/~nasmevka/plugins.kak/7
Signed-Off-By: Thomas Teixeira <thomas.teixeira@startmail.com>
README.md
dabruin.kak
dabruin.sh [new file with mode: 0644]
dabruin_light.kak [new file with mode: 0644]

index 8988e999c6b76bed771a26bfc53e1aed18dbe173..0e69ecef463248a13ae65d1d12d5482d3a26dde0 100644 (file)
--- a/README.md
+++ b/README.md
@@ -1,60 +1,73 @@
-## dabruin.kak  
+## dabruin.kak
 One color, multiple attributes.  
 **D**im, **A**ccent, **B**old, **R**everse, **U**nderline, **I**talic, **N**othing.  
   
-![common dab stylized](https://pic.t0.vc/YFCU)  
-  
-### installation  
+![common dab stylized](https://pic.t0.vc/YFCU)
+
+### installation
 Install as any other plugin. More information [here](https://github.com/mawww/kakoune/wiki/Installing-Plugins)  
-  
-### palette  
-Here is *dabruin*'s default palette.  
+
+### palette
+Here is two screenshots from this README.md when using *dabruin*'s dark/light palette.  
 I did not use the terminal palette to avoid non-optimal contrasts and keep sane defaults.  
   
-![default dabruin palette](https://pic.t0.vc/WMNK)  
-  
-### customization  
-If the `dabruin_accent` option exists, **before** calling the colorscheme command,  
+![screenshot of dabruin light theme](https://pic.t0.vc/SBSM)
+![screenshot of dabruin dark theme](https://pic.t0.vc/VOXW)
+
+### customization
+If the `dabruin_accent` option is set, **before** the colorscheme command is called,
 its value will be used as `dabruin_accent` color.  
-The following code snippet will load *dabruin* with a bright red as its accent color.  
-```kak  
+Same thing for the `dabruin_ratio` option, which tells dabruin what ratio should be used when calculating the darker/lighter secondary accent.  
+The following code snippet will load *dabruin* with a bright red as its accent color and a really dark red as the secondary one.  
+```kak
 declare-option str dabruin_accent 'rgb:ff0000'  
+declare-option str dabruin_ratio '1/10'
 colorscheme dabruin  
-```  
+```
 Each time you (re-)load *dabruin* theme the `dabruin_accent` option will be read and used.  
 For example, the following snippet changes the accent to a random value at startup, and  
 when you run the `dabruin-random-accent` command.  
-```kak  
-declare-option str dabruin_accent  
-define-command -params 0 dabruin-random-accent %{  
-    set-option global dabruin_accent %sh{  
-       printf 'rgb:%s' "$(tr -dc 'a-fA-F0-9' </dev/urandom | head -c 6)"  
-    }  
-    colorscheme dabruin  
-}  
-dabruin-random-accent  
-```  
-  
-### specifics about dim  
-The dim terminal attribute was not cooperating with the bold and reverse attributes  
-on certain terminal implementation, see [this discussion](https://discuss.kakoune.com/t/question-about-dim-and-bold-attribute-in-faces/2332) for more information.  
-So, I wrote a simple shell function to mimic its effect, and remove the need of two options (`dabruin_accent{,_dim}`).  
-```sh  
-calculate_dim() {  
-       printf "$1" | cut -d: -f2 | fold -b2 |  
-       while read -r hex; do  
-                       base10="$(printf '%d' "0x${hex}")"  
-                       printf '%02x' "$((base10 * 5 / 9))"  
-       done | xargs printf 'rgb:%s'  
-}  
-```  
-  
-### credits  
+```kak
+declare-option str dabruin_accent
+define-command -params 0 dabruin-random-accent %{
+    set-option global dabruin_accent %sh{
+       printf 'rgb:%s' "$(tr -dc 'a-fA-F0-9' </dev/urandom | head -c 6)"
+    }
+    colorscheme dabruin
+}
+dabruin-random-accent
+```
+
+### specifics about secondary accent
+I've made the conscious choice of not letting user set the secondary accent, and instead, use a lighter/darker colors, derived from the primary accent.  
+To achieve this, I could not use the dim terminal attribute, since it was not cooperating with the bold and reverse attributes on certain terminal implementation, see [this discussion](https://discuss.kakoune.com/t/question-about-dim-and-bold-attribute-in-faces/2332) for more information.  
+Plus, it would not work when trying to create the light version of this theme.  
+So, I wrote a simple awk script to mimic its effect, and remove the need of two options (`dabruin_accent{,_dim}`).  
+```sh
+ratio_calculate() {
+       printf "${1##rgb:}" | fold -w2 |
+               awk --posix -v ratio="$2" '
+               BEGIN {
+                       printf "rgb:"
+                       if (ratio ~ /[0-9]+\/[0-9]+/) {
+                               split(ratio, nums, "/")
+                               ratio = nums[1]/nums[2]
+                       }
+               }
+               {
+                       decimal = sprintf("%d", "0x" $0)
+                       ratioed = int(decimal * ratio)
+                       printf("%02x", ratioed > 255 ? 255 : ratioed)
+               }'
+}
+```
+
+### credits
 None of the credit sources support or endorse this project, as far as I know.  
-  
-#### theme  
+
+#### theme
 This theme is **heavily inspired** by [Romain Lafourcade's vim-bruin project](https://git.sr.ht/~romainl/vim-bruin).  
-  
-#### logo  
+
+#### logo
 dabruin.kak's logo is a transformation of [Hans Hillewaert picture](https://en.wikipedia.org/wiki/Common_dab#/media/File:Limanda_limanda.jpg), which is licensed under CC BY-SA 4.0.  
 To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/4.0/  
index 321cdf81bdd765b886ea5c1c053658884ec3ce2e..43e4f8b4bf3b057b3b070831e9c459a24eb4587f 100644 (file)
@@ -1,75 +1,19 @@
 ##
 ## dabruin.kak by nasmevka
 ## file structure based on base16.kak
+## dark theme
 ##
 
 evaluate-commands %sh{
-       calculate_dim() {
-               printf "$1" | cut -d: -f2 | fold -w2 |
-                       while read -r hex; do
-                               base10="$(printf '%d' "0x${hex}")"
-                               printf '%02x' "$((base10 * 5 / 9))"
-                       done | xargs printf 'rgb:%s'
-       }
-       # base
-       accent="${kak_opt_dabruin_accent:-rgb:FFB852}"
        background='rgb:242124'
-       foreground='rgb:F5F5F5'
-       grey='rgb:B2BECA'
-       deep='rgb:3D4C59'
-       # dim
-       accent_dim="$(calculate_dim "${accent}")"
-       foreground_dim="$(calculate_dim "${foreground}")"
-       grey_dim="$(calculate_dim "${grey}")"
-       ## code
-       cat     <<-COLORSCHEME
-               face global value ${foreground_dim}+i
-               face global type ${foreground}+bu
-               face global variable ${foreground}+i
-               face global module string
-               face global function ${accent_dim}+i
-               face global string ${grey}+i
-               face global keyword ${accent}
-               face global operator ${foreground}
-               face global attribute ${foreground}+i
-               face global comment ${deep}
-               face global documentation comment
-               face global meta ${accent_dim}+b
-               face global builtin ${foreground}+i
-
-               face global title ${accent}+bi
-               face global header title
-               face global mono string
-               face global block mono
-               face global link ${accent_dim}+u
-               face global bullet ${foreground_dim}
-               face global list bullet
+       foreground='rgb:FAFAFA'
+       middleground="rgb:B2B2B2"
+       ratio="${kak_opt_dabruin_ratio:-3/5}"
+       accent="${kak_opt_dabruin_accent:-rgb:FFB852}"
+       fore_middle_ratio='1.2'
+       back_middle_ratio='0.8'
 
-               face global Default ${foreground},${background}
-               face global PrimarySelection ${background},${accent}+fg
-               face global SecondarySelection ${background},${accent_dim}+fg
-               face global PrimaryCursor ${background},${foreground}+fg
-               face global SecondaryCursor ${background},${foreground_dim}+fg
-               face global PrimaryCursorEol ${grey}+r
-               face global SecondaryCursorEol ${grey_dim}+r
-               face global LineNumbers ${grey_dim},${background}
-               face global LineNumbersWrapped ${background},${background}
-               face global LineNumberCursor ${accent},${background}
-               face global MenuForeground ${accent},${background}+rb
-               face global MenuBackground ${foreground},${background}
-               face global MenuInfo ${accent}@MenuBackground
-               face global Information ${accent}+b@MenuBackground
-               face global Error red
-               face global DiagnosticError red
-               face global DiagnosticWarning yellow
-               face global StatusLine ${foreground},${background}
-               face global StatusLineMode ${accent}
-               face global StatusLineInfo ${grey}
-               face global StatusLineValue ${grey}
-               face global StatusCursor ${accent},${background}+r
-               face global Prompt ${accent},${background}
-               face global MatchingChar ${background},${foreground_dim}+fg
-               face global BufferPadding ${deep},${background}+F
-               face global Whitespace ${deep},${background}+f
-       COLORSCHEME
+       export background foreground middleground ratio accent fore_middle_ratio back_middle_ratio
+       source_directory="$(dirname "${kak_source}")"
+       sh "${source_directory}/dabruin.sh"
 }
diff --git a/dabruin.sh b/dabruin.sh
new file mode 100644 (file)
index 0000000..0b5a1ab
--- /dev/null
@@ -0,0 +1,82 @@
+# Expect to be ran with the following variables defined:
+# - background = 'rgb:rrggbb'
+# - foreground = 'rgb:rrggbb'
+# - middleground = 'rgb:rrggbb'
+# - accent = 'rgb:rrggbb'
+# - ratio = 'n/m' or 'n.m'
+# - back_middle_ratio = 'n/m' or 'n.m'
+# - fore_middle_ratio = 'n/m' or 'n.m'
+
+ratio_calculate() {
+       printf "${1##rgb:}" | fold -w2 |
+               awk --posix -v ratio="$2" '
+               BEGIN {
+                       printf "rgb:"
+                       if (ratio ~ /[0-9]+\/[0-9]+/) {
+                               split(ratio, nums, "/")
+                               ratio = nums[1]/nums[2]
+                       }
+               }
+               {
+                       decimal = sprintf("%d", "0x" $0)
+                       ratioed = int(decimal * ratio)
+                       printf("%02x", ratioed > 255 ? 255 : ratioed)
+               }'
+}
+
+to_foreground_middleground="$(ratio_calculate "${middleground}" "${fore_middle_ratio}")"
+to_background_middleground="$(ratio_calculate "${middleground}" "${back_middle_ratio}")"
+second_accent="$(ratio_calculate "${accent}" "${ratio}")"
+
+# code
+cat <<-COLORSCHEME
+       face global value ${to_foreground_middleground},${background}+biF
+       face global type ${foreground},${background}+buF
+       face global variable ${foreground}+i
+       face global module string
+       face global function ${second_accent},${background}+biF
+       face global string ${middleground}+i
+       face global keyword ${accent}+b
+       face global operator ${foreground}
+       face global attribute ${foreground}+i
+       face global comment ${to_background_middleground}+i
+       face global documentation comment
+       face global meta ${second_accent}+b
+       face global builtin ${accent}+i
+
+       face global title ${accent}+bi
+       face global header title
+       face global mono string
+       face global block mono
+       face global link ${second_accent}+u
+       face global bullet ${middleground}
+       face global list bullet
+
+       face global Default ${foreground},${background}
+       face global PrimarySelection ${foreground},${second_accent}+fg
+       face global SecondarySelection ${foreground},${to_background_middleground}+fg
+       face global PrimaryCursor ${background},${accent}+fg
+       face global SecondaryCursor ${background},${middleground}+fg
+       face global PrimaryCursorEol ${background},${foreground}+F
+       face global SecondaryCursorEol ${background},${to_foreground_middleground}+F
+       face global LineNumbers ${to_foreground_middleground},${background}
+       face global LineNumbersWrapped ${background},${background}
+       face global LineNumberCursor ${accent},${background}
+       face global MenuForeground ${background},${accent}+b
+       face global MenuBackground ${foreground},${background}
+       face global MenuInfo ${accent}@MenuBackground
+       face global Information ${accent}+b@MenuBackground
+       face global Error red
+       face global DiagnosticError red
+       face global DiagnosticWarning yellow
+       face global StatusLine ${foreground},${background}
+       face global StatusLineMode ${accent}
+       face global StatusLineInfo ${middleground}
+       face global StatusLineValue ${middleground}
+       face global StatusCursor ${background},${accent}
+       face global Prompt ${accent},${background}
+       face global MatchingChar ${background},${middleground}+F
+       face global BufferPadding ${to_background_middleground},${background}+F
+       face global Whitespace ${to_background_middleground},${background}+F
+COLORSCHEME
+
diff --git a/dabruin_light.kak b/dabruin_light.kak
new file mode 100644 (file)
index 0000000..70b3ca4
--- /dev/null
@@ -0,0 +1,19 @@
+##
+## dabruin.kak by nasmevka
+## file        structure based on base16.kak
+## light theme
+##
+
+evaluate-commands %sh{
+       background='rgb:FAFAFA'
+       foreground='rgb:242124'
+       middleground="rgb:666666"
+       accent="${kak_opt_dabruin_accent:-rgb:9F6514}"
+       ratio="${kak_opt_dabruin_ratio:-9/5}"
+       fore_middle_ratio='0.85'
+       back_middle_ratio='1.5'
+
+       export background foreground middleground accent ratio fore_middle_ratio back_middle_ratio
+       source_directory="$(dirname "${kak_source}")"
+       sh "${source_directory}/dabruin.sh"
+}