From a425e0294218fd5fff68cf10b8ce96bc95d0b8ad Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Tue, 20 Apr 2021 12:19:20 +0200 Subject: [PATCH] feat: darker sidebars --- README.md | 59 ++++++++++--------------------- colors/tokyonight.vim | 7 ---- lua/lualine/themes/tokyonight.lua | 8 ++--- lua/tokyonight/config.lua | 5 +++ lua/tokyonight/util.lua | 33 +++++++++++++++-- 5 files changed, 59 insertions(+), 53 deletions(-) diff --git a/README.md b/README.md index 730fd43..b11542a 100644 --- a/README.md +++ b/README.md @@ -70,49 +70,28 @@ require('lualine').setup { The theme comes in two styles, `storm` and a darker variant `night`. -Lua: +| Option | Default | Description | +| ----------------------------------- | --------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| tokyonight_style | `"storm"` | The theme comes in two styles, `"storm"` and a darker variant `"night"`. | +| tokyonight_terminal_colors | `true` | Configure the colors used when opening a `:terminal` in Neovim | +| tokyonight_italic_comments | `true` | Make comments italic | +| tokyonight_italic_keywords | `true` | Make keywords italic | +| tokyonight_italic_functions | `false` | Make functions italic | +| tokyonight_transparent | `false` | Enable this to disable setting the background color | +| tokyonight_hide_inactive_statusline | `false` | Enabling this option, will hide inactive statuslines and replace them with a thin border instead. Should work with the standard **StatusLine** and **LuaLine**. | +| tokyonight_sidebars | `{}` | Set a darker background on sidebar-like windows. For example: `["quickfix", "__vista__", "terminal"]` | + ```lua --- The theme comes in two styles, "storm" and a darker variant "night". -vim.g.tokyonight_style = "storm" - --- Comments are italicized by default -vim.g.tokyonight_italic_comments = true - --- Keywords are italicized by default -vim.g.tokyonight_italic_keywords = true - --- Functions are not italicized by default -vim.g.tokyonight_italic_functions = false - --- Enable this to disable setting the background color -vim.g.tokyonight_transparent = false - --- Enabling this option, will hide inactive statuslines and --- replace them with a thin border instead. Should work with --- the standard `StatusLine` and `LuaLine`. -vim.g.tokyonight_hide_inactive_statusline = true +-- Example config in Lua +vim.g.tokyonight_style = "night" +vim.g.tokyonight_italic_functions = true +vim.g.tokyonight_sidebars = { "quickfix", "__vista__", "terminal" } ``` -Vim Script: ```vim -" The theme comes in two styles, 'storm' and a darker variant 'night'. -let g:tokyonight_style = "storm" - -" Comments are italicized by default -let g:tokyonight_italic_comments = 1 - -" Keywords are italicized by default -let g:tokyonight_italic_keywords = 1 - -" Functions are not italicized by default -let g:tokyonight_italic_functions = 0 - -" Enable this to disable setting the background color -let g:tokyonight_transparent = 0 - -" Enabling this option, will hide inactive statuslines and -" replace them with a thin border instead. Should work with -" the standard `StatusLine` and `LuaLine`. -let g:tokyonight_hide_inactive_statusline = 1 +" Example config in VimScript +let g:tokyonight_style = "night" +let g:tokyonight_italic_functions = true +let g:tokyonight_sidebars = [ "quickfix", "__vista__", "terminal" ] ``` diff --git a/colors/tokyonight.vim b/colors/tokyonight.vim index e214080..dcb36ea 100644 --- a/colors/tokyonight.vim +++ b/colors/tokyonight.vim @@ -7,10 +7,3 @@ lua package.loaded['tokyonight.util'] = nil lua package.loaded['tokyonight.config'] = nil lua require('tokyonight').colorscheme() - -augroup TokyoNight - autocmd! - autocmd BufWritePost */lua/tokyonight/** nested colorscheme tokyonight -augroup end - -" autocmd BufWinEnter quickfix setlocal winhighlight=Normal:NormalSB,SignColumn:SignColumnSB \ No newline at end of file diff --git a/lua/lualine/themes/tokyonight.lua b/lua/lualine/themes/tokyonight.lua index 8ff3094..7d3f548 100644 --- a/lua/lualine/themes/tokyonight.lua +++ b/lua/lualine/themes/tokyonight.lua @@ -11,8 +11,8 @@ tokyonight.normal = { } tokyonight.insert = { - a = { bg = colors.green3, fg = colors.bg_dark }, - b = { bg = colors.fg_gutter, fg = colors.green3 }, + a = { bg = colors.green, fg = colors.bg_dark }, + b = { bg = colors.fg_gutter, fg = colors.green }, c = c, } @@ -23,8 +23,8 @@ tokyonight.command = { } tokyonight.visual = { - a = { bg = colors.magenta, fg = colors.bg_dark }, - b = { bg = colors.fg_gutter, fg = colors.magenta }, + a = { bg = colors.blue0, fg = colors.fg }, + b = { bg = colors.fg_gutter, fg = colors.fg }, c = c, } diff --git a/lua/tokyonight/config.lua b/lua/tokyonight/config.lua index 7ec6e5d..0bebce3 100644 --- a/lua/tokyonight/config.lua +++ b/lua/tokyonight/config.lua @@ -1,6 +1,9 @@ ---@class Config local config +-- shim vim for kitty and other generators +vim = vim or { g = {} } + local function opt(key, default) key = "tokyonight_" .. key if vim.g[key] == nil then return default end @@ -16,6 +19,8 @@ config = { functionStyle = opt("italic_functions", false) and "italic" or "NONE", hideInactiveStatusline = opt("hide_inactive_statusline", false), terminalColors = opt("terminal_colors", true), + sidebars = opt("sidebars", {}), + dev = opt("dev", false), } return config diff --git a/lua/tokyonight/util.lua b/lua/tokyonight/util.lua index e641be9..642e0e3 100644 --- a/lua/tokyonight/util.lua +++ b/lua/tokyonight/util.lua @@ -31,8 +31,8 @@ function util.blend(fg, bg, alpha) return string.format("#%02X%02X%02X", blendChannel(1), blendChannel(2), blendChannel(3)) end -function util.darken(hex, amount, bg) return blend(hex, bg or util.bg, math.abs(amount)) end -function util.lighten(hex, amount, fg) return blend(hex, fg or util.fg, math.abs(amount)) end +function util.darken(hex, amount, bg) return util.blend(hex, bg or util.bg, math.abs(amount)) end +function util.lighten(hex, amount, fg) return util.blend(hex, fg or util.fg, math.abs(amount)) end function util.highlight(group, color) if color.fg then util.colorsUsed[color.fg] = true end @@ -59,6 +59,34 @@ function util.debug(colors) end end +---@param config Config +function util.autocmds(config) + vim.cmd [[augroup TokyoNight]] + vim.cmd [[ autocmd!]] + if config.dev then + vim.cmd [[ autocmd BufWritePost */lua/tokyonight/** nested colorscheme tokyonight]] + end + for _, sidebar in ipairs(config.sidebars) do + if sidebar == "terminal" then + vim.cmd [[ autocmd TermOpen * setlocal winhighlight=Normal:NormalSB,SignColumn:SignColumnSB]] + else + vim.cmd([[ autocmd BufWinEnter ]] .. sidebar .. + [[ setlocal winhighlight=Normal:NormalSB,SignColumn:SignColumnSB]]) + end + end + vim.cmd [[augroup end]] +end + +-- Simple string interpolation. +-- +-- Example template: "${name} is ${value}" +-- +---@param str string template string +---@param table table key value pairs to replace in the string +function util.template(str, table) + return (str:gsub("($%b{})", function(w) return table[w:sub(3, -2)] or w end)) +end + function util.syntax(syntax) for group, colors in pairs(syntax) do util.highlight(group, colors) end end ---@param colors ColorScheme @@ -107,6 +135,7 @@ function util.load(theme) async = vim.loop.new_async(vim.schedule_wrap(function() util.terminal(theme.colors) util.syntax(theme.plugins) + util.autocmds(theme.config) async:close() end)) async:send()