diff --git a/lua/kulala/config/init.lua b/lua/kulala/config/init.lua index 1f1654d..66629c7 100644 --- a/lua/kulala/config/init.lua +++ b/lua/kulala/config/init.lua @@ -1,4 +1,6 @@ -KULALA_CONFIG = KULALA_CONFIG or { +local M = {} + +M.defaults = { -- default_view, body or headers default_view = "body", -- dev, test, prod, can be anything @@ -16,7 +18,7 @@ KULALA_CONFIG = KULALA_CONFIG or { icons = { inlay = { loading = "⏳", - done = "✅ " + done = "✅" }, lualine = "🐼", }, @@ -25,15 +27,18 @@ KULALA_CONFIG = KULALA_CONFIG or { additional_curl_options = {}, } -local M = {} +M.options = {} + +M.setup = function(config) + M.options = vim.tbl_deep_extend("force", M.defaults, config or {}) +end -M.set_config = function(config) - config = config or {} - KULALA_CONFIG = vim.tbl_deep_extend("force", KULALA_CONFIG, config) +M.set = function(config) + M.options = vim.tbl_deep_extend("force", M.options, config or {}) end -M.get_config = function() - return KULALA_CONFIG +M.get = function() + return M.options end return M diff --git a/lua/kulala/formatter/init.lua b/lua/kulala/formatter/init.lua index e48b143..da7b48c 100644 --- a/lua/kulala/formatter/init.lua +++ b/lua/kulala/formatter/init.lua @@ -1,19 +1,19 @@ local CONFIG = require("kulala.config") local FS = require("kulala.utils.fs") -local CFG = CONFIG.get_config() local M = {} M.format = function(ft, contents) + local cfg = CONFIG.get() local cmd = {} local cmd_exists = false if ft == "json" then - cmd = CFG.formatters.json + cmd = cfg.formatters.json cmd_exists = FS.command_exists("jq") elseif ft == "xml" then - cmd = CFG.formatters.xml + cmd = cfg.formatters.xml cmd_exists = FS.command_exists("xmllint") elseif ft == "html" then - cmd = CFG.formatters.html + cmd = cfg.formatters.html cmd_exists = FS.command_exists("xmllint") end if not cmd_exists then diff --git a/lua/kulala/init.lua b/lua/kulala/init.lua index d720ecb..5c89c7d 100644 --- a/lua/kulala/init.lua +++ b/lua/kulala/init.lua @@ -7,9 +7,9 @@ local JUMPS = require("kulala.jumps") local M = {} M.setup = function(config) - CONFIG.set_config(config) - GLOBAL_STORE.set("selected_env", CONFIG.get_config().default_env) - vim.g.kulala_selected_env = CONFIG.get_config().default_env + CONFIG.setup(config) + GLOBAL_STORE.set("selected_env", CONFIG.get().default_env) + vim.g.kulala_selected_env = CONFIG.get().default_env ENV_PARSER.load_envs() end diff --git a/lua/kulala/inlay/init.lua b/lua/kulala/inlay/init.lua index 76d8dd1..13a6db5 100644 --- a/lua/kulala/inlay/init.lua +++ b/lua/kulala/inlay/init.lua @@ -13,11 +13,15 @@ M.clear = function() end M.show_loading = function() - M.show(CONFIG.get_config().icons.inlay.loading) + M.show(CONFIG.get().icons.inlay.loading) end M.show_done = function(self, elapsed_time) - M.show(CONFIG.get_config().icons.inlay.done .. elapsed_time) + icon = "" + if string.len(CONFIG.get().icons.inlay.done) > 0 then + icon = CONFIG.get().icons.inlay.done .. " " + end + M.show(icon .. elapsed_time) end diff --git a/lua/kulala/parser/dynamic_vars.lua b/lua/kulala/parser/dynamic_vars.lua index 86b56fa..4f3b17e 100644 --- a/lua/kulala/parser/dynamic_vars.lua +++ b/lua/kulala/parser/dynamic_vars.lua @@ -1,7 +1,6 @@ -local Config = require("kulala.config") +local CONFIG = require("kulala.config") local M = {} -local config = Config.get_config() local random = math.random math.randomseed(os.time()) @@ -20,7 +19,7 @@ end ---the user on his configuration ---@return { [string]: fun():string }[] An array-like table of tables which contains dynamic variables definition function M.retrieve_all() - local user_variables = config.custom_dynamic_variables or {} + local user_variables = CONFIG.get().custom_dynamic_variables or {} local rest_variables = { ["$uuid"] = uuid, ["$date"] = function() diff --git a/lua/kulala/parser/init.lua b/lua/kulala/parser/init.lua index 5d81103..486b9f9 100644 --- a/lua/kulala/parser/init.lua +++ b/lua/kulala/parser/init.lua @@ -4,7 +4,6 @@ local CONFIG = require("kulala.config") local DYNAMIC_VARS = require("kulala.parser.dynamic_vars") local STRING_UTILS = require("kulala.utils.string") local ENV_PARSER = require("kulala.parser.env") -local CFG = CONFIG.get_config() local PLUGIN_TMP_DIR = FS.get_plugin_tmp_dir() local M = {} @@ -457,7 +456,7 @@ function M.parse() end table.insert(res.cmd, "-A") table.insert(res.cmd, "kulala.nvim/".. GLOBALS.VERSION) - for _, additional_curl_option in pairs(CFG.additional_curl_options) do + for _, additional_curl_option in pairs(CONFIG.get().additional_curl_options) do table.insert(res.cmd, additional_curl_option) end table.insert(res.cmd, res.request.url) @@ -469,7 +468,7 @@ function M.parse() res.ft = "html" end FS.write_file(PLUGIN_TMP_DIR .. "/ft.txt", res.ft) - if CFG.debug then + if CONFIG.get().debug then FS.write_file(PLUGIN_TMP_DIR .. "/request.txt", table.concat(res.cmd, " ")) end return res diff --git a/lua/kulala/ui/init.lua b/lua/kulala/ui/init.lua index 36ff648..bcad6d0 100644 --- a/lua/kulala/ui/init.lua +++ b/lua/kulala/ui/init.lua @@ -1,6 +1,5 @@ local GLOBALS = require("kulala.globals") local CONFIG = require("kulala.config") -local CFG = CONFIG.get_config() local INLAY = require("kulala.inlay") local PARSER = require("kulala.parser") local CMD = require("kulala.cmd") @@ -81,7 +80,7 @@ M.open = function() if not buffer_exists() then open_buffer() end - if CFG.default_view == "body" then + if CONFIG.get().default_view == "body" then M.show_body() else M.show_headers() @@ -116,13 +115,14 @@ M.show_headers = function() end M.toggle_headers = function() - if CFG.default_view == "headers" then - CFG.default_view = "body" + cfg = CONFIG.get() + if cfg.default_view == "headers" then + cfg.default_view = "body" else - CFG.default_view = "headers" + cfg.default_view = "headers" end - CONFIG.set_config(CFG) - if CFG.default_view == "body" then + CONFIG.set(cfg) + if cfg.default_view == "body" then M.show_body() else M.show_headers() diff --git a/lua/lualine/components/kulala.lua b/lua/lualine/components/kulala.lua index d435d81..bbc3f6d 100644 --- a/lua/lualine/components/kulala.lua +++ b/lua/lualine/components/kulala.lua @@ -4,7 +4,7 @@ local CONFIG = require("kulala.config") local default_options = { fg = "#10B1FE", - icon = CONFIG.get_config().icons.lualine, + icon = CONFIG.get().icons.lualine, } function M:init(options)