style: enhance window decorations for improved visual appeal
This commit is contained in:
@@ -130,4 +130,93 @@ function M.complementary_color(hex_color)
|
||||
return string.format("#%02x%02x%02x", complementary_r, complementary_g, complementary_b)
|
||||
end
|
||||
|
||||
---@function Helper function to check if a value exists in a table
|
||||
---@param tab table The table to search in
|
||||
---@param val any The value to search for in the table
|
||||
---@return boolean exists True if the value is found in the table, false otherwise
|
||||
function M.has_value(tab, val)
|
||||
for _, value in ipairs(tab) do
|
||||
if value == val then
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
---@function Function to send a notification using toastify
|
||||
---@param title string The title of the notification
|
||||
---@param body? string The body of the notification
|
||||
---@param timeout? number Time in milliseconds before the notification expires
|
||||
---@param options? table A table containing additional optional settings for the notification
|
||||
function M.notify(title, body, timeout, options)
|
||||
-- Default values for optional fields
|
||||
-- Initialize 'options' as an empty table if not provided
|
||||
options = options or {}
|
||||
|
||||
-- Retrieve specific options from the 'options' table, or set to nil/default if not provided
|
||||
local app_name = options.app_name or nil
|
||||
local categories = options.categories or nil
|
||||
local icon = options.icon or nil
|
||||
local sound_name = options.sound_name or nil
|
||||
local urgency = options.urgency or "normal" -- Default urgency is 'normal'
|
||||
local hint = options.hint or nil
|
||||
local debug = options.debug and "--debug" or nil -- Add '--debug' flag if debug is true
|
||||
|
||||
-- Allowed urgency levels for validation
|
||||
local allowed_urgency = { "low", "normal", "critical" }
|
||||
-- If the provided urgency is not one of the allowed values, default to 'normal'
|
||||
if not M.has_value(allowed_urgency, urgency) then
|
||||
urgency = "normal"
|
||||
end
|
||||
|
||||
-- Start building the command as a table of strings (to execute via wezterm)
|
||||
-- 'toastify send' is the base command, with 'title' as a required argument
|
||||
local cmd = { "toastify", "send", title }
|
||||
|
||||
-- Append the body if provided (body is optional)
|
||||
if body then
|
||||
table.insert(cmd, body)
|
||||
end
|
||||
|
||||
-- Append the timeout if provided (timeout is optional)
|
||||
if timeout then
|
||||
table.insert(cmd, "--expire-time")
|
||||
table.insert(cmd, tostring(timeout)) -- Convert to string for command execution
|
||||
end
|
||||
|
||||
-- Append optional arguments if provided, using the corresponding flag
|
||||
if app_name then
|
||||
table.insert(cmd, "--app-name")
|
||||
table.insert(cmd, app_name)
|
||||
end
|
||||
if categories then
|
||||
table.insert(cmd, "--categories")
|
||||
table.insert(cmd, categories)
|
||||
end
|
||||
if icon then
|
||||
table.insert(cmd, "--icon")
|
||||
table.insert(cmd, icon)
|
||||
end
|
||||
if sound_name then
|
||||
table.insert(cmd, "--sound-name")
|
||||
table.insert(cmd, sound_name)
|
||||
end
|
||||
if hint then
|
||||
table.insert(cmd, "--hint")
|
||||
table.insert(cmd, hint)
|
||||
end
|
||||
-- Append the '--debug' flag if debug mode is enabled
|
||||
if debug then
|
||||
table.insert(cmd, debug)
|
||||
end
|
||||
|
||||
-- Always include the urgency flag with the validated urgency value
|
||||
table.insert(cmd, "--urgency")
|
||||
table.insert(cmd, urgency)
|
||||
|
||||
-- Execute the command using wezterm's built-in child process runner
|
||||
-- 'wezterm.run_child_process' takes a table of strings and executes it as a command
|
||||
wezterm.run_child_process(cmd)
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
Reference in New Issue
Block a user