irongit

A Neovim plugin enabling you to solve LeetCode problems.

feat(description): toggle statistics visibility (#28)

kawreauthored
parent 9cb2f1ecommit d1543f8973aeeadc002366752f8419b67f9be6bcBrowse files

5 files changed, +44 -14

+4-0README.md
@@ -119,6 +119,8 @@ To see full configuration types see [template.lua](./lua/leetcode/config/templat
119119 position = "left", ---@type lc.position
120120
121121 width = "40%", ---@type lc.size
122+
123+ show_stats = true, ---@type boolean
122124 },
123125
124126 hooks = {
@@ -237,6 +239,8 @@ image_support = false, -- setting this to `true` will disable question descripti
237239
238240 - `toggle` same as `Leet desc`
239241
242+ - `stats` toggle description stats visibility
243+
240244 - `cookie`
241245
242246 - `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
123123 position = "left", ---@type lc.position
124124
125125 width = "40%", ---@type lc.size
126+
127+ show_stats = true, ---@type boolean
126128 },
127129
128130 hooks = {
@@ -241,6 +243,8 @@ image_support = false, -- 将此设置为 `true` 将禁用问题描述的换行
241243
242244 - `toggle` 与 `Leet desc` 相同
243245
246+ - `stats` 切换描述统计可见性
247+
244248 - `cookie`
245249
246250 - `update` 打开提示输入新 cookie
+26-14lua/leetcode-ui/split/description.lua
@@ -97,6 +97,12 @@ function Description:draw_imgs()
9797 end
9898 end
9999
100+function Description:toggle_stats()
101+ self.show_stats = not self.show_stats
102+ self:populate()
103+ self:draw()
104+end
105+
100106 ---@private
101107 function Description:populate()
102108 local q = self.question.q
@@ -114,22 +120,27 @@ function Description:populate()
114120 header:append(utils.translate(q.title, q.translated_title))
115121 header:endgrp()
116122
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+
125131 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+
128139 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")
133144 if not vim.tbl_isempty(q.hints) then
134145 header:append(" | ")
135146 header:append("󰛨 " .. t("Hints"), "leetcode_hint")
@@ -156,6 +167,7 @@ function Description:init(parent)
156167 })
157168
158169 self.question = parent
170+ self.show_stats = config.user.description.show_stats
159171 self.images = {}
160172 end
161173
+8-0lua/leetcode/command/init.lua
@@ -176,6 +176,12 @@ function cmd.desc_toggle()
176176 if q then q.description:toggle() end
177177 end
178178
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+
179185 function cmd.console()
180186 local utils = require("leetcode.utils")
181187 local q = utils.curr_question()
@@ -353,6 +359,8 @@ cmd.commands = {
353359 desc = {
354360 cmd.desc_toggle,
355361
362+ stats = { cmd.desc_toggle_stats },
363+
356364 toggle = { cmd.desc_toggle },
357365 },
358366
+2-0lua/leetcode/config/template.lua
@@ -86,6 +86,8 @@ local M = {
8686 position = "left", ---@type lc.position
8787
8888 width = "40%", ---@type lc.size
89+
90+ show_stats = true, ---@type boolean
8991 },
9092
9193 hooks = {