Skip to content

Commit

Permalink
feat: theme file icons (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
uncenter authored Jun 17, 2024
1 parent 4599abe commit 9bfdccc
Show file tree
Hide file tree
Showing 11 changed files with 2,321 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.luarocks/
lua_modules/
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"deno.enable": true,
"[typescript]": {
"editor.defaultFormatter": "denoland.vscode-deno"
}
}
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,15 @@
## Usage

1. Copy the theme file of your choice from `themes/` to your [Yazi configuration directory](https://yazi-rs.github.io/docs/configuration/overview) with the filename `theme.toml`.
2. For Catppuccin-themed syntax highlighting in the preview pane:
- Download the `.tmTheme` file of your choice from [catppuccin/bat](https://github.com/catppuccin/bat).
- Replace the path of `syntect_theme` (line 27) with the path of your downloaded `.tmTheme` file.
2. For Catppuccin-themed syntax highlighting in the preview pane:
- Download the `.tmTheme` file of your choice from [catppuccin/bat](https://github.com/catppuccin/bat).
- Replace the path of `syntect_theme` (line 27) with the path of your downloaded `.tmTheme` file.

## Contributing

To contribute to this port you will need the following dependencies installed: [Whiskers](https://github.com/catppuccin/whiskers), [Deno](https://docs.deno.com/runtime/manual/getting_started/installation), [Lua](https://lua.org/start.html), [LuaRocks](https://luarocks.org/), and the [`dkjson` LuaRocks module](https://luarocks.org/modules/dhkolf/dkjson).

Edit `yazi.tera` to make changes to the theme. Run `just build` to build the output themes (including the `-with-icons` variants) in `themes/`.

## 💝 Thanks to

Expand Down
9 changes: 9 additions & 0 deletions deno.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"tasks": {
"icons": "deno run -A icons.ts"
},
"imports": {
"@catppuccin/palette": "https://esm.sh/@catppuccin/palette@1.2.0",
"ctpvert": "https://deno.land/x/ctpvert@v0.4.0/main.ts"
}
}
13 changes: 13 additions & 0 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 50 additions & 0 deletions icons.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { closest } from "ctpvert";
import { type ColorName, flavorEntries, flavors } from "@catppuccin/palette";

const { icons_by_filename, icons_by_file_extension } = JSON.parse(
Deno.args.join("")!,
) as Record<
string,
Record<
string,
{
name: string;
icon: string;
cterm_color: string;
color: string;
}
>
>;

for (const [identifier] of flavorEntries) {
let output = `[icon]\nprepend_rules = [\n`;

for (
const [filename, { color, icon }] of Object.entries(icons_by_filename)
.sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0)
) {
const match = closest(color);
output += ` { name = "${filename}", text = "${icon}", fg = "${
flavors[identifier].colors[match[identifier].name as ColorName].hex
}" },\n`;
}

for (
const [ext, { color, icon }] of Object.entries(icons_by_file_extension)
.sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0)
) {
const match = closest(color);
output += ` { name = "*.${ext}", text = "${icon}", fg = "${
flavors[identifier].colors[match[identifier].name as ColorName].hex
}" },\n`;
}

output += "]\n";

const dist = `themes/${identifier}.toml`;
const theme = await Deno.readTextFile(dist);
await Deno.writeTextFile(
dist,
theme + "\n" + output,
);
}
8 changes: 8 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,12 @@ _default:
@just --list

build:
#!/usr/bin/env bash
whiskers yazi.tera
# Fetch file associations, colors, icons.
data="$(curl https://raw.githubusercontent.com/nvim-tree/nvim-web-devicons/master/lua/nvim-web-devicons/icons-default.lua | sed 's/return {/local tbl = {/g')"
# Create a script that ends with the contents of it being printed as JSON.
script="$data
print(require('dkjson').encode(tbl, { indent = false }))"
# Run the Deno script to find the closest matching colors and write the files.
deno task icons $(echo "$script" | lua)
Loading

0 comments on commit 9bfdccc

Please sign in to comment.