Skip to content

Commit 704c62f

Browse files
committed
feat: extend logs module to show warning
1 parent 75c0b13 commit 704c62f

File tree

2 files changed

+22
-13
lines changed

2 files changed

+22
-13
lines changed

lua/one_monokai/colors.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ local function get_hex_value(name, value)
8181
})
8282

8383
if not type_ok then
84-
logs.error.notify(err)
84+
logs.notify.error(err)
8585

8686
return defaults[name]
8787
end
@@ -93,7 +93,7 @@ local function get_hex_value(name, value)
9393
local rgb = vim.api.nvim_get_color_by_name(value)
9494

9595
if rgb == -1 then
96-
logs.error.notify("colors(%s): %q is not a valid color", name, value)
96+
logs.notify.error("colors(%s): %q is not a valid color", name, value)
9797

9898
return defaults[name]
9999
end

lua/one_monokai/logs.lua

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,26 @@
1+
---@class logs
12
local logs = {}
23

3-
logs.error = {
4-
---Display error message.
5-
---
6-
---NOTE: This function receives params that will be passed to `string.format`.
7-
---@param s string
8-
---@param ... any
9-
notify = function(s, ...)
10-
local message = string.format(s, ...)
4+
---Display a notification to the user
5+
---@param log_level string
6+
---@param s string
7+
local function notify(log_level, s, ...)
8+
local message = string.format(s, ...)
119

12-
vim.notify_once(message, vim.log.levels.ERROR, {
13-
title = "One Monokai",
14-
})
10+
vim.notify_once(message, log_level, {
11+
title = "One Monokai",
12+
})
13+
end
14+
15+
---@class notify
16+
---@field error fun(s:string, ...) #Show error message
17+
---@field warning fun(s: string, ...) #Show warning message
18+
logs.notify = {
19+
error = function(s, ...)
20+
notify(vim.log.levels.ERROR, s, ...)
21+
end,
22+
warning = function(s, ...)
23+
notify(vim.log.levels.WARNING, s, ...)
1524
end,
1625
}
1726

0 commit comments

Comments
 (0)