refactor(_utils): change way how it organizes
This commit is contained in:
parent
6dcfe9c9ef
commit
616474b919
1 changed files with 33 additions and 42 deletions
|
|
@ -1,48 +1,39 @@
|
|||
---@diagnostic disable: param-type-mismatch
|
||||
return {
|
||||
---@param t table
|
||||
---@return boolean
|
||||
empty = function(t)
|
||||
local utils = {}
|
||||
|
||||
---@param t table
|
||||
---@return boolean
|
||||
function utils.is_tbl_empty(t)
|
||||
if t == nil then
|
||||
return true
|
||||
end
|
||||
|
||||
return next(t) == nil
|
||||
end,
|
||||
end
|
||||
|
||||
---@param s string
|
||||
---@return string
|
||||
rtrim = function(s)
|
||||
---@param s string
|
||||
---@return string
|
||||
function utils.rtrim(s)
|
||||
local n = #s
|
||||
while n > 0 and s:find("^%s", n) do
|
||||
n = n - 1
|
||||
end
|
||||
|
||||
return s:sub(1, n)
|
||||
end,
|
||||
|
||||
---@param msg string
|
||||
---@param lvl string|integer
|
||||
notify = function(msg, lvl)
|
||||
local l
|
||||
if lvl == "error" or lvl == 4 then
|
||||
l = vim.log.levels.ERROR
|
||||
elseif lvl == "info" or lvl == 2 then
|
||||
l = vim.log.levels.INFO
|
||||
elseif lvl == "debug" or lvl == 1 then
|
||||
l = vim.log.levels.DEBUG
|
||||
end
|
||||
end
|
||||
|
||||
---@param msg string
|
||||
---@param lvl any
|
||||
function utils.deferred_notify(msg, lvl)
|
||||
vim.defer_fn(function()
|
||||
vim.notify(msg, l)
|
||||
vim.notify(msg, lvl)
|
||||
end, 0)
|
||||
end,
|
||||
end
|
||||
|
||||
---safe require
|
||||
---@param name string module name
|
||||
sreq = function(name)
|
||||
local ok, m = pcall(require, name)
|
||||
assert(ok, string.format("gopher.nvim dependency error: %s not installed", name))
|
||||
-- safe require
|
||||
---@param module string module name
|
||||
function utils.sreq(module)
|
||||
local ok, m = pcall(require, module)
|
||||
assert(ok, string.format("gopher.nvim dependency error: %s not installed", module))
|
||||
return m
|
||||
end,
|
||||
}
|
||||
end
|
||||
|
||||
return utils
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue