From d17125ff8954fd2ca1db4aaee625f934f9f4d3e4 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 5cc7313..0f32010 100644 --- a/lua/mellifluous/config.lua +++ b/lua/mellifluous/config.lua @@ -1,64 +1,68 @@ local M = {} - -local config = { - color_set = "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 { + color_set = "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_color_set_defaults_merged = false -local function merge_color_set_defaults() +local function merge_color_set_defaults(color_set) if are_color_set_defaults_merged then return end are_color_set_defaults_merged = true - local color_set = require("mellifluous.colors.sets." .. config.color_set) + local color_set_module = require("mellifluous.colors.sets." .. color_set) - if not color_set.get_config then + if not color_set_module.get_config then return end - config[config.color_set] = vim.tbl_deep_extend("force", config[config.color_set] or {}, color_set.get_config()) + config[color_set] = vim.tbl_deep_extend("force", config[color_set] or {}, color_set_module.get_config()) end local function process_color_set() config.is_bg_dark = require("mellifluous.colors").get_is_bg_dark(config.color_set) config.ui_color_base_lightness = require("mellifluous.colors").get_ui_color_base_lightness(config.color_set, config.is_bg_dark) - - merge_color_set_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_color_set_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_color_set_defaults(vim.tbl_get(saved_user_config, "color_set") or config.color_set) + config = vim.tbl_deep_extend("force", config, saved_user_config or {}) + process_color_set() disable_disabled()