feat: add setup and simplify logic (#22)

* feat: add setup and simplify logic

* docs: update README

* chore: add config styles

* chore: simplify util function

* docs: add identifiers to styles
This commit is contained in:
tiagovla
2023-07-31 19:22:35 -03:00
committed by GitHub
parent b44f0cac4a
commit 984c4c699a
7 changed files with 392 additions and 410 deletions

View File

@@ -1,4 +1,4 @@
column_width = 120 column_width = 80
line_endings = "Unix" line_endings = "Unix"
indent_type = "Spaces" indent_type = "Spaces"
indent_width = 4 indent_width = 4

View File

@@ -4,62 +4,49 @@
### About ### About
A clean dark theme written in lua for neovim 0.7. A clean dark theme written in lua for neovim (0.7.2 or older).
### Features ### Features
- Support for numerous plugins - Support for numerous plugins
- Customizable - Customizable
- Italic Support
### Installation ### Installation
Install with your favorite package manager: Install with your favorite package manager:
[packer](https://github.com/wbthomason/packer.nvim) [lazy](https://github.com/wbthomason/lazy.nvim)
``` lua ``` lua
use 'tiagovla/tokyodark.nvim' {
"tiagovla/tokyodark.nvim",
opts = {
-- custom options here
},
config = function(_, opts)
require("tokyodark").setup(opts) -- calling setup is optional
vim.cmd [[colorscheme tokyodark]]
end,
}
``` ```
[vim-plug](https://github.com/junegunn/vim-plug) ### Default configuration
``` vim ```lua
Plug 'tiagovla/tokyodark.nvim' local default_config = {
``` transparent_background = false, -- set background to transparent
gamma = 1.00, -- adjust the brightness of the theme
### Available configuration styles = {
comments = { italic = true }, -- style for comments
**Note:** The configuration options should be placed before keywords = { italic = true }, -- style for keywords
`colorscheme tokyodark` . identifiers = { italic = true }, -- style for identifiers
functions = {}, -- style for functions
- `tokyodark_transparent_background`: Set to enable transparent variables = {}, -- style for variables
background. },
- `tokyodark_enable_italic_comment`: Set to enable italic in `Comment` . custom_highlights = {} or function(highlights, palette) return {} end, -- extend highlights
- `tokyodark_enable_italic`: Set to italicize keywords. This option is custom_palette = {} or function(palette) return {} end, -- extend palette
designed to use with fonts that support italic styles, for example terminal_colors = true, -- enable terminal colors
[Fira Code, MonoLisa, Dank Mono](https://www.nerdfonts.com/). }
- `tokyodark_color_gamma`: Change to adjust the brightness of the theme.
(Darker \< 1.0 \< Lighter).
#### Default configuration
``` lua
-- init.lua
vim.g.tokyodark_transparent_background = false
vim.g.tokyodark_enable_italic_comment = true
vim.g.tokyodark_enable_italic = true
vim.g.tokyodark_color_gamma = "1.0"
vim.cmd("colorscheme tokyodark")
```
``` vim
" .vimrc
let g:tokyodark_transparent_background = 0
let g:tokyodark_enable_italic_comment = 1
let g:tokyodark_enable_italic = 1
let g:tokyodark_color_gamma = "1.0"
colorscheme tokyodark
``` ```
### Inspiration ### Inspiration

View File

@@ -1,16 +1,31 @@
local function get(setting, default) local config = {}
local key = "tokyodark_" .. setting
if vim.g[key] == nil then
return default
end
return vim.g[key]
end
local config = { local default_config = {
bg = get("transparent_background", false), transparent_background = false,
italic = get("enable_italic", true), gamma = 1.00,
italic_comment = get("enable_italic_comment", true), styles = {
gamma = get("color_gamma", "1.0"), comments = { italic = true },
keywords = { italic = true },
identifiers = { italic = true },
functions = {},
variables = {},
},
custom_highlights = {} or function(highlights, palette) end,
custom_palette = {} or function(palette) end,
terminal_colors = true,
} }
return config function config.setup(opts)
for k, v in pairs(opts or {}) do
if type(v) == "table" then
config[k] = {}
for kk, vv in pairs(v) do
config[k][kk] = vv
end
else
config[k] = v
end
end
end
return setmetatable(config, { __index = default_config })

View File

@@ -1,25 +1,40 @@
local p = require("tokyodark.palette") local p = require("tokyodark.palette")
local cfg = require("tokyodark.config") local utils = require("tokyodark.utils")
local u = require("tokyodark.utils") local config = require("tokyodark.config")
local terminal = require("tokyodark.terminal")
local M = {} local M = {}
local hl = { langs = {}, plugins = {} }
local highlight = vim.api.nvim_set_hl
local function load_highlights(highlights) local function load_highlights(highlights)
for group_name, group_settings in pairs(highlights) do for group_name, group_settings in pairs(highlights) do
highlight(0, group_name, group_settings) vim.api.nvim_set_hl(0, group_name, group_settings)
end end
end end
local function make_default(table) local styles = vim.tbl_map(function(value)
for _, v in pairs(table) do return setmetatable(value, {
v.default = true __add = function(a, b)
end return vim.tbl_extend("force", a, b)
end,
})
end, config.styles)
local transparent_bg = setmetatable({}, {
__add = function(a)
a.bg = config.transparent_background and p.none or a.bg
return a
end,
})
local function gamma(value)
return setmetatable({}, {
__add = function(a)
return utils.color_gamma(a, value)
end,
})
end end
hl.predef = { M.highlights = {
Fg = { fg = p.fg }, Fg = { fg = p.fg },
Grey = { fg = p.grey }, Grey = { fg = p.grey },
Red = { fg = p.red }, Red = { fg = p.red },
@@ -28,23 +43,15 @@ hl.predef = {
Green = { fg = p.green }, Green = { fg = p.green },
Blue = { fg = p.blue }, Blue = { fg = p.blue },
Purple = { fg = p.purple }, Purple = { fg = p.purple },
BlueItalic = { fg = p.blue, italic = cfg.italic }, Normal = { fg = p.fg, bg = p.bg0 } + transparent_bg,
GreenItalic = { fg = p.green, italic = cfg.italic }, NormalNC = { fg = p.fg, bg = p.bg0 } + transparent_bg,
OrangeItalic = { fg = p.orange, italic = cfg.italic }, NormalSB = { fg = p.fg, bg = p.bg0 } + transparent_bg,
RedItalic = { fg = p.red, italic = cfg.italic }, NormalFloat = { fg = p.fg, bg = p.bg0 } + transparent_bg,
YellowItalic = { fg = p.yellow, italic = cfg.italic }, Terminal = { fg = p.fg, bg = p.bg0 } + transparent_bg,
} EndOfBuffer = { fg = p.bg2, bg = p.bg0 } + transparent_bg,
FoldColumn = { fg = p.fg, bg = p.bg1 } + transparent_bg,
hl.common = { Folded = { fg = p.fg, bg = p.bg1 } + transparent_bg,
Normal = { fg = p.fg, bg = cfg.bg and p.none or p.bg0 }, SignColumn = { fg = p.fg, bg = p.bg0 } + transparent_bg,
NormalNC = { fg = p.fg, bg = cfg.bg and p.none or p.bg0 },
NormalSB = { fg = p.fg, bg = cfg.bg and p.none or p.bg0 },
NormalFloat = { fg = p.fg, bg = cfg.bg and p.none or p.bg0 },
Terminal = { fg = p.fg, bg = cfg.bg and p.none or p.bg0 },
EndOfBuffer = { fg = p.bg2, bg = cfg.bg and p.none or p.bg0 },
FoldColumn = { fg = p.fg, bg = cfg.bg and p.none or p.bg1 },
Folded = { fg = p.fg, bg = cfg.bg and p.none or p.bg1 },
SignColumn = { fg = p.fg, bg = cfg.bg and p.none or p.bg0 },
ToolbarLine = { fg = p.fg }, ToolbarLine = { fg = p.fg },
Cursor = { reverse = true }, Cursor = { reverse = true },
vCursor = { reverse = true }, vCursor = { reverse = true },
@@ -98,199 +105,196 @@ hl.common = {
debugBreakpoint = { fg = p.bg0, bg = p.red }, debugBreakpoint = { fg = p.bg0, bg = p.red },
ToolbarButton = { fg = p.bg0, bg = p.bg_blue }, ToolbarButton = { fg = p.bg0, bg = p.bg_blue },
FocusedSymbol = { bg = p.bg3 }, FocusedSymbol = { bg = p.bg3 },
}
hl.syntax = { Type = { fg = p.blue } + styles.keywords,
Type = hl.predef.BlueItalic, Structure = { fg = p.blue } + styles.keywords,
Structure = hl.predef.BlueItalic, StorageClass = { fg = p.blue } + styles.keywords,
StorageClass = hl.predef.BlueItalic, Identifier = { fg = p.orange } + styles.identifiers,
Identifier = hl.predef.OrangeItalic, Constant = { fg = p.orange } + styles.variables,
Constant = hl.predef.OrangeItalic, PreProc = { fg = p.red },
PreProc = hl.predef.Red, PreCondit = { fg = p.red },
PreCondit = hl.predef.Red, Include = { fg = p.red },
Include = hl.predef.Red, Keyword = { fg = p.red } + styles.keywords,
Keyword = hl.predef.Red, Define = { fg = p.red },
Define = hl.predef.Red, Typedef = { fg = p.red },
Typedef = hl.predef.Red, Exception = { fg = p.red },
Exception = hl.predef.Red, Conditional = { fg = p.red },
Conditional = hl.predef.Red, Repeat = { fg = p.red },
Repeat = hl.predef.Red, Statement = { fg = p.red },
Statement = hl.predef.Red, Macro = { fg = p.purple },
Macro = hl.predef.Purple, Error = { fg = p.red },
Error = hl.predef.Red, Label = { fg = p.purple },
Label = hl.predef.Purple, Special = { fg = p.purple },
Special = hl.predef.Purple, SpecialChar = { fg = p.purple },
SpecialChar = hl.predef.Purple, Boolean = { fg = p.purple },
Boolean = hl.predef.Purple, String = { fg = p.yellow },
String = hl.predef.Yellow, Character = { fg = p.yellow },
Character = hl.predef.Yellow, Number = { fg = p.purple },
Number = hl.predef.Purple, Float = { fg = p.purple },
Float = hl.predef.Purple, Function = { fg = p.green } + styles.functions,
Function = hl.predef.Green, Operator = { fg = p.red },
Operator = hl.predef.Red, Title = { fg = p.yellow },
Title = hl.predef.Yellow, Tag = { fg = p.orange },
Tag = hl.predef.Orange, Delimiter = { fg = p.fg },
Delimiter = hl.predef.Fg, Comment = { fg = p.bg4 } + styles.comments,
Comment = { fg = p.bg4, italic = cfg.italic_comment }, SpecialComment = { fg = p.bg4 } + styles.comments,
SpecialComment = { fg = p.bg4, italic = cfg.italic_comment }, Todo = { fg = p.blue } + styles.comments,
Todo = { fg = p.blue, italic = cfg.italic_comment },
}
hl.plugins.lsp = { -- whichkey
LspCxxHlGroupEnumConstant = hl.predef.Orange, WhichKey = { fg = p.red },
LspCxxHlGroupMemberVariable = hl.predef.Orange, WhichKeyDesc = { fg = p.blue },
LspCxxHlGroupNamespace = hl.predef.Blue, WhichKeyGroup = { fg = p.orange },
LspCxxHlSkippedRegion = hl.predef.Grey, WhichKeySeperator = { fg = p.green },
LspCxxHlSkippedRegionBeginEnd = hl.predef.Red,
LspDiagnosticsDefaultError = { fg = u.color_gamma(p.red, 0.5) }, -- flash
LspDiagnosticsDefaultHint = { fg = u.color_gamma(p.purple, 0.5) }, FlashBackdrop = { fg = p.bg4 },
LspDiagnosticsDefaultInformation = { fg = u.color_gamma(p.blue, 0.5) }, FlashLabel = { fg = p.bg0, bg = p.blue, bold = true },
LspDiagnosticsDefaultWarning = { fg = u.color_gamma(p.yellow, 0.5) },
LspDiagnosticsUnderlineError = { underline = true, sp = u.color_gamma(p.red, 0.5) }, -- gitgutter
LspDiagnosticsUnderlineHint = { underline = true, sp = u.color_gamma(p.purple, 0.5) }, GitGutterAdd = { fg = p.diff_green },
LspDiagnosticsUnderlineInformation = { underline = true, sp = u.color_gamma(p.blue, 0.5) }, GitGutterChange = { fg = p.diff_blue },
LspDiagnosticsUnderlineWarning = { underline = true, sp = u.color_gamma(p.yellow, 0.5) }, GitGutterDelete = { fg = p.diff_red },
DiagnosticSignError = { fg = u.color_gamma(p.red, 0.5) },
DiagnosticSignHint = { fg = u.color_gamma(p.purple, 0.5) }, -- diffview
DiagnosticSignInfo = { fg = u.color_gamma(p.blue, 0.5) }, DiffviewFilePanelTitle = { fg = p.blue, bold = true },
DiagnosticSignWarn = { fg = u.color_gamma(p.yellow, 0.5) }, DiffviewFilePanelCounter = { fg = p.purple, bold = true },
DiffviewFilePanelFileName = { fg = p.fg },
DiffviewNormal = { link = "Normal" },
DiffviewCursorLine = { link = "CursorLine" },
DiffviewVertSplit = { link = "VertSplit" },
DiffviewSignColumn = { link = "SignColumn" },
DiffviewStatusLine = { link = "StatusLine" },
DiffviewStatusLineNC = { link = "StatusLineNC" },
DiffviewEndOfBuffer = { link = "EndOfBuffer" },
DiffviewFilePanelRootPath = { fg = p.grey },
DiffviewFilePanelPath = { fg = p.grey },
DiffviewFilePanelInsertions = { fg = p.green },
DiffviewFilePanelDeletions = { fg = p.red },
DiffviewStatusAdded = { fg = p.green },
DiffviewStatusUntracked = { fg = p.blue },
DiffviewStatusModified = { fg = p.blue },
DiffviewStatusRenamed = { fg = p.blue },
DiffviewStatusCopied = { fg = p.blue },
DiffviewStatusTypeChange = { fg = p.blue },
DiffviewStatusUnmerged = { fg = p.blue },
DiffviewStatusUnknown = { fg = p.red },
DiffviewStatusDeleted = { fg = p.red },
DiffviewStatusBroken = { fg = p.red },
-- comments
commentTSDanger = { fg = p.red } + styles.comments,
commentTSNote = { fg = p.blue } + styles.comments,
commentTSWarning = { fg = p.yellow } + styles.comments,
-- treesitter
["@annotation"] = { link = "PreProc", default = true },
["@attribute"] = { link = "PreProc", default = true },
["@boolean"] = { link = "Boolean", default = true },
["@character"] = { link = "Character", default = true },
["@character.special"] = { link = "SpecialChar", default = true },
["@comment"] = { link = "Comment", default = true },
["@conditional"] = { link = "Conditional", default = true },
["@constant"] = { link = "Constant", default = true },
["@constant.builtin"] = { link = "Special", default = true },
["@constant.macro"] = { link = "Define", default = true },
["@constructor"] = { link = "Special", default = true },
["@debug"] = { link = "Debug", default = true },
["@define"] = { link = "Define", default = true },
["@defaultLibrary"] = { link = "Special", default = true },
["@error"] = { link = "Error", default = true },
["@exception"] = { link = "Exception", default = true },
["@field"] = { link = "Identifier", default = true },
["@float"] = { link = "Float", default = true },
["@function"] = { link = "Function", default = true },
["@function.builtin"] = { link = "Special", default = true },
["@function.call"] = { link = "@function", default = true },
["@function.macro"] = { link = "Macro", default = true },
["@include"] = { link = "Include", default = true },
["@keyword"] = { link = "Keyword", default = true },
["@keyword.function"] = { link = "Keyword", default = true },
["@keyword.operator"] = { link = "@operator", default = true },
["@keyword.return"] = { link = "@keyword", default = true },
["@label"] = { link = "Label", default = true },
["@method"] = { link = "Function", default = true },
["@method.call"] = { link = "@method", default = true },
["@namespace"] = { link = "Include", default = true },
["@none"] = { bg = "NONE", fg = "NONE", default = true },
["@number"] = { link = "Number", default = true },
["@operator"] = { link = "Operator", default = true },
["@parameter"] = { link = "Identifier", default = true },
["@parameter.reference"] = { link = "@parameter", default = true },
["@preproc"] = { link = "PreProc", default = true },
["@property"] = { link = "Identifier", default = true },
["@punctuation.bracket"] = { link = "Delimiter", default = true },
["@punctuation.delimiter"] = { link = "Delimiter", default = true },
["@punctuation.special"] = { link = "Delimiter", default = true },
["@repeat"] = { link = "Repeat", default = true },
["@storageclass"] = { link = "StorageClass", default = true },
["@string"] = { link = "String", default = true },
["@string.escape"] = { link = "SpecialChar", default = true },
["@string.regex"] = { link = "String", default = true },
["@string.special"] = { link = "SpecialChar", default = true },
["@symbol"] = { link = "Identifier", default = true },
["@tag"] = { link = "Label", default = true },
["@tag.attribute"] = { link = "@property", default = true },
["@tag.delimiter"] = { link = "Delimiter", default = true },
["@text"] = { link = "@none", default = true },
["@text.danger"] = { link = "WarningMsg", default = true },
["@text.emphasis"] = { italic = true, default = true },
["@text.environment"] = { link = "Macro", default = true },
["@text.environment.name"] = { link = "Type", default = true },
["@text.literal"] = { link = "String", default = true },
["@text.math"] = { link = "Special", default = true },
["@text.note"] = { link = "SpecialComment", default = true },
["@text.reference"] = { link = "Constant", default = true },
["@text.strike"] = { strikethrough = true, default = true },
["@text.strong"] = { bold = true, default = true },
["@text.title"] = { link = "Title", default = true },
["@text.todo"] = { link = "Todo", default = true },
["@text.underline"] = { underline = true, default = true },
["@text.uri"] = { link = "Underlined", default = true },
["@text.warning"] = { link = "Todo", default = true },
["@todo"] = { link = "Todo", default = true },
["@type"] = { link = "Type", default = true },
["@type.builtin"] = { link = "Type", default = true },
["@type.definition"] = { link = "Typedef", default = true },
["@type.qualifier"] = { link = "Type", default = true },
["@variable"] = { fg = p.fg, default = true } + styles.variables,
["@variable.builtin"] = { fg = p.purple, default = true },
-- lsp
LspCxxHlGroupEnumConstant = { fg = p.orange },
LspCxxHlGroupMemberVariable = { fg = p.orange },
LspCxxHlGroupNamespace = { fg = p.blue },
LspCxxHlSkippedRegion = { fg = p.grey },
LspCxxHlSkippedRegionBeginEnd = { fg = p.red },
LspDiagnosticsDefaultError = { fg = p.red + gamma(0.5) },
LspDiagnosticsDefaultHint = { fg = p.purple + gamma(0.5) },
LspDiagnosticsDefaultInformation = { fg = p.blue + gamma(0.5) },
LspDiagnosticsDefaultWarning = { fg = p.yellow + gamma(0.5) },
LspDiagnosticsUnderlineError = { underline = true, sp = p.red + gamma(0.5) },
LspDiagnosticsUnderlineHint = {
underline = true,
sp = p.purple + gamma(0.5),
},
LspDiagnosticsUnderlineInformation = {
underline = true,
sp = p.blue + gamma(0.5),
},
LspDiagnosticsUnderlineWarning = {
underline = true,
sp = p.yellow + gamma(0.5),
},
DiagnosticSignError = { fg = p.red + gamma(0.5) },
DiagnosticSignHint = { fg = p.purple + gamma(0.5) },
DiagnosticSignInfo = { fg = p.blue + gamma(0.5) },
DiagnosticSignWarn = { fg = p.yellow + gamma(0.5) },
LspReferenceRead = { bg = p.bg3 }, LspReferenceRead = { bg = p.bg3 },
LspReferenceWrite = { bg = p.bg3 }, LspReferenceWrite = { bg = p.bg3 },
LspReferenceText = { bg = p.bg3 }, LspReferenceText = { bg = p.bg3 },
LspInfoBorder = { fg = p.bg4 }, LspInfoBorder = { fg = p.bg4 },
}
hl.plugins.whichkey = { -- lsp semantic tokens
WhichKey = hl.predef.Red,
WhichKeyDesc = hl.predef.Blue,
WhichKeyGroup = hl.predef.Orange,
WhichKeySeperator = hl.predef.Green,
}
hl.plugins.flash = {
FlashBackdrop = { fg = p.bg4 },
FlashLabel = { fg = p.bg0, bg = p.blue, bold=true },
}
hl.plugins.gitgutter = {
GitGutterAdd = { fg = p.diff_green },
GitGutterChange = { fg = p.diff_blue },
GitGutterDelete = { fg = p.diff_red },
}
hl.plugins.diffview = {
DiffviewFilePanelTitle = { fg = p.blue, bold = true },
DiffviewFilePanelCounter = { fg = p.purple, bold = true },
DiffviewFilePanelFileName = hl.predef.Fg,
DiffviewNormal = hl.common.Normal,
DiffviewCursorLine = hl.common.CursorLine,
DiffviewVertSplit = hl.common.VertSplit,
DiffviewSignColumn = hl.common.SignColumn,
DiffviewStatusLine = hl.common.StatusLine,
DiffviewStatusLineNC = hl.common.StatusLineNC,
DiffviewEndOfBuffer = hl.common.EndOfBuffer,
DiffviewFilePanelRootPath = hl.predef.Grey,
DiffviewFilePanelPath = hl.predef.Grey,
DiffviewFilePanelInsertions = hl.predef.Green,
DiffviewFilePanelDeletions = hl.predef.Red,
DiffviewStatusAdded = hl.predef.Green,
DiffviewStatusUntracked = hl.predef.Blue,
DiffviewStatusModified = hl.predef.Blue,
DiffviewStatusRenamed = hl.predef.Blue,
DiffviewStatusCopied = hl.predef.Blue,
DiffviewStatusTypeChange = hl.predef.Blue,
DiffviewStatusUnmerged = hl.predef.Blue,
DiffviewStatusUnknown = hl.predef.Red,
DiffviewStatusDeleted = hl.predef.Red,
DiffviewStatusBroken = hl.predef.Red,
}
hl.plugins.treesitter = {
commentTSDanger = hl.predef.RedItalic,
commentTSNote = hl.predef.BlueItalic,
commentTSWarning = hl.predef.YellowItalic,
}
if u.check_min_version(0, 8, 0) then
hl.plugins.treesitter = {
["@annotation"] = { link = "PreProc" },
["@attribute"] = { link = "PreProc" },
["@boolean"] = { link = "Boolean" },
["@character"] = { link = "Character" },
["@character.special"] = { link = "SpecialChar" },
["@comment"] = { link = "Comment" },
["@conditional"] = { link = "Conditional" },
["@constant"] = { link = "Constant" },
["@constant.builtin"] = { link = "Special" },
["@constant.macro"] = { link = "Define" },
["@constructor"] = { link = "Special" },
["@debug"] = { link = "Debug" },
["@define"] = { link = "Define" },
["@defaultLibrary"] = { link = "Special" },
["@error"] = { link = "Error" },
["@exception"] = { link = "Exception" },
["@field"] = { link = "Identifier" },
["@float"] = { link = "Float" },
["@function"] = { link = "Function" },
["@function.builtin"] = { link = "Special" },
["@function.call"] = { link = "@function" },
["@function.macro"] = { link = "Macro" },
["@include"] = { link = "Include" },
["@keyword"] = { link = "Keyword" },
["@keyword.function"] = { link = "Keyword" },
["@keyword.operator"] = { link = "@operator" },
["@keyword.return"] = { link = "@keyword" },
["@label"] = { link = "Label" },
["@method"] = { link = "Function" },
["@method.call"] = { link = "@method" },
["@namespace"] = { link = "Include" },
["@none"] = { bg = "NONE", fg = "NONE" },
["@number"] = { link = "Number" },
["@operator"] = { link = "Operator" },
["@parameter"] = { link = "Identifier" },
["@parameter.reference"] = { link = "@parameter" },
["@preproc"] = { link = "PreProc" },
["@property"] = { link = "Identifier" },
["@punctuation.bracket"] = { link = "Delimiter" },
["@punctuation.delimiter"] = { link = "Delimiter" },
["@punctuation.special"] = { link = "Delimiter" },
["@repeat"] = { link = "Repeat" },
["@storageclass"] = { link = "StorageClass" },
["@string"] = { link = "String" },
["@string.escape"] = { link = "SpecialChar" },
["@string.regex"] = { link = "String" },
["@string.special"] = { link = "SpecialChar" },
["@symbol"] = { link = "Identifier" },
["@tag"] = { link = "Label" },
["@tag.attribute"] = { link = "@property" },
["@tag.delimiter"] = { link = "Delimiter" },
["@text"] = { link = "@none" },
["@text.danger"] = { link = "WarningMsg" },
["@text.emphasis"] = { italic = true },
["@text.environment"] = { link = "Macro" },
["@text.environment.name"] = { link = "Type" },
["@text.literal"] = { link = "String" },
["@text.math"] = { link = "Special" },
["@text.note"] = { link = "SpecialComment" },
["@text.reference"] = { link = "Constant" },
["@text.strike"] = { strikethrough = true },
["@text.strong"] = { bold = true },
["@text.title"] = { link = "Title" },
["@text.todo"] = { link = "Todo" },
["@text.underline"] = { underline = true },
["@text.uri"] = { link = "Underlined" },
["@text.warning"] = { link = "Todo" },
["@todo"] = { link = "Todo" },
["@type"] = { link = "Type" },
["@type.builtin"] = { link = "Type" },
["@type.definition"] = { link = "Typedef" },
["@type.qualifier"] = { link = "Type" },
["@variable"] = { link = "Normal" },
["@variable.builtin"] = { link = "Special" },
}
make_default(hl.plugins.treesitter)
hl.plugins.lsp_semantic_tokens = {
LspNamespace = { link = "@namespace" }, LspNamespace = { link = "@namespace" },
LspType = { link = "@type" }, LspType = { link = "@type" },
LspClass = { link = "@type" }, LspClass = { link = "@type" },
@@ -315,118 +319,100 @@ if u.check_min_version(0, 8, 0) then
LspOperator = { link = "@operator" }, LspOperator = { link = "@operator" },
LspDecorator = { link = "@symbol" }, LspDecorator = { link = "@symbol" },
LspDeprecated = { link = "@text.strike" }, LspDeprecated = { link = "@text.strike" },
}
end
hl.plugins.cmp = { -- cmp
CmpItemKindDefault = { fg = p.blue, bg = p.none }, CmpItemKindDefault = { fg = p.blue },
CmpItemAbbrMatch = { fg = p.blue, bg = p.none }, CmpItemAbbrMatch = { fg = p.blue },
CmpItemAbbrMatchFuzzy = { fg = p.blue, bg = p.none }, CmpItemAbbrMatchFuzzy = { fg = p.blue },
CmpItemKindKeyword = { fg = p.fg },
CmpItemKindVariable = { fg = p.cyan },
CmpItemKindConstant = { fg = p.cyan },
CmpItemKindReference = { fg = p.cyan },
CmpItemKindValue = { fg = p.cyan },
CmpItemKindFunction = { fg = p.purple },
CmpItemKindMethod = { fg = p.purple },
CmpItemKindConstructor = { fg = p.purple },
CmpItemKindClass = { fg = p.yellow },
CmpItemKindInterface = { fg = p.yellow },
CmpItemKindStruct = { fg = p.yellow },
CmpItemKindEvent = { fg = p.yellow },
CmpItemKindEnum = { fg = p.yellow },
CmpItemKindUnit = { fg = p.yellow },
CmpItemKindModule = { fg = p.yellow },
CmpItemKindProperty = { fg = p.green },
CmpItemKindField = { fg = p.green },
CmpItemKindTypeParameter = { fg = p.green },
CmpItemKindEnumMember = { fg = p.green },
CmpItemKindOperator = { fg = p.green },
CmpItemKindSnippet = { fg = p.red },
CmpItemKindKeyword = { fg = p.fg, bg = p.none }, -- coc
CocErrorSign = { fg = p.red + gamma(0.5) },
CocHintSign = { fg = p.red + gamma(0.5) },
CocInfoSign = { fg = p.red + gamma(0.5) },
CocWarningSign = { fg = p.red + gamma(0.5) },
FgCocErrorFloatBgCocFloating = { fg = p.red + gamma(0.5), bg = p.bg2 },
FgCocHintFloatBgCocFloating = { fg = p.purple + gamma(0.5), bg = p.bg2 },
FgCocInfoFloatBgCocFloating = { fg = p.blue + gamma(0.5), bg = p.bg2 },
FgCocWarningFloatBgCocFloating = { fg = p.yellow + gamma(0.5), bg = p.bg2 },
CmpItemKindVariable = { fg = p.cyan, bg = p.none }, -- gitsigns
CmpItemKindConstant = { fg = p.cyan, bg = p.none }, GitSignsAdd = { fg = p.green },
CmpItemKindReference = { fg = p.cyan, bg = p.none }, GitSignsAddLn = { fg = p.green },
CmpItemKindValue = { fg = p.cyan, bg = p.none }, GitSignsAddNr = { fg = p.green },
GitSignsChange = { fg = p.blue },
GitSignsChangeLn = { fg = p.blue },
GitSignsChangeNr = { fg = p.blue },
GitSignsDelete = { fg = p.red },
GitSignsDeleteLn = { fg = p.red },
GitSignsDeleteNr = { fg = p.red },
CmpItemKindFunction = { fg = p.purple, bg = p.none }, -- markdown
CmpItemKindMethod = { fg = p.purple, bg = p.none }, markdownBlockquote = { fg = p.grey },
CmpItemKindConstructor = { fg = p.purple, bg = p.none },
CmpItemKindClass = { fg = p.yellow, bg = p.none },
CmpItemKindInterface = { fg = p.yellow, bg = p.none },
CmpItemKindStruct = { fg = p.yellow, bg = p.none },
CmpItemKindEvent = { fg = p.yellow, bg = p.none },
CmpItemKindEnum = { fg = p.yellow, bg = p.none },
CmpItemKindUnit = { fg = p.yellow, bg = p.none },
CmpItemKindModule = { fg = p.yellow, bg = p.none },
CmpItemKindProperty = { fg = p.green, bg = p.none },
CmpItemKindField = { fg = p.green, bg = p.none },
CmpItemKindTypeParameter = { fg = p.green, bg = p.none },
CmpItemKindEnumMember = { fg = p.green, bg = p.none },
CmpItemKindOperator = { fg = p.green, bg = p.none },
CmpItemKindSnippet = { fg = p.red, bg = p.none },
}
hl.plugins.coc = {
CocErrorSign = { fg = u.color_gamma(p.red, 0.5) },
CocHintSign = { fg = u.color_gamma(p.red, 0.5) },
CocInfoSign = { fg = u.color_gamma(p.red, 0.5) },
CocWarningSign = { fg = u.color_gamma(p.red, 0.5) },
FgCocErrorFloatBgCocFloating = { fg = u.color_gamma(p.red, 0.5), bg = p.bg2 },
FgCocHintFloatBgCocFloating = { fg = u.color_gamma(p.purple, 0.5), bg = p.bg2 },
FgCocInfoFloatBgCocFloating = { fg = u.color_gamma(p.blue, 0.5), bg = p.bg2 },
FgCocWarningFloatBgCocFloating = { fg = u.color_gamma(p.yellow, 0.5), bg = p.bg2 },
}
hl.plugins.gitsigns = {
GitSignsAdd = hl.predef.Green,
GitSignsAddLn = hl.predef.Green,
GitSignsAddNr = hl.predef.Green,
GitSignsChange = hl.predef.Blue,
GitSignsChangeLn = hl.predef.Blue,
GitSignsChangeNr = hl.predef.Blue,
GitSignsDelete = hl.predef.Red,
GitSignsDeleteLn = hl.predef.Red,
GitSignsDeleteNr = hl.predef.Red,
}
hl.langs.markdown = {
markdownBlockquote = hl.predef.Grey,
markdownBold = { fg = p.none, bold = true }, markdownBold = { fg = p.none, bold = true },
markdownBoldDelimiter = hl.predef.Grey, markdownBoldDelimiter = { fg = p.grey },
markdownCode = hl.predef.Yellow, markdownCode = { fg = p.yellow },
markdownCodeBlock = hl.predef.Yellow, markdownCodeBlock = { fg = p.yellow },
markdownCodeDelimiter = hl.predef.Green, markdownCodeDelimiter = { fg = p.green },
markdownH1 = { fg = p.red, bold = true }, markdownH1 = { fg = p.red, bold = true },
markdownH2 = { fg = p.red, bold = true }, markdownH2 = { fg = p.red, bold = true },
markdownH3 = { fg = p.red, bold = true }, markdownH3 = { fg = p.red, bold = true },
markdownH4 = { fg = p.red, bold = true }, markdownH4 = { fg = p.red, bold = true },
markdownH5 = { fg = p.red, bold = true }, markdownH5 = { fg = p.red, bold = true },
markdownH6 = { fg = p.red, bold = true }, markdownH6 = { fg = p.red, bold = true },
markdownHeadingDelimiter = hl.predef.Grey, markdownHeadingDelimiter = { fg = p.grey },
markdownHeadingRule = hl.predef.Grey, markdownHeadingRule = { fg = p.grey },
markdownId = hl.predef.Yellow, markdownId = { fg = p.yellow },
markdownIdDeclaration = hl.predef.Red, markdownIdDeclaration = { fg = p.red },
markdownItalic = { fg = p.none, italic = true }, markdownItalic = { fg = p.none, italic = true },
markdownItalicDelimiter = { fg = p.grey, italic = true }, markdownItalicDelimiter = { fg = p.grey, italic = true },
markdownLinkDelimiter = hl.predef.Grey, markdownLinkDelimiter = { fg = p.grey },
markdownLinkText = hl.predef.Red, markdownLinkText = { fg = p.red },
markdownLinkTextDelimiter = hl.predef.Grey, markdownLinkTextDelimiter = { fg = p.grey },
markdownListMarker = hl.predef.Red, markdownListMarker = { fg = p.red },
markdownOrderedListMarker = hl.predef.Red, markdownOrderedListMarker = { fg = p.red },
markdownRule = hl.predef.Purple, markdownRule = { fg = p.purple },
markdownUrl = { fg = p.blue, underline = true }, markdownUrl = { fg = p.blue, underline = true },
markdownUrlDelimiter = hl.predef.Grey, markdownUrlDelimiter = { fg = p.grey },
markdownUrlTitleDelimiter = hl.predef.Green, markdownUrlTitleDelimiter = { fg = p.green },
}
hl.langs.scala = { -- scala
scalaNameDefinition = hl.predef.Fg, scalaNameDefinition = { fg = p.fg },
scalaInterpolationBoundary = hl.predef.Purple, scalaInterpolationBoundary = { fg = p.purple },
scalaInterpolation = hl.predef.Purple, scalaInterpolation = { fg = p.purple },
scalaTypeOperator = hl.predef.Red, scalaTypeOperator = { fg = p.red },
scalaOperator = hl.predef.Red, scalaOperator = { fg = p.red },
scalaKeywordModifier = hl.predef.Red, scalaKeywordModifier = { fg = p.red },
} }
local function load_sync()
load_highlights(hl.predef)
load_highlights(hl.common)
load_highlights(hl.syntax)
for _, group in pairs(hl.langs) do
load_highlights(group)
end
for _, group in pairs(hl.plugins) do
load_highlights(group)
end
end
function M.setup() function M.setup()
load_sync() local highlights = type(config.custom_highlights) == "function"
and config.custom_highlights(M.highlights, p)
or config.custom_highlights
load_highlights(vim.tbl_extend("force", M.highlights, highlights))
if config.terminal_colors then
terminal.setup()
end
end end
return M return M

View File

@@ -1,6 +1,3 @@
local highlights = require("tokyodark.highlights")
local terminal = require("tokyodark.terminal")
local M = {} local M = {}
function M.colorscheme() function M.colorscheme()
@@ -11,8 +8,9 @@ function M.colorscheme()
vim.o.background = "dark" vim.o.background = "dark"
vim.o.termguicolors = true vim.o.termguicolors = true
vim.g.colors_name = "tokyodark" vim.g.colors_name = "tokyodark"
highlights.setup() require("tokyodark.highlights").setup()
terminal.setup()
end end
M.setup = require("tokyodark.config").setup
return M return M

View File

@@ -1,7 +1,7 @@
local color_gamma = require("tokyodark.utils").color_gamma local config = require("tokyodark.config")
local gamma = require("tokyodark.config").gamma local utils = require("tokyodark.utils")
local colors = { local palette = {
black = "#06080A", black = "#06080A",
bg0 = "#11121D", bg0 = "#11121D",
bg1 = "#1A1B2A", bg1 = "#1A1B2A",
@@ -30,12 +30,17 @@ local colors = {
grey = "#4A5057", grey = "#4A5057",
none = "NONE", none = "NONE",
} }
local function gamma_correction(colors) local function gamma_correction(colors)
local colors_corrected = {} local colors_corrected = {}
for k, v in pairs(colors) do for k, v in pairs(colors) do
colors_corrected[k] = color_gamma(v, gamma) colors_corrected[k] = utils.color_gamma(v, config.gamma)
end end
return colors_corrected return colors_corrected
end end
return gamma_correction(colors) local custom_palette = type(config.custom_palette) == "function"
and config.custom_palette(palette)
or config.custom_palette
return gamma_correction(vim.tbl_extend("force", palette, custom_palette))

View File

@@ -19,7 +19,9 @@ end
function U.hex2rgb(hex) function U.hex2rgb(hex)
hex = hex:gsub("#", "") hex = hex:gsub("#", "")
return tonumber("0x" .. hex:sub(1, 2)), tonumber("0x" .. hex:sub(3, 4)), tonumber("0x" .. hex:sub(5, 6)) return tonumber("0x" .. hex:sub(1, 2)),
tonumber("0x" .. hex:sub(3, 4)),
tonumber("0x" .. hex:sub(5, 6))
end end
function U.gamma_corrector(value, gamma) function U.gamma_corrector(value, gamma)
@@ -39,18 +41,7 @@ function U.color_gamma(hex, gamma)
end end
function U.check_min_version(major, minor, patch) function U.check_min_version(major, minor, patch)
local version = vim.version() return vim.version.gt({ major, minor, patch }, vim.version())
local current_major = version.major
local current_minor = version.minor
local current_patch = version.patch
if current_major > major then
return true
elseif current_major == major and current_minor > minor then
return true
elseif current_major == major and current_minor == minor and current_patch >= patch then
return true
end
return false
end end
return U return U