From 62dd1a4c98e506ff68e14461bee06c739f7f8c0a Mon Sep 17 00:00:00 2001 From: David Thievon Date: Sun, 5 Jan 2025 18:24:30 +0100 Subject: [PATCH] feat(platforms): add generation for platform files This is based heavily off of the tokyonight extras-generation system. --- lua/nordic/platforms/foot.lua | 38 +++++++++++++++ lua/nordic/platforms/init.lua | 46 +++++++++++++++++++ lua/nordic/utils.lua | 28 +++++++++++ .../fish/Nordic.theme | 0 platforms-old/foot/nordic.ini | 23 ++++++++++ .../iTerm2/nordic.itermcolors | 0 .../kitty/nordic.conf | 0 .../konsole/nordic.colorscheme | 0 .../wezterm/nordic.toml | 0 .../windows-terminal/nordic.json | 0 platforms.sh | 3 ++ platforms/foot/nordic.ini | 17 +++---- 12 files changed, 145 insertions(+), 10 deletions(-) create mode 100644 lua/nordic/platforms/foot.lua create mode 100644 lua/nordic/platforms/init.lua rename {platforms => platforms-old}/fish/Nordic.theme (100%) create mode 100644 platforms-old/foot/nordic.ini rename {platforms => platforms-old}/iTerm2/nordic.itermcolors (100%) rename {platforms => platforms-old}/kitty/nordic.conf (100%) rename {platforms => platforms-old}/konsole/nordic.colorscheme (100%) rename {platforms => platforms-old}/wezterm/nordic.toml (100%) rename {platforms => platforms-old}/windows-terminal/nordic.json (100%) create mode 100755 platforms.sh diff --git a/lua/nordic/platforms/foot.lua b/lua/nordic/platforms/foot.lua new file mode 100644 index 00000000..70c155dc --- /dev/null +++ b/lua/nordic/platforms/foot.lua @@ -0,0 +1,38 @@ +local utils = require('nordic.utils') + +local M = {} + +--- @param colors ColorScheme +function M.generate(colors) + local footColors = utils.removeHash(colors) + + local foot = utils.template( + [[ +[colors] +foreground=${white1} +background=${bg} + +regular0=${gray2} +regular1=${red.base} +regular2=${green.base} +regular3=${yellow.base} +regular4=${blue1} +regular5=${magenta.base} +regular6=${cyan.base} +regular7=${white1} +bright0=${gray3} +bright1=${red.bright} +bright2=${green.bright} +bright3=${yellow.bright} +bright4=${blue2} +bright5=${magenta.bright} +bright6=${cyan.bright} +bright7=${white2} +]], + footColors + ) + + return foot +end + +return M diff --git a/lua/nordic/platforms/init.lua b/lua/nordic/platforms/init.lua new file mode 100644 index 00000000..06afe92c --- /dev/null +++ b/lua/nordic/platforms/init.lua @@ -0,0 +1,46 @@ +-- Adapted from [tokyonight](https://github.com/folke/tokyonight.nvim) +-- +-- Tokyonight is licensed under [Apache License 2.0](https://raw.githubusercontent.com/folke/tokyonight.nvim/refs/heads/main/LICENSE) +-- +-- Changes: +-- - Adjusted the format of M.platforms +-- - Changed variable names (mostly from extra -> platform) +-- - Simplified code to work better for just one color scheme "flavor" +local utils = require('nordic.utils') + +local M = {} + +---@param file string +---@param contents string +function utils.write(file, contents) + vim.fn.mkdir(vim.fn.fnamemodify(file, ':h'), 'p') + local fd = assert(io.open(file, 'w+')) + fd:write(contents) + fd:close() +end + +--- @type table +-- stylua: ignore +M.platforms = { + foot = { ext = "ini", url = "https://codeberg.org/dnkl/foot" }, +} + +function M.setup() + local C = require('nordic.colors') + + ---@type string[] + local platform_names = vim.tbl_keys(M.platforms) + table.sort(platform_names) + + for _, platform in ipairs(platform_names) do + local info = M.platforms[platform] + local plugin = require('nordic.platforms.' .. platform) + local fname = platform .. (info.subdir and '/' .. info.subdir .. '/' or '') .. '/nordic' .. '.' .. info.ext + fname = string.gsub(fname, '%.$', '') -- remove trailing dot when no extension + + print('[write] ' .. fname) + utils.write('platforms/' .. fname, plugin.generate(C)) + end +end + +return M diff --git a/lua/nordic/utils.lua b/lua/nordic/utils.lua index b8ba4cc7..cd96bc22 100644 --- a/lua/nordic/utils.lua +++ b/lua/nordic/utils.lua @@ -101,4 +101,32 @@ function M.assert_eq(left, right, message) end end +---Simple string interpolation. +--- +---Example template: "${name} is ${value}" +--- +---@param str string template string +---@param table table key value pairs to replace in the string +function M.template(str, table) + return ( + str:gsub('($%b{})', function(w) + -- TODO: unpack is depreciated + return vim.tbl_get(table, unpack(vim.split(w:sub(3, -2), '.', { plain = true }))) or w + end) + ) +end + +function M.removeHash(colors) + local output_colors = {} + for k, v in pairs(colors) do + if type(v) == 'string' then + output_colors[k] = v:gsub('^#', '') + elseif type(v) == 'table' then + output_colors[k] = M.removeHash(v) + end + end + + return output_colors +end + return M diff --git a/platforms/fish/Nordic.theme b/platforms-old/fish/Nordic.theme similarity index 100% rename from platforms/fish/Nordic.theme rename to platforms-old/fish/Nordic.theme diff --git a/platforms-old/foot/nordic.ini b/platforms-old/foot/nordic.ini new file mode 100644 index 00000000..3dc7a929 --- /dev/null +++ b/platforms-old/foot/nordic.ini @@ -0,0 +1,23 @@ +# Nordic Colorscheme for foot. +# Based on https://github.com/AlexvZyl/nordic.nvim +# Author: @filahf + +[colors] +foreground=D8DEE9 +background=242933 +regular0=3B4252 +regular1=BF616A +regular2=A3BE8C +regular3=EBCB8B +regular4=81A1C1 +regular5=B48EAD +regular6=8FBCBB +regular7=D8DEE9 +bright0=3B4252 +bright1=D06F79 +bright2=B1D196 +bright3=F0D399 +bright4=88C0D0 +bright5=C895BF +bright6=93CCDC +bright7=E5E9F0 diff --git a/platforms/iTerm2/nordic.itermcolors b/platforms-old/iTerm2/nordic.itermcolors similarity index 100% rename from platforms/iTerm2/nordic.itermcolors rename to platforms-old/iTerm2/nordic.itermcolors diff --git a/platforms/kitty/nordic.conf b/platforms-old/kitty/nordic.conf similarity index 100% rename from platforms/kitty/nordic.conf rename to platforms-old/kitty/nordic.conf diff --git a/platforms/konsole/nordic.colorscheme b/platforms-old/konsole/nordic.colorscheme similarity index 100% rename from platforms/konsole/nordic.colorscheme rename to platforms-old/konsole/nordic.colorscheme diff --git a/platforms/wezterm/nordic.toml b/platforms-old/wezterm/nordic.toml similarity index 100% rename from platforms/wezterm/nordic.toml rename to platforms-old/wezterm/nordic.toml diff --git a/platforms/windows-terminal/nordic.json b/platforms-old/windows-terminal/nordic.json similarity index 100% rename from platforms/windows-terminal/nordic.json rename to platforms-old/windows-terminal/nordic.json diff --git a/platforms.sh b/platforms.sh new file mode 100755 index 00000000..c7ced6e3 --- /dev/null +++ b/platforms.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env sh + +nvim --headless -u NONE -c "lua package.path = package.path .. ';./lua/?/init.lua;./lua/?.lua'; require('nordic.platforms').setup() ; vim.api.nvim_command('quit')" diff --git a/platforms/foot/nordic.ini b/platforms/foot/nordic.ini index 3dc7a929..bc55dffd 100644 --- a/platforms/foot/nordic.ini +++ b/platforms/foot/nordic.ini @@ -1,10 +1,7 @@ -# Nordic Colorscheme for foot. -# Based on https://github.com/AlexvZyl/nordic.nvim -# Author: @filahf - [colors] foreground=D8DEE9 background=242933 + regular0=3B4252 regular1=BF616A regular2=A3BE8C @@ -13,11 +10,11 @@ regular4=81A1C1 regular5=B48EAD regular6=8FBCBB regular7=D8DEE9 -bright0=3B4252 -bright1=D06F79 -bright2=B1D196 -bright3=F0D399 +bright0=434C5E +bright1=C5727A +bright2=B1C89D +bright3=EFD49F bright4=88C0D0 -bright5=C895BF -bright6=93CCDC +bright5=BE9DB8 +bright6=9FC6C5 bright7=E5E9F0