irongit

A Neovim plugin enabling you to solve LeetCode problems.

feat: new customization

kawreauthored
parent 2d685b5commit 9db9bf8c563047d831a58613ddb4e725f0c8e05cBrowse files

6 files changed, +41 -20

+12-2lua/leetcode/config/template.lua
@@ -58,16 +58,26 @@ local M = {
5858 console = {
5959 open_on_runcode = false, ---@type boolean
6060
61+ dir = "row", ---@type "col" | "row"
62+
6163 size = {
62- width = "75%", ---@type string | integer
64+ width = "90%", ---@type string | integer
6365 height = "75%", ---@type string | integer
6466 },
6567
66- dir = "row", ---@type "col" | "row"
68+ result = {
69+ size = "60%", ---@type string | integer
70+ },
71+
72+ testcase = {
73+ size = "40%", ---@type string | integer
74+ },
6775 },
6876
6977 description = {
7078 width = "40%", ---@type string | integer
79+
80+ position = "left", ---@type "top" | "right" | "bottom" | "left"
7181 },
7282 }
7383
+12-0lua/leetcode/theme/init.lua
@@ -24,6 +24,18 @@ local highlights = {
2424 input = "header",
2525 output = "header",
2626 explanation = "header",
27+
28+ -- pre = "",
29+ -- span = "",
30+ -- p = "",
31+ -- ul = "",
32+ -- ol = "",
33+ -- li = "",
34+ -- font = "",
35+ -- sup = "",
36+ -- sub = "",
37+ -- small = "",
38+ -- div = "",
2739 }
2840
2941 function theme.load_devicons()
+2-1lua/leetcode/ui/console/components/case.lua
@@ -19,7 +19,8 @@ function case:init(index, input, output, expected, passed)
1919 local match = passed or (output == expected)
2020 local icon = match and "" or ""
2121 local hi = match and "leetcode_ok" or "leetcode_error"
22- local title_line = NuiLine():append(icon .. " Case " .. index, hi)
22+ local title_line = NuiLine()
23+ title_line:append(icon .. " Case " .. index, hi)
2324
2425 local input_line = NuiLine()
2526 input_line:append("Input: ")
+10-12lua/leetcode/ui/console/init.lua
@@ -57,35 +57,33 @@ end
5757
5858 ---@param parent lc.Question
5959 function console:init(parent)
60- local obj = setmetatable({
60+ self = setmetatable({
6161 parent = parent,
6262 opened = false,
6363 }, self)
6464
6565 local keymap = {
66- ["R"] = function() obj:run() end,
67- ["S"] = function() obj:submit() end,
68- [{ "q", "<Esc>" }] = function() obj:hide() end,
66+ ["R"] = function() self:run() end,
67+ ["S"] = function() self:submit() end,
68+ [{ "q", "<Esc>" }] = function() self:hide() end,
6969 }
7070
71- obj.testcase = Testcase:init(obj):keymaps(keymap) ---@diagnostic disable-line
72- obj.result = Result:init(obj):keymaps(keymap) ---@diagnostic disable-line
71+ self.testcase = Testcase:init(self):keymaps(keymap) ---@diagnostic disable-line
72+ self.result = Result:init(self):keymaps(keymap) ---@diagnostic disable-line
7373
74- obj.layout = NuiLayout(
74+ self.layout = NuiLayout(
7575 {
7676 relative = "editor",
7777 position = "50%",
7878 size = config.user.console.size,
7979 },
8080 NuiLayout.Box({
81- NuiLayout.Box(obj.testcase.popup, { size = "50%" }),
82- NuiLayout.Box(obj.result.popup, { size = "50%" }),
81+ NuiLayout.Box(self.testcase.popup, { size = config.user.console.testcase.size }),
82+ NuiLayout.Box(self.result.popup, { size = config.user.console.result.size }),
8383 }, { dir = config.user.console.dir })
8484 )
8585
86- -- obj:keymaps()
87-
88- return obj
86+ return self
8987 end
9088
9189 return console
+4-4lua/leetcode/ui/console/result.lua
@@ -100,14 +100,14 @@ function result:handle_runtime(item) -- status code = 10
100100 for i, answer in ipairs(item.code_answer) do
101101 local passed = item.compare_result:sub(i, i) == "1"
102102
103- local text = Case:init(
103+ local case = Case:init(
104104 i,
105105 self.parent.testcase.testcases[i],
106106 answer,
107107 item.expected_code_answer[i],
108108 passed
109109 )
110- group:append(text)
110+ group:append(case)
111111
112112 local stdout = Stdout:init(item.std_output_list[i])
113113 if stdout then group:append(stdout) end
@@ -367,7 +367,7 @@ function result:init(parent)
367367 },
368368 })
369369
370- local obj = setmetatable({
370+ self = setmetatable({
371371 popup = popup,
372372 layout = Layout:init({
373373 winid = popup.winid,
@@ -376,7 +376,7 @@ function result:init(parent)
376376 parent = parent,
377377 }, self)
378378
379- return obj
379+ return self
380380 end
381381
382382 return result
+1-1lua/leetcode/ui/description.lua
@@ -152,7 +152,7 @@ end
152152 function description:init(parent)
153153 local split = Split({
154154 relative = "editor",
155- position = "left",
155+ position = config.user.description.position,
156156 size = config.user.description.width,
157157 enter = true,
158158 focusable = true,