|
| 1 | +local util = require "astrotheme.extras" |
| 2 | + |
| 3 | +local M = {} |
| 4 | + |
| 5 | +--- @param colors AstroThemePalette |
| 6 | +function M.generate(colors) |
| 7 | + local function normalize_colors(_colors) |
| 8 | + local new_colors = {} |
| 9 | + for k, v in pairs(_colors) do |
| 10 | + local new_color = v |
| 11 | + if type(v) == "string" and v:match "^#" then |
| 12 | + local hex = v:gsub("^#", "") |
| 13 | + new_color = string.format( |
| 14 | + "rgb(%d, %d, %d)", |
| 15 | + tonumber(hex:sub(1, 2), 16), |
| 16 | + tonumber(hex:sub(3, 4), 16), |
| 17 | + tonumber(hex:sub(5, 6), 16) |
| 18 | + ) |
| 19 | + elseif type(v) == "table" then |
| 20 | + new_color = normalize_colors(v) |
| 21 | + end |
| 22 | + new_colors[k] = new_color |
| 23 | + end |
| 24 | + return new_colors |
| 25 | + end |
| 26 | + return util.template( |
| 27 | + [[ |
| 28 | +# Import this theme as follows: |
| 29 | +# 1. Create a new profile for GNOME Terminal |
| 30 | +# 2. Copy the UUID of the new profile (bottom right corner of the preferences window) |
| 31 | +# 3. Replace <PROFILE_UUID> below with the copied UUID |
| 32 | +# 4. Execute `dconf load /org/gnome/terminal/legacy/profiles:/ < ${_style}.dconf` |
| 33 | +[:<PROFILE_UUID>] |
| 34 | +background-color='${ui.base}' |
| 35 | +cursor-background-color='${ui.text}' |
| 36 | +cursor-colors-set=true |
| 37 | +cursor-foreground-color='${ui.base}' |
| 38 | +foreground-color='${syntax.text}' |
| 39 | +highlight-background-color='${ui.selection}' |
| 40 | +highlight-colors-set=true |
| 41 | +highlight-foreground-color='${syntax.text}' |
| 42 | +palette=['${term.black}', '${term.red}', '${term.green}', '${term.yellow}', '${term.blue}', '${term.purple}', '${term.cyan}', '${term.white}', '${term.bright_black}', '${term.bright_red}', '${term.bright_green}', '${term.bright_yellow}', '${term.bright_blue}', '${term.bright_purple}', '${term.bright_cyan}', '${term.bright_white}'] |
| 43 | +use-theme-colors=false |
| 44 | +visible-name='${_style_name}' |
| 45 | +]], |
| 46 | + normalize_colors(colors) |
| 47 | + ) |
| 48 | +end |
| 49 | + |
| 50 | +return M |
0 commit comments