diff --git a/.config/wezterm/wezterm.lua b/.config/wezterm/wezterm.lua index 27fadc7b..63314a08 100644 --- a/.config/wezterm/wezterm.lua +++ b/.config/wezterm/wezterm.lua @@ -1,4 +1,4 @@ -local Table = require("wlib").new_table() +local wlib = require("wlib") -- NOTE: Should be merged local events = require("config.events") @@ -9,5 +9,5 @@ local rendering = require("config.rendering") local keybinds = require("config.keybinds") local misc = require("config.misc") -local config = Table.merge(events, fonts, theme, tabbar, misc, rendering, keybinds) +local config = wlib.Table.merge(events, fonts, theme, tabbar, misc, rendering, keybinds) return config diff --git a/.config/wezterm/wlib.lua b/.config/wezterm/wlib.lua index b3554953..ea5d87d8 100644 --- a/.config/wezterm/wlib.lua +++ b/.config/wezterm/wlib.lua @@ -1,55 +1,38 @@ local os = require("os") local M = {} ---- Creates a new custom table that allows ---- usage of lua's `table` attributes ---- ---- This is done really oddly such that we create a local table instance for ---- each invocation, but also get methods for each new table in a lua style ---- +M.Table = {} + +--- Dump a table into a json-ish string format, +--- shamelessly taken from https://stackoverflow.com/a/27028488 +---@param o table +function M.Table.dump(o) + if type(o) == "table" then + local s = "{\n" + for k, v in pairs(o) do + if type(k) ~= "number" then + k = '"' .. k .. '"' + end + s = s .. " [" .. k .. "] = " .. dump(v) .. ",\n" + end + return s .. "} " + else + return tostring(o) + end +end + +--- Allows the combining of multiple tables, where the last table given has the highest +--- priority (it overrides the keys of other tables) +---@vararg table ---@return table -function M.new_table() - local t = {} - - --- Dump a table into a json-ish string format, - --- shamelessly taken from https://stackoverflow.com/a/27028488 - ---@param o table - local function dump(o) - if type(o) == "table" then - local s = "{\n" - for k, v in pairs(o) do - if type(k) ~= "number" then - k = '"' .. k .. '"' - end - s = s .. " [" .. k .. "] = " .. dump(v) .. ",\n" - end - return s .. "} " - else - return tostring(o) +function M.Table.merge(...) + local ret = {} + for _, tbl in ipairs({ ... }) do + for k, v in pairs(tbl) do + ret[k] = v end end - - --- Simple wrapper around dump function - ---@return string - function t.dump() - return dump(t) - end - - --- Allows the combining of multiple tables, where the last table given has the highest - --- priority (it overrides the keys of other tables) - ---@vararg table - ---@return table - function t.merge(...) - local ret = {} - for _, tbl in ipairs({ ... }) do - for k, v in pairs(tbl) do - ret[k] = v - end - end - return ret - end - - return t + return ret end --- Returns the path to the users home, note this string needs to be regularized as @@ -59,7 +42,7 @@ function M.determine_home_path() -- This helps give a better error message -- if we are unable to find their home dir -- from a environment variable - local checked_env_vars = M.new_table() + local checked_env_vars = {} -- Attempt to get UNIX home local unix_home_var = "HOME" @@ -81,7 +64,7 @@ function M.determine_home_path() -- NOTE: This will error if it cannot determine the home path error( "Unable to determine user's home directory, checked environment variables:\n\n" - .. checked_env_vars.dump() + .. M.Table.dump(checked_env_vars) .. "\n\n" ) end