A Neovim plugin enabling you to solve LeetCode problems.
| 1 | local NuiLine = require("nui.line") |
| 2 | local NuiText = require("nui.text") |
| 3 | local Opts = require("leetcode-ui.opts") |
| 4 | local utils = require("leetcode-ui.utils") |
| 5 | local log = require("leetcode.logger") |
| 6 | |
| 7 | ---@class lc.ui.Line : NuiLine |
| 8 | local Line = NuiLine:extend("LeetLine") |
| 9 | |
| 10 | |
| 11 | return self._texts |
| 12 | end |
| 13 | |
| 14 | |
| 15 | if self.class.name == "LeetLine" then |
| 16 | return vim.api.nvim_strwidth(self:content()) |
| 17 | end |
| 18 | |
| 19 | local max_len = 0 |
| 20 | for _, item in pairs(self:contents()) do |
| 21 | max_len = math.max(Line.longest(item), max_len) |
| 22 | end |
| 23 | |
| 24 | return max_len |
| 25 | end |
| 26 | |
| 27 | ---@param layout lc.ui.Renderer |
| 28 | ---@param opts lc.ui.opts |
| 29 | |
| 30 | local texts = utils.shallowcopy(self:contents()) |
| 31 | |
| 32 | local options = Opts(self._.opts):merge(opts) |
| 33 | local pad = options:get_padding() |
| 34 | |
| 35 | if pad then |
| 36 | if pad.left then |
| 37 | table.insert(texts, 1, NuiText((" "):rep(pad.left))) |
| 38 | elseif pad.right then |
| 39 | table.insert(texts, NuiText((" "):rep(pad.right))) |
| 40 | end |
| 41 | end |
| 42 | |
| 43 | local line_idx = layout:get_line_idx(1) |
| 44 | NuiLine(texts):render(layout.bufnr, -1, line_idx, line_idx) |
| 45 | end |
| 46 | |
| 47 | -- |
| 48 | self._texts = {} |
| 49 | |
| 50 | return self |
| 51 | end |
| 52 | |
| 53 | |
| 54 | self._texts = texts |
| 55 | |
| 56 | return self |
| 57 | end |
| 58 | |
| 59 | |
| 60 | Line.super.append(self, content, highlight or self._.opts.hl) |
| 61 | |
| 62 | return self |
| 63 | end |
| 64 | |
| 65 | ---@param opts? lc.ui.opts |
| 66 | -- |
| 67 | self._.opts = vim.tbl_deep_extend("force", self._.opts or {}, opts or {}) |
| 68 | end |
| 69 | |
| 70 | ---@param texts? NuiText[] |
| 71 | ---@param opts? lc.ui.opts |
| 72 | -- |
| 73 | self._ = {} |
| 74 | self:set_opts(opts) |
| 75 | |
| 76 | Line.super.init(self, texts) |
| 77 | end |
| 78 | |
| 79 | ---@type fun(texts?: NuiText[], opts?: lc.ui.opts): lc.ui.Line |
| 80 | local LeetLine = Line |
| 81 | |
| 82 | return LeetLine |