Skip to content

Commit 0d61d54

Browse files
committed
feat(extras): Init lsd theme
1 parent fadfa8e commit 0d61d54

File tree

4 files changed

+124
-0
lines changed

4 files changed

+124
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ We've cooked up some wonderful extras to enhance your cyberdream experience. Mos
213213
- **[Kitty](extras/kitty/)**
214214
- **[Lazydocker](extras/lazydocker/)**
215215
- **[Lazygit](extras/lazygit/)**
216+
- **[lsd](extras/lsd/)**
216217
- **[Pywal](extras/pywal/)**
217218
- **[Rio](extras/rio/)**
218219
- **[Textmate/Bat/Sublime/Delta](extras/textmate/)**

extras/lsd/README.md

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
## Usage
2+
3+
### Approach 1
4+
5+
Create a directory `~/.config/lsd/themes` if it does not already exist.
6+
7+
Copy `cyberdream.yml` and/or `cyberdream-light.yml` to the directory.
8+
9+
Put the following config into the `config.yaml` under `~/.config/lsd`.
10+
11+
```yaml
12+
color:
13+
when: auto
14+
theme: custom
15+
```
16+
17+
Create a symlink to the theme.
18+
19+
```sh
20+
# Assuming you are in ~/.config/lsd
21+
ln -s themes/cyberdream.yaml colors.yaml
22+
```
23+
24+
### Approach 2
25+
26+
Copy the `cyberdream.yml` or `cyberdream-light.yml` directly under the `~/.config/lsd` directory
27+
and rename it to `colors.yaml`
28+
29+
Set the config according to [Approach 1](#approach-1).
30+
31+
---
32+
33+
See also: [lsd - README - Theme](https://github.com/lsd-rs/lsd#theme)

lua/cyberdream/extra/init.lua

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ M.extras = {
1313
kitty = { extension = "conf", name = "kitty" },
1414
lazydocker = { extension = "yml", name = "lazydocker" },
1515
lazygit = { extension = "yml", name = "lazygit" },
16+
lsd = { extension = "yml", name = "lsd" },
1617
pywal = { extension = "json", name = "pywal" },
1718
rio = { extension = "toml", name = "rio" },
1819
textmate = { extension = "tmTheme", name = "textmate" },

lua/cyberdream/extra/lsd.lua

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
local colors = require("cyberdream.colors")
2+
local util = require("cyberdream.util")
3+
4+
local M = {}
5+
6+
--- Generate cyberdream theme for https://github.com/lsd-rs/lsd
7+
--- @param variant string: Variation of the colorscheme to use.
8+
function M.generate(variant)
9+
function CreateDimColor(hex)
10+
return util.blend(hex, variant == "default" and colors[variant].bg or colors[variant].fg, 0.8)
11+
end
12+
13+
function HexToAnsi(hex)
14+
-- Remove the leading "#" if present
15+
hex = hex:gsub("#", "")
16+
17+
-- Extract the red, green, and blue components
18+
local r = tonumber(string.sub(hex, 1, 2), 16)
19+
local g = tonumber(string.sub(hex, 3, 4), 16)
20+
local b = tonumber(string.sub(hex, 5, 6), 16)
21+
22+
-- Normalize the RGB values to a range of 0-5
23+
local ansi_r = math.floor(r / 51)
24+
local ansi_g = math.floor(g / 51)
25+
local ansi_b = math.floor(b / 51)
26+
27+
-- Calculate the ANSI color code
28+
local ansi_code = 16 + (ansi_r * 36) + (ansi_g * 6) + ansi_b
29+
30+
return ansi_code
31+
end
32+
33+
-- Extend default hex colors with dimmed colors
34+
local extended_hex_colors = vim.fn.copy(colors[variant])
35+
for key, value in pairs(colors[variant]) do
36+
extended_hex_colors[key .. "Dim"] = CreateDimColor(value)
37+
end
38+
39+
-- Create Ansi colors from extended hex colors
40+
local ansi_colors = {}
41+
for key, value in pairs(extended_hex_colors) do
42+
ansi_colors[key] = HexToAnsi(value)
43+
end
44+
45+
local template = [==[
46+
user: ${cyan}
47+
group: ${blue}
48+
permission:
49+
read: ${green}
50+
write: ${yellow}
51+
exec: ${red}
52+
exec-sticky: ${purple}
53+
no-access: ${grey}
54+
octal: ${cyanDim}
55+
acl: ${cyanDim}
56+
context: ${cyan}
57+
date:
58+
hour-old: ${fgDim}
59+
day-old: ${grey}
60+
older: ${bgHighlight}
61+
size:
62+
none: ${grey}
63+
small: ${green}
64+
medium: ${yellow}
65+
large: ${orange}
66+
inode:
67+
valid: ${magenta}
68+
invalid: ${grey}
69+
links:
70+
valid: ${magenta}
71+
invalid: ${grey}
72+
tree-edge: ${grey}
73+
git-status:
74+
default: ${grey}
75+
unmodified: ${grey}
76+
ignored: ${grey}
77+
new-in-index: ${greenDim}
78+
new-in-workdir: ${greenDim}
79+
typechange: ${yellowDim}
80+
deleted: ${redDim}
81+
renamed: ${greenDim}
82+
modified: ${yellowDim}
83+
conflicted: ${redDim}
84+
]==]
85+
86+
return util.parse_extra_template(template, ansi_colors)
87+
end
88+
89+
return M

0 commit comments

Comments
 (0)