-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(platforms): add generation for platform files #161
base: main
Are you sure you want to change the base?
Conversation
I'm more than willing to implement all the steps listed above, but I would first like to get this approved, before I take the time to implement the rest. |
I am in support of this PR, I think it would make updating the color palate much easier and help keep thing in sync. It would also make vetting new extras faster (no more checking hex codes). I think the simplest approach for CI would be to just add the generation to the If I remember right, we used to have color conversion stuff in Edit: It looks like we still have some of them. I am not near a device with a working nvim config, but something like this should work: local U = require("nordic.utils")
local r, g, b = U.hex_to_rgb(hex)
return string.format("%d,%d,%d", r, g, b) I would define that function in the individual themes, because I doubt we will find What do you think @AlexvZyl? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That looks great!
Yeah this is very nice, thanks @DOD-101. |
b42ad32
to
6ca749c
Compare
This is based heavily off of the tokyonight extras-generation system. Co-authored-by: Owen Friedman <[email protected]>
Also adjust their doc strings slightly.
6ca749c
to
04890a8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am noticing we have a lot of colors, in the platforms, that aren't used anywhere else... If you can keep those close to their original value, but of course, use values actually in our palette.
Also, thanks for doing this, I didn't realize what a mess it was until now.
I do not personally use all of the platforms and plugins in the list, so if something is not right, or you have a suggestion, please open a PR! | ||
## Contributing a new Platform | ||
|
||
All of the platform files are generated using a template system. Have a look at the files in [this directory](https://github.com/AlexvZyl/nordic.nvim/tree/main/lua/nordic/platforms) to see how it works. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This feels a little cumbersome to read:
All of the platform files are generated using a template system. Have a look at the files in [this directory](https://github.com/AlexvZyl/nordic.nvim/tree/main/lua/nordic/platforms) to see how it works. | |
All of the platform files are generated using a template system. Have a look at [this directory](https://github.com/AlexvZyl/nordic.nvim/tree/main/lua/nordic/platforms) to see how it works. |
-- stylua: ignore | ||
---@type table<string, {ext: string, url:string, subdir?: string}> | ||
M.platforms = { | ||
-- fish = { ext = "theme", url = "https://fishshell.com/docs/current/index.html" }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this supposed to be here?
---Simple string interpolation. | ||
--- | ||
---Example template: "${name} is ${age}" | ||
--- | ||
--- This function is taken from tokyonight. | ||
--- For more information see `platforms/init.lua` | ||
---@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) | ||
return vim.tbl_get(table, unpack(vim.split(w:sub(3, -2), '.', { plain = true }))) or w | ||
end) | ||
) | ||
end | ||
|
||
---Remove the hash (#) from the beginning of all color values in a table | ||
---@param colors table | ||
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 | ||
|
||
---Write a file and its contents to disk | ||
--- | ||
--- This function is taken from tokyonight. | ||
--- For more information see `platforms/init.lua` | ||
---@param path string | ||
---@param contents string | ||
function M.write(path, contents) | ||
vim.fn.mkdir(vim.fn.fnamemodify(path, ':h'), 'p') | ||
local fd = assert(io.open(path, 'w+')) | ||
fd:write(contents) | ||
fd:close() | ||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ugh, my eyes!
There should be a space between the comment marker and the text...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the annotations are fine, though.
I have ported Tokonights extra-generation system to work for nordic.nvim.
I have adjusted the code to make it more well suited for nordic.nvim, mainly simplifying it, since nordic.nvim doesn't have mutliple flavors, but reversing this to work for multiple flavors in the future wouldn't be a significant challange.
Why?
This would allow for easier creation of additional platforms, as well as help reduce inconsistencies between the different handwritten themes.
To-Do:
The one problem currently is that we would need to find a way to convert the hex color values to work for
iTerm2
andKonsole
since they use other formats.However, I don't think this will be a significant blocker.
iTerm2
andKonsole
/platforms
on each addition / change of one of the template filesNote on Licensing
Since Tokyonight is licensed under Apache License 2.0 we need to make sure we are in compliance with their License. I have added a note to the top of
platforms/init.lua
, but I am not sure if this is all that we require.It might be a good idea to add a
NOTICE
file.