|
| 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