refactor(wezterm): superior table handling
This commit is contained in:
parent
98da4f7142
commit
f3e5818a47
@ -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
|
||||
|
@ -1,20 +1,12 @@
|
||||
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
|
||||
---
|
||||
---@return table
|
||||
function M.new_table()
|
||||
local t = {}
|
||||
M.Table = {}
|
||||
|
||||
--- Dump a table into a json-ish string format,
|
||||
--- shamelessly taken from https://stackoverflow.com/a/27028488
|
||||
---@param o table
|
||||
local function dump(o)
|
||||
function M.Table.dump(o)
|
||||
if type(o) == "table" then
|
||||
local s = "{\n"
|
||||
for k, v in pairs(o) do
|
||||
@ -29,17 +21,11 @@ function M.new_table()
|
||||
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(...)
|
||||
function M.Table.merge(...)
|
||||
local ret = {}
|
||||
for _, tbl in ipairs({ ... }) do
|
||||
for k, v in pairs(tbl) do
|
||||
@ -49,9 +35,6 @@ function M.new_table()
|
||||
return ret
|
||||
end
|
||||
|
||||
return t
|
||||
end
|
||||
|
||||
--- Returns the path to the users home, note this string needs to be regularized as
|
||||
--- this is used on both windows and unix.
|
||||
--- @return string
|
||||
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user