diff --git a/lua/tokyo/config.lua b/lua/tokyo/config.lua index e69de29..9c76b5a 100644 --- a/lua/tokyo/config.lua +++ b/lua/tokyo/config.lua @@ -0,0 +1,4 @@ + +local cfg = {bg_transparent = true, italic_enabled = true, gamma = 1.0} + +return cfg diff --git a/lua/tokyo/init.lua b/lua/tokyo/init.lua index f2212fb..b246a8f 100644 --- a/lua/tokyo/init.lua +++ b/lua/tokyo/init.lua @@ -1,10 +1,24 @@ local M = {} +local hl = require('tokyo.theme') -function M.setup() require('tokyo.theme').set_hl() end +local highlight = vim.api.nvim_set_hl +local set_hl_ns = vim.api.nvim__set_hl_ns or vim.api.nvim_set_hl_ns +local create_namespace = vim.api.nvim_create_namespace +local function colorscheme() + vim.cmd("hi clear") + if vim.fn.exists("syntax_on") then vim.cmd("syntax reset") end + vim.o.background = "dark" + vim.o.termguicolors = true + local ns = create_namespace("tokyo") + for _, group in pairs(hl) do + for group_name, group_settings in pairs(group) do + highlight(ns, group_name, group_settings) + end + end + set_hl_ns(ns) +end --- vim.cmd [[augroup Tokyo]] --- vim.cmd [[ autocmd!]] --- vim.cmd [[ autocmd ColorScheme * lua require("tokyo.theme").set_hl()]] +function M.setup() colorscheme() end return M diff --git a/lua/tokyo/palette.lua b/lua/tokyo/palette.lua index 7e35aec..d3d2ace 100644 --- a/lua/tokyo/palette.lua +++ b/lua/tokyo/palette.lua @@ -1,3 +1,6 @@ +local color_gamma = require('tokyo.utils').color_gamma +local gamma = require('tokyo.config').gamma + local colors = { black = '#06080A', bg0 = '#11121D', @@ -21,5 +24,10 @@ local colors = { grey = '#3b4261', none = 'NONE' } +local function gamma_correction(colors) + local colors_corrected = {} + for k, v in pairs(colors) do colors_corrected[k] = color_gamma(v, gamma) end + return colors_corrected +end -return colors +return gamma_correction(colors) diff --git a/lua/tokyo/theme.lua b/lua/tokyo/theme.lua index b222b80..b3f2a3f 100644 --- a/lua/tokyo/theme.lua +++ b/lua/tokyo/theme.lua @@ -1,11 +1,8 @@ -local M = {} local p = require 'tokyo.palette' -local utils = require 'tokyo.utils' local function opt_italic(lhs, rhs) vim.tbl_extend('force', lhs, {italic = rhs}) end +local cfg = require('tokyo.config') local hl = {} -local cfg = {bg_transparent = false, italic_enabled = true} - hl.predef = { Fg = {fg = p.fg}, Gray = {fg = p.gray}, @@ -15,18 +12,15 @@ hl.predef = { Green = {fg = p.green}, Blue = {fg = p.blue}, Purple = {fg = p.purple}, - BlueItalic = {fg = p.blue, italic = true}, - GreenItalic = {fg = p.green, italic = true}, - RedItalic = {fg = p.red, italic = true} } hl.common = { - Normal = {fg = p.fg, bg = not cfg.bg_transparent and p.bg0}, - Terminal = {fg = p.fg, bg = not cfg.bg_transparent and p.bg0}, - EndOfBuffer = {fg = p.bg2, bg = not cfg.bg_transparent and p.bg0}, - FoldColumn = {fg = p.fg, bg = not cfg.bg_transparent and p.bg1}, - Folded = {fg = p.fg, bg = not cfg.bg_transparent and p.bg1}, - SignColumn = {fg = p.fg, bg = not cfg.bg_transparent and p.bg0}, + Normal = {fg = p.fg, bg = cfg.bg_transparent and p.none or p.bg0}, + Terminal = {fg = p.fg, bg = cfg.bg_transparent and p.none or p.bg0}, + EndOfBuffer = {fg = p.bg2, bg = cfg.bg_transparent and p.none or p.bg0}, + FoldColumn = {fg = p.fg, bg = cfg.bg_transparent and p.none or p.bg1}, + Folded = {fg = p.fg, bg = cfg.bg_transparent and p.none or p.bg1}, + SignColumn = {fg = p.fg, bg = cfg.bg_transparent and p.none or p.bg0}, ToolbarLine = {fg = p.fg}, Cursor = {reverse = true}, vCursor = {reverse = true}, @@ -297,30 +291,5 @@ hl.cmake = { cmakeKWwrite_file = hl.predef.Green } -local highlight = vim.api.nvim_set_hl -local set_hl_ns = vim.api.nvim__set_hl_ns -local create_namespace = vim.api.nvim_create_namespace - -function M.set_hl() - vim.cmd("hi clear") - if vim.fn.exists("syntax_on") then vim.cmd("syntax reset") end - vim.o.background = "dark" - vim.o.termguicolors = true - vim.g.colors_name = "tokyo" - local ns = create_namespace("tokyo") - for _, group in pairs(hl) do - for group_name, group_settings in pairs(group) do - if group_settings.link ~= nil then - print(group_settings.link) - end - highlight(ns, group_name, group_settings) - -- print(group_name) - end - end - set_hl_ns(ns) - -end - -return M --- utils.tprint(hl) +return hl diff --git a/lua/tokyo/utils.lua b/lua/tokyo/utils.lua index 526f39f..d7d5925 100644 --- a/lua/tokyo/utils.lua +++ b/lua/tokyo/utils.lua @@ -16,8 +16,25 @@ function U.tprint(tbl, indent) end function U.hex2rgb(hex) - hex = hex:gsub("#","") - return tonumber("0x"..hex:sub(1,2)), tonumber("0x"..hex:sub(3,4)), tonumber("0x"..hex:sub(5,6)) + hex = hex:gsub("#", "") + return tonumber("0x" .. hex:sub(1, 2)), tonumber("0x" .. hex:sub(3, 4)), + tonumber("0x" .. hex:sub(5, 6)) +end + +function U.gamma_corrector(value, gamma) + value = ((value / 255) ^ (1 / gamma)) * 255 + return math.min(math.max(math.floor(value), 0), 255) +end + +function U.color_gamma(hex, gamma) + if hex:find('#') == nil then + return hex + end + local r, g, b = U.hex2rgb(hex) + r = U.gamma_corrector(r, gamma) + g = U.gamma_corrector(g, gamma) + b = U.gamma_corrector(b, gamma) + return string.format("#%02x%02x%02x", r, g, b) end return U