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

feat(highlights): allow adding custom highlights #166

Merged
merged 18 commits into from
Apr 6, 2022

Conversation

aspeddro
Copy link
Contributor

@aspeddro aspeddro commented Mar 2, 2022

This PR add support to highlights

@akinsho
Copy link
Owner

akinsho commented Mar 31, 2022

@aspeddro sorry for the radio silence on this PR just been busy with a bunch of things it's next on my list to review though

@aspeddro
Copy link
Contributor Author

@akinsho, alright. I'm making some adjustments on highlights.

Copy link
Owner

@akinsho akinsho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aspeddro thanks for the PR had a read through and have made some comments on tweaks that I think would be good

Normal = {
guibg = colors.shade_color(colors.get_hex("Normal", "bg"), constants.shading_amount),
},
NormalFloat = {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aspeddro can these be snake_case rather than PascalCase, not sure why they are if it's because of converting the names, so they can be used in a map then you can use

  -- convert 'highlight_value' to 'HighlightValue' -> snake to pascal
  local formatted = name:gsub("_(.)", name.upper):gsub("^%l", string.upper)

I think this would look much tidier if the casing was consistent

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@akinsho keeping PascalCase makes mapping easier. One problem with the conversion is that it doesn't work for StatusLineNC, you would have to use status_line_n_c.

Another facility, passing the arguments to vim.highlights.create is made simpler.

lua/toggleterm/ui.lua Outdated Show resolved Hide resolved
lua/toggleterm/config.lua Outdated Show resolved Hide resolved
lua/toggleterm/config.lua Outdated Show resolved Hide resolved
return hi_target
end, vim.tbl_keys(term.highlights))

vim.api.nvim_win_set_option(term.window, "winhighlight", table.concat(highlights, ","))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved to window api

lua/toggleterm/colors.lua Outdated Show resolved Hide resolved
@akinsho
Copy link
Owner

akinsho commented Apr 6, 2022

@aspeddro thanks for your work on this 👍🏿. I made a couple of tweaks to the documentation and some formatting but perhaps most significantly I made sure only FloatBorder and NormalFloat are set when highlighting a floating window and specifically set the value of those windows to Normal since this change would be disruptive to users otherwise as they might suddenly find their terminal looking different

users usually copy paste these examples without inspecting the a la
stack overflow so I'd rather avoid a bunch of issues about the terminal
being all black etc.
Copy link
Owner

@akinsho akinsho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@akinsho akinsho changed the title feat(highlights): add custom highlights feat(highlights): allow adding custom highlights Apr 6, 2022
@akinsho akinsho merged commit 37b2527 into akinsho:master Apr 6, 2022
@will
Copy link

will commented Apr 13, 2022

I switch between light mode and dark mode depending on the time of day (the rose-pine theme if it matters). Neovim handles this automatically at startup by doing some magic to detect the background of the shell and setting background to dark or light automatically.

I did a manual bisect and before this patch, when I'd open a terminal, the background would always just match. However with this patch I get a dark background always.

Can you please point me in the right direction so I can always get a matching background?

@akinsho
Copy link
Owner

akinsho commented Apr 13, 2022

@will the difference since this change is that rather than depending directly on X highlight, the plugin creates its own and derives them at startup from the theme. If you'd like to make a specific highlight follow another e.g. keep the background of the terminal matching the Normal background then you can use the solution for a similar issue I mentioned in #196 (comment)

@will
Copy link

will commented Apr 13, 2022

Thanks @akinsho for the tip!

It ended up being for me:

highlights = { NormalFloat = { link = "NormalFloat" }, FloatBorder = {link = "FloatBorder"}},

to get it mostly working. Still need to do some tweaking I think, but now not super wrong.

Just for the future if anyone else comes across these comments:
I was able to find those keys by looking at lua print(vim.inspect(require("toggleterm.config").get("highlights"))) and seeing what was being used after all of the plugin setup/initialization

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants