Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Highlight group separation #79

Closed
AlejandroSuero opened this issue Jun 16, 2024 · 1 comment
Closed

Highlight group separation #79

AlejandroSuero opened this issue Jun 16, 2024 · 1 comment
Labels
question Further information is requested

Comments

@AlejandroSuero
Copy link
Contributor

Question or Suggestion

To keep better separation in the file structure I thought of something to help separate highlight groups.

  • Right now:
# ./lua/cyberdream
├── colors.lua
├── config.lua
├── extra/
├── init.lua
├── theme.lua
├── treesitter.lua
└── util.lua
  • What I propose:
# ./lua/cyberdream
├── colors.lua
├── config.lua
├── extra/
├── init.lua
├── groups/
├──├──base.lua
├──├──treesitter.lua
├──├──telescope.lua
├──├──lsp.lua
├── treesitter.lua
├── theme.lua
└── util.lua

With this I think it will reduce the theme.lua file to simply hook up the highlight groups and change the palette variant and apply the config.theme options, so each group has it separation.

Example:

-- ./lua/cyberdream/groups/telescope
local function callback(opts)
  local t = util.get_palette()
  local borderless_telescope = opts.borderless_telescope
  local telescope_style = ""
  if type(opts.borderless_telescope) == "table" then
    borderless_telescope = not opts.borderless_telescope.border
    telescope_style = opts.borderless_telescope.style
  end
  local highlights = {
    TelescopeBorder = { fg = t.bgHighlight },
    TelescopePromptTitle = { fg = t.blue },
    TelescopeResultsTitle = { fg = t.cyan },
    TelescopePromptPrefix = { fg = t.pink },
    TelescopePreviewTitle = { fg = t.magenta },
    TelescopeSelection = { bg = t.bgHighlight },
    TelescopePromptCounter = { fg = t.pink },
    GrappleTitle = { fg = t.pink },
    GrappleFooter = { fg = t.grey },
    GrappleBorder = { fg = t.cyan },
  }
  if borderless_telescope then
    vim.tbl_deep_extend("force", highlights, {
        TelescopeBorder = { fg = t.bgAlt, bg = t.bgAlt },
        TelescopeNormal = { bg = t.bgAlt },
        TelescopePreviewBorder = { fg = t.bgAlt, bg = t.bgAlt },
        TelescopePreviewNormal = { bg = t.bgAlt },
        TelescopeResultsBorder = { fg = t.bgAlt, bg = t.bgAlt },
        TelescopeResultsNormal = { bg = t.bgAlt },
        TelescopeResultsTitle = { fg = t.bgAlt, bg = t.bgAlt },
        GrappleNormal = { bg = t.bgAlt }
        GrappleBorder = { fg = t.bgAlt, bg = t.bgAlt }
        GrappleTitle = { fg = t.bgAlt, bg = t.cyan }
    })
    if telescope_style == "nvchad" then
      vim.tbl_deep_extend("force", hihglights, {
        TelescopePreviewTitle = { fg = t.bgAlt, bg = t.green, bold = true },
        TelescopePromptBorder = { fg = t.bgHighlight, bg = t.bgHighlight },
        TelescopePromptNormal = { fg = t.fg, bg = t.bgHighlight },
        TelescopePromptPrefix = { fg = t.red, bg = t.bgHighlight },
        TelescopePromptTitle = { fg = t.bgAlt, bg = t.red, bold = true },
      })
    else
      vim.tbl_deep_extend("force", hihglights, {
         TelescopePreviewTitle = { fg = t.bgAlt, bg = t.green },
         TelescopePromptBorder = { fg = t.bgAlt, bg = t.bgAlt },
         TelescopePromptNormal = { fg = t.fg, bg = t.bgAlt },
         TelescopePromptPrefix = { fg = t.red, bg = t.bgAlt },
         TelescopePromptTitle = { fg = t.bgAlt, bg = t.red },
      })
    end
  end
  return highlights
end

return callback
-- ./lua/cyberdream/theme.lua
local opts = config.options

local theme = {}

theme.highligths = util.get_hl_groups(opts)

if opts.hide_fillchars then
  vim.opt.fillchars:append({
    horiz = " ",
    horizup = " ",
    horizdown = " ",
    vert = " ",
    vertleft = " ",
    vertright = " ",
    verthoriz = " ",
    eob = " ",
  })
else
  vim.opt.fillchars:append({
    eob = " ",
  })
end

-- Use #000000 for full transparency
if opts.transparent then
  theme.highlights.NotifyBackground = { bg = "#000000" }
end

local overrides = opts.theme.overrides or opts.theme.highlights
if type(overrides) == "function" then
 overrides = overrides(t)
end
-- Override highlights with user defined highlights
theme.highlights = vim.tbl_deep_extend("force", theme.highlights, overrides or {})

return theme

Of course, util functions that I wrote in the examples had to be implemented. Or pass the opts necessary and return a table instead of a callback function

@AlejandroSuero AlejandroSuero added the question Further information is requested label Jun 16, 2024
@scottmckendry
Copy link
Owner

I think this is something I would consider in the future. theme.lua is going to grow, that's inevitable. But for now, I think it's still within a manageable size. I have no problem grepping around the project as it stands.

I'm going to close this for now as 'won't fix' but with the intention to return and review at a later date when the theme.lua file is completely out of control 😄

TheItCrowdMossTheItCrowdGIF

@scottmckendry scottmckendry closed this as not planned Won't fix, can't repro, duplicate, stale Jun 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants