Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 21 additions & 20 deletions lua/one_monokai/colors.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
---@class one_monokai.colors
---@field [string] string|number
local colors = {}

---@class colors
---@type one_monokai.colors
local defaults = {
fg = "#abb2bf",
bg = "#282c34",
Expand All @@ -27,12 +29,11 @@ local defaults = {
none = "NONE",
}

---@type colors
colors = vim.deepcopy(defaults)

---Converts a hex color to an RGB table
---@param color string #Hex color
---@return integer[] #RGB table {r, g, b}
---Converts a hex color to an RGB table.
---@param color string #Hex color.
---@return integer[] #RGB table {r, g, b}.
local function hex2rgb(color)
color = color:lower()

Expand All @@ -45,11 +46,11 @@ end

---Blends two hex colors together based on the alpha value.
---
---[View source](https://github.com/folke/tokyonight.nvim/blob/main/lua/tokyonight/util.lua)
---@param fg string #Foreground hex color
---@param bg string #Background hex color
---@param alpha number #Blend factor between 0 (only bg) and 1 (only fg)
---@return string #Hex color of the resulting blended color
---[View source](https://github.com/folke/tokyonight.nvim/blob/main/lua/tokyonight/util.lua).
---@param fg string #Foreground hex color.
---@param bg string #Background hex color.
---@param alpha number #Blend factor between 0 (only bg) and 1 (only fg).
---@return string #Hex color of the resulting blended color.
local function blend(fg, bg, alpha)
local bg_rgb = hex2rgb(bg)
local fg_rgb = hex2rgb(fg)
Expand All @@ -61,25 +62,25 @@ local function blend(fg, bg, alpha)
return ("#%02x%02x%02x"):format(r, g, b)
end

---Darkens the current hex color
---Darkens the current hex color.
---@param s string
---@param alpha number #Value between 0 and 1
---@param alpha number #Value between 0 and 1.
function string.darken(s, alpha)
return blend(s, "#000000", alpha)
end

---Lightens the current hex color
---Lightens the current hex color.
---@param s string
---@param alpha number #Value between 0 and 1
---@param alpha number #Value between 0 and 1.
function string.lighten(s, alpha)
return blend(s, "#ffffff", alpha)
end

---Resolve and retrieve the value of a color
---@param name string #Name of the color
---@param value string|number #Value of the color
---@return string|number? #Hex color or 24-bit RGB value, or default if invalid
local function resolve_color(name, value)
---Resolve and retrieve the value of a color.
---@param name string #Name of the color.
---@param value string|number #Value of the color.
---@return string|number? #Hex color or 24-bit RGB value, or default if invalid.
local function resolve(name, value)
local color_type = type(value)

-- Resolve string first to optimize the common case
Expand Down Expand Up @@ -115,7 +116,7 @@ end
local config = require "one_monokai.config"

for name, value in pairs(config.colors or {}) do
colors[name] = resolve_color(name, value)
colors[name] = resolve(name, value)
end

return colors
16 changes: 8 additions & 8 deletions lua/one_monokai/config.lua
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
---@class one_monokai.config
---@field transparent boolean #Whether to enable transparent background.
---@field colors? one_monokai.colors #Custom colors.
---@field highlights? fun(colors:one_monokai.colors):one_monokai.highlights.groups #Custom highlight groups.
---@field italics boolean #Whether to apply italics to certain highlight groups.
local config = {}

---@class options
---@field transparent boolean #Whether to enable transparent background
---@field colors? colors #Custom colors
---@field highlights? fun(colors:colors):groups #Custom highlight groups
---@field italics boolean #Whether to apply italics to certain highlight groups
---@type one_monokai.config
local defaults = {
transparent = false,
colors = nil,
Expand All @@ -14,11 +15,10 @@ local defaults = {
italics = true,
}

---@type options
local options = vim.deepcopy(defaults)

---Extend default with user's config
---@param opts options
---Extend default with user's config.
---@param opts one_monokai.config
function config.extend(opts)
if not opts or vim.tbl_isempty(opts) then
return
Expand Down
8 changes: 4 additions & 4 deletions lua/one_monokai/highlights/groups.lua
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
---@class one_monokai.highlights.groups
---@field [string] vim.api.keyset.highlight
local groups = {}

local colors = require "one_monokai.colors"
local config = require "one_monokai.config"

---@class groups
---@type one_monokai.highlights.groups
local defaults = {
Boolean = { fg = colors.cyan },
Character = { fg = colors.yellow },
Expand Down Expand Up @@ -764,15 +766,13 @@ local defaults = {
SnacksPickerMatch = { fg = colors.green },
}

-- hide all semantic highlights by default,
-- only enable those from the default table
-- Hide all semantic highlights by default, only enable those from the default table.
for _, semantic_group in ipairs(vim.fn.getcompletion("@lsp", "highlight")) do
if not defaults[semantic_group] then
defaults[semantic_group] = {}
end
end

---@type groups
groups = vim.deepcopy(defaults)

return groups
7 changes: 4 additions & 3 deletions lua/one_monokai/highlights/init.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
---@class one_monokai.highlights
local highlights = {}

---Set highlight groups
---@param groups groups #Highlight groups
---Set highlight groups.
---@param groups one_monokai.highlights.groups #Highlight groups.
local function set_highlight(groups)
local logs = require "one_monokai.logs"
local set_hl = vim.api.nvim_set_hl
Expand All @@ -15,7 +16,7 @@ local function set_highlight(groups)
end
end

---Load all highlight groups
---Load all highlight groups.
function highlights.load()
local config = require "one_monokai.config"
local default = require "one_monokai.highlights.groups"
Expand Down
8 changes: 4 additions & 4 deletions lua/one_monokai/logs.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---@class logs
---@class one_monokai.logs
local logs = {}

---Display a notification to the user
---Display a notification to the user.
---@param level vim.log.levels
---@param s string|number
---@param ... any
Expand All @@ -13,14 +13,14 @@ local function notify(level, s, ...)
})
end

---Display an error message to the user
---Display an error message to the user.
---@param s string|number
---@param ... any
logs.error = function(s, ...)
notify(vim.log.levels.ERROR, s, ...)
end

---Display a warning message to the user
---Display a warning message to the user.
---@param s string|number
---@param ... any
logs.warning = function(s, ...)
Expand Down
Loading