Skip to content

Commit

Permalink
feat(platforms): add generation for platform files
Browse files Browse the repository at this point in the history
This is based heavily off of the tokyonight extras-generation system.
  • Loading branch information
DOD-101 committed Jan 5, 2025
1 parent 1ee4044 commit 62dd1a4
Show file tree
Hide file tree
Showing 12 changed files with 145 additions and 10 deletions.
38 changes: 38 additions & 0 deletions lua/nordic/platforms/foot.lua
Original file line number Diff line number Diff line change
@@ -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
46 changes: 46 additions & 0 deletions lua/nordic/platforms/init.lua
Original file line number Diff line number Diff line change
@@ -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<string, {ext?: string, url:string, subdir?: string}>
-- 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
28 changes: 28 additions & 0 deletions lua/nordic/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
File renamed without changes.
23 changes: 23 additions & 0 deletions platforms-old/foot/nordic.ini
Original file line number Diff line number Diff line change
@@ -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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions platforms.sh
Original file line number Diff line number Diff line change
@@ -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')"
17 changes: 7 additions & 10 deletions platforms/foot/nordic.ini
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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

0 comments on commit 62dd1a4

Please sign in to comment.