|
1 | | -local utils = require("heirline.utils") |
2 | | - |
3 | 1 | local M = {} |
4 | 2 |
|
| 3 | +---If highlight is a string, use it as highlight name and extract the |
| 4 | +-- properties from the highlight. |
| 5 | +-- Borrowed from the feline codebase. |
| 6 | +local function get_hl_properties(hlname) |
| 7 | + local hl = vim.api.nvim_get_hl_by_name(hlname, true) |
| 8 | + local styles = {} |
| 9 | + |
| 10 | + for k, v in ipairs(hl) do |
| 11 | + if v == true then |
| 12 | + styles[#styles + 1] = k |
| 13 | + end |
| 14 | + end |
| 15 | + |
| 16 | + return { |
| 17 | + name = hlname, |
| 18 | + fg = hl.foreground and string.format("#%06x", hl.foreground), |
| 19 | + bg = hl.background and string.format("#%06x", hl.background), |
| 20 | + style = next(styles) and table.concat(styles, ",") or "NONE", |
| 21 | + } |
| 22 | +end |
| 23 | + |
5 | 24 | M.force_inactive = { --{{{ |
6 | 25 | filetypes = { |
7 | 26 | "NvimTree", |
@@ -34,12 +53,12 @@ M.colors = {--{{{ |
34 | 53 | light_bg = "#222930", |
35 | 54 | light_bg2 = "#1d242b", |
36 | 55 | mid_bg = "#2B3033", |
37 | | - orange = utils.get_highlight("DiagnosticWarn").fg, |
38 | | - cyan = utils.get_highlight("Special").fg, |
39 | | - folder = utils.get_highlight("NvimTreeFolderIcon").fg, |
40 | | - git_add = utils.get_highlight("DiffAdd").fg, |
41 | | - git_del = utils.get_highlight("DiffDelete").bg, |
42 | | - git_change = utils.get_highlight("DiffChange").fg, |
| 56 | + orange = get_hl_properties("DiagnosticWarn").fg, |
| 57 | + cyan = get_hl_properties("Special").fg, |
| 58 | + folder = get_hl_properties("NvimTreeFolderIcon").fg, |
| 59 | + git_add = get_hl_properties("DiffAdd").fg, |
| 60 | + git_del = get_hl_properties("DiffDelete").bg, |
| 61 | + git_change = get_hl_properties("DiffChange").fg, |
43 | 62 | } |
44 | 63 | --}}} |
45 | 64 | -- stylua: ignore |
|
0 commit comments