Merge pull request #191 from folke/refactor
feat: big refactor of the theme
This commit is contained in:
96
README.md
96
README.md
@@ -107,56 +107,68 @@ The theme comes in three styles, `storm`, a darker variant `night` and `day`.
|
||||
|
||||
The **day** style will be used if:
|
||||
|
||||
- `vim.g.tokyonight_style = "day"`
|
||||
- `{ style = "day"}` was passed to `setup(options)`
|
||||
- or `vim.o.background = "light"`
|
||||
|
||||
| Option | Default | Description |
|
||||
| ----------------------------------- | --------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| tokyonight_style | `"storm"` | The theme comes in three styles, `storm`, a darker variant `night` and `day`. |
|
||||
| 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_italic_variables | `false` | Make variables and identifiers 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: `["qf", "vista_kind", "terminal", "packer"]` |
|
||||
| tokyonight_transparent_sidebar | `false` | Sidebar like windows like `NvimTree` get a transparent background |
|
||||
| tokyonight_dark_sidebar | `true` | Sidebar like windows like `NvimTree` get a darker background |
|
||||
| tokyonight_dark_float | `true` | Float windows like the lsp diagnostics windows get a darker background. |
|
||||
| tokyonight_colors | `{}` | You can override specific color groups to use other groups or a hex color |
|
||||
| tokyonight_day_brightness | `0.3` | Adjusts the brightness of the colors of the **Day** style. Number between 0 and 1, from dull to vibrant colors |
|
||||
| tokyonight_lualine_bold | `false` | When `true`, section headers in the lualine theme will be bold |
|
||||
TokyoNight will use the default options, unless you call `setup`.
|
||||
|
||||
```lua
|
||||
require("tokyonight").setup({
|
||||
-- your configuration comes here
|
||||
-- or leave it empty to use the default settings
|
||||
style = "storm", -- The theme comes in three styles, `storm`, a darker variant `night` and `day`
|
||||
transparent = false, -- Enable this to disable setting the background color
|
||||
terminal_colors = true, -- Configure the colors used when opening a `:terminal` in Neovim |
|
||||
styles = {
|
||||
-- Style to be applied to different syntax groups
|
||||
-- Value is any valid attr-list value `:help attr-list`
|
||||
comments = "italic",
|
||||
keywords = "italic",
|
||||
functions = "NONE",
|
||||
variables = "NONE",
|
||||
-- Background styles. Can be "dark", "transparent" or "normal"
|
||||
sidebars = "dark", -- style for sidebars, see below
|
||||
floats = "dark", -- style for floating windows
|
||||
},
|
||||
sidebars = { "qf", "help" }, -- Set a darker background on sidebar-like windows. For example: `["qf", "vista_kind", "terminal", "packer"]` |
|
||||
day_brightness = 0.3, -- Adjusts the brightness of the colors of the **Day** style. Number between 0 and 1, from dull to vibrant colors |
|
||||
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**. |
|
||||
lualine_bold = false, -- When `true`, section headers in the lualine theme will be bold |
|
||||
|
||||
--- You can override specific color groups to use other groups or a hex color |
|
||||
--- fucntion will be called with a ColorScheme table
|
||||
---@param colors ColorScheme
|
||||
on_colors = function(colors) end,
|
||||
|
||||
--- You can override specific highlights to use other groups or a hex color |
|
||||
--- fucntion will be called with a Highlights and ColorScheme table
|
||||
---@param highlights Highlights
|
||||
---@param colors ColorScheme
|
||||
on_highlights = function(highlights, colors) end,
|
||||
}
|
||||
```
|
||||
|
||||
```lua
|
||||
-- Example config in Lua
|
||||
vim.g.tokyonight_style = "night"
|
||||
vim.g.tokyonight_italic_functions = true
|
||||
vim.g.tokyonight_sidebars = { "qf", "vista_kind", "terminal", "packer" }
|
||||
|
||||
-- Change the "hint" color to the "orange" color, and make the "error" color bright red
|
||||
vim.g.tokyonight_colors = { hint = "orange", error = "#ff0000" }
|
||||
require("tokyonight").setup({
|
||||
-- use the night style
|
||||
style = "night",
|
||||
-- disable italic for functions
|
||||
styles = {
|
||||
functions = "NONE"
|
||||
},
|
||||
sidebars = { "qf", "vista_kind", "terminal", "packer" },
|
||||
-- Change the "hint" color to the "orange" color, and make the "error" color bright red
|
||||
on_colors = function(colors) {
|
||||
colors.hint = colors.orange
|
||||
colors.error = "#ff0000"
|
||||
}
|
||||
})
|
||||
|
||||
-- Load the colorscheme
|
||||
vim.cmd[[colorscheme tokyonight]]
|
||||
```
|
||||
|
||||
```vim
|
||||
" Example config in VimScript
|
||||
let g:tokyonight_style = "night"
|
||||
let g:tokyonight_italic_functions = 1
|
||||
let g:tokyonight_sidebars = [ "qf", "vista_kind", "terminal", "packer" ]
|
||||
|
||||
" Change the "hint" color to the "orange" color, and make the "error" color bright red
|
||||
let g:tokyonight_colors = {
|
||||
\ 'hint': 'orange',
|
||||
\ 'error': '#ff0000'
|
||||
\ }
|
||||
|
||||
" Load the colorscheme
|
||||
colorscheme tokyonight
|
||||
```
|
||||
|
||||
### Making `undercurls` work properly in **Tmux**
|
||||
|
||||
To have undercurls show up and in color, add the following to your **Tmux** config file:
|
||||
@@ -177,7 +189,7 @@ Extra color configs for **Kitty**, **Alacritty**, **Fish**, **WezTerm**, **iTerm
|
||||
You can easily use the color palette for other plugins inside your Neovim config:
|
||||
|
||||
```lua
|
||||
local colors = require("tokyonight.colors").setup({}) -- pass in any of the config options as explained above
|
||||
local colors = require("tokyonight.colors").setup() -- pass in any of the config options as explained above
|
||||
local util = require("tokyonight.util")
|
||||
|
||||
aplugin.background = colors.bg_dark
|
||||
@@ -192,5 +204,5 @@ How to add a new extra template:
|
||||
|
||||
1. create a file like `lua/tokyonight/extra/cool-app.lua`
|
||||
2. add the name and output file extension to the `extras` table in `lua/tokyonight/extra/init.lua`
|
||||
3. in the root directory, run `$ lua lua/tokyonight/extra/init.lua` to generate / update extra themes
|
||||
3. in Nvim, run `:lua require("tokyonight.extra").setup()` to generate / update extra themes
|
||||
4. commit the newly created themes under `extra/`
|
||||
|
||||
1
colors/tokyonight-day.lua
Normal file
1
colors/tokyonight-day.lua
Normal file
@@ -0,0 +1 @@
|
||||
require("tokyonight").load({ style = "day" })
|
||||
1
colors/tokyonight-night.lua
Normal file
1
colors/tokyonight-night.lua
Normal file
@@ -0,0 +1 @@
|
||||
require("tokyonight").load({ style = "night" })
|
||||
1
colors/tokyonight-storm.lua
Normal file
1
colors/tokyonight-storm.lua
Normal file
@@ -0,0 +1 @@
|
||||
require("tokyonight").load({ style = "storm" })
|
||||
1
colors/tokyonight.lua
Normal file
1
colors/tokyonight.lua
Normal file
@@ -0,0 +1 @@
|
||||
require("tokyonight").load()
|
||||
@@ -1,9 +0,0 @@
|
||||
" clear cache so this reloads changes.
|
||||
" useful for development
|
||||
" lua package.loaded['tokyonight'] = nil
|
||||
" lua package.loaded['tokyonight.theme'] = nil
|
||||
" lua package.loaded['tokyonight.colors'] = nil
|
||||
" lua package.loaded['tokyonight.util'] = nil
|
||||
lua package.loaded['tokyonight.config'] = nil
|
||||
|
||||
lua require('tokyonight').colorscheme()
|
||||
@@ -153,56 +153,68 @@ The theme comes in three styles, `storm`, a darker variant `night` and `day`.
|
||||
The **day** style will be used if:
|
||||
|
||||
|
||||
- `vim.g.tokyonight_style = "day"`
|
||||
- `{ style = "day"}` was passed to `setup(options)`
|
||||
- or `vim.o.background = "light"`
|
||||
|
||||
|
||||
│ Option │ Default │ Description │
|
||||
│tokyonight_style │"storm" │The theme comes in three styles, storm, a darker variant night and day. │
|
||||
│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_italic_variables │false │Make variables and identifiers 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: ["qf", "vista_kind", "terminal", "packer"] │
|
||||
│tokyonight_transparent_sidebar │false │Sidebar like windows like NvimTree get a transparent background │
|
||||
│tokyonight_dark_sidebar │true │Sidebar like windows like NvimTree get a darker background │
|
||||
│tokyonight_dark_float │true │Float windows like the lsp diagnostics windows get a darker background. │
|
||||
│tokyonight_colors │{} │You can override specific color groups to use other groups or a hex color │
|
||||
│tokyonight_day_brightness │0.3 │Adjusts the brightness of the colors of the **Day** style. Number between 0 and 1, from dull to vibrant colors │
|
||||
│tokyonight_lualine_bold │false │When true, section headers in the lualine theme will be bold │
|
||||
|
||||
TokyoNight will use the default options, unless you call `setup`.
|
||||
|
||||
>
|
||||
-- Example config in Lua
|
||||
vim.g.tokyonight_style = "night"
|
||||
vim.g.tokyonight_italic_functions = true
|
||||
vim.g.tokyonight_sidebars = { "qf", "vista_kind", "terminal", "packer" }
|
||||
require("tokyonight").setup({
|
||||
-- your configuration comes here
|
||||
-- or leave it empty to use the default settings
|
||||
style = "storm", -- The theme comes in three styles, `storm`, a darker variant `night` and `day`
|
||||
transparent = false, -- Enable this to disable setting the background color
|
||||
terminal_colors = true, -- Configure the colors used when opening a `:terminal` in Neovim |
|
||||
styles = {
|
||||
-- Style to be applied to different syntax groups
|
||||
-- Value is any valid attr-list value `:help attr-list`
|
||||
comments = "italic",
|
||||
keywords = "italic",
|
||||
functions = "NONE",
|
||||
variables = "NONE",
|
||||
-- Background styles. Can be "dark", "transparent" or "normal"
|
||||
sidebars = "dark", -- style for sidebars, see below
|
||||
floats = "dark", -- style for floating windows
|
||||
},
|
||||
sidebars = { "qf", "help" }, -- Set a darker background on sidebar-like windows. For example: `["qf", "vista_kind", "terminal", "packer"]` |
|
||||
day_brightness = 0.3, -- Adjusts the brightness of the colors of the **Day** style. Number between 0 and 1, from dull to vibrant colors |
|
||||
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**. |
|
||||
lualine_bold = false, -- When `true`, section headers in the lualine theme will be bold |
|
||||
|
||||
-- Change the "hint" color to the "orange" color, and make the "error" color bright red
|
||||
vim.g.tokyonight_colors = { hint = "orange", error = "#ff0000" }
|
||||
--- You can override specific color groups to use other groups or a hex color |
|
||||
--- fucntion will be called with a ColorScheme table
|
||||
---@param colors ColorScheme
|
||||
on_colors = function(colors) end,
|
||||
|
||||
-- Load the colorscheme
|
||||
vim.cmd[[colorscheme tokyonight]]
|
||||
--- You can override specific highlights to use other groups or a hex color |
|
||||
--- fucntion will be called with a Highlights and ColorScheme table
|
||||
---@param highlights Highlights
|
||||
---@param colors ColorScheme
|
||||
on_highlights = function(highlights, colors) end,
|
||||
}
|
||||
<
|
||||
|
||||
|
||||
>
|
||||
" Example config in VimScript
|
||||
let g:tokyonight_style = "night"
|
||||
let g:tokyonight_italic_functions = 1
|
||||
let g:tokyonight_sidebars = [ "qf", "vista_kind", "terminal", "packer" ]
|
||||
-- Example config in Lua
|
||||
require("tokyonight").setup({
|
||||
-- use the night style
|
||||
style = "night",
|
||||
-- disable italic for functions
|
||||
styles = {
|
||||
functions = "NONE"
|
||||
},
|
||||
sidebars = { "qf", "vista_kind", "terminal", "packer" },
|
||||
-- Change the "hint" color to the "orange" color, and make the "error" color bright red
|
||||
on_colors = function(colors) {
|
||||
colors.hint = colors.orange
|
||||
colors.error = "#ff0000"
|
||||
}
|
||||
})
|
||||
|
||||
" Change the "hint" color to the "orange" color, and make the "error" color bright red
|
||||
let g:tokyonight_colors = {
|
||||
\ 'hint': 'orange',
|
||||
\ 'error': '#ff0000'
|
||||
\ }
|
||||
|
||||
" Load the colorscheme
|
||||
colorscheme tokyonight
|
||||
-- Load the colorscheme
|
||||
vim.cmd[[colorscheme tokyonight]]
|
||||
<
|
||||
|
||||
|
||||
@@ -234,7 +246,7 @@ You can easily use the color palette for other plugins inside your Neovim
|
||||
config:
|
||||
|
||||
>
|
||||
local colors = require("tokyonight.colors").setup({}) -- pass in any of the config options as explained above
|
||||
local colors = require("tokyonight.colors").setup() -- pass in any of the config options as explained above
|
||||
local util = require("tokyonight.util")
|
||||
|
||||
aplugin.background = colors.bg_dark
|
||||
@@ -252,7 +264,7 @@ How to add a new extra template:
|
||||
|
||||
1. create a file like `lua/tokyonight/extra/cool-app.lua`
|
||||
2. add the name and output file extension to the `extras` table in `lua/tokyonight/extra/init.lua`
|
||||
3. in the root directory, run `$ lua lua/tokyonight/extra/init.lua` to generate / update extra themes
|
||||
3. in Nvim, run `:lua require("tokyonight.extra").setup()` to generate / update extra themes
|
||||
4. commit the newly created themes under `extra/`
|
||||
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ cursor_text_color #e1e2e7
|
||||
|
||||
# Tabs
|
||||
active_tab_background #2e7de9
|
||||
active_tab_foreground #d4d6e4
|
||||
active_tab_foreground #e9e9ec
|
||||
inactive_tab_background #c4c8da
|
||||
inactive_tab_foreground #8990b3
|
||||
#tab_bar_background #e9e9ed
|
||||
@@ -44,4 +44,4 @@ color15 #3760bf
|
||||
# extended colors
|
||||
color16 #b15c00
|
||||
color17 #c64343
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ cursor_text_color #1a1b26
|
||||
|
||||
# Tabs
|
||||
active_tab_background #7aa2f7
|
||||
active_tab_foreground #1f2335
|
||||
active_tab_foreground #16161e
|
||||
inactive_tab_background #292e42
|
||||
inactive_tab_foreground #545c7e
|
||||
#tab_bar_background #15161E
|
||||
@@ -44,4 +44,4 @@ color15 #c0caf5
|
||||
# extended colors
|
||||
color16 #ff9e64
|
||||
color17 #db4b4b
|
||||
|
||||
|
||||
@@ -44,4 +44,4 @@ color15 #c0caf5
|
||||
# extended colors
|
||||
color16 #ff9e64
|
||||
color17 #db4b4b
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ set -g pane-active-border-style "fg=#2e7de9"
|
||||
set -g status "on"
|
||||
set -g status-justify "left"
|
||||
|
||||
set -g status-style "fg=#2e7de9,bg=#d4d6e4"
|
||||
set -g status-style "fg=#2e7de9,bg=#e9e9ec"
|
||||
|
||||
set -g status-left-length "100"
|
||||
set -g status-right-length "100"
|
||||
@@ -21,12 +21,12 @@ set -g status-right-length "100"
|
||||
set -g status-left-style NONE
|
||||
set -g status-right-style NONE
|
||||
|
||||
set -g status-left "#[fg=#e9e9ed,bg=#2e7de9,bold] #S #[fg=#2e7de9,bg=#d4d6e4,nobold,nounderscore,noitalics]"
|
||||
set -g status-right "#[fg=#d4d6e4,bg=#d4d6e4,nobold,nounderscore,noitalics]#[fg=#2e7de9,bg=#d4d6e4] #{prefix_highlight} #[fg=#a8aecb,bg=#d4d6e4,nobold,nounderscore,noitalics]#[fg=#2e7de9,bg=#a8aecb] %Y-%m-%d %I:%M %p #[fg=#2e7de9,bg=#a8aecb,nobold,nounderscore,noitalics]#[fg=#e9e9ed,bg=#2e7de9,bold] #h "
|
||||
set -g status-left "#[fg=#e9e9ed,bg=#2e7de9,bold] #S #[fg=#2e7de9,bg=#e9e9ec,nobold,nounderscore,noitalics]"
|
||||
set -g status-right "#[fg=#e9e9ec,bg=#e9e9ec,nobold,nounderscore,noitalics]#[fg=#2e7de9,bg=#e9e9ec] #{prefix_highlight} #[fg=#a8aecb,bg=#e9e9ec,nobold,nounderscore,noitalics]#[fg=#2e7de9,bg=#a8aecb] %Y-%m-%d %I:%M %p #[fg=#2e7de9,bg=#a8aecb,nobold,nounderscore,noitalics]#[fg=#e9e9ed,bg=#2e7de9,bold] #h "
|
||||
|
||||
setw -g window-status-activity-style "underscore,fg=#6172b0,bg=#d4d6e4"
|
||||
setw -g window-status-activity-style "underscore,fg=#6172b0,bg=#e9e9ec"
|
||||
setw -g window-status-separator ""
|
||||
setw -g window-status-style "NONE,fg=#6172b0,bg=#d4d6e4"
|
||||
setw -g window-status-format "#[fg=#d4d6e4,bg=#d4d6e4,nobold,nounderscore,noitalics]#[default] #I #W #F #[fg=#d4d6e4,bg=#d4d6e4,nobold,nounderscore,noitalics]"
|
||||
setw -g window-status-current-format "#[fg=#d4d6e4,bg=#a8aecb,nobold,nounderscore,noitalics]#[fg=#2e7de9,bg=#a8aecb,bold] #I #W #F #[fg=#a8aecb,bg=#d4d6e4,nobold,nounderscore,noitalics]"
|
||||
setw -g window-status-style "NONE,fg=#6172b0,bg=#e9e9ec"
|
||||
setw -g window-status-format "#[fg=#e9e9ec,bg=#e9e9ec,nobold,nounderscore,noitalics]#[default] #I #W #F #[fg=#e9e9ec,bg=#e9e9ec,nobold,nounderscore,noitalics]"
|
||||
setw -g window-status-current-format "#[fg=#e9e9ec,bg=#a8aecb,nobold,nounderscore,noitalics]#[fg=#2e7de9,bg=#a8aecb,bold] #I #W #F #[fg=#a8aecb,bg=#e9e9ec,nobold,nounderscore,noitalics]"
|
||||
|
||||
@@ -13,7 +13,7 @@ set -g pane-active-border-style "fg=#7aa2f7"
|
||||
set -g status "on"
|
||||
set -g status-justify "left"
|
||||
|
||||
set -g status-style "fg=#7aa2f7,bg=#1f2335"
|
||||
set -g status-style "fg=#7aa2f7,bg=#16161e"
|
||||
|
||||
set -g status-left-length "100"
|
||||
set -g status-right-length "100"
|
||||
@@ -21,12 +21,12 @@ set -g status-right-length "100"
|
||||
set -g status-left-style NONE
|
||||
set -g status-right-style NONE
|
||||
|
||||
set -g status-left "#[fg=#15161E,bg=#7aa2f7,bold] #S #[fg=#7aa2f7,bg=#1f2335,nobold,nounderscore,noitalics]"
|
||||
set -g status-right "#[fg=#1f2335,bg=#1f2335,nobold,nounderscore,noitalics]#[fg=#7aa2f7,bg=#1f2335] #{prefix_highlight} #[fg=#3b4261,bg=#1f2335,nobold,nounderscore,noitalics]#[fg=#7aa2f7,bg=#3b4261] %Y-%m-%d %I:%M %p #[fg=#7aa2f7,bg=#3b4261,nobold,nounderscore,noitalics]#[fg=#15161E,bg=#7aa2f7,bold] #h "
|
||||
set -g status-left "#[fg=#15161E,bg=#7aa2f7,bold] #S #[fg=#7aa2f7,bg=#16161e,nobold,nounderscore,noitalics]"
|
||||
set -g status-right "#[fg=#16161e,bg=#16161e,nobold,nounderscore,noitalics]#[fg=#7aa2f7,bg=#16161e] #{prefix_highlight} #[fg=#3b4261,bg=#16161e,nobold,nounderscore,noitalics]#[fg=#7aa2f7,bg=#3b4261] %Y-%m-%d %I:%M %p #[fg=#7aa2f7,bg=#3b4261,nobold,nounderscore,noitalics]#[fg=#15161E,bg=#7aa2f7,bold] #h "
|
||||
|
||||
setw -g window-status-activity-style "underscore,fg=#a9b1d6,bg=#1f2335"
|
||||
setw -g window-status-activity-style "underscore,fg=#a9b1d6,bg=#16161e"
|
||||
setw -g window-status-separator ""
|
||||
setw -g window-status-style "NONE,fg=#a9b1d6,bg=#1f2335"
|
||||
setw -g window-status-format "#[fg=#1f2335,bg=#1f2335,nobold,nounderscore,noitalics]#[default] #I #W #F #[fg=#1f2335,bg=#1f2335,nobold,nounderscore,noitalics]"
|
||||
setw -g window-status-current-format "#[fg=#1f2335,bg=#3b4261,nobold,nounderscore,noitalics]#[fg=#7aa2f7,bg=#3b4261,bold] #I #W #F #[fg=#3b4261,bg=#1f2335,nobold,nounderscore,noitalics]"
|
||||
setw -g window-status-style "NONE,fg=#a9b1d6,bg=#16161e"
|
||||
setw -g window-status-format "#[fg=#16161e,bg=#16161e,nobold,nounderscore,noitalics]#[default] #I #W #F #[fg=#16161e,bg=#16161e,nobold,nounderscore,noitalics]"
|
||||
setw -g window-status-current-format "#[fg=#16161e,bg=#3b4261,nobold,nounderscore,noitalics]#[fg=#7aa2f7,bg=#3b4261,bold] #I #W #F #[fg=#3b4261,bg=#16161e,nobold,nounderscore,noitalics]"
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
local config = require("tokyonight.config")
|
||||
local colors = require("tokyonight.colors").setup(config)
|
||||
local util = require("tokyonight.util")
|
||||
local colors = require("tokyonight.colors").setup({ transform = true })
|
||||
|
||||
local tokyonight = {}
|
||||
|
||||
@@ -37,15 +35,4 @@ tokyonight.tabline = {
|
||||
tabsel = { { colors.blue, colors.fg_gutter }, { colors.dark3, colors.bg } },
|
||||
}
|
||||
|
||||
if vim.o.background == "light" then
|
||||
for _, mode in pairs(tokyonight) do
|
||||
for _, section in pairs(mode) do
|
||||
for _, subsection in pairs(section) do
|
||||
subsection[1] = util.getColor(subsection[1])
|
||||
subsection[2] = util.getColor(subsection[2])
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return tokyonight
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
local config = require("tokyonight.config")
|
||||
local colors = require("tokyonight.colors").setup(config)
|
||||
local util = require("tokyonight.util")
|
||||
local colors = require("tokyonight.colors").setup({ transform = true })
|
||||
local config = require("tokyonight.config").options
|
||||
|
||||
local tokyonight = {}
|
||||
|
||||
@@ -36,20 +35,7 @@ tokyonight.inactive = {
|
||||
c = { bg = colors.bg_statusline, fg = colors.fg_gutter },
|
||||
}
|
||||
|
||||
if vim.o.background == "light" then
|
||||
for _, mode in pairs(tokyonight) do
|
||||
for _, section in pairs(mode) do
|
||||
if section.bg then
|
||||
section.bg = util.getColor(section.bg)
|
||||
end
|
||||
if section.fg then
|
||||
section.fg = util.getColor(section.fg)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if vim.g.tokyonight_lualine_bold then
|
||||
if config.lualine_bold then
|
||||
for _, mode in pairs(tokyonight) do
|
||||
mode.a.gui = "bold"
|
||||
end
|
||||
|
||||
@@ -2,10 +2,10 @@ local util = require("tokyonight.util")
|
||||
|
||||
local M = {}
|
||||
|
||||
---@param config Config
|
||||
---@return ColorScheme
|
||||
function M.setup(config)
|
||||
config = config or require("tokyonight.config")
|
||||
function M.setup(opts)
|
||||
opts = opts or {}
|
||||
local config = require("tokyonight.config").options
|
||||
|
||||
-- Color Palette
|
||||
---@class ColorScheme
|
||||
@@ -40,15 +40,14 @@ function M.setup(config)
|
||||
teal = "#1abc9c",
|
||||
red = "#f7768e",
|
||||
red1 = "#db4b4b",
|
||||
git = { change = "#6183bb", add = "#449dab", delete = "#914c54", conflict = "#bb7a61" },
|
||||
gitSigns = { add = "#164846", change = "#394b70", delete = "#823c41" },
|
||||
git = { change = "#6183bb", add = "#449dab", delete = "#914c54" },
|
||||
}
|
||||
if config.style == "night" or config.style == "day" or vim.o.background == "light" then
|
||||
colors.bg = "#1a1b26"
|
||||
colors.bg_dark = "#16161e"
|
||||
end
|
||||
util.bg = colors.bg
|
||||
util.day_brightness = config.dayBrightness
|
||||
util.day_brightness = config.day_brightness
|
||||
|
||||
colors.diff = {
|
||||
add = util.darken(colors.green2, 0.15),
|
||||
@@ -58,9 +57,9 @@ function M.setup(config)
|
||||
}
|
||||
|
||||
colors.gitSigns = {
|
||||
add = util.brighten(colors.gitSigns.add, 0.2),
|
||||
change = util.brighten(colors.gitSigns.change, 0.2),
|
||||
delete = util.brighten(colors.gitSigns.delete, 0.2),
|
||||
add = "#266d6a",
|
||||
change = "#536c9e",
|
||||
delete = "#b2555b",
|
||||
}
|
||||
|
||||
colors.git.ignore = colors.dark3
|
||||
@@ -73,8 +72,13 @@ function M.setup(config)
|
||||
colors.bg_statusline = colors.bg_dark
|
||||
|
||||
-- Sidebar and Floats are configurable
|
||||
colors.bg_sidebar = (config.transparentSidebar and colors.none) or config.darkSidebar and colors.bg_dark or colors.bg
|
||||
colors.bg_float = config.darkFloat and colors.bg_dark or colors.bg
|
||||
colors.bg_sidebar = config.styles.sidebars == "transparent" and colors.none
|
||||
or config.styles.sidebars == "dark" and colors.bg_dark
|
||||
or colors.bg
|
||||
|
||||
colors.bg_float = config.styles.floats == "transparent" and colors.none
|
||||
or config.styles.floats == "dark" and colors.bg_dark
|
||||
or colors.bg
|
||||
|
||||
colors.bg_visual = util.darken(colors.blue0, 0.7)
|
||||
colors.bg_search = colors.blue0
|
||||
@@ -85,10 +89,9 @@ function M.setup(config)
|
||||
colors.info = colors.blue2
|
||||
colors.hint = colors.teal
|
||||
|
||||
util.color_overrides(colors, config)
|
||||
|
||||
if config.transform_colors and (config.style == "day" or vim.o.background == "light") then
|
||||
return util.light_colors(colors)
|
||||
config.on_colors(colors)
|
||||
if opts.transform and (config.style == "day" or vim.o.background == "light") then
|
||||
util.invert_colors(colors)
|
||||
end
|
||||
|
||||
return colors
|
||||
|
||||
@@ -1,40 +1,51 @@
|
||||
-- shim vim for kitty and other generators
|
||||
vim = vim or { g = {}, o = {} }
|
||||
|
||||
local function opt(key, default)
|
||||
key = "tokyonight_" .. key
|
||||
if vim.g[key] == nil then
|
||||
return default
|
||||
end
|
||||
if vim.g[key] == 0 then
|
||||
return false
|
||||
end
|
||||
return vim.g[key]
|
||||
end
|
||||
local M = {}
|
||||
|
||||
---@class Config
|
||||
local config = {
|
||||
style = opt("style", "storm"),
|
||||
dayBrightness = opt("day_brightness", 0.3),
|
||||
transparent = opt("transparent", false),
|
||||
commentStyle = opt("italic_comments", true) and "italic" or "NONE",
|
||||
keywordStyle = opt("italic_keywords", true) and "italic" or "NONE",
|
||||
functionStyle = opt("italic_functions", false) and "italic" or "NONE",
|
||||
variableStyle = opt("italic_variables", false) and "italic" or "NONE",
|
||||
hideInactiveStatusline = opt("hide_inactive_statusline", false),
|
||||
terminalColors = opt("terminal_colors", true),
|
||||
sidebars = opt("sidebars", {}),
|
||||
colors = opt("colors", {}),
|
||||
dev = opt("dev", false),
|
||||
darkFloat = opt("dark_float", true),
|
||||
darkSidebar = opt("dark_sidebar", true),
|
||||
transparentSidebar = opt("transparent_sidebar", false),
|
||||
transform_colors = false,
|
||||
lualineBold = opt("lualine_bold", false),
|
||||
local defaults = {
|
||||
style = "storm", -- The theme comes in three styles, `storm`, a darker variant `night` and `day`
|
||||
transparent = false, -- Enable this to disable setting the background color
|
||||
terminal_colors = true, -- Configure the colors used when opening a `:terminal` in Neovim |
|
||||
styles = {
|
||||
-- Style to be applied to different syntax groups
|
||||
-- Value is any valid attr-list value `:help attr-list`
|
||||
comments = "italic",
|
||||
keywords = "italic",
|
||||
functions = "NONE",
|
||||
variables = "NONE",
|
||||
-- Background styles. Can be "dark", "transparent" or "normal"
|
||||
sidebars = "dark", -- style for sidebars, see below
|
||||
floats = "dark", -- style for floating windows
|
||||
},
|
||||
sidebars = { "qf", "help" }, -- Set a darker background on sidebar-like windows. For example: `["qf", "vista_kind", "terminal", "packer"]` |
|
||||
day_brightness = 0.3, -- Adjusts the brightness of the colors of the **Day** style. Number between 0 and 1, from dull to vibrant colors |
|
||||
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**. |
|
||||
lualine_bold = false, -- When `true`, section headers in the lualine theme will be bold |
|
||||
|
||||
--- You can override specific color groups to use other groups or a hex color |
|
||||
--- fucntion will be called with a ColorScheme table
|
||||
---@param colors ColorScheme
|
||||
on_colors = function(colors) end,
|
||||
|
||||
--- You can override specific highlights to use other groups or a hex color |
|
||||
--- fucntion will be called with a Highlights and ColorScheme table
|
||||
---@param highlights Highlights
|
||||
---@param colors ColorScheme
|
||||
on_highlights = function(highlights, colors) end,
|
||||
}
|
||||
|
||||
if config.style == "day" then
|
||||
vim.o.background = "light"
|
||||
---@type Config
|
||||
M.options = {}
|
||||
|
||||
---@param options Config|nil
|
||||
function M.setup(options)
|
||||
M.options = vim.tbl_deep_extend("force", {}, defaults, options or {})
|
||||
end
|
||||
|
||||
return config
|
||||
---@param options Config|nil
|
||||
function M.extend(options)
|
||||
M.options = vim.tbl_deep_extend("force", {}, M.options or defaults, options or {})
|
||||
end
|
||||
|
||||
M.setup()
|
||||
|
||||
return M
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
package.path = "./lua/?/init.lua;./lua/?.lua"
|
||||
|
||||
local config = require("tokyonight.config")
|
||||
local M = {}
|
||||
|
||||
local function write(str, fileName)
|
||||
print("[write] extra/" .. fileName)
|
||||
@@ -9,35 +7,40 @@ local function write(str, fileName)
|
||||
file:close()
|
||||
end
|
||||
|
||||
-- map of plugin name to plugin extension
|
||||
local extras = {
|
||||
kitty = "conf",
|
||||
fish = "fish",
|
||||
alacritty = "yml",
|
||||
wezterm = "toml",
|
||||
tmux = "tmux",
|
||||
xresources = "Xresources",
|
||||
xfceterm = "theme",
|
||||
foot = "ini",
|
||||
tilix = "json",
|
||||
}
|
||||
-- map of style to style name
|
||||
local styles = {
|
||||
storm = " Storm",
|
||||
night = "",
|
||||
day = " Day",
|
||||
}
|
||||
function M.setup()
|
||||
local config = require("tokyonight.config")
|
||||
vim.o.background = "dark"
|
||||
|
||||
for extra, ext in pairs(extras) do
|
||||
local plugin = require("tokyonight.extra." .. extra)
|
||||
for style, style_name in pairs(styles) do
|
||||
config.style = style
|
||||
config = config or require("tokyonight.config")
|
||||
config.transform_colors = true
|
||||
local colors = require("tokyonight.colors").setup(config)
|
||||
local fname = extra .. "_tokyonight_" .. style .. "." .. ext
|
||||
colors["_upstream_url"] = "https://github.com/folke/tokyonight.nvim/raw/main/extras/" .. fname
|
||||
colors["_style_name"] = "Tokyo Night" .. style_name
|
||||
write(plugin.generate(colors), fname)
|
||||
-- map of plugin name to plugin extension
|
||||
local extras = {
|
||||
kitty = "conf",
|
||||
fish = "fish",
|
||||
alacritty = "yml",
|
||||
wezterm = "toml",
|
||||
tmux = "tmux",
|
||||
xresources = "Xresources",
|
||||
xfceterm = "theme",
|
||||
foot = "ini",
|
||||
tilix = "json",
|
||||
}
|
||||
-- map of style to style name
|
||||
local styles = {
|
||||
storm = " Storm",
|
||||
night = "",
|
||||
day = " Day",
|
||||
}
|
||||
|
||||
for extra, ext in pairs(extras) do
|
||||
local plugin = require("tokyonight.extra." .. extra)
|
||||
for style, style_name in pairs(styles) do
|
||||
config.setup({ style = style })
|
||||
local colors = require("tokyonight.colors").setup({ transform = true })
|
||||
local fname = extra .. "_tokyonight_" .. style .. "." .. ext
|
||||
colors["_upstream_url"] = "https://github.com/folke/tokyonight.nvim/raw/main/extras/" .. fname
|
||||
colors["_style_name"] = "Tokyo Night" .. style_name
|
||||
write(plugin.generate(colors), fname)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
@@ -1,10 +1,20 @@
|
||||
local util = require("tokyonight.util")
|
||||
local theme = require("tokyonight.theme")
|
||||
local config = require("tokyonight.config")
|
||||
|
||||
local M = {}
|
||||
|
||||
function M.colorscheme()
|
||||
---@param opts Config|nil
|
||||
function M.load(opts)
|
||||
if opts then
|
||||
require("tokyonight.config").extend(opts)
|
||||
end
|
||||
util.load(theme.setup())
|
||||
end
|
||||
|
||||
M.setup = config.setup
|
||||
|
||||
-- keep for backward compatibility
|
||||
M.colorscheme = M.load
|
||||
|
||||
return M
|
||||
|
||||
@@ -2,21 +2,31 @@ local util = require("tokyonight.util")
|
||||
local colors = require("tokyonight.colors")
|
||||
|
||||
local M = {}
|
||||
--
|
||||
---@class Highlight
|
||||
---@field fg string|nil
|
||||
---@field bg string|nil
|
||||
---@field sp string|nil
|
||||
---@field style string|nil
|
||||
|
||||
---@alias Highlights table<string,Highlight>
|
||||
|
||||
---@param config Config
|
||||
---@return Theme
|
||||
function M.setup(config)
|
||||
config = config or require("tokyonight.config")
|
||||
|
||||
function M.setup()
|
||||
local config = require("tokyonight.config").options
|
||||
---@class Theme
|
||||
local theme = {}
|
||||
theme.config = config
|
||||
theme.colors = colors.setup(config)
|
||||
---@field highlights Highlights
|
||||
local theme = {
|
||||
config = config,
|
||||
colors = colors.setup(),
|
||||
}
|
||||
|
||||
local c = theme.colors
|
||||
|
||||
theme.base = {
|
||||
Comment = { fg = c.comment, style = config.commentStyle }, -- any comment
|
||||
theme.highlights = {
|
||||
Foo = { bg = c.magenta2, fg = c.magenta2 },
|
||||
|
||||
Comment = { fg = c.comment, style = config.styles.comments }, -- any comment
|
||||
ColorColumn = { bg = c.black }, -- used for the columns set with 'colorcolumn'
|
||||
Conceal = { fg = c.dark5 }, -- placeholder characters substituted for concealed text (see 'conceallevel')
|
||||
Cursor = { fg = c.bg, bg = c.fg }, -- character under the cursor
|
||||
@@ -34,6 +44,7 @@ function M.setup(config)
|
||||
-- TermCursorNC= { }, -- cursor in an unfocused terminal
|
||||
ErrorMsg = { fg = c.error }, -- error messages on the command line
|
||||
VertSplit = { fg = c.border }, -- the column separating vertically split windows
|
||||
WinSeparator = { fg = c.border, style = "bold" }, -- the column separating vertically split windows
|
||||
Folded = { fg = c.blue, bg = c.fg_gutter }, -- line used for closed folds
|
||||
FoldColumn = { bg = c.bg, fg = c.comment }, -- 'foldcolumn'
|
||||
SignColumn = { bg = config.transparent and c.none or c.bg, fg = c.fg_gutter }, -- column where |signs| are displayed
|
||||
@@ -90,15 +101,15 @@ function M.setup(config)
|
||||
-- Boolean = { }, -- a boolean constant: TRUE, false
|
||||
-- Float = { }, -- a floating point constant: 2.3e10
|
||||
|
||||
Identifier = { fg = c.magenta, style = config.variableStyle }, -- (preferred) any variable name
|
||||
Function = { fg = c.blue, style = config.functionStyle }, -- function name (also: methods for classes)
|
||||
Identifier = { fg = c.magenta, style = config.styles.variables }, -- (preferred) any variable name
|
||||
Function = { fg = c.blue, style = config.styles.functions }, -- function name (also: methods for classes)
|
||||
|
||||
Statement = { fg = c.magenta }, -- (preferred) any statement
|
||||
-- Conditional = { }, -- if, then, else, endif, switch, etc.
|
||||
-- Repeat = { }, -- for, do, while, etc.
|
||||
-- Label = { }, -- case, default, etc.
|
||||
Operator = { fg = c.blue5 }, -- "sizeof", "+", "*", etc.
|
||||
Keyword = { fg = c.cyan, style = config.keywordStyle }, -- any other keyword
|
||||
Keyword = { fg = c.cyan, style = config.styles.keywords }, -- any other keyword
|
||||
-- Exception = { }, -- try, catch, throw
|
||||
|
||||
PreProc = { fg = c.cyan }, -- (preferred) generic Preprocessor
|
||||
@@ -179,26 +190,6 @@ function M.setup(config)
|
||||
|
||||
ALEErrorSign = { fg = c.error },
|
||||
ALEWarningSign = { fg = c.warning },
|
||||
}
|
||||
|
||||
if not vim.diagnostic then
|
||||
local severity_map = {
|
||||
Error = "Error",
|
||||
Warn = "Warning",
|
||||
Info = "Information",
|
||||
Hint = "Hint",
|
||||
}
|
||||
local types = { "Default", "VirtualText", "Underline" }
|
||||
for _, type in ipairs(types) do
|
||||
for snew, sold in pairs(severity_map) do
|
||||
theme.base["LspDiagnostics" .. type .. sold] = {
|
||||
link = "Diagnostic" .. (type == "Default" and "" or type) .. snew,
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
theme.plugins = {
|
||||
|
||||
-- These groups are for the neovim tree-sitter highlights.
|
||||
-- As of writing, tree-sitter support is a WIP, group names may change.
|
||||
@@ -227,8 +218,8 @@ function M.setup(config)
|
||||
-- TSFuncBuiltin = { }; -- For builtin functions: `table.insert` in Lua.
|
||||
-- TSFuncMacro = { }; -- For macro defined fuctions (calls and definitions): each `macro_rules` in Rust.
|
||||
-- TSInclude = { }; -- For includes: `#include` in C, `use` or `extern crate` in Rust, or `require` in Lua.
|
||||
TSKeyword = { fg = c.purple, style = config.keywordStyle }, -- For keywords that don't fall in previous categories.
|
||||
TSKeywordFunction = { fg = c.magenta, style = config.functionStyle }, -- For keywords used to define a fuction.
|
||||
TSKeyword = { fg = c.purple, style = config.styles.keywords }, -- For keywords that don't fall in previous categories.
|
||||
TSKeywordFunction = { fg = c.magenta, style = config.styles.functions }, -- For keywords used to define a fuction.
|
||||
TSLabel = { fg = c.blue }, -- For labels: `label:` in C and `:label:` in Lua.
|
||||
-- TSMethod = { }; -- For method calls and definitions.
|
||||
-- TSNamespace = { }; -- For identifiers referring to modules and namespaces.
|
||||
@@ -248,7 +239,7 @@ function M.setup(config)
|
||||
-- TSSymbol = { }; -- For identifiers referring to symbols or atoms.
|
||||
-- TSType = { }; -- For types.
|
||||
-- TSTypeBuiltin = { }; -- For builtin types.
|
||||
TSVariable = { style = config.variableStyle }, -- Any variable name that does not have another highlight.
|
||||
TSVariable = { style = config.styles.variables }, -- Any variable name that does not have another highlight.
|
||||
TSVariableBuiltin = { fg = c.red }, -- Variable names that are defined by the languages, like `this` or `self`.
|
||||
|
||||
-- TSTag = { }; -- Tags like html tag names.
|
||||
@@ -275,9 +266,9 @@ function M.setup(config)
|
||||
rainbowcol7 = { fg = c.red },
|
||||
|
||||
-- LspTrouble
|
||||
LspTroubleText = { fg = c.fg_dark },
|
||||
LspTroubleCount = { fg = c.magenta, bg = c.fg_gutter },
|
||||
LspTroubleNormal = { fg = c.fg_sidebar, bg = c.bg_sidebar },
|
||||
TroubleText = { fg = c.fg_dark },
|
||||
TroubleCount = { fg = c.magenta, bg = c.fg_gutter },
|
||||
TroubleNormal = { fg = c.fg_sidebar, bg = c.bg_sidebar },
|
||||
|
||||
-- Illuminate
|
||||
illuminatedWord = { bg = c.fg_gutter },
|
||||
@@ -316,8 +307,8 @@ function M.setup(config)
|
||||
GitSignsDelete = { fg = c.gitSigns.delete }, -- diff mode: Deleted line |diff.txt|
|
||||
|
||||
-- Telescope
|
||||
TelescopeBorder = { fg = c.border_highlight, bg = config.transparent and c.bg_float or c.bg },
|
||||
TelescopeNormal = { fg = c.fg, bg = config.transparent and c.bg_float or c.bg },
|
||||
TelescopeBorder = { fg = c.border_highlight, bg = c.bg_float },
|
||||
TelescopeNormal = { fg = c.fg, bg = c.bg_float },
|
||||
|
||||
-- NvimTree
|
||||
NvimTreeNormal = { fg = c.fg_sidebar, bg = c.bg_sidebar },
|
||||
@@ -510,7 +501,7 @@ function M.setup(config)
|
||||
MiniStarterCurrent = { style = "nocombine" },
|
||||
MiniStarterFooter = { fg = c.yellow, style = "italic" },
|
||||
MiniStarterHeader = { fg = c.blue },
|
||||
MiniStarterInactive = { fg = c.comment, style = config.commentStyle },
|
||||
MiniStarterInactive = { fg = c.comment, style = config.styles.comments },
|
||||
MiniStarterItem = { fg = c.fg, bg = config.transparent and c.none or c.bg },
|
||||
MiniStarterItemBullet = { fg = c.border_highlight },
|
||||
MiniStarterItemPrefix = { fg = c.warning },
|
||||
@@ -546,13 +537,30 @@ function M.setup(config)
|
||||
MiniTrailspace = { bg = c.red },
|
||||
}
|
||||
|
||||
if not vim.diagnostic then
|
||||
local severity_map = {
|
||||
Error = "Error",
|
||||
Warn = "Warning",
|
||||
Info = "Information",
|
||||
Hint = "Hint",
|
||||
}
|
||||
local types = { "Default", "VirtualText", "Underline" }
|
||||
for _, type in ipairs(types) do
|
||||
for snew, sold in pairs(severity_map) do
|
||||
theme.highlights["LspDiagnostics" .. type .. sold] = {
|
||||
link = "Diagnostic" .. (type == "Default" and "" or type) .. snew,
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
theme.defer = {}
|
||||
|
||||
if config.hideInactiveStatusline then
|
||||
if config.hide_inactive_statusline then
|
||||
local inactive = { style = "underline", bg = c.none, fg = c.bg, sp = c.border }
|
||||
|
||||
-- StatusLineNC
|
||||
theme.base.StatusLineNC = inactive
|
||||
theme.highlights.StatusLineNC = inactive
|
||||
|
||||
-- LuaLine
|
||||
for _, section in ipairs({ "a", "b", "c" }) do
|
||||
@@ -560,7 +568,14 @@ function M.setup(config)
|
||||
end
|
||||
|
||||
-- mini.statusline
|
||||
theme.plugins.MiniStatuslineInactive = inactive
|
||||
theme.highlights.MiniStatuslineInactive = inactive
|
||||
end
|
||||
|
||||
config.on_highlights(theme.highlights, theme.colors)
|
||||
|
||||
if config.style == "day" or vim.o.background == "light" then
|
||||
util.invert_colors(theme.colors)
|
||||
util.invert_highlights(theme.highlights)
|
||||
end
|
||||
|
||||
return theme
|
||||
|
||||
@@ -1,29 +1,19 @@
|
||||
local hsluv = require("tokyonight.hsluv")
|
||||
local M = {}
|
||||
|
||||
local util = {}
|
||||
M.bg = "#000000"
|
||||
M.fg = "#ffffff"
|
||||
M.day_brightness = 0.3
|
||||
|
||||
util.colorsUsed = {}
|
||||
util.colorCache = {}
|
||||
|
||||
util.bg = "#000000"
|
||||
util.fg = "#ffffff"
|
||||
util.day_brightness = 0.3
|
||||
|
||||
local function hexToRgb(hex_str)
|
||||
local hex = "[abcdef0-9][abcdef0-9]"
|
||||
local pat = "^#(" .. hex .. ")(" .. hex .. ")(" .. hex .. ")$"
|
||||
hex_str = string.lower(hex_str)
|
||||
|
||||
assert(string.find(hex_str, pat) ~= nil, "hex_to_rgb: invalid hex_str: " .. tostring(hex_str))
|
||||
|
||||
local r, g, b = string.match(hex_str, pat)
|
||||
return { tonumber(r, 16), tonumber(g, 16), tonumber(b, 16) }
|
||||
---@param c string
|
||||
local function hexToRgb(c)
|
||||
c = string.lower(c)
|
||||
return { tonumber(c:sub(2, 3), 16), tonumber(c:sub(4, 5), 16), tonumber(c:sub(6, 7), 16) }
|
||||
end
|
||||
|
||||
---@param fg string foreground color
|
||||
---@param bg string background color
|
||||
---@param alpha number number between 0 and 1. 0 results in bg, 1 results in fg
|
||||
function util.blend(fg, bg, alpha)
|
||||
function M.blend(fg, bg, alpha)
|
||||
bg = hexToRgb(bg)
|
||||
fg = hexToRgb(fg)
|
||||
|
||||
@@ -32,105 +22,41 @@ function util.blend(fg, bg, alpha)
|
||||
return math.floor(math.min(math.max(0, ret), 255) + 0.5)
|
||||
end
|
||||
|
||||
return string.format("#%02X%02X%02X", blendChannel(1), blendChannel(2), blendChannel(3))
|
||||
return string.format("#%02x%02x%02x", blendChannel(1), blendChannel(2), blendChannel(3))
|
||||
end
|
||||
|
||||
function util.darken(hex, amount, bg)
|
||||
return util.blend(hex, bg or util.bg, math.abs(amount))
|
||||
function M.darken(hex, amount, bg)
|
||||
return M.blend(hex, bg or M.bg, math.abs(amount))
|
||||
end
|
||||
function util.lighten(hex, amount, fg)
|
||||
return util.blend(hex, fg or util.fg, math.abs(amount))
|
||||
function M.lighten(hex, amount, fg)
|
||||
return M.blend(hex, fg or M.fg, math.abs(amount))
|
||||
end
|
||||
|
||||
function util.brighten(color, percentage)
|
||||
local hsl = hsluv.hex_to_hsluv(color)
|
||||
local larpSpace = 100 - hsl[3]
|
||||
if percentage < 0 then
|
||||
larpSpace = hsl[3]
|
||||
end
|
||||
hsl[3] = hsl[3] + larpSpace * percentage
|
||||
return hsluv.hsluv_to_hex(hsl)
|
||||
end
|
||||
|
||||
function util.invertColor(color)
|
||||
function M.invert_color(color)
|
||||
local hsluv = require("tokyonight.hsluv")
|
||||
if color ~= "NONE" then
|
||||
local hsl = hsluv.hex_to_hsluv(color)
|
||||
hsl[3] = 100 - hsl[3]
|
||||
if hsl[3] < 40 then
|
||||
hsl[3] = hsl[3] + (100 - hsl[3]) * util.day_brightness
|
||||
hsl[3] = hsl[3] + (100 - hsl[3]) * M.day_brightness
|
||||
end
|
||||
return hsluv.hsluv_to_hex(hsl)
|
||||
end
|
||||
return color
|
||||
end
|
||||
|
||||
function util.randomColor(color)
|
||||
if color ~= "NONE" then
|
||||
local hsl = hsluv.hex_to_hsluv(color)
|
||||
hsl[1] = math.random(1, 360)
|
||||
return hsluv.hsluv_to_hex(hsl)
|
||||
end
|
||||
return color
|
||||
end
|
||||
|
||||
function util.getColor(color)
|
||||
if vim.o.background == "dark" then
|
||||
return color
|
||||
end
|
||||
if not util.colorCache[color] then
|
||||
util.colorCache[color] = util.invertColor(color)
|
||||
end
|
||||
return util.colorCache[color]
|
||||
end
|
||||
|
||||
-- local ns = vim.api.nvim_create_namespace("tokyonight")
|
||||
function util.highlight(group, color)
|
||||
if color.fg then
|
||||
util.colorsUsed[color.fg] = true
|
||||
end
|
||||
if color.bg then
|
||||
util.colorsUsed[color.bg] = true
|
||||
end
|
||||
if color.sp then
|
||||
util.colorsUsed[color.sp] = true
|
||||
end
|
||||
|
||||
local style = color.style and "gui=" .. color.style or "gui=NONE"
|
||||
local fg = color.fg and "guifg=" .. util.getColor(color.fg) or "guifg=NONE"
|
||||
local bg = color.bg and "guibg=" .. util.getColor(color.bg) or "guibg=NONE"
|
||||
local sp = color.sp and "guisp=" .. util.getColor(color.sp) or ""
|
||||
|
||||
local hl = "highlight " .. group .. " " .. style .. " " .. fg .. " " .. bg .. " " .. sp
|
||||
|
||||
if color.link then
|
||||
vim.cmd("highlight! link " .. group .. " " .. color.link)
|
||||
else
|
||||
-- local data = {}
|
||||
-- if color.fg then data.foreground = color.fg end
|
||||
-- if color.bg then data.background = color.bg end
|
||||
-- if color.sp then data.special = color.sp end
|
||||
-- if color.style then data[color.style] = true end
|
||||
-- vim.api.nvim_set_hl(ns, group, data)
|
||||
vim.cmd(hl)
|
||||
end
|
||||
end
|
||||
|
||||
function util.debug(colors)
|
||||
colors = colors or require("tokyonight.colors")
|
||||
-- Dump unused colors
|
||||
for name, color in pairs(colors) do
|
||||
if type(color) == "table" then
|
||||
util.debug(color)
|
||||
else
|
||||
if util.colorsUsed[color] == nil then
|
||||
print("not used: " .. name .. " : " .. color)
|
||||
end
|
||||
function M.highlight(group, color)
|
||||
local hl = { fg = color.fg, bg = color.bg, sp = color.sp, link = color.link }
|
||||
if color.style and color.style:lower() ~= "none" then
|
||||
for s in string.gmatch(color.style, "([^,]+)") do
|
||||
hl[s] = true
|
||||
end
|
||||
end
|
||||
vim.api.nvim_set_hl(0, group, hl)
|
||||
end
|
||||
|
||||
--- Delete the autocmds when the theme changes to something else
|
||||
function util.onColorScheme()
|
||||
function M.onColorScheme()
|
||||
if vim.g.colors_name ~= "tokyonight" then
|
||||
vim.cmd([[autocmd! TokyoNight]])
|
||||
vim.cmd([[augroup! TokyoNight]])
|
||||
@@ -138,13 +64,10 @@ function util.onColorScheme()
|
||||
end
|
||||
|
||||
---@param config Config
|
||||
function util.autocmds(config)
|
||||
function M.autocmds(config)
|
||||
vim.cmd([[augroup TokyoNight]])
|
||||
vim.cmd([[ autocmd!]])
|
||||
vim.cmd([[ autocmd ColorScheme * lua require("tokyonight.util").onColorScheme()]])
|
||||
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]])
|
||||
@@ -161,20 +84,20 @@ end
|
||||
--
|
||||
---@param str string template string
|
||||
---@param table table key value pairs to replace in the string
|
||||
function util.template(str, table)
|
||||
function M.template(str, table)
|
||||
return (str:gsub("($%b{})", function(w)
|
||||
return table[w:sub(3, -2)] or w
|
||||
end))
|
||||
end
|
||||
|
||||
function util.syntax(syntax)
|
||||
function M.syntax(syntax)
|
||||
for group, colors in pairs(syntax) do
|
||||
util.highlight(group, colors)
|
||||
M.highlight(group, colors)
|
||||
end
|
||||
end
|
||||
|
||||
---@param colors ColorScheme
|
||||
function util.terminal(colors)
|
||||
function M.terminal(colors)
|
||||
-- dark
|
||||
vim.g.terminal_color_0 = colors.black
|
||||
vim.g.terminal_color_8 = colors.terminal_black
|
||||
@@ -201,130 +124,56 @@ function util.terminal(colors)
|
||||
|
||||
vim.g.terminal_color_6 = colors.cyan
|
||||
vim.g.terminal_color_14 = colors.cyan
|
||||
end
|
||||
|
||||
if vim.o.background == "light" then
|
||||
for i = 0, 15, 1 do
|
||||
vim.g["terminal_color_" .. i] = util.getColor(vim.g["terminal_color_" .. i])
|
||||
---@param colors ColorScheme
|
||||
function M.invert_colors(colors)
|
||||
if type(colors) == "string" then
|
||||
---@diagnostic disable-next-line: return-type-mismatch
|
||||
return M.invert_color(colors)
|
||||
end
|
||||
for key, value in pairs(colors) do
|
||||
colors[key] = M.invert_colors(value)
|
||||
end
|
||||
end
|
||||
|
||||
---@param hls Highlights
|
||||
function M.invert_highlights(hls)
|
||||
for _, hl in pairs(hls) do
|
||||
if hl.fg then
|
||||
hl.fg = M.invert_color(hl.fg)
|
||||
end
|
||||
if hl.bg then
|
||||
hl.bg = M.invert_color(hl.bg)
|
||||
end
|
||||
if hl.sp then
|
||||
hl.sp = M.invert_color(hl.sp)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function util.light_colors(colors)
|
||||
if type(colors) == "string" then
|
||||
return util.getColor(colors)
|
||||
end
|
||||
local ret = {}
|
||||
for key, value in pairs(colors) do
|
||||
ret[key] = util.light_colors(value)
|
||||
end
|
||||
return ret
|
||||
end
|
||||
|
||||
---@param theme Theme
|
||||
function util.load(theme)
|
||||
function M.load(theme)
|
||||
-- only needed to clear when not the default colorscheme
|
||||
if vim.g.colors_name then
|
||||
vim.cmd("hi clear")
|
||||
end
|
||||
-- if vim.fn.exists("syntax_on") then
|
||||
-- vim.cmd("syntax reset")
|
||||
-- end
|
||||
|
||||
vim.o.termguicolors = true
|
||||
vim.g.colors_name = "tokyonight"
|
||||
-- vim.api.nvim__set_hl_ns(ns)
|
||||
-- load base theme
|
||||
util.syntax(theme.base)
|
||||
util.syntax(theme.plugins)
|
||||
if theme.config.terminalColors then
|
||||
util.terminal(theme.colors)
|
||||
|
||||
M.syntax(theme.highlights)
|
||||
|
||||
-- vim.api.nvim_set_hl_ns(M.ns)
|
||||
if theme.config.terminal_colors then
|
||||
M.terminal(theme.colors)
|
||||
end
|
||||
|
||||
util.autocmds(theme.config)
|
||||
M.autocmds(theme.config)
|
||||
|
||||
vim.defer_fn(function()
|
||||
util.syntax(theme.defer)
|
||||
M.syntax(theme.defer)
|
||||
end, 100)
|
||||
end
|
||||
|
||||
---@param config Config
|
||||
---@param colors ColorScheme
|
||||
function util.color_overrides(colors, config)
|
||||
if type(config.colors) == "table" then
|
||||
for key, value in pairs(config.colors) do
|
||||
if not colors[key] then
|
||||
error("Color " .. key .. " does not exist")
|
||||
end
|
||||
|
||||
-- Patch: https://github.com/ful1e5/onedark.nvim/issues/6
|
||||
if type(colors[key]) == "table" then
|
||||
util.color_overrides(colors[key], { colors = value })
|
||||
else
|
||||
if value:lower() == "none" then
|
||||
-- set to none
|
||||
colors[key] = "NONE"
|
||||
elseif string.sub(value, 1, 1) == "#" then
|
||||
-- hex override
|
||||
colors[key] = value
|
||||
else
|
||||
-- another group
|
||||
if not colors[value] then
|
||||
error("Color " .. value .. " does not exist")
|
||||
end
|
||||
colors[key] = colors[value]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function util.light(brightness)
|
||||
for hl_name, hl in pairs(vim.api.nvim__get_hl_defs(0)) do
|
||||
local def = {}
|
||||
for key, def_key in pairs({ foreground = "fg", background = "bg", special = "sp" }) do
|
||||
if type(hl[key]) == "number" then
|
||||
local hex = string.format("#%06x", hl[key])
|
||||
local color = util.invertColor(hex)
|
||||
if brightness then
|
||||
color = util.brighten(hex, brightness)
|
||||
end
|
||||
table.insert(def, "gui" .. def_key .. "=" .. color)
|
||||
end
|
||||
end
|
||||
if hl_name ~= "" and #def > 0 then
|
||||
for _, style in pairs({ "bold", "italic", "underline", "undercurl", "reverse" }) do
|
||||
if hl[style] then
|
||||
table.insert(def, "gui=" .. style)
|
||||
end
|
||||
end
|
||||
|
||||
vim.cmd("highlight! " .. hl_name .. " " .. table.concat(def, " "))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function util.random()
|
||||
local colors = {}
|
||||
for hl_name, hl in pairs(vim.api.nvim__get_hl_defs(0)) do
|
||||
local def = {}
|
||||
for key, def_key in pairs({ foreground = "fg", background = "bg", special = "sp" }) do
|
||||
if type(hl[key]) == "number" then
|
||||
local hex = string.format("#%06x", hl[key])
|
||||
local color = colors[hex] and colors[hex] or util.randomColor(hex)
|
||||
colors[hex] = color
|
||||
table.insert(def, "gui" .. def_key .. "=" .. color)
|
||||
end
|
||||
end
|
||||
if hl_name ~= "" and #def > 0 then
|
||||
for _, style in pairs({ "bold", "italic", "underline", "undercurl", "reverse" }) do
|
||||
if hl[style] then
|
||||
table.insert(def, "gui=" .. style)
|
||||
end
|
||||
end
|
||||
|
||||
vim.cmd("highlight! " .. hl_name .. " " .. table.concat(def, " "))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return util
|
||||
return M
|
||||
|
||||
Reference in New Issue
Block a user