Skip to content

Commit 39ee509

Browse files
committed
feat: nested nav buttons
1 parent 1152b43 commit 39ee509

File tree

4 files changed

+55
-74
lines changed

4 files changed

+55
-74
lines changed

lua/leetcode/api/auth.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ function Auth.handle(res, err)
4848
return nil, err
4949
end
5050

51-
config.auth = log.debug(auth) ---@diagnostic disable-line
51+
config.auth = auth
52+
log.debug(auth)
5253
return auth
5354
end
5455

lua/leetcode/logger/init.lua

Lines changed: 43 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,60 @@
1-
local n_ok, notify = pcall(require, "notify")
2-
if n_ok then
3-
vim.notify = notify
4-
end
5-
61
local config = require("leetcode.config")
7-
local t = require("leetcode.translator")
82
local lvls = vim.log.levels
93

10-
---@class lc.Logger
4+
---@class leet.Logger
5+
---@field trace fun(...)
6+
---@field debug fun(...)
7+
---@field info fun(...)
8+
---@field warn fun(...)
9+
---@field error fun(...)
10+
---@field off fun(...)
1111
local logger = {}
1212

1313
local function normalize(msg)
14-
return type(msg) == "string" and t(msg) or vim.inspect(msg)
14+
if type(msg) == "string" then
15+
return msg
16+
else
17+
return vim.inspect(msg, { depth = 3 })
18+
end
1519
end
1620

17-
-- ---@private
18-
-- ---@param msg any
19-
-- ---@param lvl? integer
20-
-- ---@return any
21-
-- logger.log = vim.schedule_wrap(function(msg, lvl)
22-
-- end)
23-
24-
function logger.log(msg, lvl)
25-
if not config.user.logging then
21+
---@private
22+
---@param lvl number
23+
---@param ... any
24+
function logger.log(lvl, ...)
25+
if not config.debug and (lvl == lvls.DEBUG or lvl == lvls.TRACE) then
2626
return
2727
end
2828

29-
local title = config.name
30-
lvl = lvl or lvls.INFO
31-
msg = normalize(msg)
32-
33-
if lvl == lvls.DEBUG then
34-
msg = debug.traceback(msg .. "\n")
35-
end
36-
37-
vim.notify(msg, lvl, { title = title })
38-
end
39-
40-
---@param msg any
41-
logger.info = function(msg)
42-
logger.log(msg)
43-
end
44-
45-
---@param msg any
46-
logger.warn = function(msg)
47-
logger.log(msg, lvls.WARN)
48-
end
49-
50-
---@param msg any
51-
logger.error = function(msg)
52-
logger.log(msg, lvls.ERROR)
53-
logger.debug(msg)
29+
local msg = table.concat(vim.tbl_map(normalize, { ... }), " ")
30+
vim.notify(msg, lvl, {
31+
title = config.name,
32+
on_open = function(win)
33+
local buf = vim.api.nvim_win_get_buf(win)
34+
vim.api.nvim_set_option_value("filetype", "markdown", { buf = buf })
35+
vim.api.nvim_set_option_value("spell", false, { win = win })
36+
end,
37+
})
5438
end
5539

5640
---@param err lc.err
5741
logger.err = function(err)
58-
if not err then
59-
return logger.error("error")
42+
if not err or not err.msg then
43+
return logger.error("unknown error")
6044
end
6145

62-
local msg = err.msg or ""
63-
local lvl = err.lvl or lvls.ERROR
64-
65-
logger.log(msg, lvl)
66-
end
67-
68-
---@param msg any
69-
---@param show? boolean
70-
---@return any
71-
logger.debug = function(msg, show)
72-
if not config.debug then
73-
return msg
74-
end
75-
76-
local lvl = (show == nil or not show) and lvls.DEBUG or lvls.ERROR
77-
logger.log(msg, lvl)
78-
79-
return msg
80-
end
81-
82-
return logger
46+
logger.error(err.msg)
47+
end
48+
49+
return setmetatable(logger, {
50+
__index = function(_, key)
51+
return function(...)
52+
local lvl = lvls[key:upper()]
53+
if lvl then
54+
return logger.log(lvl, ...)
55+
else
56+
return logger.error("Invalid log level:", key)
57+
end
58+
end
59+
end,
60+
})

lua/leetcode/theme/default.lua

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,9 @@ M.get = function()
9191
-- menu button
9292
menu_button_icon = hl("Special"),
9393
menu_button_title = hl("Normal"),
94-
menu_button_key = hl("Character"),
95-
94+
menu_button_nested = { fg = hl("Comment").fg },
95+
menu_button_key = { fg = hl("Character").fg, italic = true },
96+
-- menu footer
9697
menu_footer = hl("Comment"),
9798
menu_footer_username = hl("Label"),
9899
}

lua/leetcode/ui/menu/buttons.lua

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
local markup = require("markup")
22

3-
local function Button(icon, title, key)
3+
local function Button(icon, title, key, nested)
44
return markup.Inline({
55
markup.Inline(icon, "leetcode_menu_button_icon"),
66
markup.Inline(" "),
77
markup.Inline(title, "leetcode_menu_button_title"),
8+
markup.Inline(nested and "" or "", "leetcode_menu_button_nested"),
89
markup.Inline(" "),
910
markup.Inline(key, "leetcode_menu_button_key"),
1011
})
@@ -14,11 +15,11 @@ return function()
1415
return markup.Flex({
1516
spacing = 1,
1617
children = {
17-
Button("", "Problems", "p"),
18-
Button("", "Statistics", "p"),
19-
Button("󰆘", "Cookie", "p"),
20-
Button("", "Cache", "p"),
21-
Button("󰩈", "Exit", "p"),
18+
Button("", "Problems", "p", true),
19+
Button("", "Statistics", "s", true),
20+
Button("󰆘", "Cookie", "i", true),
21+
Button("", "Cache", "c", true),
22+
Button("󰩈", "Exit", "qa"),
2223
},
2324
})
2425
end

0 commit comments

Comments
 (0)