From bba8397e2e60cd8fb0bcd70dce5cf45e81956f34 Mon Sep 17 00:00:00 2001 From: Ramojus Lapinskas <41536253+ramojus@users.noreply.github.com> Date: Sat, 14 Sep 2024 17:39:40 +0300 Subject: [PATCH] feat!: add breaking v1 changes (#67) Not the best way to introduce this many changes (with one merge), but I really wanted to avoid breaking people's configs a bunch of times. The changes (every pull request has a link to migration instructions): - feat(colors): allow color overrides to override shades with predefined colors (#45) - chore(naming): rename color set to colorset (#46) - chore: remove deprecated meliora module (a9ed485) - fix(config): change styles to match with names of colorset colors (#57) - chore(config): deprecate global `neutral` option (#59) - chore(mellifluous): remove `bg_contrast` option (#60) --- README.md | 185 ++++++++-------- doc/mellifluous.txt | 206 +++++++++--------- lua/meliora/init.lua | 8 - lua/mellifluous/cli.lua | 8 +- lua/mellifluous/color.lua | 2 +- .../colors/{sets => colorsets}/alduin.lua | 0 .../{sets => colorsets}/kanagawa_dragon.lua | 0 .../{sets => colorsets}/mellifluous.lua | 44 +--- .../colors/{sets => colorsets}/mountain.lua | 0 .../colors/{sets => colorsets}/tender.lua | 0 lua/mellifluous/colors/init.lua | 93 +++++--- lua/mellifluous/colors/shades.lua | 4 +- lua/mellifluous/config.lua | 44 ++-- lua/mellifluous/highlights/custom_groups.lua | 2 +- lua/mellifluous/highlights/general.lua | 16 +- .../highlights/plugins/treesitter.lua | 2 +- 16 files changed, 322 insertions(+), 292 deletions(-) delete mode 100644 lua/meliora/init.lua rename lua/mellifluous/colors/{sets => colorsets}/alduin.lua (100%) rename lua/mellifluous/colors/{sets => colorsets}/kanagawa_dragon.lua (100%) rename lua/mellifluous/colors/{sets => colorsets}/mellifluous.lua (65%) rename lua/mellifluous/colors/{sets => colorsets}/mountain.lua (100%) rename lua/mellifluous/colors/{sets => colorsets}/tender.lua (100%) diff --git a/README.md b/README.md index ce9f1b7..7343dbf 100644 --- a/README.md +++ b/README.md @@ -4,13 +4,13 @@ A colorscheme for [Neovim](https://github.com/neovim/neovim). Pleasant and produ ![preview](https://github.com/ramojus/mellifluous.nvim/assets/41536253/a4b01a46-6ec9-408a-9c2f-08995c53155a) ## Highlighted features -- [**Multiple color sets**](#color-sets): Each color set presents a unique visual theme while adhering to the same set of productive highlight rules. Every color set [can be customised](#overriding-colors-of-a-color-set). +- [**Multiple colorsets**](#color-sets): Each colorset presents a unique visual theme while adhering to the same set of productive highlight rules. Every colorset [can be customised](#overriding-colors-of-a-color-set). - **Layered backgrounds**: Most UI elements have backgrounds with different shades of the background color and have no borders. This allows for easy differentiation between the relative importance of the elements and keeps the colorscheme looking minimal. - [**Oklab color space**](https://bottosson.github.io/posts/oklab/): To truly achieve perceptually uniform variations of colors, all color modifications are done in this color space; thanks to [mini.colors](https://github.com/echasnovski/mini.colors) project for the code and idea. -- **Small number of colors**: Color sets use a small number of colors to provide distraction-free coding experience. +- **Small number of colors**: Colorsets use a small number of colors to provide distraction-free coding experience. - **Stronger highlights on important keywords**: Keywords related to control flow have stronger highlights, making it easier to quickly understand the code. @@ -51,24 +51,20 @@ Here is an example with the default config. This is optional, and only relevant ```lua require("mellifluous").setup({ dim_inactive = false, - color_set = "mellifluous", + colorset = "mellifluous", styles = { -- see :h attr-list for options. set {} for NONE, { option = true } for option - comments = { italic = true }, - conditionals = {}, - folds = {}, - loops = {}, - functions = {}, - keywords = {}, - strings = {}, - variables = {}, - numbers = {}, - booleans = {}, - properties = {}, + main_keywords = {}, + other_keywords = {}, types = {}, operators = {}, + strings = {}, + functions = {}, + constants = {}, + comments = { italic = true }, markup = { headings = { bold = true }, }, + folds = {}, }, transparent_background = { enabled = false, @@ -104,15 +100,15 @@ require("mellifluous").setup({ }) ``` -### Setting light theme -Set `vim.opt.background` to `"light"`. This will only work on color sets that have light theme. +### Light theme +For light theme, set `vim.opt.background` to `"light"`. This will only work on colorsets that have light theme. -### Color sets -Non-original color sets are made to match their original version as closely as possible with the same highlight rules as mellifluous. +### Colorsets +Non-original colorsets are made to match their original version as closely as possible with the same highlight rules as mellifluous. -These color sets don't get loaded, unless you specify them in a `color_set` option, so there is no performance impact. +These colorsets don't get loaded, unless you specify them in a `colorset` option, so there is no performance impact. -Available color sets: +Available colorsets: - `mellifluous`. Dark and light, original. - `alduin`. Dark, [link to original](https://github.com/alessandroyorba/alduin). @@ -120,50 +116,35 @@ Available color sets: - `tender`. Dark, [link to original](https://github.com/jacoborus/tender.vim). - `kanagawa_dragon`. Dark, [link to original](https://github.com/rebelot/kanagawa.nvim). -#### Mellifluous color set configuration +#### Mellifluous colorset configuration Default config: ```lua require("mellifluous").setup({ mellifluous = { - neutral = true, -- set this to false and bg_contrast to "medium" for original mellifluous (then it was called meliora theme) - bg_contrast = "medium", -- options: "soft", "medium", "hard" + neutral = true, -- set this to false for original mellifluous (when it was called meliora theme) }, }) ``` -#### Overriding colors of a color set +### Color overrides The following snippet shows where and which colors can be overridden: ```lua require("mellifluous").setup({ - = { -- name any of the defined color sets + = { -- name any of the defined colorsets color_overrides = { - dark = { -- dark variant of the color set - bg = nil, -- used for shades, on some color sets fg will be derived from this - fg = nil, -- used for shades if shades_fg is undefined - shades_fg = nil, -- used for shades (dimmed foregrounds) - - main_keywords = nil, - other_keywords = nil, - types = nil, - operators = nil, - strings = nil, - functions = nil, - constants = nil, - comments = nil, - - red = nil, -- errors, deletes, bad spellings - orange = nil, -- warnings, changes, unusual spellings - green = nil, -- staged, additions - blue = nil, -- information, new files - purple = nil, -- hints, merge - - -- for better terminal highlights - yellow = nil, - cyan = nil, + dark = { -- for dark theme + bg = function(bg) -- bg is used for bg shades and may be used for some colorset colors + return + end, + colors = function(colors) + return { + -- check "Available colors" section for colors that can be used and overriden. + } + end, }, - light = { -- light variant of the color set + light = { -- for light theme -- same keys as in dark variant }, }, @@ -171,48 +152,70 @@ require("mellifluous").setup({ }) ``` -For example, to override a color for the main keywords group in the dark version of the mellifluous color set, one could do the following: +To override colors for all colorsets, omit `` table. + +NOTE: parameter `colors` will have all of the colors set by the colorset, but it will not have shades. + +Example: ```lua require("mellifluous").setup({ + -- invert bg shades for all colorsets + color_overrides = { + dark = { + colors = function(colors) + return { + bg2 = colors.bg:darkened(2), + bg3 = colors.bg:darkened(4), + bg4 = colors.bg:darkened(6), + bg5 = colors.bg:darkened(8), + } + end, + } + }, + -- modify some colors for mellifluous colorset mellifluous = { color_overrides = { dark = { - main_keywords = "#e0e066", + bg = function(bg) + return bg:lightened(2) + end, + colors = function(colors) + return { + main_keywords = "#e0e066", + operators = colors.functions:desaturated(10), + } + end, }, }, }, }) ``` -#### Overriding highlights of a color set -The following snippet shows how highlight overrides can be defined for a specific color set: - -```lua -require("mellifluous").setup({ - = { -- name any of the defined color sets - -- config structure from here is the same as for global highlight overrides - }, -}) -``` - -For further instructions, refer to [overriding highlights](#overriding-highlights) section - -##### Extra colors -In addition to the colors listed in [available colors](#available-colors) section, some color sets may have more colors available (`cyan`). To check your color set, refer to [the source code for color sets](lua/mellifluous/colors/sets/) and see if `get_colors_*` functions return any extra (optional) colors. - -### Overriding highlights -The following snippet shows how global (for any color set) highlight overrides can be defined: +### Highlight overrides +The following snippet shows how highlight overrides can be defined: ```lua require("mellifluous").setup({ + -- highlight overrides for all colorsets highlight_overrides = { - dark = function(highlighter, colors) -- dark variant of the color set + dark = function(highlighter, colors) -- dark theme -- set highlights here (using highlighter) end, - light = function(highlighter, colors) -- light variant of the color set + light = function(highlighter, colors) -- light theme -- set highlights here (using highlighter) end, }, + -- highlight overrides for specific colorset + = { + highlight_overrides = { + dark = function(highlighter, colors) -- dark variant of the colorset + -- set highlights here (using highlighter) + end, + light = function(highlighter, colors) -- light variant of the colorset + -- set highlights here (using highlighter) + end, + }, + }, }) ``` @@ -238,12 +241,12 @@ highlighter.get(name) This function returns highlight definition map for highlight group with the requested name. -#### Available colors -To use one of the available colors from a color set, in highlight definition map, set the value of `fg`, `bg` or `sp` key to `colors.available_color` +### Available colors +Named colors are used several times in configuration (as parameter `colors` of some function). This section lists and explains those colors. Available colors: -- Syntax element colors. +- Syntax element colors - `main_keywords`: used to indicate keywords related to control flow. - `other_keywords` - `types` @@ -254,22 +257,34 @@ Available colors: - `comments` - `fg`: in code -- identifiers. - `bg` -- Named colors. Used for terminal colors, but most of these colors will match some syntax element color. +- Named colors: used for terminal colors, but most of these colors will match some syntax element color. - `red` - `orange` - `green` - `blue` - `purple` - `yellow` -- UI colors. Same as named colors, but all are of the same brightness (lightness). - - `ui_red`: used to indicate errors, deletes, bad spellings. - - `ui_orange`: used to indicate warnings, changes, other (strange) spellings. - - `ui_green`: used to indicate staged, additions. - - `ui_blue`: used to indicate information, new files. - - `ui_purple`: used to indicate hints, merge. - - `ui_yellow` - -NOTE: some color sets may have more colors available. See [extra colors](#extra-colors) section. +- Shades: colors that are derived from colors defined in the colorset (those listed above). + - UI colors: same as named colors, but all are of the same brightness (lightness). + - `ui_red`: used to indicate errors, deletes, bad spellings. + - `ui_orange`: used to indicate warnings, changes, other (strange) spellings. + - `ui_green`: used to indicate staged, additions. + - `ui_blue`: used to indicate information, new files. + - `ui_purple`: used to indicate hints, merge. + - `ui_yellow` + - Shades of fg and bg colors. These colors might be used for more than explained below. + - `fg2`: used for statusline, normal text in plugins that open in split windows. + - `fg3`: used for folded text. + - `fg4`: used for line numbers. + - `fg5`: used for active indent line, "hidden" text. + - `dark_bg`: used for background in plugins that open in split windows. + - `bg2`: used for cursorline/column, some floating windows. + - `bg3`: used for folded text background, floating windows, showing LSP references. + - `bg4`: used for visual mode, completion menu, statusline, fg of inactive indent line. + - `bg5` (only for dark background): indicates a more prominent selection than visual, might be deprecated in the future. + - `dark_bg2`(only for light background): used as a replacement for bg5 and also for visual mode + +Some colorsets may have more colors available. To check that, refer to [the source of the colorset](lua/mellifluous/colors/colorsets/). #### Color functions Every color from [available colors](#available-colors) has the following meta functions (accessed with `:` operator): @@ -289,7 +304,7 @@ Type `:Mellifluous ` and see the available options. Options include: - Toggling transparency. -- Changing color set. +- Changing colorset. ## TODO - [ ] Support more plugins (contributions are welcome). diff --git a/doc/mellifluous.txt b/doc/mellifluous.txt index 438f773..4d4a6b2 100644 --- a/doc/mellifluous.txt +++ b/doc/mellifluous.txt @@ -6,9 +6,11 @@ Table of Contents *mellifluous-table-of-contents* 1. Styled plugins |mellifluous-styled-plugins| 2. Installation and usage |mellifluous-installation-and-usage| 3. Configuration |mellifluous-configuration| - - Setting light theme |mellifluous-configuration-setting-light-theme| - - Color sets |mellifluous-configuration-color-sets| - - Overriding highlights |mellifluous-configuration-overriding-highlights| + - Light theme |mellifluous-configuration-light-theme| + - Colorsets |mellifluous-configuration-colorsets| + - Color overrides |mellifluous-configuration-color-overrides| + - Highlight overrides |mellifluous-configuration-highlight-overrides| + - Available colors |mellifluous-configuration-available-colors| 4. CLI options |mellifluous-cli-options| 5. TODO |mellifluous-todo| 6. Ports |mellifluous-ports| @@ -60,24 +62,20 @@ parts of the config can be included. >lua require("mellifluous").setup({ dim_inactive = false, - color_set = "mellifluous", + colorset = "mellifluous", styles = { -- see :h attr-list for options. set {} for NONE, { option = true } for option - comments = { italic = true }, - conditionals = {}, - folds = {}, - loops = {}, - functions = {}, - keywords = {}, - strings = {}, - variables = {}, - numbers = {}, - booleans = {}, - properties = {}, + main_keywords = {}, + other_keywords = {}, types = {}, operators = {}, + strings = {}, + functions = {}, + constants = {}, + comments = { italic = true }, markup = { headings = { bold = true }, }, + folds = {}, }, transparent_background = { enabled = false, @@ -114,21 +112,21 @@ parts of the config can be included. < -SETTING LIGHT THEME *mellifluous-configuration-setting-light-theme* +LIGHT THEME *mellifluous-configuration-light-theme* -Set `vim.opt.background` to `"light"`. This will only work on color sets that -have light theme. +For light theme, set `vim.opt.background` to `"light"`. This will only work on +colorsets that have light theme. -COLOR SETS *mellifluous-configuration-color-sets* +COLORSETS *mellifluous-configuration-colorsets* -Non-original color sets are made to match their original version as closely as +Non-original colorsets are made to match their original version as closely as possible with the same highlight rules as mellifluous. -These color sets don’t get loaded, unless you specify them in a `color_set` +These colorsets don’t get loaded, unless you specify them in a `colorset` option, so there is no performance impact. -Available color sets: +Available colorsets: - `mellifluous`. Dark and light, original. - `alduin`. Dark, link to original . @@ -137,53 +135,38 @@ Available color sets: - `kanagawa_dragon`. Dark, link to original . -MELLIFLUOUS COLOR SET CONFIGURATION ~ +MELLIFLUOUS COLORSET CONFIGURATION ~ Default config: >lua require("mellifluous").setup({ mellifluous = { - neutral = true, -- set this to false and bg_contrast to "medium" for original mellifluous (then it was called meliora theme) - bg_contrast = "medium", -- options: "soft", "medium", "hard" + neutral = true, -- set this to false for original mellifluous (when it was called meliora theme) }, }) < -OVERRIDING COLORS OF A COLOR SET ~ +COLOR OVERRIDES *mellifluous-configuration-color-overrides* The following snippet shows where and which colors can be overridden: >lua require("mellifluous").setup({ - = { -- name any of the defined color sets + = { -- name any of the defined colorsets color_overrides = { - dark = { -- dark variant of the color set - bg = nil, -- used for shades, on some color sets fg will be derived from this - fg = nil, -- used for shades if shades_fg is undefined - shades_fg = nil, -- used for shades (dimmed foregrounds) - - main_keywords = nil, - other_keywords = nil, - types = nil, - operators = nil, - strings = nil, - functions = nil, - constants = nil, - comments = nil, - - red = nil, -- errors, deletes, bad spellings - orange = nil, -- warnings, changes, unusual spellings - green = nil, -- staged, additions - blue = nil, -- information, new files - purple = nil, -- hints, merge - - -- for better terminal highlights - yellow = nil, - cyan = nil, + dark = { -- for dark theme + bg = function(bg) -- bg is used for bg shades and may be used for some colorset colors + return + end, + colors = function(colors) + return { + -- check "Available colors" section for colors that can be used and overriden. + } + end, }, - light = { -- light variant of the color set + light = { -- for light theme -- same keys as in dark variant }, }, @@ -191,15 +174,41 @@ The following snippet shows where and which colors can be overridden: }) < -For example, to override a color for the main keywords group in the dark -version of the mellifluous color set, one could do the following: +To override colors for all colorsets, omit `` table. + +NOTE: parameter `colors` will have all of the colors set by the colorset, but +it will not have shades. + +Example: >lua require("mellifluous").setup({ + -- invert bg shades for all colorsets + color_overrides = { + dark = { + colors = function(colors) + return { + bg2 = colors.bg:darkened(2), + bg3 = colors.bg:darkened(4), + bg4 = colors.bg:darkened(6), + bg5 = colors.bg:darkened(8), + } + end, + } + }, + -- modify some colors for mellifluous colorset mellifluous = { color_overrides = { dark = { - main_keywords = "#e0e066", + bg = function(bg) + return bg:lightened(2) + end, + colors = function(colors) + return { + main_keywords = "#e0e066", + operators = colors.functions:desaturated(10), + } + end, }, }, }, @@ -207,45 +216,32 @@ version of the mellifluous color set, one could do the following: < -OVERRIDING HIGHLIGHTS OF A COLOR SET ~ +HIGHLIGHT OVERRIDES *mellifluous-configuration-highlight-overrides* -The following snippet shows how highlight overrides can be defined for a -specific color set: - ->lua - require("mellifluous").setup({ - = { -- name any of the defined color sets - -- config structure from here is the same as for global highlight overrides - }, - }) -< - -For further instructions, refer to |mellifluous-overriding-highlights| section - - -EXTRA COLORS - -In addition to the colors listed in |mellifluous-available-colors| section, -some color sets may have more colors available (`cyan`). To check your color -set, refer to the source code for color sets and -see if `get_colors_*` functions return any extra (optional) colors. - - -OVERRIDING HIGHLIGHTS *mellifluous-configuration-overriding-highlights* - -The following snippet shows how global (for any color set) highlight overrides -can be defined: +The following snippet shows how highlight overrides can be defined: >lua require("mellifluous").setup({ + -- highlight overrides for all colorsets highlight_overrides = { - dark = function(highlighter, colors) -- dark variant of the color set + dark = function(highlighter, colors) -- dark theme -- set highlights here (using highlighter) end, - light = function(highlighter, colors) -- light variant of the color set + light = function(highlighter, colors) -- light theme -- set highlights here (using highlighter) end, }, + -- highlight overrides for specific colorset + = { + highlight_overrides = { + dark = function(highlighter, colors) -- dark variant of the colorset + -- set highlights here (using highlighter) + end, + light = function(highlighter, colors) -- light variant of the colorset + -- set highlights here (using highlighter) + end, + }, + }, }) < @@ -278,14 +274,14 @@ This function returns highlight definition map for highlight group with the requested name. -AVAILABLE COLORS ~ +AVAILABLE COLORS *mellifluous-configuration-available-colors* -To use one of the available colors from a color set, in highlight definition -map, set the value of `fg`, `bg` or `sp` key to `colors.available_color` +Named colors are used several times in configuration (as parameter `colors` of +some function). This section lists and explains those colors. Available colors: -- Syntax element colors. +- Syntax element colors - `main_keywords`: used to indicate keywords related to control flow. - `other_keywords` - `types` @@ -296,23 +292,35 @@ Available colors: - `comments` - `fg`: in code – identifiers. - `bg` -- Named colors. Used for terminal colors, but most of these colors will match some syntax element color. +- Named colors: used for terminal colors, but most of these colors will match some syntax element color. - `red` - `orange` - `green` - `blue` - `purple` - `yellow` -- UI colors. Same as named colors, but all are of the same brightness (lightness). - - `ui_red`: used to indicate errors, deletes, bad spellings. - - `ui_orange`: used to indicate warnings, changes, other (strange) spellings. - - `ui_green`: used to indicate staged, additions. - - `ui_blue`: used to indicate information, new files. - - `ui_purple`: used to indicate hints, merge. - - `ui_yellow` - -NOTE: some color sets may have more colors available. See -|mellifluous-extra-colors| section. +- Shades: colors that are derived from colors defined in the colorset (those listed above). + - UI colors: same as named colors, but all are of the same brightness (lightness). + - `ui_red`: used to indicate errors, deletes, bad spellings. + - `ui_orange`: used to indicate warnings, changes, other (strange) spellings. + - `ui_green`: used to indicate staged, additions. + - `ui_blue`: used to indicate information, new files. + - `ui_purple`: used to indicate hints, merge. + - `ui_yellow` + - Shades of fg and bg colors. These colors might be used for more than explained below. + - `fg2`: used for statusline, normal text in plugins that open in split windows. + - `fg3`: used for folded text. + - `fg4`: used for line numbers. + - `fg5`: used for active indent line, "hidden" text. + - `dark_bg`: used for background in plugins that open in split windows. + - `bg2`: used for cursorline/column, some floating windows. + - `bg3`: used for folded text background, floating windows, showing LSP references. + - `bg4`: used for visual mode, completion menu, statusline, fg of inactive indent line. + - `bg5` (only for dark background): indicates a more prominent selection than visual, might be deprecated in the future. + - `dark_bg2`(only for light background): used as a replacement for bg5 and also for visual mode + +Some colorsets may have more colors available. To check that, refer to the +source of the colorset . COLOR FUNCTIONS ~ @@ -339,7 +347,7 @@ Type `:Mellifluous ` and see the available options. Options include: - Toggling transparency. -- Changing color set. +- Changing colorset. ============================================================================== diff --git a/lua/meliora/init.lua b/lua/meliora/init.lua deleted file mode 100644 index 05337e0..0000000 --- a/lua/meliora/init.lua +++ /dev/null @@ -1,8 +0,0 @@ -local M = {} - --- kept for compatibility with older configs. -function M.setup(user_config) - require("mellifluous").setup(user_config) -end - -return M diff --git a/lua/mellifluous/cli.lua b/lua/mellifluous/cli.lua index 18db46f..4bbe53b 100644 --- a/lua/mellifluous/cli.lua +++ b/lua/mellifluous/cli.lua @@ -4,8 +4,8 @@ function M.create() local options = { toggle_transparency = 100, } - local color_sets = require("mellifluous.colors").get_color_sets_table() - options = vim.tbl_deep_extend("force", options, color_sets) + local colorsets = require("mellifluous.colors").get_colorsets_table() + options = vim.tbl_deep_extend("force", options, colorsets) local config = require("mellifluous.config").config vim.api.nvim_create_user_command("Mellifluous", function(input) @@ -15,9 +15,9 @@ function M.create() enabled = not config.transparent_background.enabled, }, }) - elseif color_sets[input.args] then + elseif colorsets[input.args] then require("mellifluous").setup({ - color_set = input.args, + colorset = input.args, }) else require("mellifluous").print_error("unrecognised cli argument: '" .. input.args .. "'") diff --git a/lua/mellifluous/color.lua b/lua/mellifluous/color.lua index 37524b7..0024861 100644 --- a/lua/mellifluous/color.lua +++ b/lua/mellifluous/color.lua @@ -89,7 +89,7 @@ function color_meta:get_hsl() return hex_to_okhsl(self.hex) end -function M.color_set_to_hsl(colors) +function M.colorset_to_hsl(colors) for name, color in pairs(colors) do local okhsl = hex_to_okhsl(color.hex) okhsl.h = okhsl.h or 0 diff --git a/lua/mellifluous/colors/sets/alduin.lua b/lua/mellifluous/colors/colorsets/alduin.lua similarity index 100% rename from lua/mellifluous/colors/sets/alduin.lua rename to lua/mellifluous/colors/colorsets/alduin.lua diff --git a/lua/mellifluous/colors/sets/kanagawa_dragon.lua b/lua/mellifluous/colors/colorsets/kanagawa_dragon.lua similarity index 100% rename from lua/mellifluous/colors/sets/kanagawa_dragon.lua rename to lua/mellifluous/colors/colorsets/kanagawa_dragon.lua diff --git a/lua/mellifluous/colors/sets/mellifluous.lua b/lua/mellifluous/colors/colorsets/mellifluous.lua similarity index 65% rename from lua/mellifluous/colors/sets/mellifluous.lua rename to lua/mellifluous/colors/colorsets/mellifluous.lua index e4006d1..159f31c 100644 --- a/lua/mellifluous/colors/sets/mellifluous.lua +++ b/lua/mellifluous/colors/colorsets/mellifluous.lua @@ -1,51 +1,28 @@ local M = {} local color = require("mellifluous.color") -local color_set_name = "mellifluous" - -local function get_is_neutral(mellifluous_config) - local config = require("mellifluous.config").config - -- for compatibility with configs from before color set specific config was supported - if config.neutral ~= nil then - return config.neutral - end - return mellifluous_config.neutral -end +local colorset_name = "mellifluous" function M.get_bg_dark() local config = require("mellifluous.config").config - local mellifluous_config = config[color_set_name] - local is_neutral = get_is_neutral(mellifluous_config) - + local mellifluous_config = config[colorset_name] local brightness = 11.5 - if mellifluous_config.bg_contrast == "hard" then - brightness = brightness - 2 - elseif mellifluous_config.bg_contrast == "soft" then - brightness = brightness + 2 - end - if is_neutral then - return color.new_from_hsl({ h = 0, s = 0, l = brightness }) + if mellifluous_config.neutral == false then + return color.new_from_hsl({ h = 24, s = 10, l = brightness }) end - return color.new_from_hsl({ h = 24, s = 10, l = brightness }) + return color.new_from_hsl({ h = 0, s = 0, l = brightness }) end function M.get_bg_light() local config = require("mellifluous.config").config - local mellifluous_config = config[color_set_name] - local is_neutral = get_is_neutral(mellifluous_config) - + local mellifluous_config = config[colorset_name] local brightness = 91.5 - if mellifluous_config.bg_contrast == "hard" then - brightness = brightness + 2 - elseif mellifluous_config.bg_contrast == "soft" then - brightness = brightness - 2 - end - if is_neutral then - return color.new_from_hsl({ h = 0, s = 0, l = brightness }) + if mellifluous_config.neutral == false then + return color.new_from_hsl({ h = 24, s = 10, l = brightness }) end - return color.new_from_hsl({ h = 24, s = 10, l = brightness }) + return color.new_from_hsl({ h = 0, s = 0, l = brightness }) end function M.get_colors_dark(bg) @@ -122,8 +99,7 @@ end function M.get_config() return { - neutral = true, -- set this to false and bg_contrast to 'medium' for original mellifluous (then it was called mellifluous theme) - bg_contrast = "medium", -- options: 'soft', 'medium', 'hard' + neutral = true, } end diff --git a/lua/mellifluous/colors/sets/mountain.lua b/lua/mellifluous/colors/colorsets/mountain.lua similarity index 100% rename from lua/mellifluous/colors/sets/mountain.lua rename to lua/mellifluous/colors/colorsets/mountain.lua diff --git a/lua/mellifluous/colors/sets/tender.lua b/lua/mellifluous/colors/colorsets/tender.lua similarity index 100% rename from lua/mellifluous/colors/sets/tender.lua rename to lua/mellifluous/colors/colorsets/tender.lua diff --git a/lua/mellifluous/colors/init.lua b/lua/mellifluous/colors/init.lua index 8e6ccd7..b6b9c8b 100644 --- a/lua/mellifluous/colors/init.lua +++ b/lua/mellifluous/colors/init.lua @@ -1,6 +1,6 @@ local M = {} -function M.get_color_sets_table() +function M.get_colorsets_table() return { mellifluous = 1, alduin = 2, @@ -16,26 +16,47 @@ local function tbl_extend_non_nil(base_table, overlay_table) end end -local function get_color_overrides(is_bg_dark, color_set_name) +local function get_color_overrides_bg_fn() local config = require("mellifluous.config").config - local color_overrides = vim.tbl_get(config, color_set_name, "color_overrides", is_bg_dark and "dark" or "light") - or {} + local global_color_overrides_bg_fn = + vim.tbl_get(config, "color_overrides", config.is_bg_dark and "dark" or "light", "bg") + local color_overrides_bg_fn = + vim.tbl_get(config, config.colorset, "color_overrides", config.is_bg_dark and "dark" or "light", "bg") - for key, color in pairs(color_overrides) do - if color.hex then -- overrides were already converted to mellifluous.color - break - end - color_overrides[key] = require("mellifluous.color").new(color) + if color_overrides_bg_fn == nil then + color_overrides_bg_fn = global_color_overrides_bg_fn end - return color_overrides + return color_overrides_bg_fn +end + +local function apply_color_overrides(colors) + local config = require("mellifluous.config").config + local global_color_overrides_fn = + vim.tbl_get(config, "color_overrides", config.is_bg_dark and "dark" or "light", "colors") + local color_overrides_fn = + vim.tbl_get(config, config.colorset, "color_overrides", config.is_bg_dark and "dark" or "light", "colors") + + if global_color_overrides_fn ~= nil then + tbl_extend_non_nil(colors, global_color_overrides_fn(colors)) + end + if color_overrides_fn ~= nil then + tbl_extend_non_nil(colors, color_overrides_fn(colors)) + end + return colors +end + +local function ensure_correct_color_types(colors) + local color_lib = require("mellifluous.color") + for key, color in pairs(colors) do + colors[key] = color_lib.new(color.hex or color) + end end -function M.get_is_bg_dark(color_set_name) - local color_set_functions = require("mellifluous.colors.sets." .. color_set_name) - local is_light_set_available = color_set_functions.get_bg_light ~= nil - and color_set_functions.get_colors_light ~= nil - local is_dark_set_available = color_set_functions.get_bg_dark ~= nil and color_set_functions.get_colors_dark ~= nil +function M.get_is_bg_dark(colorset_name) + local colorset_functions = require("mellifluous.colors.colorsets." .. colorset_name) + local is_light_set_available = colorset_functions.get_bg_light ~= nil and colorset_functions.get_colors_light ~= nil + local is_dark_set_available = colorset_functions.get_bg_dark ~= nil and colorset_functions.get_colors_dark ~= nil if vim.o.background == "light" and is_light_set_available then return false @@ -44,31 +65,53 @@ function M.get_is_bg_dark(color_set_name) elseif is_light_set_available then return false else - require("mellifluous").return_error("Required color set is either incomplete or missing") + require("mellifluous").return_error("Required colorset is either incomplete or missing") end end -function M.get_ui_color_base_lightness(color_set_name, is_bg_dark) - return require("mellifluous.colors.sets." .. color_set_name).get_ui_color_base_lightness(is_bg_dark) +function M.get_ui_color_base_lightness(colorset_name, is_bg_dark) + return require("mellifluous.colors.colorsets." .. colorset_name).get_ui_color_base_lightness(is_bg_dark) end function M.get_colors() local config = require("mellifluous.config").config - if not M.get_color_sets_table()[config.color_set] then - require("mellifluous").return_error("Color set '" .. config.color_set .. "' not found") + if not M.get_colorsets_table()[config.colorset] then + require("mellifluous").return_error("Colorset '" .. config.colorset .. "' not found") end - local color_overrides = get_color_overrides(config.is_bg_dark, config.color_set) + local colorset_functions = require("mellifluous.colors.colorsets." .. config.colorset) + + local color_overrides_bg_fn = get_color_overrides_bg_fn() + + local colorset_bg + if config.is_bg_dark then + colorset_bg = colorset_functions.get_bg_dark() + else + colorset_bg = colorset_functions.get_bg_light() + end + + local bg = colorset_bg + + if color_overrides_bg_fn then + if type(color_overrides_bg_fn) ~= "function" then + require("mellifluous").return_error("color_overrides.bg should be a function. It takes bg as an argument and returns the new bg.") + end + + local overriden_bg = color_overrides_bg_fn(colorset_bg) + if overriden_bg ~= nil then + bg = overriden_bg + end + end - local color_set_functions = require("mellifluous.colors.sets." .. config.color_set) local colors if config.is_bg_dark then - colors = color_set_functions.get_colors_dark(color_overrides.bg or color_set_functions.get_bg_dark()) + colors = colorset_functions.get_colors_dark(bg) else - colors = color_set_functions.get_colors_light(color_overrides.bg or color_set_functions.get_bg_light()) + colors = colorset_functions.get_colors_light(bg) end - tbl_extend_non_nil(colors, color_overrides) + colors = apply_color_overrides(colors) + ensure_correct_color_types(colors) colors = require("mellifluous.colors.shades").extend_with_shades(colors) diff --git a/lua/mellifluous/colors/shades.lua b/lua/mellifluous/colors/shades.lua index dd2417c..5c5085e 100644 --- a/lua/mellifluous/colors/shades.lua +++ b/lua/mellifluous/colors/shades.lua @@ -41,8 +41,8 @@ function M.extend_with_shades(colors) } end - colors = vim.tbl_extend("force", colors, shared_shades) - return vim.tbl_extend("force", colors, shades) + colors = vim.tbl_extend("keep", colors, shared_shades) + return vim.tbl_extend("keep", colors, shades) end return M diff --git a/lua/mellifluous/config.lua b/lua/mellifluous/config.lua index 2f33094..10623ab 100644 --- a/lua/mellifluous/config.lua +++ b/lua/mellifluous/config.lua @@ -4,7 +4,7 @@ local saved_user_config = {} local function get_default_config() return { - color_set = "mellifluous", + colorset = "mellifluous", plugins = { cmp = true, indent_blankline = true, @@ -30,22 +30,18 @@ local function get_default_config() }, dim_inactive = false, styles = { - comments = { italic = true }, - conditionals = {}, - folds = {}, - loops = {}, - functions = {}, - keywords = {}, - strings = {}, - variables = {}, - numbers = {}, - booleans = {}, - properties = {}, + main_keywords = {}, + other_keywords = {}, types = {}, operators = {}, + strings = {}, + functions = {}, + constants = {}, + comments = { italic = true }, markup = { headings = { bold = true }, }, + folds = {}, }, transparent_background = { enabled = false, @@ -78,20 +74,20 @@ local function disable_disabled() end end -local function merge_color_set_defaults(color_set) - local color_set_module = require("mellifluous.colors.sets." .. color_set) +local function merge_colorset_defaults(colorset) + local colorset_module = require("mellifluous.colors.colorsets." .. colorset) - if not color_set_module.get_config then + if not colorset_module.get_config then return end - config[color_set] = vim.tbl_deep_extend("force", config[color_set] or {}, color_set_module.get_config()) + config[colorset] = vim.tbl_deep_extend("force", config[colorset] or {}, colorset_module.get_config()) end -local function process_color_set() - config.is_bg_dark = require("mellifluous.colors").get_is_bg_dark(config.color_set) +local function process_colorset() + config.is_bg_dark = require("mellifluous.colors").get_is_bg_dark(config.colorset) config.ui_color_base_lightness = - require("mellifluous.colors").get_ui_color_base_lightness(config.color_set, config.is_bg_dark) + require("mellifluous.colors").get_ui_color_base_lightness(config.colorset, config.is_bg_dark) end -- https://www.lua.org/pil/13.4.5.html @@ -113,10 +109,10 @@ end function M.prepare() config = get_default_config() - merge_color_set_defaults(vim.tbl_get(saved_user_config, "color_set") or config.color_set) + merge_colorset_defaults(vim.tbl_get(saved_user_config, "colorset") or config.colorset) config = vim.tbl_deep_extend("force", config, saved_user_config or {}) - process_color_set() + process_colorset() disable_disabled() M.config = read_only(config) @@ -130,10 +126,10 @@ function M.set_highlight_overrides(highlighter, colors) global_highlight_overrides(highlighter, colors) end - local color_set_highlight_overrides = vim.tbl_get(M.config, M.config.color_set, "highlight_overrides", background) + local colorset_highlight_overrides = vim.tbl_get(M.config, M.config.colorset, "highlight_overrides", background) or nil - if color_set_highlight_overrides then - color_set_highlight_overrides(highlighter, colors) + if colorset_highlight_overrides then + colorset_highlight_overrides(highlighter, colors) end end diff --git a/lua/mellifluous/highlights/custom_groups.lua b/lua/mellifluous/highlights/custom_groups.lua index f985fa6..0ac9ea1 100644 --- a/lua/mellifluous/highlights/custom_groups.lua +++ b/lua/mellifluous/highlights/custom_groups.lua @@ -14,7 +14,7 @@ function M.get(colors) local shader = require("mellifluous.utils.shader") return { - MainKeyword = { fg = colors.main_keywords, style = config.styles.keywords }, + MainKeyword = { fg = colors.main_keywords, style = config.styles.main_keywords or {} }, IndentLine = function(bg) bg = fallback_if_none(bg, colors.bg) diff --git a/lua/mellifluous/highlights/general.lua b/lua/mellifluous/highlights/general.lua index 2cf818e..fd0b750 100644 --- a/lua/mellifluous/highlights/general.lua +++ b/lua/mellifluous/highlights/general.lua @@ -121,23 +121,23 @@ function M.set(hl, colors) -- -- Uncomment and edit if you want more specific syntax highlighting. hl.set("Comment", { fg = colors.comments, style = config.styles.comments or {} }) -- Any comment - hl.set("Constant", { fg = colors.constants }) -- (*) Any constant + hl.set("Constant", { fg = colors.constants, style = config.styles.constants or {} } ) -- (*) Any constant hl.set("String", { fg = colors.strings, style = config.styles.strings or {} }) -- A string constant: 'this is a string' hl.set("Character", { fg = hl.get("String").fg }) -- A character constant: 'c', '\n' - hl.set("Number", { link = "Constant", style = config.styles.numbers or {} }) -- A number constant: 234, 0xff - hl.set("Boolean", { link = "Constant", style = config.styles.booleans or {} }) -- A boolean constant: TRUE, false - hl.set("Float", { link = "Constant", style = config.styles.numbers or {} }) -- A floating point constant: 2.3e10 - hl.set("Identifier", { fg = colors.fg, style = config.styles.variables or {} }) -- (*) Any variable name + hl.set("Number", { link = "Constant" }) -- A number constant: 234, 0xff + hl.set("Boolean", { link = "Constant" }) -- A boolean constant: TRUE, false + hl.set("Float", { link = "Constant" }) -- A floating point constant: 2.3e10 + hl.set("Identifier", { fg = colors.fg }) -- (*) Any variable name hl.set("Function", { fg = colors.functions, style = config.styles.functions or {} }) -- Function name (also: methods for classes) hl.set("Statement", { link = "Keyword" }) -- (*) Any statement - hl.set("Conditional", { fg = colors.main_keywords, style = config.styles.conditionals or {} }) -- if, then, else, endif, switch, etc. - hl.set("Repeat", { fg = colors.main_keywords, style = config.styles.loops or {} }) -- for, do, while, etc. + hl.set("Conditional", groups.MainKeyword) -- if, then, else, endif, switch, etc. + hl.set("Repeat", groups.MainKeyword) -- for, do, while, etc. hl.set("Label", { fg = colors.other_keywords }) hl.set("Operator", { fg = config.is_bg_dark and colors.operators or colors.fg3, style = config.styles.operators or {}, }) -- 'sizeof', '+', '*', etc. - hl.set("Keyword", { fg = colors.other_keywords, style = config.styles.keywords }) -- any other keyword + hl.set("Keyword", { fg = colors.other_keywords, style = config.styles.other_keywords }) -- any other keyword hl.set("Exception", groups.MainKeyword) -- try, catch, throw hl.set("PreProc", { fg = colors.functions }) -- (*) Generic Preprocessor hl.set("Include", { link = "PreProc" }) -- Preprocessor #include diff --git a/lua/mellifluous/highlights/plugins/treesitter.lua b/lua/mellifluous/highlights/plugins/treesitter.lua index ff1156a..d249c42 100644 --- a/lua/mellifluous/highlights/plugins/treesitter.lua +++ b/lua/mellifluous/highlights/plugins/treesitter.lua @@ -10,7 +10,7 @@ function M.set(hl, colors) hl.set("@variable.builtin", { fg = colors.other_keywords }) -- Variable names defined by the language: `this` or `self` in Javascript. hl.set("@variable.parameter", { fg = colors.fg }) -- Parameters of a function. hl.set("@variable.parameter.reference", { link = "@variable.parameter" }) -- References to parameters of a function. - hl.set("@variable.member", { fg = colors.fg, style = config.styles.properties }) -- Object and struct fields. + hl.set("@variable.member", { fg = colors.fg }) -- Object and struct fields. hl.set("@constant", { link = "Constant" }) -- Constants identifiers. These might not be semantically constant. E.g. uppercase variables in Python. hl.set("@constant.builtin", { link = "Constant" }) -- Built-in constant values: `nil` in Lua. hl.set("@constant.macro", { link = "Constant" }) -- Constants defined by macros: `NULL` in C.