A Neovim plugin enabling you to solve LeetCode problems.
feat(description): toggle statistics visibility (#28)
5 files changed, +44 -14
+4-0README.md
| @@ -119,6 +119,8 @@ To see full configuration types see [template.lua](./lua/leetcode/config/templat | ||
| 119 | 119 | position = "left", ---@type lc.position |
| 120 | 120 | |
| 121 | 121 | width = "40%", ---@type lc.size |
| 122 | + | |
| 123 | + show_stats = true, ---@type boolean | |
| 122 | 124 | }, |
| 123 | 125 | |
| 124 | 126 | hooks = { |
| @@ -237,6 +239,8 @@ image_support = false, -- setting this to `true` will disable question descripti | ||
| 237 | 239 | |
| 238 | 240 | - `toggle` same as `Leet desc` |
| 239 | 241 | |
| 242 | + - `stats` toggle description stats visibility | |
| 243 | + | |
| 240 | 244 | - `cookie` |
| 241 | 245 | |
| 242 | 246 | - `update` opens a prompt to enter a new cookie |
+4-0README.zh.md
| @@ -123,6 +123,8 @@ https://github.com/kawre/leetcode.nvim/assets/69250723/309088c9-4ff7-4dff-ab61-a | ||
| 123 | 123 | position = "left", ---@type lc.position |
| 124 | 124 | |
| 125 | 125 | width = "40%", ---@type lc.size |
| 126 | + | |
| 127 | + show_stats = true, ---@type boolean | |
| 126 | 128 | }, |
| 127 | 129 | |
| 128 | 130 | hooks = { |
| @@ -241,6 +243,8 @@ image_support = false, -- 将此设置为 `true` 将禁用问题描述的换行 | ||
| 241 | 243 | |
| 242 | 244 | - `toggle` 与 `Leet desc` 相同 |
| 243 | 245 | |
| 246 | + - `stats` 切换描述统计可见性 | |
| 247 | + | |
| 244 | 248 | - `cookie` |
| 245 | 249 | |
| 246 | 250 | - `update` 打开提示输入新 cookie |
+26-14lua/leetcode-ui/split/description.lua
| @@ -97,6 +97,12 @@ function Description:draw_imgs() | ||
| 97 | 97 | end |
| 98 | 98 | end |
| 99 | 99 | |
| 100 | +function Description:toggle_stats() | |
| 101 | + self.show_stats = not self.show_stats | |
| 102 | + self:populate() | |
| 103 | + self:draw() | |
| 104 | +end | |
| 105 | + | |
| 100 | 106 | ---@private |
| 101 | 107 | function Description:populate() |
| 102 | 108 | local q = self.question.q |
| @@ -114,22 +120,27 @@ function Description:populate() | ||
| 114 | 120 | header:append(utils.translate(q.title, q.translated_title)) |
| 115 | 121 | header:endgrp() |
| 116 | 122 | |
| 117 | - header:append( | |
| 118 | - t(q.difficulty), | |
| 119 | - ({ | |
| 120 | - ["Easy"] = "leetcode_easy", | |
| 121 | - ["Medium"] = "leetcode_medium", | |
| 122 | - ["Hard"] = "leetcode_hard", | |
| 123 | - })[q.difficulty] | |
| 124 | - ) | |
| 123 | + local show_stats = self.show_stats | |
| 124 | + | |
| 125 | + if show_stats then | |
| 126 | + header:append(t(q.difficulty), "leetcode_" .. q.difficulty:lower()) | |
| 127 | + else | |
| 128 | + header:append("????", "leetcode_list") | |
| 129 | + end | |
| 130 | + | |
| 125 | 131 | header:append(" | ") |
| 126 | - header:append(q.likes .. " ", "leetcode_alt") | |
| 127 | - if not config.is_cn then header:append(" " .. q.dislikes .. " ", "leetcode_alt") end | |
| 132 | + | |
| 133 | + local likes = show_stats and q.likes or "___" | |
| 134 | + header:append(likes .. " ", "leetcode_alt") | |
| 135 | + | |
| 136 | + local dislikes = show_stats and q.dislikes or "___" | |
| 137 | + if not config.is_cn then header:append((" %s "):format(dislikes), "leetcode_alt") end | |
| 138 | + | |
| 128 | 139 | header:append(" | ") |
| 129 | - header:append( | |
| 130 | - ("%s %s %s"):format(q.stats.acRate, t("of"), q.stats.totalSubmission), | |
| 131 | - "leetcode_alt" | |
| 132 | - ) | |
| 140 | + | |
| 141 | + local ac_rate = show_stats and q.stats.acRate or "__%" | |
| 142 | + local total_sub = show_stats and q.stats.totalSubmission or "__" | |
| 143 | + header:append(("%s %s %s"):format(ac_rate, t("of"), total_sub), "leetcode_alt") | |
| 133 | 144 | if not vim.tbl_isempty(q.hints) then |
| 134 | 145 | header:append(" | ") |
| 135 | 146 | header:append(" " .. t("Hints"), "leetcode_hint") |
| @@ -156,6 +167,7 @@ function Description:init(parent) | ||
| 156 | 167 | }) |
| 157 | 168 | |
| 158 | 169 | self.question = parent |
| 170 | + self.show_stats = config.user.description.show_stats | |
| 159 | 171 | self.images = {} |
| 160 | 172 | end |
| 161 | 173 |
+8-0lua/leetcode/command/init.lua
| @@ -176,6 +176,12 @@ function cmd.desc_toggle() | ||
| 176 | 176 | if q then q.description:toggle() end |
| 177 | 177 | end |
| 178 | 178 | |
| 179 | +function cmd.desc_toggle_stats() | |
| 180 | + local utils = require("leetcode.utils") | |
| 181 | + local q = utils.curr_question() | |
| 182 | + if q then q.description:toggle_stats() end | |
| 183 | +end | |
| 184 | + | |
| 179 | 185 | function cmd.console() |
| 180 | 186 | local utils = require("leetcode.utils") |
| 181 | 187 | local q = utils.curr_question() |
| @@ -353,6 +359,8 @@ cmd.commands = { | ||
| 353 | 359 | desc = { |
| 354 | 360 | cmd.desc_toggle, |
| 355 | 361 | |
| 362 | + stats = { cmd.desc_toggle_stats }, | |
| 363 | + | |
| 356 | 364 | toggle = { cmd.desc_toggle }, |
| 357 | 365 | }, |
| 358 | 366 |
+2-0lua/leetcode/config/template.lua
| @@ -86,6 +86,8 @@ local M = { | ||
| 86 | 86 | position = "left", ---@type lc.position |
| 87 | 87 | |
| 88 | 88 | width = "40%", ---@type lc.size |
| 89 | + | |
| 90 | + show_stats = true, ---@type boolean | |
| 89 | 91 | }, |
| 90 | 92 | |
| 91 | 93 | hooks = { |