Skip to content

Commit 60ecf29

Browse files
authored
chore: simplify logs module (#106)
1 parent 23cf91c commit 60ecf29

File tree

4 files changed

+22
-19
lines changed

4 files changed

+22
-19
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.notify.error(err)
84+
logs.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.notify.error("colors(%s): %q is not a valid color", name, value)
96+
logs.error("colors(%s): %q is not a valid color", name, value)
9797

9898
return defaults[name]
9999
end

lua/one_monokai/config.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ function config.extend(opts)
2727
local logs = require "one_monokai.logs"
2828

2929
if opts.themes then
30-
logs.notify.warning(
30+
logs.warning(
3131
"config: %q option has been deprecated and will be removed soon. Please update your config to use %q instead.",
3232
"themes",
3333
"highlights"

lua/one_monokai/highlights/init.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ local function set_highlight(groups)
1010
local status_ok, err = pcall(set_hl, 0, name, attrs)
1111

1212
if not status_ok then
13-
logs.notify.error("highlights(%s): %s", name, err)
13+
logs.error("highlights(%s): %s", name, err)
1414
end
1515
end
1616
end

lua/one_monokai/logs.lua

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,29 @@
22
local logs = {}
33

44
---Display a notification to the user
5-
---@param log_level string
6-
---@param s string
7-
local function notify(log_level, s, ...)
5+
---@param level vim.log.levels
6+
---@param s string|number
7+
---@param ... any
8+
local function notify(level, s, ...)
89
local message = string.format(s, ...)
910

10-
vim.notify_once(message, log_level, {
11+
vim.notify(message, level, {
1112
title = "One Monokai",
1213
})
1314
end
1415

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, ...)
24-
end,
25-
}
16+
---Display an error message to the user
17+
---@param s string|number
18+
---@param ... any
19+
logs.error = function(s, ...)
20+
notify(vim.log.levels.ERROR, s, ...)
21+
end
22+
23+
---Display a warning message to the user
24+
---@param s string|number
25+
---@param ... any
26+
logs.warning = function(s, ...)
27+
notify(vim.log.levels.WARN, s, ...)
28+
end
2629

2730
return logs

0 commit comments

Comments
 (0)