aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLibravatar Alexey Stepanov <blueingreen@bluig.space>2024-10-12 20:51:26 +0000
committerLibravatar Alexey Stepanov <blueingreen@bluig.space>2024-10-12 20:51:26 +0000
commit07c6bf1645d6d172a5f752a2dcbdeb5921ac1fce (patch)
treeb3fb786b1eea8a40d4ecb49a90afd07dc4d5bcd4
add project
-rw-r--r--LICENSE21
-rw-r--r--README.md84
-rwxr-xr-xbuilder.sh145
3 files changed, 250 insertions, 0 deletions
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..dede353
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) 2024 Aleksey Stepanov
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..f267fe4
--- /dev/null
+++ b/README.md
@@ -0,0 +1,84 @@
+# base16-builder
+
+<!-- markdownlint-disable MD013 -->
+
+This repo provides a `builder.sh` to create your base16 colorschemes.
+
+## Dependecies
+
+- [lustache](https://luarocks.org/modules/olivine-labs/lustache);
+- [lustache-cli](https://github.com/djmattyg007/lustache-cli);
+- [tinty](https://github.com/tinted-theming/tinty).
+
+## Preparation
+
+Make sure you have the following structure for your project:
+
+```bash
+├── colors
+└── templates
+```
+
+Folder `templates` must contain the following files:
+
+```bash
+├── body.mustache
+├── config.yaml
+└── head.mustache
+```
+
+with the following content:
+
+```mustache
+# config.yaml
+
+default:
+ supported-systems: [base16]
+ filename: "colors/{{scheme-system}}-{{scheme-slug}}.theme"
+```
+
+The file `body.mustache` must contain a template for the program for which the color scheme is made, for example, for the program [wlr-which-key](https://github.com/MaxVerevkin/wlr-which-key) it will be as follows:
+
+```yaml
+background: "#{{base00-hex}}"
+color: "#{{base06-hex}}"
+border: "#{{base0D-hex}}"
+```
+
+The file `head.mustache` contains metadata about the colorscheme:
+
+```yaml
+#
+#
+# name: {{scheme-name}}
+# author: {{{scheme-author}}}
+# slug: {{scheme-slug}}
+# slug-underscored: {{scheme-slug-underscored}}
+# system: {{scheme-system}}
+# variant: {{scheme-variant}}
+# is-{{scheme-variant}}-variant: {{hasVariant}}
+#
+#
+```
+
+> If you will use this file, change the comment symbols to match the extensions of the final colorscheme file, if for example the colorscheme will be `base16-google-light.css`, then replace the symbol `#` with `/* */`, etc.
+
+Put `builder.sh` in your project directory, make it executable and launch it:
+
+## Usage
+
+```bash
+cp base16-builder /path/to/your/project
+
+chmod +x builder.sh
+
+./builder.sh
+```
+
+## Summary
+
+I tried to make this build according to the [official spec](https://github.com/tinted-theming/home/blob/main/builder.md), i may have missed something, if so - create a ticket in [todo](https://todo.sr.ht/~blueingreen/base16-builder).
+
+## License
+
+MIT
diff --git a/builder.sh b/builder.sh
new file mode 100755
index 0000000..5f944cb
--- /dev/null
+++ b/builder.sh
@@ -0,0 +1,145 @@
+#!/bin/bash
+
+declare -g configFile="./templates/config.yaml"
+declare -g fileName
+declare -g headFileTemplate="./templates/head.mustache"
+declare -g headJson
+declare -g bodyFileTemplate="./templates/body.mustache"
+declare -g bodyJson
+declare -g tmpBodyJson
+
+declare -g schemesPath="$HOME/.local/share/tinted-theming/tinty/repos/schemes/base16/"
+declare -g schemeSystem
+declare -g schemeSlug
+declare -g schemeSlugUnderscored
+declare -g schemeName
+declare -g schemeAuthor
+declare -g schemeVariant
+
+declare -g tokenHex
+declare -g tokenBgr
+declare -g tokenHexR
+declare -g tokenHexG
+declare -g tokenHexB
+declare -g tokenRgbR
+declare -g tokenRgbG
+declare -g tokenRgbB
+declare -g tokenRgb16R
+declare -g tokenRgb16G
+declare -g tokenRgb16B
+declare -g tokenDecR
+declare -g tokenDecG
+declare -g tokenDecB
+
+readarray -t schemesFiles < <(find "$schemesPath" -type f -iname '*.yaml')
+readarray -t necessaryTokensPaletteList < <(grep -oP '\{\{\K[^}]+(?=\}\})' "$bodyFileTemplate" | awk -F'-' '{print $1}' | sort -u)
+
+function getProperty() {
+ yq -oy "$schemeFile" | yq -o=json -r ".$1"
+}
+
+function createFile() {
+ # Extract filename entry from config
+ yq '.default.filename' "$configFile" >"/tmp/filename-base16-nwg-dock.txt"
+
+ fileName=$(lustache-cli -i "/tmp/filename-base16-nwg-dock.txt" --json-data "$headJson")
+
+ if [[ -e ./"$fileName" ]]; then
+ return
+ else
+ touch ./"$fileName"
+ fi
+}
+
+for schemeFile in "${schemesFiles[@]}"; do
+ schemeName=$(getProperty "name")
+ schemeAuthor=$(getProperty "author")
+ schemeSlug=$(basename "$schemeFile" .yaml)
+ schemeSlugUnderscored="${schemeSlug//-/_}"
+ schemeSystem=$(yq '.default.supported-systems[0]' "$configFile")
+ schemeVariant=$(getProperty "variant")
+
+ headJson=$(
+ jq \
+ --null-input \
+ --arg schemeName "$schemeName" \
+ --arg schemeAuthor "$schemeAuthor" \
+ --arg schemeSlug "$schemeSlug" \
+ --arg schemeSlugUnderscored "$schemeSlugUnderscored" \
+ --arg schemeSystem "$schemeSystem" \
+ --arg schemeVariant "$schemeVariant" \
+ '{
+ "scheme-name": $schemeName,
+ "scheme-author": $schemeAuthor,
+ "scheme-slug": $schemeSlug,
+ "scheme-slug-underscored": $schemeSlugUnderscored,
+ "scheme-system": $schemeSystem,
+ "scheme-variant": $schemeVariant,
+ "hasVariant": (if $schemeVariant != "" then "true" else "false" end)
+ }'
+ )
+
+ for tokenName in "${necessaryTokensPaletteList[@]}"; do
+ tokenHex=$(yq -oy "$schemeFile" | yq -o=json -r ".palette.$tokenName")
+ tokenBgr=$(echo "$tokenHex" | rev)
+ tokenHexR=${tokenHex:0:2}
+ tokenHexG=${tokenHex:2:2}
+ tokenHexB=${tokenHex: -2}
+ tokenRgbR=$((16#$tokenHexR))
+ tokenRgbG=$((16#$tokenHexG))
+ tokenRgbB=$((16#$tokenHexB))
+ tokenRgb16R=$(echo "($tokenRgbR / 255) * 65535" | bc -l | awk '{print int($1)}')
+ tokenRgb16G=$(echo "($tokenRgbG / 255) * 65535" | bc -l | awk '{print int($1)}')
+ tokenRgb16B=$(echo "($tokenRgbB / 255) * 65535" | bc -l | awk '{print int($1)}')
+ tokenDecR=$(echo "scale=4; $tokenRgbR / 255" | bc)
+ tokenDecG=$(echo "scale=4; $tokenRgbG / 255" | bc)
+ tokenDecB=$(echo "scale=4; $tokenRgbB / 255" | bc)
+
+ tmpBodyJson=$(
+ jq \
+ --null-input \
+ --arg tokenName "$tokenName" \
+ --arg tokenHex "$tokenHex" \
+ --arg tokenBgr "$tokenBgr" \
+ --arg tokenHexR "$tokenHexR" \
+ --arg tokenHexG "$tokenHexG" \
+ --arg tokenHexB "$tokenHexB" \
+ --arg tokenRgbR "$tokenRgbR" \
+ --arg tokenRgbG "$tokenRgbG" \
+ --arg tokenRgbB "$tokenRgbB" \
+ --arg tokenRgb16R "$tokenRgb16R" \
+ --arg tokenRgb16G "$tokenRgb16G" \
+ --arg tokenRgb16B "$tokenRgb16B" \
+ --arg tokenDecR "$tokenDecR" \
+ --arg tokenDecG "$tokenDecG" \
+ --arg tokenDecB "$tokenDecB" \
+ '{
+ ($tokenName + "-hex"): $tokenHex,
+ ($tokenName + "-bgr"): $tokenBgr,
+ ($tokenName + "-hex-r"): $tokenHexR,
+ ($tokenName + "-hex-g"): $tokenHexG,
+ ($tokenName + "-hex-b"): $tokenHexB,
+ ($tokenName + "-rgb-r"): $tokenRgbR,
+ ($tokenName + "-rgb-g"): $tokenRgbG,
+ ($tokenName + "-rgb-b"): $tokenRgbB,
+ ($tokenName + "-rgb16-r"): $tokenRgb16R,
+ ($tokenName + "-rgb16-g"): $tokenRgb16G,
+ ($tokenName + "-rgb16-b"): $tokenRgb16B,
+ ($tokenName + "-dec-r"): $tokenDecR,
+ ($tokenName + "-dec-g"): $tokenDecG,
+ ($tokenName + "-dec-b"): $tokenDecB
+ }'
+ )
+
+ bodyJson=$(echo "$bodyJson" "$tmpBodyJson" | jq -s 'add')
+ done
+
+ createFile
+
+ lustache-cli -i "$headFileTemplate" --json-data "$headJson" >./"$fileName"
+
+ echo >>./"$fileName"
+
+ lustache-cli -i "$bodyFileTemplate" --json-data "$bodyJson" >>./"$fileName"
+
+done