A Neovim plugin enabling you to solve LeetCode problems.
feat: new customization
6 files changed, +41 -20
+12-2lua/leetcode/config/template.lua
| @@ -58,16 +58,26 @@ local M = { | ||
| 58 | 58 | console = { |
| 59 | 59 | open_on_runcode = false, ---@type boolean |
| 60 | 60 | |
| 61 | + dir = "row", ---@type "col" | "row" | |
| 62 | + | |
| 61 | 63 | size = { |
| 62 | - width = "75%", ---@type string | integer | |
| 64 | + width = "90%", ---@type string | integer | |
| 63 | 65 | height = "75%", ---@type string | integer |
| 64 | 66 | }, |
| 65 | 67 | |
| 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 | + }, | |
| 67 | 75 | }, |
| 68 | 76 | |
| 69 | 77 | description = { |
| 70 | 78 | width = "40%", ---@type string | integer |
| 79 | + | |
| 80 | + position = "left", ---@type "top" | "right" | "bottom" | "left" | |
| 71 | 81 | }, |
| 72 | 82 | } |
| 73 | 83 |
+12-0lua/leetcode/theme/init.lua
| @@ -24,6 +24,18 @@ local highlights = { | ||
| 24 | 24 | input = "header", |
| 25 | 25 | output = "header", |
| 26 | 26 | 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 = "", | |
| 27 | 39 | } |
| 28 | 40 | |
| 29 | 41 | function theme.load_devicons() |
+2-1lua/leetcode/ui/console/components/case.lua
| @@ -19,7 +19,8 @@ function case:init(index, input, output, expected, passed) | ||
| 19 | 19 | local match = passed or (output == expected) |
| 20 | 20 | local icon = match and "" or "" |
| 21 | 21 | 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) | |
| 23 | 24 | |
| 24 | 25 | local input_line = NuiLine() |
| 25 | 26 | input_line:append("Input: ") |
+10-12lua/leetcode/ui/console/init.lua
| @@ -57,35 +57,33 @@ end | ||
| 57 | 57 | |
| 58 | 58 | ---@param parent lc.Question |
| 59 | 59 | function console:init(parent) |
| 60 | - local obj = setmetatable({ | |
| 60 | + self = setmetatable({ | |
| 61 | 61 | parent = parent, |
| 62 | 62 | opened = false, |
| 63 | 63 | }, self) |
| 64 | 64 | |
| 65 | 65 | 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, | |
| 69 | 69 | } |
| 70 | 70 | |
| 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 | |
| 73 | 73 | |
| 74 | - obj.layout = NuiLayout( | |
| 74 | + self.layout = NuiLayout( | |
| 75 | 75 | { |
| 76 | 76 | relative = "editor", |
| 77 | 77 | position = "50%", |
| 78 | 78 | size = config.user.console.size, |
| 79 | 79 | }, |
| 80 | 80 | 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 }), | |
| 83 | 83 | }, { dir = config.user.console.dir }) |
| 84 | 84 | ) |
| 85 | 85 | |
| 86 | - -- obj:keymaps() | |
| 87 | - | |
| 88 | - return obj | |
| 86 | + return self | |
| 89 | 87 | end |
| 90 | 88 | |
| 91 | 89 | return console |
+4-4lua/leetcode/ui/console/result.lua
| @@ -100,14 +100,14 @@ function result:handle_runtime(item) -- status code = 10 | ||
| 100 | 100 | for i, answer in ipairs(item.code_answer) do |
| 101 | 101 | local passed = item.compare_result:sub(i, i) == "1" |
| 102 | 102 | |
| 103 | - local text = Case:init( | |
| 103 | + local case = Case:init( | |
| 104 | 104 | i, |
| 105 | 105 | self.parent.testcase.testcases[i], |
| 106 | 106 | answer, |
| 107 | 107 | item.expected_code_answer[i], |
| 108 | 108 | passed |
| 109 | 109 | ) |
| 110 | - group:append(text) | |
| 110 | + group:append(case) | |
| 111 | 111 | |
| 112 | 112 | local stdout = Stdout:init(item.std_output_list[i]) |
| 113 | 113 | if stdout then group:append(stdout) end |
| @@ -367,7 +367,7 @@ function result:init(parent) | ||
| 367 | 367 | }, |
| 368 | 368 | }) |
| 369 | 369 | |
| 370 | - local obj = setmetatable({ | |
| 370 | + self = setmetatable({ | |
| 371 | 371 | popup = popup, |
| 372 | 372 | layout = Layout:init({ |
| 373 | 373 | winid = popup.winid, |
| @@ -376,7 +376,7 @@ function result:init(parent) | ||
| 376 | 376 | parent = parent, |
| 377 | 377 | }, self) |
| 378 | 378 | |
| 379 | - return obj | |
| 379 | + return self | |
| 380 | 380 | end |
| 381 | 381 | |
| 382 | 382 | return result |
+1-1lua/leetcode/ui/description.lua
| @@ -152,7 +152,7 @@ end | ||
| 152 | 152 | function description:init(parent) |
| 153 | 153 | local split = Split({ |
| 154 | 154 | relative = "editor", |
| 155 | - position = "left", | |
| 155 | + position = config.user.description.position, | |
| 156 | 156 | size = config.user.description.width, |
| 157 | 157 | enter = true, |
| 158 | 158 | focusable = true, |