Skip to content
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

chore(#192): generate from css class names #418

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,18 @@ jobs:
steps:
- uses: actions/checkout@v3

- uses: leafo/gh-actions-lua@v10
with:
luaVersion: "5.4"

- uses: leafo/gh-actions-luarocks@v4

- uses: rhysd/action-setup-vim@v1
with:
neovim: true

- run: luarocks install inspect 3.1.3

- name: make colors-check
run: make colors-check

82 changes: 51 additions & 31 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,43 @@ Thank you for your contribution!

Please name your commits and the PR simply e.g.

add .tex
update makefile icon
update .kt colors

## Order

Please ensure `icons_by_filename`, `icons_by_file_extension` and `filetypes` are ordered alphabetically, to prevent merge conflicts.
feat: add tex
fix: makefile icon
fix: update kt colors

## Prerequisites

Code is formatted using stylua and linted using luacheck.
### Style And Lint

You can install these with:
```sh
cargo install stylua
luarocks install luacheck
luarocks --local install luacheck
```

or via your OS package manager e.g. Arch linux:
or
```sh
pacman -S stylua
pacman -S luacheck
```

### Building

Generating icon lua code:
```sh
luarocks --local install inspect
```
or
```sh
yay -S lua-inspect
```

### Optional

[yq](https://github.com/mikefarah/yq) for updating nerd-fonts `glyphnames.lua`

```sh
pacman -S go-yq
```

## Building

Following your changes, please run:
Expand All @@ -39,11 +52,12 @@ make
```

This will:
1. Generate `lua/nvim-web-devicons/icons-*.lua`
1. `git clone --depth 1 https://github.com/lifepillar/vim-colortemplate.git vim-colortemplate` if necessary
1. Generate cterm colors
2. Generate light color variants
3. Check style
4. Lint
1. Generate light color variants
1. Check style
1. Lint

You can automatically fix any style issues via:
```sh
Expand All @@ -52,37 +66,43 @@ make style-fix

## Generate Colors

Add or update icons in `lua/nvim-web-devicons/icons-default.lua`

There are two tables where icons can be added:
1. icons_by_filename
2. icons_by_file_extension
Add or update icons in `src/by-*.lua`

Add the icon in table 1. if the icon is for a file that is always named that
way, for example `.gitconfig`. Add to table 2. if the icon is for all files
with an extension.
There are three tables in which icons can be added:
1. name: the icon is for a file that is always named that way, for example `.gitconfig`
1. ext: the icon is for all files with that extension
1. os: icon for an os or variant

Each icon must have the following (this is an example):

```lua
[".gitconfig"] = {
icon = "",
class = "seti-config",
color = "#41535b",
cterm_color = "0",
name = "GitConfig",
},
```
___Key/value pairs must appear in the same exact order!___

- `class` must be a vailid nerd-font class, see [cheat sheet](https://www.nerdfonts.com/cheat-sheet)
- `color` must contain a color in the html notation
- `cterm_color` must be below `color`, and it must contain a number (any number)
- the correct value for `cterm_color` will be generated by the script

Ensure your current working directory is the repo root.
Run `make`. This will:
- Update `cterm_color` based on `color`
- Generate `lua/nvim-web-devicons/icons-light.lua`
- Generate `lua/nvim-web-devicons/icons-*.lua` with an `icon` and `cterm_color`
- Generate `lua/nvim-web-devicons/icons-light.lua` from the above, with light `color` and `cterm_color`

Example generated icon:
```lua
[".gitconfig"] = {
class = "seti-config",
color = "#41535b",
cterm_color = "239",
icon = "",
name = "GitConfig"
},
```

Please commit both `lua/nvim-web-devicons/icons-default.lua` and `lua/nvim-web-devicons/icons-light.lua`
Please commit `src/by-*.lua`, `lua/nvim-web-devicons/icons-default.lua` and `lua/nvim-web-devicons/icons-light.lua`

## Test

Expand Down
17 changes: 15 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,20 @@ VIM_COLORTEMPLATE_VERSION = 2.2.3

all: colors style-check lint

colors: vim-colortemplate
# generate lua/nvim-web-devicons/icons-*.lua from src/by-*.lua
icons: src/glyphnames.lua
lua scripts/gen-icons.lua

# TODO #192 remove before merge
gen-check: colors
lua scripts/gen-check.lua

# only needed when updating nerd font classes
src/glyphnames.lua: src/glyphnames.json
yq '.METADATA' $(^) -oy
yq 'del(.METADATA)' $(^) -ol > $(@)

colors: vim-colortemplate icons
nvim \
--clean \
--headless \
Expand All @@ -29,4 +42,4 @@ lint:
clean:
rm -rf vim-colortemplate

.PHONY: all colors style-check style-fix lint
.PHONY: all icons colors style-check style-fix lint
Loading
Loading