From c0b966d9307e718cb41bfa8dc356cb4124714854 Mon Sep 17 00:00:00 2001 From: Ramojus Lapinskas <41536253+ramojus@users.noreply.github.com> Date: Sat, 10 Aug 2024 15:43:27 +0300 Subject: [PATCH] fix(config): rebase on default config after changes from cli (#53) --- lua/mellifluous/config.lua | 133 +++++++++++++++++++------------------ 1 file changed, 69 insertions(+), 64 deletions(-) diff --git a/lua/mellifluous/config.lua b/lua/mellifluous/config.lua index 26de6c4..e7af481 100644 --- a/lua/mellifluous/config.lua +++ b/lua/mellifluous/config.lua @@ -1,64 +1,68 @@ local M = {} - -local config = { - colorset = "mellifluous", - plugins = { - cmp = true, - indent_blankline = true, - nvim_tree = { - enabled = true, - show_root = false, +local config = {} +local saved_user_config = {} + +local function get_default_config() + return { + colorset = "mellifluous", + plugins = { + cmp = true, + indent_blankline = true, + nvim_tree = { + enabled = true, + show_root = false, + }, + neo_tree = { + enabled = true, + }, + telescope = { + enabled = true, + nvchad_like = true, + }, + startify = true, + gitsigns = true, + neorg = true, + nvim_notify = true, + aerial = true, + neotest = true, + lazy = true, + mason = true, }, - neo_tree = { - enabled = true, + dim_inactive = false, + styles = { + comments = { italic = true }, + conditionals = {}, + folds = {}, + loops = {}, + functions = {}, + keywords = {}, + strings = {}, + variables = {}, + numbers = {}, + booleans = {}, + properties = {}, + types = {}, + operators = {}, + markup = { + headings = { bold = true }, + }, }, - telescope = { - enabled = true, - nvchad_like = true, + transparent_background = { + enabled = false, + floating_windows = true, + telescope = true, + file_tree = true, + cursor_line = true, + status_line = false, }, - startify = true, - gitsigns = true, - neorg = true, - nvim_notify = true, - aerial = true, - neotest = true, - lazy = true, - mason = true, - }, - dim_inactive = false, - styles = { - comments = { italic = true }, - conditionals = {}, - folds = {}, - loops = {}, - functions = {}, - keywords = {}, - strings = {}, - variables = {}, - numbers = {}, - booleans = {}, - properties = {}, - types = {}, - operators = {}, - markup = { - headings = { bold = true }, + flat_background = { + line_numbers = false, + floating_windows = false, + file_tree = false, + cursor_line_number = false, }, - }, - transparent_background = { - enabled = false, - floating_windows = true, - telescope = true, - file_tree = true, - cursor_line = true, - status_line = false, - }, - flat_background = { - line_numbers = false, - floating_windows = false, - file_tree = false, - cursor_line_number = false, - }, -} + } +end local function disable_disabled() for _, v in pairs(config) do @@ -76,27 +80,25 @@ end local are_colorset_defaults_merged = false -local function merge_colorset_defaults() +local function merge_colorset_defaults(colorset) if are_colorset_defaults_merged then return end are_colorset_defaults_merged = true - local colorset = require("mellifluous.colors.colorsets." .. config.colorset) + local colorset_module = require("mellifluous.colors.colorsets." .. colorset) - if not colorset.get_config then + if not colorset_module.get_config then return end - config[config.colorset] = vim.tbl_deep_extend("force", config[config.colorset] or {}, colorset.get_config()) + config[colorset] = vim.tbl_deep_extend("force", config[colorset] or {}, colorset_module.get_config()) end 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.colorset, config.is_bg_dark) - - merge_colorset_defaults() end -- https://www.lua.org/pil/13.4.5.html @@ -113,11 +115,14 @@ local function read_only(table) end function M.setup(user_config) - merge_colorset_defaults() - config = vim.tbl_deep_extend("force", config, user_config or {}) + saved_user_config = vim.tbl_deep_extend("force", saved_user_config, user_config) end function M.prepare() + config = get_default_config() + 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_colorset() disable_disabled()