lbrayner / tint.nvim

Dim inactive windows in Neovim using window-local highlight namespaces.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

👓 tint.nvim

Tint inactive windows in Neovim using window-local highlight namespaces.

⚠️ Caveats

  • This feature was added via !13457. Your version of Neovim must include this change in order for this to work.
  • If you are noticing that certain colors are not being tinted, it is because likely they are defined after tint has been loaded and are "standalone" (i.e. not link).
    • tint applies changes to your colorscheme (i.e. the global highlight namespace with ns_id=0) when its setup function is called. From this then, if you are lazy-loading a different plugin that declares its own standalone highlight groups and loads after tint, they will likely not work as intended.
    • To help work around this (perhaps until a better solution is found), you can use require("tint").refresh() after a plugin loads if you are having issues with its colors.
  • Highlight groups that "replace" another in unfocused windows (e.g. NormalNC "replacing" Normal) must have both highlight groups defined. The *NC group is what will be tinted in unfocused windows.

🎬 Demo

tint

❔ About

Using window-local highlight namespaces, this plugin will iterate over each highlight group in the active colorscheme when the plugin is setup and either brighten or darken each value (based on what you configure) for inactive windows.

⚙️ Setup

See docs or :h tint for more details.

-- Default configuration
require("tint").setup()

Or if you want to override the defaults:

-- Override some defaults
require("tint").setup({
  tint = -45,  -- Darken colors, use a positive value to brighten
  saturation = 0.6,  -- Saturation to preserve
  transforms = require("tint").transforms.SATURATE_TINT,  -- Showing default behavior, but value here can be predefined set of transforms
  tint_background_colors = true,  -- Tint background portions of highlight groups
  highlight_ignore_patterns = { "WinSeparator", "Status.*" },  -- Highlight group patterns to ignore, see `string.find`
  window_ignore_function = function(winid)
    local bufid = vim.api.nvim_win_get_buf(winid)
    local buftype = vim.api.nvim_buf_get_option(bufid, "buftype")
    local floating = vim.api.nvim_win_get_config(winid).relative ~= ""

    -- Do not tint `terminal` or floating windows, tint everything else
    return buftype == "terminal" or floating
  end
})

Custom color transformations

See :h tint-transforms_api for more details.

If you come up with a cool set of transformations that you think might be useful to others, see the contributing guide on how you can make this available for others.

-- Handle transformations of highlight groups for the tinted namespace yourself
require("tint").setup({
  transforms = {
    require("tint.transforms").saturate(0.5),
    function(r, g, b, hl_group_info)
      print("Higlight group name: " .. hl_group_info.hl_group_name)

      local hl_def = vim.api.nvim_get_hl_by_name(hl_group_info.hl_group_name)
      print("Highlight group definition: " .. vim.inspect(hl_def))

      return r + 1, g + 1, b + 1
    end
  }
})

Bounding colors to some threshold

See :h tint-transforms-tint_with_threshold for more details.

Your colorscheme might have colors that are slightly different from your default editor background, and those that are much further away. You want the colors that are further away tinted more, and those that are closer tinted less. In order to achieve this, you can set some arbitrary "tint bounding color" and keep all tinted colors some threshold away from it.

Setting this to the background portion of your Normal highlight group is usually the easiest way to go.

require("tint").setup({
  transforms = {
    require("tint.transforms").tint_with_threshold(-100, "#1C1C1C", 150),  -- Try to tint by `-100`, but keep all colors at least `150` away from `#1C1C1C`
    require("tint.transforms").saturate(0.5),
  }
})

🖥️ API

See docs or :h tint for more details.

❤️ Acknowledgements

  • The harder part of the plugin to dim colors from StackOverflow
  • The general idea from Shade.nvim
  • bfredl for making everyones life better
  • williamboman for adding saturation to better mimic the way Shade looks

About

Dim inactive windows in Neovim using window-local highlight namespaces.

License:MIT License


Languages

Language:Lua 99.3%Language:Makefile 0.7%